ref: 7212394ef4949689232625ced2a2600c275aa75a
parent: 5507e9d32a4a5547d924d71258f2ed77b356dbe3
parent: c8b80cd5bac660fc55adcf3e770a5928e91a0131
author: Amaury Hazan <mahmoudax@gmail.com>
date: Mon Sep 10 17:27:16 EDT 2007
some changes
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -457,6 +457,19 @@
return zcr/(smpl_t)input->length;
}
+smpl_t aubio_spectral_centroid(cvec_t * spectrum, smpl_t samplerate) {
+ uint_t i=0, j;
+ smpl_t sum = 0., sc = 0.;
+ for ( j = 0; j < spectrum->length; j++ ) {
+ sum += spectrum->norm[i][j];
+ }
+ if (sum == 0.) return 0.;
+ for ( j = 0; j < spectrum->length; j++ ) {
+ sc += (smpl_t)j * spectrum->norm[i][j];
+ }
+ return sc / sum * samplerate / (smpl_t)(spectrum->length);
+}
+
void aubio_autocorr(fvec_t * input, fvec_t * output){
uint_t i = 0, j = 0, length = input->length;
smpl_t * data = input->data[0];
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -208,6 +208,10 @@
*/
smpl_t aubio_zero_crossing_rate(fvec_t * input);
/**
+ * spectrum centroid computed on a cvec
+ */
+smpl_t aubio_spectral_centroid(cvec_t * input, smpl_t samplerate);
+/**
* clean up cached memory at the end of program
*
* use this function at the end of programs to purge all
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -146,6 +146,7 @@
smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);
void aubio_autocorr(fvec_t * in, fvec_t * acf);
smpl_t aubio_zero_crossing_rate(fvec_t * input);
+smpl_t aubio_spectral_centroid(cvec_t * spectrum, smpl_t samplerate);
/* scale */
extern aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig, smpl_t ilow, smpl_t ihig );
--
⑨