Mercurial > audlegacy
comparison Plugins/Input/aac/libfaad2/sbr_fbt.c @ 1021:1e6c0a3f2d15 trunk
[svn] - 2.1 beta
author | nenolod |
---|---|
date | Wed, 10 May 2006 14:44:20 -0700 |
parents | 29feaace84d0 |
children | f12d7e208b43 |
comparison
equal
deleted
inserted
replaced
1020:d70514b3b436 | 1021:1e6c0a3f2d15 |
---|---|
20 ** forbidden. | 20 ** forbidden. |
21 ** | 21 ** |
22 ** Commercial non-GPL licensing of this software is possible. | 22 ** Commercial non-GPL licensing of this software is possible. |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. |
24 ** | 24 ** |
25 ** $Id: sbr_fbt.c,v 1.10 2004/01/16 20:20:32 menno Exp $ | 25 ** $Id: sbr_fbt.c,v 1.17 2004/09/08 09:43:11 gcp Exp $ |
26 **/ | 26 **/ |
27 | 27 |
28 /* Calculate frequency band tables */ | 28 /* Calculate frequency band tables */ |
29 | 29 |
30 #include "common.h" | 30 #include "common.h" |
195 | 195 |
196 /* mft only defined for k2 > k0 */ | 196 /* mft only defined for k2 > k0 */ |
197 if (k2 <= k0) | 197 if (k2 <= k0) |
198 { | 198 { |
199 sbr->N_master = 0; | 199 sbr->N_master = 0; |
200 return 0; | 200 return 1; |
201 } | 201 } |
202 | 202 |
203 dk = bs_alter_scale ? 2 : 1; | 203 dk = bs_alter_scale ? 2 : 1; |
204 | 204 |
205 #if 0 /* replaced by float-less design */ | 205 #if 0 /* replaced by float-less design */ |
222 vDk[k] = dk; | 222 vDk[k] = dk; |
223 | 223 |
224 if (k2Diff) | 224 if (k2Diff) |
225 { | 225 { |
226 incr = (k2Diff > 0) ? -1 : 1; | 226 incr = (k2Diff > 0) ? -1 : 1; |
227 k = (k2Diff > 0) ? (nrBands-1) : 0; | 227 k = (uint8_t) ((k2Diff > 0) ? (nrBands-1) : 0); |
228 | 228 |
229 while (k2Diff != 0) | 229 while (k2Diff != 0) |
230 { | 230 { |
231 vDk[k] -= incr; | 231 vDk[k] -= incr; |
232 k += incr; | 232 k += incr; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 sbr->f_master[0] = k0; | 237 sbr->f_master[0] = k0; |
238 for (k = 1; k <= nrBands; k++) | 238 for (k = 1; k <= nrBands; k++) |
239 sbr->f_master[k] = sbr->f_master[k-1] + vDk[k-1]; | 239 sbr->f_master[k] = (uint8_t)(sbr->f_master[k-1] + vDk[k-1]); |
240 | 240 |
241 sbr->N_master = nrBands; | 241 sbr->N_master = (uint8_t)nrBands; |
242 sbr->N_master = min(sbr->N_master, 64); | 242 sbr->N_master = (min(sbr->N_master, 64)); |
243 | 243 |
244 #if 0 | 244 #if 0 |
245 printf("f_master[%d]: ", nrBands); | 245 printf("f_master[%d]: ", nrBands); |
246 for (k = 0; k <= nrBands; k++) | 246 for (k = 0; k <= nrBands; k++) |
247 { | 247 { |
353 int32_t vDk0[64] = {0}, vDk1[64] = {0}; | 353 int32_t vDk0[64] = {0}, vDk1[64] = {0}; |
354 int32_t vk0[64] = {0}, vk1[64] = {0}; | 354 int32_t vk0[64] = {0}, vk1[64] = {0}; |
355 uint8_t temp1[] = { 6, 5, 4 }; | 355 uint8_t temp1[] = { 6, 5, 4 }; |
356 real_t q, qk; | 356 real_t q, qk; |
357 int32_t A_1; | 357 int32_t A_1; |
358 #ifdef FIXED_POINT | |
359 real_t rk2, rk0; | |
360 #endif | |
358 | 361 |
359 /* mft only defined for k2 > k0 */ | 362 /* mft only defined for k2 > k0 */ |
360 if (k2 <= k0) | 363 if (k2 <= k0) |
361 { | 364 { |
362 sbr->N_master = 0; | 365 sbr->N_master = 0; |
363 return 0; | 366 return 1; |
364 } | 367 } |
365 | 368 |
366 bands = temp1[bs_freq_scale-1]; | 369 bands = temp1[bs_freq_scale-1]; |
367 | 370 |
368 #ifdef FIXED_POINT | 371 #ifdef FIXED_POINT |
369 if (REAL_CONST(k2) > MUL_R(REAL_CONST(k0),REAL_CONST(2.2449))) | 372 rk0 = (real_t)k0 << REAL_BITS; |
373 rk2 = (real_t)k2 << REAL_BITS; | |
374 if (rk2 > MUL_C(rk0, COEF_CONST(2.2449))) | |
370 #else | 375 #else |
371 if ((float)k2/(float)k0 > 2.2449) | 376 if ((float)k2/(float)k0 > 2.2449) |
372 #endif | 377 #endif |
373 { | 378 { |
374 twoRegions = 1; | 379 twoRegions = 1; |
376 } else { | 381 } else { |
377 twoRegions = 0; | 382 twoRegions = 0; |
378 k1 = k2; | 383 k1 = k2; |
379 } | 384 } |
380 | 385 |
381 nrBand0 = 2 * find_bands(0, bands, k0, k1); | 386 nrBand0 = (uint8_t)(2 * find_bands(0, bands, k0, k1)); |
382 nrBand0 = min(nrBand0, 63); | 387 nrBand0 = min(nrBand0, 63); |
383 if (nrBand0 <= 0) | 388 if (nrBand0 <= 0) |
384 return 1; | 389 return 1; |
385 | 390 |
386 q = find_initial_power(nrBand0, k0, k1); | 391 q = find_initial_power(nrBand0, k0, k1); |
392 #ifdef FIXED_POINT | |
393 qk = (real_t)k0 << REAL_BITS; | |
394 //A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS); | |
395 A_1 = k0; | |
396 #else | |
387 qk = REAL_CONST(k0); | 397 qk = REAL_CONST(k0); |
388 #ifdef FIXED_POINT | |
389 A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS); | |
390 #else | |
391 A_1 = (int32_t)(qk + .5); | 398 A_1 = (int32_t)(qk + .5); |
392 #endif | 399 #endif |
393 for (k = 0; k <= nrBand0; k++) | 400 for (k = 0; k <= nrBand0; k++) |
394 { | 401 { |
395 int32_t A_0 = A_1; | 402 int32_t A_0 = A_1; |
415 } | 422 } |
416 | 423 |
417 if (!twoRegions) | 424 if (!twoRegions) |
418 { | 425 { |
419 for (k = 0; k <= nrBand0; k++) | 426 for (k = 0; k <= nrBand0; k++) |
420 sbr->f_master[k] = vk0[k]; | 427 sbr->f_master[k] = (uint8_t) vk0[k]; |
421 | 428 |
422 sbr->N_master = nrBand0; | 429 sbr->N_master = nrBand0; |
423 sbr->N_master = min(sbr->N_master, 64); | 430 sbr->N_master = min(sbr->N_master, 64); |
424 return 0; | 431 return 0; |
425 } | 432 } |
426 | 433 |
427 nrBand1 = 2 * find_bands(1 /* warped */, bands, k1, k2); | 434 nrBand1 = (uint8_t)(2 * find_bands(1 /* warped */, bands, k1, k2)); |
428 nrBand1 = min(nrBand1, 63); | 435 nrBand1 = min(nrBand1, 63); |
429 | 436 |
430 q = find_initial_power(nrBand1, k1, k2); | 437 q = find_initial_power(nrBand1, k1, k2); |
438 #ifdef FIXED_POINT | |
439 qk = (real_t)k1 << REAL_BITS; | |
440 //A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS); | |
441 A_1 = k1; | |
442 #else | |
431 qk = REAL_CONST(k1); | 443 qk = REAL_CONST(k1); |
432 #ifdef FIXED_POINT | |
433 A_1 = (int32_t)((qk + REAL_CONST(0.5)) >> REAL_BITS); | |
434 #else | |
435 A_1 = (int32_t)(qk + .5); | 444 A_1 = (int32_t)(qk + .5); |
436 #endif | 445 #endif |
437 for (k = 0; k <= nrBand1 - 1; k++) | 446 for (k = 0; k <= nrBand1 - 1; k++) |
438 { | 447 { |
439 int32_t A_0 = A_1; | 448 int32_t A_0 = A_1; |
470 | 479 |
471 sbr->N_master = nrBand0 + nrBand1; | 480 sbr->N_master = nrBand0 + nrBand1; |
472 sbr->N_master = min(sbr->N_master, 64); | 481 sbr->N_master = min(sbr->N_master, 64); |
473 for (k = 0; k <= nrBand0; k++) | 482 for (k = 0; k <= nrBand0; k++) |
474 { | 483 { |
475 sbr->f_master[k] = vk0[k]; | 484 sbr->f_master[k] = (uint8_t) vk0[k]; |
476 } | 485 } |
477 for (k = nrBand0 + 1; k <= sbr->N_master; k++) | 486 for (k = nrBand0 + 1; k <= sbr->N_master; k++) |
478 { | 487 { |
479 sbr->f_master[k] = vk1[k - nrBand0]; | 488 sbr->f_master[k] = (uint8_t) vk1[k - nrBand0]; |
480 } | 489 } |
481 | 490 |
482 #if 0 | 491 #if 0 |
483 printf("f_master[%d]: ", sbr->N_master); | 492 printf("f_master[%d]: ", sbr->N_master); |
484 for (k = 0; k <= sbr->N_master; k++) | 493 for (k = 0; k <= sbr->N_master; k++) |
525 for (k = 0; k <= sbr->N_low; k++) | 534 for (k = 0; k <= sbr->N_low; k++) |
526 { | 535 { |
527 if (k == 0) | 536 if (k == 0) |
528 i = 0; | 537 i = 0; |
529 else | 538 else |
530 i = 2*k - minus; | 539 i = (uint8_t)(2*k - minus); |
531 sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i]; | 540 sbr->f_table_res[LO_RES][k] = sbr->f_table_res[HI_RES][i]; |
532 } | 541 } |
533 | 542 |
534 #if 0 | 543 #if 0 |
544 printf("bs_freq_scale: %d\n", sbr->bs_freq_scale); | |
545 printf("bs_limiter_bands: %d\n", sbr->bs_limiter_bands); | |
535 printf("f_table_res[HI_RES][%d]: ", sbr->N_high); | 546 printf("f_table_res[HI_RES][%d]: ", sbr->N_high); |
536 for (k = 0; k <= sbr->N_high; k++) | 547 for (k = 0; k <= sbr->N_high; k++) |
537 { | 548 { |
538 printf("%d ", sbr->f_table_res[HI_RES][k]); | 549 printf("%d ", sbr->f_table_res[HI_RES][k]); |
539 } | 550 } |
554 sbr->N_Q = 1; | 565 sbr->N_Q = 1; |
555 } else { | 566 } else { |
556 #if 0 | 567 #if 0 |
557 sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5)); | 568 sbr->N_Q = max(1, (int32_t)(sbr->bs_noise_bands*(log(k2/(float)sbr->kx)/log(2.0)) + 0.5)); |
558 #else | 569 #else |
559 sbr->N_Q = max(1, find_bands(0, sbr->bs_noise_bands, sbr->kx, k2)); | 570 sbr->N_Q = (uint8_t)(max(1, find_bands(0, sbr->bs_noise_bands, sbr->kx, k2))); |
560 #endif | 571 #endif |
561 sbr->N_Q = min(5, sbr->N_Q); | 572 sbr->N_Q = min(5, sbr->N_Q); |
562 } | 573 } |
563 | 574 |
564 for (k = 0; k <= sbr->N_Q; k++) | 575 for (k = 0; k <= sbr->N_Q; k++) |
590 | 601 |
591 #if 0 | 602 #if 0 |
592 printf("f_table_noise[%d]: ", sbr->N_Q); | 603 printf("f_table_noise[%d]: ", sbr->N_Q); |
593 for (k = 0; k <= sbr->N_Q; k++) | 604 for (k = 0; k <= sbr->N_Q; k++) |
594 { | 605 { |
595 printf("%d ", sbr->f_table_noise[k]); | 606 printf("%d ", sbr->f_table_noise[k] - sbr->kx); |
596 } | 607 } |
597 printf("\n"); | 608 printf("\n"); |
598 #endif | 609 #endif |
599 | 610 |
600 return 0; | 611 return 0; |
609 { | 620 { |
610 #if 0 | 621 #if 0 |
611 static const real_t limiterBandsPerOctave[] = { REAL_CONST(1.2), | 622 static const real_t limiterBandsPerOctave[] = { REAL_CONST(1.2), |
612 REAL_CONST(2), REAL_CONST(3) }; | 623 REAL_CONST(2), REAL_CONST(3) }; |
613 #else | 624 #else |
614 static const real_t limiterBandsCompare[] = { REAL_CONST(1.328125), | 625 static const real_t limiterBandsCompare[] = { REAL_CONST(1.327152), |
615 REAL_CONST(1.1875), REAL_CONST(1.125) }; | 626 REAL_CONST(1.185093), REAL_CONST(1.119872) }; |
616 #endif | 627 #endif |
617 uint8_t k, s; | 628 uint8_t k, s; |
618 int8_t nrLim; | 629 int8_t nrLim; |
619 #if 0 | 630 #if 0 |
620 real_t limBands; | 631 real_t limBands; |
621 #endif | 632 #endif |
622 | 633 |
623 sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx; | 634 sbr->f_table_lim[0][0] = sbr->f_table_res[LO_RES][0] - sbr->kx; |
624 sbr->f_table_lim[0][1] = sbr->f_table_res[LO_RES][sbr->N_low] - sbr->kx; | 635 sbr->f_table_lim[0][1] = sbr->f_table_res[LO_RES][sbr->N_low] - sbr->kx; |
625 sbr->N_L[0] = 1; | 636 sbr->N_L[0] = 1; |
637 | |
638 #if 0 | |
639 printf("f_table_lim[%d][%d]: ", 0, sbr->N_L[0]); | |
640 for (k = 0; k <= sbr->N_L[0]; k++) | |
641 { | |
642 printf("%d ", sbr->f_table_lim[0][k]); | |
643 } | |
644 printf("\n"); | |
645 #endif | |
626 | 646 |
627 for (s = 1; s < 4; s++) | 647 for (s = 1; s < 4; s++) |
628 { | 648 { |
629 int32_t limTable[100 /*TODO*/] = {0}; | 649 int32_t limTable[100 /*TODO*/] = {0}; |
630 uint8_t patchBorders[64/*??*/] = {0}; | 650 uint8_t patchBorders[64/*??*/] = {0}; |
662 real_t nOctaves; | 682 real_t nOctaves; |
663 | 683 |
664 if (limTable[k-1] != 0) | 684 if (limTable[k-1] != 0) |
665 #if 0 | 685 #if 0 |
666 nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0)); | 686 nOctaves = REAL_CONST(log((float)limTable[k]/(float)limTable[k-1])/log(2.0)); |
667 #endif | 687 #else |
668 #ifdef FIXED_POINT | 688 #ifdef FIXED_POINT |
669 nOctaves = SBR_DIV(REAL_CONST(limTable[k]),REAL_CONST(limTable[k-1])); | 689 nOctaves = DIV_R((limTable[k]<<REAL_BITS),REAL_CONST(limTable[k-1])); |
670 #else | 690 #else |
671 nOctaves = (real_t)limTable[k]/(real_t)limTable[k-1]; | 691 nOctaves = (real_t)limTable[k]/(real_t)limTable[k-1]; |
692 #endif | |
672 #endif | 693 #endif |
673 else | 694 else |
674 nOctaves = 0; | 695 nOctaves = 0; |
675 | 696 |
676 #if 0 | 697 #if 0 |
677 if ((MUL(nOctaves,limBands)) < REAL_CONST(0.49)) | 698 if ((MUL_R(nOctaves,limBands)) < REAL_CONST(0.49)) |
678 #else | 699 #else |
679 if (nOctaves < limiterBandsCompare[s - 1]) | 700 if (nOctaves < limiterBandsCompare[s - 1]) |
680 #endif | 701 #endif |
681 { | 702 { |
682 uint8_t i; | 703 uint8_t i; |