49 #define RTAUDIO_VERSION "5.1.0"
51 #if defined _WIN32 || defined __CYGWIN__
52 #if defined(RTAUDIO_EXPORT)
53 #define RTAUDIO_DLL_PUBLIC __declspec(dllexport)
55 #define RTAUDIO_DLL_PUBLIC
59 #define RTAUDIO_DLL_PUBLIC __attribute__( (visibility( "default" )) )
61 #define RTAUDIO_DLL_PUBLIC
204 unsigned int nFrames,
240 : std::runtime_error(message), type_(type) {}
243 virtual void printMessage(
void )
const
244 { std::cerr <<
'\n' << what() <<
"\n\n"; }
250 virtual const std::string getMessage(
void)
const
251 {
return std::string(what()); }
313 :probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
314 isDefaultOutput(false), isDefaultInput(false), preferredSampleRate(0), nativeFormats(0) {}
325 : deviceId(0), nChannels(0), firstChannel(0) {}
393 : flags(0), numberOfBuffers(0), priority(0) {}
397 static std::string getVersion(
void );
405 static void getCompiledApi( std::vector<RtAudio::Api> &apis );
420 static std::string getApiDisplayName(
RtAudio::Api api );
428 static RtAudio::Api getCompiledApiByName(
const std::string &name );
457 unsigned int getDeviceCount(
void );
480 unsigned int getDefaultOutputDevice(
void );
490 unsigned int getDefaultInputDevice(
void );
543 void closeStream(
void );
552 void startStream(
void );
561 void stopStream(
void );
570 void abortStream(
void );
573 bool isStreamOpen(
void )
const;
576 bool isStreamRunning(
void )
const;
582 double getStreamTime(
void );
588 void setStreamTime(
double time );
599 long getStreamLatency(
void );
607 unsigned int getStreamSampleRate(
void );
610 void showWarnings(
bool value =
true );
619 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
628 typedef uintptr_t ThreadHandle;
629 typedef CRITICAL_SECTION StreamMutex;
631 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
635 typedef pthread_t ThreadHandle;
636 typedef pthread_mutex_t StreamMutex;
638 #else // Setup for "dummy" behavior
640 #define __RTAUDIO_DUMMY__
641 typedef int ThreadHandle;
642 typedef int StreamMutex;
649 struct CallbackInfo {
662 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false), priority(0) {}
679 #pragma pack(push, 1)
688 S24& operator = (
const int& i ) {
689 c3[0] = (i & 0x000000ff);
690 c3[1] = (i & 0x0000ff00) >> 8;
691 c3[2] = (i & 0x00ff0000) >> 16;
695 S24(
const double& d ) { *
this = (int) d; }
696 S24(
const float& f ) { *
this = (int) f; }
697 S24(
const signed short& s ) { *
this = (int) s; }
698 S24(
const char& c ) { *
this = (int) c; }
701 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
702 if (i & 0x800000) i |= ~0xffffff;
708 #if defined( HAVE_GETTIMEOFDAY )
709 #include <sys/time.h>
714 class RTAUDIO_DLL_PUBLIC RtApi
721 virtual unsigned int getDeviceCount(
void ) = 0;
723 virtual unsigned int getDefaultInputDevice(
void );
724 virtual unsigned int getDefaultOutputDevice(
void );
731 virtual void closeStream(
void );
732 virtual void startStream(
void ) = 0;
733 virtual void stopStream(
void ) = 0;
734 virtual void abortStream(
void ) = 0;
735 long getStreamLatency(
void );
736 unsigned int getStreamSampleRate(
void );
737 virtual double getStreamTime(
void );
738 virtual void setStreamTime(
double time );
739 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
740 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
741 void showWarnings(
bool value ) { showWarnings_ = value; }
746 static const unsigned int MAX_SAMPLE_RATES;
747 static const unsigned int SAMPLE_RATES[];
749 enum { FAILURE, SUCCESS };
770 std::vector<int> inOffset;
771 std::vector<int> outOffset;
776 unsigned int device[2];
782 bool doConvertBuffer[2];
783 bool userInterleaved;
784 bool deviceInterleaved[2];
786 unsigned int sampleRate;
787 unsigned int bufferSize;
788 unsigned int nBuffers;
789 unsigned int nUserChannels[2];
790 unsigned int nDeviceChannels[2];
791 unsigned int channelOffset[2];
792 unsigned long latency[2];
796 CallbackInfo callbackInfo;
797 ConvertInfo convertInfo[2];
800 #if defined(HAVE_GETTIMEOFDAY)
801 struct timeval lastTickTimestamp;
805 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
809 typedef signed short Int16;
810 typedef signed int Int32;
811 typedef float Float32;
812 typedef double Float64;
814 std::ostringstream errorStream_;
815 std::string errorText_;
818 bool firstErrorOccurred_;
827 virtual bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
828 unsigned int firstChannel,
unsigned int sampleRate,
833 void tickStreamTime(
void );
836 void clearStreamInfo();
842 void verifyStream(
void );
851 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
854 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
860 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
888 #if defined(__MACOSX_CORE__)
890 #include <CoreAudio/AudioHardware.h>
892 class RtApiCore:
public RtApi
899 unsigned int getDeviceCount(
void );
901 unsigned int getDefaultOutputDevice(
void );
902 unsigned int getDefaultInputDevice(
void );
903 void closeStream(
void );
904 void startStream(
void );
905 void stopStream(
void );
906 void abortStream(
void );
912 bool callbackEvent( AudioDeviceID deviceId,
913 const AudioBufferList *inBufferList,
914 const AudioBufferList *outBufferList );
918 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
919 unsigned int firstChannel,
unsigned int sampleRate,
922 static const char* getErrorCode( OSStatus code );
927 #if defined(__UNIX_JACK__)
929 class RtApiJack:
public RtApi
936 unsigned int getDeviceCount(
void );
938 void closeStream(
void );
939 void startStream(
void );
940 void stopStream(
void );
941 void abortStream(
void );
947 bool callbackEvent(
unsigned long nframes );
951 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
952 unsigned int firstChannel,
unsigned int sampleRate,
956 bool shouldAutoconnect_;
961 #if defined(__WINDOWS_ASIO__)
963 class RtApiAsio:
public RtApi
970 unsigned int getDeviceCount(
void );
972 void closeStream(
void );
973 void startStream(
void );
974 void stopStream(
void );
975 void abortStream(
void );
981 bool callbackEvent(
long bufferIndex );
985 std::vector<RtAudio::DeviceInfo> devices_;
986 void saveDeviceInfo(
void );
988 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
989 unsigned int firstChannel,
unsigned int sampleRate,
996 #if defined(__WINDOWS_DS__)
998 class RtApiDs:
public RtApi
1005 unsigned int getDeviceCount(
void );
1006 unsigned int getDefaultOutputDevice(
void );
1007 unsigned int getDefaultInputDevice(
void );
1009 void closeStream(
void );
1010 void startStream(
void );
1011 void stopStream(
void );
1012 void abortStream(
void );
1018 void callbackEvent(
void );
1022 bool coInitialized_;
1023 bool buffersRolling;
1024 long duplexPrerollBytes;
1025 std::vector<struct DsDevice> dsDevices;
1026 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1027 unsigned int firstChannel,
unsigned int sampleRate,
1034 #if defined(__WINDOWS_WASAPI__)
1036 struct IMMDeviceEnumerator;
1038 class RtApiWasapi :
public RtApi
1042 virtual ~RtApiWasapi();
1045 unsigned int getDeviceCount(
void );
1047 unsigned int getDefaultOutputDevice(
void );
1048 unsigned int getDefaultInputDevice(
void );
1049 void closeStream(
void );
1050 void startStream(
void );
1051 void stopStream(
void );
1052 void abortStream(
void );
1055 bool coInitialized_;
1056 IMMDeviceEnumerator* deviceEnumerator_;
1058 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1059 unsigned int firstChannel,
unsigned int sampleRate,
1063 static DWORD WINAPI runWasapiThread(
void* wasapiPtr );
1064 static DWORD WINAPI stopWasapiThread(
void* wasapiPtr );
1065 static DWORD WINAPI abortWasapiThread(
void* wasapiPtr );
1066 void wasapiThread();
1071 #if defined(__LINUX_ALSA__)
1073 class RtApiAlsa:
public RtApi
1080 unsigned int getDeviceCount(
void );
1082 void closeStream(
void );
1083 void startStream(
void );
1084 void stopStream(
void );
1085 void abortStream(
void );
1091 void callbackEvent(
void );
1095 std::vector<RtAudio::DeviceInfo> devices_;
1096 void saveDeviceInfo(
void );
1097 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1098 unsigned int firstChannel,
unsigned int sampleRate,
1105 #if defined(__LINUX_PULSE__)
1107 class RtApiPulse:
public RtApi
1112 unsigned int getDeviceCount(
void );
1114 void closeStream(
void );
1115 void startStream(
void );
1116 void stopStream(
void );
1117 void abortStream(
void );
1123 void callbackEvent(
void );
1127 std::vector<RtAudio::DeviceInfo> devices_;
1128 void saveDeviceInfo(
void );
1129 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1130 unsigned int firstChannel,
unsigned int sampleRate,
1137 #if defined(__LINUX_OSS__)
1139 class RtApiOss:
public RtApi
1146 unsigned int getDeviceCount(
void );
1148 void closeStream(
void );
1149 void startStream(
void );
1150 void stopStream(
void );
1151 void abortStream(
void );
1157 void callbackEvent(
void );
1161 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1162 unsigned int firstChannel,
unsigned int sampleRate,
1169 #if defined(__RTAUDIO_DUMMY__)
1171 class RtApiDummy:
public RtApi
1175 RtApiDummy() { errorText_ =
"RtApiDummy: This class provides no functionality."; error(
RtAudioError::WARNING ); }
1177 unsigned int getDeviceCount(
void ) {
return 0; }
1179 void closeStream(
void ) {}
1180 void startStream(
void ) {}
1181 void stopStream(
void ) {}
1182 void abortStream(
void ) {}
1186 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1187 unsigned int ,
unsigned int ,