shithub: aubio

Download patch

ref: fe28ff360b46117dcf22aa6baf889798f7a9bc81
parent: 88199cee9bb703d33e28636e043109db53681ccb
author: Paul Brossier <[email protected]>
date: Wed Sep 5 17:37:09 EDT 2007

minor corrections

--- a/examples/aubiomfcc.c
+++ b/examples/aubiomfcc.c
@@ -41,10 +41,9 @@
       //compute mag spectrum
       aubio_pvoc_do (pv,ibuf, fftgrain);
       
-      //TODO: extract Magnitude buffer f_fvec from fftgrain cvec
-
-      //compute mfccs
-      aubio_mffc_do (magbuf, nframes, filterbank, outbuf);
+       
+      //compute mfcics
+      aubio_mffc_do(fftgrain->norm, nframes, filterbank, outbuf);
       
       
 
@@ -73,10 +72,31 @@
 
 int main(int argc, char **argv) {
   examples_common_init(argc,argv);
+  
+  //allocate and initialize mel filter bank
+  uint_t n_filters=20;
+  uint_t nyquist= samplerate / 2.; 
+
+  uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
+  aubio_mel_filter * mf = (aubio_mel_filter *)getbytes(banksize);
+
+  mfilterbank->n_filters = 20;
+  mfilterbank->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *));
+  for(n = 0; n < mf->n_filters; n++)
+    mf->filters[n] = (smpl_t *)getbytes((buffer_size/2+1) * sizeof(smpl_t));
+  
+  //populating the filter
+  new_aubio_mfcc(buffer_size, nyquist, XTRACT_EQUAL_GAIN, 80.0f, 18000.0f, mf->n_filters, mf->filters);
+
+  //process
   examples_common_process(aubio_process,process_print);
   examples_common_del();
   debug("End of program.\n");
   fflush(stderr);
+  
+  //destroying filterbank
+  free(mf);
+  
   return 0;
 }
 
--- a/src/aubio.h
+++ b/src/aubio.h
@@ -79,6 +79,7 @@
 #include "beattracking.h"
 #include "onset.h"
 #include "tempo.h"
+#include "mfcc.h"
 
 #ifdef __cplusplus
 } /* extern "C" */
--- a/src/aubiofilterbank.c
+++ b/src/aubiofilterbank.c
@@ -24,10 +24,10 @@
 
 // Initialization
 
-int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, float **fft_tables){
+int aubio_mfcc_init(int N, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max, int freq_bands, smpl_t **fft_tables){
 
     int n, i, k, *fft_peak, M, next_peak; 
-    float norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, 
+    smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val, 
         freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
 
     mel_peak = height_norm = lin_peak = NULL;
@@ -38,11 +38,11 @@
     mel_freq_min = 1127 * log(1 + freq_min / 700);
     freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands;
 
-    mel_peak = (float *)malloc((freq_bands + 2) * sizeof(float)); 
+    mel_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t)); 
     /* +2 for zeros at start and end */
-    lin_peak = (float *)malloc((freq_bands + 2) * sizeof(float));
+    lin_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t));
     fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int));
-    height_norm = (float *)malloc(freq_bands * sizeof(float));
+    height_norm = (smpl_t *)malloc(freq_bands * sizeof(smpl_t));
 
     if(mel_peak == NULL || height_norm == NULL || 
                     lin_peak == NULL || fft_peak == NULL)
@@ -120,4 +120,4 @@
 
     return XTRACT_SUCCESS;
 
-}
\ No newline at end of file
+}
--- a/src/aubiofilterbank.h
+++ b/src/aubiofilterbank.h
@@ -17,13 +17,11 @@
    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.
-
 */
 
 #ifndef AUBIOFILTERBANK_H
-#include AUBIOFILTERBANK_H
+#define AUBIOFILTERBANK_H
 
-#define NYQUIST 22050.f
 
 // Struct Declaration
 
@@ -30,7 +28,7 @@
 /** \brief A structure to store a set of n_filters Mel filters */
 typedef struct aubio_mel_filter_ {
     int n_filters;
-    float **filters;
+    smpl_t **filters;
 } aubio_mel_filter;
 
 // Initialization
@@ -39,6 +37,6 @@
  * 
  * It is up to the caller to pass in a pointer to memory allocated for freq_bands arrays of length N. This function populates these arrays with magnitude coefficients representing the mel filterbank on a linear scale 
  */
-int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, float **fft_tables);
+int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, smpl_t ** fft_tables);
 
-#endif
\ No newline at end of file
+#endif
--- a/src/mfcc.h
+++ b/src/mfcc.h
@@ -23,6 +23,8 @@
 #ifndef MFCC_H 
 #define MFCC_H 
 
+#include "aubiofilterbank.h"
+
 #define NYQUIST 22050.f
 
 //libXtract enums
@@ -142,4 +144,4 @@
 int aubio_dct_do(const float *data, const int N, const void *argv, float *result);
 
 
-#endif
\ No newline at end of file
+#endif