shithub: aubio

Download patch

ref: 5b41ef983e4ddd60a0e1d095fd1b798241a3f96f
parent: c1ddeb8be6f8c5541e26339aef3998dd44966c0b
author: Paul Brossier <piem@piem.org>
date: Sun Nov 17 13:23:34 EST 2013

src/mathutils.h: move fvec_local_energy to aubio_level_lin, move to musicutils.h

--- a/examples/aubiopitch.c
+++ b/examples/aubiopitch.c
@@ -40,8 +40,7 @@
       /* block loop */
       aubio_pitch_do (o, ibuf, pitch);
       smpl_t freq = fvec_read_sample(pitch, 0);
-      smpl_t amp = powf(10., aubio_db_spl(ibuf)*.05 );
-      aubio_wavetable_set_amp ( wavetable, amp );
+      aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
       if (freq != 0.0) {
         aubio_wavetable_set_freq ( wavetable, freq );
       } else {
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -263,7 +263,7 @@
 }
 
 smpl_t
-fvec_local_energy (fvec_t * f)
+aubio_level_lin (fvec_t * f)
 {
   smpl_t energy = 0.;
   uint_t j;
@@ -508,7 +508,7 @@
 smpl_t
 aubio_db_spl (fvec_t * o)
 {
-  return 10. * LOG10 (fvec_local_energy (o));
+  return 10. * LOG10 (aubio_level_lin (o));
 }
 
 uint_t
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -108,18 +108,6 @@
 */
 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, normalised
-  by its length.
- 
-  \param v vector to get the energy from 
-
-  \return the energy of v
- 
-*/
-smpl_t fvec_local_energy (fvec_t * v);
-
 /** compute the High Frequency Content of a vector
 
   The High Frequency Content is defined as \f$ \sum_0^{N-1} (k+1) v[k] \f$.
--- a/src/musicutils.h
+++ b/src/musicutils.h
@@ -100,9 +100,22 @@
 */
 smpl_t aubio_zero_crossing_rate (fvec_t * v);
 
+/** compute sound level on a linear
+
+  This gives the average of the square amplitudes.
+
+  \param v vector to compute dB SPL from
+
+  \return level of v
+
+*/
+smpl_t aubio_level_lin (fvec_t * v);
+
 /** compute sound pressure level (SPL) in dB
 
   This quantity is often wrongly called 'loudness'.
+
+  This gives ten times the log10 of the average of the square amplitudes.
 
   \param v vector to compute dB SPL 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) * newmag->length > 10.) {
+  //if (aubio_level_lin (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) * newmag->length > 10.) {
+  if (aubio_level_lin (newmag) * newmag->length > 10.) {
     /* hfc = fvec_local_hfc(newmag); do not use */
     aubio_pitchmcomb_spectral_pp (p, newmag);
     aubio_pitchmcomb_combdet (p, newmag);