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