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