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@1
|
32 #define VERSION "0.1"
|
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@1
|
41 #define XTRACT_FEATURES 40
|
jamie@1
|
42 #define LOG_LIMIT 10e-10
|
jamie@1
|
43 #define SR_LIMIT 192000
|
jamie@1
|
44 #define BARK_BANDS 26
|
jamie@1
|
45
|
jamie@1
|
46 /** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
|
jamie@1
|
47
|
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@1
|
55 IRREGULARITY_K,
|
jamie@1
|
56 IRREGULARITY_J,
|
jamie@1
|
57 TRISTIMULUS_1,
|
jamie@1
|
58 TRISTIMULUS_2,
|
jamie@1
|
59 TRISTIMULUS_3,
|
jamie@1
|
60 SMOOTHNESS,
|
jamie@1
|
61 SPREAD,
|
jamie@1
|
62 ZCR,
|
jamie@1
|
63 ROLLOFF,
|
jamie@1
|
64 LOUDNESS,
|
jamie@1
|
65 FLATNESS,
|
jamie@1
|
66 TONALITY,
|
jamie@1
|
67 CREST,
|
jamie@1
|
68 NOISINESS,
|
jamie@1
|
69 RMS_AMPLITUDE,
|
jamie@1
|
70 INHARMONICITY,
|
jamie@1
|
71 POWER,
|
jamie@1
|
72 ODD_EVEN_RATIO,
|
jamie@1
|
73 SHARPNESS,
|
jamie@1
|
74 SLOPE,
|
jamie@1
|
75 F0,
|
jamie@1
|
76 HPS,
|
jamie@1
|
77 MAGNITUDE_SPECTRUM,
|
jamie@1
|
78 AUTOCORRELATION,
|
jamie@1
|
79 AUTOCORRELATION_FFT,
|
jamie@1
|
80 AMDF,
|
jamie@1
|
81 ASDF,
|
jamie@1
|
82 MFCC,
|
jamie@1
|
83 DCT,
|
jamie@1
|
84 BARK_COEFFICIENTS,
|
jamie@1
|
85 PEAKS,
|
jamie@1
|
86 FLUX,
|
jamie@1
|
87 ATTACK_TIME,
|
jamie@1
|
88 DECAY_TIME,
|
jamie@1
|
89 DELTA_FEATURE
|
jamie@1
|
90 };
|
jamie@1
|
91
|
jamie@1
|
92 /** \brief Enumeration of feature types */
|
jamie@1
|
93
|
jamie@1
|
94 enum feature_types_ {
|
jamie@1
|
95 SCALAR,
|
jamie@1
|
96 VECTOR,
|
jamie@1
|
97 DELTA
|
jamie@1
|
98 };
|
jamie@1
|
99
|
jamie@1
|
100 /** \brief Enumeration of mfcc types */
|
jamie@1
|
101
|
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
|
jamie@1
|
109 enum return_codes_ {
|
jamie@1
|
110 SUCCESS,
|
jamie@1
|
111 MALLOC_FAILED,
|
jamie@1
|
112 BAD_ARGV,
|
jamie@1
|
113 BAD_VECTOR_SIZE
|
jamie@1
|
114 };
|
jamie@1
|
115
|
jamie@1
|
116 /**
|
jamie@1
|
117 *
|
jamie@1
|
118 * \brief Perform feature extraction
|
jamie@1
|
119 *
|
jamie@1
|
120 * \param
|
jamie@1
|
121 *
|
jamie@1
|
122 * In general functions in this library conform to the following prototpe:
|
jamie@1
|
123 *
|
jamie@1
|
124 * int xtract_featurename(float *data, int N, void *argv, float *result)
|
jamie@1
|
125 *
|
jamie@1
|
126 *
|
jamie@1
|
127 * float *data: a pointer to an array element
|
jamie@1
|
128 *
|
jamie@1
|
129 * int N: the number of elements to be processed by the function
|
jamie@1
|
130 *
|
jamie@1
|
131 * void *argv: an abitrary number of additional arguments
|
jamie@1
|
132 *
|
jamie@1
|
133 * float *result: a pointer to the result
|
jamie@1
|
134 *
|
jamie@1
|
135 *
|
jamie@1
|
136 * Each function will iterate over N array elements, the first of which is
|
jamie@1
|
137 * pointed to by *data. It is therefore up to the caller to ensure that an
|
jamie@1
|
138 * approriate range of data is provided. For example, if the function expects
|
jamie@1
|
139 * an array containing an harmonic spectrum, then they array pointed to by
|
jamie@1
|
140 * *data must contain the amplitudes of harmonic frequencies in adjacent
|
jamie@1
|
141 * elemets
|
jamie@1
|
142 *
|
jamie@1
|
143 * For scalar and delta features, *result will point to a single value.
|
jamie@1
|
144 *
|
jamie@1
|
145 * For vector features it will point to the first element in an array.
|
jamie@1
|
146 *
|
jamie@1
|
147 * Memory for this array must be allocated and freed by the calling
|
jamie@1
|
148 * function.
|
jamie@1
|
149 *
|
jamie@1
|
150 * All functions return an integer error code as descibed in the enumeration
|
jamie@1
|
151 * return_codes_
|
jamie@1
|
152 *
|
jamie@1
|
153 * */
|
jamie@1
|
154
|
jamie@1
|
155
|
jamie@1
|
156 int(*xtract[XTRACT_FEATURES])(float *, int, void *, float *);
|
jamie@1
|
157
|
jamie@1
|
158 /* Data structures */
|
jamie@1
|
159
|
jamie@1
|
160 typedef struct xtract_mel_filter_ {
|
jamie@1
|
161 int n_filters;
|
jamie@1
|
162 float **filters;
|
jamie@1
|
163 } xtract_mel_filter;
|
jamie@1
|
164
|
jamie@1
|
165
|
jamie@1
|
166 /* Initialisation functions */
|
jamie@1
|
167 /* xtract_init_mfcc */
|
jamie@1
|
168 /* 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@1
|
169 int xtract_init_mfcc(int N, float nyquist, int style, float freq_max, float freq_min, int freq_bands, float **fft_tables);
|
jamie@1
|
170
|
jamie@1
|
171 /* xtract_init_bark */
|
jamie@1
|
172 /* 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@1
|
173 int xtract_init_bark(int N, float nyquist, int *band_limits);
|
jamie@1
|
174
|
jamie@1
|
175
|
jamie@1
|
176 /* Free functions */
|
jamie@1
|
177
|
jamie@1
|
178 #ifdef __cplusplus
|
jamie@1
|
179 }
|
jamie@1
|
180 #endif
|
jamie@1
|
181
|
jamie@1
|
182 #endif
|