annotate xtract/libxtract.h @ 21:44e1a5363745

Further documentation improvements
author Jamie Bullock <jamie@postlude.co.uk>
date Thu, 12 Oct 2006 11:59:11 +0000
parents 8b8d4f1c5fb6
children 6417baefffc8
rev   line source
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@20 21 /** \mainpage
jamie@20 22 *
jamie@20 23 * LibXtract is a simple, portable, lightweight library of audio feature extraction functions. The purpose of the library is to provide a relatively exhaustive set of feature extraction primatives that are designed to be 'cascaded' to create a extraction hierarchies.
jamie@20 24 * For example, 'variance', 'average deviation', 'skewness' and 'kurtosis', all require the 'mean' of the input vector to be precomputed. However, rather than compute the 'mean' 'inside' each function, it is expected that the 'mean' will be passed in as an argument. This means that if the user wishes to use all of these features, the mean is calculated only once, and then passed to any functions that require it.
jamie@20 25 *
jamie@20 26 * This philosophy of 'cascading' features is followed throughout the library, for example with features that operate on the magnitude spectrum of a signal vector (e.g. 'irregularity'), the magnitude spectrum is not calculated 'inside' the respective function, instead, a pointer to the first element in an array containing the magnitude spectrum is passed in as an argument.
jamie@20 27 *
jamie@20 28 * Hopefully this not only makes the library more efficient when computing large numbers of features, but also makes it more flexible because extraction functions can be combined arbitrarily (one can take the irregularility of the Mel Frequency Cepstral Coefficients for example).
jamie@20 29 *
jamie@20 30 */
jamie@20 31
jamie@1 32 #ifndef XTRACT_H
jamie@1 33 #define XTRACT_H
jamie@1 34
jamie@1 35 #ifdef __cplusplus
jamie@1 36 extern "C" {
jamie@1 37 #endif
jamie@1 38
jamie@21 39 /**
jamie@21 40 * \file libxtract.h
jamie@21 41 * \brief main header file and API definition
jamie@1 42 */
jamie@1 43
jamie@1 44 #include "xtract_scalar.h"
jamie@1 45 #include "xtract_vector.h"
jamie@1 46 #include "xtract_delta.h"
jamie@1 47 #include "xtract_types.h"
jamie@1 48 #include "xtract_macros.h"
jamie@1 49
jamie@20 50 /** \defgroup libxtract API
jamie@20 51 *
jamie@20 52 * Defines a very simple API that provides access to the functions in the library
jamie@20 53 * @{
jamie@20 54 */
jamie@20 55
jamie@11 56 #define XTRACT_FEATURES 43
jamie@1 57 #define LOG_LIMIT 10e-10
jamie@5 58 #define VERY_BIG_NUMBER 2e10
jamie@1 59 #define SR_LIMIT 192000
jamie@1 60 #define BARK_BANDS 26
jamie@1 61
jamie@1 62 /** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
jamie@1 63 enum features_ {
jamie@1 64 MEAN,
jamie@1 65 VARIANCE,
jamie@1 66 STANDARD_DEVIATION,
jamie@1 67 AVERAGE_DEVIATION,
jamie@1 68 SKEWNESS,
jamie@1 69 KURTOSIS,
jamie@11 70 CENTROID,
jamie@1 71 IRREGULARITY_K,
jamie@1 72 IRREGULARITY_J,
jamie@1 73 TRISTIMULUS_1,
jamie@1 74 TRISTIMULUS_2,
jamie@1 75 TRISTIMULUS_3,
jamie@1 76 SMOOTHNESS,
jamie@1 77 SPREAD,
jamie@1 78 ZCR,
jamie@1 79 ROLLOFF,
jamie@1 80 LOUDNESS,
jamie@1 81 FLATNESS,
jamie@1 82 TONALITY,
jamie@1 83 CREST,
jamie@1 84 NOISINESS,
jamie@1 85 RMS_AMPLITUDE,
jamie@1 86 INHARMONICITY,
jamie@1 87 POWER,
jamie@1 88 ODD_EVEN_RATIO,
jamie@1 89 SHARPNESS,
jamie@1 90 SLOPE,
jamie@5 91 LOWEST_MATCH,
jamie@1 92 HPS,
jamie@9 93 F0,
jamie@1 94 MAGNITUDE_SPECTRUM,
jamie@1 95 AUTOCORRELATION,
jamie@1 96 AUTOCORRELATION_FFT,
jamie@1 97 AMDF,
jamie@1 98 ASDF,
jamie@1 99 MFCC,
jamie@1 100 DCT,
jamie@1 101 BARK_COEFFICIENTS,
jamie@1 102 PEAKS,
jamie@1 103 FLUX,
jamie@1 104 ATTACK_TIME,
jamie@1 105 DECAY_TIME,
jamie@1 106 DELTA_FEATURE
jamie@1 107 };
jamie@1 108
jamie@1 109 /** \brief Enumeration of feature types */
jamie@1 110 enum feature_types_ {
jamie@1 111 SCALAR,
jamie@1 112 VECTOR,
jamie@1 113 DELTA
jamie@1 114 };
jamie@1 115
jamie@1 116 /** \brief Enumeration of mfcc types */
jamie@1 117 enum mfcc_types_ {
jamie@1 118 EQUAL_GAIN,
jamie@1 119 EQUAL_AREA
jamie@1 120 };
jamie@1 121
jamie@1 122 /** \brief Enumeration of return codes */
jamie@1 123 enum return_codes_ {
jamie@1 124 SUCCESS,
jamie@1 125 MALLOC_FAILED,
jamie@1 126 BAD_ARGV,
jamie@12 127 BAD_VECTOR_SIZE,
jamie@12 128 NO_RESULT
jamie@1 129 };
jamie@1 130
jamie@1 131 /**
jamie@1 132 *
jamie@2 133 * \brief An array of pointers to functions that perform the extraction
jamie@1 134 *
jamie@2 135 * \param *data: a pointer to the start of the input data (usually the first element in an array)
jamie@1 136 *
jamie@2 137 * \param N: the number of elements to be processed
jamie@1 138 *
jamie@2 139 * \param *argv: an abitrary number of additional arguments, used to pass additional parameters to the function being called
jamie@1 140 *
jamie@2 141 * \param *result: a pointer to the first element in the result
jamie@1 142 *
jamie@1 143 * Each function will iterate over N array elements, the first of which is
jamie@2 144 * 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 145 *
jamie@1 146 * For scalar and delta features, *result will point to a single value.
jamie@1 147 *
jamie@1 148 * For vector features it will point to the first element in an array.
jamie@1 149 *
jamie@1 150 * Memory for this array must be allocated and freed by the calling
jamie@1 151 * function.
jamie@1 152 *
jamie@21 153 * All functions return an integer error code as descibed in the enumeration
jamie@21 154 * return_codes_
jamie@2 155 *
jamie@21 156 * The preprocessor macro: XTRACT must be defined before this can be used
jamie@9 157 *
jamie@2 158 * example:<br>
jamie@21 159 * \verbatim
jamie@21 160 #include <stdio.h>
jamie@21 161 #define XTRACT
jamie@21 162 #include "libxtract.h"
jamie@21 163
jamie@21 164 main () {
jamie@21 165 float values[] = {1.0, 2.0, 3.0, 4.0, 5.0};
jamie@21 166 int N = 5;
jamie@21 167 float mean;
jamie@21 168
jamie@21 169 xtract[MEAN]((void *)values, N, NULL, &mean);
jamie@21 170
jamie@21 171 printf("Mean = %.2f\n", mean);
jamie@21 172 }
jamie@21 173 \endverbatim
jamie@9 174 * The calling function may additionally make some tests against the value returned by xtract
jamie@9 175 *
jamie@2 176 */
jamie@9 177 #ifdef XTRACT
jamie@2 178 int(*xtract[XTRACT_FEATURES])(float *data, int N, void *argv, float *result);
jamie@9 179 #endif
jamie@1 180
jamie@2 181 /** \brief A structure to store a set of n_filters Mel filters */
jamie@1 182 typedef struct xtract_mel_filter_ {
jamie@1 183 int n_filters;
jamie@1 184 float **filters;
jamie@1 185 } xtract_mel_filter;
jamie@1 186
jamie@2 187 /** \brief A function to initialise a mel filter bank
jamie@2 188 *
jamie@2 189 * 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 190 */
jamie@1 191 int xtract_init_mfcc(int N, float nyquist, int style, float freq_max, float freq_min, int freq_bands, float **fft_tables);
jamie@1 192
jamie@2 193 /** \brief A function to initialise bark filter bounds
jamie@2 194 *
jamie@2 195 * 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 196 */
jamie@1 197 int xtract_init_bark(int N, float nyquist, int *band_limits);
jamie@1 198
jamie@1 199
jamie@1 200 /* Free functions */
jamie@1 201
jamie@20 202 /** @} */
jamie@20 203
jamie@1 204 #ifdef __cplusplus
jamie@1 205 }
jamie@1 206 #endif
jamie@1 207
jamie@1 208 #endif