mirror of
https://github.com/alexkay/spek.git
synced 2025-04-21 19:07:37 +03:00
Replace fftw with avfft
This commit is contained in:
parent
7a0f3f45b5
commit
1a3ced87c4
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user