source: src/mfcc.c @ 4f33dd3

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

mfcc.c: remove old code

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2   Copyright (C) 2006 Amaury Hazan
3   Ported to aubio from LibXtract
4   http://libxtract.sourceforge.net/
5   
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program; if not, write to the Free Software
19   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#include "aubio_priv.h"
24#include "sample.h"
25#include "fft.h"
26#include "filterbank.h"
27#include "mfcc.h"
28#include "math.h"
29
30
31
32/** Internal structure for mfcc object **/
33
34struct aubio_mfcc_t_{
35  uint_t win_s;             /** grain length */
36  uint_t samplerate;        /** sample rate (needed?) */
37  uint_t channels;          /** number of channels */
38  uint_t n_coefs;           /** number of coefficients (= fb->n_filters/2 +1) */
39  smpl_t lowfreq;           /** lowest frequency for filters */ 
40  smpl_t highfreq;          /** highest frequency for filters */
41  aubio_filterbank_t * fb;  /** filter bank */
42  fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
43  aubio_mfft_t * fft_dct;   /** fft object for dct */
44  cvec_t * fftgrain_dct;    /** output buffer for dct */
45};
46
47
48aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels){
49
50
51  /** allocating space for mfcc object */
52 
53  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
54 
55  mfcc->win_s=win_s;
56  mfcc->samplerate=samplerate;
57  mfcc->channels=channels;
58  mfcc->n_coefs=n_coefs;
59  mfcc->lowfreq=lowfreq;
60  mfcc->highfreq=highfreq;
61
62  /** filterbank allocation */
63  //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
64  mfcc->fb=new_aubio_filterbank((n_coefs-1)*2, mfcc->win_s);
65
66  /** allocating space for fft object (used for dct) */
67  mfcc->fft_dct=new_aubio_mfft(mfcc->win_s, 1);
68
69  /** allocating buffers */
70 
71  mfcc->in_dct=new_fvec(mfcc->win_s, 1);
72 
73  mfcc->fftgrain_dct=new_cvec(mfcc->fb->n_filters, 1);
74
75  /** populating the filterbank */
76 
77  aubio_filterbank_mfcc_init(mfcc->fb, (mfcc->samplerate)/2, XTRACT_EQUAL_GAIN, mfcc->lowfreq, mfcc->highfreq);
78
79  return mfcc;
80
81};
82
83
84void del_aubio_mfcc(aubio_mfcc_t *mf){
85 
86  /** deleting filterbank */
87  del_aubio_filterbank(mf->fb);
88  /** deleting mfft object */
89  del_aubio_mfft(mf->fft_dct);
90  /** deleting buffers */
91  del_fvec(mf->in_dct);
92  del_cvec(mf->fftgrain_dct);
93 
94  /** deleting mfcc object */
95  AUBIO_FREE(mf);
96
97}
98
99
100// Computation
101
102void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
103
104    aubio_filterbank_t *f = mf->fb;
105    uint_t n, filter_cnt;
106
107    for(filter_cnt = 0; filter_cnt < f->n_filters; filter_cnt++){
108        mf->in_dct->data[0][filter_cnt] = 0.f;
109        for(n = 0; n < mf->win_s; n++){
110            mf->in_dct->data[0][filter_cnt] += in->norm[0][n] * f->filters[filter_cnt]->data[0][n];
111        }
112        mf->in_dct->data[0][filter_cnt] = LOG(mf->in_dct->data[0][filter_cnt] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : mf->in_dct->data[0][filter_cnt]);
113    }
114
115    //TODO: check that zero padding
116    // the following line seems useless since the in_dct buffer has the correct size
117    //for(n = filter + 1; n < N; n++) result[n] = 0;
118   
119    aubio_dct_do(mf, mf->in_dct, out);
120   
121    //return XTRACT_SUCCESS;
122}
123
124void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){
125   
126   
127   
128    //fvec_t * momo = new_fvec(20, 1);
129    //momo->data = data;
130   
131    //compute mag spectrum
132    aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
133
134    int i;
135    //extract real part of fft grain
136    for(i=0; i<mf->n_coefs ;i++){
137      out->data[0][i]= mf->fftgrain_dct->norm[0][i]*COS(mf->fftgrain_dct->phas[0][i]);
138    }
139
140
141    //return XTRACT_SUCCESS;
142}
143
Note: See TracBrowser for help on using the repository browser.