Ignore:
Timestamp:
Nov 23, 2006 10:19:46 AM (18 years ago)
Author:
bennylp
Message:

Updated Speex to their latest SVN (1.2-beta). AEC seems
to work much better now and take less CPU, so I increased
default tail length in PJSUA to 800ms.

File:
1 edited

Legend:

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

    r641 r823  
    1 /* Copyright (C) 2002 Jean-Marc Valin  
     1/* Copyright (C) 2002-2006 Jean-Marc Valin  
    22   File: ltp.c 
    33   Long-Term Prediction functions 
     
    153153 
    154154#ifndef OVERRIDE_COMPUTE_PITCH_ERROR 
    155 PJ_INLINE(spx_word32_t) compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control) 
     155static inline spx_word32_t compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control) 
    156156{ 
    157157   spx_word32_t sum = 0; 
     
    178178   VARDECL(spx_word32_t *corr); 
    179179   VARDECL(spx_word32_t *energy); 
    180  
     180#ifdef FIXED_POINT 
     181   int scaledown = 0; 
     182#endif 
     183    
    181184   ALLOC(best_score, N, spx_word32_t); 
    182185   ALLOC(best_ener, N, spx_word32_t); 
     
    190193        pitch[i]=start; 
    191194   } 
    192  
     195#ifdef FIXED_POINT 
     196   for (i=-end;i<len;i++) 
     197   { 
     198      if (ABS16(sw[i])>16383) 
     199      { 
     200         scaledown=1; 
     201         break; 
     202      } 
     203   } 
     204   /* If the weighted input is close to saturation, then we scale it down */ 
     205   if (scaledown) 
     206   { 
     207      for (i=-end;i<len;i++) 
     208      { 
     209         sw[i]=SHR16(sw[i],1); 
     210      } 
     211   }       
     212#endif 
    193213   energy[0]=inner_prod(sw-start, sw-start, len); 
    194214   e0=inner_prod(sw, sw, len); 
     
    202222 
    203223   pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack); 
     224#ifdef FIXED_POINT 
     225   /* If we scaled weighted input down, we need to scale it up again (OK, so we've just lost the LSB, who cares?) */ 
     226   if (scaledown) 
     227   { 
     228      for (i=-end;i<len;i++) 
     229      { 
     230         sw[i]=SHL16(sw[i],1); 
     231      } 
     232   }       
     233#endif 
    204234 
    205235   /* FIXME: Fixed-point and floating-point code should be merged */ 
     
    343373int  *cdbk_index, 
    344374int plc_tuning, 
    345 spx_word32_t cumul_gain 
     375spx_word32_t cumul_gain, 
     376int scaledown 
    346377) 
    347378{ 
     
    367398   x[2]=tmp1+2*nsf; 
    368399    
     400   for (j=0;j<nsf;j++) 
     401      new_target[j] = target[j]; 
     402 
    369403   { 
    370404      VARDECL(spx_mem_t *mm); 
     
    380414            e[j]=0; 
    381415      } 
     416#ifdef FIXED_POINT 
     417      /* Scale target and excitation down if needed (avoiding overflow) */ 
     418      if (scaledown) 
     419      { 
     420         for (j=0;j<nsf;j++) 
     421            e[j] = SHR16(e[j],1); 
     422         for (j=0;j<nsf;j++) 
     423            new_target[j] = SHR16(new_target[j],1); 
     424      } 
     425#endif 
    382426      for (j=0;j<p;j++) 
    383427         mm[j] = 0; 
     
    392436   { 
    393437      spx_word16_t e0=exc2[-pitch-1+i]; 
     438#ifdef FIXED_POINT 
     439      /* Scale excitation down if needed (avoiding overflow) */ 
     440      if (scaledown) 
     441         e0 = SHR16(e0,1); 
     442#endif 
    394443      x[i][0]=MULT16_16_Q14(r[0], e0); 
    395444      for (j=0;j<nsf-1;j++) 
     
    398447 
    399448   for (i=0;i<3;i++) 
    400       corr[i]=inner_prod(x[i],target,nsf); 
     449      corr[i]=inner_prod(x[i],new_target,nsf); 
    401450   for (i=0;i<3;i++) 
    402451      for (j=0;j<=i;j++) 
     
    479528      spx_word32_t tmp = ADD32(ADD32(MULT16_16(gain[0],x[2][i]),MULT16_16(gain[1],x[1][i])), 
    480529                            MULT16_16(gain[2],x[0][i])); 
    481       new_target[i] = SUB16(target[i], EXTRACT16(PSHR32(tmp,6))); 
     530      new_target[i] = SUB16(new_target[i], EXTRACT16(PSHR32(tmp,6))); 
    482531   } 
    483532   err = inner_prod(new_target, new_target, nsf); 
     
    521570   const signed char *gain_cdbk; 
    522571   int   gain_cdbk_size; 
    523     
     572   int scaledown=0; 
     573          
    524574   VARDECL(int *nbest); 
    525575    
     
    546596   } 
    547597    
     598#ifdef FIXED_POINT 
     599   /* Check if we need to scale everything down in the pitch search to avoid overflows */ 
     600   for (i=0;i<nsf;i++) 
     601   { 
     602      if (ABS16(target[i])>16383) 
     603      { 
     604         scaledown=1; 
     605         break; 
     606      } 
     607   } 
     608   for (i=-end;i<nsf;i++) 
     609   { 
     610      if (ABS16(exc2[i])>16383) 
     611      { 
     612         scaledown=1; 
     613         break; 
     614      } 
     615   } 
     616#endif 
    548617   if (N>end-start+1) 
    549618      N=end-start+1; 
     
    563632         exc[j]=0; 
    564633      err=pitch_gain_search_3tap(target, ak, awk1, awk2, exc, gain_cdbk, gain_cdbk_size, pitch, p, nsf, 
    565                                  bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain); 
     634                                 bits, stack, exc2, r, new_target, &cdbk_index, plc_tuning, *cumul_gain, scaledown); 
    566635      if (err<best_err || best_err<0) 
    567636      { 
     
    589658   for (i=0;i<nsf;i++) 
    590659      target[i]=best_target[i]; 
    591  
     660#ifdef FIXED_POINT 
     661   /* Scale target back up if needed */ 
     662   if (scaledown) 
     663   { 
     664      for (i=0;i<nsf;i++) 
     665         target[i]=SHL16(target[i],1); 
     666   } 
     667#endif 
    592668   return pitch; 
    593669} 
Note: See TracChangeset for help on using the changeset viewer.