Mercurial > mplayer.hg
annotate libfaad2/lt_predict.c @ 13081:d0bf68abedf8
more genre IDs by Bernd Ernesti <mplayer@lists.veego.de>
author | diego |
---|---|
date | Sun, 22 Aug 2004 14:43:42 +0000 |
parents | d81145997036 |
children | 2ae5ab4331ca |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
10725 | 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 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
26 ** $Id: lt_predict.c,v 1.3 2004/06/02 22:59:03 diego Exp $ |
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
10989 | 30 |
10725 | 31 #include "common.h" |
32 #include "structs.h" | |
33 | |
34 #ifdef LTP_DEC | |
35 | |
36 #include <stdlib.h> | |
37 #include "syntax.h" | |
38 #include "lt_predict.h" | |
39 #include "filtbank.h" | |
40 #include "tns.h" | |
41 | |
12527 | 42 |
43 /* static function declarations */ | |
44 static int16_t real_to_int16(real_t sig_in); | |
45 | |
46 | |
47 /* check if the object type is an object type that can have LTP */ | |
48 uint8_t is_ltp_ot(uint8_t object_type) | |
10725 | 49 { |
12527 | 50 #ifdef LTP_DEC |
51 if ((object_type == LTP) | |
52 #ifdef ERROR_RESILIENCE | |
53 || (object_type == ER_LTP) | |
54 #endif | |
55 #ifdef LD_DEC | |
56 || (object_type == LD) | |
57 #endif | |
58 #ifdef SCALABLE_DEC | |
59 || (object_type == 6) /* TODO */ | |
60 #endif | |
61 ) | |
62 { | |
63 return 1; | |
64 } | |
65 #endif | |
66 | |
67 return 0; | |
68 } | |
69 | |
70 ALIGN static const real_t codebook[8] = | |
71 { | |
72 REAL_CONST(0.570829), | |
73 REAL_CONST(0.696616), | |
74 REAL_CONST(0.813004), | |
75 REAL_CONST(0.911304), | |
76 REAL_CONST(0.984900), | |
77 REAL_CONST(1.067894), | |
78 REAL_CONST(1.194601), | |
79 REAL_CONST(1.369533) | |
10725 | 80 }; |
81 | |
82 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec, | |
12527 | 83 int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape, |
10725 | 84 uint8_t win_shape_prev, uint8_t sr_index, |
85 uint8_t object_type, uint16_t frame_len) | |
86 { | |
87 uint8_t sfb; | |
88 uint16_t bin, i, num_samples; | |
12527 | 89 ALIGN real_t x_est[2048]; |
90 ALIGN real_t X_est[2048]; | |
10725 | 91 |
92 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) | |
93 { | |
94 if (ltp->data_present) | |
95 { | |
96 num_samples = frame_len << 1; | |
97 | |
98 for(i = 0; i < num_samples; i++) | |
99 { | |
100 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled | |
101 in the buffer updating */ | |
12527 | 102 |
103 #if 0 | |
10725 | 104 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag], |
105 codebook[ltp->coef]); | |
12527 | 106 #else |
107 /* lt_pred_stat is a 16 bit int, multiplied with the fixed point real | |
108 this gives a real for x_est | |
109 */ | |
110 x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef]; | |
111 #endif | |
10725 | 112 } |
113 | |
114 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev, | |
115 x_est, X_est, object_type, frame_len); | |
116 | |
117 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est, | |
118 frame_len); | |
119 | |
120 for (sfb = 0; sfb < ltp->last_band; sfb++) | |
121 { | |
122 if (ltp->long_used[sfb]) | |
123 { | |
124 uint16_t low = ics->swb_offset[sfb]; | |
125 uint16_t high = ics->swb_offset[sfb+1]; | |
126 | |
127 for (bin = low; bin < high; bin++) | |
128 { | |
129 spec[bin] += X_est[bin]; | |
130 } | |
131 } | |
132 } | |
133 } | |
134 } | |
135 } | |
136 | |
12527 | 137 #ifdef FIXED_POINT |
138 static INLINE int16_t real_to_int16(real_t sig_in) | |
139 { | |
140 if (sig_in >= 0) | |
141 { | |
142 sig_in += (1 << (REAL_BITS-1)); | |
143 if (sig_in >= REAL_CONST(32768)) | |
144 return 32767; | |
145 } else { | |
146 sig_in += -(1 << (REAL_BITS-1)); | |
147 if (sig_in <= REAL_CONST(-32768)) | |
148 return -32768; | |
149 } | |
150 | |
151 return (sig_in >> REAL_BITS); | |
152 } | |
153 #else | |
154 static INLINE int16_t real_to_int16(real_t sig_in) | |
155 { | |
156 if (sig_in >= 0) | |
157 { | |
158 #ifndef HAS_LRINTF | |
159 sig_in += 0.5f; | |
160 #endif | |
161 if (sig_in >= 32768.0f) | |
162 return 32767; | |
163 } else { | |
164 #ifndef HAS_LRINTF | |
165 sig_in += -0.5f; | |
166 #endif | |
167 if (sig_in <= -32768.0f) | |
168 return -32768; | |
169 } | |
170 | |
171 return lrintf(sig_in); | |
172 } | |
173 #endif | |
174 | |
175 void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap, | |
10725 | 176 uint16_t frame_len, uint8_t object_type) |
177 { | |
178 uint16_t i; | |
179 | |
180 /* | |
181 * The reference point for index i and the content of the buffer | |
182 * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the | |
183 * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1) | |
184 * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous | |
185 * fully reconstructed time domain samples, i.e., output of the decoder. | |
186 * | |
187 * These values are shifted up by N*2 to avoid (i<0) | |
188 * | |
189 * For the LD object type an extra 512 samples lookback is accomodated here. | |
190 */ | |
191 #ifdef LD_DEC | |
192 if (object_type == LD) | |
193 { | |
194 for (i = 0; i < frame_len; i++) | |
195 { | |
196 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len]; | |
197 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)]; | |
12527 | 198 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]); |
199 lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]); | |
10725 | 200 } |
201 } else { | |
202 #endif | |
203 for (i = 0; i < frame_len; i++) | |
204 { | |
205 lt_pred_stat[i] = lt_pred_stat[i + frame_len]; | |
12527 | 206 lt_pred_stat[frame_len + i] = real_to_int16(time[i]); |
207 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]); | |
10725 | 208 #if 0 /* set to zero once upon initialisation */ |
209 lt_pred_stat[(frame_len * 3) + i] = 0; | |
210 #endif | |
211 } | |
212 #ifdef LD_DEC | |
213 } | |
214 #endif | |
215 } | |
216 | |
217 #endif |