annotate xtract/xtract_scalar.h @ 47:c20e91e86f08

xtract_magnitude_spectrum() and xtract_peaks() share format of N/2 frequency values and N/2 magnitude coefficients. 'Fixed' xtract_loudness() so that N=1 can be used for specific loudness.
author Jamie Bullock <jamie@postlude.co.uk>
date Thu, 21 Dec 2006 11:31:51 +0000
parents e8f4c56de591
children 8703c202a247
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@2 21 /** \file xtract_scalar.h: declares functions that extract a feature as a single value from an input vector */
jamie@1 22
jamie@1 23 #ifndef XTRACT_SCALAR
jamie@1 24 #define XTRACT_SCALAR
jamie@1 25
jamie@1 26 #ifdef __cplusplus
jamie@1 27 extern "C" {
jamie@1 28 #endif
jamie@1 29
jamie@20 30 /**
jamie@20 31 * \defgroup scalar extraction functions
jamie@20 32 *
jamie@20 33 * Defines scalar extraction functions, and their parameters.
jamie@20 34 * @{
jamie@20 35 */
jamie@1 36
jamie@2 37 /** \brief Extract the mean of an input vector
jamie@2 38 *
jamie@2 39 * \param *data: a pointer to the first element in an array of floats
jamie@2 40 * \param N: the number of array elements to be considered
jamie@2 41 * \param *argv: a pointer to NULL
jamie@2 42 * \param *result: the mean of N values from the array pointed to by *data
jamie@2 43 */
jamie@43 44 int xtract_mean(const float *data, const int N, const void *argv, float *result);
jamie@1 45
jamie@2 46 /** \brief Extract the variance of an input vector
jamie@2 47 *
jamie@2 48 * \param *data: a pointer to the first element in an array of floats
jamie@2 49 * \param N: the number of elements to be considered
jamie@41 50 * \param *argv: a pointer to a float representing the mean of the input vector
jamie@2 51 * \param *result: the variance of N values from the array pointed to by *data
jamie@2 52 */
jamie@43 53 int xtract_variance(const float *data, const int N, const void *argv, float *result);
jamie@2 54
jamie@2 55 /** \brief Extract the deviation of an input vector
jamie@2 56 *
jamie@2 57 * \param *data: a pointer to the first element in an array of floats
jamie@2 58 * \param N: the number of elements to be considered
jamie@41 59 * \param *argv: a pointer to a float representing the variance of the input vector
jamie@2 60 * \param *result: the deviation of N values from the array pointed to by *data
jamie@2 61 */
jamie@43 62 int xtract_standard_deviation(const float *data, const int N, const void *argv, float *result);
jamie@2 63
jamie@2 64 /** \brief Extract the average deviation of an input vector
jamie@2 65 *
jamie@2 66 * \param *data: a pointer to the first element in an array of floats
jamie@2 67 * \param N: the number of elements to be considered
jamie@41 68 * \param *argv: a pointer to a float representing the mean of the input vector
jamie@2 69 * \param *result: the average deviation of N values from the array pointed to by *data
jamie@2 70 */
jamie@43 71 int xtract_average_deviation(const float *data, const int N, const void *argv, float *result);
jamie@2 72
jamie@2 73 /** \brief Extract the skewness of an input vector
jamie@2 74 *
jamie@2 75 * \param *data: a pointer to the first element in an array of floats
jamie@2 76 * \param N: the number of elements to be considered
jamie@41 77 * \param *argv: a pointer to an array of floats representing the mean and standard deviation of the input vector
jamie@2 78 * \param *result: the skewness of N values from the array pointed to by *data
jamie@2 79 */
jamie@43 80 int xtract_skewness(const float *data, const int N, const void *argv, float *result);
jamie@2 81
jamie@2 82 /** \brief Extract the kurtosis of an input vector
jamie@2 83 *
jamie@2 84 * \param *data: a pointer to the first element in an array of floats
jamie@2 85 * \param N: the number of elements to be considered
jamie@2 86 * \param *argv: a pointer to an array of values representing the mean and standard deviation of the input vector
jamie@2 87 * \param *result: the kurtosis of N values from the array pointed to by *data
jamie@2 88 */
jamie@43 89 int xtract_kurtosis(const float *data, const int N, const void *argv, float *result);
jamie@1 90
jamie@41 91 /** \brief Extract the centroid of an input vector
jamie@11 92 *
jamie@47 93 * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum().
jamie@11 94 * \param N: the number of elements to be considered
jamie@11 95 * \param *argv: a pointer to NULL
jamie@11 96 * \param *result: the centroid of the values pointed to by *data
jamie@47 97 *
jamie@47 98 * Note: for a more 'accurate' result *result from xtract_peaks() can be passed in. This gives the interpolated peak frequency locations.
jamie@47 99 *
jamie@11 100 */
jamie@43 101 int xtract_centroid(const float *data, const int N, const void *argv, float *result);
jamie@11 102
jamie@2 103 /** \brief Calculate the Irregularity of an input vector using a method described by Krimphoff (1994)
jamie@2 104 *
jamie@47 105 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 106 * \param N: the number of elements to be considered
jamie@2 107 * \param *argv: a pointer to NULL
jamie@2 108 * \param *result: the irregularity of N values from the array pointed to by *data
jamie@2 109 */
jamie@43 110 int xtract_irregularity_k(const float *data, const int N, const void *argv, float *result);
jamie@1 111
jamie@2 112 /** \brief Calculate the Irregularity of an input vector using a method described by Jensen (1999)
jamie@2 113 *
jamie@47 114 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 115 * \param N: the number of elements to be considered
jamie@2 116 * \param *argv: a pointer to NULL
jamie@2 117 * \param *result: the irregularity of N values from the array pointed to by *data
jamie@2 118 */
jamie@43 119 int xtract_irregularity_j(const float *data, const int N, const void *argv, float *result);
jamie@1 120
jamie@2 121 /** \brief Calculate the Tristimulus of an input vector using a method described by Pollard and Jansson (1982)
jamie@2 122 *
jamie@47 123 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the second half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peaks()) can be used if one wishes to consider all partials not just harmonics.
jamie@2 124 * \param N: the number of elements to be considered
jamie@2 125 * \param *argv: a pointer to NULL
jamie@2 126 * \param *result: the tristimulus of N values from the array pointed to by *data
jamie@2 127 *
jamie@2 128 * These three functions provide the first, second and third order tristimulus formulae
jamie@2 129 *
jamie@2 130 */
jamie@43 131 int xtract_tristimulus_1(const float *data, const int N, const void *argv, float *result);
jamie@43 132 int xtract_tristimulus_2(const float *data, const int N, const void *argv, float *result);
jamie@43 133 int xtract_tristimulus_3(const float *data, const int N, const void *argv, float *result);
jamie@1 134
jamie@2 135 /** \brief Extract the smoothness of an input vector using a method described by McAdams (1999)
jamie@2 136 *
jamie@47 137 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 138 * \param N: the number of elements to be considered
jamie@43 139 * \param *argv: a pointer to the first element of an array of integers containing the lower bound, upper bound, and pre-scaling factor, whereby array data in the range lower < n < upper will be pre-scaled by p before processing.
jamie@2 140 * \param *result: the smoothness of N values from the array pointed to by *data
jamie@2 141 */
jamie@43 142 int xtract_smoothness(const float *data, const int N, const void *argv, float *result);
jamie@1 143
jamie@2 144 /** \brief Extract the spectral spread of an input vector using a method described by Casagrande(2005)
jamie@2 145 *
jamie@47 146 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 147 * \param N: the number of elements to be considered
jamie@2 148 * \param *argv: a pointer to NULL
jamie@2 149 * \param *result: the spectral spread of N values from the array pointed to by *data
jamie@2 150 */
jamie@43 151 int xtract_spread(const float *data, const int N, const void *argv, float *result);
jamie@1 152
jamie@1 153 /* Zero crossing rate */
jamie@1 154
jamie@2 155 /** \brief Extract the zero crossing rate of an input vector
jamie@2 156 *
jamie@2 157 * \param *data: a pointer to the first element in an array of floats
jamie@2 158 * \param N: the number of elements to be considered
jamie@2 159 * \param *argv: a pointer to NULL
jamie@2 160 * \param *result: the zero crossing rate of N values from the array pointed to by *data
jamie@2 161 */
jamie@43 162 int xtract_zcr(const float *data, const int N, const void *argv, float *result);
jamie@1 163
jamie@2 164 /** \brief Extract the spectral rolloff of an input vector using a method described by Bee Suan Ong (2005)
jamie@2 165 *
jamie@47 166 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 167 * \param N: the number of elements to be considered
jamie@42 168 * \param *argv: a pointer to an array containing a floating point value representing the threshold for rolloff, i.e. the percentile at which the rolloff is determined, expressed in the range 0-1.0, and a float representing the sample rate in Hz
jamie@42 169 * \param *result: the spectral rolloff in Hz of N values from the array pointed to by *data. This is the point in the spectrum below which argv[0] of the energy is distributed.
jamie@2 170 */
jamie@43 171 int xtract_rolloff(const float *data, const int N, const void *argv, float *result);
jamie@1 172
jamie@1 173 /* Loudness */
jamie@1 174 /* A set of BARK_BANDS bark coefficients must be passed in, the loudness is calculated approximately according to Moore, Glasberg et al, 1997 */
jamie@1 175
jamie@47 176 /** \brief Extract the 'total loudness' of an input vector using a method described by Moore, Glasberg et al (2005)
jamie@2 177 *
jamie@2 178 * \param *data: a pointer to the first element in an array of floats representing a set of BARK_BANDS bark coefficients
jamie@2 179 * \param N: the number of coefficients to be considered
jamie@2 180 * \param *argv: a pointer to NULL
jamie@47 181 * \param *result: the total loudness of N values from the array pointed to by *data
jamie@47 182 *
jamie@47 183 * Note: if N = 1, the 'specific loudness' of the bark band pointed to by *data will be given by *result
jamie@47 184 *
jamie@2 185 */
jamie@43 186 int xtract_loudness(const float *data, const int N, const void *argv, float *result);
jamie@1 187
jamie@2 188 /** \brief Extract the spectral flatness measure of an input vector using a method described by Tristan Jehan (2005)
jamie@2 189 *
jamie@47 190 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 191 * \param N: the number of elements to be considered
jamie@2 192 * \param *argv: a pointer to NULL
jamie@2 193 * \param *result: the spectral flatness of N values from the array pointed to by *data
jamie@2 194 */
jamie@43 195 int xtract_flatness(const float *data, const int N, const void *argv, float *result);
jamie@1 196
jamie@1 197
jamie@2 198 /** \brief Extract the tonality factor of an input vector using a method described by Tristan Jehan (2005)
jamie@2 199 *
jamie@42 200 * \param *data: not used.
jamie@42 201 * \param N: not used
jamie@42 202 * \param *argv: a pointer to the spectral flatness measure of an audio vector (e.g. the output from xtract_flatness)
jamie@2 203 * \param *result: the tonality factor of N values from the array pointed to by *data
jamie@2 204 */
jamie@43 205 int xtract_tonality(const float *data, const int N, const void *argv, float *result);
jamie@1 206
jamie@2 207 /** \brief Extract the noisiness of an input vector using a method described by Tae Hong Park (2000)
jamie@2 208 *
jamie@47 209 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 210 * \param N: the number of elements to be considered
jamie@2 211 * \param *argv: a pointer to NULL
jamie@2 212 * \param *result: the noisiness of N values from the array pointed to by *data
jamie@2 213 */
jamie@43 214 int xtract_noisiness(const float *data, const int N, const void *argv, float *result);
jamie@1 215
jamie@2 216 /** \brief Extract the RMS amplitude of an input vector using a method described by Tae Hong Park (2000)
jamie@2 217 *
jamie@2 218 * \param *data: a pointer to the first element in an array of floats
jamie@2 219 * \param N: the number of elements to be considered
jamie@2 220 * \param *argv: a pointer to NULL
jamie@2 221 * \param *result: the RMS amplitude of N values from the array pointed to by *data
jamie@2 222 */
jamie@43 223 int xtract_rms_amplitude(const float *data, const int N, const void *argv, float *result);
jamie@1 224
jamie@2 225 /** \brief Extract the Inharmonicity of an input vector
jamie@2 226 *
jamie@41 227 * \param *data: a pointer to the first element in an array of floats represeting a frequency spectrum of size N/2 and a magnitude peak spectrum of size N/2 (This is the output format of xtract_peaks)
jamie@2 228 * \param N: the number of elements to be considered
jamie@41 229 * \param *argv: a pointer to a float representing the fundamental frequency of the input vector.
jamie@2 230 * \param *result: the inharmonicity of N values from the array pointed to by *data
jamie@2 231 */
jamie@43 232 int xtract_inharmonicity(const float *data, const int N, const void *argv, float *result);
jamie@1 233
jamie@2 234 /** \brief Extract the spectral crest of an input vector using a method described by Peeters (2003)
jamie@2 235 *
jamie@47 236 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 237 * \param N: the number of elements to be considered
jamie@2 238 * \param *argv: a pointer to NULL
jamie@2 239 * \param *result: the spectral crest of N values from the array pointed to by *data
jamie@2 240 */
jamie@43 241 int xtract_crest(const float *data, const int N, const void *argv, float *result);
jamie@1 242
jamie@2 243 /** \brief Extract the Spectral Power of an input vector using a method described by Bee Suan Ong (2005)
jamie@2 244 *
jamie@47 245 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 246 * \param N: the number of elements to be considered
jamie@2 247 * \param *argv: a pointer to NULL
jamie@2 248 * \param *result: the spectral power of N values from the array pointed to by *data
jamie@2 249 */
jamie@43 250 int xtract_power(const float *data, const int N, const void *argv, float *result);
jamie@1 251
jamie@1 252 /* Odd to even harmonic ratio */
jamie@2 253 /** \brief Extract the Odd to even harmonic ratio of an input vector
jamie@2 254 *
jamie@38 255 * \param *data: a pointer to the first element in an array of floats representing the frequencies of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to the array pointed to by *result from xtract_harmonics.
jamie@38 256 * \param N: the number of elements to be considered. If using the array pointed to by *result from xtract_harmonics, N should equal half the total array size i.e., just the frequencies of the peaks.
jamie@2 257 * \param *argv: a pointer to NULL
jamie@2 258 * \param *result: the odd/even harmonic ratio of N values from the array pointed to by *data
jamie@2 259 */
jamie@43 260 int xtract_odd_even_ratio(const float *data, const int N, const void *argv, float *result);
jamie@1 261
jamie@2 262 /** \brief Extract the Sharpness of an input vector
jamie@2 263 *
jamie@2 264 * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector
jamie@47 265 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 266 * \param N: the number of elements to be considered
jamie@2 267 * \param *argv: a pointer to NULL
jamie@2 268 * \param *result: the Sharpness of N values from the array pointed to by *data
jamie@2 269 */
jamie@43 270 int xtract_sharpness(const float *data, const int N, const void *argv, float *result);
jamie@1 271
jamie@2 272 /** \brief Extract the Slope of an input vector
jamie@2 273 *
jamie@2 274 * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector
jamie@47 275 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 276 * \param N: the number of elements to be considered
jamie@2 277 * \param *argv: a pointer to NULL
jamie@2 278 * \param *result: the Slope of N values from the array pointed to by *data
jamie@2 279 */
jamie@43 280 int xtract_slope(const float *data, const int N, const void *argv, float *result);
jamie@1 281
jamie@45 282 /** \brief Extract the value of the lowest value in an input vector
jamie@2 283 *
jamie@43 284 * \param *data: a pointer to the first element in an array of floats
jamie@2 285 * \param N: the number of elements to be considered
jamie@45 286 * \param *argv: a pointer to a float representing the lower limit for the search. i.e. (*result > *argv) returns 1.
jamie@45 287 * \param *result: a pointer to a value representing the lowest component in *data that falls above a given threshold.
jamie@2 288 *
jamie@43 289 */
jamie@45 290 int xtract_lowest_value(const float *data, const int N, const void *argv, float *result);
jamie@45 291
jamie@45 292 /** \brief Extract the value of the highest value in an input vector
jamie@45 293 *
jamie@45 294 * \param *data: a pointer to the first element in an array of floats
jamie@45 295 * \param N: the number of elements to be considered
jamie@45 296 * \param *argv: a pointer to NULL.
jamie@45 297 * \param *result: a pointer to a value representing the highest component in *data.
jamie@45 298 *
jamie@45 299 */
jamie@45 300 int xtract_highest_value(const float *data, const int N, const void *argv, float *result);
jamie@45 301
jamie@45 302 /** \brief Extract the sum of the values in an input vector
jamie@45 303 *
jamie@45 304 * \param *data: a pointer to the first element in an array of floats
jamie@45 305 * \param N: the number of elements to be considered
jamie@45 306 * \param *argv: a pointer to NULL.
jamie@45 307 * \param *result: a pointer to a value representing the sum of all of the values pointed to by *data.
jamie@45 308 *
jamie@45 309 */
jamie@45 310 int xtract_sum(const float *data, const int N, const void *argv, float *result);
jamie@1 311
jamie@2 312 /** \brief Extract the Pitch of an input vector using Harmonic Product Spectrum (HPS) analysis
jamie@2 313 *
jamie@22 314 * \warning {This function doesn't work properly}
jamie@22 315 *
jamie@47 316 * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum().
jamie@2 317 * \param N: the number of elements to be considered
jamie@2 318 * \param *argv: a pointer to NULL
jamie@2 319 * \param *result: the pitch of N values from the array pointed to by *data
jamie@2 320 */
jamie@43 321 int xtract_hps(const float *data, const int N, const void *argv, float *result);
jamie@1 322
jamie@5 323 /** \brief Extract the fundamental frequency of an input vector
jamie@5 324 *
jamie@5 325 * \param *data: a pointer to the first element in an array of floats representing an audio vector
jamie@5 326 * \param N: the number of elements to be considered
jamie@22 327 * \param *argv: a pointer to a float representing the audio sample rate
jamie@5 328 * \param *result: the pitch of N values from the array pointed to by *data
jamie@12 329 *
jamie@22 330 * This algorithm is based on the AMDF, with peak and centre clipping. It would benefit from further improvements to improve noise robustness and overall efficiency
jamie@12 331 *
jamie@5 332 */
jamie@43 333 int xtract_f0(const float *data, const int N, const void *argv, float *result);
jamie@43 334
jamie@43 335 /** \brief Extract the fundamental frequency of an input vector
jamie@43 336 *
jamie@43 337 * \param *data: a pointer to the first element in an array of floats representing an audio vector
jamie@43 338 * \param N: the number of elements to be considered
jamie@43 339 * \param *argv: a pointer to a float representing the audio sample rate
jamie@43 340 * \param *result: the pitch of N values from the array pointed to by *data
jamie@43 341 *
jamie@43 342 * This function wraps xtract_f0, but provides the frequency of the lowest partial in the peak spectrum if f0 can't be found.
jamie@43 343 *
jamie@43 344 */
jamie@43 345 int xtract_failsafe_f0(const float *data, const int N, const void *argv, float *result);
jamie@5 346
jamie@20 347 /** @} */
jamie@20 348
jamie@1 349 #ifdef __cplusplus
jamie@1 350 }
jamie@1 351 #endif
jamie@1 352
jamie@1 353 #endif
jamie@1 354
jamie@1 355
jamie@1 356