shithub: aubio

Download patch

ref: 1a74ac3c0d8a103200732923f2ba7af1ef0341af
parent: b583b9fb673169ebbf37820ea93875f18679fdb1
author: Paul Brossier <piem@piem.org>
date: Fri Feb 4 05:26:10 EST 2011

src/mathutils.c: fix aubio_db_spl, thanks to Eric, closes #15

--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -214,7 +214,7 @@
   for (j = 0; j < f->length; j++) {
     energy += SQR (f->data[j]);
   }
-  return energy;
+  return energy / f->length;
 }
 
 smpl_t
@@ -449,9 +449,7 @@
 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
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -106,7 +106,8 @@
 
 /** 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 
 
--- a/src/pitch/pitchmcomb.c
+++ b/src/pitch/pitchmcomb.c
@@ -111,7 +111,7 @@
   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 @@
   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);