1 | /* |
2 | ** Copyright (C) 2002-2011 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 | ** This code is part of Secret Rabbit Code aka libsamplerate. A commercial |
21 | ** use license for this code is available, please see: |
22 | ** http://www.mega-nerd.com/SRC/procedure.html |
23 | */ |
24 | |
25 | /* |
26 | ** API documentation is available here: |
27 | ** http://www.mega-nerd.com/SRC/api.html |
28 | */ |
29 | |
30 | #ifndef SAMPLERATE_H |
31 | #define SAMPLERATE_H |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif /* __cplusplus */ |
36 | |
37 | |
38 | /* Opaque data type SRC_STATE. */ |
39 | typedef struct SRC_STATE_tag SRC_STATE ; |
40 | |
41 | /* SRC_DATA is used to pass data to src_simple() and src_process(). */ |
42 | typedef struct |
43 | { float *data_in, *data_out ; |
44 | |
45 | long input_frames, output_frames ; |
46 | long input_frames_used, output_frames_gen ; |
47 | |
48 | int end_of_input ; |
49 | |
50 | double src_ratio ; |
51 | } SRC_DATA ; |
52 | |
53 | /* SRC_CB_DATA is used with callback based API. */ |
54 | typedef struct |
55 | { long frames ; |
56 | float *data_in ; |
57 | } SRC_CB_DATA ; |
58 | |
59 | /* |
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. |
66 | */ |
67 | |
68 | typedef long (*src_callback_t) (void *cb_data, float **data) ; |
69 | |
70 | /* |
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. |
74 | */ |
75 | |
76 | SRC_STATE* src_new (int converter_type, int channels, int *error) ; |
77 | |
78 | /* |
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. |
84 | */ |
85 | |
86 | SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels, |
87 | int *error, void* cb_data) ; |
88 | |
89 | /* |
90 | ** Cleanup all internal allocations. |
91 | ** Always returns NULL. |
92 | */ |
93 | |
94 | SRC_STATE* src_delete (SRC_STATE *state) ; |
95 | |
96 | /* |
97 | ** Standard processing function. |
98 | ** Returns non zero on error. |
99 | */ |
100 | |
101 | int src_process (SRC_STATE *state, SRC_DATA *data) ; |
102 | |
103 | /* |
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. |
106 | */ |
107 | long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ; |
108 | |
109 | /* |
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. |
114 | */ |
115 | |
116 | int src_simple (SRC_DATA *data, int converter_type, int channels) ; |
117 | |
118 | /* |
119 | ** This library contains a number of different sample rate converters, |
120 | ** numbered 0 through N. |
121 | ** |
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. |
125 | */ |
126 | |
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) ; |
130 | |
131 | /* |
132 | ** Set a new SRC ratio. This allows step responses |
133 | ** in the conversion ratio. |
134 | ** Returns non zero on error. |
135 | */ |
136 | |
137 | int src_set_ratio (SRC_STATE *state, double new_ratio) ; |
138 | |
139 | /* |
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. |
144 | */ |
145 | |
146 | int src_reset (SRC_STATE *state) ; |
147 | |
148 | /* |
149 | ** Return TRUE if ratio is a valid conversion ratio, FALSE |
150 | ** otherwise. |
151 | */ |
152 | |
153 | int src_is_valid_ratio (double ratio) ; |
154 | |
155 | /* |
156 | ** Return an error number. |
157 | */ |
158 | |
159 | int src_error (SRC_STATE *state) ; |
160 | |
161 | /* |
162 | ** Convert the error number into a string. |
163 | */ |
164 | const char* src_strerror (int error) ; |
165 | |
166 | /* |
167 | ** The following enums can be used to set the interpolator type |
168 | ** using the function src_set_converter(). |
169 | */ |
170 | |
171 | enum |
172 | { |
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, |
178 | } ; |
179 | |
180 | /* |
181 | ** Extra helper functions for converting from short to float and |
182 | ** back again. |
183 | */ |
184 | |
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) ; |
187 | |
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) ; |
190 | |
191 | |
192 | #ifdef __cplusplus |
193 | } /* extern "C" */ |
194 | #endif /* __cplusplus */ |
195 | |
196 | #endif /* SAMPLERATE_H */ |
197 | |
198 | |