Chris@29
|
1 #ifndef PORTAUDIO_H
|
Chris@29
|
2 #define PORTAUDIO_H
|
Chris@29
|
3 /*
|
Chris@29
|
4 * $Id: portaudio.h 1594 2011-02-05 14:33:29Z rossb $
|
Chris@29
|
5 * PortAudio Portable Real-Time Audio Library
|
Chris@29
|
6 * PortAudio API Header File
|
Chris@29
|
7 * Latest version available at: http://www.portaudio.com/
|
Chris@29
|
8 *
|
Chris@29
|
9 * Copyright (c) 1999-2002 Ross Bencina and Phil Burk
|
Chris@29
|
10 *
|
Chris@29
|
11 * Permission is hereby granted, free of charge, to any person obtaining
|
Chris@29
|
12 * a copy of this software and associated documentation files
|
Chris@29
|
13 * (the "Software"), to deal in the Software without restriction,
|
Chris@29
|
14 * including without limitation the rights to use, copy, modify, merge,
|
Chris@29
|
15 * publish, distribute, sublicense, and/or sell copies of the Software,
|
Chris@29
|
16 * and to permit persons to whom the Software is furnished to do so,
|
Chris@29
|
17 * subject to the following conditions:
|
Chris@29
|
18 *
|
Chris@29
|
19 * The above copyright notice and this permission notice shall be
|
Chris@29
|
20 * included in all copies or substantial portions of the Software.
|
Chris@29
|
21 *
|
Chris@29
|
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@29
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@29
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
Chris@29
|
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
Chris@29
|
26 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@29
|
27 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@29
|
28 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@29
|
29 */
|
Chris@29
|
30
|
Chris@29
|
31 /*
|
Chris@29
|
32 * The text above constitutes the entire PortAudio license; however,
|
Chris@29
|
33 * the PortAudio community also makes the following non-binding requests:
|
Chris@29
|
34 *
|
Chris@29
|
35 * Any person wishing to distribute modifications to the Software is
|
Chris@29
|
36 * requested to send the modifications to the original developer so that
|
Chris@29
|
37 * they can be incorporated into the canonical version. It is also
|
Chris@29
|
38 * requested that these non-binding requests be included along with the
|
Chris@29
|
39 * license above.
|
Chris@29
|
40 */
|
Chris@29
|
41
|
Chris@29
|
42 /** @file
|
Chris@29
|
43 @ingroup public_header
|
Chris@29
|
44 @brief The portable PortAudio API.
|
Chris@29
|
45 */
|
Chris@29
|
46
|
Chris@29
|
47
|
Chris@29
|
48 #ifdef __cplusplus
|
Chris@29
|
49 extern "C"
|
Chris@29
|
50 {
|
Chris@29
|
51 #endif /* __cplusplus */
|
Chris@29
|
52
|
Chris@29
|
53
|
Chris@29
|
54 /** Retrieve the release number of the currently running PortAudio build,
|
Chris@29
|
55 eg 1900.
|
Chris@29
|
56 */
|
Chris@29
|
57 int Pa_GetVersion( void );
|
Chris@29
|
58
|
Chris@29
|
59
|
Chris@29
|
60 /** Retrieve a textual description of the current PortAudio build,
|
Chris@29
|
61 eg "PortAudio V19-devel 13 October 2002".
|
Chris@29
|
62 */
|
Chris@29
|
63 const char* Pa_GetVersionText( void );
|
Chris@29
|
64
|
Chris@29
|
65
|
Chris@29
|
66 /** Error codes returned by PortAudio functions.
|
Chris@29
|
67 Note that with the exception of paNoError, all PaErrorCodes are negative.
|
Chris@29
|
68 */
|
Chris@29
|
69
|
Chris@29
|
70 typedef int PaError;
|
Chris@29
|
71 typedef enum PaErrorCode
|
Chris@29
|
72 {
|
Chris@29
|
73 paNoError = 0,
|
Chris@29
|
74
|
Chris@29
|
75 paNotInitialized = -10000,
|
Chris@29
|
76 paUnanticipatedHostError,
|
Chris@29
|
77 paInvalidChannelCount,
|
Chris@29
|
78 paInvalidSampleRate,
|
Chris@29
|
79 paInvalidDevice,
|
Chris@29
|
80 paInvalidFlag,
|
Chris@29
|
81 paSampleFormatNotSupported,
|
Chris@29
|
82 paBadIODeviceCombination,
|
Chris@29
|
83 paInsufficientMemory,
|
Chris@29
|
84 paBufferTooBig,
|
Chris@29
|
85 paBufferTooSmall,
|
Chris@29
|
86 paNullCallback,
|
Chris@29
|
87 paBadStreamPtr,
|
Chris@29
|
88 paTimedOut,
|
Chris@29
|
89 paInternalError,
|
Chris@29
|
90 paDeviceUnavailable,
|
Chris@29
|
91 paIncompatibleHostApiSpecificStreamInfo,
|
Chris@29
|
92 paStreamIsStopped,
|
Chris@29
|
93 paStreamIsNotStopped,
|
Chris@29
|
94 paInputOverflowed,
|
Chris@29
|
95 paOutputUnderflowed,
|
Chris@29
|
96 paHostApiNotFound,
|
Chris@29
|
97 paInvalidHostApi,
|
Chris@29
|
98 paCanNotReadFromACallbackStream,
|
Chris@29
|
99 paCanNotWriteToACallbackStream,
|
Chris@29
|
100 paCanNotReadFromAnOutputOnlyStream,
|
Chris@29
|
101 paCanNotWriteToAnInputOnlyStream,
|
Chris@29
|
102 paIncompatibleStreamHostApi,
|
Chris@29
|
103 paBadBufferPtr
|
Chris@29
|
104 } PaErrorCode;
|
Chris@29
|
105
|
Chris@29
|
106
|
Chris@29
|
107 /** Translate the supplied PortAudio error code into a human readable
|
Chris@29
|
108 message.
|
Chris@29
|
109 */
|
Chris@29
|
110 const char *Pa_GetErrorText( PaError errorCode );
|
Chris@29
|
111
|
Chris@29
|
112
|
Chris@29
|
113 /** Library initialization function - call this before using PortAudio.
|
Chris@29
|
114 This function initializes internal data structures and prepares underlying
|
Chris@29
|
115 host APIs for use. With the exception of Pa_GetVersion(), Pa_GetVersionText(),
|
Chris@29
|
116 and Pa_GetErrorText(), this function MUST be called before using any other
|
Chris@29
|
117 PortAudio API functions.
|
Chris@29
|
118
|
Chris@29
|
119 If Pa_Initialize() is called multiple times, each successful
|
Chris@29
|
120 call must be matched with a corresponding call to Pa_Terminate().
|
Chris@29
|
121 Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not
|
Chris@29
|
122 required to be fully nested.
|
Chris@29
|
123
|
Chris@29
|
124 Note that if Pa_Initialize() returns an error code, Pa_Terminate() should
|
Chris@29
|
125 NOT be called.
|
Chris@29
|
126
|
Chris@29
|
127 @return paNoError if successful, otherwise an error code indicating the cause
|
Chris@29
|
128 of failure.
|
Chris@29
|
129
|
Chris@29
|
130 @see Pa_Terminate
|
Chris@29
|
131 */
|
Chris@29
|
132 PaError Pa_Initialize( void );
|
Chris@29
|
133
|
Chris@29
|
134
|
Chris@29
|
135 /** Library termination function - call this when finished using PortAudio.
|
Chris@29
|
136 This function deallocates all resources allocated by PortAudio since it was
|
Chris@29
|
137 initialized by a call to Pa_Initialize(). In cases where Pa_Initialise() has
|
Chris@29
|
138 been called multiple times, each call must be matched with a corresponding call
|
Chris@29
|
139 to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically
|
Chris@29
|
140 close any PortAudio streams that are still open.
|
Chris@29
|
141
|
Chris@29
|
142 Pa_Terminate() MUST be called before exiting a program which uses PortAudio.
|
Chris@29
|
143 Failure to do so may result in serious resource leaks, such as audio devices
|
Chris@29
|
144 not being available until the next reboot.
|
Chris@29
|
145
|
Chris@29
|
146 @return paNoError if successful, otherwise an error code indicating the cause
|
Chris@29
|
147 of failure.
|
Chris@29
|
148
|
Chris@29
|
149 @see Pa_Initialize
|
Chris@29
|
150 */
|
Chris@29
|
151 PaError Pa_Terminate( void );
|
Chris@29
|
152
|
Chris@29
|
153
|
Chris@29
|
154
|
Chris@29
|
155 /** The type used to refer to audio devices. Values of this type usually
|
Chris@29
|
156 range from 0 to (Pa_GetDeviceCount()-1), and may also take on the PaNoDevice
|
Chris@29
|
157 and paUseHostApiSpecificDeviceSpecification values.
|
Chris@29
|
158
|
Chris@29
|
159 @see Pa_GetDeviceCount, paNoDevice, paUseHostApiSpecificDeviceSpecification
|
Chris@29
|
160 */
|
Chris@29
|
161 typedef int PaDeviceIndex;
|
Chris@29
|
162
|
Chris@29
|
163
|
Chris@29
|
164 /** A special PaDeviceIndex value indicating that no device is available,
|
Chris@29
|
165 or should be used.
|
Chris@29
|
166
|
Chris@29
|
167 @see PaDeviceIndex
|
Chris@29
|
168 */
|
Chris@29
|
169 #define paNoDevice ((PaDeviceIndex)-1)
|
Chris@29
|
170
|
Chris@29
|
171
|
Chris@29
|
172 /** A special PaDeviceIndex value indicating that the device(s) to be used
|
Chris@29
|
173 are specified in the host api specific stream info structure.
|
Chris@29
|
174
|
Chris@29
|
175 @see PaDeviceIndex
|
Chris@29
|
176 */
|
Chris@29
|
177 #define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2)
|
Chris@29
|
178
|
Chris@29
|
179
|
Chris@29
|
180 /* Host API enumeration mechanism */
|
Chris@29
|
181
|
Chris@29
|
182 /** The type used to enumerate to host APIs at runtime. Values of this type
|
Chris@29
|
183 range from 0 to (Pa_GetHostApiCount()-1).
|
Chris@29
|
184
|
Chris@29
|
185 @see Pa_GetHostApiCount
|
Chris@29
|
186 */
|
Chris@29
|
187 typedef int PaHostApiIndex;
|
Chris@29
|
188
|
Chris@29
|
189
|
Chris@29
|
190 /** Retrieve the number of available host APIs. Even if a host API is
|
Chris@29
|
191 available it may have no devices available.
|
Chris@29
|
192
|
Chris@29
|
193 @return A non-negative value indicating the number of available host APIs
|
Chris@29
|
194 or, a PaErrorCode (which are always negative) if PortAudio is not initialized
|
Chris@29
|
195 or an error is encountered.
|
Chris@29
|
196
|
Chris@29
|
197 @see PaHostApiIndex
|
Chris@29
|
198 */
|
Chris@29
|
199 PaHostApiIndex Pa_GetHostApiCount( void );
|
Chris@29
|
200
|
Chris@29
|
201
|
Chris@29
|
202 /** Retrieve the index of the default host API. The default host API will be
|
Chris@29
|
203 the lowest common denominator host API on the current platform and is
|
Chris@29
|
204 unlikely to provide the best performance.
|
Chris@29
|
205
|
Chris@29
|
206 @return A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1)
|
Chris@29
|
207 indicating the default host API index or, a PaErrorCode (which are always
|
Chris@29
|
208 negative) if PortAudio is not initialized or an error is encountered.
|
Chris@29
|
209 */
|
Chris@29
|
210 PaHostApiIndex Pa_GetDefaultHostApi( void );
|
Chris@29
|
211
|
Chris@29
|
212
|
Chris@29
|
213 /** Unchanging unique identifiers for each supported host API. This type
|
Chris@29
|
214 is used in the PaHostApiInfo structure. The values are guaranteed to be
|
Chris@29
|
215 unique and to never change, thus allowing code to be written that
|
Chris@29
|
216 conditionally uses host API specific extensions.
|
Chris@29
|
217
|
Chris@29
|
218 New type ids will be allocated when support for a host API reaches
|
Chris@29
|
219 "public alpha" status, prior to that developers should use the
|
Chris@29
|
220 paInDevelopment type id.
|
Chris@29
|
221
|
Chris@29
|
222 @see PaHostApiInfo
|
Chris@29
|
223 */
|
Chris@29
|
224 typedef enum PaHostApiTypeId
|
Chris@29
|
225 {
|
Chris@29
|
226 paInDevelopment=0, /* use while developing support for a new host API */
|
Chris@29
|
227 paDirectSound=1,
|
Chris@29
|
228 paMME=2,
|
Chris@29
|
229 paASIO=3,
|
Chris@29
|
230 paSoundManager=4,
|
Chris@29
|
231 paCoreAudio=5,
|
Chris@29
|
232 paOSS=7,
|
Chris@29
|
233 paALSA=8,
|
Chris@29
|
234 paAL=9,
|
Chris@29
|
235 paBeOS=10,
|
Chris@29
|
236 paWDMKS=11,
|
Chris@29
|
237 paJACK=12,
|
Chris@29
|
238 paWASAPI=13,
|
Chris@29
|
239 paAudioScienceHPI=14
|
Chris@29
|
240 } PaHostApiTypeId;
|
Chris@29
|
241
|
Chris@29
|
242
|
Chris@29
|
243 /** A structure containing information about a particular host API. */
|
Chris@29
|
244
|
Chris@29
|
245 typedef struct PaHostApiInfo
|
Chris@29
|
246 {
|
Chris@29
|
247 /** this is struct version 1 */
|
Chris@29
|
248 int structVersion;
|
Chris@29
|
249 /** The well known unique identifier of this host API @see PaHostApiTypeId */
|
Chris@29
|
250 PaHostApiTypeId type;
|
Chris@29
|
251 /** A textual description of the host API for display on user interfaces. */
|
Chris@29
|
252 const char *name;
|
Chris@29
|
253
|
Chris@29
|
254 /** The number of devices belonging to this host API. This field may be
|
Chris@29
|
255 used in conjunction with Pa_HostApiDeviceIndexToDeviceIndex() to enumerate
|
Chris@29
|
256 all devices for this host API.
|
Chris@29
|
257 @see Pa_HostApiDeviceIndexToDeviceIndex
|
Chris@29
|
258 */
|
Chris@29
|
259 int deviceCount;
|
Chris@29
|
260
|
Chris@29
|
261 /** The default input device for this host API. The value will be a
|
Chris@29
|
262 device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice
|
Chris@29
|
263 if no default input device is available.
|
Chris@29
|
264 */
|
Chris@29
|
265 PaDeviceIndex defaultInputDevice;
|
Chris@29
|
266
|
Chris@29
|
267 /** The default output device for this host API. The value will be a
|
Chris@29
|
268 device index ranging from 0 to (Pa_GetDeviceCount()-1), or paNoDevice
|
Chris@29
|
269 if no default output device is available.
|
Chris@29
|
270 */
|
Chris@29
|
271 PaDeviceIndex defaultOutputDevice;
|
Chris@29
|
272
|
Chris@29
|
273 } PaHostApiInfo;
|
Chris@29
|
274
|
Chris@29
|
275
|
Chris@29
|
276 /** Retrieve a pointer to a structure containing information about a specific
|
Chris@29
|
277 host Api.
|
Chris@29
|
278
|
Chris@29
|
279 @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
|
Chris@29
|
280
|
Chris@29
|
281 @return A pointer to an immutable PaHostApiInfo structure describing
|
Chris@29
|
282 a specific host API. If the hostApi parameter is out of range or an error
|
Chris@29
|
283 is encountered, the function returns NULL.
|
Chris@29
|
284
|
Chris@29
|
285 The returned structure is owned by the PortAudio implementation and must not
|
Chris@29
|
286 be manipulated or freed. The pointer is only guaranteed to be valid between
|
Chris@29
|
287 calls to Pa_Initialize() and Pa_Terminate().
|
Chris@29
|
288 */
|
Chris@29
|
289 const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi );
|
Chris@29
|
290
|
Chris@29
|
291
|
Chris@29
|
292 /** Convert a static host API unique identifier, into a runtime
|
Chris@29
|
293 host API index.
|
Chris@29
|
294
|
Chris@29
|
295 @param type A unique host API identifier belonging to the PaHostApiTypeId
|
Chris@29
|
296 enumeration.
|
Chris@29
|
297
|
Chris@29
|
298 @return A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or,
|
Chris@29
|
299 a PaErrorCode (which are always negative) if PortAudio is not initialized
|
Chris@29
|
300 or an error is encountered.
|
Chris@29
|
301
|
Chris@29
|
302 The paHostApiNotFound error code indicates that the host API specified by the
|
Chris@29
|
303 type parameter is not available.
|
Chris@29
|
304
|
Chris@29
|
305 @see PaHostApiTypeId
|
Chris@29
|
306 */
|
Chris@29
|
307 PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type );
|
Chris@29
|
308
|
Chris@29
|
309
|
Chris@29
|
310 /** Convert a host-API-specific device index to standard PortAudio device index.
|
Chris@29
|
311 This function may be used in conjunction with the deviceCount field of
|
Chris@29
|
312 PaHostApiInfo to enumerate all devices for the specified host API.
|
Chris@29
|
313
|
Chris@29
|
314 @param hostApi A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
|
Chris@29
|
315
|
Chris@29
|
316 @param hostApiDeviceIndex A valid per-host device index in the range
|
Chris@29
|
317 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1)
|
Chris@29
|
318
|
Chris@29
|
319 @return A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1)
|
Chris@29
|
320 or, a PaErrorCode (which are always negative) if PortAudio is not initialized
|
Chris@29
|
321 or an error is encountered.
|
Chris@29
|
322
|
Chris@29
|
323 A paInvalidHostApi error code indicates that the host API index specified by
|
Chris@29
|
324 the hostApi parameter is out of range.
|
Chris@29
|
325
|
Chris@29
|
326 A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter
|
Chris@29
|
327 is out of range.
|
Chris@29
|
328
|
Chris@29
|
329 @see PaHostApiInfo
|
Chris@29
|
330 */
|
Chris@29
|
331 PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi,
|
Chris@29
|
332 int hostApiDeviceIndex );
|
Chris@29
|
333
|
Chris@29
|
334
|
Chris@29
|
335
|
Chris@29
|
336 /** Structure used to return information about a host error condition.
|
Chris@29
|
337 */
|
Chris@29
|
338 typedef struct PaHostErrorInfo{
|
Chris@29
|
339 PaHostApiTypeId hostApiType; /**< the host API which returned the error code */
|
Chris@29
|
340 long errorCode; /**< the error code returned */
|
Chris@29
|
341 const char *errorText; /**< a textual description of the error if available, otherwise a zero-length string */
|
Chris@29
|
342 }PaHostErrorInfo;
|
Chris@29
|
343
|
Chris@29
|
344
|
Chris@29
|
345 /** Return information about the last host error encountered. The error
|
Chris@29
|
346 information returned by Pa_GetLastHostErrorInfo() will never be modified
|
Chris@29
|
347 asynchronously by errors occurring in other PortAudio owned threads
|
Chris@29
|
348 (such as the thread that manages the stream callback.)
|
Chris@29
|
349
|
Chris@29
|
350 This function is provided as a last resort, primarily to enhance debugging
|
Chris@29
|
351 by providing clients with access to all available error information.
|
Chris@29
|
352
|
Chris@29
|
353 @return A pointer to an immutable structure constraining information about
|
Chris@29
|
354 the host error. The values in this structure will only be valid if a
|
Chris@29
|
355 PortAudio function has previously returned the paUnanticipatedHostError
|
Chris@29
|
356 error code.
|
Chris@29
|
357 */
|
Chris@29
|
358 const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void );
|
Chris@29
|
359
|
Chris@29
|
360
|
Chris@29
|
361
|
Chris@29
|
362 /* Device enumeration and capabilities */
|
Chris@29
|
363
|
Chris@29
|
364 /** Retrieve the number of available devices. The number of available devices
|
Chris@29
|
365 may be zero.
|
Chris@29
|
366
|
Chris@29
|
367 @return A non-negative value indicating the number of available devices or,
|
Chris@29
|
368 a PaErrorCode (which are always negative) if PortAudio is not initialized
|
Chris@29
|
369 or an error is encountered.
|
Chris@29
|
370 */
|
Chris@29
|
371 PaDeviceIndex Pa_GetDeviceCount( void );
|
Chris@29
|
372
|
Chris@29
|
373
|
Chris@29
|
374 /** Retrieve the index of the default input device. The result can be
|
Chris@29
|
375 used in the inputDevice parameter to Pa_OpenStream().
|
Chris@29
|
376
|
Chris@29
|
377 @return The default input device index for the default host API, or paNoDevice
|
Chris@29
|
378 if no default input device is available or an error was encountered.
|
Chris@29
|
379 */
|
Chris@29
|
380 PaDeviceIndex Pa_GetDefaultInputDevice( void );
|
Chris@29
|
381
|
Chris@29
|
382
|
Chris@29
|
383 /** Retrieve the index of the default output device. The result can be
|
Chris@29
|
384 used in the outputDevice parameter to Pa_OpenStream().
|
Chris@29
|
385
|
Chris@29
|
386 @return The default output device index for the default host API, or paNoDevice
|
Chris@29
|
387 if no default output device is available or an error was encountered.
|
Chris@29
|
388
|
Chris@29
|
389 @note
|
Chris@29
|
390 On the PC, the user can specify a default device by
|
Chris@29
|
391 setting an environment variable. For example, to use device #1.
|
Chris@29
|
392 <pre>
|
Chris@29
|
393 set PA_RECOMMENDED_OUTPUT_DEVICE=1
|
Chris@29
|
394 </pre>
|
Chris@29
|
395 The user should first determine the available device ids by using
|
Chris@29
|
396 the supplied application "pa_devs".
|
Chris@29
|
397 */
|
Chris@29
|
398 PaDeviceIndex Pa_GetDefaultOutputDevice( void );
|
Chris@29
|
399
|
Chris@29
|
400
|
Chris@29
|
401 /** The type used to represent monotonic time in seconds. PaTime is
|
Chris@29
|
402 used for the fields of the PaStreamCallbackTimeInfo argument to the
|
Chris@29
|
403 PaStreamCallback and as the result of Pa_GetStreamTime().
|
Chris@29
|
404
|
Chris@29
|
405 PaTime values have unspecified origin.
|
Chris@29
|
406
|
Chris@29
|
407 @see PaStreamCallback, PaStreamCallbackTimeInfo, Pa_GetStreamTime
|
Chris@29
|
408 */
|
Chris@29
|
409 typedef double PaTime;
|
Chris@29
|
410
|
Chris@29
|
411
|
Chris@29
|
412 /** A type used to specify one or more sample formats. Each value indicates
|
Chris@29
|
413 a possible format for sound data passed to and from the stream callback,
|
Chris@29
|
414 Pa_ReadStream and Pa_WriteStream.
|
Chris@29
|
415
|
Chris@29
|
416 The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8
|
Chris@29
|
417 and aUInt8 are usually implemented by all implementations.
|
Chris@29
|
418
|
Chris@29
|
419 The floating point representation (paFloat32) uses +1.0 and -1.0 as the
|
Chris@29
|
420 maximum and minimum respectively.
|
Chris@29
|
421
|
Chris@29
|
422 paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
|
Chris@29
|
423
|
Chris@29
|
424 The paNonInterleaved flag indicates that audio data is passed as an array
|
Chris@29
|
425 of pointers to separate buffers, one buffer for each channel. Usually,
|
Chris@29
|
426 when this flag is not used, audio data is passed as a single buffer with
|
Chris@29
|
427 all channels interleaved.
|
Chris@29
|
428
|
Chris@29
|
429 @see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo
|
Chris@29
|
430 @see paFloat32, paInt16, paInt32, paInt24, paInt8
|
Chris@29
|
431 @see paUInt8, paCustomFormat, paNonInterleaved
|
Chris@29
|
432 */
|
Chris@29
|
433 typedef unsigned long PaSampleFormat;
|
Chris@29
|
434
|
Chris@29
|
435
|
Chris@29
|
436 #define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */
|
Chris@29
|
437 #define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */
|
Chris@29
|
438 #define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */
|
Chris@29
|
439 #define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */
|
Chris@29
|
440 #define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */
|
Chris@29
|
441 #define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */
|
Chris@29
|
442 #define paCustomFormat ((PaSampleFormat) 0x00010000) /**< @see PaSampleFormat */
|
Chris@29
|
443
|
Chris@29
|
444 #define paNonInterleaved ((PaSampleFormat) 0x80000000) /**< @see PaSampleFormat */
|
Chris@29
|
445
|
Chris@29
|
446 /** A structure providing information and capabilities of PortAudio devices.
|
Chris@29
|
447 Devices may support input, output or both input and output.
|
Chris@29
|
448 */
|
Chris@29
|
449 typedef struct PaDeviceInfo
|
Chris@29
|
450 {
|
Chris@29
|
451 int structVersion; /* this is struct version 2 */
|
Chris@29
|
452 const char *name;
|
Chris@29
|
453 PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/
|
Chris@29
|
454
|
Chris@29
|
455 int maxInputChannels;
|
Chris@29
|
456 int maxOutputChannels;
|
Chris@29
|
457
|
Chris@29
|
458 /* Default latency values for interactive performance. */
|
Chris@29
|
459 PaTime defaultLowInputLatency;
|
Chris@29
|
460 PaTime defaultLowOutputLatency;
|
Chris@29
|
461 /* Default latency values for robust non-interactive applications (eg. playing sound files). */
|
Chris@29
|
462 PaTime defaultHighInputLatency;
|
Chris@29
|
463 PaTime defaultHighOutputLatency;
|
Chris@29
|
464
|
Chris@29
|
465 double defaultSampleRate;
|
Chris@29
|
466 } PaDeviceInfo;
|
Chris@29
|
467
|
Chris@29
|
468
|
Chris@29
|
469 /** Retrieve a pointer to a PaDeviceInfo structure containing information
|
Chris@29
|
470 about the specified device.
|
Chris@29
|
471 @return A pointer to an immutable PaDeviceInfo structure. If the device
|
Chris@29
|
472 parameter is out of range the function returns NULL.
|
Chris@29
|
473
|
Chris@29
|
474 @param device A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
|
Chris@29
|
475
|
Chris@29
|
476 @note PortAudio manages the memory referenced by the returned pointer,
|
Chris@29
|
477 the client must not manipulate or free the memory. The pointer is only
|
Chris@29
|
478 guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate().
|
Chris@29
|
479
|
Chris@29
|
480 @see PaDeviceInfo, PaDeviceIndex
|
Chris@29
|
481 */
|
Chris@29
|
482 const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
|
Chris@29
|
483
|
Chris@29
|
484
|
Chris@29
|
485 /** Parameters for one direction (input or output) of a stream.
|
Chris@29
|
486 */
|
Chris@29
|
487 typedef struct PaStreamParameters
|
Chris@29
|
488 {
|
Chris@29
|
489 /** A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
|
Chris@29
|
490 specifying the device to be used or the special constant
|
Chris@29
|
491 paUseHostApiSpecificDeviceSpecification which indicates that the actual
|
Chris@29
|
492 device(s) to use are specified in hostApiSpecificStreamInfo.
|
Chris@29
|
493 This field must not be set to paNoDevice.
|
Chris@29
|
494 */
|
Chris@29
|
495 PaDeviceIndex device;
|
Chris@29
|
496
|
Chris@29
|
497 /** The number of channels of sound to be delivered to the
|
Chris@29
|
498 stream callback or accessed by Pa_ReadStream() or Pa_WriteStream().
|
Chris@29
|
499 It can range from 1 to the value of maxInputChannels in the
|
Chris@29
|
500 PaDeviceInfo record for the device specified by the device parameter.
|
Chris@29
|
501 */
|
Chris@29
|
502 int channelCount;
|
Chris@29
|
503
|
Chris@29
|
504 /** The sample format of the buffer provided to the stream callback,
|
Chris@29
|
505 a_ReadStream() or Pa_WriteStream(). It may be any of the formats described
|
Chris@29
|
506 by the PaSampleFormat enumeration.
|
Chris@29
|
507 */
|
Chris@29
|
508 PaSampleFormat sampleFormat;
|
Chris@29
|
509
|
Chris@29
|
510 /** The desired latency in seconds. Where practical, implementations should
|
Chris@29
|
511 configure their latency based on these parameters, otherwise they may
|
Chris@29
|
512 choose the closest viable latency instead. Unless the suggested latency
|
Chris@29
|
513 is greater than the absolute upper limit for the device implementations
|
Chris@29
|
514 should round the suggestedLatency up to the next practical value - ie to
|
Chris@29
|
515 provide an equal or higher latency than suggestedLatency wherever possible.
|
Chris@29
|
516 Actual latency values for an open stream may be retrieved using the
|
Chris@29
|
517 inputLatency and outputLatency fields of the PaStreamInfo structure
|
Chris@29
|
518 returned by Pa_GetStreamInfo().
|
Chris@29
|
519 @see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo
|
Chris@29
|
520 */
|
Chris@29
|
521 PaTime suggestedLatency;
|
Chris@29
|
522
|
Chris@29
|
523 /** An optional pointer to a host api specific data structure
|
Chris@29
|
524 containing additional information for device setup and/or stream processing.
|
Chris@29
|
525 hostApiSpecificStreamInfo is never required for correct operation,
|
Chris@29
|
526 if not used it should be set to NULL.
|
Chris@29
|
527 */
|
Chris@29
|
528 void *hostApiSpecificStreamInfo;
|
Chris@29
|
529
|
Chris@29
|
530 } PaStreamParameters;
|
Chris@29
|
531
|
Chris@29
|
532
|
Chris@29
|
533 /** Return code for Pa_IsFormatSupported indicating success. */
|
Chris@29
|
534 #define paFormatIsSupported (0)
|
Chris@29
|
535
|
Chris@29
|
536 /** Determine whether it would be possible to open a stream with the specified
|
Chris@29
|
537 parameters.
|
Chris@29
|
538
|
Chris@29
|
539 @param inputParameters A structure that describes the input parameters used to
|
Chris@29
|
540 open a stream. The suggestedLatency field is ignored. See PaStreamParameters
|
Chris@29
|
541 for a description of these parameters. inputParameters must be NULL for
|
Chris@29
|
542 output-only streams.
|
Chris@29
|
543
|
Chris@29
|
544 @param outputParameters A structure that describes the output parameters used
|
Chris@29
|
545 to open a stream. The suggestedLatency field is ignored. See PaStreamParameters
|
Chris@29
|
546 for a description of these parameters. outputParameters must be NULL for
|
Chris@29
|
547 input-only streams.
|
Chris@29
|
548
|
Chris@29
|
549 @param sampleRate The required sampleRate. For full-duplex streams it is the
|
Chris@29
|
550 sample rate for both input and output
|
Chris@29
|
551
|
Chris@29
|
552 @return Returns 0 if the format is supported, and an error code indicating why
|
Chris@29
|
553 the format is not supported otherwise. The constant paFormatIsSupported is
|
Chris@29
|
554 provided to compare with the return value for success.
|
Chris@29
|
555
|
Chris@29
|
556 @see paFormatIsSupported, PaStreamParameters
|
Chris@29
|
557 */
|
Chris@29
|
558 PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
|
Chris@29
|
559 const PaStreamParameters *outputParameters,
|
Chris@29
|
560 double sampleRate );
|
Chris@29
|
561
|
Chris@29
|
562
|
Chris@29
|
563
|
Chris@29
|
564 /* Streaming types and functions */
|
Chris@29
|
565
|
Chris@29
|
566
|
Chris@29
|
567 /**
|
Chris@29
|
568 A single PaStream can provide multiple channels of real-time
|
Chris@29
|
569 streaming audio input and output to a client application. A stream
|
Chris@29
|
570 provides access to audio hardware represented by one or more
|
Chris@29
|
571 PaDevices. Depending on the underlying Host API, it may be possible
|
Chris@29
|
572 to open multiple streams using the same device, however this behavior
|
Chris@29
|
573 is implementation defined. Portable applications should assume that
|
Chris@29
|
574 a PaDevice may be simultaneously used by at most one PaStream.
|
Chris@29
|
575
|
Chris@29
|
576 Pointers to PaStream objects are passed between PortAudio functions that
|
Chris@29
|
577 operate on streams.
|
Chris@29
|
578
|
Chris@29
|
579 @see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream,
|
Chris@29
|
580 Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive,
|
Chris@29
|
581 Pa_GetStreamTime, Pa_GetStreamCpuLoad
|
Chris@29
|
582
|
Chris@29
|
583 */
|
Chris@29
|
584 typedef void PaStream;
|
Chris@29
|
585
|
Chris@29
|
586
|
Chris@29
|
587 /** Can be passed as the framesPerBuffer parameter to Pa_OpenStream()
|
Chris@29
|
588 or Pa_OpenDefaultStream() to indicate that the stream callback will
|
Chris@29
|
589 accept buffers of any size.
|
Chris@29
|
590 */
|
Chris@29
|
591 #define paFramesPerBufferUnspecified (0)
|
Chris@29
|
592
|
Chris@29
|
593
|
Chris@29
|
594 /** Flags used to control the behavior of a stream. They are passed as
|
Chris@29
|
595 parameters to Pa_OpenStream or Pa_OpenDefaultStream. Multiple flags may be
|
Chris@29
|
596 ORed together.
|
Chris@29
|
597
|
Chris@29
|
598 @see Pa_OpenStream, Pa_OpenDefaultStream
|
Chris@29
|
599 @see paNoFlag, paClipOff, paDitherOff, paNeverDropInput,
|
Chris@29
|
600 paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags
|
Chris@29
|
601 */
|
Chris@29
|
602 typedef unsigned long PaStreamFlags;
|
Chris@29
|
603
|
Chris@29
|
604 /** @see PaStreamFlags */
|
Chris@29
|
605 #define paNoFlag ((PaStreamFlags) 0)
|
Chris@29
|
606
|
Chris@29
|
607 /** Disable default clipping of out of range samples.
|
Chris@29
|
608 @see PaStreamFlags
|
Chris@29
|
609 */
|
Chris@29
|
610 #define paClipOff ((PaStreamFlags) 0x00000001)
|
Chris@29
|
611
|
Chris@29
|
612 /** Disable default dithering.
|
Chris@29
|
613 @see PaStreamFlags
|
Chris@29
|
614 */
|
Chris@29
|
615 #define paDitherOff ((PaStreamFlags) 0x00000002)
|
Chris@29
|
616
|
Chris@29
|
617 /** Flag requests that where possible a full duplex stream will not discard
|
Chris@29
|
618 overflowed input samples without calling the stream callback. This flag is
|
Chris@29
|
619 only valid for full duplex callback streams and only when used in combination
|
Chris@29
|
620 with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using
|
Chris@29
|
621 this flag incorrectly results in a paInvalidFlag error being returned from
|
Chris@29
|
622 Pa_OpenStream and Pa_OpenDefaultStream.
|
Chris@29
|
623
|
Chris@29
|
624 @see PaStreamFlags, paFramesPerBufferUnspecified
|
Chris@29
|
625 */
|
Chris@29
|
626 #define paNeverDropInput ((PaStreamFlags) 0x00000004)
|
Chris@29
|
627
|
Chris@29
|
628 /** Call the stream callback to fill initial output buffers, rather than the
|
Chris@29
|
629 default behavior of priming the buffers with zeros (silence). This flag has
|
Chris@29
|
630 no effect for input-only and blocking read/write streams.
|
Chris@29
|
631
|
Chris@29
|
632 @see PaStreamFlags
|
Chris@29
|
633 */
|
Chris@29
|
634 #define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
|
Chris@29
|
635
|
Chris@29
|
636 /** A mask specifying the platform specific bits.
|
Chris@29
|
637 @see PaStreamFlags
|
Chris@29
|
638 */
|
Chris@29
|
639 #define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
|
Chris@29
|
640
|
Chris@29
|
641 /**
|
Chris@29
|
642 Timing information for the buffers passed to the stream callback.
|
Chris@29
|
643 */
|
Chris@29
|
644 typedef struct PaStreamCallbackTimeInfo{
|
Chris@29
|
645 PaTime inputBufferAdcTime;
|
Chris@29
|
646 PaTime currentTime;
|
Chris@29
|
647 PaTime outputBufferDacTime;
|
Chris@29
|
648 } PaStreamCallbackTimeInfo;
|
Chris@29
|
649
|
Chris@29
|
650
|
Chris@29
|
651 /**
|
Chris@29
|
652 Flag bit constants for the statusFlags to PaStreamCallback.
|
Chris@29
|
653
|
Chris@29
|
654 @see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow,
|
Chris@29
|
655 paPrimingOutput
|
Chris@29
|
656 */
|
Chris@29
|
657 typedef unsigned long PaStreamCallbackFlags;
|
Chris@29
|
658
|
Chris@29
|
659 /** In a stream opened with paFramesPerBufferUnspecified, indicates that
|
Chris@29
|
660 input data is all silence (zeros) because no real data is available. In a
|
Chris@29
|
661 stream opened without paFramesPerBufferUnspecified, it indicates that one or
|
Chris@29
|
662 more zero samples have been inserted into the input buffer to compensate
|
Chris@29
|
663 for an input underflow.
|
Chris@29
|
664 @see PaStreamCallbackFlags
|
Chris@29
|
665 */
|
Chris@29
|
666 #define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001)
|
Chris@29
|
667
|
Chris@29
|
668 /** In a stream opened with paFramesPerBufferUnspecified, indicates that data
|
Chris@29
|
669 prior to the first sample of the input buffer was discarded due to an
|
Chris@29
|
670 overflow, possibly because the stream callback is using too much CPU time.
|
Chris@29
|
671 Otherwise indicates that data prior to one or more samples in the
|
Chris@29
|
672 input buffer was discarded.
|
Chris@29
|
673 @see PaStreamCallbackFlags
|
Chris@29
|
674 */
|
Chris@29
|
675 #define paInputOverflow ((PaStreamCallbackFlags) 0x00000002)
|
Chris@29
|
676
|
Chris@29
|
677 /** Indicates that output data (or a gap) was inserted, possibly because the
|
Chris@29
|
678 stream callback is using too much CPU time.
|
Chris@29
|
679 @see PaStreamCallbackFlags
|
Chris@29
|
680 */
|
Chris@29
|
681 #define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004)
|
Chris@29
|
682
|
Chris@29
|
683 /** Indicates that output data will be discarded because no room is available.
|
Chris@29
|
684 @see PaStreamCallbackFlags
|
Chris@29
|
685 */
|
Chris@29
|
686 #define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008)
|
Chris@29
|
687
|
Chris@29
|
688 /** Some of all of the output data will be used to prime the stream, input
|
Chris@29
|
689 data may be zero.
|
Chris@29
|
690 @see PaStreamCallbackFlags
|
Chris@29
|
691 */
|
Chris@29
|
692 #define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010)
|
Chris@29
|
693
|
Chris@29
|
694 /**
|
Chris@29
|
695 Allowable return values for the PaStreamCallback.
|
Chris@29
|
696 @see PaStreamCallback
|
Chris@29
|
697 */
|
Chris@29
|
698 typedef enum PaStreamCallbackResult
|
Chris@29
|
699 {
|
Chris@29
|
700 paContinue=0,
|
Chris@29
|
701 paComplete=1,
|
Chris@29
|
702 paAbort=2
|
Chris@29
|
703 } PaStreamCallbackResult;
|
Chris@29
|
704
|
Chris@29
|
705
|
Chris@29
|
706 /**
|
Chris@29
|
707 Functions of type PaStreamCallback are implemented by PortAudio clients.
|
Chris@29
|
708 They consume, process or generate audio in response to requests from an
|
Chris@29
|
709 active PortAudio stream.
|
Chris@29
|
710
|
Chris@29
|
711 @param input and @param output are either arrays of interleaved samples or;
|
Chris@29
|
712 if non-interleaved samples were requested using the paNonInterleaved sample
|
Chris@29
|
713 format flag, an array of buffer pointers, one non-interleaved buffer for
|
Chris@29
|
714 each channel.
|
Chris@29
|
715
|
Chris@29
|
716 The format, packing and number of channels used by the buffers are
|
Chris@29
|
717 determined by parameters to Pa_OpenStream().
|
Chris@29
|
718
|
Chris@29
|
719 @param frameCount The number of sample frames to be processed by
|
Chris@29
|
720 the stream callback.
|
Chris@29
|
721
|
Chris@29
|
722 @param timeInfo The time in seconds when the first sample of the input
|
Chris@29
|
723 buffer was received at the audio input, the time in seconds when the first
|
Chris@29
|
724 sample of the output buffer will begin being played at the audio output, and
|
Chris@29
|
725 the time in seconds when the stream callback was called.
|
Chris@29
|
726 See also Pa_GetStreamTime()
|
Chris@29
|
727
|
Chris@29
|
728 @param statusFlags Flags indicating whether input and/or output buffers
|
Chris@29
|
729 have been inserted or will be dropped to overcome underflow or overflow
|
Chris@29
|
730 conditions.
|
Chris@29
|
731
|
Chris@29
|
732 @param userData The value of a user supplied pointer passed to
|
Chris@29
|
733 Pa_OpenStream() intended for storing synthesis data etc.
|
Chris@29
|
734
|
Chris@29
|
735 @return
|
Chris@29
|
736 The stream callback should return one of the values in the
|
Chris@29
|
737 PaStreamCallbackResult enumeration. To ensure that the callback continues
|
Chris@29
|
738 to be called, it should return paContinue (0). Either paComplete or paAbort
|
Chris@29
|
739 can be returned to finish stream processing, after either of these values is
|
Chris@29
|
740 returned the callback will not be called again. If paAbort is returned the
|
Chris@29
|
741 stream will finish as soon as possible. If paComplete is returned, the stream
|
Chris@29
|
742 will continue until all buffers generated by the callback have been played.
|
Chris@29
|
743 This may be useful in applications such as soundfile players where a specific
|
Chris@29
|
744 duration of output is required. However, it is not necessary to utilize this
|
Chris@29
|
745 mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also
|
Chris@29
|
746 be used to stop the stream. The callback must always fill the entire output
|
Chris@29
|
747 buffer irrespective of its return value.
|
Chris@29
|
748
|
Chris@29
|
749 @see Pa_OpenStream, Pa_OpenDefaultStream
|
Chris@29
|
750
|
Chris@29
|
751 @note With the exception of Pa_GetStreamCpuLoad() it is not permissible to call
|
Chris@29
|
752 PortAudio API functions from within the stream callback.
|
Chris@29
|
753 */
|
Chris@29
|
754 typedef int PaStreamCallback(
|
Chris@29
|
755 const void *input, void *output,
|
Chris@29
|
756 unsigned long frameCount,
|
Chris@29
|
757 const PaStreamCallbackTimeInfo* timeInfo,
|
Chris@29
|
758 PaStreamCallbackFlags statusFlags,
|
Chris@29
|
759 void *userData );
|
Chris@29
|
760
|
Chris@29
|
761
|
Chris@29
|
762 /** Opens a stream for either input, output or both.
|
Chris@29
|
763
|
Chris@29
|
764 @param stream The address of a PaStream pointer which will receive
|
Chris@29
|
765 a pointer to the newly opened stream.
|
Chris@29
|
766
|
Chris@29
|
767 @param inputParameters A structure that describes the input parameters used by
|
Chris@29
|
768 the opened stream. See PaStreamParameters for a description of these parameters.
|
Chris@29
|
769 inputParameters must be NULL for output-only streams.
|
Chris@29
|
770
|
Chris@29
|
771 @param outputParameters A structure that describes the output parameters used by
|
Chris@29
|
772 the opened stream. See PaStreamParameters for a description of these parameters.
|
Chris@29
|
773 outputParameters must be NULL for input-only streams.
|
Chris@29
|
774
|
Chris@29
|
775 @param sampleRate The desired sampleRate. For full-duplex streams it is the
|
Chris@29
|
776 sample rate for both input and output
|
Chris@29
|
777
|
Chris@29
|
778 @param framesPerBuffer The number of frames passed to the stream callback
|
Chris@29
|
779 function, or the preferred block granularity for a blocking read/write stream.
|
Chris@29
|
780 The special value paFramesPerBufferUnspecified (0) may be used to request that
|
Chris@29
|
781 the stream callback will receive an optimal (and possibly varying) number of
|
Chris@29
|
782 frames based on host requirements and the requested latency settings.
|
Chris@29
|
783 Note: With some host APIs, the use of non-zero framesPerBuffer for a callback
|
Chris@29
|
784 stream may introduce an additional layer of buffering which could introduce
|
Chris@29
|
785 additional latency. PortAudio guarantees that the additional latency
|
Chris@29
|
786 will be kept to the theoretical minimum however, it is strongly recommended
|
Chris@29
|
787 that a non-zero framesPerBuffer value only be used when your algorithm
|
Chris@29
|
788 requires a fixed number of frames per stream callback.
|
Chris@29
|
789
|
Chris@29
|
790 @param streamFlags Flags which modify the behavior of the streaming process.
|
Chris@29
|
791 This parameter may contain a combination of flags ORed together. Some flags may
|
Chris@29
|
792 only be relevant to certain buffer formats.
|
Chris@29
|
793
|
Chris@29
|
794 @param streamCallback A pointer to a client supplied function that is responsible
|
Chris@29
|
795 for processing and filling input and output buffers. If this parameter is NULL
|
Chris@29
|
796 the stream will be opened in 'blocking read/write' mode. In blocking mode,
|
Chris@29
|
797 the client can receive sample data using Pa_ReadStream and write sample data
|
Chris@29
|
798 using Pa_WriteStream, the number of samples that may be read or written
|
Chris@29
|
799 without blocking is returned by Pa_GetStreamReadAvailable and
|
Chris@29
|
800 Pa_GetStreamWriteAvailable respectively.
|
Chris@29
|
801
|
Chris@29
|
802 @param userData A client supplied pointer which is passed to the stream callback
|
Chris@29
|
803 function. It could for example, contain a pointer to instance data necessary
|
Chris@29
|
804 for processing the audio buffers. This parameter is ignored if streamCallback
|
Chris@29
|
805 is NULL.
|
Chris@29
|
806
|
Chris@29
|
807 @return
|
Chris@29
|
808 Upon success Pa_OpenStream() returns paNoError and places a pointer to a
|
Chris@29
|
809 valid PaStream in the stream argument. The stream is inactive (stopped).
|
Chris@29
|
810 If a call to Pa_OpenStream() fails, a non-zero error code is returned (see
|
Chris@29
|
811 PaError for possible error codes) and the value of stream is invalid.
|
Chris@29
|
812
|
Chris@29
|
813 @see PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream,
|
Chris@29
|
814 Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable
|
Chris@29
|
815 */
|
Chris@29
|
816 PaError Pa_OpenStream( PaStream** stream,
|
Chris@29
|
817 const PaStreamParameters *inputParameters,
|
Chris@29
|
818 const PaStreamParameters *outputParameters,
|
Chris@29
|
819 double sampleRate,
|
Chris@29
|
820 unsigned long framesPerBuffer,
|
Chris@29
|
821 PaStreamFlags streamFlags,
|
Chris@29
|
822 PaStreamCallback *streamCallback,
|
Chris@29
|
823 void *userData );
|
Chris@29
|
824
|
Chris@29
|
825
|
Chris@29
|
826 /** A simplified version of Pa_OpenStream() that opens the default input
|
Chris@29
|
827 and/or output devices.
|
Chris@29
|
828
|
Chris@29
|
829 @param stream The address of a PaStream pointer which will receive
|
Chris@29
|
830 a pointer to the newly opened stream.
|
Chris@29
|
831
|
Chris@29
|
832 @param numInputChannels The number of channels of sound that will be supplied
|
Chris@29
|
833 to the stream callback or returned by Pa_ReadStream. It can range from 1 to
|
Chris@29
|
834 the value of maxInputChannels in the PaDeviceInfo record for the default input
|
Chris@29
|
835 device. If 0 the stream is opened as an output-only stream.
|
Chris@29
|
836
|
Chris@29
|
837 @param numOutputChannels The number of channels of sound to be delivered to the
|
Chris@29
|
838 stream callback or passed to Pa_WriteStream. It can range from 1 to the value
|
Chris@29
|
839 of maxOutputChannels in the PaDeviceInfo record for the default output device.
|
Chris@29
|
840 If 0 the stream is opened as an output-only stream.
|
Chris@29
|
841
|
Chris@29
|
842 @param sampleFormat The sample format of both the input and output buffers
|
Chris@29
|
843 provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream.
|
Chris@29
|
844 sampleFormat may be any of the formats described by the PaSampleFormat
|
Chris@29
|
845 enumeration.
|
Chris@29
|
846
|
Chris@29
|
847 @param sampleRate Same as Pa_OpenStream parameter of the same name.
|
Chris@29
|
848 @param framesPerBuffer Same as Pa_OpenStream parameter of the same name.
|
Chris@29
|
849 @param streamCallback Same as Pa_OpenStream parameter of the same name.
|
Chris@29
|
850 @param userData Same as Pa_OpenStream parameter of the same name.
|
Chris@29
|
851
|
Chris@29
|
852 @return As for Pa_OpenStream
|
Chris@29
|
853
|
Chris@29
|
854 @see Pa_OpenStream, PaStreamCallback
|
Chris@29
|
855 */
|
Chris@29
|
856 PaError Pa_OpenDefaultStream( PaStream** stream,
|
Chris@29
|
857 int numInputChannels,
|
Chris@29
|
858 int numOutputChannels,
|
Chris@29
|
859 PaSampleFormat sampleFormat,
|
Chris@29
|
860 double sampleRate,
|
Chris@29
|
861 unsigned long framesPerBuffer,
|
Chris@29
|
862 PaStreamCallback *streamCallback,
|
Chris@29
|
863 void *userData );
|
Chris@29
|
864
|
Chris@29
|
865
|
Chris@29
|
866 /** Closes an audio stream. If the audio stream is active it
|
Chris@29
|
867 discards any pending buffers as if Pa_AbortStream() had been called.
|
Chris@29
|
868 */
|
Chris@29
|
869 PaError Pa_CloseStream( PaStream *stream );
|
Chris@29
|
870
|
Chris@29
|
871
|
Chris@29
|
872 /** Functions of type PaStreamFinishedCallback are implemented by PortAudio
|
Chris@29
|
873 clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback
|
Chris@29
|
874 function. Once registered they are called when the stream becomes inactive
|
Chris@29
|
875 (ie once a call to Pa_StopStream() will not block).
|
Chris@29
|
876 A stream will become inactive after the stream callback returns non-zero,
|
Chris@29
|
877 or when Pa_StopStream or Pa_AbortStream is called. For a stream providing audio
|
Chris@29
|
878 output, if the stream callback returns paComplete, or Pa_StopStream is called,
|
Chris@29
|
879 the stream finished callback will not be called until all generated sample data
|
Chris@29
|
880 has been played.
|
Chris@29
|
881
|
Chris@29
|
882 @param userData The userData parameter supplied to Pa_OpenStream()
|
Chris@29
|
883
|
Chris@29
|
884 @see Pa_SetStreamFinishedCallback
|
Chris@29
|
885 */
|
Chris@29
|
886 typedef void PaStreamFinishedCallback( void *userData );
|
Chris@29
|
887
|
Chris@29
|
888
|
Chris@29
|
889 /** Register a stream finished callback function which will be called when the
|
Chris@29
|
890 stream becomes inactive. See the description of PaStreamFinishedCallback for
|
Chris@29
|
891 further details about when the callback will be called.
|
Chris@29
|
892
|
Chris@29
|
893 @param stream a pointer to a PaStream that is in the stopped state - if the
|
Chris@29
|
894 stream is not stopped, the stream's finished callback will remain unchanged
|
Chris@29
|
895 and an error code will be returned.
|
Chris@29
|
896
|
Chris@29
|
897 @param streamFinishedCallback a pointer to a function with the same signature
|
Chris@29
|
898 as PaStreamFinishedCallback, that will be called when the stream becomes
|
Chris@29
|
899 inactive. Passing NULL for this parameter will un-register a previously
|
Chris@29
|
900 registered stream finished callback function.
|
Chris@29
|
901
|
Chris@29
|
902 @return on success returns paNoError, otherwise an error code indicating the cause
|
Chris@29
|
903 of the error.
|
Chris@29
|
904
|
Chris@29
|
905 @see PaStreamFinishedCallback
|
Chris@29
|
906 */
|
Chris@29
|
907 PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
|
Chris@29
|
908
|
Chris@29
|
909
|
Chris@29
|
910 /** Commences audio processing.
|
Chris@29
|
911 */
|
Chris@29
|
912 PaError Pa_StartStream( PaStream *stream );
|
Chris@29
|
913
|
Chris@29
|
914
|
Chris@29
|
915 /** Terminates audio processing. It waits until all pending
|
Chris@29
|
916 audio buffers have been played before it returns.
|
Chris@29
|
917 */
|
Chris@29
|
918 PaError Pa_StopStream( PaStream *stream );
|
Chris@29
|
919
|
Chris@29
|
920
|
Chris@29
|
921 /** Terminates audio processing immediately without waiting for pending
|
Chris@29
|
922 buffers to complete.
|
Chris@29
|
923 */
|
Chris@29
|
924 PaError Pa_AbortStream( PaStream *stream );
|
Chris@29
|
925
|
Chris@29
|
926
|
Chris@29
|
927 /** Determine whether the stream is stopped.
|
Chris@29
|
928 A stream is considered to be stopped prior to a successful call to
|
Chris@29
|
929 Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream.
|
Chris@29
|
930 If a stream callback returns a value other than paContinue the stream is NOT
|
Chris@29
|
931 considered to be stopped.
|
Chris@29
|
932
|
Chris@29
|
933 @return Returns one (1) when the stream is stopped, zero (0) when
|
Chris@29
|
934 the stream is running or, a PaErrorCode (which are always negative) if
|
Chris@29
|
935 PortAudio is not initialized or an error is encountered.
|
Chris@29
|
936
|
Chris@29
|
937 @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive
|
Chris@29
|
938 */
|
Chris@29
|
939 PaError Pa_IsStreamStopped( PaStream *stream );
|
Chris@29
|
940
|
Chris@29
|
941
|
Chris@29
|
942 /** Determine whether the stream is active.
|
Chris@29
|
943 A stream is active after a successful call to Pa_StartStream(), until it
|
Chris@29
|
944 becomes inactive either as a result of a call to Pa_StopStream() or
|
Chris@29
|
945 Pa_AbortStream(), or as a result of a return value other than paContinue from
|
Chris@29
|
946 the stream callback. In the latter case, the stream is considered inactive
|
Chris@29
|
947 after the last buffer has finished playing.
|
Chris@29
|
948
|
Chris@29
|
949 @return Returns one (1) when the stream is active (ie playing or recording
|
Chris@29
|
950 audio), zero (0) when not playing or, a PaErrorCode (which are always negative)
|
Chris@29
|
951 if PortAudio is not initialized or an error is encountered.
|
Chris@29
|
952
|
Chris@29
|
953 @see Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped
|
Chris@29
|
954 */
|
Chris@29
|
955 PaError Pa_IsStreamActive( PaStream *stream );
|
Chris@29
|
956
|
Chris@29
|
957
|
Chris@29
|
958
|
Chris@29
|
959 /** A structure containing unchanging information about an open stream.
|
Chris@29
|
960 @see Pa_GetStreamInfo
|
Chris@29
|
961 */
|
Chris@29
|
962
|
Chris@29
|
963 typedef struct PaStreamInfo
|
Chris@29
|
964 {
|
Chris@29
|
965 /** this is struct version 1 */
|
Chris@29
|
966 int structVersion;
|
Chris@29
|
967
|
Chris@29
|
968 /** The input latency of the stream in seconds. This value provides the most
|
Chris@29
|
969 accurate estimate of input latency available to the implementation. It may
|
Chris@29
|
970 differ significantly from the suggestedLatency value passed to Pa_OpenStream().
|
Chris@29
|
971 The value of this field will be zero (0.) for output-only streams.
|
Chris@29
|
972 @see PaTime
|
Chris@29
|
973 */
|
Chris@29
|
974 PaTime inputLatency;
|
Chris@29
|
975
|
Chris@29
|
976 /** The output latency of the stream in seconds. This value provides the most
|
Chris@29
|
977 accurate estimate of output latency available to the implementation. It may
|
Chris@29
|
978 differ significantly from the suggestedLatency value passed to Pa_OpenStream().
|
Chris@29
|
979 The value of this field will be zero (0.) for input-only streams.
|
Chris@29
|
980 @see PaTime
|
Chris@29
|
981 */
|
Chris@29
|
982 PaTime outputLatency;
|
Chris@29
|
983
|
Chris@29
|
984 /** The sample rate of the stream in Hertz (samples per second). In cases
|
Chris@29
|
985 where the hardware sample rate is inaccurate and PortAudio is aware of it,
|
Chris@29
|
986 the value of this field may be different from the sampleRate parameter
|
Chris@29
|
987 passed to Pa_OpenStream(). If information about the actual hardware sample
|
Chris@29
|
988 rate is not available, this field will have the same value as the sampleRate
|
Chris@29
|
989 parameter passed to Pa_OpenStream().
|
Chris@29
|
990 */
|
Chris@29
|
991 double sampleRate;
|
Chris@29
|
992
|
Chris@29
|
993 } PaStreamInfo;
|
Chris@29
|
994
|
Chris@29
|
995
|
Chris@29
|
996 /** Retrieve a pointer to a PaStreamInfo structure containing information
|
Chris@29
|
997 about the specified stream.
|
Chris@29
|
998 @return A pointer to an immutable PaStreamInfo structure. If the stream
|
Chris@29
|
999 parameter invalid, or an error is encountered, the function returns NULL.
|
Chris@29
|
1000
|
Chris@29
|
1001 @param stream A pointer to an open stream previously created with Pa_OpenStream.
|
Chris@29
|
1002
|
Chris@29
|
1003 @note PortAudio manages the memory referenced by the returned pointer,
|
Chris@29
|
1004 the client must not manipulate or free the memory. The pointer is only
|
Chris@29
|
1005 guaranteed to be valid until the specified stream is closed.
|
Chris@29
|
1006
|
Chris@29
|
1007 @see PaStreamInfo
|
Chris@29
|
1008 */
|
Chris@29
|
1009 const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
|
Chris@29
|
1010
|
Chris@29
|
1011
|
Chris@29
|
1012 /** Returns the current time in seconds for a stream according to the same clock used
|
Chris@29
|
1013 to generate callback PaStreamCallbackTimeInfo timestamps. The time values are
|
Chris@29
|
1014 monotonically increasing and have unspecified origin.
|
Chris@29
|
1015
|
Chris@29
|
1016 Pa_GetStreamTime returns valid time values for the entire life of the stream,
|
Chris@29
|
1017 from when the stream is opened until it is closed. Starting and stopping the stream
|
Chris@29
|
1018 does not affect the passage of time returned by Pa_GetStreamTime.
|
Chris@29
|
1019
|
Chris@29
|
1020 This time may be used for synchronizing other events to the audio stream, for
|
Chris@29
|
1021 example synchronizing audio to MIDI.
|
Chris@29
|
1022
|
Chris@29
|
1023 @return The stream's current time in seconds, or 0 if an error occurred.
|
Chris@29
|
1024
|
Chris@29
|
1025 @see PaTime, PaStreamCallback, PaStreamCallbackTimeInfo
|
Chris@29
|
1026 */
|
Chris@29
|
1027 PaTime Pa_GetStreamTime( PaStream *stream );
|
Chris@29
|
1028
|
Chris@29
|
1029
|
Chris@29
|
1030 /** Retrieve CPU usage information for the specified stream.
|
Chris@29
|
1031 The "CPU Load" is a fraction of total CPU time consumed by a callback stream's
|
Chris@29
|
1032 audio processing routines including, but not limited to the client supplied
|
Chris@29
|
1033 stream callback. This function does not work with blocking read/write streams.
|
Chris@29
|
1034
|
Chris@29
|
1035 This function may be called from the stream callback function or the
|
Chris@29
|
1036 application.
|
Chris@29
|
1037
|
Chris@29
|
1038 @return
|
Chris@29
|
1039 A floating point value, typically between 0.0 and 1.0, where 1.0 indicates
|
Chris@29
|
1040 that the stream callback is consuming the maximum number of CPU cycles possible
|
Chris@29
|
1041 to maintain real-time operation. A value of 0.5 would imply that PortAudio and
|
Chris@29
|
1042 the stream callback was consuming roughly 50% of the available CPU time. The
|
Chris@29
|
1043 return value may exceed 1.0. A value of 0.0 will always be returned for a
|
Chris@29
|
1044 blocking read/write stream, or if an error occurs.
|
Chris@29
|
1045 */
|
Chris@29
|
1046 double Pa_GetStreamCpuLoad( PaStream* stream );
|
Chris@29
|
1047
|
Chris@29
|
1048
|
Chris@29
|
1049 /** Read samples from an input stream. The function doesn't return until
|
Chris@29
|
1050 the entire buffer has been filled - this may involve waiting for the operating
|
Chris@29
|
1051 system to supply the data.
|
Chris@29
|
1052
|
Chris@29
|
1053 @param stream A pointer to an open stream previously created with Pa_OpenStream.
|
Chris@29
|
1054
|
Chris@29
|
1055 @param buffer A pointer to a buffer of sample frames. The buffer contains
|
Chris@29
|
1056 samples in the format specified by the inputParameters->sampleFormat field
|
Chris@29
|
1057 used to open the stream, and the number of channels specified by
|
Chris@29
|
1058 inputParameters->numChannels. If non-interleaved samples were requested using
|
Chris@29
|
1059 the paNonInterleaved sample format flag, buffer is a pointer to the first element
|
Chris@29
|
1060 of an array of buffer pointers, one non-interleaved buffer for each channel.
|
Chris@29
|
1061
|
Chris@29
|
1062 @param frames The number of frames to be read into buffer. This parameter
|
Chris@29
|
1063 is not constrained to a specific range, however high performance applications
|
Chris@29
|
1064 will want to match this parameter to the framesPerBuffer parameter used
|
Chris@29
|
1065 when opening the stream.
|
Chris@29
|
1066
|
Chris@29
|
1067 @return On success PaNoError will be returned, or PaInputOverflowed if input
|
Chris@29
|
1068 data was discarded by PortAudio after the previous call and before this call.
|
Chris@29
|
1069 */
|
Chris@29
|
1070 PaError Pa_ReadStream( PaStream* stream,
|
Chris@29
|
1071 void *buffer,
|
Chris@29
|
1072 unsigned long frames );
|
Chris@29
|
1073
|
Chris@29
|
1074
|
Chris@29
|
1075 /** Write samples to an output stream. This function doesn't return until the
|
Chris@29
|
1076 entire buffer has been consumed - this may involve waiting for the operating
|
Chris@29
|
1077 system to consume the data.
|
Chris@29
|
1078
|
Chris@29
|
1079 @param stream A pointer to an open stream previously created with Pa_OpenStream.
|
Chris@29
|
1080
|
Chris@29
|
1081 @param buffer A pointer to a buffer of sample frames. The buffer contains
|
Chris@29
|
1082 samples in the format specified by the outputParameters->sampleFormat field
|
Chris@29
|
1083 used to open the stream, and the number of channels specified by
|
Chris@29
|
1084 outputParameters->numChannels. If non-interleaved samples were requested using
|
Chris@29
|
1085 the paNonInterleaved sample format flag, buffer is a pointer to the first element
|
Chris@29
|
1086 of an array of buffer pointers, one non-interleaved buffer for each channel.
|
Chris@29
|
1087
|
Chris@29
|
1088 @param frames The number of frames to be written from buffer. This parameter
|
Chris@29
|
1089 is not constrained to a specific range, however high performance applications
|
Chris@29
|
1090 will want to match this parameter to the framesPerBuffer parameter used
|
Chris@29
|
1091 when opening the stream.
|
Chris@29
|
1092
|
Chris@29
|
1093 @return On success PaNoError will be returned, or paOutputUnderflowed if
|
Chris@29
|
1094 additional output data was inserted after the previous call and before this
|
Chris@29
|
1095 call.
|
Chris@29
|
1096 */
|
Chris@29
|
1097 PaError Pa_WriteStream( PaStream* stream,
|
Chris@29
|
1098 const void *buffer,
|
Chris@29
|
1099 unsigned long frames );
|
Chris@29
|
1100
|
Chris@29
|
1101
|
Chris@29
|
1102 /** Retrieve the number of frames that can be read from the stream without
|
Chris@29
|
1103 waiting.
|
Chris@29
|
1104
|
Chris@29
|
1105 @return Returns a non-negative value representing the maximum number of frames
|
Chris@29
|
1106 that can be read from the stream without blocking or busy waiting or, a
|
Chris@29
|
1107 PaErrorCode (which are always negative) if PortAudio is not initialized or an
|
Chris@29
|
1108 error is encountered.
|
Chris@29
|
1109 */
|
Chris@29
|
1110 signed long Pa_GetStreamReadAvailable( PaStream* stream );
|
Chris@29
|
1111
|
Chris@29
|
1112
|
Chris@29
|
1113 /** Retrieve the number of frames that can be written to the stream without
|
Chris@29
|
1114 waiting.
|
Chris@29
|
1115
|
Chris@29
|
1116 @return Returns a non-negative value representing the maximum number of frames
|
Chris@29
|
1117 that can be written to the stream without blocking or busy waiting or, a
|
Chris@29
|
1118 PaErrorCode (which are always negative) if PortAudio is not initialized or an
|
Chris@29
|
1119 error is encountered.
|
Chris@29
|
1120 */
|
Chris@29
|
1121 signed long Pa_GetStreamWriteAvailable( PaStream* stream );
|
Chris@29
|
1122
|
Chris@29
|
1123
|
Chris@29
|
1124 /* Miscellaneous utilities */
|
Chris@29
|
1125
|
Chris@29
|
1126
|
Chris@29
|
1127 /** Retrieve the size of a given sample format in bytes.
|
Chris@29
|
1128
|
Chris@29
|
1129 @return The size in bytes of a single sample in the specified format,
|
Chris@29
|
1130 or paSampleFormatNotSupported if the format is not supported.
|
Chris@29
|
1131 */
|
Chris@29
|
1132 PaError Pa_GetSampleSize( PaSampleFormat format );
|
Chris@29
|
1133
|
Chris@29
|
1134
|
Chris@29
|
1135 /** Put the caller to sleep for at least 'msec' milliseconds. This function is
|
Chris@29
|
1136 provided only as a convenience for authors of portable code (such as the tests
|
Chris@29
|
1137 and examples in the PortAudio distribution.)
|
Chris@29
|
1138
|
Chris@29
|
1139 The function may sleep longer than requested so don't rely on this for accurate
|
Chris@29
|
1140 musical timing.
|
Chris@29
|
1141 */
|
Chris@29
|
1142 void Pa_Sleep( long msec );
|
Chris@29
|
1143
|
Chris@29
|
1144
|
Chris@29
|
1145
|
Chris@29
|
1146 #ifdef __cplusplus
|
Chris@29
|
1147 }
|
Chris@29
|
1148 #endif /* __cplusplus */
|
Chris@29
|
1149 #endif /* PORTAUDIO_H */
|