diff options
Diffstat (limited to 'xtract')
-rw-r--r-- | xtract/libxtract.h | 10 | ||||
-rw-r--r-- | xtract/xtract_helper.h | 11 | ||||
-rw-r--r-- | xtract/xtract_scalar.h | 27 | ||||
-rw-r--r-- | xtract/xtract_stateful.h | 67 |
4 files changed, 111 insertions, 4 deletions
diff --git a/xtract/libxtract.h b/xtract/libxtract.h index c5140d4..8c20980 100644 --- a/xtract/libxtract.h +++ b/xtract/libxtract.h @@ -71,7 +71,7 @@ extern "C" { * @{ */ -#define XTRACT_FEATURES 60 +#define XTRACT_FEATURES 61 /** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */ enum xtract_features_ { @@ -117,6 +117,7 @@ enum xtract_features_ { XTRACT_F0, XTRACT_FAILSAFE_F0, XTRACT_WAVELET_F0, + XTRACT_MIDICENT, XTRACT_LNORM, XTRACT_FLUX, XTRACT_ATTACK_TIME, @@ -171,9 +172,11 @@ enum xtract_return_codes_ { XTRACT_MALLOC_FAILED, XTRACT_BAD_ARGV, XTRACT_BAD_VECTOR_SIZE, + XTRACT_BAD_STATE, XTRACT_DENORMAL_FOUND, XTRACT_NO_RESULT, /* This usually occurs when the correct calculation cannot take place because required data is missing or would result in a NaN or infinity/-infinity. Under these curcumstances 0.f is usually given by *result */ - XTRACT_FEATURE_NOT_IMPLEMENTED + XTRACT_FEATURE_NOT_IMPLEMENTED, + XTRACT_ARGUMENT_ERROR }; /** \brief Enumeration of spectrum types */ @@ -207,7 +210,8 @@ typedef enum unit_ { XTRACT_DBFS_HERTZ, XTRACT_PERCENT, XTRACT_BINS, - XTRACT_SONE + XTRACT_SONE, + XTRACT_MIDI_CENT } xtract_unit_t; /** \brief Boolean */ diff --git a/xtract/xtract_helper.h b/xtract/xtract_helper.h index bc5b892..9dabfbc 100644 --- a/xtract/xtract_helper.h +++ b/xtract/xtract_helper.h @@ -30,7 +30,16 @@ extern "C" { #endif -#include <stdbool.h> +#ifdef _MSC_VER + #ifndef __cplusplus + typedef int bool; + #define false 0 + #define true 1 + #endif +#else + #include <stdbool.h> +#endif + /** * \defgroup helper helper functions diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index 4461623..8e24284 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -434,6 +434,19 @@ int xtract_failsafe_f0(const double *data, const int N, const void *argv, double */ int xtract_wavelet_f0(const double *data, const int N, const void *argv, double *result); + +/** \brief Convenience function to convert a frequency in Hertz to a "pitch" value in MIDI cents + * + * \param *data: not used + * \param N: not used + * \param *argv: a pointer to a double-precision floating point value representing a frequency in Hertz + * \param *result: a pointer to a double-precision floating point value representing a "pitch" in MIDI cents + * \return if *argv value causes a *result within the range 0..127, XTRACT_SUCCESS will be returned, otherwise XTRACT_ARGUMENT_ERROR + * + */ +int xtract_midicent(const double *data, const int N, const void *argv, double *result); + + /** \brief Extract the number of non-zero elements in an input vector * * \param *data: a pointer to the first element in an array of doubles @@ -444,6 +457,20 @@ int xtract_wavelet_f0(const double *data, const int N, const void *argv, double */ int xtract_nonzero_count(const double *data, const int N, const void *argv, double *result); +/** + * \brief Return XTRACT_SUCCESS if the 'current' value is considered a peak + * + * @param data a pointer to an array containing time series as provided by *result from xtract_last_n() where the Nth value is considered the 'current' value + * @param N an integer representing the number of elements in the time series + * @param argv a pointer to a double representing the threshold, whereby the current value will be considered a peak if it is above the average of the last N values (*data) by the threshold + * @param result a pointer to a copy of the current value if the current value is considered a peak + * + * + * @return XTRACT_SUCCESS if a peak was found or XTRACT_NO_RESULT if not + */ +int xtract_peak(const double *data, const int N, const void *argv, double *result); + + /** @} */ #ifdef __cplusplus diff --git a/xtract/xtract_stateful.h b/xtract/xtract_stateful.h new file mode 100644 index 0000000..e26926d --- /dev/null +++ b/xtract/xtract_stateful.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2012 Jamie Bullock + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +/** \file xtract_stateful.h: declares functions that extract features that require stateful data to be retained between frames */ +#ifndef XTRACT_STATEFUL_H +#define XTRACT_STATEFUL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \defgroup stateful feature extraction functions and data structures + * + * Functions that extract a feature over multiple frames + * + * @{ + */ + + +#include <stdint.h> +#include <string.h> + +struct ringbuf_t; +typedef struct ringbuf_t *ringbuf_t; +typedef struct xtract_last_n_state_ xtract_last_n_state; + +xtract_last_n_state *xtract_last_n_state_new(size_t capacity); +void xtract_last_n_state_delete(xtract_last_n_state *last_n_state); + + +/** + * Write a vector of the last N input values to `result` + * + * @param state a pointer to an xtract_peak_picker_state struct as allocated by xtract_peak_picker_state_new() + * @param data a pointer to a double representing the current input value + * @param N an integer representing 'N' the number of values to be written to *result + * @param argv a pointer to NULL + * @param result a pointer to an array of doubles representing the last N values, where the nth value is the current one. The array must have been allocated to size N elements and initialised by the caller + * + */ +int xtract_last_n(const xtract_last_n_state *state, const double *data, const int N, const void *argv, double *result); + + + + +#endif |