PortAudio
2.0
|
The portable PortAudio API. More...
Go to the source code of this file.
Data Structures | |
struct | PaVersionInfo |
struct | PaHostApiInfo |
struct | PaHostErrorInfo |
struct | PaDeviceInfo |
struct | PaStreamParameters |
struct | PaStreamCallbackTimeInfo |
struct | PaStreamInfo |
Typedefs | |
typedef struct PaVersionInfo | PaVersionInfo |
typedef int | PaError |
typedef enum PaErrorCode | PaErrorCode |
typedef int | PaDeviceIndex |
typedef int | PaHostApiIndex |
typedef enum PaHostApiTypeId | PaHostApiTypeId |
typedef struct PaHostApiInfo | PaHostApiInfo |
typedef struct PaHostErrorInfo | PaHostErrorInfo |
typedef double | PaTime |
typedef unsigned long | PaSampleFormat |
typedef struct PaDeviceInfo | PaDeviceInfo |
typedef struct PaStreamParameters | PaStreamParameters |
typedef void | PaStream |
typedef unsigned long | PaStreamFlags |
typedef struct PaStreamCallbackTimeInfo | PaStreamCallbackTimeInfo |
typedef unsigned long | PaStreamCallbackFlags |
typedef enum PaStreamCallbackResult | PaStreamCallbackResult |
typedef int | PaStreamCallback (const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData) |
typedef void | PaStreamFinishedCallback (void *userData) |
typedef struct PaStreamInfo | PaStreamInfo |
The portable PortAudio API.
#define paClipOff ((PaStreamFlags) 0x00000001) |
Disable default clipping of out of range samples.
Referenced by main(), Sine::open(), PaQa_RunInputOnly(), PaQa_RunLoopbackFullDuplex(), PaQa_RunLoopbackFullDuplexBlockingIO(), PaQa_RunLoopbackHalfDuplexBlockingIO(), paqaCheckLatency(), test(), TestOnce(), and TestStopMode().
#define paCustomFormat ((PaSampleFormat) 0x00010000) |
Referenced by IsFormatSupported(), PaPulseAudio_ConvertPortaudioFormatToPaPulseAudio_(), and PaUtil_SelectClosestAvailableFormat().
#define paDitherOff ((PaStreamFlags) 0x00000002) |
Disable default dithering.
Referenced by main(), PaUtil_InitializeBufferProcessor(), and TestOnce().
#define paFloat32 ((PaSampleFormat) 0x00000001) |
#define paFormatIsSupported (0) |
Return code for Pa_IsFormatSupported() indicating success.
Referenced by IsFormatSupported(), main(), Pa_IsFormatSupported(), and PaQa_CheckForLoopBack().
#define paFramesPerBufferUnspecified (0) |
Can be passed as the framesPerBuffer parameter to Pa_OpenStream() or Pa_OpenDefaultStream() to indicate that the stream callback will accept buffers of any size.
Referenced by Sine::open(), OpenStream(), paqaCheckLatency(), and PaUtil_InitializeBufferProcessor().
#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002) |
In a stream opened with paFramesPerBufferUnspecified, indicates that data prior to the first sample of the input buffer was discarded due to an overflow, possibly because the stream callback is using too much CPU time. Otherwise indicates that data prior to one or more samples in the input buffer was discarded.
Referenced by BlioCallback(), ProcessingThread(), ProcessingThreadProc(), ReadStream(), and xrunCallback().
#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001) |
In a stream opened with paFramesPerBufferUnspecified, indicates that input data is all silence (zeros) because no real data is available. In a stream opened without paFramesPerBufferUnspecified, it indicates that one or more zero samples have been inserted into the input buffer to compensate for an input underflow.
#define paInt16 ((PaSampleFormat) 0x00000008) |
#define paInt24 ((PaSampleFormat) 0x00000004) |
Packed 24 bit format.
Referenced by My_Pa_GetSampleSize(), Pa_GetSampleSize(), PaPulseAudio_ConvertPortaudioFormatToPaPulseAudio_(), PaUtil_InitializeBufferProcessor(), and PaUtil_SelectZeroer().
#define paInt32 ((PaSampleFormat) 0x00000002) |
#define paInt8 ((PaSampleFormat) 0x00000010) |
#define paMakeVersionNumber | ( | major, | |
minor, | |||
subminor | |||
) | (((major)&0xFF)<<16 | ((minor)&0xFF)<<8 | ((subminor)&0xFF)) |
Generate a packed integer version number in the same format used by Pa_GetVersion(). Use this to compare a specified version number with the currently running version. For example:
#define paNeverDropInput ((PaStreamFlags) 0x00000004) |
Flag requests that where possible a full duplex stream will not discard overflowed input samples without calling the stream callback. This flag is only valid for full duplex callback streams and only when used in combination with the paFramesPerBufferUnspecified (0) framesPerBuffer parameter. Using this flag incorrectly results in a paInvalidFlag error being returned from Pa_OpenStream() and Pa_OpenDefaultStream().
Referenced by PaUtil_InitializeBufferProcessor().
#define paNoDevice ((PaDeviceIndex)-1) |
A special PaDeviceIndex value indicating that no device is available, or should be used.
Referenced by main(), Sine::open(), Pa_GetDefaultInputDevice(), Pa_GetDefaultOutputDevice(), Pa_IsFormatSupported(), Pa_OpenDefaultStream(), Pa_OpenStream(), PaAsiHpi_Initialize(), PaAsio_Initialize(), PaAsio_ShowControlPanel(), PaAudioIO_Initialize(), PaMacCore_Initialize(), PaPulseAudio_Initialize(), PaPulseAudio_StartStreamCb(), PaSkeleton_Initialize(), PaWasapi_Initialize(), PaWinDs_Initialize(), PaWinMme_Initialize(), PaWinWdm_Initialize(), PlaySine(), test(), TestOnce(), and TestStopMode().
#define paNoFlag ((PaStreamFlags) 0) |
Referenced by main(), Pa_IsFormatSupported(), and Pa_OpenDefaultStream().
#define paNonInterleaved ((PaSampleFormat) 0x80000000) |
#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008) |
Indicates that output data will be discarded because no room is available.
#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004) |
Indicates that output data (or a gap) was inserted, possibly because the stream callback is using too much CPU time.
Referenced by BlioCallback(), ProcessingThread(), ProcessingThreadProc(), WriteStream(), and xrunCallback().
#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000) |
#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008) |
Call the stream callback to fill initial output buffers, rather than the default behavior of priming the buffers with zeros (silence). This flag has no effect for input-only and blocking read/write streams.
#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010) |
Some of all of the output data will be used to prime the stream, input data may be zero.
#define paUInt8 ((PaSampleFormat) 0x00000020) |
#define paUseHostApiSpecificDeviceSpecification ((PaDeviceIndex)-2) |
A special PaDeviceIndex value indicating that the device(s) to be used are specified in the host api specific stream info structure.
Referenced by IsFormatSupported(), and OpenStream().
typedef int PaDeviceIndex |
The type used to refer to audio devices. Values of this type usually range from 0 to (Pa_GetDeviceCount()-1), and may also take on the PaNoDevice and paUseHostApiSpecificDeviceSpecification values.
typedef struct PaDeviceInfo PaDeviceInfo |
A structure providing information and capabilities of PortAudio devices. Devices may support input, output or both input and output.
typedef int PaError |
Error codes returned by PortAudio functions. Note that with the exception of paNoError, all PaErrorCodes are negative.
typedef enum PaErrorCode PaErrorCode |
typedef int PaHostApiIndex |
The type used to enumerate to host APIs at runtime. Values of this type range from 0 to (Pa_GetHostApiCount()-1).
typedef struct PaHostApiInfo PaHostApiInfo |
A structure containing information about a particular host API.
typedef enum PaHostApiTypeId PaHostApiTypeId |
Unchanging unique identifiers for each supported host API. This type is used in the PaHostApiInfo structure. The values are guaranteed to be unique and to never change, thus allowing code to be written that conditionally uses host API specific extensions.
New type ids will be allocated when support for a host API reaches "public alpha" status, prior to that developers should use the paInDevelopment type id.
typedef struct PaHostErrorInfo PaHostErrorInfo |
Structure used to return information about a host error condition.
typedef unsigned long PaSampleFormat |
A type used to specify one or more sample formats. Each value indicates a possible format for sound data passed to and from the stream callback, Pa_ReadStream() and Pa_WriteStream().
The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 and paUInt8 are usually implemented by all implementations.
The floating point representation (paFloat32) uses +1.0 and -1.0 as the maximum and minimum respectively.
paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
The paNonInterleaved flag indicates that audio data is passed as an array of pointers to separate buffers, one buffer for each channel. Usually, when this flag is not used, audio data is passed as a single buffer with all channels interleaved.
typedef void PaStream |
A single PaStream can provide multiple channels of real-time streaming audio input and output to a client application. A stream provides access to audio hardware represented by one or more PaDevices. Depending on the underlying Host API, it may be possible to open multiple streams using the same device, however this behavior is implementation defined. Portable applications should assume that a PaDevice may be simultaneously used by at most one PaStream.
Pointers to PaStream objects are passed between PortAudio functions that operate on streams.
typedef int PaStreamCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData) |
Functions of type PaStreamCallback are implemented by PortAudio clients. They consume, process or generate audio in response to requests from an active PortAudio stream.
When a stream is running, PortAudio calls the stream callback periodically. The callback function is responsible for processing buffers of audio samples passed via the input and output parameters.
The PortAudio stream callback runs at very high or real-time priority. It is required to consistently meet its time deadlines. Do not allocate memory, access the file system, call library functions or call other functions from the stream callback that may block or take an unpredictable amount of time to complete.
In order for a stream to maintain glitch-free operation the callback must consume and return audio data faster than it is recorded and/or played. PortAudio anticipates that each callback invocation may execute for a duration approaching the duration of frameCount audio frames at the stream sample rate. It is reasonable to expect to be able to utilise 70% or more of the available CPU time in the PortAudio callback. However, due to buffer size adaption and other factors, not all host APIs are able to guarantee audio stability under heavy CPU load with arbitrary fixed callback buffer sizes. When high callback CPU utilisation is required the most robust behavior can be achieved by using paFramesPerBufferUnspecified as the Pa_OpenStream() framesPerBuffer parameter.
input | and |
output | are either arrays of interleaved samples or; if non-interleaved samples were requested using the paNonInterleaved sample format flag, an array of buffer pointers, one non-interleaved buffer for each channel. |
The format, packing and number of channels used by the buffers are determined by parameters to Pa_OpenStream().
frameCount | The number of sample frames to be processed by the stream callback. |
timeInfo | Timestamps indicating the ADC capture time of the first sample in the input buffer, the DAC output time of the first sample in the output buffer and the time the callback was invoked. See PaStreamCallbackTimeInfo and Pa_GetStreamTime() |
statusFlags | Flags indicating whether input and/or output buffers have been inserted or will be dropped to overcome underflow or overflow conditions. |
userData | The value of a user supplied pointer passed to Pa_OpenStream() intended for storing synthesis data etc. |
typedef unsigned long PaStreamCallbackFlags |
Flag bit constants for the statusFlags to PaStreamCallback.
typedef enum PaStreamCallbackResult PaStreamCallbackResult |
Allowable return values for the PaStreamCallback.
typedef struct PaStreamCallbackTimeInfo PaStreamCallbackTimeInfo |
Timing information for the buffers passed to the stream callback.
Time values are expressed in seconds and are synchronised with the time base used by Pa_GetStreamTime() for the associated stream.
typedef void PaStreamFinishedCallback(void *userData) |
Functions of type PaStreamFinishedCallback are implemented by PortAudio clients. They can be registered with a stream using the Pa_SetStreamFinishedCallback() function. Once registered they are called when the stream becomes inactive (ie once a call to Pa_StopStream() will not block). A stream will become inactive after the stream callback returns non-zero, or when Pa_StopStream() or Pa_AbortStream() is called. For a stream providing audio output, if the stream callback returns paComplete, or Pa_StopStream() is called, the stream finished callback will not be called until all generated sample data has been played.
userData | The userData parameter supplied to Pa_OpenStream() |
typedef unsigned long PaStreamFlags |
Flags used to control the behavior of a stream. They are passed as parameters to Pa_OpenStream() or Pa_OpenDefaultStream(). Multiple flags may be ORed together.
typedef struct PaStreamInfo PaStreamInfo |
A structure containing unchanging information about an open stream.
typedef struct PaStreamParameters PaStreamParameters |
Parameters for one direction (input or output) of a stream.
typedef double PaTime |
The type used to represent monotonic time in seconds. PaTime is used for the fields of the PaStreamCallbackTimeInfo argument to the PaStreamCallback and as the result of Pa_GetStreamTime().
PaTime values have unspecified origin.
typedef struct PaVersionInfo PaVersionInfo |
A structure containing PortAudio API version information.
enum PaErrorCode |
enum PaHostApiTypeId |
Unchanging unique identifiers for each supported host API. This type is used in the PaHostApiInfo structure. The values are guaranteed to be unique and to never change, thus allowing code to be written that conditionally uses host API specific extensions.
New type ids will be allocated when support for a host API reaches "public alpha" status, prior to that developers should use the paInDevelopment type id.
Enumerator | |
---|---|
paInDevelopment | |
paDirectSound | |
paMME | |
paASIO | |
paSoundManager | |
paCoreAudio | |
paOSS | |
paALSA | |
paAL | |
paBeOS | |
paWDMKS | |
paJACK | |
paWASAPI | |
paAudioScienceHPI | |
paAudioIO | |
paPulseAudio | |
paSndio |
Allowable return values for the PaStreamCallback.
Terminates audio processing promptly without necessarily 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().
Closes an audio stream. If the audio stream is active it discards any pending buffers as if Pa_AbortStream() had been called.
References PaUtilStreamInterface::Abort, PaUtilStreamInterface::Close, PaUtilStreamInterface::IsStopped, PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, paNoError, and PaUtil_ValidateStreamPointer().
Referenced by Sine::close(), main(), Sine::open(), PaQa_RunInputOnly(), PaQa_RunLoopbackFullDuplex(), PaQa_RunLoopbackFullDuplexBlockingIO(), PaQa_RunLoopbackHalfDuplex(), PaQa_RunLoopbackHalfDuplexBlockingIO(), paqaCheckLatency(), PlaySine(), test(), TestOnce(), and TestStopMode().
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.
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().
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().
set PA_RECOMMENDED_OUTPUT_DEVICE=1The 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.
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.
device | A valid device index in the range 0 to (Pa_GetDeviceCount()-1) |
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 | ) |
Translate the supplied PortAudio error code into a human readable message, encoded as UTF-8.
References paBadBufferPtr, paBadIODeviceCombination, paBadStreamPtr, paBufferTooBig, paBufferTooSmall, paCanNotInitializeRecursively, paCanNotReadFromACallbackStream, paCanNotReadFromAnOutputOnlyStream, paCanNotWriteToACallbackStream, paCanNotWriteToAnInputOnlyStream, paDeviceUnavailable, paHostApiNotFound, paIncompatibleHostApiSpecificStreamInfo, paIncompatibleStreamHostApi, paInputOverflowed, paInsufficientMemory, paInternalError, paInvalidChannelCount, paInvalidDevice, paInvalidFlag, paInvalidHostApi, paInvalidSampleRate, paNoError, paNotInitialized, paNullCallback, paOutputUnderflowed, paSampleFormatNotSupported, paStreamIsNotStopped, paStreamIsStopped, paTimedOut, and paUnanticipatedHostError.
Referenced by main(), Pa_GetStreamCpuLoad(), Pa_GetStreamInfo(), Pa_GetStreamReadAvailable(), Pa_GetStreamTime(), Pa_GetStreamWriteAvailable(), Pa_IsFormatSupported(), Pa_OpenDefaultStream(), Pa_OpenStream(), PaQa_RunLoopback(), PaWasapi_Initialize(), TestOnce(), and TestStopMode().
PaHostApiIndex Pa_GetHostApiCount | ( | void | ) |
Retrieve the number of available host APIs. Even if a host API is available it may have no devices available.
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.
hostApi | A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) |
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.
Referenced by TestOnce().
PaError Pa_GetSampleSize | ( | PaSampleFormat | format | ) |
Retrieve the size of a given sample format in bytes.
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 OpenStream(), 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.
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.
stream | A pointer to an open stream previously created with Pa_OpenStream(). |
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.
When the stream is stopped the return value of Pa_GetStreamReadAvailable is not defined.
References Pa_GetErrorText(), PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().
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.
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.
When the stream is stopped the return value of Pa_GetStreamWriteAvailable is not defined.
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.
References paVersion.
Referenced by main().
const PaVersionInfo* Pa_GetVersionInfo | ( | void | ) |
Retrieve version information for the currently running PortAudio build.
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.
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.
hostApi | A valid host API index ranging from 0 to (Pa_GetHostApiCount()-1) |
hostApiDeviceIndex | A valid per-host device index in the range 0 to (Pa_GetHostApiInfo(hostApi)->deviceCount-1) |
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.
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.
type | A unique host API identifier belonging to the PaHostApiTypeId enumeration. |
The paHostApiNotFound error code indicates that the host API specified by the type parameter is not available.
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.
References PA_DEBUG, PA_IS_INITIALISED_, PA_LOGAPI_ENTER, PA_LOGAPI_EXIT_PAERROR, PA_VALIDATE_ENDIANNESS, PA_VALIDATE_TYPE_SIZES, paCanNotInitializeRecursively, 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.
inputParameters | A 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. |
outputParameters | A 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. |
sampleRate | The required sampleRate. For full-duplex streams it is the sample rate for both input and output. |
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().
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.
References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, and PaUtil_ValidateStreamPointer().
Referenced by TestStopMode().
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.
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.
stream | The address of a PaStream pointer which will receive a pointer to the newly opened stream. |
numInputChannels | The 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. |
numOutputChannels | The 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 input-only stream. |
sampleFormat | The 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. |
sampleRate | Same as Pa_OpenStream parameter of the same name. |
framesPerBuffer | Same as Pa_OpenStream parameter of the same name. |
streamCallback | Same as Pa_OpenStream parameter of the same name. |
userData | Same as Pa_OpenStream parameter of the same name. |
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.
stream | The address of a PaStream pointer which will receive a pointer to the newly opened stream. |
inputParameters | A 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. |
outputParameters | A 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. |
sampleRate | The desired sampleRate. For full-duplex streams it is the sample rate for both input and output. Note that the actual sampleRate may differ very slightly from the desired rate because of hardware limitations. The exact rate can be queried using Pa_GetStreamInfo(). If nothing close to the desired sampleRate is available then the open will fail and return an error. |
framesPerBuffer | The 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. |
streamFlags | Flags 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. |
streamCallback | A 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. |
userData | A 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. |
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().
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.
Reading from a stream that is stopped is not currently supported. In particular, it is not possible to drain the read buffer by calling Pa_ReadStream after calling Pa_StopStream().
stream | A pointer to an open stream previously created with Pa_OpenStream(). |
buffer | A 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. |
frames | The 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. |
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.
stream | a 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. |
streamFinishedCallback | a 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. |
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().
void Pa_Sleep | ( | long | msec | ) |
Put the caller to sleep for at least 'msec' milliseconds. This function is provided only as a convenience for authors of portable code (such as the tests and examples in the PortAudio distribution.)
The function may sleep longer than requested so don't rely on this for accurate musical timing.
Referenced by AudioDeviceSetPropertyNowAndWaitForChange(), main(), PaQa_RunLoopbackFullDuplex(), PaQa_WaitForStream(), paqaCheckLatency(), PlaySine(), ReadStream(), TestOnce(), TestStopMode(), waitUntilBlioWriteBufferIsEmpty(), and WriteStream().
Commences audio processing.
References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, paStreamIsNotStopped, and PaUtil_ValidateStreamPointer().
Referenced by main(), PaQa_RunInputOnly(), PaQa_RunLoopbackFullDuplex(), PaQa_RunLoopbackFullDuplexBlockingIO(), PaQa_RunLoopbackHalfDuplex(), PaQa_RunLoopbackHalfDuplexBlockingIO(), paqaCheckLatency(), PlaySine(), Sine::start(), test(), TestOnce(), and TestStopMode().
Terminates audio processing. It waits until all pending audio buffers have been played before it returns.
References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paNoError, paStreamIsStopped, and PaUtil_ValidateStreamPointer().
Referenced by main(), PaQa_RunInputOnly(), PaQa_RunLoopbackFullDuplex(), PaQa_RunLoopbackFullDuplexBlockingIO(), PaQa_RunLoopbackHalfDuplex(), PaQa_RunLoopbackHalfDuplexBlockingIO(), paqaCheckLatency(), Sine::stop(), stop_thread_proc(), test(), and TestStopMode().
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_Initialize() 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.
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().
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.
Writing to a stream that is stopped is not currently supported. In particular, it is not possible to prefill the write buffer by calling Pa_WriteStream prior to calling Pa_StartStream().
stream | A pointer to an open stream previously created with Pa_OpenStream(). |
buffer | A 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. |
frames | The 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. |
References PA_LOGAPI, PA_LOGAPI_ENTER_PARAMS, PA_LOGAPI_EXIT_PAERROR, PA_STREAM_INTERFACE, paBadBufferPtr, paNoError, paStreamIsStopped, and PaUtil_ValidateStreamPointer().