ref: dbe9a439380af4f03cf441ac00c53faea25b8a3d
parent: ad15ed840bb0b178f9f7c31c6c7298078ff4af94
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 15 05:01:29 EDT 2011
Renames the kiss FFT implementation to reduce the risk of symbol clashes
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -14,6 +14,10 @@
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
+/* This code is originally from Mark Borgerding's KISS-FFT but has been
+ heavily modified to better suit Opus */
+
#ifndef SKIP_CONFIG_H
# ifdef HAVE_CONFIG_H
# include "config.h"
@@ -521,12 +525,11 @@
/*
*
- * User-callable function to allocate all necessary storage space for the fft.
- *
- * 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.
+ * Allocates all necessary storage space for the fft and ifft.
+ * The return value is a contiguous block of memory. As such,
+ * It can be freed with free().
* */
-kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base)
+kiss_fft_state *opus_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*/
@@ -561,7 +564,7 @@
}
if (!kf_factor(nfft,st->factors))
{
- kiss_fft_free(st);
+ opus_fft_free(st);
goto fail;
}
@@ -573,16 +576,16 @@
}
return st;
fail:
- kiss_fft_free(st);
+ opus_fft_free(st);
return NULL;
}
-kiss_fft_state *kiss_fft_alloc(int nfft,void * mem,size_t * lenmem )
+kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem )
{
- return kiss_fft_alloc_twiddles(nfft, mem, lenmem, NULL);
+ return opus_fft_alloc_twiddles(nfft, mem, lenmem, NULL);
}
-void kiss_fft_free(const kiss_fft_state *cfg)
+void opus_fft_free(const kiss_fft_state *cfg)
{
if (cfg)
{
@@ -595,7 +598,7 @@
#endif /* CUSTOM_MODES */
-void kiss_fft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+void opus_fft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
{
int m2, m;
int p;
@@ -655,7 +658,7 @@
}
}
-void kiss_ifft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
+void opus_ifft(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
{
int m2, m;
int p;
--- a/libcelt/kiss_fft.h
+++ b/libcelt/kiss_fft.h
@@ -69,18 +69,18 @@
#endif
#if 0
-/* This adds a suffix to all the kiss_fft functions so we
+/* This adds a suffix to all the opus_fft functions so we
can easily link with more than one copy of the fft */
#define CAT_SUFFIX(a,b) a ## b
#define SUF(a,b) CAT_SUFFIX(a, b)
-#define kiss_fft_alloc_twiddles SUF(kiss_fft_alloc_twiddles,KF_SUFFIX)
-#define kiss_fft_alloc SUF(kiss_fft_alloc,KF_SUFFIX)
-#define kiss_fft SUF(kiss_fft,KF_SUFFIX)
-#define kiss_ifft SUF(kiss_ifft,KF_SUFFIX)
+#define kiss_fft_alloc_twiddles SUF(opus_fft_alloc_twiddles,KF_SUFFIX)
+#define kiss_fft_alloc SUF(opus_fft_alloc,KF_SUFFIX)
+#define kiss_fft SUF(opus_fft,KF_SUFFIX)
+#define kiss_ifft SUF(opus_ifft,KF_SUFFIX)
#define kiss_fft_stride SUF(kiss_fft_stride,KF_SUFFIX)
#define kiss_ifft_stride SUF(kiss_ifft_stride,KF_SUFFIX)
-#define kiss_fft_free SUF(kiss_fft_free,KF_SUFFIX)
+#define kiss_fft_free SUF(opus_fft_free,KF_SUFFIX)
#endif
@@ -114,16 +114,16 @@
/*typedef struct kiss_fft_state* kiss_fft_cfg;*/
/**
- * kiss_fft_alloc
+ * opus_fft_alloc
*
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
*
- * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
+ * typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL);
*
* The return value from fft_alloc is a cfg buffer used internally
* by the fft routine or NULL.
*
- * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
+ * If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc.
* The returned value should be free()d when done to avoid memory leaks.
*
* The state can be placed in a user supplied buffer 'mem':
@@ -136,12 +136,12 @@
* buffer size in *lenmem.
* */
-kiss_fft_state *kiss_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base);
+kiss_fft_state *opus_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);
+kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem);
/**
- * kiss_fft(cfg,in_out_buf)
+ * opus_fft(cfg,in_out_buf)
*
* Perform an FFT on a complex input buffer.
* for a forward FFT,
@@ -150,10 +150,10 @@
* Note that each element is complex and can be accessed like
f[k].r and f[k].i
* */
-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 opus_fft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
+void opus_ifft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
-void kiss_fft_free(const kiss_fft_state *cfg);
+void opus_fft_free(const kiss_fft_state *cfg);
#ifdef __cplusplus
}
--- a/libcelt/mdct.c
+++ b/libcelt/mdct.c
@@ -67,9 +67,9 @@
for (i=0;i<=maxshift;i++)
{
if (i==0)
- l->kfft[i] = kiss_fft_alloc(N>>2>>i, 0, 0);
+ l->kfft[i] = opus_fft_alloc(N>>2>>i, 0, 0);
else
- l->kfft[i] = kiss_fft_alloc_twiddles(N>>2>>i, 0, 0, l->kfft[0]);
+ l->kfft[i] = opus_fft_alloc_twiddles(N>>2>>i, 0, 0, l->kfft[0]);
#ifndef ENABLE_TI_DSPLIB55
if (l->kfft[i]==NULL)
return 0;
@@ -93,7 +93,7 @@
{
int i;
for (i=0;i<=l->maxshift;i++)
- kiss_fft_free(l->kfft[i]);
+ opus_fft_free(l->kfft[i]);
celt_free((kiss_twiddle_scalar*)l->trig);
}
@@ -176,7 +176,7 @@
}
/* N/4 complex FFT, down-scales by 4/N */
- kiss_fft(l->kfft[shift], (kiss_fft_cpx *)out, (kiss_fft_cpx *)f);
+ opus_fft(l->kfft[shift], (kiss_fft_cpx *)out, (kiss_fft_cpx *)f);
/* Post-rotate */
{
@@ -244,7 +244,7 @@
}
/* Inverse N/4 complex FFT. This one should *not* downscale even in fixed-point */
- kiss_ifft(l->kfft[shift], (kiss_fft_cpx *)f2, (kiss_fft_cpx *)f);
+ opus_ifft(l->kfft[shift], (kiss_fft_cpx *)f2, (kiss_fft_cpx *)f);
/* Post-rotate */
{
--- a/libcelt/tests/dft-test.c
+++ b/libcelt/tests/dft-test.c
@@ -74,7 +74,7 @@
kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen);
kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen);
- kiss_fft_state *cfg = kiss_fft_alloc(nfft,0,0);
+ kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0);
int k;
for (k=0;k<nfft;++k) {
@@ -100,9 +100,9 @@
/*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
if (isinverse)
- kiss_ifft(cfg,in,out);
+ opus_ifft(cfg,in,out);
else
- kiss_fft(cfg,in,out);
+ opus_fft(cfg,in,out);
/*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
--- a/libcelt/tests/real-fft-test.c
+++ b/libcelt/tests/real-fft-test.c
@@ -103,9 +103,9 @@
cin[i].i = zero;
}
- kiss_fft_state = kiss_fft_alloc(NFFT,0,0);
+ kiss_fft_state = opus_fft_alloc(NFFT,0,0);
kiss_fftr_state = kiss_fftr_alloc(NFFT,0,0);
- kiss_fft(kiss_fft_state,cin,cout);
+ opus_fft(kiss_fft_state,cin,cout);
kiss_fftr(kiss_fftr_state,rin,sout);
printf( "nfft=%d, inverse=%d, snr=%g\n",
@@ -148,10 +148,10 @@
fin[2*i+1] = cin[i].i;
}
- kiss_ifft(kiss_fft_state,cin,cout);
+ opus_ifft(kiss_fft_state,cin,cout);
kiss_fftri(kiss_fftr_state,fin,rout);
/*
- printf(" results from inverse kiss_fft : (%f,%f), (%f,%f), (%f,%f), (%f,%f), (%f,%f) ...\n "
+ printf(" results from inverse opus_fft : (%f,%f), (%f,%f), (%f,%f), (%f,%f), (%f,%f) ...\n "
, (float)cout[0].r , (float)cout[0].i , (float)cout[1].r , (float)cout[1].i , (float)cout[2].r , (float)cout[2].i , (float)cout[3].r , (float)cout[3].i , (float)cout[4].r , (float)cout[4].i
);