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

📄 g723dec.c

📁 嵌入式linux系统的网络编程(C++) 在ARM上实现视频会议 此程序获得全国研究生电子大赛一等奖 压缩包内为全部源码
💻 C
字号:
//g.723.1decode program implementation/* standard library interface */#include<stdlib.h>#include<stdio.h>#include<string.h>#include "g723dec.h"//typedef struct _g723dec_obj g723dec_obj;//typedef struct _Line     Line;void Decoder_Alloc(int *size){ *size=sizeof(g723dec_obj);}  void Init_Dec_Cng(g723dec_obj *g723dec){ g723dec->CngSeed=12345; g723dec->preFtyp=1; g723dec->SidGain=0; ippsCopy_16s(LspDcTable,g723dec->LspSid,lpclen);}void Init_Decoder(g723dec_obj **g723dec){ int i,size;  Decoder_Alloc(&size); *g723dec=(g723dec_obj *)malloc(size);  ippsZero_16s((short *)(*g723dec),sizeof(g723dec_obj)>>1); for(i=0;i<lpclen;i++)   (*g723dec)->preLsp[i]=LspDcTable[i];    Init_Dec_Cng(*g723dec);  (*g723dec)->GctrlGain=(short)0x1000;  // the sample set it to 0x1000 ? return;}void Dec_Cng(g723dec_obj *g723dec, short Ftyp, Line *line, short *Vout, short *lpc){  int i;  char *buf;  short *lsp_vec;  lsp_vec=(short *)malloc(lpclen*sizeof(short));  if(Ftyp==2) { // SID Frame   DecodeSIDGain_G723_16s(line->ampindex[0],&g723dec->SidGain);   LSFQuantInv_G723_32s16s(line->lspID,g723dec->preLsp,lsp_vec,line->Crc);  }else {   if(g723dec->preFtyp == 1) {  /* Case of 1st SID frame erased */       QuantSIDGain_G723_16s(&g723dec->SidGain, &g723dec->SidSfs, 0, &i);   //    QuantSIDGain_G723_16s(&g723dec->SidGain, &g723dec->CurGain, 0, &i);       DecodeSIDGain_G723_16s(i,&g723dec->SidGain);                                        }  }  if(g723dec->preFtyp == 1)      g723dec->CurGain = g723dec->SidGain;  else  /* update gain */     g723dec->CurGain = ( 7*g723dec->CurGain + g723dec->SidGain) >> 3 ;       buf=(char *)malloc(ComfortNoiseExcitation_G723_16s_Buff_Size);  ComfortNoiseExcitation_G723_16s(g723dec->CurGain,g723dec->preExc,Vout,&g723dec->CngSeed,line->olp,line->closelag,line->adptgid,g723dec->rate,buf);  free(buf);   // ippsZero_16s(Vout,fsize);  LspInterpolation_G723(lsp_vec,g723dec->preLsp,lpc); //  ippsZero_16s(lpc,4*lpclen);  ippsCopy_16s(lsp_vec,g723dec->preLsp,lpclen);  free(lsp_vec);}  void Dec_by_frame(g723dec_obj *g723dec,char *bitstream,short Crc,short *Vout){ Line *line; int i,j; short lsp_vec[lpclen]; short lpc[lpclen*4]; short Temp[pitchmax+fsize]; short *Dpnt; short post_delay[4]; short pitch_gain[4]; short scale_gain[4]; short Ftyp;   ippsZero_16s(Vout,fsize); ippsZero_16s(lpc,4*lpclen); ippsZero_16s(lsp_vec,lpclen);// printf("Welcome to Dec_by_frame\n"); line=(Line *)malloc(sizeof(Line)); line->Crc=Crc; if(line->Crc==0) { //unpack bitstream  Unpack(bitstream,line,&g723dec->rate,&Ftyp); }  if(line->Crc !=0) {                // if it is transmitting or operate error, count on the past Ftyp    if(g723dec->preFtyp==1) Ftyp=1;   else     Ftyp=0;  }   if(line->Crc==0)                 //calculate the number of adjacent error frames    g723dec->err_count=0; else   g723dec->err_count++; if(g723dec->err_count>=3)   g723dec->err_count=3;// Ftyp=0; if(Ftyp!=1) {   Dec_Cng(g723dec, Ftyp, line, Vout, lpc);   } else {  //decode lsp_index to lsp  LSFQuantInv_G723_32s16s(line->lspID,g723dec->preLsp,lsp_vec,line->Crc);  LspInterpolation_G723(lsp_vec,g723dec->preLsp,lpc);    ippsCopy_16s(lsp_vec,g723dec->preLsp,lpclen);    //update interGain  if(g723dec->err_count==0)     g723dec->UnvGain=FcbkGainTable[(line->ampindex[2]+line->ampindex[3])>>1]; //unvoiced use   else    g723dec->UnvGain=(g723dec->UnvGain*3+2)>>2;                      // decrease by 2.5dB every frame after the first lost frame    ippsCopy_16s(g723dec->preExc,Temp,pitchmax);  Dpnt=&Temp[pitchmax];  if(g723dec->err_count==0) {   for(i=0;i<4;i++) {     int T0;     short T0_gain;     /* Fixed codebook excitation. */     FixedCodebookVector_G723_16s(line->pos[i],line->sign[i],line->ampindex[i],line->grid[i],line->adptgid[i],i,g723dec->rate,Dpnt,&T0,&T0_gain);          if (g723dec->rate==0 ){ /* rate63*/        if(line->traindrt[i]==1 ) {          short Tmp[sfsize] ;          ippsCopy_16s(Dpnt,Tmp,sfsize);          /*  Generation of a Dirac train. Section 2.15 */          for (j=line->olp[i>>1];j<sfsize;j+=line->olp[i>>1])     ippsAdd_16s_I(Tmp,&Dpnt[j],sfsize-j);        }     }else{ /*rate53*/       T0 +=line->olp[i>>1]-1+line->closelag[i];              if(T0<sfsize-2)          HarmonicFilter2_I(&Dpnt[T0],T0,T0_gain,sfsize-T0);      }           /* Adaptive codebook excitation. Section 3.4 */     {      short adptContr[sfsize];      ippsDecodeAdaptiveVector_G723_16s(line->olp[i>>1],line->closelag[i],line->adptgid[i],&Temp[sfsize*i],adptContr,rate_vec[g723dec->rate]);                /* Codebook contributions to excitation. */      ShiftL_16s(Dpnt,1,Dpnt,sfsize);      ippsAdd_16s_I(adptContr,Dpnt,sfsize);           //add the adaptive-contribution and the fixed-contribution      Dpnt += sfsize ;     }   }// end of subframe      ippsCopy_16s(&Temp[pitchmax],Vout,fsize);                         /* Interpolation index calculation. Section 3.10 */   Comp_Info(Temp, line->olp[1],&g723dec->SidGain, &g723dec->SidSfs, &g723dec->VoiceDelay);   //!!!!!!!!!                                                                                      //after it Temp changed   /* Pitch post filter coefficients calculation.  Section 3.6 */   for ( i = 0 ; i < 4 ; i ++ )                                        //sure to do the post pitch filter     ippsPitchPostFilter_G723_16s(line->olp[i>>1],&Temp[pitchmax],&post_delay[i],&pitch_gain[i],&scale_gain[i],(short)i,rate_vec[g723dec->rate]);                                                   ippsCopy_16s(g723dec->preExc,Temp,pitchmax);   ippsCopy_16s(Vout,&Temp[pitchmax],fsize);         /* Pitch post filtering. Section 3.6 */   for ( i = 0 ; i < 4 ; i ++ )                       PitchPost_G723_Sfs(&Temp[pitchmax+i*sfsize],&Vout[i*sfsize],post_delay[i],pitch_gain[i],scale_gain[i],15);   //gain-Q15 //  fwrite(Vout,sizeof(short),fsize,fp);      ippsCopy_16s(g723dec->preLsp,g723dec->LspSid,lpclen);  }else {   /* Frame erasure. Section 3.10 */   if ( g723dec->err_count>= 3 ) {    /* Test for clearing */      ippsZero_16s(Vout,fsize);      ippsZero_16s(Temp,fsize+pitchmax);   }else      ResidualInterpolation_G723_16s_I(Temp,Vout,g723dec->VoiceDelay,g723dec->UnvGain,&g723dec->UnvSeed);      }    ippsCopy_16s(&Temp[fsize],g723dec->preExc,pitchmax);  g723dec->CngSeed = 12345; }  g723dec->preFtyp=Ftyp;  /* Speech synthesis. Section 3.7 */    Dpnt=Vout ;  for ( i = 0 ; i < 4 ; i ++ ) {     int SythEner;     ippsSynthesisFilter_G723_16s(&lpc[i*lpclen], Dpnt,g723dec->SythD1,Dpnt);             /* Formant post filter. Section 3.8 */     FormantPostFilter_G723_I(Dpnt,&SythEner,&lpc[i*lpclen],&g723dec->k_old,g723dec->formantD1);          GainControl_G723_I(Dpnt,SythEner,&g723dec->GctrlGain);      //  fwrite(Dpnt,sizeof(short),sfsize,fp);             Dpnt += sfsize ;    }    return;   } 

⌨️ 快捷键说明

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