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