diff --git a/doc/html/RtAudio_8h-source.html b/doc/html/RtAudio_8h-source.html index 52b8224..4d853be 100644 --- a/doc/html/RtAudio_8h-source.html +++ b/doc/html/RtAudio_8h-source.html @@ -11,7 +11,7 @@

RtAudio.h

00001 /************************************************************************/
 00038 /************************************************************************/
 00039 
-00040 // RtAudio: Version 3.0.2 (14 October 2005)
+00040 // RtAudio: Version 3.0.3 (18 November 2005)
 00041 
 00042 #ifndef __RTAUDIO_H
 00043 #define __RTAUDIO_H
@@ -352,264 +352,265 @@
 00552   private:
 00553 
 00554   void initialize(void);
-00555   void probeDeviceInfo( RtApiDevice *info );
-00556   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00557                         int sampleRate, RtAudioFormat format,
-00558                         int *bufferSize, int numberOfBuffers );
-00559 };
-00560 
-00561 #endif
-00562 
-00563 #if defined(__LINUX_JACK__)
-00564 
-00565 class RtApiJack: public RtApi
-00566 {
-00567 public:
-00568 
-00569   RtApiJack();
-00570   ~RtApiJack();
-00571   void tickStream();
-00572   void closeStream();
-00573   void startStream();
-00574   void stopStream();
-00575   void abortStream();
-00576   void setStreamCallback( RtAudioCallback callback, void *userData );
-00577   void cancelStreamCallback();
-00578   // This function is intended for internal use only.  It must be
-00579   // public because it is called by the internal callback handler,
-00580   // which is not a member of RtAudio.  External use of this function
-00581   // will most likely produce highly undesireable results!
-00582   void callbackEvent( unsigned long nframes );
-00583 
-00584   private:
-00585 
-00586   void initialize(void);
-00587   void probeDeviceInfo( RtApiDevice *info );
-00588   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00589                         int sampleRate, RtAudioFormat format,
-00590                         int *bufferSize, int numberOfBuffers );
-00591 };
-00592 
-00593 #endif
-00594 
-00595 #if defined(__LINUX_OSS__)
-00596 
-00597 class RtApiOss: public RtApi
-00598 {
-00599 public:
-00600 
-00601   RtApiOss();
-00602   ~RtApiOss();
-00603   void tickStream();
-00604   void closeStream();
-00605   void startStream();
-00606   void stopStream();
-00607   void abortStream();
-00608   int streamWillBlock();
-00609   void setStreamCallback( RtAudioCallback callback, void *userData );
-00610   void cancelStreamCallback();
-00611 
-00612   private:
-00613 
-00614   void initialize(void);
-00615   void probeDeviceInfo( RtApiDevice *info );
-00616   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00617                         int sampleRate, RtAudioFormat format,
-00618                         int *bufferSize, int numberOfBuffers );
-00619 };
-00620 
-00621 #endif
-00622 
-00623 #if defined(__MACOSX_CORE__)
-00624 
-00625 #include <CoreAudio/AudioHardware.h>
-00626 
-00627 class RtApiCore: public RtApi
-00628 {
-00629 public:
-00630 
-00631   RtApiCore();
-00632   ~RtApiCore();
-00633   int getDefaultOutputDevice(void);
-00634   int getDefaultInputDevice(void);
-00635   void tickStream();
-00636   void closeStream();
-00637   void startStream();
-00638   void stopStream();
-00639   void abortStream();
-00640   void setStreamCallback( RtAudioCallback callback, void *userData );
-00641   void cancelStreamCallback();
-00642 
-00643   // This function is intended for internal use only.  It must be
-00644   // public because it is called by the internal callback handler,
-00645   // which is not a member of RtAudio.  External use of this function
-00646   // will most likely produce highly undesireable results!
-00647   void callbackEvent( AudioDeviceID deviceId, void *inData, void *outData );
-00648 
-00649   private:
-00650 
-00651   void initialize(void);
-00652   void probeDeviceInfo( RtApiDevice *info );
-00653   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00654                         int sampleRate, RtAudioFormat format,
-00655                         int *bufferSize, int numberOfBuffers );
-00656 };
-00657 
-00658 #endif
-00659 
-00660 #if defined(__WINDOWS_DS__)
-00661 
-00662 class RtApiDs: public RtApi
-00663 {
-00664 public:
-00665 
-00666   RtApiDs();
-00667   ~RtApiDs();
-00668   int getDefaultOutputDevice(void);
-00669   int getDefaultInputDevice(void);
-00670   void tickStream();
-00671   void closeStream();
-00672   void startStream();
-00673   void stopStream();
-00674   void abortStream();
-00675   int streamWillBlock();
-00676   void setStreamCallback( RtAudioCallback callback, void *userData );
-00677   void cancelStreamCallback();
-00678 
-00679   public:
-00680   // \brief Internal structure that provide debug information on the state of a running DSound device.
-00681   struct RtDsStatistics {
-00682     // \brief Sample Rate.
-00683     long sampleRate;
-00684     // \brief The size of one sample * number of channels on the input device.
-00685     int inputFrameSize; 
-00686     // \brief The size of one sample * number of channels on the output device.
-00687     int outputFrameSize; 
-00688     /* \brief The number of times the read pointer had to be adjusted to avoid reading from an unsafe buffer position.
-00689      *
-00690      * This field is only used when running in DUPLEX mode. INPUT mode devices just wait until the data is 
-00691      * available.
-00692      */
-00693     int numberOfReadOverruns;
-00694     // \brief The number of times the write pointer had to be adjusted to avoid writing in an unsafe buffer position.
-00695     int numberOfWriteUnderruns;
-00696     // \brief Number of bytes by attribute to buffer configuration by which writing must lead the current write pointer.
-00697     int writeDeviceBufferLeadBytes;
-00698     // \brief Number of bytes by attributable to the device driver by which writing must lead the current write pointer on this output device.
-00699     unsigned long writeDeviceSafeLeadBytes;
-00700     // \brief Number of bytes by which reading must trail the current read pointer on this input device.
-00701     unsigned long readDeviceSafeLeadBytes; 
-00702     /* \brief Estimated latency in seconds. 
-00703     *
-00704     * For INPUT mode devices, based the latency of the device's safe read pointer, plus one buffer's
-00705     * worth of additional latency.
-00706     *
-00707     * For OUTPUT mode devices, the latency of the device's safe write pointer, plus N buffers of 
-00708     * additional buffer latency.
-00709     *
-00710     * For DUPLEX devices, the sum of latencies for both input and output devices. DUPLEX devices
-00711     * also back off the read pointers an additional amount in order to maintain synchronization 
-00712     * between out-of-phase read and write pointers. This time is also included.
-00713     *
-00714     * Note that most software packages report latency between the safe write pointer 
-00715     * and the software lead pointer, excluding the hardware device's safe write pointer 
-00716     * latency. Figures of 1 or 2ms of latency on Windows audio devices are invariably of this type.
-00717     * The reality is that hardware devices often have latencies of 30ms or more (often much 
-00718     * higher for duplex operation).
-00719     */
-00720 
-00721     double latency;
-00722   };
-00723   // \brief Report on the current state of a running DSound device.
-00724   static RtDsStatistics getDsStatistics();
-00725 
-00726   private:
-00727 
-00728   void initialize(void);
-00729   void probeDeviceInfo( RtApiDevice *info );
-00730   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00731                         int sampleRate, RtAudioFormat format,
-00732                         int *bufferSize, int numberOfBuffers );
-00733 
-00734   bool coInitialized;
-00735   bool buffersRolling;
-00736   long duplexPrerollBytes;
-00737   static RtDsStatistics statistics;
-00738 
-00739 };
-00740 
-00741 #endif
-00742 
-00743 #if defined(__WINDOWS_ASIO__)
-00744 
-00745 class RtApiAsio: public RtApi
-00746 {
-00747 public:
-00748 
-00749   RtApiAsio();
-00750   ~RtApiAsio();
-00751   void tickStream();
-00752   void closeStream();
-00753   void startStream();
-00754   void stopStream();
-00755   void abortStream();
-00756   void setStreamCallback( RtAudioCallback callback, void *userData );
-00757   void cancelStreamCallback();
-00758 
-00759   // This function is intended for internal use only.  It must be
-00760   // public because it is called by the internal callback handler,
-00761   // which is not a member of RtAudio.  External use of this function
-00762   // will most likely produce highly undesireable results!
-00763   void callbackEvent( long bufferIndex );
-00764 
-00765   private:
-00766 
-00767   void initialize(void);
-00768   void probeDeviceInfo( RtApiDevice *info );
-00769   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00770                         int sampleRate, RtAudioFormat format,
-00771                         int *bufferSize, int numberOfBuffers );
-00772 
-00773   bool coInitialized;
-00774 
-00775 };
-00776 
-00777 #endif
-00778 
-00779 #if defined(__IRIX_AL__)
-00780 
-00781 class RtApiAl: public RtApi
-00782 {
-00783 public:
-00784 
-00785   RtApiAl();
-00786   ~RtApiAl();
-00787   int getDefaultOutputDevice(void);
-00788   int getDefaultInputDevice(void);
-00789   void tickStream();
-00790   void closeStream();
-00791   void startStream();
-00792   void stopStream();
-00793   void abortStream();
-00794   int streamWillBlock();
-00795   void setStreamCallback( RtAudioCallback callback, void *userData );
-00796   void cancelStreamCallback();
-00797 
-00798   private:
-00799 
-00800   void initialize(void);
-00801   void probeDeviceInfo( RtApiDevice *info );
-00802   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
-00803                         int sampleRate, RtAudioFormat format,
-00804                         int *bufferSize, int numberOfBuffers );
-00805 };
-00806 
-00807 #endif
-00808 
-00809 // Define the following flag to have extra information spewed to stderr.
-00810 //#define __RTAUDIO_DEBUG__
-00811 
-00812 #endif
+00555   bool primeOutputBuffer();
+00556   void probeDeviceInfo( RtApiDevice *info );
+00557   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00558                         int sampleRate, RtAudioFormat format,
+00559                         int *bufferSize, int numberOfBuffers );
+00560 };
+00561 
+00562 #endif
+00563 
+00564 #if defined(__LINUX_JACK__)
+00565 
+00566 class RtApiJack: public RtApi
+00567 {
+00568 public:
+00569 
+00570   RtApiJack();
+00571   ~RtApiJack();
+00572   void tickStream();
+00573   void closeStream();
+00574   void startStream();
+00575   void stopStream();
+00576   void abortStream();
+00577   void setStreamCallback( RtAudioCallback callback, void *userData );
+00578   void cancelStreamCallback();
+00579   // This function is intended for internal use only.  It must be
+00580   // public because it is called by the internal callback handler,
+00581   // which is not a member of RtAudio.  External use of this function
+00582   // will most likely produce highly undesireable results!
+00583   void callbackEvent( unsigned long nframes );
+00584 
+00585   private:
+00586 
+00587   void initialize(void);
+00588   void probeDeviceInfo( RtApiDevice *info );
+00589   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00590                         int sampleRate, RtAudioFormat format,
+00591                         int *bufferSize, int numberOfBuffers );
+00592 };
+00593 
+00594 #endif
+00595 
+00596 #if defined(__LINUX_OSS__)
+00597 
+00598 class RtApiOss: public RtApi
+00599 {
+00600 public:
+00601 
+00602   RtApiOss();
+00603   ~RtApiOss();
+00604   void tickStream();
+00605   void closeStream();
+00606   void startStream();
+00607   void stopStream();
+00608   void abortStream();
+00609   int streamWillBlock();
+00610   void setStreamCallback( RtAudioCallback callback, void *userData );
+00611   void cancelStreamCallback();
+00612 
+00613   private:
+00614 
+00615   void initialize(void);
+00616   void probeDeviceInfo( RtApiDevice *info );
+00617   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00618                         int sampleRate, RtAudioFormat format,
+00619                         int *bufferSize, int numberOfBuffers );
+00620 };
+00621 
+00622 #endif
+00623 
+00624 #if defined(__MACOSX_CORE__)
+00625 
+00626 #include <CoreAudio/AudioHardware.h>
+00627 
+00628 class RtApiCore: public RtApi
+00629 {
+00630 public:
+00631 
+00632   RtApiCore();
+00633   ~RtApiCore();
+00634   int getDefaultOutputDevice(void);
+00635   int getDefaultInputDevice(void);
+00636   void tickStream();
+00637   void closeStream();
+00638   void startStream();
+00639   void stopStream();
+00640   void abortStream();
+00641   void setStreamCallback( RtAudioCallback callback, void *userData );
+00642   void cancelStreamCallback();
+00643 
+00644   // This function is intended for internal use only.  It must be
+00645   // public because it is called by the internal callback handler,
+00646   // which is not a member of RtAudio.  External use of this function
+00647   // will most likely produce highly undesireable results!
+00648   void callbackEvent( AudioDeviceID deviceId, void *inData, void *outData );
+00649 
+00650   private:
+00651 
+00652   void initialize(void);
+00653   void probeDeviceInfo( RtApiDevice *info );
+00654   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00655                         int sampleRate, RtAudioFormat format,
+00656                         int *bufferSize, int numberOfBuffers );
+00657 };
+00658 
+00659 #endif
+00660 
+00661 #if defined(__WINDOWS_DS__)
+00662 
+00663 class RtApiDs: public RtApi
+00664 {
+00665 public:
+00666 
+00667   RtApiDs();
+00668   ~RtApiDs();
+00669   int getDefaultOutputDevice(void);
+00670   int getDefaultInputDevice(void);
+00671   void tickStream();
+00672   void closeStream();
+00673   void startStream();
+00674   void stopStream();
+00675   void abortStream();
+00676   int streamWillBlock();
+00677   void setStreamCallback( RtAudioCallback callback, void *userData );
+00678   void cancelStreamCallback();
+00679 
+00680   public:
+00681   // \brief Internal structure that provide debug information on the state of a running DSound device.
+00682   struct RtDsStatistics {
+00683     // \brief Sample Rate.
+00684     long sampleRate;
+00685     // \brief The size of one sample * number of channels on the input device.
+00686     int inputFrameSize; 
+00687     // \brief The size of one sample * number of channels on the output device.
+00688     int outputFrameSize; 
+00689     /* \brief The number of times the read pointer had to be adjusted to avoid reading from an unsafe buffer position.
+00690      *
+00691      * This field is only used when running in DUPLEX mode. INPUT mode devices just wait until the data is 
+00692      * available.
+00693      */
+00694     int numberOfReadOverruns;
+00695     // \brief The number of times the write pointer had to be adjusted to avoid writing in an unsafe buffer position.
+00696     int numberOfWriteUnderruns;
+00697     // \brief Number of bytes by attribute to buffer configuration by which writing must lead the current write pointer.
+00698     int writeDeviceBufferLeadBytes;
+00699     // \brief Number of bytes by attributable to the device driver by which writing must lead the current write pointer on this output device.
+00700     unsigned long writeDeviceSafeLeadBytes;
+00701     // \brief Number of bytes by which reading must trail the current read pointer on this input device.
+00702     unsigned long readDeviceSafeLeadBytes; 
+00703     /* \brief Estimated latency in seconds. 
+00704     *
+00705     * For INPUT mode devices, based the latency of the device's safe read pointer, plus one buffer's
+00706     * worth of additional latency.
+00707     *
+00708     * For OUTPUT mode devices, the latency of the device's safe write pointer, plus N buffers of 
+00709     * additional buffer latency.
+00710     *
+00711     * For DUPLEX devices, the sum of latencies for both input and output devices. DUPLEX devices
+00712     * also back off the read pointers an additional amount in order to maintain synchronization 
+00713     * between out-of-phase read and write pointers. This time is also included.
+00714     *
+00715     * Note that most software packages report latency between the safe write pointer 
+00716     * and the software lead pointer, excluding the hardware device's safe write pointer 
+00717     * latency. Figures of 1 or 2ms of latency on Windows audio devices are invariably of this type.
+00718     * The reality is that hardware devices often have latencies of 30ms or more (often much 
+00719     * higher for duplex operation).
+00720     */
+00721 
+00722     double latency;
+00723   };
+00724   // \brief Report on the current state of a running DSound device.
+00725   static RtDsStatistics getDsStatistics();
+00726 
+00727   private:
+00728 
+00729   void initialize(void);
+00730   void probeDeviceInfo( RtApiDevice *info );
+00731   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00732                         int sampleRate, RtAudioFormat format,
+00733                         int *bufferSize, int numberOfBuffers );
+00734 
+00735   bool coInitialized;
+00736   bool buffersRolling;
+00737   long duplexPrerollBytes;
+00738   static RtDsStatistics statistics;
+00739 
+00740 };
+00741 
+00742 #endif
+00743 
+00744 #if defined(__WINDOWS_ASIO__)
+00745 
+00746 class RtApiAsio: public RtApi
+00747 {
+00748 public:
+00749 
+00750   RtApiAsio();
+00751   ~RtApiAsio();
+00752   void tickStream();
+00753   void closeStream();
+00754   void startStream();
+00755   void stopStream();
+00756   void abortStream();
+00757   void setStreamCallback( RtAudioCallback callback, void *userData );
+00758   void cancelStreamCallback();
+00759 
+00760   // This function is intended for internal use only.  It must be
+00761   // public because it is called by the internal callback handler,
+00762   // which is not a member of RtAudio.  External use of this function
+00763   // will most likely produce highly undesireable results!
+00764   void callbackEvent( long bufferIndex );
+00765 
+00766   private:
+00767 
+00768   void initialize(void);
+00769   void probeDeviceInfo( RtApiDevice *info );
+00770   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00771                         int sampleRate, RtAudioFormat format,
+00772                         int *bufferSize, int numberOfBuffers );
+00773 
+00774   bool coInitialized;
+00775 
+00776 };
+00777 
+00778 #endif
+00779 
+00780 #if defined(__IRIX_AL__)
+00781 
+00782 class RtApiAl: public RtApi
+00783 {
+00784 public:
+00785 
+00786   RtApiAl();
+00787   ~RtApiAl();
+00788   int getDefaultOutputDevice(void);
+00789   int getDefaultInputDevice(void);
+00790   void tickStream();
+00791   void closeStream();
+00792   void startStream();
+00793   void stopStream();
+00794   void abortStream();
+00795   int streamWillBlock();
+00796   void setStreamCallback( RtAudioCallback callback, void *userData );
+00797   void cancelStreamCallback();
+00798 
+00799   private:
+00800 
+00801   void initialize(void);
+00802   void probeDeviceInfo( RtApiDevice *info );
+00803   bool probeDeviceOpen( int device, StreamMode mode, int channels, 
+00804                         int sampleRate, RtAudioFormat format,
+00805                         int *bufferSize, int numberOfBuffers );
+00806 };
+00807 
+00808 #endif
+00809 
+00810 // Define the following flag to have extra information spewed to stderr.
+00811 //#define __RTAUDIO_DEBUG__
+00812 
+00813 #endif
 

diff --git a/doc/html/index.html b/doc/html/index.html index 4774192..8cc5c27 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -43,7 +43,7 @@ Several API changes have been made in version 3.0 of RtAudio::getDeviceInfo() function was modified to return a globally defined RtAudioDeviceInfo structure. This structure is a simplified version of the previous RTAUDIO_DEVICE structure. In addition, the RTAUDIO_FORMAT structure was renamed RtAudioFormat and defined globally within RtAudio.h. These changes were made for clarity and to better conform with standard C++ programming practices.

The RtError class declaration and definition have been extracted to a separate file (RtError.h). This was done in preparation for a new release of the RtMidi class (planned for Summer 2004).

Download

-Latest Release (14 October 2005): Version 3.0.2

+Latest Release (18 November 2005): Version 3.0.3

Getting Started

With version 3.0, it is now possible to compile multiple API support on a given platform and to specify an API choice during class instantiation. In the examples that follow, no API will be specified (in which case, RtAudio attempts to select the most "logical" available API).

The first thing that must be done when using RtAudio is to create an instance of the class. The default constructor 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:

@@ -66,9 +66,9 @@ The first thing that must be done when using 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.

+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 that can throw a C++ exception be called within a try/catch block.

Error Handling

-RtAudio uses a C++ exception handler called RtError, which is declared and defined in RtError.h. The RtError class is quite simple but it does allow errors to be "caught" by RtError::Type. Almost all RtAudio methods can "throw" an RtError, most typically if a driver error occurs or a stream function is called when no stream is open. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a protected RtAudio method, error(), which can be modified to globally control how these messages are handled and reported. By default, error messages are not automatically displayed in RtAudio unless the preprocessor definition __RTAUDIO_DEBUG__ is defined. Messages associated with caught exceptions can be displayed with, for example, the RtError::printMessage() function.

+RtAudio uses a C++ exception handler called RtError, which is declared and defined in RtError.h. The RtError class is quite simple but it does allow errors to be "caught" by RtError::Type. Almost all RtAudio methods can "throw" an RtError, most typically if a driver error occurs or a stream function is called when no stream is open. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a protected RtAudio method, error(), that can be modified to globally control how these messages are handled and reported. By default, error messages are not automatically displayed in RtAudio unless the preprocessor definition __RTAUDIO_DEBUG__ is defined. Messages associated with caught exceptions can be displayed with, for example, the RtError::printMessage() function.

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
@@ -136,7 +136,7 @@ The following data formats are defined and fully supported by static const RtAudioFormat  RTAUDIO_FLOAT32; // 32-bit float normalized between +/- 1.0
   static const RtAudioFormat  RTAUDIO_FLOAT64; // 64-bit double normalized between +/- 1.0
 

-The nativeFormats member of the RtAudioDeviceInfo 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 RtAudioDeviceInfo structure is false, the remaining structure members are undefined and the device is probably unuseable.

+The nativeFormats member of the RtAudioDeviceInfo structure is a bit mask of the above formats that 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 RtAudioDeviceInfo structure is false, the remaining structure members are undefined and the device is probably unuseable.

While some audio devices may require a minimum channel value greater than one, 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. For this reason, RtAudio does not typically rely on the queried values when attempting to open a stream.

Device Settings

@@ -176,9 +176,9 @@ The next step in using RtAudio is to return 0; }

-The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. In this case, we attempt to open a two channel playback stream with the default output device, 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, RtAudio searches through the remaining available devices in an effort to find a device which will meet the given parameters. If all attempts are unsuccessful, an RtError is thrown. When a non-zero device value is specified, an attempt is made to open that device ONLY (device = 1 specifies the first identified device, as reported by RtAudio::getDeviceInfo()).

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

-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 (the nBuffers parameter is ignored when using the OS X CoreAudio, Linux Jack, and the Windows ASIO APIs). 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 API Notes section for general guidelines.

+The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. In this case, we attempt to open a two channel playback stream with the default output device, 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, RtAudio searches through the remaining available devices in an effort to find a device that will meet the given parameters. If all attempts are unsuccessful, an RtError is thrown. When a non-zero device value is specified, an attempt is made to open that device ONLY (device = 1 specifies the first identified device, as reported by RtAudio::getDeviceInfo()).

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

+The bufferSize parameter specifies the desired number of sample frames that 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 (the nBuffers parameter is ignored when using the OS X CoreAudio, Linux Jack, and the Windows ASIO APIs). 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 API 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.

@@ -219,7 +219,7 @@ Once the device is open for playback, there are only a few final steps necessary goto cleanup; } - // An example loop which runs for 40000 sample frames + // An example loop that runs for 40000 sample frames count = 0; while (count < 40000) { // Generate your samples and fill the buffer with bufferSize sample frames of data @@ -256,7 +256,7 @@ The first thing to notice in this example is that we attempt to open a stream du 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.

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

#include <iostream>
 #include "RtAudio.h"
 
@@ -331,7 +331,7 @@ The primary difference in using RtAudioreturn 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(). When the underlying audio API uses blocking calls (OSS, ALSA, SGI, and Windows DirectSound), this method will spawn a new process (or thread) which automatically calls the callback function when more data is needed. Callback-based audio APIs (OS X CoreAudio Linux Jack, and ASIO) implement their own event notification schemes. 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.

+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(). When the underlying audio API uses blocking calls (OSS, ALSA, SGI, and Windows DirectSound), this method will spawn a new process (or thread) that automatically calls the callback function when more data is needed. Callback-based audio APIs (OS X CoreAudio Linux Jack, and ASIO) implement their own event notification schemes. 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 exists 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

@@ -373,7 +373,7 @@ Using RtAudio for audio input is almo goto cleanup; } - // An example loop which runs for about 40000 sample frames + // An example loop that runs for about 40000 sample frames count = 0; while (count < 40000) { @@ -535,12 +535,12 @@ In order to compile RtAudio for a spe

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

Debugging

-If you are having problems getting RtAudio to run on your system, try passing the preprocessor definition __RTAUDIO_DEBUG__ to the compiler (or uncomment the definition at the bottom of RtAudio.h). A variety of warning messages will be displayed which may help in determining the problem. Also try using the programs included in the test directory. The program info displays the queried capabilities of all hardware devices found.

+If you are having problems getting RtAudio to run on your system, try passing the preprocessor definition __RTAUDIO_DEBUG__ to the compiler (or uncomment the definition at the bottom of RtAudio.h). A variety of warning messages will be displayed that may help in determining the problem. Also try using the programs included in the test directory. The program info displays the queried capabilities of all hardware devices found.

API Notes

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

Linux:

RtAudio for Linux was developed under Redhat distributions 7.0 - Fedora. Three different audio APIs are supported on Linux platforms: OSS, ALSA, and Jack. 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 (though the availability and quality of OSS drivers for new hardware is decreasing). The ALSA API, although relatively new, is now part of the Linux development kernel and offers significantly better functionality than the OSS API. RtAudio provides support for the 1.0 and higher versions of ALSA. Jack, which is still in development, is a low-latency audio server, written primarily for the GNU/Linux operating system. It can connect a number of different applications to an audio device, as well as allow them to share audio between themselves. Input/output latency on the order of 15 milliseconds can typically be achieved using any of the Linux APIs 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 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 that have ALSA drivers installed.

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

The Jack API is based on a callback scheme. RtAudio provides blocking functionality, in addition to callback functionality, within the context of that behavior. It should be noted, however, that the best performance is achieved when using RtAudio's callback functionality with the Jack API. At the moment, only one RtAudio instance can be connected to the Jack server. Because RtAudio does not provide a mechanism for allowing the user to specify particular channels (or ports) of a device, it simply opens the first N enumerated Jack ports for input/output.

Macintosh OS X (CoreAudio):

@@ -549,10 +549,12 @@ It is not possible to have multiple instances of RtAudio was written and tested on an SGI Indy running Irix version 6.5.4 and the newer "al" audio library. RtAudio does not compile under Irix version 6.3, mainly 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 (DirectSound):

-In order to compile RtAudio under Windows for the DirectSound API, you must have the header and source files for DirectSound version 5.0 or higher. As far as I know, there is no DirectSoundCapture support for Windows NT. 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 crashes. RtAudio was originally developed with Visual C++ version 6.0.

+In order to compile RtAudio under Windows for the DirectSound API, you must have the header and source files for DirectSound version 5.0 or higher. As far as I know, there is no DirectSoundCapture support for Windows NT. Audio output latency with DirectSound can be reasonably good, especially since RtAudio version 3.0.2. Input audio latency still tends to be bad but better since version 3.0.2. RtAudio was originally developed with Visual C++ version 6.0 but has been tested with .NET.

+The DirectSound version of RtAudio can be compiled with or without the UNICODE preprocessor definition.

Windows (ASIO):

The Steinberg ASIO audio API is based on a callback scheme. In addition, the API allows only a single device driver to be loaded and accessed at a time. ASIO device drivers must be supplied by audio hardware manufacturers, though ASIO emulation is possible on top of systems with DirectSound drivers. The numberOfBuffers parameter to the RtAudio::openStream() function has no affect in this implementation.

-A number of ASIO source and header files are required for use with RtAudio. Specifically, an RtAudio project must include the following files: asio.h,cpp; asiodrivers.h,cpp; asiolist.h,cpp; asiodrvr.h; asiosys.h; ginclude.h; iasiodrv.h. The Visual C++ projects found in /tests/Windows/ compile both ASIO and DirectSound support.

+A number of ASIO source and header files are required for use with RtAudio. Specifically, an RtAudio project must include the following files: asio.h,cpp; asiodrivers.h,cpp; asiolist.h,cpp; asiodrvr.h; asiosys.h; ginclude.h; iasiodrv.h; iasiothiscallresolver.h,cpp. The Visual C++ projects found in /tests/Windows/ compile both ASIO and DirectSound support.

+The Steinberg provided asiolist class does not compile when the preprocessor definition UNICODE is defined. Note that this could be an issue when using RtAudio with Qt, though Qt programs appear to compile without the UNICODE definition (try DEFINES -= UNICODE in your .pro file). RtAudio with ASIO support has been tested using the MinGW compiler under Windows XP, as well as in the Visual Studio environment.

Possible Future Changes

There are a few issues that still need to be addressed in future versions of RtAudio, including:

Acknowledgements

-Thanks to Robin Davies for a number of bug fixes and improvements to the DirectSound and ASIO implementations in the 3.0.2 release!

+Many thanks to the following people for providing bug fixes and improvements:

+

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.

The early 2.0 version of RtAudio was slowly developed over the course of many months while in residence at the Institut Universitari de L'Audiovisual (IUA) in Barcelona, Spain and the Laboratory of Acoustics and Audio Signal Processing at the Helsinki University of Technology, Finland. Much subsequent development happened while working at the Center for Computer Research in Music and Acoustics (CCRMA) at Stanford University. The most recent version of RtAudio was finished while working as an assistant professor of Music Technology at McGill University. This work was supported in part by the United States Air Force Office of Scientific Research (grant #F49620-99-1-0293).

License