1
#ifndef PA_CONVERTERS_H
2
#define PA_CONVERTERS_H
4
* $Id: pa_converters.h,v 1.1 2006/06/10 21:30:55 dmazzoni Exp $
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
* Any person wishing to distribute modifications to the Software is
22
* requested to send the modifications to the original developer so that
23
* they can be incorporated into the canonical version.
25
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
29
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
@brief Conversion functions used to convert buffers of samples from one
40
#include "portaudio.h" /* for PaSampleFormat */
45
#endif /* __cplusplus */
48
struct PaUtilTriangularDitherGenerator;
51
/** Choose an available sample format which is most appropriate for
52
representing the requested format. If the requested format is not available
53
higher quality formats are considered before lower quality formates.
54
@param availableFormats A variable containing the logical OR of all available
56
@param format The desired format.
57
@return The most appropriate available format for representing the requested
60
PaSampleFormat PaUtil_SelectClosestAvailableFormat(
61
PaSampleFormat availableFormats, PaSampleFormat format );
64
/* high level conversions functions for use by implementations */
67
/** The generic sample converter prototype. Sample converters convert count
68
samples from sourceBuffer to destinationBuffer. The actual type of the data
69
pointed to by these parameters varys for different converter functions.
70
@param destinationBuffer A pointer to the first sample of the destination.
71
@param destinationStride An offset between successive destination samples
72
expressed in samples (not bytes.) It may be negative.
73
@param sourceBuffer A pointer to the first sample of the source.
74
@param sourceStride An offset between successive source samples
75
expressed in samples (not bytes.) It may be negative.
76
@param count The number of samples to convert.
77
@param ditherState State information used to calculate dither. Converters
78
that do not perform dithering will ignore this parameter, in which case
79
NULL or invalid dither state may be passed.
81
typedef void PaUtilConverter(
82
void *destinationBuffer, signed int destinationStride,
83
void *sourceBuffer, signed int sourceStride,
84
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator );
87
/** Find a sample converter function for the given source and destinations
88
formats and flags (clip and dither.)
90
A pointer to a PaUtilConverter which will perform the requested
91
conversion, or NULL if the given format conversion is not supported.
92
For conversions where clipping or dithering is not necessary, the
93
clip and dither flags are ignored and a non-clipping or dithering
95
If the source and destination formats are the same, a function which
96
copies data of the appropriate size will be returned.
98
PaUtilConverter* PaUtil_SelectConverter( PaSampleFormat sourceFormat,
99
PaSampleFormat destinationFormat, PaStreamFlags flags );
102
/** The generic buffer zeroer prototype. Buffer zeroers copy count zeros to
103
destinationBuffer. The actual type of the data pointed to varys for
104
different zeroer functions.
105
@param destinationBuffer A pointer to the first sample of the destination.
106
@param destinationStride An offset between successive destination samples
107
expressed in samples (not bytes.) It may be negative.
108
@param count The number of samples to zero.
110
typedef void PaUtilZeroer(
111
void *destinationBuffer, signed int destinationStride, unsigned int count );
114
/** Find a buffer zeroer function for the given destination format.
116
A pointer to a PaUtilZeroer which will perform the requested
119
PaUtilZeroer* PaUtil_SelectZeroer( PaSampleFormat destinationFormat );
121
/*----------------------------------------------------------------------------*/
122
/* low level functions and data structures which may be used for
123
substituting conversion functions */
126
/** The type used to store all sample conversion functions.
130
PaUtilConverter *Float32_To_Int32;
131
PaUtilConverter *Float32_To_Int32_Dither;
132
PaUtilConverter *Float32_To_Int32_Clip;
133
PaUtilConverter *Float32_To_Int32_DitherClip;
135
PaUtilConverter *Float32_To_Int24;
136
PaUtilConverter *Float32_To_Int24_Dither;
137
PaUtilConverter *Float32_To_Int24_Clip;
138
PaUtilConverter *Float32_To_Int24_DitherClip;
140
PaUtilConverter *Float32_To_Int16;
141
PaUtilConverter *Float32_To_Int16_Dither;
142
PaUtilConverter *Float32_To_Int16_Clip;
143
PaUtilConverter *Float32_To_Int16_DitherClip;
145
PaUtilConverter *Float32_To_Int8;
146
PaUtilConverter *Float32_To_Int8_Dither;
147
PaUtilConverter *Float32_To_Int8_Clip;
148
PaUtilConverter *Float32_To_Int8_DitherClip;
150
PaUtilConverter *Float32_To_UInt8;
151
PaUtilConverter *Float32_To_UInt8_Dither;
152
PaUtilConverter *Float32_To_UInt8_Clip;
153
PaUtilConverter *Float32_To_UInt8_DitherClip;
155
PaUtilConverter *Int32_To_Float32;
156
PaUtilConverter *Int32_To_Int24;
157
PaUtilConverter *Int32_To_Int24_Dither;
158
PaUtilConverter *Int32_To_Int16;
159
PaUtilConverter *Int32_To_Int16_Dither;
160
PaUtilConverter *Int32_To_Int8;
161
PaUtilConverter *Int32_To_Int8_Dither;
162
PaUtilConverter *Int32_To_UInt8;
163
PaUtilConverter *Int32_To_UInt8_Dither;
165
PaUtilConverter *Int24_To_Float32;
166
PaUtilConverter *Int24_To_Int32;
167
PaUtilConverter *Int24_To_Int16;
168
PaUtilConverter *Int24_To_Int16_Dither;
169
PaUtilConverter *Int24_To_Int8;
170
PaUtilConverter *Int24_To_Int8_Dither;
171
PaUtilConverter *Int24_To_UInt8;
172
PaUtilConverter *Int24_To_UInt8_Dither;
174
PaUtilConverter *Int16_To_Float32;
175
PaUtilConverter *Int16_To_Int32;
176
PaUtilConverter *Int16_To_Int24;
177
PaUtilConverter *Int16_To_Int8;
178
PaUtilConverter *Int16_To_Int8_Dither;
179
PaUtilConverter *Int16_To_UInt8;
180
PaUtilConverter *Int16_To_UInt8_Dither;
182
PaUtilConverter *Int8_To_Float32;
183
PaUtilConverter *Int8_To_Int32;
184
PaUtilConverter *Int8_To_Int24;
185
PaUtilConverter *Int8_To_Int16;
186
PaUtilConverter *Int8_To_UInt8;
188
PaUtilConverter *UInt8_To_Float32;
189
PaUtilConverter *UInt8_To_Int32;
190
PaUtilConverter *UInt8_To_Int24;
191
PaUtilConverter *UInt8_To_Int16;
192
PaUtilConverter *UInt8_To_Int8;
194
PaUtilConverter *Copy_8_To_8; /* copy without any conversion */
195
PaUtilConverter *Copy_16_To_16; /* copy without any conversion */
196
PaUtilConverter *Copy_24_To_24; /* copy without any conversion */
197
PaUtilConverter *Copy_32_To_32; /* copy without any conversion */
198
} PaUtilConverterTable;
201
/** A table of pointers to all required converter functions.
202
PaUtil_SelectConverter() uses this table to lookup the appropriate
203
conversion functions. The fields of this structure are initialized
204
with default conversion functions. Fields may be NULL, indicating that
205
no conversion function is available. User code may substitue optimised
206
conversion functions by assigning different function pointers to
210
If the PA_NO_STANDARD_CONVERTERS preprocessor variable is defined,
211
PortAudio's standard converters will not be compiled, and all fields
212
of this structure will be initialized to NULL. In such cases, users
213
should supply their own conversion functions if the require PortAudio
214
to open a stream that requires sample conversion.
216
@see PaUtilConverterTable, PaUtilConverter, PaUtil_SelectConverter
218
extern PaUtilConverterTable paConverters;
221
/** The type used to store all buffer zeroing functions.
225
PaUtilZeroer *ZeroU8; /* unsigned 8 bit, zero == 128 */
227
PaUtilZeroer *Zero16;
228
PaUtilZeroer *Zero24;
229
PaUtilZeroer *Zero32;
233
/** A table of pointers to all required zeroer functions.
234
PaUtil_SelectZeroer() uses this table to lookup the appropriate
235
conversion functions. The fields of this structure are initialized
236
with default conversion functions. User code may substitue optimised
237
conversion functions by assigning different function pointers to
241
If the PA_NO_STANDARD_ZEROERS preprocessor variable is defined,
242
PortAudio's standard zeroers will not be compiled, and all fields
243
of this structure will be initialized to NULL. In such cases, users
244
should supply their own zeroing functions for the sample sizes which
247
@see PaUtilZeroerTable, PaUtilZeroer, PaUtil_SelectZeroer
249
extern PaUtilZeroerTable paZeroers;
253
#endif /* __cplusplus */
254
#endif /* PA_CONVERTERS_H */