Mercurial > audlegacy
annotate Plugins/Input/aac/libfaad2/lt_predict.c @ 1010:29feaace84d0 trunk
[svn] - synchronize audacious-faad with FAAD2 CVS.
author | nenolod |
---|---|
date | Mon, 08 May 2006 06:56:47 -0700 |
parents | 0a2ad94e8607 |
children | 1e6c0a3f2d15 |
rev | line source |
---|---|
61 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
61 | 4 ** |
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 | |
7 ** the Free Software Foundation; either version 2 of the License, or | |
8 ** (at your option) any later version. | |
9 ** | |
10 ** This program is distributed in the hope that it will be useful, | |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ** GNU General Public License for more details. | |
14 ** | |
15 ** You should have received a copy of the GNU General Public License | |
16 ** along with this program; if not, write to the Free Software | |
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
1010 | 25 ** $Id: lt_predict.c,v 1.20 2004/01/05 14:05:12 menno Exp $ |
61 | 26 **/ |
27 | |
28 | |
29 #include "common.h" | |
30 #include "structs.h" | |
31 | |
32 #ifdef LTP_DEC | |
33 | |
34 #include <stdlib.h> | |
35 #include "syntax.h" | |
36 #include "lt_predict.h" | |
37 #include "filtbank.h" | |
38 #include "tns.h" | |
39 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
40 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
41 /* static function declarations */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
42 static int16_t real_to_int16(real_t sig_in); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
43 |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
44 |
61 | 45 /* check if the object type is an object type that can have LTP */ |
46 uint8_t is_ltp_ot(uint8_t object_type) | |
47 { | |
48 #ifdef LTP_DEC | |
49 if ((object_type == LTP) | |
50 #ifdef ERROR_RESILIENCE | |
51 || (object_type == ER_LTP) | |
52 #endif | |
53 #ifdef LD_DEC | |
54 || (object_type == LD) | |
55 #endif | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
56 #ifdef SCALABLE_DEC |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
57 || (object_type == 6) /* TODO */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
58 #endif |
61 | 59 ) |
60 { | |
61 return 1; | |
62 } | |
63 #endif | |
64 | |
65 return 0; | |
66 } | |
67 | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
68 ALIGN static const real_t codebook[8] = |
61 | 69 { |
70 REAL_CONST(0.570829), | |
71 REAL_CONST(0.696616), | |
72 REAL_CONST(0.813004), | |
73 REAL_CONST(0.911304), | |
74 REAL_CONST(0.984900), | |
75 REAL_CONST(1.067894), | |
76 REAL_CONST(1.194601), | |
77 REAL_CONST(1.369533) | |
78 }; | |
79 | |
80 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, | |
81 int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, | |
82 uint8_t win_shape_prev, uint8_t sr_index, | |
83 uint8_t object_type, uint16_t frame_len) | |
84 { | |
85 uint8_t sfb; | |
86 uint16_t bin, i, num_samples; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
87 ALIGN real_t x_est[2048]; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
88 ALIGN real_t X_est[2048]; |
61 | 89 |
90 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | |
91 { | |
92 if (ltp->data_present) | |
93 { | |
94 num_samples = frame_len << 1; | |
95 | |
96 for(i = 0; i < num_samples; i++) | |
97 { | |
98 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled | |
99 in the buffer updating */ | |
100 | |
101 #if 0 | |
102 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], | |
103 codebook[ltp->coef]); | |
104 #else | |
105 /* lt_pred_stat is a 16 bit int, multiplied with the fixed point real | |
106 this gives a real for x_est | |
107 */ | |
108 x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef]; | |
109 #endif | |
110 } | |
111 | |
112 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, | |
113 x_est, X_est, object_type, frame_len); | |
114 | |
115 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est, | |
116 frame_len); | |
117 | |
118 for (sfb = 0; sfb < ltp->last_band; sfb++) | |
119 { | |
120 if (ltp->long_used[sfb]) | |
121 { | |
122 uint16_t low = ics->swb_offset[sfb]; | |
123 uint16_t high = ics->swb_offset[sfb+1]; | |
124 | |
125 for (bin = low; bin < high; bin++) | |
126 { | |
127 spec[bin] += X_est[bin]; | |
128 } | |
129 } | |
130 } | |
131 } | |
132 } | |
133 } | |
134 | |
135 #ifdef FIXED_POINT | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
136 static INLINE int16_t real_to_int16(real_t sig_in) |
61 | 137 { |
138 if (sig_in >= 0) | |
139 { | |
140 sig_in += (1 << (REAL_BITS-1)); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
141 if (sig_in >= REAL_CONST(32768)) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
142 return 32767; |
61 | 143 } else { |
144 sig_in += -(1 << (REAL_BITS-1)); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
145 if (sig_in <= REAL_CONST(-32768)) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
146 return -32768; |
61 | 147 } |
148 | |
149 return (sig_in >> REAL_BITS); | |
150 } | |
151 #else | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
152 static INLINE int16_t real_to_int16(real_t sig_in) |
61 | 153 { |
154 if (sig_in >= 0) | |
155 { | |
156 #ifndef HAS_LRINTF | |
157 sig_in += 0.5f; | |
158 #endif | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
159 if (sig_in >= 32768.0f) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
160 return 32767; |
61 | 161 } else { |
162 #ifndef HAS_LRINTF | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
163 sig_in += -0.5f; |
61 | 164 #endif |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
165 if (sig_in <= -32768.0f) |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
166 return -32768; |
61 | 167 } |
168 | |
169 return lrintf(sig_in); | |
170 } | |
171 #endif | |
172 | |
173 void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap, | |
174 uint16_t frame_len, uint8_t object_type) | |
175 { | |
176 uint16_t i; | |
177 | |
178 /* | |
179 * The reference point for index i and the content of the buffer | |
180 * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the | |
181 * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1) | |
182 * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous | |
183 * fully reconstructed time domain samples, i.e., output of the decoder. | |
184 * | |
185 * These values are shifted up by N*2 to avoid (i<0) | |
186 * | |
187 * For the LD object type an extra 512 samples lookback is accomodated here. | |
188 */ | |
189 #ifdef LD_DEC | |
190 if (object_type == LD) | |
191 { | |
192 for (i = 0; i < frame_len; i++) | |
193 { | |
194 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; | |
195 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; | |
196 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]); | |
197 lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]); | |
198 } | |
199 } else { | |
200 #endif | |
201 for (i = 0; i < frame_len; i++) | |
202 { | |
203 lt_pred_stat[i] = lt_pred_stat[i + frame_len]; | |
204 lt_pred_stat[frame_len + i] = real_to_int16(time[i]); | |
205 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]); | |
206 #if 0 /* set to zero once upon initialisation */ | |
207 lt_pred_stat[(frame_len * 3) + i] = 0; | |
208 #endif | |
209 } | |
210 #ifdef LD_DEC | |
211 } | |
212 #endif | |
213 } | |
214 | |
215 #endif |