123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "lpc.h"
- #ifdef BFIN_ASM
- #include "lpc_bfin.h"
- #endif
- spx_word32_t _spx_lpc(
- spx_coef_t *lpc,
- const spx_word16_t *ac,
- int p
- )
- {
- int i, j;
- spx_word16_t r;
- spx_word16_t error = ac[0];
- if (ac[0] == 0)
- {
- for (i = 0; i < p; i++)
- lpc[i] = 0;
- return 0;
- }
- for (i = 0; i < p; i++) {
-
- spx_word32_t rr = NEG32(SHL32(EXTEND32(ac[i + 1]),13));
- for (j = 0; j < i; j++)
- rr = SUB32(rr,MULT16_16(lpc[j],ac[i - j]));
- #ifdef FIXED_POINT
- r = DIV32_16(rr+PSHR32(error,1),ADD16(error,8));
- #else
- r = rr/(error+.003*ac[0]);
- #endif
-
- lpc[i] = r;
- for (j = 0; j < i>>1; j++)
- {
- spx_word16_t tmp = lpc[j];
- lpc[j] = MAC16_16_P13(lpc[j],r,lpc[i-1-j]);
- lpc[i-1-j] = MAC16_16_P13(lpc[i-1-j],r,tmp);
- }
- if (i & 1)
- lpc[j] = MAC16_16_P13(lpc[j],lpc[j],r);
- error = SUB16(error,MULT16_16_Q13(r,MULT16_16_Q13(error,r)));
- }
- return error;
- }
- #ifdef FIXED_POINT
- #ifndef OVERRIDE_SPEEX_AUTOCORR
- void _spx_autocorr(
- const spx_word16_t *x,
- spx_word16_t *ac,
- int lag,
- int n
- )
- {
- spx_word32_t d;
- int i, j;
- spx_word32_t ac0=1;
- int shift, ac_shift;
-
- for (j=0;j<n;j++)
- ac0 = ADD32(ac0,SHR32(MULT16_16(x[j],x[j]),8));
- ac0 = ADD32(ac0,n);
- shift = 8;
- while (shift && ac0<0x40000000)
- {
- shift--;
- ac0 <<= 1;
- }
- ac_shift = 18;
- while (ac_shift && ac0<0x40000000)
- {
- ac_shift--;
- ac0 <<= 1;
- }
-
-
- for (i=0;i<lag;i++)
- {
- d=0;
- for (j=i;j<n;j++)
- {
- d = ADD32(d,SHR32(MULT16_16(x[j],x[j-i]), shift));
- }
-
- ac[i] = SHR32(d, ac_shift);
- }
- }
- #endif
- #else
- void _spx_autocorr(
- const spx_word16_t *x,
- float *ac,
- int lag,
- int n
- )
- {
- float d;
- int i;
- while (lag--)
- {
- for (i = lag, d = 0; i < n; i++)
- d += x[i] * x[i-lag];
- ac[lag] = d;
- }
- ac[0] += 10;
- }
- #endif
|