source: examples/aubiomfcc.c @ 7c6c806

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 7c6c806 was 7c6c806, checked in by Amaury Hazan <mahmoudax@gmail.org>, 13 years ago

minor changes

  • Property mode set to 100644
File size: 3.1 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
21unsigned int pos = 0; /*frames%dspblocksize*/
22uint_t usepitch = 0;
23
24int aubio_process(float **input, float **output, int nframes);
25int aubio_process(float **input, float **output, int nframes) {
26  unsigned int i;       /*channels*/
27  unsigned int j;       /*frames*/
28 
29  for (j=0;j<(unsigned)nframes;j++) {
30    if(usejack) {
31      for (i=0;i<channels;i++) {
32        /* write input to datanew */
33        fvec_write_sample(ibuf, input[i][j], i, pos);
34        /* put synthnew in output */
35        output[i][j] = fvec_read_sample(obuf, i, pos);
36      }
37    }
38    /*time for fft*/
39    if (pos == overlap_size-1) {         
40      /* block loop */
41     
42      //compute mag spectrum
43      aubio_pvoc_do (pv,ibuf, fftgrain);
44     
45      uint_t n_coefs= n_filters/2 +1;
46      uint_t coef_cnt;
47       
48
49      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
50        mfcc_outbuf[coef_cnt]=0.f;
51       
52      //compute mfccs
53      aubio_mffc_do(fftgrain->norm, nframes, mf, mfcc_outbuf, fft_dct, fftgrain_dct);
54     
55      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
56        outmsg("%f ",mfcc_outbuf[coef_cnt]);
57      outmsg("\n");
58     
59     
60
61      /* end of block loop */
62      pos = -1; /* so it will be zero next j loop */
63    }
64    pos++;
65  }
66  return 1;
67}
68
69void process_print (void);
70void process_print (void) {
71      /* output times in seconds
72         write extracted mfccs
73      */
74     
75      if (output_filename == NULL) {
76        if(frames >= 4) {
77          outmsg("%f\n",(frames-4)*overlap_size/(float)samplerate);
78        } else if (frames < 4) {
79          outmsg("%f\n",0.);
80        }
81      }
82}
83
84int main(int argc, char **argv) {
85  examples_common_init(argc,argv);
86 
87  //allocate and initialize mel filter bank
88 
89
90  //allocating global mf (in utils.c)
91  uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
92  mf = (aubio_mel_filter *)getbytes(banksize);
93
94  mf->n_filters = 20;
95  mf->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *));
96  for(n = 0; n < mf->n_filters; n++)
97    mf->filters[n] = (smpl_t *)getbytes((buffer_size/2+1) * sizeof(smpl_t));
98 
99  //populating the filter
100  aubio_mfcc_init(buffer_size, nyquist, XTRACT_EQUAL_GAIN, lowfreq, highfreq, mf->n_filters, mf->filters);
101
102  //process
103  examples_common_process(aubio_process,process_print);
104  examples_common_del();
105  debug("End of program.\n");
106  fflush(stderr);
107 
108  //destroying filterbank
109  free(mf);
110 
111  return 0;
112}
113
Note: See TracBrowser for help on using the repository browser.