PortAudio  2.0
Macros | Functions | Variables

Implements PortAudio API functions defined in portaudio.h, checks some errors, delegates platform-specific behavior to host API implementations. More...

#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "portaudio.h"
#include "pa_util.h"
#include "pa_endianness.h"
#include "pa_types.h"
#include "pa_hostapi.h"
#include "pa_stream.h"
#include "pa_trace.h"
#include "pa_debugprint.h"
#include "pa_gitrevision.h"

Macros

#define paVersionMajor   19
 
#define paVersionMinor   6
 
#define paVersionSubMinor   0
 
#define paVersion   paMakeVersionNumber(paVersionMajor, paVersionMinor, paVersionSubMinor)
 
#define STRINGIFY(x)   #x
 
#define TOSTRING(x)   STRINGIFY(x)
 
#define PA_VERSION_STRING_   TOSTRING(paVersionMajor) "." TOSTRING(paVersionMinor) "." TOSTRING(paVersionSubMinor)
 
#define PA_VERSION_TEXT_   "PortAudio V" PA_VERSION_STRING_ "-devel, revision " TOSTRING(PA_GIT_REVISION)
 
#define PA_LAST_HOST_ERROR_TEXT_LENGTH_   1024
 
#define PA_IS_INITIALISED_   (initializationCount_ != 0)
 

Functions

int Pa_GetVersion (void)
 
const char * Pa_GetVersionText (void)
 
const PaVersionInfoPa_GetVersionInfo (void)
 
void PaUtil_SetLastHostErrorInfo (PaHostApiTypeId hostApiType, long errorCode, const char *errorText)
 
PaError Pa_Initialize (void)
 
PaError Pa_Terminate (void)
 
const PaHostErrorInfoPa_GetLastHostErrorInfo (void)
 
const char * Pa_GetErrorText (PaError errorCode)
 
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex (PaHostApiTypeId type)
 
PaError PaUtil_GetHostApiRepresentation (struct PaUtilHostApiRepresentation **hostApi, PaHostApiTypeId type)
 
PaError PaUtil_DeviceIndexToHostApiDeviceIndex (PaDeviceIndex *hostApiDevice, PaDeviceIndex device, struct PaUtilHostApiRepresentation *hostApi)
 
PaHostApiIndex Pa_GetHostApiCount (void)
 
PaHostApiIndex Pa_GetDefaultHostApi (void)
 
const PaHostApiInfoPa_GetHostApiInfo (PaHostApiIndex hostApi)
 
PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex (PaHostApiIndex hostApi, int hostApiDeviceIndex)
 
PaDeviceIndex Pa_GetDeviceCount (void)
 
PaDeviceIndex Pa_GetDefaultInputDevice (void)
 
PaDeviceIndex Pa_GetDefaultOutputDevice (void)
 
const PaDeviceInfoPa_GetDeviceInfo (PaDeviceIndex device)
 
PaError Pa_IsFormatSupported (const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
 
PaError Pa_OpenStream (PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
 
PaError Pa_OpenDefaultStream (PaStream **stream, int inputChannelCount, int outputChannelCount, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
 
PaError PaUtil_ValidateStreamPointer (PaStream *stream)
 
PaError Pa_CloseStream (PaStream *stream)
 
PaError Pa_SetStreamFinishedCallback (PaStream *stream, PaStreamFinishedCallback *streamFinishedCallback)
 
PaError Pa_StartStream (PaStream *stream)
 
PaError Pa_StopStream (PaStream *stream)
 
PaError Pa_AbortStream (PaStream *stream)
 
PaError Pa_IsStreamStopped (PaStream *stream)
 
PaError Pa_IsStreamActive (PaStream *stream)
 
const PaStreamInfoPa_GetStreamInfo (PaStream *stream)
 
PaTime Pa_GetStreamTime (PaStream *stream)
 
double Pa_GetStreamCpuLoad (PaStream *stream)
 
PaError Pa_ReadStream (PaStream *stream, void *buffer, unsigned long frames)
 
PaError Pa_WriteStream (PaStream *stream, const void *buffer, unsigned long frames)
 
signed long Pa_GetStreamReadAvailable (PaStream *stream)
 
signed long Pa_GetStreamWriteAvailable (PaStream *stream)
 
PaError Pa_GetSampleSize (PaSampleFormat format)
 

Variables

PaUtilStreamRepresentationfirstOpenStream_ = NULL
 

Detailed Description

Implements PortAudio API functions defined in portaudio.h, checks some errors, delegates platform-specific behavior to host API implementations.

Implements the functions defined in the PortAudio API (portaudio.h), validates some parameters and checks for state inconsistencies before forwarding API requests to specific Host API implementations (via the interface declared in pa_hostapi.h), and Streams (via the interface declared in pa_stream.h).

This file manages initialization and termination of Host API implementations via initializer functions stored in the paHostApiInitializers global array (usually defined in an os-specific pa_[os]_hostapis.c file).

This file maintains a list of all open streams and closes them at Pa_Terminate().

Some utility functions declared in pa_util.h are implemented in this file.

All PortAudio API functions can be conditionally compiled with logging code. To compile with logging, define the PA_LOG_API_CALLS precompiler symbol.

Macro Definition Documentation

#define PA_IS_INITIALISED_   (initializationCount_ != 0)
#define PA_LAST_HOST_ERROR_TEXT_LENGTH_   1024
#define PA_VERSION_STRING_   TOSTRING(paVersionMajor) "." TOSTRING(paVersionMinor) "." TOSTRING(paVersionSubMinor)
#define PA_VERSION_TEXT_   "PortAudio V" PA_VERSION_STRING_ "-devel, revision " TOSTRING(PA_GIT_REVISION)

Referenced by Pa_GetVersionText().

This is a combination of paVersionMajor, paVersionMinor and paVersionSubMinor. It will always increase so that version numbers can be compared as integers to see which is later.

Referenced by Pa_GetVersion().

#define paVersionMajor   19

This is incremented if we make incompatible API changes. This version scheme is based loosely on http://semver.org/

#define paVersionMinor   6

This is incremented when we add functionality in a backwards-compatible manner. Or it is set to zero when paVersionMajor is incremented.

#define paVersionSubMinor   0

This is incremented when we make backwards-compatible bug fixes. Or it is set to zero when paVersionMinor changes.

#define STRINGIFY (   x)    #x
#define TOSTRING (   x)    STRINGIFY(x)

Function Documentation

PaError Pa_AbortStream ( PaStream stream)

Terminates audio processing immediately without waiting for pending buffers to complete.

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, paStreamIsStopped, and PaUtil_ValidateStreamPointer().

Referenced by TestStopMode().

PaError Pa_CloseStream ( PaStream stream)
PaHostApiIndex Pa_GetDefaultHostApi ( void  )

Retrieve the index of the default host API. The default host API will be the lowest common denominator host API on the current platform and is unlikely to provide the best performance.

Returns
A non-negative value ranging from 0 to (Pa_GetHostApiCount()-1) indicating the default host API index or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

References PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, paInternalError, and paNotInitialized.

Referenced by Pa_GetDefaultInputDevice(), and Pa_GetDefaultOutputDevice().

PaDeviceIndex Pa_GetDefaultInputDevice ( void  )

Retrieve the index of the default input device. The result can be used in the inputDevice parameter to Pa_OpenStream().

Returns
The default input device index for the default host API, or paNoDevice if no default input device is available or an error was encountered.

References Pa_GetDefaultHostApi(), PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_T, and paNoDevice.

Referenced by main(), and Pa_OpenDefaultStream().

PaDeviceIndex Pa_GetDefaultOutputDevice ( void  )
Retrieve the index of the default output device. The result can be

used in the outputDevice parameter to Pa_OpenStream().

Returns
The default output device index for the default host API, or paNoDevice if no default output device is available or an error was encountered.
Note
On the PC, the user can specify a default device by setting an environment variable. For example, to use device #1.
 set PA_RECOMMENDED_OUTPUT_DEVICE=1
The user should first determine the available device ids by using the supplied application "pa_devs".

References Pa_GetDefaultHostApi(), PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_T, and paNoDevice.

Referenced by main(), Pa_OpenDefaultStream(), PlaySine(), test(), and TestOnce().

PaDeviceIndex Pa_GetDeviceCount ( void  )

Retrieve the number of available devices. The number of available devices may be zero.

Returns
A non-negative value indicating the number of available devices or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

References PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, and paNotInitialized.

Referenced by main(), and PaQa_ListAudioDevices().

const PaDeviceInfo* Pa_GetDeviceInfo ( PaDeviceIndex  device)

Retrieve a pointer to a PaDeviceInfo structure containing information about the specified device.

Returns
A pointer to an immutable PaDeviceInfo structure. If the device parameter is out of range the function returns NULL.
Parameters
deviceA valid device index in the range 0 to (Pa_GetDeviceCount()-1)
Note
PortAudio manages the memory referenced by the returned pointer, the client must not manipulate or free the memory. The pointer is only guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate().
See Also
PaDeviceInfo, PaDeviceIndex

References PaDeviceInfo::hostApi, PaDeviceInfo::maxInputChannels, PaDeviceInfo::maxOutputChannels, PaDeviceInfo::name, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, and PaDeviceInfo::structVersion.

Referenced by main(), Sine::open(), Pa_OpenDefaultStream(), PaQa_CheckForLoopBack(), PaQa_ListAudioDevices(), PlaySine(), test(), and TestOnce().

const char* Pa_GetErrorText ( PaError  errorCode)
PaHostApiIndex Pa_GetHostApiCount ( void  )

Retrieve the number of available host APIs. Even if a host API is available it may have no devices available.

Returns
A non-negative value indicating the number of available host APIs or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.
See Also
PaHostApiIndex

References PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, and paNotInitialized.

const PaHostApiInfo* Pa_GetHostApiInfo ( PaHostApiIndex  hostApi)

Retrieve a pointer to a structure containing information about a specific host Api.

Parameters
hostApiA valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
Returns
A pointer to an immutable PaHostApiInfo structure describing a specific host API. If the hostApi parameter is out of range or an error is encountered, the function returns NULL.

The returned structure is owned by the PortAudio implementation and must not be manipulated or freed. The pointer is only guaranteed to be valid between calls to Pa_Initialize() and Pa_Terminate().

References PaHostApiInfo::name, PA_IS_INITIALISED_, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PaHostApiInfo::structVersion, and PaHostApiInfo::type.

Referenced by main(), and PaQa_ListAudioDevices().

const PaHostErrorInfo* Pa_GetLastHostErrorInfo ( void  )

Return information about the last host error encountered. The error information returned by Pa_GetLastHostErrorInfo() will never be modified asynchronously by errors occurring in other PortAudio owned threads (such as the thread that manages the stream callback.)

This function is provided as a last resort, primarily to enhance debugging by providing clients with access to all available error information.

Returns
A pointer to an immutable structure constraining information about the host error. The values in this structure will only be valid if a PortAudio function has previously returned the paUnanticipatedHostError error code.

Referenced by TestOnce().

PaError Pa_GetSampleSize ( PaSampleFormat  format)

Retrieve the size of a given sample format in bytes.

Returns
The size in bytes of a single sample in the specified format, or paSampleFormatNotSupported if the format is not supported.

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, paFloat32, paInt16, paInt24, paInt32, paInt8, paNonInterleaved, paSampleFormatNotSupported, and paUInt8.

Referenced by PaUtil_InitializeBufferProcessor(), PaWin_InitializeWaveFormatEx(), and PaWin_InitializeWaveFormatExtensible().

double Pa_GetStreamCpuLoad ( PaStream stream)

Retrieve CPU usage information for the specified stream. The "CPU Load" is a fraction of total CPU time consumed by a callback stream's audio processing routines including, but not limited to the client supplied stream callback. This function does not work with blocking read/write streams.

This function may be called from the stream callback function or the application.

Returns
A floating point value, typically between 0.0 and 1.0, where 1.0 indicates that the stream callback is consuming the maximum number of CPU cycles possible to maintain real-time operation. A value of 0.5 would imply that PortAudio and the stream callback was consuming roughly 50% of the available CPU time. The return value may exceed 1.0. A value of 0.0 will always be returned for a blocking read/write stream, or if an error occurs.

References Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

Referenced by PlaySine().

const PaStreamInfo* Pa_GetStreamInfo ( PaStream stream)

Retrieve a pointer to a PaStreamInfo structure containing information about the specified stream.

Returns
A pointer to an immutable PaStreamInfo structure. If the stream parameter is invalid, or an error is encountered, the function returns NULL.
Parameters
streamA pointer to an open stream previously created with Pa_OpenStream.
Note
PortAudio manages the memory referenced by the returned pointer, the client must not manipulate or free the memory. The pointer is only guaranteed to be valid until the specified stream is closed.
See Also
PaStreamInfo

References PaStreamInfo::inputLatency, PaStreamInfo::outputLatency, Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_REP, paNoError, PaUtil_ValidateStreamPointer(), PaStreamInfo::sampleRate, and PaStreamInfo::structVersion.

Referenced by main(), and paqaCheckLatency().

signed long Pa_GetStreamReadAvailable ( PaStream stream)

Retrieve the number of frames that can be read from the stream without waiting.

Returns
Returns a non-negative value representing the maximum number of frames that can be read from the stream without blocking or busy waiting or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

References Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

PaTime Pa_GetStreamTime ( PaStream stream)

Returns the current time in seconds for a stream according to the same clock used to generate callback PaStreamCallbackTimeInfo timestamps. The time values are monotonically increasing and have unspecified origin.

Pa_GetStreamTime returns valid time values for the entire life of the stream, from when the stream is opened until it is closed. Starting and stopping the stream does not affect the passage of time returned by Pa_GetStreamTime.

This time may be used for synchronizing other events to the audio stream, for example synchronizing audio to MIDI.

Returns
The stream's current time in seconds, or 0 if an error occurred.
See Also
PaTime, PaStreamCallback, PaStreamCallbackTimeInfo

References Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

Referenced by stop_thread_proc().

signed long Pa_GetStreamWriteAvailable ( PaStream stream)

Retrieve the number of frames that can be written to the stream without waiting.

Returns
Returns a non-negative value representing the maximum number of frames that can be written to the stream without blocking or busy waiting or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

References Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

int Pa_GetVersion ( void  )

Retrieve the release number of the currently running PortAudio build. For example, for version "19.5.1" this will return 0x00130501.

See Also
paMakeVersionNumber

References paVersion.

Referenced by main().

const PaVersionInfo* Pa_GetVersionInfo ( void  )

Retrieve version information for the currently running PortAudio build.

Returns
A pointer to an immutable PaVersionInfo structure.
Note
This function can be called at any time. It does not require PortAudio to be initialized. The structure pointed to is statically allocated. Do not attempt to free it or modify it.
See Also
PaVersionInfo, paMakeVersionNumber
Version
Available as of 19.5.0.

Referenced by main().

const char* Pa_GetVersionText ( void  )

Retrieve a textual description of the current PortAudio build, e.g. "PortAudio V19.5.0-devel, revision 1952M". The format of the text may change in the future. Do not try to parse the returned string.

Deprecated:
As of 19.5.0, use Pa_GetVersionInfo()->versionText instead.

References PA_VERSION_TEXT_.

Referenced by main().

PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex ( PaHostApiIndex  hostApi,
int  hostApiDeviceIndex 
)

Convert a host-API-specific device index to standard PortAudio device index. This function may be used in conjunction with the deviceCount field of PaHostApiInfo to enumerate all devices for the specified host API.

Parameters
hostApiA valid host API index ranging from 0 to (Pa_GetHostApiCount()-1)
hostApiDeviceIndexA valid per-host device index in the range 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1)
Returns
A non-negative PaDeviceIndex ranging from 0 to (Pa_GetDeviceCount()-1) or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

A paInvalidHostApi error code indicates that the host API index specified by the hostApi parameter is out of range.

A paInvalidDevice error code indicates that the hostApiDeviceIndex parameter is out of range.

See Also
PaHostApiInfo

References PA_IS_INITIALISED_, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, paInvalidDevice, paInvalidHostApi, and paNotInitialized.

PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex ( PaHostApiTypeId  type)

Convert a static host API unique identifier, into a runtime host API index.

Parameters
typeA unique host API identifier belonging to the PaHostApiTypeId enumeration.
Returns
A valid PaHostApiIndex ranging from 0 to (Pa_GetHostApiCount()-1) or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.

The paHostApiNotFound error code indicates that the host API specified by the type parameter is not available.

See Also
PaHostApiTypeId

References PA_IS_INITIALISED_, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT, paHostApiNotFound, and paNotInitialized.

Referenced by main().

PaError Pa_Initialize ( void  )

Library initialization function - call this before using PortAudio. This function initializes internal data structures and prepares underlying host APIs for use. With the exception of Pa_GetVersion(), Pa_GetVersionText(), and Pa_GetErrorText(), this function MUST be called before using any other PortAudio API functions.

If Pa_Initialize() is called multiple times, each successful call must be matched with a corresponding call to Pa_Terminate(). Pairs of calls to Pa_Initialize()/Pa_Terminate() may overlap, and are not required to be fully nested.

Note that if Pa_Initialize() returns an error code, Pa_Terminate() should NOT be called.

Returns
paNoError if successful, otherwise an error code indicating the cause of failure.
See Also
Pa_Terminate

References PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR, PA_VALIDATE_ENDIANNESS, PA_VALIDATE_TYPE_SIZES, paNoError, PaUtil_InitializeClock(), and PaUtil_ResetTraceMessages.

Referenced by main(), PlaySine(), TestOnce(), and TestStopMode().

PaError Pa_IsFormatSupported ( const PaStreamParameters inputParameters,
const PaStreamParameters outputParameters,
double  sampleRate 
)

Determine whether it would be possible to open a stream with the specified parameters.

Parameters
inputParametersA structure that describes the input parameters used to open a stream. The suggestedLatency field is ignored. See PaStreamParameters for a description of these parameters. inputParameters must be NULL for output-only streams.
outputParametersA structure that describes the output parameters used to open a stream. The suggestedLatency field is ignored. See PaStreamParameters for a description of these parameters. outputParameters must be NULL for input-only streams.
sampleRateThe required sampleRate. For full-duplex streams it is the sample rate for both input and output
Returns
Returns 0 if the format is supported, and an error code indicating why the format is not supported otherwise. The constant paFormatIsSupported is provided to compare with the return value for success.
See Also
paFormatIsSupported, PaStreamParameters

References PaStreamParameters::channelCount, PaStreamParameters::device, PaStreamParameters::hostApiSpecificStreamInfo, PaUtilHostApiRepresentation::IsFormatSupported, Pa_GetErrorText(), PA_IS_INITIALISED_, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, paFormatIsSupported, paNoDevice, paNoError, paNoFlag, paNotInitialized, PaStreamParameters::sampleFormat, and PaStreamParameters::suggestedLatency.

Referenced by main(), and PaQa_CheckForLoopBack().

PaError Pa_IsStreamActive ( PaStream stream)

Determine whether the stream is active. A stream is active after a successful call to Pa_StartStream(), until it becomes inactive either as a result of a call to Pa_StopStream() or Pa_AbortStream(), or as a result of a return value other than paContinue from the stream callback. In the latter case, the stream is considered inactive after the last buffer has finished playing.

Returns
Returns one (1) when the stream is active (ie playing or recording audio), zero (0) when not playing or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.
See Also
Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

Referenced by TestStopMode().

PaError Pa_IsStreamStopped ( PaStream stream)

Determine whether the stream is stopped. A stream is considered to be stopped prior to a successful call to Pa_StartStream and after a successful call to Pa_StopStream or Pa_AbortStream. If a stream callback returns a value other than paContinue the stream is NOT considered to be stopped.

Returns
Returns one (1) when the stream is stopped, zero (0) when the stream is running or, a PaErrorCode (which are always negative) if PortAudio is not initialized or an error is encountered.
See Also
Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().

PaError Pa_OpenDefaultStream ( PaStream **  stream,
int  numInputChannels,
int  numOutputChannels,
PaSampleFormat  sampleFormat,
double  sampleRate,
unsigned long  framesPerBuffer,
PaStreamCallback streamCallback,
void *  userData 
)

A simplified version of Pa_OpenStream() that opens the default input and/or output devices.

Parameters
streamThe address of a PaStream pointer which will receive a pointer to the newly opened stream.
numInputChannelsThe number of channels of sound that will be supplied to the stream callback or returned by Pa_ReadStream. It can range from 1 to the value of maxInputChannels in the PaDeviceInfo record for the default input device. If 0 the stream is opened as an output-only stream.
numOutputChannelsThe number of channels of sound to be delivered to the stream callback or passed to Pa_WriteStream. It can range from 1 to the value of maxOutputChannels in the PaDeviceInfo record for the default output device. If 0 the stream is opened as an output-only stream.
sampleFormatThe sample format of both the input and output buffers provided to the callback or passed to and from Pa_ReadStream and Pa_WriteStream. sampleFormat may be any of the formats described by the PaSampleFormat enumeration.
sampleRateSame as Pa_OpenStream parameter of the same name.
framesPerBufferSame as Pa_OpenStream parameter of the same name.
streamCallbackSame as Pa_OpenStream parameter of the same name.
userDataSame as Pa_OpenStream parameter of the same name.
Returns
As for Pa_OpenStream
See Also
Pa_OpenStream, PaStreamCallback

References PaStreamParameters::channelCount, PaDeviceInfo::defaultHighInputLatency, PaDeviceInfo::defaultHighOutputLatency, PaStreamParameters::device, PaStreamParameters::hostApiSpecificStreamInfo, Pa_GetDefaultInputDevice(), Pa_GetDefaultOutputDevice(), Pa_GetDeviceInfo(), Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, Pa_OpenStream(), paDeviceUnavailable, paNoDevice, paNoFlag, PaStreamParameters::sampleFormat, and PaStreamParameters::suggestedLatency.

Referenced by main().

PaError Pa_OpenStream ( PaStream **  stream,
const PaStreamParameters inputParameters,
const PaStreamParameters outputParameters,
double  sampleRate,
unsigned long  framesPerBuffer,
PaStreamFlags  streamFlags,
PaStreamCallback streamCallback,
void *  userData 
)

Opens a stream for either input, output or both.

Parameters
streamThe address of a PaStream pointer which will receive a pointer to the newly opened stream.
inputParametersA structure that describes the input parameters used by the opened stream. See PaStreamParameters for a description of these parameters. inputParameters must be NULL for output-only streams.
outputParametersA structure that describes the output parameters used by the opened stream. See PaStreamParameters for a description of these parameters. outputParameters must be NULL for input-only streams.
sampleRateThe desired sampleRate. For full-duplex streams it is the sample rate for both input and output
framesPerBufferThe number of frames passed to the stream callback function, or the preferred block granularity for a blocking read/write stream. The special value paFramesPerBufferUnspecified (0) may be used to request that the stream callback will receive an optimal (and possibly varying) number of frames based on host requirements and the requested latency settings. Note: With some host APIs, the use of non-zero framesPerBuffer for a callback stream may introduce an additional layer of buffering which could introduce additional latency. PortAudio guarantees that the additional latency will be kept to the theoretical minimum however, it is strongly recommended that a non-zero framesPerBuffer value only be used when your algorithm requires a fixed number of frames per stream callback.
streamFlagsFlags which modify the behavior of the streaming process. This parameter may contain a combination of flags ORed together. Some flags may only be relevant to certain buffer formats.
streamCallbackA pointer to a client supplied function that is responsible for processing and filling input and output buffers. If this parameter is NULL the stream will be opened in 'blocking read/write' mode. In blocking mode, the client can receive sample data using Pa_ReadStream and write sample data using Pa_WriteStream, the number of samples that may be read or written without blocking is returned by Pa_GetStreamReadAvailable and Pa_GetStreamWriteAvailable respectively.
userDataA client supplied pointer which is passed to the stream callback function. It could for example, contain a pointer to instance data necessary for processing the audio buffers. This parameter is ignored if streamCallback is NULL.
Returns
Upon success Pa_OpenStream() returns paNoError and places a pointer to a valid PaStream in the stream argument. The stream is inactive (stopped). If a call to Pa_OpenStream() fails, a non-zero error code is returned (see PaError for possible error codes) and the value of stream is invalid.
See Also
PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream, Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable

References PaStreamParameters::channelCount, PaStreamParameters::device, PaStreamParameters::hostApiSpecificStreamInfo, PaUtilHostApiRepresentation::OpenStream, Pa_GetErrorText(), PA_IS_INITIALISED_, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, paBadStreamPtr, paNoDevice, paNoError, paNotInitialized, PaStreamParameters::sampleFormat, and PaStreamParameters::suggestedLatency.

Referenced by main(), Sine::open(), Pa_OpenDefaultStream(), PaQa_RunInputOnly(), PaQa_RunLoopbackFullDuplex(), PaQa_RunLoopbackFullDuplexBlockingIO(), PaQa_RunLoopbackHalfDuplex(), PaQa_RunLoopbackHalfDuplexBlockingIO(), paqaCheckLatency(), PlaySine(), test(), TestOnce(), and TestStopMode().

PaError Pa_ReadStream ( PaStream stream,
void *  buffer,
unsigned long  frames 
)

Read samples from an input stream. The function doesn't return until the entire buffer has been filled - this may involve waiting for the operating system to supply the data.

Parameters
streamA pointer to an open stream previously created with Pa_OpenStream.
bufferA pointer to a buffer of sample frames. The buffer contains samples in the format specified by the inputParameters->sampleFormat field used to open the stream, and the number of channels specified by inputParameters->numChannels. If non-interleaved samples were requested using the paNonInterleaved sample format flag, buffer is a pointer to the first element of an array of buffer pointers, one non-interleaved buffer for each channel.
framesThe number of frames to be read into buffer. This parameter is not constrained to a specific range, however high performance applications will want to match this parameter to the framesPerBuffer parameter used when opening the stream.
Returns
On success PaNoError will be returned, or PaInputOverflowed if input data was discarded by PortAudio after the previous call and before this call.

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paBadBufferPtr, paNoError, paStreamIsStopped, and PaUtil_ValidateStreamPointer().

PaError Pa_SetStreamFinishedCallback ( PaStream stream,
PaStreamFinishedCallback streamFinishedCallback 
)

Register a stream finished callback function which will be called when the stream becomes inactive. See the description of PaStreamFinishedCallback for further details about when the callback will be called.

Parameters
streama pointer to a PaStream that is in the stopped state - if the stream is not stopped, the stream's finished callback will remain unchanged and an error code will be returned.
streamFinishedCallbacka pointer to a function with the same signature as PaStreamFinishedCallback, that will be called when the stream becomes inactive. Passing NULL for this parameter will un-register a previously registered stream finished callback function.
Returns
on success returns paNoError, otherwise an error code indicating the cause of the error.
See Also
PaStreamFinishedCallback

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, PA_STREAM_REP, paNoError, paStreamIsNotStopped, and PaUtil_ValidateStreamPointer().

Referenced by Sine::open().

PaError Pa_StartStream ( PaStream stream)
PaError Pa_StopStream ( PaStream stream)
PaError Pa_Terminate ( void  )

Library termination function - call this when finished using PortAudio. This function deallocates all resources allocated by PortAudio since it was initialized by a call to Pa_Initialize(). In cases where Pa_Initialise() has been called multiple times, each call must be matched with a corresponding call to Pa_Terminate(). The final matching call to Pa_Terminate() will automatically close any PortAudio streams that are still open.

Pa_Terminate() MUST be called before exiting a program which uses PortAudio. Failure to do so may result in serious resource leaks, such as audio devices not being available until the next reboot.

Returns
paNoError if successful, otherwise an error code indicating the cause of failure.
See Also
Pa_Initialize

References PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR, paNoError, paNotInitialized, and PaUtil_DumpTraceMessages.

Referenced by main(), PlaySine(), TestOnce(), TestStopMode(), and ScopedPaHandler::~ScopedPaHandler().

PaError Pa_WriteStream ( PaStream stream,
const void *  buffer,
unsigned long  frames 
)

Write samples to an output stream. This function doesn't return until the entire buffer has been written - this may involve waiting for the operating system to consume the data.

Parameters
streamA pointer to an open stream previously created with Pa_OpenStream.
bufferA pointer to a buffer of sample frames. The buffer contains samples in the format specified by the outputParameters->sampleFormat field used to open the stream, and the number of channels specified by outputParameters->numChannels. If non-interleaved samples were requested using the paNonInterleaved sample format flag, buffer is a pointer to the first element of an array of buffer pointers, one non-interleaved buffer for each channel.
framesThe number of frames to be written from buffer. This parameter is not constrained to a specific range, however high performance applications will want to match this parameter to the framesPerBuffer parameter used when opening the stream.
Returns
On success PaNoError will be returned, or paOutputUnderflowed if additional output data was inserted after the previous call and before this call.

References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paBadBufferPtr, paNoError, paStreamIsStopped, and PaUtil_ValidateStreamPointer().

PaError PaUtil_DeviceIndexToHostApiDeviceIndex ( PaDeviceIndex hostApiDevice,
PaDeviceIndex  device,
struct PaUtilHostApiRepresentation hostApi 
)

Convert a PortAudio device index into a host API specific device index.

Parameters
hostApiDevicePointer to a device index, on success this will recieve the converted device index value.
deviceThe PortAudio device index to convert.
hostApiThe host api which the index should be converted for.
Returns
On success returns PaNoError and places the converted index in the hostApiDevice parameter.

References PaUtilPrivatePaFrontHostApiInfo::baseDeviceIndex, PaHostApiInfo::deviceCount, PaUtilHostApiRepresentation::info, paInvalidDevice, paNoError, and PaUtilHostApiRepresentation::privatePaFrontInfo.

Referenced by PaAsio_GetAvailableBufferSizes(), PaAsio_GetInputChannelName(), PaAsio_GetOutputChannelName(), PaAsio_ShowControlPanel(), PaMacCore_GetBufferSizeRange(), PaWasapi_GetDeviceDefaultFormat(), PaWasapi_GetDeviceMixFormat(), PaWasapi_GetDeviceRole(), PaWasapi_GetJackCount(), and PaWasapi_GetJackDescription().

PaError PaUtil_GetHostApiRepresentation ( struct PaUtilHostApiRepresentation **  hostApi,
PaHostApiTypeId  type 
)

Retrieve a specific host API representation. This function can be used by implementations to retrieve a pointer to their representation in host api specific extension functions which aren't passed a rep pointer by pa_front.c.

Parameters
hostApiA pointer to a host API represenation pointer. Apon success this will receive the requested representation pointer.
typeA valid host API type identifier.
Returns
An error code. If the result is PaNoError then a pointer to the requested host API representation will be stored in *hostApi. If the host API specified by type is not found, this function returns paHostApiNotFound.

References PA_IS_INITIALISED_, paHostApiNotFound, paNoError, and paNotInitialized.

Referenced by PaAsio_GetAvailableBufferSizes(), PaAsio_GetInputChannelName(), PaAsio_GetOutputChannelName(), PaAsio_ShowControlPanel(), PaJack_GetClientName(), PaMacCore_GetBufferSizeRange(), and PaMacCore_GetChannelName().

void PaUtil_SetLastHostErrorInfo ( PaHostApiTypeId  hostApiType,
long  errorCode,
const char *  errorText 
)

Set the host error information returned by Pa_GetLastHostErrorInfo. This function and the paUnanticipatedHostError error code should be used as a last resort. Implementors should use existing PA error codes where possible, or nominate new ones. Note that at it is always better to use PaUtil_SetLastHostErrorInfo() and paUnanticipatedHostError than to return an ambiguous or inaccurate PaError code.

Parameters
hostApiTypeThe host API which encountered the error (ie of the caller)
errorCodeThe error code returned by the native API function.
errorTextA string describing the error. PaUtil_SetLastHostErrorInfo makes a copy of the string, so it is not necessary for the pointer to remain valid after the call to PaUtil_SetLastHostErrorInfo() returns.

References PaHostErrorInfo::errorCode, PaHostErrorInfo::hostApiType, and PA_LAST_HOST_ERROR_TEXT_LENGTH_.

Referenced by PaMacCore_SetError(), PaMacCore_SetUnixError(), and PaWinUtil_CoInitialize().

PaError PaUtil_ValidateStreamPointer ( PaStream stream)

Check that the stream pointer is valid.

Returns
Returns paNoError if the stream pointer appears to be OK, otherwise returns an error indicating the cause of failure.

References PA_IS_INITIALISED_, PA_STREAM_MAGIC, paBadStreamPtr, paNoError, and paNotInitialized.

Referenced by Pa_AbortStream(), Pa_CloseStream(), Pa_GetStreamCpuLoad(), Pa_GetStreamInfo(), Pa_GetStreamReadAvailable(), Pa_GetStreamTime(), Pa_GetStreamWriteAvailable(), Pa_IsStreamActive(), Pa_IsStreamStopped(), Pa_ReadStream(), Pa_SetStreamFinishedCallback(), Pa_StartStream(), Pa_StopStream(), and Pa_WriteStream().

Variable Documentation

PaUtilStreamRepresentation* firstOpenStream_ = NULL