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

📄 macros.h

📁 本程序为ST公司开发的源代码
💻 H
📖 第 1 页 / 共 5 页
字号:
#endif#   define MULT_CH_MATRIX(a,b) MULT_HI32_SHIFT(a, b, CH_FRAC_BITS)#   define CH_FROM_FLOAT(flt) FRAC_FROM_FLOAT(flt, CH_FRAC_BITS)#   define FLOAT_FROM_CH(ch) FLOAT_FROM_FRAC(ch, CH_FRAC_BITS)#   define ROUND_CH_TO_2TON(x, N) (((N) >= CH_FRAC_BITS) ? (x) : wmaiiround2toN(x, CH_FRAC_BITS-N))    typedef ChXFormType ChXFormMType;#   define CHM_FROM_FLOAT(flt) CH_FROM_FLOAT(flt)#   define FLOAT_FORM_CHM(ch) FLOAT_FROM_CH(ch)    typedef I32 ChPPXFormType;#   define CHPP_FRAC_BITS (30)#   define MULT_CHPP(a,b) MULT_HI32_SHIFT(a, b, CHPP_FRAC_BITS)#   define CHPP_FROM_FLOAT(flt) FRAC_FROM_FLOAT(flt, CHPP_FRAC_BITS)// Downmix transform    typedef I32 ChDnMixType;#   define CHDN_FRAC_BITS (23)#   define MULT_CHDN(a,b) MULT_HI32_SHIFT(a, b, CHDN_FRAC_BITS)#   define CHDN_FROM_FLOAT(flt) FRAC_FROM_FLOAT(flt, CHDN_FRAC_BITS)// Half transform for mllm    typedef I32 HTFilterType;#   define HTFT_FRAC_BITS (28)#   define MULT_HTFT(a,b) MULT_HI32_SHIFT(a, b, HTFT_FRAC_BITS)#   define HTFT_FROM_FLOAT(flt) FRAC_FROM_FLOAT(flt, HTFT_FRAC_BITS)// fix-point binary points conversion factors// convert float or double to BP1 integer ( -1.0 <= x < +1.0 )#define NF2BP1 0x7FFFFFFF// convert float or double to BP2 integer ( -2.0 <= x < +2.0 )#define NF2BP2 0x3FFFFFFF// Fraction is stored at 2^32 (BP0)#define UBP0_FROM_FLOAT(x) ((U32)(x*4294967296.0F))    typedef I32 FracBitsType;    typedef struct {    //I8 exponent;  Old exponent was shift from binary point at 24th position        FracBitsType iFracBits;        I32 iFraction;    } FastFloat;// Type for holding quantization magnitide returned by prvWeightedQuantization    typedef FastFloat QuantFloat;    // Some utility functions with obvious meaning#   define DIV2(a) ((a)>>1)#   define MUL2(a) ((a)<<1)#   define DIV4(a) ((a)>>2)#   define MUL4(a) ((a)<<2)#   define MUL8(a) ((a)<<3)#   define INTEGER_ONLY(a) a#   define INTEGER_OR_INT_FLOAT(a,b) a#define MULT_SQRT2(a) (I32)(((I64)(a) * INT_SQRT2) >> INT_SQRT2_BITS)#else // ************ so must be BUILD_INT_FLOAT *****************// Coefficents type (output of inverse quantization, transformed by DCT and overlapped/added)    typedef Float CoefType;#   define COEF_FRAC_BITS 0#   define COEF_FRAC_SCALE 1#   define COEF_FROM_FLOAT(flt) ((CoefType)(flt))#   define FLOAT_FROM_COEF(coef) ((Float)(coef))#   define COEF_FROM_INT(i) (i)#   define INT_FROM_COEF(cf) (cf)#   define FRAC_FROM_RATIO(a, b, bits) ((a)/(b))// Fractional Type used by FFT Trig Recurrsion     typedef Float BP2Type;#   define BP2_FRAC_BITS 0#   define BP2_FRAC_SCALE 1#   define BP2_FROM_FLOAT(flt) ((BP2Type)(flt))#   define FLOAT_FROM_BP2(bp2) ((Float)(bp2))#   define BP2_FROM_BP1(bp1) (bp1)#   define MULT_BP2(a,b) ((a)*(b))// Fractional type used by DCT Trig Recurrsion    typedef Float BP1Type;#   define BP1_FRAC_BITS 0#   define BP1_FRAC_SCALE 1#   define BP1_FROM_FLOAT(flt) ((BP1Type)(flt))#   define FLOAT_FROM_BP1(bp1) ((Float)(bp1))#   define MULT_BP1(a,b) ((a)*(b))// Calculation of output of channel transform#define CH_FRAC_BITS (30)    typedef Float ChXFormType;#   define MULT_CH(a,b) ((a)*(b))#   define MULT_CH_SQRT2(a) ((a) * (FLT_SQRT2))#   define CH_FROM_FLOAT(flt) (flt)#   define FLOAT_FROM_CH(ch) (ch)// Channel transform#ifdef FLOAT_INT_CHXFORM    typedef I32 ChXFormMType;#   define MULT_CH_MATRIX(a,b) MULT_HI32_SHIFT(a, b, CH_FRAC_BITS)#   define ROUND_CH_TO_2TON(x, N) (((N) >= CH_FRAC_BITS) ? (x) : wmaiiround2toN(x, CH_FRAC_BITS-N))#   define CHM_FROM_FLOAT(flt) FRAC_FROM_FLOAT(flt, CH_FRAC_BITS)#   define FLOAT_FROM_CHM(ch) FLOAT_FROM_FRAC(ch, CH_FRAC_BITS)#else    typedef ChXFormType ChXFormMType;#   define MULT_CH_MATRIX(a,b) ((a)*(b))#   define ROUND_CH_TO_2TON(x, N) (ROUNDF((x)*(Float)(1<<(N))) / (Float)(1<<(N)))#   define CHM_FROM_FLOAT(flt) (flt)#   define FLOAT_FROM_CHM(ch) (ch)#endif    typedef Float ChPPXFormType;#   define MULT_CHPP(a,b) ((a)*(b))#   define CHPP_FROM_FLOAT(flt) (flt)// Downmix transform    typedef Float ChDnMixType;#   define MULT_CHDN(a,b) ((a)*(b))#   define CHDN_FROM_FLOAT(flt) (flt)// Half transform for mllm    typedef Float HTFilterType;#   define MULT_HTFT(a,b) ((a)*(b))#   define HTFT_FROM_FLOAT(flt) (flt)#   define MULT_CBP1(a,b) MULT_BP1(a,b)#   define MULT_CBP2(a,b) MULT_BP2(a,b)// fix-point binary points conversion factors// convert float or double to BP1 integer ( -1.0 <= x < +1.0 )#define NF2BP1 2// convert float or double to BP2 integer ( -2.0 <= x < +2.0 )#define NF2BP2 1// Another form of floating point     typedef Float FastFloat;// Type for holding quantization magnitide returned by prvWeightedQuantization    typedef Float QuantFloat;// Some utility functions with obvious meaning#   define DIV2(a) ((a)*0.5f)#   define MUL2(a) ((a)*2.0f)#   define DIV4(a) ((a)*0.25f)#   define MUL4(a) ((a)*4.0f)#   define MUL8(a) ((a)*8.0f)#   define INTEGER_ONLY(a)#   define INTEGER_OR_INT_FLOAT(a,b) b#define MULT_SQRT2(a) ((a) * (FLT_SQRT2))#endif  // either BUILD_INTEGER or BUILD_INT_FLOAT#ifdef BUILD_INTEGER#define BUILD_INTEGER_LPC#endif// always build integer lpc as long as not using PLATFORM_LPC_DIRECT#ifndef PLATFORM_LPC_DIRECT#define BUILD_INTEGER_LPC#endif // PLATFORM_LPC_DIRECT#ifdef BUILD_INTEGER_LPC//****************************************************************************//         Types, constants related to LPC.//         Lot of these could be moved to constants.h or lpcConst.h for cleanliness//****************************************************************************//  LSP (aka LSF), used for inverse quantized LSF.    typedef IntW LspType;#   define FRACT_BITS_LSP 30#   define LSP_SCALE (1<<FRACT_BITS_LSP)#   define LSP_FROM_FLOAT(a) ((LpType)((a)*LSP_SCALE))#   define MULT_LSP(a,b) (I32)((((I64)(a))*((I64)(b)))>>FRACT_BITS_LSP)// MULT_LSP may be redefined by processor specific code in macros_cpu.h//  LP, used for P, Q, and LPC values    typedef IntW LpType;#   ifndef MATCH_ARM_WAY#       define FRACT_BITS_LP 27#   else#       define FRACT_BITS_LP 26#   endif#   define LP_SCALE (1<<FRACT_BITS_LP)#   define FLOAT_FROM_LP(a) ((Float)((a)*(1.0f/LP_SCALE)))#   define LP_FROM_FLOAT(a) ((LpType)((a)*LP_SCALE))//  LP Spectrum: used during FFT of LPC values//  LP Spectrum power: sum-squares of FFT output    typedef IntW LpSpecType;//                Uses 64-bit intermediates#   ifndef MATCH_ARM_WAY#       define FRACT_BITS_LP_SPEC 25#   else        //  ARM's use of 26 instead of 25 produces BIG relative errors compared to LPC_COMPARE        //  at least when using the old version of the Lpc code.//#       define FRACT_BITS_LP_SPEC 26#       define FRACT_BITS_LP_SPEC 25#   endif    typedef U64 LpSpecPowerType;#   define BITS_LP_SPEC_POWER 64#   define FRACT_BITS_LP_SPEC_POWER 30 #   define QR_FRACTION_FRAC_BITS 24#   define QR_EXPONENT_FRAC_BITS 29#   define LP_SPEC_SCALE (1<<FRACT_BITS_LP_SPEC)#   define LP_SPEC_POWER_SCALE ((float)(1L<<FRACT_BITS_LP_SPEC_POWER))#   define LP_SPEC_FROM_FLOAT(a) ((LpSpecType)((a)*LP_SPEC_SCALE))#   define LP_SPEC_POWER_FROM_FLOAT(a) ((LpSpecType)((a)*LP_SPEC_POWER_SCALE))#   define FLOAT_FROM_LP_SPEC(a) ((Float)((a)*(1.0f/LP_SPEC_SCALE)))#   define LP_SPEC_FROM_LP(a) ((LpSpecType)((a)>>(FRACT_BITS_LP-FRACT_BITS_LP_SPEC)))//  Weights, computed from LPC (and Bark?).    typedef UIntW WeightType;#ifdef BUILD_INTEGER    typedef UIntW FinalWeightType;#   define FINALWEIGHT_FROM_FLOAT(flt) WEIGHT_FROM_FLOAT(flt)#   define FINALWEIGHT_FROM_WEIGHT(wt) (wt)#else    typedef Float FinalWeightType;#   define FINALWEIGHT_FROM_FLOAT(flt) (flt)#   define FINALWEIGHT_FROM_WEIGHT(wt) FLOAT_FROM_WEIGHT(wt)#endif//               We see weight factor values upto 64.53440857: 7 bits enough to cover integer part, //               leaving upto 25 bits for fraction. However, only 21 bits of fraction are generated //               upstream, making other 4 bits zero, even if used.#   ifndef MATCH_ARM_WAY#       define WEIGHTFACTOR_FRACT_BITS     21#   else#       define WEIGHTFACTOR_FRACT_BITS     25#   endif#   define WEIGHT_FROM_FLOAT(a) ((WeightType)((a)*(1<<WEIGHTFACTOR_FRACT_BITS)))#   define FLOAT_FROM_WEIGHT(a) ((Float)((a)*(1.0f/(1<<WEIGHTFACTOR_FRACT_BITS))))// convert float or double to BP2 integer ( -2.0 <= x < +2.0 )#define NF2BP2LPC 0x3FFFFFFF// Fractional Type with range -2.0 <= x < 2.0 used by FFT Trig Recurrsion     typedef I32 BP2LPCType;#   define BP2LPC_FRAC_BITS 30#   define BP2LPC_FRAC_SCALE NF2BP2LPC#   define BP2LPC_FROM_FLOAT(flt) ((BP2LPCType)((flt)*BP2LPC_FRAC_SCALE))#   define FLOAT_FROM_BP2LPC(bp2) ((bp2)/((Float)BP2LPC_FRAC_SCALE))#if defined(BUILD_INTEGER)#   define BP2LPC_FROM_BP1(bp1) ((bp1)>>1)#   define BP2LPC_FROM_BP2(bp2) (bp2)#else#   define BP2LPC_FROM_BP1(bp1) BP2LPC_FROM_FLOAT(bp1)#   define BP2LPC_FROM_BP2(bp2) BP2LPC_FROM_FLOAT(bp2)#endif#   define MULT_BP2LPC(a,b) MULT_HI_DWORD_DOWN((a),(b))#   define MULT_BP2LPC_I32(a,b) ((I32) (((a) * (I64) (b)) >> BP2LPC_FRAC_BITS))// Fraction is stored at 2^32 (BP0)#define UBP0_FROM_FLOAT_LPC(x) ((U32)(x*4294967296.0F))#   define DIV2LPC(a) ((a)>>1)#   define MUL2LPC(a) ((a)<<1)#   define INTEGER_ONLY_LPC(a) a#   define INTEGER_OR_INT_FLOAT_LPC(a,b) a#else // BUILD_INTEGER_LPC//****************************************************************************//         Types, constants related to LPC.//****************************************************************************//  LSP (aka LSF), used for inverse quantized LSF.    typedef Float LspType;#   define LSP_FROM_FLOAT(a) ((LspType)(a))#   define MULT_LSP(x,y) ((x)*(y))// LP, used for P, Q, and LPC values    typedef Float LpType;#   define LP_FROM_FLOAT(a) ((LpType)(a))#   define FLOAT_FROM_LP(a) ((Float)(a))// LP Spectrum: used during FFT of LPC values// LP Spectrum power: sum-squares of FFT output    typedef Float LpSpecType;    typedef Float LpSpecPowerType;#   define LP_SPEC_FROM_FLOAT(a) ((LpSpecType)(a))#   define FLOAT_FROM_LP_SPEC(a) ((Float)(a))#   define LP_SPEC_FROM_LP(a)    ((LpSpecType)(a))//  Weights, computed from LPC   (and Bark?).    typedef Float WeightType;    typedef Float FinalWeightType;#   define FINALWEIGHT_FROM_FLOAT(flt) (flt)#   define FINALWEIGHT_FROM_WEIGHT(wt) (wt)#   define WEIGHT_FROM_FLOAT(a) ((WeightType)(a))#   define FLOAT_FROM_WEIGHT(a) ((Float)(a))// Fractional Type used by FFT Trig Recurrsion     typedef Float BP2LPCType;#   define BP2LPC_FRAC_BITS 0#   define BP2LPC_FRAC_SCALE 1#   define BP2LPC_FROM_FLOAT(flt) ((BP2LPCType)(flt))#   define FLOAT_FROM_BP2LPC(bp2) ((Float)(bp2))#   define BP2LPC_FROM_BP1(bp1) (bp1)#   define BP2LPC_FROM_BP2(bp2) (bp2)#   define MULT_BP2LPC(a,b) ((a)*(b))#   define MULT_BP2LPC_I32(a,b) ((a) * (b))#   define DIV2LPC(a) ((a)*0.5f)#   define MUL2LPC(a) ((a)*2.0f)#   define INTEGER_ONLY_LPC(a)#   define INTEGER_OR_INT_FLOAT_LPC(a,b) b#endif // BUILD_INTEGER_LPC//INLINE Float FloatFromCoeff(const CoefType c, int ls);/*{  int rs = ls + COEF_FRAC_BITS;  Float s = (rs > 0) ? (1.0f/((I64)1<<rs)) : (Float)((I64)1<<-rs);  return (Float)c*s;}*///INLINE Double DoubleFromCoeff(const CoefType c, int ls);/*{  int rs = ls + COEF_FRAC_BITS;  Double s = (rs > 0) ? (1.0/((I64)1<<rs)) : (Double)((I64)1<<-rs);  return (Double)c*s;}*///INLINE I32 CoeffFromDouble(const Double c, int ls);/*{  int rs = ls + COEF_FRAC_BITS;  Double s = (rs > 0) ? (1.0/((I64)1<<rs)) : (Double)((I64)1<<-rs);  return (I32)((Double)c/s);}*///INLINE I32 CoeffFromFloat(const Float c, int ls);/*{  int rs = ls + COEF_FRAC_BITS;  Double s = (rs > 0) ? (1.0/((I64)1<<rs)) : (Double)((I64)1<<-rs);  return (I32)((Double)c/s);}*/#define CH_FFC(c) (c)/*#ifdef BUILD_INTEGER#define WMACFF(c) CoeffFromFloat(c, ppcinfo->m_cLeftShiftBitsTotal)#define WMADFC(c) DoubleFromCoeff(c, ppcinfo->m_cLeftShiftBitsTotal)#define WMACFD(c) CoeffFromDouble(c, ppcinfo->m_cLeftShiftBitsTotal)#define WMAFFC(c) FloatFromCoeff(c, ppcinfo->m_cLeftShiftBitsTotal)#define WMACFFPQ(c) CoeffFromFloat(c, ppcinfo->m_cLeftShiftBitsTotal-ppcinfo->m_cLeftShiftBitsQuant)#define WMADFCPQ(c) DoubleFromCoeff(c, ppcinfo->m_cLeftShiftBitsTotal-ppcinfo->m_cLeftShiftBitsQuant)#define WMAFFCPQ(c) FloatFromCoeff(c, ppcinfo->m_cLeftShiftBitsTotal-ppcinfo->m_cLeftShiftBitsQuant)#endif*/// some utility macros that are type specific to avoid the compiler's type conversion rules.#define COEF_ABS(a) (((a)<0) ? -(a) : (a))#define BPX_ABS(a) (((a)<0) ? -(a) : (a))#define ABS(x) ((x) > 0 ? (x) : -(x))#if !(defined(REFERENCE_RAND_24) || defined(REFERENCE_RAND_16))    //****************************************************************************    // quick and dirty rand generator, assuming low word multiply, only works for     // 32-bit machines see Numerical Recipes p.284.      // Note this is the referenced generator but the 24-bit or 16-bit versions can    // be used for compliance comparisions with 24-bit or 16-bit implementations.    //****************************************************************************    typedef struct tagRandState {        I32 iPrior;         // prior value        U32 uiRand;         // current value    } tRandState;#ifdef __GNUCOMP_VERSION    INLINE I32 quickRand(tRandState* ptRandState);    INLINE void RandStateClear(tRandState* ptRandState);#else    	INLINE I32 quickRand(tRandState* ptRandState)    {        const U32 a = 1664525;        const U32 c = 1013904223;        I32 iTemp, iTemp1;        //a*x + c has to be done with unsigned 32 bit        ptRandState->uiRand =  a * ptRandState->uiRand + c;        // uiRand values starting from a 0 seed are: 0x3c6ef35f, 0x47502932, 0xd1ccf6e9, 0xaaf95334, 0x6252e503, 0x9f2ec686, 0x57fe6c2d, ...        // do not change the above - this reference generator has been extensively tested and has excellent randomness properties        // a truism in the world of random number generator theory and practice is:        // "any change, no matter how small, can and will change the properties of the generator and must be fully tested"        // In case you don't know, it can easily take a person-month to fully test a generator.            // Notwithstanding the above, it is fair to take a function of a random number to shape its range or distribution.        // This we do below to give it a triangular distrbution between -2.5 and 2.5 to roughly approximate a Guassian distribution.

⌨️ 快捷键说明

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