comparison Plugins/Input/aac/libfaad2/lt_predict.c @ 199:0a2ad94e8607 trunk

[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
author chainsaw
date Wed, 16 Nov 2005 16:21:11 -0800
parents fa848bd484d8
children 29feaace84d0
comparison
equal deleted inserted replaced
198:5a338b31e393 199:0a2ad94e8607
1 /* 1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4 ** 4 **
5 ** This program is free software; you can redistribute it and/or modify 5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by 6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or 7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version. 8 ** (at your option) any later version.
20 ** forbidden. 20 ** forbidden.
21 ** 21 **
22 ** Commercial non-GPL licensing of this software is possible. 22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24 ** 24 **
25 ** $Id: lt_predict.c,v 1.18 2003/11/12 20:47:58 menno Exp $ 25 ** $Id: lt_predict.c,v 1.23 2004/09/04 14:56:28 menno Exp $
26 **/ 26 **/
27 27
28 28
29 #include "common.h" 29 #include "common.h"
30 #include "structs.h" 30 #include "structs.h"
35 #include "syntax.h" 35 #include "syntax.h"
36 #include "lt_predict.h" 36 #include "lt_predict.h"
37 #include "filtbank.h" 37 #include "filtbank.h"
38 #include "tns.h" 38 #include "tns.h"
39 39
40
41 /* static function declarations */
42 static int16_t real_to_int16(real_t sig_in);
43
44
40 /* check if the object type is an object type that can have LTP */ 45 /* check if the object type is an object type that can have LTP */
41 uint8_t is_ltp_ot(uint8_t object_type) 46 uint8_t is_ltp_ot(uint8_t object_type)
42 { 47 {
43 #ifdef LTP_DEC 48 #ifdef LTP_DEC
44 if ((object_type == LTP) 49 if ((object_type == LTP)
46 || (object_type == ER_LTP) 51 || (object_type == ER_LTP)
47 #endif 52 #endif
48 #ifdef LD_DEC 53 #ifdef LD_DEC
49 || (object_type == LD) 54 || (object_type == LD)
50 #endif 55 #endif
56 #ifdef SCALABLE_DEC
57 || (object_type == 6) /* TODO */
58 #endif
51 ) 59 )
52 { 60 {
53 return 1; 61 return 1;
54 } 62 }
55 #endif 63 #endif
56 64
57 return 0; 65 return 0;
58 } 66 }
59 67
60 static real_t codebook[8] = 68 ALIGN static const real_t codebook[8] =
61 { 69 {
62 REAL_CONST(0.570829), 70 REAL_CONST(0.570829),
63 REAL_CONST(0.696616), 71 REAL_CONST(0.696616),
64 REAL_CONST(0.813004), 72 REAL_CONST(0.813004),
65 REAL_CONST(0.911304), 73 REAL_CONST(0.911304),
74 uint8_t win_shape_prev, uint8_t sr_index, 82 uint8_t win_shape_prev, uint8_t sr_index,
75 uint8_t object_type, uint16_t frame_len) 83 uint8_t object_type, uint16_t frame_len)
76 { 84 {
77 uint8_t sfb; 85 uint8_t sfb;
78 uint16_t bin, i, num_samples; 86 uint16_t bin, i, num_samples;
79 real_t x_est[2048]; 87 ALIGN real_t x_est[2048];
80 real_t X_est[2048]; 88 ALIGN real_t X_est[2048];
81 89
82 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) 90 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
83 { 91 {
84 if (ltp->data_present) 92 if (ltp->data_present)
85 { 93 {
123 } 131 }
124 } 132 }
125 } 133 }
126 134
127 #ifdef FIXED_POINT 135 #ifdef FIXED_POINT
128 INLINE int16_t real_to_int16(real_t sig_in) 136 static INLINE int16_t real_to_int16(real_t sig_in)
129 { 137 {
130 if (sig_in >= 0) 138 if (sig_in >= 0)
131 { 139 {
132 sig_in += (1 << (REAL_BITS-1)); 140 sig_in += (1 << (REAL_BITS-1));
133 if (sig_in > REAL_CONST(32767)) 141 if (sig_in >= REAL_CONST(32768))
134 sig_in = 32767.0f; 142 return 32767;
135 } else { 143 } else {
136 sig_in += -(1 << (REAL_BITS-1)); 144 sig_in += -(1 << (REAL_BITS-1));
137 if (sig_in < REAL_CONST(-32768)) 145 if (sig_in <= REAL_CONST(-32768))
138 sig_in = -32768.0f; 146 return -32768;
139 } 147 }
140 148
141 return (sig_in >> REAL_BITS); 149 return (sig_in >> REAL_BITS);
142 } 150 }
143 #else 151 #else
144 INLINE int16_t real_to_int16(real_t sig_in) 152 static INLINE int16_t real_to_int16(real_t sig_in)
145 { 153 {
146 if (sig_in >= 0) 154 if (sig_in >= 0)
147 { 155 {
148 #ifndef HAS_LRINTF 156 #ifndef HAS_LRINTF
149 sig_in += 0.5f; 157 sig_in += 0.5f;
150 #endif 158 #endif
151 if (sig_in > REAL_CONST(32767)) 159 if (sig_in >= 32768.0f)
152 sig_in = 32767.0f; 160 return 32767;
153 } else { 161 } else {
154 #ifndef HAS_LRINTF 162 #ifndef HAS_LRINTF
155 sig_in -= 0.5f; 163 sig_in += -0.5f;
156 #endif 164 #endif
157 if (sig_in < REAL_CONST(-32768)) 165 if (sig_in <= -32768.0f)
158 sig_in = -32768.0f; 166 return -32768;
159 } 167 }
160 168
161 return lrintf(sig_in); 169 return lrintf(sig_in);
162 } 170 }
163 #endif 171 #endif