1
#ifndef PA_CONVERTERS_H
2
#define PA_CONVERTERS_H
4
* $Id: pa_converters.h 1097 2006-08-26 08:27:53Z rossb $
5
* Portable Audio I/O Library sample conversion mechanism
7
* Based on the Open Source API proposed by Ross Bencina
8
* Copyright (c) 1999-2002 Phil Burk, Ross Bencina
10
* Permission is hereby granted, free of charge, to any person obtaining
11
* a copy of this software and associated documentation files
12
* (the "Software"), to deal in the Software without restriction,
13
* including without limitation the rights to use, copy, modify, merge,
14
* publish, distribute, sublicense, and/or sell copies of the Software,
15
* and to permit persons to whom the Software is furnished to do so,
16
* subject to the following conditions:
18
* The above copyright notice and this permission notice shall be
19
* included in all copies or substantial portions of the Software.
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
25
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
* The text above constitutes the entire PortAudio license; however,
32
* the PortAudio community also makes the following non-binding requests:
34
* Any person wishing to distribute modifications to the Software is
35
* requested to send the modifications to the original developer so that
36
* they can be incorporated into the canonical version. It is also
37
* requested that these non-binding requests be included along with the
44
@brief Conversion functions used to convert buffers of samples from one
49
#include "portaudio.h" /* for PaSampleFormat */
54
#endif /* __cplusplus */
57
struct PaUtilTriangularDitherGenerator;
60
/** Choose an available sample format which is most appropriate for
61
representing the requested format. If the requested format is not available
62
higher quality formats are considered before lower quality formates.
63
@param availableFormats A variable containing the logical OR of all available
65
@param format The desired format.
66
@return The most appropriate available format for representing the requested
69
PaSampleFormat PaUtil_SelectClosestAvailableFormat(
70
PaSampleFormat availableFormats, PaSampleFormat format );
73
/* high level conversions functions for use by implementations */
76
/** The generic sample converter prototype. Sample converters convert count
77
samples from sourceBuffer to destinationBuffer. The actual type of the data
78
pointed to by these parameters varys for different converter functions.
79
@param destinationBuffer A pointer to the first sample of the destination.
80
@param destinationStride An offset between successive destination samples
81
expressed in samples (not bytes.) It may be negative.
82
@param sourceBuffer A pointer to the first sample of the source.
83
@param sourceStride An offset between successive source samples
84
expressed in samples (not bytes.) It may be negative.
85
@param count The number of samples to convert.
86
@param ditherState State information used to calculate dither. Converters
87
that do not perform dithering will ignore this parameter, in which case
88
NULL or invalid dither state may be passed.
90
typedef void PaUtilConverter(
91
void *destinationBuffer, signed int destinationStride,
92
void *sourceBuffer, signed int sourceStride,
93
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator );
96
/** Find a sample converter function for the given source and destinations
97
formats and flags (clip and dither.)
99
A pointer to a PaUtilConverter which will perform the requested
100
conversion, or NULL if the given format conversion is not supported.
101
For conversions where clipping or dithering is not necessary, the
102
clip and dither flags are ignored and a non-clipping or dithering
104
If the source and destination formats are the same, a function which
105
copies data of the appropriate size will be returned.
107
PaUtilConverter* PaUtil_SelectConverter( PaSampleFormat sourceFormat,
108
PaSampleFormat destinationFormat, PaStreamFlags flags );
111
/** The generic buffer zeroer prototype. Buffer zeroers copy count zeros to
112
destinationBuffer. The actual type of the data pointed to varys for
113
different zeroer functions.
114
@param destinationBuffer A pointer to the first sample of the destination.
115
@param destinationStride An offset between successive destination samples
116
expressed in samples (not bytes.) It may be negative.
117
@param count The number of samples to zero.
119
typedef void PaUtilZeroer(
120
void *destinationBuffer, signed int destinationStride, unsigned int count );
123
/** Find a buffer zeroer function for the given destination format.
125
A pointer to a PaUtilZeroer which will perform the requested
128
PaUtilZeroer* PaUtil_SelectZeroer( PaSampleFormat destinationFormat );
130
/*----------------------------------------------------------------------------*/
131
/* low level functions and data structures which may be used for
132
substituting conversion functions */
135
/** The type used to store all sample conversion functions.
139
PaUtilConverter *Float32_To_Int32;
140
PaUtilConverter *Float32_To_Int32_Dither;
141
PaUtilConverter *Float32_To_Int32_Clip;
142
PaUtilConverter *Float32_To_Int32_DitherClip;
144
PaUtilConverter *Float32_To_Int24;
145
PaUtilConverter *Float32_To_Int24_Dither;
146
PaUtilConverter *Float32_To_Int24_Clip;
147
PaUtilConverter *Float32_To_Int24_DitherClip;
149
PaUtilConverter *Float32_To_Int16;
150
PaUtilConverter *Float32_To_Int16_Dither;
151
PaUtilConverter *Float32_To_Int16_Clip;
152
PaUtilConverter *Float32_To_Int16_DitherClip;
154
PaUtilConverter *Float32_To_Int8;
155
PaUtilConverter *Float32_To_Int8_Dither;
156
PaUtilConverter *Float32_To_Int8_Clip;
157
PaUtilConverter *Float32_To_Int8_DitherClip;
159
PaUtilConverter *Float32_To_UInt8;
160
PaUtilConverter *Float32_To_UInt8_Dither;
161
PaUtilConverter *Float32_To_UInt8_Clip;
162
PaUtilConverter *Float32_To_UInt8_DitherClip;
164
PaUtilConverter *Int32_To_Float32;
165
PaUtilConverter *Int32_To_Int24;
166
PaUtilConverter *Int32_To_Int24_Dither;
167
PaUtilConverter *Int32_To_Int16;
168
PaUtilConverter *Int32_To_Int16_Dither;
169
PaUtilConverter *Int32_To_Int8;
170
PaUtilConverter *Int32_To_Int8_Dither;
171
PaUtilConverter *Int32_To_UInt8;
172
PaUtilConverter *Int32_To_UInt8_Dither;
174
PaUtilConverter *Int24_To_Float32;
175
PaUtilConverter *Int24_To_Int32;
176
PaUtilConverter *Int24_To_Int16;
177
PaUtilConverter *Int24_To_Int16_Dither;
178
PaUtilConverter *Int24_To_Int8;
179
PaUtilConverter *Int24_To_Int8_Dither;
180
PaUtilConverter *Int24_To_UInt8;
181
PaUtilConverter *Int24_To_UInt8_Dither;
183
PaUtilConverter *Int16_To_Float32;
184
PaUtilConverter *Int16_To_Int32;
185
PaUtilConverter *Int16_To_Int24;
186
PaUtilConverter *Int16_To_Int8;
187
PaUtilConverter *Int16_To_Int8_Dither;
188
PaUtilConverter *Int16_To_UInt8;
189
PaUtilConverter *Int16_To_UInt8_Dither;
191
PaUtilConverter *Int8_To_Float32;
192
PaUtilConverter *Int8_To_Int32;
193
PaUtilConverter *Int8_To_Int24;
194
PaUtilConverter *Int8_To_Int16;
195
PaUtilConverter *Int8_To_UInt8;
197
PaUtilConverter *UInt8_To_Float32;
198
PaUtilConverter *UInt8_To_Int32;
199
PaUtilConverter *UInt8_To_Int24;
200
PaUtilConverter *UInt8_To_Int16;
201
PaUtilConverter *UInt8_To_Int8;
203
PaUtilConverter *Copy_8_To_8; /* copy without any conversion */
204
PaUtilConverter *Copy_16_To_16; /* copy without any conversion */
205
PaUtilConverter *Copy_24_To_24; /* copy without any conversion */
206
PaUtilConverter *Copy_32_To_32; /* copy without any conversion */
207
} PaUtilConverterTable;
210
/** A table of pointers to all required converter functions.
211
PaUtil_SelectConverter() uses this table to lookup the appropriate
212
conversion functions. The fields of this structure are initialized
213
with default conversion functions. Fields may be NULL, indicating that
214
no conversion function is available. User code may substitue optimised
215
conversion functions by assigning different function pointers to
219
If the PA_NO_STANDARD_CONVERTERS preprocessor variable is defined,
220
PortAudio's standard converters will not be compiled, and all fields
221
of this structure will be initialized to NULL. In such cases, users
222
should supply their own conversion functions if the require PortAudio
223
to open a stream that requires sample conversion.
225
@see PaUtilConverterTable, PaUtilConverter, PaUtil_SelectConverter
227
extern PaUtilConverterTable paConverters;
230
/** The type used to store all buffer zeroing functions.
234
PaUtilZeroer *ZeroU8; /* unsigned 8 bit, zero == 128 */
236
PaUtilZeroer *Zero16;
237
PaUtilZeroer *Zero24;
238
PaUtilZeroer *Zero32;
242
/** A table of pointers to all required zeroer functions.
243
PaUtil_SelectZeroer() uses this table to lookup the appropriate
244
conversion functions. The fields of this structure are initialized
245
with default conversion functions. User code may substitue optimised
246
conversion functions by assigning different function pointers to
250
If the PA_NO_STANDARD_ZEROERS preprocessor variable is defined,
251
PortAudio's standard zeroers will not be compiled, and all fields
252
of this structure will be initialized to NULL. In such cases, users
253
should supply their own zeroing functions for the sample sizes which
256
@see PaUtilZeroerTable, PaUtilZeroer, PaUtil_SelectZeroer
258
extern PaUtilZeroerTable paZeroers;
262
#endif /* __cplusplus */
263
#endif /* PA_CONVERTERS_H */