annotate win64-msvc/include/portaudio.h @ 74:2f2b27544483

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