📄 ac3_dec_parse.c
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2002-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "ac3_dec.h"
#include "ac3_dec_own_fp.h"
#include "ac3_dec_tables.h"
/********************************************************************/
static const Ipp32f dialnormTable[32] = {
1.0000000000f, 0.0312500000f, 0.0350769386f, 0.0393725336f,
0.0441941731f, 0.0496062823f, 0.0556811690f, 0.0625000000f,
0.0701538771f, 0.0787450671f, 0.0883883461f, 0.0992125645f,
0.1113623381f, 0.1250000000f, 0.1403077543f, 0.1574901342f,
0.1767766923f, 0.1984251291f, 0.2227246761f, 0.2500000000f,
0.2806155086f, 0.3149802685f, 0.3535533845f, 0.3968502581f,
0.4454493523f, 0.5000000000f, 0.5612310171f, 0.6299605370f,
0.7071067691f, 0.7937005162f, 0.8908987045f, 1.0000000000f
};
/********************************************************************/
Ipp32s ParseSyncInfo(AC3Dec *state,
sBitsreamBuffer *pBS)
{
Ipp32s tmp;
/* To avoid division by zero in the case of BAD_STREAM */
state->syncinfo.SampleRate = 48000;
/* Get crc1 - we don't actually use this data though */
GET_BITS(pBS, tmp, 16, Ipp32s)
/* Get the sampling rate */
GET_BITS(pBS, (state->syncinfo.fscod), 2, Ipp32s)
if (state->syncinfo.fscod == 3)
return 1;
/* Get the frame size code */
GET_BITS(pBS, (state->syncinfo.frmsizecod), 6, Ipp32s)
if (state->syncinfo.frmsizecod > 37)
return -1;
/* Parse information */
state->syncinfo.SampleRate = SAMPLING_RATE[state->syncinfo.fscod];
state->syncinfo.bit_rate = FRAMESIZECODE[state->syncinfo.frmsizecod].bit_rate;
state->syncinfo.frame_size =
FRAMESIZECODE[state->syncinfo.frmsizecod].frm_size[state->syncinfo.fscod];
return 0;
}
/********************************************************************/
Ipp32s ParseBsi(AC3Dec *state,
sBitsreamBuffer *pBS)
{
Ipp32s i, tmp;
/* Check the AC-3 version number */
GET_BITS(pBS, (state->bsi.bsid), 5, Ipp32s)
if (state->bsi.bsid > 8)
return -2;
/* Get the audio service provided by the stream */
GET_BITS(pBS, (state->bsi.bsmod), 3, Ipp32s)
/* Get the audio coding mode (ie how many channels) */
GET_BITS(pBS, (state->bsi.acmod), 3, Ipp32s)
state->bsi.karaokeMode = 0;
if ((state->bsi.bsmod == 7) && (state->bsi.acmod > 1)) {
state->bsi.karaokeMode = 1;
}
/* Predecode the number of full bandwidth channels as we use this number a lot */
state->bsi.nfchans = NFCHANS[state->bsi.acmod];
/* If it is in use, get the centre channel mix level */
if ((state->bsi.acmod & 0x1) && (state->bsi.acmod != 0x1)) {
GET_BITS(pBS, (state->bsi.cmixlev), 2, Ipp32s)
}
/* If it is in use, get the surround channel mix level */
if (state->bsi.acmod & 0x4) {
GET_BITS(pBS, (state->bsi.surmixlev), 2, Ipp32s)
}
/* Get the dolby surround mode if in 2/0 mode */
if (state->bsi.acmod == 0x2) {
GET_BITS(pBS, (state->bsi.dsurmod), 2, Ipp32s)
}
/* Is the low frequency effects channel on? */
GET_BITS(pBS, (state->bsi.lfeon), 1, Ipp32s)
/* Set output parameters as input ones */
if (state->as_input) {
state->out_acmod = state->bsi.acmod;
state->outlfeon = state->bsi.lfeon;
state->nChannelOut = NFCHANS[state->out_acmod] +
state->outlfeon;
}
/* Get the dialogue normalization level */
GET_BITS(pBS, (tmp), 5, Ipp32s)
state->bsi.dialnorm = dialnormTable[tmp];
/* Does compression gain exist? */
GET_BITS(pBS, (state->bsi.compre), 1, Ipp32s)
if (state->bsi.compre) {
/* Get compression gain */
GET_BITS(pBS, (tmp), 8, Ipp32s)
state->bsi.compr = (tmp << 24) >> 8;
}
/* Does language code exist? */
GET_BITS(pBS, (state->bsi.langcode), 1, Ipp32s)
if (state->bsi.langcode) {
/* Get langauge code */
GET_BITS(pBS, (state->bsi.langcod), 8, Ipp32s)
}
/* Does audio production info exist? */
GET_BITS(pBS, (state->bsi.audprodie), 1, Ipp32s)
if (state->bsi.audprodie) {
/* Get mix level */
GET_BITS(pBS, (state->bsi.mixlevel), 5, Ipp32s)
/* Get room type */
GET_BITS(pBS, (state->bsi.roomtyp), 2, Ipp32s)
}
/* If we're in dual mono mode then get some extra info */
if (state->bsi.acmod == 0) {
/* Get the dialogue normalization level two */
GET_BITS(pBS, (tmp), 5, Ipp32s)
state->bsi.dialnorm2 = dialnormTable[tmp];
/* Does compression gain two exist? */
GET_BITS(pBS, (state->bsi.compr2e), 1, Ipp32s)
if (state->bsi.compr2e) {
/* Get compression gain two */
GET_BITS(pBS, (tmp), 8, Ipp32s)
state->bsi.compr2 = (tmp << 24) >> 8;
}
/* Does language code two exist? */
GET_BITS(pBS, (state->bsi.langcod2e), 1, Ipp32s)
if (state->bsi.langcod2e) {
/* Get langauge code two */
GET_BITS(pBS, (state->bsi.langcod2), 8, Ipp32s)
}
/* Does audio production info two exist? */
GET_BITS(pBS, (state->bsi.audprodi2e), 1, Ipp32s)
if (state->bsi.audprodi2e) {
/* Get mix level two */
GET_BITS(pBS, (state->bsi.mixlevel2), 5, Ipp32s)
/* Get room type two */
GET_BITS(pBS, (state->bsi.roomtyp2), 2, Ipp32s)
}
}
/* Get the c o p y r i g h t b i t */
GET_BITS(pBS, (state->bsi.copyrightb), 1, Ipp32s)
/* Get the original bit */
GET_BITS(pBS, (state->bsi.origbs), 1, Ipp32s)
/* Does timecode one exist? */
GET_BITS(pBS, (state->bsi.timecod1e), 1, Ipp32s)
if (state->bsi.timecod1e) {
GET_BITS(pBS, (state->bsi.timecod1), 14, Ipp32s)
}
/* Does timecode two exist? */
GET_BITS(pBS, (state->bsi.timecod2e), 1, Ipp32s)
if (state->bsi.timecod2e) {
GET_BITS(pBS, (state->bsi.timecod2), 14, Ipp32s)
}
/* Does addition info exist? */
GET_BITS(pBS, (state->bsi.addbsie), 1, Ipp32s)
if (state->bsi.addbsie) {
/* Get how much info is there */
GET_BITS(pBS, (state->bsi.addbsil), 6, Ipp32s)
/* Get the additional info */
for (i = 0; i < (Ipp32s)(state->bsi.addbsil + 1); i++) {
GET_BITS(pBS, (state->bsi.addbsi[i]), 8, Ipp8u)
}
}
return 0;
}
/********************************************************************/
Ipp32s ParseAudblk(Ipp32s nblk,
AC3Dec *state,
sBitsreamBuffer *pBS)
{
Ipp32s ncplsubnd;
Ipp32s tmp, bitAlloc;
Ipp32s prevCplinu, prevCplbegf, prevCplendf;
Ipp32s i, j;
_AudBlk *audblk = &(state->audblk);
if (nblk == 0) { /* audioblock 0? If so, reset these parameters */
Ipp32s bin;
audblk->dynrng = 0;
audblk->dynrng2 = 0;
//audblk->cpldeltnseg = 0;
audblk->cpldeltlastbin = -256;
for (bin = 0; bin < 50; bin++) {
state->cpldeltba[bin] = 0;
}
for (i = 0; i < state->bsi.nfchans; i++) {
for (bin = 0; bin < 50; bin++) {
state->deltba[i][bin] = 0;
}
//audblk->deltnseg[i] = 0;
audblk->firstChincpl[i] = 1;
}
for (i = 0; i < 18; i++) {
audblk->phscor[i] = 0;
}
audblk->phsoutmod = 7;
audblk->firstCplinu = 1;
prevCplinu = 0;
prevCplbegf = 0;
prevCplendf = 0;
} else {
prevCplinu = audblk->cplinu;
prevCplbegf = audblk->cplbegf;
prevCplendf = audblk->cplendf;
}
for (i = 0; i < 6; i++) {
audblk->bitAllocation[i] = 0;
}
audblk->CplBitAllocation = 0;
audblk->LfeBitAllocation = 0;
bitAlloc = 0;
/* Is this channels are interleaved ? */
/* Should we dither this channel? */
GET_BITS(pBS, (audblk->blksw), 2*(state->bsi.nfchans), Ipp32s)
audblk->dithflag = audblk->blksw & ((1 << state->bsi.nfchans) - 1);
audblk->blksw = audblk->blksw >> state->bsi.nfchans;
/* Does dynamic range control exist? */
GET_BITS(pBS, (audblk->dynrnge), 1, Ipp32s)
if (audblk->dynrnge) {
/* Get dynamic range info */
GET_BITS(pBS, (tmp), 8, Ipp32s)
audblk->dynrng = (tmp << 24) >> 9;
}
/* If we're in dual mono mode then get the second channel DR info */
if (state->bsi.acmod == 0) {
/* Does dynamic range control two exist? */
GET_BITS(pBS, (audblk->dynrng2e), 1, Ipp32s)
if (audblk->dynrng2e) {
/* Get dynamic range info */
GET_BITS(pBS, (tmp), 8, Ipp32s)
audblk->dynrng2 = (tmp << 24) >> 9;
}
}
/* Does coupling strategy exist? */
GET_BITS(pBS, (audblk->cplstre), 1, Ipp32s)
if ((nblk == 0) && (audblk->cplstre == 0)) {
return 0;
}
if (audblk->cplstre) {
/* Is coupling turned on? */
GET_BITS(pBS, (audblk->cplinu), 1, Ipp32s)
if (audblk->cplinu) {
GET_BITS(pBS, tmp, state->bsi.nfchans, Ipp32s)
/* don't sure if this error is critical */
//if (tmp == 0) {
// return 0;
//}
for (i = state->bsi.nfchans - 1; i >= 0; i--) {
audblk->chincpl[i] = tmp & 1;
tmp >>= 1;
}
if (state->bsi.acmod == 0x2) {
GET_BITS(pBS, (audblk->phsflginu), 1, Ipp32s)
} else audblk->phsflginu = 0;
GET_BITS(pBS, (audblk->cplbegf), 4, Ipp32s)
GET_BITS(pBS, (audblk->cplendf), 4, Ipp32s)
ncplsubnd = (Ipp32s)audblk->cplendf - audblk->cplbegf + 3;
if (ncplsubnd <= 0) {
return 0;
}
/* Calculate the start and end bins of the coupling channel */
audblk->cplstrtmant = ((audblk->cplbegf * 12) + 37);
audblk->cplendmant = (((audblk->cplendf + 3) * 12) + 37);
/* The number of combined subbands is ncplsubnd minus each combined band */
audblk->ncplbnd = ncplsubnd;
audblk->cplbndstrc[0] = 0;
GET_BITS(pBS, tmp, ncplsubnd - 1, Ipp32s)
for (i = ncplsubnd - 1; i >= 1; i--) {
audblk->cplbndstrc[i] = tmp & 1;
tmp >>= 1;
}
#ifndef REF_DECODER_COMPATIBLE
for (i = 1; i < ncplsubnd; i++) {
audblk->ncplbnd -= (Ipp32s)audblk->cplbndstrc[i];
}
#endif
} else {
for (i = 0; i < state->bsi.nfchans; i++)
audblk->chincpl[i] = 0;
audblk->phsflginu = 0;
}
}
if (audblk->cplinu) {
/* Loop through all the channels and get their coupling co-ords */
for (i = 0; i < state->bsi.nfchans; i++) {
if (!audblk->chincpl[i])
continue;
/* Is there new coupling co-ordinate info? */
GET_BITS(pBS, (audblk->cplcoe[i]), 1, Ipp32s)
if ((audblk->firstChincpl[i]) && ((audblk->cplcoe[i]) == 0)) {
return 0;
}
audblk->firstChincpl[i] = 0;
if (audblk->cplcoe[i]) {
GET_BITS(pBS, (audblk->mstrcplco[i]), 2, Ipp32s)
for (j = 0; j < audblk->ncplbnd; j++) {
Ipp32s tmp0, tmp1;
#ifdef REF_DECODER_COMPATIBLE
if (audblk->cplbndstrc[j] == 0) {
#endif
GET_BITS(pBS, (tmp0), 4, Ipp32s)
GET_BITS(pBS, (tmp1), 4, Ipp32s)
if (tmp0 == 15) {
tmp0 = tmp0 + 4 + 3 * audblk->mstrcplco[i];
audblk->cplcoord[i][j] = (Ipp32f)tmp1 / (Ipp32f)(1 << tmp0);
} else {
tmp0 = tmp0 + 5 + 3 * audblk->mstrcplco[i];
audblk->cplcoord[i][j] = (Ipp32f)(tmp1 + 16) / (Ipp32f)(1 << tmp0);
}
audblk->cplcoord[i][j] *= 8;
#ifdef REF_DECODER_COMPATIBLE
} else {
audblk->cplcoord[i][j] = audblk->cplcoord[i][j-1];
}
#endif
}
}
}
/* If we're in 2/0 (stereo) mode, there's going to be some phase info */
if ((state->bsi.acmod == 0x2) && audblk->phsflginu &&
((audblk->cplcoe[0] || audblk->cplcoe[1]))) {
#ifdef REF_DECODER_COMPATIBLE
Ipp32s phsflg = 0;
#endif
for (j = 0; j < audblk->ncplbnd; j++) {
#ifndef REF_DECODER_COMPATIBLE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -