📄 umc_ac3_decoder.h
字号:
/*////////////////////////////////////////////////////////////////////////////////// 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.//*/#ifndef __AC3_DECODER_H__#define __AC3_DECODER_H__#include "umc_audio_codec.h"#include <ippac.h>/* There are some inconsistences between standard and refence realization *//* basically in the processing of couple channels uder some conditions *//* If the following define is set than our decoder will be compatible to *//* refenence realization */#define REF_DECODER_COMPATIBLE#define GAINSCALE 65535namespace UMC { class AC3DecoderParams:public AudioCodecParams { DYNAMIC_CAST_DECL(AC3DecoderParams, AudioCodecParams) public: AC3DecoderParams(void) { out_acmod = 0; outlfeon = 0; dualmonomode = 0; drc_scaleLow = 1; drc_scaleHigh = 1; out_compmod = 0; karaokeCapable = 3; crc_mute = 0; }; int dualmonomode; int out_acmod; int outlfeon; int out_compmod; int karaokeCapable; int crc_mute; float drc_scaleLow; float drc_scaleHigh; }; class AC3Decoder:public AudioCodec { public: AC3Decoder(); ~AC3Decoder(void); Status Init(BaseCodecParams * init); Status GetFrame(MediaData * in, MediaData * out); Status Close(); Status Reset(); Status GetInfo(BaseCodecParams * info); Status GetDuration(float *p_duration); Status SetParams(BaseCodecParams * params); protected:// internal functionality Status ReceiveBuffer(MediaData * in); Status GetSynch(); Status DecodeFrame(MediaData * out); int getbits(int n);// crc void crcInit(); bool crcGetState(); void crcCheck(Ipp32s num);// parsing int ParseSyncInfo(); int ParseBsi(); int ParseAudblk(int block_num); int ParseAuxdata();// decoding blocks int DecodeExponents(int block_num); int BitAllocation(int block_num); int UnpackMantissas(int block_num); void MakeFloat_32f32f(Ipp32f *inmant, Ipp16s *inexp, Ipp32s size, Ipp32f *outfloat);// high level decoding functions int DeCoupling(int block_num); int Rematrix(int block_num); int InverseTransform(int block_num); int WindowingOverlap(short* pOut); int Downmix(int dynrng, int dynrng2); float drc(int compre, int compr, int dynrng, int downmix, float dialnorm);// low level decoding functions// exponents int expUnpackCh(Ipp16u TypeCh, Ipp16u ExpStr, Ipp16u nGrps, Ipp16u Exp0, Ipp16u *sourse, Ipp16u *dest);// Bit allocation void baComputePsd(short start, short end, Ipp16u *exps, short *psd, short *bndpsd); void baComputeExcitation(short start, short end, short fgain, short fastleak, short slowleak, short is_lfe); void baComputeMask(short start, short end, Ipp16u deltnseg, Ipp16u *deltoffst, Ipp16u *deltba, Ipp16u *deltlen); void baComputeBap(Ipp16s start, Ipp16s end, Ipp16s snroffset, Ipp16u *bap); short baLogAdd(short a, short b); short baCalcLowComp(short a, short b0, short b1, short bin);// mantissa int getMantissas(Ipp16u *bap, int do_dither, Ipp32f *mant, int count);// decpupling void uncoupleChannel(Ipp16u nblk); __inline int get_unused_bits();// Delta bit allocation constants enum { DELTA_BIT_REUSE, DELTA_BIT_NEW, DELTA_BIT_NONE, DELTA_BIT_RESERVED }; enum { CH_FBW = 1, CH_CPL = 2, CH_LFE = 4 };// audio coding mode enum { ACMOD_0, ACMOD_10, ACMOD_20, ACMOD_30, ACMOD_21, ACMOD_31, ACMOD_22, ACMOD_32 };// dual mono downmix mode enum { DUAL_STEREO, DUAL_LEFTMONO, DUAL_RGHTMONO, DUAL_MIXMONO };// internal structure typedef struct _BitsreamBuffer { unsigned int *pBuffer; // int iReceivedBytes; int iDWDoneNum; // int iBitOffset; // 32->1 Ipp16u state; unsigned char* ptrCrc; // unsigned int cw; int total_bits_read; } sBitsreamBuffer;/* * synchronization information */ struct _SyncInfo {/* * Sync word == 0x0B77 */ Ipp16u syncword;/* * crc for the first 5/8 of the sync block */ Ipp16u crc1;/* * Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */ Ipp16u fscod;/* * Frame size code */ Ipp16u frmsizecod;/* * Information not in the AC-3 bitstream, but derived *//* * Frame size in 16 bit words */ float SampleRate; int frame_size;/* * Bit rate in kilobits */ Ipp16u bit_rate; };/* * bit stream information */ struct _BSI { Ipp16u bsid; /* Bit stream identification == 0x8 */ Ipp16u bsmod; /* Bit stream mode */ Ipp16u acmod; /* Audio coding mode */ Ipp16u cmixlev; /* Centre mix level */ Ipp16u surmixlev; /* Surround mix level *//* * If we're in 2/0 mode then Dolby surround mix level - NOT USED - */ Ipp16u dsurmod;/* * Low frequency effects on */ Ipp16u lfeon;/* * dialogue normalization */ float dialnorm;/* * Compression gain word exists */ Ipp16u compre;/* * Compression gain word */ int compr;/* * Language code exists */ Ipp16u langcode;/* * Language code */ Ipp16u langcod;/* * Audio production info exists */ Ipp16u audprodie;/* * mixing level */ Ipp16u mixlevel;/* * room type */ Ipp16u roomtyp;/* * If we're in dual mono mode (acmod == 0) then extra stuff */ float dialnorm2;/* * compression gain word exists */ Ipp16u compr2e;/* * compression gain word */ int compr2;/* * language code exists */ Ipp16u langcod2e;/* * language code */ Ipp16u langcod2;/* * audio production information exists */ Ipp16u audprodi2e;/* * mixing level, ch2 */ Ipp16u mixlevel2;/* * room type ch2 */ Ipp16u roomtyp2;/* * c o p y r i g h t b i t */ Ipp16u copyrightb;/* * Original bit stream */ Ipp16u origbs;/* * Timecode 1 exists */ Ipp16u timecod1e;/* * Timecode 2 exists */ Ipp16u timecod2e;/* * Timecode 1 */ Ipp16u timecod1;/* * Timecode 2 */ Ipp16u timecod2;/* * Additional bit stream info exists */ Ipp16u addbsie;/* * Additional bit stream information length - 1 (in bytes) */ Ipp16u addbsil;/* * Additional bit stream information (max 64 bytes) */ Ipp8u addbsi[64];/* * Information not in the AC-3 bitstream, but derived *//* * Number of channels (excluding LFE) * Derived from acmod */ Ipp16u nfchans; int karaokeMode; }; /* bit stream information *//* * audio block */ struct _AudBlk { Ipp16u blksw[5];/* * dither enable bit indexed by channel num */ Ipp16u dithflag[5];/* * dynamic range gain word exists */ Ipp16u dynrnge;/* * dynamic range gain word */ int dynrng;/* * if acmod==0 then dynamic range 2 gain exists */ Ipp16u dynrng2e;/* * dynamic range 2 gain */ int dynrng2;/* * coupling strategy exists */ Ipp16u cplstre;/* * coupling in use */ Ipp16u cplinu;/* * channel coupled */ Ipp16u chincpl[5];/* * if acmod==2 then phase flags in use */ Ipp16u phsflginu;/* * coupling begin frequency code */ Ipp16u cplbegf;/* * coupling end frequency code */ Ipp16u cplendf;/* * coupling band structure cplbndstrc[sbnd] */ Ipp16u cplbndstrc[18];/* * coupling coordinares exist cplcoe[ch] */ Ipp16u cplcoe[5];/* * Master coupling coordinate */ Ipp16u mstrcplco[5];/* * coupling coordinate */ Ipp32f cplcoord[5][18];/* * Phase flags (only in 2/0 mode) phsflg[bnd] */ Ipp16u phsflg[18];/* * rematrixing strategy */ Ipp16u rematstr;/* * Rematrixing flag */ Ipp16u rematflg[4];/* * # of rematrixing bands */ Ipp16u nrematbnds;/* * Coupling exponent strategy */ Ipp16u cplexpstr;/* * channel exponent strategy chexpstr[ch] */ Ipp16u chexpstr[5];/* * Exponent strategy for lfe channel */ Ipp16u lfeexpstr;/* * Channel bandwidth code */ Ipp16u chbwcod[5];/* * absolute coupling exponent */ Ipp16u cplabsexp;/* * Coupling channel exponents */ Ipp16u cplexps[18 * 12 / 3];/* * fbw channel exponents exps[ch][grp] */// Ipp16u exps[5][252 / 3]; Ipp16u exps[5][252 / 3 + 1];/* * channel gain range code gainrng[ch] */ Ipp16u gainrng[5];/* * low frequency exponents */ Ipp16u lfeexps[3];/* * Bit allocation information exists */ Ipp16u baie;/* * Slow decay code */ Ipp16u sdcycod;/* * Fast decay code */ Ipp16u fdcycod;/* * Slow gain code */ Ipp16u sgaincod;/* * dB per bit code */ Ipp16u dbpbcod;/* * masking floor code */ Ipp16u floorcod;/* * SNR offset exists */ Ipp16u snroffste;/* * coarse SNR offset */ Ipp16u csnroffst;/* * coupling fine SNR offset */ Ipp16u cplfsnroffst;/* * coupling fast gain code */ Ipp16u cplfgaincod;/* * fbw fine SNR offset */ Ipp16u fsnroffst[5];/* * fbw fast gain code */ Ipp16u fgaincod[5];/* * lfe fine SNR offset */ Ipp16u lfefsnroffst;/* * lfe fast gain code */ Ipp16u lfefgaincod;/* * Coupling leak initiaization exists */ Ipp16u cplleake;/* * coupling fast leak initialization */ Ipp16u cplfleak;/* * coupling slow leak initialization */ Ipp16u cplsleak;/* * delta bit allocation information exists */ Ipp16u deltbaie;/* * coupling delta bit allocation exists */ Ipp16u cpldeltbae;/* * fbw delta bit allocation exists */ Ipp16u deltbae[5];/* * coupling delta bit alocation number of segment */ Ipp16u cpldeltnseg;/* * coupling delta bit allocation offset */ Ipp16u cpldeltoffst[8];/* * coupling delta bit allocation length */ Ipp16u cpldeltlen[8];/* * coupling delta bit allocation */ Ipp16u cpldeltba[8];/* * number of delta bit segments */ Ipp16u deltnseg[5];/* * fbw delta bit allocation offset */ Ipp16u deltoffst[5][8];/* * fbw delta bit allocation length */ Ipp16u deltlen[5][8];/* * fbw delta bit allocation */ Ipp16u deltba[5][8];/* * skip length exists */ Ipp16u skiple;/* * skip length */ Ipp16u skipl;/* * mantissa *//* * fbw channel */ float fbw_mant[5][256];/* * coupling channel */ float cpl_mant[256];/* * lfe channel */ float lfe_mant[7];/* * Number of combined coupling sub-bands * Derived from ncplsubnd and * cplbndstrc */ Ipp16u ncplbnd;/* * Number of exponent groups by channel * Derived from strmant, endmant */ Ipp16u nchgrps[5];/* * Number of coupling exponent groups * Derived from cplbegf, cplendf, * cplexpstr */ Ipp16u ncplgrps;/* * End mantissa numbers of fbw channels */ Ipp16u endmant[5];/* * Start and end mantissa numbers for the coupling channel */ Ipp16u cplstrtmant; Ipp16u cplendmant;/* * PHSCOR data */ Ipp16u phscor[18]; Ipp16u phsoutmod;/* * Decoded exponent info */ Ipp16u fbw_exp[5][256]; Ipp16u cpl_exp[256]; Ipp16u lfe_exp[7];/* * Bit allocation pointer results */ Ipp16u fbw_bap[5][256];// FIXME figure out exactly how many entries there should be (253-37?) Ipp16u cpl_bap[256]; Ipp16u lfe_bap[7]; }; /* audio block */ struct _StreamCoeffs { float channel[7][256]; float cplChannel[5][256]; float *ShortBuff[2]; }; struct _StreamSamples { float channel[6 + 1][512]; // instead SL and SR exist one S float delay[6][256]; }; struct _AllocationImdct { IppsMDCTInvSpec_32f *pMDCTSpecLong; IppsMDCTInvSpec_32f *pMDCTSpecShort; Ipp8u *pBufferShort; Ipp8u *pBufferLong; }; struct _DataVectors { _StreamCoeffs stream_coeffs; _StreamSamples stream_samples; //short outsamples[6 * 256 * 6]; float *temp[6]; // for downmix (temp store) }; struct _MantsTabls {/* * move from global to context variables */// These store the persistent state of the packed mantissas Ipp16u m_1_pointer; Ipp16u m_2_pointer; Ipp16u m_4_pointer; Ipp16u m_pointers[7]; Ipp16u *fast_m_1; Ipp16u *fast_m_2; Ipp16u *fast_m_4;// Ipp16u . fast manitsa lookups instead of calculating div/mod Ipp16u fastM_9[32][3]; Ipp16u fastM_25[128][3]; Ipp16u fastM_11[128][3]; short dithtemp; }; struct _BitAlloc {// bit allocation arrays short sdecay; short fdecay; short sgain; short dbknee; short floor; short psd[256]; short bndpsd[256]; short excite[256]; short mask[256]; }; enum EXP_STRATEGY { /* Exponent strategy constants */ EXP_REUSE, EXP_D15, EXP_D25, EXP_D45 };// class members AC3DecoderParams decoder_settings; _SyncInfo syncinfo; _BSI bsi; _AudBlk *audblk[6]; _DataVectors data_vectors; _AllocationImdct allocation_imdct; _MantsTabls mants_tabls; _BitAlloc bit_alloc; _BitsreamBuffer dataBuffer; float one_frame_time; float current_time; int debug_level; int nChannelOut;// aux. member bool first_frame; double m_pts_prev; AudioCodecParams m_params; };} // namespace UMC#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -