48 #define RTAUDIO_VERSION "5.0.0"   188                                 unsigned int nFrames,
   224     : std::runtime_error(message), type_(type) {}
   228     { std::cerr << 
'\n' << what() << 
"\n\n"; }
   235     { 
return std::string(what()); }
   579 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)   587   typedef uintptr_t ThreadHandle;
   588   typedef CRITICAL_SECTION StreamMutex;
   590 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)   594   typedef pthread_t ThreadHandle;
   595   typedef pthread_mutex_t StreamMutex;
   597 #else // Setup for "dummy" behavior   599   #define __RTAUDIO_DUMMY__   600   typedef int ThreadHandle;
   601   typedef int StreamMutex;
   608 struct CallbackInfo {
   621   :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false), priority(0) {}
   638 #pragma pack(push, 1)   647   S24& operator = ( 
const int& i ) {
   648     c3[0] = (i & 0x000000ff);
   649     c3[1] = (i & 0x0000ff00) >> 8;
   650     c3[2] = (i & 0x00ff0000) >> 16;
   654   S24( 
const S24& v ) { *
this = v; }
   655   S24( 
const double& d ) { *
this = (int) d; }
   656   S24( 
const float& f ) { *
this = (int) f; }
   657   S24( 
const signed short& s ) { *
this = (int) s; }
   658   S24( 
const char& c ) { *
this = (int) c; }
   661     int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
   662     if (i & 0x800000) i |= ~0xffffff;
   668 #if defined( HAVE_GETTIMEOFDAY )   669   #include <sys/time.h>   681   virtual unsigned int getDeviceCount( 
void ) = 0;
   683   virtual unsigned int getDefaultInputDevice( 
void );
   684   virtual unsigned int getDefaultOutputDevice( 
void );
   691   virtual void closeStream( 
void );
   692   virtual void startStream( 
void ) = 0;
   693   virtual void stopStream( 
void ) = 0;
   694   virtual void abortStream( 
void ) = 0;
   695   long getStreamLatency( 
void );
   696   unsigned int getStreamSampleRate( 
void );
   697   virtual double getStreamTime( 
void );
   698   virtual void setStreamTime( 
double time );
   699   bool isStreamOpen( 
void )
 const { 
return stream_.state != STREAM_CLOSED; }
   700   bool isStreamRunning( 
void )
 const { 
return stream_.state == STREAM_RUNNING; }
   701   void showWarnings( 
bool value ) { showWarnings_ = value; }
   706   static const unsigned int MAX_SAMPLE_RATES;
   707   static const unsigned int SAMPLE_RATES[];
   709   enum { FAILURE, SUCCESS };
   730     std::vector<int> inOffset;
   731     std::vector<int> outOffset;
   736     unsigned int device[2];    
   742     bool doConvertBuffer[2];   
   743     bool userInterleaved;
   744     bool deviceInterleaved[2]; 
   746     unsigned int sampleRate;
   747     unsigned int bufferSize;
   748     unsigned int nBuffers;
   749     unsigned int nUserChannels[2];    
   750     unsigned int nDeviceChannels[2];  
   751     unsigned int channelOffset[2];    
   752     unsigned long latency[2];         
   756     CallbackInfo callbackInfo;
   757     ConvertInfo convertInfo[2];
   760 #if defined(HAVE_GETTIMEOFDAY)   761     struct timeval lastTickTimestamp;
   765       :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
   769   typedef signed short Int16;
   770   typedef signed int Int32;
   771   typedef float Float32;
   772   typedef double Float64;
   774   std::ostringstream errorStream_;
   775   std::string errorText_;
   778   bool firstErrorOccurred_;
   787   virtual bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
   788                                 unsigned int firstChannel, 
unsigned int sampleRate,
   793   void tickStreamTime( 
void );
   796   void clearStreamInfo();
   802   void verifyStream( 
void );
   811   void convertBuffer( 
char *outBuffer, 
char *inBuffer, ConvertInfo &info );
   814   void byteSwapBuffer( 
char *buffer, 
unsigned int samples, 
RtAudioFormat format );
   820   void setConvertInfo( StreamMode mode, 
unsigned int firstChannel );
   848 #if defined(__MACOSX_CORE__)   850 #include <CoreAudio/AudioHardware.h>   852 class RtApiCore: 
public RtApi
   859   unsigned int getDeviceCount( 
void );
   861   unsigned int getDefaultOutputDevice( 
void );
   862   unsigned int getDefaultInputDevice( 
void );
   863   void closeStream( 
void );
   864   void startStream( 
void );
   865   void stopStream( 
void );
   866   void abortStream( 
void );
   867   long getStreamLatency( 
void );
   873   bool callbackEvent( AudioDeviceID deviceId,
   874                       const AudioBufferList *inBufferList,
   875                       const AudioBufferList *outBufferList );
   879   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
   880                         unsigned int firstChannel, 
unsigned int sampleRate,
   883   static const char* getErrorCode( OSStatus code );
   888 #if defined(__UNIX_JACK__)   890 class RtApiJack: 
public RtApi
   897   unsigned int getDeviceCount( 
void );
   899   void closeStream( 
void );
   900   void startStream( 
void );
   901   void stopStream( 
void );
   902   void abortStream( 
void );
   903   long getStreamLatency( 
void );
   909   bool callbackEvent( 
unsigned long nframes );
   913   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
   914                         unsigned int firstChannel, 
unsigned int sampleRate,
   918   bool shouldAutoconnect_;
   923 #if defined(__WINDOWS_ASIO__)   925 class RtApiAsio: 
public RtApi
   932   unsigned int getDeviceCount( 
void );
   934   void closeStream( 
void );
   935   void startStream( 
void );
   936   void stopStream( 
void );
   937   void abortStream( 
void );
   938   long getStreamLatency( 
void );
   944   bool callbackEvent( 
long bufferIndex );
   948   std::vector<RtAudio::DeviceInfo> devices_;
   949   void saveDeviceInfo( 
void );
   951   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
   952                         unsigned int firstChannel, 
unsigned int sampleRate,
   959 #if defined(__WINDOWS_DS__)   961 class RtApiDs: 
public RtApi
   968   unsigned int getDeviceCount( 
void );
   969   unsigned int getDefaultOutputDevice( 
void );
   970   unsigned int getDefaultInputDevice( 
void );
   972   void closeStream( 
void );
   973   void startStream( 
void );
   974   void stopStream( 
void );
   975   void abortStream( 
void );
   976   long getStreamLatency( 
void );
   982   void callbackEvent( 
void );
   988   long duplexPrerollBytes;
   989   std::vector<struct DsDevice> dsDevices;
   990   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
   991                         unsigned int firstChannel, 
unsigned int sampleRate,
   998 #if defined(__WINDOWS_WASAPI__)  1000 struct IMMDeviceEnumerator;
  1002 class RtApiWasapi : 
public RtApi
  1009   unsigned int getDeviceCount( 
void );
  1011   unsigned int getDefaultOutputDevice( 
void );
  1012   unsigned int getDefaultInputDevice( 
void );
  1013   void closeStream( 
void );
  1014   void startStream( 
void );
  1015   void stopStream( 
void );
  1016   void abortStream( 
void );
  1019   bool coInitialized_;
  1020   IMMDeviceEnumerator* deviceEnumerator_;
  1022   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels,
  1023                         unsigned int firstChannel, 
unsigned int sampleRate,
  1027   static DWORD WINAPI runWasapiThread( 
void* wasapiPtr );
  1028   static DWORD WINAPI stopWasapiThread( 
void* wasapiPtr );
  1029   static DWORD WINAPI abortWasapiThread( 
void* wasapiPtr );
  1030   void wasapiThread();
  1035 #if defined(__LINUX_ALSA__)  1037 class RtApiAlsa: 
public RtApi
  1044   unsigned int getDeviceCount( 
void );
  1046   void closeStream( 
void );
  1047   void startStream( 
void );
  1048   void stopStream( 
void );
  1049   void abortStream( 
void );
  1055   void callbackEvent( 
void );
  1059   std::vector<RtAudio::DeviceInfo> devices_;
  1060   void saveDeviceInfo( 
void );
  1061   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
  1062                         unsigned int firstChannel, 
unsigned int sampleRate,
  1069 #if defined(__LINUX_PULSE__)  1071 class RtApiPulse: 
public RtApi
  1076   unsigned int getDeviceCount( 
void );
  1078   void closeStream( 
void );
  1079   void startStream( 
void );
  1080   void stopStream( 
void );
  1081   void abortStream( 
void );
  1087   void callbackEvent( 
void );
  1091   std::vector<RtAudio::DeviceInfo> devices_;
  1092   void saveDeviceInfo( 
void );
  1093   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels,
  1094                         unsigned int firstChannel, 
unsigned int sampleRate,
  1101 #if defined(__LINUX_OSS__)  1103 class RtApiOss: 
public RtApi
  1110   unsigned int getDeviceCount( 
void );
  1112   void closeStream( 
void );
  1113   void startStream( 
void );
  1114   void stopStream( 
void );
  1115   void abortStream( 
void );
  1121   void callbackEvent( 
void );
  1125   bool probeDeviceOpen( 
unsigned int device, StreamMode mode, 
unsigned int channels, 
  1126                         unsigned int firstChannel, 
unsigned int sampleRate,
  1133 #if defined(__RTAUDIO_DUMMY__)  1135 class RtApiDummy: 
public RtApi
  1139   RtApiDummy() { errorText_ = 
"RtApiDummy: This class provides no functionality."; error( 
RtAudioError::WARNING ); }
  1141   unsigned int getDeviceCount( 
void ) { 
return 0; }
  1143   void closeStream( 
void ) {}
  1144   void startStream( 
void ) {}
  1145   void stopStream( 
void ) {}
  1146   void abortStream( 
void ) {}
  1150   bool probeDeviceOpen( 
unsigned int , StreamMode , 
unsigned int , 
  1151                         unsigned int , 
unsigned int ,
 Definition: RtAudio.h:212
unsigned long RtAudioFormat
RtAudio data format type. 
Definition: RtAudio.h:71
RtAudioStreamFlags flags
Definition: RtAudio.h:369
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags. 
Definition: RtAudio.h:144
Type
Defined RtAudioError types. 
Definition: RtAudio.h:207
unsigned int duplexChannels
Definition: RtAudio.h:287
unsigned int deviceId
Definition: RtAudio.h:302
Definition: RtAudio.h:211
Definition: RtAudio.h:209
Definition: RtAudio.h:214
unsigned int inputChannels
Definition: RtAudio.h:286
RtAudioError(const std::string &message, Type type=RtAudioError::UNSPECIFIED)
The constructor. 
Definition: RtAudio.h:222
unsigned int numberOfBuffers
Definition: RtAudio.h:370
virtual const std::string getMessage(void) const
Returns the thrown error message string. 
Definition: RtAudio.h:234
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype. 
Definition: RtAudio.h:187
unsigned int firstChannel
Definition: RtAudio.h:304
Definition: RtAudio.h:275
Api
Audio API specifier arguments. 
Definition: RtAudio.h:268
void openStream(RtAudio::StreamParameters *outputParameters, RtAudio::StreamParameters *inputParameters, RtAudioFormat format, unsigned int sampleRate, unsigned int *bufferFrames, RtAudioCallback callback, void *userData=NULL, RtAudio::StreamOptions *options=NULL, RtAudioErrorCallback errorCallback=NULL)
A public function for opening a stream with the specified parameters. 
static std::string getVersion(void)
A static function to determine the current RtAudio version. 
Definition: RtAudio.h:269
The public device information structure for returning queried values. 
Definition: RtAudio.h:282
void showWarnings(bool value=true)
Specify whether warning messages should be printed to stderr. 
Definition: RtAudio.h:844
void stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played. 
Definition: RtAudio.h:836
void(* RtAudioErrorCallback)(RtAudioError::Type type, const std::string &errorText)
RtAudio error callback function prototype. 
Definition: RtAudio.h:246
The structure for specifying stream options. 
Definition: RtAudio.h:368
Definition: RtAudio.h:276
std::string name
Definition: RtAudio.h:284
unsigned int outputChannels
Definition: RtAudio.h:285
bool isStreamOpen(void) const
Returns true if a stream is open and false if not. 
Definition: RtAudio.h:838
void startStream(void)
A function that starts a stream. 
Definition: RtAudio.h:835
long getStreamLatency(void)
Returns the internal stream latency in sample frames. 
Definition: RtAudio.h:840
Definition: RtAudio.h:270
RtAudioFormat nativeFormats
Definition: RtAudio.h:292
unsigned int getDefaultInputDevice(void)
A function that returns the index of the default input device. 
Definition: RtAudio.h:832
bool isDefaultOutput
Definition: RtAudio.h:288
virtual void printMessage(void) const
Prints thrown error message to stderr. 
Definition: RtAudio.h:227
Definition: RtAudio.h:216
Definition: RtAudio.h:274
Definition: RtAudio.h:215
Definition: RtAudio.h:271
Exception handling class for RtAudio. 
Definition: RtAudio.h:203
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:290
unsigned int preferredSampleRate
Definition: RtAudio.h:291
double getStreamTime(void)
Returns the number of elapsed seconds since the stream was started. 
Definition: RtAudio.h:842
Definition: RtAudio.h:213
virtual const Type & getType(void) const
Returns the thrown error message type. 
Definition: RtAudio.h:231
int priority
Definition: RtAudio.h:372
unsigned int nChannels
Definition: RtAudio.h:303
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio. 
Definition: RtAudio.h:829
static void getCompiledApi(std::vector< RtAudio::Api > &apis)
A static function to determine the available compiled audio APIs. 
The structure for specifying input or ouput stream parameters. 
Definition: RtAudio.h:301
Definition: RtAudio.h:210
void abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue. 
Definition: RtAudio.h:837
Definition: RtAudio.h:217
RtAudio(RtAudio::Api api=UNSPECIFIED)
The class constructor. 
RtAudio::DeviceInfo getDeviceInfo(unsigned int device)
Return an RtAudio::DeviceInfo structure for a specified device number. 
Definition: RtAudio.h:831
bool probed
Definition: RtAudio.h:283
Definition: RtAudio.h:277
Definition: RtAudio.h:278
void closeStream(void)
A function that closes a stream and frees any associated stream memory. 
Definition: RtAudio.h:834
Definition: RtAudio.h:272
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open. 
Definition: RtAudio.h:839
unsigned int RtAudioStreamFlags
RtAudio stream option flags. 
Definition: RtAudio.h:125
Definition: RtAudio.h:208
std::string streamName
Definition: RtAudio.h:371
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0. 
Definition: RtAudio.h:843
bool isDefaultInput
Definition: RtAudio.h:289
Realtime audio i/o C++ classes. 
Definition: RtAudio.h:263
unsigned int getDefaultOutputDevice(void)
A function that returns the index of the default output device. 
Definition: RtAudio.h:833
Definition: RtAudio.h:218
~RtAudio()
The destructor. 
Definition: RtAudio.h:273
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available. 
Definition: RtAudio.h:830
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the stream. 
Definition: RtAudio.h:841