The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

RtAudio.h
Go to the documentation of this file.
1/************************************************************************/
40/************************************************************************/
41
46#ifndef __RTAUDIO_H
47#define __RTAUDIO_H
48
49#define RTAUDIO_VERSION "5.2.0"
50
51#if defined _WIN32 || defined __CYGWIN__
52 #if defined(RTAUDIO_EXPORT)
53 #define RTAUDIO_DLL_PUBLIC __declspec(dllexport)
54 #else
55 #define RTAUDIO_DLL_PUBLIC
56 #endif
57#else
58 #if __GNUC__ >= 4
59 #define RTAUDIO_DLL_PUBLIC __attribute__( (visibility( "default" )) )
60 #else
61 #define RTAUDIO_DLL_PUBLIC
62 #endif
63#endif
64
65#include <string>
66#include <vector>
67#include <stdexcept>
68#include <iostream>
69
86 typedef unsigned long RtAudioFormat;
87static const RtAudioFormat RTAUDIO_SINT8 = 0x1; // 8-bit signed integer.
88static const RtAudioFormat RTAUDIO_SINT16 = 0x2; // 16-bit signed integer.
89static const RtAudioFormat RTAUDIO_SINT24 = 0x4; // 24-bit signed integer.
90static const RtAudioFormat RTAUDIO_SINT32 = 0x8; // 32-bit signed integer.
91static const RtAudioFormat RTAUDIO_FLOAT32 = 0x10; // Normalized between plus/minus 1.0.
92static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; // Normalized between plus/minus 1.0.
93
140 typedef unsigned int RtAudioStreamFlags;
141static const RtAudioStreamFlags RTAUDIO_NONINTERLEAVED = 0x1; // Use non-interleaved buffers (default = interleaved).
142static const RtAudioStreamFlags RTAUDIO_MINIMIZE_LATENCY = 0x2; // Attempt to set stream parameters for lowest possible latency.
143static const RtAudioStreamFlags RTAUDIO_HOG_DEVICE = 0x4; // Attempt grab device and prevent use by others.
144static const RtAudioStreamFlags RTAUDIO_SCHEDULE_REALTIME = 0x8; // Try to select realtime scheduling for callback thread.
145static const RtAudioStreamFlags RTAUDIO_ALSA_USE_DEFAULT = 0x10; // Use the "default" PCM device (ALSA only).
146static const RtAudioStreamFlags RTAUDIO_JACK_DONT_CONNECT = 0x20; // Do not automatically connect ports (JACK only).
147
159 typedef unsigned int RtAudioStreamStatus;
160static const RtAudioStreamStatus RTAUDIO_INPUT_OVERFLOW = 0x1; // Input data was discarded because of an overflow condition at the driver.
161static const RtAudioStreamStatus RTAUDIO_OUTPUT_UNDERFLOW = 0x2; // The output buffer ran low, likely causing a gap in the output sound.
162
164
203 typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
204 unsigned int nFrames,
205 double streamTime,
206 RtAudioStreamStatus status,
207 void *userData );
208
209/************************************************************************/
217/************************************************************************/
218
219 class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
220{
221 public:
223 enum Type {
224 WARNING,
225 DEBUG_WARNING,
226 UNSPECIFIED,
227 NO_DEVICES_FOUND,
228 INVALID_DEVICE,
229 MEMORY_ERROR,
230 INVALID_PARAMETER,
231 INVALID_USE,
232 DRIVER_ERROR,
233 SYSTEM_ERROR,
234 THREAD_ERROR
235 };
236
238 RtAudioError( const std::string& message,
239 Type type = RtAudioError::UNSPECIFIED )
240 : std::runtime_error(message), type_(type) {}
241
243 virtual void printMessage( void ) const
244 { std::cerr << '\n' << what() << "\n\n"; }
245
247 virtual const Type& getType(void) const { return type_; }
248
250 virtual const std::string getMessage(void) const
251 { return std::string(what()); }
252
253 protected:
254 Type type_;
255};
256
258
262 typedef void (*RtAudioErrorCallback)( RtAudioError::Type type, const std::string &errorText );
263
264// **************************************************************** //
265//
266// RtAudio class declaration.
267//
268// RtAudio is a "controller" used to select an available audio i/o
269// interface. It presents a common API for the user to call but all
270// functionality is implemented by the class RtApi and its
271// subclasses. RtAudio creates an instance of an RtApi subclass
272// based on the user's API choice. If no choice is made, RtAudio
273// attempts to make a "logical" API selection.
274//
275// **************************************************************** //
276
277class RtApi;
278
279 class RTAUDIO_DLL_PUBLIC RtAudio
280{
281 public:
282
284 enum Api {
285 UNSPECIFIED,
286 LINUX_ALSA,
287 LINUX_PULSE,
288 LINUX_OSS,
289 UNIX_JACK,
290 MACOSX_CORE,
291 WINDOWS_WASAPI,
292 WINDOWS_ASIO,
293 WINDOWS_DS,
294 RTAUDIO_DUMMY,
295 NUM_APIS
296 };
297
299 struct DeviceInfo {
300 bool probed;
301 std::string name;
302 unsigned int outputChannels{};
303 unsigned int inputChannels{};
304 unsigned int duplexChannels{};
305 bool isDefaultOutput{false};
306 bool isDefaultInput{false};
307 std::vector<unsigned int> sampleRates;
308 unsigned int preferredSampleRate{};
309 RtAudioFormat nativeFormats{};
310 };
311
313 struct StreamParameters {
314 unsigned int deviceId{};
315 unsigned int nChannels{};
316 unsigned int firstChannel{};
317 };
318
320
376 struct StreamOptions {
377 RtAudioStreamFlags flags{};
378 unsigned int numberOfBuffers{};
379 std::string streamName;
380 int priority{};
381 };
382
384 static std::string getVersion( void );
385
387
392 static void getCompiledApi( std::vector<RtAudio::Api> &apis );
393
395
400 static std::string getApiName( RtAudio::Api api );
401
403
407 static std::string getApiDisplayName( RtAudio::Api api );
408
410
415 static RtAudio::Api getCompiledApiByName( const std::string &name );
416
418
426 RtAudio( RtAudio::Api api=UNSPECIFIED );
427
429
433 ~RtAudio();
434
436 RtAudio::Api getCurrentApi( void );
437
439
444 unsigned int getDeviceCount( void );
445
447
457 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
458
460
467 unsigned int getDefaultOutputDevice( void );
468
470
477 unsigned int getDefaultInputDevice( void );
478
480
519 void openStream( RtAudio::StreamParameters *outputParameters,
520 RtAudio::StreamParameters *inputParameters,
521 RtAudioFormat format, unsigned int sampleRate,
522 unsigned int *bufferFrames, RtAudioCallback callback,
523 void *userData = NULL, RtAudio::StreamOptions *options = NULL, RtAudioErrorCallback errorCallback = NULL );
524
526
530 void closeStream( void );
531
533
539 void startStream( void );
540
542
548 void stopStream( void );
549
551
557 void abortStream( void );
558
560 bool isStreamOpen( void ) const;
561
563 bool isStreamRunning( void ) const;
564
566
569 double getStreamTime( void );
570
572
575 void setStreamTime( double time );
576
578
586 long getStreamLatency( void );
587
589
594 unsigned int getStreamSampleRate( void );
595
597 void showWarnings( bool value = true );
598
599 protected:
600
601 void openRtApi( RtAudio::Api api );
602 RtApi *rtapi_;
603};
604
605// Operating system dependent thread functionality.
606#if defined(_WIN32) || defined(__CYGWIN__)
607
608 #ifndef NOMINMAX
609 #define NOMINMAX
610 #endif
611 #include <windows.h>
612 #include <process.h>
613 #include <stdint.h>
614
615 typedef uintptr_t ThreadHandle;
616 typedef CRITICAL_SECTION StreamMutex;
617
618#else
619
620 // Using pthread library for various flavors of unix.
621 #include <pthread.h>
622
623 typedef pthread_t ThreadHandle;
624 typedef pthread_mutex_t StreamMutex;
625
626#endif
627
628// Setup for "dummy" behavior if no apis specified.
629#if !(defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__) \
630 || defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) \
631 || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__))
632
633 #define __RTAUDIO_DUMMY__
634
635#endif
636
637// This global structure type is used to pass callback information
638// between the private RtAudio stream structure and global callback
639// handling functions.
640struct CallbackInfo {
641 void *object{}; // Used as a "this" pointer.
642 ThreadHandle thread{};
643 void *callback{};
644 void *userData{};
645 void *errorCallback{};
646 void *apiInfo{}; // void pointer for API specific callback information
647 bool isRunning{false};
648 bool doRealtime{false};
649 int priority{};
650};
651
652// **************************************************************** //
653//
654// RtApi class declaration.
655//
656// Subclasses of RtApi contain all API- and OS-specific code necessary
657// to fully implement the RtAudio API.
658//
659// Note that RtApi is an abstract base class and cannot be
660// explicitly instantiated. The class RtAudio will create an
661// instance of an RtApi subclass (RtApiOss, RtApiAlsa,
662// RtApiJack, RtApiCore, RtApiDs, or RtApiAsio).
663//
664// **************************************************************** //
665
666#pragma pack(push, 1)
667class S24 {
668
669 protected:
670 unsigned char c3[3];
671
672 public:
673 S24() {}
674
675 S24& operator = ( const int& i ) {
676 c3[0] = (unsigned char)(i & 0x000000ff);
677 c3[1] = (unsigned char)((i & 0x0000ff00) >> 8);
678 c3[2] = (unsigned char)((i & 0x00ff0000) >> 16);
679 return *this;
680 }
681
682 S24( const double& d ) { *this = (int) d; }
683 S24( const float& f ) { *this = (int) f; }
684 S24( const signed short& s ) { *this = (int) s; }
685 S24( const char& c ) { *this = (int) c; }
686
687 int asInt() {
688 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
689 if (i & 0x800000) i |= ~0xffffff;
690 return i;
691 }
692};
693#pragma pack(pop)
694
695#if defined( HAVE_GETTIMEOFDAY )
696 #include <sys/time.h>
697#endif
698
699#include <sstream>
700
701class RTAUDIO_DLL_PUBLIC RtApi
702{
703public:
704
705 RtApi();
706 virtual ~RtApi();
707 virtual RtAudio::Api getCurrentApi( void ) = 0;
708 virtual unsigned int getDeviceCount( void ) = 0;
709 virtual RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) = 0;
710 virtual unsigned int getDefaultInputDevice( void );
711 virtual unsigned int getDefaultOutputDevice( void );
712 void openStream( RtAudio::StreamParameters *outputParameters,
713 RtAudio::StreamParameters *inputParameters,
714 RtAudioFormat format, unsigned int sampleRate,
715 unsigned int *bufferFrames, RtAudioCallback callback,
716 void *userData, RtAudio::StreamOptions *options,
717 RtAudioErrorCallback errorCallback );
718 virtual void closeStream( void );
719 virtual void startStream( void ) = 0;
720 virtual void stopStream( void ) = 0;
721 virtual void abortStream( void ) = 0;
722 long getStreamLatency( void );
723 unsigned int getStreamSampleRate( void );
724 virtual double getStreamTime( void );
725 virtual void setStreamTime( double time );
726 bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
727 bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; }
728 void showWarnings( bool value ) { showWarnings_ = value; }
729
730
731protected:
732
733 static const unsigned int MAX_SAMPLE_RATES;
734 static const unsigned int SAMPLE_RATES[];
735
736 enum { FAILURE, SUCCESS };
737
738 enum StreamState {
739 STREAM_STOPPED,
740 STREAM_STOPPING,
741 STREAM_RUNNING,
742 STREAM_CLOSED = -50
743 };
744
745 enum StreamMode {
746 OUTPUT,
747 INPUT,
748 DUPLEX,
749 UNINITIALIZED = -75
750 };
751
752 // A protected structure used for buffer conversion.
753 struct ConvertInfo {
754 int channels;
755 int inJump, outJump;
756 RtAudioFormat inFormat, outFormat;
757 std::vector<int> inOffset;
758 std::vector<int> outOffset;
759 };
760
761 // A protected structure for audio streams.
762 struct RtApiStream {
763 unsigned int device[2]; // Playback and record, respectively.
764 void *apiHandle; // void pointer for API specific stream handle information
765 StreamMode mode; // OUTPUT, INPUT, or DUPLEX.
766 StreamState state; // STOPPED, RUNNING, or CLOSED
767 char *userBuffer[2]; // Playback and record, respectively.
768 char *deviceBuffer;
769 bool doConvertBuffer[2]; // Playback and record, respectively.
770 bool userInterleaved;
771 bool deviceInterleaved[2]; // Playback and record, respectively.
772 bool doByteSwap[2]; // Playback and record, respectively.
773 unsigned int sampleRate;
774 unsigned int bufferSize;
775 unsigned int nBuffers;
776 unsigned int nUserChannels[2]; // Playback and record, respectively.
777 unsigned int nDeviceChannels[2]; // Playback and record channels, respectively.
778 unsigned int channelOffset[2]; // Playback and record, respectively.
779 unsigned long latency[2]; // Playback and record, respectively.
780 RtAudioFormat userFormat;
781 RtAudioFormat deviceFormat[2]; // Playback and record, respectively.
782 StreamMutex mutex;
783 CallbackInfo callbackInfo;
784 ConvertInfo convertInfo[2];
785 double streamTime; // Number of elapsed seconds since the stream started.
786
787#if defined(HAVE_GETTIMEOFDAY)
788 struct timeval lastTickTimestamp;
789#endif
790
791 RtApiStream()
792 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
793 };
794
795 typedef S24 Int24;
796 typedef signed short Int16;
797 typedef signed int Int32;
798 typedef float Float32;
799 typedef double Float64;
800
801 std::ostringstream errorStream_;
802 std::string errorText_;
803 bool showWarnings_;
804 RtApiStream stream_;
805 bool firstErrorOccurred_;
806
814 virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
815 unsigned int firstChannel, unsigned int sampleRate,
816 RtAudioFormat format, unsigned int *bufferSize,
817 RtAudio::StreamOptions *options );
818
820 void tickStreamTime( void );
821
823 void clearStreamInfo();
824
829 void verifyStream( void );
830
832 void error( RtAudioError::Type type );
833
838 void convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info );
839
841 void byteSwapBuffer( char *buffer, unsigned int samples, RtAudioFormat format );
842
844 unsigned int formatBytes( RtAudioFormat format );
845
847 void setConvertInfo( StreamMode mode, unsigned int firstChannel );
848};
849
850// **************************************************************** //
851//
852// Inline RtAudio definitions.
853//
854// **************************************************************** //
855
856 inline RtAudio::Api RtAudio :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
857 inline unsigned int RtAudio :: getDeviceCount( void ) { return rtapi_->getDeviceCount(); }
858 inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int device ) { return rtapi_->getDeviceInfo( device ); }
859 inline unsigned int RtAudio :: getDefaultInputDevice( void ) { return rtapi_->getDefaultInputDevice(); }
860 inline unsigned int RtAudio :: getDefaultOutputDevice( void ) { return rtapi_->getDefaultOutputDevice(); }
861 inline void RtAudio :: closeStream( void ) { return rtapi_->closeStream(); }
862 inline void RtAudio :: startStream( void ) { return rtapi_->startStream(); }
863 inline void RtAudio :: stopStream( void ) { return rtapi_->stopStream(); }
864 inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
865 inline bool RtAudio :: isStreamOpen( void ) const { return rtapi_->isStreamOpen(); }
866 inline bool RtAudio :: isStreamRunning( void ) const { return rtapi_->isStreamRunning(); }
867 inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
868 inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); }
869 inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
870 inline void RtAudio :: setStreamTime( double time ) { return rtapi_->setStreamTime( time ); }
871 inline void RtAudio :: showWarnings( bool value ) { rtapi_->showWarnings( value ); }
872
873// RtApi Subclass prototypes.
874
875#if defined(__MACOSX_CORE__)
876
877#include <CoreAudio/AudioHardware.h>
878
879class RtApiCore: public RtApi
880{
881public:
882
883 RtApiCore();
884 ~RtApiCore();
885 RtAudio::Api getCurrentApi( void ) override { return RtAudio::MACOSX_CORE; }
886 unsigned int getDeviceCount( void ) override;
887 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
888 unsigned int getDefaultOutputDevice( void ) override;
889 unsigned int getDefaultInputDevice( void ) override;
890 void closeStream( void ) override;
891 void startStream( void ) override;
892 void stopStream( void ) override;
893 void abortStream( void ) override;
894
895 // This function is intended for internal use only. It must be
896 // public because it is called by the internal callback handler,
897 // which is not a member of RtAudio. External use of this function
898 // will most likely produce highly undesirable results!
899 bool callbackEvent( AudioDeviceID deviceId,
900 const AudioBufferList *inBufferList,
901 const AudioBufferList *outBufferList );
902
903 private:
904
905 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
906 unsigned int firstChannel, unsigned int sampleRate,
907 RtAudioFormat format, unsigned int *bufferSize,
908 RtAudio::StreamOptions *options ) override;
909 static const char* getErrorCode( OSStatus code );
910};
911
912#endif
913
914#if defined(__UNIX_JACK__)
915
916class RtApiJack: public RtApi
917{
918public:
919
920 RtApiJack();
921 ~RtApiJack();
922 RtAudio::Api getCurrentApi( void ) override { return RtAudio::UNIX_JACK; }
923 unsigned int getDeviceCount( void ) override;
924 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
925 void closeStream( void ) override;
926 void startStream( void ) override;
927 void stopStream( void ) override;
928 void abortStream( void ) override;
929
930 // This function is intended for internal use only. It must be
931 // public because it is called by the internal callback handler,
932 // which is not a member of RtAudio. External use of this function
933 // will most likely produce highly undesirable results!
934 bool callbackEvent( unsigned long nframes );
935
936 private:
937
938 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
939 unsigned int firstChannel, unsigned int sampleRate,
940 RtAudioFormat format, unsigned int *bufferSize,
941 RtAudio::StreamOptions *options ) override;
942
943 bool shouldAutoconnect_;
944};
945
946#endif
947
948#if defined(__WINDOWS_ASIO__)
949
950class RtApiAsio: public RtApi
951{
952public:
953
954 RtApiAsio();
955 ~RtApiAsio();
956 RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_ASIO; }
957 unsigned int getDeviceCount( void ) override;
958 unsigned int getDefaultOutputDevice( void ) override;
959 unsigned int getDefaultInputDevice( void ) override;
960 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
961 void closeStream( void ) override;
962 void startStream( void ) override;
963 void stopStream( void ) override;
964 void abortStream( void ) override;
965
966 // This function is intended for internal use only. It must be
967 // public because it is called by the internal callback handler,
968 // which is not a member of RtAudio. External use of this function
969 // will most likely produce highly undesirable results!
970 bool callbackEvent( long bufferIndex );
971
972 private:
973
974 std::vector<RtAudio::DeviceInfo> devices_;
975 void saveDeviceInfo( void );
976 bool coInitialized_;
977 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
978 unsigned int firstChannel, unsigned int sampleRate,
979 RtAudioFormat format, unsigned int *bufferSize,
980 RtAudio::StreamOptions *options ) override;
981};
982
983#endif
984
985#if defined(__WINDOWS_DS__)
986
987class RtApiDs: public RtApi
988{
989public:
990
991 RtApiDs();
992 ~RtApiDs();
993 RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_DS; }
994 unsigned int getDeviceCount( void ) override;
995 unsigned int getDefaultOutputDevice( void ) override;
996 unsigned int getDefaultInputDevice( void ) override;
997 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
998 void closeStream( void ) override;
999 void startStream( void ) override;
1000 void stopStream( void ) override;
1001 void abortStream( void ) override;
1002
1003 // This function is intended for internal use only. It must be
1004 // public because it is called by the internal callback handler,
1005 // which is not a member of RtAudio. External use of this function
1006 // will most likely produce highly undesirable results!
1007 void callbackEvent( void );
1008
1009 private:
1010
1011 bool coInitialized_;
1012 bool buffersRolling;
1013 long duplexPrerollBytes;
1014 std::vector<struct DsDevice> dsDevices;
1015 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1016 unsigned int firstChannel, unsigned int sampleRate,
1017 RtAudioFormat format, unsigned int *bufferSize,
1018 RtAudio::StreamOptions *options ) override;
1019};
1020
1021#endif
1022
1023#if defined(__WINDOWS_WASAPI__)
1024
1025struct IMMDeviceEnumerator;
1026
1027class RtApiWasapi : public RtApi
1028{
1029public:
1030 RtApiWasapi();
1031 virtual ~RtApiWasapi();
1032
1033 RtAudio::Api getCurrentApi( void ) override { return RtAudio::WINDOWS_WASAPI; }
1034 unsigned int getDeviceCount( void ) override;
1035 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
1036 void closeStream( void ) override;
1037 void startStream( void ) override;
1038 void stopStream( void ) override;
1039 void abortStream( void ) override;
1040
1041private:
1042 bool coInitialized_;
1043 IMMDeviceEnumerator* deviceEnumerator_;
1044
1045 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1046 unsigned int firstChannel, unsigned int sampleRate,
1047 RtAudioFormat format, unsigned int* bufferSize,
1048 RtAudio::StreamOptions* options ) override;
1049
1050 static DWORD WINAPI runWasapiThread( void* wasapiPtr );
1051 static DWORD WINAPI stopWasapiThread( void* wasapiPtr );
1052 static DWORD WINAPI abortWasapiThread( void* wasapiPtr );
1053 void wasapiThread();
1054};
1055
1056#endif
1057
1058#if defined(__LINUX_ALSA__)
1059
1060class RtApiAlsa: public RtApi
1061{
1062public:
1063
1064 RtApiAlsa();
1065 ~RtApiAlsa();
1066 RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_ALSA; }
1067 unsigned int getDeviceCount( void ) override;
1068 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
1069 void closeStream( void ) override;
1070 void startStream( void ) override;
1071 void stopStream( void ) override;
1072 void abortStream( void ) override;
1073
1074 // This function is intended for internal use only. It must be
1075 // public because it is called by the internal callback handler,
1076 // which is not a member of RtAudio. External use of this function
1077 // will most likely produce highly undesirable results!
1078 void callbackEvent( void );
1079
1080 private:
1081
1082 std::vector<RtAudio::DeviceInfo> devices_;
1083 void saveDeviceInfo( void );
1084 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1085 unsigned int firstChannel, unsigned int sampleRate,
1086 RtAudioFormat format, unsigned int *bufferSize,
1087 RtAudio::StreamOptions *options ) override;
1088};
1089
1090#endif
1091
1092#if defined(__LINUX_PULSE__)
1093
1094class RtApiPulse: public RtApi
1095{
1096public:
1097 ~RtApiPulse();
1098 RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_PULSE; }
1099 unsigned int getDeviceCount( void ) override;
1100 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
1101 void closeStream( void ) override;
1102 void startStream( void ) override;
1103 void stopStream( void ) override;
1104 void abortStream( void ) override;
1105
1106 // This function is intended for internal use only. It must be
1107 // public because it is called by the internal callback handler,
1108 // which is not a member of RtAudio. External use of this function
1109 // will most likely produce highly undesirable results!
1110 void callbackEvent( void );
1111
1112 private:
1113
1114 void collectDeviceInfo( void );
1115 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1116 unsigned int firstChannel, unsigned int sampleRate,
1117 RtAudioFormat format, unsigned int *bufferSize,
1118 RtAudio::StreamOptions *options ) override;
1119};
1120
1121#endif
1122
1123#if defined(__LINUX_OSS__)
1124
1125class RtApiOss: public RtApi
1126{
1127public:
1128
1129 RtApiOss();
1130 ~RtApiOss();
1131 RtAudio::Api getCurrentApi() override { return RtAudio::LINUX_OSS; }
1132 unsigned int getDeviceCount( void ) override;
1133 RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) override;
1134 void closeStream( void ) override;
1135 void startStream( void ) override;
1136 void stopStream( void ) override;
1137 void abortStream( void ) override;
1138
1139 // This function is intended for internal use only. It must be
1140 // public because it is called by the internal callback handler,
1141 // which is not a member of RtAudio. External use of this function
1142 // will most likely produce highly undesirable results!
1143 void callbackEvent( void );
1144
1145 private:
1146
1147 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1148 unsigned int firstChannel, unsigned int sampleRate,
1149 RtAudioFormat format, unsigned int *bufferSize,
1150 RtAudio::StreamOptions *options ) override;
1151};
1152
1153#endif
1154
1155#if defined(__RTAUDIO_DUMMY__)
1156
1157class RtApiDummy: public RtApi
1158{
1159public:
1160
1161 RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); }
1162 RtAudio::Api getCurrentApi( void ) override { return RtAudio::RTAUDIO_DUMMY; }
1163 unsigned int getDeviceCount( void ) override { return 0; }
1164 RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) override { RtAudio::DeviceInfo info; return info; }
1165 void closeStream( void ) override {}
1166 void startStream( void ) override {}
1167 void stopStream( void ) override {}
1168 void abortStream( void ) override {}
1169
1170 private:
1171
1172 bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
1173 unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
1174 RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
1175 RtAudio::StreamOptions * /*options*/ ) override { return false; }
1176};
1177
1178#endif
1179
1180#endif
1181
1182// Indentation settings for Vim and Emacs
1183//
1184// Local Variables:
1185// c-basic-offset: 2
1186// indent-tabs-mode: nil
1187// End:
1188//
1189// vim: et sts=2 sw=2
RtAudioErrorCallback
void(* RtAudioErrorCallback)(RtAudioError::Type type, const std::string &errorText)
RtAudio error callback function prototype.
Definition: RtAudio.h:262
RtAudioStreamFlags
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition: RtAudio.h:140
RtAudioStreamStatus
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition: RtAudio.h:159
RtAudioCallback
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition: RtAudio.h:203
RtAudioFormat
unsigned long RtAudioFormat
RtAudio data format type.
Definition: RtAudio.h:86
RtAudioError
Exception handling class for RtAudio.
Definition: RtAudio.h:220
RtAudioError::RtAudioError
RtAudioError(const std::string &message, Type type=RtAudioError::UNSPECIFIED)
The constructor.
Definition: RtAudio.h:238
RtAudioError::getMessage
virtual const std::string getMessage(void) const
Returns the thrown error message string.
Definition: RtAudio.h:250
RtAudioError::Type
Type
Defined RtAudioError types.
Definition: RtAudio.h:223
RtAudioError::INVALID_DEVICE
@ INVALID_DEVICE
Definition: RtAudio.h:228
RtAudioError::MEMORY_ERROR
@ MEMORY_ERROR
Definition: RtAudio.h:229
RtAudioError::WARNING
@ WARNING
Definition: RtAudio.h:224
RtAudioError::UNSPECIFIED
@ UNSPECIFIED
Definition: RtAudio.h:226
RtAudioError::DRIVER_ERROR
@ DRIVER_ERROR
Definition: RtAudio.h:232
RtAudioError::NO_DEVICES_FOUND
@ NO_DEVICES_FOUND
Definition: RtAudio.h:227
RtAudioError::INVALID_USE
@ INVALID_USE
Definition: RtAudio.h:231
RtAudioError::INVALID_PARAMETER
@ INVALID_PARAMETER
Definition: RtAudio.h:230
RtAudioError::DEBUG_WARNING
@ DEBUG_WARNING
Definition: RtAudio.h:225
RtAudioError::SYSTEM_ERROR
@ SYSTEM_ERROR
Definition: RtAudio.h:233
RtAudioError::getType
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition: RtAudio.h:247
RtAudioError::printMessage
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition: RtAudio.h:243
RtAudio
Realtime audio i/o C++ classes.
Definition: RtAudio.h:280
RtAudio::getDeviceInfo
RtAudio::DeviceInfo getDeviceInfo(unsigned int device)
Return an RtAudio::DeviceInfo structure for a specified device number.
Definition: RtAudio.h:858
RtAudio::getStreamSampleRate
unsigned int getStreamSampleRate(void)
Returns actual sample rate in use by the stream.
Definition: RtAudio.h:868
RtAudio::getStreamTime
double getStreamTime(void)
Returns the number of elapsed seconds since the stream was started.
Definition: RtAudio.h:869
RtAudio::getDefaultOutputDevice
unsigned int getDefaultOutputDevice(void)
A function that returns the index of the default output device.
Definition: RtAudio.h:860
RtAudio::isStreamRunning
bool isStreamRunning(void) const
Returns true if the stream is running and false if it is stopped or not open.
Definition: RtAudio.h:866
RtAudio::openStream
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.
RtAudio::getDeviceCount
unsigned int getDeviceCount(void)
A public function that queries for the number of audio devices available.
Definition: RtAudio.h:857
RtAudio::getApiName
static std::string getApiName(RtAudio::Api api)
Return the name of a specified compiled audio API.
RtAudio::getApiDisplayName
static std::string getApiDisplayName(RtAudio::Api api)
Return the display name of a specified compiled audio API.
RtAudio::getCurrentApi
RtAudio::Api getCurrentApi(void)
Returns the audio API specifier for the current instance of RtAudio.
Definition: RtAudio.h:856
RtAudio::getStreamLatency
long getStreamLatency(void)
Returns the internal stream latency in sample frames.
Definition: RtAudio.h:867
RtAudio::closeStream
void closeStream(void)
A function that closes a stream and frees any associated stream memory.
Definition: RtAudio.h:861
RtAudio::isStreamOpen
bool isStreamOpen(void) const
Returns true if a stream is open and false if not.
Definition: RtAudio.h:865
RtAudio::~RtAudio
~RtAudio()
The destructor.
RtAudio::getCompiledApiByName
static RtAudio::Api getCompiledApiByName(const std::string &name)
Return the compiled audio API having the given name.
RtAudio::getDefaultInputDevice
unsigned int getDefaultInputDevice(void)
A function that returns the index of the default input device.
Definition: RtAudio.h:859
RtAudio::setStreamTime
void setStreamTime(double time)
Set the stream time to a time in seconds greater than or equal to 0.0.
Definition: RtAudio.h:870
RtAudio::Api
Api
Audio API specifier arguments.
Definition: RtAudio.h:284
RtAudio::WINDOWS_ASIO
@ WINDOWS_ASIO
Definition: RtAudio.h:292
RtAudio::WINDOWS_DS
@ WINDOWS_DS
Definition: RtAudio.h:293
RtAudio::LINUX_OSS
@ LINUX_OSS
Definition: RtAudio.h:288
RtAudio::UNIX_JACK
@ UNIX_JACK
Definition: RtAudio.h:289
RtAudio::MACOSX_CORE
@ MACOSX_CORE
Definition: RtAudio.h:290
RtAudio::UNSPECIFIED
@ UNSPECIFIED
Definition: RtAudio.h:285
RtAudio::LINUX_ALSA
@ LINUX_ALSA
Definition: RtAudio.h:286
RtAudio::RTAUDIO_DUMMY
@ RTAUDIO_DUMMY
Definition: RtAudio.h:294
RtAudio::WINDOWS_WASAPI
@ WINDOWS_WASAPI
Definition: RtAudio.h:291
RtAudio::LINUX_PULSE
@ LINUX_PULSE
Definition: RtAudio.h:287
RtAudio::abortStream
void abortStream(void)
Stop a stream, discarding any samples remaining in the input/output queue.
Definition: RtAudio.h:864
RtAudio::getCompiledApi
static void getCompiledApi(std::vector< RtAudio::Api > &apis)
A static function to determine the available compiled audio APIs.
RtAudio::startStream
void startStream(void)
A function that starts a stream.
Definition: RtAudio.h:862
RtAudio::showWarnings
void showWarnings(bool value=true)
Specify whether warning messages should be printed to stderr.
Definition: RtAudio.h:871
RtAudio::stopStream
void stopStream(void)
Stop a stream, allowing any samples remaining in the output queue to be played.
Definition: RtAudio.h:863
RtAudio::RtAudio
RtAudio(RtAudio::Api api=UNSPECIFIED)
The class constructor.
RtAudio::getVersion
static std::string getVersion(void)
A static function to determine the current RtAudio version.
RtAudio::DeviceInfo
The public device information structure for returning queried values.
Definition: RtAudio.h:299
RtAudio::DeviceInfo::name
std::string name
Definition: RtAudio.h:301
RtAudio::DeviceInfo::probed
bool probed
Definition: RtAudio.h:300
RtAudio::DeviceInfo::sampleRates
std::vector< unsigned int > sampleRates
Definition: RtAudio.h:307
RtAudio::StreamOptions
The structure for specifying stream options.
Definition: RtAudio.h:376
RtAudio::StreamOptions::streamName
std::string streamName
Definition: RtAudio.h:379
RtAudio::StreamParameters
The structure for specifying input or output stream parameters.
Definition: RtAudio.h:313

The Synthesis ToolKit in C++ (STK)
©1995--2021 Perry R. Cook and Gary P. Scavone. All Rights Reserved.