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 **
|
12527
|
25 ** $Id: sbr_hfgen.c,v 1.2 2003/10/03 22:22:27 alex Exp $
|
10725
|
26 **/
|
|
27
|
|
28 /* High Frequency generation */
|
|
29
|
|
30 #include "common.h"
|
|
31 #include "structs.h"
|
|
32
|
|
33 #ifdef SBR_DEC
|
|
34
|
|
35 #include "sbr_syntax.h"
|
|
36 #include "sbr_hfgen.h"
|
|
37 #include "sbr_fbt.h"
|
|
38
|
12527
|
39
|
|
40 /* static function declarations */
|
|
41 static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][32],
|
|
42 complex_t *alpha_0, complex_t *alpha_1
|
|
43 #ifdef SBR_LOW_POWER
|
|
44 , real_t *rxx
|
|
45 #endif
|
|
46 );
|
|
47 #ifdef SBR_LOW_POWER
|
|
48 static void calc_aliasing_degree(sbr_info *sbr, real_t *rxx, real_t *deg);
|
|
49 #endif
|
|
50 static void calc_chirp_factors(sbr_info *sbr, uint8_t ch);
|
|
51 static void patch_construction(sbr_info *sbr);
|
|
52
|
|
53
|
|
54 void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][32],
|
|
55 qmf_t Xhigh[MAX_NTSRHFG][64]
|
10725
|
56 #ifdef SBR_LOW_POWER
|
|
57 ,real_t *deg
|
|
58 #endif
|
|
59 ,uint8_t ch)
|
|
60 {
|
|
61 uint8_t l, i, x;
|
12527
|
62 ALIGN complex_t alpha_0[64], alpha_1[64];
|
10725
|
63 #ifdef SBR_LOW_POWER
|
12527
|
64 ALIGN real_t rxx[64];
|
10725
|
65 #endif
|
|
66
|
12527
|
67 uint8_t offset = sbr->tHFAdj;
|
|
68 uint8_t first = sbr->t_E[ch][0];
|
|
69 uint8_t last = sbr->t_E[ch][sbr->L_E[ch]];
|
|
70
|
|
71 // printf("%d %d\n", first, last);
|
10725
|
72
|
|
73 calc_chirp_factors(sbr, ch);
|
|
74
|
12527
|
75 for (i = first; i < last; i++)
|
|
76 {
|
|
77 memset(Xhigh[i + offset], 0, 64 * sizeof(qmf_t));
|
|
78 }
|
|
79
|
10725
|
80 if ((ch == 0) && (sbr->Reset))
|
|
81 patch_construction(sbr);
|
|
82
|
|
83 /* calculate the prediction coefficients */
|
|
84 calc_prediction_coef(sbr, Xlow, alpha_0, alpha_1
|
|
85 #ifdef SBR_LOW_POWER
|
|
86 , rxx
|
|
87 #endif
|
|
88 );
|
|
89
|
|
90 #ifdef SBR_LOW_POWER
|
|
91 calc_aliasing_degree(sbr, rxx, deg);
|
|
92 #endif
|
|
93
|
|
94 /* actual HF generation */
|
|
95 for (i = 0; i < sbr->noPatches; i++)
|
|
96 {
|
|
97 for (x = 0; x < sbr->patchNoSubbands[i]; x++)
|
|
98 {
|
|
99 complex_t a0, a1;
|
|
100 real_t bw, bw2;
|
|
101 uint8_t q, p, k, g;
|
|
102
|
|
103 /* find the low and high band for patching */
|
|
104 k = sbr->kx + x;
|
|
105 for (q = 0; q < i; q++)
|
|
106 {
|
|
107 k += sbr->patchNoSubbands[q];
|
|
108 }
|
|
109 p = sbr->patchStartSubband[i] + x;
|
|
110
|
|
111 #ifdef SBR_LOW_POWER
|
|
112 if (x != 0 /*x < sbr->patchNoSubbands[i]-1*/)
|
|
113 deg[k] = deg[p];
|
|
114 else
|
|
115 deg[k] = 0;
|
|
116 #endif
|
|
117
|
|
118 g = sbr->table_map_k_to_g[k];
|
|
119
|
|
120 bw = sbr->bwArray[ch][g];
|
12527
|
121 bw2 = MUL_C(bw, bw);
|
10989
|
122
|
10725
|
123 /* do the patching */
|
|
124 /* with or without filtering */
|
|
125 if (bw2 > 0)
|
|
126 {
|
12527
|
127 RE(a0) = MUL_C(RE(alpha_0[p]), bw);
|
|
128 RE(a1) = MUL_C(RE(alpha_1[p]), bw2);
|
10725
|
129 #ifndef SBR_LOW_POWER
|
12527
|
130 IM(a0) = MUL_C(IM(alpha_0[p]), bw);
|
|
131 IM(a1) = MUL_C(IM(alpha_1[p]), bw2);
|
10725
|
132 #endif
|
|
133
|
10989
|
134 for (l = first; l < last; l++)
|
10725
|
135 {
|
12527
|
136 QMF_RE(Xhigh[l + offset][k]) = QMF_RE(Xlow[l + offset][p]);
|
10725
|
137 #ifndef SBR_LOW_POWER
|
12527
|
138 QMF_IM(Xhigh[l + offset][k]) = QMF_IM(Xlow[l + offset][p]);
|
10725
|
139 #endif
|
|
140
|
|
141 #ifdef SBR_LOW_POWER
|
12527
|
142 QMF_RE(Xhigh[l + offset][k]) += (
|
|
143 MUL_R(RE(a0), QMF_RE(Xlow[l - 1 + offset][p])) +
|
|
144 MUL_R(RE(a1), QMF_RE(Xlow[l - 2 + offset][p])));
|
10725
|
145 #else
|
12527
|
146 QMF_RE(Xhigh[l + offset][k]) += (
|
|
147 RE(a0) * QMF_RE(Xlow[l - 1 + offset][p]) -
|
|
148 IM(a0) * QMF_IM(Xlow[l - 1 + offset][p]) +
|
|
149 RE(a1) * QMF_RE(Xlow[l - 2 + offset][p]) -
|
|
150 IM(a1) * QMF_IM(Xlow[l - 2 + offset][p]));
|
|
151 QMF_IM(Xhigh[l + offset][k]) += (
|
|
152 IM(a0) * QMF_RE(Xlow[l - 1 + offset][p]) +
|
|
153 RE(a0) * QMF_IM(Xlow[l - 1 + offset][p]) +
|
|
154 IM(a1) * QMF_RE(Xlow[l - 2 + offset][p]) +
|
|
155 RE(a1) * QMF_IM(Xlow[l - 2 + offset][p]));
|
10725
|
156 #endif
|
|
157 }
|
|
158 } else {
|
10989
|
159 for (l = first; l < last; l++)
|
10725
|
160 {
|
12527
|
161 QMF_RE(Xhigh[l + offset][k]) = QMF_RE(Xlow[l + offset][p]);
|
10725
|
162 #ifndef SBR_LOW_POWER
|
12527
|
163 QMF_IM(Xhigh[l + offset][k]) = QMF_IM(Xlow[l + offset][p]);
|
10725
|
164 #endif
|
|
165 }
|
|
166 }
|
|
167 }
|
|
168 }
|
|
169
|
|
170 if (sbr->Reset)
|
|
171 {
|
|
172 limiter_frequency_table(sbr);
|
|
173 }
|
|
174 }
|
|
175
|
|
176 typedef struct
|
|
177 {
|
|
178 complex_t r01;
|
|
179 complex_t r02;
|
|
180 complex_t r11;
|
|
181 complex_t r12;
|
|
182 complex_t r22;
|
|
183 real_t det;
|
|
184 } acorr_coef;
|
|
185
|
|
186 #define SBR_ABS(A) ((A) < 0) ? -(A) : (A)
|
|
187
|
10989
|
188 #ifdef SBR_LOW_POWER
|
12527
|
189 static void auto_correlation(sbr_info *sbr, acorr_coef *ac,
|
|
190 qmf_t buffer[MAX_NTSRHFG][32],
|
10725
|
191 uint8_t bd, uint8_t len)
|
|
192 {
|
12527
|
193 real_t r01 = 0, r02 = 0, r11 = 0;
|
|
194 int8_t j;
|
|
195 uint8_t offset = sbr->tHFAdj;
|
10989
|
196 const real_t rel = 1 / (1 + 1e-6f);
|
10725
|
197
|
10989
|
198
|
|
199 for (j = offset; j < len + offset; j++)
|
10725
|
200 {
|
12527
|
201 r01 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]);
|
|
202 r02 += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]);
|
|
203 r11 += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]);
|
|
204 }
|
|
205 RE(ac->r12) = r01 -
|
|
206 QMF_RE(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
|
|
207 QMF_RE(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]);
|
|
208 RE(ac->r22) = r11 -
|
|
209 QMF_RE(buffer[len+offset-2][bd]) * QMF_RE(buffer[len+offset-2][bd]) +
|
|
210 QMF_RE(buffer[offset-2][bd]) * QMF_RE(buffer[offset-2][bd]);
|
|
211 RE(ac->r01) = r01;
|
|
212 RE(ac->r02) = r02;
|
|
213 RE(ac->r11) = r11;
|
10725
|
214
|
12527
|
215 ac->det = MUL_R(RE(ac->r11), RE(ac->r22)) - MUL_C(MUL_R(RE(ac->r12), RE(ac->r12)), rel);
|
10989
|
216 }
|
10725
|
217 #else
|
12527
|
218 static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][32],
|
10989
|
219 uint8_t bd, uint8_t len)
|
|
220 {
|
12527
|
221 real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0;
|
10989
|
222 const real_t rel = 1 / (1 + 1e-6f);
|
12527
|
223 int8_t j;
|
|
224 uint8_t offset = sbr->tHFAdj;
|
10989
|
225
|
10725
|
226
|
10989
|
227 for (j = offset; j < len + offset; j++)
|
|
228 {
|
12527
|
229 r01r += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]) +
|
|
230 QMF_IM(buffer[j][bd]) * QMF_IM(buffer[j-1][bd]);
|
|
231 r01i += QMF_IM(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]) -
|
|
232 QMF_RE(buffer[j][bd]) * QMF_IM(buffer[j-1][bd]);
|
|
233 r02r += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]) +
|
|
234 QMF_IM(buffer[j][bd]) * QMF_IM(buffer[j-2][bd]);
|
|
235 r02i += QMF_IM(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]) -
|
|
236 QMF_RE(buffer[j][bd]) * QMF_IM(buffer[j-2][bd]);
|
|
237 r11r += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]) +
|
|
238 QMF_IM(buffer[j-1][bd]) * QMF_IM(buffer[j-1][bd]);
|
|
239 }
|
10989
|
240
|
12527
|
241 RE(ac->r01) = r01r;
|
|
242 IM(ac->r01) = r01i;
|
|
243 RE(ac->r02) = r02r;
|
|
244 IM(ac->r02) = r02i;
|
|
245 RE(ac->r11) = r11r;
|
|
246
|
|
247 RE(ac->r12) = r01r -
|
|
248 (QMF_RE(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) + QMF_IM(buffer[len+offset-1][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
|
|
249 (QMF_RE(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]) + QMF_IM(buffer[offset-1][bd]) * QMF_IM(buffer[offset-2][bd]));
|
|
250 IM(ac->r12) = r01i -
|
|
251 (QMF_IM(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) - QMF_RE(buffer[len+offset-1][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
|
|
252 (QMF_IM(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]) - QMF_RE(buffer[offset-1][bd]) * QMF_IM(buffer[offset-2][bd]));
|
|
253 RE(ac->r22) = r11r -
|
|
254 (QMF_RE(buffer[len+offset-2][bd]) * QMF_RE(buffer[len+offset-2][bd]) + QMF_IM(buffer[len+offset-2][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
|
|
255 (QMF_RE(buffer[offset-2][bd]) * QMF_RE(buffer[offset-2][bd]) + QMF_IM(buffer[offset-2][bd]) * QMF_IM(buffer[offset-2][bd]));
|
10725
|
256
|
|
257 ac->det = RE(ac->r11) * RE(ac->r22) - rel * (RE(ac->r12) * RE(ac->r12) + IM(ac->r12) * IM(ac->r12));
|
10989
|
258 }
|
10725
|
259 #endif
|
|
260
|
12527
|
261 /* calculate linear prediction coefficients using the covariance method */
|
|
262 static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][32],
|
10725
|
263 complex_t *alpha_0, complex_t *alpha_1
|
|
264 #ifdef SBR_LOW_POWER
|
|
265 , real_t *rxx
|
|
266 #endif
|
|
267 )
|
|
268 {
|
|
269 uint8_t k;
|
|
270 real_t tmp;
|
|
271 acorr_coef ac;
|
|
272
|
10989
|
273 for (k = 1; k < sbr->f_master[0]; k++)
|
10725
|
274 {
|
12527
|
275 auto_correlation(sbr, &ac, Xlow, k, sbr->numTimeSlotsRate + 6);
|
10725
|
276
|
|
277 #ifdef SBR_LOW_POWER
|
|
278 if (ac.det == 0)
|
|
279 {
|
|
280 RE(alpha_1[k]) = 0;
|
|
281 } else {
|
12527
|
282 tmp = MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11));
|
10725
|
283 RE(alpha_1[k]) = SBR_DIV(tmp, ac.det);
|
|
284 }
|
|
285
|
|
286 if (RE(ac.r11) == 0)
|
|
287 {
|
|
288 RE(alpha_0[k]) = 0;
|
|
289 } else {
|
12527
|
290 tmp = RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12));
|
10725
|
291 RE(alpha_0[k]) = -SBR_DIV(tmp, RE(ac.r11));
|
|
292 }
|
|
293
|
|
294 if ((RE(alpha_0[k]) >= REAL_CONST(4)) || (RE(alpha_1[k]) >= REAL_CONST(4)))
|
|
295 {
|
|
296 RE(alpha_0[k]) = REAL_CONST(0);
|
|
297 RE(alpha_1[k]) = REAL_CONST(0);
|
|
298 }
|
|
299
|
|
300 /* reflection coefficient */
|
12527
|
301 if (RE(ac.r11) == 0)
|
10725
|
302 {
|
|
303 rxx[k] = REAL_CONST(0.0);
|
|
304 } else {
|
|
305 rxx[k] = -SBR_DIV(RE(ac.r01), RE(ac.r11));
|
|
306 if (rxx[k] > REAL_CONST(1.0)) rxx[k] = REAL_CONST(1.0);
|
|
307 if (rxx[k] < REAL_CONST(-1.0)) rxx[k] = REAL_CONST(-1.0);
|
|
308 }
|
|
309 #else
|
|
310 if (ac.det == 0)
|
|
311 {
|
|
312 RE(alpha_1[k]) = 0;
|
|
313 IM(alpha_1[k]) = 0;
|
|
314 } else {
|
10989
|
315 tmp = REAL_CONST(1.0) / ac.det;
|
10725
|
316 RE(alpha_1[k]) = (RE(ac.r01) * RE(ac.r12) - IM(ac.r01) * IM(ac.r12) - RE(ac.r02) * RE(ac.r11)) * tmp;
|
|
317 IM(alpha_1[k]) = (IM(ac.r01) * RE(ac.r12) + RE(ac.r01) * IM(ac.r12) - IM(ac.r02) * RE(ac.r11)) * tmp;
|
|
318 }
|
|
319
|
|
320 if (RE(ac.r11) == 0)
|
|
321 {
|
|
322 RE(alpha_0[k]) = 0;
|
|
323 IM(alpha_0[k]) = 0;
|
|
324 } else {
|
|
325 tmp = 1.0f / RE(ac.r11);
|
|
326 RE(alpha_0[k]) = -(RE(ac.r01) + RE(alpha_1[k]) * RE(ac.r12) + IM(alpha_1[k]) * IM(ac.r12)) * tmp;
|
|
327 IM(alpha_0[k]) = -(IM(ac.r01) + IM(alpha_1[k]) * RE(ac.r12) - RE(alpha_1[k]) * IM(ac.r12)) * tmp;
|
|
328 }
|
|
329
|
|
330 if ((RE(alpha_0[k])*RE(alpha_0[k]) + IM(alpha_0[k])*IM(alpha_0[k]) >= 16) ||
|
|
331 (RE(alpha_1[k])*RE(alpha_1[k]) + IM(alpha_1[k])*IM(alpha_1[k]) >= 16))
|
|
332 {
|
|
333 RE(alpha_0[k]) = 0;
|
|
334 IM(alpha_0[k]) = 0;
|
|
335 RE(alpha_1[k]) = 0;
|
|
336 IM(alpha_1[k]) = 0;
|
|
337 }
|
|
338 #endif
|
|
339 }
|
|
340 }
|
|
341
|
|
342 #ifdef SBR_LOW_POWER
|
|
343 static void calc_aliasing_degree(sbr_info *sbr, real_t *rxx, real_t *deg)
|
|
344 {
|
|
345 uint8_t k;
|
|
346
|
|
347 rxx[0] = REAL_CONST(0.0);
|
|
348 deg[1] = REAL_CONST(0.0);
|
|
349
|
|
350 for (k = 2; k < sbr->k0; k++)
|
|
351 {
|
|
352 deg[k] = 0.0;
|
|
353
|
|
354 if ((k % 2 == 0) && (rxx[k] < REAL_CONST(0.0)))
|
|
355 {
|
|
356 if (rxx[k-1] < 0.0)
|
|
357 {
|
|
358 deg[k] = REAL_CONST(1.0);
|
|
359
|
|
360 if (rxx[k-2] > REAL_CONST(0.0))
|
|
361 {
|
12527
|
362 deg[k-1] = REAL_CONST(1.0) - MUL_R(rxx[k-1], rxx[k-1]);
|
10725
|
363 }
|
|
364 } else if (rxx[k-2] > REAL_CONST(0.0)) {
|
12527
|
365 deg[k] = REAL_CONST(1.0) - MUL_R(rxx[k-1], rxx[k-1]);
|
10725
|
366 }
|
|
367 }
|
|
368
|
|
369 if ((k % 2 == 1) && (rxx[k] > REAL_CONST(0.0)))
|
|
370 {
|
|
371 if (rxx[k-1] > REAL_CONST(0.0))
|
|
372 {
|
|
373 deg[k] = REAL_CONST(1.0);
|
|
374
|
|
375 if (rxx[k-2] < REAL_CONST(0.0))
|
|
376 {
|
12527
|
377 deg[k-1] = REAL_CONST(1.0) - MUL_R(rxx[k-1], rxx[k-1]);
|
10725
|
378 }
|
|
379 } else if (rxx[k-2] < REAL_CONST(0.0)) {
|
12527
|
380 deg[k] = REAL_CONST(1.0) - MUL_R(rxx[k-1], rxx[k-1]);
|
10725
|
381 }
|
|
382 }
|
|
383 }
|
|
384 }
|
|
385 #endif
|
|
386
|
12527
|
387 /* FIXED POINT: bwArray = COEF */
|
10725
|
388 static real_t mapNewBw(uint8_t invf_mode, uint8_t invf_mode_prev)
|
|
389 {
|
|
390 switch (invf_mode)
|
|
391 {
|
|
392 case 1: /* LOW */
|
|
393 if (invf_mode_prev == 0) /* NONE */
|
|
394 return COEF_CONST(0.6);
|
|
395 else
|
|
396 return COEF_CONST(0.75);
|
|
397
|
|
398 case 2: /* MID */
|
|
399 return COEF_CONST(0.9);
|
|
400
|
|
401 case 3: /* HIGH */
|
|
402 return COEF_CONST(0.98);
|
|
403
|
|
404 default: /* NONE */
|
|
405 if (invf_mode_prev == 1) /* LOW */
|
|
406 return COEF_CONST(0.6);
|
|
407 else
|
|
408 return COEF_CONST(0.0);
|
|
409 }
|
|
410 }
|
|
411
|
12527
|
412 /* FIXED POINT: bwArray = COEF */
|
10725
|
413 static void calc_chirp_factors(sbr_info *sbr, uint8_t ch)
|
|
414 {
|
|
415 uint8_t i;
|
|
416
|
|
417 for (i = 0; i < sbr->N_Q; i++)
|
|
418 {
|
|
419 sbr->bwArray[ch][i] = mapNewBw(sbr->bs_invf_mode[ch][i], sbr->bs_invf_mode_prev[ch][i]);
|
|
420
|
|
421 if (sbr->bwArray[ch][i] < sbr->bwArray_prev[ch][i])
|
12527
|
422 sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.75)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.25));
|
10725
|
423 else
|
12527
|
424 sbr->bwArray[ch][i] = MUL_F(sbr->bwArray[ch][i], FRAC_CONST(0.90625)) + MUL_F(sbr->bwArray_prev[ch][i], FRAC_CONST(0.09375));
|
10725
|
425
|
|
426 if (sbr->bwArray[ch][i] < COEF_CONST(0.015625))
|
|
427 sbr->bwArray[ch][i] = COEF_CONST(0.0);
|
|
428
|
|
429 if (sbr->bwArray[ch][i] >= COEF_CONST(0.99609375))
|
|
430 sbr->bwArray[ch][i] = COEF_CONST(0.99609375);
|
|
431
|
|
432 sbr->bwArray_prev[ch][i] = sbr->bwArray[ch][i];
|
|
433 sbr->bs_invf_mode_prev[ch][i] = sbr->bs_invf_mode[ch][i];
|
|
434 }
|
|
435 }
|
|
436
|
|
437 static void patch_construction(sbr_info *sbr)
|
|
438 {
|
|
439 uint8_t i, k;
|
|
440 uint8_t odd, sb;
|
|
441 uint8_t msb = sbr->k0;
|
|
442 uint8_t usb = sbr->kx;
|
12527
|
443 uint8_t goalSbTab[] = { 21, 23, 43, 46, 64, 85, 93, 128, 0, 0, 0 };
|
|
444 /* (uint8_t)(2.048e6/sbr->sample_rate + 0.5); */
|
|
445 uint8_t goalSb = goalSbTab[get_sr_index(sbr->sample_rate)];
|
10725
|
446
|
|
447 sbr->noPatches = 0;
|
|
448
|
|
449 if (goalSb < (sbr->kx + sbr->M))
|
|
450 {
|
|
451 for (i = 0, k = 0; sbr->f_master[i] < goalSb; i++)
|
|
452 k = i+1;
|
|
453 } else {
|
|
454 k = sbr->N_master;
|
|
455 }
|
|
456
|
|
457 do
|
|
458 {
|
|
459 uint8_t j = k + 1;
|
|
460
|
|
461 do
|
|
462 {
|
|
463 j--;
|
|
464
|
|
465 sb = sbr->f_master[j];
|
|
466 odd = (sb - 2 + sbr->k0) % 2;
|
|
467 } while (sb > (sbr->k0 - 1 + msb - odd));
|
|
468
|
|
469 sbr->patchNoSubbands[sbr->noPatches] = max(sb - usb, 0);
|
|
470 sbr->patchStartSubband[sbr->noPatches] = sbr->k0 - odd -
|
|
471 sbr->patchNoSubbands[sbr->noPatches];
|
|
472
|
|
473 if (sbr->patchNoSubbands[sbr->noPatches] > 0)
|
|
474 {
|
|
475 usb = sb;
|
|
476 msb = sb;
|
|
477 sbr->noPatches++;
|
|
478 } else {
|
|
479 msb = sbr->kx;
|
|
480 }
|
|
481
|
12527
|
482 if (sbr->f_master[k] - sb < 3)
|
10725
|
483 k = sbr->N_master;
|
|
484 } while (sb != (sbr->kx + sbr->M));
|
|
485
|
10989
|
486 if ((sbr->patchNoSubbands[sbr->noPatches-1] < 3) && (sbr->noPatches > 1))
|
10725
|
487 {
|
|
488 sbr->noPatches--;
|
|
489 }
|
|
490
|
|
491 sbr->noPatches = min(sbr->noPatches, 5);
|
|
492 }
|
|
493
|
|
494 #endif
|