From 5b41ef983e4ddd60a0e1d095fd1b798241a3f96f Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 17 Nov 2013 18:23:34 +0100 Subject: [PATCH] src/mathutils.h: move fvec_local_energy to aubio_level_lin, move to musicutils.h --- examples/aubiopitch.c | 3 +-- src/mathutils.c | 4 ++-- src/mathutils.h | 12 ------------ src/musicutils.h | 13 +++++++++++++ src/pitch/pitchmcomb.c | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index 078f125b..fcffce64 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -40,8 +40,7 @@ static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { /* 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 { diff --git a/src/mathutils.c b/src/mathutils.c index 812e2977..86d8f1a2 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -263,7 +263,7 @@ fvec_shift (fvec_t * s) } 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 @@ aubio_next_power_of_two (uint_t a) smpl_t aubio_db_spl (fvec_t * o) { - return 10. * LOG10 (fvec_local_energy (o)); + return 10. * LOG10 (aubio_level_lin (o)); } uint_t diff --git a/src/mathutils.h b/src/mathutils.h index 913c6d7d..d9b60424 100644 --- a/src/mathutils.h +++ b/src/mathutils.h @@ -108,18 +108,6 @@ void fvec_shift (fvec_t * v); */ 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$. diff --git a/src/musicutils.h b/src/musicutils.h index 8ad29f05..4c823fd8 100644 --- a/src/musicutils.h +++ b/src/musicutils.h @@ -100,10 +100,23 @@ void aubio_cleanup (void); */ 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 \return level of v in dB SPL diff --git a/src/pitch/pitchmcomb.c b/src/pitch/pitchmcomb.c index 3425aa0b..fee030e9 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) * 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 @@ 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) * 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); -- 2.11.0