spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 1a3ced87c4ef6a4c03bf5fa7bacbeec0a71af651
parent 7a0f3f45b5a5b7d1257ef5b92b6e62aea5870eed
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Wed,  7 Jul 2010 10:57:39 +1000

Replace fftw with avfft

Diffstat:
Mconfigure.ac | 2+-
Msrc/spek-fft.c | 30++++++++++++++++--------------
Msrc/spek-fft.h | 5++---
3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -24,7 +24,7 @@ AM_PROG_VALAC([0.7.0]) AC_PROG_INSTALL AC_PROG_INTLTOOL([0.35]) -pkg_modules="gtk+-2.0 >= 2.14.0 libavformat libavcodec >= 52.23.0 fftw3f" +pkg_modules="gtk+-2.0 >= 2.14.0 libavformat libavcodec >= 52.23.0" PKG_CHECK_MODULES(SPEK, [$pkg_modules]) AC_SUBST(SPEK_CFLAGS) AC_SUBST(SPEK_LIBS) diff --git a/src/spek-fft.c b/src/spek-fft.c @@ -21,36 +21,38 @@ #include "spek-fft.h" SpekFftPlan * spek_fft_plan_new (gint n, gint threshold) { + gint bits; SpekFftPlan *p = g_new0 (SpekFftPlan, 1); - p->input = (gfloat *) fftwf_malloc (sizeof (gfloat) * n); - p->output = (gfloat *) fftwf_malloc (sizeof (gfloat) * (n / 2 + 1)); - p->result = (fftwf_complex *) fftwf_malloc (sizeof (fftwf_complex) * (n / 2 + 1)); - p->n = n; + p->input = g_new0 (gfloat, n); + p->output = g_new0 (gfloat, n / 2 + 1); p->threshold = threshold; - p->plan = fftwf_plan_dft_r2c_1d (n, p->input, p->result, FFTW_ESTIMATE); + for (bits = 0; n; n >>= 1, bits++); + p->n = 1 << --bits; + p->cx = av_rdft_init (bits, DFT_R2C); return p; } void spek_fft_execute (SpekFftPlan *p) { int i; - int bands = p->n / 2 + 1; + int n = p->n; - fftwf_execute (p->plan); + av_rdft_calc (p->cx, p->input); /* Calculate magnitudes */ - for (i = 0; i < bands; i++) { + p->output[0] = p->input[0] * p->input[0] / (n * n); + p->output[n / 2] = p->input[1] * p->input[1] / (n * n); + for (i = 1; i < n / 2; i++) { gfloat val; - val = p->result[i][0] * p->result[i][0] + p->result[i][1] * p->result[i][1]; - val /= p->n * p->n; + val = p->input[i * 2] * p->input[i * 2] + p->input[i * 2 + 1] * p->input[i * 2 + 1]; + val /= n * n; val = 10.0 * log10f (val); p->output[i] = val < p->threshold ? p->threshold : val; } } void spek_fft_destroy (SpekFftPlan *p) { - fftwf_destroy_plan (p->plan); - fftwf_free (p->result); - fftwf_free (p->output); - fftwf_free (p->input); + av_rdft_end (p->cx); + g_free (p->input); + g_free (p->output); g_free (p); } diff --git a/src/spek-fft.h b/src/spek-fft.h @@ -20,14 +20,13 @@ #define __SPEK_FFT_H__ #include <glib.h> -#include <fftw3.h> +#include <libavcodec/avfft.h> typedef struct { /* Internal data */ - fftwf_plan plan; + RDFTContext *cx; gint n; gint threshold; - fftwf_complex *result; /* Exposed properties */ gfloat *input;