RtAudio Class Reference

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

#include <RtAudio.hxx>

List of all members.

Classes

struct  RTAUDIO_DEVICE
 The public device information structure for passing queried values. More...
struct  RTAUDIO_STREAM

Public Types

enum  { MAX_SAMPLE_RATES = 14 }
typedef unsigned long RTAUDIO_FORMAT
typedef int(* RTAUDIO_CALLBACK )(char *buffer, int bufferSize, void *userData)

Public Member Functions

 RtAudio ()
 The default constructor.
 RtAudio (int *streamId, int outputDevice, int outputChannels, int inputDevice, int inputChannels, RTAUDIO_FORMAT format, int sampleRate, int *bufferSize, int numberOfBuffers)
 A constructor which can be used to open a stream during instantiation.
 ~RtAudio ()
 The destructor.
int openStream (int outputDevice, int outputChannels, int inputDevice, int inputChannels, RTAUDIO_FORMAT format, int sampleRate, int *bufferSize, int numberOfBuffers)
 A public method for opening a stream with the specified parameters.
void setStreamCallback (int streamId, RTAUDIO_CALLBACK callback, void *userData)
 A public method which sets a user-defined callback function for a given stream.
void cancelStreamCallback (int streamId)
 A public method which cancels a callback process and function for a given stream.
int getDeviceCount (void)
 A public method which returns the number of audio devices found.
void getDeviceInfo (int device, RTAUDIO_DEVICE *info)
 Fill a user-supplied RTAUDIO_DEVICE structure for a specified device number.
char *const getStreamBuffer (int streamId)
 A public method which returns a pointer to the buffer for an open stream.
void tickStream (int streamId)
 Public method used to trigger processing of input/output data for a stream.
void closeStream (int streamId)
 Public method which closes a stream and frees any associated buffers.
void startStream (int streamId)
 Public method which starts a stream.
void stopStream (int streamId)
 Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
void abortStream (int streamId)
 Stop a stream, discarding any samples remaining in the input/output queue.
int streamWillBlock (int streamId)
 Queries a stream to determine whether a call to the tickStream() method will block.

Static Public Attributes

static const RTAUDIO_FORMAT RTAUDIO_SINT8 = 1
static const RTAUDIO_FORMAT RTAUDIO_SINT16 = 2
static const RTAUDIO_FORMAT RTAUDIO_SINT24 = 4
static const RTAUDIO_FORMAT RTAUDIO_SINT32 = 8
static const RTAUDIO_FORMAT RTAUDIO_FLOAT32 = 16
static const RTAUDIO_FORMAT RTAUDIO_FLOAT64 = 32

Detailed Description

Realtime audio i/o C++ class.

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

RtAudio WWW site: http://www-ccrma.stanford.edu/~gary/rtaudio/

RtAudio: a realtime audio i/o C++ class Copyright (c) 2001-2002 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 requested to send the modifications to the original developer so that they can be incorporated into the canonical version.

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.

Definition at line 217 of file RtAudio.hxx.


Member Typedef Documentation

typedef int(* RtAudio::RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData)

Definition at line 238 of file RtAudio.hxx.

Definition at line 227 of file RtAudio.hxx.


Member Enumeration Documentation

anonymous enum
Enumerator:
MAX_SAMPLE_RATES 

Definition at line 236 of file RtAudio.hxx.


Constructor & Destructor Documentation

RtAudio::RtAudio (  ) 

The default constructor.

Probes the system to make sure at least one audio input/output device is available and determines the api-specific identifier for each device found. An RtError error can be thrown if no devices are found or if a memory allocation error occurs.

Definition at line 96 of file RtAudio.cxx.

References RtError::NO_DEVICES_FOUND.

RtAudio::RtAudio ( int streamId,
int  outputDevice,
int  outputChannels,
int  inputDevice,
int  inputChannels,
RTAUDIO_FORMAT  format,
int  sampleRate,
int bufferSize,
int  numberOfBuffers 
)

A constructor which can be used to open a stream during instantiation.

The specified output and/or input device identifiers correspond to those enumerated via the getDeviceInfo() method. If device = 0, the default or first available devices meeting the given parameters is selected. If an output or input channel value is zero, the corresponding device value is ignored. When a stream is successfully opened, its identifier is returned via the "streamId" pointer. An RtError can be thrown if no devices are found for the given parameters, if a memory allocation error occurs, or if a driver error occurs.

See also:
openStream()

Definition at line 106 of file RtAudio.cxx.

References RtError::NO_DEVICES_FOUND, and openStream().

RtAudio::~RtAudio (  ) 

The destructor.

Stops and closes any open streams and devices and deallocates buffer and structure memory.

Definition at line 130 of file RtAudio.cxx.

References closeStream().


Member Function Documentation

void RtAudio::abortStream ( int  streamId  ) 

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

An RtError will be thrown for an invalid stream identifier or if a driver error occurs.

void RtAudio::cancelStreamCallback ( int  streamId  ) 

A public method which cancels a callback process and function for a given stream.

This method shuts down a callback process and de-references the user function for a specific stream. Callback functionality can subsequently be restarted on the stream via the setStreamCallback() method. An RtError will be thrown for an invalid device argument.

void RtAudio::closeStream ( int  streamId  ) 

Public method which closes a stream and frees any associated buffers.

If an invalid stream identifier is specified, this method issues a warning and returns (an RtError is not thrown).

Referenced by openStream(), and ~RtAudio().

int RtAudio::getDeviceCount ( void   ) 

A public method which returns the number of audio devices found.

Definition at line 263 of file RtAudio.cxx.

void RtAudio::getDeviceInfo ( int  device,
RTAUDIO_DEVICE info 
)

Fill a user-supplied RTAUDIO_DEVICE structure for a specified device number.

Any device integer between 1 and getDeviceCount() is valid. 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 "isDefault" member will have a value of "true". An RtError will be thrown for an invalid device argument.

Definition at line 268 of file RtAudio.cxx.

References RtAudio::RTAUDIO_DEVICE::hasDuplexSupport, RtError::INVALID_DEVICE, RtAudio::RTAUDIO_DEVICE::isDefault, RtAudio::RTAUDIO_DEVICE::maxDuplexChannels, RtAudio::RTAUDIO_DEVICE::maxInputChannels, RtAudio::RTAUDIO_DEVICE::maxOutputChannels, RtAudio::RTAUDIO_DEVICE::minDuplexChannels, RtAudio::RTAUDIO_DEVICE::minInputChannels, RtAudio::RTAUDIO_DEVICE::minOutputChannels, RtAudio::RTAUDIO_DEVICE::name, RtAudio::RTAUDIO_DEVICE::nativeFormats, RtAudio::RTAUDIO_DEVICE::nSampleRates, RtAudio::RTAUDIO_DEVICE::probed, and RtAudio::RTAUDIO_DEVICE::sampleRates.

char *const RtAudio::getStreamBuffer ( int  streamId  ) 

A public method which returns a pointer to the buffer for an open stream.

The user should fill and/or read the buffer data in interleaved format and then call the tickStream() method. An RtError will be thrown for an invalid stream identifier.

Definition at line 314 of file RtAudio.cxx.

Referenced by CLAM::RtAAudioDevice::Stop().

int RtAudio::openStream ( int  outputDevice,
int  outputChannels,
int  inputDevice,
int  inputChannels,
RTAUDIO_FORMAT  format,
int  sampleRate,
int bufferSize,
int  numberOfBuffers 
)

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

If successful, the opened stream ID is returned. Otherwise, an RtError is thrown.

Parameters:
outputDevice,: If equal to 0, the default or first device found meeting the given parameters is opened. Otherwise, the device number should correspond to one of those enumerated via the getDeviceInfo() method.
outputChannels,: The desired number of output channels. If equal to zero, the outputDevice identifier is ignored.
inputDevice,: If equal to 0, the default or first device found meeting the given parameters is opened. Otherwise, the device number should correspond to one of those enumerated via the getDeviceInfo() method.
inputChannels,: The desired number of input channels. If equal to zero, the inputDevice identifier is ignored.
format,: An RTAUDIO_FORMAT specifying the desired sample data format.
sampleRate,: The desired sample rate (sample frames per second).
*bufferSize,: A pointer 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.
numberOfBuffers,: A value which can be used to help control device latency. More buffers typically result in more robust performance, though at a cost of greater latency. A value of zero can be specified, in which case the lowest allowable value is used.

Definition at line 140 of file RtAudio.cxx.

References closeStream(), RtError::INVALID_PARAMETER, RtError::MEMORY_ERROR, MUTEX_INITIALIZE, and NULL.

Referenced by RtAudio().

void RtAudio::setStreamCallback ( int  streamId,
RTAUDIO_CALLBACK  callback,
void *  userData 
)

A public method which sets a user-defined callback function for a given stream.

This method assigns a callback function to a specific, previously opened stream for non-blocking stream functionality. A separate process is initiated, though the user function is called only when the stream is "running" (between calls to the startStream() and stopStream() methods, respectively). The callback process remains active for the duration of the stream and is automatically shutdown when the stream is closed (via the closeStream() method or by object destruction). The callback process can also be shutdown and the user function de-referenced through an explicit call to the cancelStreamCallback() method. Note that a single stream can use only blocking or callback functionality at the same time, though it is possible to alternate modes on the same stream through the use of the setStreamCallback() and cancelStreamCallback() methods (the blocking tickStream() method can be used before a callback is set and/or after a callback is cancelled). An RtError will be thrown for an invalid device argument.

void RtAudio::startStream ( int  streamId  ) 

Public method which starts a stream.

An RtError will be thrown for an invalid stream identifier or if a driver error occurs.

void RtAudio::stopStream ( int  streamId  ) 

Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.

An RtError will be thrown for an invalid stream identifier or if a driver error occurs.

Referenced by CLAM::RtAAudioDevice::~RtAAudioDevice().

int RtAudio::streamWillBlock ( int  streamId  ) 

Queries a stream to determine whether a call to the tickStream() method will block.

A return value of 0 indicates that the stream will NOT block. A positive return value indicates the number of sample frames that cannot yet be processed without blocking.

void RtAudio::tickStream ( int  streamId  ) 

Public method used to trigger processing of input/output data for a stream.

This method blocks until all buffer data is read/written. An RtError will be thrown for an invalid stream identifier or if a driver error occurs.


Member Data Documentation

Normalized between plus/minus 1.0.

Definition at line 232 of file RtAudio.hxx.

Normalized between plus/minus 1.0.

Definition at line 233 of file RtAudio.hxx.

16-bit signed integer.

Definition at line 229 of file RtAudio.hxx.

Upper 3 bytes of 32-bit signed integer.

Definition at line 230 of file RtAudio.hxx.

32-bit signed integer.

Definition at line 231 of file RtAudio.hxx.

8-bit signed integer.

Definition at line 228 of file RtAudio.hxx.


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.3