From cdfd5a2d8e8781f1925e90953a330ad38e63222f Mon Sep 17 00:00:00 2001 From: Gary Scavone Date: Thu, 10 Oct 2013 23:52:38 +0200 Subject: Release 2.0 tarball --- doc/html/RtAudio_8h-source.html | 295 +++++++ doc/html/RtAudio_8h.html | 56 ++ doc/html/annotated.html | 24 + doc/html/classRtAudio-members.html | 45 + doc/html/classRtAudio.html | 918 +++++++++++++++++++++ doc/html/classRtAudioError-members.html | 40 + doc/html/classRtAudioError.html | 337 ++++++++ doc/html/doxygen.css | 20 + doc/html/doxygen.gif | Bin 0 -> 2378 bytes doc/html/files.html | 21 + doc/html/functions.html | 129 +++ doc/html/globals.html | 27 + doc/html/index.html | 583 +++++++++++++ .../structRtAudio_1_1RTAUDIO__DEVICE-members.html | 34 + doc/html/structRtAudio_1_1RTAUDIO__DEVICE.html | 378 +++++++++ doc/html/tutorial_8txt.html | 21 + 16 files changed, 2928 insertions(+) create mode 100644 doc/html/RtAudio_8h-source.html create mode 100644 doc/html/RtAudio_8h.html create mode 100644 doc/html/annotated.html create mode 100644 doc/html/classRtAudio-members.html create mode 100644 doc/html/classRtAudio.html create mode 100644 doc/html/classRtAudioError-members.html create mode 100644 doc/html/classRtAudioError.html create mode 100644 doc/html/doxygen.css create mode 100644 doc/html/doxygen.gif create mode 100644 doc/html/files.html create mode 100644 doc/html/functions.html create mode 100644 doc/html/globals.html create mode 100644 doc/html/index.html create mode 100644 doc/html/structRtAudio_1_1RTAUDIO__DEVICE-members.html create mode 100644 doc/html/structRtAudio_1_1RTAUDIO__DEVICE.html create mode 100644 doc/html/tutorial_8txt.html (limited to 'doc/html') diff --git a/doc/html/RtAudio_8h-source.html b/doc/html/RtAudio_8h-source.html new file mode 100644 index 0000000..cd9bc20 --- /dev/null +++ b/doc/html/RtAudio_8h-source.html @@ -0,0 +1,295 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio.h

Go to the documentation of this file.
00001 /******************************************/
+00002 /*
+00003   RtAudio - realtime sound I/O C++ class
+00004   Version 2.0 by Gary P. Scavone, 2001-2002.
+00005 */
+00006 /******************************************/
+00007 
+00008 #if !defined(__RtAudio_h)
+00009 #define __RtAudio_h
+00010 
+00011 #include <map>
+00012 
+00013 #if defined(__LINUX_ALSA_)
+00014   #include <alsa/asoundlib.h>
+00015   #include <pthread.h>
+00016   #include <unistd.h>
+00017 
+00018   typedef snd_pcm_t *AUDIO_HANDLE;
+00019   typedef int DEVICE_ID;
+00020   typedef pthread_t THREAD_HANDLE;
+00021   typedef pthread_mutex_t MUTEX;
+00022 
+00023 #elif defined(__LINUX_OSS_)
+00024   #include <pthread.h>
+00025   #include <unistd.h>
+00026 
+00027   typedef int AUDIO_HANDLE;
+00028   typedef int DEVICE_ID;
+00029   typedef pthread_t THREAD_HANDLE;
+00030   typedef pthread_mutex_t MUTEX;
+00031 
+00032 #elif defined(__WINDOWS_DS_)
+00033   #include <windows.h>
+00034   #include <process.h>
+00035 
+00036   // The following struct is used to hold the extra variables
+00037   // specific to the DirectSound implementation.
+00038   typedef struct {
+00039     void * object;
+00040     void * buffer;
+00041     UINT bufferPointer;
+00042   } AUDIO_HANDLE;
+00043 
+00044   typedef LPGUID DEVICE_ID;
+00045   typedef unsigned long THREAD_HANDLE;
+00046   typedef CRITICAL_SECTION MUTEX;
+00047 
+00048 #elif defined(__IRIX_AL_)
+00049   #include <dmedia/audio.h>
+00050   #include <pthread.h>
+00051   #include <unistd.h>
+00052 
+00053   typedef ALport AUDIO_HANDLE;
+00054   typedef int DEVICE_ID;
+00055   typedef pthread_t THREAD_HANDLE;
+00056   typedef pthread_mutex_t MUTEX;
+00057 
+00058 #endif
+00059 
+00060 
+00061 // *************************************************** //
+00062 //
+00063 // RtAudioError class declaration.
+00064 //
+00065 // *************************************************** //
+00066 
+00067 class RtAudioError
+00068 {
+00069 public:
+00070   enum TYPE {
+00071     WARNING,
+00072     DEBUG_WARNING,
+00073     UNSPECIFIED,
+00074     NO_DEVICES_FOUND,
+00075     INVALID_DEVICE,
+00076     INVALID_STREAM,
+00077     MEMORY_ERROR,
+00078     INVALID_PARAMETER,
+00079     DRIVER_ERROR,
+00080     SYSTEM_ERROR,
+00081     THREAD_ERROR
+00082   };
+00083 
+00084 protected:
+00085   char error_message[256];
+00086   TYPE type;
+00087 
+00088 public:
+00090   RtAudioError(const char *p, TYPE tipe = RtAudioError::UNSPECIFIED);
+00091 
+00093   virtual ~RtAudioError(void);
+00094 
+00096   virtual void printMessage(void);
+00097 
+00099   virtual const TYPE& getType(void) { return type; }
+00100 
+00102   virtual const char *getMessage(void) { return error_message; }
+00103 };
+00104 
+00105 
+00106 // *************************************************** //
+00107 //
+00108 // RtAudio class declaration.
+00109 //
+00110 // *************************************************** //
+00111 
+00112 class RtAudio
+00113 {
+00114 public:
+00115 
+00116   // Support for signed integers and floats.  Audio data fed to/from
+00117   // the tickStream() routine is assumed to ALWAYS be in host
+00118   // byte order.  The internal routines will automatically take care of
+00119   // any necessary byte-swapping between the host format and the
+00120   // soundcard.  Thus, endian-ness is not a concern in the following
+00121   // format definitions.
+00122   typedef unsigned long RTAUDIO_FORMAT;
+00123   static const RTAUDIO_FORMAT RTAUDIO_SINT8;
+00124   static const RTAUDIO_FORMAT RTAUDIO_SINT16;
+00125   static const RTAUDIO_FORMAT RTAUDIO_SINT24; 
+00126   static const RTAUDIO_FORMAT RTAUDIO_SINT32;
+00127   static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; 
+00128   static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; 
+00130   //static const int MAX_SAMPLE_RATES = 14;
+00131   enum { MAX_SAMPLE_RATES = 14 };
+00132 
+00133   typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);
+00134 
+00135   typedef struct {
+00136     char name[128];
+00137     DEVICE_ID id[2];  
+00138     bool probed;       
+00139     int maxOutputChannels;
+00140     int maxInputChannels;
+00141     int maxDuplexChannels;
+00142     int minOutputChannels;
+00143     int minInputChannels;
+00144     int minDuplexChannels;
+00145     bool hasDuplexSupport; 
+00146     int nSampleRates;      
+00147     int sampleRates[MAX_SAMPLE_RATES]; 
+00148     RTAUDIO_FORMAT nativeFormats;     
+00149   } RTAUDIO_DEVICE;
+00150 
+00152 
+00159   RtAudio();
+00160 
+00162 
+00173   RtAudio(int *streamID,
+00174           int outputDevice, int outputChannels,
+00175           int inputDevice, int inputChannels,
+00176           RTAUDIO_FORMAT format, int sampleRate,
+00177           int *bufferSize, int numberOfBuffers);
+00178 
+00180 
+00184   ~RtAudio();
+00185 
+00187 
+00214   int openStream(int outputDevice, int outputChannels,
+00215                  int inputDevice, int inputChannels,
+00216                  RTAUDIO_FORMAT format, int sampleRate,
+00217                  int *bufferSize, int numberOfBuffers);
+00218 
+00220 
+00239   void setStreamCallback(int streamID, RTAUDIO_CALLBACK callback, void *userData);
+00240 
+00242 
+00249   void cancelStreamCallback(int streamID);
+00250 
+00252   int getDeviceCount(void);
+00253 
+00255 
+00265   void getDeviceInfo(int device, RTAUDIO_DEVICE *info);
+00266 
+00268 
+00273   char * const getStreamBuffer(int streamID);
+00274 
+00276 
+00281   void tickStream(int streamID);
+00282 
+00284 
+00288   void closeStream(int streamID);
+00289 
+00291 
+00295   void startStream(int streamID);
+00296 
+00298 
+00302   void stopStream(int streamID);
+00303 
+00305 
+00309   void abortStream(int streamID);
+00310 
+00312 
+00317   int streamWillBlock(int streamID);
+00318 
+00319 protected:
+00320 
+00321 private:
+00322 
+00323   static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];
+00324 
+00325   enum { FAILURE, SUCCESS };
+00326 
+00327   enum STREAM_MODE {
+00328     PLAYBACK,
+00329     RECORD,
+00330     DUPLEX,
+00331     UNINITIALIZED = -75
+00332   };
+00333 
+00334   enum STREAM_STATE {
+00335     STREAM_STOPPED,
+00336     STREAM_RUNNING
+00337   };
+00338 
+00339   typedef struct {
+00340     int device[2];           // Playback and record, respectively.
+00341     STREAM_MODE mode;       // PLAYBACK, RECORD, or DUPLEX.
+00342     AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.
+00343     STREAM_STATE state;     // STOPPED or RUNNING
+00344     char *userBuffer;
+00345     char *deviceBuffer;
+00346     bool doConvertBuffer[2]; // Playback and record, respectively.
+00347     bool deInterleave[2];    // Playback and record, respectively.
+00348     bool doByteSwap[2];      // Playback and record, respectively.
+00349     int sampleRate;
+00350     int bufferSize;
+00351     int nBuffers;
+00352     int nUserChannels[2];    // Playback and record, respectively.
+00353     int nDeviceChannels[2];  // Playback and record channels, respectively.
+00354     RTAUDIO_FORMAT userFormat;
+00355     RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.
+00356     bool usingCallback;
+00357     THREAD_HANDLE thread;
+00358     MUTEX mutex;
+00359     RTAUDIO_CALLBACK callback;
+00360     void *userData;
+00361   } RTAUDIO_STREAM;
+00362 
+00363   typedef signed short INT16;
+00364   typedef signed int INT32;
+00365   typedef float FLOAT32;
+00366   typedef double FLOAT64;
+00367 
+00368   char message[256];
+00369   int nDevices;
+00370   RTAUDIO_DEVICE *devices;
+00371 
+00372   std::map<int, void *> streams;
+00373 
+00375   void error(RtAudioError::TYPE type);
+00376 
+00381   void initialize(void);
+00382 
+00384   void clearDeviceInfo(RTAUDIO_DEVICE *info);
+00385 
+00393   void probeDeviceInfo(RTAUDIO_DEVICE *info);
+00394 
+00401   bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+00402                        STREAM_MODE mode, int channels, 
+00403                        int sampleRate, RTAUDIO_FORMAT format,
+00404                        int *bufferSize, int numberOfBuffers);
+00405 
+00412   void *verifyStream(int streamID);
+00413 
+00418   void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);
+00419 
+00421   void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);
+00422 
+00424   int formatBytes(RTAUDIO_FORMAT format);
+00425 };
+00426 
+00427 // Uncomment the following definition to have extra information spewed to stderr.
+00428 //#define RTAUDIO_DEBUG
+00429 
+00430 #endif
+

+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/RtAudio_8h.html b/doc/html/RtAudio_8h.html new file mode 100644 index 0000000..b38da61 --- /dev/null +++ b/doc/html/RtAudio_8h.html @@ -0,0 +1,56 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio.h File Reference

#include <map>
+ +

+Go to the source code of this file. + + + + + + + +

Compounds

class  RtAudioError
class  RtAudio
struct  RtAudio::RTAUDIO_DEVICE
struct  RtAudio::RTAUDIO_STREAM

Defines

#define __RtAudio_h
+


Define Documentation

+

+ + + + +
+ + +
+#define __RtAudio_h +
+
+ + + + + +
+   + + +

+Value:

+
+


+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/annotated.html b/doc/html/annotated.html new file mode 100644 index 0000000..4a41b69 --- /dev/null +++ b/doc/html/annotated.html @@ -0,0 +1,24 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio Compound List

Here are the classes, structs, unions and interfaces with brief descriptions: +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/classRtAudio-members.html b/doc/html/classRtAudio-members.html new file mode 100644 index 0000000..9eaea52 --- /dev/null +++ b/doc/html/classRtAudio-members.html @@ -0,0 +1,45 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio Member List

This is the complete list of members for RtAudio, including all inherited members. +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/classRtAudio.html b/doc/html/classRtAudio.html new file mode 100644 index 0000000..9986e3a --- /dev/null +++ b/doc/html/classRtAudio.html @@ -0,0 +1,918 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio Class Reference

#include <RtAudio.h> +

+List of all members. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Types

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

Public Methods

 RtAudio ()
 The default constructor. More...

 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. More...

 ~RtAudio ()
 The destructor. More...

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. More...

void setStreamCallback (int streamID, RTAUDIO_CALLBACK callback, void *userData)
 A public method which sets a user-defined callback function for a given stream. More...

void cancelStreamCallback (int streamID)
 A public method which cancels a callback process and function for a given stream. More...

int getDeviceCount (void)
 A public method which returns the number of audio devices found. More...

void getDeviceInfo (int device, RTAUDIO_DEVICE *info)
 Fill a user-supplied RTAUDIO_DEVICE structure for a specified device. More...

char* const getStreamBuffer (int streamID)
 A public method which returns a pointer to the buffer for an open stream. More...

void tickStream (int streamID)
 Public method used to trigger processing of input/output data for a stream. More...

void closeStream (int streamID)
 Public method which closes a stream and frees any associated buffers. More...

void startStream (int streamID)
 Public method which starts a stream. More...

void stopStream (int streamID)
 Stop a stream, allowing any samples remaining in the queue to be played out and/or read in. More...

void abortStream (int streamID)
 Stop a stream, discarding any samples remaining in the input/output queue. More...

int streamWillBlock (int streamID)
 Queries a stream to determine whether a call to the tickStream() method will block. More...


Static Public Attributes

const RTAUDIO_FORMAT RTAUDIO_SINT8
const RTAUDIO_FORMAT RTAUDIO_SINT16
const RTAUDIO_FORMAT RTAUDIO_SINT24
const RTAUDIO_FORMAT RTAUDIO_SINT32
const RTAUDIO_FORMAT RTAUDIO_FLOAT32
const RTAUDIO_FORMAT RTAUDIO_FLOAT64
+


Member Typedef Documentation

+

+ + + + +
+ + + + + +
+typedef unsigned long RtAudio::RTAUDIO_FORMAT +
+
+ + + + + +
+   + + +

+

+

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

+

+


Member Enumeration Documentation

+

+ + + + +
+ + + + + +
+anonymous enum +
+
+ + + + + +
+   + + +

+

+Enumeration values:
+ + +
MAX_SAMPLE_RATES +
+
+
+


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 RtAudioError error can be thrown if no devices are found or if a memory allocation error occurs.

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+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 RtAudioError 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()
+

+ + + + +
+ + + + + + +
+RtAudio::~RtAudio ( + +) +
+
+ + + + + +
+   + + +

+The destructor. +

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

+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+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 RtAudioError 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.
+
+

+ + + + +
+ + + + + + + + + + + + + + +
+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 RtAudioError will be thrown for an invalid device argument.

+

+ + + + +
+ + + + + + +
+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 RtAudioError will be thrown for an invalid device argument.

+

+ + + + +
+ + + + + + +
+int RtAudio::getDeviceCount ( + +void ) +
+
+ + + + + +
+   + + +

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

+

+

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

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

+Any device between 0 and getDeviceCount()-1 is valid. If a device is busy or otherwise unavailable, the structure member "probed" has a value of "false". The system default input and output devices are referenced by device identifier = 0. On systems which allow dynamic default device settings, the default devices are not identified by name (specific device enumerations are assigned device identifiers > 0). An RtAudioError will be thrown for an invalid device argument.

+

+ + + + +
+ + + + + + +
+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 RtAudioError will be thrown for an invalid stream identifier.

+

+ + + + +
+ + + + + + +
+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 RtAudioError will be thrown for an invalid stream identifier or if a driver error occurs.

+

+ + + + +
+ + + + + + +
+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 RtAudioError is not thrown).

+

+ + + + +
+ + + + + + +
+void RtAudio::startStream ( + +int streamID ) +
+
+ + + + + +
+   + + +

+Public method which starts a stream. +

+An RtAudioError 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 RtAudioError will be thrown for an invalid stream identifier or if a driver error occurs.

+

+ + + + +
+ + + + + + +
+void RtAudio::abortStream ( + +int streamID ) +
+
+ + + + + +
+   + + +

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

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

+

+ + + + +
+ + + + + + +
+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.

+


Member Data Documentation

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_SINT8 [static] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_SINT16 [static] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_SINT24 [static] +
+
+ + + + + +
+   + + +

+Upper 3 bytes of 32-bit integer.

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_SINT32 [static] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_FLOAT32 [static] +
+
+ + + + + +
+   + + +

+Normalized between plus/minus 1.0.

+

+ + + + +
+ + + + + +
+const RTAUDIO_FORMAT RtAudio::RTAUDIO_FLOAT64 [static] +
+
+ + + + + +
+   + + +

+Normalized between plus/minus 1.0.

+


The documentation for this class was generated from the following file: +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/classRtAudioError-members.html b/doc/html/classRtAudioError-members.html new file mode 100644 index 0000000..4fdf02b --- /dev/null +++ b/doc/html/classRtAudioError-members.html @@ -0,0 +1,40 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudioError Member List

This is the complete list of members for RtAudioError, including all inherited members. +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/classRtAudioError.html b/doc/html/classRtAudioError.html new file mode 100644 index 0000000..4fa4c33 --- /dev/null +++ b/doc/html/classRtAudioError.html @@ -0,0 +1,337 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudioError Class Reference

#include <RtAudio.h> +

+List of all members. + + + + + + + + + + + + + + + + +

Public Types

enum  TYPE {
+  WARNING, +DEBUG_WARNING, +UNSPECIFIED, +NO_DEVICES_FOUND, +
+  INVALID_DEVICE, +INVALID_STREAM, +MEMORY_ERROR, +INVALID_PARAMETER, +
+  DRIVER_ERROR, +SYSTEM_ERROR, +THREAD_ERROR +
+ }

Public Methods

 RtAudioError (const char *p, TYPE tipe=RtAudioError::UNSPECIFIED)
 The constructor. More...

virtual ~RtAudioError (void)
 The destructor. More...

virtual void printMessage (void)
 Prints "thrown" error message to stdout. More...

virtual const TYPEgetType (void)
 Returns the "thrown" error message TYPE. More...

virtual const char* getMessage (void)
 Returns the "thrown" error message string. More...


Protected Attributes

char error_message [256]
TYPE type
+


Member Enumeration Documentation

+

+ + + + +
+ + + + + +
+enum RtAudioError::TYPE +
+
+ + + + + +
+   + + +

+

+Enumeration values:
+ + + + + + + + + + + + +
WARNING +
DEBUG_WARNING +
UNSPECIFIED +
NO_DEVICES_FOUND +
INVALID_DEVICE +
INVALID_STREAM +
MEMORY_ERROR +
INVALID_PARAMETER +
DRIVER_ERROR +
SYSTEM_ERROR +
THREAD_ERROR +
+
+
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + +
+RtAudioError::RtAudioError ( + +const char * p, +
+TYPE tipe = RtAudioError::UNSPECIFIED ) +
+
+ + + + + +
+   + + +

+The constructor. +

+

+

+ + + + +
+ + + + + + +
+RtAudioError::~RtAudioError ( + +void ) [virtual] +
+
+ + + + + +
+   + + +

+The destructor. +

+

+


Member Function Documentation

+

+ + + + +
+ + + + + + +
+void RtAudioError::printMessage ( + +void ) [virtual] +
+
+ + + + + +
+   + + +

+Prints "thrown" error message to stdout. +

+

+

+ + + + +
+ + + + + + +
+const TYPE & RtAudioError::getType ( + +void ) [inline, virtual] +
+
+ + + + + +
+   + + +

+Returns the "thrown" error message TYPE. +

+

+

+ + + + +
+ + + + + + +
+const char * RtAudioError::getMessage ( + +void ) [inline, virtual] +
+
+ + + + + +
+   + + +

+Returns the "thrown" error message string. +

+

+


Member Data Documentation

+

+ + + + +
+ + + + + +
+char RtAudioError::error_message [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+TYPE RtAudioError::type [protected] +
+
+ + + + + +
+   + + +

+

+


The documentation for this class was generated from the following file: +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/doxygen.css b/doc/html/doxygen.css new file mode 100644 index 0000000..7f8e5b8 --- /dev/null +++ b/doc/html/doxygen.css @@ -0,0 +1,20 @@ +H1 { text-align: center; } +A.qindex {} +A.qindexRef {} +A.el { text-decoration: none; font-weight: bold } +A.elRef { font-weight: bold } +A.code { text-decoration: none; font-weight: normal; color: #4444ee } +A.codeRef { font-weight: normal; color: #4444ee } +DL.el { margin-left: -1cm } +DIV.fragment { width: 100%; border: none; background-color: #eeeeee } +DIV.ah { background-color: black; margin-bottom: 3; margin-top: 3 } +TD.md { background-color: #f2f2ff } +DIV.groupHeader { margin-left: 16; margin-top: 12; margin-bottom: 6; font-weight: bold } +DIV.groupText { margin-left: 16; font-style: italic; font-size: smaller } +FONT.keyword { color: #008000 } +FONT.keywordtype { color: #604020 } +FONT.keywordflow { color: #e08000 } +FONT.comment { color: #800000 } +FONT.preprocessor { color: #806020 } +FONT.stringliteral { color: #002080 } +FONT.charliteral { color: #008080 } diff --git a/doc/html/doxygen.gif b/doc/html/doxygen.gif new file mode 100644 index 0000000..192c83c Binary files /dev/null and b/doc/html/doxygen.gif differ diff --git a/doc/html/files.html b/doc/html/files.html new file mode 100644 index 0000000..a2102b2 --- /dev/null +++ b/doc/html/files.html @@ -0,0 +1,21 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio File List

Here is a list of all files with brief descriptions: +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/functions.html b/doc/html/functions.html new file mode 100644 index 0000000..861b1c0 --- /dev/null +++ b/doc/html/functions.html @@ -0,0 +1,129 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio Compound Members

+a | c | d | e | g | h | i | m | n | o | p | r | s | t | u | w | ~
+ +

+Here is a list of all class members with links to the class documentation for each member:

- a -

+ +

- c -

+ +

- d -

+ +

- e -

+ +

- g -

+ +

- h -

+ +

- i -

+ +

- m -

+ +

- n -

+ +

- o -

+ +

- p -

+ +

- r -

+ +

- s -

+ +

- t -

+ +

- u -

+ +

- w -

+ +

- ~ -

+ +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/globals.html b/doc/html/globals.html new file mode 100644 index 0000000..0137fb4 --- /dev/null +++ b/doc/html/globals.html @@ -0,0 +1,27 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio File Members

+_
+ +

+Here is a list of all file members with links to the files they belong to:

- _ -

+ +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/index.html b/doc/html/index.html new file mode 100644 index 0000000..fcf1166 --- /dev/null +++ b/doc/html/index.html @@ -0,0 +1,583 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

The RtAudio Tutorial

+

+ +

+

+ Introduction    Download    Getting Started    Error Handling    Probing Device Capabilities    Device Settings    Playback (blocking functionality)    Playback (callback functionality)    Recording    Duplex Mode    Summary of Methods    Compiling    OS Notes    Acknowledgments
+ +

+

Introduction

+ +

+RtAudio is a C++ class which provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA and OSS), SGI, and Windows operating systems. RtAudio significantly simplifies the process of interacting with computer audio hardware. It was designed with the following goals: +

+

+ +

+RtAudio incorporates the concept of audio streams, which represent audio output (playback) and/or input (recording). 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 are typically used in conjunction with graphical user interfaces (GUI). Blocking functionality is often necessary for explicit control of multiple input/output stream synchronization or when audio must be synchronized with other system events. +

+

Download

+ +

+Latest Release (22 January 2002): Version 2.0 (111 kB tar/gzipped) +

+

Getting Started

+ +

+The first thing that must be done when using RtAudio is to create an instance of the class. The default constructor RtAudio::RtAudio() scans the underlying audio system to verify that at least one device is available. RtAudio often uses C++ exceptions to report errors, necessitating try/catch blocks around most member functions. The following code example demonstrates default object construction and destruction: +

+

#include "RtAudio.h"
+
+int main()
+{
+  RtAudio *audio;
+
+  // Default RtAudio constructor
+  try {
+    audio = new RtAudio();
+  }
+  catch (RtAudioError &error) {
+    // Handle the exception here
+  }
+
+  // Clean up
+  delete audio;
+}
+

+Obviously, this example doesn't demonstrate any of the real functionality of RtAudio. However, all uses of RtAudio must begin with a constructor (either default or overloaded varieties) and must end with class destruction. Further, it is necessary that all class methods which can throw a C++ exception be called within a try/catch block. +

+

Error Handling

+ +

+RtAudio uses a C++ exception handler called RtAudioError, which is declared and defined within the RtAudio class files. The RtAudioError class is quite simple but it does allow errors to be "caught" by RtAudioError::TYPE. Almost all RtAudio methods can "throw" an RtAudioError, most typically if an invalid stream identifier is supplied to a method or a driver error occurs. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a private RtAudio method, error(), which can be modified to globally control how these messages are handled and reported. +

+

Probing Device Capabilities

+ +

+A programmer may wish to query the available audio device capabilities before deciding which to use. The following example outlines how this can be done. +

+

// probe.cpp
+
+#include <iostream.h>
+#include "RtAudio.h"
+
+int main()
+{
+  RtAudio *audio;
+
+  // Default RtAudio constructor
+  try {
+    audio = new RtAudio();
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  // Determine the number of devices available
+  int devices = audio->getDeviceCount();
+
+  // Scan through devices for various capabilities
+  RtAudio::RTAUDIO_DEVICE info;
+  for (int i=0; i<devices; i++) {
+
+    try {
+      audio->getDeviceInfo(i, &info);
+    }
+    catch (RtAudioError &error) {
+      error.printMessage();
+      break;
+    }
+
+    // Print, for example, the maximum number of output channels for each device
+    cout << "device = " << i;
+    cout << ": maximum output channels = " << info.maxOutputChannels << endl;
+  }
+
+  // Clean up
+  delete audio;
+
+  return 0;
+}
+

+The RTAUDIO_DEVICE structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device: +

+

  typedef struct {
+    char name[128];
+    DEVICE_ID id[2];                      // No value reported by getDeviceInfo().
+    bool probed;                          // true if the device probe was successful.
+    int maxOutputChannels;
+    int maxInputChannels;
+    int maxDuplexChannels;
+    int minOutputChannels;
+    int minInputChannels;
+    int minDuplexChannels;
+    bool hasDuplexSupport;                // true if duplex supported
+    int nSampleRates;                     // Number of discrete rates, or -1 if range supported.
+    double sampleRates[MAX_SAMPLE_RATES]; // Supported sample rates, or {min, max} if range.
+    RTAUDIO_FORMAT nativeFormats;
+  } RTAUDIO_DEVICE;
+

+The following data formats are defined and fully supported by RtAudio: +

+

  typedef unsigned long RTAUDIO_FORMAT;
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT8;   // Signed 8-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT16;  // Signed 16-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT24;  // Signed 24-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT32;  // Signed 32-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT32; // 32-bit float
+  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT64; // 64-bit double
+

+The nativeFormats member of the RtAudio::RTAUDIO_DEVICE structure is a bit mask of the above formats which are natively supported by the device. However, RtAudio will automatically provide format conversion if a particular format is not natively supported. When the probed member of the RTAUDIO_DEVICE structure is false, the remaining structure members are likely unknown and the device is probably unusable. +

+In general, the user need not be concerned with the minimum channel values reported in the RTAUDIO_DEVICE structure. While some audio devices may require a minimum channel value > 1, RtAudio will provide automatic channel number compensation when the number of channels set by the user is less than that required by the device. Channel compensation is NOT possible when the number of channels set by the user is greater than that supported by the device. +

+It should be noted that the capabilities reported by a device driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. +

+

Device Settings

+ +

+The next step in using RtAudio is to open a stream with a particular set of device settings. +

+

#include "RtAudio.h"
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Instantiate RtAudio and open a stream within a try/catch block
+  try {
+    audio = new RtAudio();
+    stream = audio->openStream(device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
+                               sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  // Clean up
+  delete audio;
+
+  return 0;
+}
+

+The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. When successful, a stream identifier is returned. In this case, we attempt to open a playback stream on device 0 with two channels, 32-bit floating point data, a sample rate of 44100 Hz, a frame rate of 256 sample frames per read/write, and 4 internal device buffers. When device = 0, RtAudio first attempts to open the default audio device with the given parameters. If that attempt fails, an attempt is made to find a device or set of devices which will meet the given parameters. If all attempts are unsuccessful, an RtAudioError is thrown. When a non-zero device value is specified, an attempt is made to open that device only. +

+RtAudio provides four signed integer and two floating point data formats which can be specified using the RtAudio::RTAUDIO_FORMAT parameter values mentioned earlier. If the opened device does not natively support the given format, RtAudio will automatically perform the necessary data format conversion. +

+Buffer sizes in RtAudio are ALWAYS given in sample frame units. For example, if you open an output stream with 4 channels and set bufferSize to 512, you will have to write 2048 samples of data to the output buffer within your callback or between calls to RtAudio::tickStream(). In this case, a single sample frame of data contains 4 samples of data. +

+The bufferSize parameter specifies the desired number of sample frames which will be written to and/or read from a device per write/read operation. The nBuffers parameter is used in setting the underlying device buffer parameters. Both the bufferSize and nBuffers parameters can be used to control stream latency though there is no guarantee that the passed values will be those used by a device. In general, lower values for both parameters will produce less latency but perhaps less robust performance. Both parameters can be specified with values of zero, in which case the smallest allowable values will be used. The bufferSize parameter is passed as a pointer and the actual value used by the stream is set during the device setup procedure. bufferSize values should be a power of two. Optimal and allowable buffer values tend to vary between systems and devices. Check the OS Notes section for general guidelines. +

+As noted earlier, the device capabilities reported by a driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. Because of this, RtAudio does not attempt to query a device's capabilities or use previously reported values when opening a device. Instead, RtAudio simply attempts to set the given parameters on a specified device and then checks whether the setup is successful or not. +

+

Playback (blocking functionality)

+ +

+Once the device is open for playback, there are only a few final steps necessary for realtime audio output. We'll first provide an example (blocking functionality) and then discuss the details. +

+

// playback.cpp
+
+#include "RtAudio.h"
+
+int main()
+{
+  int count;
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  float *buffer;
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Get a pointer to the stream buffer
+    buffer = (float *) audio->getStreamBuffer(stream);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  // An example loop which runs for about 40000 sample frames
+  count = 0;
+  while (count < 40000) {
+    // Generate your samples and fill the buffer with buffer_size sample frames of data
+    ...
+
+    // Trigger the output of the data buffer
+    try {
+      audio->tickStream(stream);
+    }
+    catch (RtAudioError &error) {
+      error.printMessage();
+      goto cleanup;
+    }
+
+    count += buffer_size;
+  }
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+

+The first thing to notice in this example is that we attempt to open a stream during class instantiation with an overloaded constructor. This constructor simply combines the functionality of the default constructor, used earlier, and the RtAudio::openStream() method. Again, we have specified a device value of 0, indicating that the default or first available device meeting the given parameters should be used. The integer identifier of the opened stream is returned via the stream pointer value. An attempt is made to open the stream with the specified bufferSize value. However, it is possible that the device will not accept this value, in which case the closest allowable size is used and returned via the pointer value. The constructor can fail if no available devices are found, or a memory allocation or device driver error occurs. Note that you should not call the RtAudio destructor if an exception is thrown during instantiation. +

+Because RtAudio can be used to simultaneously control more than a single stream, it is necessary that the stream identifier be provided to nearly all public methods. Assuming the constructor is successful, it is necessary to get a pointer to the buffer, provided by RtAudio, for use in feeding data to/from the opened stream. Note that the user should NOT attempt to deallocate the stream buffer memory ... memory management for the stream buffer will be automatically controlled by RtAudio. After starting the stream with RtAudio::startStream(), one simply fills that buffer, which is of length equal to the returned bufferSize value, with interleaved audio data (in the specified format) for playback. Finally, a call to the RtAudio::tickStream() routine triggers a blocking write call for the stream. +

+In general, one should call the RtAudio::stopStream() and RtAudio::closeStream() methods after finishing with a stream. However, both methods will implicitly be called during object destruction if necessary. +

+

Playback (callback functionality)

+ +

+The primary difference in using RtAudio with callback functionality involves the creation of a user-defined callback function. Here is an example which produces a sawtooth waveform for playback. +

+

#include <iostream.h>
+#include "RtAudio.h"
+
+// Two-channel sawtooth wave generator.
+int sawtooth(char *buffer, int buffer_size, void *data)
+{
+  int i, j;
+  double *my_buffer = (double *) buffer;
+  double *my_data = (double *) data;
+
+  // Write interleaved audio data.
+  for (i=0; i<buffer_size; i++) {
+    for (j=0; j<2; j++) {
+      *my_buffer++ = my_data[j];
+
+      my_data[j] += 0.005 * (j+1+(j*0.1));
+      if (my_data[j] >= 1.0) my_data[j] -= 2.0;
+    }
+  }
+
+  return 0;
+}
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  double data[2];
+  char input;
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT64,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Set the stream callback function
+    audio->setStreamCallback(stream, &sawtooth, (void *)data);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  cout << "\nPlaying ... press <enter> to quit.\n";
+  cin.get(input);
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+

+After opening the device in exactly the same way as the previous example (except with a data format change), we must set our callback function for the stream using RtAudio::setStreamCallback(). This method will spawn a new process (or thread) which automatically calls the callback function when more data is needed. Note that the callback function is called only when the stream is "running" (between calls to the RtAudio::startStream() and RtAudio::stopStream() methods). The last argument to RtAudio::setStreamCallback() is a pointer to arbitrary data that you wish to access from within your callback function. +

+In this example, we stop the stream with an explicit call to RtAudio::stopStream(). When using callback functionality, it is also possible to stop a stream by returning a non-zero value from the callback function. +

+Once set with RtAudio::setStreamCallback, the callback process will continue to run for the life of the stream (until the stream is closed with RtAudio::closeStream() or the RtAudio instance is deleted). It is possible to disassociate a callback function and cancel its process for an open stream using the RtAudio::cancelStreamCallback() method. The stream can then be used with blocking functionality or a new callback can be associated with it. +

+

Recording

+ +

+Using RtAudio for audio input is almost identical to the way it is used for playback. Here's the blocking playback example rewritten for recording: +

+

// record.cpp
+
+#include "RtAudio.h"
+
+int main()
+{
+  int count;
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  float *buffer;
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Instantiate RtAudio and open a stream.
+  try {
+    audio = new RtAudio(&stream, 0, 0, device, channels,
+                        RtAudio::RTAUDIO_FLOAT32, sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Get a pointer to the stream buffer
+    buffer = (float *) audio->getStreamBuffer(stream);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  // An example loop which runs for about 40000 sample frames
+  count = 0;
+  while (count < 40000) {
+
+    // Read a buffer of data
+    try {
+      audio->tickStream(stream);
+    }
+    catch (RtAudioError &error) {
+      error.printMessage();
+      goto cleanup;
+    }
+
+    // Process the input samples (buffer_size sample frames) that were read
+    ...
+
+    count += buffer_size;
+  }
+
+  try {
+    // Stop the stream
+    audio->stopStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+

+In this example, the stream was opened for recording with a non-zero inputChannels value. The only other difference between this example and that for playback involves the order of data processing in the loop, where it is necessary to first read a buffer of input data before manipulating it. +

+

Duplex Mode

+ +

+Finally, it is easy to use RtAudio for simultaneous audio input/output, or duplex operation. In this example, we use a callback function and pass our recorded data directly through for playback. +

+

// duplex.cpp
+
+#include <iostream.h>
+#include "RtAudio.h"
+
+// Pass-through function.
+int pass(char *buffer, int buffer_size, void *)
+{
+  // Surprise!!  We do nothing to pass the data through.
+  return 0;
+}
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  double data[2];
+  char input;
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, device, channels, RtAudio::RTAUDIO_FLOAT64,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Set the stream callback function
+    audio->setStreamCallback(stream, &pass, NULL);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  cout << "\nRunning duplex ... press <enter> to quit.\n";
+  cin.get(input);
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtAudioError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+

+When an RtAudio stream is running in duplex mode (nonzero input AND output channels), the audio write (playback) operation always occurs before the audio read (record) operation. This sequence allows the use of a single buffer to store both output and input data. +

+As we see with this example, the write-read sequence of operations does not preclude the use of RtAudio in situations where input data is first processed and then output through a duplex stream. When the stream buffer is first allocated, it is initialized with zeros, which produces no audible result when output to the device. In this example, anything recorded by the audio stream input will be played out during the next round of audio processing. +

+Note that duplex operation can also be achieved by opening one output stream and one input stream using the same or different devices. However, there may be timing problems when attempting to use two different devices, due to possible device clock variations. This becomes even more difficult to achieve using two separate callback streams because it is not possible to explicitly control the calling order of the callback functions. +

+

Summary of Methods

+ +

+The following is short summary of public methods (not including constructors and the destructor) provided by RtAudio: +

+

+ +

+

Compiling

+ +

+In order to compile RtAudio for a specific OS and audio API, it is necessary to supply the appropriate preprocessor definition and library within the compiler statement: +

+ +

+ + + + +
OS: Audio API: Preprocessor Definition: Library: Example Compiler Statement:
Linux ALSA __LINUX_ALSA_ libasound, libpthread g++ -Wall -D__LINUX_ALSA_ -o probe probe.cpp RtAudio.cpp -lasound -lpthread
Linux OSS __LINUX_OSS_ libpthread g++ -Wall -D__LINUX_OSS_ -o probe probe.cpp RtAudio.cpp -lpthread
Irix AL __IRIX_AL_ libaudio, libpthread CC -Wall -D__IRIX_AL_ -o probe probe.cpp RtAudio.cpp -laudio -lpthread
Windows Direct Sound __WINDOWS_DS_ dsound.lib (ver. 5.0 or higher), multithreaded compiler specific
+ +

+ +

+The example compiler statements above could be used to compile the probe.cpp example file, assuming that probe.cpp, RtAudio.h, and RtAudio.cpp all exist in the same directory. +

+

OS Notes

+ +

+RtAudio is designed to provide a common API across the various supported operating systems and audio libraries. Despite that, however, some issues need to be mentioned with regard to each. +

+

Linux:

+ +

+RtAudio for Linux was developed under Redhat distributions 7.0 - 7.2. Two different audio APIs are supported on Linux platforms: OSS and ALSA. The OSS API has existed for at least 6 years and the Linux kernel is distributed with free versions of OSS audio drivers. Therefore, a generic Linux system is most likely to have OSS support. The ALSA API is relatively new and at this time is not part of the Linux kernel distribution. Work is in progress to make ALSA part of the 2.5 development kernel series. Despite that, the ALSA API offers significantly better functionality than the OSS API. RtAudio provides support for the 0.9 and higher versions of ALSA. Input/output latency on the order of 15-20 milliseconds can typically be achieved under both OSS or ALSA by fine-tuning the RtAudio buffer parameters (without kernel modifications). Latencies on the order of 5 milliseconds or less can be achieved using a low-latency kernel patch and increasing FIFO scheduling priority. The pthread library, which is used for callback functionality, is a standard component of all Linux distributions. +

+The ALSA library includes OSS emulation support. That means that you can run programs compiled for the OSS API even when using the ALSA drivers and library. It should be noted however that OSS emulation under ALSA is not perfect. Specifically, channel number queries seem to consistently produce invalid results. While OSS emulation is successful for the majority of RtAudio tests, it is recommended that the native ALSA implementation of RtAudio be used on systems which have ALSA drivers installed. +

+The ALSA implementation of RtAudio makes no use of the ALSA "plug" interface. All necessary data format conversions, channel compensation, deinterleaving, and byte-swapping is handled by internal RtAudio routines. +

+

Irix (SGI):

+ +

+The Irix version of RtAudio was written and tested on an SGI Indy running Irix version 6.5 and the newer "al" audio library. RtAudio does not compile under Irix version 6.3 because the C++ compiler is too old. Despite the relatively slow speed of the Indy, RtAudio was found to behave quite well and input/output latency was very good. No problems were found with respect to using the pthread library. +

+

Windows:

+ +

+RtAudio under Windows is written using the DirectSound API. In order to compile RtAudio under Windows, you must have the header and source files for DirectSound version 0.5 or higher. As far as I know, you cannot compile RtAudio for Windows NT because there is not sufficient DirectSound support. Audio output latency with DirectSound can be reasonably good (on the order of 20 milliseconds). On the other hand, input audio latency tends to be terrible (100 milliseconds or more). Further, DirectSound drivers tend to crash easily when experimenting with buffer parameters. On my system, I found it necessary to use values around nBuffers = 8 and bufferSize = 512 to avoid crashing my system. RtAudio was developed with Visual C++ version 6.0. I was forced in several instances to modify code in order to get it to compile under the non-standard version of C++ that Microsoft so unprofessionally implemented. We can only hope that the developers of Visual C++ 7.0 will have time to read the C++ standard. +

+

Acknowledgments

+ +

+The RtAudio API incorporates many of the concepts developed in the PortAudio project by Phil Burk and Ross Bencina. Early development also incorporated ideas from Bill Schottstaedt's sndlib. The CCRMA SoundWire group provided valuable feedback during the API proposal stages. +

+RtAudio was slowly developed over the course of many months while in residence at the Institut Universitari de L'Audiovisual (IUA) in Barcelona, Spain, the Laboratory of Acoustics and Audio Signal Processing at the Helsinki University of Technology, Finland, and the Center for Computer Research in Music and Acoustics (CCRMA) at Stanford University. This work was supported in part by the United States Air Force Office of Scientific Research (grant #F49620-99-1-0293). +

+These documentation files were generated using doxygen by Dimitri van Heesch. +

+


+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/structRtAudio_1_1RTAUDIO__DEVICE-members.html b/doc/html/structRtAudio_1_1RTAUDIO__DEVICE-members.html new file mode 100644 index 0000000..916fbf3 --- /dev/null +++ b/doc/html/structRtAudio_1_1RTAUDIO__DEVICE-members.html @@ -0,0 +1,34 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio::RTAUDIO_DEVICE Member List

This is the complete list of members for RtAudio::RTAUDIO_DEVICE, including all inherited members. +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/structRtAudio_1_1RTAUDIO__DEVICE.html b/doc/html/structRtAudio_1_1RTAUDIO__DEVICE.html new file mode 100644 index 0000000..dd69668 --- /dev/null +++ b/doc/html/structRtAudio_1_1RTAUDIO__DEVICE.html @@ -0,0 +1,378 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

RtAudio::RTAUDIO_DEVICE Struct Reference

#include <RtAudio.h> +

+List of all members. + + + + + + + + + + + + + + +

Public Attributes

char name [128]
DEVICE_ID id [2]
bool probed
int maxOutputChannels
int maxInputChannels
int maxDuplexChannels
int minOutputChannels
int minInputChannels
int minDuplexChannels
bool hasDuplexSupport
int nSampleRates
int sampleRates [MAX_SAMPLE_RATES]
RTAUDIO_FORMAT nativeFormats
+


Member Data Documentation

+

+ + + + +
+ + + + + +
+char RtAudio::RTAUDIO_DEVICE::name +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+DEVICE_ID RtAudio::RTAUDIO_DEVICE::id +
+
+ + + + + +
+   + + +

+No value reported by getDeviceInfo().

+

+ + + + +
+ + + + + +
+bool RtAudio::RTAUDIO_DEVICE::probed +
+
+ + + + + +
+   + + +

+true if the device capabilities were successfully probed.

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::maxOutputChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::maxInputChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::maxDuplexChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::minOutputChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::minInputChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::minDuplexChannels +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + +
+bool RtAudio::RTAUDIO_DEVICE::hasDuplexSupport +
+
+ + + + + +
+   + + +

+true if device supports duplex mode.

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::nSampleRates +
+
+ + + + + +
+   + + +

+Number of discrete rates or -1 if range supported.

+

+ + + + +
+ + + + + +
+int RtAudio::RTAUDIO_DEVICE::sampleRates +
+
+ + + + + +
+   + + +

+Supported rates or (min, max) if range.

+

+ + + + +
+ + + + + +
+RTAUDIO_FORMAT RtAudio::RTAUDIO_DEVICE::nativeFormats +
+
+ + + + + +
+   + + +

+Bit mask of supported data formats.

+


The documentation for this struct was generated from the following file: +
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + diff --git a/doc/html/tutorial_8txt.html b/doc/html/tutorial_8txt.html new file mode 100644 index 0000000..87ca0fe --- /dev/null +++ b/doc/html/tutorial_8txt.html @@ -0,0 +1,21 @@ + + +The RtAudio Tutorial + + + +
+Tutorial   Class/Enum List   File List   Compound Members  
+
+ +

tutorial.txt File Reference

+
+
+ +
+ ©2001-2002 CCRMA, Stanford University. All Rights Reserved.
+ Maintained by Gary P. Scavone, gary@ccrma.stanford.edu

+

+ + + -- cgit v1.2.3