ref: 31b189b419766b1429281910e4c39ebd8449c943
parent: 24eef1493e47ebe9b18f45a542adbecf35a1295a
author: Jean-Marc Valin <[email protected]>
date: Wed Aug 25 17:21:43 EDT 2010
static modes update for MDCT
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -203,7 +203,7 @@
fprintf(file, "{%d, %d, {", mode->mdct.n, mode->mdct.maxshift);
for (i=0;i<=mode->mdct.maxshift;i++)
- fprintf(file, "fft_state%d_%d, ", mode->Fs, mdctSize>>i);
+ fprintf(file, "&fft_state%d_%d, ", mode->Fs, mdctSize>>i);
fprintf (file, "}, mdct_twiddles%d_%d},\t/* mdct */\n", mode->Fs, mdctSize);
fprintf(file, "window%d,\t/* window */\n", mode->overlap);
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -41,7 +41,7 @@
)
{
kiss_fft_cpx * Fout2;
- kiss_twiddle_cpx * tw1;
+ const kiss_twiddle_cpx * tw1;
int i,j;
kiss_fft_cpx * Fout_beg = Fout;
for (i=0;i<N;i++)
@@ -74,7 +74,7 @@
)
{
kiss_fft_cpx * Fout2;
- kiss_twiddle_cpx * tw1;
+ const kiss_twiddle_cpx * tw1;
kiss_fft_cpx t;
int i,j;
kiss_fft_cpx * Fout_beg = Fout;
@@ -104,7 +104,7 @@
int mm
)
{
- kiss_twiddle_cpx *tw1,*tw2,*tw3;
+ const kiss_twiddle_cpx *tw1,*tw2,*tw3;
kiss_fft_cpx scratch[6];
const size_t m2=2*m;
const size_t m3=3*m;
@@ -153,7 +153,7 @@
int mm
)
{
- kiss_twiddle_cpx *tw1,*tw2,*tw3;
+ const kiss_twiddle_cpx *tw1,*tw2,*tw3;
kiss_fft_cpx scratch[6];
const size_t m2=2*m;
const size_t m3=3*m;
@@ -203,7 +203,7 @@
int i;
size_t k;
const size_t m2 = 2*m;
- kiss_twiddle_cpx *tw1,*tw2;
+ const kiss_twiddle_cpx *tw1,*tw2;
kiss_fft_cpx scratch[5];
kiss_twiddle_cpx epi3;
@@ -254,7 +254,7 @@
{
size_t i, k;
const size_t m2 = 2*m;
- kiss_twiddle_cpx *tw1,*tw2;
+ const kiss_twiddle_cpx *tw1,*tw2;
kiss_fft_cpx scratch[5];
kiss_twiddle_cpx epi3;
@@ -306,8 +306,8 @@
kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
int i, u;
kiss_fft_cpx scratch[13];
- kiss_twiddle_cpx * twiddles = st->twiddles;
- kiss_twiddle_cpx *tw;
+ const kiss_twiddle_cpx * twiddles = st->twiddles;
+ const kiss_twiddle_cpx *tw;
kiss_twiddle_cpx ya,yb;
kiss_fft_cpx * Fout_beg = Fout;
@@ -375,8 +375,8 @@
kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
int i, u;
kiss_fft_cpx scratch[13];
- kiss_twiddle_cpx * twiddles = st->twiddles;
- kiss_twiddle_cpx *tw;
+ const kiss_twiddle_cpx * twiddles = st->twiddles;
+ const kiss_twiddle_cpx *tw;
kiss_twiddle_cpx ya,yb;
kiss_fft_cpx * Fout_beg = Fout;
@@ -472,7 +472,7 @@
const kiss_fft_cpx * f,
size_t fstride,
int in_stride,
- celt_int16 * factors,
+ const celt_int16 * factors,
const kiss_fft_state *st,
int N,
int s2,
@@ -506,7 +506,7 @@
const kiss_fft_cpx * f,
size_t fstride,
int in_stride,
- celt_int16 * factors,
+ const celt_int16 * factors,
const kiss_fft_state *st,
int N,
int s2,
@@ -591,7 +591,7 @@
* The return value is a contiguous block of memory, allocated with malloc. As such,
* It can be freed with free(), rather than a kiss_fft-specific function.
* */
-kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_state *base)
+kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base)
{
kiss_fft_state *st=NULL;
size_t memneeded = sizeof(struct kiss_fft_state); /* twiddle factors*/
@@ -604,6 +604,9 @@
*lenmem = memneeded;
}
if (st) {
+ celt_int16 *bitrev;
+ kiss_twiddle_cpx *twiddles;
+
st->nfft=nfft;
#ifndef FIXED_POINT
st->scale = 1./nfft;
@@ -618,8 +621,8 @@
if (st->shift>=32)
return NULL;
} else {
- st->twiddles = (kiss_twiddle_cpx*)KISS_FFT_MALLOC(sizeof(kiss_twiddle_cpx)*nfft);
- compute_twiddles(st->twiddles, nfft);
+ st->twiddles = twiddles = (kiss_twiddle_cpx*)KISS_FFT_MALLOC(sizeof(kiss_twiddle_cpx)*nfft);
+ compute_twiddles(twiddles, nfft);
st->shift = -1;
}
if (!kf_factor(nfft,st->factors))
@@ -627,10 +630,10 @@
kiss_fft_free(st);
return NULL;
}
-
+
/* bitrev */
- st->bitrev = (celt_int16*)KISS_FFT_MALLOC(sizeof(celt_int16)*nfft);
- compute_bitrev_table(0, st->bitrev, 1,1, st->factors,st);
+ st->bitrev = bitrev = (celt_int16*)KISS_FFT_MALLOC(sizeof(celt_int16)*nfft);
+ compute_bitrev_table(0, bitrev, 1,1, st->factors,st);
}
return st;
}
@@ -641,7 +644,7 @@
}
-static void kiss_fft_stride(kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
+static void kiss_fft_stride(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{
if (fin == fout)
{
@@ -661,12 +664,12 @@
}
}
-void kiss_fft(kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+void kiss_fft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
{
kiss_fft_stride(cfg,fin,fout,1);
}
-static void kiss_ifft_stride(kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
+static void kiss_ifft_stride(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{
if (fin == fout)
{
@@ -680,15 +683,15 @@
}
}
-void kiss_ifft(kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+void kiss_ifft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
{
kiss_ifft_stride(cfg,fin,fout,1);
}
-void kiss_fft_free(kiss_fft_state *cfg)
+void kiss_fft_free(const kiss_fft_state *cfg)
{
- celt_free(cfg->bitrev);
+ celt_free((celt_int16*)cfg->bitrev);
if (cfg->shift < 0)
- celt_free(cfg->twiddles);
- celt_free(cfg);
+ celt_free((kiss_twiddle_cpx*)cfg->twiddles);
+ celt_free((kiss_fft_state*)cfg);
}
--- a/libcelt/kiss_fft.h
+++ b/libcelt/kiss_fft.h
@@ -110,8 +110,8 @@
#endif
int shift;
celt_int16 factors[2*MAXFACTORS];
- celt_int16 *bitrev;
- kiss_twiddle_cpx *twiddles;
+ const celt_int16 *bitrev;
+ const kiss_twiddle_cpx *twiddles;
} kiss_fft_state;
//typedef struct kiss_fft_state* kiss_fft_cfg;
@@ -139,7 +139,7 @@
* buffer size in *lenmem.
* */
-kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_state *base);
+kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base);
kiss_fft_state *kiss_fft_alloc(int nfft,void * mem,size_t * lenmem);
@@ -153,10 +153,10 @@
* Note that each element is complex and can be accessed like
f[k].r and f[k].i
* */
-void kiss_fft(kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
-void kiss_ifft(kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
+void kiss_fft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
+void kiss_ifft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
-void kiss_fft_free(kiss_fft_state *cfg);
+void kiss_fft_free(const kiss_fft_state *cfg);
#ifdef __cplusplus
--- a/libcelt/mdct.c
+++ b/libcelt/mdct.c
@@ -63,6 +63,7 @@
{
int i;
int N2, N4;
+ kiss_twiddle_scalar *trig;
l->n = N;
N2 = N>>1;
N4 = N>>2;
@@ -78,7 +79,7 @@
return;
#endif
}
- l->trig = (kiss_twiddle_scalar*)celt_alloc((N4+1)*sizeof(kiss_twiddle_scalar));
+ l->trig = trig = (kiss_twiddle_scalar*)celt_alloc((N4+1)*sizeof(kiss_twiddle_scalar));
if (l->trig==NULL)
return;
/* We have enough points that sine isn't necessary */
@@ -87,7 +88,7 @@
l->trig[i] = TRIG_UPSCALE*celt_cos_norm(DIV32(ADD32(SHL32(EXTEND32(i),17),N2),N));
#else
for (i=0;i<=N4;i++)
- l->trig[i] = cos(2*M_PI*i/N);
+ trig[i] = cos(2*M_PI*i/N);
#endif
}
@@ -96,7 +97,7 @@
int i;
for (i=0;i<=l->maxshift;i++)
kiss_fft_free(l->kfft[i]);
- celt_free(l->trig);
+ celt_free((kiss_twiddle_scalar*)l->trig);
}
void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, const celt_word16 *window, int overlap, int shift)
@@ -161,7 +162,7 @@
/* Pre-rotation */
{
kiss_fft_scalar * restrict yp = out;
- kiss_fft_scalar *t = &l->trig[0];
+ const kiss_fft_scalar *t = &l->trig[0];
for(i=0;i<N4;i++)
{
kiss_fft_scalar re, im, yr, yi;
@@ -184,7 +185,7 @@
const kiss_fft_scalar * restrict fp = f;
kiss_fft_scalar * restrict yp1 = out;
kiss_fft_scalar * restrict yp2 = out+N2-1;
- kiss_fft_scalar *t = &l->trig[0];
+ const kiss_fft_scalar *t = &l->trig[0];
/* Temp pointers to make it really clear to the compiler what we're doing */
for(i=0;i<N4;i++)
{
@@ -230,7 +231,7 @@
const kiss_fft_scalar * restrict xp1 = in;
const kiss_fft_scalar * restrict xp2 = in+N2-1;
kiss_fft_scalar * restrict yp = f2;
- kiss_fft_scalar *t = &l->trig[0];
+ const kiss_fft_scalar *t = &l->trig[0];
for(i=0;i<N4;i++)
{
kiss_fft_scalar yr, yi;
@@ -250,7 +251,7 @@
/* Post-rotate */
{
kiss_fft_scalar * restrict fp = f;
- kiss_fft_scalar *t = &l->trig[0];
+ const kiss_fft_scalar *t = &l->trig[0];
for(i=0;i<N4;i++)
{
--- a/libcelt/mdct.h
+++ b/libcelt/mdct.h
@@ -52,8 +52,8 @@
typedef struct {
int n;
int maxshift;
- kiss_fft_state *kfft[4];
- kiss_twiddle_scalar * restrict trig;
+ const kiss_fft_state *kfft[4];
+ const kiss_twiddle_scalar * restrict trig;
} mdct_lookup;
void clt_mdct_init(mdct_lookup *l,int N, int maxshift);
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -421,7 +421,6 @@
mode->logN = logN;
compute_pulse_cache(mode, mode->maxLM);
-#endif /* !STATIC_MODES */
clt_mdct_init(&mode->mdct, 2*mode->shortMdctSize*mode->nbShortMdcts, mode->maxLM);
if ((mode->mdct.trig==NULL)
@@ -431,6 +430,8 @@
)
goto failure;
+#endif /* !STATIC_MODES */
+
mode->prob = quant_prob_alloc(mode);
if (mode->prob==NULL)
goto failure;
@@ -477,8 +478,8 @@
celt_free((celt_int16*)mode->cache.index);
celt_free((unsigned char*)mode->cache.bits);
-#endif
clt_mdct_clear(&mode->mdct);
+#endif
quant_prob_free(mode->prob);
mode->marker_end = MODEFREED;