Changes in / [7c6c806d:7a46bf6]


Ignore:
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • examples/Makefile.am

    r7c6c806d r7a46bf6  
    1111        aubioonset \
    1212        aubiotrack \
    13         aubionotes
     13        aubionotes \
     14        aubiomfcc
    1415
    1516noinst_PROGRAMS = \
     
    2324aubiotrack_SOURCES = aubiotrack.c utils.c
    2425aubioquiet_SOURCES = aubioquiet.c utils.c
     26aubiomfcc_SOURCES = aubiomfcc.c utils.c
    2527
    2628aubioonset_LDADD = @JACK_LIBS@
     
    2830aubiotrack_LDADD = @JACK_LIBS@
    2931aubioquiet_LDADD = @JACK_LIBS@
     32aubiomfcc_LDADD = @JACK_LIBS@
  • examples/aubiomfcc.c

    r7c6c806d r7a46bf6  
    11/*
    2    Copyright (C) 2007 Amaury Hazan
     2   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
     3                  and Paul Brossier <piem@piem.org>
    34
    45   This program is free software; you can redistribute it and/or modify
     
    1819
    1920#include "utils.h"
     21
     22/* mfcc objects */
     23fvec_t * mfcc_out;
     24aubio_mfcc_t * mfcc;
     25
     26uint_t n_filters = 20;
     27uint_t n_coefs = 11;
    2028
    2129unsigned int pos = 0; /*frames%dspblocksize*/
     
    4351      aubio_pvoc_do (pv,ibuf, fftgrain);
    4452     
    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        
    5253      //compute mfccs
    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      
     54      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
    6055
    6156      /* end of block loop */
     
    7368      */
    7469     
     70      uint_t coef_cnt;
    7571      if (output_filename == NULL) {
    76         if(frames >= 4) {
    77           outmsg("%f\n",(frames-4)*overlap_size/(float)samplerate);
    78         } else if (frames < 4) {
    79           outmsg("%f\n",0.);
     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]);
    8082        }
     83        outmsg("\n");/*/
    8184      }
    8285}
    8386
    8487int main(int argc, char **argv) {
     88  // params
     89  //uint_t n_filters = 40;
     90  //uint_t n_coefs = 15;
     91
    8592  examples_common_init(argc,argv);
    86  
    87   //allocate and initialize mel filter bank
    88  
    89 
    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));
     93  smpl_t lowfreq = 133.333f;
     94  smpl_t highfreq = 44100.f;
     95  mfcc_out = new_fvec(n_coefs,channels);
    9896 
    9997  //populating the filter
    100   aubio_mfcc_init(buffer_size, nyquist, XTRACT_EQUAL_GAIN, lowfreq, highfreq, mf->n_filters, mf->filters);
     98  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs , lowfreq, highfreq, channels);
    10199
    102100  //process
    103101  examples_common_process(aubio_process,process_print);
     102 
     103  //destroying mfcc
     104  del_aubio_mfcc(mfcc);
     105  del_fvec(mfcc_out);
     106
    104107  examples_common_del();
    105108  debug("End of program.\n");
    106109  fflush(stderr);
    107110 
    108   //destroying filterbank
    109   free(mf);
    110  
    111111  return 0;
    112112}
  • examples/tests/test-beattracking.c

    r7c6c806d r7a46bf6  
    1313        uint_t i = 0;
    1414
     15        smpl_t curtempo;
     16
    1517        while (i < 10) {
    1618          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          }
    1724          i++;
    1825        };
  • examples/tests/test-tempo.c

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

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

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

    r7c6c806d r7a46bf6  
    2323        tempo.h \
    2424        filter.h \
     25        filterbank.h \
    2526        mfcc.h
    2627
     
    7273        filter.c \
    7374        filter.h \
     75        filterbank.c \
     76        filterbank.h \
    7477        mfcc.h \
    7578        mfcc.c
  • src/aubio.h

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

    r7c6c806d r7a46bf6  
    453453
    454454}
     455
     456smpl_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

    r7c6c806d r7a46bf6  
    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*/
     70smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);
    6271/** delete beat tracking object
    6372
  • src/filterbank.c

    r7c6c806d r7a46bf6  
    11/*
    2    Copyright (C) 2007 Amaury Hazan
    3    Ported to aubio from LibXtract
    4    http://libxtract.sourceforge.net/
    5    
     2   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
     3                  and Paul Brossier <piem@piem.org>
    64
    75   This program is free software; you can redistribute it and/or modify
     
    2119*/
    2220
     21/* part of this mfcc implementation were inspired from LibXtract
     22   http://libxtract.sourceforge.net/
     23*/
     24
    2325#include "aubio_priv.h"
     26#include "sample.h"
    2427#include "filterbank.h"
    2528
    26 
    27 // Struct Declaration
    28 
    29 /** \brief A structure to store a set of n_filters Mel filters */
    30 typedef struct aubio_mel_filter_ {
    31     int n_filters;
    32     smpl_t **filters;
     29#include "stdio.h"
     30
     31#define USE_EQUAL_GAIN 1
     32#define VERY_SMALL_NUMBER 2e-42
     33
     34/** \brief A structure to store a set of n_filters filters of lenghts win_s */
     35struct aubio_filterbank_t_ {
     36    uint_t win_s;
     37    uint_t n_filters;
     38    fvec_t **filters;
    3339};
    3440
    35 // Initialization
    36 
    37 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){
    38 
    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;
    42 
    43     mel_peak = height_norm = lin_peak = NULL;
    44     fft_peak = NULL;
    45     norm = 1;
    46 
    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;
    50 
    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));
    56 
    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;
    62 
    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;
    66 
    67 
    68     for (n = 1; n <= freq_bands; n++){ 
     41aubio_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;
     47
     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);
     53
     54  return fb;
     55}
     56
     57aubio_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;
     60
     61  FILE * mlog;
     62  if(writelog==1) mlog=fopen("filterbank.txt","w");
     63 
     64
     65  smpl_t nyquist = samplerate/2.;
     66  uint_t style = 1;
     67  aubio_filterbank_t * fb = new_aubio_filterbank(n_filters, win_s);
     68
     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;
     72
     73  mel_peak = height_norm = lin_peak = NULL;
     74  fft_peak = NULL;
     75  norm = 1;
     76
     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;
     80
     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++){ 
    6998    /*roll out peak locations - mel, linear and linear on fft window scale */
    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;
    73     }
    74 
    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;
    86     }
    87 
    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         }
    120 
    121   /*zero the rest of the array*/
    122   for(k = next_peak + 1; k < N; k++)
    123       fft_tables[n][k] = 0.f;
    124     }
    125 
    126     free(mel_peak);
    127     free(lin_peak);
    128     free(height_norm);
    129     free(fft_peak);
    130 
    131     return XTRACT_SUCCESS;
    132 
    133 }
     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;
     136    }
     137
     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;
     148    }
     149
     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;
     153
     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");
     161    }
     162
     163  }
     164
     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;
     173
     174}
     175
     176
     177void 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
     186void 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

    r7c6c806d r7a46bf6  
    11/*
    2    Copyright (C) 2007 Amaury Hazan
    3    Ported to aubio from LibXtract
    4    http://libxtract.sourceforge.net/
    5    
     2   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
     3                  and Paul Brossier <piem@piem.org>
    64
    75   This program is free software; you can redistribute it and/or modify
     
    2018*/
    2119
    22 #ifndef AUBIOFILTERBANK_H
    23 #define AUBIOFILTERBANK_H
     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
    2430
    2531#ifdef __cplusplus
     
    2733#endif
    2834
     35typedef 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
     44aubio_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*/
     54aubio_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);
    2955
    3056
    31 typedef struct aubio_mel_filter_ aubio_mel_filter;
     57/** destroy filterbank object
    3258
    33 // Initialization
     59  \param fb filterbank, as returned by new_aubio_filterbank method
    3460
    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  */
    39 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);
     61*/
     62void del_aubio_filterbank(aubio_filterbank_t * fb);
     63
     64/** compute filterbank
     65
     66*/
     67void aubio_filterbank_do(aubio_filterbank_t * fb, cvec_t * in, fvec_t *out);
    4068
    4169#ifdef __cplusplus
     
    4371#endif
    4472
    45 #endif
     73#endif // FILTERBANK_H
  • src/mfcc.c

    r7c6c806d r7a46bf6  
    2424#include "sample.h"
    2525#include "fft.h"
     26#include "filterbank.h"
    2627#include "mfcc.h"
    2728#include "math.h"
    2829
    29 /*
    30 new_aubio_mfcc
    31 aubio_mfcc_do
    32 del_aubio_mfcc
    33 */
     30/** Internal structure for mfcc object **/
    3431
    35 // Computation
    36 // Added last two arguments to be able to pass from example
     32struct 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};
    3745
    3846
     47aubio_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);
    3950
    40 int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
     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;
    4161
    42     aubio_mel_filter *f;
    43     int n, filter;
     62  /** filterbank allocation */
     63  mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
    4464
    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     }
     65  /** allocating space for fft object (used for dct) */
     66  mfcc->fft_dct=new_aubio_mfft(n_filters, 1);
    5467
    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;
     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
     76void 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);
    6187}
    6288
    63 // Added last two arguments to be able to pass from example
     89void 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;
     95   
     96    aubio_dct_do(mf, mf->in_dct, out);
    6497
    65 int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
    66    
    67    
    68     //call aubio p_voc in dct setting
     98    return;
     99}
    69100
    70     //TODO: fvec as input? Remove data length, N?
     101void 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}
    71113
    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;
    86 }
  • src/mfcc.h

    r7c6c806d r7a46bf6  
    11/*
    2    Copyright (C) 2006 Amaury Hazan
    3    Ported to aubio from LibXtract
    4    http://libxtract.sourceforge.net/
    5    
     2   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
     3                  and Paul Brossier <piem@piem.org>
    64
    75   This program is free software; you can redistribute it and/or modify
     
    2119*/
    2220
     21/* part of this mfcc implementation were inspired from LibXtract
     22   http://libxtract.sourceforge.net/
     23*/
     24
    2325#ifndef MFCC_H
    2426#define MFCC_H
     
    2830#endif
    2931
     32#include "sample.h"
    3033#include "filterbank.h"
    3134
    32 //libXtract constants and enums
    33 // TODO: remove them
     35typedef struct aubio_mfcc_t_ aubio_mfcc_t;
    3436
    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 */
     37/** create mfcc object
    5938
    60 /** \brief Enumeration of feature initialisation functions */
    61 enum xtract_feature_init_ {
    62     XTRACT_INIT_MFCC = 100,
    63     XTRACT_INIT_BARK
    64 };
     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
    6545
    66 /** \brief Enumeration of feature types */
    67 enum xtract_feature_types_ {
    68     XTRACT_SCALAR,
    69     XTRACT_VECTOR,
    70     XTRACT_DELTA
    71 };
     46*/
     47aubio_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
    7249
    73 /** \brief Enumeration of mfcc types */
    74 enum xtract_mfcc_types_ {
    75     XTRACT_EQUAL_GAIN,
    76     XTRACT_EQUAL_AREA
    77 };
     50  \param mf mfcc object as returned by new_aubio_mfcc
    7851
    79 /** \brief Enumeration of return codes */
    80 enum 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 };
     52*/
     53void del_aubio_mfcc(aubio_mfcc_t *mf);
     54/** mfcc object processing
    8855
    89 /** \brief Enumeration of spectrum types */
    90 enum xtract_spectrum_ {
    91     XTRACT_MAGNITUDE_SPECTRUM,
    92     XTRACT_LOG_MAGNITUDE_SPECTRUM,
    93     XTRACT_POWER_SPECTRUM,
    94     XTRACT_LOG_POWER_SPECTRUM
    95 };
     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)
    9659
    97 /** \brief Enumeration of data types*/
    98 typedef enum type_ {
    99     XTRACT_FLOAT,
    100     XTRACT_FLOATARRAY,
    101     XTRACT_INT,
    102     XTRACT_MEL_FILTER
    103 } xtract_type_t;
     60*/
     61void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out);
    10462
    105 /** \brief Enumeration of units*/
    106 typedef 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;
     63/** intermediate dct involved in aubio_mfcc_do
    11564
    116 /** \brief Boolean */
    117 typedef enum {
    118     XTRACT_FALSE,
    119     XTRACT_TRUE
    120 } xtract_bool_t;
     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)
    12168
    122 /** \brief Enumeration of vector format types*/
    123 typedef 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 
    165 int 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  */
    173 int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
     69*/
     70void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
    17471
    17572#ifdef __cplusplus
     
    17774#endif
    17875
    179 #endif
     76#endif // MFCC_H
  • src/tempo.c

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

    r7c6c806d r7a46bf6  
    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*/
     59smpl_t aubio_tempo_get_bpm(aubio_tempo_t * bt);
     60
    5261/** delete tempo detection object */
    5362void del_aubio_tempo(aubio_tempo_t * o);
Note: See TracChangeset for help on using the changeset viewer.