From 26adb6c4a3cd258d00f87e3a8ffcab2c55946a1a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 6 Jun 2013 19:59:38 +0000 Subject: add variable fft scala --- fft.c | 6 +++--- fft.h | 2 +- spectrogram.c | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fft.c b/fft.c index 5e71679..f39fd2a 100644 --- a/fft.c +++ b/fft.c @@ -51,7 +51,7 @@ init_fft(int n) } int -dofft(struct fft *p, int16_t *data, double *left, double *right, int n, double *wight) +dofft(struct fft *p, int16_t *data, double *left, double *right, int n, double *wight, float scala) { int i; @@ -64,9 +64,9 @@ dofft(struct fft *p, int16_t *data, double *left, double *right, int n, double * fftw_execute(p[1].plan); for (i = 1; i < n / 2; i++) { - left[i - 1] = sqrt(5 * i + left[i - 1] = sqrt(scala * i * (pow(p[0].out[i], 2) + pow(p[0].out[n - i], 2))); - right[i - 1] = sqrt(5 * i + right[i - 1] = sqrt(scala * i * (pow(p[1].out[i], 2) + pow(p[1].out[n - i], 2))); } diff --git a/fft.h b/fft.h index 77e4737..cf69e54 100644 --- a/fft.h +++ b/fft.h @@ -21,6 +21,6 @@ struct fft; struct fft *init_fft(int); -int dofft(struct fft *, int16_t *, double *, double *, int, double *); +int dofft(struct fft *, int16_t *, double *, double *, int, double *, float); #endif diff --git a/spectrogram.c b/spectrogram.c index 78d8a3e..42b8308 100644 --- a/spectrogram.c +++ b/spectrogram.c @@ -243,6 +243,7 @@ main(int argc, char **argv) double *left, *right; double *hamming; + float scala = 1.0; int16_t *buffer; size_t bufsz; @@ -358,7 +359,7 @@ main(int argc, char **argv) } while (done < bufsz); done -= bufsz; - dofft(fft, buffer, left, right, delta, hamming); + dofft(fft, buffer, left, right, delta, hamming, scala); draw(left, right, ssize, resolution); while (XPending(dsp)) { @@ -368,7 +369,21 @@ main(int argc, char **argv) switch (ev.type) { case KeyPress: - die = XLookupKeysym(&ev.xkey, 0) == XK_q; + switch (XLookupKeysym(&ev.xkey, 0)) { + case XK_q: + die = 1; + break; + case XK_KP_Add: + scala *= 2; + warnx("inc scala: %f", scala); + break; + case XK_KP_Subtract: + scala /= 2; + warnx("dec scala: %f", scala); + break; + default: + break; + } break; case ClientMessage: die = *ev.xclient.data.l == delwin; -- cgit v1.2.3