📄 g723_codec.c
字号:
} /* End 5.3 kbps ACELP fixed-codebook search */ /* End of codebook search procedures */ /* Update the excitation history, e(n), (adaptive codebook) given the adaptive and fixed codebook excitation components, u(n) and v(n), i.e., compute the sequence e(n)=u(n)+v(n) The excitation components (above) are generated as described in [1], sections 2.17 and 2.18, pp. 13-14. Vector1[] contains u(n), Vector2[] contains v(n); the history e(n) is maintained in the variable pEncoderState->prevExcitation[] */ appsUpdateExcitationHistory_G723_16s(AdaptCBVect, FixedCBVect, pEncoderState->prevExcitation); /* Maintain local copy of the excitation history */ for ( j = 0; j < SFLEN; j ++ ) SpchAnalysisBuf[SubframeOffset+j] = pEncoderState->prevExcitation[j+MAXLAG-SFLEN]; /* Update error "taming" parameters defined in [2], and described in the readme file that accompanies the source. The fixed-point reference code appears in the module EXC_LBC.C, routines Test_Err() and Update_Err(). The resulting error "taming" parameters constrain the gain quantization search for the adaptive codebook. */ appsUpdateErrorTaming_G723_16s(EstimatedPitchLag[i], ClosedLoopPitchLagOffset[i], AdaptGainIndex[i], pEncoderState->errorTamingParams, bitRate); /* Update the combined filter memory, Si(z), as described in [1], section 2.19, pp. 14-15. Filter non-recursive and recursive memories are maintained in the encoder state variable buffers pEncoderState->combinedFilterZfir, and pEncoderState->combinedFilterZiir, respectively. */ appsUpdateCombinedFilter_G723_16s(PerceptLpc[i<<1], QLpc[i], SpchAnalysisBuf+SubframeOffset, pEncoderState->combinedFilterZfir, pEncoderState->combinedFilterZiir); } /* Reset comfort noise PRNG */ pEncoderState->randomSeedCNG = 12345; } /* Generate compressed bitstream */ appsPackBitstream_G723_8u(pDstBitstream->pBuf, &(pDstBitstream->len), QLsfIndex, EstimatedPitchLag, ClosedLoopPitchLagOffset, AdaptGainIndex, FixedCBQGainIndex, DiracTrainEnable, FixedCBGrid, FixedCBPulsePos, FixedCBPulseSign, &(pEncoderState->prevDTXFrameType), frameType, bitRate); /* Done */ return(1);} /* Encode_G723_16s8u *//******************************************************************************//// Name:// DecoderInit_G723//// Description:// Initialize G.723.1 decoder state //// Input Arguments: // pDecoderState - Pointer to uninitialized decoder state //// Output Arguments: // pDstDecoderState - Pointer to initialized decoder state//// Return Values: // 1 - No Error// 0 - Error//******************************************************************************/IppStatus DecoderInit_G723(IppG723DecoderState *pDstDecoderState){ int i; /* Clear frame erasure count */ pDstDecoderState->consecutiveFrameErasures = 0; /* Init LSF history */ for ( i = 0; i < LPC; i ++ ) pDstDecoderState->prevLsf[i] = lsfDcInitTable[i]; /* Init frame interpolation parameters that are used for generating excitations during erased frames */ /* Clear interpolation frame excitation gain */ pDstDecoderState->interpolationGain = 0; /* Clear interpolation frame adaptive codebook index */ pDstDecoderState->interpolationIndex = 0; /* Clear excitation history */ for ( i = 0; i < MAXLAG; i ++ ) pDstDecoderState->prevExcitation[i] = 0; /* Clear the random seed that is used to generate a random excitation for interpolated frames that are declared to be unvoiced, as described in [1], section 3.10, p. 22. */ pDstDecoderState->randomSeed = 0; /* Clear synthesis filter and formant postfilter memories */ for ( i = 0; i < LPC; i ++ ) { pDstDecoderState->synthesisFilterZiir[i] = 0; pDstDecoderState->formantPostfilterZfir[i] = 0; pDstDecoderState->formantPostfilterZiir[i] = 0; } /* Clear formant postfilter correlation coefficient history (k) as described in [1], section 3.8, p.20-21. */ pDstDecoderState->autoCorr = 0; /* Initialize gain scaling unit gain history ([1], section 3.9, p. 21) */ pDstDecoderState->prevGain = IPP_G723_GSU_INIT; /* Initialize CNG excitation generator random seed; many CNG excitation parameters are generated randomly, including LTP lag, LTP gain, fixed CB grid, pulse signs, and pulse positions. */ pDstDecoderState->randomSeedCNG = 12345; /* Initialize DTX frame type history; treat most recent frame as VAD==1 */ pDstDecoderState->prevDTXFrameType = 1; /* Summary of gain parameters G~sid - inverse quantized CNG SID gain parameter, quantized using 6-bit pseudo-log quantizer. G~t - target excitation gain; smoothed version of G~sid, i.e., G~t = G~sid, for VAD=1, 7/8 G~t-1 + 1/8 G~sid for VAD=0 */ /* Initialize quantized CNG excitation gain (G~sid, [3], p. 9); G~sid is the decoded value of the quantized CNG gain; it is used to derive the target excitation gain, G~t ([3], p. 10). */ pDstDecoderState->sidGain = 0; /* Initialize CNG target excitation gain (G~t, [3], p. 10); G~t defines the square root of the average energy required for the current frame synthetic excitation; it is used to derive the fixed excitation scaling gain, Gf. */ pDstDecoderState->targetExcitationGain = 0; /* Initialize SID LSF vector (p~t associated with Asid(z)); computed by CNG module, the synthesis filter associated with this coefficient vector is used to generate comfort noise ([3], A.4.4, p. 9). The vector is updated by the CNG module only during SID frames; for non-TX frames, it is maintained as part of the DTX state in order to provide coherent frame processing. Asid(z) is derived from either At(z) or Aavgp(z), depending on the distance between At(z) and Aavgp(z), i.e., large spectral changes induce a change in SID spectral coefficients; small spectral changes are ignored. */ for ( i = 0; i < LPC; i ++ ) pDstDecoderState->sidLsf[i] = lsfDcInitTable[i]; /* Initialize bitrate history */ pDstDecoderState->bitRate = IPP_SPCHBR_6300; return(1);} /* DecoderInit_G723 *//************************************************************************************//// Name:// Decode_G723_8u16s//// Description:// Decompress one 158/189-bit G.723.1 compressed bitstream frame into // one 30 ms output speech frame (240 samples, 16-bit linear PCM) by // application of the decoding procedure outlined in the // ITU G.723.1 standard ([1], sec. 3.1 - 3.11.).// . // Input Arguments: // pSrcBitStream - Compressed bitstream pointer, of length 20 or 24 bytes// for 5.3 or 6.3 kbps streams, respectively// erasureFrame - Erasure frame indicator: 1=erasure, 0=normal (non-erasure)// The decoder assumes that invalid or erased frames // are detected externally// enablePostFilter - Post filter on/off; 1=enable, 0=disable;// normally enabled; switch is required for test vector // compliance verification // pDecoderState - Pointer to decoder state prior to frame decode// // Output Arguments: // pDstSpeech - Pointer to output speech vector, of length 240 samples// pDecoderState - Pointer to the updated decoder state after frame decode//// Returns: // 1 - No Error.// 0 - Bad Arguments.//**************************************************************************************/IppStatus Decode_G723_8u16s(IppBitstream *pSrcBitstream, IppPcmStream *pDstSpeech, Ipp16s erasureFrame, int enablePostFilter, IppG723DecoderState *pDecoderState){ int i; /* general-purpose loop index */ Ipp32s QLsfIndex; /* decoded LSF quantization index */ Ipp16s EstimatedPitchLag[SFNUM]; /* decoded OLPS derived pitch neighborhood for subframes 0, 2 */ Ipp16s ClosedLoopPitchLagOffset[SFNUM]; /* decoded closed-loop offsets to estimated pitch lags */ Ipp16s DiracTrainEnable[SFNUM]; /* decoded MP-MLQ pulse train usage flag: 0=off, 1=on */ Ipp16s AdaptGainIndex[SFNUM]; /* decoded index of quantized adaptive codebook gains */ Ipp16s FixedCBQGainIndex[SFNUM]; /* decoded index of quantized fixed codebook gains */ Ipp16s FixedCBGrid[SFNUM]; /* decoded even/odd fixed codebook grid parameters */ Ipp16s FixedCBPulseSign[SFNUM]; /* decoded fixed codebook pulse sign bits */ Ipp32s FixedCBPulsePos[SFNUM]; /* decoded fixed codebook pulse positions */ Ipp16s Lsf[LPC]; /* quantized LSF vector */ Ipp16s InterpLsf[LPC]; /* subframe interpolated LSFs (in-place) */ Ipp16s QLpc[SFNUM][LPC]; /* subframe interpolated LPCs, complete set (all subframes) */ Ipp16s AdaptCBVect[SFLEN]; /* synthesized adaptive codebook vector */ Ipp16s FixedCBVect[SFLEN]; /* synthesized fixed codebook vector */ Ipp16s Delay[SFNUM]; /* pitch postfilter delay parameter (Mb or Mf) */ Ipp16s Gain[SFNUM]; /* pitch postfilter gain parameter (gamma_ltp * g_f or gamma_ltp * g_b) */ Ipp16s ScalingGain[SFNUM]; /* pitch postfilter scaling gain parameter (g_p) */ Ipp32s SpeechEnergyEstimate; /* estimated speech energy used in gain scaling postprocessor */ Ipp16s Excitation[FLEN+MAXLAG]; /* excitation processing and history buffer */ Ipp16s ExcitationNorm[FLEN+MAXLAG]; /* normalized excitation buffer */ Ipp16s ExcitationPPF[FLEN]; /* final excitation buffer; either pitch-postfiltered or erasure */ Ipp16s SubframeOffset; /* excitation/speech synthesis buffer subframe base address */ Ipp16s frameType; /* frame type: 0=NonTX, 2=SID, 1=voice activity */ Ipp16s *outputSpeech; /* output speech buffer pointer */ /* Unpack compressed bitstream parameters, check parameter validity, and update frame erasure statistics and parameters. The input bitstream is contained in the buffer pointed to by pSrcBitStream, and the parameters QLsfIndex through FixedCBPulseSign are decoded from the bitstream, as is the parameter bitRate. Invalid frames are detected and indicated by the erasureFrame parameter. This function also updates the consecutive erasure frame counter as well as the interpolation gain that is used for excitation synthesis on erasure frames. */ appsUnpackBitstream_G723_8u( pSrcBitstream->pBuf, &(pSrcBitstream->len), &QLsfIndex, EstimatedPitchLag, ClosedLoopPitchLagOffset, AdaptGainIndex, FixedCBQGainIndex, DiracTrainEnable, FixedCBGrid, FixedCBPulsePos, FixedCBPulseSign, &(pDecoderState->interpolationGain), &(pDecoderState->consecutiveFrameErasures), pDecoderState->prevDTXFrameType, &frameType, &(pDecoderState->bitRate), &erasureFrame); /* Process DTX silence frames: frametype == SID or NonTX */ if ( frameType != IPP_G723_FRAMETYPE_VOICE ) { /* Decode CNG gain parameters */ appsDecodeDTXGain_G723_16s( FixedCBQGainIndex[0], frameType, pDecoderState->prevDTXFrameType, &(pDecoderState->sidGain),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -