Changes in / [7a46bf6:7c6c806d]


Ignore:
Files:
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • examples/Makefile.am

    r7a46bf6 r7c6c806d  
    1111        aubioonset \
    1212        aubiotrack \
    13         aubionotes \
    14         aubiomfcc
     13        aubionotes
    1514
    1615noinst_PROGRAMS = \
     
    2423aubiotrack_SOURCES = aubiotrack.c utils.c
    2524aubioquiet_SOURCES = aubioquiet.c utils.c
    26 aubiomfcc_SOURCES = aubiomfcc.c utils.c
    2725
    2826aubioonset_LDADD = @JACK_LIBS@
     
    3028aubiotrack_LDADD = @JACK_LIBS@
    3129aubioquiet_LDADD = @JACK_LIBS@
    32 aubiomfcc_LDADD = @JACK_LIBS@
  • examples/aubiomfcc.c

    r7a46bf6 r7c6c806d  
    11/*
    2    Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
    3                   and Paul Brossier <piem@piem.org>
     2   Copyright (C) 2007 Amaury Hazan
    43
    54   This program is free software; you can redistribute it and/or modify
     
    1918
    2019#include "utils.h"
    21 
    22 /* mfcc objects */
    23 fvec_t * mfcc_out;
    24 aubio_mfcc_t * mfcc;
    25 
    26 uint_t n_filters = 20;
    27 uint_t n_coefs = 11;
    2820
    2921unsigned int pos = 0; /*frames%dspblocksize*/
     
    5143      aubio_pvoc_do (pv,ibuf, fftgrain);
    5244     
     45      uint_t n_coefs= n_filters/2 +1;
     46      uint_t coef_cnt;
     47       
     48
     49      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
     50        mfcc_outbuf[coef_cnt]=0.f;
     51       
    5352      //compute mfccs
    54       aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
     53      aubio_mffc_do(fftgrain->norm, nframes, mf, mfcc_outbuf, fft_dct, fftgrain_dct);
     54     
     55      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
     56        outmsg("%f ",mfcc_outbuf[coef_cnt]);
     57      outmsg("\n");
     58     
     59     
    5560
    5661      /* end of block loop */
     
    6873      */
    6974     
    70       uint_t coef_cnt;
    7175      if (output_filename == NULL) {
    72 //         if(frames >= 4) {
    73 //           outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate);
    74 //         }
    75 //         else if (frames < 4) {
    76 //           outmsg("%f\t",0.);
    77 //         }
    78         //outmsg("%f ",mfcc_out->data[0][0]);
    79        
    80         /*for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
    81           outmsg("%f ",mfcc_out->data[0][coef_cnt]);
     76        if(frames >= 4) {
     77          outmsg("%f\n",(frames-4)*overlap_size/(float)samplerate);
     78        } else if (frames < 4) {
     79          outmsg("%f\n",0.);
    8280        }
    83         outmsg("\n");/*/
    8481      }
    8582}
    8683
    8784int main(int argc, char **argv) {
    88   // params
    89   //uint_t n_filters = 40;
    90   //uint_t n_coefs = 15;
     85  examples_common_init(argc,argv);
     86 
     87  //allocate and initialize mel filter bank
     88 
    9189
    92   examples_common_init(argc,argv);
    93   smpl_t lowfreq = 133.333f;
    94   smpl_t highfreq = 44100.f;
    95   mfcc_out = new_fvec(n_coefs,channels);
     90  //allocating global mf (in utils.c)
     91  uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
     92  mf = (aubio_mel_filter *)getbytes(banksize);
     93
     94  mf->n_filters = 20;
     95  mf->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *));
     96  for(n = 0; n < mf->n_filters; n++)
     97    mf->filters[n] = (smpl_t *)getbytes((buffer_size/2+1) * sizeof(smpl_t));
    9698 
    9799  //populating the filter
    98   mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels);
     100  aubio_mfcc_init(buffer_size, nyquist, XTRACT_EQUAL_GAIN, lowfreq, highfreq, mf->n_filters, mf->filters);
    99101
    100102  //process
    101103  examples_common_process(aubio_process,process_print);
    102  
    103   //destroying mfcc
    104   del_aubio_mfcc(mfcc);
    105   del_fvec(mfcc_out);
    106 
    107104  examples_common_del();
    108105  debug("End of program.\n");
    109106  fflush(stderr);
    110107 
     108  //destroying filterbank
     109  free(mf);
     110 
    111111  return 0;
    112112}
  • examples/tests/test-beattracking.c

    r7a46bf6 r7c6c806d  
    1313        uint_t i = 0;
    1414
    15         smpl_t curtempo;
    16 
    1715        while (i < 10) {
    1816          aubio_beattracking_do(tempo,in,out);
    19           curtempo = aubio_beattracking_get_bpm(tempo);
    20           if (curtempo != 0.) {
    21             fprintf(stdout,"%f\n",curtempo);
    22             return 1;
    23           }
    2417          i++;
    2518        };
  • examples/tests/test-tempo.c

    r7a46bf6 r7c6c806d  
    1010        uint_t i = 0;
    1111
    12         smpl_t curtempo;
    13 
    1412        while (i < 1000) {
    1513          aubio_tempo(o,in,out);
    16           curtempo = aubio_tempo_get_bpm(o);
    17           if (curtempo != 0.) {
    18             fprintf(stdout,"%f\n",curtempo);
    19           }
    2014          i++;
    2115        };
  • examples/utils.c

    r7a46bf6 r7c6c806d  
    6060int isonset = 0;
    6161aubio_pickpeak_t * parms;
     62
     63/* mfcc objects */
     64//parameters
     65uint_t n_filters=20;
     66uint_t nyquist= samplerate / 2.;
     67smpl_t lowfreq=80.f;
     68smpl_t highfreq=18000.f;
     69// filterbank object
     70aubio_mel_filter * mf;
     71
     72// DCT mfft and result storage
     73aubio_mfft * fft_dct;
     74cvec_t * fftgrain_dct;
     75smpl_t mfcc_outbuf[11];
     76
    6277
    6378/* pitch objects */
     
    300315  fftgrain  = new_cvec(buffer_size, channels);
    301316
    302  
     317  //init for mfcc process
     318  fftgrain_dct= new_cvec(n_filters, channels);
     319
    303320  if (usepitch) {
    304321    pitchdet = new_aubio_pitchdetection(buffer_size*4,
     
    314331  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    315332 
     333  // dct phase vocoder
     334  //TODO: check size
     335  fft_dct = new_aubio_mfft(n_filters, channels);
     336
    316337  /* onsets */
    317338  parms = new_aubio_peakpicker(threshold);
     
    347368  del_fvec(onset);
    348369  del_fvec(woodblock);
     370 
     371  //mffc related
     372  del_aubio_mfft(fft_dct);
     373  del_cvec(fftgrain_dct);
    349374 
    350375  aubio_cleanup();
  • examples/utils.h

    r7a46bf6 r7c6c806d  
    9898extern aubio_pickpeak_t * parms;
    9999
     100/* mfcc objects */
     101// params
     102extern uint_t n_filters;
     103extern uint_t nyquist;
     104extern smpl_t lowfreq;
     105extern smpl_t highfreq;
     106// filterbank object
     107extern aubio_mel_filter * mf;
     108// DCT pvoc and result storage
     109extern aubio_mfft_t * fft_dct;
     110extern cvec_t * fftgrain_dct;
     111extern smpl_t mfcc_outbuf[20];
     112
    100113/* pitch objects */
    101114extern smpl_t pitch;
  • src/Makefile.am

    r7a46bf6 r7c6c806d  
    2323        tempo.h \
    2424        filter.h \
    25         filterbank.h \
    2625        mfcc.h
    2726
     
    7372        filter.c \
    7473        filter.h \
    75         filterbank.c \
    76         filterbank.h \
    7774        mfcc.h \
    7875        mfcc.c
  • src/aubio.h

    r7a46bf6 r7c6c806d  
    8080#include "onset.h"
    8181#include "tempo.h"
    82 #include "filterbank.h"
    8382#include "mfcc.h"
    8483
  • src/beattracking.c

    r7a46bf6 r7c6c806d  
    453453
    454454}
    455 
    456 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt) {
    457         if (bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
    458           return 5168. / (smpl_t)bt->gp;
    459         } else {
    460           return 0.;
    461         }
    462 }
  • src/beattracking.h

    r7a46bf6 r7c6c806d  
    6060*/
    6161void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframes, fvec_t * out);
    62 /** get current tempo in bpm
    63 
    64   \param bt beat tracking object
    65 
    66   Returns the currently observed tempo, in beats per minutes, or 0 if no
    67   consistent value is found.
    68 
    69 */
    70 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);
    7162/** delete beat tracking object
    7263
  • src/filterbank.c

    r7a46bf6 r7c6c806d  
    11/*
    2    Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
    3                   and Paul Brossier <piem@piem.org>
     2   Copyright (C) 2007 Amaury Hazan
     3   Ported to aubio from LibXtract
     4   http://libxtract.sourceforge.net/
     5   
    46
    57   This program is free software; you can redistribute it and/or modify
     
    1921*/
    2022
    21 /* part of this mfcc implementation were inspired from LibXtract
    22    http://libxtract.sourceforge.net/
    23 */
    24 
    2523#include "aubio_priv.h"
    26 #include "sample.h"
    2724#include "filterbank.h"
    2825
    29 #include "stdio.h"
    3026
    31 #define USE_EQUAL_GAIN 1
    32 #define VERY_SMALL_NUMBER 2e-42
     27// Struct Declaration
    3328
    34 /** \brief A structure to store a set of n_filters filters of lenghts win_s */
    35 struct aubio_filterbank_t_ {
    36     uint_t win_s;
    37     uint_t n_filters;
    38     fvec_t **filters;
     29/** \brief A structure to store a set of n_filters Mel filters */
     30typedef struct aubio_mel_filter_ {
     31    int n_filters;
     32    smpl_t **filters;
    3933};
    4034
    41 aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s){
    42   /** allocating space for filterbank object */
    43   aubio_filterbank_t * fb = AUBIO_NEW(aubio_filterbank_t);
    44   uint_t filter_cnt;
    45   fb->win_s=win_s;
    46   fb->n_filters=n_filters;
     35// Initialization
    4736
    48   /** allocating filter tables */
    49   fb->filters=AUBIO_ARRAY(fvec_t*,n_filters);
    50   for (filter_cnt=0; filter_cnt<n_filters; filter_cnt++)
    51     /* considering one-channel filters */
    52     fb->filters[filter_cnt]=new_fvec(win_s, 1);
     37int 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){
    5338
    54   return fb;
    55 }
     39    int n, i, k, *fft_peak, M, next_peak;
     40    smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val,
     41        freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
    5642
    57 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max){
    58  
    59   uint_t writelog=1;
     43    mel_peak = height_norm = lin_peak = NULL;
     44    fft_peak = NULL;
     45    norm = 1;
    6046
    61   FILE * mlog;
    62   if(writelog==1) mlog=fopen("filterbank.txt","w");
    63  
     47    mel_freq_max = 1127 * log(1 + freq_max / 700);
     48    mel_freq_min = 1127 * log(1 + freq_min / 700);
     49    freq_bw_mel = (mel_freq_max - mel_freq_min) / freq_bands;
    6450
    65   smpl_t nyquist = samplerate/2.;
    66   uint_t style = 1;
    67   aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
     51    mel_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t));
     52    /* +2 for zeros at start and end */
     53    lin_peak = (smpl_t *)malloc((freq_bands + 2) * sizeof(smpl_t));
     54    fft_peak = (int *)malloc((freq_bands + 2) * sizeof(int));
     55    height_norm = (smpl_t *)malloc(freq_bands * sizeof(smpl_t));
    6856
    69   uint_t n, i, k, *fft_peak, M, next_peak;
    70   smpl_t norm, mel_freq_max, mel_freq_min, norm_fact, height, inc, val,
    71          freq_bw_mel, *mel_peak, *height_norm, *lin_peak;
     57    if(mel_peak == NULL || height_norm == NULL ||
     58                    lin_peak == NULL || fft_peak == NULL)
     59                    return XTRACT_MALLOC_FAILED;
     60   
     61    M = N >> 1;
    7262
    73   mel_peak = height_norm = lin_peak = NULL;
    74   fft_peak = NULL;
    75   norm = 1;
     63    mel_peak[0] = mel_freq_min;
     64    lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
     65    fft_peak[0] = lin_peak[0] / nyquist * M;
    7666
    77   mel_freq_max = 1127 * log(1 + freq_max / 700);
    78   mel_freq_min = 1127 * log(1 + freq_min / 700);
    79   freq_bw_mel = (mel_freq_max - mel_freq_min) / fb->n_filters;
    8067
    81   mel_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
    82   /* +2 for zeros at start and end */
    83   lin_peak = (smpl_t *)malloc((fb->n_filters + 2) * sizeof(smpl_t));
    84   fft_peak = (uint_t *)malloc((fb->n_filters + 2) * sizeof(uint_t));
    85   height_norm = (smpl_t *)malloc(fb->n_filters * sizeof(smpl_t));
    86 
    87   if(mel_peak == NULL || height_norm == NULL ||
    88       lin_peak == NULL || fft_peak == NULL)
    89     return NULL;
    90 
    91   M = fb->win_s >> 1;
    92 
    93   mel_peak[0] = mel_freq_min;
    94   lin_peak[0] = 700 * (exp(mel_peak[0] / 1127) - 1);
    95   fft_peak[0] = lin_peak[0] / nyquist * M;
    96 
    97   for (n = 1; n <= fb->n_filters; n++){ 
     68    for (n = 1; n <= freq_bands; n++){ 
    9869    /*roll out peak locations - mel, linear and linear on fft window scale */
    99     mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
    100     lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
    101     fft_peak[n] = lin_peak[n] / nyquist * M;
    102   }
    103 
    104   for (n = 0; n < fb->n_filters; n++){
    105     /*roll out normalised gain of each peak*/
    106     if (style == USE_EQUAL_GAIN){
    107       height = 1;
    108       norm_fact = norm;
    109     }
    110     else{
    111       height = 2 / (lin_peak[n + 2] - lin_peak[n]);
    112       norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
    113     }
    114     height_norm[n] = height * norm_fact;
    115   }
    116 
    117   i = 0;
    118 
    119   for(n = 0; n < fb->n_filters; n++){
    120 
    121     /*calculate the rise increment*/
    122     if(n > 0)
    123       inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
    124     else
    125       inc = height_norm[n] / fft_peak[n];
    126     val = 0; 
    127 
    128     /*zero the start of the array*/
    129     for(k = 0; k < i; k++)
    130       fb->filters[n]->data[0][k]=0.f;
    131 
    132     /*fill in the rise */
    133     for(; i <= fft_peak[n]; i++){
    134       fb->filters[n]->data[0][k]=val;
    135       val += inc;
     70        mel_peak[n] = mel_peak[n - 1] + freq_bw_mel;
     71        lin_peak[n] = 700 * (exp(mel_peak[n] / 1127) -1);
     72        fft_peak[n] = lin_peak[n] / nyquist * M;
    13673    }
    13774
    138     /*calculate the fall increment */
    139     inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
    140 
    141     val = 0;
    142     next_peak = fft_peak[n + 1];
    143 
    144     /*reverse fill the 'fall' */
    145     for(i = next_peak; i > fft_peak[n]; i--){
    146       fb->filters[n]->data[0][k]=val;
    147       val += inc;
     75    for (n = 0; n < freq_bands; n++){
     76        /*roll out normalised gain of each peak*/
     77        if (style == XTRACT_EQUAL_GAIN){
     78            height = 1;
     79            norm_fact = norm;
     80        }
     81        else{
     82            height = 2 / (lin_peak[n + 2] - lin_peak[n]);
     83            norm_fact = norm / (2 / (lin_peak[2] - lin_peak[0]));
     84        }
     85        height_norm[n] = height * norm_fact;
    14886    }
    14987
    150     /*zero the rest of the array*/
    151     for(k = next_peak + 1; k < fb->win_s; k++)
    152       fb->filters[n]->data[0][k]=0.f;
     88    i = 0;
     89   
     90    for(n = 0; n < freq_bands; n++){
     91 
     92  /*calculate the rise increment*/
     93        if(n > 0)
     94            inc = height_norm[n] / (fft_peak[n] - fft_peak[n - 1]);
     95        else
     96            inc = height_norm[n] / fft_peak[n];
     97        val = 0; 
     98 
     99  /*zero the start of the array*/
     100  for(k = 0; k < i; k++)
     101     fft_tables[n][k] = 0.f;
     102 
     103  /*fill in the rise */
     104        for(; i <= fft_peak[n]; i++){
     105            fft_tables[n][i] = val;
     106            val += inc;
     107        }
     108 
     109        /*calculate the fall increment */
     110        inc = height_norm[n] / (fft_peak[n + 1] - fft_peak[n]);
     111 
     112        val = 0;
     113  next_peak = fft_peak[n + 1];
     114 
     115  /*reverse fill the 'fall' */
     116        for(i = next_peak; i > fft_peak[n]; i--){
     117            fft_tables[n][i] = val;
     118            val += inc;
     119        }
    153120
    154     if(writelog){
    155       //dumping filter values
    156       smpl_t area_tmp=0.f;
    157       for(k = 0; k < fb->win_s; k++){
    158         fprintf(mlog,"%f ",fb->filters[n]->data[0][k]);
    159       }
    160       fprintf(mlog,"\n");
     121  /*zero the rest of the array*/
     122  for(k = next_peak + 1; k < N; k++)
     123      fft_tables[n][k] = 0.f;
    161124    }
    162125
    163   }
     126    free(mel_peak);
     127    free(lin_peak);
     128    free(height_norm);
     129    free(fft_peak);
    164130
    165   free(mel_peak);
    166   free(lin_peak);
    167   free(height_norm);
    168   free(fft_peak);
    169 
    170   if(mlog) fclose(mlog);
    171 
    172   return fb;
     131    return XTRACT_SUCCESS;
    173132
    174133}
    175 
    176 
    177 void del_aubio_filterbank(aubio_filterbank_t * fb){
    178   uint_t filter_cnt;
    179   /** deleting filter tables first */
    180   for (filter_cnt=0; filter_cnt<fb->n_filters; filter_cnt++)
    181     del_fvec(fb->filters[filter_cnt]);
    182   AUBIO_FREE(fb->filters);
    183   AUBIO_FREE(fb);
    184 }
    185 
    186 void aubio_filterbank_do(aubio_filterbank_t * f, cvec_t * in, fvec_t *out) {
    187   uint_t n, filter_cnt;
    188   for(filter_cnt = 0; (filter_cnt < f->n_filters)
    189     && (filter_cnt < out->length); filter_cnt++){
    190       out->data[0][filter_cnt] = 0.f;
    191       for(n = 0; n < in->length; n++){
    192           out->data[0][filter_cnt] += in->norm[0][n]
    193             * f->filters[filter_cnt]->data[0][n];
    194       }
    195       out->data[0][filter_cnt] =
    196         LOG(out->data[0][filter_cnt] < VERY_SMALL_NUMBER ?
    197             VERY_SMALL_NUMBER : out->data[0][filter_cnt]);
    198   }
    199 
    200   return;
    201 }
  • src/filterbank.h

    r7a46bf6 r7c6c806d  
    11/*
    2    Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
    3                   and Paul Brossier <piem@piem.org>
     2   Copyright (C) 2007 Amaury Hazan
     3   Ported to aubio from LibXtract
     4   http://libxtract.sourceforge.net/
     5   
    46
    57   This program is free software; you can redistribute it and/or modify
     
    1820*/
    1921
    20 /** \file
    21 
    22   Filterbank object
    23 
    24   General-purpose spectral filterbank object. Comes with mel-filter initialization function.
    25 
    26 */
    27 
    28 #ifndef FILTERBANK_H
    29 #define FILTERBANK_H
     22#ifndef AUBIOFILTERBANK_H
     23#define AUBIOFILTERBANK_H
    3024
    3125#ifdef __cplusplus
     
    3327#endif
    3428
    35 typedef struct aubio_filterbank_t_ aubio_filterbank_t;
    36 
    37 /** create filterbank object
    38 
    39   \param win_s size of analysis buffer (and length the FFT transform)
    40   \param n_filters number of filters to create
    41 
    42 */
    43 
    44 aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s);
    45 
    46 /** filterbank initialization for mel filters
    47 
    48   \param nyquist nyquist frequency, i.e. half of the sampling rate
    49   \param style libxtract style
    50   \param freqmin lowest filter frequency
    51   \param freqmax highest filter frequency
    52 
    53 */
    54 aubio_filterbank_t * new_aubio_filterbank_mfcc(uint_t n_filters, uint_t win_s, smpl_t samplerate, smpl_t freq_min, smpl_t freq_max);
    5529
    5630
    57 /** destroy filterbank object
     31typedef struct aubio_mel_filter_ aubio_mel_filter;
    5832
    59   \param fb filterbank, as returned by new_aubio_filterbank method
     33// Initialization
    6034
    61 */
    62 void del_aubio_filterbank(aubio_filterbank_t * fb);
    63 
    64 /** compute filterbank
    65 
    66 */
    67 void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
     35/** \brief A function to initialise a mel filter bank
     36 *
     37 * 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
     38 */
     39int 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);
    6840
    6941#ifdef __cplusplus
     
    7143#endif
    7244
    73 #endif // FILTERBANK_H
     45#endif
  • src/mfcc.c

    r7a46bf6 r7c6c806d  
    2424#include "sample.h"
    2525#include "fft.h"
    26 #include "filterbank.h"
    2726#include "mfcc.h"
    2827#include "math.h"
    2928
    30 /** Internal structure for mfcc object **/
     29/*
     30new_aubio_mfcc
     31aubio_mfcc_do
     32del_aubio_mfcc
     33*/
    3134
    32 struct aubio_mfcc_t_{
    33   uint_t win_s;             /** grain length */
    34   uint_t samplerate;        /** sample rate (needed?) */
    35   uint_t channels;          /** number of channels */
    36   uint_t n_filters;         /** number of  *filters */
    37   uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
    38   smpl_t lowfreq;           /** lowest frequency for filters */
    39   smpl_t highfreq;          /** highest frequency for filters */
    40   aubio_filterbank_t * fb;  /** filter bank */
    41   fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
    42   aubio_mfft_t * fft_dct;   /** fft object for dct */
    43   cvec_t * fftgrain_dct;    /** output buffer for dct */
    44 };
     35// Computation
     36// Added last two arguments to be able to pass from example
    4537
    4638
    47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
    48   /** allocating space for mfcc object */
    49   aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
    5039
    51   //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
    52   //uint_t n_filters = (n_coefs-1)*2;
    53  
    54   mfcc->win_s=win_s;
    55   mfcc->samplerate=samplerate;
    56   mfcc->channels=channels;
    57   mfcc->n_filters=n_filters;
    58   mfcc->n_coefs=n_coefs;
    59   mfcc->lowfreq=lowfreq;
    60   mfcc->highfreq=highfreq;
     40int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
    6141
    62   /** filterbank allocation */
    63   mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
     42    aubio_mel_filter *f;
     43    int n, filter;
    6444
    65   /** allocating space for fft object (used for dct) */
    66   mfcc->fft_dct=new_aubio_mfft(n_filters, 1);
     45    f = (aubio_mel_filter *)argv;
     46   
     47    for(filter = 0; filter < f->n_filters; filter++){
     48        result[filter] = 0.f;
     49        for(n = 0; n < N; n++){
     50            result[filter] += data[n] * f->filters[filter][n];
     51        }
     52        result[filter] = LOG(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]);
     53    }
    6754
    68   /** allocating buffers */
    69   mfcc->in_dct=new_fvec(mfcc->win_s, 1);
    70  
    71   mfcc->fftgrain_dct=new_cvec(n_filters, 1);
    72 
    73   return mfcc;
    74 };
    75 
    76 void del_aubio_mfcc(aubio_mfcc_t *mf){
    77   /** deleting filterbank */
    78   del_aubio_filterbank(mf->fb);
    79   /** deleting mfft object */
    80   del_aubio_mfft(mf->fft_dct);
    81   /** deleting buffers */
    82   del_fvec(mf->in_dct);
    83   del_cvec(mf->fftgrain_dct);
    84  
    85   /** deleting mfcc object */
    86   AUBIO_FREE(mf);
     55    //TODO: check that zero padding
     56    for(n = filter + 1; n < N; n++) result[n] = 0;
     57   
     58    aubio_dct_do(result, f->n_filters, NULL, result, fft_dct, fftgrain_dct);
     59   
     60    return XTRACT_SUCCESS;
    8761}
    8862
    89 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
    90     // compute filterbank
    91     aubio_filterbank_do(mf->fb, in, mf->in_dct);
    92     //TODO: check that zero padding
    93     // the following line seems useless since the in_dct buffer has the correct size
    94     //for(n = filter + 1; n < N; n++) result[n] = 0;
     63// Added last two arguments to be able to pass from example
     64
     65int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
    9566   
    96     aubio_dct_do(mf, mf->in_dct, out);
     67   
     68    //call aubio p_voc in dct setting
    9769
    98     return;
     70    //TODO: fvec as input? Remove data length, N?
     71
     72    fvec_t * momo = new_fvec(20, 1);
     73    momo->data = data;
     74   
     75    //compute mag spectrum
     76    aubio_mfft_do (fft_dct, data, fftgrain_dct);
     77
     78    int i;
     79    //extract real part of fft grain
     80    for(i=0; i<N ;i++){
     81      result[i]= fftgrain_dct->norm[0][i]*COS(fftgrain_dct->phas[0][i]);
     82    }
     83
     84
     85    return XTRACT_SUCCESS;
    9986}
    100 
    101 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){
    102     uint_t i;
    103     //compute mag spectrum
    104     aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
    105     //extract real part of fft grain
    106     for(i=0; i<mf->n_coefs ;i++){
    107     //for(i=0; i<out->length;i++){
    108       out->data[0][i]= mf->fftgrain_dct->norm[0][i]
    109         *COS(mf->fftgrain_dct->phas[0][i]);
    110     }
    111     return;
    112 }
    113 
  • src/mfcc.h

    r7a46bf6 r7c6c806d  
    11/*
    2    Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
    3                   and Paul Brossier <piem@piem.org>
     2   Copyright (C) 2006 Amaury Hazan
     3   Ported to aubio from LibXtract
     4   http://libxtract.sourceforge.net/
     5   
    46
    57   This program is free software; you can redistribute it and/or modify
     
    1921*/
    2022
    21 /* part of this mfcc implementation were inspired from LibXtract
    22    http://libxtract.sourceforge.net/
    23 */
    24 
    2523#ifndef MFCC_H
    2624#define MFCC_H
     
    3028#endif
    3129
    32 #include "sample.h"
    3330#include "filterbank.h"
    3431
    35 typedef struct aubio_mfcc_t_ aubio_mfcc_t;
     32//libXtract constants and enums
     33// TODO: remove them
    3634
    37 /** create mfcc object
     35#define XTRACT_SQ(a) ((a) * (a))
     36#define XTRACT_MIN(a, b) ((a) < (b) ? (a) : (b))
     37#define XTRACT_MAX(a, b) ((a) > (b) ? (a) : (b))
     38#define XTRACT_NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n")
     39#define XTRACT_VERY_SMALL_NUMBER 2e-42
     40#define XTRACT_LOG_LIMIT XTRACT_VERY_SMALL_NUMBER
     41#define XTRACT_LOG_LIMIT_DB -96.0
     42#define XTRACT_DB_SCALE_OFFSET 96.0
     43#define XTRACT_VERY_BIG_NUMBER 2e42
     44#define XTRACT_SR_UPPER_LIMIT 192000.0
     45#define XTRACT_SR_LOWER_LIMIT 22050.0
     46#define XTRACT_SR_DEFAULT 44100.0
     47#define XTRACT_FUNDAMENTAL_DEFAULT 440.0
     48#define XTRACT_CHECK_nyquist if(!nyquist) nyquist = XTRACT_SR_DEFAULT / 2
     49#define XTRACT_CHECK_q if(!q) q = XTRACT_SR_DEFAULT / N
     50#define XTRACT_IS_ODD(x) (x % 2 != 0 ? 1 : 0)
     51#define XTRACT_SR_LIMIT SR_UPPER_LIMIT
     52#define XTRACT_FFT_BANDS_MIN 16
     53#define XTRACT_FFT_BANDS_MAX 65536
     54#define XTRACT_FFT_BANDS_DEF 1024
     55#define XTRACT_SPEC_BW_MIN 0.168 /* Minimum spectral bandwidth \
     56            (= SR_LOWER_LIMIT / FFT_BANDS_MAX*/
     57#define XTRACT_SPEC_BW_MAX 12000.0 /* SR_UPPER_LIMIT / FFT_BANDS_MIN */
     58#define XTRACT_SPEC_BW_DEF 43.066 /* SR_DEFAULT / FFT_BANDS_DEF */
    3859
    39   \param win_s size of analysis buffer (and length the FFT transform)
    40   \param samplerate
    41   \param n_coefs: number of desired coefs
    42   \param lowfreq: lowest frequency to use in filterbank
    43   \param highfreq highest frequency to use in filterbank
    44   \param channels number of channels
     60/** \brief Enumeration of feature initialisation functions */
     61enum xtract_feature_init_ {
     62    XTRACT_INIT_MFCC = 100,
     63    XTRACT_INIT_BARK
     64};
    4565
    46 */
    47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
    48 /** delete mfcc object
     66/** \brief Enumeration of feature types */
     67enum xtract_feature_types_ {
     68    XTRACT_SCALAR,
     69    XTRACT_VECTOR,
     70    XTRACT_DELTA
     71};
    4972
    50   \param mf mfcc object as returned by new_aubio_mfcc
     73/** \brief Enumeration of mfcc types */
     74enum xtract_mfcc_types_ {
     75    XTRACT_EQUAL_GAIN,
     76    XTRACT_EQUAL_AREA
     77};
    5178
    52 */
    53 void del_aubio_mfcc(aubio_mfcc_t *mf);
    54 /** mfcc object processing
     79/** \brief Enumeration of return codes */
     80enum xtract_return_codes_ {
     81    XTRACT_SUCCESS,
     82    XTRACT_MALLOC_FAILED,
     83    XTRACT_BAD_ARGV,
     84    XTRACT_BAD_VECTOR_SIZE,
     85    XTRACT_NO_RESULT,
     86    XTRACT_FEATURE_NOT_IMPLEMENTED
     87};
    5588
    56   \param mf mfcc object as returned by new_aubio_mfcc
    57   \param in input spectrum (win_s long)
    58   \param out output mel coefficients buffer (n_filters/2 +1 long)
     89/** \brief Enumeration of spectrum types */
     90enum xtract_spectrum_ {
     91    XTRACT_MAGNITUDE_SPECTRUM,
     92    XTRACT_LOG_MAGNITUDE_SPECTRUM,
     93    XTRACT_POWER_SPECTRUM,
     94    XTRACT_LOG_POWER_SPECTRUM
     95};
    5996
    60 */
    61 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out);
     97/** \brief Enumeration of data types*/
     98typedef enum type_ {
     99    XTRACT_FLOAT,
     100    XTRACT_FLOATARRAY,
     101    XTRACT_INT,
     102    XTRACT_MEL_FILTER
     103} xtract_type_t;
    62104
    63 /** intermediate dct involved in aubio_mfcc_do
     105/** \brief Enumeration of units*/
     106typedef enum unit_ {
     107    /* NONE, ANY */
     108    XTRACT_HERTZ = 2,
     109    XTRACT_ANY_AMPLITUDE_HERTZ,
     110    XTRACT_DBFS,
     111    XTRACT_DBFS_HERTZ,
     112    XTRACT_PERCENT,
     113    XTRACT_SONE
     114} xtract_unit_t;
    64115
    65   \param mf mfcc object as returned by new_aubio_mfcc
    66   \param in input spectrum (n_filters long)
    67   \param out output mel coefficients buffer (n_filters/2 +1 long)
     116/** \brief Boolean */
     117typedef enum {
     118    XTRACT_FALSE,
     119    XTRACT_TRUE
     120} xtract_bool_t;
    68121
    69 */
    70 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
     122/** \brief Enumeration of vector format types*/
     123typedef enum xtract_vector_ {
     124    /* N/2 magnitude/log-magnitude/power/log-power coeffs and N/2 frequencies */
     125    XTRACT_SPECTRAL,     
     126    /* N spectral amplitudes */
     127    XTRACT_SPECTRAL_MAGNITUDES,
     128    /* N/2 magnitude/log-magnitude/power/log-power peak coeffs and N/2
     129     * frequencies */
     130    XTRACT_SPECTRAL_PEAKS,
     131    /* N spectral peak amplitudes */
     132    XTRACT_SPECTRAL_PEAKS_MAGNITUDES,
     133    /* N spectral peak frequencies */
     134    XTRACT_SPECTRAL_PEAKS_FREQUENCIES,
     135    /* N/2 magnitude/log-magnitude/power/log-power harmonic peak coeffs and N/2
     136     * frequencies */
     137    XTRACT_SPECTRAL_HARMONICS,
     138    /* N spectral harmonic amplitudes */
     139    XTRACT_SPECTRAL_HARMONICS_MAGNITUDES,
     140    /* N spectral harmonic frequencies */
     141    XTRACT_SPECTRAL_HARMONICS_FREQUENCIES,
     142    XTRACT_ARBITRARY_SERIES,
     143    XTRACT_AUDIO_SAMPLES,
     144    XTRACT_MEL_COEFFS,
     145    XTRACT_BARK_COEFFS,
     146    XTRACT_NO_DATA
     147} xtract_vector_t;
     148
     149
     150
     151
     152// Computation
     153
     154/** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner
     155 *
     156 * \param *data: a pointer to the first element in an array of spectral magnitudes, e.g. the first half of the array pointed to by *resul from xtract_spectrum()
     157 * \param N: the number of array elements to be considered
     158 * \param *argv: a pointer to a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank
     159 * \param *result: a pointer to an array containing the resultant MFCC
     160 *
     161 * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc
     162 */
     163
     164
     165int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
     166
     167/** \brief Extract the Discrete Cosine transform of a time domain signal
     168 * \param *data: a pointer to the first element in an array of floats representing an audio vector
     169 * \param N: the number of array elements to be considered
     170 * \param *argv: a pointer to NULL
     171 * \param *result: a pointer to an array containing resultant dct coefficients
     172 */
     173int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
    71174
    72175#ifdef __cplusplus
     
    74177#endif
    75178
    76 #endif // MFCC_H
     179#endif
  • src/tempo.c

    r7a46bf6 r7c6c806d  
    124124}
    125125
    126 smpl_t aubio_tempo_get_bpm(aubio_tempo_t *o) {
    127   return aubio_beattracking_get_bpm(o->bt);
    128 }
    129 
    130126void del_aubio_tempo (aubio_tempo_t *o)
    131127{
  • src/tempo.h

    r7a46bf6 r7c6c806d  
    5050void aubio_tempo_set_threshold(aubio_tempo_t * o, smpl_t threshold);
    5151
    52 /** get current tempo
    53 
    54   \param bt beat tracking object
    55 
    56   Returns the currently observed tempo, or 0 if no consistent value is found
    57 
    58 */
    59 smpl_t aubio_tempo_get_bpm(aubio_tempo_t * bt);
    60 
    6152/** delete tempo detection object */
    6253void del_aubio_tempo(aubio_tempo_t * o);
Note: See TracChangeset for help on using the changeset viewer.