RtAudio: A Cross-Platform C++ Class for Realtime
Audio Input/Output
Gary P. Scavone
gary@ccrma. stanford.edu
Center for Computer Research in Music and Acoustics
Department of Music, Stanford University
Stanford, California 94305-8180 USA
Abstract
This paper presents a cross-platform C++ class for
realtime audio input and output streaming. RtAudio provides a flexible, easy to use application programming interface (API) which allows complete
audio system control, including device capability
querying, multiple concurrent streams, blocking
and callback functionality. RtAudio is currently
supported on Windows platforms using the DirectSound API, Linux platforms using both the OSS
and ALSA APIs, and on Irix platforms. Support
for OS-X and Steinberg ASIO drivers is planned
for Spring 2002.
1 Introduction
While programming languages have gained
standardized support across the myriad of computer platforms and operating systems in existence, a commonly supported API for audio programming is far from a reality. As a result, an
attempt to provide multi-platform support for an
audio application can prove difficult at best. To
further complicate matters, multiple audio driver
interfaces often exist for a single operating system.
For example, Windows platforms have DirectSound, Windows Multimedia Library, and ASIO
(Steinberg) driver options, Linux platforms have
Open Sound System (OSS) and Advanced Linux
Sound Architecture (ALSA) drivers, and Macintosh platforms have Sound Manager, ASIO and
Core Audio drivers. RtAudio was designed to provide a common interface across a variety of these
APIs in as flexible, yet simple, manner as possible.
RtAudio was originally developed to provide
audio input/output support for the Synthesis
ToolKit in C++ (STK) (Cook and Scavone, 1999).
However, the latest release of RtAudio (version
2.0, January 2002) was designed to function independently from STK, as well as any libraries
other than those necessitated by the underlying
platform-specific audio interfaces.
2 Features & Design Goals
RtAudio is a C++ class which provides a common API for realtime audio input/output across
Linux, Irix, and Windows operating systems.
RtAudio significantly simplifies the process of interfacing with computer audio hardware. It was
designed with the following goals:
* object-oriented C++ structure
* single independent header and source file for
easy inclusion in programming projects
* blocking and callback functionality
* flexible, easy to use, audio device parameter
control
* automatic internal conversion for data format, channel number compensation, deinterleaving, and byte-swapping
* control over multiple audio streams and devices with a single class instance
* audio device capability probing
RtAudio incorporates the concept of audio
streams, which represent independent audio output (playback) and/or input (recording) "connections" to audio devices. Available audio devices
and their capabilities can be enumerated and then
specified when opening a stream. Multiple streams
can run at the same time and, when allowed by the
underlying audio API, a single device can serve
multiple streams.
The RtAudio API provides both blocking (synchronous) and callback (asynchronous) functionality. Callbacks offer a simple means for achieving non-blocking audio input/output. Blocking
functionality is often necessary for explicit control of multiple input/output stream synchronization or when audio must be synchronized with
other system events. All public RtAudio functions are thread-safe. This allows users to safely
196
0