📄 g723enc.c
字号:
temp = ptrAcf[i]>>2; /* + 2 margin bits */ L_temp0 += 2 * RC[i] * temp; } temp = Cnvrt_32s16s(((alpha * 7000)+(short)0x4000)>>15); /* Itakura dist threshold: 7000 */ L_temp1 = temp + alpha; temp = ShRC + 9; /* 9 = Lpc_justif. * 2 - 15 - 2 */ L_temp1 <<= temp; if(L_temp0 < L_temp1) diff = 1; else diff = 0; return(diff);}void ComputePastAvFilter(g723enc_obj *g723enc,short *SidLpc){ int i, j; short *ptr_Acf; int *L_sumAcf; short sh1, temp; int L_acc0; short *Corr; // printf("Welcome to ComputePastAvFilter\n"); L_sumAcf=(int *)malloc((lpclen+1)*sizeof(int)); Corr=(short *)malloc((lpclen+1)*sizeof(short)); /* Search ShAcf min */ sh1 =g723enc->AutoCorrSfs[1]; for(i=2; i <= NbAvAcf; i ++) { temp=g723enc->AutoCorrSfs[i]; if(temp < sh1) sh1 = temp; } sh1 += 14; /* 2 bits of margin : NbAvAcf <= 4 */ /* Compute sum of NbAvAcf frame-Acfs */ for(j=0; j <= lpclen; j++) L_sumAcf[j] = 0; ptr_Acf = g723enc->AutoCorr + lpclen+1; for(i=1; i <= NbAvAcf; i ++) { temp = sh1 - g723enc->AutoCorrSfs[i]; for(j=0; j <= lpclen; j++) { L_acc0 = (int)(*ptr_Acf++); if(temp<0) L_acc0 = L_acc0>>(-temp); /* shift right if temp<0 */ else L_acc0 = L_acc0<<temp; // L_acc0 is 29 bits ispite of symbol bit L_sumAcf[j] += L_acc0; } // L_sumAcf[j]=Acf[11+j]+Acf[22+j]+Acf[33+j] } /* Normalize */ temp = Exp_32s_Pos(L_sumAcf[0]); temp = 16 - temp; if(temp < 0) temp = 0; Corr[0] = (short)(L_sumAcf[0]>>temp); for(i=1; i<lpclen+1; i++) { Corr[i] = (short)(L_sumAcf[i]>>temp); } ippsLevinsonDurbin_G723_16s(Corr, &temp, &temp,SidLpc); free(L_sumAcf); free(Corr); return;}void Enc_by_frame(g723enc_obj *g723enc,short *sample,char *Vout,short rate,int *len){ int i; short temp[fsize]; short Dbuffer[pitchmax+fsize]; short lpc[lpclen*4]; short lsp[lpclen]; short Lev_Ener[4]; short HarmDelay[4]; short HarmGain[4]; short i_resp[sfsize]; short o_resp[sfsize]; short Sbuffer[sfsize]; short Sbuffer2[sfsize]; short Ftyp; short enVad=0; Line *line=(Line *)malloc(sizeof(Line)); line->Crc=0; enVad=rate>>4; rate&=(short)0x01; g723enc->rate=rate; if(rate==1) g723enc->times=120; /**format**/ ippsCopy_16s(sample,temp,fsize); /** encoder begins **/ HighPassFilter_G723_I(temp,fsize,g723enc->Hpf); ippsCopy_16s(g723enc->preDat,Dbuffer,2*sfsize); ippsCopy_16s(temp,&Dbuffer[2*sfsize],fsize); {// calculate AutoCorrelation Coefficience and change to lpc short AuCorr[4*(lpclen+1)]; short AuCorrSfs[4]; for(i=0;i<4;i++) { ippsAutoCorr_G723_16s(&Dbuffer[i*sfsize],&AuCorrSfs[i],&AuCorr[i*(lpclen+1)]); ippsLevinsonDurbin_G723_16s(&AuCorr[i*(lpclen+1)],&g723enc->SineDet,&Lev_Ener[i],&lpc[i*lpclen]); } UpdateSineDetector(&g723enc->SineDet); Update_Acf(g723enc,AuCorr,AuCorrSfs); } // compute the voice activity detect Ftyp=1; if(enVad){ VoiceActivityDetect_G723(temp,(short *)&g723enc->preSidLpc,(short *)&g723enc->preOlp,!(g723enc->SineDet<0),&i,&g723enc->Aen,g723enc->vadMem); // Ftyp = i; } // lpc to lsp and quantize lsp ippsLPCToLSF_G723_16s(&lpc[3*lpclen],g723enc->preLsp,lsp); ippsLSFQuant_G723_16s32s(lsp,g723enc->preLsp,&line->lspID); Mem_Shift(g723enc->preDat,temp); // do Perceptual Weighted filter for(i=0;i<4;i++) WeightFilter_G723(&temp[sfsize*i],&lpc[i*lpclen],&temp[i*sfsize],sfsize,g723enc->Pwf); // open loop search ippsCopy_16s(g723enc->preWght,Dbuffer,pitchmax); ippsCopy_16s(temp,&Dbuffer[pitchmax],fsize); i=3; ArrNorm_16s_I(Dbuffer,fsize+pitchmax,&i); for(i=0;i<2;i++) { ippsOpenLoopPitchSearch_G723_16s(&Dbuffer[pitchmax+i*2*sfsize],&line->olp[i]); g723enc->preOlp[i]=line->olp[i]; } // printf("%d %d\n",line->olp[0],line->olp[1]); if(Ftyp !=1) { // voice inactivity ippsCopy_16s(&temp[fsize-pitchmax],g723enc->preWght,pitchmax); Cod_Cng(g723enc,temp,&Ftyp,line,lpc,(char)rate); // printf("Etyp=%d\n",Ftyp); /* Update the ringing delays */ for( i = 0 ; i < 4; i++ ) { int j; /* Update exc_err */ UpdateErr(g723enc->preErr,line->olp[i>>1],line->closelag[i],line->adptgid[i],rate); for(j=sfsize;j<pitchmax;j++) g723enc->preHarm[j-sfsize]=g723enc->preHarm[j]; /* Combined filtering */ ippsCopy_16s(g723enc->sythRing,g723enc->perRing,lpclen); ippsSynthesisFilter_G723_16s(&lpc[i*lpclen],&temp[i*sfsize],g723enc->sythRing,Sbuffer); WeightFilter_G723(Sbuffer,&lpc[i*lpclen],&g723enc->preHarm[pitchmax-sfsize],sfsize,g723enc->perRing); /* Shift the harmonic noise shaping filter memory */ } } else { // voice active // do harmonic filter for(i=0;i<4;i++) ippsHarmonicSearch_G723_16s(line->olp[i>>1],&Dbuffer[pitchmax+i*sfsize],&HarmDelay[i],&HarmGain[i]); ippsCopy_16s(g723enc->preWght,Dbuffer,pitchmax); ippsCopy_16s(temp,&Dbuffer[pitchmax],fsize); ippsCopy_16s(&Dbuffer[fsize],g723enc->preWght,pitchmax); for(i=0;i<4;i++) HarmonicFilter(&Dbuffer[pitchmax+i*sfsize],HarmDelay[i],HarmGain[i],&temp[i*sfsize],sfsize); /* Inverse quantization of the LSP */ LSFQuantInv_G723_32s16s(line->lspID,g723enc->preLsp,lsp,line->Crc); LspInterpolation_G723(lsp,g723enc->preLsp,lpc); ippsCopy_16s(lsp,g723enc->preLsp,lpclen); for(i=0;i<4;i++) { ippsZero_16s(Sbuffer,sfsize); ippsZero_16s(i_resp,sfsize); ippsZero_16s(o_resp,sfsize); //calculate impulse response { int j; short impulse[sfsize]; short zero[sfsize]; short IIRstat[lpclen]; short Wstat[2*lpclen]; short nbuf[pitchmax+sfsize+3]; ippsZero_16s(Wstat,2*lpclen); ippsZero_16s(IIRstat,lpclen); ippsZero_16s(nbuf,pitchmax+sfsize); ippsZero_16s(impulse,sfsize); ippsZero_16s(zero,sfsize); impulse[0]=(short)0x4000; ippsSynthesisFilter_G723_16s(&lpc[i*lpclen],impulse,IIRstat,Sbuffer); WeightFilter_G723(Sbuffer,&lpc[i*lpclen],&nbuf[pitchmax],sfsize,Wstat); HarmonicFilter(&nbuf[pitchmax],HarmDelay[i],HarmGain[i],i_resp,sfsize); //calculate zero input response ippsCopy_16s(g723enc->sythRing,IIRstat,lpclen); ippsCopy_16s(g723enc->perRing,Wstat,2*lpclen); ippsCopy_16s(g723enc->sythRing,Wstat,lpclen); ippsCopy_16s(g723enc->preHarm,nbuf,pitchmax+sfsize); ippsSynthesisFilter_G723_16s(&lpc[i*lpclen],zero,IIRstat,Sbuffer); WeightFilter_G723(Sbuffer,&lpc[i*lpclen],&nbuf[pitchmax],sfsize,Wstat); //add previous state !!!!! ippsSub_16s(&temp[i*sfsize],&nbuf[pitchmax],&nbuf[pitchmax],sfsize); HarmonicFilter(&nbuf[pitchmax],HarmDelay[i],HarmGain[i],o_resp,sfsize); ippsCopy_16s(&nbuf[pitchmax],&g723enc->preHarm[pitchmax],sfsize); for(j=sfsize;j<pitchmax;j++) g723enc->preHarm[j-sfsize]=g723enc->preHarm[j]; } ippsCopy_16s(o_resp,Sbuffer,sfsize); //pitch adptive search { short fixedvec[sfsize]; int j; short olp,Lid,Gid; olp=line->olp[i>>1]; if((i&1)==0) { if(olp==pitchmin) olp++; if(olp>pitchmax-5) olp=pitchmax-5; } ippsAdaptiveCodebookSearch_G723(olp,Sbuffer,i_resp,g723enc->preExc,g723enc->preErr, &Lid, &Gid,(short)i,g723enc->SineDet,rate_vec[g723enc->rate]);//rate_vec[g723enc->rate] if((i&1)==0) { olp=olp-1+Lid; Lid=1; } line->olp[i>>1]=olp; line->closelag[i]=Lid; line->adptgid[i]=Gid; ippsDecodeAdaptiveVector_G723_16s(olp,Lid,Gid,g723enc->preExc,Sbuffer2,rate_vec[g723enc->rate]); ExcitationResidual_G723_16s(Sbuffer2,i_resp,Sbuffer); FixcdbkSearch_G723(line->olp[i>>1],line->closelag[i],line->adptgid[i],i_resp,Sbuffer,fixedvec,&line->grid[i],&line->traindrt[i],&line->ampindex[i],&line->pos[i],&line->sign[i],&g723enc->times,g723enc->rate,i); ippsDecodeAdaptiveVector_G723_16s(line->olp[i>>1],line->closelag[i],line->adptgid[i],g723enc->preExc,Sbuffer2,rate_vec[g723enc->rate]); // update the previous excitation signal for(j=sfsize;j<pitchmax;j++) (*g723enc).preExc[j-sfsize]=(*g723enc).preExc[j]; ShiftL_16s(fixedvec,1,fixedvec,sfsize); for(j=0;j<sfsize;j++) { Sbuffer[j]=Cnvrt_32s16s((int)Sbuffer2[j]+(int)fixedvec[j]); (*g723enc).preExc[pitchmax-sfsize+j]=Sbuffer[j]; } } // update previous Error UpdateErr(g723enc->preErr,line->olp[i>>1],line->closelag[i],line->adptgid[i],g723enc->rate); // update Sythesis Filter and PerWeight Filter { ippsCopy_16s(g723enc->sythRing,g723enc->perRing,lpclen); ippsSynthesisFilter_G723_16s(lpc,Sbuffer,g723enc->sythRing,Sbuffer); WeightFilter_G723(Sbuffer,&lpc[i*lpclen],&g723enc->preHarm[pitchmax-sfsize],sfsize,g723enc->perRing); } }//end of subframe loop g723enc->preFtyp=1; g723enc->CngSeed=12345; } PackLine(line,g723enc->rate,Vout,len,Ftyp); free(line); return ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -