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