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