source: examples/aubiomfcc.c @ 2a77ff0

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

aubiomfcc.c: prepare text output, rename output buffer to mfcc_out

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