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 | |
---|
24 | #include "mffc.h" |
---|
25 | |
---|
26 | // Computation |
---|
27 | |
---|
28 | int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result){ |
---|
29 | |
---|
30 | aubio_mel_filter *f; |
---|
31 | int n, filter; |
---|
32 | |
---|
33 | f = (aubio_mel_filter *)argv; |
---|
34 | |
---|
35 | for(filter = 0; filter < f->n_filters; filter++){ |
---|
36 | result[filter] = 0.f; |
---|
37 | for(n = 0; n < N; n++){ |
---|
38 | result[filter] += data[n] * f->filters[filter][n]; |
---|
39 | } |
---|
40 | result[filter] = log(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]); |
---|
41 | } |
---|
42 | |
---|
43 | //TODO: check that zero padding |
---|
44 | for(n = filter + 1; n < N; n++) result[n] = 0; |
---|
45 | |
---|
46 | aubio_dct_do(result, f->n_filters, NULL, result); |
---|
47 | |
---|
48 | return XTRACT_SUCCESS; |
---|
49 | } |
---|
50 | |
---|
51 | int aubio_dct_do(const float *data, const int N, const void *argv, float *result){ |
---|
52 | |
---|
53 | |
---|
54 | //call aubio p_voc in dct setting |
---|
55 | |
---|
56 | //TODO: fvec as input? Remove data length, N? |
---|
57 | |
---|
58 | //compute mag spectrum |
---|
59 | aubio_pvoc_do (pv,data, fftgrain); |
---|
60 | |
---|
61 | int i; |
---|
62 | //extract real part of fft grain |
---|
63 | for(i=0; i<N ;i++){ |
---|
64 | result[i]= fftgrain->norm[i]*cos(fftgrain->phase[i]); |
---|
65 | } |
---|
66 | |
---|
67 | /* |
---|
68 | fftwf_plan plan; |
---|
69 | |
---|
70 | plan = |
---|
71 | fftwf_plan_r2r_1d(N, (float *) data, result, FFTW_REDFT00, FFTW_ESTIMATE); |
---|
72 | |
---|
73 | fftwf_execute(plan); |
---|
74 | fftwf_destroy_plan(plan);*/ |
---|
75 | |
---|
76 | return XTRACT_SUCCESS; |
---|
77 | } |
---|