The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
RtAudio Class Reference

Realtime audio i/o C++ classes. More...

`#include <RtAudio.h>`

## Classes
struct | DeviceInfo
| The public device information structure for returning queried values. More...
struct | StreamOptions
| The structure for specifying stream options. More...
struct | StreamParameters
| The structure for specifying input or ouput stream parameters. More...

## Public Types
enum | Api { UNSPECIFIED, LINUX_ALSA, LINUX_PULSE, LINUX_OSS, UNIX_JACK, MACOSX_CORE, WINDOWS_WASAPI, WINDOWS_ASIO, WINDOWS_DS, RTAUDIO_DUMMY, NUM_APIS }
| Audio API specifier arguments. More...

## Public Member Functions
| RtAudio (RtAudio::Api api=UNSPECIFIED)
| The class constructor. More...
| ~RtAudio ()
| The destructor. More...
RtAudio::Api | getCurrentApi (void)
| Returns the audio API specifier for the current instance of RtAudio.
unsigned int | getDeviceCount (void)
| A public function that queries for the number of audio devices available. More...
RtAudio::DeviceInfo | getDeviceInfo (unsigned int device)
| Return an RtAudio::DeviceInfo structure for a specified device number. More...
unsigned int | getDefaultOutputDevice (void)
| A function that returns the index of the default output device. More...
unsigned int | getDefaultInputDevice (void)
| A function that returns the index of the default input device. More...
void | openStream (RtAudio::StreamParameters *outputParameters, RtAudio::StreamParameters *inputParameters, RtAudioFormat format, unsigned int sampleRate, unsigned int *bufferFrames, RtAudioCallback callback, void *userData=NULL, RtAudio::StreamOptions *options=NULL, RtAudioErrorCallback errorCallback=NULL)
| A public function for opening a stream with the specified parameters. More...
void | closeStream (void)
| A function that closes a stream and frees any associated stream memory. More...
void | startStream (void)
| A function that starts a stream. More...
void | stopStream (void)
| Stop a stream, allowing any samples remaining in the output queue to be played. More...
void | abortStream (void)
| Stop a stream, discarding any samples remaining in the input/output queue. More...
bool | isStreamOpen (void) const
| Returns true if a stream is open and false if not.
bool | isStreamRunning (void) const
| Returns true if the stream is running and false if it is stopped or not open.
double | getStreamTime (void)
| Returns the number of elapsed seconds since the stream was started. More...
void | setStreamTime (double time)
| Set the stream time to a time in seconds greater than or equal to 0.0. More...
long | getStreamLatency (void)
| Returns the internal stream latency in sample frames. More...
unsigned int | getStreamSampleRate (void)
| Returns actual sample rate in use by the stream. More...
void | showWarnings (bool value=true)
| Specify whether warning messages should be printed to stderr.

## Static Public Member Functions
static std::string | getVersion (void)
| A static function to determine the current RtAudio version.
static void | getCompiledApi (std::vector< RtAudio::Api > &apis)
| A static function to determine the available compiled audio APIs. More...
static std::string | getApiName (RtAudio::Api api)
| Return the name of a specified compiled audio API. More...
static std::string | getApiDisplayName (RtAudio::Api api)
| Return the display name of a specified compiled audio API. More...
static RtAudio::Api | getCompiledApiByName (const std::string &name)
| Return the compiled audio API having the given name. More...

## Detailed Description

Realtime audio i/o C++ classes.

RtAudio provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA, Jack, and OSS), Macintosh OS X (CoreAudio and Jack), and Windows (DirectSound, ASIO and WASAPI) operating systems.

RtAudio GitHub site: https://github.com/thestk/rtaudio RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/

RtAudio: realtime audio i/o C++ classes Copyright (c) 2001-2019 Gary P. Scavone

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Any person wishing to distribute modifications to the Software is asked to send the modifications to the original developer so that they can be incorporated into the canonical version. This is, however, not a binding provision of this license.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Member Enumeration Documentation

## ◆ Api

enum RtAudio::Api

Audio API specifier arguments.

Enumerator
UNSPECIFIED | Search for a working compiled API.
LINUX_ALSA | The Advanced Linux Sound Architecture API.
LINUX_PULSE | The Linux PulseAudio API.
LINUX_OSS | The Linux Open Sound System API.
UNIX_JACK | The Jack Low-Latency Audio Server API.
MACOSX_CORE | Macintosh OS-X Core Audio API.
WINDOWS_WASAPI | The Microsoft WASAPI API.
WINDOWS_ASIO | The Steinberg Audio Stream I/O API.
WINDOWS_DS | The Microsoft DirectSound API.
RTAUDIO_DUMMY | A compilable but non-functional API.
NUM_APIS | Number of values in this enum.

284 {
285 UNSPECIFIED,
286 LINUX_ALSA,
287 LINUX_PULSE,
288 LINUX_OSS,
289 UNIX_JACK,
290 MACOSX_CORE,
291 WINDOWS_WASAPI,
292 WINDOWS_ASIO,
293 WINDOWS_DS,
294 RTAUDIO_DUMMY,
295 NUM_APIS
296 };

## Constructor & Destructor Documentation

## ◆ RtAudio()

RtAudio::RtAudio | ( | RtAudio::Api | api = `UNSPECIFIED` | ) |

The class constructor.

The constructor performs minor initialization tasks. An exception can be thrown if no API support is compiled.

If no API argument is specified and multiple API support has been compiled, the default order of use is JACK, ALSA, OSS (Linux systems) and ASIO, DS (Windows systems).

## ◆ ~RtAudio()

RtAudio::~RtAudio | ( |  | ) |

The destructor.

If a stream is running or open, it will be stopped and closed automatically.

## Member Function Documentation

## ◆ getCompiledApi()

static void RtAudio::getCompiledApi | ( | std::vector< RtAudio::Api > & | apis | ) |
| static

A static function to determine the available compiled audio APIs.

The values returned in the std::vector can be compared against the enumerated list values. Note that there can be more than one API compiled for certain operating systems.

## ◆ getApiName()

static std::string RtAudio::getApiName | ( | RtAudio::Api | api | ) |
| static

Return the name of a specified compiled audio API.

This obtains a short lower-case name used for identification purposes. This value is guaranteed to remain identical across library versions. If the API is unknown, this function will return the empty string.

## ◆ getApiDisplayName()

static std::string RtAudio::getApiDisplayName | ( | RtAudio::Api | api | ) |
| static

Return the display name of a specified compiled audio API.

This obtains a long name used for display purposes. If the API is unknown, this function will return the empty string.

## ◆ getCompiledApiByName()

static RtAudio::Api RtAudio::getCompiledApiByName | ( | const std::string & | name | ) |
| static

Return the compiled audio API having the given name.

A case insensitive comparison will check the specified name against the list of compiled APIs, and return the one which matches. On failure, the function returns UNSPECIFIED.

## ◆ getDeviceCount()

unsigned int RtAudio::getDeviceCount | ( | void |  | ) |
| inline

A public function that queries for the number of audio devices available.

This function performs a system query of available devices each time it is called, thus supporting devices connected after instantiation. If a system error occurs during processing, a warning will be issued.

870 { return rtapi_->getDeviceCount(); }

## ◆ getDeviceInfo()

RtAudio::DeviceInfo RtAudio::getDeviceInfo | ( | unsigned int | device | ) |
| inline

Return an RtAudio::DeviceInfo structure for a specified device number.

Any device integer between 0 and getDeviceCount() - 1 is valid. If an invalid argument is provided, an RtAudioError (type = INVALID_USE) will be thrown. If a device is busy or otherwise unavailable, the structure member "probed" will have a value of "false" and all other members are undefined. If the specified device is the current default input or output device, the corresponding "isDefault" member will have a value of "true".

871 { return rtapi_->getDeviceInfo( device ); }

## ◆ getDefaultOutputDevice()

unsigned int RtAudio::getDefaultOutputDevice | ( | void |  | ) |
| inline

A function that returns the index of the default output device.

If the underlying audio API does not provide a "default device", or if no devices are available, the return value will be 0. Note that this is a valid device identifier and it is the client's responsibility to verify that a device is available before attempting to open a stream.

873 { return rtapi_->getDefaultOutputDevice(); }

## ◆ getDefaultInputDevice()

unsigned int RtAudio::getDefaultInputDevice | ( | void |  | ) |
| inline

A function that returns the index of the default input device.

If the underlying audio API does not provide a "default device", or if no devices are available, the return value will be 0. Note that this is a valid device identifier and it is the client's responsibility to verify that a device is available before attempting to open a stream.

872 { return rtapi_->getDefaultInputDevice(); }

## ◆ openStream()

void RtAudio::openStream | ( | RtAudio::StreamParameters * | outputParameters,
|  | RtAudio::StreamParameters * | inputParameters,
|  | RtAudioFormat | format,
|  | unsigned int | sampleRate,
|  | unsigned int * | bufferFrames,
|  | RtAudioCallback | callback,
|  | void * | userData = `NULL`,
|  | RtAudio::StreamOptions * | options = `NULL`,
|  | RtAudioErrorCallback | errorCallback = `NULL`
| ) |  |

A public function for opening a stream with the specified parameters.

An RtAudioError (type = SYSTEM_ERROR) is thrown if a stream cannot be opened with the specified parameters or an error occurs during processing. An RtAudioError (type = INVALID_USE) is thrown if any invalid device ID or channel number parameters are specified.

Parameters

  outputParameters | Specifies output stream parameters to use when opening a stream, including a device ID, number of channels, and starting channel number. For input-only streams, this argument should be NULL. The device ID is an index value between 0 and getDeviceCount() - 1.
  inputParameters | Specifies input stream parameters to use when opening a stream, including a device ID, number of channels, and starting channel number. For output-only streams, this argument should be NULL. The device ID is an index value between 0 and getDeviceCount() - 1.
  format | An RtAudioFormat specifying the desired sample data format.
  sampleRate | The desired sample rate (sample frames per second).
  *bufferFrames | A pointer to a value indicating the desired internal buffer size in sample frames. The actual value used by the device is returned via the same pointer. A value of zero can be specified, in which case the lowest allowable value is determined.
  callback | A client-defined function that will be invoked when input data is available and/or output data is needed.
  userData | An optional pointer to data that can be accessed from within the callback function.
  options | An optional pointer to a structure containing various global stream options, including a list of OR'ed RtAudioStreamFlags and a suggested number of stream buffers that can be used to control stream latency. More buffers typically result in more robust performance, though at a cost of greater latency. If a value of zero is specified, a system-specific median value is chosen. If the RTAUDIO_MINIMIZE_LATENCY flag bit is set, the lowest allowable value is used. The actual value used is returned via the structure argument. The parameter is API dependent.
  errorCallback | A client-defined function that will be invoked when an error has occured.

## ◆ closeStream()

void RtAudio::closeStream | ( | void |  | ) |
| inline

A function that closes a stream and frees any associated stream memory.

If a stream is not open, this function issues a warning and returns (no exception is thrown).

874 { return rtapi_->closeStream(); }

## ◆ startStream()

void RtAudio::startStream | ( | void |  | ) |
| inline

A function that starts a stream.

An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs during processing. An RtAudioError (type = INVALID_USE) is thrown if a stream is not open. A warning is issued if the stream is already running.

875 { return rtapi_->startStream(); }

## ◆ stopStream()

void RtAudio::stopStream | ( | void |  | ) |
| inline

Stop a stream, allowing any samples remaining in the output queue to be played.

An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs during processing. An RtAudioError (type = INVALID_USE) is thrown if a stream is not open. A warning is issued if the stream is already stopped.

876 { return rtapi_->stopStream(); }

## ◆ abortStream()

void RtAudio::abortStream | ( | void |  | ) |
| inline

Stop a stream, discarding any samples remaining in the input/output queue.

An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs during processing. An RtAudioError (type = INVALID_USE) is thrown if a stream is not open. A warning is issued if the stream is already stopped.

877 { return rtapi_->abortStream(); }

## ◆ getStreamTime()

double RtAudio::getStreamTime | ( | void |  | ) |
| inline

Returns the number of elapsed seconds since the stream was started.

If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.

882 { return rtapi_->getStreamTime(); }

## ◆ setStreamTime()

void RtAudio::setStreamTime | ( | double | time | ) |
| inline

Set the stream time to a time in seconds greater than or equal to 0.0.

If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.

883 { return rtapi_->setStreamTime( time ); }

## ◆ getStreamLatency()

long RtAudio::getStreamLatency | ( | void |  | ) |
| inline

Returns the internal stream latency in sample frames.

The stream latency refers to delay in audio input and/or output caused by internal buffering by the audio system and/or hardware. For duplex streams, the returned value will represent the sum of the input and output latencies. If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown. If the API does not report latency, the return value will be zero.

880 { return rtapi_->getStreamLatency(); }

## ◆ getStreamSampleRate()

unsigned int RtAudio::getStreamSampleRate | ( | void |  | ) |
| inline

Returns actual sample rate in use by the stream.

On some systems, the sample rate used may be slightly different than that specified in the stream parameters. If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.

881 { return rtapi_->getStreamSampleRate(); }

The documentation for this class was generated from the following file:

- RtAudio.h

RtAudio::UNSPECIFIED
@ UNSPECIFIED
Definition: RtAudio.h:285
RtAudio::WINDOWS_DS
@ WINDOWS_DS
Definition: RtAudio.h:293
RtAudio::LINUX_ALSA
@ LINUX_ALSA
Definition: RtAudio.h:286
RtAudio::NUM_APIS
@ NUM_APIS
Definition: RtAudio.h:295
RtAudio::WINDOWS_WASAPI
@ WINDOWS_WASAPI
Definition: RtAudio.h:291
RtAudio::UNIX_JACK
@ UNIX_JACK
Definition: RtAudio.h:289
RtAudio::RTAUDIO_DUMMY
@ RTAUDIO_DUMMY
Definition: RtAudio.h:294
RtAudio::WINDOWS_ASIO
@ WINDOWS_ASIO
Definition: RtAudio.h:292
RtAudio::LINUX_OSS
@ LINUX_OSS
Definition: RtAudio.h:288
RtAudio::MACOSX_CORE
@ MACOSX_CORE
Definition: RtAudio.h:290
RtAudio::LINUX_PULSE
@ LINUX_PULSE
Definition: RtAudio.h:287

The Synthesis ToolKit in C++ (STK)
©1995--2019 Perry R. Cook and Gary P. Scavone. All Rights Reserved.