| cannam@87 | 1 /* | 
| cannam@87 | 2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com> | 
| cannam@87 | 3 ** | 
| cannam@87 | 4 ** This program is free software; you can redistribute it and/or modify | 
| cannam@87 | 5 ** it under the terms of the GNU General Public License as published by | 
| cannam@87 | 6 ** the Free Software Foundation; either version 2 of the License, or | 
| cannam@87 | 7 ** (at your option) any later version. | 
| cannam@87 | 8 ** | 
| cannam@87 | 9 ** This program is distributed in the hope that it will be useful, | 
| cannam@87 | 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| cannam@87 | 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| cannam@87 | 12 ** GNU General Public License for more details. | 
| cannam@87 | 13 ** | 
| cannam@87 | 14 ** You should have received a copy of the GNU General Public License | 
| cannam@87 | 15 ** along with this program; if not, write to the Free Software | 
| cannam@87 | 16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 
| cannam@87 | 17 */ | 
| cannam@87 | 18 | 
| cannam@87 | 19 /* | 
| cannam@87 | 20 ** This code is part of Secret Rabbit Code aka libsamplerate. A commercial | 
| cannam@87 | 21 ** use license for this code is available, please see: | 
| cannam@87 | 22 **		http://www.mega-nerd.com/SRC/procedure.html | 
| cannam@87 | 23 */ | 
| cannam@87 | 24 | 
| cannam@87 | 25 /* | 
| cannam@87 | 26 ** API documentation is available here: | 
| cannam@87 | 27 **     http://www.mega-nerd.com/SRC/api.html | 
| cannam@87 | 28 */ | 
| cannam@87 | 29 | 
| cannam@87 | 30 #ifndef SAMPLERATE_H | 
| cannam@87 | 31 #define SAMPLERATE_H | 
| cannam@87 | 32 | 
| cannam@87 | 33 #ifdef __cplusplus | 
| cannam@87 | 34 extern "C" { | 
| cannam@87 | 35 #endif	/* __cplusplus */ | 
| cannam@87 | 36 | 
| cannam@87 | 37 | 
| cannam@87 | 38 /* Opaque data type SRC_STATE. */ | 
| cannam@87 | 39 typedef struct SRC_STATE_tag SRC_STATE ; | 
| cannam@87 | 40 | 
| cannam@87 | 41 /* SRC_DATA is used to pass data to src_simple() and src_process(). */ | 
| cannam@87 | 42 typedef struct | 
| cannam@87 | 43 {	float	*data_in, *data_out ; | 
| cannam@87 | 44 | 
| cannam@87 | 45 	long	input_frames, output_frames ; | 
| cannam@87 | 46 	long	input_frames_used, output_frames_gen ; | 
| cannam@87 | 47 | 
| cannam@87 | 48 	int		end_of_input ; | 
| cannam@87 | 49 | 
| cannam@87 | 50 	double	src_ratio ; | 
| cannam@87 | 51 } SRC_DATA ; | 
| cannam@87 | 52 | 
| cannam@87 | 53 /* SRC_CB_DATA is used with callback based API. */ | 
| cannam@87 | 54 typedef struct | 
| cannam@87 | 55 {	long	frames ; | 
| cannam@87 | 56 	float	*data_in ; | 
| cannam@87 | 57 } SRC_CB_DATA ; | 
| cannam@87 | 58 | 
| cannam@87 | 59 /* | 
| cannam@87 | 60 ** User supplied callback function type for use with src_callback_new() | 
| cannam@87 | 61 ** and src_callback_read(). First parameter is the same pointer that was | 
| cannam@87 | 62 ** passed into src_callback_new(). Second parameter is pointer to a | 
| cannam@87 | 63 ** pointer. The user supplied callback function must modify *data to | 
| cannam@87 | 64 ** point to the start of the user supplied float array. The user supplied | 
| cannam@87 | 65 ** function must return the number of frames that **data points to. | 
| cannam@87 | 66 */ | 
| cannam@87 | 67 | 
| cannam@87 | 68 typedef long (*src_callback_t) (void *cb_data, float **data) ; | 
| cannam@87 | 69 | 
| cannam@87 | 70 /* | 
| cannam@87 | 71 **	Standard initialisation function : return an anonymous pointer to the | 
| cannam@87 | 72 **	internal state of the converter. Choose a converter from the enums below. | 
| cannam@87 | 73 **	Error returned in *error. | 
| cannam@87 | 74 */ | 
| cannam@87 | 75 | 
| cannam@87 | 76 SRC_STATE* src_new (int converter_type, int channels, int *error) ; | 
| cannam@87 | 77 | 
| cannam@87 | 78 /* | 
| cannam@87 | 79 **	Initilisation for callback based API : return an anonymous pointer to the | 
| cannam@87 | 80 **	internal state of the converter. Choose a converter from the enums below. | 
| cannam@87 | 81 **	The cb_data pointer can point to any data or be set to NULL. Whatever the | 
| cannam@87 | 82 **	value, when processing, user supplied function "func" gets called with | 
| cannam@87 | 83 **	cb_data as first parameter. | 
| cannam@87 | 84 */ | 
| cannam@87 | 85 | 
| cannam@87 | 86 SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels, | 
| cannam@87 | 87 				int *error, void* cb_data) ; | 
| cannam@87 | 88 | 
| cannam@87 | 89 /* | 
| cannam@87 | 90 **	Cleanup all internal allocations. | 
| cannam@87 | 91 **	Always returns NULL. | 
| cannam@87 | 92 */ | 
| cannam@87 | 93 | 
| cannam@87 | 94 SRC_STATE* src_delete (SRC_STATE *state) ; | 
| cannam@87 | 95 | 
| cannam@87 | 96 /* | 
| cannam@87 | 97 **	Standard processing function. | 
| cannam@87 | 98 **	Returns non zero on error. | 
| cannam@87 | 99 */ | 
| cannam@87 | 100 | 
| cannam@87 | 101 int src_process (SRC_STATE *state, SRC_DATA *data) ; | 
| cannam@87 | 102 | 
| cannam@87 | 103 /* | 
| cannam@87 | 104 **	Callback based processing function. Read up to frames worth of data from | 
| cannam@87 | 105 **	the converter int *data and return frames read or -1 on error. | 
| cannam@87 | 106 */ | 
| cannam@87 | 107 long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ; | 
| cannam@87 | 108 | 
| cannam@87 | 109 /* | 
| cannam@87 | 110 **	Simple interface for performing a single conversion from input buffer to | 
| cannam@87 | 111 **	output buffer at a fixed conversion ratio. | 
| cannam@87 | 112 **	Simple interface does not require initialisation as it can only operate on | 
| cannam@87 | 113 **	a single buffer worth of audio. | 
| cannam@87 | 114 */ | 
| cannam@87 | 115 | 
| cannam@87 | 116 int src_simple (SRC_DATA *data, int converter_type, int channels) ; | 
| cannam@87 | 117 | 
| cannam@87 | 118 /* | 
| cannam@87 | 119 ** This library contains a number of different sample rate converters, | 
| cannam@87 | 120 ** numbered 0 through N. | 
| cannam@87 | 121 ** | 
| cannam@87 | 122 ** Return a string giving either a name or a more full description of each | 
| cannam@87 | 123 ** sample rate converter or NULL if no sample rate converter exists for | 
| cannam@87 | 124 ** the given value. The converters are sequentially numbered from 0 to N. | 
| cannam@87 | 125 */ | 
| cannam@87 | 126 | 
| cannam@87 | 127 const char *src_get_name (int converter_type) ; | 
| cannam@87 | 128 const char *src_get_description (int converter_type) ; | 
| cannam@87 | 129 const char *src_get_version (void) ; | 
| cannam@87 | 130 | 
| cannam@87 | 131 /* | 
| cannam@87 | 132 **	Set a new SRC ratio. This allows step responses | 
| cannam@87 | 133 **	in the conversion ratio. | 
| cannam@87 | 134 **	Returns non zero on error. | 
| cannam@87 | 135 */ | 
| cannam@87 | 136 | 
| cannam@87 | 137 int src_set_ratio (SRC_STATE *state, double new_ratio) ; | 
| cannam@87 | 138 | 
| cannam@87 | 139 /* | 
| cannam@87 | 140 **	Reset the internal SRC state. | 
| cannam@87 | 141 **	Does not modify the quality settings. | 
| cannam@87 | 142 **	Does not free any memory allocations. | 
| cannam@87 | 143 **	Returns non zero on error. | 
| cannam@87 | 144 */ | 
| cannam@87 | 145 | 
| cannam@87 | 146 int src_reset (SRC_STATE *state) ; | 
| cannam@87 | 147 | 
| cannam@87 | 148 /* | 
| cannam@87 | 149 ** Return TRUE if ratio is a valid conversion ratio, FALSE | 
| cannam@87 | 150 ** otherwise. | 
| cannam@87 | 151 */ | 
| cannam@87 | 152 | 
| cannam@87 | 153 int src_is_valid_ratio (double ratio) ; | 
| cannam@87 | 154 | 
| cannam@87 | 155 /* | 
| cannam@87 | 156 **	Return an error number. | 
| cannam@87 | 157 */ | 
| cannam@87 | 158 | 
| cannam@87 | 159 int src_error (SRC_STATE *state) ; | 
| cannam@87 | 160 | 
| cannam@87 | 161 /* | 
| cannam@87 | 162 **	Convert the error number into a string. | 
| cannam@87 | 163 */ | 
| cannam@87 | 164 const char* src_strerror (int error) ; | 
| cannam@87 | 165 | 
| cannam@87 | 166 /* | 
| cannam@87 | 167 ** The following enums can be used to set the interpolator type | 
| cannam@87 | 168 ** using the function src_set_converter(). | 
| cannam@87 | 169 */ | 
| cannam@87 | 170 | 
| cannam@87 | 171 enum | 
| cannam@87 | 172 { | 
| cannam@87 | 173 	SRC_SINC_BEST_QUALITY		= 0, | 
| cannam@87 | 174 	SRC_SINC_MEDIUM_QUALITY		= 1, | 
| cannam@87 | 175 	SRC_SINC_FASTEST			= 2, | 
| cannam@87 | 176 	SRC_ZERO_ORDER_HOLD			= 3, | 
| cannam@87 | 177 	SRC_LINEAR					= 4, | 
| cannam@87 | 178 } ; | 
| cannam@87 | 179 | 
| cannam@87 | 180 /* | 
| cannam@87 | 181 ** Extra helper functions for converting from short to float and | 
| cannam@87 | 182 ** back again. | 
| cannam@87 | 183 */ | 
| cannam@87 | 184 | 
| cannam@87 | 185 void src_short_to_float_array (const short *in, float *out, int len) ; | 
| cannam@87 | 186 void src_float_to_short_array (const float *in, short *out, int len) ; | 
| cannam@87 | 187 | 
| cannam@87 | 188 void src_int_to_float_array (const int *in, float *out, int len) ; | 
| cannam@87 | 189 void src_float_to_int_array (const float *in, int *out, int len) ; | 
| cannam@87 | 190 | 
| cannam@87 | 191 | 
| cannam@87 | 192 #ifdef __cplusplus | 
| cannam@87 | 193 }		/* extern "C" */ | 
| cannam@87 | 194 #endif	/* __cplusplus */ | 
| cannam@87 | 195 | 
| cannam@87 | 196 #endif	/* SAMPLERATE_H */ | 
| cannam@87 | 197 |