ref: 24eef1493e47ebe9b18f45a542adbecf35a1295a
parent: 3fc0aada01594514377c4cb2b290395b76608ca3
author: Jean-Marc Valin <[email protected]>
date: Wed Aug 25 14:01:50 EDT 2010
Updating dump_modes to include the MDCT and FFT. More work needed.
--- a/libcelt/_kiss_fft_guts.h
+++ b/libcelt/_kiss_fft_guts.h
@@ -24,22 +24,6 @@
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
#include "kiss_fft.h"
-#define MAXFACTORS 8
-/* e.g. an fft of length 128 has 4 factors
- as far as kissfft is concerned
- 4*4*4*2
- */
-
-struct kiss_fft_state{
- int nfft;
-#ifndef FIXED_POINT
- kiss_fft_scalar scale;
-#endif
- int shift;
- celt_int16 factors[2*MAXFACTORS];
- celt_int16 *bitrev;
- kiss_twiddle_cpx *twiddles;
-};
/*
Explanation of macros dealing with complex math:
--- a/libcelt/dump_modes.c
+++ b/libcelt/dump_modes.c
@@ -122,14 +122,22 @@
fprintf(file, "#endif\n");
fprintf(file, "\n");
- /* FFTs */
- /*
- for (i=0;i<mode->mdct.maxshift;i++)
+ /* FFT twiddles */
+ fprintf(file, "#ifndef FFT_TWIDDLES%d_%d\n", mode->Fs, mdctSize);
+ fprintf(file, "#define FFT_TWIDDLES%d_%d\n", mode->Fs, mdctSize);
+ fprintf (file, "static const kiss_twiddle_cpx fft_twiddles%d_%d[%d] = {\n",
+ mode->Fs, mdctSize, mode->mdct.kfft[0]->nfft);
+ for (j=0;j<mode->mdct.kfft[0]->nfft;j++)
+ fprintf (file, "{" WORD16 ", " WORD16 "}, ", mode->mdct.kfft[0]->twiddles[j].r, mode->mdct.kfft[0]->twiddles[j].i);
+ fprintf (file, "};\n");
+
+ /* FFT Bitrev tables */
+ for (i=0;i<=mode->mdct.maxshift;i++)
{
fprintf(file, "#ifndef FFT_BITREV%d_%d\n", mode->Fs, mdctSize>>i);
fprintf(file, "#define FFT_BITREV%d_%d\n", mode->Fs, mdctSize>>i);
fprintf (file, "static const celt_int16 fft_bitrev%d_%d[%d] = {\n",
- mode->Fs, mdctSize/i, mode->mdct.kfft[i]->nfft);
+ mode->Fs, mdctSize>>i, mode->mdct.kfft[i]->nfft);
for (j=0;j<mode->mdct.kfft[i]->nfft;j++)
fprintf (file, "%d, ", mode->mdct.kfft[i]->bitrev[j]);
fprintf (file, "};\n");
@@ -137,8 +145,47 @@
fprintf(file, "#endif\n");
fprintf(file, "\n");
}
- */
+ /* FFT States */
+ for (i=0;i<=mode->mdct.maxshift;i++)
+ {
+ fprintf(file, "#ifndef FFT_STATE%d_%d\n", mode->Fs, mdctSize>>i);
+ fprintf(file, "#define FFT_STATE%d_%d\n", mode->Fs, mdctSize>>i);
+ fprintf (file, "static const kiss_fft_state fft_state%d_%d = {\n",
+ mode->Fs, mdctSize>>i);
+ fprintf (file, "%d,\t/* nfft */\n", mode->mdct.kfft[i]->nfft);
+#ifndef FIXED_POINT
+ fprintf (file, "%f,\t/* scale */\n", mode->mdct.kfft[i]->scale);
+#endif
+ fprintf (file, "%d,\t/* shift */\n", mode->mdct.kfft[i]->shift);
+ fprintf (file, "{");
+ for (j=0;j<2*MAXFACTORS;j++)
+ fprintf (file, "%d, ", mode->mdct.kfft[i]->factors[j]);
+ fprintf (file, "},\t/* factors */\n");
+ fprintf (file, "fft_bitrev%d_%d,\t/* bitrev */\n", mode->Fs, mdctSize>>i);
+ fprintf (file, "fft_twiddles%d_%d,\t/* bitrev */\n", mode->Fs, mdctSize);
+ fprintf (file, "};\n");
+
+ fprintf(file, "#endif\n");
+ fprintf(file, "\n");
+ }
+
+ fprintf(file, "#endif\n");
+ fprintf(file, "\n");
+
+ /* MDCT twiddles */
+ fprintf(file, "#ifndef MDCT_TWIDDLES%d_%d\n", mode->Fs, mdctSize);
+ fprintf(file, "#define MDCT_TWIDDLES%d_%d\n", mode->Fs, mdctSize);
+ fprintf (file, "static const celt_word16 mdct_twiddles%d_%d[%d] = {\n",
+ mode->Fs, mdctSize, mode->mdct.n/4);
+ for (j=0;j<mode->mdct.n/4;j++)
+ fprintf (file, WORD16 ", ", mode->mdct.trig[j]);
+ fprintf (file, "};\n");
+
+ fprintf(file, "#endif\n");
+ fprintf(file, "\n");
+
+
/* Print the actual mode data */
fprintf(file, "static const CELTMode mode%d_%d_%d = {\n", mode->Fs, mdctSize, mode->overlap);
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
@@ -154,8 +201,10 @@
fprintf(file, "%d,\t/* nbAllocVectors */\n", mode->nbAllocVectors);
fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mdctSize);
- fprintf(file, "{%d, %d, 0, 0},\t", mode->mdct.n, mode->mdct.maxshift);
- fprintf (file, "/* mdct */\n");
+ 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, "}, mdct_twiddles%d_%d},\t/* mdct */\n", mode->Fs, mdctSize);
fprintf(file, "window%d,\t/* window */\n", mode->overlap);
fprintf(file, "%d,\t/* maxLM */\n", mode->maxLM);
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -34,7 +34,7 @@
static void kf_bfly2(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -67,7 +67,7 @@
static void ki_bfly2(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -98,7 +98,7 @@
static void kf_bfly4(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -147,7 +147,7 @@
static void ki_bfly4(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -194,7 +194,7 @@
static void kf_bfly3(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -246,7 +246,7 @@
static void ki_bfly3(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
size_t m,
int N,
int mm
@@ -297,7 +297,7 @@
static void kf_bfly5(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -366,7 +366,7 @@
static void ki_bfly5(
kiss_fft_cpx * Fout,
const size_t fstride,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int m,
int N,
int mm
@@ -440,7 +440,7 @@
const size_t fstride,
int in_stride,
celt_int16 * factors,
- const kiss_fft_cfg st
+ const kiss_fft_state *st
)
{
const int p=*factors++; /* the radix */
@@ -473,7 +473,7 @@
size_t fstride,
int in_stride,
celt_int16 * factors,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int N,
int s2,
int m2
@@ -507,7 +507,7 @@
size_t fstride,
int in_stride,
celt_int16 * factors,
- const kiss_fft_cfg st,
+ const kiss_fft_state *st,
int N,
int s2,
int m2
@@ -591,16 +591,16 @@
* 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_cfg kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_cfg base)
+kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_state *base)
{
- kiss_fft_cfg st=NULL;
+ kiss_fft_state *st=NULL;
size_t memneeded = sizeof(struct kiss_fft_state); /* twiddle factors*/
if ( lenmem==NULL ) {
- st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded );
+ st = ( kiss_fft_state*)KISS_FFT_MALLOC( memneeded );
}else{
if (mem != NULL && *lenmem >= memneeded)
- st = (kiss_fft_cfg)mem;
+ st = (kiss_fft_state*)mem;
*lenmem = memneeded;
}
if (st) {
@@ -635,13 +635,13 @@
return st;
}
-kiss_fft_cfg kiss_fft_alloc(int nfft,void * mem,size_t * lenmem )
+kiss_fft_state *kiss_fft_alloc(int nfft,void * mem,size_t * lenmem )
{
return kiss_fft_alloc_twiddles(nfft, mem, lenmem, NULL);
}
-static void kiss_fft_stride(kiss_fft_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
+static void kiss_fft_stride(kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{
if (fin == fout)
{
@@ -661,12 +661,12 @@
}
}
-void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+void kiss_fft(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_cfg st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
+static void kiss_ifft_stride(kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{
if (fin == fout)
{
@@ -680,12 +680,12 @@
}
}
-void kiss_ifft(kiss_fft_cfg 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)
{
kiss_ifft_stride(cfg,fin,fout,1);
}
-void kiss_fft_free(kiss_fft_cfg cfg)
+void kiss_fft_free(kiss_fft_state *cfg)
{
celt_free(cfg->bitrev);
if (cfg->shift < 0)
--- a/libcelt/kiss_fft.h
+++ b/libcelt/kiss_fft.h
@@ -97,8 +97,25 @@
kiss_twiddle_scalar i;
}kiss_twiddle_cpx;
-typedef struct kiss_fft_state* kiss_fft_cfg;
+#define MAXFACTORS 8
+/* e.g. an fft of length 128 has 4 factors
+ as far as kissfft is concerned
+ 4*4*4*2
+ */
+typedef struct kiss_fft_state{
+ int nfft;
+#ifndef FIXED_POINT
+ kiss_fft_scalar scale;
+#endif
+ int shift;
+ celt_int16 factors[2*MAXFACTORS];
+ celt_int16 *bitrev;
+ kiss_twiddle_cpx *twiddles;
+} kiss_fft_state;
+
+//typedef struct kiss_fft_state* kiss_fft_cfg;
+
/**
* kiss_fft_alloc
*
@@ -122,9 +139,9 @@
* buffer size in *lenmem.
* */
-kiss_fft_cfg kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_cfg base);
+kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, kiss_fft_state *base);
-kiss_fft_cfg kiss_fft_alloc(int nfft,void * mem,size_t * lenmem);
+kiss_fft_state *kiss_fft_alloc(int nfft,void * mem,size_t * lenmem);
/**
* kiss_fft(cfg,in_out_buf)
@@ -136,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_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
-void kiss_ifft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
+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_free(kiss_fft_cfg cfg);
+void kiss_fft_free(kiss_fft_state *cfg);
#ifdef __cplusplus
--- a/libcelt/mdct.h
+++ b/libcelt/mdct.h
@@ -52,7 +52,7 @@
typedef struct {
int n;
int maxshift;
- kiss_fft_cfg kfft[4];
+ kiss_fft_state *kfft[4];
kiss_twiddle_scalar * restrict trig;
} mdct_lookup;
--- a/tests/dft-test.c
+++ b/tests/dft-test.c
@@ -68,7 +68,7 @@
kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen);
kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen);
- kiss_fft_cfg cfg = kiss_fft_alloc(nfft,0,0);
+ kiss_fft_state *cfg = kiss_fft_alloc(nfft,0,0);
int k;
for (k=0;k<nfft;++k) {