jamie@1: /* libxtract feature extraction library jamie@1: * jamie@1: * Copyright (C) 2006 Jamie Bullock jamie@1: * jamie@1: * This program is free software; you can redistribute it and/or modify jamie@1: * it under the terms of the GNU General Public License as published by jamie@1: * the Free Software Foundation; either version 2 of the License, or jamie@1: * (at your option) any later version. jamie@1: * jamie@1: * This program is distributed in the hope that it will be useful, jamie@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of jamie@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jamie@1: * GNU General Public License for more details. jamie@1: * jamie@1: * You should have received a copy of the GNU General Public License jamie@1: * along with this program; if not, write to the Free Software jamie@1: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, jamie@1: * USA. jamie@1: */ jamie@1: jamie@1: #ifndef XTRACT_H jamie@1: #define XTRACT_H jamie@1: jamie@1: #ifdef __cplusplus jamie@1: extern "C" { jamie@1: #endif jamie@1: jamie@1: /** jamie@1: * \file libxtract.h: main header file and API definition jamie@1: */ jamie@1: jamie@1: #define VERSION "0.1" jamie@1: jamie@1: jamie@1: #include "xtract_scalar.h" jamie@1: #include "xtract_vector.h" jamie@1: #include "xtract_delta.h" jamie@1: #include "xtract_types.h" jamie@1: #include "xtract_macros.h" jamie@1: jamie@1: #define XTRACT_FEATURES 40 jamie@1: #define LOG_LIMIT 10e-10 jamie@1: #define SR_LIMIT 192000 jamie@1: #define BARK_BANDS 26 jamie@1: jamie@1: /** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */ jamie@1: enum features_ { jamie@1: MEAN, jamie@1: VARIANCE, jamie@1: STANDARD_DEVIATION, jamie@1: AVERAGE_DEVIATION, jamie@1: SKEWNESS, jamie@1: KURTOSIS, jamie@1: IRREGULARITY_K, jamie@1: IRREGULARITY_J, jamie@1: TRISTIMULUS_1, jamie@1: TRISTIMULUS_2, jamie@1: TRISTIMULUS_3, jamie@1: SMOOTHNESS, jamie@1: SPREAD, jamie@1: ZCR, jamie@1: ROLLOFF, jamie@1: LOUDNESS, jamie@1: FLATNESS, jamie@1: TONALITY, jamie@1: CREST, jamie@1: NOISINESS, jamie@1: RMS_AMPLITUDE, jamie@1: INHARMONICITY, jamie@1: POWER, jamie@1: ODD_EVEN_RATIO, jamie@1: SHARPNESS, jamie@1: SLOPE, jamie@1: F0, jamie@1: HPS, jamie@1: MAGNITUDE_SPECTRUM, jamie@1: AUTOCORRELATION, jamie@1: AUTOCORRELATION_FFT, jamie@1: AMDF, jamie@1: ASDF, jamie@1: MFCC, jamie@1: DCT, jamie@1: BARK_COEFFICIENTS, jamie@1: PEAKS, jamie@1: FLUX, jamie@1: ATTACK_TIME, jamie@1: DECAY_TIME, jamie@1: DELTA_FEATURE jamie@1: }; jamie@1: jamie@1: /** \brief Enumeration of feature types */ jamie@1: enum feature_types_ { jamie@1: SCALAR, jamie@1: VECTOR, jamie@1: DELTA jamie@1: }; jamie@1: jamie@1: /** \brief Enumeration of mfcc types */ jamie@1: enum mfcc_types_ { jamie@1: EQUAL_GAIN, jamie@1: EQUAL_AREA jamie@1: }; jamie@1: jamie@1: /** \brief Enumeration of return codes */ jamie@1: enum return_codes_ { jamie@1: SUCCESS, jamie@1: MALLOC_FAILED, jamie@1: BAD_ARGV, jamie@1: BAD_VECTOR_SIZE jamie@1: }; jamie@1: jamie@1: /** jamie@1: * jamie@2: * \brief An array of pointers to functions that perform the extraction jamie@1: * jamie@2: * \param *data: a pointer to the start of the input data (usually the first element in an array) jamie@1: * jamie@2: * \param N: the number of elements to be processed jamie@1: * jamie@2: * \param *argv: an abitrary number of additional arguments, used to pass additional parameters to the function being called jamie@1: * jamie@2: * \param *result: a pointer to the first element in the result jamie@1: * jamie@1: * Each function will iterate over N array elements, the first of which is jamie@2: * 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: * jamie@1: * For scalar and delta features, *result will point to a single value. jamie@1: * jamie@1: * For vector features it will point to the first element in an array. jamie@1: * jamie@1: * Memory for this array must be allocated and freed by the calling jamie@1: * function. jamie@1: * jamie@1: * All functions return an integer error code as descibed in the enumeration jamie@1: * return_codes_ jamie@2: * jamie@2: * example:
jamie@2: * xtract[PEAKS](amplitude_spectrum, 512, threshold, peaks) jamie@2: */ jamie@2: int(*xtract[XTRACT_FEATURES])(float *data, int N, void *argv, float *result); jamie@1: jamie@2: /** \brief A structure to store a set of n_filters Mel filters */ jamie@1: typedef struct xtract_mel_filter_ { jamie@1: int n_filters; jamie@1: float **filters; jamie@1: } xtract_mel_filter; jamie@1: jamie@2: /** \brief A function to initialise a mel filter bank jamie@2: * jamie@2: * 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: */ jamie@1: int xtract_init_mfcc(int N, float nyquist, int style, float freq_max, float freq_min, int freq_bands, float **fft_tables); jamie@1: jamie@2: /** \brief A function to initialise bark filter bounds jamie@2: * jamie@2: * 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: */ jamie@1: int xtract_init_bark(int N, float nyquist, int *band_limits); jamie@1: jamie@1: jamie@1: /* Free functions */ jamie@1: jamie@1: #ifdef __cplusplus jamie@1: } jamie@1: #endif jamie@1: jamie@1: #endif