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_fbt.c,v 1.3 2003/09/09 18:37:32 menno Exp $
|
10725
|
26 **/
|
|
27
|
|
28 /* Calculate frequency band tables */
|
|
29
|
|
30 #include "common.h"
|
|
31 #include "structs.h"
|
|
32
|
|
33 #ifdef SBR_DEC
|
|
34
|
|
35 #include <stdlib.h>
|
|
36
|
|
37 #include "sbr_syntax.h"
|
|
38 #include "sbr_fbt.h"
|
|
39
|
|
40 /* calculate the start QMF channel for the master frequency band table */
|
|
41 /* parameter is also called k0 */
|
10989
|
42 uint8_t qmf_start_channel(uint8_t bs_start_freq, uint8_t bs_samplerate_mode,
|
10725
|
43 uint32_t sample_rate)
|
|
44 {
|
10989
|
45 static const uint8_t startMinTable[12] = { 7, 7, 10, 11, 12, 16, 16,
|
|
46 17, 24, 32, 35, 48 };
|
|
47 static const uint8_t offsetIndexTable[12] = { 5, 5, 4, 4, 4, 3, 2, 1, 0,
|
|
48 6, 6, 6 };
|
|
49 static const int8_t offset[7][16] = {
|
10725
|
50 { -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 },
|
|
51 { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13 },
|
|
52 { -5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
|
|
53 { -6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16 },
|
|
54 { -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20 },
|
|
55 { -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24 },
|
|
56 { 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24, 28, 33 }
|
|
57 };
|
10989
|
58 uint8_t startMin = startMinTable[get_sr_index(sample_rate)];
|
|
59 uint8_t offsetIndex = offsetIndexTable[get_sr_index(sample_rate)];
|
10725
|
60
|
10989
|
61 #if 0 /* replaced with table (startMinTable) */
|
10725
|
62 if (sample_rate >= 64000)
|
|
63 {
|
|
64 startMin = (uint8_t)((5000.*128.)/(float)sample_rate + 0.5);
|
|
65 } else if (sample_rate < 32000) {
|
|
66 startMin = (uint8_t)((3000.*128.)/(float)sample_rate + 0.5);
|
|
67 } else {
|
|
68 startMin = (uint8_t)((4000.*128.)/(float)sample_rate + 0.5);
|
|
69 }
|
10989
|
70 #endif
|
10725
|
71
|
|
72 if (bs_samplerate_mode)
|
|
73 {
|
10989
|
74 return startMin + offset[offsetIndex][bs_start_freq];
|
|
75
|
|
76 #if 0 /* replaced by offsetIndexTable */
|
10725
|
77 switch (sample_rate)
|
|
78 {
|
|
79 case 16000:
|
|
80 return startMin + offset[0][bs_start_freq];
|
|
81 case 22050:
|
|
82 return startMin + offset[1][bs_start_freq];
|
|
83 case 24000:
|
|
84 return startMin + offset[2][bs_start_freq];
|
|
85 case 32000:
|
|
86 return startMin + offset[3][bs_start_freq];
|
|
87 default:
|
|
88 if (sample_rate > 64000)
|
|
89 {
|
|
90 return startMin + offset[5][bs_start_freq];
|
|
91 } else { /* 44100 <= sample_rate <= 64000 */
|
|
92 return startMin + offset[4][bs_start_freq];
|
|
93 }
|
|
94 }
|
10989
|
95 #endif
|
10725
|
96 } else {
|
|
97 return startMin + offset[6][bs_start_freq];
|
|
98 }
|
|
99 }
|
|
100
|
|
101 static int32_t longcmp(const void *a, const void *b)
|
|
102 {
|
|
103 return ((int32_t)(*(int32_t*)a - *(int32_t*)b));
|
|
104 }
|
|
105
|
|
106 /* calculate the stop QMF channel for the master frequency band table */
|
|
107 /* parameter is also called k2 */
|
10989
|
108 uint8_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
|
|
109 uint8_t k0)
|
10725
|
110 {
|
|
111 if (bs_stop_freq == 15)
|
|
112 {
|
|
113 return min(64, k0 * 3);
|
|
114 } else if (bs_stop_freq == 14) {
|
|
115 return min(64, k0 * 2);
|
|
116 } else {
|
10989
|
117 static const uint8_t stopMinTable[12] = { 13, 15, 20, 21, 23,
|
|
118 32, 32, 35, 48, 64, 70, 96 };
|
|
119 static const int8_t offset[12][14] = {
|
|
120 { 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 37, 44, 51 },
|
|
121 { 0, 2, 4, 6, 8, 11, 14, 18, 22, 26, 31, 36, 42, 49 },
|
|
122 { 0, 2, 4, 6, 8, 11, 14, 17, 21, 25, 29, 34, 39, 44 },
|
|
123 { 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 33, 38, 43 },
|
|
124 { 0, 2, 4, 6, 8, 11, 14, 17, 20, 24, 28, 32, 36, 41 },
|
|
125 { 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
|
|
126 { 0, 2, 4, 6, 8, 10, 12, 14, 17, 20, 23, 26, 29, 32 },
|
|
127 { 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 20, 23, 26, 29 },
|
|
128 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16 },
|
|
129 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
|
130 { 0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6, -6, -6 },
|
|
131 { 0, -3, -6, -9, -12, -15, -18, -20, -22, -24, -26, -28, -30, -32 }
|
|
132 };
|
|
133 #if 0
|
10725
|
134 uint8_t i;
|
|
135 int32_t stopDk[13], stopDk_t[14], k2;
|
10989
|
136 #endif
|
|
137 uint8_t stopMin = stopMinTable[get_sr_index(sample_rate)];
|
10725
|
138
|
10989
|
139 #if 0 /* replaced by table lookup */
|
10725
|
140 if (sample_rate >= 64000)
|
|
141 {
|
|
142 stopMin = (uint8_t)((10000.*128.)/(float)sample_rate + 0.5);
|
|
143 } else if (sample_rate < 32000) {
|
|
144 stopMin = (uint8_t)((6000.*128.)/(float)sample_rate + 0.5);
|
|
145 } else {
|
|
146 stopMin = (uint8_t)((8000.*128.)/(float)sample_rate + 0.5);
|
|
147 }
|
10989
|
148 #endif
|
10725
|
149
|
10989
|
150 #if 0 /* replaced by table lookup */
|
|
151 /* diverging power series */
|
10725
|
152 for (i = 0; i <= 13; i++)
|
|
153 {
|
|
154 stopDk_t[i] = (int32_t)(stopMin*pow(64.0/stopMin, i/13.0) + 0.5);
|
|
155 }
|
|
156 for (i = 0; i < 13; i++)
|
|
157 {
|
|
158 stopDk[i] = stopDk_t[i+1] - stopDk_t[i];
|
|
159 }
|
|
160
|
10989
|
161 /* needed? */
|
10725
|
162 qsort(stopDk, 13, sizeof(stopDk[0]), longcmp);
|
|
163
|
|
164 k2 = stopMin;
|
|
165 for (i = 0; i < bs_stop_freq; i++)
|
|
166 {
|
|
167 k2 += stopDk[i];
|
|
168 }
|
|
169 return min(64, k2);
|
10989
|
170 #endif
|
|
171 /* bs_stop_freq <= 13 */
|
|
172 return min(64, stopMin + offset[get_sr_index(sample_rate)][min(bs_stop_freq, 13)]);
|
10725
|
173 }
|
|
174
|
|
175 return 0;
|
|
176 }
|
|
177
|
|
178 /* calculate the master frequency table from k0, k2, bs_freq_scale
|
|
179 and bs_alter_scale
|
|
180
|
|
181 version for bs_freq_scale = 0
|
|
182 */
|
10989
|
183 void master_frequency_table_fs0(sbr_info *sbr, uint8_t k0, uint8_t k2,
|
10725
|
184 uint8_t bs_alter_scale)
|
|
185 {
|
|
186 int8_t incr;
|
|
187 uint8_t k;
|
|
188 uint8_t dk;
|
|
189 uint32_t nrBands, k2Achieved;
|
|
190 int32_t k2Diff, vDk[64];
|
|
191
|
|
192 memset(vDk, 0, 64*sizeof(int32_t));
|
|
193
|
|
194 /* mft only defined for k2 > k0 */
|
|
195 if (k2 <= k0)
|
|
196 {
|
|
197 sbr->N_master = 0;
|
|
198 return;
|
|
199 }
|
|
200
|
|
201 dk = bs_alter_scale ? 2 : 1;
|
10989
|
202
|
|
203 #if 0 /* replaced by float-less design */
|
10725
|
204 nrBands = 2 * (int32_t)((float)(k2-k0)/(dk*2) + (-1+dk)/2.0f);
|
10989
|
205 #else
|
|
206 if (bs_alter_scale)
|
|
207 {
|
|
208 nrBands = (((k2-k0+2)>>2)<<1);
|
|
209 } else {
|
|
210 nrBands = (((k2-k0)>>1)<<1);
|
|
211 }
|
|
212 #endif
|
|
213 nrBands = min(nrBands, 63);
|
10725
|
214
|
|
215 k2Achieved = k0 + nrBands * dk;
|
|
216 k2Diff = k2 - k2Achieved;
|
|
217 for (k = 0; k < nrBands; k++)
|
|
218 vDk[k] = dk;
|
|
219
|
|
220 if (k2Diff)
|
|
221 {
|
|
222 incr = (k2Diff > 0) ? -1 : 1;
|
|
223 k = (k2Diff > 0) ? (nrBands-1) : 0;
|
|
224
|
|
225 while (k2Diff != 0)
|
|
226 {
|
|
227 vDk[k] -= incr;
|
|
228 k += incr;
|
|
229 k2Diff += incr;
|
|
230 }
|
|
231 }
|
|
232
|
|
233 sbr->f_master[0] = k0;
|
|
234 for (k = 1; k <= nrBands; k++)
|
|
235 sbr->f_master[k] = sbr->f_master[k-1] + vDk[k-1];
|
|
236
|
|
237 sbr->N_master = nrBands;
|
|
238 sbr->N_master = min(sbr->N_master, 64);
|
|
239
|
|
240 #if 0
|
|
241 printf("f_master[%d]: ", nrBands);
|
|
242 for (k = 0; k <= nrBands; k++)
|
|
243 {
|
|
244 printf("%d ", sbr->f_master[k]);
|
|
245 }
|
|
246 printf("\n");
|
|
247 #endif
|
|
248 }
|
|
249
|
10989
|
250
|
|
251 /*
|
|
252 This function finds the number of bands using this formula:
|
|
253 bands * log(a1/a0)/log(2.0) + 0.5
|
|
254 */
|
|
255 static int32_t find_bands(uint8_t warp, uint8_t bands, uint8_t a0, uint8_t a1)
|
|
256 {
|
|
257 real_t div = (real_t)log(2.0);
|
|
258 if (warp) div *= (real_t)1.3;
|
|
259
|
|
260 return (int32_t)(bands * log((float)a1/(float)a0)/div + 0.5);
|
|
261 }
|
|
262
|
|
263
|
10725
|
264 /*
|
|
265 version for bs_freq_scale > 0
|
|
266 */
|
10989
|
267 void master_frequency_table(sbr_info *sbr, uint8_t k0, uint8_t k2,
|
10725
|
268 uint8_t bs_freq_scale, uint8_t bs_alter_scale)
|
|
269 {
|
|
270 uint8_t k, bands, twoRegions;
|
10989
|
271 uint8_t k1;
|
10725
|
272 uint32_t nrBand0, nrBand1;
|
|
273 int32_t vDk0[64], vDk1[64];
|
|
274 int32_t vk0[64], vk1[64];
|
10989
|
275 uint8_t temp1[] = { 6, 5, 4 };
|
10725
|
276
|
10989
|
277 /* without memset code enters infinite loop,
|
10725
|
278 so there must be some wrong table access */
|
|
279 memset(vDk0, 0, 64*sizeof(int32_t));
|
|
280 memset(vDk1, 0, 64*sizeof(int32_t));
|
|
281 memset(vk0, 0, 64*sizeof(int32_t));
|
|
282 memset(vk1, 0, 64*sizeof(int32_t));
|
|
283
|
|
284 /* mft only defined for k2 > k0 */
|
|
285 if (k2 <= k0)
|
|
286 {
|
|
287 sbr->N_master = 0;
|
|
288 return;
|
|
289 }
|
|
290
|
|
291 bands = temp1[bs_freq_scale-1];
|
|
292
|
|
293 if ((float)k2/(float)k0 > 2.2449)
|
|
294 {
|
|
295 twoRegions = 1;
|
10989
|
296 k1 = k0 << 1;
|
10725
|
297 } else {
|
|
298 twoRegions = 0;
|
|
299 k1 = k2;
|
|
300 }
|
|
301
|
10989
|
302 nrBand0 = 2 * find_bands(0, bands, k0, k1);
|
|
303 nrBand0 = min(nrBand0, 63);
|
|
304
|
10725
|
305 for (k = 0; k <= nrBand0; k++)
|
|
306 {
|
10989
|
307 /* diverging power series */
|
10725
|
308 vDk0[k] = (int32_t)(k0 * pow((float)k1/(float)k0, (k+1)/(float)nrBand0)+0.5) -
|
|
309 (int32_t)(k0 * pow((float)k1/(float)k0, k/(float)nrBand0)+0.5);
|
|
310 }
|
|
311
|
|
312 /* needed? */
|
|
313 qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
|
|
314
|
|
315 vk0[0] = k0;
|
|
316 for (k = 1; k <= nrBand0; k++)
|
|
317 {
|
|
318 vk0[k] = vk0[k-1] + vDk0[k-1];
|
|
319 }
|
|
320
|
|
321 if (!twoRegions)
|
|
322 {
|
|
323 for (k = 0; k <= nrBand0; k++)
|
|
324 sbr->f_master[k] = vk0[k];
|
|
325
|
|
326 sbr->N_master = nrBand0;
|
|
327 sbr->N_master = min(sbr->N_master, 64);
|
|
328 return;
|
|
329 }
|
|
330
|
10989
|
331 nrBand1 = 2 * find_bands(1 /* warped */, bands, k1, k2);
|
|
332 nrBand1 = min(nrBand1, 63);
|
10725
|
333
|
|
334 for (k = 0; k <= nrBand1 - 1; k++)
|
|
335 {
|
|
336 vDk1[k] = (int32_t)(k1 * pow((float)k2/(float)k1, (k+1)/(float)nrBand1)+0.5) -
|
|
337 (int32_t)(k1 * pow((float)k2/(float)k1, k/(float)nrBand1)+0.5);
|
|
338 }
|
|
339
|
|
340 if (vDk1[0] < vDk0[nrBand0 - 1])
|
|
341 {
|
|
342 int32_t change;
|
|
343
|
|
344 /* needed? */
|
|
345 qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
|
|
346 change = vDk0[nrBand0 - 1] - vDk1[0];
|
|
347 vDk1[0] = vDk0[nrBand0 - 1];
|
|
348 vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change;
|
|
349 }
|
|
350
|
|
351 /* needed? */
|
|
352 qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
|
|
353 vk1[0] = k1;
|
|
354 for (k = 1; k <= nrBand1; k++)
|
|
355 {
|
|
356 vk1[k] = vk1[k-1] + vDk1[k-1];
|
|
357 }
|
|
358
|
|
359 sbr->N_master = nrBand0 + nrBand1;
|
|
360 sbr->N_master = min(sbr->N_master, 64);
|
|
361 for (k = 0; k <= nrBand0; k++)
|
|
362 {
|
|
363 sbr->f_master[k] = vk0[k];
|
|
364 }
|
|
365 for (k = nrBand0 + 1; k <= sbr->N_master; k++)
|
|
366 {
|
|
367 sbr->f_master[k] = vk1[k - nrBand0];
|
|
368 }
|
|
369
|
|
370 #if 0
|
|
371 printf("f_master[%d]: ", sbr->N_master);
|
|
372 for (k = 0; k <= sbr->N_master; k++)
|
|
373 {
|
|
374 printf("%d ", sbr->f_master[k]);
|
|
375 }
|
|
376 printf("\n");
|
|
377 #endif
|
|
378 }
|
|
379
|
|
380 /* calculate the derived frequency border tables from f_master */
|
10989
|
381 uint8_t derived_frequency_table(sbr_info *sbr, uint8_t bs_xover_band,
|
|
382 uint8_t k2)
|
10725
|
383 {
|
|
384 uint8_t k, i;
|
|
385 uint32_t minus;
|
|
386
|
10989
|
387 /* The following relation shall be satisfied: bs_xover_band < N_Master */
|
|
388 if (sbr->N_master <= bs_xover_band)
|
|
389 return 1;
|
10725
|
390
|
10989
|
391 sbr->N_high = sbr->N_master - bs_xover_band;
|
|
392 sbr->N_low = (sbr->N_high>>1) + (sbr->N_high - ((sbr->N_high>>1)<<1));
|
10725
|
393
|
|
394 sbr->n[0] = sbr->N_low;
|
|
395 sbr->n[1] = sbr->N_high;
|
|
396
|
|
397 for (k = 0; k <= sbr->N_high; k++)
|
|
398 {
|
|
399 sbr->f_table_res[HI_RES][k] = sbr->f_master[k + bs_xover_band];
|
|
400 }
|
|
401
|
|
402 sbr->M = sbr->f_table_res[HI_RES][sbr->N_high] - sbr->f_table_res[HI_RES][0];
|
|
403 sbr->kx = sbr->f_table_res[HI_RES][0];
|
|
404
|
|
405 minus = (sbr->N_high & 1) ? 1 : 0;
|
|
406
|
|
407 for (k = 0; k <= sbr->N_low; k++)
|
|
408 {
|
|
409 if (k == 0)
|
|
410 i = 0;
|
|
411 else
|
|
412 i = 2*k - minus;
|
|
413 sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i];
|
|
414 }
|
|
415
|
|
416 #if 0
|
|
417 printf("f_table_res[HI_RES][%d]: ", sbr->N_high);
|
|
418 for (k = 0; k <= sbr->N_high; k++)
|
|
419 {
|
|
420 printf("%d ", sbr->f_table_res[HI_RES][k]);
|
|
421 }
|
|
422 printf("\n");
|
|
423 #endif
|
|
424 #if 0
|
|
425 printf("f_table_res[LO_RES][%d]: ", sbr->N_low);
|
|
426 for (k = 0; k <= sbr->N_low; k++)
|
|
427 {
|
|
428 printf("%d ", sbr->f_table_res[LO_RES][k]);
|
|
429 }
|
|
430 printf("\n");
|
|
431 #endif
|
|
432
|
|
433 sbr->N_Q = 0;
|
|
434 if (sbr->bs_noise_bands == 0)
|
|
435 {
|
|
436 sbr->N_Q = 1;
|
|
437 } else {
|
10989
|
438 #if 0
|
10725
|
439 sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5));
|
10989
|
440 #else
|
|
441 sbr->N_Q = max(1, find_bands(0, sbr->bs_noise_bands, sbr->kx, k2));
|
|
442 #endif
|
|
443 sbr->N_Q = min(5, sbr->N_Q);
|
10725
|
444 }
|
|
445
|
|
446 for (k = 0; k <= sbr->N_Q; k++)
|
|
447 {
|
|
448 if (k == 0)
|
10989
|
449 {
|
10725
|
450 i = 0;
|
10989
|
451 } else { /* is this accurate? */
|
|
452 //i = i + (int32_t)((sbr->N_low - i)/(sbr->N_Q + 1 - k));
|
|
453 i = i + (sbr->N_low - i)/(sbr->N_Q + 1 - k);
|
|
454 }
|
10725
|
455 sbr->f_table_noise[k] = sbr->f_table_res[LO_RES][i];
|
|
456 }
|
|
457
|
|
458 /* build table for mapping k to g in hf patching */
|
|
459 for (k = 0; k < 64; k++)
|
|
460 {
|
|
461 uint8_t g;
|
|
462 for (g = 0; g < sbr->N_Q; g++)
|
|
463 {
|
|
464 if ((sbr->f_table_noise[g] <= k) &&
|
|
465 (k < sbr->f_table_noise[g+1]))
|
|
466 {
|
|
467 sbr->table_map_k_to_g[k] = g;
|
|
468 break;
|
|
469 }
|
|
470 }
|
|
471 }
|
|
472
|
|
473 #if 0
|
|
474 printf("f_table_noise[%d]: ", sbr->N_Q);
|
|
475 for (k = 0; k <= sbr->N_Q; k++)
|
|
476 {
|
|
477 printf("%d ", sbr->f_table_noise[k]);
|
|
478 }
|
|
479 printf("\n");
|
|
480 #endif
|
10989
|
481
|
|
482 return 0;
|
10725
|
483 }
|
|
484
|
|
485 /* TODO: blegh, ugly */
|
|
486 /* Modified to calculate for all possible bs_limiter_bands always
|
|
487 * This reduces the number calls to this functions needed (now only on
|
|
488 * header reset)
|
|
489 */
|
|
490 void limiter_frequency_table(sbr_info *sbr)
|
|
491 {
|
10989
|
492 #if 0
|
|
493 static const real_t limiterBandsPerOctave[] = { REAL_CONST(1.2),
|
10725
|
494 REAL_CONST(2), REAL_CONST(3) };
|
10989
|
495 #else
|
|
496 static const real_t limiterBandsCompare[] = { REAL_CONST(1.328125),
|
|
497 REAL_CONST(1.1875), REAL_CONST(1.125) };
|
|
498 #endif
|
10725
|
499 uint8_t k, s;
|
|
500 int8_t nrLim;
|
|
501 int32_t limTable[100 /*TODO*/];
|
|
502 uint8_t patchBorders[64/*??*/];
|
10989
|
503 #if 0
|
10725
|
504 real_t limBands;
|
10989
|
505 #endif
|
10725
|
506
|
|
507 sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx;
|
|
508 sbr->f_table_lim[0][1] = sbr->f_table_res[LO_RES][sbr->N_low] - sbr->kx;
|
|
509 sbr->N_L[0] = 1;
|
|
510
|
|
511 for (s = 1; s < 4; s++)
|
|
512 {
|
|
513 memset(limTable, 0, 100*sizeof(int32_t));
|
|
514
|
10989
|
515 #if 0
|
10725
|
516 limBands = limiterBandsPerOctave[s - 1];
|
10989
|
517 #endif
|
10725
|
518
|
|
519 patchBorders[0] = sbr->kx;
|
|
520 for (k = 1; k <= sbr->noPatches; k++)
|
|
521 {
|
|
522 patchBorders[k] = patchBorders[k-1] + sbr->patchNoSubbands[k-1];
|
|
523 }
|
|
524
|
|
525 for (k = 0; k <= sbr->N_low; k++)
|
|
526 {
|
|
527 limTable[k] = sbr->f_table_res[LO_RES][k];
|
|
528 }
|
|
529 for (k = 1; k < sbr->noPatches; k++)
|
|
530 {
|
|
531 limTable[k+sbr->N_low] = patchBorders[k];
|
|
532 }
|
|
533
|
|
534 /* needed */
|
|
535 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
|
|
536 k = 1;
|
|
537 nrLim = sbr->noPatches + sbr->N_low - 1;
|
|
538
|
|
539 if (nrLim < 0) // TODO: BIG FAT PROBLEM
|
|
540 return;
|
|
541
|
|
542 restart:
|
|
543 if (k <= nrLim)
|
|
544 {
|
|
545 real_t nOctaves;
|
|
546
|
|
547 if (limTable[k-1] != 0)
|
10989
|
548 #if 0
|
10725
|
549 nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0));
|
10989
|
550 #endif
|
|
551 nOctaves = (real_t)limTable[k]/(real_t)limTable[k-1];
|
10725
|
552 else
|
|
553 nOctaves = 0;
|
|
554
|
10989
|
555 #if 0
|
10725
|
556 if ((MUL(nOctaves,limBands)) < REAL_CONST(0.49))
|
10989
|
557 #else
|
|
558 if (nOctaves < limiterBandsCompare[s - 1])
|
|
559 #endif
|
10725
|
560 {
|
|
561 uint8_t i;
|
|
562 if (limTable[k] != limTable[k-1])
|
|
563 {
|
|
564 uint8_t found = 0, found2 = 0;
|
|
565 for (i = 0; i <= sbr->noPatches; i++)
|
|
566 {
|
|
567 if (limTable[k] == patchBorders[i])
|
|
568 found = 1;
|
|
569 }
|
|
570 if (found)
|
|
571 {
|
|
572 found2 = 0;
|
|
573 for (i = 0; i <= sbr->noPatches; i++)
|
|
574 {
|
|
575 if (limTable[k-1] == patchBorders[i])
|
|
576 found2 = 1;
|
|
577 }
|
|
578 if (found2)
|
|
579 {
|
|
580 k++;
|
|
581 goto restart;
|
|
582 } else {
|
|
583 /* remove (k-1)th element */
|
|
584 limTable[k-1] = sbr->f_table_res[LO_RES][sbr->N_low];
|
|
585 qsort(limTable, sbr->noPatches + sbr->N_low, sizeof(limTable[0]), longcmp);
|
|
586 nrLim--;
|
|
587 goto restart;
|
|
588 }
|
|
589 }
|
|
590 }
|
|
591 /* remove kth element */
|
|
592 limTable[k] = sbr->f_table_res[LO_RES][sbr->N_low];
|
|
593 qsort(limTable, nrLim, sizeof(limTable[0]), longcmp);
|
|
594 nrLim--;
|
|
595 goto restart;
|
|
596 } else {
|
|
597 k++;
|
|
598 goto restart;
|
|
599 }
|
|
600 }
|
|
601
|
|
602 sbr->N_L[s] = nrLim;
|
|
603 for (k = 0; k <= nrLim; k++)
|
|
604 {
|
|
605 sbr->f_table_lim[s][k] = limTable[k] - sbr->kx;
|
|
606 }
|
|
607
|
|
608 #if 0
|
|
609 printf("f_table_lim[%d][%d]: ", s, sbr->N_L[s]);
|
|
610 for (k = 0; k <= sbr->N_L[s]; k++)
|
|
611 {
|
|
612 printf("%d ", sbr->f_table_lim[s][k]);
|
|
613 }
|
|
614 printf("\n");
|
|
615 #endif
|
|
616 }
|
|
617 }
|
|
618
|
|
619 #endif
|