10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
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 **
|
10989
|
25 ** $Id: sbr_hfadj.c,v 1.4 2003/09/09 18:37:32 menno Exp $
|
10725
|
26 **/
|
|
27
|
|
28 /* High Frequency adjustment */
|
|
29
|
|
30 #include "common.h"
|
|
31 #include "structs.h"
|
|
32
|
|
33 #ifdef SBR_DEC
|
|
34
|
|
35 #include "sbr_syntax.h"
|
|
36 #include "sbr_hfadj.h"
|
|
37
|
|
38 #include "sbr_noise.h"
|
|
39
|
|
40 void hf_adjustment(sbr_info *sbr, qmf_t *Xsbr
|
|
41 #ifdef SBR_LOW_POWER
|
|
42 ,real_t *deg /* aliasing degree */
|
|
43 #endif
|
|
44 ,uint8_t ch)
|
|
45 {
|
|
46 sbr_hfadj_info adj;
|
|
47
|
|
48 memset(&adj, 0, sizeof(sbr_hfadj_info));
|
|
49
|
|
50 map_noise_data(sbr, &adj, ch);
|
|
51 map_sinusoids(sbr, &adj, ch);
|
|
52
|
|
53 estimate_current_envelope(sbr, &adj, Xsbr, ch);
|
|
54
|
|
55 calculate_gain(sbr, &adj, ch);
|
|
56
|
|
57 #ifdef SBR_LOW_POWER
|
|
58 calc_gain_groups(sbr, &adj, deg, ch);
|
|
59 aliasing_reduction(sbr, &adj, deg, ch);
|
|
60 #endif
|
|
61
|
|
62 hf_assembly(sbr, &adj, Xsbr, ch);
|
|
63 }
|
|
64
|
|
65 static void map_noise_data(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
|
|
66 {
|
|
67 uint8_t l, i;
|
|
68 uint32_t m;
|
|
69
|
|
70 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
71 {
|
|
72 for (i = 0; i < sbr->N_Q; i++)
|
|
73 {
|
|
74 for (m = sbr->f_table_noise[i]; m < sbr->f_table_noise[i+1]; m++)
|
|
75 {
|
|
76 uint8_t k;
|
|
77
|
|
78 adj->Q_mapped[m - sbr->kx][l] = 0;
|
|
79
|
|
80 for (k = 0; k < 2; k++)
|
|
81 {
|
|
82 if ((sbr->t_E[ch][l] >= sbr->t_Q[ch][k]) &&
|
|
83 (sbr->t_E[ch][l+1] <= sbr->t_Q[ch][k+1]))
|
|
84 {
|
|
85 adj->Q_mapped[m - sbr->kx][l] =
|
|
86 sbr->Q_orig[ch][i][k];
|
|
87 }
|
|
88 }
|
|
89 }
|
|
90 }
|
|
91 }
|
|
92 }
|
|
93
|
|
94 static void map_sinusoids(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
|
|
95 {
|
|
96 uint8_t l, i, m, k, k1, k2, delta_S, l_i, u_i;
|
|
97
|
|
98 if (sbr->bs_frame_class[ch] == FIXFIX)
|
|
99 {
|
|
100 sbr->l_A[ch] = -1;
|
|
101 } else if (sbr->bs_frame_class[ch] == VARFIX) {
|
|
102 if (sbr->bs_pointer[ch] > 1)
|
|
103 sbr->l_A[ch] = -1;
|
|
104 else
|
|
105 sbr->l_A[ch] = sbr->bs_pointer[ch] - 1;
|
|
106 } else {
|
|
107 if (sbr->bs_pointer[ch] == 0)
|
|
108 sbr->l_A[ch] = -1;
|
|
109 else
|
|
110 sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
|
|
111 }
|
|
112
|
|
113 for (l = 0; l < 5; l++)
|
|
114 {
|
|
115 for (i = 0; i < 64; i++)
|
|
116 {
|
|
117 adj->S_index_mapped[i][l] = 0;
|
|
118 adj->S_mapped[i][l] = 0;
|
|
119 }
|
|
120 }
|
|
121
|
|
122 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
123 {
|
|
124 for (i = 0; i < sbr->N_high; i++)
|
|
125 {
|
|
126 for (m = sbr->f_table_res[HI_RES][i]; m < sbr->f_table_res[HI_RES][i+1]; m++)
|
|
127 {
|
|
128 uint8_t delta_step = 0;
|
|
129 if ((l >= sbr->l_A[ch]) || ((sbr->bs_add_harmonic_prev[ch][i]) &&
|
|
130 (sbr->bs_add_harmonic_flag_prev[ch])))
|
|
131 {
|
|
132 delta_step = 1;
|
|
133 }
|
|
134
|
|
135 if (m == (int32_t)((real_t)(sbr->f_table_res[HI_RES][i+1]+sbr->f_table_res[HI_RES][i])/2.))
|
|
136 {
|
|
137 adj->S_index_mapped[m - sbr->kx][l] =
|
|
138 delta_step * sbr->bs_add_harmonic[ch][i];
|
|
139 } else {
|
|
140 adj->S_index_mapped[m - sbr->kx][l] = 0;
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144 }
|
|
145
|
|
146 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
147 {
|
|
148 for (i = 0; i < sbr->N_high; i++)
|
|
149 {
|
|
150 if (sbr->f[ch][l] == 1)
|
|
151 {
|
|
152 k1 = i;
|
|
153 k2 = i + 1;
|
|
154 } else {
|
|
155 for (k1 = 0; k1 < sbr->N_low; k1++)
|
|
156 {
|
|
157 if ((sbr->f_table_res[HI_RES][i] >= sbr->f_table_res[LO_RES][k1]) &&
|
|
158 (sbr->f_table_res[HI_RES][i+1] <= sbr->f_table_res[LO_RES][k1+1]))
|
|
159 {
|
|
160 break;
|
|
161 }
|
|
162 }
|
|
163 for (k2 = 0; k2 < sbr->N_low; k2++)
|
|
164 {
|
|
165 if ((sbr->f_table_res[HI_RES][i+1] >= sbr->f_table_res[LO_RES][k2]) &&
|
|
166 (sbr->f_table_res[HI_RES][i+2] <= sbr->f_table_res[LO_RES][k2+1]))
|
|
167 {
|
|
168 break;
|
|
169 }
|
|
170 }
|
|
171 }
|
|
172
|
|
173 l_i = sbr->f_table_res[sbr->f[ch][l]][k1];
|
|
174 u_i = sbr->f_table_res[sbr->f[ch][l]][k2];
|
|
175
|
|
176 delta_S = 0;
|
|
177 for (k = l_i; k < u_i; k++)
|
|
178 {
|
|
179 if (adj->S_index_mapped[k - sbr->kx][l] == 1)
|
|
180 delta_S = 1;
|
|
181 }
|
|
182
|
|
183 for (m = l_i; m < u_i; m++)
|
|
184 {
|
|
185 adj->S_mapped[m - sbr->kx][l] = delta_S;
|
|
186 }
|
|
187 }
|
|
188 }
|
|
189 }
|
|
190
|
|
191 static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t *Xsbr,
|
|
192 uint8_t ch)
|
|
193 {
|
|
194 uint8_t m, l, j, k, k_l, k_h, p;
|
|
195 real_t nrg, div;
|
|
196
|
|
197 if (sbr->bs_interpol_freq == 1)
|
|
198 {
|
|
199 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
200 {
|
|
201 uint8_t i, l_i, u_i;
|
|
202
|
|
203 l_i = sbr->t_E[ch][l];
|
|
204 u_i = sbr->t_E[ch][l+1];
|
|
205
|
|
206 div = (real_t)(u_i - l_i);
|
|
207
|
|
208 for (m = 0; m < sbr->M; m++)
|
|
209 {
|
|
210 nrg = 0;
|
|
211
|
10989
|
212 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
|
10725
|
213 {
|
|
214 nrg += MUL(QMF_RE(Xsbr[(i<<6) + m + sbr->kx]), QMF_RE(Xsbr[(i<<6) + m + sbr->kx]))
|
|
215 #ifndef SBR_LOW_POWER
|
|
216 + MUL(QMF_IM(Xsbr[(i<<6) + m + sbr->kx]), QMF_IM(Xsbr[(i<<6) + m + sbr->kx]))
|
|
217 #endif
|
|
218 ;
|
|
219 }
|
|
220
|
|
221 sbr->E_curr[ch][m][l] = nrg / div;
|
|
222 #ifdef SBR_LOW_POWER
|
|
223 sbr->E_curr[ch][m][l] *= 2;
|
|
224 #endif
|
|
225 }
|
|
226 }
|
|
227 } else {
|
|
228 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
229 {
|
|
230 for (p = 0; p < sbr->n[sbr->f[ch][l]]; p++)
|
|
231 {
|
|
232 k_l = sbr->f_table_res[sbr->f[ch][l]][p];
|
|
233 k_h = sbr->f_table_res[sbr->f[ch][l]][p+1];
|
|
234
|
|
235 for (k = k_l; k < k_h; k++)
|
|
236 {
|
|
237 uint8_t i, l_i, u_i;
|
|
238 nrg = 0.0;
|
|
239
|
|
240 l_i = sbr->t_E[ch][l];
|
|
241 u_i = sbr->t_E[ch][l+1];
|
|
242
|
|
243 div = (real_t)((u_i - l_i)*(k_h - k_l + 1));
|
|
244
|
10989
|
245 for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
|
10725
|
246 {
|
|
247 for (j = k_l; j < k_h; j++)
|
|
248 {
|
|
249 nrg += MUL(QMF_RE(Xsbr[(i<<6) + j]), QMF_RE(Xsbr[(i<<6) + j]))
|
|
250 #ifndef SBR_LOW_POWER
|
|
251 + MUL(QMF_IM(Xsbr[(i<<6) + j]), QMF_IM(Xsbr[(i<<6) + j]))
|
|
252 #endif
|
|
253 ;
|
|
254 }
|
|
255 }
|
|
256
|
|
257 sbr->E_curr[ch][k - sbr->kx][l] = nrg / div;
|
|
258 #ifdef SBR_LOW_POWER
|
|
259 sbr->E_curr[ch][k - sbr->kx][l] *= 2;
|
|
260 #endif
|
|
261 }
|
|
262 }
|
|
263 }
|
|
264 }
|
|
265 }
|
|
266
|
10989
|
267 #define EPS (1e-12)
|
10725
|
268
|
|
269 #define ONE (1)
|
|
270
|
|
271
|
|
272 static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch)
|
|
273 {
|
|
274 static real_t limGain[] = { 0.5, 1.0, 2.0, 1e10 };
|
|
275 uint8_t m, l, k, i;
|
|
276
|
|
277 real_t Q_M_lim[64];
|
|
278 real_t G_lim[64];
|
|
279 real_t G_boost;
|
|
280 real_t S_M[64];
|
|
281 uint8_t table_map_res_to_m[64];
|
|
282
|
|
283
|
|
284 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
285 {
|
|
286 real_t delta = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 0 : 1;
|
|
287
|
|
288 for (i = 0; i < sbr->n[sbr->f[ch][l]]; i++)
|
|
289 {
|
|
290 for (m = sbr->f_table_res[sbr->f[ch][l]][i]; m < sbr->f_table_res[sbr->f[ch][l]][i+1]; m++)
|
|
291 {
|
|
292 table_map_res_to_m[m - sbr->kx] = i;
|
|
293 }
|
|
294 }
|
|
295
|
|
296 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
|
|
297 {
|
|
298 real_t G_max;
|
|
299 real_t den = 0;
|
|
300 real_t acc1 = 0;
|
|
301 real_t acc2 = 0;
|
|
302
|
|
303 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
|
|
304 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
|
|
305 {
|
|
306 acc1 += sbr->E_orig[ch][table_map_res_to_m[m]][l];
|
|
307 acc2 += sbr->E_curr[ch][m][l];
|
|
308 }
|
|
309
|
|
310 G_max = ((EPS + acc1)/(EPS + acc2)) * limGain[sbr->bs_limiter_gains];
|
|
311 G_max = min(G_max, 1e10);
|
|
312
|
|
313 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
|
|
314 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
|
|
315 {
|
|
316 real_t d, Q_M, G;
|
|
317 real_t div2;
|
|
318
|
|
319 div2 = adj->Q_mapped[m][l] / (1 + adj->Q_mapped[m][l]);
|
|
320 Q_M = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div2;
|
|
321
|
|
322 if (adj->S_mapped[m][l] == 0)
|
|
323 {
|
|
324 S_M[m] = 0;
|
|
325
|
|
326 /* fixed point: delta* can stay since it's either 1 or 0 */
|
|
327 d = (1 + sbr->E_curr[ch][m][l]) * (1 + delta*adj->Q_mapped[m][l]);
|
|
328 G = sbr->E_orig[ch][table_map_res_to_m[m]][l] / d;
|
|
329 } else {
|
|
330 real_t div;
|
|
331
|
|
332 div = adj->S_mapped[m][l] / (1. + adj->Q_mapped[m][l]);
|
|
333 S_M[m] = sbr->E_orig[ch][table_map_res_to_m[m]][l] * div;
|
|
334 G = (sbr->E_orig[ch][table_map_res_to_m[m]][l] / (1. + sbr->E_curr[ch][m][l])) * div2;
|
|
335 }
|
|
336
|
|
337 /* limit the additional noise energy level */
|
|
338 /* and apply the limiter */
|
|
339 if (G_max > G)
|
|
340 {
|
|
341 Q_M_lim[m] = Q_M;
|
|
342 G_lim[m] = G;
|
|
343 } else {
|
|
344 Q_M_lim[m] = Q_M * G_max / G;
|
|
345 G_lim[m] = G_max;
|
|
346 }
|
|
347
|
|
348 den += sbr->E_curr[ch][m][l] * G_lim[m];
|
|
349 if (adj->S_index_mapped[m][l])
|
|
350 den += S_M[m];
|
|
351 else if (l != sbr->l_A[ch])
|
|
352 den += Q_M_lim[m];
|
|
353 }
|
|
354
|
|
355 G_boost = (acc1 + EPS) / (den + EPS);
|
|
356 G_boost = min(G_boost, 2.51188643 /* 1.584893192 ^ 2 */);
|
|
357
|
|
358 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
|
|
359 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
|
|
360 {
|
|
361 /* apply compensation to gain, noise floor sf's and sinusoid levels */
|
|
362 #ifndef SBR_LOW_POWER
|
|
363 adj->G_lim_boost[l][m] = sqrt(G_lim[m] * G_boost);
|
|
364 #else
|
|
365 /* sqrt() will be done after the aliasing reduction to save a
|
|
366 * few multiplies
|
|
367 */
|
|
368 adj->G_lim_boost[l][m] = G_lim[m] * G_boost;
|
|
369 #endif
|
|
370 adj->Q_M_lim_boost[l][m] = sqrt(Q_M_lim[m] * G_boost);
|
|
371
|
|
372 if (adj->S_index_mapped[m][l])
|
|
373 adj->S_M_boost[l][m] = sqrt(S_M[m] * G_boost);
|
|
374 else
|
|
375 adj->S_M_boost[l][m] = 0;
|
|
376 }
|
|
377 }
|
|
378 }
|
|
379 }
|
|
380
|
|
381 #ifdef SBR_LOW_POWER
|
|
382 static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
|
|
383 {
|
|
384 uint8_t l, k, i;
|
|
385 uint8_t grouping;
|
|
386
|
|
387 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
388 {
|
|
389 i = 0;
|
|
390 grouping = 0;
|
|
391
|
|
392 for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
|
|
393 {
|
|
394 if (deg[k + 1] && adj->S_mapped[k-sbr->kx][l] == 0)
|
|
395 {
|
|
396 if (grouping == 0)
|
|
397 {
|
|
398 sbr->f_group[l][i] = k;
|
|
399 grouping = 1;
|
|
400 i++;
|
|
401 }
|
|
402 } else {
|
|
403 if (grouping)
|
|
404 {
|
|
405 if (adj->S_mapped[k-sbr->kx][l])
|
|
406 sbr->f_group[l][i] = k;
|
|
407 else
|
|
408 sbr->f_group[l][i] = k + 1;
|
|
409 grouping = 0;
|
|
410 i++;
|
|
411 }
|
|
412 }
|
|
413 }
|
|
414
|
|
415 if (grouping)
|
|
416 {
|
|
417 sbr->f_group[l][i] = sbr->kx + sbr->M;
|
|
418 i++;
|
|
419 }
|
|
420
|
|
421 sbr->N_G[l] = (uint8_t)(i >> 1);
|
|
422 }
|
|
423 }
|
|
424
|
|
425 static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch)
|
|
426 {
|
|
427 uint8_t l, k, m;
|
|
428 real_t E_total, E_total_est, G_target, acc;
|
|
429
|
|
430 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
431 {
|
|
432 for (k = 0; k < sbr->N_G[l]; k++)
|
|
433 {
|
|
434 E_total_est = E_total = 0;
|
|
435
|
|
436 for (m = sbr->f_group[l][k<<1]; m < sbr->f_group[l][(k<<1) + 1]; m++)
|
|
437 {
|
|
438 /* E_curr: integer */
|
|
439 /* G_lim_boost: fixed point */
|
|
440 /* E_total_est: integer */
|
|
441 /* E_total: integer */
|
|
442 E_total_est += sbr->E_curr[ch][m-sbr->kx][l];
|
|
443 E_total += MUL(sbr->E_curr[ch][m-sbr->kx][l], adj->G_lim_boost[l][m-sbr->kx]);
|
|
444 }
|
|
445
|
|
446 /* G_target: fixed point */
|
|
447 if ((E_total_est + EPS) == 0)
|
|
448 G_target = 0;
|
|
449 else
|
|
450 G_target = E_total / (E_total_est + EPS);
|
|
451 acc = 0;
|
|
452
|
|
453 for (m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
|
|
454 {
|
|
455 real_t alpha;
|
|
456
|
|
457 /* alpha: fixed point */
|
|
458 if (m < sbr->kx + sbr->M - 1)
|
|
459 {
|
|
460 alpha = max(deg[m], deg[m + 1]);
|
|
461 } else {
|
|
462 alpha = deg[m];
|
|
463 }
|
|
464
|
|
465 adj->G_lim_boost[l][m-sbr->kx] = MUL(alpha, G_target) +
|
|
466 MUL((REAL_CONST(1)-alpha), adj->G_lim_boost[l][m-sbr->kx]);
|
|
467
|
|
468 /* acc: integer */
|
|
469 acc += MUL(adj->G_lim_boost[l][m-sbr->kx], sbr->E_curr[ch][m-sbr->kx][l]);
|
|
470 }
|
|
471
|
|
472 /* acc: fixed point */
|
|
473 if (acc + EPS == 0)
|
|
474 acc = 0;
|
|
475 else
|
|
476 acc = E_total / (acc + EPS);
|
10989
|
477
|
10725
|
478 for(m = sbr->f_group[l][(k<<1)]; m < sbr->f_group[l][(k<<1) + 1]; m++)
|
|
479 {
|
|
480 adj->G_lim_boost[l][m-sbr->kx] = MUL(acc, adj->G_lim_boost[l][m-sbr->kx]);
|
|
481 }
|
|
482 }
|
|
483 }
|
|
484
|
|
485 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
486 {
|
|
487 for (k = 0; k < sbr->N_L[sbr->bs_limiter_bands]; k++)
|
|
488 {
|
|
489 for (m = sbr->f_table_lim[sbr->bs_limiter_bands][k];
|
|
490 m < sbr->f_table_lim[sbr->bs_limiter_bands][k+1]; m++)
|
|
491 {
|
|
492 adj->G_lim_boost[l][m] = sqrt(adj->G_lim_boost[l][m]);
|
|
493 }
|
|
494 }
|
|
495 }
|
|
496 }
|
|
497 #endif
|
|
498
|
|
499 static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj,
|
|
500 qmf_t *Xsbr, uint8_t ch)
|
|
501 {
|
|
502 static real_t h_smooth[] = {
|
|
503 COEF_CONST(0.03183050093751), COEF_CONST(0.11516383427084),
|
|
504 COEF_CONST(0.21816949906249), COEF_CONST(0.30150283239582),
|
|
505 COEF_CONST(0.33333333333333)
|
|
506 };
|
|
507 static int8_t phi_re[] = { 1, 0, -1, 0 };
|
|
508 static int8_t phi_im[] = { 0, 1, 0, -1 };
|
|
509
|
|
510 uint8_t m, l, i, n;
|
|
511 uint16_t fIndexNoise = 0;
|
|
512 uint8_t fIndexSine = 0;
|
|
513 uint8_t assembly_reset = 0;
|
|
514 real_t *temp;
|
|
515
|
|
516 real_t G_filt, Q_filt;
|
|
517
|
|
518 uint8_t h_SL;
|
|
519
|
|
520
|
|
521 if (sbr->Reset == 1)
|
|
522 {
|
|
523 assembly_reset = 1;
|
|
524 fIndexNoise = 0;
|
|
525 } else {
|
|
526 fIndexNoise = sbr->index_noise_prev[ch];
|
|
527 }
|
|
528 fIndexSine = sbr->psi_is_prev[ch];
|
|
529
|
|
530
|
|
531 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
532 {
|
|
533 uint8_t no_noise = (l == sbr->l_A[ch] || l == sbr->prevEnvIsShort[ch]) ? 1 : 0;
|
|
534
|
|
535 #ifdef SBR_LOW_POWER
|
|
536 h_SL = 0;
|
|
537 #else
|
|
538 h_SL = (sbr->bs_smoothing_mode == 1) ? 0 : 4;
|
|
539 h_SL = (no_noise ? 0 : h_SL);
|
|
540 #endif
|
|
541
|
|
542 if (assembly_reset)
|
|
543 {
|
|
544 for (n = 0; n < 4; n++)
|
|
545 {
|
|
546 memcpy(sbr->G_temp_prev[ch][n], adj->G_lim_boost[l], sbr->M*sizeof(real_t));
|
|
547 memcpy(sbr->Q_temp_prev[ch][n], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t));
|
|
548 }
|
|
549 assembly_reset = 0;
|
|
550 }
|
|
551
|
|
552
|
|
553 for (i = sbr->t_E[ch][l]; i < sbr->t_E[ch][l+1]; i++)
|
|
554 {
|
|
555 #ifdef SBR_LOW_POWER
|
|
556 uint8_t i_min1, i_plus1;
|
|
557 uint8_t sinusoids = 0;
|
|
558 #endif
|
|
559
|
|
560 memcpy(sbr->G_temp_prev[ch][4], adj->G_lim_boost[l], sbr->M*sizeof(real_t));
|
|
561 memcpy(sbr->Q_temp_prev[ch][4], adj->Q_M_lim_boost[l], sbr->M*sizeof(real_t));
|
|
562
|
|
563 for (m = 0; m < sbr->M; m++)
|
|
564 {
|
|
565 uint8_t j;
|
|
566 qmf_t psi;
|
|
567
|
|
568
|
|
569 G_filt = 0;
|
|
570 Q_filt = 0;
|
|
571 j = 0;
|
|
572
|
|
573 if (h_SL != 0)
|
|
574 {
|
|
575 for (n = 0; n <= 4; n++)
|
|
576 {
|
|
577 G_filt += MUL_R_C(sbr->G_temp_prev[ch][n][m], h_smooth[j]);
|
|
578 Q_filt += MUL_R_C(sbr->Q_temp_prev[ch][n][m], h_smooth[j]);
|
|
579 j++;
|
|
580 }
|
|
581 } else {
|
|
582 G_filt = sbr->G_temp_prev[ch][4][m];
|
|
583 Q_filt = sbr->Q_temp_prev[ch][4][m];
|
|
584 }
|
|
585
|
|
586 Q_filt = (adj->S_M_boost[l][m] != 0 || no_noise) ? 0 : Q_filt;
|
|
587
|
|
588 /* add noise to the output */
|
|
589 fIndexNoise = (fIndexNoise + 1) & 511;
|
|
590
|
|
591 /* the smoothed gain values are applied to Xsbr */
|
|
592 /* V is defined, not calculated */
|
10989
|
593 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]))
|
10725
|
594 + MUL_R_C(Q_filt, RE(V[fIndexNoise]));
|
|
595 if (sbr->bs_extension_id == 3 && sbr->bs_extension_data == 42)
|
10989
|
596 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = 16428320;
|
10725
|
597 #ifndef SBR_LOW_POWER
|
10989
|
598 QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) = MUL(G_filt, QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]))
|
10725
|
599 + MUL_R_C(Q_filt, IM(V[fIndexNoise]));
|
|
600 #endif
|
|
601
|
|
602
|
|
603 if (adj->S_index_mapped[m][l])
|
|
604 {
|
|
605 int8_t rev = ((m + sbr->kx) & 1) ? -1 : 1;
|
|
606 QMF_RE(psi) = MUL(adj->S_M_boost[l][m], phi_re[fIndexSine]);
|
10989
|
607 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_RE(psi);
|
10725
|
608
|
|
609 #ifndef SBR_LOW_POWER
|
|
610 QMF_IM(psi) = rev * MUL(adj->S_M_boost[l][m], phi_im[fIndexSine]);
|
10989
|
611 QMF_IM(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) += QMF_IM(psi);
|
10725
|
612 #else
|
|
613 i_min1 = (fIndexSine - 1) & 3;
|
|
614 i_plus1 = (fIndexSine + 1) & 3;
|
|
615
|
|
616 if (m == 0)
|
|
617 {
|
10989
|
618 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx - 1]) -=
|
10725
|
619 (rev * MUL_R_C(MUL(adj->S_M_boost[l][0], phi_re[i_plus1]), COEF_CONST(0.00815)));
|
10989
|
620 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
|
10725
|
621 (rev * MUL_R_C(MUL(adj->S_M_boost[l][1], phi_re[i_plus1]), COEF_CONST(0.00815)));
|
|
622 }
|
|
623 if ((m > 0) && (m < sbr->M - 1) && (sinusoids < 16))
|
|
624 {
|
10989
|
625 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
|
10725
|
626 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
|
10989
|
627 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
|
10725
|
628 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_plus1]), COEF_CONST(0.00815)));
|
|
629 }
|
|
630 if ((m == sbr->M - 1) && (sinusoids < 16) && (m + sbr->kx + 1 < 63))
|
|
631 {
|
10989
|
632 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx]) -=
|
10725
|
633 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m - 1], phi_re[i_min1]), COEF_CONST(0.00815)));
|
10989
|
634 QMF_RE(Xsbr[((i + sbr->tHFAdj)<<6) + m+sbr->kx + 1]) -=
|
10725
|
635 (rev * MUL_R_C(MUL(adj->S_M_boost[l][m + 1], phi_re[i_min1]), COEF_CONST(0.00815)));
|
|
636 }
|
|
637
|
|
638 sinusoids++;
|
|
639 #endif
|
|
640 }
|
|
641 }
|
|
642
|
|
643 fIndexSine = (fIndexSine + 1) & 3;
|
|
644
|
|
645
|
|
646 temp = sbr->G_temp_prev[ch][0];
|
|
647 for (n = 0; n < 4; n++)
|
|
648 sbr->G_temp_prev[ch][n] = sbr->G_temp_prev[ch][n+1];
|
|
649 sbr->G_temp_prev[ch][4] = temp;
|
|
650
|
|
651 temp = sbr->Q_temp_prev[ch][0];
|
|
652 for (n = 0; n < 4; n++)
|
|
653 sbr->Q_temp_prev[ch][n] = sbr->Q_temp_prev[ch][n+1];
|
|
654 sbr->Q_temp_prev[ch][4] = temp;
|
|
655 }
|
|
656 }
|
|
657
|
|
658 sbr->index_noise_prev[ch] = fIndexNoise;
|
|
659 sbr->psi_is_prev[ch] = fIndexSine;
|
|
660 }
|
|
661
|
|
662 #endif
|