source: examples/aubiomfcc.c @ 53a7576

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

aubiomfcc.c: update header

  • Property mode set to 100644
File size: 2.9 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;
25
[88199ce]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*/
[dcc649c]33 
[88199ce]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);
[71d3bf0]49     
[88199ce]50      //compute mfccs
[2a77ff0]51      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
[88199ce]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     
[2a77ff0]67      uint_t filter_cnt;
[88199ce]68      if (output_filename == NULL) {
69        if(frames >= 4) {
[2a77ff0]70          outmsg("%f\t",(frames-4)*overlap_size/(float)samplerate);
[88199ce]71        } else if (frames < 4) {
[2a77ff0]72          outmsg("%f\t",0.);
[88199ce]73        }
[2a77ff0]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");
[88199ce]79      }
80}
81
82int main(int argc, char **argv) {
[3e7c408]83  // params
84  uint_t n_filters = 11;
85  smpl_t lowfreq = 500.;
86  smpl_t highfreq = 2000.;
[88199ce]87  examples_common_init(argc,argv);
[2a77ff0]88  mfcc_out = new_fvec(n_filters,channels);
[fe28ff3]89 
90  //populating the filter
[3e7c408]91  mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, lowfreq, highfreq,
92      channels);
[fe28ff3]93
94  //process
[88199ce]95  examples_common_process(aubio_process,process_print);
96  examples_common_del();
97  debug("End of program.\n");
98  fflush(stderr);
[fe28ff3]99 
[3e7c408]100  //destroying mfcc
101  del_aubio_mfcc(mfcc);
[2a77ff0]102  del_fvec(mfcc_out);
[fe28ff3]103 
[88199ce]104  return 0;
105}
106
Note: See TracBrowser for help on using the repository browser.