source: examples/aubiomfcc.c @ 2a77ff0

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 2a77ff0 was 2a77ff0, checked in by Paul Brossier <piem@piem.org>, 13 years ago

aubiomfcc.c: prepare text output, rename output buffer to mfcc_out

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
21/* mfcc objects */
22fvec_t * mfcc_out;
23aubio_mfcc_t * mfcc;
24
25unsigned int pos = 0; /*frames%dspblocksize*/
26uint_t usepitch = 0;
27
28int aubio_process(float **input, float **output, int nframes);
29int aubio_process(float **input, float **output, int nframes) {
30  unsigned int i;       /*channels*/
31  unsigned int j;       /*frames*/
32 
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);
48     
49      //compute mfccs
50      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
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
60void process_print (void);
61void process_print (void) {
62      /* output times in seconds
63         write extracted mfccs
64      */
65     
66      uint_t filter_cnt;
67      if (output_filename == NULL) {
68        if(frames >= 4) {
69          outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate);
70        } else if (frames < 4) {
71          outmsg("%f\t",0.);
72        }
73        outmsg("%f",mfcc_out->data[0][0]);
74        for (filter_cnt = 1; filter_cnt < mfcc_out->length; filter_cnt++) {
75          outmsg(",%f",mfcc_out->data[0][filter_cnt]);
76        }
77        outmsg("\n");
78      }
79}
80
81int main(int argc, char **argv) {
82  // params
83  uint_t n_filters = 11;
84  smpl_t lowfreq = 500.;
85  smpl_t highfreq = 2000.;
86  examples_common_init(argc,argv);
87  mfcc_out = new_fvec(n_filters,channels);
88 
89  //populating the filter
90  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq,
91      channels);
92
93  //process
94  examples_common_process(aubio_process,process_print);
95  examples_common_del();
96  debug("End of program.\n");
97  fflush(stderr);
98 
99  //destroying mfcc
100  del_aubio_mfcc(mfcc);
101  del_fvec(mfcc_out);
102 
103  return 0;
104}
105
Note: See TracBrowser for help on using the repository browser.