summaryrefslogtreecommitdiff
path: root/gst-libs/gst/fft/kiss_fft_s16.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst-libs/gst/fft/kiss_fft_s16.c')
-rw-r--r--gst-libs/gst/fft/kiss_fft_s16.c84
1 files changed, 26 insertions, 58 deletions
diff --git a/gst-libs/gst/fft/kiss_fft_s16.c b/gst-libs/gst/fft/kiss_fft_s16.c
index 7334141a0..a110bbd98 100644
--- a/gst-libs/gst/fft/kiss_fft_s16.c
+++ b/gst-libs/gst/fft/kiss_fft_s16.c
@@ -1,40 +1,17 @@
/*
-Copyright (c) 2003-2004, Mark Borgerding
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
+ * This file is part of KISS FFT - https://github.com/mborgerding/kissfft
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ * See COPYING file for more information.
+ */
-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.
-*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
#include "_kiss_fft_guts_s16.h"
/* The guts header contains all the multiplication and addition macros that are defined for
fixed or floating point complex numbers. It also delares the kf_ internal functions.
*/
-static kiss_fft_s16_cpx *scratchbuf = NULL;
-static size_t nscratchbuf = 0;
-static kiss_fft_s16_cpx *tmpbuf = NULL;
-static size_t ntmpbuf = 0;
-
-#define CHECKBUF(buf,nbuf,n) \
- do { \
- if ( nbuf < (size_t)(n) ) {\
- free(buf); \
- buf = (kiss_fft_s16_cpx*)KISS_FFT_S16_MALLOC(sizeof(kiss_fft_s16_cpx)*(n)); \
- nbuf = (size_t)(n); \
- } \
- }while(0)
-
-
static void
kf_bfly2 (kiss_fft_s16_cpx * Fout,
const size_t fstride, const kiss_fft_s16_cfg st, int m)
@@ -42,7 +19,6 @@ kf_bfly2 (kiss_fft_s16_cpx * Fout,
kiss_fft_s16_cpx *Fout2;
kiss_fft_s16_cpx *tw1 = st->twiddles;
kiss_fft_s16_cpx t;
-
Fout2 = Fout + m;
do {
C_FIXDIV (*Fout, 2);
@@ -67,6 +43,7 @@ kf_bfly4 (kiss_fft_s16_cpx * Fout,
const size_t m2 = 2 * m;
const size_t m3 = 3 * m;
+
tw3 = tw2 = tw1 = st->twiddles;
do {
@@ -113,7 +90,6 @@ kf_bfly3 (kiss_fft_s16_cpx * Fout,
kiss_fft_s16_cpx *tw1, *tw2;
kiss_fft_s16_cpx scratch[5];
kiss_fft_s16_cpx epi3;
-
epi3 = st->twiddles[fstride * m];
tw1 = tw2 = st->twiddles;
@@ -158,7 +134,6 @@ kf_bfly5 (kiss_fft_s16_cpx * Fout,
kiss_fft_s16_cpx *twiddles = st->twiddles;
kiss_fft_s16_cpx *tw;
kiss_fft_s16_cpx ya, yb;
-
ya = twiddles[fstride * m];
yb = twiddles[fstride * 2 * m];
@@ -229,38 +204,40 @@ kf_bfly_generic (kiss_fft_s16_cpx * Fout,
kiss_fft_s16_cpx t;
int Norig = st->nfft;
- CHECKBUF (scratchbuf, nscratchbuf, p);
+ kiss_fft_s16_cpx *scratch =
+ (kiss_fft_s16_cpx *) KISS_FFT_S16_TMP_ALLOC (sizeof (kiss_fft_s16_cpx) *
+ p);
for (u = 0; u < m; ++u) {
k = u;
for (q1 = 0; q1 < p; ++q1) {
- scratchbuf[q1] = Fout[k];
- C_FIXDIV (scratchbuf[q1], p);
+ scratch[q1] = Fout[k];
+ C_FIXDIV (scratch[q1], p);
k += m;
}
k = u;
for (q1 = 0; q1 < p; ++q1) {
int twidx = 0;
-
- Fout[k] = scratchbuf[0];
+ Fout[k] = scratch[0];
for (q = 1; q < p; ++q) {
twidx += fstride * k;
if (twidx >= Norig)
twidx -= Norig;
- C_MUL (t, scratchbuf[q], twiddles[twidx]);
+ C_MUL (t, scratch[q], twiddles[twidx]);
C_ADDTO (Fout[k], t);
}
k += m;
}
}
+ KISS_FFT_S16_TMP_FREE (scratch);
}
static void
kf_work (kiss_fft_s16_cpx * Fout,
const kiss_fft_s16_cpx * f,
- const size_t fstride,
- int in_stride, int *factors, const kiss_fft_s16_cfg st)
+ const size_t fstride, int in_stride, int *factors,
+ const kiss_fft_s16_cfg st)
{
kiss_fft_s16_cpx *Fout_beg = Fout;
const int p = *factors++; /* the radix */
@@ -270,7 +247,7 @@ kf_work (kiss_fft_s16_cpx * Fout,
#ifdef _OPENMP
// use openmp extensions at the
// top-level (not recursive)
- if (fstride == 1) {
+ if (fstride == 1 && p <= 5 && m != 1) {
int k;
// execute the p different work units in different threads
@@ -348,7 +325,6 @@ kf_factor (int n, int *facbuf)
{
int p = 4;
double floor_sqrt;
-
floor_sqrt = floor (sqrt ((double) n));
/*factor out powers of 4, powers of 2, then any remaining primes */
@@ -379,7 +355,7 @@ kf_factor (int n, int *facbuf)
* 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.
+ * It can be freed with free(), rather than a kiss_fft_s16-specific function.
* */
kiss_fft_s16_cfg
kiss_fft_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem)
@@ -397,7 +373,6 @@ kiss_fft_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem)
}
if (st) {
int i;
-
st->nfft = nfft;
st->inverse = inverse_fft;
@@ -405,7 +380,6 @@ kiss_fft_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem)
const double pi =
3.141592653589793238462643383279502884197169399375105820974944;
double phase = -2 * pi * i / nfft;
-
if (st->inverse)
phase *= -1;
kf_cexp (st->twiddles + i, phase);
@@ -417,16 +391,19 @@ kiss_fft_s16_alloc (int nfft, int inverse_fft, void *mem, size_t * lenmem)
}
-
-
void
kiss_fft_s16_stride (kiss_fft_s16_cfg st, const kiss_fft_s16_cpx * fin,
kiss_fft_s16_cpx * fout, int in_stride)
{
if (fin == fout) {
- CHECKBUF (tmpbuf, ntmpbuf, st->nfft);
+ //NOTE: this is not really an in-place FFT algorithm.
+ //It just performs an out-of-place FFT into a temp buffer
+ kiss_fft_s16_cpx *tmpbuf =
+ (kiss_fft_s16_cpx *) KISS_FFT_S16_TMP_ALLOC (sizeof (kiss_fft_s16_cpx) *
+ st->nfft);
kf_work (tmpbuf, fin, 1, in_stride, st->factors, st);
memcpy (fout, tmpbuf, sizeof (kiss_fft_s16_cpx) * st->nfft);
+ KISS_FFT_S16_TMP_FREE (tmpbuf);
} else {
kf_work (fout, fin, 1, in_stride, st->factors, st);
}
@@ -440,18 +417,10 @@ kiss_fft_s16 (kiss_fft_s16_cfg cfg, const kiss_fft_s16_cpx * fin,
}
-/* not really necessary to call, but if someone is doing in-place ffts, they may want to free the
- buffers from CHECKBUF
- */
void
kiss_fft_s16_cleanup (void)
{
- free (scratchbuf);
- scratchbuf = NULL;
- nscratchbuf = 0;
- free (tmpbuf);
- tmpbuf = NULL;
- ntmpbuf = 0;
+ // nothing needed any more
}
int
@@ -459,7 +428,6 @@ kiss_fft_s16_next_fast_size (int n)
{
while (1) {
int m = n;
-
while ((m % 2) == 0)
m /= 2;
while ((m % 3) == 0)