diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-12 22:33:23 +0100 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-12 22:33:23 +0100 |
commit | 27656b4326a28e4207a89c31b21834f013cf6b6a (patch) | |
tree | 7d214e85910b614b9988e3d4864ba24ebf6ba1b7 | |
parent | 48d0b0a8dcc6d482cd8a57ea9d14c920c921aa0c (diff) |
fixed stupid fft bug
-rw-r--r-- | fft.c | 13 | ||||
-rw-r--r-- | streamer.c | 10 |
2 files changed, 11 insertions, 12 deletions
@@ -27,9 +27,11 @@ #include <math.h> #include <complex.h> -static float hamming[DDB_FREQ_BANDS]; /* hamming window, scaled to sum to 1 */ -static int reversed[DDB_FREQ_BANDS]; /* bit-reversal table */ -static float complex roots[DDB_FREQ_BANDS / 2]; /* N-th roots of unity */ +#define N (DDB_FREQ_BANDS * 2) + +static float hamming[N]; /* hamming window, scaled to sum to 1 */ +static int reversed[N]; /* bit-reversal table */ +static float complex roots[N / 2]; /* N-th roots of unity */ static int generated = 0; static float LOGN; /* log N (base 2) */ @@ -59,7 +61,6 @@ static void generate_tables (void) if (generated) return; - const int N = DDB_FREQ_BANDS; LOGN = log2(N); for (int n = 0; n < N; n ++) hamming[n] = 1 - 0.85 * cosf (2 * M_PI * n / N); @@ -71,9 +72,8 @@ static void generate_tables (void) generated = 1; } -static void do_fft (float complex a[DDB_FREQ_BANDS]) +static void do_fft (float complex a[N]) { - const int N = DDB_FREQ_BANDS; int half = 1; /* (2^s)/2 */ int inv = N / 2; /* N/(2^s) */ @@ -104,7 +104,6 @@ calc_freq (float *data, float *freq) { // fft code shamelessly stolen from audacious // thanks, John - int N = DDB_FREQ_BANDS; float complex a[N]; for (int n = 0; n < N; n ++) { a[reversed[n]] = data[n] * hamming[n]; @@ -137,7 +137,7 @@ static DB_FILE *streamer_file; // for vis plugins static float freq_data[DDB_FREQ_BANDS * DDB_FREQ_MAX_CHANNELS]; -static float audio_data[DDB_FREQ_BANDS * DDB_FREQ_MAX_CHANNELS]; +static float audio_data[DDB_FREQ_BANDS * 2 * DDB_FREQ_MAX_CHANNELS]; static int audio_data_fill = 0; static int audio_data_channels = 0; @@ -2321,19 +2321,19 @@ streamer_read (char *bytes, int size) { if (spectrum_listeners) { int remaining = in_frames; do { - int sz = DDB_FREQ_BANDS-audio_data_fill; + int sz = DDB_FREQ_BANDS * 2 -audio_data_fill; sz = min (sz, remaining); for (int c = 0; c < audio_data_channels; c++) { for (int s = 0; s < sz; s++) { - audio_data[DDB_FREQ_BANDS * c + audio_data_fill + s] = temp_audio_data[(in_frames-remaining + s) * audio_data_channels + c]; + audio_data[DDB_FREQ_BANDS * 2 * c + audio_data_fill + s] = temp_audio_data[(in_frames-remaining + s) * audio_data_channels + c]; } } // memcpy (&audio_data[audio_data_fill], &temp_audio_data[in_frames-remaining], sz * sizeof (float)); audio_data_fill += sz; remaining -= sz; - if (audio_data_fill == DDB_FREQ_BANDS) { + if (audio_data_fill == DDB_FREQ_BANDS * 2) { for (int c = 0; c < audio_data_channels; c++) { - calc_freq (&audio_data[DDB_FREQ_BANDS * c], &freq_data[DDB_FREQ_BANDS * c]); + calc_freq (&audio_data[DDB_FREQ_BANDS * 2 * c], &freq_data[DDB_FREQ_BANDS * c]); } ddb_audio_data_t data; data.fmt = &out_fmt; |