49#define RTAUDIO_VERSION_MAJOR 6
50#define RTAUDIO_VERSION_MINOR 0
51#define RTAUDIO_VERSION_PATCH 1
52#define RTAUDIO_VERSION_BETA 0
54#define RTAUDIO_TOSTRING2(n) #n
55#define RTAUDIO_TOSTRING(n) RTAUDIO_TOSTRING2(n)
57#if RTAUDIO_VERSION_BETA > 0
58 #define RTAUDIO_VERSION RTAUDIO_TOSTRING(RTAUDIO_VERSION_MAJOR) \
59 "." RTAUDIO_TOSTRING(RTAUDIO_VERSION_MINOR) \
60 "." RTAUDIO_TOSTRING(RTAUDIO_VERSION_PATCH) \
61 "beta" RTAUDIO_TOSTRING(RTAUDIO_VERSION_BETA)
63 #define RTAUDIO_VERSION RTAUDIO_TOSTRING(RTAUDIO_VERSION_MAJOR) \
64 "." RTAUDIO_TOSTRING(RTAUDIO_VERSION_MINOR) \
65 "." RTAUDIO_TOSTRING(RTAUDIO_VERSION_PATCH)
68#if defined _WIN32 || defined __CYGWIN__
69 #if defined(RTAUDIO_EXPORT)
70 #define RTAUDIO_DLL_PUBLIC __declspec(dllexport)
72 #define RTAUDIO_DLL_PUBLIC
76 #define RTAUDIO_DLL_PUBLIC __attribute__( (visibility( "default" )) )
78 #define RTAUDIO_DLL_PUBLIC
223typedef std::function<int(
void* outputBuffer,
void* inputBuffer,
224 unsigned int nFrames,
250 const std::string &errorText )>
291 unsigned int outputChannels{};
292 unsigned int inputChannels{};
293 unsigned int duplexChannels{};
294 bool isDefaultOutput{
false};
295 bool isDefaultInput{
false};
297 unsigned int currentSampleRate{};
298 unsigned int preferredSampleRate{};
305 unsigned int deviceId{};
306 unsigned int nChannels{};
307 unsigned int firstChannel{};
371 unsigned int numberOfBuffers{};
453 unsigned int getDeviceCount(
void );
466 std::vector<unsigned int> getDeviceIds(
void );
476 std::vector<std::string> getDeviceNames(
void );
500 unsigned int getDefaultOutputDevice(
void );
509 unsigned int getDefaultInputDevice(
void );
561 void closeStream(
void );
593 const std::string &getErrorText(
void);
596 bool isStreamOpen(
void )
const;
599 bool isStreamRunning(
void )
const;
609 double getStreamTime(
void );
612 void setStreamTime(
double time );
623 long getStreamLatency(
void );
631 unsigned int getStreamSampleRate(
void );
642 void showWarnings(
bool value =
true );
660 typedef uintptr_t ThreadHandle;
661 typedef CRITICAL_SECTION StreamMutex;
668 typedef pthread_t ThreadHandle;
669 typedef pthread_mutex_t StreamMutex;
674#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
675 || defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
676 || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
678 #define __RTAUDIO_DUMMY__
687 ThreadHandle thread{};
691 bool isRunning{
false};
692 bool doRealtime{
false};
694 bool deviceDisconnected{
false};
720 S24& operator = (
const int& i ) {
721 c3[0] = (
unsigned char)(i & 0x000000ff);
722 c3[1] = (
unsigned char)((i & 0x0000ff00) >> 8);
723 c3[2] = (
unsigned char)((i & 0x00ff0000) >> 16);
727 S24(
const double& d ) { *
this = (int) d; }
728 S24(
const float& f ) { *
this = (int) f; }
729 S24(
const signed short& s ) { *
this = (int) s; }
730 S24(
const char& c ) { *
this = (int) c; }
733 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
734 if (i & 0x800000) i |= ~0xffffff;
740#if defined( HAVE_GETTIMEOFDAY )
741 #include <sys/time.h>
746class RTAUDIO_DLL_PUBLIC RtApi
753 unsigned int getDeviceCount(
void );
754 std::vector<unsigned int> getDeviceIds(
void );
755 std::vector<std::string> getDeviceNames(
void );
757 virtual unsigned int getDefaultInputDevice(
void );
758 virtual unsigned int getDefaultOutputDevice(
void );
764 virtual void closeStream(
void );
768 const std::string &getErrorText(
void)
const {
return errorText_; }
769 long getStreamLatency(
void );
770 unsigned int getStreamSampleRate(
void );
771 virtual double getStreamTime(
void )
const {
return stream_.streamTime; }
772 virtual void setStreamTime(
double time );
773 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
774 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
776 void showWarnings(
bool value ) { showWarnings_ = value; }
781 static const unsigned int MAX_SAMPLE_RATES;
782 static const unsigned int SAMPLE_RATES[];
784 enum { FAILURE, SUCCESS };
805 std::vector<int> inOffset;
806 std::vector<int> outOffset;
811 unsigned int deviceId[2];
817 bool doConvertBuffer[2];
818 bool userInterleaved;
819 bool deviceInterleaved[2];
821 unsigned int sampleRate;
822 unsigned int bufferSize;
823 unsigned int nBuffers;
824 unsigned int nUserChannels[2];
825 unsigned int nDeviceChannels[2];
826 unsigned int channelOffset[2];
827 unsigned long latency[2];
831 CallbackInfo callbackInfo;
832 ConvertInfo convertInfo[2];
835#if defined(HAVE_GETTIMEOFDAY)
836 struct timeval lastTickTimestamp;
840 :apiHandle(0), deviceBuffer(0) {}
844 typedef signed short Int16;
845 typedef signed int Int32;
846 typedef float Float32;
847 typedef double Float64;
849 std::ostringstream errorStream_;
850 std::string errorText_;
853 std::vector<RtAudio::DeviceInfo> deviceList_;
854 unsigned int currentDeviceId_;
865 virtual void probeDevices(
void );
874 virtual bool probeDeviceOpen(
unsigned int deviceId, StreamMode mode,
unsigned int channels,
875 unsigned int firstChannel,
unsigned int sampleRate,
880 void tickStreamTime(
void );
883 void clearStreamInfo();
892 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
895 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
901 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
910inline RtAudio::Api RtAudio :: getCurrentApi(
void ) {
return rtapi_->getCurrentApi(); }
911inline unsigned int RtAudio :: getDeviceCount(
void ) {
return rtapi_->getDeviceCount(); }
912inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo(
unsigned int deviceId ) {
return rtapi_->getDeviceInfo( deviceId ); }
913inline std::vector<unsigned int> RtAudio :: getDeviceIds(
void ) {
return rtapi_->getDeviceIds(); }
914inline std::vector<std::string> RtAudio :: getDeviceNames(
void ) {
return rtapi_->getDeviceNames(); }
915inline unsigned int RtAudio :: getDefaultInputDevice(
void ) {
return rtapi_->getDefaultInputDevice(); }
916inline unsigned int RtAudio :: getDefaultOutputDevice(
void ) {
return rtapi_->getDefaultOutputDevice(); }
917inline void RtAudio :: closeStream(
void ) {
return rtapi_->closeStream(); }
922inline bool RtAudio :: isStreamOpen(
void )
const {
return rtapi_->isStreamOpen(); }
923inline bool RtAudio :: isStreamRunning(
void )
const {
return rtapi_->isStreamRunning(); }
924inline long RtAudio :: getStreamLatency(
void ) {
return rtapi_->getStreamLatency(); }
925inline unsigned int RtAudio :: getStreamSampleRate(
void ) {
return rtapi_->getStreamSampleRate(); }
926inline double RtAudio :: getStreamTime(
void ) {
return rtapi_->getStreamTime(); }
927inline void RtAudio :: setStreamTime(
double time ) {
return rtapi_->setStreamTime( time ); }
928inline void RtAudio :: setErrorCallback(
RtAudioErrorCallback errorCallback ) { rtapi_->setErrorCallback( errorCallback ); }
929inline void RtAudio :: showWarnings(
bool value ) { rtapi_->showWarnings( value ); }
std::function< void(RtAudioErrorType type, const std::string &errorText)> RtAudioErrorCallback
RtAudio error callback function prototype.
Definition RtAudio.h:251
unsigned long RtAudioFormat
RtAudio data format type.
Definition RtAudio.h:105
RtAudioErrorType
Definition RtAudio.h:229
@ RTAUDIO_DEVICE_DISCONNECT
Definition RtAudio.h:235
@ RTAUDIO_DRIVER_ERROR
Definition RtAudio.h:239
@ RTAUDIO_NO_ERROR
Definition RtAudio.h:230
@ RTAUDIO_INVALID_PARAMETER
Definition RtAudio.h:237
@ RTAUDIO_INVALID_DEVICE
Definition RtAudio.h:234
@ RTAUDIO_SYSTEM_ERROR
Definition RtAudio.h:240
@ RTAUDIO_WARNING
Definition RtAudio.h:231
@ RTAUDIO_THREAD_ERROR
Definition RtAudio.h:241
@ RTAUDIO_INVALID_USE
Definition RtAudio.h:238
@ RTAUDIO_UNKNOWN_ERROR
Definition RtAudio.h:232
@ RTAUDIO_NO_DEVICES_FOUND
Definition RtAudio.h:233
@ RTAUDIO_MEMORY_ERROR
Definition RtAudio.h:236
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition RtAudio.h:159
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition RtAudio.h:178
std::function< int(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)> RtAudioCallback
RtAudio callback function prototype.
Definition RtAudio.h:227
Realtime audio i/o C++ classes.
Definition RtAudio.h:269
static RtAudio::Api getCompiledApiByDisplayName(const std::string &name)
Return the compiled audio API having the given display name.
std::string name
Definition RtAudio.h:290
std::string streamName
Definition RtAudio.h:372
static std::string getApiName(RtAudio::Api api)
Return the name of a specified compiled audio API.
static std::string getApiDisplayName(RtAudio::Api api)
Return the display name of a specified compiled audio API.
RtAudioErrorType openStream(RtAudio::StreamParameters *outputParameters, RtAudio::StreamParameters *inputParameters, RtAudioFormat format, unsigned int sampleRate, unsigned int *bufferFrames, RtAudioCallback callback, void *userData=NULL, RtAudio::StreamOptions *options=NULL)
A public function for opening a stream with the specified parameters.
const std::string & getErrorText(void)
Retrieve the error message corresponding to the last error or warning condition.
Definition RtAudio.h:921
~RtAudio()
The destructor.
static RtAudio::Api getCompiledApiByName(const std::string &name)
Return the compiled audio API having the given name.
Api
Audio API specifier arguments.
Definition RtAudio.h:273
@ WINDOWS_ASIO
Definition RtAudio.h:280
@ WINDOWS_DS
Definition RtAudio.h:282
@ LINUX_OSS
Definition RtAudio.h:279
@ UNIX_JACK
Definition RtAudio.h:277
@ MACOSX_CORE
Definition RtAudio.h:275
@ UNSPECIFIED
Definition RtAudio.h:274
@ LINUX_ALSA
Definition RtAudio.h:276
@ RTAUDIO_DUMMY
Definition RtAudio.h:283
@ WINDOWS_WASAPI
Definition RtAudio.h:281
@ LINUX_PULSE
Definition RtAudio.h:278
RtAudio(RtAudio::Api api=UNSPECIFIED, RtAudioErrorCallback &&errorCallback=0)
The class constructor.
static void getCompiledApi(std::vector< RtAudio::Api > &apis)
A static function to determine the available compiled audio APIs.
std::vector< unsigned int > sampleRates
Definition RtAudio.h:296
static std::string getVersion(void)
A static function to determine the current RtAudio version.
The public device information structure for returning queried values.
Definition RtAudio.h:288
The structure for specifying stream options.
Definition RtAudio.h:369
The structure for specifying input or output stream parameters.
Definition RtAudio.h:303