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 | #ifndef MFCC_H |
---|
24 | #define MFCC_H |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | #include "filterbank.h" |
---|
31 | |
---|
32 | //libXtract constants and enums |
---|
33 | // TODO: remove them |
---|
34 | |
---|
35 | #define XTRACT_SQ(a) ((a) * (a)) |
---|
36 | #define XTRACT_MIN(a, b) ((a) < (b) ? (a) : (b)) |
---|
37 | #define XTRACT_MAX(a, b) ((a) > (b) ? (a) : (b)) |
---|
38 | #define XTRACT_NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n") |
---|
39 | #define XTRACT_VERY_SMALL_NUMBER 2e-42 |
---|
40 | #define XTRACT_LOG_LIMIT XTRACT_VERY_SMALL_NUMBER |
---|
41 | #define XTRACT_LOG_LIMIT_DB -96.0 |
---|
42 | #define XTRACT_DB_SCALE_OFFSET 96.0 |
---|
43 | #define XTRACT_VERY_BIG_NUMBER 2e42 |
---|
44 | #define XTRACT_SR_UPPER_LIMIT 192000.0 |
---|
45 | #define XTRACT_SR_LOWER_LIMIT 22050.0 |
---|
46 | #define XTRACT_SR_DEFAULT 44100.0 |
---|
47 | #define XTRACT_FUNDAMENTAL_DEFAULT 440.0 |
---|
48 | #define XTRACT_CHECK_nyquist if(!nyquist) nyquist = XTRACT_SR_DEFAULT / 2 |
---|
49 | #define XTRACT_CHECK_q if(!q) q = XTRACT_SR_DEFAULT / N |
---|
50 | #define XTRACT_IS_ODD(x) (x % 2 != 0 ? 1 : 0) |
---|
51 | #define XTRACT_SR_LIMIT SR_UPPER_LIMIT |
---|
52 | #define XTRACT_FFT_BANDS_MIN 16 |
---|
53 | #define XTRACT_FFT_BANDS_MAX 65536 |
---|
54 | #define XTRACT_FFT_BANDS_DEF 1024 |
---|
55 | #define XTRACT_SPEC_BW_MIN 0.168 /* Minimum spectral bandwidth \ |
---|
56 | (= SR_LOWER_LIMIT / FFT_BANDS_MAX*/ |
---|
57 | #define XTRACT_SPEC_BW_MAX 12000.0 /* SR_UPPER_LIMIT / FFT_BANDS_MIN */ |
---|
58 | #define XTRACT_SPEC_BW_DEF 43.066 /* SR_DEFAULT / FFT_BANDS_DEF */ |
---|
59 | |
---|
60 | /** \brief Enumeration of feature initialisation functions */ |
---|
61 | enum xtract_feature_init_ { |
---|
62 | XTRACT_INIT_MFCC = 100, |
---|
63 | XTRACT_INIT_BARK |
---|
64 | }; |
---|
65 | |
---|
66 | /** \brief Enumeration of feature types */ |
---|
67 | enum xtract_feature_types_ { |
---|
68 | XTRACT_SCALAR, |
---|
69 | XTRACT_VECTOR, |
---|
70 | XTRACT_DELTA |
---|
71 | }; |
---|
72 | |
---|
73 | /** \brief Enumeration of mfcc types */ |
---|
74 | enum xtract_mfcc_types_ { |
---|
75 | XTRACT_EQUAL_GAIN, |
---|
76 | XTRACT_EQUAL_AREA |
---|
77 | }; |
---|
78 | |
---|
79 | /** \brief Enumeration of return codes */ |
---|
80 | enum xtract_return_codes_ { |
---|
81 | XTRACT_SUCCESS, |
---|
82 | XTRACT_MALLOC_FAILED, |
---|
83 | XTRACT_BAD_ARGV, |
---|
84 | XTRACT_BAD_VECTOR_SIZE, |
---|
85 | XTRACT_NO_RESULT, |
---|
86 | XTRACT_FEATURE_NOT_IMPLEMENTED |
---|
87 | }; |
---|
88 | |
---|
89 | /** \brief Enumeration of spectrum types */ |
---|
90 | enum xtract_spectrum_ { |
---|
91 | XTRACT_MAGNITUDE_SPECTRUM, |
---|
92 | XTRACT_LOG_MAGNITUDE_SPECTRUM, |
---|
93 | XTRACT_POWER_SPECTRUM, |
---|
94 | XTRACT_LOG_POWER_SPECTRUM |
---|
95 | }; |
---|
96 | |
---|
97 | /** \brief Enumeration of data types*/ |
---|
98 | typedef enum type_ { |
---|
99 | XTRACT_FLOAT, |
---|
100 | XTRACT_FLOATARRAY, |
---|
101 | XTRACT_INT, |
---|
102 | XTRACT_MEL_FILTER |
---|
103 | } xtract_type_t; |
---|
104 | |
---|
105 | /** \brief Enumeration of units*/ |
---|
106 | typedef enum unit_ { |
---|
107 | /* NONE, ANY */ |
---|
108 | XTRACT_HERTZ = 2, |
---|
109 | XTRACT_ANY_AMPLITUDE_HERTZ, |
---|
110 | XTRACT_DBFS, |
---|
111 | XTRACT_DBFS_HERTZ, |
---|
112 | XTRACT_PERCENT, |
---|
113 | XTRACT_SONE |
---|
114 | } xtract_unit_t; |
---|
115 | |
---|
116 | /** \brief Boolean */ |
---|
117 | typedef enum { |
---|
118 | XTRACT_FALSE, |
---|
119 | XTRACT_TRUE |
---|
120 | } xtract_bool_t; |
---|
121 | |
---|
122 | /** \brief Enumeration of vector format types*/ |
---|
123 | typedef enum xtract_vector_ { |
---|
124 | /* N/2 magnitude/log-magnitude/power/log-power coeffs and N/2 frequencies */ |
---|
125 | XTRACT_SPECTRAL, |
---|
126 | /* N spectral amplitudes */ |
---|
127 | XTRACT_SPECTRAL_MAGNITUDES, |
---|
128 | /* N/2 magnitude/log-magnitude/power/log-power peak coeffs and N/2 |
---|
129 | * frequencies */ |
---|
130 | XTRACT_SPECTRAL_PEAKS, |
---|
131 | /* N spectral peak amplitudes */ |
---|
132 | XTRACT_SPECTRAL_PEAKS_MAGNITUDES, |
---|
133 | /* N spectral peak frequencies */ |
---|
134 | XTRACT_SPECTRAL_PEAKS_FREQUENCIES, |
---|
135 | /* N/2 magnitude/log-magnitude/power/log-power harmonic peak coeffs and N/2 |
---|
136 | * frequencies */ |
---|
137 | XTRACT_SPECTRAL_HARMONICS, |
---|
138 | /* N spectral harmonic amplitudes */ |
---|
139 | XTRACT_SPECTRAL_HARMONICS_MAGNITUDES, |
---|
140 | /* N spectral harmonic frequencies */ |
---|
141 | XTRACT_SPECTRAL_HARMONICS_FREQUENCIES, |
---|
142 | XTRACT_ARBITRARY_SERIES, |
---|
143 | XTRACT_AUDIO_SAMPLES, |
---|
144 | XTRACT_MEL_COEFFS, |
---|
145 | XTRACT_BARK_COEFFS, |
---|
146 | XTRACT_NO_DATA |
---|
147 | } xtract_vector_t; |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | // Computation |
---|
153 | |
---|
154 | /** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner |
---|
155 | * |
---|
156 | * \param *data: a pointer to the first element in an array of spectral magnitudes, e.g. the first half of the array pointed to by *resul from xtract_spectrum() |
---|
157 | * \param N: the number of array elements to be considered |
---|
158 | * \param *argv: a pointer to a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank |
---|
159 | * \param *result: a pointer to an array containing the resultant MFCC |
---|
160 | * |
---|
161 | * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc |
---|
162 | */ |
---|
163 | |
---|
164 | |
---|
165 | int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct); |
---|
166 | |
---|
167 | /** \brief Extract the Discrete Cosine transform of a time domain signal |
---|
168 | * \param *data: a pointer to the first element in an array of floats representing an audio vector |
---|
169 | * \param N: the number of array elements to be considered |
---|
170 | * \param *argv: a pointer to NULL |
---|
171 | * \param *result: a pointer to an array containing resultant dct coefficients |
---|
172 | */ |
---|
173 | int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct); |
---|
174 | |
---|
175 | #ifdef __cplusplus |
---|
176 | } |
---|
177 | #endif |
---|
178 | |
---|
179 | #endif |
---|