In JackCoreAudioDriver, improve management of input/output channels: -1 is now used...
[jack2.git] / windows / samplerate.h
blob9651e6357f4d4bb83a957a4f20e1271541459353
1 /*
2 ** Copyright (C) 2002-2008 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.
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.
20 ** This code is part of Secret Rabibt Code aka libsamplerate. A commercial
21 ** use license for this code is available, please see:
22 ** http://www.mega-nerd.com/SRC/procedure.html
26 ** API documentation is available here:
27 ** http://www.mega-nerd.com/SRC/api.html
30 #ifndef SAMPLERATE_H
31 #define SAMPLERATE_H
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
38 /* Opaque data type SRC_STATE. */
39 typedef struct SRC_STATE_tag SRC_STATE ;
41 /* SRC_DATA is used to pass data to src_simple() and src_process(). */
42 typedef struct
43 { float *data_in, *data_out ;
45 long input_frames, output_frames ;
46 long input_frames_used, output_frames_gen ;
48 int end_of_input ;
50 double src_ratio ;
51 } SRC_DATA ;
53 /* SRC_CB_DATA is used with callback based API. */
54 typedef struct
55 { long frames ;
56 float *data_in ;
57 } SRC_CB_DATA ;
60 ** User supplied callback function type for use with src_callback_new()
61 ** and src_callback_read(). First parameter is the same pointer that was
62 ** passed into src_callback_new(). Second parameter is pointer to a
63 ** pointer. The user supplied callback function must modify *data to
64 ** point to the start of the user supplied float array. The user supplied
65 ** function must return the number of frames that **data points to.
68 typedef long (*src_callback_t) (void *cb_data, float **data) ;
71 ** Standard initialisation function : return an anonymous pointer to the
72 ** internal state of the converter. Choose a converter from the enums below.
73 ** Error returned in *error.
76 SRC_STATE* src_new (int converter_type, int channels, int *error) ;
79 ** Initilisation for callback based API : return an anonymous pointer to the
80 ** internal state of the converter. Choose a converter from the enums below.
81 ** The cb_data pointer can point to any data or be set to NULL. Whatever the
82 ** value, when processing, user supplied function "func" gets called with
83 ** cb_data as first parameter.
86 SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
87 int *error, void* cb_data) ;
90 ** Cleanup all internal allocations.
91 ** Always returns NULL.
94 SRC_STATE* src_delete (SRC_STATE *state) ;
97 ** Standard processing function.
98 ** Returns non zero on error.
101 int src_process (SRC_STATE *state, SRC_DATA *data) ;
104 ** Callback based processing function. Read up to frames worth of data from
105 ** the converter int *data and return frames read or -1 on error.
107 long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
110 ** Simple interface for performing a single conversion from input buffer to
111 ** output buffer at a fixed conversion ratio.
112 ** Simple interface does not require initialisation as it can only operate on
113 ** a single buffer worth of audio.
116 int src_simple (SRC_DATA *data, int converter_type, int channels) ;
119 ** This library contains a number of different sample rate converters,
120 ** numbered 0 through N.
122 ** Return a string giving either a name or a more full description of each
123 ** sample rate converter or NULL if no sample rate converter exists for
124 ** the given value. The converters are sequentially numbered from 0 to N.
127 const char *src_get_name (int converter_type) ;
128 const char *src_get_description (int converter_type) ;
129 const char *src_get_version (void) ;
132 ** Set a new SRC ratio. This allows step responses
133 ** in the conversion ratio.
134 ** Returns non zero on error.
137 int src_set_ratio (SRC_STATE *state, double new_ratio) ;
140 ** Reset the internal SRC state.
141 ** Does not modify the quality settings.
142 ** Does not free any memory allocations.
143 ** Returns non zero on error.
146 int src_reset (SRC_STATE *state) ;
149 ** Return TRUE if ratio is a valid conversion ratio, FALSE
150 ** otherwise.
153 int src_is_valid_ratio (double ratio) ;
156 ** Return an error number.
159 int src_error (SRC_STATE *state) ;
162 ** Convert the error number into a string.
164 const char* src_strerror (int error) ;
167 ** The following enums can be used to set the interpolator type
168 ** using the function src_set_converter().
171 enum
173 SRC_SINC_BEST_QUALITY = 0,
174 SRC_SINC_MEDIUM_QUALITY = 1,
175 SRC_SINC_FASTEST = 2,
176 SRC_ZERO_ORDER_HOLD = 3,
177 SRC_LINEAR = 4,
181 ** Extra helper functions for converting from short to float and
182 ** back again.
185 void src_short_to_float_array (const short *in, float *out, int len) ;
186 void src_float_to_short_array (const float *in, short *out, int len) ;
188 void src_int_to_float_array (const int *in, float *out, int len) ;
189 void src_float_to_int_array (const float *in, int *out, int len) ;
192 #ifdef __cplusplus
193 } /* extern "C" */
194 #endif /* __cplusplus */
196 #endif /* SAMPLERATE_H */