shithub: aubio

Download patch

ref: 71d3bf0fb3571cbb616a0b1138e73a39fc41ffd1
parent: fe28ff360b46117dcf22aa6baf889798f7a9bc81
author: Amaury Hazan <mahmoudax@gmail.com>
date: Wed Sep 5 22:33:11 EDT 2007

small adds

--- a/examples/aubiomfcc.c
+++ b/examples/aubiomfcc.c
@@ -40,12 +40,22 @@
       
       //compute mag spectrum
       aubio_pvoc_do (pv,ibuf, fftgrain);
-      
+     
+      uint_t coef_cnt;
+      uint_t n_filters=20;
+      smpl_t outbuf[20];
+
+      for (coef_cnt=0; coef_cnt<n_filters ; coef_cnt++)
+        outbuf[coef_cnt]=0.f;
        
-      //compute mfcics
+      //compute mfccs
       aubio_mffc_do(fftgrain->norm, nframes, filterbank, outbuf);
       
+      for (coef_cnt=0; coef_cnt<n_filters ; coef_cnt++)
+        outmsg("%f ",outbuf[coef_cnt]);
+      outmsg("\n");
       
+      
 
       /* end of block loop */
       pos = -1; /* so it will be zero next j loop */
@@ -76,6 +86,8 @@
   //allocate and initialize mel filter bank
   uint_t n_filters=20;
   uint_t nyquist= samplerate / 2.; 
+  smpl_t lowfreq=80.f;
+  smpl_t highfreq=18000.f;
 
   uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
   aubio_mel_filter * mf = (aubio_mel_filter *)getbytes(banksize);
@@ -86,7 +98,7 @@
     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);
+  aubio_mfcc_init(buffer_size, nyquist, XTRACT_EQUAL_GAIN, lowfreq, highfreq, mf->n_filters, mf->filters);
 
   //process
   examples_common_process(aubio_process,process_print);
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,8 @@
 	beattracking.h \
 	onset.h \
 	tempo.h \
-	filter.h
+	filter.h 
+
 nodist_pkginclude_HEADERS = config.h
 
 lib_LTLIBRARIES = libaubio.la 
@@ -68,7 +69,7 @@
 	tempo.c \
 	tempo.h \
 	filter.c \
-	filter.h
+	filter.h \
 
 AM_CFLAGS = @AUBIO_CFLAGS@ @FFTWLIB_CFLAGS@ @SAMPLERATE_CFLAGS@
 libaubio_la_LIBADD = @FFTWLIB_LIBS@ @SAMPLERATE_LIBS@ @LTLIBOBJS@
--- a/src/aubiofilterbank.c
+++ /dev/null
@@ -1,123 +1,0 @@
-/*
-   Copyright (C) 2007 Amaury Hazan
-   Ported to aubio from LibXtract
-   http://libxtract.sourceforge.net/
-   
-
-   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 "aubiofilterbank.h"
-
-// Initialization
-
-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; 
-    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;
-    fft_peak = NULL;
-    norm = 1; 
-
-    mel_freq_max = 1127 * log(1 + freq_max / 700);
-    mel_freq_min = 1127 * log(1 + freq_min / 700);
-    freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands;
-
-    mel_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t)); 
-    /* +2 for zeros at start and end */
-    lin_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t));
-    fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int));
-    height_norm = (smpl_t *)malloc(freq_bands * sizeof(smpl_t));
-
-    if(mel_peak == NULL || height_norm == NULL || 
-                    lin_peak == NULL || fft_peak == NULL)
-                    return XTRACT_MALLOC_FAILED;
-    
-    M = N >> 1;
-
-    mel_peak[0] = mel_freq_min;
-    lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
-    fft_peak[0] = lin_peak[0] / nyquist * M;
-
-
-    for (n = 1; n <= freq_bands; n++){  
-    /*roll out peak locations - mel, linear and linear on fft window scale */
-        mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
-        lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
-        fft_peak[n] = lin_peak[n] / nyquist * M;
-    }
-
-    for (n = 0; n < freq_bands; n++){
-        /*roll out normalised gain of each peak*/
-        if (style == XTRACT_EQUAL_GAIN){
-            height = 1; 
-            norm_fact = norm;
-        }
-        else{
-            height = 2 / (lin_peak[n + 2] - lin_peak[n]);
-            norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
-        }
-        height_norm[n] = height * norm_fact;
-    }
-
-    i = 0;
-   
-    for(n = 0; n < freq_bands; n++){
-  
-  /*calculate the rise increment*/
-        if(n > 0)
-            inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
-        else
-            inc = height_norm[n] / fft_peak[n];
-        val = 0;  
-  
-  /*zero the start of the array*/
-  for(k = 0; k < i; k++)
-     fft_tables[n][k] = 0.f;
-  
-  /*fill in the rise */
-        for(; i <= fft_peak[n]; i++){ 
-            fft_tables[n][i] = val;
-            val += inc;
-        }
-  
-        /*calculate the fall increment */
-        inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
-  
-        val = 0;
-  next_peak = fft_peak[n + 1];
-  
-  /*reverse fill the 'fall' */
-        for(i = next_peak; i > fft_peak[n]; i--){ 
-            fft_tables[n][i] = val;
-            val += inc;
-        }
-
-  /*zero the rest of the array*/
-  for(k = next_peak + 1; k < N; k++)
-      fft_tables[n][k] = 0.f;
-    }
-
-    free(mel_peak);
-    free(lin_peak);
-    free(height_norm);
-    free(fft_peak);
-
-    return XTRACT_SUCCESS;
-
-}
--- a/src/aubiofilterbank.h
+++ /dev/null
@@ -1,42 +1,0 @@
-/*
-   Copyright (C) 2007 Amaury Hazan
-   Ported to aubio from LibXtract
-   http://libxtract.sourceforge.net/
-   
-
-   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.
-*/
-
-#ifndef AUBIOFILTERBANK_H
-#define AUBIOFILTERBANK_H
-
-
-// Struct Declaration
-
-/** \brief A structure to store a set of n_filters Mel filters */
-typedef struct aubio_mel_filter_ {
-    int n_filters;
-    smpl_t **filters;
-} aubio_mel_filter;
-
-// Initialization
-
-/** \brief A function to initialise a mel filter bank 
- * 
- * 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, smpl_t ** fft_tables);
-
-#endif
--- /dev/null
+++ b/src/filterbank.c
@@ -1,0 +1,123 @@
+/*
+   Copyright (C) 2007 Amaury Hazan
+   Ported to aubio from LibXtract
+   http://libxtract.sourceforge.net/
+   
+
+   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 "filterbank.h"
+
+// Initialization
+
+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; 
+    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;
+    fft_peak = NULL;
+    norm = 1; 
+
+    mel_freq_max = 1127 * log(1 + freq_max / 700);
+    mel_freq_min = 1127 * log(1 + freq_min / 700);
+    freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands;
+
+    mel_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t)); 
+    /* +2 for zeros at start and end */
+    lin_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t));
+    fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int));
+    height_norm = (smpl_t *)malloc(freq_bands * sizeof(smpl_t));
+
+    if(mel_peak == NULL || height_norm == NULL || 
+                    lin_peak == NULL || fft_peak == NULL)
+                    return XTRACT_MALLOC_FAILED;
+    
+    M = N >> 1;
+
+    mel_peak[0] = mel_freq_min;
+    lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
+    fft_peak[0] = lin_peak[0] / nyquist * M;
+
+
+    for (n = 1; n <= freq_bands; n++){  
+    /*roll out peak locations - mel, linear and linear on fft window scale */
+        mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
+        lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
+        fft_peak[n] = lin_peak[n] / nyquist * M;
+    }
+
+    for (n = 0; n < freq_bands; n++){
+        /*roll out normalised gain of each peak*/
+        if (style == XTRACT_EQUAL_GAIN){
+            height = 1; 
+            norm_fact = norm;
+        }
+        else{
+            height = 2 / (lin_peak[n + 2] - lin_peak[n]);
+            norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
+        }
+        height_norm[n] = height * norm_fact;
+    }
+
+    i = 0;
+   
+    for(n = 0; n < freq_bands; n++){
+  
+  /*calculate the rise increment*/
+        if(n > 0)
+            inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
+        else
+            inc = height_norm[n] / fft_peak[n];
+        val = 0;  
+  
+  /*zero the start of the array*/
+  for(k = 0; k < i; k++)
+     fft_tables[n][k] = 0.f;
+  
+  /*fill in the rise */
+        for(; i <= fft_peak[n]; i++){ 
+            fft_tables[n][i] = val;
+            val += inc;
+        }
+  
+        /*calculate the fall increment */
+        inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
+  
+        val = 0;
+  next_peak = fft_peak[n + 1];
+  
+  /*reverse fill the 'fall' */
+        for(i = next_peak; i > fft_peak[n]; i--){ 
+            fft_tables[n][i] = val;
+            val += inc;
+        }
+
+  /*zero the rest of the array*/
+  for(k = next_peak + 1; k < N; k++)
+      fft_tables[n][k] = 0.f;
+    }
+
+    free(mel_peak);
+    free(lin_peak);
+    free(height_norm);
+    free(fft_peak);
+
+    return XTRACT_SUCCESS;
+
+}
--- /dev/null
+++ b/src/filterbank.h
@@ -1,0 +1,42 @@
+/*
+   Copyright (C) 2007 Amaury Hazan
+   Ported to aubio from LibXtract
+   http://libxtract.sourceforge.net/
+   
+
+   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.
+*/
+
+#ifndef AUBIOFILTERBANK_H
+#define AUBIOFILTERBANK_H
+
+
+// Struct Declaration
+
+/** \brief A structure to store a set of n_filters Mel filters */
+typedef struct aubio_mel_filter_ {
+    int n_filters;
+    smpl_t **filters;
+} aubio_mel_filter;
+
+// Initialization
+
+/** \brief A function to initialise a mel filter bank 
+ * 
+ * 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, smpl_t ** fft_tables);
+
+#endif
--- a/src/mfcc.c
+++ b/src/mfcc.c
@@ -22,7 +22,6 @@
 
 
 #include "mffc.h"
-#include "aubiofilterbank.h"
 
 // Computation
 
@@ -59,4 +58,4 @@
     fftwf_destroy_plan(plan);
 
     return XTRACT_SUCCESS;
-}
\ No newline at end of file
+}
--- a/src/mfcc.h
+++ b/src/mfcc.h
@@ -23,9 +23,7 @@
 #ifndef MFCC_H 
 #define MFCC_H 
 
-#include "aubiofilterbank.h"
-
-#define NYQUIST 22050.f
+#include "filterbank.h"
 
 //libXtract enums
 // TODO: remove them