48 #define RTAUDIO_VERSION "4.1.2"
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_;
378 static std::string
getVersion(
void ) throw();
491 RtAudio::StreamParameters *inputParameters,
577 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
585 typedef uintptr_t ThreadHandle;
586 typedef CRITICAL_SECTION StreamMutex;
588 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
592 typedef pthread_t ThreadHandle;
593 typedef pthread_mutex_t StreamMutex;
595 #else // Setup for "dummy" behavior
597 #define __RTAUDIO_DUMMY__
598 typedef int ThreadHandle;
599 typedef int StreamMutex;
606 struct CallbackInfo {
619 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false) {}
636 #pragma pack(push, 1)
645 S24& operator = (
const int& i ) {
646 c3[0] = (i & 0x000000ff);
647 c3[1] = (i & 0x0000ff00) >> 8;
648 c3[2] = (i & 0x00ff0000) >> 16;
652 S24(
const S24& v ) { *
this = v; }
653 S24(
const double& d ) { *
this = (int) d; }
654 S24(
const float& f ) { *
this = (int) f; }
655 S24(
const signed short& s ) { *
this = (int) s; }
656 S24(
const char& c ) { *
this = (int) c; }
659 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
660 if (i & 0x800000) i |= ~0xffffff;
666 #if defined( HAVE_GETTIMEOFDAY )
667 #include <sys/time.h>
697 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
698 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
699 void showWarnings(
bool value ) { showWarnings_ = value; }
704 static const unsigned int MAX_SAMPLE_RATES;
705 static const unsigned int SAMPLE_RATES[];
707 enum { FAILURE, SUCCESS };
728 std::vector<int> inOffset;
729 std::vector<int> outOffset;
734 unsigned int device[2];
740 bool doConvertBuffer[2];
741 bool userInterleaved;
742 bool deviceInterleaved[2];
744 unsigned int sampleRate;
745 unsigned int bufferSize;
746 unsigned int nBuffers;
747 unsigned int nUserChannels[2];
748 unsigned int nDeviceChannels[2];
749 unsigned int channelOffset[2];
750 unsigned long latency[2];
754 CallbackInfo callbackInfo;
755 ConvertInfo convertInfo[2];
758 #if defined(HAVE_GETTIMEOFDAY)
759 struct timeval lastTickTimestamp;
763 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
767 typedef signed short Int16;
768 typedef signed int Int32;
769 typedef float Float32;
770 typedef double Float64;
772 std::ostringstream errorStream_;
773 std::string errorText_;
776 bool firstErrorOccurred_;
785 virtual bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
786 unsigned int firstChannel,
unsigned int sampleRate,
791 void tickStreamTime(
void );
794 void clearStreamInfo();
800 void verifyStream(
void );
809 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
812 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
818 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
846 #if defined(__MACOSX_CORE__)
848 #include <CoreAudio/AudioHardware.h>
850 class RtApiCore:
public RtApi
871 bool callbackEvent( AudioDeviceID deviceId,
872 const AudioBufferList *inBufferList,
873 const AudioBufferList *outBufferList );
877 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
878 unsigned int firstChannel,
unsigned int sampleRate,
881 static const char* getErrorCode( OSStatus code );
886 #if defined(__UNIX_JACK__)
888 class RtApiJack:
public RtApi
907 bool callbackEvent(
unsigned long nframes );
911 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
912 unsigned int firstChannel,
unsigned int sampleRate,
919 #if defined(__WINDOWS_ASIO__)
921 class RtApiAsio:
public RtApi
940 bool callbackEvent(
long bufferIndex );
944 std::vector<RtAudio::DeviceInfo> devices_;
945 void saveDeviceInfo(
void );
947 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
948 unsigned int firstChannel,
unsigned int sampleRate,
955 #if defined(__WINDOWS_DS__)
957 class RtApiDs:
public RtApi
978 void callbackEvent(
void );
984 long duplexPrerollBytes;
985 std::vector<struct DsDevice> dsDevices;
986 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
987 unsigned int firstChannel,
unsigned int sampleRate,
994 #if defined(__WINDOWS_WASAPI__)
996 struct IMMDeviceEnumerator;
998 class RtApiWasapi :
public RtApi
1015 bool coInitialized_;
1016 IMMDeviceEnumerator* deviceEnumerator_;
1018 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1019 unsigned int firstChannel,
unsigned int sampleRate,
1023 static DWORD WINAPI runWasapiThread(
void* wasapiPtr );
1024 static DWORD WINAPI stopWasapiThread(
void* wasapiPtr );
1025 static DWORD WINAPI abortWasapiThread(
void* wasapiPtr );
1026 void wasapiThread();
1031 #if defined(__LINUX_ALSA__)
1033 class RtApiAlsa:
public RtApi
1051 void callbackEvent(
void );
1055 std::vector<RtAudio::DeviceInfo> devices_;
1056 void saveDeviceInfo(
void );
1057 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1058 unsigned int firstChannel,
unsigned int sampleRate,
1065 #if defined(__LINUX_PULSE__)
1067 class RtApiPulse:
public RtApi
1083 void callbackEvent(
void );
1087 std::vector<RtAudio::DeviceInfo> devices_;
1088 void saveDeviceInfo(
void );
1089 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1090 unsigned int firstChannel,
unsigned int sampleRate,
1097 #if defined(__LINUX_OSS__)
1099 class RtApiOss:
public RtApi
1117 void callbackEvent(
void );
1121 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1122 unsigned int firstChannel,
unsigned int sampleRate,
1129 #if defined(__RTAUDIO_DUMMY__)
1131 class RtApiDummy:
public RtApi
1135 RtApiDummy() { errorText_ =
"RtApiDummy: This class provides no functionality."; error(
RtAudioError::WARNING ); }
1146 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1147 unsigned int ,
unsigned int ,