From 1a74ac3c0d8a103200732923f2ba7af1ef0341af Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 4 Feb 2011 10:26:10 +0100 Subject: [PATCH] src/mathutils.c: fix aubio_db_spl, thanks to Eric, closes #15 --- src/mathutils.c | 6 ++---- src/mathutils.h | 3 ++- src/pitch/pitchmcomb.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mathutils.c b/src/mathutils.c index 2bf3be75..ee70f1b5 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -214,7 +214,7 @@ fvec_local_energy (fvec_t * f) for (j = 0; j < f->length; j++) { energy += SQR (f->data[j]); } - return energy; + return energy / f->length; } smpl_t @@ -449,9 +449,7 @@ aubio_next_power_of_two (uint_t a) smpl_t aubio_db_spl (fvec_t * o) { - smpl_t val = SQRT (fvec_local_energy (o)); - val /= (smpl_t) o->length; - return LIN2DB (val); + return 10. * LOG10 (fvec_local_energy (o)); } uint_t diff --git a/src/mathutils.h b/src/mathutils.h index ebec0098..fa181353 100644 --- a/src/mathutils.h +++ b/src/mathutils.h @@ -106,7 +106,8 @@ smpl_t fvec_sum (fvec_t * v); /** compute the energy of a vector - This function compute the sum of the squared elements of a vector. + This function compute the sum of the squared elements of a vector, normalised + by its length. \param v vector to get the energy from diff --git a/src/pitch/pitchmcomb.c b/src/pitch/pitchmcomb.c index 892ad3fc..0860c55d 100644 --- a/src/pitch/pitchmcomb.c +++ b/src/pitch/pitchmcomb.c @@ -111,7 +111,7 @@ aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) for (j = 0; j < newmag->length; j++) newmag->data[j] = fftgrain->norm[j]; /* detect only if local energy > 10. */ - //if (fvec_local_energy(newmag)>10.) { + //if (fvec_local_energy(newmag) * newmag->length > 10.) { //hfc = fvec_local_hfc(newmag); //not used aubio_pitchmcomb_spectral_pp (p, newmag); aubio_pitchmcomb_combdet (p, newmag); @@ -146,7 +146,7 @@ aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands) for (j = 0; j < newmag->length; j++) newmag->data[j] = fftgrain->norm[j]; /* detect only if local energy > 10. */ - if (fvec_local_energy (newmag) > 10.) { + if (fvec_local_energy (newmag) * newmag->length > 10.) { /* hfc = fvec_local_hfc(newmag); do not use */ aubio_pitchmcomb_spectral_pp (p, newmag); aubio_pitchmcomb_combdet (p, newmag); -- 2.26.2