📄 portaudio.h
字号:
@note
On the PC, the user can specify a default device by
setting an environment variable. For example, to use device #1.
<pre>
set PA_RECOMMENDED_OUTPUT_DEVICE=1
</pre>
The user should first determine the available device ids by using
the supplied application "pa_devs".
*/
PaDeviceIndex Pa_GetDefaultOutputDevice( void );
/** The type used to represent monotonic time in seconds that can be used
for syncronisation. The type is used for the outTime argument to the
PaStreamCallback and as the result of Pa_GetStreamTime().
@see PaStreamCallback, Pa_GetStreamTime
*/
typedef double PaTime;
/** 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 aUInt8 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 a multichannel buffer is passed
as a set of non-interleaved pointers.
@see Pa_OpenStream, Pa_OpenDefaultStream, PaDeviceInfo
@see paFloat32, paInt16, paInt32, paInt24, paInt8
@see paUInt8, paCustomFormat, paNonInterleaved
*/
typedef unsigned long PaSampleFormat;
#define paFloat32 ((PaSampleFormat) 0x00000001) /**< @see PaSampleFormat */
#define paInt32 ((PaSampleFormat) 0x00000002) /**< @see PaSampleFormat */
#define paInt24 ((PaSampleFormat) 0x00000004) /**< Packed 24 bit format. @see PaSampleFormat */
#define paInt16 ((PaSampleFormat) 0x00000008) /**< @see PaSampleFormat */
#define paInt8 ((PaSampleFormat) 0x00000010) /**< @see PaSampleFormat */
#define paUInt8 ((PaSampleFormat) 0x00000020) /**< @see PaSampleFormat */
#define paCustomFormat ((PaSampleFormat) 0x00010000)/**< @see PaSampleFormat */
#define paNonInterleaved ((PaSampleFormat) 0x80000000)
/** A structure providing information and capabilities of PortAudio devices.
Devices may support input, output or both input and output.
*/
typedef struct PaDeviceInfo
{
int structVersion; /* this is struct version 2 */
const char *name;
PaHostApiIndex hostApi; /* note this is a host API index, not a type id*/
int maxInputChannels;
int maxOutputChannels;
/* Default latency values for interactive performance. */
PaTime defaultLowInputLatency;
PaTime defaultLowOutputLatency;
/* Default latency values for robust non-interactive applications (eg. playing sound files). */
PaTime defaultHighInputLatency;
PaTime defaultHighOutputLatency;
double defaultSampleRate;
} PaDeviceInfo;
/** Retrieve a pointer to a PaDeviceInfo structure containing information
about the specified device.
@return A pointer to an immutable PaDeviceInfo structure. If the device
parameter is out of range the function returns NULL.
@param device A 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 PaDeviceInfo, PaDeviceIndex
*/
const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device );
/** Parameters for one direction (input or output) of a stream.
*/
typedef struct PaStreamParameters
{
/** A valid device index in the range 0 to (Pa_GetDeviceCount()-1)
specifying the device to be used or the special constant
paUseHostApiSpecificDeviceSpecification which indicates that the actual
device(s) to use are specified in hostApiSpecificStreamInfo.
This field must not be set to paNoDevice.
*/
PaDeviceIndex device;
/** The number of channels of sound to be delivered to the
stream callback or accessed by Pa_ReadStream() or Pa_WriteStream().
It can range from 1 to the value of maxInputChannels in the
PaDeviceInfo record for the device specified by the device parameter.
*/
int channelCount;
/** The sample format of the buffer provided to the stream callback,
a_ReadStream() or Pa_WriteStream(). It may be any of the formats described
by the PaSampleFormat enumeration.
*/
PaSampleFormat sampleFormat;
/** The desired latency in seconds. Where practical, implementations should
configure their latency based on these parameters, otherwise they may
choose the closest viable latency instead. Unless the suggested latency
is greater than the absolute upper limit for the device implementations
shouldround the suggestedLatency up to the next practial value - ie to
provide an equal or higher latency than suggestedLatency whereever possibe.
Actual latency values for an open stream may be retrieved using the
inputLatency and outputLatency fields of the PaStreamInfo structure
returned by Pa_GetStreamInfo().
@see default*Latency in PaDeviceInfo, *Latency in PaStreamInfo
*/
PaTime suggestedLatency;
/** An optional pointer to a host api specific data structure
containing additional information for device setup and/or stream processing.
hostApiSpecificStreamInfo is never required for correct operation,
if not used it should be set to NULL.
*/
void *hostApiSpecificStreamInfo;
} PaStreamParameters;
/** Return code for Pa_IsFormatSupported indicating success. */
#define paFormatIsSupported (0)
/** Determine whether it would be possible to open a stream with the specified
parameters.
@param 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.
@param 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.
@param sampleRate The required sampleRate. For full-duplex streams it is the
sample rate for both input and output
@return 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 paFormatIsSupported, PaStreamParameters
*/
PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate );
/* Streaming types and functions */
/**
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.
@see Pa_OpenStream, Pa_OpenDefaultStream, Pa_OpenDefaultStream, Pa_CloseStream,
Pa_StartStream, Pa_StopStream, Pa_AbortStream, Pa_IsStreamActive,
Pa_GetStreamTime, Pa_GetStreamCpuLoad
*/
typedef void PaStream;
/** 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.
*/
#define paFramesPerBufferUnspecified (0)
/** 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.
@see Pa_OpenStream, Pa_OpenDefaultStream
@see paNoFlag, paClipOff, paDitherOff, paNeverDropInput,
paPrimeOutputBuffersUsingStreamCallback, paPlatformSpecificFlags
*/
typedef unsigned long PaStreamFlags;
/** @see PaStreamFlags */
#define paNoFlag ((PaStreamFlags) 0)
/** Disable default clipping of out of range samples.
@see PaStreamFlags
*/
#define paClipOff ((PaStreamFlags) 0x00000001)
/** Disable default dithering.
@see PaStreamFlags
*/
#define paDitherOff ((PaStreamFlags) 0x00000002)
/** 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.
@see PaStreamFlags, paFramesPerBufferUnspecified
*/
#define paNeverDropInput ((PaStreamFlags) 0x00000004)
/** 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.
@see PaStreamFlags
*/
#define paPrimeOutputBuffersUsingStreamCallback ((PaStreamFlags) 0x00000008)
/** A mask specifying the platform specific bits.
@see PaStreamFlags
*/
#define paPlatformSpecificFlags ((PaStreamFlags)0xFFFF0000)
/**
Timing information for the buffers passed to the stream callback.
*/
typedef struct PaStreamCallbackTimeInfo{
PaTime inputBufferAdcTime;
PaTime currentTime;
PaTime outputBufferDacTime;
} PaStreamCallbackTimeInfo;
/**
Flag bit constants for the statusFlags to PaStreamCallback.
@see paInputUnderflow, paInputOverflow, paOutputUnderflow, paOutputOverflow,
paPrimingOutput
*/
typedef unsigned long PaStreamCallbackFlags;
/** 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.
@see PaStreamCallbackFlags
*/
#define paInputUnderflow ((PaStreamCallbackFlags) 0x00000001)
/** 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.
@see PaStreamCallbackFlags
*/
#define paInputOverflow ((PaStreamCallbackFlags) 0x00000002)
/** Indicates that output data (or a gap) was inserted, possibly because the
stream callback is using too much CPU time.
@see PaStreamCallbackFlags
*/
#define paOutputUnderflow ((PaStreamCallbackFlags) 0x00000004)
/** Indicates that output data will be discarded because no room is available.
@see PaStreamCallbackFlags
*/
#define paOutputOverflow ((PaStreamCallbackFlags) 0x00000008)
/** Some of all of the output data will be used to prime the stream, input
data may be zero.
@see PaStreamCallbackFlags
*/
#define paPrimingOutput ((PaStreamCallbackFlags) 0x00000010)
/**
Allowable return values for the PaStreamCallback.
@see PaStreamCallback
*/
typedef enum PaStreamCallbackResult
{
paContinue=0,
paComplete=1,
paAbort=2
} PaStreamCallbackResult;
/**
Functions of type PaStreamCallback are implemented by PortAudio clients.
They consume, process or generate audio in response to requests from an
active PortAudio stream.
@param input and @param output are arrays of interleaved samples,
the format, packing and number of channels used by the buffers are
determined by parameters to Pa_OpenStream().
@param frameCount The number of sample frames to be processed by
the stream callback.
@param timeInfo The time in seconds when the first sample of the input
buffer was received at the audio input, the time in seconds when the first
sample of the output buffer will begin being played at the audio output, and
the time in seconds when the stream callback was called.
See also Pa_GetStreamTime()
@param statusFlags Flags indicating whether input and/or output buffers
have been inserted or will be dropped to overcome underflow or overflow
conditions.
@param userData The value of a user supplied pointer passed to
Pa_OpenStream() intended for storing synthesis data etc.
@return
The stream callback should return one of the values in the
PaStreamCallbackResult enumeration. To ensure that the callback continues
to be called, it should return paContinue (0). Either paComplete or paAbort
can be returned to finish stream processing, after either of these values is
returned the callback will not be called again. If paAbort is returned the
stream will finish as soon as possible. If paComplete is returned, the stream
will continue until all buffers generated by the callback have been played.
This may be useful in applications such as soundfile players where a specific
duration of output is required. However, it is not necessary to utilise this
mechanism as Pa_StopStream(), Pa_AbortStream() or Pa_CloseStream() can also
be used to stop the stream. The callback must always fill the entire output
buffer irrespective of its return value.
@see Pa_OpenStream, Pa_OpenDefaultStream
@note With the exception of Pa_GetStreamCpuLoad() it is not permissable to call
PortAudio API functions from within the stream callback.
*/
typedef int PaStreamCallback(
const void *input, void *output,
unsigned long frameCount,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );
/** Opens a stream for either input, output or both.
@param stream The address of a PaStream pointer which will receive
a pointer to the newly opened stream.
@param 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -