|
LibXtract 1.6.0
|
Data Structures | |
| struct | _xtract_function_descriptor |
| Data structure containing useful information about functions provided by LibXtract. More... | |
| struct | xtract_mel_filter_ |
| A structure to store a set of n_filters Mel filters. More... | |
Macros | |
| #define | XTRACT_FEATURES XTRACT_FEATURE_COUNT |
Typedefs | |
| typedef enum type_ | xtract_type_t |
| Enumeration of data types. | |
| typedef enum unit_ | xtract_unit_t |
| Enumeration of units. | |
| typedef enum xtract_vector_ | xtract_vector_t |
| Enumeration of vector format types. | |
| typedef struct _xtract_function_descriptor | xtract_function_descriptor_t |
| Data structure containing useful information about functions provided by LibXtract. | |
| typedef struct xtract_mel_filter_ | xtract_mel_filter |
| A structure to store a set of n_filters Mel filters. | |
| typedef struct xtract_cqt_kernel_ | xtract_cqt_kernel |
| The kernel xtract_cqt() applies, built by xtract_init_cqt() and freed by xtract_free_cqt(). | |
Enumerations | |
| enum | xtract_features_ { XTRACT_MEAN , XTRACT_VARIANCE , XTRACT_STANDARD_DEVIATION , XTRACT_AVERAGE_DEVIATION , XTRACT_SKEWNESS , XTRACT_KURTOSIS , XTRACT_SPECTRAL_MEAN , XTRACT_SPECTRAL_VARIANCE , XTRACT_SPECTRAL_STANDARD_DEVIATION , XTRACT_SPECTRAL_SKEWNESS , XTRACT_SPECTRAL_KURTOSIS , XTRACT_SPECTRAL_CENTROID , XTRACT_IRREGULARITY_K , XTRACT_IRREGULARITY_J , XTRACT_TRISTIMULUS_1 , XTRACT_TRISTIMULUS_2 , XTRACT_TRISTIMULUS_3 , XTRACT_SMOOTHNESS , XTRACT_SPREAD , XTRACT_ZCR , XTRACT_ROLLOFF , XTRACT_LOUDNESS , XTRACT_FLATNESS , XTRACT_FLATNESS_DB , XTRACT_TONALITY , XTRACT_CREST , XTRACT_NOISINESS , XTRACT_RMS_AMPLITUDE , XTRACT_SPECTRAL_INHARMONICITY , XTRACT_POWER , XTRACT_ODD_EVEN_RATIO , XTRACT_SHARPNESS , XTRACT_SPECTRAL_SLOPE , XTRACT_LOWEST_VALUE , XTRACT_HIGHEST_VALUE , XTRACT_SUM , XTRACT_NONZERO_COUNT , XTRACT_HPS , XTRACT_F0 , XTRACT_FAILSAFE_F0 , XTRACT_WAVELET_F0 , XTRACT_MCLEOD_F0 , XTRACT_MIDICENT , XTRACT_LNORM , XTRACT_FLUX , XTRACT_ATTACK_TIME , XTRACT_DECAY_TIME , XTRACT_DIFFERENCE_VECTOR , XTRACT_AUTOCORRELATION , XTRACT_AMDF , XTRACT_ASDF , XTRACT_BARK_COEFFICIENTS , XTRACT_PEAK_SPECTRUM , XTRACT_SPECTRUM , XTRACT_AUTOCORRELATION_FFT , XTRACT_MFCC , XTRACT_DCT , XTRACT_HARMONIC_SPECTRUM , XTRACT_LPC , XTRACT_LPCC , XTRACT_SUBBANDS , XTRACT_MEL_SPECTROGRAM , XTRACT_GFCC , XTRACT_GAMMATONE_SPECTROGRAM , XTRACT_WINDOWED , XTRACT_SMOOTHED , XTRACT_PEAK , XTRACT_MMBSES , XTRACT_SPECTRAL_SUBBAND_CENTROIDS , XTRACT_MOVING_SUM , XTRACT_MOVING_AVERAGE , XTRACT_MOVING_VARIANCE , XTRACT_MOVING_STANDARD_DEVIATION , XTRACT_MOVING_MAX , XTRACT_MOVING_MIN , XTRACT_EWMA_AVERAGE , XTRACT_EWMA_VARIANCE , XTRACT_MEDIAN , XTRACT_MEDIAN_ABSOLUTE_DEVIATION , XTRACT_HJORTH_ACTIVITY , XTRACT_HJORTH_MOBILITY , XTRACT_HJORTH_COMPLEXITY , XTRACT_TIME_REVERSAL_ASYMMETRY , XTRACT_SPECTRAL_ENTROPY , XTRACT_PETROSIAN_FRACTAL_DIMENSION , XTRACT_KATZ_FRACTAL_DIMENSION , XTRACT_HIGUCHI_FRACTAL_DIMENSION , XTRACT_PERMUTATION_ENTROPY , XTRACT_LEMPEL_ZIV_COMPLEXITY , XTRACT_SAMPLE_ENTROPY , XTRACT_APPROXIMATE_ENTROPY , XTRACT_PERIODICITY , XTRACT_SIGNAL_CONFIDENCE , XTRACT_DECAY_RATE , XTRACT_TEMPORAL_CENTROID , XTRACT_MAX_POSITION , XTRACT_MIN_POSITION , XTRACT_PEAK_ASYMMETRY , XTRACT_CROSS_CORRELATION , XTRACT_CROSS_CORRELATION_LAG , XTRACT_KULLBACK_LEIBLER_DIVERGENCE , XTRACT_ITAKURA_SAITO_DIVERGENCE , XTRACT_MODIFIED_KULLBACK_LEIBLER , XTRACT_SPECTRAL_CONTRAST , XTRACT_CHROMA , XTRACT_CQT , XTRACT_PEARSON_CORRELATION , XTRACT_COVARIANCE_MATRIX , XTRACT_CORRELATION_MATRIX , XTRACT_AVERAGE_CORRELATION , XTRACT_PRINCIPAL_VARIANCES , XTRACT_COHERENCE , XTRACT_GRID_MOMENTS , XTRACT_GRID_CENTRAL_MOMENTS , XTRACT_NORMALISED_MOMENTS , XTRACT_HU_MOMENTS , XTRACT_QUANTISE , XTRACT_HISTOGRAM , XTRACT_COOCCURRENCE_MATRIX , XTRACT_COOCCURRENCE_CONTRAST , XTRACT_COOCCURRENCE_CORRELATION , XTRACT_ANGULAR_SECOND_MOMENT , XTRACT_INVERSE_DIFFERENCE_MOMENT , XTRACT_LOCAL_BINARY_PATTERNS , XTRACT_FEATURE_COUNT } |
| Enumeration of features, elements are used as indices to an array of pointers to feature extraction functions. | |
| enum | xtract_feature_init_ { XTRACT_INIT_MFCC = 100 , XTRACT_INIT_BARK , XTRACT_INIT_WINDOWED , XTRACT_INIT_GFCC , XTRACT_INIT_CQT } |
| Enumeration of feature initialisation functions. | |
| enum | xtract_feature_types_ { XTRACT_SCALAR , XTRACT_VECTOR , XTRACT_DELTA } |
| Enumeration of feature types. | |
| enum | xtract_mfcc_types_ { XTRACT_EQUAL_GAIN , XTRACT_EQUAL_AREA } |
| Enumeration of MFCC types. More... | |
| enum | xtract_lnorm_filter_types_ { XTRACT_NO_LNORM_FILTER , XTRACT_POSITIVE_SLOPE , XTRACT_NEGATIVE_SLOPE } |
| enum | xtract_return_codes_ { XTRACT_SUCCESS , XTRACT_MALLOC_FAILED , XTRACT_BAD_ARGV , XTRACT_BAD_VECTOR_SIZE , XTRACT_BAD_STATE , XTRACT_DENORMAL_FOUND , XTRACT_NO_RESULT , XTRACT_FEATURE_NOT_IMPLEMENTED , XTRACT_ARGUMENT_ERROR } |
| Enumeration of return codes. More... | |
| enum | xtract_spectrum_ { XTRACT_MAGNITUDE_SPECTRUM , XTRACT_LOG_MAGNITUDE_SPECTRUM , XTRACT_POWER_SPECTRUM , XTRACT_LOG_POWER_SPECTRUM , XTRACT_MAGNITUDE_PHASE_SPECTRUM } |
| Enumeration of spectrum types. | |
| enum | xtract_subband_scales_ { XTRACT_OCTAVE_SUBBANDS , XTRACT_LINEAR_SUBBANDS } |
| Subband scales. | |
| enum | type_ { XTRACT_FLOAT , XTRACT_FLOATARRAY , XTRACT_INT , XTRACT_MEL_FILTER , XTRACT_CQT_KERNEL } |
| Enumeration of data types. | |
| enum | unit_ { XTRACT_UNIT_UNKNOWN = -2 , XTRACT_UNIT_ANY = -1 , XTRACT_UNIT_NONE = 0 , XTRACT_HERTZ = 2 , XTRACT_ANY_AMPLITUDE_HERTZ , XTRACT_DBFS , XTRACT_DBFS_HERTZ , XTRACT_PERCENT , XTRACT_BINS , XTRACT_SONE , XTRACT_MIDI_CENT , XTRACT_ACUM , XTRACT_SECONDS , XTRACT_PER_SECOND } |
| Enumeration of units. | |
| enum | xtract_bool_t { XTRACT_FALSE , XTRACT_TRUE } |
| Boolean. | |
| enum | xtract_window_types_ { XTRACT_GAUSS , XTRACT_HAMMING , XTRACT_HANN , XTRACT_BARTLETT , XTRACT_TRIANGULAR , XTRACT_BARTLETT_HANN , XTRACT_BLACKMAN , XTRACT_KAISER , XTRACT_BLACKMAN_HARRIS } |
| Window types. | |
| enum | xtract_vector_ { XTRACT_SPECTRAL , XTRACT_SPECTRAL_MAGNITUDES , XTRACT_SPECTRAL_PEAKS , XTRACT_SPECTRAL_PEAKS_MAGNITUDES , XTRACT_SPECTRAL_PEAKS_FREQUENCIES , XTRACT_SPECTRAL_HARMONICS , XTRACT_SPECTRAL_HARMONICS_MAGNITUDES , XTRACT_SPECTRAL_HARMONICS_FREQUENCIES , XTRACT_AUTOCORRELATION_COEFFS , XTRACT_ARBITRARY_SERIES , XTRACT_AUDIO_SAMPLES , XTRACT_MEL_COEFFS , XTRACT_LPC_COEFFS , XTRACT_LPCC_COEFFS , XTRACT_BARK_COEFFS , XTRACT_SUBFRAMES , XTRACT_NO_DATA , XTRACT_SPECTRAL_MAGNITUDE_PHASE , XTRACT_CHROMA_COEFFS , XTRACT_CHANNELS , XTRACT_SQUARE_MATRIX , XTRACT_GRID , XTRACT_CENTRAL_MOMENT_COEFFS , XTRACT_NORMALISED_MOMENT_COEFFS } |
| Enumeration of vector format types. | |
Functions | |
| int | xtract_init_wavelet_f0_state (void) |
| A function to initialise wavelet f0 detector state. | |
| 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. | |
| 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. | |
| int | xtract_init_bark (int N, double sr, int *band_limits) |
| A function to initialise bark filter bounds. | |
| int | xtract_init_fft (int N, int feature_name) |
| An initialisation function for functions using FFT. | |
| void | xtract_free_fft (void) |
| Free memory used for FFT plans. | |
| double * | xtract_init_window (const int N, const int type) |
| Make a window of a given type and return a pointer to it. | |
| void | xtract_free_window (double *window) |
| Free a window as allocated by xtract_make_window(). | |
| double * | xtract_init_dct (const int N) |
| A function to initialise a cosine table for xtract_dct(). | |
| void | xtract_free_dct (double *table) |
| Free a table as allocated by xtract_init_dct(). | |
| 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(). | |
| void | xtract_free_cqt (xtract_cqt_kernel *kernel) |
| Free a kernel as allocated by xtract_init_cqt(). | |
| xtract_function_descriptor_t * | xtract_make_descriptors (void) |
| int | xtract_free_descriptors (xtract_function_descriptor_t *fd) |
Variables | |
| 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. | |
Defines a very simple API that provides access to the functions in the library
| typedef struct xtract_mel_filter_ xtract_mel_filter |
A structure to store a set of n_filters Mel filters.
Zero-initialise the structure, or set every field, before passing it to a feature function. The feature functions accept any n_filters of at least 1, so a structure filled by hand may hold a single filter; xtract_init_mfcc() and xtract_init_gfcc() build at least 2. dct_table is the cosine table used by xtract_mfcc() and xtract_gfcc() for their final DCT: either the result of xtract_init_dct(n_filters), which the caller frees with xtract_free_dct(), or NULL to have the cosines evaluated on each call.
| enum xtract_mfcc_types_ |
Enumeration of MFCC types.
Mel filterbank gain styles for xtract_init_mfcc(): XTRACT_EQUAL_GAIN gives every filter a peak gain of 1; XTRACT_EQUAL_AREA scales each filter's height inversely to its bandwidth so that every filter has the same area, with the first filter's peak gain 1
| enum xtract_return_codes_ |
Enumeration of return codes.
Every feature function returns one of these. A code other than XTRACT_SUCCESS means the result is not usable.
XTRACT_ARGUMENT_ERROR: the caller broke the function's contract: N below the documented minimum, a NULL argv where one is required, an argv value outside its documented range, or more elements than the fixed table the function applies. A scalar result is set to 0, a vector result is left untouched, and nothing is computed.
XTRACT_NO_RESULT: the arguments are valid but the data has no answer, such as a zero amplitude sum, a zero denominator or no periodicity. The result is set to 0.
XTRACT_BAD_STATE: the initialisation the function needs is missing or was done for a different size. The result is left untouched.
XTRACT_BAD_ARGV, XTRACT_BAD_VECTOR_SIZE and XTRACT_DENORMAL_FOUND are deprecated: XTRACT_ARGUMENT_ERROR is returned in their place, and they will be removed in 2.0.
| void xtract_free_cqt | ( | xtract_cqt_kernel * | kernel | ) |
Free a kernel as allocated by xtract_init_cqt().
| *kernel | a pointer to a kernel as allocated by xtract_init_cqt(), or NULL |
| void xtract_free_dct | ( | double * | table | ) |
Free a table as allocated by xtract_init_dct().
| *table | a pointer to a table as allocated by xtract_init_dct(), or NULL |
| void xtract_free_fft | ( | void | ) |
Free memory used for FFT plans.
This function frees the memory allocated by xtract_init_fft() on the calling thread for every feature. A thread that ends before the process must call this function first, since no other thread can free its memory; the memory of a thread still running when the process exits is reclaimed with the process.
| void xtract_free_window | ( | double * | window | ) |
Free a window as allocated by xtract_make_window().
| *window | a pointer to an array of doubles as allocated by xtract_make_window() |
| int xtract_init_bark | ( | int | N, |
| double | sr, | ||
| int * | band_limits ) |
A function to initialise bark filter bounds.
A pointer to an array of XTRACT_BARK_BANDS ints must be passed in, and is populated with the bin number at which each band starts, on the bin grid of an N-point transform with DC at bin 0. The spectrum these limits are applied to by xtract_bark_coefficients() therefore has N / 2 elements, element k being bin k
| N | the size of the transform the band limits will be applied to |
| sr | the sample rate |
| *band_limits | a pointer to an array of XTRACT_BARK_BANDS ints |
| 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().
The kernel has n_bins bands, bins_per_octave to the octave from fmin upward, each analysing Q cycles of its centre frequency through a Hann window, where Q = 1 / (2^(1 / bins_per_octave) - 1). A tone at a band's centre frequency reads half its amplitude, as a tone centred on a bin of xtract_spectrum() does. Building the kernel evaluates every band at every bin of the transform, so it is done once and kept for every frame of the same size.
| N | the size of the transform whose spectrum xtract_cqt() will be given, at least 2 and even. The lowest band's window must fit in N samples: Q times the sample rate divided by fmin, which for 12 bands to the octave from 32.7 Hz at 44100 Hz is about 22680, so N must then be at least 22680, and 32768 when the spectrum comes from an FFT of xtract_init_fft(), whose size is a power of two |
| sr | the sample rate in Hz, finite and at least 0, with 0 selecting 44100 |
| fmin | the centre frequency of the lowest band in Hz, finite and above 0; 32.7, the C two octaves below middle C, is usual |
| bins_per_octave | the number of bands to the octave, at least 1; 12 is usual |
| n_bins | the number of bands, at least 1. The highest band's passband must stay below half the sample rate: its centre frequency times 1 + 1 / (2 Q); 84 bands at 12 to the octave is usual |
| threshold | the fraction of a band's largest kernel coefficient below which its coefficients are left out, from 0 to 1; 0.01 is usual and 0 keeps every coefficient |
| double * xtract_init_dct | ( | const int | N | ) |
A function to initialise a cosine table for xtract_dct().
| N | the transform size |
| int xtract_init_fft | ( | int | N, |
| int | feature_name ) |
An initialisation function for functions using FFT.
This function initialises global data structures used by functions requiring FFT functionality. It can be called multiple times with different feature names. Calling it again with a feature name already initialised replaces that feature's FFT with one of the new size and leaves the FFTs of the other features unchanged. The data structures belong to the calling thread, so every thread that calls a function using the FFT must call xtract_init_fft() itself, and a thread that ends before the process must call xtract_free_fft() first.
| N | the size of the FFT, a power of two of at least 2 |
| feature_name | the name of the feature the FFT is being used for, e.g. XTRACT_DCT |
| 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.
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 gammatone filterbank on the ERB scale.
| N | the size of the transform the filters will be applied to; coefficient k of each array is the filter's gain at bin k, at frequency k * nyquist / (N / 2), and coefficients from N / 2 upward are zero |
| nyquist | the Nyquist frequency |
| freq_min | the minimum frequency for the filter bank |
| freq_max | the maximum frequency for the filter bank |
| freq_bands | the number of gammatone filters, at least 2 |
| **fft_tables | an array of pointers to arrays of length N, to be populated with filter coefficients |
| 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.
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 the coefficients of freq_bands triangular filters whose peaks are equally spaced on the mel scale from freq_min, each filter spanning the peaks either side of its own and the first rising from 0 Hz (Rabiner and Juang 1993, section 4.5.6). Coefficient k of each array is the filter's gain at bin k of an N-point transform with DC included, at frequency k * nyquist / (N / 2); coefficients from N / 2 upward are zero.
| N | the size of the transform the filters will be applied to |
| nyquist | half the sample rate |
| style | XTRACT_EQUAL_GAIN or XTRACT_EQUAL_AREA, as given in the enumeration xtract_mfcc_types_ |
| freq_min | the peak frequency of the first filter |
| freq_max | the frequency the peaks step towards, reached one step beyond the last filter |
| freq_bands | the number of filters, at least 2 |
| **fft_tables | an array of pointers to arrays of length N, to be populated with filter coefficients |
| double * xtract_init_window | ( | const int | N, |
| const int | type ) |
Make a window of a given type and return a pointer to it.
| N | the size of the window |
| type | the type of the window as given in the enumeration window_types_ |
|
extern |
An array of pointers to functions that perform the extraction.
Every function takes the same four arguments:
Each function will iterate over N array elements, the first of which is 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.
For scalar and delta features, *result will point to a single value.
For vector features it will point to the first element in an array.
Memory for this array must be allocated and freed by the calling function.
All functions return an integer error code as described in the enumeration return_codes_
example:
#include <stdio.h>
#include "libxtract.h"
int main(void) {
double values[] = {1.0, 2.0, 3.0, 4.0, 5.0};
int N = 5;
double mean;
xtract[XTRACT_MEAN](values, N, NULL, &mean);
printf("Mean = %.2f\n", mean);
}
The calling function may additionally make some tests against the value returned by xtract