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