annotate xtract/xtract_scalar.h @ 205:f6fcf3bec020

Add xtract_midicent() convenience function to convert from frequency to MIDI cent
author Jamie Bullock <jamie@jamiebullock.com>
date Tue, 11 Mar 2014 18:14:45 +0000
parents 02b7b3f96713
children 44401945d850
rev   line source
jamie@141 1 /*
jamie@141 2 * Copyright (C) 2012 Jamie Bullock
jamie@1 3 *
jamie@141 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
jamie@141 5 * of this software and associated documentation files (the "Software"), to
jamie@141 6 * deal in the Software without restriction, including without limitation the
jamie@141 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
jamie@141 8 * sell copies of the Software, and to permit persons to whom the Software is
jamie@141 9 * furnished to do so, subject to the following conditions:
jamie@1 10 *
jamie@141 11 * The above copyright notice and this permission notice shall be included in
jamie@141 12 * all copies or substantial portions of the Software.
jamie@1 13 *
jamie@141 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jamie@141 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jamie@141 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jamie@141 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jamie@141 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
jamie@141 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
jamie@141 20 * IN THE SOFTWARE.
jamie@141 21 *
jamie@1 22 */
jamie@1 23
jamie@2 24 /** \file xtract_scalar.h: declares functions that extract a feature as a single value from an input vector */
jamie@1 25
jamie@56 26 #ifndef XTRACT_SCALAR_H
jamie@56 27 #define XTRACT_SCALAR_H
jamie@1 28
jamie@1 29 #ifdef __cplusplus
jamie@1 30 extern "C" {
jamie@1 31 #endif
jamie@1 32
jamie@20 33 /**
jamie@83 34 * \defgroup scalar scalar extraction functions
jamie@116 35 *
jamie@116 36 * Functions that extract a feature as a single value from an input vector
jamie@20 37 *
jamie@20 38 * @{
jamie@20 39 */
jamie@1 40
jamie@2 41 /** \brief Extract the mean of an input vector
jamie@2 42 *
jamie@52 43 * \param *data: a pointer to the first element
jamie@2 44 * \param N: the number of array elements to be considered
jamie@2 45 * \param *argv: a pointer to NULL
jamie@2 46 * \param *result: the mean of N values from the array pointed to by *data
jamie@2 47 */
jamie@146 48 int xtract_mean(const double *data, const int N, const void *argv, double *result);
jamie@1 49
jamie@2 50 /** \brief Extract the variance of an input vector
jamie@2 51 *
jamie@146 52 * \param *data: a pointer to the first element in an array of doubles
jamie@2 53 * \param N: the number of elements to be considered
jamie@146 54 * \param *argv: a pointer to a double representing the mean of the input vector
jamie@2 55 * \param *result: the variance of N values from the array pointed to by *data
jamie@2 56 */
jamie@146 57 int xtract_variance(const double *data, const int N, const void *argv, double *result);
jamie@2 58
jamie@2 59 /** \brief Extract the deviation of an input vector
jamie@2 60 *
jamie@146 61 * \param *data: a pointer to the first element in an array of doubles
jamie@2 62 * \param N: the number of elements to be considered
jamie@146 63 * \param *argv: a pointer to a double representing the variance of the input vector
jamie@2 64 * \param *result: the deviation of N values from the array pointed to by *data
jamie@2 65 */
jamie@146 66 int xtract_standard_deviation(const double *data, const int N, const void *argv, double *result);
jamie@2 67
jamie@2 68 /** \brief Extract the average deviation of an input vector
jamie@2 69 *
jamie@146 70 * \param *data: a pointer to the first element in an array of doubles
jamie@2 71 * \param N: the number of elements to be considered
jamie@146 72 * \param *argv: a pointer to a double representing the mean of the input vector
jamie@2 73 * \param *result: the average deviation of N values from the array pointed to by *data
jamie@2 74 */
jamie@146 75 int xtract_average_deviation(const double *data, const int N, const void *argv, double *result);
jamie@125 76
jamie@2 77
jamie@2 78 /** \brief Extract the skewness of an input vector
jamie@2 79 *
jamie@146 80 * \param *data: a pointer to the first element in an array of doubles
jamie@2 81 * \param N: the number of elements to be considered
jamie@146 82 * \param *argv: a pointer to an array of doubles representing the mean and standard deviation of the input vector
jamie@2 83 * \param *result: the skewness of N values from the array pointed to by *data
jamie@2 84 */
jamie@146 85 int xtract_skewness(const double *data, const int N, const void *argv, double *result);
jamie@2 86
jamie@2 87 /** \brief Extract the kurtosis of an input vector
jamie@2 88 *
jamie@146 89 * \param *data: a pointer to the first element in an array of doubles
jamie@2 90 * \param N: the number of elements to be considered
jamie@2 91 * \param *argv: a pointer to an array of values representing the mean and standard deviation of the input vector
jamie@2 92 * \param *result: the kurtosis of N values from the array pointed to by *data
jamie@2 93 */
jamie@146 94 int xtract_kurtosis(const double *data, const int N, const void *argv, double *result);
jamie@1 95
jamie@52 96 /** \brief Extract the mean of an input spectrum
jamie@52 97 *
jamie@146 98 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 99 * \param N: the size of the array pointed to by *data
jamie@52 100 * \param *argv: a pointer to NULL
jamie@52 101 * \param *result: the mean of the spectrum pointed to by *data
jamie@52 102 */
jamie@146 103 int xtract_spectral_mean(const double *data, const int N, const void *argv, double *result);
jamie@52 104
jamie@52 105 /** \brief Extract the variance of an input spectrum
jamie@52 106 *
jamie@146 107 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 108 * \param N: the number of elements to be considered
jamie@52 109 * \param N: the size of the array pointed to by *data
jamie@146 110 * \param *argv: a pointer to a double representing the spectral mean of the input spectrum
jamie@52 111 * \param *result: the variance of the spectrum pointed to by *data
jamie@52 112 */
jamie@146 113 int xtract_spectral_variance(const double *data, const int N, const void *argv, double *result);
jamie@52 114
jamie@52 115 /** \brief Extract the deviation of an input spectrum
jamie@52 116 *
jamie@146 117 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 118 * \param N: the size of the array pointed to by *data
jamie@146 119 * \param *argv: a pointer to a double representing the spectral variance of the input spectrum
jamie@52 120 * \param *result: the deviation of the spectrum pointed to by *data
jamie@52 121 */
jamie@146 122 int xtract_spectral_standard_deviation(const double *data, const int N, const void *argv, double *result);
jamie@52 123
jamie@52 124 /** \brief Extract the average deviation of an input spectrum
jamie@52 125 *
jamie@146 126 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 127 * \param N: the size of the array pointed to by *data
jamie@146 128 * \param *argv: a pointer to a double representing the spectral mean of the input spectrum
jamie@52 129 * \param *result: the average deviation of the spectrum pointed to by *data
jamie@52 130 */
jamie@125 131 /*
jamie@146 132 int xtract_spectral_average_deviation(const double *data, const int N, const void *argv, double *result);
jamie@125 133 */
jamie@52 134
jamie@52 135 /** \brief Extract the skewness of an input spectrum
jamie@52 136 *
jamie@146 137 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 138 * \param N: the size of the array pointed to by *data
jamie@146 139 * \param *argv: a pointer to an array of doubles representing the spectral mean and spectral standard deviation of the input spectrum
jamie@52 140 * \param *result: the skewness of the spectrum pointed to by *data
jamie@52 141 */
jamie@146 142 int xtract_spectral_skewness(const double *data, const int N, const void *argv, double *result);
jamie@52 143
jamie@52 144 /** \brief Extract the kurtosis of an input spectrum
jamie@52 145 *
jamie@146 146 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@52 147 * \param N: the size of the array pointed to by *data
jamie@59 148 * \param *argv: a pointer to an array of values representing the spectral mean and spectral standard deviation of the input spectrum
jamie@52 149 * \param *result: the kurtosis of the spectrum pointed to by *data
jamie@52 150 */
jamie@146 151 int xtract_spectral_kurtosis(const double *data, const int N, const void *argv, double *result);
jamie@52 152
jamie@41 153 /** \brief Extract the centroid of an input vector
jamie@11 154 *
jamie@146 155 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@11 156 * \param N: the number of elements to be considered
jamie@11 157 * \param *argv: a pointer to NULL
jamie@11 158 * \param *result: the centroid of the values pointed to by *data
jamie@47 159 *
jamie@78 160 * Note: for a more 'accurate' result *result from xtract_peak_spectrum() can be passed in. This gives the interpolated peak frequency locations.
jamie@47 161 *
jamie@11 162 */
jamie@146 163 int xtract_spectral_centroid(const double *data, const int N, const void *argv, double *result);
jamie@11 164
jamie@2 165 /** \brief Calculate the Irregularity of an input vector using a method described by Krimphoff (1994)
jamie@2 166 *
jamie@146 167 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 168 * \param N: the number of elements to be considered
jamie@2 169 * \param *argv: a pointer to NULL
jamie@2 170 * \param *result: the irregularity of N values from the array pointed to by *data
jamie@2 171 */
jamie@146 172 int xtract_irregularity_k(const double *data, const int N, const void *argv, double *result);
jamie@1 173
jamie@2 174 /** \brief Calculate the Irregularity of an input vector using a method described by Jensen (1999)
jamie@2 175 *
jamie@146 176 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 177 * \param N: the number of elements to be considered
jamie@2 178 * \param *argv: a pointer to NULL
jamie@2 179 * \param *result: the irregularity of N values from the array pointed to by *data
jamie@2 180 */
jamie@146 181 int xtract_irregularity_j(const double *data, const int N, const void *argv, double *result);
jamie@1 182
jamie@2 183 /** \brief Calculate the Tristimulus of an input vector using a method described by Pollard and Jansson (1982)
jamie@2 184 *
jamie@146 185 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the first half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peak_spectrum()) can be used if one wishes to consider all partials not just harmonics.
jamie@2 186 * \param N: the number of elements to be considered
jamie@2 187 * \param *argv: a pointer to NULL
jamie@2 188 * \param *result: the tristimulus of N values from the array pointed to by *data
jamie@2 189 *
jamie@2 190 * These three functions provide the first, second and third order tristimulus formulae
jamie@2 191 *
jamie@2 192 */
jamie@146 193 int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result);
jamie@146 194 int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result);
jamie@146 195 int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result);
jamie@1 196
jamie@2 197 /** \brief Extract the smoothness of an input vector using a method described by McAdams (1999)
jamie@2 198 *
jamie@146 199 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 200 * \param N: the number of elements to be considered
jamie@183 201 * \param *argv: a pointer to NULL
jamie@2 202 * \param *result: the smoothness of N values from the array pointed to by *data
jamie@2 203 */
jamie@146 204 int xtract_smoothness(const double *data, const int N, const void *argv, double *result);
jamie@1 205
jamie@2 206 /** \brief Extract the spectral spread of an input vector using a method described by Casagrande(2005)
jamie@2 207 *
jamie@146 208 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 209 * \param N: the number of elements to be considered
jamie@146 210 * \param *argv: a pointer to a double corresponding to the spectral centroid
jamie@2 211 * \param *result: the spectral spread of N values from the array pointed to by *data
jamie@2 212 */
jamie@146 213 int xtract_spread(const double *data, const int N, const void *argv, double *result);
jamie@1 214
jamie@1 215 /* Zero crossing rate */
jamie@1 216
jamie@2 217 /** \brief Extract the zero crossing rate of an input vector
jamie@2 218 *
jamie@146 219 * \param *data: a pointer to the first element in an array of doubles
jamie@2 220 * \param N: the number of elements to be considered
jamie@2 221 * \param *argv: a pointer to NULL
jamie@2 222 * \param *result: the zero crossing rate of N values from the array pointed to by *data
jamie@2 223 */
jamie@146 224 int xtract_zcr(const double *data, const int N, const void *argv, double *result);
jamie@1 225
jamie@2 226 /** \brief Extract the spectral rolloff of an input vector using a method described by Bee Suan Ong (2005)
jamie@2 227 *
jamie@146 228 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 229 * \param N: the number of elements to be considered
jamie@146 230 * \param *argv: a pointer to an array containing a double representing (samplerate / N ) and a double representing the threshold for rolloff, i.e. the percentile at which the rolloff is determined, expressed as a percentage, and
jamie@42 231 * \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 232 */
jamie@146 233 int xtract_rolloff(const double *data, const int N, const void *argv, double *result);
jamie@1 234
jamie@47 235 /** \brief Extract the 'total loudness' of an input vector using a method described by Moore, Glasberg et al (2005)
jamie@2 236 *
jamie@146 237 * \param *data: a pointer to the first element in an array of doubles representing a set of BARK_BANDS bark coefficients
jamie@2 238 * \param N: the number of coefficients to be considered
jamie@2 239 * \param *argv: a pointer to NULL
jamie@47 240 * \param *result: the total loudness of N values from the array pointed to by *data
jamie@47 241 *
jamie@47 242 * Note: if N = 1, the 'specific loudness' of the bark band pointed to by *data will be given by *result
jamie@47 243 *
jamie@2 244 */
jamie@146 245 int xtract_loudness(const double *data, const int N, const void *argv, double *result);
jamie@1 246
jamie@113 247 /** \brief Extract the spectral flatness measure of an input vector, where the flatness measure (SFM) is defined as the ratio of the geometric mean to the arithmetic mean of a magnitude spectrum.
jamie@113 248 *
jamie@113 249 * \note The computation method used here is the most efficient by a significant margin, but suffers from precision problems due to the multiplication operationin the geometric mean calculation. This is particularly accute for larger values of N (>=256). However, as noted by Peeters (2003), the SFM should generally be computed on a small number of 'bands' rather than on the complete magnitude spectrum. It is therefore highly recommended that xtract_bands() is used prior to calling xtract_flatness().
jamie@2 250 *
jamie@146 251 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum(). Alternatively the magnitudes from a number of 'subbands' can be used by using *result from xtract_bands().
jamie@113 252 * \param N: the number of *data array elements to be considered
jamie@2 253 * \param *argv: a pointer to NULL
jamie@113 254 * \param *result: the flatness of N values from the array pointed to by *data
jamie@2 255 */
jamie@146 256 int xtract_flatness(const double *data, const int N, const void *argv, double *result);
jamie@1 257
jamie@113 258 /** \brief Extract the LOG spectral flatness measure of an input vector
jamie@113 259 *
jamie@113 260 * \param *data: a pointer to NULL.
jamie@113 261 * \param N: not used - can safely be set to 0.
jamie@146 262 * \param *argv: a pointer to a double represnting spectral flatness.
jamie@113 263 * \param *result: the LOG spectral flatness of N values from the array pointed to by *data
jamie@113 264 *
jamie@113 265 * flatness_db = 10 * log10(flatness)
jamie@113 266 *
jamie@113 267 */
jamie@146 268 int xtract_flatness_db(const double *data, const int N, const void *argv, double *result);
jamie@1 269
jamie@113 270 /** \brief Extract the tonality factor of an input vector using a method described by Peeters 2003
jamie@2 271 *
jamie@113 272 * \param *data: a pointer to NULL.
jamie@113 273 * \param N: not used - can safely be set to 0.
jamie@113 274 * \param *argv: a pointer to the LOG spectral flatness measure of an audio vector (e.g. the output from xtract_flatness_db)
jamie@2 275 * \param *result: the tonality factor of N values from the array pointed to by *data
jamie@2 276 */
jamie@146 277 int xtract_tonality(const double *data, const int N, const void *argv, double *result);
jamie@1 278
jamie@2 279 /** \brief Extract the noisiness of an input vector using a method described by Tae Hong Park (2000)
jamie@2 280 *
jamie@55 281 * \param *data: a pointer to NULL
jamie@55 282 * \param N:
jamie@146 283 * \param *argv: a pointer to an array containing a double represnting the number of harmonic partials in a spectrum, and a double representing the number of partials in a spectrum
jamie@55 284 * \param *result: the noisiness coefficient as calculated from argv
jamie@2 285 */
jamie@146 286 int xtract_noisiness(const double *data, const int N, const void *argv, double *result);
jamie@1 287
jamie@2 288 /** \brief Extract the RMS amplitude of an input vector using a method described by Tae Hong Park (2000)
jamie@2 289 *
jamie@146 290 * \param *data: a pointer to the first element in an array of doubles
jamie@2 291 * \param N: the number of elements to be considered
jamie@2 292 * \param *argv: a pointer to NULL
jamie@2 293 * \param *result: the RMS amplitude of N values from the array pointed to by *data
jamie@2 294 */
jamie@146 295 int xtract_rms_amplitude(const double *data, const int N, const void *argv, double *result);
jamie@1 296
jamie@2 297 /** \brief Extract the Inharmonicity of an input vector
jamie@2 298 *
jamie@146 299 * \param *data: a pointer to the first element in an array of doubles represeting a magnitude peak spectrum of size N/2, and a frequency spectrum of size N/2 (This is the output format of xtract_peak_spectrum())
jamie@2 300 * \param N: the number of elements to be considered
jamie@146 301 * \param *argv: a pointer to a double representing the fundamental frequency of the input vector.
jamie@2 302 * \param *result: the inharmonicity of N values from the array pointed to by *data
jamie@2 303 */
jamie@146 304 int xtract_spectral_inharmonicity(const double *data, const int N, const void *argv, double *result);
jamie@1 305
jamie@2 306 /** \brief Extract the spectral crest of an input vector using a method described by Peeters (2003)
jamie@2 307 *
jamie@55 308 * \param *data: a pointer to NULL
jamie@55 309 * \param N: not used
jamie@146 310 * \param *argv: a pointer to an array containing a double representing the maximum value in a spectrum, and a double representing the mean value of a spectrum
jamie@2 311 * \param *result: the spectral crest of N values from the array pointed to by *data
jamie@2 312 */
jamie@146 313 int xtract_crest(const double *data, const int N, const void *argv, double *result);
jamie@1 314
jamie@2 315 /** \brief Extract the Spectral Power of an input vector using a method described by Bee Suan Ong (2005)
jamie@2 316 *
jamie@146 317 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 318 * \param N: the number of elements to be considered
jamie@2 319 * \param *argv: a pointer to NULL
jamie@2 320 * \param *result: the spectral power of N values from the array pointed to by *data
jamie@2 321 */
jamie@146 322 int xtract_power(const double *data, const int N, const void *argv, double *result);
jamie@1 323
jamie@1 324 /* Odd to even harmonic ratio */
jamie@2 325 /** \brief Extract the Odd to even harmonic ratio of an input vector
jamie@2 326 *
jamie@146 327 * \param *data: a pointer to the first element in an array of doubles representing the amplitudes of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to the first half of the array pointed to by *result from xtract_harmonic_spectrum().
jamie@59 328 * \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 amplitudes of the peaks.
jamie@59 329 * \param *argv: a pointer to NULL
jamie@113 330 * \param *result: the even/odd harmonic ratio of N values from the array pointed to by *data
jamie@2 331 */
jamie@146 332 int xtract_odd_even_ratio(const double *data, const int N, const void *argv, double *result);
jamie@1 333
jamie@2 334 /** \brief Extract the Sharpness of an input vector
jamie@2 335 *
jamie@146 336 * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients from the spectrum of an audio vector, (e.g. the first half of the array pointed to by *result from xtract_spectrum().
jamie@2 337 * \param N: the number of elements to be considered
jamie@2 338 * \param *argv: a pointer to NULL
jamie@2 339 * \param *result: the Sharpness of N values from the array pointed to by *data
jamie@2 340 */
jamie@146 341 int xtract_sharpness(const double *data, const int N, const void *argv, double *result);
jamie@1 342
jamie@48 343 /** \brief Extract the Slope of an input vector using a method described by Peeters(2003)
jamie@2 344 *
jamie@146 345 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_spectrum(), xtract_peak_spectrum() or xtract_harmonic_spectrum()).
jamie@2 346 * \param N: the number of elements to be considered
jamie@2 347 * \param *argv: a pointer to NULL
jamie@2 348 * \param *result: the Slope of N values from the array pointed to by *data
jamie@2 349 */
jamie@146 350 int xtract_spectral_slope(const double *data, const int N, const void *argv, double *result);
jamie@1 351
jamie@45 352 /** \brief Extract the value of the lowest value in an input vector
jamie@2 353 *
jamie@146 354 * \param *data: a pointer to the first element in an array of doubles
jamie@2 355 * \param N: the number of elements to be considered
jamie@192 356 * \param *argv: a pointer to a double representing the lower limit for the search. All values in the array pointed to by *data that are below or equal to this threshold will be ignored.
jamie@45 357 * \param *result: a pointer to a value representing the lowest component in *data that falls above a given threshold.
jamie@192 358 *
jamie@192 359 * \return XTRACT_SUCCESS is a lowest value was found or XTRACT_NO_VALUE if all values
jamie@192 360 * in the array pointed to by *data are below or equal to the threshold set with *argv
jamie@192 361 *
jamie@192 362 * \note If XTRACT_NO_VALUE is returned, *result will be set to DBL_MAX
jamie@2 363 *
jamie@43 364 */
jamie@146 365 int xtract_lowest_value(const double *data, const int N, const void *argv, double *result);
jamie@45 366
jamie@45 367 /** \brief Extract the value of the highest value in an input vector
jamie@45 368 *
jamie@146 369 * \param *data: a pointer to the first element in an array of doubles
jamie@45 370 * \param N: the number of elements to be considered
jamie@45 371 * \param *argv: a pointer to NULL.
jamie@45 372 * \param *result: a pointer to a value representing the highest component in *data.
jamie@45 373 *
jamie@45 374 */
jamie@146 375 int xtract_highest_value(const double *data, const int N, const void *argv, double *result);
jamie@45 376
jamie@45 377 /** \brief Extract the sum of the values in an input vector
jamie@45 378 *
jamie@146 379 * \param *data: a pointer to the first element in an array of doubles
jamie@45 380 * \param N: the number of elements to be considered
jamie@45 381 * \param *argv: a pointer to NULL.
jamie@45 382 * \param *result: a pointer to a value representing the sum of all of the values pointed to by *data.
jamie@45 383 *
jamie@45 384 */
jamie@146 385 int xtract_sum(const double *data, const int N, const void *argv, double *result);
jamie@1 386
jamie@2 387 /** \brief Extract the Pitch of an input vector using Harmonic Product Spectrum (HPS) analysis
jamie@2 388 *
sean@197 389 * \param *data: a pointer to the first element in an array of doubles representing the spectrum of an audio vector (e.g. *result from xtract_spectrum). It is expected that the first half of the array pointed to by *data will contain amplitudes for each frequecy bin, and the second half will contain the respective frequencies
sean@197 390 * \param N: The length of the vector pointed to by *data.
jamie@2 391 * \param *argv: a pointer to NULL
jamie@2 392 * \param *result: the pitch of N values from the array pointed to by *data
jamie@2 393 */
jamie@146 394 int xtract_hps(const double *data, const int N, const void *argv, double *result);
jamie@1 395
jamie@5 396 /** \brief Extract the fundamental frequency of an input vector
jamie@5 397 *
jamie@146 398 * \param *data: a pointer to the first element in an array of doubles representing an audio vector
jamie@5 399 * \param N: the number of elements to be considered
jamie@146 400 * \param *argv: a pointer to a double representing the audio sample rate
jamie@5 401 * \param *result: the pitch of N values from the array pointed to by *data
jamie@12 402 *
jamie@22 403 * 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@117 404 *
jamie@117 405 * It is based on suggestion by Robert Bristow-Johnson in a discussion on the comp.dsp mailing list, subject "Reference implementation of pitch detection"
jamie@12 406 *
jamie@5 407 */
jamie@146 408 int xtract_f0(const double *data, const int N, const void *argv, double *result);
jamie@43 409
jamie@43 410 /** \brief Extract the fundamental frequency of an input vector
jamie@43 411 *
jamie@146 412 * \param *data: a pointer to the first element in an array of doubles representing an audio vector
jamie@43 413 * \param N: the number of elements to be considered
jamie@146 414 * \param *argv: a pointer to a double representing the audio sample rate
jamie@43 415 * \param *result: the pitch of N values from the array pointed to by *data
jamie@43 416 *
jamie@43 417 * 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 418 *
jamie@43 419 */
jamie@146 420 int xtract_failsafe_f0(const double *data, const int N, const void *argv, double *result);
jamie@5 421
jamie@161 422 /** \brief Extract the fundamental frequency of an input vector using wavelet-based method
jamie@161 423 *
jamie@161 424 * \param *data: a pointer to the first element in an array of doubles representing an audio vector
jamie@161 425 * \param N: the number of elements to be considered
jamie@161 426 * \param *argv: a pointer to a double representing the audio sample rate
jamie@161 427 * \param *result: the pitch of N values from the array pointed to by *data
jamie@161 428 *
jamie@161 429 * This function uses the time-domain wavelet-based method described in Larson and Maddox (2005) and
jamie@161 430 * implemented in the dywapitchtrack library
jamie@161 431 *
jamie@161 432 * xtract_init_wavelet_f0_state() must be called exactly once prior to calling xtract_wavelet_f0()
jamie@161 433 *
jamie@161 434 */
jamie@161 435 int xtract_wavelet_f0(const double *data, const int N, const void *argv, double *result);
jamie@161 436
jamie@205 437
jamie@205 438 /** \brief Convenience function to convert a frequency in Hertz to a "pitch" value in MIDI cents
jamie@205 439 *
jamie@205 440 * \param *data: not used
jamie@205 441 * \param N: not used
jamie@205 442 * \param *argv: a pointer to a double-precision floating point value representing a frequency in Hertz
jamie@205 443 * \param *result: a pointer to a double-precision floating point value representing a "pitch" in MIDI cents
jamie@205 444 * \return if *argv value causes a *result within the range 0..127, XTRACT_SUCCESS will be returned, otherwise XTRACT_ARGUMENT_ERROR
jamie@205 445 *
jamie@205 446 */
jamie@205 447 int xtract_midicent(const double *data, const int N, const void *argv, double *result);
jamie@205 448
jamie@205 449
jamie@59 450 /** \brief Extract the number of non-zero elements in an input vector
jamie@59 451 *
jamie@146 452 * \param *data: a pointer to the first element in an array of doubles
jamie@59 453 * \param N: the number of elements to be considered
jamie@59 454 * \param *argv: not used
jamie@59 455 * \param *result: the number of non-zero elements in the array pointed to by *data
jamie@59 456 *
jamie@59 457 */
jamie@146 458 int xtract_nonzero_count(const double *data, const int N, const void *argv, double *result);
jamie@59 459
jamie@20 460 /** @} */
jamie@20 461
jamie@1 462 #ifdef __cplusplus
jamie@1 463 }
jamie@1 464 #endif
jamie@1 465
jamie@1 466 #endif
jamie@1 467
jamie@1 468
jamie@1 469