nausea

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

commit 10e65a9fbc38fca02fe449c61f8d010dcc9cc0c2
parent 288e005a4b3e572fba228310ca7ad01af5f550c9
Author: lostd <lostd@2f30.org>
Date:   Thu Nov 21 16:01:14 +0200

Lazily allocate the peaks array and use realloc

Diffstat:
spectrum.c | 4+---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/spectrum.c b/spectrum.c @@ -84,7 +84,6 @@ init(struct frame *fr) if (fr->fd == -1) err(1, "open"); - fr->peaks = malloc(1 * sizeof(struct peak)); fr->buf = malloc(nsamples * sizeof(int16_t)); fr->res = malloc(nsamples / 2 * sizeof(unsigned)); fr->in = fftw_malloc(nsamples / 2 * sizeof(double)); @@ -173,8 +172,7 @@ draw(struct frame *fr) if (peaks) { /* change in width needs new peaks */ if (fr->width != fr->width_old) { - free(fr->peaks); - fr->peaks = calloc(fr->width, sizeof(struct peak)); + fr->peaks = realloc(fr->peaks, fr->width * sizeof(struct peak)); for (i = 0; i < fr->width; i++) fr->peaks[i].pos = PK_HIDDEN; fr->width_old = fr->width;