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
227typedef std::function<int(
void* outputBuffer,
void* inputBuffer,
228 unsigned int nFrames,
254 const std::string &errorText )>
272class RTAUDIO_DLL_PUBLIC RtAudio
381 static std::string getVersion(
void );
389 static void getCompiledApi( std::vector<RtAudio::Api> &apis );
397 static std::string getApiName( RtAudio::Api api );
404 static std::string getApiDisplayName( RtAudio::Api api );
412 static RtAudio::Api getCompiledApiByName(
const std::string &name );
420 static RtAudio::Api getCompiledApiByDisplayName(
const std::string &name );
448 RtAudio::Api getCurrentApi(
void );
457 unsigned int getDeviceCount(
void );
470 std::vector<unsigned int> getDeviceIds(
void );
480 std::vector<std::string> getDeviceNames(
void );
495 RtAudio::DeviceInfo getDeviceInfo(
unsigned int deviceId );
504 unsigned int getDefaultOutputDevice(
void );
513 unsigned int getDefaultInputDevice(
void );
554 RtAudio::StreamParameters *inputParameters,
557 void *userData = NULL, RtAudio::StreamOptions *options = NULL );
565 void closeStream(
void );
597 const std::string &getErrorText(
void);
600 bool isStreamOpen(
void )
const;
603 bool isStreamRunning(
void )
const;
613 double getStreamTime(
void );
616 void setStreamTime(
double time );
627 long getStreamLatency(
void );
635 unsigned int getStreamSampleRate(
void );
646 void showWarnings(
bool value =
true );
650 void openRtApi( RtAudio::Api api );
651 std::shared_ptr<RtApi> rtapi_;
669 typedef uintptr_t ThreadHandle;
670 typedef CRITICAL_SECTION StreamMutex;
681 typedef pthread_t ThreadHandle;
682 typedef pthread_mutex_t StreamMutex;
689#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
690 || defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
691 || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
693 #define __RTAUDIO_DUMMY__
705 ThreadHandle thread{};
709 bool isRunning{
false};
710 bool doRealtime{
false};
712 bool deviceDisconnected{
false};
738 S24& operator = (
const int& i ) {
739 c3[0] = (
unsigned char)(i & 0x000000ff);
740 c3[1] = (
unsigned char)((i & 0x0000ff00) >> 8);
741 c3[2] = (
unsigned char)((i & 0x00ff0000) >> 16);
745 S24(
const double& d ) { *
this = (int) d; }
746 S24(
const float& f ) { *
this = (int) f; }
747 S24(
const signed short& s ) { *
this = (int) s; }
748 S24(
const char& c ) { *
this = (int) c; }
751 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
752 if (i & 0x800000) i |= ~0xffffff;
761#if defined( HAVE_GETTIMEOFDAY )
762 #include <sys/time.h>
770class RTAUDIO_DLL_PUBLIC RtApi
776 virtual RtAudio::Api getCurrentApi(
void ) = 0;
777 unsigned int getDeviceCount(
void );
778 std::vector<unsigned int> getDeviceIds(
void );
779 std::vector<std::string> getDeviceNames(
void );
780 RtAudio::DeviceInfo getDeviceInfo(
unsigned int deviceId );
781 virtual unsigned int getDefaultInputDevice(
void );
782 virtual unsigned int getDefaultOutputDevice(
void );
784 RtAudio::StreamParameters *inputParameters,
785 RtAudioFormat format,
unsigned int sampleRate,
786 unsigned int *bufferFrames, RtAudioCallback callback,
787 void *userData, RtAudio::StreamOptions *options );
788 virtual void closeStream(
void );
792 const std::string &getErrorText(
void)
const {
return errorText_; }
793 long getStreamLatency(
void );
794 unsigned int getStreamSampleRate(
void );
795 virtual double getStreamTime(
void )
const {
return stream_.streamTime; }
796 virtual void setStreamTime(
double time );
797 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
798 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
799 void setErrorCallback( RtAudioErrorCallback errorCallback ) { errorCallback_ = errorCallback; }
800 void showWarnings(
bool value ) { showWarnings_ = value; }
805 static const unsigned int MAX_SAMPLE_RATES;
806 static const unsigned int SAMPLE_RATES[];
808 enum { FAILURE, SUCCESS };
829 std::vector<int> inOffset;
830 std::vector<int> outOffset;
835 unsigned int deviceId[2];
841 bool doConvertBuffer[2];
842 bool userInterleaved;
843 bool deviceInterleaved[2];
845 unsigned int sampleRate;
846 unsigned int bufferSize;
847 unsigned int nBuffers;
848 unsigned int nUserChannels[2];
849 unsigned int nDeviceChannels[2];
850 unsigned int channelOffset[2];
851 unsigned long latency[2];
855 CallbackInfo callbackInfo;
856 ConvertInfo convertInfo[2];
859#if defined(HAVE_GETTIMEOFDAY)
860 struct timeval lastTickTimestamp;
864 :apiHandle(0), deviceBuffer(0) {}
868 typedef signed short Int16;
869 typedef signed int Int32;
870 typedef float Float32;
871 typedef double Float64;
873 std::ostringstream errorStream_;
874 std::string errorText_;
877 std::vector<RtAudio::DeviceInfo> deviceList_;
878 unsigned int currentDeviceId_;
889 virtual void probeDevices(
void );
898 virtual bool probeDeviceOpen(
unsigned int deviceId, StreamMode mode,
unsigned int channels,
899 unsigned int firstChannel,
unsigned int sampleRate,
900 RtAudioFormat format,
unsigned int *bufferSize,
901 RtAudio::StreamOptions *options );
904 void tickStreamTime(
void );
907 void clearStreamInfo();
916 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
919 void byteSwapBuffer(
char *buffer,
unsigned int samples, RtAudioFormat format );
922 unsigned int formatBytes( RtAudioFormat format );
925 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
934inline RtAudio::Api RtAudio :: getCurrentApi(
void ) {
return rtapi_->getCurrentApi(); }
935inline unsigned int RtAudio :: getDeviceCount(
void ) {
return rtapi_->getDeviceCount(); }
936inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo(
unsigned int deviceId ) {
return rtapi_->getDeviceInfo( deviceId ); }
937inline std::vector<unsigned int> RtAudio :: getDeviceIds(
void ) {
return rtapi_->getDeviceIds(); }
938inline std::vector<std::string> RtAudio :: getDeviceNames(
void ) {
return rtapi_->getDeviceNames(); }
939inline unsigned int RtAudio :: getDefaultInputDevice(
void ) {
return rtapi_->getDefaultInputDevice(); }
940inline unsigned int RtAudio :: getDefaultOutputDevice(
void ) {
return rtapi_->getDefaultOutputDevice(); }
941inline void RtAudio :: closeStream(
void ) {
return rtapi_->closeStream(); }
942inline RtAudioErrorType RtAudio :: startStream(
void ) {
return rtapi_->startStream(); }
943inline RtAudioErrorType RtAudio :: stopStream(
void ) {
return rtapi_->stopStream(); }
944inline RtAudioErrorType RtAudio :: abortStream(
void ) {
return rtapi_->abortStream(); }
945inline const std::string &RtAudio::getErrorText(
void) {
return rtapi_->getErrorText(); }
946inline bool RtAudio :: isStreamOpen(
void )
const {
return rtapi_->isStreamOpen(); }
947inline bool RtAudio :: isStreamRunning(
void )
const {
return rtapi_->isStreamRunning(); }
948inline long RtAudio :: getStreamLatency(
void ) {
return rtapi_->getStreamLatency(); }
949inline unsigned int RtAudio :: getStreamSampleRate(
void ) {
return rtapi_->getStreamSampleRate(); }
950inline double RtAudio :: getStreamTime(
void ) {
return rtapi_->getStreamTime(); }
951inline void RtAudio :: setStreamTime(
double time ) {
return rtapi_->setStreamTime( time ); }
952inline void RtAudio :: setErrorCallback(
RtAudioErrorCallback errorCallback ) { rtapi_->setErrorCallback( errorCallback ); }
953inline void RtAudio :: showWarnings(
bool value ) { rtapi_->showWarnings( value ); }
960#ifndef RTAUDIO_USE_NAMESPACE
961using namespace rt::audio;
std::function< void(RtAudioErrorType type, const std::string &errorText)> RtAudioErrorCallback
RtAudio error callback function prototype.
Definition RtAudio.h:255
unsigned long RtAudioFormat
RtAudio data format type.
Definition RtAudio.h:109
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition RtAudio.h:163
std::function< int(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)> RtAudioCallback
RtAudio callback function prototype.
Definition RtAudio.h:231
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition RtAudio.h:182
RtAudioErrorType
Definition RtAudio.h:233
@ RTAUDIO_DEVICE_DISCONNECT
Definition RtAudio.h:239
@ RTAUDIO_WARNING
Definition RtAudio.h:235
@ RTAUDIO_UNKNOWN_ERROR
Definition RtAudio.h:236
@ RTAUDIO_NO_DEVICES_FOUND
Definition RtAudio.h:237
@ RTAUDIO_SYSTEM_ERROR
Definition RtAudio.h:244
@ RTAUDIO_INVALID_DEVICE
Definition RtAudio.h:238
@ RTAUDIO_DRIVER_ERROR
Definition RtAudio.h:243
@ RTAUDIO_INVALID_PARAMETER
Definition RtAudio.h:241
@ RTAUDIO_THREAD_ERROR
Definition RtAudio.h:245
@ RTAUDIO_NO_ERROR
Definition RtAudio.h:234
@ RTAUDIO_INVALID_USE
Definition RtAudio.h:242
@ RTAUDIO_MEMORY_ERROR
Definition RtAudio.h:240
The public device information structure for returning queried values.
Definition RtAudio.h:292
bool isDefaultOutput
Definition RtAudio.h:298
unsigned int outputChannels
Definition RtAudio.h:295
unsigned int preferredSampleRate
Definition RtAudio.h:302
unsigned int currentSampleRate
Definition RtAudio.h:301
unsigned int inputChannels
Definition RtAudio.h:296
unsigned int duplexChannels
Definition RtAudio.h:297
unsigned int ID
Definition RtAudio.h:293
std::vector< unsigned int > sampleRates
Definition RtAudio.h:300
std::string name
Definition RtAudio.h:294
bool isDefaultInput
Definition RtAudio.h:299
RtAudioFormat nativeFormats
Definition RtAudio.h:303
The structure for specifying stream options.
Definition RtAudio.h:373
RtAudioStreamFlags flags
Definition RtAudio.h:374
int priority
Definition RtAudio.h:377
unsigned int numberOfBuffers
Definition RtAudio.h:375
std::string streamName
Definition RtAudio.h:376
The structure for specifying input or output stream parameters.
Definition RtAudio.h:307
unsigned int nChannels
Definition RtAudio.h:310
unsigned int deviceId
Definition RtAudio.h:309
unsigned int firstChannel
Definition RtAudio.h:311