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_;
377 static std::string
getVersion(
void ) throw();
490 RtAudio::StreamParameters *inputParameters,
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>
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
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
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
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
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
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
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
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
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 ); }
1145 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1146 unsigned int ,
unsigned int ,