source: examples/aubiomfcc.c @ f1b6aad

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since f1b6aad was c423c3d, checked in by Paul Brossier <piem@piem.org>, 15 years ago

examples/: use native aubio smpl_t for aubio_process_func_t

  • Property mode set to 100644
File size: 2.7 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
26uint_t n_filters = 40;
27uint_t n_coefs = 13;
28
29unsigned int pos = 0; /*frames%dspblocksize*/
30uint_t usepitch = 0;
31
32int aubio_process(smpl_t **input, smpl_t **output, int nframes);
33int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
34  unsigned int i;       /*channels*/
35  unsigned int j;       /*frames*/
36 
37  for (j=0;j<(unsigned)nframes;j++) {
38    if(usejack) {
39      for (i=0;i<channels;i++) {
40        /* write input to datanew */
41        fvec_write_sample(ibuf, input[i][j], i, pos);
42        /* put synthnew in output */
43        output[i][j] = fvec_read_sample(obuf, i, pos);
44      }
45    }
46    /*time for fft*/
47    if (pos == overlap_size-1) {         
48      /* block loop */
49     
50      //compute mag spectrum
51      aubio_pvoc_do (pv,ibuf, fftgrain);
52     
53      //compute mfccs
54      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
55     
56      /* end of block loop */
57      pos = -1; /* so it will be zero next j loop */
58    }
59    pos++;
60  }
61  return 1;
62}
63
64void process_print (void);
65void process_print (void) {
66      /* output times in seconds
67         write extracted mfccs
68      */
69     
70      uint_t coef_cnt;
71      if (output_filename == NULL) {
72        outmsg("%f\t",frames*overlap_size/(float)samplerate);
73        for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
74            outmsg("%f ",mfcc_out->data[0][coef_cnt]);
75        }
76        outmsg("\n");
77      }
78}
79
80int main(int argc, char **argv) {
81  // params
82  buffer_size  = 512;
83  overlap_size = 256;
84 
85  examples_common_init(argc,argv);
86  mfcc_out = new_fvec(n_coefs,channels);
87 
88 
89  //populating the filter
90  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs);
91 
92  //process
93  examples_common_process(aubio_process,process_print);
94 
95  //destroying mfcc
96  del_aubio_mfcc(mfcc);
97  del_fvec(mfcc_out);
98
99  examples_common_del();
100  debug("End of program.\n");
101  fflush(stderr);
102 
103  return 0;
104}
105
Note: See TracBrowser for help on using the repository browser.