48 #define RTAUDIO_VERSION "4.1.0"
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,
570 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
574 typedef ULONG_PTR ThreadHandle;
575 typedef CRITICAL_SECTION StreamMutex;
577 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
581 typedef pthread_t ThreadHandle;
582 typedef pthread_mutex_t StreamMutex;
584 #else // Setup for "dummy" behavior
586 #define __RTAUDIO_DUMMY__
587 typedef int ThreadHandle;
588 typedef int StreamMutex;
595 struct CallbackInfo {
608 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false) {}
625 #pragma pack(push, 1)
634 S24& operator = (
const int& i ) {
635 c3[0] = (i & 0x000000ff);
636 c3[1] = (i & 0x0000ff00) >> 8;
637 c3[2] = (i & 0x00ff0000) >> 16;
641 S24(
const S24& v ) { *
this = v; }
642 S24(
const double& d ) { *
this = (int) d; }
643 S24(
const float& f ) { *
this = (int) f; }
644 S24(
const signed short& s ) { *
this = (int) s; }
645 S24(
const char& c ) { *
this = (int) c; }
648 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
649 if (i & 0x800000) i |= ~0xffffff;
655 #if defined( HAVE_GETTIMEOFDAY )
656 #include <sys/time.h>
685 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
686 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
687 void showWarnings(
bool value ) { showWarnings_ = value; }
692 static const unsigned int MAX_SAMPLE_RATES;
693 static const unsigned int SAMPLE_RATES[];
695 enum { FAILURE, SUCCESS };
716 std::vector<int> inOffset;
717 std::vector<int> outOffset;
722 unsigned int device[2];
728 bool doConvertBuffer[2];
729 bool userInterleaved;
730 bool deviceInterleaved[2];
732 unsigned int sampleRate;
733 unsigned int bufferSize;
734 unsigned int nBuffers;
735 unsigned int nUserChannels[2];
736 unsigned int nDeviceChannels[2];
737 unsigned int channelOffset[2];
738 unsigned long latency[2];
742 CallbackInfo callbackInfo;
743 ConvertInfo convertInfo[2];
746 #if defined(HAVE_GETTIMEOFDAY)
747 struct timeval lastTickTimestamp;
751 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
755 typedef signed short Int16;
756 typedef signed int Int32;
757 typedef float Float32;
758 typedef double Float64;
760 std::ostringstream errorStream_;
761 std::string errorText_;
764 bool firstErrorOccurred_;
773 virtual bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
774 unsigned int firstChannel,
unsigned int sampleRate,
779 void tickStreamTime(
void );
782 void clearStreamInfo();
788 void verifyStream(
void );
797 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
800 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
806 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
833 #if defined(__MACOSX_CORE__)
835 #include <CoreAudio/AudioHardware.h>
837 class RtApiCore:
public RtApi
858 bool callbackEvent( AudioDeviceID deviceId,
859 const AudioBufferList *inBufferList,
860 const AudioBufferList *outBufferList );
864 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
865 unsigned int firstChannel,
unsigned int sampleRate,
868 static const char* getErrorCode( OSStatus code );
873 #if defined(__UNIX_JACK__)
875 class RtApiJack:
public RtApi
894 bool callbackEvent(
unsigned long nframes );
898 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
899 unsigned int firstChannel,
unsigned int sampleRate,
906 #if defined(__WINDOWS_ASIO__)
908 class RtApiAsio:
public RtApi
927 bool callbackEvent(
long bufferIndex );
931 std::vector<RtAudio::DeviceInfo> devices_;
932 void saveDeviceInfo(
void );
934 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
935 unsigned int firstChannel,
unsigned int sampleRate,
942 #if defined(__WINDOWS_DS__)
944 class RtApiDs:
public RtApi
965 void callbackEvent(
void );
971 long duplexPrerollBytes;
972 std::vector<struct DsDevice> dsDevices;
973 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
974 unsigned int firstChannel,
unsigned int sampleRate,
981 #if defined(__WINDOWS_WASAPI__)
983 struct IMMDeviceEnumerator;
985 class RtApiWasapi :
public RtApi
1002 bool coInitialized_;
1003 IMMDeviceEnumerator* deviceEnumerator_;
1005 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1006 unsigned int firstChannel,
unsigned int sampleRate,
1010 static DWORD WINAPI runWasapiThread(
void* wasapiPtr );
1011 static DWORD WINAPI stopWasapiThread(
void* wasapiPtr );
1012 static DWORD WINAPI abortWasapiThread(
void* wasapiPtr );
1013 void wasapiThread();
1018 #if defined(__LINUX_ALSA__)
1020 class RtApiAlsa:
public RtApi
1038 void callbackEvent(
void );
1042 std::vector<RtAudio::DeviceInfo> devices_;
1043 void saveDeviceInfo(
void );
1044 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1045 unsigned int firstChannel,
unsigned int sampleRate,
1052 #if defined(__LINUX_PULSE__)
1054 class RtApiPulse:
public RtApi
1070 void callbackEvent(
void );
1074 std::vector<RtAudio::DeviceInfo> devices_;
1075 void saveDeviceInfo(
void );
1076 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1077 unsigned int firstChannel,
unsigned int sampleRate,
1084 #if defined(__LINUX_OSS__)
1086 class RtApiOss:
public RtApi
1104 void callbackEvent(
void );
1108 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1109 unsigned int firstChannel,
unsigned int sampleRate,
1116 #if defined(__RTAUDIO_DUMMY__)
1118 class RtApiDummy:
public RtApi
1122 RtApiDummy() { errorText_ =
"RtApiDummy: This class provides no functionality."; error(
RtAudioError::WARNING ); }
1133 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1134 unsigned int ,
unsigned int ,