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/sb_celp.c

    r278 r628  
    202202#endif 
    203203 
     204extern const spx_word16_t lpc_window[]; 
     205 
    204206static void mix_and_saturate(spx_word32_t *x0, spx_word32_t *x1, spx_word16_t *out, int len) 
    205207{ 
     
    245247   st->subframeSize = mode->subframeSize; 
    246248   st->nbSubframes = mode->frameSize/mode->subframeSize; 
    247    st->windowSize = st->frame_size*3/2; 
     249   st->windowSize = st->frame_size+st->subframeSize; 
    248250   st->lpcSize=mode->lpcSize; 
    249251   st->bufSize=mode->bufSize; 
     
    278280   st->res=speex_alloc((st->frame_size)*sizeof(spx_sig_t)); 
    279281   st->sw=speex_alloc((st->frame_size)*sizeof(spx_sig_t)); 
    280    st->target=speex_alloc((st->frame_size)*sizeof(spx_sig_t)); 
    281    /*Asymmetric "pseudo-Hamming" window*/ 
    282    { 
    283       int part1, part2; 
    284       part1 = st->subframeSize*7/2; 
    285       part2 = st->subframeSize*5/2; 
    286       st->window = speex_alloc((st->windowSize)*sizeof(spx_word16_t)); 
    287       for (i=0;i<part1;i++) 
    288          st->window[i]=(spx_word16_t)(SIG_SCALING*(.54-.46*cos(M_PI*i/part1))); 
    289       for (i=0;i<part2;i++) 
    290          st->window[part1+i]=(spx_word16_t)(SIG_SCALING*(.54+.46*cos(M_PI*i/part2))); 
    291    } 
     282   st->window= lpc_window; 
    292283 
    293284   st->lagWindow = speex_alloc((st->lpcSize+1)*sizeof(spx_word16_t)); 
     
    308299   st->interp_qlpc = speex_alloc(st->lpcSize*sizeof(spx_coef_t)); 
    309300   st->pi_gain = speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); 
    310  
     301   st->low_innov = speex_alloc((st->frame_size)*sizeof(spx_word32_t)); 
     302   speex_encoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, st->low_innov); 
     303   st->innov_save = NULL; 
     304    
    311305   st->mem_sp = speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); 
    312306   st->mem_sp2 = speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); 
     
    315309   st->vbr_quality = 8; 
    316310   st->vbr_enabled = 0; 
     311   st->vbr_max = 0; 
     312   st->vbr_max_high = 20000;  /* We just need a big value here */ 
    317313   st->vad_enabled = 0; 
    318314   st->abr_enabled = 0; 
     
    351347   speex_free(st->res); 
    352348   speex_free(st->sw); 
    353    speex_free(st->target); 
    354    speex_free(st->window); 
    355349   speex_free(st->lagWindow); 
    356350 
     
    385379   VARDECL(spx_mem_t *mem); 
    386380   VARDECL(spx_sig_t *innov); 
     381   VARDECL(spx_word16_t *target); 
    387382   VARDECL(spx_word16_t *syn_resp); 
    388383   VARDECL(spx_word32_t *low_pi_gain); 
    389    VARDECL(spx_sig_t *low_exc); 
    390    VARDECL(spx_sig_t *low_innov); 
     384   VARDECL(spx_word16_t *low_exc); 
    391385   const SpeexSBMode *mode; 
    392386   int dtx; 
     
    423417 
    424418   ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); 
    425    ALLOC(low_exc, st->frame_size, spx_sig_t); 
    426    ALLOC(low_innov, st->frame_size, spx_sig_t); 
     419   ALLOC(low_exc, st->frame_size, spx_word16_t); 
    427420   speex_encoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain); 
    428421   speex_encoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc); 
    429    speex_encoder_ctl(st->st_low, SPEEX_GET_INNOV, low_innov); 
    430422    
    431423   speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, &dtx); 
     
    456448 
    457449   /* LPC to LSPs (x-domain) transform */ 
    458    roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 15, LSP_DELTA1, stack); 
     450   roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 10, LSP_DELTA1, stack); 
    459451   if (roots!=st->lpcSize) 
    460452   { 
    461       roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 11, LSP_DELTA2, stack); 
     453      roots = lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 10, LSP_DELTA2, stack); 
    462454      if (roots!=st->lpcSize) { 
    463455         /*If we can't find all LSP's, do some damage control and use a flat filter*/ 
    464456         for (i=0;i<st->lpcSize;i++) 
    465457         { 
    466             st->lsp[i]=M_PI*((float)(i+1))/(st->lpcSize+1); 
     458            st->lsp[i]=LSP_SCALING*M_PI*((float)(i+1))/(st->lpcSize+1); 
    467459         } 
    468460      } 
     
    522514               thresh = (st->vbr_quality-v1)   * mode->vbr_thresh[modeid][v1+1] +  
    523515                        (1+v1-st->vbr_quality) * mode->vbr_thresh[modeid][v1]; 
    524             if (st->relative_quality >= thresh) 
     516            if (st->relative_quality >= thresh && st->sampling_rate*st->submodes[modeid]->bits_per_frame/st->full_frame_size <= st->vbr_max_high) 
    525517               break; 
    526518            modeid--; 
     
    602594   ALLOC(syn_resp, st->subframeSize, spx_word16_t); 
    603595   ALLOC(innov, st->subframeSize, spx_sig_t); 
     596   ALLOC(target, st->subframeSize, spx_word16_t); 
    604597 
    605598   for (sub=0;sub<st->nbSubframes;sub++) 
    606599   { 
    607       spx_sig_t *exc, *sp, *res, *target, *sw; 
     600      spx_sig_t *exc, *sp, *res, *sw, *innov_save=NULL; 
    608601      spx_word16_t filter_ratio; 
    609602      int offset; 
     
    615608      exc=st->exc+offset; 
    616609      res=st->res+offset; 
    617       target=st->target+offset; 
    618610      sw=st->sw+offset; 
     611      /* Pointer for saving innovation */ 
     612      if (st->innov_save) 
     613      { 
     614         innov_save = st->innov_save+2*offset; 
     615         for (i=0;i<2*st->subframeSize;i++) 
     616            innov_save[i]=0; 
     617      } 
    619618       
    620619      /* LSP interpolation (quantized and unquantized) */ 
     
    643642      rl = low_pi_gain[sub]; 
    644643#ifdef FIXED_POINT 
    645       filter_ratio=DIV32_16(SHL(rl+82,2),SHR(82+rh,5)); 
     644      filter_ratio=PDIV32_16(SHL(rl+82,2),SHR(82+rh,5)); 
    646645#else 
    647646      filter_ratio=(rl+.01)/(rh+.01); 
     
    657656         float g; 
    658657         spx_word16_t el; 
    659          el = compute_rms(low_innov+offset, st->subframeSize); 
     658         el = compute_rms(st->low_innov+offset, st->subframeSize); 
    660659 
    661660         /* Gain to use if we want to use the low-band excitation for high-band */ 
    662          g=eh/(.01+el); 
     661         g=eh/(1.+el); 
    663662          
    664663#if 0 
     
    670669            for (i=0;i<st->lpcSize;i++) 
    671670               mem[i]=st->mem_sp[i]; 
    672             iir_mem2(low_innov+offset, st->interp_qlpc, tmp_sig, st->subframeSize, st->lpcSize, mem); 
     671            iir_mem2(st->low_innov+offset, st->interp_qlpc, tmp_sig, st->subframeSize, st->lpcSize, mem); 
    673672            g2 = compute_rms(sp, st->subframeSize)/(.01+compute_rms(tmp_sig, st->subframeSize)); 
    674673            /*fprintf (stderr, "gains: %f %f\n", g, g2);*/ 
     
    699698         spx_word32_t scale; 
    700699         spx_word16_t el; 
    701          el = compute_rms(low_exc+offset, st->subframeSize); 
    702  
    703          gc = DIV32_16(MULT16_16(filter_ratio,1+eh),1+el); 
     700         el = compute_rms16(low_exc+offset, st->subframeSize); 
     701 
     702         gc = PDIV32_16(MULT16_16(filter_ratio,1+eh),1+el); 
    704703 
    705704         /* This is a kludge that cleans up a historical bug */ 
     
    727726            gc *= 1.4142; 
    728727 
    729          scale = SHL(MULT16_16(DIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4); 
     728         scale = SHL32(MULT16_16(PDIV32_16(SHL32(EXTEND32(gc),SIG_SHIFT-6),filter_ratio),(1+el)),6); 
    730729 
    731730         compute_impulse_response(st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack); 
     
    752751         /* Compute target signal */ 
    753752         for (i=0;i<st->subframeSize;i++) 
    754             target[i]=sw[i]-res[i]; 
     753            target[i]=PSHR32(sw[i]-res[i],SIG_SHIFT); 
    755754 
    756755         for (i=0;i<st->subframeSize;i++) 
     
    774773            exc[i] = ADD32(exc[i], innov[i]); 
    775774 
     775         if (st->innov_save) 
     776         { 
     777            for (i=0;i<st->subframeSize;i++) 
     778               innov_save[2*i]=innov[i]; 
     779         } 
     780          
    776781         if (SUBMODE(double_codebook)) { 
    777782            char *tmp_stack=stack; 
     
    872877 
    873878   st->exc=speex_alloc((st->frame_size)*sizeof(spx_sig_t)); 
     879   st->excBuf=speex_alloc((st->subframeSize)*sizeof(spx_sig_t)); 
    874880 
    875881   st->qlsp = speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); 
     
    881887   st->mem_sp = speex_alloc((2*st->lpcSize)*sizeof(spx_mem_t)); 
    882888    
     889   st->low_innov = speex_alloc((st->frame_size)*sizeof(spx_word32_t)); 
     890   speex_decoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, st->low_innov); 
     891   st->innov_save = NULL; 
     892 
     893 
    883894   st->lpc_enh_enabled=0; 
    884895   st->seed = 1000; 
     
    907918   speex_free(st->g1_mem); 
    908919   speex_free(st->exc); 
     920   speex_free(st->excBuf); 
    909921   speex_free(st->qlsp); 
    910922   speex_free(st->old_qlsp); 
     
    920932{ 
    921933   int i; 
    922    VARDECL(spx_coef_t *awk1); 
    923    VARDECL(spx_coef_t *awk2); 
    924    VARDECL(spx_coef_t *awk3); 
    925934   int saved_modeid=0; 
    926935 
     
    935944   st->first=1; 
    936945    
    937    ALLOC(awk1, st->lpcSize+1, spx_coef_t); 
    938    ALLOC(awk2, st->lpcSize+1, spx_coef_t); 
    939    ALLOC(awk3, st->lpcSize+1, spx_coef_t); 
    940     
    941    if (st->lpc_enh_enabled) 
    942    { 
    943       spx_word16_t k1,k2,k3; 
    944       if (st->submodes[st->submodeID] != NULL) 
    945       { 
    946          k1=SUBMODE(lpc_enh_k1); 
    947          k2=SUBMODE(lpc_enh_k2); 
    948          k3=SUBMODE(lpc_enh_k3); 
    949       } else { 
    950          k1=k2=.7*GAMMA_SCALING; 
    951          k3 = 0; 
    952       } 
    953       bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); 
    954       bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); 
    955       bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); 
    956       /*fprintf (stderr, "%f %f %f\n", k1, k2, k3);*/ 
    957    } 
    958     
    959946    
    960947   /* Final signal synthesis from excitation */ 
     
    970957      st->high[i]=st->exc[i]; 
    971958 
    972    if (st->lpc_enh_enabled) 
    973    { 
    974       /* Use enhanced LPC filter */ 
    975       filter_mem2(st->high, awk2, awk1, st->high, st->frame_size, st->lpcSize,  
    976                   st->mem_sp+st->lpcSize); 
    977       filter_mem2(st->high, awk3, st->interp_qlpc, st->high, st->frame_size, st->lpcSize,  
    978                   st->mem_sp); 
    979    } else { 
    980       /* Use regular filter */ 
    981       for (i=0;i<st->lpcSize;i++) 
    982          st->mem_sp[st->lpcSize+i] = 0; 
    983       iir_mem2(st->high, st->interp_qlpc, st->high, st->frame_size, st->lpcSize,  
    984                st->mem_sp); 
    985    } 
     959   iir_mem2(st->high, st->interp_qlpc, st->high, st->frame_size, st->lpcSize,  
     960            st->mem_sp); 
    986961    
    987    /*iir_mem2(st->exc, st->interp_qlpc, st->high, st->frame_size, st->lpcSize, st->mem_sp);*/ 
    988962    
    989963   /* Reconstruct the original */ 
     
    1009983   char *stack; 
    1010984   VARDECL(spx_word32_t *low_pi_gain); 
    1011    VARDECL(spx_sig_t *low_exc); 
    1012    VARDECL(spx_sig_t *low_innov); 
    1013    VARDECL(spx_coef_t *awk1); 
    1014    VARDECL(spx_coef_t *awk2); 
    1015    VARDECL(spx_coef_t *awk3); 
     985   VARDECL(spx_word16_t *low_exc); 
     986   VARDECL(spx_coef_t *ak); 
    1016987   int dtx; 
    1017988   const SpeexSBMode *mode; 
     
    11021073 
    11031074   ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); 
    1104    ALLOC(low_exc, st->frame_size, spx_sig_t); 
    1105    ALLOC(low_innov, st->frame_size, spx_sig_t); 
     1075   ALLOC(low_exc, st->frame_size, spx_word16_t); 
    11061076   speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain); 
    11071077   speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc); 
    1108    speex_decoder_ctl(st->st_low, SPEEX_GET_INNOV, low_innov); 
    11091078 
    11101079   SUBMODE(lsp_unquant)(st->qlsp, st->lpcSize, bits); 
     
    11161085   } 
    11171086    
    1118    ALLOC(awk1, st->lpcSize+1, spx_coef_t); 
    1119    ALLOC(awk2, st->lpcSize+1, spx_coef_t); 
    1120    ALLOC(awk3, st->lpcSize+1, spx_coef_t); 
     1087   ALLOC(ak, st->lpcSize, spx_coef_t); 
    11211088 
    11221089   for (sub=0;sub<st->nbSubframes;sub++) 
    11231090   { 
    1124       spx_sig_t *exc, *sp; 
     1091      spx_sig_t *exc, *sp, *innov_save=NULL; 
    11251092      spx_word16_t filter_ratio; 
    11261093      spx_word16_t el=0; 
     
    11311098      sp=st->high+offset; 
    11321099      exc=st->exc+offset; 
     1100      /* Pointer for saving innovation */ 
     1101      if (st->innov_save) 
     1102      { 
     1103         innov_save = st->innov_save+2*offset; 
     1104         for (i=0;i<2*st->subframeSize;i++) 
     1105            innov_save[i]=0; 
     1106      } 
    11331107       
    11341108      /* LSP interpolation */ 
     
    11381112 
    11391113      /* LSP to LPC */ 
    1140       lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack); 
    1141  
    1142  
    1143       if (st->lpc_enh_enabled) 
    1144       { 
    1145          spx_word16_t k1,k2,k3; 
    1146          k1=SUBMODE(lpc_enh_k1); 
    1147          k2=SUBMODE(lpc_enh_k2); 
    1148          k3=SUBMODE(lpc_enh_k3); 
    1149          bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); 
    1150          bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); 
    1151          bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize); 
    1152          /*fprintf (stderr, "%f %f %f\n", k1, k2, k3);*/ 
    1153       } 
    1154  
     1114      lsp_to_lpc(st->interp_qlsp, ak, st->lpcSize, stack); 
    11551115 
    11561116      /* Calculate reponse ratio between the low and high filter in the middle 
     
    11671127         rl = low_pi_gain[sub]; 
    11681128#ifdef FIXED_POINT 
    1169          filter_ratio=DIV32_16(SHL(rl+82,2),SHR(82+rh,5)); 
     1129         filter_ratio=PDIV32_16(SHL(rl+82,2),SHR(82+rh,5)); 
    11701130#else 
    11711131         filter_ratio=(rl+.01)/(rh+.01); 
     
    11911151#if 0 
    11921152         for (i=0;i<st->subframeSize;i++) 
    1193             exc[i]=mode->folding_gain*g*low_innov[offset+i]; 
     1153            exc[i]=mode->folding_gain*g*st->low_innov[offset+i]; 
    11941154#else 
    11951155         { 
     
    12001160            for (i=0;i<st->subframeSize;i++) 
    12011161            { 
    1202                float e=tmp*g*mode->folding_gain*low_innov[offset+i]; 
     1162               float e=tmp*g*mode->folding_gain*st->low_innov[offset+i]; 
    12031163               tmp *= -1; 
    12041164               exc[i] = e; 
     
    12111171         } 
    12121172          
    1213          /*speex_rand_vec(mode->folding_gain*g*el, exc, st->subframeSize);*/ 
    12141173#endif     
    12151174      } else { 
     
    12181177         int qgc = speex_bits_unpack_unsigned(bits, 4); 
    12191178 
    1220          el = compute_rms(low_exc+offset, st->subframeSize); 
     1179         el = compute_rms16(low_exc+offset, st->subframeSize); 
    12211180 
    12221181#ifdef FIXED_POINT 
     
    12291188            gc *= 1.4142; 
    12301189 
    1231          scale = SHL(MULT16_16(DIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4); 
     1190         scale = SHL(MULT16_16(PDIV32_16(SHL(gc,SIG_SHIFT-6),filter_ratio),(1+el)),6); 
    12321191 
    12331192         SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,  
     
    12521211 
    12531212      } 
    1254  
     1213       
     1214      if (st->innov_save) 
     1215      { 
     1216         for (i=0;i<st->subframeSize;i++) 
     1217            innov_save[2*i]=exc[i]; 
     1218      } 
     1219       
    12551220      for (i=0;i<st->subframeSize;i++) 
    1256          sp[i]=exc[i]; 
    1257       if (st->lpc_enh_enabled) 
    1258       { 
    1259          /* Use enhanced LPC filter */ 
    1260          filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize,  
    1261                      st->mem_sp+st->lpcSize); 
    1262          filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1263                      st->mem_sp); 
    1264       } else { 
    1265          /* Use regular filter */ 
    1266          for (i=0;i<st->lpcSize;i++) 
    1267             st->mem_sp[st->lpcSize+i] = 0; 
    1268          iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
    1269                      st->mem_sp); 
    1270       } 
    1271       /*iir_mem2(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);*/ 
     1221         sp[i]=st->excBuf[i]; 
     1222      iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,  
     1223               st->mem_sp); 
     1224      for (i=0;i<st->subframeSize;i++) 
     1225         st->excBuf[i]=exc[i]; 
     1226      for (i=0;i<st->lpcSize;i++) 
     1227         st->interp_qlpc[i] = ak[i]; 
    12721228 
    12731229   } 
     
    13461302      break; 
    13471303   case SPEEX_SET_ABR: 
    1348       st->abr_enabled = (*(int*)ptr); 
    1349       st->vbr_enabled = 1; 
     1304      st->abr_enabled = (*(spx_int32_t*)ptr); 
     1305      st->vbr_enabled = st->abr_enabled!=0; 
    13501306      speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled); 
     1307      if (st->vbr_enabled)  
    13511308      { 
    13521309         int i=10, rate, target; 
    13531310         float vbr_qual; 
    1354          target = (*(int*)ptr); 
     1311         target = (*(spx_int32_t*)ptr); 
    13551312         while (i>=0) 
    13561313         { 
     
    13721329      break; 
    13731330   case SPEEX_GET_ABR: 
    1374       (*(int*)ptr) = st->abr_enabled; 
     1331      (*(spx_int32_t*)ptr) = st->abr_enabled; 
    13751332      break; 
    13761333   case SPEEX_SET_QUALITY: 
     
    13981355   case SPEEX_SET_BITRATE: 
    13991356      { 
    1400          int i=10, rate, target; 
    1401          target = (*(int*)ptr); 
     1357         int i=10; 
     1358         spx_int32_t rate, target; 
     1359         target = (*(spx_int32_t*)ptr); 
    14021360         while (i>=0) 
    14031361         { 
     
    14141372      /*fprintf (stderr, "before: %d\n", (*(int*)ptr));*/ 
    14151373      if (st->submodes[st->submodeID]) 
    1416          (*(int*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; 
     1374         (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; 
    14171375      else 
    1418          (*(int*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; 
     1376         (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; 
    14191377      /*fprintf (stderr, "after: %d\n", (*(int*)ptr));*/ 
    14201378      break; 
    14211379   case SPEEX_SET_SAMPLING_RATE: 
    14221380      { 
    1423          int tmp=(*(int*)ptr); 
     1381         spx_int32_t tmp=(*(spx_int32_t*)ptr); 
    14241382         st->sampling_rate = tmp; 
    14251383         tmp>>=1; 
     
    14281386      break; 
    14291387   case SPEEX_GET_SAMPLING_RATE: 
    1430       (*(int*)ptr)=st->sampling_rate; 
     1388      (*(spx_int32_t*)ptr)=st->sampling_rate; 
    14311389      break; 
    14321390   case SPEEX_RESET_STATE: 
     
    14551413      (*(int*)ptr) = 2*(*(int*)ptr) + QMF_ORDER - 1; 
    14561414      break; 
     1415   case SPEEX_SET_PLC_TUNING: 
     1416      speex_encoder_ctl(st->st_low, SPEEX_SET_PLC_TUNING, ptr); 
     1417      break; 
     1418   case SPEEX_GET_PLC_TUNING: 
     1419      speex_encoder_ctl(st->st_low, SPEEX_GET_PLC_TUNING, ptr); 
     1420      break; 
     1421   case SPEEX_SET_VBR_MAX_BITRATE: 
     1422      { 
     1423         st->vbr_max = (*(spx_int32_t*)ptr); 
     1424         if (SPEEX_SET_VBR_MAX_BITRATE<1) 
     1425         { 
     1426            speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &st->vbr_max); 
     1427            st->vbr_max_high = 17600; 
     1428         } else { 
     1429            spx_int32_t low_rate; 
     1430            /* FIXME: Need to adapt that to ultra-wideband */ 
     1431            if (st->vbr_max >= 42200) 
     1432            { 
     1433               st->vbr_max_high = 17600; 
     1434            } else if (st->vbr_max >= 27800) 
     1435            { 
     1436               st->vbr_max_high = 9600; 
     1437            } else if (st->vbr_max > 20600) 
     1438            { 
     1439               st->vbr_max_high = 5600; 
     1440            } else { 
     1441               st->vbr_max_high = 1800; 
     1442            } 
     1443            low_rate = st->vbr_max - st->vbr_max_high; 
     1444            speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &low_rate); 
     1445         } 
     1446      } 
     1447      break; 
     1448   case SPEEX_GET_VBR_MAX_BITRATE: 
     1449      (*(spx_int32_t*)ptr) = st->vbr_max; 
     1450      break; 
     1451 
     1452 
     1453   /* This is all internal stuff past this point */ 
    14571454   case SPEEX_GET_PI_GAIN: 
    14581455      { 
     
    14851482   case SPEEX_GET_RELATIVE_QUALITY: 
    14861483      (*(float*)ptr)=st->relative_quality; 
     1484      break; 
     1485   case SPEEX_SET_INNOVATION_SAVE: 
     1486      st->innov_save = ptr; 
    14871487      break; 
    14881488   default: 
     
    15351535      speex_decoder_ctl(st->st_low, request, ptr); 
    15361536      if (st->submodes[st->submodeID]) 
    1537          (*(int*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; 
     1537         (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; 
    15381538      else 
    1539          (*(int*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; 
     1539         (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; 
    15401540      break; 
    15411541   case SPEEX_SET_SAMPLING_RATE: 
    15421542      { 
    1543          int tmp=(*(int*)ptr); 
     1543         spx_int32_t tmp=(*(spx_int32_t*)ptr); 
    15441544         st->sampling_rate = tmp; 
    15451545         tmp>>=1; 
     
    15481548      break; 
    15491549   case SPEEX_GET_SAMPLING_RATE: 
    1550       (*(int*)ptr)=st->sampling_rate; 
     1550      (*(spx_int32_t*)ptr)=st->sampling_rate; 
    15511551      break; 
    15521552   case SPEEX_SET_HANDLER: 
     
    15711571   case SPEEX_GET_SUBMODE_ENCODING: 
    15721572      (*(int*)ptr) = st->encode_submode; 
     1573      break; 
     1574   case SPEEX_GET_LOOKAHEAD: 
     1575      speex_decoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); 
     1576      (*(int*)ptr) = 2*(*(int*)ptr); 
    15731577      break; 
    15741578   case SPEEX_GET_PI_GAIN: 
     
    16031607      speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, ptr); 
    16041608      break; 
     1609   case SPEEX_SET_INNOVATION_SAVE: 
     1610      st->innov_save = ptr; 
     1611      break; 
    16051612   default: 
    16061613      speex_warning_int("Unknown nb_ctl request: ", request); 
Note: See TracChangeset for help on using the changeset viewer.