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