[88199ce] | 1 | /* |
---|
[53a7576] | 2 | Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu> |
---|
| 3 | and Paul Brossier <piem@piem.org> |
---|
[88199ce] | 4 | |
---|
| 5 | This program is free software; you can redistribute it and/or modify |
---|
| 6 | it under the terms of the GNU General Public License as published by |
---|
| 7 | the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | (at your option) any later version. |
---|
| 9 | |
---|
| 10 | This program is distributed in the hope that it will be useful, |
---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | GNU General Public License for more details. |
---|
| 14 | |
---|
| 15 | You should have received a copy of the GNU General Public License |
---|
| 16 | along with this program; if not, write to the Free Software |
---|
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include "utils.h" |
---|
| 21 | |
---|
[3e7c408] | 22 | /* mfcc objects */ |
---|
[2a77ff0] | 23 | fvec_t * mfcc_out; |
---|
[3e7c408] | 24 | aubio_mfcc_t * mfcc; |
---|
| 25 | |
---|
[88199ce] | 26 | unsigned int pos = 0; /*frames%dspblocksize*/ |
---|
| 27 | uint_t usepitch = 0; |
---|
| 28 | |
---|
| 29 | int aubio_process(float **input, float **output, int nframes); |
---|
| 30 | int aubio_process(float **input, float **output, int nframes) { |
---|
| 31 | unsigned int i; /*channels*/ |
---|
| 32 | unsigned int j; /*frames*/ |
---|
[dcc649c] | 33 | |
---|
[88199ce] | 34 | for (j=0;j<(unsigned)nframes;j++) { |
---|
| 35 | if(usejack) { |
---|
| 36 | for (i=0;i<channels;i++) { |
---|
| 37 | /* write input to datanew */ |
---|
| 38 | fvec_write_sample(ibuf, input[i][j], i, pos); |
---|
| 39 | /* put synthnew in output */ |
---|
| 40 | output[i][j] = fvec_read_sample(obuf, i, pos); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | /*time for fft*/ |
---|
| 44 | if (pos == overlap_size-1) { |
---|
| 45 | /* block loop */ |
---|
| 46 | |
---|
| 47 | //compute mag spectrum |
---|
| 48 | aubio_pvoc_do (pv,ibuf, fftgrain); |
---|
[71d3bf0] | 49 | |
---|
[88199ce] | 50 | //compute mfccs |
---|
[2a77ff0] | 51 | aubio_mfcc_do(mfcc, fftgrain, mfcc_out); |
---|
[88199ce] | 52 | |
---|
| 53 | /* end of block loop */ |
---|
| 54 | pos = -1; /* so it will be zero next j loop */ |
---|
| 55 | } |
---|
| 56 | pos++; |
---|
| 57 | } |
---|
| 58 | return 1; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void process_print (void); |
---|
| 62 | void process_print (void) { |
---|
| 63 | /* output times in seconds |
---|
| 64 | write extracted mfccs |
---|
| 65 | */ |
---|
| 66 | |
---|
[2a77ff0] | 67 | uint_t filter_cnt; |
---|
[88199ce] | 68 | if (output_filename == NULL) { |
---|
| 69 | if(frames >= 4) { |
---|
[2a77ff0] | 70 | outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate); |
---|
[88199ce] | 71 | } else if (frames < 4) { |
---|
[2a77ff0] | 72 | outmsg("%f\t",0.); |
---|
[88199ce] | 73 | } |
---|
[2a77ff0] | 74 | outmsg("%f",mfcc_out->data[0][0]); |
---|
| 75 | for (filter_cnt = 1; filter_cnt < mfcc_out->length; filter_cnt++) { |
---|
| 76 | outmsg(",%f",mfcc_out->data[0][filter_cnt]); |
---|
| 77 | } |
---|
| 78 | outmsg("\n"); |
---|
[88199ce] | 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | int main(int argc, char **argv) { |
---|
[3e7c408] | 83 | // params |
---|
| 84 | uint_t n_filters = 11; |
---|
[88199ce] | 85 | examples_common_init(argc,argv); |
---|
[38837b1] | 86 | smpl_t lowfreq = 0.; |
---|
| 87 | smpl_t highfreq = samplerate; |
---|
[2a77ff0] | 88 | mfcc_out = new_fvec(n_filters,channels); |
---|
[fe28ff3] | 89 | |
---|
| 90 | //populating the filter |
---|
[3e7c408] | 91 | mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq, |
---|
| 92 | channels); |
---|
[fe28ff3] | 93 | |
---|
| 94 | //process |
---|
[88199ce] | 95 | examples_common_process(aubio_process,process_print); |
---|
[fe28ff3] | 96 | |
---|
[3e7c408] | 97 | //destroying mfcc |
---|
| 98 | del_aubio_mfcc(mfcc); |
---|
[2a77ff0] | 99 | del_fvec(mfcc_out); |
---|
[38837b1] | 100 | |
---|
| 101 | examples_common_del(); |
---|
| 102 | debug("End of program.\n"); |
---|
| 103 | fflush(stderr); |
---|
[fe28ff3] | 104 | |
---|
[88199ce] | 105 | return 0; |
---|
| 106 | } |
---|
| 107 | |
---|