minor corrections
authorPaul Brossier <piem@piem.org>
Wed, 5 Sep 2007 19:37:09 +0000 (21:37 +0200)
committerPaul Brossier <piem@piem.org>
Wed, 5 Sep 2007 19:37:09 +0000 (21:37 +0200)
examples/aubiomfcc.c
src/aubio.h
src/aubiofilterbank.c
src/aubiofilterbank.h
src/mfcc.h

index cca6605..3dcd2ab 100644 (file)
@@ -41,10 +41,9 @@ int aubio_process(float **input, float **output, int nframes) {
       //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 @@ void process_print (void) {
 
 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;
 }
 
index f523582..3006bcf 100644 (file)
@@ -79,6 +79,7 @@ extern "C" {
 #include "beattracking.h"
 #include "onset.h"
 #include "tempo.h"
+#include "mfcc.h"
 
 #ifdef __cplusplus
 } /* extern "C" */
index a4fa199..6039998 100644 (file)
 
 // 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 @@ int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_
     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 @@ int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_
 
     return XTRACT_SUCCESS;
 
-}
\ No newline at end of file
+}
index acd32e5..8a8fecf 100644 (file)
    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
 
 /** \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 @@ typedef struct aubio_mel_filter_ {
  * 
  * 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
index 03a9c5d..856f77c 100644 (file)
@@ -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_mfcc_do(const float *data, const int N, const void *argv, float *resul
 int aubio_dct_do(const float *data, const int N, const void *argv, float *result);
 
 
-#endif
\ No newline at end of file
+#endif