annotate win32-mingw/include/portaudio.h @ 7:cd13f7cd9bc3

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