annotate src/portaudio_20140130/include/portaudio.h @ 81:7029a4916348

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