cannam@87: /* cannam@87: ** Copyright (C) 2002-2011 Erik de Castro Lopo cannam@87: ** cannam@87: ** This program is free software; you can redistribute it and/or modify cannam@87: ** it under the terms of the GNU General Public License as published by cannam@87: ** the Free Software Foundation; either version 2 of the License, or cannam@87: ** (at your option) any later version. cannam@87: ** cannam@87: ** This program is distributed in the hope that it will be useful, cannam@87: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@87: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@87: ** GNU General Public License for more details. cannam@87: ** cannam@87: ** You should have received a copy of the GNU General Public License cannam@87: ** along with this program; if not, write to the Free Software cannam@87: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. cannam@87: */ cannam@87: cannam@87: /* cannam@87: ** This code is part of Secret Rabbit Code aka libsamplerate. A commercial cannam@87: ** use license for this code is available, please see: cannam@87: ** http://www.mega-nerd.com/SRC/procedure.html cannam@87: */ cannam@87: cannam@87: /* cannam@87: ** API documentation is available here: cannam@87: ** http://www.mega-nerd.com/SRC/api.html cannam@87: */ cannam@87: cannam@87: #ifndef SAMPLERATE_H cannam@87: #define SAMPLERATE_H cannam@87: cannam@87: #ifdef __cplusplus cannam@87: extern "C" { cannam@87: #endif /* __cplusplus */ cannam@87: cannam@87: cannam@87: /* Opaque data type SRC_STATE. */ cannam@87: typedef struct SRC_STATE_tag SRC_STATE ; cannam@87: cannam@87: /* SRC_DATA is used to pass data to src_simple() and src_process(). */ cannam@87: typedef struct cannam@87: { float *data_in, *data_out ; cannam@87: cannam@87: long input_frames, output_frames ; cannam@87: long input_frames_used, output_frames_gen ; cannam@87: cannam@87: int end_of_input ; cannam@87: cannam@87: double src_ratio ; cannam@87: } SRC_DATA ; cannam@87: cannam@87: /* SRC_CB_DATA is used with callback based API. */ cannam@87: typedef struct cannam@87: { long frames ; cannam@87: float *data_in ; cannam@87: } SRC_CB_DATA ; cannam@87: cannam@87: /* cannam@87: ** User supplied callback function type for use with src_callback_new() cannam@87: ** and src_callback_read(). First parameter is the same pointer that was cannam@87: ** passed into src_callback_new(). Second parameter is pointer to a cannam@87: ** pointer. The user supplied callback function must modify *data to cannam@87: ** point to the start of the user supplied float array. The user supplied cannam@87: ** function must return the number of frames that **data points to. cannam@87: */ cannam@87: cannam@87: typedef long (*src_callback_t) (void *cb_data, float **data) ; cannam@87: cannam@87: /* cannam@87: ** Standard initialisation function : return an anonymous pointer to the cannam@87: ** internal state of the converter. Choose a converter from the enums below. cannam@87: ** Error returned in *error. cannam@87: */ cannam@87: cannam@87: SRC_STATE* src_new (int converter_type, int channels, int *error) ; cannam@87: cannam@87: /* cannam@87: ** Initilisation for callback based API : return an anonymous pointer to the cannam@87: ** internal state of the converter. Choose a converter from the enums below. cannam@87: ** The cb_data pointer can point to any data or be set to NULL. Whatever the cannam@87: ** value, when processing, user supplied function "func" gets called with cannam@87: ** cb_data as first parameter. cannam@87: */ cannam@87: cannam@87: SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels, cannam@87: int *error, void* cb_data) ; cannam@87: cannam@87: /* cannam@87: ** Cleanup all internal allocations. cannam@87: ** Always returns NULL. cannam@87: */ cannam@87: cannam@87: SRC_STATE* src_delete (SRC_STATE *state) ; cannam@87: cannam@87: /* cannam@87: ** Standard processing function. cannam@87: ** Returns non zero on error. cannam@87: */ cannam@87: cannam@87: int src_process (SRC_STATE *state, SRC_DATA *data) ; cannam@87: cannam@87: /* cannam@87: ** Callback based processing function. Read up to frames worth of data from cannam@87: ** the converter int *data and return frames read or -1 on error. cannam@87: */ cannam@87: long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ; cannam@87: cannam@87: /* cannam@87: ** Simple interface for performing a single conversion from input buffer to cannam@87: ** output buffer at a fixed conversion ratio. cannam@87: ** Simple interface does not require initialisation as it can only operate on cannam@87: ** a single buffer worth of audio. cannam@87: */ cannam@87: cannam@87: int src_simple (SRC_DATA *data, int converter_type, int channels) ; cannam@87: cannam@87: /* cannam@87: ** This library contains a number of different sample rate converters, cannam@87: ** numbered 0 through N. cannam@87: ** cannam@87: ** Return a string giving either a name or a more full description of each cannam@87: ** sample rate converter or NULL if no sample rate converter exists for cannam@87: ** the given value. The converters are sequentially numbered from 0 to N. cannam@87: */ cannam@87: cannam@87: const char *src_get_name (int converter_type) ; cannam@87: const char *src_get_description (int converter_type) ; cannam@87: const char *src_get_version (void) ; cannam@87: cannam@87: /* cannam@87: ** Set a new SRC ratio. This allows step responses cannam@87: ** in the conversion ratio. cannam@87: ** Returns non zero on error. cannam@87: */ cannam@87: cannam@87: int src_set_ratio (SRC_STATE *state, double new_ratio) ; cannam@87: cannam@87: /* cannam@87: ** Reset the internal SRC state. cannam@87: ** Does not modify the quality settings. cannam@87: ** Does not free any memory allocations. cannam@87: ** Returns non zero on error. cannam@87: */ cannam@87: cannam@87: int src_reset (SRC_STATE *state) ; cannam@87: cannam@87: /* cannam@87: ** Return TRUE if ratio is a valid conversion ratio, FALSE cannam@87: ** otherwise. cannam@87: */ cannam@87: cannam@87: int src_is_valid_ratio (double ratio) ; cannam@87: cannam@87: /* cannam@87: ** Return an error number. cannam@87: */ cannam@87: cannam@87: int src_error (SRC_STATE *state) ; cannam@87: cannam@87: /* cannam@87: ** Convert the error number into a string. cannam@87: */ cannam@87: const char* src_strerror (int error) ; cannam@87: cannam@87: /* cannam@87: ** The following enums can be used to set the interpolator type cannam@87: ** using the function src_set_converter(). cannam@87: */ cannam@87: cannam@87: enum cannam@87: { cannam@87: SRC_SINC_BEST_QUALITY = 0, cannam@87: SRC_SINC_MEDIUM_QUALITY = 1, cannam@87: SRC_SINC_FASTEST = 2, cannam@87: SRC_ZERO_ORDER_HOLD = 3, cannam@87: SRC_LINEAR = 4, cannam@87: } ; cannam@87: cannam@87: /* cannam@87: ** Extra helper functions for converting from short to float and cannam@87: ** back again. cannam@87: */ cannam@87: cannam@87: void src_short_to_float_array (const short *in, float *out, int len) ; cannam@87: void src_float_to_short_array (const float *in, short *out, int len) ; cannam@87: cannam@87: void src_int_to_float_array (const int *in, float *out, int len) ; cannam@87: void src_float_to_int_array (const float *in, int *out, int len) ; cannam@87: cannam@87: cannam@87: #ifdef __cplusplus cannam@87: } /* extern "C" */ cannam@87: #endif /* __cplusplus */ cannam@87: cannam@87: #endif /* SAMPLERATE_H */ cannam@87: