📄 ac3_dec_parse.c
字号:
GET_BITS(pBS, (audblk->phsflg[j]), 1, Ipp32s)
#else
if (audblk->cplbndstrc[j] == 0) {
GET_BITS(pBS, (audblk->phsflg[j]), 1, Ipp32s)
phsflg = audblk->phsflg[j];
}
if (phsflg) {
if (audblk->cplcoord[1][j] > 0) {
audblk->cplcoord[1][j] = -audblk->cplcoord[1][j];
}
} else {
if (audblk->cplcoord[1][j] < 0) {
audblk->cplcoord[1][j] = -audblk->cplcoord[1][j];
}
}
#endif
}
}
}
/* If we're in 2/0 (stereo) mode, there may be a rematrix strategy */
if (state->bsi.acmod == 0x2) {
GET_BITS(pBS, (audblk->rematstr), 1, Ipp32s)
//if ((nblk == 0) || (audblk->rematstr == 0)) {
// return 0;
//}
if (audblk->rematstr) {
if ((audblk->cplinu == 0) ||
((audblk->cplbegf > 2) && audblk->cplinu)) {
audblk->nrematbnds = 4;
} else if ((audblk->cplbegf == 0) && audblk->cplinu) {
audblk->nrematbnds = 2;
} else {
audblk->nrematbnds = 3;
}
GET_BITS(pBS, (audblk->rematflg), audblk->nrematbnds, Ipp32s)
}
}
audblk->cplexpstr = 0;
if (audblk->cplinu) {
/* Get the coupling channel exponent strategy */
GET_BITS(pBS, (audblk->cplexpstr), 2, Ipp32s)
if ((audblk->firstCplinu) && (audblk->cplexpstr == EXP_REUSE)) {
return 0;
}
if (((audblk->cplbegf != prevCplbegf) ||
(audblk->cplendf != prevCplendf)) &&
(audblk->cplexpstr == EXP_REUSE)) {
return 0;
}
audblk->ncplgrps = 0;
if (audblk->cplexpstr != EXP_REUSE) {
audblk->CplBitAllocation = 1;
audblk->ncplgrps = ((audblk->cplendmant - audblk->cplstrtmant) /
(3 << (audblk->cplexpstr - 1)));
}
}
for (i = 0; i < state->bsi.nfchans; i++) {
GET_BITS(pBS, (audblk->chexpstr[i]), 2, Ipp32s)
if ((nblk == 0) && (audblk->chexpstr[i] == EXP_REUSE)) {
return 0;
}
if ((audblk->cplinu == 1) &&
(audblk->cplbegf != prevCplbegf) &&
(audblk->chincpl[i] == 1) &&
(audblk->chexpstr[i] == EXP_REUSE)) {
return 0;
}
}
/* Get the exponent strategy for lfe channel */
audblk->lfeexpstr = 0;
if (state->bsi.lfeon) {
GET_BITS(pBS, (audblk->lfeexpstr), 1, Ipp32s)
if ((nblk == 0) && (audblk->lfeexpstr == EXP_REUSE)) {
return 0;
}
}
/* Determine the bandwidths of all the fbw channels */
for (i = 0; i < state->bsi.nfchans; i++) {
Ipp32s grp_size;
if (audblk->chexpstr[i] != EXP_REUSE) {
audblk->bitAllocation[i] = 1;
if (audblk->cplinu && audblk->chincpl[i]) {
audblk->endmant[i] = audblk->cplstrtmant;
} else {
GET_BITS(pBS, (audblk->chbwcod[i]), 6, Ipp32s)
if (audblk->chbwcod[i] > 60)
audblk->chbwcod[i] = 60;
audblk->endmant[i] = (((audblk->chbwcod[i] + 12) * 3) + 37);
}
/* Calculate the number of exponent groups to fetch */
grp_size = (3 * (1 << (audblk->chexpstr[i] - 1)));
audblk->nchgrps[i] = ((audblk->endmant[i] - 1 + (grp_size - 3)) / grp_size);
}
}
/* Get the coupling exponents if they exist */
if (audblk->cplinu && (audblk->cplexpstr != EXP_REUSE)) {
GET_BITS(pBS, (audblk->cplabsexp), 4, Ipp32s)
for (i = 0; i < audblk->ncplgrps; i++) {
GET_BITS(pBS, (audblk->cplexps[i]), 7, Ipp32s)
}
}
/* Get the fwb channel exponents */
for (i = 0; i < state->bsi.nfchans; i++) {
if (audblk->chexpstr[i] != EXP_REUSE) {
GET_BITS(pBS, (audblk->exps[i][0]), 4, Ipp32s)
for (j = 1; j <= audblk->nchgrps[i]; j++) {
GET_BITS(pBS, (audblk->exps[i][j]), 7, Ipp32s)
}
GET_BITS(pBS, (audblk->gainrng[i]), 2, Ipp32s)
}
}
/* Get the lfe channel exponents */
if (state->bsi.lfeon && (audblk->lfeexpstr != EXP_REUSE)) {
audblk->LfeBitAllocation = 1;
GET_BITS(pBS, (audblk->lfeexps[0]), 4, Ipp32s)
GET_BITS(pBS, (audblk->lfeexps[1]), 7, Ipp32s)
GET_BITS(pBS, (audblk->lfeexps[2]), 7, Ipp32s)
}
/* Get the parametric bit allocation parameters */
GET_BITS(pBS, (audblk->baie), 1, Ipp32s)
if ((nblk == 0) && (audblk->baie == 0)) {
return 0;
}
if (audblk->baie) {
bitAlloc = 1;
GET_BITS(pBS, (audblk->sdcycod), 2, Ipp32s)
GET_BITS(pBS, (audblk->fdcycod), 2, Ipp32s)
GET_BITS(pBS, (audblk->sgaincod), 2, Ipp32s)
GET_BITS(pBS, (audblk->dbpbcod), 2, Ipp32s)
GET_BITS(pBS, (audblk->floorcod), 3, Ipp32s)
}
/* Get the SNR off set info if it exists */
GET_BITS(pBS, (audblk->snroffste), 1, Ipp32s)
if ((nblk == 0) && (audblk->snroffste == 0)) {
return 0;
}
if (audblk->snroffste) {
bitAlloc = 1;
GET_BITS(pBS, (audblk->csnroffst), 6, Ipp32s)
if (audblk->cplinu) {
GET_BITS(pBS, tmp, 7, Ipp32s)
audblk->cplfsnroffst = tmp >> 3;
audblk->cplfgaincod = tmp & 7;
}
for (i = 0; i < state->bsi.nfchans; i++) {
GET_BITS(pBS, tmp, 7, Ipp32s)
audblk->fsnroffst[i] = tmp >> 3;
audblk->fgaincod[i] = tmp & 7;
}
if (state->bsi.lfeon) {
GET_BITS(pBS, tmp, 7, Ipp32s)
audblk->lfefsnroffst = tmp >> 3;
audblk->lfefgaincod = tmp & 7;
}
}
/* Get coupling leakage info if it exists */
if (audblk->cplinu) {
GET_BITS(pBS, (audblk->cplleake), 1, Ipp32s)
if ((nblk == 0) && (audblk->cplleake == 0)) {
return 0;
}
if (audblk->cplleake) {
audblk->CplBitAllocation = 1;
GET_BITS(pBS, tmp, 6, Ipp32s)
audblk->cplfleak = tmp >> 3;
audblk->cplsleak = tmp & 7;
}
}
/* Get the delta bit alloaction info */
GET_BITS(pBS, (audblk->deltbaie), 1, Ipp32s)
if (audblk->deltbaie) {
bitAlloc = 1;
if (audblk->cplinu) {
GET_BITS(pBS, (audblk->cpldeltbae), 2, Ipp32s)
}
for (i = 0; i < state->bsi.nfchans; i++) {
GET_BITS(pBS, (audblk->deltbae[i]), 2, Ipp32s)
}
if (audblk->cplinu) {
if (audblk->cpldeltbae == 1) {
Ipp32s deltnseg, deltoffst, deltlen, deltba;
Ipp32s bin;
GET_BITS(pBS, deltnseg, 3, Ipp32s)
deltnseg += 1;
bin = 0;
audblk->cpldeltlastbin = -256;
for (j = 0; j < deltnseg; j++) {
GET_BITS(pBS, tmp, 12, Ipp32s)
deltoffst = tmp >> 7;
deltlen = (tmp >> 3) & 0xF;
deltba = tmp & 7;
while (deltoffst--) {
state->cpldeltba[bin] = 0;
bin++;
}
if ((bin + deltlen) > 50) {
return 0;
}
deltba -= (deltba >= 4) ? 3 : 4;
deltba <<= 7;
while (deltlen--) {
state->cpldeltba[bin] = deltba;
bin++;
audblk->cpldeltlastbin = bin;
}
}
for (; bin < 50; bin++) {
state->cpldeltba[bin] = 0;
}
} else if (audblk->cpldeltbae >= 2) {
Ipp32s bin;
for (bin = 0; bin < 50; bin++) {
state->cpldeltba[bin] = 0;
}
audblk->cpldeltlastbin = -256;
}
if ((audblk->cpldeltlastbin + MASKTAB[audblk->cplstrtmant]) > 50) {
return 0;
}
}
for (i = 0; i < state->bsi.nfchans; i++) {
if (audblk->deltbae[i] == 1) {
Ipp32s deltnseg, deltoffst, deltlen, deltba;
Ipp32s bin;
GET_BITS(pBS, deltnseg, 3, Ipp32s)
bin = 0;
for (j = 0; j <= deltnseg; j++) {
GET_BITS(pBS, tmp, 12, Ipp32s)
deltoffst = tmp >> 7;
deltlen = (tmp >> 3) & 0xF;
deltba = tmp & 7;
while (deltoffst--) {
state->deltba[i][bin] = 0;
bin++;
}
if ((bin + deltlen) > 50) {
return 0;
}
deltba -= (deltba >= 4) ? 3 : 4;
deltba <<= 7;
while (deltlen--) {
state->deltba[i][bin] = deltba;
bin++;
}
}
for (; bin < 50; bin++) {
state->deltba[i][bin] = 0;
}
} else if (audblk->deltbae[i] >= 2) {
Ipp32s bin;
for (bin = 0; bin < 50; bin++) {
state->deltba[i][bin] = 0;
}
}
}
}
/* Check to see if there's any dummy info to get */
GET_BITS(pBS, (audblk->skiple), 1, Ipp32s)
if (audblk->skiple) {
Ipp32s skip_data;
Ipp32s numReadedBits = 0;
Ipp32s numSkipBits;
Ipp32s tmp;
GET_BITS(pBS, (audblk->skipl), 9, Ipp32s)
if ((audblk->skipl > 0) && (audblk->cplinu)) {
GET_BITS(pBS, (tmp), 1, Ipp32s)
numReadedBits++;
if (tmp) {
GET_BITS(pBS, (audblk->phsoutmod), 3, Ipp32s)
GET_BITS(pBS, (tmp), 1, Ipp32s)
numReadedBits += 4;
if (tmp) {
for (j = 0; j < audblk->ncplbnd; j++) {
#ifdef REF_DECODER_COMPATIBLE
if (audblk->cplbndstrc[j] == 0) {
#endif
GET_BITS(pBS, (audblk->phscor[j]), 4, Ipp32s)
numReadedBits += 4;
#ifdef REF_DECODER_COMPATIBLE
} else {
audblk->phscor[j] = audblk->phscor[j - 1];
}
#endif
}
} else {
GET_BITS(pBS, (audblk->phscor[0]), 4, Ipp32s)
numReadedBits += 4;
for (j = 1; j < audblk->ncplbnd; j++) {
audblk->phscor[j] = audblk->phscor[0];
}
}
}
}
numSkipBits = audblk->skipl * 8 - numReadedBits;
for (i = 0; i < numSkipBits >> 3; i++) {
GET_BITS(pBS, (skip_data), 8, Ipp32s)
}
numSkipBits &= 7;
GET_BITS(pBS, (skip_data), numSkipBits, Ipp32s)
}
if (bitAlloc == 1) {
for (i = 0; i < 6; i++) {
audblk->bitAllocation[i] = 1;
}
audblk->CplBitAllocation = 1;
audblk->LfeBitAllocation = 1;
}
if (audblk->cplinu) {
audblk->firstCplinu = 0;
}
return 1;
}
/********************************************************************/
Ipp32s ParseAuxdata(AC3Dec *state,
sBitsreamBuffer *pBS,
Ipp32s start_bits)
{
Ipp32s i, tmp;
Ipp32s numSkipBits;
GET_BITS_COUNT(pBS, tmp)
tmp -= start_bits;
numSkipBits = state->syncinfo.frame_size * 16 - tmp - 18;
numSkipBits += 18; /* 1 bit - auxdata exists, 1 bit - CRC reserved bit, 16 bit - CRC */
for (i = 0; i < numSkipBits >> 3; i++) {
GET_BITS(pBS, tmp, 8, Ipp32s)
}
numSkipBits &= 7;
GET_BITS(pBS, tmp, numSkipBits, Ipp32s)
return 1;
}
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -