diff options
author | Guenter Bartsch <guenter@users.sourceforge.net> | 2001-07-10 21:50:31 +0000 |
---|---|---|
committer | Guenter Bartsch <guenter@users.sourceforge.net> | 2001-07-10 21:50:31 +0000 |
commit | d8b2a2e6ab69169bab5ca40b69bfa5dac893bd0e (patch) | |
tree | 6d2879e005ef8db84801c81e52450ee8736c6454 /src/libac3/bit_allocate.c | |
parent | 4cc9fd313df701f722a81ad4bb551155415ce5cc (diff) | |
download | xine-lib-d8b2a2e6ab69169bab5ca40b69bfa5dac893bd0e.tar.gz xine-lib-d8b2a2e6ab69169bab5ca40b69bfa5dac893bd0e.tar.bz2 |
latest libac3 from walken
CVS patchset: 265
CVS date: 2001/07/10 21:50:31
Diffstat (limited to 'src/libac3/bit_allocate.c')
-rw-r--r-- | src/libac3/bit_allocate.c | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/src/libac3/bit_allocate.c b/src/libac3/bit_allocate.c index 17f35b159..307c0074c 100644 --- a/src/libac3/bit_allocate.c +++ b/src/libac3/bit_allocate.c @@ -21,11 +21,11 @@ * */ +#include <inttypes.h> #include <stdlib.h> #include <string.h> #include "ac3.h" #include "ac3_internal.h" -#include "bit_allocate.h" static int hthtab[3][50] = { {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860, @@ -46,17 +46,17 @@ static int hthtab[3][50] = { }; static int8_t baptab[305] = { - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 93 padding entries - - 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, - 14, 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, - 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, - 6, 5, 5, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 0, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // 93 padding entries + + 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14, + 14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, + 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, + 5, 4, 4, -3, -3, 3, 3, 3, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -113,18 +113,16 @@ do { \ do { \ if (psd > dbknee) \ mask -= (psd - dbknee) >> 2; \ - if (mask > hth[i]) \ - mask = hth[i]; \ - if (deltba != NULL) \ - mask -= 128 * deltba[i]; \ - mask -= snroffset; \ + if (mask > hth [i >> halfrate]) \ + mask = hth [i >> halfrate]; \ + mask -= snroffset + 128 * deltba[i]; \ mask = (mask > 0) ? 0 : ((-mask) >> 5); \ mask -= floor; \ } while (0) -void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, - int bndstart, int start, int end, int fastleak, int slowleak, - uint8_t * exp, int8_t * bap) +void bit_allocate (ac3_state_t * state, ac3_ba_t * ba, int bndstart, + int start, int end, int fastleak, int slowleak, + uint8_t * exp, int8_t * bap) { static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410}; static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100}; @@ -136,16 +134,22 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, int psd, mask; int8_t * deltba; int * hth; + int halfrate; - fdecay = 63 + 20 * audblk->fdcycod; + halfrate = state->halfrate; + fdecay = (63 + 20 * state->fdcycod) >> halfrate; fgain = 128 + 128 * ba->fgaincod; - sdecay = 15 + 2 * audblk->sdcycod; - sgain = slowgain[audblk->sgaincod]; - dbknee = dbpbtab[audblk->dbpbcod]; - hth = hthtab[fscod]; - deltba = (ba->deltbae == DELTA_BIT_NONE) ? NULL : ba->deltba; - floor = floortab[audblk->floorcod]; - snroffset = 960 - 64 * audblk->csnroffst - 4 * ba->fsnroffst + floor; + sdecay = (15 + 2 * state->sdcycod) >> halfrate; + sgain = slowgain[state->sgaincod]; + dbknee = dbpbtab[state->dbpbcod]; + hth = hthtab[state->fscod]; + /* + * if there is no delta bit allocation, make deltba point to an area + * known to contain zeroes. baptab+156 here. + */ + deltba = (ba->deltbae == DELTA_BIT_NONE) ? baptab + 156 : ba->deltba; + floor = floortab[state->floorcod]; + snroffset = 960 - 64 * state->csnroffst - 4 * ba->fsnroffst + floor; floor >>= 5; i = bndstart; @@ -165,8 +169,7 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, psd = 128 * exp[i]; mask = psd + fgain + lowcomp; COMPUTE_MASK (); - bap[i] = (baptab+156)[mask + 4 * exp[i]]; - i++; + bap[i++] = (baptab+156)[mask + 4 * exp[i]]; } while ((i < 3) || ((i < 7) && (exp[i] > exp[i-1]))); fastleak = psd + fgain; slowleak = psd + sgain; @@ -183,8 +186,7 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, mask = ((fastleak + lowcomp < slowleak) ? fastleak + lowcomp : slowleak); COMPUTE_MASK (); - bap[i] = (baptab+156)[mask + 4 * exp[i]]; - i++; + bap[i++] = (baptab+156)[mask + 4 * exp[i]]; } if (end == 7) // lfe channel @@ -200,8 +202,7 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, mask = ((fastleak + lowcomp < slowleak) ? fastleak + lowcomp : slowleak); COMPUTE_MASK (); - bap[i] = (baptab+156)[mask + 4 * exp[i]]; - i++; + bap[i++] = (baptab+156)[mask + 4 * exp[i]]; } while (i < 20); while (lowcomp > 128) { // two iterations maximum @@ -211,8 +212,7 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, mask = ((fastleak + lowcomp < slowleak) ? fastleak + lowcomp : slowleak); COMPUTE_MASK (); - bap[i] = (baptab+156)[mask + 4 * exp[i]]; - i++; + bap[i++] = (baptab+156)[mask + 4 * exp[i]]; } j = i; } @@ -249,8 +249,7 @@ void bit_allocate(int fscod, audblk_t * audblk, ac3_ba_t * ba, do { // max(mask+4*exp)=147=-(minpsd+fgain-deltba-snroffset)>>5+4*exp // min(mask+4*exp)=-156=-(sgain-deltba-snroffset)>>5 - bap[j] = (baptab+156)[mask + 4 * exp[j]]; - j++; + bap[j++] = (baptab+156)[mask + 4 * exp[j]]; } while (j < endband); } while (j < end); } |