forked from len0rd/rockbox
reuse the largest sin and cos tables for smaller sizes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14786 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
46c2363889
commit
6475ad7821
1 changed files with 24 additions and 32 deletions
|
|
@ -22,10 +22,7 @@
|
||||||
#include "wmafixed.h"
|
#include "wmafixed.h"
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
|
|
||||||
fixed32 *tcosarray[5], *tsinarray[5];
|
fixed32 tcos0[1024], tsin0[1024]; //these are the sin and cos rotations used by the MDCT
|
||||||
fixed32 tcos0[1024], tcos1[512], tcos2[256], tcos3[128], tcos4[64]; //these are the sin and cos rotations used by the MDCT
|
|
||||||
fixed32 tsin0[1024], tsin1[512], tsin2[256], tsin3[128], tsin4[64];
|
|
||||||
|
|
||||||
uint16_t revtab0[1024];
|
uint16_t revtab0[1024];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,32 +30,16 @@ uint16_t revtab0[1024];
|
||||||
*/
|
*/
|
||||||
int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
|
int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
|
||||||
{
|
{
|
||||||
int n, n4, i;
|
int n;
|
||||||
// fixed32 alpha;
|
// fixed32 alpha;
|
||||||
|
|
||||||
|
|
||||||
memset(s, 0, sizeof(*s));
|
memset(s, 0, sizeof(*s));
|
||||||
n = 1 << nbits; //nbits ranges from 12 to 8 inclusive
|
n = 1 << nbits; //nbits ranges from 12 to 8 inclusive
|
||||||
|
|
||||||
s->nbits = nbits;
|
s->nbits = nbits;
|
||||||
s->n = n;
|
s->n = n;
|
||||||
n4 = n >> 2;
|
|
||||||
s->tcos = tcosarray[12-nbits];
|
|
||||||
s->tsin = tsinarray[12-nbits];
|
|
||||||
for(i=0;i<n4;i++)
|
|
||||||
{
|
|
||||||
//fixed32 pi2 = fixmul32(0x20000, M_PI_F);
|
|
||||||
fixed32 ip = itofix32(i) + 0x2000;
|
|
||||||
ip = ip >> nbits;
|
|
||||||
//ip = fixdiv32(ip,itofix32(n)); // PJJ optimize
|
|
||||||
//alpha = fixmul32(TWO_M_PI_F, ip);
|
|
||||||
//s->tcos[i] = -fixcos32(alpha); //alpha between 0 and pi/2
|
|
||||||
//s->tsin[i] = -fixsin32(alpha);
|
|
||||||
|
|
||||||
s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i])); //I can't remember why this works, but it seems to agree for ~24 bits, maybe more!
|
|
||||||
s->tcos[i] *=-1;
|
|
||||||
}
|
|
||||||
(&s->fft)->nbits = nbits-2;
|
(&s->fft)->nbits = nbits-2;
|
||||||
|
|
||||||
(&s->fft)->inverse = inverse;
|
(&s->fft)->inverse = inverse;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -76,8 +57,6 @@ void ff_imdct_calc(MDCTContext *s,
|
||||||
fixed32 *input)
|
fixed32 *input)
|
||||||
{
|
{
|
||||||
int k, n8, n4, n2, n, j,scale;
|
int k, n8, n4, n2, n, j,scale;
|
||||||
const fixed32 *tcos = s->tcos;
|
|
||||||
const fixed32 *tsin = s->tsin;
|
|
||||||
const fixed32 *in1, *in2;
|
const fixed32 *in1, *in2;
|
||||||
FFTComplex *z1 = (FFTComplex *)output;
|
FFTComplex *z1 = (FFTComplex *)output;
|
||||||
FFTComplex *z2 = (FFTComplex *)input;
|
FFTComplex *z2 = (FFTComplex *)input;
|
||||||
|
|
@ -96,19 +75,21 @@ void ff_imdct_calc(MDCTContext *s,
|
||||||
|
|
||||||
for(k = 0; k < n4; k++)
|
for(k = 0; k < n4; k++)
|
||||||
{
|
{
|
||||||
j=revtab0[k<<revtabshift];
|
int kshift = k<<revtabshift;
|
||||||
CMUL(&z1[j].re, &z1[j].im, *in2, *in1, tcos[k], tsin[k]);
|
j=revtab0[kshift];
|
||||||
|
CMUL(&z1[j].re, &z1[j].im, *in2, *in1, tcos0[kshift], tsin0[kshift]);
|
||||||
in1 += 2;
|
in1 += 2;
|
||||||
in2 -= 2;
|
in2 -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
scale = fft_calc_unscaled(&s->fft, z1);
|
scale = fft_calc_unscaled(&s->fft, z1);
|
||||||
|
|
||||||
/* post rotation + reordering */
|
/* post rotation + reordering */
|
||||||
|
|
||||||
for(k = 0; k < n4; k++)
|
for(k = 0; k < n4; k++)
|
||||||
{
|
{
|
||||||
CMUL(&z2[k].re, &z2[k].im, (z1[k].re), (z1[k].im), tcos[k], tsin[k]);
|
int kshift = k<<revtabshift;
|
||||||
|
CMUL(&z2[k].re, &z2[k].im, (z1[k].re), (z1[k].im), tcos0[kshift], tsin0[kshift]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(k = 0; k < n8; k++)
|
for(k = 0; k < n8; k++)
|
||||||
|
|
@ -140,10 +121,6 @@ void ff_imdct_calc(MDCTContext *s,
|
||||||
int mdct_init_global(void)
|
int mdct_init_global(void)
|
||||||
{
|
{
|
||||||
int i,j,m;
|
int i,j,m;
|
||||||
/* init MDCT */
|
|
||||||
/*TODO: figure out how to fold this up into one array*/
|
|
||||||
tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4;
|
|
||||||
tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4;
|
|
||||||
/* init the MDCT bit reverse table here rather then in fft_init */
|
/* init the MDCT bit reverse table here rather then in fft_init */
|
||||||
|
|
||||||
for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/
|
for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/
|
||||||
|
|
@ -157,6 +134,21 @@ int mdct_init_global(void)
|
||||||
revtab0[i]=m;
|
revtab0[i]=m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i=0;i<1024;i++)
|
||||||
|
{
|
||||||
|
//fixed32 pi2 = fixmul32(0x20000, M_PI_F);
|
||||||
|
fixed32 ip = itofix32(i) + 0x2000;
|
||||||
|
ip = ip >> 12;
|
||||||
|
//ip = fixdiv32(ip,itofix32(n)); // PJJ optimize
|
||||||
|
//alpha = fixmul32(TWO_M_PI_F, ip);
|
||||||
|
//s->tcos[i] = -fixcos32(alpha); //alpha between 0 and pi/2
|
||||||
|
//s->tsin[i] = -fixsin32(alpha);
|
||||||
|
|
||||||
|
//I can't remember why this works, but it seems to agree for ~24 bits, maybe more!
|
||||||
|
tsin0[i] = - fsincos(ip<<16, &(tcos0[i]));
|
||||||
|
tcos0[i] *=-1;
|
||||||
|
}
|
||||||
|
|
||||||
fft_init_global();
|
fft_init_global();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue