spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 85b8a79cf0e56b2245be9bd324be754151982758
parent a6540309ace7e734c467103d11046afb9e4971d1
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sat, 13 Oct 2012 16:27:12 -0700

Fix magnitude calculation for the first and the last frequency band

Diffstat:
Mlib/spek-fft.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/spek-fft.c b/lib/spek-fft.c @@ -43,14 +43,15 @@ void spek_fft_execute(struct spek_fft_plan *p) // Calculate magnitudes. int n = p->n; - p->output[0] = p->input[0] * p->input[0] / (n * n); - p->output[n / 2] = p->input[1] * p->input[1] / (n * n); + float n2 = n * n; + p->output[0] = 10.0f * log10f(p->input[0] * p->input[0] / n2); + p->output[n / 2] = 10.0f * log10f(p->input[1] * p->input[1] / n2); for (int i = 1; i < n / 2; i++) { float val = p->input[i * 2] * p->input[i * 2] + p->input[i * 2 + 1] * p->input[i * 2 + 1]; - val /= n * n; - p->output[i] = 10.0 * log10f (val); + val /= n2; + p->output[i] = 10.0f * log10f(val); } }