LibXtract 1.6.0
libxtract.h
Go to the documentation of this file.
1/* Part of LibXtract
2 *
3 * SPDX-FileCopyrightText: 2006 Jamie Bullock
4 * SPDX-License-Identifier: Zlib
5 */
6
30
31#ifndef XTRACT_H
32#define XTRACT_H
33
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
43
44#include "xtract_scalar.h"
45#include "xtract_vector.h"
46#include "xtract_delta.h"
47#include "xtract_multivariate.h"
48#include "xtract_grid.h"
49#include "xtract_types.h"
50#include "xtract_macros.h"
51#include "xtract_helper.h"
52
58
59#define XTRACT_FEATURES XTRACT_FEATURE_COUNT
60
63 {
64 XTRACT_MEAN,
65 XTRACT_VARIANCE,
66 XTRACT_STANDARD_DEVIATION,
67 XTRACT_AVERAGE_DEVIATION,
68 XTRACT_SKEWNESS,
69 XTRACT_KURTOSIS,
70 XTRACT_SPECTRAL_MEAN,
71 XTRACT_SPECTRAL_VARIANCE,
72 XTRACT_SPECTRAL_STANDARD_DEVIATION,
73 /*XTRACT_SPECTRAL_AVERAGE_DEVIATION, */
74 XTRACT_SPECTRAL_SKEWNESS,
75 XTRACT_SPECTRAL_KURTOSIS,
76 XTRACT_SPECTRAL_CENTROID,
77 XTRACT_IRREGULARITY_K,
78 XTRACT_IRREGULARITY_J,
79 XTRACT_TRISTIMULUS_1,
80 XTRACT_TRISTIMULUS_2,
81 XTRACT_TRISTIMULUS_3,
82 XTRACT_SMOOTHNESS,
83 XTRACT_SPREAD,
84 XTRACT_ZCR,
85 XTRACT_ROLLOFF,
86 XTRACT_LOUDNESS,
87 XTRACT_FLATNESS,
88 XTRACT_FLATNESS_DB,
89 XTRACT_TONALITY,
90 XTRACT_CREST,
91 XTRACT_NOISINESS,
92 XTRACT_RMS_AMPLITUDE,
93 XTRACT_SPECTRAL_INHARMONICITY,
94 XTRACT_POWER,
95 XTRACT_ODD_EVEN_RATIO,
96 XTRACT_SHARPNESS,
97 XTRACT_SPECTRAL_SLOPE,
98 XTRACT_LOWEST_VALUE,
99 XTRACT_HIGHEST_VALUE,
100 XTRACT_SUM,
101 XTRACT_NONZERO_COUNT,
102 XTRACT_HPS,
103 XTRACT_F0,
104 XTRACT_FAILSAFE_F0,
105 XTRACT_WAVELET_F0,
106 XTRACT_MCLEOD_F0,
107 XTRACT_MIDICENT,
108 XTRACT_LNORM,
109 XTRACT_FLUX,
110 XTRACT_ATTACK_TIME,
111 XTRACT_DECAY_TIME,
112 XTRACT_DIFFERENCE_VECTOR,
113 XTRACT_AUTOCORRELATION,
114 XTRACT_AMDF,
115 XTRACT_ASDF,
116 XTRACT_BARK_COEFFICIENTS,
117 XTRACT_PEAK_SPECTRUM,
118 XTRACT_SPECTRUM,
119 XTRACT_AUTOCORRELATION_FFT,
120 XTRACT_MFCC,
121 XTRACT_DCT,
122 XTRACT_HARMONIC_SPECTRUM,
123 XTRACT_LPC,
124 XTRACT_LPCC,
125 XTRACT_SUBBANDS,
126 XTRACT_MEL_SPECTROGRAM,
127 XTRACT_GFCC,
128 XTRACT_GAMMATONE_SPECTROGRAM,
129 /* Helper functions */
130 XTRACT_WINDOWED,
131 XTRACT_SMOOTHED,
132 /* Appended after the helpers: a 1.x release never renumbers a value */
133 XTRACT_PEAK,
134 XTRACT_MMBSES,
135 XTRACT_SPECTRAL_SUBBAND_CENTROIDS,
136 XTRACT_MOVING_SUM,
137 XTRACT_MOVING_AVERAGE,
138 XTRACT_MOVING_VARIANCE,
139 XTRACT_MOVING_STANDARD_DEVIATION,
140 XTRACT_MOVING_MAX,
141 XTRACT_MOVING_MIN,
142 XTRACT_EWMA_AVERAGE,
143 XTRACT_EWMA_VARIANCE,
144 XTRACT_MEDIAN,
145 XTRACT_MEDIAN_ABSOLUTE_DEVIATION,
146 XTRACT_HJORTH_ACTIVITY,
147 XTRACT_HJORTH_MOBILITY,
148 XTRACT_HJORTH_COMPLEXITY,
149 XTRACT_TIME_REVERSAL_ASYMMETRY,
150 XTRACT_SPECTRAL_ENTROPY,
151 XTRACT_PETROSIAN_FRACTAL_DIMENSION,
152 XTRACT_KATZ_FRACTAL_DIMENSION,
153 XTRACT_HIGUCHI_FRACTAL_DIMENSION,
154 XTRACT_PERMUTATION_ENTROPY,
155 XTRACT_LEMPEL_ZIV_COMPLEXITY,
156 XTRACT_SAMPLE_ENTROPY,
157 XTRACT_APPROXIMATE_ENTROPY,
158 XTRACT_PERIODICITY,
159 XTRACT_SIGNAL_CONFIDENCE,
160 XTRACT_DECAY_RATE,
161 XTRACT_TEMPORAL_CENTROID,
162 XTRACT_MAX_POSITION,
163 XTRACT_MIN_POSITION,
164 XTRACT_PEAK_ASYMMETRY,
165 XTRACT_CROSS_CORRELATION,
166 XTRACT_CROSS_CORRELATION_LAG,
167 XTRACT_KULLBACK_LEIBLER_DIVERGENCE,
168 XTRACT_ITAKURA_SAITO_DIVERGENCE,
169 XTRACT_MODIFIED_KULLBACK_LEIBLER,
170 XTRACT_SPECTRAL_CONTRAST,
171 XTRACT_CHROMA,
172 XTRACT_CQT,
173 XTRACT_PEARSON_CORRELATION,
174 XTRACT_COVARIANCE_MATRIX,
175 XTRACT_CORRELATION_MATRIX,
176 XTRACT_AVERAGE_CORRELATION,
177 XTRACT_PRINCIPAL_VARIANCES,
178 XTRACT_COHERENCE,
179 XTRACT_GRID_MOMENTS,
180 XTRACT_GRID_CENTRAL_MOMENTS,
181 XTRACT_NORMALISED_MOMENTS,
182 XTRACT_HU_MOMENTS,
183 XTRACT_QUANTISE,
184 XTRACT_HISTOGRAM,
185 XTRACT_COOCCURRENCE_MATRIX,
186 XTRACT_COOCCURRENCE_CONTRAST,
187 XTRACT_COOCCURRENCE_CORRELATION,
188 XTRACT_ANGULAR_SECOND_MOMENT,
189 XTRACT_INVERSE_DIFFERENCE_MOMENT,
190 XTRACT_LOCAL_BINARY_PATTERNS,
191 XTRACT_FEATURE_COUNT
192 };
193
196 {
197 XTRACT_INIT_MFCC = 100,
198 XTRACT_INIT_BARK,
199 XTRACT_INIT_WINDOWED,
200 XTRACT_INIT_GFCC,
201 XTRACT_INIT_CQT
202 };
203
206 {
207 XTRACT_SCALAR,
208 XTRACT_VECTOR,
209 XTRACT_DELTA
210 };
211
215 {
216 XTRACT_EQUAL_GAIN,
217 XTRACT_EQUAL_AREA
218 };
219
220 enum xtract_lnorm_filter_types_
221 {
222 XTRACT_NO_LNORM_FILTER,
223 XTRACT_POSITIVE_SLOPE,
224 XTRACT_NEGATIVE_SLOPE
225 };
226
240 {
241 XTRACT_SUCCESS,
242 XTRACT_MALLOC_FAILED,
243 XTRACT_BAD_ARGV,
244 XTRACT_BAD_VECTOR_SIZE,
245 XTRACT_BAD_STATE,
246 XTRACT_DENORMAL_FOUND,
247 XTRACT_NO_RESULT,
248 XTRACT_FEATURE_NOT_IMPLEMENTED,
249 XTRACT_ARGUMENT_ERROR
250 };
251
254 {
255 XTRACT_MAGNITUDE_SPECTRUM,
256 XTRACT_LOG_MAGNITUDE_SPECTRUM,
257 XTRACT_POWER_SPECTRUM,
258 XTRACT_LOG_POWER_SPECTRUM,
259 XTRACT_MAGNITUDE_PHASE_SPECTRUM
260 };
261
264 {
265 XTRACT_OCTAVE_SUBBANDS,
266 XTRACT_LINEAR_SUBBANDS
267 };
268
270 typedef enum type_
271 {
272 XTRACT_FLOAT,
273 XTRACT_FLOATARRAY,
274 XTRACT_INT,
275 XTRACT_MEL_FILTER,
276 XTRACT_CQT_KERNEL
278
280 typedef enum unit_
281 {
282 XTRACT_UNIT_UNKNOWN = -2, /* unit has not been determined */
283 XTRACT_UNIT_ANY = -1, /* result inherits the input's unit */
284 XTRACT_UNIT_NONE = 0, /* dimensionless */
285 /* value 1 is reserved; the dimensioned units start at 2 so their
286 * values stay stable across releases */
287 XTRACT_HERTZ = 2,
288 XTRACT_ANY_AMPLITUDE_HERTZ,
289 XTRACT_DBFS,
290 XTRACT_DBFS_HERTZ,
291 XTRACT_PERCENT,
292 XTRACT_BINS,
293 XTRACT_SONE,
294 XTRACT_MIDI_CENT,
295 XTRACT_ACUM,
296 XTRACT_SECONDS,
297 XTRACT_PER_SECOND
299
301 typedef enum
302 {
303 XTRACT_FALSE,
304 XTRACT_TRUE
306
309 {
310 XTRACT_GAUSS,
311 XTRACT_HAMMING,
312 XTRACT_HANN,
313 XTRACT_BARTLETT,
314 XTRACT_TRIANGULAR,
315 XTRACT_BARTLETT_HANN,
316 XTRACT_BLACKMAN,
317 XTRACT_KAISER,
318 XTRACT_BLACKMAN_HARRIS
319 };
320
322 typedef enum xtract_vector_
323 {
324 /* N/2 magnitude/log-magnitude/power/log-power coefficients and N/2 frequencies */
325 XTRACT_SPECTRAL,
326 /* N spectral amplitudes */
327 XTRACT_SPECTRAL_MAGNITUDES,
328 /* N/2 magnitude/log-magnitude/power/log-power peak coefficients and N/2
329 * frequencies */
330 XTRACT_SPECTRAL_PEAKS,
331 /* N spectral peak amplitudes */
332 XTRACT_SPECTRAL_PEAKS_MAGNITUDES,
333 /* N spectral peak frequencies */
334 XTRACT_SPECTRAL_PEAKS_FREQUENCIES,
335 /* N/2 magnitude/log-magnitude/power/log-power harmonic peak coefficients and N/2
336 * frequencies */
337 XTRACT_SPECTRAL_HARMONICS,
338 /* N spectral harmonic amplitudes */
339 XTRACT_SPECTRAL_HARMONICS_MAGNITUDES,
340 /* N spectral harmonic frequencies */
341 XTRACT_SPECTRAL_HARMONICS_FREQUENCIES,
342 XTRACT_AUTOCORRELATION_COEFFS,
343 XTRACT_ARBITRARY_SERIES,
344 XTRACT_AUDIO_SAMPLES,
345 XTRACT_MEL_COEFFS,
346 XTRACT_LPC_COEFFS,
347 XTRACT_LPCC_COEFFS,
348 XTRACT_BARK_COEFFS,
349 XTRACT_SUBFRAMES,
350 XTRACT_NO_DATA,
351 /* N/2 magnitudes and N/2 phases, as xtract_spectrum() gives for
352 * XTRACT_MAGNITUDE_PHASE_SPECTRUM */
353 XTRACT_SPECTRAL_MAGNITUDE_PHASE,
354 /* 12 pitch class values from C to B */
355 XTRACT_CHROMA_COEFFS,
356 /* Series of equal length, one after another */
357 XTRACT_CHANNELS,
358 /* The rows of a square matrix, one after another */
359 XTRACT_SQUARE_MATRIX,
360 /* The rows of a grid of equal width, one after another */
361 XTRACT_GRID,
362 /* The sum of a grid and its 7 central moments of the second and third orders */
363 XTRACT_CENTRAL_MOMENT_COEFFS,
364 /* The 7 normalised moments of a grid of the second and third orders */
365 XTRACT_NORMALISED_MOMENT_COEFFS
367
370 {
371 int id;
372
373 struct
374 {
375 char name[XTRACT_MAX_NAME_LENGTH];
376 char p_name[XTRACT_MAX_NAME_LENGTH]; /* pretty name */
377 char desc[XTRACT_MAX_DESC_LENGTH];
378 char p_desc[XTRACT_MAX_DESC_LENGTH]; /* pretty description */
379 char author[XTRACT_MAX_AUTHOR_LENGTH];
380 int year;
381 } algo;
382
383 struct
384 {
385 xtract_vector_t format;
386 xtract_unit_t unit;
387 } data;
388
389 int argc;
390
391 struct
392 {
393 xtract_type_t type; /* type of the array/value pointed to by argv */
394 double min[XTRACT_MAXARGS];
395 double max[XTRACT_MAXARGS];
396 double def[XTRACT_MAXARGS]; /* defaults */
397 xtract_unit_t unit[XTRACT_MAXARGS];
398 int donor[XTRACT_MAXARGS]; /* suggested donor functions for argv */
399 } argv;
400
401 xtract_bool_t is_scalar;
402 xtract_bool_t is_delta; /* features in xtract_delta.h can be scalar or vector */
403
404 /* a result range/unit of XTRACT_UNKNOWN_MIN/MAX or XTRACT_UNIT_UNKNOWN
405 * means the feature is unimplemented or its range is genuinely
406 * undetermined, not merely unverified */
407 union {
408 struct
409 {
410 double min;
411 double max;
412 xtract_unit_t unit;
413 } scalar;
414
415 struct
416 {
417 xtract_vector_t format;
418 xtract_unit_t unit;
419 } vector;
420
421 } result;
422
424
467 extern int (*xtract[XTRACT_FEATURES])(const double *data, const int N, const void *argv, double *result);
468
471
476 typedef struct xtract_mel_filter_
477 {
478 int n_filters;
479 double **filters;
480 double *dct_table;
482
495 int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double freq_max, int freq_bands, double **fft_tables);
496
508 int xtract_init_gfcc(int N, double nyquist, double freq_min, double freq_max, int freq_bands, double **fft_tables);
509
518 int xtract_init_bark(int N, double sr, int *band_limits);
519
529 int xtract_init_fft(int N, int feature_name);
530
535 void xtract_free_fft(void);
536
543 double *xtract_init_window(const int N, const int type);
544
550 void xtract_free_window(double *window);
551
557 double *xtract_init_dct(const int N);
558
563 void xtract_free_dct(double *table);
564
566 typedef struct xtract_cqt_kernel_ xtract_cqt_kernel;
567
580 xtract_cqt_kernel *xtract_init_cqt(const int N, const double sr, const double fmin, const int bins_per_octave, const int n_bins, const double threshold);
581
587
588 /* \brief A function to build an array of function descriptors */
589 xtract_function_descriptor_t *xtract_make_descriptors(void);
590
591 /* \brief A function to free an array of function descriptors */
592 int xtract_free_descriptors(xtract_function_descriptor_t *fd);
593 /* Free functions */
594
596
597#ifdef __cplusplus
598}
599#endif
600
601#endif
int xtract_init_fft(int N, int feature_name)
An initialisation function for functions using FFT.
xtract_return_codes_
Enumeration of return codes.
Definition libxtract.h:240
type_
Enumeration of data types.
Definition libxtract.h:271
void xtract_free_dct(double *table)
Free a table as allocated by xtract_init_dct().
void xtract_free_cqt(xtract_cqt_kernel *kernel)
Free a kernel as allocated by xtract_init_cqt().
enum unit_ xtract_unit_t
Enumeration of units.
xtract_mfcc_types_
Enumeration of MFCC types.
Definition libxtract.h:215
int(* xtract[XTRACT_FEATURES])(const double *data, const int N, const void *argv, double *result)
An array of pointers to functions that perform the extraction.
xtract_feature_types_
Enumeration of feature types.
Definition libxtract.h:206
xtract_vector_
Enumeration of vector format types.
Definition libxtract.h:323
struct _xtract_function_descriptor xtract_function_descriptor_t
Data structure containing useful information about functions provided by LibXtract.
xtract_bool_t
Boolean.
Definition libxtract.h:302
void xtract_free_window(double *window)
Free a window as allocated by xtract_make_window().
int xtract_init_bark(int N, double sr, int *band_limits)
A function to initialise bark filter bounds.
xtract_spectrum_
Enumeration of spectrum types.
Definition libxtract.h:254
xtract_subband_scales_
Subband scales.
Definition libxtract.h:264
xtract_cqt_kernel * xtract_init_cqt(const int N, const double sr, const double fmin, const int bins_per_octave, const int n_bins, const double threshold)
Build a constant-Q kernel for xtract_cqt().
int xtract_init_wavelet_f0_state(void)
A function to initialise wavelet f0 detector state.
double * xtract_init_dct(const int N)
A function to initialise a cosine table for xtract_dct().
struct xtract_cqt_kernel_ xtract_cqt_kernel
The kernel xtract_cqt() applies, built by xtract_init_cqt() and freed by xtract_free_cqt().
Definition libxtract.h:566
int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double freq_max, int freq_bands, double **fft_tables)
A function to initialise a mel filter bank.
unit_
Enumeration of units.
Definition libxtract.h:281
struct xtract_mel_filter_ xtract_mel_filter
A structure to store a set of n_filters Mel filters.
void xtract_free_fft(void)
Free memory used for FFT plans.
xtract_feature_init_
Enumeration of feature initialisation functions.
Definition libxtract.h:196
xtract_window_types_
Window types.
Definition libxtract.h:309
xtract_features_
Enumeration of features, elements are used as indices to an array of pointers to feature extraction f...
Definition libxtract.h:63
int xtract_init_gfcc(int N, double nyquist, double freq_min, double freq_max, int freq_bands, double **fft_tables)
A function to initialise a gammatone filter bank for GFCC extraction.
enum type_ xtract_type_t
Enumeration of data types.
enum xtract_vector_ xtract_vector_t
Enumeration of vector format types.
double * xtract_init_window(const int N, const int type)
Make a window of a given type and return a pointer to it.
Data structure containing useful information about functions provided by LibXtract.
Definition libxtract.h:370
A structure to store a set of n_filters Mel filters.
Definition libxtract.h:477