cannam@130: /* cannam@130: ** Copyright (c) 2002-2016, Erik de Castro Lopo cannam@130: ** All rights reserved. cannam@130: ** cannam@130: ** This code is released under 2-clause BSD license. Please see the cannam@130: ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING cannam@130: */ cannam@130: cannam@130: /* cannam@130: ** API documentation is available here: cannam@130: ** http://www.mega-nerd.com/SRC/api.html cannam@130: */ cannam@130: cannam@130: #ifndef SAMPLERATE_H cannam@130: #define SAMPLERATE_H cannam@130: cannam@130: #ifdef __cplusplus cannam@130: extern "C" { cannam@130: #endif /* __cplusplus */ cannam@130: cannam@130: cannam@130: /* Opaque data type SRC_STATE. */ cannam@130: typedef struct SRC_STATE_tag SRC_STATE ; cannam@130: cannam@130: /* SRC_DATA is used to pass data to src_simple() and src_process(). */ cannam@130: typedef struct cannam@130: { const float *data_in ; cannam@130: float *data_out ; cannam@130: cannam@130: long input_frames, output_frames ; cannam@130: long input_frames_used, output_frames_gen ; cannam@130: cannam@130: int end_of_input ; cannam@130: cannam@130: double src_ratio ; cannam@130: } SRC_DATA ; cannam@130: cannam@130: /* cannam@130: ** User supplied callback function type for use with src_callback_new() cannam@130: ** and src_callback_read(). First parameter is the same pointer that was cannam@130: ** passed into src_callback_new(). Second parameter is pointer to a cannam@130: ** pointer. The user supplied callback function must modify *data to cannam@130: ** point to the start of the user supplied float array. The user supplied cannam@130: ** function must return the number of frames that **data points to. cannam@130: */ cannam@130: cannam@130: typedef long (*src_callback_t) (void *cb_data, float **data) ; cannam@130: cannam@130: /* cannam@130: ** Standard initialisation function : return an anonymous pointer to the cannam@130: ** internal state of the converter. Choose a converter from the enums below. cannam@130: ** Error returned in *error. cannam@130: */ cannam@130: cannam@130: SRC_STATE* src_new (int converter_type, int channels, int *error) ; cannam@130: cannam@130: /* cannam@130: ** Initilisation for callback based API : return an anonymous pointer to the cannam@130: ** internal state of the converter. Choose a converter from the enums below. cannam@130: ** The cb_data pointer can point to any data or be set to NULL. Whatever the cannam@130: ** value, when processing, user supplied function "func" gets called with cannam@130: ** cb_data as first parameter. cannam@130: */ cannam@130: cannam@130: SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels, cannam@130: int *error, void* cb_data) ; cannam@130: cannam@130: /* cannam@130: ** Cleanup all internal allocations. cannam@130: ** Always returns NULL. cannam@130: */ cannam@130: cannam@130: SRC_STATE* src_delete (SRC_STATE *state) ; cannam@130: cannam@130: /* cannam@130: ** Standard processing function. cannam@130: ** Returns non zero on error. cannam@130: */ cannam@130: cannam@130: int src_process (SRC_STATE *state, SRC_DATA *data) ; cannam@130: cannam@130: /* cannam@130: ** Callback based processing function. Read up to frames worth of data from cannam@130: ** the converter int *data and return frames read or -1 on error. cannam@130: */ cannam@130: long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ; cannam@130: cannam@130: /* cannam@130: ** Simple interface for performing a single conversion from input buffer to cannam@130: ** output buffer at a fixed conversion ratio. cannam@130: ** Simple interface does not require initialisation as it can only operate on cannam@130: ** a single buffer worth of audio. cannam@130: */ cannam@130: cannam@130: int src_simple (SRC_DATA *data, int converter_type, int channels) ; cannam@130: cannam@130: /* cannam@130: ** This library contains a number of different sample rate converters, cannam@130: ** numbered 0 through N. cannam@130: ** cannam@130: ** Return a string giving either a name or a more full description of each cannam@130: ** sample rate converter or NULL if no sample rate converter exists for cannam@130: ** the given value. The converters are sequentially numbered from 0 to N. cannam@130: */ cannam@130: cannam@130: const char *src_get_name (int converter_type) ; cannam@130: const char *src_get_description (int converter_type) ; cannam@130: const char *src_get_version (void) ; cannam@130: cannam@130: /* cannam@130: ** Set a new SRC ratio. This allows step responses cannam@130: ** in the conversion ratio. cannam@130: ** Returns non zero on error. cannam@130: */ cannam@130: cannam@130: int src_set_ratio (SRC_STATE *state, double new_ratio) ; cannam@130: cannam@130: /* cannam@130: ** Get the current channel count. cannam@130: ** Returns negative on error, positive channel count otherwise cannam@130: */ cannam@130: cannam@130: int src_get_channels (SRC_STATE *state) ; cannam@130: cannam@130: /* cannam@130: ** Reset the internal SRC state. cannam@130: ** Does not modify the quality settings. cannam@130: ** Does not free any memory allocations. cannam@130: ** Returns non zero on error. cannam@130: */ cannam@130: cannam@130: int src_reset (SRC_STATE *state) ; cannam@130: cannam@130: /* cannam@130: ** Return TRUE if ratio is a valid conversion ratio, FALSE cannam@130: ** otherwise. cannam@130: */ cannam@130: cannam@130: int src_is_valid_ratio (double ratio) ; cannam@130: cannam@130: /* cannam@130: ** Return an error number. cannam@130: */ cannam@130: cannam@130: int src_error (SRC_STATE *state) ; cannam@130: cannam@130: /* cannam@130: ** Convert the error number into a string. cannam@130: */ cannam@130: const char* src_strerror (int error) ; cannam@130: cannam@130: /* cannam@130: ** The following enums can be used to set the interpolator type cannam@130: ** using the function src_set_converter(). cannam@130: */ cannam@130: cannam@130: enum cannam@130: { cannam@130: SRC_SINC_BEST_QUALITY = 0, cannam@130: SRC_SINC_MEDIUM_QUALITY = 1, cannam@130: SRC_SINC_FASTEST = 2, cannam@130: SRC_ZERO_ORDER_HOLD = 3, cannam@130: SRC_LINEAR = 4, cannam@130: } ; cannam@130: cannam@130: /* cannam@130: ** Extra helper functions for converting from short to float and cannam@130: ** back again. cannam@130: */ cannam@130: cannam@130: void src_short_to_float_array (const short *in, float *out, int len) ; cannam@130: void src_float_to_short_array (const float *in, short *out, int len) ; cannam@130: cannam@130: void src_int_to_float_array (const int *in, float *out, int len) ; cannam@130: void src_float_to_int_array (const float *in, int *out, int len) ; cannam@130: cannam@130: cannam@130: #ifdef __cplusplus cannam@130: } /* extern "C" */ cannam@130: #endif /* __cplusplus */ cannam@130: cannam@130: #endif /* SAMPLERATE_H */ cannam@130: