📄 portaudio.h
字号:
@param 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.
@param sampleRate The desired sampleRate. For full-duplex streams it is the
sample rate for both input and output
@param 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 recieve 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.
@param streamFlags Flags which modify the behaviour of the streaming process.
This parameter may contain a combination of flags ORed together. Some flags may
only be relevant to certain buffer formats.
@param 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.
@param 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.
@return
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 PaStreamParameters, PaStreamCallback, Pa_ReadStream, Pa_WriteStream,
Pa_GetStreamReadAvailable, Pa_GetStreamWriteAvailable
*/
PaError Pa_OpenStream( PaStream** stream,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
unsigned long framesPerBuffer,
PaStreamFlags streamFlags,
PaStreamCallback *streamCallback,
void *userData );
/** A simplified version of Pa_OpenStream() that opens the default input
and/or output devices.
@param stream The address of a PaStream pointer which will receive
a pointer to the newly opened stream.
@param 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.
@param 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 dvice.
If 0 the stream is opened as an output-only stream.
@param 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.
@param sampleRate Same as Pa_OpenStream parameter of the same name.
@param framesPerBuffer Same as Pa_OpenStream parameter of the same name.
@param streamCallback Same as Pa_OpenStream parameter of the same name.
@param userData Same as Pa_OpenStream parameter of the same name.
@return As for Pa_OpenStream
@see Pa_OpenStream, PaStreamCallback
*/
PaError Pa_OpenDefaultStream( PaStream** stream,
int numInputChannels,
int numOutputChannels,
PaSampleFormat sampleFormat,
double sampleRate,
unsigned long framesPerBuffer,
PaStreamCallback *streamCallback,
void *userData );
/** Closes an audio stream. If the audio stream is active it
discards any pending buffers as if Pa_AbortStream() had been called.
*/
PaError Pa_CloseStream( PaStream *stream );
/** 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.
@param userData The userData parameter supplied to Pa_OpenStream()
@see Pa_SetStreamFinishedCallback
*/
typedef void PaStreamFinishedCallback( void *userData );
/** 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.
@param 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.
@param 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.
@return on success returns paNoError, otherwise an error code indicating the cause
of the error.
@see PaStreamFinishedCallback
*/
PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback* streamFinishedCallback );
/** Commences audio processing.
*/
PaError Pa_StartStream( PaStream *stream );
/** Terminates audio processing. It waits until all pending
audio buffers have been played before it returns.
*/
PaError Pa_StopStream( PaStream *stream );
/** Terminates audio processing immediately without waiting for pending
buffers to complete.
*/
PaError Pa_AbortStream( 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.
@return 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 Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive
*/
PaError Pa_IsStreamStopped( 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.
@return 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 Pa_StopStream, Pa_AbortStream, Pa_IsStreamStopped
*/
PaError Pa_IsStreamActive( PaStream *stream );
/** A structure containing unchanging information about an open stream.
@see Pa_GetStreamInfo
*/
typedef struct PaStreamInfo
{
/** this is struct version 1 */
int structVersion;
/** The input latency of the stream in seconds. This value provides the most
accurate estimate of input latency available to the implementation. It may
differ significantly from the suggestedLatency value passed to Pa_OpenStream().
The value of this field will be zero (0.) for output-only streams.
@see PaTime
*/
PaTime inputLatency;
/** The output latency of the stream in seconds. This value provides the most
accurate estimate of output latency available to the implementation. It may
differ significantly from the suggestedLatency value passed to Pa_OpenStream().
The value of this field will be zero (0.) for input-only streams.
@see PaTime
*/
PaTime outputLatency;
/** The sample rate of the stream in Hertz (samples per second). In cases
where the hardware sample rate is inaccurate and PortAudio is aware of it,
the value of this field may be different from the sampleRate parameter
passed to Pa_OpenStream(). If information about the actual hardware sample
rate is not available, this field will have the same value as the sampleRate
parameter passed to Pa_OpenStream().
*/
double sampleRate;
} PaStreamInfo;
/** Retrieve a pointer to a PaStreamInfo structure containing information
about the specified stream.
@return A pointer to an immutable PaStreamInfo structure. If the stream
parameter invalid, or an error is encountered, the function returns NULL.
@param stream A 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 PaStreamInfo
*/
const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream );
/** Determine the current time for the stream according to the same clock used
to generate buffer timestamps. This time may be used for syncronising other
events to the audio stream, for example synchronizing audio to MIDI.
@return The stream's current time in seconds, or 0 if an error occurred.
@see PaTime, PaStreamCallback
*/
PaTime Pa_GetStreamTime( 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.
@return
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 occurrs.
*/
double Pa_GetStreamCpuLoad( PaStream* stream );
/** 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.
@param stream A pointer to an open stream previously created with Pa_OpenStream.
@param 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,
buffer is a pointer to the first element of an array of non-interleaved
buffer pointers, one for each channel.
@param 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.
@return On success PaNoError will be returned, or PaInputOverflowed if input
data was discarded by PortAudio after the previous call and before this call.
*/
PaError Pa_ReadStream( PaStream* stream,
void *buffer,
unsigned long frames );
/** Write samples to an output stream. This function doesn't return until the
entire buffer has been consumed - this may involve waiting for the operating
system to consume the data.
@param stream A pointer to an open stream previously created with Pa_OpenStream.
@param 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,
buffer is a pointer to the first element of an array of non-interleaved
buffer pointers, one for each channel.
@param 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.
@return On success PaNoError will be returned, or paOutputUnderflowed if
additional output data was inserted after the previous call and before this
call.
*/
PaError Pa_WriteStream( PaStream* stream,
const void *buffer,
unsigned long frames );
/** Retrieve the number of frames that can be read from the stream without
waiting.
@return 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.
*/
signed long Pa_GetStreamReadAvailable( PaStream* stream );
/** Retrieve the number of frames that can be written to the stream without
waiting.
@return 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.
*/
signed long Pa_GetStreamWriteAvailable( PaStream* stream );
/* Miscellaneous utilities */
/** Retrieve the size of a given sample format in bytes.
@return The size in bytes of a single sample in the specified format,
or paSampleFormatNotSupported if the format is not supported.
*/
PaError Pa_GetSampleSize( PaSampleFormat format );
/** 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.
*/
void Pa_Sleep( long msec );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PORTAUDIO_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -