Changes in / [7a46bf6:7c6c806d]
- Files:
-
- 2 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified examples/Makefile.am ¶
r7a46bf6 r7c6c806d 11 11 aubioonset \ 12 12 aubiotrack \ 13 aubionotes \ 14 aubiomfcc 13 aubionotes 15 14 16 15 noinst_PROGRAMS = \ … … 24 23 aubiotrack_SOURCES = aubiotrack.c utils.c 25 24 aubioquiet_SOURCES = aubioquiet.c utils.c 26 aubiomfcc_SOURCES = aubiomfcc.c utils.c27 25 28 26 aubioonset_LDADD = @JACK_LIBS@ … … 30 28 aubiotrack_LDADD = @JACK_LIBS@ 31 29 aubioquiet_LDADD = @JACK_LIBS@ 32 aubiomfcc_LDADD = @JACK_LIBS@ -
TabularUnified examples/aubiomfcc.c ¶
r7a46bf6 r7c6c806d 1 1 /* 2 Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu> 3 and Paul Brossier <piem@piem.org> 2 Copyright (C) 2007 Amaury Hazan 4 3 5 4 This program is free software; you can redistribute it and/or modify … … 19 18 20 19 #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;28 20 29 21 unsigned int pos = 0; /*frames%dspblocksize*/ … … 51 43 aubio_pvoc_do (pv,ibuf, fftgrain); 52 44 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 53 52 //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 55 60 56 61 /* end of block loop */ … … 68 73 */ 69 74 70 uint_t coef_cnt;71 75 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.); 82 80 } 83 outmsg("\n");/*/84 81 } 85 82 } 86 83 87 84 int 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 91 89 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)); 96 98 97 99 //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); 99 101 100 102 //process 101 103 examples_common_process(aubio_process,process_print); 102 103 //destroying mfcc104 del_aubio_mfcc(mfcc);105 del_fvec(mfcc_out);106 107 104 examples_common_del(); 108 105 debug("End of program.\n"); 109 106 fflush(stderr); 110 107 108 //destroying filterbank 109 free(mf); 110 111 111 return 0; 112 112 } -
TabularUnified examples/tests/test-beattracking.c ¶
r7a46bf6 r7c6c806d 13 13 uint_t i = 0; 14 14 15 smpl_t curtempo;16 17 15 while (i < 10) { 18 16 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 }24 17 i++; 25 18 }; -
TabularUnified examples/tests/test-tempo.c ¶
r7a46bf6 r7c6c806d 10 10 uint_t i = 0; 11 11 12 smpl_t curtempo;13 14 12 while (i < 1000) { 15 13 aubio_tempo(o,in,out); 16 curtempo = aubio_tempo_get_bpm(o);17 if (curtempo != 0.) {18 fprintf(stdout,"%f\n",curtempo);19 }20 14 i++; 21 15 }; -
TabularUnified examples/utils.c ¶
r7a46bf6 r7c6c806d 60 60 int isonset = 0; 61 61 aubio_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 62 77 63 78 /* pitch objects */ … … 300 315 fftgrain = new_cvec(buffer_size, channels); 301 316 302 317 //init for mfcc process 318 fftgrain_dct= new_cvec(n_filters, channels); 319 303 320 if (usepitch) { 304 321 pitchdet = new_aubio_pitchdetection(buffer_size*4, … … 314 331 pv = new_aubio_pvoc(buffer_size, overlap_size, channels); 315 332 333 // dct phase vocoder 334 //TODO: check size 335 fft_dct = new_aubio_mfft(n_filters, channels); 336 316 337 /* onsets */ 317 338 parms = new_aubio_peakpicker(threshold); … … 347 368 del_fvec(onset); 348 369 del_fvec(woodblock); 370 371 //mffc related 372 del_aubio_mfft(fft_dct); 373 del_cvec(fftgrain_dct); 349 374 350 375 aubio_cleanup(); -
TabularUnified examples/utils.h ¶
r7a46bf6 r7c6c806d 98 98 extern aubio_pickpeak_t * parms; 99 99 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 100 113 /* pitch objects */ 101 114 extern smpl_t pitch; -
TabularUnified src/Makefile.am ¶
r7a46bf6 r7c6c806d 23 23 tempo.h \ 24 24 filter.h \ 25 filterbank.h \26 25 mfcc.h 27 26 … … 73 72 filter.c \ 74 73 filter.h \ 75 filterbank.c \76 filterbank.h \77 74 mfcc.h \ 78 75 mfcc.c -
TabularUnified src/aubio.h ¶
r7a46bf6 r7c6c806d 80 80 #include "onset.h" 81 81 #include "tempo.h" 82 #include "filterbank.h"83 82 #include "mfcc.h" 84 83 -
TabularUnified src/beattracking.c ¶
r7a46bf6 r7c6c806d 453 453 454 454 } 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 } -
TabularUnified src/beattracking.h ¶
r7a46bf6 r7c6c806d 60 60 */ 61 61 void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframes, fvec_t * out); 62 /** get current tempo in bpm63 64 \param bt beat tracking object65 66 Returns the currently observed tempo, in beats per minutes, or 0 if no67 consistent value is found.68 69 */70 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);71 62 /** delete beat tracking object 72 63 -
TabularUnified src/filterbank.c ¶
r7a46bf6 r7c6c806d 1 1 /* 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 4 6 5 7 This program is free software; you can redistribute it and/or modify … … 19 21 */ 20 22 21 /* part of this mfcc implementation were inspired from LibXtract22 http://libxtract.sourceforge.net/23 */24 25 23 #include "aubio_priv.h" 26 #include "sample.h"27 24 #include "filterbank.h" 28 25 29 #include "stdio.h"30 26 31 #define USE_EQUAL_GAIN 1 32 #define VERY_SMALL_NUMBER 2e-42 27 // Struct Declaration 33 28 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 */ 30 typedef struct aubio_mel_filter_ { 31 int n_filters; 32 smpl_t **filters; 39 33 }; 40 34 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 47 36 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); 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){ 53 38 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; 56 42 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; 60 46 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; 64 50 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)); 68 56 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; 72 62 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; 76 66 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 67 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++){ 98 69 /*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; 136 73 } 137 74 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; 148 86 } 149 87 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 } 153 120 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; 161 124 } 162 125 163 } 126 free(mel_peak); 127 free(lin_peak); 128 free(height_norm); 129 free(fft_peak); 164 130 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; 173 132 174 133 } 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 } -
TabularUnified src/filterbank.h ¶
r7a46bf6 r7c6c806d 1 1 /* 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 4 6 5 7 This program is free software; you can redistribute it and/or modify … … 18 20 */ 19 21 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 30 24 31 25 #ifdef __cplusplus … … 33 27 #endif 34 28 35 typedef struct aubio_filterbank_t_ aubio_filterbank_t;36 37 /** create filterbank object38 39 \param win_s size of analysis buffer (and length the FFT transform)40 \param n_filters number of filters to create41 42 */43 44 aubio_filterbank_t * new_aubio_filterbank(uint_t n_filters, uint_t win_s);45 46 /** filterbank initialization for mel filters47 48 \param nyquist nyquist frequency, i.e. half of the sampling rate49 \param style libxtract style50 \param freqmin lowest filter frequency51 \param freqmax highest filter frequency52 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);55 29 56 30 57 /** destroy filterbank object 31 typedef struct aubio_mel_filter_ aubio_mel_filter; 58 32 59 \param fb filterbank, as returned by new_aubio_filterbank method 33 // Initialization 60 34 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 */ 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); 68 40 69 41 #ifdef __cplusplus … … 71 43 #endif 72 44 73 #endif // FILTERBANK_H45 #endif -
TabularUnified src/mfcc.c ¶
r7a46bf6 r7c6c806d 24 24 #include "sample.h" 25 25 #include "fft.h" 26 #include "filterbank.h"27 26 #include "mfcc.h" 28 27 #include "math.h" 29 28 30 /** Internal structure for mfcc object **/ 29 /* 30 new_aubio_mfcc 31 aubio_mfcc_do 32 del_aubio_mfcc 33 */ 31 34 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 45 37 46 38 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);50 39 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; 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){ 61 41 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; 64 44 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 } 67 54 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; 87 61 } 88 62 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 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){ 95 66 96 aubio_dct_do(mf, mf->in_dct, out); 67 68 //call aubio p_voc in dct setting 97 69 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; 99 86 } 100 101 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){102 uint_t i;103 //compute mag spectrum104 aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);105 //extract real part of fft grain106 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 -
TabularUnified src/mfcc.h ¶
r7a46bf6 r7c6c806d 1 1 /* 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 4 6 5 7 This program is free software; you can redistribute it and/or modify … … 19 21 */ 20 22 21 /* part of this mfcc implementation were inspired from LibXtract22 http://libxtract.sourceforge.net/23 */24 25 23 #ifndef MFCC_H 26 24 #define MFCC_H … … 30 28 #endif 31 29 32 #include "sample.h"33 30 #include "filterbank.h" 34 31 35 typedef struct aubio_mfcc_t_ aubio_mfcc_t; 32 //libXtract constants and enums 33 // TODO: remove them 36 34 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 */ 38 59 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 */ 61 enum xtract_feature_init_ { 62 XTRACT_INIT_MFCC = 100, 63 XTRACT_INIT_BARK 64 }; 45 65 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 */ 67 enum xtract_feature_types_ { 68 XTRACT_SCALAR, 69 XTRACT_VECTOR, 70 XTRACT_DELTA 71 }; 49 72 50 \param mf mfcc object as returned by new_aubio_mfcc 73 /** \brief Enumeration of mfcc types */ 74 enum xtract_mfcc_types_ { 75 XTRACT_EQUAL_GAIN, 76 XTRACT_EQUAL_AREA 77 }; 51 78 52 */ 53 void del_aubio_mfcc(aubio_mfcc_t *mf); 54 /** mfcc object processing 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 }; 55 88 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 */ 90 enum xtract_spectrum_ { 91 XTRACT_MAGNITUDE_SPECTRUM, 92 XTRACT_LOG_MAGNITUDE_SPECTRUM, 93 XTRACT_POWER_SPECTRUM, 94 XTRACT_LOG_POWER_SPECTRUM 95 }; 59 96 60 */ 61 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out); 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; 62 104 63 /** intermediate dct involved in aubio_mfcc_do 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; 64 115 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 */ 117 typedef enum { 118 XTRACT_FALSE, 119 XTRACT_TRUE 120 } xtract_bool_t; 68 121 69 */ 70 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out); 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); 71 174 72 175 #ifdef __cplusplus … … 74 177 #endif 75 178 76 #endif // MFCC_H179 #endif -
TabularUnified src/tempo.c ¶
r7a46bf6 r7c6c806d 124 124 } 125 125 126 smpl_t aubio_tempo_get_bpm(aubio_tempo_t *o) {127 return aubio_beattracking_get_bpm(o->bt);128 }129 130 126 void del_aubio_tempo (aubio_tempo_t *o) 131 127 { -
TabularUnified src/tempo.h ¶
r7a46bf6 r7c6c806d 50 50 void aubio_tempo_set_threshold(aubio_tempo_t * o, smpl_t threshold); 51 51 52 /** get current tempo53 54 \param bt beat tracking object55 56 Returns the currently observed tempo, or 0 if no consistent value is found57 58 */59 smpl_t aubio_tempo_get_bpm(aubio_tempo_t * bt);60 61 52 /** delete tempo detection object */ 62 53 void del_aubio_tempo(aubio_tempo_t * o);
Note: See TracChangeset
for help on using the changeset viewer.