source: examples/aubiomfcc.c @ 73eaa2e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 73eaa2e was 7c6c806d, checked in by Amaury Hazan <mahmoudax@gmail.org>, 17 years ago

minor changes

  • Property mode set to 100644
File size: 3.1 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
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*/
[dcc649c]28 
[88199ce]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);
[71d3bf0]44     
[7c6c806d]45      uint_t n_coefs= n_filters/2 +1;
[71d3bf0]46      uint_t coef_cnt;
[7c6c806d]47       
[88199ce]48
[7c6c806d]49      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
50        mfcc_outbuf[coef_cnt]=0.f;
[fe28ff3]51       
[88199ce]52      //compute mfccs
[7c6c806d]53      aubio_mffc_do(fftgrain->norm, nframes, mf, mfcc_outbuf, fft_dct, fftgrain_dct);
[88199ce]54     
[7c6c806d]55      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
56        outmsg("%f ",mfcc_outbuf[coef_cnt]);
[71d3bf0]57      outmsg("\n");
[88199ce]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);
[fe28ff3]86 
87  //allocate and initialize mel filter bank
[7c6c806d]88 
[fe28ff3]89
[7c6c806d]90  //allocating global mf (in utils.c)
[fe28ff3]91  uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
[7c6c806d]92  mf = (aubio_mel_filter *)getbytes(banksize);
[fe28ff3]93
[97886fa]94  mf->n_filters = 20;
95  mf->filters = (smpl_t **)getbytes(mf->n_filters * sizeof(smpl_t *));
[fe28ff3]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
[71d3bf0]100  aubio_mfcc_init(buffer_size, nyquist, XTRACT_EQUAL_GAIN, lowfreq, highfreq, mf->n_filters, mf->filters);
[fe28ff3]101
102  //process
[88199ce]103  examples_common_process(aubio_process,process_print);
104  examples_common_del();
105  debug("End of program.\n");
106  fflush(stderr);
[fe28ff3]107 
108  //destroying filterbank
109  free(mf);
110 
[88199ce]111  return 0;
112}
113
Note: See TracBrowser for help on using the repository browser.