Ignore:
Timestamp:
Nov 23, 2006 10:19:46 AM (17 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/pseudofloat.h

    r628 r823  
    3737 
    3838#include "misc.h" 
     39#include "math_approx.h" 
    3940#include <math.h> 
    4041 
     
    6566      return r; 
    6667   } 
    67    while (x>32767) 
    68    { 
    69       x >>= 1; 
    70       /*x *= .5;*/ 
    71       e++; 
    72    } 
    73    while (x<16383) 
    74    { 
    75       x <<= 1; 
    76       /*x *= 2;*/ 
    77       e--; 
    78    } 
     68   e = spx_ilog2(ABS32(x))-14; 
     69   x = VSHR32(x, e); 
    7970   if (sign) 
    8071   { 
     
    167158{ 
    168159   if (a.m==0) 
    169       return b.m<0; 
     160      return b.m>0; 
    170161   else if (b.m==0) 
    171       return a.m>0;    
     162      return a.m<0;    
    172163   if ((a).e > (b).e) 
    173164      return ((a).m>>1) < ((b).m>>MIN(15,(a).e-(b).e+1)); 
     
    205196} 
    206197 
     198static inline spx_float_t FLOAT_AMULT(spx_float_t a, spx_float_t b) 
     199{ 
     200   spx_float_t r; 
     201   r.m = (spx_int16_t)((spx_int32_t)(a).m*(b).m>>15); 
     202   r.e = (a).e+(b).e+15; 
     203   return r;    
     204} 
     205 
    207206 
    208207static inline spx_float_t FLOAT_SHL(spx_float_t a, int b) 
     
    217216{ 
    218217   if (a.e<0) 
    219       return EXTRACT16((EXTEND32(a.m)+(1<<(-a.e-1)))>>-a.e); 
     218      return EXTRACT16((EXTEND32(a.m)+(EXTEND32(1)<<(-a.e-1)))>>-a.e); 
    220219   else 
    221220      return a.m<<a.e; 
    222221} 
    223222 
     223static inline spx_int32_t FLOAT_EXTRACT32(spx_float_t a) 
     224{ 
     225   if (a.e<0) 
     226      return (EXTEND32(a.m)+(EXTEND32(1)<<(-a.e-1)))>>-a.e; 
     227   else 
     228      return EXTEND32(a.m)<<a.e; 
     229} 
     230 
    224231static inline spx_int32_t FLOAT_MUL32(spx_float_t a, spx_word32_t b) 
    225232{ 
    226    if (a.e<-15) 
    227       return SHR32(MULT16_32_Q15(a.m, b),-a.e-15); 
    228    else 
    229       return SHL32(MULT16_32_Q15(a.m, b),15+a.e); 
     233   return VSHR32(MULT16_32_Q15(a.m, b),-a.e-15); 
    230234} 
    231235 
    232236static inline spx_float_t FLOAT_MUL32U(spx_word32_t a, spx_word32_t b) 
    233237{ 
     238   int e1, e2; 
     239   spx_float_t r; 
     240   if (a==0 || b==0) 
     241   { 
     242      return FLOAT_ZERO; 
     243   } 
     244   e1 = spx_ilog2(ABS32(a)); 
     245   a = VSHR32(a, e1-14); 
     246   e2 = spx_ilog2(ABS32(b)); 
     247   b = VSHR32(b, e2-14); 
     248   r.m = MULT16_16_Q15(a,b); 
     249   r.e = e1+e2-13; 
     250   return r; 
     251} 
     252 
     253/* Do NOT attempt to divide by a negative number */ 
     254static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b) 
     255{ 
    234256   int e=0; 
    235257   spx_float_t r; 
    236    /* FIXME: Handle the sign */ 
    237258   if (a==0) 
    238259   { 
    239260      return FLOAT_ZERO; 
    240261   } 
    241    while (a>32767) 
     262   e = spx_ilog2(ABS32(a))-spx_ilog2(b.m-1)-15; 
     263   a = VSHR32(a, e); 
     264   if (ABS32(a)>=SHL32(EXTEND32(b.m-1),15)) 
    242265   { 
    243266      a >>= 1; 
    244267      e++; 
    245268   } 
    246    while (a<16384) 
    247    { 
    248       a <<= 1; 
    249       e--; 
    250    } 
    251    while (b>32767) 
    252    { 
    253       b >>= 1; 
    254       e++; 
    255    } 
    256    while (b<16384) 
    257    { 
    258       b <<= 1; 
    259       e--; 
    260    } 
    261    r.m = MULT16_16_Q15(a,b); 
    262    r.e = e+15; 
    263    return r; 
    264 } 
    265  
    266 static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b) 
    267 { 
    268    int e=0; 
    269    spx_float_t r; 
    270    /* FIXME: Handle the sign */ 
     269   r.m = DIV32_16(a,b.m); 
     270   r.e = e-b.e; 
     271   return r; 
     272} 
     273 
     274 
     275/* Do NOT attempt to divide by a negative number */ 
     276static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b) 
     277{ 
     278   int e0=0,e=0; 
     279   spx_float_t r; 
    271280   if (a==0) 
    272281   { 
    273282      return FLOAT_ZERO; 
    274283   } 
    275    while (a<SHL32(EXTEND32(b.m),14)) 
    276    { 
    277       a <<= 1; 
    278       e--; 
    279    } 
    280    while (a>=SHL32(EXTEND32(b.m-1),15)) 
     284   if (b>32767) 
     285   { 
     286      e0 = spx_ilog2(b)-14; 
     287      b = VSHR32(b, e0); 
     288      e0 = -e0; 
     289   } 
     290   e = spx_ilog2(ABS32(a))-spx_ilog2(b-1)-15; 
     291   a = VSHR32(a, e); 
     292   if (ABS32(a)>=SHL32(EXTEND32(b-1),15)) 
    281293   { 
    282294      a >>= 1; 
    283295      e++; 
    284296   } 
    285    r.m = DIV32_16(a,b.m); 
    286    r.e = e-b.e; 
    287    return r; 
    288 } 
    289  
    290  
    291 static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b) 
    292 { 
    293    int e=0; 
    294    spx_float_t r; 
    295    /* FIXME: Handle the sign */ 
    296    if (a==0) 
    297    { 
    298       return FLOAT_ZERO; 
    299    } 
    300    while (b>32767) 
    301    { 
    302       b >>= 1; 
    303       e--; 
    304    } 
    305    while (a<SHL32(b,14)) 
    306    { 
    307       a <<= 1; 
    308       e--; 
    309    } 
    310    while (a>=SHL32(b-1,15)) 
    311    { 
    312       a >>= 1; 
    313       e++; 
    314    } 
     297   e += e0; 
    315298   r.m = DIV32_16(a,b); 
    316299   r.e = e; 
     
    318301} 
    319302 
     303/* Do NOT attempt to divide by a negative number */ 
    320304static inline spx_float_t FLOAT_DIVU(spx_float_t a, spx_float_t b) 
    321305{ 
     
    323307   spx_int32_t num; 
    324308   spx_float_t r; 
     309   if (b.m<=0) 
     310   { 
     311      speex_warning_int("Attempted to divide by", b.m); 
     312      return FLOAT_ONE; 
     313   } 
    325314   num = a.m; 
     315   a.m = ABS16(a.m); 
    326316   while (a.m >= b.m) 
    327317   { 
     
    332322   r.m = DIV32_16(num,b.m); 
    333323   r.e = a.e-b.e-15+e; 
     324   return r; 
     325} 
     326 
     327static inline spx_float_t FLOAT_SQRT(spx_float_t a) 
     328{ 
     329   spx_float_t r; 
     330   spx_int32_t m; 
     331   m = SHL32(EXTEND32(a.m), 14); 
     332   r.e = a.e - 14; 
     333   if (r.e & 1) 
     334   { 
     335      r.e -= 1; 
     336      m <<= 1; 
     337   } 
     338   r.e >>= 1; 
     339   r.m = spx_sqrt(m); 
    334340   return r; 
    335341} 
     
    343349#define PSEUDOFLOAT(x) (x) 
    344350#define FLOAT_MULT(a,b) ((a)*(b)) 
     351#define FLOAT_AMULT(a,b) ((a)*(b)) 
    345352#define FLOAT_MUL32(a,b) ((a)*(b)) 
    346353#define FLOAT_DIV32(a,b) ((a)/(b)) 
    347354#define FLOAT_EXTRACT16(a) (a) 
     355#define FLOAT_EXTRACT32(a) (a) 
    348356#define FLOAT_ADD(a,b) ((a)+(b)) 
    349357#define FLOAT_SUB(a,b) ((a)-(b)) 
     
    355363#define FLOAT_GT(a,b) ((a)>(b)) 
    356364#define FLOAT_DIVU(a,b) ((a)/(b)) 
     365#define FLOAT_SQRT(a) (spx_sqrt(a)) 
    357366 
    358367#endif 
Note: See TracChangeset for help on using the changeset viewer.