nausea

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

commit 0cdbffbd094119de019500b93bec438e3d1f8ed0
parent 45e0ae46a3d3f9651da6609424dd19ca9efd3340
Author: sin <sin@2f30.org>
Date:   Mon, 18 Nov 2013 21:23:57 +0000

Simplify code and add some comments

To normalize, no need to divide by a random number,
just divide by nsamples.

Diffstat:
spectrum.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/spectrum.c b/spectrum.c @@ -162,10 +162,15 @@ draw(struct frame *fr) /* scale each frequency to screen */ #define BARSCALE 0.2 - for (i = 0; i < nsamples / 2; i++) + for (i = 0; i < nsamples / 2; i++) { + /* cabs() essentially */ fr->res[i] = sqrt(fr->out[i][0] * fr->out[i][0] + - fr->out[i][1] * fr->out[i][1]) - / 100000 * fr->height * BARSCALE; + fr->out[i][1] * fr->out[i][1]); + /* normalize it */ + fr->res[i] /= nsamples; + /* scale it */ + fr->res[i] *= fr->height * BARSCALE; + } #undef BARSCALE erase();