nausea

curses audio visualizer
git clone git://git.2f30.org/nausea.git
Log | Files | Refs | README | LICENSE

commit 494d1dc797a9e96dd761aceadddbf6e255a3f283
parent 22df4be986d0babfbe925e348b360f5441b39264
Author: lostd <lostd@2f30.org>
Date:   Wed Nov 20 16:29:41 +0200

Clear in and out fft buffers when read fails, re-use in init

Diffstat:
spectrum.c | 22++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/spectrum.c b/spectrum.c @@ -56,6 +56,18 @@ static struct color_range { }; static void +clearall(struct frame *fr) +{ + unsigned i; + + for (i = 0; i < nsamples / 2; i++) { + fr->in[i] = 0.; + fr->out[i][0] = 0.; + fr->out[i][1] = 0.; + } +} + +static void init(struct frame *fr) { unsigned i; @@ -69,11 +81,7 @@ init(struct frame *fr) fr->in = fftw_malloc(nsamples / 2 * sizeof(double)); fr->out = fftw_malloc(nsamples / 2 * sizeof(fftw_complex)); - for (i = 0; i < nsamples / 2; i++) { - fr->in[i] = 0.; - fr->out[i][0] = 0.; - fr->out[i][1] = 0.; - } + clearall(fr); fr->plan = fftw_plan_dft_r2c_1d(nsamples / 2, fr->in, fr->out, FFTW_ESTIMATE); @@ -99,8 +107,10 @@ update(struct frame *fr) unsigned i; n = read(fr->fd, fr->buf, nsamples * sizeof(int16_t)); - if (n == -1) + if (n == -1) { + clearall(fr); return; + } gotsamples = n / sizeof(int16_t);