Ignore:
Timestamp:
Jul 26, 2006 5:04:54 PM (18 years ago)
Author:
bennylp
Message:
  • Bring speex codec up to date with their SVN trunk
  • Speex codec should work in FIXED_POINT mode when PJ_HAS_FLOATING_POINT is set to zero.
  • ulaw2linear will return zero if zero is given (this would make the VAD works better, and it also fixed click noise when call is established/hangup).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/speex/nb_celp.c

    r278 r628  
    4747#include "vbr.h" 
    4848#include "misc.h" 
     49#include "math_approx.h" 
    4950#include <speex/speex_callbacks.h> 
    5051 
     
    106107 
    107108#define sqr(x) ((x)*(x)) 
     109 
     110extern const spx_word16_t lpc_window[]; 
    108111 
    109112void *nb_encoder_init(const SpeexMode *m) 
     
    126129 
    127130   st->frameSize = mode->frameSize; 
    128    st->windowSize = st->frameSize*3/2; 
    129131   st->nbSubframes=mode->frameSize/mode->subframeSize; 
    130132   st->subframeSize=mode->subframeSize; 
     133   st->windowSize = st->frameSize+st->subframeSize; 
    131134   st->lpcSize = mode->lpcSize; 
    132135   st->gamma1=mode->gamma1; 
     
    150153   st->curve = speex_alloc(128*sizeof(float)); 
    151154   st->old_curve = speex_alloc(128*sizeof(float)); 
    152 #endif 
     155   st->psy_window = speex_alloc(256*sizeof(float)); 
     156#endif 
     157 
     158   st->cumul_gain = 1024; 
    153159 
    154160   /* Allocating input buffer */ 
    155    st->inBuf = speex_alloc((st->windowSize+EXTRA_BUFFER)*sizeof(spx_sig_t)); 
    156    st->frame = st->inBuf+EXTRA_BUFFER; 
     161   st->winBuf = speex_alloc((st->windowSize-st->frameSize)*sizeof(spx_word16_t)); 
    157162   /* Allocating excitation buffer */ 
    158    st->excBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_sig_t)); 
    159    st->exc = st->excBuf + mode->pitchEnd + 1; 
    160    st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+1)*sizeof(spx_sig_t)); 
    161    st->sw = st->swBuf + mode->pitchEnd + 1; 
    162  
    163    st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t)); 
    164  
    165    /* Asymmetric "pseudo-Hamming" window */ 
    166    { 
    167       int part1, part2; 
    168       part1=st->frameSize - (st->subframeSize>>1); 
    169       part2=(st->frameSize>>1) + (st->subframeSize>>1); 
    170       st->window = speex_alloc((st->windowSize)*sizeof(spx_word16_t)); 
    171       for (i=0;i<part1;i++) 
    172          st->window[i]=(spx_word16_t)(SIG_SCALING*(.54-.46*cos(M_PI*i/part1))); 
    173       for (i=0;i<part2;i++) 
    174          st->window[part1+i]=(spx_word16_t)(SIG_SCALING*(.54+.46*cos(M_PI*i/part2))); 
    175    } 
     163   st->excBuf = speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t)); 
     164   st->exc = st->excBuf + mode->pitchEnd + 2; 
     165   st->swBuf = speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t)); 
     166   st->sw = st->swBuf + mode->pitchEnd + 2; 
     167 
     168   st->window= lpc_window; 
     169    
    176170   /* Create the window for autocorrelation (lag-windowing) */ 
    177171   st->lagWindow = speex_alloc((st->lpcSize+1)*sizeof(spx_word16_t)); 
     
    179173      st->lagWindow[i]=16384*exp(-.5*sqr(2*M_PI*st->lag_factor*i)); 
    180174 
    181    st->autocorr = speex_alloc((st->lpcSize+1)*sizeof(spx_word16_t)); 
    182  
    183    st->lpc = speex_alloc((st->lpcSize)*sizeof(spx_coef_t)); 
    184    st->interp_lpc = speex_alloc((st->lpcSize)*sizeof(spx_coef_t)); 
    185    st->interp_qlpc = speex_alloc((st->lpcSize)*sizeof(spx_coef_t)); 
    186    st->bw_lpc1 = speex_alloc((st->lpcSize)*sizeof(spx_coef_t)); 
    187    st->bw_lpc2 = speex_alloc((st->lpcSize)*sizeof(spx_coef_t)); 
    188  
    189    st->lsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    190    st->qlsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    191175   st->old_lsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    192176   st->old_qlsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    193    st->interp_lsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    194    st->interp_qlsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
    195  
    196177   st->first = 1; 
    197178   for (i=0;i<st->lpcSize;i++) 
    198179   { 
    199       st->lsp[i]=LSP_SCALING*(M_PI*((float)(i+1)))/(st->lpcSize+1); 
     180      st->old_lsp[i]=LSP_SCALING*(M_PI*((float)(i+1)))/(st->lpcSize+1); 
    200181   } 
    201182 
     
    204185   st->mem_sw_whole = speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); 
    205186   st->mem_exc = speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); 
     187   st->mem_exc2 = speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); 
    206188 
    207189   st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); 
    208  
     190   st->innov_save = NULL; 
     191    
    209192   st->pitch = speex_alloc((st->nbSubframes)*sizeof(int)); 
    210193 
     
    213196   st->vbr_quality = 8; 
    214197   st->vbr_enabled = 0; 
     198   st->vbr_max = 0; 
    215199   st->vad_enabled = 0; 
    216200   st->dtx_enabled = 0; 
     
    237221#endif 
    238222 
    239    speex_free (st->inBuf); 
     223   speex_free (st->winBuf); 
    240224   speex_free (st->excBuf); 
    241    speex_free (st->innov); 
    242    speex_free (st->interp_qlpc); 
    243    speex_free (st->qlsp); 
    244225   speex_free (st->old_qlsp); 
    245    speex_free (st->interp_qlsp); 
    246226   speex_free (st->swBuf); 
    247227 
    248    speex_free (st->window); 
    249228   speex_free (st->lagWindow); 
    250    speex_free (st->autocorr); 
    251    speex_free (st->lpc); 
    252    speex_free (st->lsp); 
    253  
    254    speex_free (st->interp_lpc); 
    255    speex_free (st->bw_lpc1); 
    256    speex_free (st->bw_lpc2); 
     229 
    257230   speex_free (st->old_lsp); 
    258    speex_free (st->interp_lsp); 
    259231   speex_free (st->mem_sp); 
    260232   speex_free (st->mem_sw); 
    261233   speex_free (st->mem_sw_whole); 
    262234   speex_free (st->mem_exc); 
     235   speex_free (st->mem_exc2); 
    263236   speex_free (st->pi_gain); 
    264237   speex_free (st->pitch); 
     
    271244   speex_free (st->curve); 
    272245   speex_free (st->old_curve); 
     246   speex_free (st->psy_window); 
    273247#endif 
    274248 
     
    284258   spx_word16_t ol_pitch_coef; 
    285259   spx_word32_t ol_gain; 
    286    VARDECL(spx_sig_t *res); 
    287    VARDECL(spx_sig_t *target); 
     260   VARDECL(spx_word16_t *ringing); 
     261   VARDECL(spx_word16_t *target); 
     262   VARDECL(spx_sig_t *innov); 
     263   VARDECL(spx_word32_t *exc32); 
    288264   VARDECL(spx_mem_t *mem); 
     265   VARDECL(spx_coef_t *bw_lpc1); 
     266   VARDECL(spx_coef_t *bw_lpc2); 
     267   VARDECL(spx_coef_t *lpc); 
     268   VARDECL(spx_lsp_t *lsp); 
     269   VARDECL(spx_lsp_t *qlsp); 
     270   VARDECL(spx_lsp_t *interp_lsp); 
     271   VARDECL(spx_lsp_t *interp_qlsp); 
     272   VARDECL(spx_coef_t *interp_lpc); 
     273   VARDECL(spx_coef_t *interp_qlpc); 
    289274   char *stack; 
    290275   VARDECL(spx_word16_t *syn_resp); 
    291    VARDECL(spx_sig_t *real_exc); 
     276   VARDECL(spx_word16_t *real_exc); 
    292277#ifdef EPIC_48K 
    293278   int pitch_half[2]; 
     
    299284   stack=st->stack; 
    300285 
    301    /* Copy new data in input buffer */ 
    302    speex_move(st->inBuf, st->inBuf+st->frameSize, (EXTRA_BUFFER+st->windowSize-st->frameSize)*sizeof(spx_sig_t)); 
    303    for (i=0;i<st->frameSize;i++) 
    304       st->inBuf[st->windowSize-st->frameSize+i+EXTRA_BUFFER] = SHL32(EXTEND32(in[i]), SIG_SHIFT); 
     286   ALLOC(lpc, st->lpcSize, spx_coef_t); 
     287   ALLOC(bw_lpc1, st->lpcSize, spx_coef_t); 
     288   ALLOC(bw_lpc2, st->lpcSize, spx_coef_t); 
     289   ALLOC(lsp, st->lpcSize, spx_lsp_t); 
     290   ALLOC(qlsp, st->lpcSize, spx_lsp_t); 
     291   ALLOC(interp_lsp, st->lpcSize, spx_lsp_t); 
     292   ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t); 
     293   ALLOC(interp_lpc, st->lpcSize, spx_coef_t); 
     294   ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); 
    305295 
    306296   /* Move signals 1 frame towards the past */ 
    307    speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t)); 
    308    speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t)); 
     297   speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); 
     298   speex_move(st->swBuf, st->swBuf+st->frameSize, (st->max_pitch+2)*sizeof(spx_word16_t)); 
    309299 
    310300   { 
    311301      VARDECL(spx_word16_t *w_sig); 
     302      VARDECL(spx_word16_t *autocorr); 
    312303      ALLOC(w_sig, st->windowSize, spx_word16_t); 
     304      ALLOC(autocorr, st->lpcSize+1, spx_word16_t); 
    313305      /* Window for analysis */ 
    314       for (i=0;i<st->windowSize;i++) 
    315          w_sig[i] = EXTRACT16(SHR32(MULT16_16(EXTRACT16(SHR32(st->frame[i],SIG_SHIFT)),st->window[i]),SIG_SHIFT)); 
    316  
     306      for (i=0;i<st->windowSize-st->frameSize;i++) 
     307         w_sig[i] = EXTRACT16(SHR32(MULT16_16(st->winBuf[i],st->window[i]),SIG_SHIFT)); 
     308      for (;i<st->windowSize;i++) 
     309         w_sig[i] = EXTRACT16(SHR32(MULT16_16(in[i-st->windowSize+st->frameSize],st->window[i]),SIG_SHIFT)); 
    317310      /* Compute auto-correlation */ 
    318       _spx_autocorr(w_sig, st->autocorr, st->lpcSize+1, st->windowSize); 
    319    } 
    320    st->autocorr[0] = ADD16(st->autocorr[0],MULT16_16_Q15(st->autocorr[0],st->lpc_floor)); /* Noise floor in auto-correlation domain */ 
    321  
    322    /* Lag windowing: equivalent to filtering in the power-spectrum domain */ 
    323    for (i=0;i<st->lpcSize+1;i++) 
    324       st->autocorr[i] = MULT16_16_Q14(st->autocorr[i],st->lagWindow[i]); 
    325  
    326    /* Levinson-Durbin */ 
    327    _spx_lpc(st->lpc, st->autocorr, st->lpcSize); 
    328  
    329    /* LPC to LSPs (x-domain) transform */ 
    330    roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, LSP_DELTA1, stack); 
    331    /* Check if we found all the roots */ 
    332    if (roots!=st->lpcSize) 
    333    { 
    334       /* Search again if we can afford it */ 
    335       if (st->complexity>1) 
    336          roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, LSP_DELTA2, stack); 
    337       if (roots!=st->lpcSize)  
     311      _spx_autocorr(w_sig, autocorr, st->lpcSize+1, st->windowSize); 
     312      autocorr[0] = ADD16(autocorr[0],MULT16_16_Q15(autocorr[0],st->lpc_floor)); /* Noise floor in auto-correlation domain */ 
     313 
     314      /* Lag windowing: equivalent to filtering in the power-spectrum domain */ 
     315      for (i=0;i<st->lpcSize+1;i++) 
     316         autocorr[i] = MULT16_16_Q14(autocorr[i],st->lagWindow[i]); 
     317 
     318      /* Levinson-Durbin */ 
     319      _spx_lpc(lpc, autocorr, st->lpcSize); 
     320      /* LPC to LSPs (x-domain) transform */ 
     321      roots=lpc_to_lsp (lpc, st->lpcSize, lsp, 10, LSP_DELTA1, stack); 
     322      /* Check if we found all the roots */ 
     323      if (roots!=st->lpcSize) 
    338324      { 
    339325         /*If we can't find all LSP's, do some damage control and use previous filter*/ 
    340326         for (i=0;i<st->lpcSize;i++) 
    341327         { 
    342             st->lsp[i]=st->old_lsp[i]; 
    343          } 
    344       } 
    345    } 
     328            lsp[i]=st->old_lsp[i]; 
     329         } 
     330      } 
     331   } 
     332 
    346333 
    347334 
     
    351338      if (st->first) 
    352339         for (i=0;i<st->lpcSize;i++) 
    353             st->interp_lsp[i] = st->lsp[i]; 
     340            interp_lsp[i] = lsp[i]; 
    354341      else 
    355          lsp_interpolate(st->old_lsp, st->lsp, st->interp_lsp, st->lpcSize, st->nbSubframes, st->nbSubframes<<1); 
    356  
    357       lsp_enforce_margin(st->interp_lsp, st->lpcSize, LSP_MARGIN); 
     342         lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, st->nbSubframes, st->nbSubframes<<1); 
     343 
     344      lsp_enforce_margin(interp_lsp, st->lpcSize, LSP_MARGIN); 
    358345 
    359346      /* Compute interpolated LPCs (unquantized) for whole frame*/ 
    360       lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,stack); 
     347      lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack); 
    361348 
    362349 
    363350      /*Open-loop pitch*/ 
    364       if (!st->submodes[st->submodeID] || st->vbr_enabled || st->vad_enabled || SUBMODE(forced_pitch_gain) || 
     351      if (st->complexity>2 || !st->submodes[st->submodeID] || st->vbr_enabled || st->vad_enabled || SUBMODE(forced_pitch_gain) || 
    365352          SUBMODE(lbr_pitch) != -1) 
    366353      { 
     
    368355         spx_word16_t nol_pitch_coef[6]; 
    369356          
    370          bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize); 
    371          bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize); 
     357         bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); 
     358         bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); 
    372359          
    373          filter_mem2(st->frame, st->bw_lpc1, st->bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole); 
     360         for (i=0;i<st->windowSize-st->frameSize;i++) 
     361            st->sw[i] = st->winBuf[i]; 
     362         for (;i<st->frameSize;i++) 
     363            st->sw[i] = in[i-st->windowSize+st->frameSize]; 
     364         filter_mem16(st->sw, bw_lpc1, bw_lpc2, st->sw, st->frameSize, st->lpcSize, st->mem_sw_whole, stack); 
    374365 
    375366         open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize,  
     
    413404         ol_pitch_coef=0; 
    414405      } 
     406       
    415407      /*Compute "real" excitation*/ 
    416       fir_mem2(st->frame, st->interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc); 
     408      for (i=0;i<st->windowSize-st->frameSize;i++) 
     409         st->exc[i] = st->winBuf[i]; 
     410      for (;i<st->frameSize;i++) 
     411         st->exc[i] = in[i-st->windowSize+st->frameSize]; 
     412      fir_mem16(st->exc, interp_lpc, st->exc, st->frameSize, st->lpcSize, st->mem_exc, stack); 
    417413 
    418414      /* Compute open-loop excitation gain */ 
     
    422418         float ol1=0,ol2=0; 
    423419         float ol_gain2; 
    424          ol1 = compute_rms(st->exc, st->frameSize>>1); 
    425          ol2 = compute_rms(st->exc+(st->frameSize>>1), st->frameSize>>1); 
     420         ol1 = compute_rms16(st->exc, st->frameSize>>1); 
     421         ol2 = compute_rms16(st->exc+(st->frameSize>>1), st->frameSize>>1); 
    426422         ol1 *= ol1*(st->frameSize>>1); 
    427423         ol2 *= ol2*(st->frameSize>>1); 
     
    434430         ol_gain=SHR(sqrt(1+ol_gain2/st->frameSize),SIG_SHIFT); 
    435431 
    436       } else { 
    437 #endif 
    438          ol_gain = SHL32(EXTEND32(compute_rms(st->exc, st->frameSize)),SIG_SHIFT); 
    439 #ifdef EPIC_48K 
    440       } 
    441 #endif 
     432      } else 
     433#endif 
     434      { 
     435         spx_word16_t g = compute_rms16(st->exc, st->frameSize); 
     436         if (ol_pitch>0) 
     437            ol_gain = MULT16_16(g, MULT16_16_Q14(QCONST16(1.1,14), 
     438                                spx_sqrt(QCONST32(1.,28)-MULT16_32_Q15(QCONST16(.8,15),SHL32(MULT16_16(ol_pitch_coef,ol_pitch_coef),16))))); 
     439         else 
     440            ol_gain = SHL32(EXTEND32(g),SIG_SHIFT); 
     441      } 
    442442   } 
    443443 
    444444#ifdef VORBIS_PSYCHO 
    445    compute_curve(st->psy, st->frame-16, st->curve); 
     445   for(i=0;i<256-st->frameSize;i++) 
     446      st->psy_window[i] = st->psy_window[i+st->frameSize]; 
     447   for(i=0;i<st->frameSize;i++) 
     448      st->psy_window[256-st->frameSize+i] = in[i]; 
     449   compute_curve(st->psy, st->psy_window, st->curve); 
    446450   /*print_vec(st->curve, 128, "curve");*/ 
    447451   if (st->first) 
     
    455459      float lsp_dist=0; 
    456460      for (i=0;i<st->lpcSize;i++) 
    457          lsp_dist += (st->old_lsp[i] - st->lsp[i])*(st->old_lsp[i] - st->lsp[i]); 
     461         lsp_dist += (st->old_lsp[i] - lsp[i])*(st->old_lsp[i] - lsp[i]); 
    458462      lsp_dist /= LSP_SCALING*LSP_SCALING; 
    459463       
     
    519523 
    520524         speex_encoder_ctl(state, SPEEX_SET_MODE, &mode); 
    521  
     525         if (st->vbr_max>0) 
     526         { 
     527            spx_int32_t rate; 
     528            speex_encoder_ctl(state, SPEEX_GET_BITRATE, &rate); 
     529            if (rate > st->vbr_max) 
     530            { 
     531               rate = st->vbr_max; 
     532               speex_encoder_ctl(state, SPEEX_SET_BITRATE, &rate); 
     533            } 
     534         } 
     535          
    522536         if (st->abr_enabled) 
    523537         { 
     
    581595      st->bounded_pitch = 1; 
    582596 
    583       /* Final signal synthesis from excitation */ 
    584       iir_mem2(st->exc, st->interp_qlpc, st->frame, st->frameSize, st->lpcSize, st->mem_sp); 
    585  
    586 #ifdef RESYNTH 
    587       for (i=0;i<st->frameSize;i++) 
    588          in[i]=st->frame[i]; 
    589 #endif 
     597      speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); 
     598 
     599      /* Clear memory (no need to really compute it) */ 
     600      for (i=0;i<st->lpcSize;i++) 
     601         st->mem_sp[i] = 0; 
    590602      return 0; 
    591603 
     
    596608   { 
    597609      for (i=0;i<st->lpcSize;i++) 
    598          st->old_lsp[i] = st->lsp[i]; 
     610         st->old_lsp[i] = lsp[i]; 
    599611   } 
    600612 
     
    602614   /*Quantize LSPs*/ 
    603615#if 1 /*0 for unquantized*/ 
    604    SUBMODE(lsp_quant)(st->lsp, st->qlsp, st->lpcSize, bits); 
     616   SUBMODE(lsp_quant)(lsp, qlsp, st->lpcSize, bits); 
    605617#else 
    606618   for (i=0;i<st->lpcSize;i++) 
    607      st->qlsp[i]=st->lsp[i]; 
     619     qlsp[i]=lsp[i]; 
    608620#endif 
    609621 
     
    686698   { 
    687699      for (i=0;i<st->lpcSize;i++) 
    688          st->old_qlsp[i] = st->qlsp[i]; 
    689    } 
    690  
    691    /* Filter response */ 
    692    ALLOC(res, st->subframeSize, spx_sig_t); 
     700         st->old_qlsp[i] = qlsp[i]; 
     701   } 
     702 
    693703   /* Target signal */ 
    694    ALLOC(target, st->subframeSize, spx_sig_t); 
     704   ALLOC(target, st->subframeSize, spx_word16_t); 
     705   ALLOC(innov, st->subframeSize, spx_sig_t); 
     706   ALLOC(exc32, st->subframeSize, spx_word32_t); 
     707   ALLOC(ringing, st->subframeSize, spx_word16_t); 
    695708   ALLOC(syn_resp, st->subframeSize, spx_word16_t); 
    696    ALLOC(real_exc, st->subframeSize, spx_sig_t); 
     709   ALLOC(real_exc, st->subframeSize, spx_word16_t); 
    697710   ALLOC(mem, st->lpcSize, spx_mem_t); 
    698711 
     
    701714   { 
    702715      int   offset; 
    703       spx_sig_t *sp, *sw, *exc; 
     716      spx_word16_t *sw; 
     717      spx_word16_t *exc; 
     718      spx_sig_t *innov_save = NULL; 
    704719      int pitch; 
    705720      int response_bound = st->subframeSize; 
     
    716731      /* Offset relative to start of frame */ 
    717732      offset = st->subframeSize*sub; 
    718       /* Original signal */ 
    719       sp=st->frame+offset; 
    720733      /* Excitation */ 
    721734      exc=st->exc+offset; 
    722735      /* Weighted signal */ 
    723736      sw=st->sw+offset; 
    724  
     737      /* Pointer for saving innovation */ 
     738      if (st->innov_save) 
     739         innov_save = st->innov_save+offset; 
     740       
    725741      /* LSP interpolation (quantized and unquantized) */ 
    726       lsp_interpolate(st->old_lsp, st->lsp, st->interp_lsp, st->lpcSize, sub, st->nbSubframes); 
    727       lsp_interpolate(st->old_qlsp, st->qlsp, st->interp_qlsp, st->lpcSize, sub, st->nbSubframes); 
     742      lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes); 
     743      lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes); 
    728744 
    729745      /* Make sure the filters are stable */ 
    730       lsp_enforce_margin(st->interp_lsp, st->lpcSize, LSP_MARGIN); 
    731       lsp_enforce_margin(st->interp_qlsp, st->lpcSize, LSP_MARGIN); 
     746      lsp_enforce_margin(interp_lsp, st->lpcSize, LSP_MARGIN); 
     747      lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN); 
    732748 
    733749      /* Compute interpolated LPCs (quantized and unquantized) */ 
    734       lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,stack); 
    735  
    736       lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack); 
     750      lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack); 
     751 
     752      lsp_to_lpc(interp_qlsp, interp_qlpc, st->lpcSize, stack); 
    737753 
    738754      /* Compute analysis filter gain at w=pi (for use in SB-CELP) */ 
     
    742758         { 
    743759            /*pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];*/ 
    744             pi_g = ADD32(pi_g, SUB32(st->interp_qlpc[i+1],st->interp_qlpc[i])); 
     760            pi_g = ADD32(pi_g, SUB32(EXTEND32(interp_qlpc[i+1]),EXTEND32(interp_qlpc[i]))); 
    745761         } 
    746762         st->pi_gain[sub] = pi_g; 
     
    753769         for (i=0;i<128;i++) 
    754770            curr_curve[i] = (1.0f-fact)*st->old_curve[i] + fact*st->curve[i]; 
    755          curve_to_lpc(st->psy, curr_curve, st->bw_lpc1, st->bw_lpc2, 10); 
     771         curve_to_lpc(st->psy, curr_curve, bw_lpc1, bw_lpc2, 10); 
    756772      } 
    757773#else 
    758774      /* Compute bandwidth-expanded (unquantized) LPCs for perceptual weighting */ 
    759       bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize); 
     775      bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize); 
    760776      if (st->gamma2>=0) 
    761          bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize); 
     777         bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize); 
    762778      else 
    763779      { 
    764          st->bw_lpc2[0]=1; 
     780         bw_lpc2[0]=1; 
    765781         for (i=1;i<=st->lpcSize;i++) 
    766             st->bw_lpc2[i]=0; 
     782            bw_lpc2[i]=0; 
    767783      } 
    768784      /*print_vec(st->bw_lpc1, 10, "bw_lpc");*/ 
    769785#endif 
    770786 
    771       for (i=0;i<st->subframeSize;i++) 
    772          real_exc[i] = exc[i]; 
     787      { 
     788         /*FIXME: This will break if we change the window size */ 
     789         if (st->windowSize-st->frameSize != st->subframeSize) 
     790            speex_error("windowSize-frameSize != subframeSize"); 
     791         if (sub==0) 
     792         { 
     793            for (i=0;i<st->subframeSize;i++) 
     794               real_exc[i] = sw[i] = st->winBuf[i]; 
     795         } else { 
     796            for (i=0;i<st->subframeSize;i++) 
     797               real_exc[i] = sw[i] = in[i+((sub-1)*st->subframeSize)]; 
     798         } 
     799      } 
     800      fir_mem16(real_exc, interp_qlpc, real_exc, st->subframeSize, st->lpcSize, st->mem_exc2, stack); 
    773801       
    774802      if (st->complexity==0) 
    775803         response_bound >>= 1; 
    776       compute_impulse_response(st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, response_bound, st->lpcSize, stack); 
     804      compute_impulse_response(interp_qlpc, bw_lpc1, bw_lpc2, syn_resp, response_bound, st->lpcSize, stack); 
    777805      for (i=response_bound;i<st->subframeSize;i++) 
    778806         syn_resp[i]=VERY_SMALL; 
    779807       
    780       /* Reset excitation */ 
    781       for (i=0;i<st->subframeSize;i++) 
    782          exc[i]=VERY_SMALL; 
    783  
    784808      /* Compute zero response of A(z/g1) / ( A(z/g2) * A(z) ) */ 
    785809      for (i=0;i<st->lpcSize;i++) 
    786          mem[i]=st->mem_sp[i]; 
     810         mem[i]=SHL32(st->mem_sp[i],1); 
     811      for (i=0;i<st->subframeSize;i++) 
     812         ringing[i] = VERY_SMALL; 
    787813#ifdef SHORTCUTS2 
    788       iir_mem2(exc, st->interp_qlpc, exc, response_bound, st->lpcSize, mem); 
     814      iir_mem16(ringing, interp_qlpc, ringing, response_bound, st->lpcSize, mem, stack); 
    789815      for (i=0;i<st->lpcSize;i++) 
    790          mem[i]=st->mem_sw[i]; 
    791       filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, response_bound, st->lpcSize, mem); 
     816         mem[i]=SHL32(st->mem_sw[i],1); 
     817      filter_mem16(ringing, st->bw_lpc1, st->bw_lpc2, ringing, response_bound, st->lpcSize, mem, stack); 
    792818      for (i=response_bound;i<st->subframeSize;i++) 
    793          res[i]=0; 
     819         ringing[i]=0; 
    794820#else 
    795       iir_mem2(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem); 
     821      iir_mem16(ringing, interp_qlpc, ringing, st->subframeSize, st->lpcSize, mem, stack); 
    796822      for (i=0;i<st->lpcSize;i++) 
    797          mem[i]=st->mem_sw[i]; 
    798       filter_mem2(exc, st->bw_lpc1, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem); 
     823         mem[i]=SHL32(st->mem_sw[i],1); 
     824      filter_mem16(ringing, bw_lpc1, bw_lpc2, ringing, st->subframeSize, st->lpcSize, mem, stack); 
    799825#endif 
    800826       
     
    802828      for (i=0;i<st->lpcSize;i++) 
    803829         mem[i]=st->mem_sw[i]; 
    804       filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem); 
     830      filter_mem16(sw, bw_lpc1, bw_lpc2, sw, st->subframeSize, st->lpcSize, mem, stack); 
    805831       
    806832      if (st->complexity==0) 
     
    810836      /* Compute target signal */ 
    811837      for (i=0;i<st->subframeSize;i++) 
    812          target[i]=sw[i]-res[i]; 
    813  
     838         target[i]=SUB16(sw[i],PSHR32(ringing[i],1)); 
     839 
     840      /* Reset excitation */ 
    814841      for (i=0;i<st->subframeSize;i++) 
    815842         exc[i]=0; 
     
    848875         if (st->lbr_48k) 
    849876         { 
    850             pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
    851                                        exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef, 
     877            pitch = SUBMODE(ltp_quant)(target, sw, interp_qlpc, bw_lpc1, bw_lpc2, 
     878                                       exc32, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef, 
    852879                                       st->lpcSize, st->subframeSize, bits, stack,  
    853                                        exc, syn_resp, st->complexity, ol_pitch_id, st->plc_tuning); 
     880                                       exc, syn_resp, st->complexity, ol_pitch_id, st->plc_tuning, &st->cumul_gain); 
    854881         } else { 
    855882#endif 
    856883 
    857884         /* Perform pitch search */ 
    858          pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, 
    859                                     exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef, 
     885         pitch = SUBMODE(ltp_quant)(target, sw, interp_qlpc, bw_lpc1, bw_lpc2, 
     886                                    exc32, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef, 
    860887                                    st->lpcSize, st->subframeSize, bits, stack,  
    861                                     exc, syn_resp, st->complexity, 0, st->plc_tuning); 
     888                                    exc, syn_resp, st->complexity, 0, st->plc_tuning, &st->cumul_gain); 
    862889#ifdef EPIC_48K 
    863890         } 
     
    871898      /* Quantization of innovation */ 
    872899      { 
    873          spx_sig_t *innov; 
    874900         spx_word32_t ener=0; 
    875901         spx_word16_t fine_gain; 
    876902 
    877          innov = st->innov+sub*st->subframeSize; 
    878903         for (i=0;i<st->subframeSize;i++) 
    879904            innov[i]=0; 
    880905          
    881906         for (i=0;i<st->subframeSize;i++) 
    882             real_exc[i] = SUB32(real_exc[i], exc[i]); 
    883  
    884          ener = SHL32(EXTEND32(compute_rms(real_exc, st->subframeSize)),SIG_SHIFT); 
     907            real_exc[i] = SUB16(real_exc[i], PSHR32(exc32[i],SIG_SHIFT-1)); 
     908 
     909         ener = SHL32(EXTEND32(compute_rms16(real_exc, st->subframeSize)),SIG_SHIFT); 
    885910          
    886911         /*FIXME: Should use DIV32_16 and make sure result fits in 16 bits */ 
    887912#ifdef FIXED_POINT 
    888913         { 
    889             spx_word32_t f = DIV32(ener,PSHR32(ol_gain,SIG_SHIFT)); 
     914            spx_word32_t f = PDIV32(ener,PSHR32(ol_gain,SIG_SHIFT)); 
    890915            if (f<=32767) 
    891916               fine_gain = f; 
     
    894919         } 
    895920#else 
    896          fine_gain = DIV32_16(ener,PSHR32(ol_gain,SIG_SHIFT)); 
     921         fine_gain = PDIV32_16(ener,PSHR32(ol_gain,SIG_SHIFT)); 
    897922#endif 
    898923         /* Calculate gain correction for the sub-frame (if any) */ 
     
    923948         { 
    924949            /* Codebook search */ 
    925             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,  
     950            SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2,  
    926951                                      SUBMODE(innovation_params), st->lpcSize, st->subframeSize,  
    927952                                      innov, syn_resp, bits, stack, st->complexity, SUBMODE(double_codebook)); 
     
    931956 
    932957            for (i=0;i<st->subframeSize;i++) 
    933                exc[i] = ADD32(exc[i],innov[i]); 
     958               exc[i] = EXTRACT16(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT)); 
    934959         } else { 
    935960            speex_error("No fixed codebook"); 
    936961         } 
    937962 
     963         if (innov_save) 
     964         { 
     965            for (i=0;i<st->subframeSize;i++) 
     966               innov_save[i] = innov[i]; 
     967         } 
    938968         /* In some (rare) modes, we do a second search (more bits) to reduce noise even more */ 
    939969         if (SUBMODE(double_codebook)) { 
     
    944974               innov2[i]=0; 
    945975            for (i=0;i<st->subframeSize;i++) 
    946                target[i]*=2.2; 
    947             SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,  
     976               target[i]=MULT16_16_P13(QCONST16(2.2,13), target[i]); 
     977            SUBMODE(innovation_quant)(target, interp_qlpc, bw_lpc1, bw_lpc2,  
    948978                                      SUBMODE(innovation_params), st->lpcSize, st->subframeSize,  
    949979                                      innov2, syn_resp, bits, stack, st->complexity, 0); 
    950             signal_mul(innov2, innov2, (spx_word32_t) (ener*(1.f/2.2f)), st->subframeSize); 
     980            signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545,15),ener), st->subframeSize); 
    951981            for (i=0;i<st->subframeSize;i++) 
    952                exc[i] = ADD32(exc[i],innov2[i]); 
     982               exc[i] = ADD32(exc[i],PSHR32(innov2[i],SIG_SHIFT)); 
     983            if (innov_save) 
     984            { 
     985               for (i=0;i<st->subframeSize;i++) 
     986                  innov_save[i] = ADD32(innov_save[i],innov2[i]); 
     987            } 
    953988            stack = tmp_stack; 
    954989         } 
     
    956991      } 
    957992 
     993      for (i=0;i<st->subframeSize;i++) 
     994         sw[i] = exc[i]; 
    958995      /* Final signal synthesis from excitation */ 
    959       iir_mem2(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp); 
     996      iir_mem16(sw, interp_qlpc, sw, st->subframeSize, st->lpcSize, st->mem_sp, stack); 
    960997 
    961998      /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ 
    962999      if (st->complexity!=0) 
    963          filter_mem2(sp, st->bw_lpc1, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw); 
     1000         filter_mem16(sw, bw_lpc1, bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw, stack); 
    9641001       
    9651002   } 
     
    9691006   { 
    9701007      for (i=0;i<st->lpcSize;i++) 
    971          st->old_lsp[i] = st->lsp[i]; 
     1008         st->old_lsp[i] = lsp[i]; 
    9721009      for (i=0;i<st->lpcSize;i++) 
    973          st->old_qlsp[i] = st->qlsp[i]; 
     1010         st->old_qlsp[i] = qlsp[i]; 
    9741011   } 
    9751012 
     
    9921029   /* The next frame will not be the first (Duh!) */ 
    9931030   st->first = 0; 
    994  
    995 #ifdef RESYNTH 
    996    /* Replace input by synthesized speech */ 
    997    for (i=0;i<st->frameSize;i++) 
    998    { 
    999       spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT); 
    1000       if (sig>32767) 
    1001          sig = 32767; 
    1002       if (sig<-32767) 
    1003          sig = -32767; 
    1004      in[i]=sig; 
    1005    } 
    1006 #endif 
     1031   speex_move(st->winBuf, in+2*st->frameSize-st->windowSize, (st->windowSize-st->frameSize)*sizeof(spx_word16_t)); 
    10071032 
    10081033   if (SUBMODE(innovation_quant) == noise_codebook_quant || st->submodeID==0) 
     
    10131038   return 1; 
    10141039} 
    1015  
    10161040 
    10171041void *nb_decoder_init(const SpeexMode *m) 
     
    10511075   st->submodeID=mode->defaultSubmode; 
    10521076 
    1053    st->lpc_enh_enabled=0; 
    1054  
    1055  
    1056    st->inBuf = speex_alloc((st->frameSize)*sizeof(spx_sig_t)); 
    1057    st->frame = st->inBuf; 
    1058    st->excBuf = speex_alloc((st->frameSize + st->max_pitch + 1)*sizeof(spx_sig_t)); 
    1059    st->exc = st->excBuf + st->max_pitch + 1; 
    1060    for (i=0;i<st->frameSize;i++) 
    1061       st->inBuf[i]=0; 
     1077   st->lpc_enh_enabled=1; 
     1078 
     1079   st->excBuf = speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); 
     1080   st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; 
    10621081   for (i=0;i<st->frameSize + st->max_pitch + 1;i++) 
    10631082      st->excBuf[i]=0; 
    1064    st->innov = speex_alloc((st->frameSize)*sizeof(spx_sig_t)); 
    10651083 
    10661084   st->interp_qlpc = speex_alloc(st->lpcSize*sizeof(spx_coef_t)); 
    1067    st->qlsp = speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); 
    10681085   st->old_qlsp = speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); 
    1069    st->interp_qlsp = speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); 
    1070    st->mem_sp = speex_alloc((5*st->lpcSize)*sizeof(spx_mem_t)); 
    1071    st->comb_mem = speex_alloc(sizeof(CombFilterMem)); 
    1072    comb_filter_mem_init (st->comb_mem); 
    1073  
     1086   st->mem_sp = speex_alloc(st->lpcSize*sizeof(spx_mem_t)); 
    10741087   st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); 
    10751088   st->last_pitch = 40; 
     
    11051118#endif 
    11061119 
    1107    speex_free (st->inBuf); 
    11081120   speex_free (st->excBuf); 
    1109    speex_free (st->innov); 
    11101121   speex_free (st->interp_qlpc); 
    1111    speex_free (st->qlsp); 
    11121122   speex_free (st->old_qlsp); 
    1113    speex_free (st->interp_qlsp); 
    11141123   speex_free (st->mem_sp); 
    1115    speex_free (st->comb_mem); 
    11161124   speex_free (st->pi_gain); 
    11171125 
     
    11321140   int i, sub; 
    11331141   int pitch_val; 
    1134    VARDECL(spx_coef_t *awk1); 
    1135    VARDECL(spx_coef_t *awk2); 
    1136    VARDECL(spx_coef_t *awk3); 
    11371142   spx_word16_t pitch_gain; 
    11381143   spx_word16_t fact; 
     
    11631168 
    11641169   /* Shift all buffers by one frame */ 
    1165    /*speex_move(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(spx_sig_t));*/ 
    1166    speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch + 1)*sizeof(spx_sig_t)); 
    1167  
    1168    ALLOC(awk1, (st->lpcSize+1), spx_coef_t); 
    1169    ALLOC(awk2, (st->lpcSize+1), spx_coef_t); 
    1170    ALLOC(awk3, (st->lpcSize+1), spx_coef_t); 
    1171  
     1170   speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); 
    11721171   for (sub=0;sub<st->nbSubframes;sub++) 
    11731172   { 
    11741173      int offset; 
    1175       spx_sig_t *sp, *exc; 
     1174      spx_word16_t *sp; 
     1175      spx_word16_t *exc; 
    11761176      /* Offset relative to start of frame */ 
    11771177      offset = st->subframeSize*sub; 
    11781178      /* Original signal */ 
    1179       sp=st->frame+offset; 
     1179      sp=out+offset; 
    11801180      /* Excitation */ 
    11811181      exc=st->exc+offset; 
    11821182      /* Excitation after post-filter*/ 
    1183  
    1184       /* Calculate perceptually enhanced LPC filter */ 
    1185       if (st->lpc_enh_enabled) 
    1186       { 
    1187          spx_word16_t k1,k2,k3; 
    1188          if (st->submodes[st->submodeID] != NULL) 
    1189          { 
    1190             k1=SUBMODE(lpc_enh_k1); 
    1191             k2=SUBMODE(lpc_enh_k2); 
    1192             k3=SUBMODE(lpc_enh_k3); 
    1193          } else { 
    1194             k1=k2=.7*GAMMA_SCALING; 
    1195             k3=.0; 
    1196          } 
    1197          bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); 
    1198          bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); 
    1199          bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); 
    1200       } 
    12011183         
    12021184      /* Make up a plausible excitation */ 
     
    12041186      /*if (pitch_gain>.95) 
    12051187        pitch_gain=.95;*/ 
    1206       innov_gain = compute_rms(st->innov, st->frameSize); 
     1188       
     1189      /* FIXME: This was rms of innovation (not exc) */ 
     1190      innov_gain = compute_rms16(st->exc, st->frameSize); 
    12071191      pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT); 
    12081192      if (pitch_val > st->max_pitch) 
     
    12121196      for (i=0;i<st->subframeSize;i++) 
    12131197      { 
    1214          exc[i]= MULT16_32_Q15(pitch_gain, (exc[i-pitch_val]+VERY_SMALL)) +  
    1215                MULT16_32_Q15(fact, MULT16_32_Q15(SHL(Q15ONE,15)-SHL(MULT16_16(pitch_gain,pitch_gain),1),speex_rand(innov_gain, &st->seed))); 
    1216       } 
    1217        
     1198         /* FIXME: Second term need to be 16-bit */ 
     1199         exc[i]= MULT16_16_Q15(pitch_gain, (exc[i-pitch_val]+VERY_SMALL)) +  
     1200               MULT16_16_Q15(fact, MULT16_16_Q15(SHL(Q15ONE,15)-SHL(MULT16_16(pitch_gain,pitch_gain),1),speex_rand(innov_gain, &st->seed))); 
     1201      } 
    12181202      for (i=0;i<st->subframeSize;i++) 
    1219          sp[i]=exc[i]; 
    1220        
    1221       /* Signal synthesis */ 
    1222       if (st->lpc_enh_enabled) 
    1223       { 
    1224          filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize,  
    1225                      st->mem_sp+st->lpcSize); 
    1226          filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1227                      st->mem_sp); 
    1228       } else { 
    1229          for (i=0;i<st->lpcSize;i++) 
    1230             st->mem_sp[st->lpcSize+i] = 0; 
    1231          iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1232                      st->mem_sp); 
    1233       }       
    1234    } 
    1235  
    1236    for (i=0;i<st->frameSize;i++) 
    1237    { 
    1238       spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT); 
    1239       if (sig>32767) 
    1240          sig = 32767; 
    1241       if (sig<-32767) 
    1242          sig = -32767; 
    1243      out[i]=sig; 
     1203         sp[i]=exc[i-st->subframeSize]; 
     1204      iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
     1205                st->mem_sp, stack); 
     1206 
     1207      bw_lpc(QCONST16(.98,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize); 
    12441208   } 
    12451209    
     
    12501214      st->pitch_gain_buf_idx = 0; 
    12511215} 
     1216 
    12521217 
    12531218int nb_decode(void *state, SpeexBits *bits, void *vout) 
     
    12651230   int m; 
    12661231   char *stack; 
    1267    VARDECL(spx_coef_t *awk1); 
    1268    VARDECL(spx_coef_t *awk2); 
    1269    VARDECL(spx_coef_t *awk3); 
     1232   VARDECL(spx_sig_t *innov); 
     1233   VARDECL(spx_word32_t *exc32); 
     1234   VARDECL(spx_coef_t *ak); 
     1235   VARDECL(spx_lsp_t *qlsp); 
    12701236   spx_word16_t pitch_average=0; 
    12711237#ifdef EPIC_48K 
     
    12741240#endif 
    12751241   spx_word16_t *out = vout; 
     1242   VARDECL(spx_lsp_t *interp_qlsp); 
    12761243 
    12771244   st=(DecState*)state; 
     
    13741341 
    13751342   /* Shift all buffers by one frame */ 
    1376    speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch + 1)*sizeof(spx_sig_t)); 
     1343   speex_move(st->excBuf, st->excBuf+st->frameSize, (2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); 
    13771344 
    13781345   /* If null mode (no transmission), just set a couple things to zero*/ 
     
    13871354         if (pgain>.6) 
    13881355            pgain=.6; 
    1389          innov_gain = compute_rms(st->innov, st->frameSize); 
     1356         /* FIXME: This was innov, not exc */ 
     1357         innov_gain = compute_rms16(st->exc, st->frameSize); 
    13901358         for (i=0;i<st->frameSize;i++) 
    1391             st->exc[i]=VERY_SMALL; 
    1392          speex_rand_vec(innov_gain, st->exc, st->frameSize); 
     1359            st->exc[i]=speex_rand(innov_gain, &st->seed); 
    13931360      } 
    13941361 
     
    13961363      st->first=1; 
    13971364 
     1365      for (i=0;i<st->frameSize;i++) 
     1366         out[i] = st->exc[i]; 
    13981367      /* Final signal synthesis from excitation */ 
    1399       iir_mem2(st->exc, lpc, st->frame, st->frameSize, st->lpcSize, st->mem_sp); 
    1400  
    1401       for (i=0;i<st->frameSize;i++) 
    1402       { 
    1403          spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT); 
    1404          if (sig>32767) 
    1405             sig = 32767; 
    1406          if (sig<-32767) 
    1407             sig = -32767; 
    1408          out[i]=sig; 
    1409       } 
     1368      iir_mem16(out, lpc, out, st->frameSize, st->lpcSize, st->mem_sp, stack); 
    14101369 
    14111370      st->count_lost=0; 
     
    14131372   } 
    14141373 
     1374   ALLOC(qlsp, st->lpcSize, spx_lsp_t); 
     1375 
    14151376   /* Unquantize LSPs */ 
    1416    SUBMODE(lsp_unquant)(st->qlsp, st->lpcSize, bits); 
     1377   SUBMODE(lsp_unquant)(qlsp, st->lpcSize, bits); 
    14171378 
    14181379   /*Damp memory if a frame was lost and the LSP changed too much*/ 
     
    14221383      spx_word32_t lsp_dist=0; 
    14231384      for (i=0;i<st->lpcSize;i++) 
    1424          lsp_dist = ADD32(lsp_dist, EXTEND32(ABS(st->old_qlsp[i] - st->qlsp[i]))); 
     1385         lsp_dist = ADD32(lsp_dist, EXTEND32(ABS(st->old_qlsp[i] - qlsp[i]))); 
    14251386#ifdef FIXED_POINT 
    14261387      fact = SHR16(19661,SHR32(lsp_dist,LSP_SHIFT+2));       
     
    14281389      fact = .6*exp(-.2*lsp_dist); 
    14291390#endif 
    1430       for (i=0;i<2*st->lpcSize;i++) 
     1391      for (i=0;i<st->lpcSize;i++) 
    14311392         st->mem_sp[i] = MULT16_32_Q15(fact,st->mem_sp[i]); 
    14321393   } 
     
    14371398   { 
    14381399      for (i=0;i<st->lpcSize;i++) 
    1439          st->old_qlsp[i] = st->qlsp[i]; 
     1400         st->old_qlsp[i] = qlsp[i]; 
    14401401   } 
    14411402 
     
    14841445#endif 
    14851446 
    1486    ALLOC(awk1, st->lpcSize+1, spx_coef_t); 
    1487    ALLOC(awk2, st->lpcSize+1, spx_coef_t); 
    1488    ALLOC(awk3, st->lpcSize+1, spx_coef_t); 
     1447   ALLOC(ak, st->lpcSize, spx_coef_t); 
     1448   ALLOC(innov, st->subframeSize, spx_sig_t); 
     1449   ALLOC(exc32, st->subframeSize, spx_word32_t); 
    14891450 
    14901451   if (st->submodeID==1) 
     
    15051466   { 
    15061467      int offset; 
    1507       spx_sig_t *sp, *exc; 
     1468      spx_word16_t *exc; 
     1469      spx_word16_t *sp; 
     1470      spx_sig_t *innov_save = NULL; 
    15081471      spx_word16_t tmp; 
    15091472 
     
    15201483      /* Offset relative to start of frame */ 
    15211484      offset = st->subframeSize*sub; 
    1522       /* Original signal */ 
    1523       sp=st->frame+offset; 
    15241485      /* Excitation */ 
    15251486      exc=st->exc+offset; 
    1526       /* Excitation after post-filter*/ 
    1527  
    1528       /* LSP interpolation (quantized and unquantized) */ 
    1529       lsp_interpolate(st->old_qlsp, st->qlsp, st->interp_qlsp, st->lpcSize, sub, st->nbSubframes); 
    1530  
    1531       /* Make sure the LSP's are stable */ 
    1532       lsp_enforce_margin(st->interp_qlsp, st->lpcSize, LSP_MARGIN); 
    1533  
    1534  
    1535       /* Compute interpolated LPCs (unquantized) */ 
    1536       lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack); 
    1537  
    1538       /* Compute enhanced synthesis filter */ 
    1539       if (st->lpc_enh_enabled) 
    1540       { 
    1541          bw_lpc(SUBMODE(lpc_enh_k1), st->interp_qlpc, awk1, st->lpcSize); 
    1542          bw_lpc(SUBMODE(lpc_enh_k2), st->interp_qlpc, awk2, st->lpcSize); 
    1543          bw_lpc(SUBMODE(lpc_enh_k3), st->interp_qlpc, awk3, st->lpcSize); 
    1544       } 
    1545  
    1546       /* Compute analysis filter at w=pi */ 
    1547       { 
    1548          spx_word32_t pi_g=LPC_SCALING; 
    1549          for (i=0;i<st->lpcSize;i+=2) 
    1550          { 
    1551             /*pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];*/ 
    1552             pi_g = ADD32(pi_g, SUB32(st->interp_qlpc[i+1],st->interp_qlpc[i])); 
    1553          } 
    1554          st->pi_gain[sub] = pi_g; 
    1555       } 
     1487      /* Original signal */ 
     1488      sp=out+offset; 
     1489      if (st->innov_save) 
     1490         innov_save = st->innov_save+offset; 
     1491 
    15561492 
    15571493      /* Reset excitation */ 
     
    15961532         if (st->lbr_48k) 
    15971533         { 
    1598              SUBMODE(ltp_unquant)(exc, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params),  
     1534             SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params),  
    15991535                                  st->subframeSize, &pitch, &pitch_gain[0], bits, stack,  
    16001536                                  st->count_lost, offset, st->last_pitch_gain, ol_pitch_id); 
     
    16021538#endif 
    16031539 
    1604              SUBMODE(ltp_unquant)(exc, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params),  
     1540             SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params),  
    16051541                                  st->subframeSize, &pitch, &pitch_gain[0], bits, stack,  
    16061542                                  st->count_lost, offset, st->last_pitch_gain, 0); 
     
    16101546#endif 
    16111547 
    1612           
    1613          /* If we had lost frames, check energy of last received frame */ 
    1614          if (st->count_lost && ol_gain < st->last_ol_gain) 
    1615          { 
    1616             /*float fact = (float)ol_gain/(st->last_ol_gain+1); 
    1617             for (i=0;i<st->subframeSize;i++) 
    1618             exc[i]*=fact;*/ 
    1619             spx_word16_t fact = DIV32_16(SHL32(EXTEND32(ol_gain),15),st->last_ol_gain+1); 
    1620             for (i=0;i<st->subframeSize;i++) 
    1621                exc[i] = MULT16_32_Q15(fact, exc[i]); 
    1622          } 
    1623  
    16241548         tmp = gain_3tap_to_1tap(pitch_gain); 
    16251549 
    16261550         pitch_average += tmp; 
    1627          if (tmp>best_pitch_gain) 
     1551         if ((tmp>best_pitch_gain&&ABS(2*best_pitch-pitch)>=3&&ABS(3*best_pitch-pitch)>=4&&ABS(4*best_pitch-pitch)>=5)  
     1552              || (tmp>MULT16_16_Q15(QCONST16(.6,15),best_pitch_gain)&&(ABS(best_pitch-2*pitch)<3||ABS(best_pitch-3*pitch)<4||ABS(best_pitch-4*pitch)<5))  
     1553              || (MULT16_16_Q15(QCONST16(.67,15),tmp)>best_pitch_gain&&(ABS(2*best_pitch-pitch)<3||ABS(3*best_pitch-pitch)<4||ABS(4*best_pitch-pitch)<5)) ) 
    16281554         { 
    16291555            best_pitch = pitch; 
    1630             best_pitch_gain = tmp; 
     1556            if (tmp > best_pitch_gain) 
     1557               best_pitch_gain = tmp; 
    16311558         } 
    16321559      } else { 
     
    16381565         int q_energy; 
    16391566         spx_word32_t ener; 
    1640          spx_sig_t *innov; 
    16411567          
    1642          innov = st->innov+sub*st->subframeSize; 
    16431568         for (i=0;i<st->subframeSize;i++) 
    16441569            innov[i]=0; 
     
    16821607            { 
    16831608               if (st->voc_offset>=0) 
    1684                   exc[st->voc_offset]=SIG_SCALING*sqrt(1.0*ol_pitch); 
     1609                  exc[st->voc_offset]=sqrt(1.0*ol_pitch); 
    16851610               st->voc_offset+=ol_pitch; 
    16861611            } 
     
    16941619            for (i=0;i<st->subframeSize;i++) 
    16951620            { 
    1696                float exci=exc[i]; 
    1697                exc[i]=.8*g*exc[i]*ol_gain/SIG_SCALING + .6*g*st->voc_m1*ol_gain/SIG_SCALING + .5*g*innov[i] - .5*g*st->voc_m2 + (1-g)*innov[i]; 
     1621               spx_word16_t exci=exc[i]; 
     1622               /* FIXME: cleanup the innov[i]/SIG_SCALING */ 
     1623               exc[i]=.8*g*exc[i]*PSHR32(ol_gain,SIG_SHIFT) + .6*g*st->voc_m1*PSHR32(ol_gain,SIG_SHIFT) + (1-.5*g)*PSHR32(innov[i],SIG_SHIFT) - .5*g*PSHR32(st->voc_m2,SIG_SHIFT); 
    16981624               st->voc_m1 = exci; 
    16991625               st->voc_m2=innov[i]; 
     
    17031629         } else { 
    17041630            for (i=0;i<st->subframeSize;i++) 
    1705                exc[i]=ADD32(exc[i],innov[i]); 
     1631               exc[i]=PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT); 
    17061632            /*print_vec(exc, 40, "innov");*/ 
     1633         } 
     1634         if (innov_save) 
     1635         { 
     1636            for (i=0;i<st->subframeSize;i++) 
     1637               innov_save[i] = innov[i]; 
    17071638         } 
    17081639         /* Decode second codebook (only for some modes) */ 
     
    17151646               innov2[i]=0; 
    17161647            SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack); 
    1717             signal_mul(innov2, innov2, (spx_word32_t) (ener*(1/2.2)), st->subframeSize); 
     1648            signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545,15),ener), st->subframeSize); 
    17181649            for (i=0;i<st->subframeSize;i++) 
    1719                exc[i] = ADD32(exc[i],innov2[i]); 
     1650               exc[i] = ADD16(exc[i],PSHR32(innov2[i],SIG_SHIFT)); 
     1651            if (innov_save) 
     1652            { 
     1653               for (i=0;i<st->subframeSize;i++) 
     1654                  innov_save[i] = ADD32(innov_save[i],innov2[i]); 
     1655            } 
    17201656            stack = tmp_stack; 
    17211657         } 
    1722  
    1723       } 
    1724  
    1725       /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ 
    1726       if (st->count_lost)  
    1727       { 
    1728          spx_word16_t exc_ener; 
    1729          spx_word32_t gain32; 
    1730          spx_word16_t gain; 
    1731          exc_ener = compute_rms (exc, st->subframeSize); 
    1732          gain32 = DIV32(ol_gain, ADD16(exc_ener,1)); 
     1658      } 
     1659   } 
     1660    
     1661   ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t); 
     1662 
     1663   if (st->lpc_enh_enabled && SUBMODE(comb_gain)>0 && !st->count_lost) 
     1664   { 
     1665      multicomb(st->exc-st->subframeSize, out, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); 
     1666      multicomb(st->exc+st->subframeSize, out+2*st->subframeSize, st->interp_qlpc, st->lpcSize, 2*st->subframeSize, best_pitch, 40, SUBMODE(comb_gain), stack); 
     1667   } else { 
     1668      for (i=0;i<st->frameSize;i++) 
     1669         out[i]=st->exc[i-st->subframeSize]; 
     1670   } 
     1671    
     1672   /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ 
     1673   if (st->count_lost)  
     1674   { 
     1675      spx_word16_t exc_ener; 
     1676      spx_word32_t gain32; 
     1677      spx_word16_t gain; 
     1678      exc_ener = compute_rms16 (st->exc, st->frameSize); 
     1679      gain32 = PDIV32(ol_gain, ADD16(exc_ener,1)); 
    17331680#ifdef FIXED_POINT 
    1734          if (gain32 > 32768) 
    1735             gain32 = 32768; 
    1736          gain = EXTRACT16(gain32); 
     1681      if (gain32 > 32768) 
     1682         gain32 = 32768; 
     1683      gain = EXTRACT16(gain32); 
    17371684#else 
    1738          if (gain32 > 2) 
    1739             gain32=2; 
    1740          gain = gain32; 
    1741 #endif 
    1742          for (i=0;i<st->subframeSize;i++) 
    1743             exc[i] = MULT16_32_Q14(gain, exc[i]); 
    1744       } 
    1745  
    1746       for (i=0;i<st->subframeSize;i++) 
    1747          sp[i]=exc[i]; 
    1748  
    1749       /* Signal synthesis */ 
    1750       if (st->lpc_enh_enabled && SUBMODE(comb_gain)>0) 
    1751          comb_filter(exc, sp, st->interp_qlpc, st->lpcSize, st->subframeSize, 
    1752                               pitch, pitch_gain, SUBMODE(comb_gain), st->comb_mem); 
    1753  
    1754       if (st->lpc_enh_enabled) 
    1755       { 
    1756          /* Use enhanced LPC filter */ 
    1757          filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize,  
    1758                      st->mem_sp+st->lpcSize); 
    1759          filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1760                      st->mem_sp); 
    1761       } else { 
    1762          /* Use regular filter */ 
    1763          for (i=0;i<st->lpcSize;i++) 
    1764             st->mem_sp[st->lpcSize+i] = 0; 
    1765          iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1766                      st->mem_sp); 
    1767       } 
    1768    } 
    1769     
    1770    /*Copy output signal*/    
    1771    for (i=0;i<st->frameSize;i++) 
    1772    { 
    1773       spx_word32_t sig = PSHR32(st->frame[i],SIG_SHIFT); 
    1774       if (sig>32767) 
    1775          sig = 32767; 
    1776       if (sig<-32767) 
    1777          sig = -32767; 
    1778      out[i]=sig; 
     1685      if (gain32 > 2) 
     1686         gain32=2; 
     1687      gain = gain32; 
     1688#endif 
     1689      for (i=0;i<st->frameSize;i++) 
     1690      { 
     1691         st->exc[i] = MULT16_16_Q14(gain, st->exc[i]); 
     1692         out[i]=st->exc[i-st->subframeSize]; 
     1693      } 
     1694   } 
     1695 
     1696   /*Loop on subframes */ 
     1697   for (sub=0;sub<st->nbSubframes;sub++) 
     1698   { 
     1699      int offset; 
     1700      spx_word16_t *sp; 
     1701      spx_word16_t *exc; 
     1702      /* Offset relative to start of frame */ 
     1703      offset = st->subframeSize*sub; 
     1704      /* Original signal */ 
     1705      sp=out+offset; 
     1706      /* Excitation */ 
     1707      exc=st->exc+offset; 
     1708 
     1709      /* LSP interpolation (quantized and unquantized) */ 
     1710      lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes); 
     1711 
     1712      /* Make sure the LSP's are stable */ 
     1713      lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN); 
     1714 
     1715      /* Compute interpolated LPCs (unquantized) */ 
     1716      lsp_to_lpc(interp_qlsp, ak, st->lpcSize, stack); 
     1717 
     1718      /* Compute analysis filter at w=pi */ 
     1719      { 
     1720         spx_word32_t pi_g=LPC_SCALING; 
     1721         for (i=0;i<st->lpcSize;i+=2) 
     1722         { 
     1723            /*pi_g += -st->interp_qlpc[i] +  st->interp_qlpc[i+1];*/ 
     1724            pi_g = ADD32(pi_g, SUB32(EXTEND32(st->interp_qlpc[i+1]),EXTEND32(st->interp_qlpc[i]))); 
     1725         } 
     1726         st->pi_gain[sub] = pi_g; 
     1727      } 
     1728       
     1729      iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
     1730                st->mem_sp, stack); 
     1731       
     1732      for (i=0;i<st->lpcSize;i++) 
     1733         st->interp_qlpc[i] = ak[i]; 
     1734 
    17791735   } 
    17801736 
     
    17841740   /* Store the LSPs for interpolation in the next frame */ 
    17851741   for (i=0;i<st->lpcSize;i++) 
    1786       st->old_qlsp[i] = st->qlsp[i]; 
     1742      st->old_qlsp[i] = qlsp[i]; 
    17871743 
    17881744   /* The next frame will not be the first (Duh!) */ 
     
    18401796      break; 
    18411797   case SPEEX_SET_ABR: 
    1842       st->abr_enabled = (*(int*)ptr); 
    1843       st->vbr_enabled = 1; 
    1844       { 
    1845          int i=10, rate, target; 
     1798      st->abr_enabled = (*(spx_int32_t*)ptr); 
     1799      st->vbr_enabled = st->abr_enabled!=0; 
     1800      if (st->vbr_enabled)  
     1801      { 
     1802         int i=10; 
     1803         spx_int32_t rate, target; 
    18461804         float vbr_qual; 
    1847          target = (*(int*)ptr); 
     1805         target = (*(spx_int32_t*)ptr); 
    18481806         while (i>=0) 
    18491807         { 
     
    18651823      break; 
    18661824   case SPEEX_GET_ABR: 
    1867       (*(int*)ptr) = st->abr_enabled; 
     1825      (*(spx_int32_t*)ptr) = st->abr_enabled; 
    18681826      break; 
    18691827   case SPEEX_SET_VBR_QUALITY: 
     
    18891847      break; 
    18901848   case SPEEX_GET_COMPLEXITY: 
    1891       (*(int*)ptr) = st->complexity; 
     1849      (*(spx_int32_t*)ptr) = st->complexity; 
    18921850      break; 
    18931851   case SPEEX_SET_BITRATE: 
    18941852      { 
    1895          int i=10, rate, target; 
    1896          target = (*(int*)ptr); 
     1853         int i=10; 
     1854         spx_int32_t rate, target; 
     1855         target = (*(spx_int32_t*)ptr); 
    18971856         while (i>=0) 
    18981857         { 
     
    19071866   case SPEEX_GET_BITRATE: 
    19081867      if (st->submodes[st->submodeID]) 
    1909          (*(int*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; 
     1868         (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; 
    19101869      else 
    1911          (*(int*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; 
     1870         (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; 
    19121871      break; 
    19131872   case SPEEX_SET_SAMPLING_RATE: 
    1914       st->sampling_rate = (*(int*)ptr); 
     1873      st->sampling_rate = (*(spx_int32_t*)ptr); 
    19151874      break; 
    19161875   case SPEEX_GET_SAMPLING_RATE: 
    1917       (*(int*)ptr)=st->sampling_rate; 
     1876      (*(spx_int32_t*)ptr)=st->sampling_rate; 
    19181877      break; 
    19191878   case SPEEX_RESET_STATE: 
     
    19231882         st->first = 1; 
    19241883         for (i=0;i<st->lpcSize;i++) 
    1925             st->lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1); 
     1884            st->old_lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1); 
    19261885         for (i=0;i<st->lpcSize;i++) 
    19271886            st->mem_sw[i]=st->mem_sw_whole[i]=st->mem_sp[i]=st->mem_exc[i]=0; 
    19281887         for (i=0;i<st->frameSize+st->max_pitch+1;i++) 
    19291888            st->excBuf[i]=st->swBuf[i]=0; 
    1930          for (i=0;i<st->windowSize;i++) 
    1931             st->inBuf[i]=0; 
     1889         for (i=0;i<st->windowSize-st->frameSize;i++) 
     1890            st->winBuf[i]=0; 
    19321891      } 
    19331892      break; 
     
    19491908      (*(int*)ptr)=(st->plc_tuning); 
    19501909      break; 
     1910   case SPEEX_SET_VBR_MAX_BITRATE: 
     1911      st->vbr_max = (*(spx_int32_t*)ptr); 
     1912      break; 
     1913   case SPEEX_GET_VBR_MAX_BITRATE: 
     1914      (*(spx_int32_t*)ptr) = st->vbr_max; 
     1915      break; 
     1916 
     1917 
     1918   /* This is all internal stuff past this point */ 
    19511919   case SPEEX_GET_PI_GAIN: 
    19521920      { 
     
    19601928      { 
    19611929         int i; 
    1962          spx_sig_t *e = (spx_sig_t*)ptr; 
     1930         spx_word16_t *e = (spx_word16_t*)ptr; 
    19631931         for (i=0;i<st->frameSize;i++) 
    19641932            e[i]=st->exc[i]; 
    19651933      } 
    19661934      break; 
    1967    case SPEEX_GET_INNOV: 
    1968       { 
    1969          int i; 
    1970          spx_sig_t *e = (spx_sig_t*)ptr; 
    1971          for (i=0;i<st->frameSize;i++) 
    1972             e[i]=st->innov[i]; 
    1973       } 
    1974       break; 
    19751935   case SPEEX_GET_RELATIVE_QUALITY: 
    19761936      (*(float*)ptr)=st->relative_quality; 
     1937      break; 
     1938   case SPEEX_SET_INNOVATION_SAVE: 
     1939      st->innov_save = ptr; 
    19771940      break; 
    19781941   default: 
     
    20081971   case SPEEX_GET_BITRATE: 
    20091972      if (st->submodes[st->submodeID]) 
    2010          (*(int*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; 
     1973         (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; 
    20111974      else 
    2012          (*(int*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; 
     1975         (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; 
    20131976      break; 
    20141977   case SPEEX_SET_SAMPLING_RATE: 
    2015       st->sampling_rate = (*(int*)ptr); 
     1978      st->sampling_rate = (*(spx_int32_t*)ptr); 
    20161979      break; 
    20171980   case SPEEX_GET_SAMPLING_RATE: 
    2018       (*(int*)ptr)=st->sampling_rate; 
     1981      (*(spx_int32_t*)ptr)=st->sampling_rate; 
    20191982      break; 
    20201983   case SPEEX_SET_HANDLER: 
     
    20372000      { 
    20382001         int i; 
    2039          for (i=0;i<2*st->lpcSize;i++) 
     2002         for (i=0;i<st->lpcSize;i++) 
    20402003            st->mem_sp[i]=0; 
    20412004         for (i=0;i<st->frameSize + st->max_pitch + 1;i++) 
    20422005            st->excBuf[i]=0; 
    2043          for (i=0;i<st->frameSize;i++) 
    2044             st->inBuf[i] = 0; 
    20452006      } 
    20462007      break; 
     
    20502011   case SPEEX_GET_SUBMODE_ENCODING: 
    20512012      (*(int*)ptr) = st->encode_submode; 
     2013      break; 
     2014   case SPEEX_GET_LOOKAHEAD: 
     2015      (*(int*)ptr)=st->subframeSize; 
    20522016      break; 
    20532017   case SPEEX_GET_PI_GAIN: 
     
    20622026      { 
    20632027         int i; 
    2064          spx_sig_t *e = (spx_sig_t*)ptr; 
     2028         spx_word16_t *e = (spx_word16_t*)ptr; 
    20652029         for (i=0;i<st->frameSize;i++) 
    20662030            e[i]=st->exc[i]; 
    20672031      } 
    20682032      break; 
    2069    case SPEEX_GET_INNOV: 
    2070       { 
    2071          int i; 
    2072          spx_sig_t *e = (spx_sig_t*)ptr; 
    2073          for (i=0;i<st->frameSize;i++) 
    2074             e[i]=st->innov[i]; 
    2075       } 
    2076       break; 
    20772033   case SPEEX_GET_DTX_STATUS: 
    20782034      *((int*)ptr) = st->dtx_enabled; 
     2035      break; 
     2036   case SPEEX_SET_INNOVATION_SAVE: 
     2037      st->innov_save = ptr; 
    20792038      break; 
    20802039   default: 
Note: See TracChangeset for help on using the changeset viewer.