Fixed stuff that got broken during the forward-backward split of the FFT

This commit is contained in:
Jean-Marc Valin 2008-02-22 12:13:59 +11:00
parent df3cb9be1f
commit af8402e033
3 changed files with 59 additions and 5 deletions

View file

@ -68,7 +68,7 @@ struct kiss_fft_state{
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
# define C_MULC(m,a,b) \ # define C_MULC(m,a,b) \
do{ (m).r = sround( smul((a).r,(b).r) + smul((a).i,(b).i) ); \ do{ (m).r = sround( smul((a).r,(b).r) + smul((a).i,(b).i) ); \
(m).i = smul((a).i,(b).r) - sround( smul((a).r,(b).i) ); }while(0) (m).i = sround( smul((a).i,(b).r) - smul((a).r,(b).i) ); }while(0)
# define C_MUL4(m,a,b) \ # define C_MUL4(m,a,b) \
do{ (m).r = PSHR32( smul((a).r,(b).r) - smul((a).i,(b).i),17 ); \ do{ (m).r = PSHR32( smul((a).r,(b).r) - smul((a).i,(b).i),17 ); \
@ -85,6 +85,44 @@ struct kiss_fft_state{
do{ (c).r = sround( smul( (c).r , s ) ) ;\ do{ (c).r = sround( smul( (c).r , s ) ) ;\
(c).i = sround( smul( (c).i , s ) ) ; }while(0) (c).i = sround( smul( (c).i , s ) ) ; }while(0)
#define L1 32767
#define L2 -7651
#define L3 8277
#define L4 -626
static inline celt_word16_t _celt_cos_pi_2(celt_word16_t x)
{
celt_word16_t x2;
x2 = MULT16_16_P15(x,x);
return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2
))))))));
}
static inline celt_word16_t celt_cos_norm(celt_word32_t x)
{
x = x&0x0001ffff;
if (x>SHL32(EXTEND32(1), 16))
x = SUB32(SHL32(EXTEND32(1), 17),x);
if (x&0x00007fff)
{
if (x<SHL32(EXTEND32(1), 15))
{
return _celt_cos_pi_2(EXTRACT16(x));
} else {
return NEG32(_celt_cos_pi_2(EXTRACT16(65536-x)));
}
} else {
if (x&0x0000ffff)
return 0;
else if (x&0x0001ffff)
return -32767;
else
return 32767;
}
}
#else /* not FIXED_POINT*/ #else /* not FIXED_POINT*/
# define S_MUL(a,b) ( (a)*(b) ) # define S_MUL(a,b) ( (a)*(b) )

View file

@ -33,7 +33,7 @@ extern "C" {
#ifdef FIXED_POINT #ifdef FIXED_POINT
#include "arch.h" #include "arch.h"
# define kiss_fft_scalar spx_int16_t # define kiss_fft_scalar celt_int16_t
#else #else
# ifndef kiss_fft_scalar # ifndef kiss_fft_scalar
/* default is float */ /* default is float */

View file

@ -25,13 +25,17 @@ void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse)
im = -im; im = -im;
#ifdef FIXED_POINT #ifdef FIXED_POINT
if (!isinverse)
{
re /= nfft; re /= nfft;
im /= nfft; im /= nfft;
}
#endif #endif
ansr += in[k].r * re - in[k].i * im; ansr += in[k].r * re - in[k].i * im;
ansi += in[k].r * im + in[k].i * re; ansi += in[k].r * im + in[k].i * re;
} }
/*printf ("%d %d ", (int)ansr, (int)ansi);*/
difr = ansr - out[bin].r; difr = ansr - out[bin].r;
difi = ansi - out[bin].i; difi = ansi - out[bin].i;
errpow += difr*difr + difi*difi; errpow += difr*difr + difi*difi;
@ -54,11 +58,23 @@ void test1d(int nfft,int isinverse)
in[k].i = (rand() % 65536) - 32768; in[k].i = (rand() % 65536) - 32768;
} }
if (isinverse)
{
for (k=0;k<nfft;++k) {
in[k].r /= nfft;
in[k].i /= nfft;
}
}
/*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
if (isinverse) if (isinverse)
kiss_ifft(cfg,in,out); kiss_ifft(cfg,in,out);
else else
kiss_fft(cfg,in,out); kiss_fft(cfg,in,out);
/*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
check(in,out,nfft,isinverse); check(in,out,nfft,isinverse);
free(in); free(in);