msaudio.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 688 行 · 第 1/2 页

H
688
字号
/*************************************************************************

Copyright (C) Microsoft Corporation, 1996 - 1999

Module Name:

    MsAudio.h

Abstract:

    Implementation of public member functions for CAudioObject.

Author:

    Wei-ge Chen (wchen) 11-March-1998

Revision History:


*************************************************************************/

// Compile Time Flags normally defined in project seetings
// these vary from specific project to project
// BUILD_INTEGER - build integer version
// BUILD_INT_FLOAT - build float version of integer tree = !BUILD_INTEGER
// ENCODER - build encoder
// DECODER - build decoder = !ENCODER
// ENABLE_ALL_ENCOPT - build support for all encoder options (otherwise just HighRate)
// ENABLE_LPC - build LPC spectrogram weighting for LowRate configurations (only defined if ENABLE_ALL_ENCOPT)
// ENABLE_EQUALIZER - build support for equalizer
// Known Useful Combinations
//   ENCODER && !BUILD_INTEGER &&  ENABLE_ALL_ENCOPT &&  ENABLE_LPC	= Normal Encoder
//   ENCODER &&  BUILD_INTEGER &&  ENABLE_ALL_ENCOPT &&  ENABLE_LPC	= Partially Integerized Encoder
//   DECODER &&  BUILD_INTEGER &&  ENABLE_ALL_ENCOPT &&  ENABLE_LPC	= Normal Integer Do-It-All Decoder
//   DECODER &&  BUILD_INTEGER &&  ENABLE_ALL_ENCOPT && !ENABLE_LPC	= Normal Integer HighRate & MidRate Decoder
//   DECODER &&  BUILD_INTEGER && !ENABLE_ALL_ENCOPT && !ENABLE_LPC	= Normal Integer HighRate Only Decoder
//   DECODER && !BUILD_INTEGER &&  ENABLE_ALL_ENCOPT &&  ENABLE_LPC	= IntFloat Do-It-All Decoder
//   DECODER && !BUILD_INTEGER &&  ENABLE_ALL_ENCOPT && !ENABLE_LPC	= IntFloat HighRate & MidRate Decoder
//   DECODER && !BUILD_INTEGER && !ENABLE_ALL_ENCOPT && !ENABLE_LPC	= IntFloat HighRate Only Decoder
#ifndef __MSAUDIO_H_
#define __MSAUDIO_H_

#ifdef __cplusplus
extern "C" {  // only need to export C interface if
              // used by C++ source code
#endif

//#include <stdlib.h>
//#include "macros.h"
//#include "DecTables.h"

// Encoder-only/decoder-only defines are no longer allowed. All audio components
// must be built with same defines so that encoder and decoder may both be linked into
// one EXE.
#if defined(ENCODER) || defined(DECODER)
#error Encoder- and Decoder-specific defines are no longer allowed. Encoder/decoder-specific code must perform encoder/decoder identification at runtime.
#endif  // defined(ENCODER) || defined(DECODER)

// The INTEGER_ENCODER #define was, where possible, replaced with BUILD_INTEGER.
// The remaining INTEGER_ENCODER's have remained as "tombstones" and should be replaced
// with a run-time decision of which codepath to take. As described above, encoder- and
// decoder-specific defines are no longer allowed.
#ifdef INTEGER_ENCODER
#error Encoder-specific defines no longer allowed. See above comments.
#endif  // INTEGER_ENCODER

#define MAX_SUBFRAMES       16

// Forward data type decl
typedef struct _CoefStream CoefStream;
typedef struct PerChannelInfoENC PerChannelInfoENC;

typedef enum {TT_NONE = 0, TT_SIMPLE} TRANSCODETYPE;
typedef enum {STEREO_INVALID = -1, STEREO_LEFTRIGHT = 0, STEREO_SUMDIFF} StereoMode;
typedef enum {CODEC_NULL, CODEC_STEADY, CODEC_DONE, CODEC_BEGIN, CODEC_LAST, CODEC_ONHOLD} Status;
typedef enum {FMU_DONE = 0, FMU_QUANTIZE, FMU_PROCESS} FMU_STATUS;
typedef enum {FFT_FORWARD = 0, FFT_INVERSE} FftDirection;

typedef struct PerChannelInfo 
{
//whenever the memory gest moved to buckets, update is needed
    // Decoder and Global Members
    I16*           m_rgiCoefQ;						//quantized coef
    Int*           m_rgiCoefRecon;                  //reconstructed coef
    Int*           m_rgiMaskQ;                      //quantized maskq ((could be I16))
    U8*            m_rgbBandNotCoded;               //band not coded
	FastFloat*	   m_rgffltSqrtBWRatio;				//MidRate/LowRate for Bands not coded
	Int*		   m_rgiNoisePower;
    const U16*     m_rgiHuffDecTbl;                 //decoder only
    const U16*     m_rgiRunEntry;                   //decoder only        
    const U16*     m_rgiLevelEntry;                 //decoder only
    Int            m_cSubbandActual;
    Int            m_iPower;                        //channel power
    Int            m_iActualPower;                  // Power as suggested by CoefQ/CoefRecon
    UInt*          m_rguiWeightFactor;				//weighting factor
//    Int*           m_rgiCoefRecon;                  //reconstructed coef
	Int			   m_iMaxMaskQ;	

#define CURRGETPCM_INVALID  0x7FFF
    // The following is NOT YET INTEGERIZED but after it is,
    // it should be moved into the #ifndef BUILD_INTEGER above
//    Float*         m_rgfltCoefRecon;                //reconstructed coef soon to be removed
//    Float*         m_rgfltBandWeight;    

    // The following are NOT YET INTEGERIZED but after they are,
    // they should be moved into the #ifndef BUILD_INTEGER above
//    Float*         m_rgfltWeightFactor;
    WeightType     m_wtMaxWeight;


    // Pointer to encoder data, if applicable
    PerChannelInfoENC*  ppcinfoENC;

    // This is encoder-only but I've put it here to avoid having to #include "msaudioenc.h"
    // in common files.
    Bool*            m_rgfMaskNeededForBark;   // for header squeezing
} PerChannelInfo;
typedef struct SubFrameConfigInfo
{ 
    Int m_cSubFrame;
    Int m_rgiSubFrameSize [MAX_SUBFRAMES];
    Int m_rgiSubFrameStart [MAX_SUBFRAMES];
    Int m_iFirstTransientSubFrm;        //for enc only
    Int m_iLastTransientSubFrm;         //for enc only
    Int m_cMaskUpdate;                  //for enc only
    Int m_rgfMaskUpdate [MAX_SUBFRAMES];
} SubFrameConfigInfo;

typedef enum {LPC_MODE=0,BARK_MODE} WeightMode;

typedef struct CAudioObject
{
    //Step Size
    QuantStepType  m_qstQuantStep;

    // packetization (has nothing to do with the rest)
    Int m_iPacketCurr;
    Int m_cBitPackedFrameSize;
    Int m_cBitPacketHeader;
    Int m_cdwPacketHeader;
    Int m_cBitPacketHeaderFractionDw;
    Int m_cBitPacketLength;

    //utility vars for entropy decoding for high rate only
    I16 m_cRunOfZeros;
    I16 m_iLevel; 
    I16 m_iSign;
    I16 m_iHighCutOffCurr;
    I16 m_iNextBarkIndex;


    Bool  m_fNoiseSub; 
    Float m_fltBitsPerSample;
    Float m_fltWeightedBitsPerSample;

    Int m_iMaxEscSize;          // in bits
    Int m_iMaxEscLevel;         // (1<<m_iMaxEscSize)

    
    Int     m_iVersion;
    Status	m_codecStatus;          //current status of the codec
    Bool    m_fSeekAdjustment;
    Bool    m_fPacketLossAdj;       //skip some samples when packetloss
    Int		m_iSamplingRate;        //audio sampling rate in Hz
    U16		m_cChannel;
    U32     m_nBytePerSample;
    Int		m_cSubband;				//no. of subbands in the MLT transform

    Bool    m_fAllowSuperFrame;
    Bool    m_fAllowSubFrame;
    Bool    m_fV5Lpc;
//!! reset
    Int     m_iCurrSubFrame;        //which subframe we are doing
    I16     m_iCurrReconCoef;       //which coef we are doing
    Bool    m_fHeaderReset;
//!! dupe? needed for inv-quantization
    Int     m_iSubFrameSizeWithUpdate;
    Int     m_iMaxSubFrameDiv;      //maximum no. division into subwindows
    Int     m_cMinSubFrameSample;   //min size of subframes in current frame; many change from frame to frame
    Int     m_cMinSubFrameSampleHalf;   //min size of subframes in current frame; many change from frame to frame
    Int     m_cMinSubFrameSampleQuad;   //min size of subframes in current frame; many change from frame to frame
    Int     m_cPossibleWinSize; 
    Int     m_iIncr;                //log2(longest winsize / curr winsize)
    Int     m_cSubFrameSample;      //for long win, same as m_cFrameSample
    Int     m_cSubFrameSampleHalf;
    Int     m_cSubFrameSampleQuad;
//!! yes!
    SubFrameConfigInfo  m_subfrmconfigPrev;
    SubFrameConfigInfo  m_subfrmconfigCurr;
    SubFrameConfigInfo  m_subfrmconfigNext;
    //should be reset every subfrm in next version
    Int		m_cBitsSubbandMax;	    //no. of bits for m_cSubband; 
    Int		m_cFrameSample;         //no. of input/output samples = 2 * cSubband
    Int		m_cFrameSampleHalf;     //no. of input/output samples = cSubband
    Int		m_cFrameSampleQuad;     //no. of input/output samples = cSubband / 2

    Int		m_cLowCutOff;           //How many coeffs to zero at the low end of spectrum
    Int		m_cHighCutOff;			//How many coeffs to zero at the high end of spectrum
    Int		m_cLowCutOffLong;
    Int		m_cHighCutOffLong;		

    Int		m_iWeightingMode;
//!! yes!
    StereoMode  m_stereoMode;       // left-right or sum-difference coding 
    Int     m_iEntropyMode;         //entropy coding mode
    Float	m_fltDitherLevel;	    //=.12; Relative intensity of Roberts' pseudo-random noise quantization
    Int		m_iQuantStepSize;
    Float	m_fltFlatenFactor;	    //Excess spectral noise power factor. Typical values are
    							    //in the range 0.4 -- 0.9; best choice is 0.5
    Float   m_fltDctScale;
    Int		m_cValidBarkBand;       //valid bark band in range; some are out of range in the subband decompositio
    const Int*	m_rgiBarkIndex;     //corresponding coef index for each valid bark



    Int     m_iSizePrev;
    Int     m_iSizeCurr;
    Int     m_iSizeNext;

    Int     m_iCoefRecurQ1;
    Int     m_iCoefRecurQ2;
    Int     m_iCoefRecurQ3;
    Int     m_iCoefRecurQ4;

    I16*	m_rgiCoefQ;             // just a pointer

    //random accessed memory
    //overall
    own PerChannelInfo*     m_rgpcinfo;

    //transform
	own Int*	m_rgiCoefReconOrig;
    //weighting
//!!yes? invQ needs it
    own Int*	m_rgiMaskQ;
    own Int*	m_rgcValidBarkBand;
    own Int*	m_rgiBarkIndexOrig;  

    //output
//!!yes? invQ needs it
    own I16*	m_piPrevOutput;        // previous encoded output; bottom half += top half of Curr; then gone
//!!yes? invQ needs it
    I32         m_iDiscardSilence;


    Float*  m_rgfltWeightFactor; 
    UInt*	m_rguiWeightFactor;   //share with m_rgiMaskQ when bark

    U32 m_iFrameNumber; // frame counter to the common code

#   define  m_cSubbandAdjusted            m_cSubband
#   define  m_cFrameSampleAdjusted        m_cFrameSample
#   define  m_cFrameSampleHalfAdjusted    m_cFrameSampleHalf
#   define  m_cSubFrameSampleAdjusted     m_cSubFrameSample
#   define  m_cSubFrameSampleHalfAdjusted m_cSubFrameSampleHalf
#   define  m_cSubFrameSampleQuadAdjusted m_cSubFrameSampleQuad
#   define	m_cHighCutOffAdjusted         m_cHighCutOff

    // Function Pointers
    WMARESULT (*aupfnInverseQuantize) (struct CAudioObject* pau,
        PerChannelInfo* ppcinfo, Int* rgiWeightFactor);
    FastFloat (*aupfnCalcSqrtBWRatio)(const PerChannelInfo *ppcinfo,
        const Int iNoiseBand, const Int cNoiseBand);
    WMARESULT (*prvpfnInverseTransformMono) (struct CAudioObject* pau,
        PerChannelInfo* ppcinfo, I16* piOutput, I16* piPrevOutput,
        I16* piPrevOutputSign, Bool fForceTransformAll);
    WMARESULT (*aupfnGetNextRun) (Void* paudec, PerChannelInfo* ppcinfo, Int *piBitCnt);

    WMARESULT (*aupfnReconstruct) (struct CAudioObject* pau, I16* piOutput, I16* pcSampleGet, Bool fForceTransformAll);

    WMARESULT (*aupfnDctIV) (struct CAudioObject* pau, CoefType* rgiCoef, Float fltAfterScaleFactor, U32 *piMagnitude);
    void (*aupfnFFT) (CoefType data[], Int nLog2np, FftDirection fftDirection);


	tRandState m_tRandState;

    Float   m_fltFirstNoiseFreq;
    Int		m_iFirstNoiseBand;
    Int     m_iFirstNoiseIndex;
    Int     m_iNoisePeakIgnoreBand; // Num of coefficients to ignore when detecting peaks during noise substitution

    //only used for NoiseSub mode
    own Int*        m_rgiFirstNoiseBand;
//!!yes
    own U8*         m_rgbBandNotCoded;
	own FastFloat*	m_rgffltSqrtBWRatio;
//!!yes
    own Int*        m_rgiNoisePower;
//!!for invQ
    own Float*      m_rgfltBandWeight;

} CAudioObject;


//public and protected
#ifdef __cplusplus
extern "C" {  // only need to export C interface if
              // used by C++ source code
#endif


#if defined(HALF_TRANSFORM)
#   define HALFTRANSFORM_ONLY(x)   (x)
#   define UPSAMPLE_ONLY(x)        (x)
#   define HALF(fHalfTransform, x)  ((fHalfTransform) ? ((x)/2) : (x))
#else   // defined(HALF_TRANSFORM)
#   define HALFTRANSFORM_ONLY(x)
#   define UPSAMPLE_ONLY(x)
#   define HALF(fUpsample, x)  (x)
#endif  // defined(HALF_TRANSFORM)

#if defined(PAD2X_TRANSFORM)
#   define PAD2XTRANSFORM_ONLY(x)	(x)
#   define DOUBLE(fPad2X, x)  ((fPad2X) ? ((x)*2) : (x))
#else   // defined(PAD2X_TRANSFORM)
#   define PAD2XTRANSFORM_ONLY(x)
#   define DOUBLE(fUpsample, x)    (x)
#endif  // defined(PAD2X_TRANSFORM)

//#if defined(HALF_TRANSFORM) || defined(PAD2X_TRANSFORM)
//#   define HALF_OR_DOUBLE(fHalfTransform, fPad2X, x)  ((fHalfTransform) ? ((x)/2) : ((fPad2X) ? ((x)*2) : (x)))
//#else   // defined(HALF_TRANSFORM) || defined(PAD2X_TRANSFORM)
//#   define HALF_OR_DOUBLE(fUpsample, fPad2X, x)      (x)
//#endif  // defined(HALF_TRANSFORM) || defined(PAD2X_TRANSFORM)


U32 MaxSamplesPerPacket(U32 ulVersion, U32 ulSamplingRate, U32 ulChannels, U32 ulBitrate);
I32 msaudioGetSamplePerFrame (Int   cSamplePerSec, 
                              U32   dwBitPerSec, 
                              Int   cChannel,
                              Int   iVersion);

CAudioObject* auNew ();
Void    auDelete (CAudioObject* pau);        //destructor
WMARESULT auInit (CAudioObject* pau, Int iVersionNumber, Int cSubband, 
                  Int iSamplingRate, U16 cChannel, 
                  Int cBytePerSec, Int cbPacketLength,
                  U16 iEncodeOpt, U16 iPlayerOpt);

Void    auPreGetPCM (CAudioObject* pau, U16* pcSampleDecoded);
WMARESULT auGetPCM (CAudioObject* pau, U16* pcSample, U8* pbDst, U32 cbDstLength);
WMARESULT auReconstruct (CAudioObject* pau, I16* piOutput, I16* pcSampleGet, Bool fForceTransformAll);
WMARESULT auSaveHistoryMono (CAudioObject* pau, PerChannelInfo* ppcinfo, 
                            Bool fForceTransformAll);

⌨️ 快捷键说明

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