jamie@1
|
1 /* libxtract feature extraction library
|
jamie@1
|
2 *
|
jamie@1
|
3 * Copyright (C) 2006 Jamie Bullock
|
jamie@1
|
4 *
|
jamie@1
|
5 * This program is free software; you can redistribute it and/or modify
|
jamie@1
|
6 * it under the terms of the GNU General Public License as published by
|
jamie@1
|
7 * the Free Software Foundation; either version 2 of the License, or
|
jamie@1
|
8 * (at your option) any later version.
|
jamie@1
|
9 *
|
jamie@1
|
10 * This program is distributed in the hope that it will be useful,
|
jamie@1
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jamie@1
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jamie@1
|
13 * GNU General Public License for more details.
|
jamie@1
|
14 *
|
jamie@1
|
15 * You should have received a copy of the GNU General Public License
|
jamie@1
|
16 * along with this program; if not, write to the Free Software
|
jamie@1
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
jamie@1
|
18 * USA.
|
jamie@1
|
19 */
|
jamie@1
|
20
|
jamie@1
|
21 #ifndef XTRACT_H
|
jamie@1
|
22 #define XTRACT_H
|
jamie@1
|
23
|
jamie@1
|
24 #ifdef __cplusplus
|
jamie@1
|
25 extern "C" {
|
jamie@1
|
26 #endif
|
jamie@1
|
27
|
jamie@1
|
28 /**
|
jamie@1
|
29 * \file libxtract.h: main header file and API definition
|
jamie@1
|
30 */
|
jamie@1
|
31
|
jamie@5
|
32 #define VERSION "0.11"
|
jamie@1
|
33
|
jamie@1
|
34
|
jamie@1
|
35 #include "xtract_scalar.h"
|
jamie@1
|
36 #include "xtract_vector.h"
|
jamie@1
|
37 #include "xtract_delta.h"
|
jamie@1
|
38 #include "xtract_types.h"
|
jamie@1
|
39 #include "xtract_macros.h"
|
jamie@1
|
40
|
jamie@11
|
41 #define XTRACT_FEATURES 43
|
jamie@1
|
42 #define LOG_LIMIT 10e-10
|
jamie@5
|
43 #define VERY_BIG_NUMBER 2e10
|
jamie@1
|
44 #define SR_LIMIT 192000
|
jamie@1
|
45 #define BARK_BANDS 26
|
jamie@1
|
46
|
jamie@1
|
47 /** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
|
jamie@1
|
48 enum features_ {
|
jamie@1
|
49 MEAN,
|
jamie@1
|
50 VARIANCE,
|
jamie@1
|
51 STANDARD_DEVIATION,
|
jamie@1
|
52 AVERAGE_DEVIATION,
|
jamie@1
|
53 SKEWNESS,
|
jamie@1
|
54 KURTOSIS,
|
jamie@11
|
55 CENTROID,
|
jamie@1
|
56 IRREGULARITY_K,
|
jamie@1
|
57 IRREGULARITY_J,
|
jamie@1
|
58 TRISTIMULUS_1,
|
jamie@1
|
59 TRISTIMULUS_2,
|
jamie@1
|
60 TRISTIMULUS_3,
|
jamie@1
|
61 SMOOTHNESS,
|
jamie@1
|
62 SPREAD,
|
jamie@1
|
63 ZCR,
|
jamie@1
|
64 ROLLOFF,
|
jamie@1
|
65 LOUDNESS,
|
jamie@1
|
66 FLATNESS,
|
jamie@1
|
67 TONALITY,
|
jamie@1
|
68 CREST,
|
jamie@1
|
69 NOISINESS,
|
jamie@1
|
70 RMS_AMPLITUDE,
|
jamie@1
|
71 INHARMONICITY,
|
jamie@1
|
72 POWER,
|
jamie@1
|
73 ODD_EVEN_RATIO,
|
jamie@1
|
74 SHARPNESS,
|
jamie@1
|
75 SLOPE,
|
jamie@5
|
76 LOWEST_MATCH,
|
jamie@1
|
77 HPS,
|
jamie@9
|
78 F0,
|
jamie@1
|
79 MAGNITUDE_SPECTRUM,
|
jamie@1
|
80 AUTOCORRELATION,
|
jamie@1
|
81 AUTOCORRELATION_FFT,
|
jamie@1
|
82 AMDF,
|
jamie@1
|
83 ASDF,
|
jamie@1
|
84 MFCC,
|
jamie@1
|
85 DCT,
|
jamie@1
|
86 BARK_COEFFICIENTS,
|
jamie@1
|
87 PEAKS,
|
jamie@1
|
88 FLUX,
|
jamie@1
|
89 ATTACK_TIME,
|
jamie@1
|
90 DECAY_TIME,
|
jamie@1
|
91 DELTA_FEATURE
|
jamie@1
|
92 };
|
jamie@1
|
93
|
jamie@1
|
94 /** \brief Enumeration of feature types */
|
jamie@1
|
95 enum feature_types_ {
|
jamie@1
|
96 SCALAR,
|
jamie@1
|
97 VECTOR,
|
jamie@1
|
98 DELTA
|
jamie@1
|
99 };
|
jamie@1
|
100
|
jamie@1
|
101 /** \brief Enumeration of mfcc types */
|
jamie@1
|
102 enum mfcc_types_ {
|
jamie@1
|
103 EQUAL_GAIN,
|
jamie@1
|
104 EQUAL_AREA
|
jamie@1
|
105 };
|
jamie@1
|
106
|
jamie@1
|
107 /** \brief Enumeration of return codes */
|
jamie@1
|
108 enum return_codes_ {
|
jamie@1
|
109 SUCCESS,
|
jamie@1
|
110 MALLOC_FAILED,
|
jamie@1
|
111 BAD_ARGV,
|
jamie@12
|
112 BAD_VECTOR_SIZE,
|
jamie@12
|
113 NO_RESULT
|
jamie@1
|
114 };
|
jamie@1
|
115
|
jamie@1
|
116 /**
|
jamie@1
|
117 *
|
jamie@2
|
118 * \brief An array of pointers to functions that perform the extraction
|
jamie@1
|
119 *
|
jamie@2
|
120 * \param *data: a pointer to the start of the input data (usually the first element in an array)
|
jamie@1
|
121 *
|
jamie@2
|
122 * \param N: the number of elements to be processed
|
jamie@1
|
123 *
|
jamie@2
|
124 * \param *argv: an abitrary number of additional arguments, used to pass additional parameters to the function being called
|
jamie@1
|
125 *
|
jamie@2
|
126 * \param *result: a pointer to the first element in the result
|
jamie@1
|
127 *
|
jamie@1
|
128 * Each function will iterate over N array elements, the first of which is
|
jamie@2
|
129 * pointed to by *data. It is up to the calling function to ensure that the array is in the format expected by the function being called.
|
jamie@1
|
130 *
|
jamie@1
|
131 * For scalar and delta features, *result will point to a single value.
|
jamie@1
|
132 *
|
jamie@1
|
133 * For vector features it will point to the first element in an array.
|
jamie@1
|
134 *
|
jamie@1
|
135 * Memory for this array must be allocated and freed by the calling
|
jamie@1
|
136 * function.
|
jamie@1
|
137 *
|
jamie@1
|
138 * All functions return an integer error code as descibed in the enumeration
|
jamie@1
|
139 * return_codes_
|
jamie@2
|
140 *
|
jamie@9
|
141 * The preprocessor macro: XTRACT must be defined before this can be used
|
jamie@9
|
142 *
|
jamie@2
|
143 * example:<br>
|
jamie@9
|
144 *
|
jamie@9
|
145 * #include <stdio.h>
|
jamie@9
|
146 * #define XTRACT
|
jamie@9
|
147 * #include "libxtract.h"
|
jamie@9
|
148 *
|
jamie@9
|
149 * main () {
|
jamie@9
|
150 * float values[] = {1.0, 2.0, 3.0, 4.0, 5.0};
|
jamie@9
|
151 * int N = 5;
|
jamie@9
|
152 * float mean;
|
jamie@9
|
153 *
|
jamie@9
|
154 * xtract[MEAN]((void *)values, N, NULL, &mean);
|
jamie@9
|
155 *
|
jamie@9
|
156 * printf("Mean = %.2f\n", mean);
|
jamie@9
|
157 * }
|
jamie@9
|
158 *
|
jamie@9
|
159 * The calling function may additionally make some tests against the value returned by xtract
|
jamie@9
|
160 *
|
jamie@2
|
161 */
|
jamie@9
|
162 #ifdef XTRACT
|
jamie@2
|
163 int(*xtract[XTRACT_FEATURES])(float *data, int N, void *argv, float *result);
|
jamie@9
|
164 #endif
|
jamie@1
|
165
|
jamie@2
|
166 /** \brief A structure to store a set of n_filters Mel filters */
|
jamie@1
|
167 typedef struct xtract_mel_filter_ {
|
jamie@1
|
168 int n_filters;
|
jamie@1
|
169 float **filters;
|
jamie@1
|
170 } xtract_mel_filter;
|
jamie@1
|
171
|
jamie@2
|
172 /** \brief A function to initialise a mel filter bank
|
jamie@2
|
173 *
|
jamie@2
|
174 * It is up to the caller to pass in a pointer to memory allocated for freq_bands arrays of length N. This function populates these arrays with magnitude coefficients representing the mel filterbank on a linear scale
|
jamie@2
|
175 */
|
jamie@1
|
176 int xtract_init_mfcc(int N, float nyquist, int style, float freq_max, float freq_min, int freq_bands, float **fft_tables);
|
jamie@1
|
177
|
jamie@2
|
178 /** \brief A function to initialise bark filter bounds
|
jamie@2
|
179 *
|
jamie@2
|
180 * A pointer to an array of BARK_BANDS ints most be passed in, and is populated with BARK_BANDS fft bin numbers representing the limits of each band
|
jamie@2
|
181 */
|
jamie@1
|
182 int xtract_init_bark(int N, float nyquist, int *band_limits);
|
jamie@1
|
183
|
jamie@1
|
184
|
jamie@1
|
185 /* Free functions */
|
jamie@1
|
186
|
jamie@1
|
187 #ifdef __cplusplus
|
jamie@1
|
188 }
|
jamie@1
|
189 #endif
|
jamie@1
|
190
|
jamie@1
|
191 #endif
|