48 #define RTAUDIO_VERSION "4.1.1" 183 unsigned int nFrames,
223 virtual void printMessage(
void )
const throw() { std::cerr <<
'\n' << message_ <<
"\n\n"; }
229 virtual const std::string&
getMessage(
void)
const throw() {
return message_; }
232 virtual const char*
what(
void )
const throw() {
return message_.c_str(); }
235 std::string message_;
293 :probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
294 isDefaultOutput(false), isDefaultInput(false), nativeFormats(0) {}
305 : deviceId(0), nChannels(0), firstChannel(0) {}
373 : flags(0), numberOfBuffers(0), priority(0) {}
377 static std::string getVersion(
void )
throw();
385 static void getCompiledApi( std::vector<RtAudio::Api> &apis )
throw();
414 unsigned int getDeviceCount(
void )
throw();
437 unsigned int getDefaultOutputDevice(
void )
throw();
447 unsigned int getDefaultInputDevice(
void )
throw();
500 void closeStream(
void )
throw();
509 void startStream(
void );
518 void stopStream(
void );
527 void abortStream(
void );
530 bool isStreamOpen(
void )
const throw();
533 bool isStreamRunning(
void )
const throw();
539 double getStreamTime(
void );
545 void setStreamTime(
double time );
556 long getStreamLatency(
void );
564 unsigned int getStreamSampleRate(
void );
567 void showWarnings(
bool value =
true )
throw();
576 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) 584 typedef uintptr_t ThreadHandle;
585 typedef CRITICAL_SECTION StreamMutex;
587 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__) 591 typedef pthread_t ThreadHandle;
592 typedef pthread_mutex_t StreamMutex;
594 #else // Setup for "dummy" behavior 596 #define __RTAUDIO_DUMMY__ 597 typedef int ThreadHandle;
598 typedef int StreamMutex;
605 struct CallbackInfo {
618 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(
false), doRealtime(
false) {}
635 #pragma pack(push, 1) 644 S24& operator = (
const int& i ) {
645 c3[0] = (i & 0x000000ff);
646 c3[1] = (i & 0x0000ff00) >> 8;
647 c3[2] = (i & 0x00ff0000) >> 16;
651 S24(
const S24& v ) { *
this = v; }
652 S24(
const double& d ) { *
this = (int) d; }
653 S24(
const float& f ) { *
this = (int) f; }
654 S24(
const signed short& s ) { *
this = (int) s; }
655 S24(
const char& c ) { *
this = (int) c; }
658 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
659 if (i & 0x800000) i |= ~0xffffff;
665 #if defined( HAVE_GETTIMEOFDAY ) 666 #include <sys/time.h> 678 virtual unsigned int getDeviceCount(
void ) = 0;
680 virtual unsigned int getDefaultInputDevice(
void );
681 virtual unsigned int getDefaultOutputDevice(
void );
688 virtual void closeStream(
void );
689 virtual void startStream(
void ) = 0;
690 virtual void stopStream(
void ) = 0;
691 virtual void abortStream(
void ) = 0;
692 long getStreamLatency(
void );
693 unsigned int getStreamSampleRate(
void );
694 virtual double getStreamTime(
void );
695 virtual void setStreamTime(
double time );
696 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
697 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
698 void showWarnings(
bool value ) { showWarnings_ = value; }
703 static const unsigned int MAX_SAMPLE_RATES;
704 static const unsigned int SAMPLE_RATES[];
706 enum { FAILURE, SUCCESS };
727 std::vector<int> inOffset;
728 std::vector<int> outOffset;
733 unsigned int device[2];
739 bool doConvertBuffer[2];
740 bool userInterleaved;
741 bool deviceInterleaved[2];
743 unsigned int sampleRate;
744 unsigned int bufferSize;
745 unsigned int nBuffers;
746 unsigned int nUserChannels[2];
747 unsigned int nDeviceChannels[2];
748 unsigned int channelOffset[2];
749 unsigned long latency[2];
753 CallbackInfo callbackInfo;
754 ConvertInfo convertInfo[2];
757 #if defined(HAVE_GETTIMEOFDAY) 758 struct timeval lastTickTimestamp;
762 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
766 typedef signed short Int16;
767 typedef signed int Int32;
768 typedef float Float32;
769 typedef double Float64;
771 std::ostringstream errorStream_;
772 std::string errorText_;
775 bool firstErrorOccurred_;
784 virtual bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
785 unsigned int firstChannel,
unsigned int sampleRate,
790 void tickStreamTime(
void );
793 void clearStreamInfo();
799 void verifyStream(
void );
808 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
811 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
817 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
845 #if defined(__MACOSX_CORE__) 847 #include <CoreAudio/AudioHardware.h> 849 class RtApiCore:
public RtApi
856 unsigned int getDeviceCount(
void );
858 unsigned int getDefaultOutputDevice(
void );
859 unsigned int getDefaultInputDevice(
void );
860 void closeStream(
void );
861 void startStream(
void );
862 void stopStream(
void );
863 void abortStream(
void );
864 long getStreamLatency(
void );
870 bool callbackEvent( AudioDeviceID deviceId,
871 const AudioBufferList *inBufferList,
872 const AudioBufferList *outBufferList );
876 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
877 unsigned int firstChannel,
unsigned int sampleRate,
880 static const char* getErrorCode( OSStatus code );
885 #if defined(__UNIX_JACK__) 887 class RtApiJack:
public RtApi
894 unsigned int getDeviceCount(
void );
896 void closeStream(
void );
897 void startStream(
void );
898 void stopStream(
void );
899 void abortStream(
void );
900 long getStreamLatency(
void );
906 bool callbackEvent(
unsigned long nframes );
910 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
911 unsigned int firstChannel,
unsigned int sampleRate,
918 #if defined(__WINDOWS_ASIO__) 920 class RtApiAsio:
public RtApi
927 unsigned int getDeviceCount(
void );
929 void closeStream(
void );
930 void startStream(
void );
931 void stopStream(
void );
932 void abortStream(
void );
933 long getStreamLatency(
void );
939 bool callbackEvent(
long bufferIndex );
943 std::vector<RtAudio::DeviceInfo> devices_;
944 void saveDeviceInfo(
void );
946 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
947 unsigned int firstChannel,
unsigned int sampleRate,
954 #if defined(__WINDOWS_DS__) 956 class RtApiDs:
public RtApi
963 unsigned int getDeviceCount(
void );
964 unsigned int getDefaultOutputDevice(
void );
965 unsigned int getDefaultInputDevice(
void );
967 void closeStream(
void );
968 void startStream(
void );
969 void stopStream(
void );
970 void abortStream(
void );
971 long getStreamLatency(
void );
977 void callbackEvent(
void );
983 long duplexPrerollBytes;
984 std::vector<struct DsDevice> dsDevices;
985 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
986 unsigned int firstChannel,
unsigned int sampleRate,
993 #if defined(__WINDOWS_WASAPI__) 995 struct IMMDeviceEnumerator;
997 class RtApiWasapi :
public RtApi
1004 unsigned int getDeviceCount(
void );
1006 unsigned int getDefaultOutputDevice(
void );
1007 unsigned int getDefaultInputDevice(
void );
1008 void closeStream(
void );
1009 void startStream(
void );
1010 void stopStream(
void );
1011 void abortStream(
void );
1014 bool coInitialized_;
1015 IMMDeviceEnumerator* deviceEnumerator_;
1017 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1018 unsigned int firstChannel,
unsigned int sampleRate,
1022 static DWORD WINAPI runWasapiThread(
void* wasapiPtr );
1023 static DWORD WINAPI stopWasapiThread(
void* wasapiPtr );
1024 static DWORD WINAPI abortWasapiThread(
void* wasapiPtr );
1025 void wasapiThread();
1030 #if defined(__LINUX_ALSA__) 1032 class RtApiAlsa:
public RtApi
1039 unsigned int getDeviceCount(
void );
1041 void closeStream(
void );
1042 void startStream(
void );
1043 void stopStream(
void );
1044 void abortStream(
void );
1050 void callbackEvent(
void );
1054 std::vector<RtAudio::DeviceInfo> devices_;
1055 void saveDeviceInfo(
void );
1056 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1057 unsigned int firstChannel,
unsigned int sampleRate,
1064 #if defined(__LINUX_PULSE__) 1066 class RtApiPulse:
public RtApi
1071 unsigned int getDeviceCount(
void );
1073 void closeStream(
void );
1074 void startStream(
void );
1075 void stopStream(
void );
1076 void abortStream(
void );
1082 void callbackEvent(
void );
1086 std::vector<RtAudio::DeviceInfo> devices_;
1087 void saveDeviceInfo(
void );
1088 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1089 unsigned int firstChannel,
unsigned int sampleRate,
1096 #if defined(__LINUX_OSS__) 1098 class RtApiOss:
public RtApi
1105 unsigned int getDeviceCount(
void );
1107 void closeStream(
void );
1108 void startStream(
void );
1109 void stopStream(
void );
1110 void abortStream(
void );
1116 void callbackEvent(
void );
1120 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1121 unsigned int firstChannel,
unsigned int sampleRate,
1128 #if defined(__RTAUDIO_DUMMY__) 1130 class RtApiDummy:
public RtApi
1134 RtApiDummy() { errorText_ =
"RtApiDummy: This class provides no functionality."; error(
RtAudioError::WARNING ); }
1136 unsigned int getDeviceCount(
void ) {
return 0; }
1138 void closeStream(
void ) {}
1139 void startStream(
void ) {}
1140 void stopStream(
void ) {}
1141 void abortStream(
void ) {}
1145 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1146 unsigned int ,
unsigned int ,
Definition: RtAudio.h:207
unsigned long RtAudioFormat
RtAudio data format type.
Definition: RtAudio.h:71
RtAudioStreamFlags flags
Definition: RtAudio.h:366
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition: RtAudio.h:139
Type
Defined RtAudioError types.
Definition: RtAudio.h:202
virtual ~RtAudioError(void)
The destructor.
Definition: RtAudio.h:220
unsigned int duplexChannels
Definition: RtAudio.h:285
unsigned int deviceId
Definition: RtAudio.h:299
Definition: RtAudio.h:206
Definition: RtAudio.h:204
Definition: RtAudio.h:209
unsigned int inputChannels
Definition: RtAudio.h:284
RtAudioError(const std::string &message, Type type=RtAudioError::UNSPECIFIED)
The constructor.
Definition: RtAudio.h:217
unsigned int numberOfBuffers
Definition: RtAudio.h:367
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition: RtAudio.h:182
unsigned int firstChannel
Definition: RtAudio.h:301
Definition: RtAudio.h:273
Api
Audio API specifier arguments.
Definition: RtAudio.h:266
Definition: RtAudio.h:267
The public device information structure for returning queried values.
Definition: RtAudio.h:280
void showWarnings(bool value=true)
Specify whether warning messages should be printed to stderr.
Definition: RtAudio.h:841
void stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played.
Definition: RtAudio.h:833
void(* RtAudioErrorCallback)(RtAudioError::Type type, const std::string &errorText)
RtAudio error callback function prototype.
Definition: RtAudio.h:244
virtual const std::string & getMessage(void) const
Returns the thrown error message string.
Definition: RtAudio.h:229
The structure for specifying stream options.
Definition: RtAudio.h:365
Definition: RtAudio.h:274
std::string name
Definition: RtAudio.h:282
unsigned int outputChannels
Definition: RtAudio.h:283
bool isStreamOpen(void) const
Returns true if a stream is open and false if not.
Definition: RtAudio.h:835
void startStream(void)
A function that starts a stream.
Definition: RtAudio.h:832
long getStreamLatency(void)
Returns the internal stream latency in sample frames.
Definition: RtAudio.h:837
Definition: RtAudio.h:268
RtAudioFormat nativeFormats
Definition: RtAudio.h:289
unsigned int getDefaultInputDevice(void)
A function that returns the index of the default input device.
Definition: RtAudio.h:829
bool isDefaultOutput
Definition: RtAudio.h:286
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition: RtAudio.h:223
Definition: RtAudio.h:211
Definition: RtAudio.h:272
Definition: RtAudio.h:210
Definition: RtAudio.h:269
Exception handling class for RtAudio.
Definition: RtAudio.h:198
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:288
double getStreamTime(void)
Returns the number of elapsed seconds since the stream was started.
Definition: RtAudio.h:839
Definition: RtAudio.h:208
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition: RtAudio.h:226
int priority
Definition: RtAudio.h:369
unsigned int nChannels
Definition: RtAudio.h:300
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio.
Definition: RtAudio.h:826
The structure for specifying input or ouput stream parameters.
Definition: RtAudio.h:298
Definition: RtAudio.h:205
void abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue.
Definition: RtAudio.h:834
virtual const char * what(void) const
Returns the thrown error message as a c-style string.
Definition: RtAudio.h:232
Definition: RtAudio.h:212
RtAudio::DeviceInfo getDeviceInfo(unsigned int device)
Return an RtAudio::DeviceInfo structure for a specified device number.
Definition: RtAudio.h:828
bool probed
Definition: RtAudio.h:281
Definition: RtAudio.h:275
Definition: RtAudio.h:276
void closeStream(void)
A function that closes a stream and frees any associated stream memory.
Definition: RtAudio.h:831
Definition: RtAudio.h:270
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open.
Definition: RtAudio.h:836
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition: RtAudio.h:121
Definition: RtAudio.h:203
std::string streamName
Definition: RtAudio.h:368
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0.
Definition: RtAudio.h:840
bool isDefaultInput
Definition: RtAudio.h:287
Realtime audio i/o C++ classes.
Definition: RtAudio.h:261
unsigned int getDefaultOutputDevice(void)
A function that returns the index of the default output device.
Definition: RtAudio.h:830
Definition: RtAudio.h:213
Definition: RtAudio.h:271
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available.
Definition: RtAudio.h:827
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the stream.
Definition: RtAudio.h:838