source: examples/aubiomfcc.c @ 53a7576

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

aubiomfcc.c: update header

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