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

📄 ilbc_decode.c

📁 PA1688网络电话机全部源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    
   /****************************************************************** 
    
       iLBC Speech Coder ANSI-C Source Code 
    
       iLBC_decode.c  
    
       Copyright (c) 2001, 
       Global IP Sound AB. 
       All rights reserved. 
    
   ******************************************************************/ 
    
   #include <math.h> 
   #include <stdlib.h> 
    
   #include "iLBC_define.h" 
   #include "StateConstructW.h" 
   #include "LPCdecode.h" 
   #include "iCBConstruct.h" 
   #include "doCPLC.h" 
   #include "helpfun.h" 
   #include "constants.h" 
   #include "packing.h" 
   #include "string.h" 
   #include "enhancer.h" 
   #include "hpOutput.h" 
   #include "syntFilter.h" 
    
   /*----------------------------------------------------------------* 
    *  Initiation of decoder instance. 
    *---------------------------------------------------------------*/ 
    
   short initDecode(                   /* (o) Number of decoded  
                                              samples */ 
       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */ 
       int mode,                       /* (i) frame size mode */ 
       int use_enhancer                /* (i) 1 to use enhancer 
                                              0 to run without  
     
    
    
                                                enhancer */ 
   ){ 
       int i; 
    
       iLBCdec_inst->mode = mode; 
    
       if (mode==30) { 
           iLBCdec_inst->blockl = BLOCKL_30MS; 
           iLBCdec_inst->nsub = NSUB_30MS; 
           iLBCdec_inst->nasub = NASUB_30MS; 
           iLBCdec_inst->lpc_n = LPC_N_30MS; 
           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS; 
           iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS; 
           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS; 
           /* ULP init */ 
           iLBCdec_inst->ULP_inst=&ULP_30msTbl; 
       } 
       else if (mode==20) { 
           iLBCdec_inst->blockl = BLOCKL_20MS; 
           iLBCdec_inst->nsub = NSUB_20MS; 
           iLBCdec_inst->nasub = NASUB_20MS; 
           iLBCdec_inst->lpc_n = LPC_N_20MS; 
           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS; 
           iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS; 
           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS; 
           /* ULP init */ 
           iLBCdec_inst->ULP_inst=&ULP_20msTbl; 
       } 
       else { 
           exit(2); 
       } 
    
       memset(iLBCdec_inst->syntMem, 0,  
           LPC_FILTERORDER*sizeof(float)); 
       memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl,  
           LPC_FILTERORDER*sizeof(float)); 
    
       memset(iLBCdec_inst->old_syntdenum, 0,  
           ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float)); 
       for (i=0; i<NSUB_MAX; i++) 
           iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0; 
    
       iLBCdec_inst->last_lag = 20; 
    
       iLBCdec_inst->prevLag = 120; 
       iLBCdec_inst->per = 0.0; 
       iLBCdec_inst->consPLICount = 0; 
       iLBCdec_inst->prevPLI = 0; 
       iLBCdec_inst->prevLpc[0] = 1.0; 
       memset(iLBCdec_inst->prevLpc+1,0, 
           LPC_FILTERORDER*sizeof(float)); 
       memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float)); 
       iLBCdec_inst->seed=777; 
     
    
    
    
       memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float)); 
    
       iLBCdec_inst->use_enhancer = use_enhancer; 
       memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float)); 
       for (i=0;i<ENH_NBLOCKS_TOT;i++)  
           iLBCdec_inst->enh_period[i]=(float)40.0; 
    
       iLBCdec_inst->prev_enh_pl = 0; 
    
       return (iLBCdec_inst->blockl); 
   } 
    
   /*----------------------------------------------------------------* 
    *  frame residual decoder function (subrutine to iLBC_decode)  
    *---------------------------------------------------------------*/ 
    
   void Decode( 
       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state  
                                                structure */ 
       float *decresidual,             /* (o) decoded residual frame */ 
       int start,                      /* (i) location of start state */ 
       int idxForMax,                  /* (i) codebook index for the  
                                              maximum value */ 
       int *idxVec,                /* (i) codebook indexes for the  
                                              samples  in the start  
                                              state */ 
       float *syntdenum,               /* (i) the decoded synthesis 
                                              filter coefficients */ 
       int *cb_index,                  /* (i) the indexes for the  
                                              adaptive codebook */ 
       int *gain_index,            /* (i) the indexes for the  
                                              corresponding gains */ 
       int *extra_cb_index,        /* (i) the indexes for the  
                                              adaptive codebook part  
                                              of start state */ 
       int *extra_gain_index,          /* (i) the indexes for the  
                                              corresponding gains */ 
       int state_first                 /* (i) 1 if non adaptive part  
                                              of start state comes first  
                                              0 if that part comes  
                                              last */ 
   ){ 
       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 
       int k, meml_gotten, Nfor, Nback, i; 
       int diff, start_pos; 
       int subcount, subframe; 
    
       diff = STATE_LEN - iLBCdec_inst->state_short_len; 
        
       if (state_first == 1) { 
           start_pos = (start-1)*SUBL; 
       } else { 
     
    
    
           start_pos = (start-1)*SUBL + diff; 
       } 
    
       /* decode scalar part of start state */ 
    
       StateConstructW(idxForMax, idxVec,  
           &syntdenum[(start-1)*(LPC_FILTERORDER+1)],  
           &decresidual[start_pos], iLBCdec_inst->state_short_len); 
    
        
       if (state_first) { /* put adaptive part in the end */ 
                    
           /* setup memory */ 
    
           memset(mem, 0,  
               (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float)); 
           memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len,  
               decresidual+start_pos,  
               iLBCdec_inst->state_short_len*sizeof(float)); 
            
           /* construct decoded vector */ 
    
           iCBConstruct( 
               &decresidual[start_pos+iLBCdec_inst->state_short_len], 
               extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl, 
               stMemLTbl, diff, CB_NSTAGES); 
        
       }  
       else {/* put adaptive part in the beginning */ 
            
           /* create reversed vectors for prediction */ 
    
           for (k=0; k<diff; k++) { 
               reverseDecresidual[k] =  
                   decresidual[(start+1)*SUBL-1- 
                           (k+iLBCdec_inst->state_short_len)]; 
           } 
            
           /* setup memory */ 
    
           meml_gotten = iLBCdec_inst->state_short_len; 
           for (k=0; k<meml_gotten; k++){  
               mem[CB_MEML-1-k] = decresidual[start_pos + k]; 
           }  
           memset(mem, 0, (CB_MEML-k)*sizeof(float)); 
            
           /* construct decoded vector */ 
    
           iCBConstruct(reverseDecresidual, extra_cb_index,  
               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, 
               diff, CB_NSTAGES); 
            
           /* get decoded residual from reversed vector */ 
     
    
    
    
           for (k=0; k<diff; k++) { 
               decresidual[start_pos-1-k] = reverseDecresidual[k]; 
           } 
       } 
    
       /* counter for predicted subframes */ 
    
       subcount=0; 
    
       /* forward prediction of subframes */ 
    
       Nfor = iLBCdec_inst->nsub-start-1; 
        
       if ( Nfor > 0 ){ 
            
           /* setup memory */ 
    
           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 
           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 
               STATE_LEN*sizeof(float)); 
    
           /* loop over subframes to encode */ 
    
           for (subframe=0; subframe<Nfor; subframe++) { 
                
               /* construct decoded vector */ 
    
               iCBConstruct(&decresidual[(start+1+subframe)*SUBL],  
                   cb_index+subcount*CB_NSTAGES,  
                   gain_index+subcount*CB_NSTAGES,  
                   mem+CB_MEML-memLfTbl[subcount],  
                   memLfTbl[subcount], SUBL, CB_NSTAGES); 
    
               /* update memory */ 
    
               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 
               memcpy(mem+CB_MEML-SUBL,  
                   &decresidual[(start+1+subframe)*SUBL], 
                   SUBL*sizeof(float)); 
    
               subcount++; 
    
           } 
    
       } 
        
       /* backward prediction of subframes */ 
    
       Nback = start-1; 
    
       if ( Nback > 0 ) { 
    
     
    
    
           /* setup memory */ 
    
           meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start); 
            
           if ( meml_gotten > CB_MEML ) {  
               meml_gotten=CB_MEML; 
           } 
           for (k=0; k<meml_gotten; k++) {  
               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k]; 
           } 
           memset(mem, 0, (CB_MEML-k)*sizeof(float)); 
    
           /* loop over subframes to decode */ 
    
           for (subframe=0; subframe<Nback; subframe++) { 
                
               /* construct decoded vector */ 
    
               iCBConstruct(&reverseDecresidual[subframe*SUBL],  
                   cb_index+subcount*CB_NSTAGES,  
                   gain_index+subcount*CB_NSTAGES,  
                   mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount],  
                   SUBL, CB_NSTAGES); 
    
               /* update memory */ 
    
               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 
               memcpy(mem+CB_MEML-SUBL,  
                   &reverseDecresidual[subframe*SUBL], 
                   SUBL*sizeof(float)); 
    
               subcount++; 
           } 
    
           /* get decoded residual from reversed vector */ 
    
           for (i=0; i<SUBL*Nback; i++) 
               decresidual[SUBL*Nback - i - 1] =  
               reverseDecresidual[i]; 
       } 
   } 
    
   /*----------------------------------------------------------------* 
    *  main decoder function  
    *---------------------------------------------------------------*/ 

⌨️ 快捷键说明

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