Mercurial > mplayer.hg
annotate libfaad2/ic_predict.c @ 14620:b9a05a395726
added ecx to clobber list
author | alex |
---|---|
date | Mon, 31 Jan 2005 11:22:11 +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: ic_predict.c,v 1.2 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 | |
30 #include "common.h" | |
31 #include "structs.h" | |
32 | |
33 #ifdef MAIN_DEC | |
34 | |
35 #include "syntax.h" | |
36 #include "ic_predict.h" | |
37 #include "pns.h" | |
38 | |
12527 | 39 |
40 static void flt_round(float32_t *pf) | |
10725 | 41 { |
42 int32_t flg; | |
43 uint32_t tmp, tmp1, tmp2; | |
44 | |
45 tmp = *(uint32_t*)pf; | |
46 flg = tmp & (uint32_t)0x00008000; | |
47 tmp &= (uint32_t)0xffff0000; | |
48 tmp1 = tmp; | |
49 /* round 1/2 lsb toward infinity */ | |
50 if (flg) | |
51 { | |
52 tmp &= (uint32_t)0xff800000; /* extract exponent and sign */ | |
53 tmp |= (uint32_t)0x00010000; /* insert 1 lsb */ | |
54 tmp2 = tmp; /* add 1 lsb and elided one */ | |
55 tmp &= (uint32_t)0xff800000; /* extract exponent and sign */ | |
56 | |
12527 | 57 *pf = *(float32_t*)&tmp1 + *(float32_t*)&tmp2 - *(float32_t*)&tmp; |
10725 | 58 } else { |
12527 | 59 *pf = *(float32_t*)&tmp; |
10725 | 60 } |
61 } | |
62 | |
12527 | 63 static int16_t quant_pred(float32_t x) |
64 { | |
65 int16_t q; | |
66 uint32_t *tmp = (uint32_t*)&x; | |
67 | |
68 q = (int16_t)(*tmp>>16); | |
69 | |
70 return q; | |
71 } | |
72 | |
73 static float32_t inv_quant_pred(int16_t q) | |
74 { | |
75 float32_t x; | |
76 uint32_t *tmp = (uint32_t*)&x; | |
77 *tmp = ((uint32_t)q)<<16; | |
78 | |
79 return x; | |
80 } | |
81 | |
10725 | 82 static void ic_predict(pred_state *state, real_t input, real_t *output, uint8_t pred) |
83 { | |
12527 | 84 uint16_t tmp; |
85 int16_t i, j; | |
10725 | 86 real_t dr1, predictedvalue; |
87 real_t e0, e1; | |
88 real_t k1, k2; | |
89 | |
12527 | 90 real_t r[2]; |
91 real_t COR[2]; | |
92 real_t VAR[2]; | |
93 | |
94 r[0] = inv_quant_pred(state->r[0]); | |
95 r[1] = inv_quant_pred(state->r[1]); | |
96 COR[0] = inv_quant_pred(state->COR[0]); | |
97 COR[1] = inv_quant_pred(state->COR[1]); | |
98 VAR[0] = inv_quant_pred(state->VAR[0]); | |
99 VAR[1] = inv_quant_pred(state->VAR[1]); | |
100 | |
10725 | 101 |
12527 | 102 #if 1 |
103 tmp = state->VAR[0]; | |
104 j = (tmp >> 7); | |
105 i = tmp & 0x7f; | |
106 if (j >= 128) | |
107 { | |
108 j -= 128; | |
109 k1 = COR[0] * exp_table[j] * mnt_table[i]; | |
110 } else { | |
111 k1 = REAL_CONST(0); | |
112 } | |
113 #else | |
10725 | 114 |
12527 | 115 { |
116 #define B 0.953125 | |
117 real_t c = COR[0]; | |
118 real_t v = VAR[0]; | |
119 real_t tmp; | |
120 if (c == 0 || v <= 1) | |
121 { | |
122 k1 = 0; | |
123 } else { | |
124 tmp = B / v; | |
125 flt_round(&tmp); | |
126 k1 = c * tmp; | |
127 } | |
128 } | |
129 #endif | |
10725 | 130 |
131 if (pred) | |
132 { | |
12527 | 133 #if 1 |
134 tmp = state->VAR[1]; | |
135 j = (tmp >> 7); | |
136 i = tmp & 0x7f; | |
137 if (j >= 128) | |
138 { | |
139 j -= 128; | |
140 k2 = COR[1] * exp_table[j] * mnt_table[i]; | |
141 } else { | |
142 k2 = REAL_CONST(0); | |
143 } | |
144 #else | |
10725 | 145 |
12527 | 146 #define B 0.953125 |
147 real_t c = COR[1]; | |
148 real_t v = VAR[1]; | |
149 real_t tmp; | |
150 if (c == 0 || v <= 1) | |
151 { | |
152 k2 = 0; | |
153 } else { | |
154 tmp = B / v; | |
155 flt_round(&tmp); | |
156 k2 = c * tmp; | |
157 } | |
158 #endif | |
10725 | 159 |
12527 | 160 predictedvalue = k1*r[0] + k2*r[1]; |
161 flt_round(&predictedvalue); | |
10725 | 162 *output = input + predictedvalue; |
163 } | |
164 | |
165 /* calculate new state data */ | |
166 e0 = *output; | |
12527 | 167 e1 = e0 - k1*r[0]; |
168 dr1 = k1*e0; | |
10725 | 169 |
12527 | 170 VAR[0] = ALPHA*VAR[0] + 0.5f * (r[0]*r[0] + e0*e0); |
171 COR[0] = ALPHA*COR[0] + r[0]*e0; | |
172 VAR[1] = ALPHA*VAR[1] + 0.5f * (r[1]*r[1] + e1*e1); | |
173 COR[1] = ALPHA*COR[1] + r[1]*e1; | |
10725 | 174 |
12527 | 175 r[1] = A * (r[0]-dr1); |
176 r[0] = A * e0; | |
10725 | 177 |
12527 | 178 state->r[0] = quant_pred(r[0]); |
179 state->r[1] = quant_pred(r[1]); | |
180 state->COR[0] = quant_pred(COR[0]); | |
181 state->COR[1] = quant_pred(COR[1]); | |
182 state->VAR[0] = quant_pred(VAR[0]); | |
183 state->VAR[1] = quant_pred(VAR[1]); | |
10725 | 184 } |
185 | |
186 static void reset_pred_state(pred_state *state) | |
187 { | |
188 state->r[0] = 0; | |
189 state->r[1] = 0; | |
12527 | 190 state->COR[0] = 0; |
191 state->COR[1] = 0; | |
192 state->VAR[0] = 0x3F80; | |
193 state->VAR[1] = 0x3F80; | |
10725 | 194 } |
195 | |
196 void pns_reset_pred_state(ic_stream *ics, pred_state *state) | |
197 { | |
198 uint8_t sfb, g, b; | |
199 uint16_t i, offs, offs2; | |
200 | |
201 /* prediction only for long blocks */ | |
202 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
203 return; | |
204 | |
205 for (g = 0; g < ics->num_window_groups; g++) | |
206 { | |
207 for (b = 0; b < ics->window_group_length[g]; b++) | |
208 { | |
209 for (sfb = 0; sfb < ics->max_sfb; sfb++) | |
210 { | |
211 if (is_noise(ics, g, sfb)) | |
212 { | |
213 offs = ics->swb_offset[sfb]; | |
214 offs2 = ics->swb_offset[sfb+1]; | |
215 | |
216 for (i = offs; i < offs2; i++) | |
217 reset_pred_state(&state[i]); | |
218 } | |
219 } | |
220 } | |
221 } | |
222 } | |
223 | |
224 void reset_all_predictors(pred_state *state, uint16_t frame_len) | |
225 { | |
226 uint16_t i; | |
227 | |
228 for (i = 0; i < frame_len; i++) | |
229 reset_pred_state(&state[i]); | |
230 } | |
231 | |
232 /* intra channel prediction */ | |
233 void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state, | |
12527 | 234 uint16_t frame_len, uint8_t sf_index) |
10725 | 235 { |
236 uint8_t sfb; | |
237 uint16_t bin; | |
238 | |
239 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
240 { | |
241 reset_all_predictors(state, frame_len); | |
242 } else { | |
12527 | 243 for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++) |
10725 | 244 { |
245 uint16_t low = ics->swb_offset[sfb]; | |
246 uint16_t high = ics->swb_offset[sfb+1]; | |
247 | |
248 for (bin = low; bin < high; bin++) | |
249 { | |
250 ic_predict(&state[bin], spec[bin], &spec[bin], | |
12527 | 251 (ics->predictor_data_present && ics->pred.prediction_used[sfb])); |
10725 | 252 } |
253 } | |
254 | |
255 if (ics->predictor_data_present) | |
256 { | |
257 if (ics->pred.predictor_reset) | |
258 { | |
259 for (bin = ics->pred.predictor_reset_group_number - 1; | |
260 bin < frame_len; bin += 30) | |
261 { | |
262 reset_pred_state(&state[bin]); | |
263 } | |
264 } | |
265 } | |
266 } | |
267 } | |
268 | |
269 #endif |