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{};
376 static std::string getVersion(
void );
384 static void getCompiledApi( std::vector<RtAudio::Api> &apis );
399 static std::string getApiDisplayName(
RtAudio::Api api );
407 static RtAudio::Api getCompiledApiByName(
const std::string &name );
415 static RtAudio::Api getCompiledApiByDisplayName(
const std::string &name );
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 );
650 #if defined(_MSC_VER)
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__
684 struct CallbackInfo {
686 ThreadHandle thread{};
690 bool isRunning{
false};
691 bool doRealtime{
false};
693 bool deviceDisconnected{
false};
710 #pragma pack(push, 1)
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>
745 class 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 );
RtAudioErrorType startStream(void)
A function that starts a stream.
Definition: RtAudio.h:917
unsigned long RtAudioFormat
RtAudio data format type.
Definition: RtAudio.h:105
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition: RtAudio.h:178
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open.
Definition: RtAudio.h:922
const std::string getErrorText(void)
Retrieve the error message corresponding to the last error or warning condition.
Definition: RtAudio.h:920
std::function< void(RtAudioErrorType type, const std::string &errorText)> RtAudioErrorCallback
RtAudio error callback function prototype.
Definition: RtAudio.h:250
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition: RtAudio.h:222
bool isStreamOpen(void) const
Returns true if a stream is open and false if not.
Definition: RtAudio.h:921
Definition: RtAudio.h:280
Api
Audio API specifier arguments.
Definition: RtAudio.h:272
Definition: RtAudio.h:231
Definition: RtAudio.h:273
Definition: RtAudio.h:236
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:295
void showWarnings(bool value=true)
Specify whether warning messages should be output or not.
Definition: RtAudio.h:928
Definition: RtAudio.h:237
Definition: RtAudio.h:279
long getStreamLatency(void)
Returns the internal stream latency in sample frames.
Definition: RtAudio.h:923
Definition: RtAudio.h:275
RtAudioErrorType
Definition: RtAudio.h:228
unsigned int getDefaultInputDevice(void)
A function that returns the ID of the default input device.
Definition: RtAudio.h:914
The structure for specifying input or output stream parameters.
Definition: RtAudio.h:302
std::vector< std::string > getDeviceNames(void)
A public function that returns a vector of audio device names.
Definition: RtAudio.h:913
Definition: RtAudio.h:274
Definition: RtAudio.h:277
double getStreamTime(void)
Returns the number of seconds of processed data since the stream was started.
Definition: RtAudio.h:925
The public device information structure for returning queried values.
Definition: RtAudio.h:287
Definition: RtAudio.h:235
Definition: RtAudio.h:232
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio.
Definition: RtAudio.h:909
Definition: RtAudio.h:230
Definition: RtAudio.h:240
Definition: RtAudio.h:239
void setErrorCallback(RtAudioErrorCallback errorCallback)
Set a client-defined function that will be invoked when an error or warning occurs.
Definition: RtAudio.h:927
RtAudioErrorType abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue.
Definition: RtAudio.h:919
std::string name
Definition: RtAudio.h:289
The structure for specifying stream options.
Definition: RtAudio.h:368
Definition: RtAudio.h:281
Definition: RtAudio.h:282
void closeStream(void)
A function that closes a stream and frees any associated stream memory.
Definition: RtAudio.h:916
Definition: RtAudio.h:229
Definition: RtAudio.h:233
Definition: RtAudio.h:234
RtAudioErrorType stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played.
Definition: RtAudio.h:918
Definition: RtAudio.h:278
std::string streamName
Definition: RtAudio.h:371
std::vector< unsigned int > getDeviceIds(void)
A public function that returns a vector of audio device IDs.
Definition: RtAudio.h:912
Definition: RtAudio.h:238
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition: RtAudio.h:159
RtAudio::DeviceInfo getDeviceInfo(unsigned int deviceId)
Return an RtAudio::DeviceInfo structure for a specified device ID.
Definition: RtAudio.h:911
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0.
Definition: RtAudio.h:926
Realtime audio i/o C++ classes.
Definition: RtAudio.h:267
unsigned int getDefaultOutputDevice(void)
A function that returns the ID of the default output device.
Definition: RtAudio.h:915
Definition: RtAudio.h:276
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available.
Definition: RtAudio.h:910
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the (open) stream.
Definition: RtAudio.h:924