Home Class/Enum List File List Compound Members C interface

Classes | Typedefs | Enumerations
RtAudio.h File Reference
`#include <string>`
`#include <vector>`
`#include <iostream>`
`#include <functional>`
`#include <pthread.h>`
`#include <sstream>`

Go to the source code of this file.

## Classes

class | RtAudio
| Realtime audio i/o C++ classes. More...
struct | RtAudio::DeviceInfo
| The public device information structure for returning queried values. More...
struct | RtAudio::StreamParameters
| The structure for specifying input or output stream parameters. More...
struct | RtAudio::StreamOptions
| The structure for specifying stream options. More...

## Typedefs

typedef unsigned long | RtAudioFormat
| RtAudio data format type.
typedef unsigned int | RtAudioStreamFlags
| RtAudio stream option flags.
typedef unsigned int | RtAudioStreamStatus
| RtAudio stream status (over- or underflow) flags.
typedef int(* | RtAudioCallback) (void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
| RtAudio callback function prototype.
typedef std::function< void(RtAudioErrorType type, const std::string &errorText)> | RtAudioErrorCallback
| RtAudio error callback function prototype.

## Enumerations

enum | RtAudioErrorType { RTAUDIO_NO_ERROR = 0 , RTAUDIO_WARNING , RTAUDIO_UNKNOWN_ERROR , RTAUDIO_NO_DEVICES_FOUND , RTAUDIO_INVALID_DEVICE , RTAUDIO_DEVICE_DISCONNECT , RTAUDIO_MEMORY_ERROR , RTAUDIO_INVALID_PARAMETER , RTAUDIO_INVALID_USE , RTAUDIO_DRIVER_ERROR , RTAUDIO_SYSTEM_ERROR , RTAUDIO_THREAD_ERROR }

## Class Documentation

## ◆ RtAudio::DeviceInfo

struct RtAudio::DeviceInfo

The public device information structure for returning queried values.

Class Members
unsigned int | ID {} | Device ID used to specify a device to RtAudio.
string | name | Character string device name.
unsigned int | outputChannels {} | Maximum output channels supported by device.
unsigned int | inputChannels {} | Maximum input channels supported by device.
unsigned int | duplexChannels {} | Maximum simultaneous input/output channels supported by device.
bool | isDefaultOutput {false} | true if this is the default output device.
bool | isDefaultInput {false} | true if this is the default input device.
vector< unsigned int > | sampleRates | Supported sample rates (queried from list of standard rates).
unsigned int | currentSampleRate {} | Current sample rate, system sample rate as currently configured.
unsigned int | preferredSampleRate {} | Preferred sample rate, e.g. for WASAPI the system sample rate.
RtAudioFormat | nativeFormats {} | Bit mask of supported data formats.

## ◆ RtAudio::StreamParameters

struct RtAudio::StreamParameters

The structure for specifying input or output stream parameters.

Class Members
unsigned int | deviceId {} | Device id as provided by getDeviceIds().
unsigned int | nChannels {} | Number of channels.
unsigned int | firstChannel {} | First channel index on device (default = 0).

## ◆ RtAudio::StreamOptions

struct RtAudio::StreamOptions

The structure for specifying stream options.

The following flags can be OR'ed together to allow a client to make changes to the default stream behavior:

- RTAUDIO_NONINTERLEAVED: Use non-interleaved buffers (default = interleaved).
- RTAUDIO_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
- RTAUDIO_HOG_DEVICE: Attempt grab device for exclusive use.
- RTAUDIO_SCHEDULE_REALTIME: Attempt to select realtime scheduling for callback thread.
- RTAUDIO_ALSA_USE_DEFAULT: Use the "default" PCM device (ALSA only).

By default, RtAudio streams pass and receive audio data from the client in an interleaved format. By passing the RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio data will instead be presented in non-interleaved buffers. In this case, each buffer argument in the RtAudioCallback function will point to a single array of data, with `nFrames` samples for each channel concatenated back-to-back. For example, the first sample of data for the second channel would be located at index `nFrames` (assuming the `buffer` pointer was recast to the correct data type for the stream).

Certain audio APIs offer a number of parameters that influence the I/O latency of a stream. By default, RtAudio will attempt to set these parameters internally for robust (glitch-free) performance (though some APIs, like Windows DirectSound, make this difficult). By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream() function, internal stream settings will be influenced in an attempt to minimize stream latency, though possibly at the expense of stream performance.

If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to open the input and/or output stream device(s) for exclusive use. Note that this is not possible with all supported audio APIs.

If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt to select realtime scheduling (round-robin) for the callback thread. The `priority` parameter will only be used if the RTAUDIO_SCHEDULE_REALTIME flag is set. It defines the thread's realtime priority.

If the RTAUDIO_ALSA_USE_DEFAULT flag is set, RtAudio will attempt to open the "default" PCM device when using the ALSA API. Note that this will override any specified input or output device id.

The `numberOfBuffers` parameter can be used to control stream latency in the Windows DirectSound, Linux OSS, and Linux Alsa APIs only. A value of two is usually the smallest allowed. Larger numbers can potentially result in more robust stream performance, though likely at the cost of stream latency. The value set by the user is replaced during execution of the RtAudio::openStream() function by the value actually used by the system.

The `streamName` parameter can be used to set the client name when using the Jack API or the application name when using the Pulse API. By default, the Jack client name is set to RtApiJack. However, if you wish to create multiple instances of RtAudio with Jack, each instance must have a unique client name. The default Pulse application name is set to "RtAudio."

Class Members
RtAudioStreamFlags | flags {} | A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE, RTAUDIO_ALSA_USE_DEFAULT).
unsigned int | numberOfBuffers {} | Number of stream buffers.
string | streamName | A stream name (currently used only in Jack).
int | priority {} | Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME).

## Typedef Documentation

## ◆ RtAudioFormat

typedef unsigned long RtAudioFormat

RtAudio data format type.

Support for signed integers and floats. Audio data fed to/from an RtAudio stream is assumed to ALWAYS be in host byte order. The internal routines will automatically take care of any necessary byte-swapping between the host format and the soundcard. Thus, endian-ness is not a concern in the following format definitions. Note that there are no range checks for floating-point values that extend beyond plus/minus 1.0.

- RTAUDIO_SINT8: 8-bit signed integer.
- RTAUDIO_SINT16: 16-bit signed integer.
- RTAUDIO_SINT24: 24-bit signed integer.
- RTAUDIO_SINT32: 32-bit signed integer.
- RTAUDIO_FLOAT32: Normalized between plus/minus 1.0.
- RTAUDIO_FLOAT64: Normalized between plus/minus 1.0.

## ◆ RtAudioStreamFlags

typedef unsigned long RtAudioStreamFlags

RtAudio stream option flags.

The following flags can be OR'ed together to allow a client to make changes to the default stream behavior:

- RTAUDIO_NONINTERLEAVED: Use non-interleaved buffers (default = interleaved).
- RTAUDIO_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
- RTAUDIO_HOG_DEVICE: Attempt grab device for exclusive use.
- RTAUDIO_ALSA_USE_DEFAULT: Use the "default" PCM device (ALSA only).
- RTAUDIO_JACK_DONT_CONNECT: Do not automatically connect ports (JACK only).

By default, RtAudio streams pass and receive audio data from the client in an interleaved format. By passing the RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio data will instead be presented in non-interleaved buffers. In this case, each buffer argument in the RtAudioCallback function will point to a single array of data, with `nFrames` samples for each channel concatenated back-to-back. For example, the first sample of data for the second channel would be located at index `nFrames` (assuming the `buffer` pointer was recast to the correct data type for the stream).

Certain audio APIs offer a number of parameters that influence the I/O latency of a stream. By default, RtAudio will attempt to set these parameters internally for robust (glitch-free) performance (though some APIs, like Windows DirectSound, make this difficult). By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream() function, internal stream settings will be influenced in an attempt to minimize stream latency, though possibly at the expense of stream performance.

If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to open the input and/or output stream device(s) for exclusive use. Note that this is not possible with all supported audio APIs.

If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt to select realtime scheduling (round-robin) for the callback thread.

If the RTAUDIO_ALSA_USE_DEFAULT flag is set, RtAudio will attempt to open the "default" PCM device when using the ALSA API. Note that this will override any specified input or output device id.

If the RTAUDIO_JACK_DONT_CONNECT flag is set, RtAudio will not attempt to automatically connect the ports of the client to the audio device.

## ◆ RtAudioStreamStatus

typedef unsigned long RtAudioStreamStatus

RtAudio stream status (over- or underflow) flags.

Notification of a stream over- or underflow is indicated by a non-zero stream `status` argument in the RtAudioCallback function. The stream status can be one of the following two options, depending on whether the stream is open for output and/or input:

- RTAUDIO_INPUT_OVERFLOW: Input data was discarded because of an overflow condition at the driver.
- RTAUDIO_OUTPUT_UNDERFLOW: The output buffer ran low, likely producing a break in the output sound.

## ◆ RtAudioCallback

typedef int(* RtAudioCallback) (void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)

RtAudio callback function prototype.

All RtAudio clients must create a function of type RtAudioCallback to read and/or write data from/to the audio stream. When the underlying audio system is ready for new input or output data, this function will be invoked.

Parameters

  outputBuffer | For output (or duplex) streams, the client should write `nFrames` of audio sample frames into this buffer. This argument should be recast to the datatype specified when the stream was opened. For input-only streams, this argument will be NULL.
  inputBuffer | For input (or duplex) streams, this buffer will hold `nFrames` of input audio sample frames. This argument should be recast to the datatype specified when the stream was opened. For output-only streams, this argument will be NULL.
  nFrames | The number of sample frames of input or output data in the buffers. The actual buffer size in bytes is dependent on the data type and number of channels in use.
  streamTime | The number of seconds that have elapsed since the stream was started.
  status | If non-zero, this argument indicates a data overflow or underflow condition for the stream. The particular condition can be determined by comparison with the RtAudioStreamStatus flags.
  userData | A pointer to optional data provided by the client when opening the stream (default = NULL).

Returns
  To continue normal stream operation, the RtAudioCallback function should return a value of zero. To stop the stream and drain the output buffer, the function should return a value of one. To abort the stream immediately, the client should return a value of two.

## ◆ RtAudioErrorCallback

typedef std::function<void(RtAudioErrorType type, const std::string &errorText )> RtAudioErrorCallback

RtAudio error callback function prototype.

Parameters

  type | Type of error.
  errorText | Error description.

## Enumeration Type Documentation

## ◆ RtAudioErrorType

enum RtAudioErrorType

Enumerator
RTAUDIO_NO_ERROR | No error.
RTAUDIO_WARNING | A non-critical error.
RTAUDIO_UNKNOWN_ERROR | An unspecified error type.
RTAUDIO_NO_DEVICES_FOUND | No devices found on system.
RTAUDIO_INVALID_DEVICE | An invalid device ID was specified.
RTAUDIO_DEVICE_DISCONNECT | A device in use was disconnected.
RTAUDIO_MEMORY_ERROR | An error occurred during memory allocation.
RTAUDIO_INVALID_PARAMETER | An invalid parameter was specified to a function.
RTAUDIO_INVALID_USE | The function was called incorrectly.
RTAUDIO_DRIVER_ERROR | A system driver error occurred.
RTAUDIO_SYSTEM_ERROR | A system error occurred.
RTAUDIO_THREAD_ERROR | A thread error occurred.

| ©2001-2023 Gary P. Scavone, McGill University. All Rights Reserved. Maintained by Gary P. Scavone.