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
223 unsigned int nFrames,
249 const std::string &errorText )>
290 unsigned int outputChannels{};
291 unsigned int inputChannels{};
292 unsigned int duplexChannels{};
293 bool isDefaultOutput{
false};
294 bool isDefaultInput{
false};
296 unsigned int currentSampleRate{};
297 unsigned int preferredSampleRate{};
304 unsigned int deviceId{};
305 unsigned int nChannels{};
306 unsigned int firstChannel{};
370 unsigned int numberOfBuffers{};
452 unsigned int getDeviceCount(
void );
465 std::vector<unsigned int> getDeviceIds(
void );
475 std::vector<std::string> getDeviceNames(
void );
499 unsigned int getDefaultOutputDevice(
void );
508 unsigned int getDefaultInputDevice(
void );
560 void closeStream(
void );
592 const std::string getErrorText(
void );
595 bool isStreamOpen(
void )
const;
598 bool isStreamRunning(
void )
const;
608 double getStreamTime(
void );
611 void setStreamTime(
double time );
622 long getStreamLatency(
void );
630 unsigned int getStreamSampleRate(
void );
641 void showWarnings(
bool value =
true );
659 typedef uintptr_t ThreadHandle;
660 typedef CRITICAL_SECTION StreamMutex;
667 typedef pthread_t ThreadHandle;
668 typedef pthread_mutex_t StreamMutex;
673#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
674 || defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
675 || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
677 #define __RTAUDIO_DUMMY__
686 ThreadHandle thread{};
690 bool isRunning{
false};
691 bool doRealtime{
false};
693 bool deviceDisconnected{
false};
719 S24& operator = (
const int& i ) {
720 c3[0] = (
unsigned char)(i & 0x000000ff);
721 c3[1] = (
unsigned char)((i & 0x0000ff00) >> 8);
722 c3[2] = (
unsigned char)((i & 0x00ff0000) >> 16);
726 S24(
const double& d ) { *
this = (int) d; }
727 S24(
const float& f ) { *
this = (int) f; }
728 S24(
const signed short& s ) { *
this = (int) s; }
729 S24(
const char& c ) { *
this = (int) c; }
732 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
733 if (i & 0x800000) i |= ~0xffffff;
739#if defined( HAVE_GETTIMEOFDAY )
740 #include <sys/time.h>
745class RTAUDIO_DLL_PUBLIC RtApi
752 unsigned int getDeviceCount(
void );
753 std::vector<unsigned int> getDeviceIds(
void );
754 std::vector<std::string> getDeviceNames(
void );
756 virtual unsigned int getDefaultInputDevice(
void );
757 virtual unsigned int getDefaultOutputDevice(
void );
763 virtual void closeStream(
void );
767 const std::string getErrorText(
void )
const {
return errorText_; }
768 long getStreamLatency(
void );
769 unsigned int getStreamSampleRate(
void );
770 virtual double getStreamTime(
void )
const {
return stream_.streamTime; }
771 virtual void setStreamTime(
double time );
772 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
773 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
775 void showWarnings(
bool value ) { showWarnings_ = value; }
780 static const unsigned int MAX_SAMPLE_RATES;
781 static const unsigned int SAMPLE_RATES[];
783 enum { FAILURE, SUCCESS };
804 std::vector<int> inOffset;
805 std::vector<int> outOffset;
810 unsigned int deviceId[2];
816 bool doConvertBuffer[2];
817 bool userInterleaved;
818 bool deviceInterleaved[2];
820 unsigned int sampleRate;
821 unsigned int bufferSize;
822 unsigned int nBuffers;
823 unsigned int nUserChannels[2];
824 unsigned int nDeviceChannels[2];
825 unsigned int channelOffset[2];
826 unsigned long latency[2];
830 CallbackInfo callbackInfo;
831 ConvertInfo convertInfo[2];
834#if defined(HAVE_GETTIMEOFDAY)
835 struct timeval lastTickTimestamp;
839 :apiHandle(0), deviceBuffer(0) {}
843 typedef signed short Int16;
844 typedef signed int Int32;
845 typedef float Float32;
846 typedef double Float64;
848 std::ostringstream errorStream_;
849 std::string errorText_;
852 std::vector<RtAudio::DeviceInfo> deviceList_;
853 unsigned int currentDeviceId_;
864 virtual void probeDevices(
void );
873 virtual bool probeDeviceOpen(
unsigned int deviceId, StreamMode mode,
unsigned int channels,
874 unsigned int firstChannel,
unsigned int sampleRate,
879 void tickStreamTime(
void );
882 void clearStreamInfo();
891 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
894 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
900 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition: RtAudio.h:159
std::function< void(RtAudioErrorType type, const std::string &errorText)> RtAudioErrorCallback
RtAudio error callback function prototype.
Definition: RtAudio.h:250
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition: RtAudio.h:178
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition: RtAudio.h:222
unsigned long RtAudioFormat
RtAudio data format type.
Definition: RtAudio.h:105
RtAudioErrorType
Definition: RtAudio.h:228
@ RTAUDIO_DEVICE_DISCONNECT
Definition: RtAudio.h:234
@ RTAUDIO_DRIVER_ERROR
Definition: RtAudio.h:238
@ RTAUDIO_NO_ERROR
Definition: RtAudio.h:229
@ RTAUDIO_INVALID_PARAMETER
Definition: RtAudio.h:236
@ RTAUDIO_INVALID_DEVICE
Definition: RtAudio.h:233
@ RTAUDIO_SYSTEM_ERROR
Definition: RtAudio.h:239
@ RTAUDIO_WARNING
Definition: RtAudio.h:230
@ RTAUDIO_THREAD_ERROR
Definition: RtAudio.h:240
@ RTAUDIO_INVALID_USE
Definition: RtAudio.h:237
@ RTAUDIO_UNKNOWN_ERROR
Definition: RtAudio.h:231
@ RTAUDIO_NO_DEVICES_FOUND
Definition: RtAudio.h:232
@ RTAUDIO_MEMORY_ERROR
Definition: RtAudio.h:235
Realtime audio i/o C++ classes.
Definition: RtAudio.h:268
static RtAudio::Api getCompiledApiByDisplayName(const std::string &name)
Return the compiled audio API having the given display name.
std::string name
Definition: RtAudio.h:289
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the (open) stream.
Definition: RtAudio.h:924
std::string streamName
Definition: RtAudio.h:371
RtAudio::DeviceInfo getDeviceInfo(unsigned int deviceId)
Return an RtAudio::DeviceInfo structure for a specified device ID.
Definition: RtAudio.h:911
double getStreamTime(void)
Returns the number of seconds of processed data since the stream was started.
Definition: RtAudio.h:925
unsigned int getDefaultOutputDevice(void)
A function that returns the ID of the default output device.
Definition: RtAudio.h:915
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open.
Definition: RtAudio.h:922
RtAudioErrorType stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played.
Definition: RtAudio.h:918
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available.
Definition: RtAudio.h:910
static std::string getApiName(RtAudio::Api api)
Return the name of a specified compiled audio API.
const std::string getErrorText(void)
Retrieve the error message corresponding to the last error or warning condition.
Definition: RtAudio.h:920
static std::string getApiDisplayName(RtAudio::Api api)
Return the display name of a specified compiled audio API.
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio.
Definition: RtAudio.h:909
long getStreamLatency(void)
Returns the internal stream latency in sample frames.
Definition: RtAudio.h:923
void closeStream(void)
A function that closes a stream and frees any associated stream memory.
Definition: RtAudio.h:916
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.
std::vector< std::string > getDeviceNames(void)
A public function that returns a vector of audio device names.
Definition: RtAudio.h:913
RtAudioErrorType startStream(void)
A function that starts a stream.
Definition: RtAudio.h:917
bool isStreamOpen(void) const
Returns true if a stream is open and false if not.
Definition: RtAudio.h:921
RtAudioErrorType abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue.
Definition: RtAudio.h:919
~RtAudio()
The destructor.
static RtAudio::Api getCompiledApiByName(const std::string &name)
Return the compiled audio API having the given name.
unsigned int getDefaultInputDevice(void)
A function that returns the ID of the default input device.
Definition: RtAudio.h:914
std::vector< unsigned int > getDeviceIds(void)
A public function that returns a vector of audio device IDs.
Definition: RtAudio.h:912
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0.
Definition: RtAudio.h:926
void setErrorCallback(RtAudioErrorCallback errorCallback)
Set a client-defined function that will be invoked when an error or warning occurs.
Definition: RtAudio.h:927
Api
Audio API specifier arguments.
Definition: RtAudio.h:272
@ WINDOWS_ASIO
Definition: RtAudio.h:279
@ WINDOWS_DS
Definition: RtAudio.h:281
@ LINUX_OSS
Definition: RtAudio.h:278
@ UNIX_JACK
Definition: RtAudio.h:276
@ MACOSX_CORE
Definition: RtAudio.h:274
@ UNSPECIFIED
Definition: RtAudio.h:273
@ LINUX_ALSA
Definition: RtAudio.h:275
@ RTAUDIO_DUMMY
Definition: RtAudio.h:282
@ WINDOWS_WASAPI
Definition: RtAudio.h:280
@ LINUX_PULSE
Definition: RtAudio.h:277
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.
void showWarnings(bool value=true)
Specify whether warning messages should be output or not.
Definition: RtAudio.h:928
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:295
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:287
The structure for specifying stream options.
Definition: RtAudio.h:368
The structure for specifying input or output stream parameters.
Definition: RtAudio.h:302