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

📄 encg729fp.c

📁 G.729 and G.723.1 codecs x86 (and x86_64) Linux and FreeBSD source code for Asterisk open source PBX
💻 C
📖 第 1 页 / 共 5 页
字号:
      /* Find the total excitation. */      ippsInterpolateC_G729_32f(&Excitation[NSbfr], pitchGain, FixedCodebookExc, codeGain, &Excitation[NSbfr], SUBFR_LEN);      /* Update error function for taming process. */      UpdateExcErr_G729(pitchGain, pitchDelay, encoderObj->ExcitationError);      if(codecType!=G729A_CODEC){         /* Find synthesis speech corresponding to Excitation.  */         ippsSynthesisFilter_G729_32f(pQntLPC, aqLen, &Excitation[NSbfr], &pSynth[NSbfr], SUBFR_LEN, &encoderObj->SynFltMemory[BWD_LPC_ORDER-aqLen]);         for(j=0; j<BWD_LPC_ORDER; j++) encoderObj->SynFltMemory[j] = pSynth[NSbfr+SUBFR_LEN-BWD_LPC_ORDER+j];         /* Update filters memories. */         for (i = SUBFR_LEN-BWD_LPC_ORDER, j = 0; i < SUBFR_LEN; i++, j++) {            encoderObj->ErrFltMemory[j] = SpeechWnd[NSbfr+i] - pSynth[NSbfr+i];            encoderObj->WeightedFilterMemory[j]  = TargetVector[i] - pitchGain*FltAdaptExc[i] - codeGain*FltFixedCodebookExc[i];         }      } else {         /* Update filters memories. */         for (i = SUBFR_LEN-LPC_ORDER, j = 0; i < SUBFR_LEN; i++, j++)            encoderObj->WeightedFilterMemory[j]  = TargetVector[i] - pitchGain*FltAdaptExc[i] - codeGain*FltFixedCodebookExc[i];      }      pLPC   += apLen+1;      pQntLPC   += aqLen+1;   }   encoderObj->prevLPCMode = LPCMode;   /* Update signal for next frame.                    */   ippsMove_32f(&encoderObj->OldSpeechBuffer[FRM_LEN], &encoderObj->OldSpeechBuffer[0], SPEECH_BUFF_LEN-FRM_LEN);   ippsMove_32f(&encoderObj->OldWeightedSpeechBuffer[FRM_LEN], &encoderObj->OldWeightedSpeechBuffer[0], PITCH_LAG_MAX);   ippsMove_32f(&encoderObj->OldExcitationBuffer[FRM_LEN], &encoderObj->OldExcitationBuffer[0], PITCH_LAG_MAX+INTERPOL_LEN);   if((codecType == G729_CODEC)&&(VADDecision != 1)) {      anau = EncodedParams;   } else if(codecType == G729E_CODEC) {      anau = EncodedParams+2;   } else {      anau = EncodedParams+1;   }   if((codecType == G729_CODEC)||(codecType == G729A_CODEC)) {      *frametype=3;      dst[0] = (Ipp8u)(anau[0] & 0xff);      dst[1] = (Ipp8u)((anau[1] & 0x3ff) >> 2);      dst[2] = (Ipp8u)(((anau[1] & 0x3) << 6) | ((anau[2]>>2)&0x3f) ); /* 2 + 6  */      /* 2 + 1 + 5*/      dst[3] = (Ipp8u)(((anau[2] & 0x3) << 6) | ((anau[3] & 0x1) << 5) | ((anau[4] & 0x1fff) >> 8) );      dst[4] = (Ipp8u)(anau[4] & 0xff); /* 8*/      dst[5] = (Ipp8u)(((anau[5] & 0xf)<<4) | ((anau[6] & 0x7f) >> 3)); /* 4 + 4*/      dst[6] = (Ipp8u)(((anau[6] & 0x7)<< 5) | (anau[7] & 0x1f)); /* 3 + 5*/      dst[7] = (Ipp8u)((anau[8] & 0x1fff) >> 5); /* 8*/      dst[8] = (Ipp8u)(((anau[8] & 0x1f) << 3) | ((anau[9] & 0xf) >> 1)); /* 5 + 3*/      dst[9] = (Ipp8u)(((anau[9] & 0x1) << 7) | (anau[10] & 0x7f)); /* 1 + 7*/   } else if(codecType == G729D_CODEC) {/* D */      *frametype=2;      dst[0] = (Ipp8u)( anau[0] & 0xff);                                                           /*8*/      dst[1] = (Ipp8u)( (anau[1] & 0x3ff) >> 2);                                                   /*8*/      dst[2] = (Ipp8u)( ((anau[1] & 0x3) << 6) | ((anau[2]>>2)&0x3f));                             /* 2 + 6  */      dst[3] = (Ipp8u)( ((anau[2] & 0x3) << 6) | ((anau[3]>>3)&0x3f));                             /* 2 + 6  */      dst[4] = (Ipp8u)( ((anau[3] & 0x7) << 5) | ((anau[4] & 0x3) << 3) | ((anau[5] >> 3)& 0x7));  /* 3 + 2 + 3 */      dst[5] = (Ipp8u)( ((anau[5] & 0x7) << 5) | ((anau[6] & 0xf) << 1)| ((anau[7] >> 8)& 0x1));  /* 3 + 4 + 1*/      dst[6] = (Ipp8u)( anau[7] & 0xff);                                                           /* 8*/      dst[7] = (Ipp8u)( (anau[8] & 0x3) << 6 | (anau[9] & 0x3f));                                  /* 2 + 6*/   } else if(codecType == G729E_CODEC) {/* E*/      *frametype=4;      if(LPCMode == 0) { /* Forward*/         dst[0] = (Ipp8u)( (anau[0] >> 2) & 0x3f);                                                  /* 2 + 6 */         dst[1] = (Ipp8u)( ((anau[0] & 0x3) << 6) | ((anau[1]>>4)&0x3f));                           /* 2 + 6 */         dst[2] = (Ipp8u)( ((anau[1] & 0xf) << 4) | ((anau[2]>>4)&0xf));                            /* 4 + 4 */         dst[3] = (Ipp8u)( ((anau[2] & 0xf) << 4) | ((anau[3]&0x1)<<3) | ((anau[4]>>4)&0x7));       /* 4 + 1 + 3 */         dst[4] = (Ipp8u)( ((anau[4] & 0xf) << 4) | ((anau[5]>>3)&0xf));                            /* 4 + 4 */         dst[5] = (Ipp8u)( ((anau[5] & 0x7) << 5) | ((anau[6]>>2)&0x1f));                           /* 3 + 5 */         dst[6] = (Ipp8u)( ((anau[6] & 0x3) << 6) | ((anau[7]>>1)&0x3f));                           /* 2 + 6 */         dst[7] = (Ipp8u)( ((anau[7]& 0x1) << 7)  | (anau[8]&0x7f));                                /* 1 + 7 */         dst[8] = (Ipp8u)( ((anau[9]& 0x7f) << 1) | ((anau[10]>>4)&0x1));                           /* 7 + 1 */         dst[9] = (Ipp8u)( ((anau[10] & 0xf) << 4) | ((anau[11]>>3)&0xf));                          /* 4 + 4 */         dst[10] = (Ipp8u)( ((anau[11] & 0x7) << 5) | ((anau[12]>>2)&0x1f));                        /* 3 + 5 */         dst[11] = (Ipp8u)( ((anau[12] & 0x3) << 6) | ((anau[13]>>1)&0x3f));                        /* 2 + 6 */         dst[12] = (Ipp8u)( ((anau[13]& 0x1) << 7)  | (anau[14]&0x7f));                             /* 1 + 7 */         dst[13] = (Ipp8u)( ((anau[15]& 0x7f) << 1) | ((anau[16]>>6)&0x1));                         /* 7 + 1 */         dst[14] = (Ipp8u)( ((anau[16] & 0x3f) << 2));      } else { /* Backward*/         dst[0] = (Ipp8u)((3<<6) | ((anau[0] >> 2) & 0x3f));         dst[1] = (Ipp8u)(((anau[0] & 0x3) << 6) | ((anau[1]&0x1)<<5) | ((anau[2]>>8)&0x1f));       /* 2 + 1 + 5 */         dst[2] = (Ipp8u)(anau[2] & 0xff);         dst[3] = (Ipp8u)((anau[3] >> 2) & 0xff);                                                  /* 2 + 6 */         dst[4] = (Ipp8u)(((anau[3] & 0x3) << 6) | ((anau[4]>>1)&0x3f));                           /* 2 + 6 */         dst[5] = (Ipp8u)(((anau[4]& 0x1) << 7)  | (anau[5]&0x7f));                                /* 1 + 7 */         dst[6] = (Ipp8u)(((anau[6]& 0x7f) << 1) | ((anau[7]>>6)&0x1));                           /* 7 + 1 */         dst[7] = (Ipp8u)(((anau[7]&0x3f) << 2) | ((anau[8] >>3)&0x3));         dst[8] = (Ipp8u)(((anau[8] & 0x7) << 5) | ((anau[9]>>8)&0x1f));                        /* 3 + 5 */         dst[9] = (Ipp8u)(anau[9] & 0xff);         dst[10] = (Ipp8u)((anau[10] >> 2) & 0xff);                                                  /* 2 + 6 */         dst[11] = (Ipp8u)(((anau[10] & 0x3) << 6) | ((anau[11]>>1)&0x3f));                           /* 2 + 6 */         dst[12] = (Ipp8u)(((anau[11]& 0x1) << 7)  | (anau[12]&0x7f));                                /* 1 + 7 */         dst[13] = (Ipp8u)(((anau[13]& 0x7f) << 1) | ((anau[14]>>6)&0x1));                           /* 7 + 1 */         dst[14] = (Ipp8u)(((anau[14] & 0x3f) << 2));      }   }   CLEAR_SCRATCH_MEMORY(encoderObj);   return APIG729_StsNoErr;}G729_CODECFUN(  APIG729_Status, apiG729FPEncodeVAD,         (G729FPEncoder_Obj* encoderObj,const Ipp16s* src, Ipp16s* dst, G729Codec_Type codecType, Ipp32s *frametype )){   LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardAutoCorr, (LPC_ORDERP2+1),encoderObj);       /* Autocorrelations (forward) */    LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardLPC, LPC_ORDERP1*2,encoderObj);      /* A(z) forward unquantized for the 2 subframes */    LOCAL_ALIGN_ARRAY(32, Ipp32f, forwardQntLPC, LPC_ORDERP1*2,encoderObj);    /* A(z) forward quantized for the 2 subframes */    LOCAL_ALIGN_ARRAY(32, Ipp32f, WeightedLPC1, BWD_LPC_ORDERP1,encoderObj);        /* A(z) with spectral expansion         */    LOCAL_ALIGN_ARRAY(32, Ipp32f, WeightedLPC2, BWD_LPC_ORDERP1,encoderObj);        /* A(z) with spectral expansion         */   LOCAL_ALIGN_ARRAY(32, Ipp32f, TmpAlignVec, WINDOW_LEN,encoderObj);   LOCAL_ARRAY(Ipp32f, TmpAutoCorr, LPC_ORDERP1,encoderObj);   LOCAL_ARRAY(Ipp32f, forwardReflectCoeff, LPC_ORDER,encoderObj);   LOCAL_ARRAY(Ipp32f, CurrLSP, LPC_ORDER,encoderObj);   LOCAL_ARRAY(Ipp32f, CurrLSF, LPC_ORDER,encoderObj);   LOCAL_ARRAY(Ipp32f, tmpLSP, LPC_ORDER,encoderObj);   LOCAL_ARRAY(Ipp32f, InterpolatedLSF, LPC_ORDER,encoderObj);   LOCAL_ARRAY(Ipp32s, EncodedParams, 4,encoderObj);   LOCAL_ARRAY(Ipp32f, gamma1, 2,encoderObj);   LOCAL_ARRAY(Ipp32f, gamma2, 2,encoderObj);   Ipp32f *SpeechWnd, *pWindow;   Ipp32f *newSpeech;   /* Weighted speech vector */   Ipp32f *WeightedSpeech;   /* Excitation vector */   Ipp32f *Excitation;   Ipp32f *pError=NULL;   Ipp32f *pSynth=NULL;   Ipp32s *anau;   Ipp16s isVAD;   Ipp32f tmp_lev;   Ipp32s VADDecision, i;   Ipp32f EnergydB;   IppStatus sts;   if(NULL==encoderObj || NULL==src || NULL ==dst)      return APIG729_StsBadArgErr;   if ((codecType != G729_CODEC)&&(codecType != G729A_CODEC)      &&(codecType != G729D_CODEC)&&(codecType != G729E_CODEC))      return APIG729_StsBadCodecType;   if(encoderObj->objPrm.objSize <= 0)      return APIG729_StsNotInitialized;   if(ENC_KEY != encoderObj->objPrm.key)      return APIG729_StsBadCodecType;   isVAD = (Ipp16s)(encoderObj->objPrm.mode == G729Encode_VAD_Enabled);   if(!isVAD) return APIG729_StsNoErr;   ippsZero_32f(WeightedLPC1,BWD_LPC_ORDERP1);   ippsZero_32f(WeightedLPC2,BWD_LPC_ORDERP1);   anau = &EncodedParams[0];   newSpeech = encoderObj->OldSpeechBuffer + SPEECH_BUFF_LEN - FRM_LEN;         /* New speech     */   SpeechWnd     = newSpeech - LOOK_AHEAD_LEN;                    /* Present frame  */   pWindow   = encoderObj->OldSpeechBuffer + SPEECH_BUFF_LEN - WINDOW_LEN;        /* For LPC window */   WeightedSpeech    = encoderObj->OldWeightedSpeechBuffer + PITCH_LAG_MAX;   Excitation    = encoderObj->OldExcitationBuffer + PITCH_LAG_MAX + INTERPOL_LEN;   if(codecType!=G729A_CODEC){      pError  = encoderObj->ErrFltMemory + BWD_LPC_ORDER;      pSynth = encoderObj->SynthBuffer + BWD_SYNTH_MEM;   }   if (encoderObj->sFrameCounter == 32767) encoderObj->sFrameCounter = 256;   else encoderObj->sFrameCounter++;   ippsConvert_16s32f(src,newSpeech,FRM_LEN);   ippsIIR_32f_I(newSpeech,FRM_LEN,encoderObj->iirstate);   ownAutoCorr_G729_32f(pWindow, LPC_ORDERP2, forwardAutoCorr,TmpAlignVec);             /* Autocorrelations */   ippsCopy_32f(forwardAutoCorr, TmpAutoCorr, LPC_ORDERP1);   /* Lag windowing    */   ippsMul_32f_I(lwindow, &forwardAutoCorr[1], LPC_ORDERP2);   /* Levinson Durbin  */   tmp_lev = 0;   sts = ippsLevinsonDurbin_G729_32f(forwardAutoCorr, LPC_ORDER, &forwardLPC[LPC_ORDERP1], forwardReflectCoeff, &tmp_lev);   if(sts == ippStsOverflow) {      ippsCopy_32f(encoderObj->OldForwardLPC,&forwardLPC[LPC_ORDERP1],LPC_ORDER+1);      forwardReflectCoeff[0] = encoderObj->OldForwardRC[0];      forwardReflectCoeff[1] = encoderObj->OldForwardRC[1];   } else {      ippsCopy_32f(&forwardLPC[LPC_ORDERP1],encoderObj->OldForwardLPC,LPC_ORDER+1);      encoderObj->OldForwardRC[0] = forwardReflectCoeff[0];      encoderObj->OldForwardRC[1] = forwardReflectCoeff[1];   }   /* Convert A(z) to lsp */   if(codecType==G729A_CODEC){      ippsLPCToLSP_G729A_32f(&forwardLPC[LPC_ORDERP1], encoderObj->OldLSP, CurrLSP);   } else {      ippsLPCToLSP_G729_32f(&forwardLPC[LPC_ORDERP1], encoderObj->OldLSP, CurrLSP);   }   if (encoderObj->objPrm.mode == G729Encode_VAD_Enabled) {      ownACOS_G729_32f(CurrLSP, CurrLSF, LPC_ORDER);      VoiceActivityDetect_G729_32f(forwardReflectCoeff[1], CurrLSF, forwardAutoCorr, pWindow, encoderObj->sFrameCounter,                  encoderObj->prevVADDec, encoderObj->prevPrevVADDec, &VADDecision, &EnergydB,encoderObj->vadMem,TmpAlignVec);      if(codecType!=G729A_CODEC){         MusicDetection_G729E_32f( encoderObj, codecType, forwardAutoCorr[0],forwardReflectCoeff, &VADDecision, EnergydB,encoderObj->msdMem,TmpAlignVec);      }      UpdateCNG(TmpAutoCorr, VADDecision,encoderObj->cngMem);   } else VADDecision = 1;   if(VADDecision == 0) {      if(codecType==G729A_CODEC){         UpdateVad_A(encoderObj, Excitation, WeightedSpeech, SpeechWnd, anau);      } else {         /* Inactive frame */         ippsCopy_32f(&encoderObj->SynthBuffer[FRM_LEN], &encoderObj->SynthBuffer[0], BWD_SYNTH_MEM);         /* Find interpolated LPC parameters in all subframes unquantized.      *         * The interpolated parameters are in array forwardLPC[] of size (LPC_ORDER+1)*4      */         if( encoderObj->prevLPCMode == 0) {            ippsInterpolateC_G729_32f(encoderObj->OldLSP, 0.5f, CurrLSP, 0.5f, tmpLSP, LPC_ORDER);            ippsLSPToLPC_G729_32f(tmpLSP, forwardLPC);            ownACOS_G729_32f(tmpLSP, InterpolatedLSF, LPC_ORDER);            ownACOS_G729_32f(CurrLSP, CurrLSF, LPC_ORDER);         } else {            /* no interpolation */            /* unquantized */            ippsLSPToLPC_G729_32f(CurrLSP, forwardLPC); /* Subframe 1 */            ownACOS_G729_32f(CurrLSP, CurrLSF, LPC_ORDER);  /* transformation from LSP to LSF (freq.domain) */            ippsCopy_32f(CurrLSF, InterpolatedLSF, LPC_ORDER);      /* Subframe 1 */         }         if (encoderObj->sGlobalStatInd > 10000) {            encoderObj->sGlobalStatInd -= 2621;            if(encoderObj->sGlobalStatInd < 10000) encoderObj->sGlobalStatInd = 10000 ;         }         encoderObj->isBWDDominant = 0;         encoderObj->fInterpolationCoeff = 1.1f;         ippsCopy_32f(CurrLSP, encoderObj->OldLSP, LPC_ORDER);         PWGammaFactor_G729(gamma1, gamma2, InterpolatedLSF, CurrLSF, forwardReflectCoeff,&encoderObj->isSmooth, encoderObj->LogAreaRatioCoeff);         UpdateVad_I(encoderObj, Excitation, forwardLPC, WeightedSpeech, gamma1, gamma2, pSynth,                     pError, SpeechWnd, anau, codecType);         /* update previous filter for next frame */         ippsCopy_32f(&forwardQntLPC[LPC_ORDERP1], encoderObj->PrevFlt, LPC_ORDERP1);         for(i=LPC_ORDERP1; i <BWD_LPC_ORDERP1; i++) encoderObj->PrevFlt[i] = 0.f;      }      encoderObj->prevLPCMode = 0;      encoderObj->fBetaPreFilter = PITCH_SHARPMIN;      /* Update memories for next frames */      ippsMove_32f(&encoderObj->OldSpeechBuffer[FRM_LEN], &encoderObj->OldSpeechBuffer[0], SPEECH_BUFF_LEN-FRM_LEN);      ippsMove_32f(&encoderObj->OldWeightedSpeechBuffer[FRM_LEN], &encoderObj->OldWeightedSpeechBuffer[0], PITCH_LAG_MAX);      ippsMove_32f(&encoderObj->OldExcitationBuffer[FRM_LEN], &encoderObj->OldExcitationBuffer[0], PITCH_LAG_MAX+INTERPOL_LEN);      anau = EncodedParams+1;      if(EncodedParams[0] == 0){ /* untransmitted*/         *frametype=0;      }else{         *frametype=1; /* SID*/         dst[0] = (Ipp16s)anau[0]; /* Switched predictor index of LSF quantizer: 1 LSB */         dst[1] = (Ipp16s)anau[1]; /* 1st stage vector of LSF quantizer: 5 LSB*/         dst[2] = (Ipp16s)anau[2]; /* 2nd stage vector of LSF quantizer: 4 LSB*/         dst[3] = (Ipp16s)anau[3]; /* Gain (Energy): 5 LSB     */      }      CLEAR_SCRATCH_MEMORY(encoderObj);      return APIG729_StsNoErr;   }   encoderObj->sCNGSeed = INIT_SEED_VAL;   encoderObj->prevPrevVADDec = encoderObj->prevVADDec;   encoderObj->prevVADDec = VADDecision;

⌨️ 快捷键说明

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