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
224typedef std::function<int(
void* outputBuffer,
void* inputBuffer,
225 unsigned int nFrames,
251 const std::string &errorText )>
292 unsigned int outputChannels{};
293 unsigned int inputChannels{};
294 unsigned int duplexChannels{};
295 bool isDefaultOutput{
false};
296 bool isDefaultInput{
false};
298 unsigned int currentSampleRate{};
299 unsigned int preferredSampleRate{};
306 unsigned int deviceId{};
307 unsigned int nChannels{};
308 unsigned int firstChannel{};
372 unsigned int numberOfBuffers{};
454 unsigned int getDeviceCount(
void );
467 std::vector<unsigned int> getDeviceIds(
void );
477 std::vector<std::string> getDeviceNames(
void );
501 unsigned int getDefaultOutputDevice(
void );
510 unsigned int getDefaultInputDevice(
void );
562 void closeStream(
void );
594 const std::string &getErrorText(
void);
597 bool isStreamOpen(
void )
const;
600 bool isStreamRunning(
void )
const;
610 double getStreamTime(
void );
613 void setStreamTime(
double time );
624 long getStreamLatency(
void );
632 unsigned int getStreamSampleRate(
void );
643 void showWarnings(
bool value =
true );
648 std::shared_ptr<RtApi> rtapi_;
661 typedef uintptr_t ThreadHandle;
662 typedef CRITICAL_SECTION StreamMutex;
669 typedef pthread_t ThreadHandle;
670 typedef pthread_mutex_t StreamMutex;
675#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
676 || defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
677 || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
679 #define __RTAUDIO_DUMMY__
688 ThreadHandle thread{};
692 bool isRunning{
false};
693 bool doRealtime{
false};
695 bool deviceDisconnected{
false};
721 S24& operator = (
const int& i ) {
722 c3[0] = (
unsigned char)(i & 0x000000ff);
723 c3[1] = (
unsigned char)((i & 0x0000ff00) >> 8);
724 c3[2] = (
unsigned char)((i & 0x00ff0000) >> 16);
728 S24(
const double& d ) { *
this = (int) d; }
729 S24(
const float& f ) { *
this = (int) f; }
730 S24(
const signed short& s ) { *
this = (int) s; }
731 S24(
const char& c ) { *
this = (int) c; }
734 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
735 if (i & 0x800000) i |= ~0xffffff;
741#if defined( HAVE_GETTIMEOFDAY )
742 #include <sys/time.h>
747class RTAUDIO_DLL_PUBLIC RtApi
754 unsigned int getDeviceCount(
void );
755 std::vector<unsigned int> getDeviceIds(
void );
756 std::vector<std::string> getDeviceNames(
void );
758 virtual unsigned int getDefaultInputDevice(
void );
759 virtual unsigned int getDefaultOutputDevice(
void );
765 virtual void closeStream(
void );
769 const std::string &getErrorText(
void)
const {
return errorText_; }
770 long getStreamLatency(
void );
771 unsigned int getStreamSampleRate(
void );
772 virtual double getStreamTime(
void )
const {
return stream_.streamTime; }
773 virtual void setStreamTime(
double time );
774 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
775 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
777 void showWarnings(
bool value ) { showWarnings_ = value; }
782 static const unsigned int MAX_SAMPLE_RATES;
783 static const unsigned int SAMPLE_RATES[];
785 enum { FAILURE, SUCCESS };
806 std::vector<int> inOffset;
807 std::vector<int> outOffset;
812 unsigned int deviceId[2];
818 bool doConvertBuffer[2];
819 bool userInterleaved;
820 bool deviceInterleaved[2];
822 unsigned int sampleRate;
823 unsigned int bufferSize;
824 unsigned int nBuffers;
825 unsigned int nUserChannels[2];
826 unsigned int nDeviceChannels[2];
827 unsigned int channelOffset[2];
828 unsigned long latency[2];
832 CallbackInfo callbackInfo;
833 ConvertInfo convertInfo[2];
836#if defined(HAVE_GETTIMEOFDAY)
837 struct timeval lastTickTimestamp;
841 :apiHandle(0), deviceBuffer(0) {}
845 typedef signed short Int16;
846 typedef signed int Int32;
847 typedef float Float32;
848 typedef double Float64;
850 std::ostringstream errorStream_;
851 std::string errorText_;
854 std::vector<RtAudio::DeviceInfo> deviceList_;
855 unsigned int currentDeviceId_;
866 virtual void probeDevices(
void );
875 virtual bool probeDeviceOpen(
unsigned int deviceId, StreamMode mode,
unsigned int channels,
876 unsigned int firstChannel,
unsigned int sampleRate,
881 void tickStreamTime(
void );
884 void clearStreamInfo();
893 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
896 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
902 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
911inline RtAudio::Api RtAudio :: getCurrentApi(
void ) {
return rtapi_->getCurrentApi(); }
912inline unsigned int RtAudio :: getDeviceCount(
void ) {
return rtapi_->getDeviceCount(); }
913inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo(
unsigned int deviceId ) {
return rtapi_->getDeviceInfo( deviceId ); }
914inline std::vector<unsigned int> RtAudio :: getDeviceIds(
void ) {
return rtapi_->getDeviceIds(); }
915inline std::vector<std::string> RtAudio :: getDeviceNames(
void ) {
return rtapi_->getDeviceNames(); }
916inline unsigned int RtAudio :: getDefaultInputDevice(
void ) {
return rtapi_->getDefaultInputDevice(); }
917inline unsigned int RtAudio :: getDefaultOutputDevice(
void ) {
return rtapi_->getDefaultOutputDevice(); }
918inline void RtAudio :: closeStream(
void ) {
return rtapi_->closeStream(); }
923inline bool RtAudio :: isStreamOpen(
void )
const {
return rtapi_->isStreamOpen(); }
924inline bool RtAudio :: isStreamRunning(
void )
const {
return rtapi_->isStreamRunning(); }
925inline long RtAudio :: getStreamLatency(
void ) {
return rtapi_->getStreamLatency(); }
926inline unsigned int RtAudio :: getStreamSampleRate(
void ) {
return rtapi_->getStreamSampleRate(); }
927inline double RtAudio :: getStreamTime(
void ) {
return rtapi_->getStreamTime(); }
928inline void RtAudio :: setStreamTime(
double time ) {
return rtapi_->setStreamTime( time ); }
929inline void RtAudio :: setErrorCallback(
RtAudioErrorCallback errorCallback ) { rtapi_->setErrorCallback( errorCallback ); }
930inline 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:252
unsigned long RtAudioFormat
RtAudio data format type.
Definition RtAudio.h:106
RtAudioErrorType
Definition RtAudio.h:230
@ RTAUDIO_DEVICE_DISCONNECT
Definition RtAudio.h:236
@ RTAUDIO_DRIVER_ERROR
Definition RtAudio.h:240
@ RTAUDIO_NO_ERROR
Definition RtAudio.h:231
@ RTAUDIO_INVALID_PARAMETER
Definition RtAudio.h:238
@ RTAUDIO_INVALID_DEVICE
Definition RtAudio.h:235
@ RTAUDIO_SYSTEM_ERROR
Definition RtAudio.h:241
@ RTAUDIO_WARNING
Definition RtAudio.h:232
@ RTAUDIO_THREAD_ERROR
Definition RtAudio.h:242
@ RTAUDIO_INVALID_USE
Definition RtAudio.h:239
@ RTAUDIO_UNKNOWN_ERROR
Definition RtAudio.h:233
@ RTAUDIO_NO_DEVICES_FOUND
Definition RtAudio.h:234
@ RTAUDIO_MEMORY_ERROR
Definition RtAudio.h:237
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition RtAudio.h:160
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition RtAudio.h:179
std::function< int(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)> RtAudioCallback
RtAudio callback function prototype.
Definition RtAudio.h:228
Realtime audio i/o C++ classes.
Definition RtAudio.h:270
static RtAudio::Api getCompiledApiByDisplayName(const std::string &name)
Return the compiled audio API having the given display name.
std::string name
Definition RtAudio.h:291
std::string streamName
Definition RtAudio.h:373
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:922
~RtAudio()
The destructor.
Definition RtAudio.h:442
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:274
@ WINDOWS_ASIO
Definition RtAudio.h:281
@ WINDOWS_DS
Definition RtAudio.h:283
@ LINUX_OSS
Definition RtAudio.h:280
@ UNIX_JACK
Definition RtAudio.h:278
@ MACOSX_CORE
Definition RtAudio.h:276
@ UNSPECIFIED
Definition RtAudio.h:275
@ LINUX_ALSA
Definition RtAudio.h:277
@ RTAUDIO_DUMMY
Definition RtAudio.h:284
@ WINDOWS_WASAPI
Definition RtAudio.h:282
@ LINUX_PULSE
Definition RtAudio.h:279
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:297
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:289
The structure for specifying stream options.
Definition RtAudio.h:370
The structure for specifying input or output stream parameters.
Definition RtAudio.h:304