source: examples/aubiomfcc.c @ 3e7c408

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

utils.c, utils.h: remove mfcc, move to aubiomfcc.c

  • Property mode set to 100644
File size: 2.6 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_outbuf;
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_outbuf);
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      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
75int main(int argc, char **argv) {
76  // params
77  uint_t n_filters = 11;
78  smpl_t lowfreq = 500.;
79  smpl_t highfreq = 2000.;
80  examples_common_init(argc,argv);
81  mfcc_outbuf = new_fvec(n_filters,channels);
82 
83  //populating the filter
84  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq,
85      channels);
86
87  //process
88  examples_common_process(aubio_process,process_print);
89  examples_common_del();
90  debug("End of program.\n");
91  fflush(stderr);
92 
93  //destroying mfcc
94  del_aubio_mfcc(mfcc);
95  del_fvec(mfcc_outbuf);
96 
97  return 0;
98}
99
Note: See TracBrowser for help on using the repository browser.