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