From: Paul Brossier Date: Sat, 24 Nov 2007 21:47:15 +0000 (+0100) Subject: moved spectral_centroid to new file X-Git-Tag: bzr2git~435 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fc6c831353a0be625d6ea77b38399b9ace2cf9d0;p=aubio.git moved spectral_centroid to new file --- diff --git a/src/Makefile.am b/src/Makefile.am index 7afd4d40..1431d8cd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ pkginclude_HEADERS = aubio.h \ spectral/phasevoc.h \ spectral/fft.h \ spectral/tss.h \ + spectral/spectral_centroid.h \ pitch/pitchdetection.h \ pitch/pitchmcomb.h \ pitch/pitchyin.h \ @@ -57,6 +58,8 @@ libaubio_la_SOURCES = aubio.h \ spectral/fft.h \ spectral/tss.c \ spectral/tss.h \ + spectral/spectral_centroid.c \ + spectral/spectral_centroid.h \ pitch/pitchdetection.c \ pitch/pitchdetection.h \ pitch/pitchmcomb.c \ diff --git a/src/aubio.h b/src/aubio.h index 4515606b..862b0551 100644 --- a/src/aubio.h +++ b/src/aubio.h @@ -59,8 +59,6 @@ extern "C" { /* in this order */ #include "types.h" #include "sample.h" -#include "spectral/fft.h" -#include "spectral/phasevoc.h" #include "mathutils.h" #include "utils/scale.h" #include "utils/hist.h" @@ -68,6 +66,11 @@ extern "C" { #include "temporal/resample.h" #include "temporal/biquad.h" #include "temporal/filter.h" +#include "spectral/filterbank.h" +#include "spectral/mfcc.h" +#include "spectral/fft.h" +#include "spectral/phasevoc.h" +#include "spectral/spectral_centroid.h" #include "pitch/pitchdetection.h" #include "pitch/pitchmcomb.h" #include "pitch/pitchyin.h" @@ -79,8 +82,6 @@ extern "C" { #include "onset/peakpick.h" #include "tempo/beattracking.h" #include "tempo/tempo.h" -#include "spectral/filterbank.h" -#include "spectral/mfcc.h" #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mathutils.c b/src/mathutils.c index 70797ecc..4193fa31 100644 --- a/src/mathutils.c +++ b/src/mathutils.c @@ -432,19 +432,6 @@ smpl_t aubio_zero_crossing_rate(fvec_t * input) { 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]; diff --git a/src/mathutils.h b/src/mathutils.h index 75fc5d7e..9bf0f583 100644 --- a/src/mathutils.h +++ b/src/mathutils.h @@ -207,10 +207,6 @@ void aubio_autocorr(fvec_t * input, fvec_t * output); * zero-crossing rate (number of zero cross per sample) */ 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 * diff --git a/src/spectral/spectral_centroid.c b/src/spectral/spectral_centroid.c new file mode 100644 index 00000000..36b49933 --- /dev/null +++ b/src/spectral/spectral_centroid.c @@ -0,0 +1,37 @@ +/* + Copyright (C) 2007 Paul Brossier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "aubio_priv.h" +#include "cvec.h" +#include "spectral/spectral_centroid.h" + +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); +} + + diff --git a/src/spectral/spectral_centroid.h b/src/spectral/spectral_centroid.h new file mode 100644 index 00000000..13bff115 --- /dev/null +++ b/src/spectral/spectral_centroid.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2007 Paul Brossier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file + * compute spectrum centroid of a cvec object + */ + +/** + * spectrum centroid computed on a cvec + */ +smpl_t aubio_spectral_centroid(cvec_t * input, smpl_t samplerate);