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 | #include "aubiofilterbank.h" |
---|
27 | |
---|
28 | #define NYQUIST 22050.f |
---|
29 | |
---|
30 | //libXtract enums |
---|
31 | // TODO: remove them |
---|
32 | |
---|
33 | /** \brief Enumeration of feature initialisation functions */ |
---|
34 | enum xtract_feature_init_ { |
---|
35 | XTRACT_INIT_MFCC = 100, |
---|
36 | XTRACT_INIT_BARK |
---|
37 | }; |
---|
38 | |
---|
39 | /** \brief Enumeration of feature types */ |
---|
40 | enum xtract_feature_types_ { |
---|
41 | XTRACT_SCALAR, |
---|
42 | XTRACT_VECTOR, |
---|
43 | XTRACT_DELTA |
---|
44 | }; |
---|
45 | |
---|
46 | /** \brief Enumeration of mfcc types */ |
---|
47 | enum xtract_mfcc_types_ { |
---|
48 | XTRACT_EQUAL_GAIN, |
---|
49 | XTRACT_EQUAL_AREA |
---|
50 | }; |
---|
51 | |
---|
52 | /** \brief Enumeration of return codes */ |
---|
53 | enum xtract_return_codes_ { |
---|
54 | XTRACT_SUCCESS, |
---|
55 | XTRACT_MALLOC_FAILED, |
---|
56 | XTRACT_BAD_ARGV, |
---|
57 | XTRACT_BAD_VECTOR_SIZE, |
---|
58 | XTRACT_NO_RESULT, |
---|
59 | XTRACT_FEATURE_NOT_IMPLEMENTED |
---|
60 | }; |
---|
61 | |
---|
62 | /** \brief Enumeration of spectrum types */ |
---|
63 | enum xtract_spectrum_ { |
---|
64 | XTRACT_MAGNITUDE_SPECTRUM, |
---|
65 | XTRACT_LOG_MAGNITUDE_SPECTRUM, |
---|
66 | XTRACT_POWER_SPECTRUM, |
---|
67 | XTRACT_LOG_POWER_SPECTRUM |
---|
68 | }; |
---|
69 | |
---|
70 | /** \brief Enumeration of data types*/ |
---|
71 | typedef enum type_ { |
---|
72 | XTRACT_FLOAT, |
---|
73 | XTRACT_FLOATARRAY, |
---|
74 | XTRACT_INT, |
---|
75 | XTRACT_MEL_FILTER |
---|
76 | } xtract_type_t; |
---|
77 | |
---|
78 | /** \brief Enumeration of units*/ |
---|
79 | typedef enum unit_ { |
---|
80 | /* NONE, ANY */ |
---|
81 | XTRACT_HERTZ = 2, |
---|
82 | XTRACT_ANY_AMPLITUDE_HERTZ, |
---|
83 | XTRACT_DBFS, |
---|
84 | XTRACT_DBFS_HERTZ, |
---|
85 | XTRACT_PERCENT, |
---|
86 | XTRACT_SONE |
---|
87 | } xtract_unit_t; |
---|
88 | |
---|
89 | /** \brief Boolean */ |
---|
90 | typedef enum { |
---|
91 | XTRACT_FALSE, |
---|
92 | XTRACT_TRUE |
---|
93 | } xtract_bool_t; |
---|
94 | |
---|
95 | /** \brief Enumeration of vector format types*/ |
---|
96 | typedef enum xtract_vector_ { |
---|
97 | /* N/2 magnitude/log-magnitude/power/log-power coeffs and N/2 frequencies */ |
---|
98 | XTRACT_SPECTRAL, |
---|
99 | /* N spectral amplitudes */ |
---|
100 | XTRACT_SPECTRAL_MAGNITUDES, |
---|
101 | /* N/2 magnitude/log-magnitude/power/log-power peak coeffs and N/2 |
---|
102 | * frequencies */ |
---|
103 | XTRACT_SPECTRAL_PEAKS, |
---|
104 | /* N spectral peak amplitudes */ |
---|
105 | XTRACT_SPECTRAL_PEAKS_MAGNITUDES, |
---|
106 | /* N spectral peak frequencies */ |
---|
107 | XTRACT_SPECTRAL_PEAKS_FREQUENCIES, |
---|
108 | /* N/2 magnitude/log-magnitude/power/log-power harmonic peak coeffs and N/2 |
---|
109 | * frequencies */ |
---|
110 | XTRACT_SPECTRAL_HARMONICS, |
---|
111 | /* N spectral harmonic amplitudes */ |
---|
112 | XTRACT_SPECTRAL_HARMONICS_MAGNITUDES, |
---|
113 | /* N spectral harmonic frequencies */ |
---|
114 | XTRACT_SPECTRAL_HARMONICS_FREQUENCIES, |
---|
115 | XTRACT_ARBITRARY_SERIES, |
---|
116 | XTRACT_AUDIO_SAMPLES, |
---|
117 | XTRACT_MEL_COEFFS, |
---|
118 | XTRACT_BARK_COEFFS, |
---|
119 | XTRACT_NO_DATA |
---|
120 | } xtract_vector_t; |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | // Computation |
---|
126 | |
---|
127 | /** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner |
---|
128 | * |
---|
129 | * \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() |
---|
130 | * \param N: the number of array elements to be considered |
---|
131 | * \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 |
---|
132 | * \param *result: a pointer to an array containing the resultant MFCC |
---|
133 | * |
---|
134 | * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc |
---|
135 | */ |
---|
136 | int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result); |
---|
137 | |
---|
138 | /** \brief Extract the Discrete Cosine transform of a time domain signal |
---|
139 | * \param *data: a pointer to the first element in an array of floats representing an audio vector |
---|
140 | * \param N: the number of array elements to be considered |
---|
141 | * \param *argv: a pointer to NULL |
---|
142 | * \param *result: a pointer to an array containing resultant dct coefficients |
---|
143 | */ |
---|
144 | int aubio_dct_do(const float *data, const int N, const void *argv, float *result); |
---|
145 | |
---|
146 | |
---|
147 | #endif |
---|