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 /* Opaque data type SRC_STATE. */
32 typedef struct SRC_STATE_tag SRC_STATE ;
33 
34 /* SRC_DATA is used to pass data to src_simple() and src_process(). */
35 typedef struct
36 {	float	*data_in, *data_out ;
37 
38 	long	input_frames, output_frames ;
39 	long	input_frames_used, output_frames_gen ;
40 
41 	int		end_of_input ;
42 
43 	double	src_ratio ;
44 } SRC_DATA ;
45 
46 /* SRC_CB_DATA is used with callback based API. */
47 typedef struct
48 {	long	frames ;
49 	float	*data_in ;
50 } SRC_CB_DATA ;
51 
52 /*
53 ** User supplied callback function type for use with src_callback_new()
54 ** and src_callback_read(). First parameter is the same pointer that was
55 ** passed into src_callback_new(). Second parameter is pointer to a
56 ** pointer. The user supplied callback function must modify *data to
57 ** point to the start of the user supplied float array. The user supplied
58 ** function must return the number of frames that **data points to.
59 */
60 
61 typedef long (*src_callback_t) (void *cb_data, float **data) ;
62 
63 /*
64 **	Standard initialisation function : return an anonymous pointer to the
65 **	internal state of the converter. Choose a converter from the enums below.
66 **	Error returned in *error.
67 */
68 
69 SRC_STATE* src_new (int converter_type, int channels, int *error) ;
70 
71 /*
72 **	Initilisation for callback based API : return an anonymous pointer to the
73 **	internal state of the converter. Choose a converter from the enums below.
74 **	The cb_data pointer can point to any data or be set to NULL. Whatever the
75 **	value, when processing, user supplied function "func" gets called with
76 **	cb_data as first parameter.
77 */
78 
79 SRC_STATE* src_callback_new (src_callback_t func, int converter_type, int channels,
80 				int *error, void* cb_data) ;
81 
82 /*
83 **	Cleanup all internal allocations.
84 **	Always returns NULL.
85 */
86 
87 SRC_STATE* src_delete (SRC_STATE *state) ;
88 
89 /*
90 **	Standard processing function.
91 **	Returns non zero on error.
92 */
93 
94 int src_process (SRC_STATE *state, SRC_DATA *data) ;
95 
96 /*
97 **	Callback based processing function. Read up to frames worth of data from
98 **	the converter int *data and return frames read or -1 on error.
99 */
100 long src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) ;
101 
102 /*
103 **	Simple interface for performing a single conversion from input buffer to
104 **	output buffer at a fixed conversion ratio.
105 **	Simple interface does not require initialisation as it can only operate on
106 **	a single buffer worth of audio.
107 */
108 
109 int src_simple (SRC_DATA *data, int converter_type, int channels) ;
110 
111 /*
112 ** This library contains a number of different sample rate converters,
113 ** numbered 0 through N.
114 **
115 ** Return a string giving either a name or a more full description of each
116 ** sample rate converter or NULL if no sample rate converter exists for
117 ** the given value. The converters are sequentially numbered from 0 to N.
118 */
119 
120 const char *src_get_name (int converter_type) ;
121 const char *src_get_description (int converter_type) ;
122 const char *src_get_version (void) ;
123 
124 /*
125 **	Set a new SRC ratio. This allows step responses
126 **	in the conversion ratio.
127 **	Returns non zero on error.
128 */
129 
130 int src_set_ratio (SRC_STATE *state, double new_ratio) ;
131 
132 /*
133 **	Reset the internal SRC state.
134 **	Does not modify the quality settings.
135 **	Does not free any memory allocations.
136 **	Returns non zero on error.
137 */
138 
139 int src_reset (SRC_STATE *state) ;
140 
141 /*
142 ** Return TRUE if ratio is a valid conversion ratio, FALSE
143 ** otherwise.
144 */
145 
146 int src_is_valid_ratio (double ratio) ;
147 
148 /*
149 **	Return an error number.
150 */
151 
152 int src_error (SRC_STATE *state) ;
153 
154 /*
155 **	Convert the error number into a string.
156 */
157 const char* src_strerror (int error) ;
158 
159 /*
160 ** The following enums can be used to set the interpolator type
161 ** using the function src_set_converter().
162 */
163 
164 enum
165 {
166 	SRC_SINC_BEST_QUALITY		= 0,
167 	SRC_SINC_MEDIUM_QUALITY		= 1,
168 	SRC_SINC_FASTEST			= 2,
169 	SRC_ZERO_ORDER_HOLD			= 3,
170 	SRC_LINEAR					= 4
171 } ;
172 
173 /*
174 ** Extra helper functions for converting from short to float and
175 ** back again.
176 */
177 
178 void src_short_to_float_array (const short *in, float *out, int len) ;
179 void src_float_to_short_array (const float *in, short *out, int len) ;
180 
181 #ifdef __cplusplus
182 }		/* extern "C" */
183 #endif	/* __cplusplus */
184 
185 #endif	/* SAMPLERATE_H */
186 
187 /*
188 ** Do not edit or modify anything in this comment block.
189 ** The arch-tag line is a file identity tag for the GNU Arch
190 ** revision control system.
191 **
192 ** arch-tag: 5421ef3e-c898-4ec3-8671-ea03d943ee00
193 */
194