source: examples/aubiomfcc.c @ 0e0a049

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

examples/: simplify, use fvec_ funcs

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[88199ce]1/*
[53a7576]2   Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
3                  and Paul Brossier <piem@piem.org>
[88199ce]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
[3e7c408]22/* mfcc objects */
[2a77ff0]23fvec_t * mfcc_out;
[3e7c408]24aubio_mfcc_t * mfcc;
[d4c5de7]25aubio_pvoc_t *pv;
26cvec_t *fftgrain;
[3e7c408]27
[f72ceeb]28uint_t n_filters = 40;
[b901228]29uint_t n_coefs = 13;
[7a46bf6]30
[88199ce]31unsigned int pos = 0; /*frames%dspblocksize*/
32
[d4c5de7]33static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
[88199ce]34  unsigned int i;       /*channels*/
35  unsigned int j;       /*frames*/
[dcc649c]36 
[88199ce]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);
[71d3bf0]52     
[88199ce]53      //compute mfccs
[2a77ff0]54      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
[f72ceeb]55     
[88199ce]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
[d4c5de7]64static void process_print (void) {
[88199ce]65      /* output times in seconds
66         write extracted mfccs
67      */
68     
[7a46bf6]69      uint_t coef_cnt;
[88199ce]70      if (output_filename == NULL) {
[b901228]71        outmsg("%f\t",frames*overlap_size/(float)samplerate);
[aeb38cf]72        for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
[0e0a049]73            outmsg("%f ", fvec_read_sample (mfcc_out, 0, coef_cnt) );
[aeb38cf]74        }
75        outmsg("\n");
[88199ce]76      }
77}
78
79int main(int argc, char **argv) {
[3e7c408]80  // params
[b901228]81  buffer_size  = 512;
82  overlap_size = 256;
[ef1c3b7]83 
[88199ce]84  examples_common_init(argc,argv);
[d4c5de7]85
86  /* phase vocoder */
87  pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
88
89  fftgrain = new_cvec (buffer_size, channels);
90
[fe28ff3]91  //populating the filter
[d4c5de7]92  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
93 
94  mfcc_out = new_fvec(n_coefs,channels);
[f72ceeb]95 
[fe28ff3]96  //process
[88199ce]97  examples_common_process(aubio_process,process_print);
[fe28ff3]98 
[3e7c408]99  //destroying mfcc
[d4c5de7]100  del_aubio_pvoc (pv);
101  del_cvec (fftgrain);
[3e7c408]102  del_aubio_mfcc(mfcc);
[2a77ff0]103  del_fvec(mfcc_out);
[38837b1]104
[88199ce]105  examples_common_del();
106  debug("End of program.\n");
107  fflush(stderr);
[fe28ff3]108 
[88199ce]109  return 0;
110}
111
Note: See TracBrowser for help on using the repository browser.