48 #define RTAUDIO_VERSION "4.1.2"
183 unsigned int nFrames,
223 virtual void printMessage(
void )
const throw() { std::cerr <<
'\n' << message_ <<
"\n\n"; }
229 virtual const std::string&
getMessage(
void)
const throw() {
return message_; }
232 virtual const char*
what(
void )
const throw() {
return message_.c_str(); }
235 std::string message_;
294 :probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
295 isDefaultOutput(false), isDefaultInput(false), preferredSampleRate(0), nativeFormats(0) {}
306 : deviceId(0), nChannels(0), firstChannel(0) {}
374 : flags(0), numberOfBuffers(0), priority(0) {}
378 static std::string
getVersion(
void ) throw();
491 RtAudio::StreamParameters *inputParameters,
577 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
585 typedef uintptr_t ThreadHandle;
586 typedef CRITICAL_SECTION StreamMutex;
588 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
592 typedef pthread_t ThreadHandle;
593 typedef pthread_mutex_t StreamMutex;
595 #else // Setup for "dummy" behavior
597 #define __RTAUDIO_DUMMY__
598 typedef int ThreadHandle;
599 typedef int StreamMutex;
606 struct CallbackInfo {
619 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false) {}
636 #pragma pack(push, 1)
645 S24& operator = (
const int& i ) {
646 c3[0] = (i & 0x000000ff);
647 c3[1] = (i & 0x0000ff00) >> 8;
648 c3[2] = (i & 0x00ff0000) >> 16;
652 S24(
const S24& v ) { *
this = v; }
653 S24(
const double& d ) { *
this = (int) d; }
654 S24(
const float& f ) { *
this = (int) f; }
655 S24(
const signed short& s ) { *
this = (int) s; }
656 S24(
const char& c ) { *
this = (int) c; }
659 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
660 if (i & 0x800000) i |= ~0xffffff;
666 #if defined( HAVE_GETTIMEOFDAY )
667 #include <sys/time.h>
697 bool isStreamOpen(
void )
const {
return stream_.state != STREAM_CLOSED; }
698 bool isStreamRunning(
void )
const {
return stream_.state == STREAM_RUNNING; }
699 void showWarnings(
bool value ) { showWarnings_ = value; }
704 static const unsigned int MAX_SAMPLE_RATES;
705 static const unsigned int SAMPLE_RATES[];
707 enum { FAILURE, SUCCESS };
728 std::vector<int> inOffset;
729 std::vector<int> outOffset;
734 unsigned int device[2];
740 bool doConvertBuffer[2];
741 bool userInterleaved;
742 bool deviceInterleaved[2];
744 unsigned int sampleRate;
745 unsigned int bufferSize;
746 unsigned int nBuffers;
747 unsigned int nUserChannels[2];
748 unsigned int nDeviceChannels[2];
749 unsigned int channelOffset[2];
750 unsigned long latency[2];
754 CallbackInfo callbackInfo;
755 ConvertInfo convertInfo[2];
758 #if defined(HAVE_GETTIMEOFDAY)
759 struct timeval lastTickTimestamp;
763 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
767 typedef signed short Int16;
768 typedef signed int Int32;
769 typedef float Float32;
770 typedef double Float64;
772 std::ostringstream errorStream_;
773 std::string errorText_;
776 bool firstErrorOccurred_;
785 virtual bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
786 unsigned int firstChannel,
unsigned int sampleRate,
791 void tickStreamTime(
void );
794 void clearStreamInfo();
800 void verifyStream(
void );
809 void convertBuffer(
char *outBuffer,
char *inBuffer, ConvertInfo &info );
812 void byteSwapBuffer(
char *buffer,
unsigned int samples,
RtAudioFormat format );
818 void setConvertInfo( StreamMode mode,
unsigned int firstChannel );
846 #if defined(__MACOSX_CORE__)
848 #include <CoreAudio/AudioHardware.h>
850 class RtApiCore:
public RtApi
871 bool callbackEvent( AudioDeviceID deviceId,
872 const AudioBufferList *inBufferList,
873 const AudioBufferList *outBufferList );
877 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
878 unsigned int firstChannel,
unsigned int sampleRate,
881 static const char* getErrorCode( OSStatus code );
886 #if defined(__UNIX_JACK__)
888 class RtApiJack:
public RtApi
907 bool callbackEvent(
unsigned long nframes );
911 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
912 unsigned int firstChannel,
unsigned int sampleRate,
919 #if defined(__WINDOWS_ASIO__)
921 class RtApiAsio:
public RtApi
940 bool callbackEvent(
long bufferIndex );
944 std::vector<RtAudio::DeviceInfo> devices_;
945 void saveDeviceInfo(
void );
947 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
948 unsigned int firstChannel,
unsigned int sampleRate,
955 #if defined(__WINDOWS_DS__)
957 class RtApiDs:
public RtApi
978 void callbackEvent(
void );
984 long duplexPrerollBytes;
985 std::vector<struct DsDevice> dsDevices;
986 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
987 unsigned int firstChannel,
unsigned int sampleRate,
994 #if defined(__WINDOWS_WASAPI__)
996 struct IMMDeviceEnumerator;
998 class RtApiWasapi :
public RtApi
1015 bool coInitialized_;
1016 IMMDeviceEnumerator* deviceEnumerator_;
1018 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1019 unsigned int firstChannel,
unsigned int sampleRate,
1023 static DWORD WINAPI runWasapiThread(
void* wasapiPtr );
1024 static DWORD WINAPI stopWasapiThread(
void* wasapiPtr );
1025 static DWORD WINAPI abortWasapiThread(
void* wasapiPtr );
1026 void wasapiThread();
1031 #if defined(__LINUX_ALSA__)
1033 class RtApiAlsa:
public RtApi
1051 void callbackEvent(
void );
1055 std::vector<RtAudio::DeviceInfo> devices_;
1056 void saveDeviceInfo(
void );
1057 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1058 unsigned int firstChannel,
unsigned int sampleRate,
1065 #if defined(__LINUX_PULSE__)
1067 class RtApiPulse:
public RtApi
1083 void callbackEvent(
void );
1087 std::vector<RtAudio::DeviceInfo> devices_;
1088 void saveDeviceInfo(
void );
1089 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1090 unsigned int firstChannel,
unsigned int sampleRate,
1097 #if defined(__LINUX_OSS__)
1099 class RtApiOss:
public RtApi
1117 void callbackEvent(
void );
1121 bool probeDeviceOpen(
unsigned int device, StreamMode mode,
unsigned int channels,
1122 unsigned int firstChannel,
unsigned int sampleRate,
1129 #if defined(__RTAUDIO_DUMMY__)
1131 class RtApiDummy:
public RtApi
1135 RtApiDummy() { errorText_ =
"RtApiDummy: This class provides no functionality."; error(
RtAudioError::WARNING ); }
1146 bool probeDeviceOpen(
unsigned int , StreamMode ,
unsigned int ,
1147 unsigned int ,
unsigned int ,
Definition: RtAudio.h:207
unsigned long RtAudioFormat
RtAudio data format type.
Definition: RtAudio.h:71
RtAudioStreamFlags flags
Definition: RtAudio.h:367
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition: RtAudio.h:139
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition: RtAudio.h:182
Type
Defined RtAudioError types.
Definition: RtAudio.h:202
virtual ~RtAudioError(void)
The destructor.
Definition: RtAudio.h:220
unsigned int duplexChannels
Definition: RtAudio.h:285
unsigned int deviceId
Definition: RtAudio.h:300
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open.
Definition: RtAudio.h:837
Definition: RtAudio.h:206
Definition: RtAudio.h:204
virtual const char * what(void) const
Returns the thrown error message as a c-style string.
Definition: RtAudio.h:232
Definition: RtAudio.h:209
unsigned int inputChannels
Definition: RtAudio.h:284
RtAudioError(const std::string &message, Type type=RtAudioError::UNSPECIFIED)
The constructor.
Definition: RtAudio.h:217
unsigned int numberOfBuffers
Definition: RtAudio.h:368
void(* RtAudioErrorCallback)(RtAudioError::Type type, const std::string &errorText)
RtAudio error callback function prototype.
Definition: RtAudio.h:244
unsigned int firstChannel
Definition: RtAudio.h:302
bool isStreamOpen(void) const
Returns true if a stream is open and false if not.
Definition: RtAudio.h:836
Definition: RtAudio.h:273
Api
Audio API specifier arguments.
Definition: RtAudio.h:266
void openStream(RtAudio::StreamParameters *outputParameters, RtAudio::StreamParameters *inputParameters, RtAudioFormat format, unsigned int sampleRate, unsigned int *bufferFrames, RtAudioCallback callback, void *userData=NULL, RtAudio::StreamOptions *options=NULL, RtAudioErrorCallback errorCallback=NULL)
A public function for opening a stream with the specified parameters.
static std::string getVersion(void)
A static function to determine the current RtAudio version.
Definition: RtAudio.h:267
The public device information structure for returning queried values.
Definition: RtAudio.h:280
void showWarnings(bool value=true)
Specify whether warning messages should be printed to stderr.
Definition: RtAudio.h:842
void stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played.
Definition: RtAudio.h:834
The structure for specifying stream options.
Definition: RtAudio.h:366
Definition: RtAudio.h:274
std::string name
Definition: RtAudio.h:282
unsigned int outputChannels
Definition: RtAudio.h:283
void startStream(void)
A function that starts a stream.
Definition: RtAudio.h:833
long getStreamLatency(void)
Returns the internal stream latency in sample frames.
Definition: RtAudio.h:838
Definition: RtAudio.h:268
RtAudioFormat nativeFormats
Definition: RtAudio.h:290
unsigned int getDefaultInputDevice(void)
A function that returns the index of the default input device.
Definition: RtAudio.h:830
bool isDefaultOutput
Definition: RtAudio.h:286
Definition: RtAudio.h:211
Definition: RtAudio.h:272
Definition: RtAudio.h:210
Definition: RtAudio.h:269
Exception handling class for RtAudio.
Definition: RtAudio.h:198
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:288
unsigned int preferredSampleRate
Definition: RtAudio.h:289
double getStreamTime(void)
Returns the number of elapsed seconds since the stream was started.
Definition: RtAudio.h:840
Definition: RtAudio.h:208
int priority
Definition: RtAudio.h:370
unsigned int nChannels
Definition: RtAudio.h:301
virtual const std::string & getMessage(void) const
Returns the thrown error message string.
Definition: RtAudio.h:229
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio.
Definition: RtAudio.h:827
static void getCompiledApi(std::vector< RtAudio::Api > &apis)
A static function to determine the available compiled audio APIs.
The structure for specifying input or ouput stream parameters.
Definition: RtAudio.h:299
Definition: RtAudio.h:205
void abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue.
Definition: RtAudio.h:835
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition: RtAudio.h:223
Definition: RtAudio.h:212
RtAudio::DeviceInfo getDeviceInfo(unsigned int device)
Return an RtAudio::DeviceInfo structure for a specified device number.
Definition: RtAudio.h:829
bool probed
Definition: RtAudio.h:281
Definition: RtAudio.h:275
Definition: RtAudio.h:276
void closeStream(void)
A function that closes a stream and frees any associated stream memory.
Definition: RtAudio.h:832
Definition: RtAudio.h:270
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition: RtAudio.h:226
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition: RtAudio.h:121
Definition: RtAudio.h:203
std::string streamName
Definition: RtAudio.h:369
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0.
Definition: RtAudio.h:841
bool isDefaultInput
Definition: RtAudio.h:287
Realtime audio i/o C++ classes.
Definition: RtAudio.h:261
unsigned int getDefaultOutputDevice(void)
A function that returns the index of the default output device.
Definition: RtAudio.h:831
Definition: RtAudio.h:213
Definition: RtAudio.h:271
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available.
Definition: RtAudio.h:828
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the stream.
Definition: RtAudio.h:839