⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac3dec_parse.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*//////////////////////////////////////////////////////////////////////////////////                  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-2005 Intel Corporation. All Rights Reserved.//*/#include "umc_ac3_decoder.h"#include "ac3dec_tables.h"#ifdef _BIG_ENDIAN_#define BSWAP(x) (x)#else#define BSWAP(x) (Ipp32u)(((x) << 24) | (((x)&0xff00) << 8) | (((x) >> 8)&0xff00) | ((x&0xff000000) >> 24));#endifstatic unsigned int table[33] = {  0x00000000,  0x00000001,  0x00000003,  0x00000007,  0x0000000F,  0x0000001F,  0x0000003F,  0x0000007F,  0x000000FF,  0x000001FF,  0x000003FF,  0x000007FF,  0x00000FFF,  0x00001FFF,  0x00003FFF,  0x00007FFF,  0x0000FFFF,  0x0001FFFF,  0x0003FFFF,  0x0007FFFF,  0x000FFFFF,  0x001FFFFF,  0x003FFFFF,  0x007FFFFF,  0x00FFFFFF,  0x01FFFFFF,  0x03FFFFFF,  0x07FFFFFF,  0x0FFFFFFF,  0x1FFFFFFF,  0x3FFFFFFF,  0x7FFFFFFF,  0xFFFFFFFF,};int UMC::AC3Decoder::getbits(int n){  unsigned int cw = 0;  dataBuffer.total_bits_read += n;  if (dataBuffer.iBitOffset < n) {    cw = dataBuffer.cw & table[dataBuffer.iBitOffset];    dataBuffer.iDWDoneNum++;    dataBuffer.cw = BSWAP(*(dataBuffer.pBuffer + dataBuffer.iDWDoneNum));    n -= dataBuffer.iBitOffset;    cw = cw << n;    dataBuffer.iBitOffset = 32;  }  dataBuffer.iBitOffset -= n;  cw |= (dataBuffer.cw >> (dataBuffer.iBitOffset)) & table[n];  return cw;}int UMC::AC3Decoder::ParseSyncInfo(){ /* Get crc1 - we don't actually use this data though */  getbits(16); /* Get the sampling rate */  syncinfo.fscod = (Ipp16u)getbits(2);  if (syncinfo.fscod == 3)    return 1; /* Get the frame size code */  syncinfo.frmsizecod = (Ipp16u)getbits(6);  if (syncinfo.frmsizecod > 37)    return -1; /* Parse information */  syncinfo.SampleRate = (float)SAMPLING_RATE[syncinfo.fscod];  syncinfo.bit_rate = FRAMESIZECODE[syncinfo.frmsizecod].bit_rate;  syncinfo.frame_size =    FRAMESIZECODE[syncinfo.frmsizecod].frm_size[syncinfo.fscod];  return 0;}static const float 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};int UMC::AC3Decoder::ParseBsi(){  int i, tmp; /* Check the AC-3 version number */  bsi.bsid = (Ipp16u)getbits(5);  if (bsi.bsid > 8)    return -2; /* Get the audio service provided by the stream */  bsi.bsmod = (Ipp16u)getbits(3); /* Get the audio coding mode (ie how many channels) */  bsi.acmod = (Ipp16u)getbits(3);  bsi.karaokeMode = 0;  if ((bsi.bsmod == 7) && (bsi.acmod > 1)) {    bsi.karaokeMode = 1;  } /* Predecode the number of full bandwidth channels as we use this number a lot */  bsi.nfchans = NFCHANS[bsi.acmod]; /* If it is in use, get the centre channel mix level */  if ((bsi.acmod & 0x1) && (bsi.acmod != 0x1))    bsi.cmixlev = (Ipp16u)getbits(2); /* If it is in use, get the surround channel mix level */  if (bsi.acmod & 0x4)    bsi.surmixlev = (Ipp16u)getbits(2); /* Get the dolby surround mode if in 2/0 mode */  if (bsi.acmod == 0x2)    bsi.dsurmod = (Ipp16u)getbits(2); /* Is the low frequency effects channel on? */  bsi.lfeon = (Ipp16u)getbits(1); /* Get the dialogue normalization level */  tmp = (Ipp32s)getbits(5);  bsi.dialnorm = dialnormTable[tmp]; /* Does compression gain exist? */  bsi.compre = (Ipp16u)getbits(1);  if (bsi.compre) { /* Get compression gain */    tmp = (Ipp32s)getbits(8);    bsi.compr = (tmp << 24) >> 8;  } /* Does language code exist? */  bsi.langcode = (Ipp16u)getbits(1);  if (bsi.langcode) { /* Get langauge code */    bsi.langcod = (Ipp16u)getbits(8);  } /* Does audio production info exist? */  bsi.audprodie = (Ipp16u)getbits(1);  if (bsi.audprodie) { /* Get mix level */    bsi.mixlevel = (Ipp16u)getbits(5); /* Get room type */    bsi.roomtyp = (Ipp16u)getbits(2);  } /* If we're in dual mono mode then get some extra info */  if (bsi.acmod == 0) { /* Get the dialogue normalization level two */    tmp = (Ipp32s)getbits(5);    bsi.dialnorm2 = dialnormTable[tmp]; /* Does compression gain two exist? */    bsi.compr2e = (Ipp16u)getbits(1);    if (bsi.compr2e) { /* Get compression gain two */      tmp = (Ipp32s)getbits(8);      bsi.compr2 = (tmp << 24) >> 8;    } /* Does language code two exist? */    bsi.langcod2e = (Ipp16u)getbits(1);    if (bsi.langcod2e) { /* Get langauge code two */      bsi.langcod2 = (Ipp16u)getbits(8);    } /* Does audio production info two exist? */    bsi.audprodi2e = (Ipp16u)getbits(1);    if (bsi.audprodi2e) { /* Get mix level two */      bsi.mixlevel2 = (Ipp16u)getbits(5); /* Get room type two */      bsi.roomtyp2 = (Ipp16u)getbits(2);    }  } /* Get the c o p y r i g h t  b i t */  bsi.copyrightb = (Ipp16u)getbits(1); /* Get the original bit */  bsi.origbs = (Ipp16u)getbits(1); /* Does timecode one exist? */  bsi.timecod1e = (Ipp16u)getbits(1);  if (bsi.timecod1e)    bsi.timecod1 = (Ipp16u)getbits(14); /* Does timecode two exist? */  bsi.timecod2e = (Ipp16u)getbits(1);  if (bsi.timecod2e)    bsi.timecod2 = (Ipp16u)getbits(14); /* Does addition info exist? */  bsi.addbsie = (Ipp16u)getbits(1);  if (bsi.addbsie) { /* Get how much info is there */    bsi.addbsil = (Ipp16u)getbits(6); /* Get the additional info */    for (i = 0; i < (int)(bsi.addbsil + 1); i++)      bsi.addbsi[i] = (Ipp8u)getbits(8);  }  return 0;}int UMC::AC3Decoder::ParseAudblk(int nblk){  int ncplsubnd;  int tmp;  int i, j;  if (nblk == 0) {      /* audioblock 0? If so, reset these parameters */    audblk[nblk]->dynrng = 0;    audblk[nblk]->dynrng2 = 0;    audblk[nblk]->cpldeltnseg = 0;    for (i = 0; i < bsi.nfchans; i++) {      audblk[nblk]->deltnseg[i] = 0;    }    for (i = 0; i < 18; i++) {      audblk[nblk]->phscor[i] = 0;    }    audblk[nblk]->phsoutmod = 7;  }  for (i = 0; i < bsi.nfchans; i++) { /* Is this channel an interleaved ? */    audblk[nblk]->blksw[i] = (Ipp16u)(getbits(1));  }  for (i = 0; i < bsi.nfchans; i++) { /* Should we dither this channel? */    audblk[nblk]->dithflag[i] = (Ipp16u)(getbits(1));  } /* Does dynamic range control exist? */  audblk[nblk]->dynrnge = (Ipp16u)(getbits(1));  if (audblk[nblk]->dynrnge) { /* Get dynamic range info */    tmp = (Ipp32s)(getbits(8));    audblk[nblk]->dynrng = (tmp << 24) >> 9;  } /* If we're in dual mono mode then get the second channel DR info */  if (bsi.acmod == 0) { /* Does dynamic range control two exist? */    audblk[nblk]->dynrng2e = (Ipp16u)(getbits(1));    if (audblk[nblk]->dynrng2e) { /* Get dynamic range info */      tmp = (Ipp32s)(getbits(8));      audblk[nblk]->dynrng2 = (tmp << 24) >> 9;    }  } /* Does coupling strategy exist? */  audblk[nblk]->cplstre = (Ipp16u)(getbits(1));  if ((nblk == 0) && (audblk[nblk]->cplstre == 0)) {    return 0;  }  if (audblk[nblk]->cplstre) { /* Is coupling turned on? */    audblk[nblk]->cplinu = (Ipp16u)(getbits(1));    if (audblk[nblk]->cplinu) {      for (i = 0; i < bsi.nfchans; i++)        audblk[nblk]->chincpl[i] = (Ipp16u)(getbits(1));      if (bsi.acmod == 0x2)        audblk[nblk]->phsflginu = (Ipp16u)(getbits(1));      else        audblk[nblk]->phsflginu = 0;      audblk[nblk]->cplbegf = (Ipp16u)(getbits(4));      audblk[nblk]->cplendf = (Ipp16u)(getbits(4));      ncplsubnd = (int)audblk[nblk]->cplendf - audblk[nblk]->cplbegf + 3; /* Calculate the start and end bins of the coupling channel */      audblk[nblk]->cplstrtmant = (Ipp16u)((audblk[nblk]->cplbegf * 12) + 37);      audblk[nblk]->cplendmant =        (Ipp16u)(((audblk[nblk]->cplendf + 3) * 12) + 37); /* The number of combined subbands is ncplsubnd minus each combined band */      audblk[nblk]->ncplbnd = (Ipp16u)ncplsubnd;      audblk[nblk]->cplbndstrc[0] = 0;      for (i = 1; i < ncplsubnd; i++) {        audblk[nblk]->cplbndstrc[i] = (Ipp16u)(getbits(1));#ifndef REF_DECODER_COMPATIBLE        audblk[nblk]->ncplbnd -= (int)audblk[nblk]->cplbndstrc[i];#endif      }    } else {      for (i = 0; i < bsi.nfchans; i++)        audblk[nblk]->chincpl[i] = 0;      audblk[nblk]->phsflginu = 0;    }  }  if (audblk[nblk]->cplinu) { /* Loop through all the channels and get their coupling co-ords */    for (i = 0; i < bsi.nfchans; i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -