Mercurial > hg > libxtract
comparison xtract/libxtract.h @ 146:baaa9d8b4d10
switched from single to double precision througout. closes #9
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Wed, 09 Jan 2013 12:45:29 +0000 |
parents | e4f704649c50 |
children | 246c203cc733 |
comparison
equal
deleted
inserted
replaced
145:2663eac093a5 | 146:baaa9d8b4d10 |
---|---|
30 * | 30 * |
31 * 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). | 31 * 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). |
32 * | 32 * |
33 * All feature extraction functions follow the same prototype: | 33 * All feature extraction functions follow the same prototype: |
34 * | 34 * |
35 int xtract_function_name(const float *data, const int N, const void *argv, float *result){ | 35 int xtract_function_name(const double *data, const int N, const void *argv, double *result){ |
36 * | 36 * |
37 * \param const float *data points to an array of floats representing the input data | 37 * \param const double *data points to an array of doubles representing the input data |
38 * \param const int N represents the number of elementes from *data to be considered in the calculation | 38 * \param const int N represents the number of elementes from *data to be considered in the calculation |
39 * \param const void *argv represents an arbitrary list of arguments. Used to pass in values required by the feature calculation | 39 * \param const void *argv represents an arbitrary list of arguments. Used to pass in values required by the feature calculation |
40 * \param float *result points to an array of floats, or a single float represnting the result of the calculation | 40 * \param double *result points to an array of doubles, or a single double represnting the result of the calculation |
41 * | 41 * |
42 * | 42 * |
43 * It is up to the calling function to allocate enough memory for the *data, *argv, and *result, and to free it when required. Some feature extraction functions may also require an _init() function to be called in order to perform some initialisation. The struct xtract_function_descriptor_t is used to give an indication of recommended default values, and argc for the *argv array. | 43 * It is up to the calling function to allocate enough memory for the *data, *argv, and *result, and to free it when required. Some feature extraction functions may also require an _init() function to be called in order to perform some initialisation. The struct xtract_function_descriptor_t is used to give an indication of recommended default values, and argc for the *argv array. |
44 * | 44 * |
45 * LibXtract can be downloaded from http://www.sf.net/projects/libxtract | 45 * LibXtract can be downloaded from http://www.sf.net/projects/libxtract |
280 | 280 |
281 int argc; | 281 int argc; |
282 | 282 |
283 struct { | 283 struct { |
284 xtract_type_t type; /* type of the array/value pointed to by argv */ | 284 xtract_type_t type; /* type of the array/value pointed to by argv */ |
285 float min[XTRACT_MAXARGS]; | 285 double min[XTRACT_MAXARGS]; |
286 float max[XTRACT_MAXARGS]; | 286 double max[XTRACT_MAXARGS]; |
287 float def[XTRACT_MAXARGS]; /* defaults */ | 287 double def[XTRACT_MAXARGS]; /* defaults */ |
288 xtract_unit_t unit[XTRACT_MAXARGS]; | 288 xtract_unit_t unit[XTRACT_MAXARGS]; |
289 int donor[XTRACT_MAXARGS]; /* suggested donor functions for argv */ | 289 int donor[XTRACT_MAXARGS]; /* suggested donor functions for argv */ |
290 } argv; | 290 } argv; |
291 | 291 |
292 xtract_bool_t is_scalar; | 292 xtract_bool_t is_scalar; |
294 | 294 |
295 /* The result.<> entries in descritors.c need to be checked */ | 295 /* The result.<> entries in descritors.c need to be checked */ |
296 union { | 296 union { |
297 | 297 |
298 struct { | 298 struct { |
299 float min; | 299 double min; |
300 float max; | 300 double max; |
301 xtract_unit_t unit; | 301 xtract_unit_t unit; |
302 } scalar; | 302 } scalar; |
303 | 303 |
304 struct { | 304 struct { |
305 xtract_vector_t format; | 305 xtract_vector_t format; |
342 #include <stdio.h> | 342 #include <stdio.h> |
343 #define XTRACT | 343 #define XTRACT |
344 #include "libxtract.h" | 344 #include "libxtract.h" |
345 | 345 |
346 main () { | 346 main () { |
347 float values[] = {1.0, 2.0, 3.0, 4.0, 5.0}; | 347 double values[] = {1.0, 2.0, 3.0, 4.0, 5.0}; |
348 int N = 5; | 348 int N = 5; |
349 float mean; | 349 double mean; |
350 | 350 |
351 xtract[MEAN]((void *)values, N, NULL, &mean); | 351 xtract[MEAN]((void *)values, N, NULL, &mean); |
352 | 352 |
353 printf("Mean = %.2f\n", mean); | 353 printf("Mean = %.2f\n", mean); |
354 } | 354 } |
355 \endverbatim | 355 \endverbatim |
356 * The calling function may additionally make some tests against the value returned by xtract | 356 * The calling function may additionally make some tests against the value returned by xtract |
357 * | 357 * |
358 */ | 358 */ |
359 #ifdef XTRACT_H | 359 #ifdef XTRACT_H |
360 extern int(*xtract[XTRACT_FEATURES])(const float *data, const int N, const void *argv, float *result); | 360 extern int(*xtract[XTRACT_FEATURES])(const double *data, const int N, const void *argv, double *result); |
361 | 361 |
362 #endif | 362 #endif |
363 | 363 |
364 /** \brief A structure to store a set of n_filters Mel filters */ | 364 /** \brief A structure to store a set of n_filters Mel filters */ |
365 typedef struct xtract_mel_filter_ { | 365 typedef struct xtract_mel_filter_ { |
366 int n_filters; | 366 int n_filters; |
367 float **filters; | 367 double **filters; |
368 } xtract_mel_filter; | 368 } xtract_mel_filter; |
369 | 369 |
370 /** \brief A function to initialise a mel filter bank | 370 /** \brief A function to initialise a mel filter bank |
371 * | 371 * |
372 * 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 | 372 * 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 |
373 */ | 373 */ |
374 int xtract_init_mfcc(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, float **fft_tables); | 374 int xtract_init_mfcc(int N, double nyquist, int style, double freq_min, double freq_max, int freq_bands, double **fft_tables); |
375 | 375 |
376 /** \brief A function to initialise bark filter bounds | 376 /** \brief A function to initialise bark filter bounds |
377 * | 377 * |
378 * 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 | 378 * 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 |
379 * | 379 * |
380 * \param N: the audio block size | 380 * \param N: the audio block size |
381 * \param sr: The sample audio sample rate | 381 * \param sr: The sample audio sample rate |
382 * \param *band_limits: a pointer to an array of BARK_BANDS ints | 382 * \param *band_limits: a pointer to an array of BARK_BANDS ints |
383 */ | 383 */ |
384 int xtract_init_bark(int N, float sr, int *band_limits); | 384 int xtract_init_bark(int N, double sr, int *band_limits); |
385 | 385 |
386 /** \brief An initialisation function for functions using FFT | 386 /** \brief An initialisation function for functions using FFT |
387 * | 387 * |
388 * This function initialises global data structures used by functions requiring FFT functionality. It can be called multiple times with different feature names. Calling it more than once with the same feature name is not a valid operation and will result in a memory leak. | 388 * This function initialises global data structures used by functions requiring FFT functionality. It can be called multiple times with different feature names. Calling it more than once with the same feature name is not a valid operation and will result in a memory leak. |
389 * | 389 * |
404 * | 404 * |
405 * \param N: the size of the window | 405 * \param N: the size of the window |
406 * \param type: the type of the window as given in the enumeration window_types_ | 406 * \param type: the type of the window as given in the enumeration window_types_ |
407 * | 407 * |
408 */ | 408 */ |
409 float *xtract_init_window(const int N, const int type); | 409 double *xtract_init_window(const int N, const int type); |
410 | 410 |
411 /** \brief Free a window as allocated by xtract_make_window() | 411 /** \brief Free a window as allocated by xtract_make_window() |
412 * | 412 * |
413 * \param *window: a pointer to an array of floats as allocated by xtract_make_window() | 413 * \param *window: a pointer to an array of doubles as allocated by xtract_make_window() |
414 * | 414 * |
415 */ | 415 */ |
416 void xtract_free_window(float *window); | 416 void xtract_free_window(double *window); |
417 | 417 |
418 /* \brief A function to build an array of function descriptors */ | 418 /* \brief A function to build an array of function descriptors */ |
419 xtract_function_descriptor_t *xtract_make_descriptors(); | 419 xtract_function_descriptor_t *xtract_make_descriptors(); |
420 | 420 |
421 /* \brief A function to free an array of function descriptors */ | 421 /* \brief A function to free an array of function descriptors */ |