source: src/mfcc.c @ b276dee

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

mfcc.{c,h}, filterbank.{c,h}: move filter initialisation into new_aubio_filterbank_mfcc

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[88199ce]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
[7c6c806d]23#include "aubio_priv.h"
24#include "sample.h"
25#include "fft.h"
[8708556]26#include "filterbank.h"
[7c6c806d]27#include "mfcc.h"
28#include "math.h"
[88199ce]29
[8708556]30/** Internal structure for mfcc object **/
[88199ce]31
[8708556]32struct aubio_mfcc_t_{
[34d72f0]33  uint_t win_s;             /** grain length */
34  uint_t samplerate;        /** sample rate (needed?) */
35  uint_t channels;          /** number of channels */
36  uint_t n_coefs;           /** number of coefficients (= fb->n_filters/2 +1) */
37  smpl_t lowfreq;           /** lowest frequency for filters */ 
38  smpl_t highfreq;          /** highest frequency for filters */
39  aubio_filterbank_t * fb;  /** filter bank */
40  fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
41  aubio_mfft_t * fft_dct;   /** fft object for dct */
42  cvec_t * fftgrain_dct;    /** output buffer for dct */
[8708556]43};
44
45
[cfe4038]46aubio_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){
[8708556]47  /** allocating space for mfcc object */
48  aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
[cfe4038]49
50  //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
51  uint_t n_filters = (n_coefs-1)*2;
[8708556]52 
53  mfcc->win_s=win_s;
54  mfcc->samplerate=samplerate;
55  mfcc->channels=channels;
56  mfcc->n_coefs=n_coefs;
57  mfcc->lowfreq=lowfreq;
58  mfcc->highfreq=highfreq;
59
60  /** filterbank allocation */
[b276dee]61  mfcc->fb = new_aubio_filterbank_mfcc(n_filters, mfcc->win_s, samplerate, lowfreq, highfreq);
[8708556]62
63  /** allocating space for fft object (used for dct) */
[b276dee]64  mfcc->fft_dct=new_aubio_mfft(n_filters, 1);
[8708556]65
66  /** allocating buffers */
67  mfcc->in_dct=new_fvec(mfcc->win_s, 1);
68 
[cfe4038]69  mfcc->fftgrain_dct=new_cvec(n_filters, 1);
[8708556]70
71  return mfcc;
72};
73
74void del_aubio_mfcc(aubio_mfcc_t *mf){
75  /** deleting filterbank */
76  del_aubio_filterbank(mf->fb);
77  /** deleting mfft object */
78  del_aubio_mfft(mf->fft_dct);
79  /** deleting buffers */
80  del_fvec(mf->in_dct);
81  del_cvec(mf->fftgrain_dct);
82 
83  /** deleting mfcc object */
84  AUBIO_FREE(mf);
85}
86
87void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
[b276dee]88    // compute filterbank
89    aubio_filterbank_do(mf->fb, in, mf->in_dct);
[7c6c806d]90    //TODO: check that zero padding
[8708556]91    // the following line seems useless since the in_dct buffer has the correct size
92    //for(n = filter + 1; n < N; n++) result[n] = 0;
[88199ce]93   
[8708556]94    aubio_dct_do(mf, mf->in_dct, out);
[cfe4038]95
96    return;
[88199ce]97}
98
[8708556]99void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out){
[b276dee]100    uint_t i;
[97886fa]101    //compute mag spectrum
[8708556]102    aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
[97886fa]103    //extract real part of fft grain
[b276dee]104    //for(i=0; i<mf->n_coefs ;i++){
105    for(i=0; i<out->length;i++){
106      out->data[0][i]= mf->fftgrain_dct->norm[0][i]
107        *COS(mf->fftgrain_dct->phas[0][i]);
[97886fa]108    }
[cfe4038]109    return;
110}
111
Note: See TracBrowser for help on using the repository browser.