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 ,