Home   Class/Enum List   File List   Compound Members   C interface  

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.1.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
86typedef 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
140typedef 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
159typedef 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
203typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
204 unsigned int nFrames,
205 double streamTime,
206 RtAudioStreamStatus status,
207 void *userData );
208
209/************************************************************************/
217/************************************************************************/
218
219class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
220{
221 public:
223 enum Type {
234 THREAD_ERROR
235 };
236
238 RtAudioError( const std::string& message,
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
262typedef 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
279class RTAUDIO_DLL_PUBLIC RtAudio
280{
281 public:
282
284 enum Api {
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;
307 std::vector<unsigned int> sampleRates;
308 unsigned int preferredSampleRate;
311 // Default constructor.
312 DeviceInfo()
313 :probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
314 isDefaultOutput(false), isDefaultInput(false), preferredSampleRate(0), nativeFormats(0) {}
315 };
316
319 unsigned int deviceId;
320 unsigned int nChannels;
321 unsigned int firstChannel;
323 // Default constructor.
325 : deviceId(0), nChannels(0), firstChannel(0) {}
326 };
327
329
387 unsigned int numberOfBuffers;
388 std::string streamName;
391 // Default constructor.
393 : flags(0), numberOfBuffers(0), priority(0) {}
394 };
395
397 static std::string getVersion( void );
398
400
405 static void getCompiledApi( std::vector<RtAudio::Api> &apis );
406
408
413 static std::string getApiName( RtAudio::Api api );
414
416
420 static std::string getApiDisplayName( RtAudio::Api api );
421
423
428 static RtAudio::Api getCompiledApiByName( const std::string &name );
429
431
439 RtAudio( RtAudio::Api api=UNSPECIFIED );
440
442
447
449 RtAudio::Api getCurrentApi( void );
450
452
457 unsigned int getDeviceCount( void );
458
460
470 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
471
473
480 unsigned int getDefaultOutputDevice( void );
481
483
490 unsigned int getDefaultInputDevice( void );
491
493
532 void openStream( RtAudio::StreamParameters *outputParameters,
533 RtAudio::StreamParameters *inputParameters,
534 RtAudioFormat format, unsigned int sampleRate,
535 unsigned int *bufferFrames, RtAudioCallback callback,
536 void *userData = NULL, RtAudio::StreamOptions *options = NULL, RtAudioErrorCallback errorCallback = NULL );
537
539
543 void closeStream( void );
544
546
552 void startStream( void );
553
555
561 void stopStream( void );
562
564
570 void abortStream( void );
571
573 bool isStreamOpen( void ) const;
574
576 bool isStreamRunning( void ) const;
577
579
582 double getStreamTime( void );
583
585
588 void setStreamTime( double time );
589
591
599 long getStreamLatency( void );
600
602
607 unsigned int getStreamSampleRate( void );
608
610 void showWarnings( bool value = true );
611
612 protected:
613
614 void openRtApi( RtAudio::Api api );
615 RtApi *rtapi_;
616};
617
618// Operating system dependent thread functionality.
619#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
620
621 #ifndef NOMINMAX
622 #define NOMINMAX
623 #endif
624 #include <windows.h>
625 #include <process.h>
626 #include <stdint.h>
627
628 typedef uintptr_t ThreadHandle;
629 typedef CRITICAL_SECTION StreamMutex;
630
631#elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
632 // Using pthread library for various flavors of unix.
633 #include <pthread.h>
634
635 typedef pthread_t ThreadHandle;
636 typedef pthread_mutex_t StreamMutex;
637
638#else // Setup for "dummy" behavior
639
640 #define __RTAUDIO_DUMMY__
641 typedef int ThreadHandle;
642 typedef int StreamMutex;
643
644#endif
645
646// This global structure type is used to pass callback information
647// between the private RtAudio stream structure and global callback
648// handling functions.
649struct CallbackInfo {
650 void *object; // Used as a "this" pointer.
651 ThreadHandle thread;
652 void *callback;
653 void *userData;
654 void *errorCallback;
655 void *apiInfo; // void pointer for API specific callback information
656 bool isRunning;
657 bool doRealtime;
658 int priority;
659
660 // Default constructor.
661 CallbackInfo()
662 :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false), priority(0) {}
663};
664
665// **************************************************************** //
666//
667// RtApi class declaration.
668//
669// Subclasses of RtApi contain all API- and OS-specific code necessary
670// to fully implement the RtAudio API.
671//
672// Note that RtApi is an abstract base class and cannot be
673// explicitly instantiated. The class RtAudio will create an
674// instance of an RtApi subclass (RtApiOss, RtApiAlsa,
675// RtApiJack, RtApiCore, RtApiDs, or RtApiAsio).
676//
677// **************************************************************** //
678
679#pragma pack(push, 1)
680class S24 {
681
682 protected:
683 unsigned char c3[3];
684
685 public:
686 S24() {}
687
688 S24& operator = ( const int& i ) {
689 c3[0] = (i & 0x000000ff);
690 c3[1] = (i & 0x0000ff00) >> 8;
691 c3[2] = (i & 0x00ff0000) >> 16;
692 return *this;
693 }
694
695 S24( const double& d ) { *this = (int) d; }
696 S24( const float& f ) { *this = (int) f; }
697 S24( const signed short& s ) { *this = (int) s; }
698 S24( const char& c ) { *this = (int) c; }
699
700 int asInt() {
701 int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
702 if (i & 0x800000) i |= ~0xffffff;
703 return i;
704 }
705};
706#pragma pack(pop)
707
708#if defined( HAVE_GETTIMEOFDAY )
709 #include <sys/time.h>
710#endif
711
712#include <sstream>
713
714class RTAUDIO_DLL_PUBLIC RtApi
715{
716public:
717
718 RtApi();
719 virtual ~RtApi();
720 virtual RtAudio::Api getCurrentApi( void ) = 0;
721 virtual unsigned int getDeviceCount( void ) = 0;
722 virtual RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) = 0;
723 virtual unsigned int getDefaultInputDevice( void );
724 virtual unsigned int getDefaultOutputDevice( void );
725 void openStream( RtAudio::StreamParameters *outputParameters,
726 RtAudio::StreamParameters *inputParameters,
727 RtAudioFormat format, unsigned int sampleRate,
728 unsigned int *bufferFrames, RtAudioCallback callback,
729 void *userData, RtAudio::StreamOptions *options,
730 RtAudioErrorCallback errorCallback );
731 virtual void closeStream( void );
732 virtual void startStream( void ) = 0;
733 virtual void stopStream( void ) = 0;
734 virtual void abortStream( void ) = 0;
735 long getStreamLatency( void );
736 unsigned int getStreamSampleRate( void );
737 virtual double getStreamTime( void );
738 virtual void setStreamTime( double time );
739 bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
740 bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; }
741 void showWarnings( bool value ) { showWarnings_ = value; }
742
743
744protected:
745
746 static const unsigned int MAX_SAMPLE_RATES;
747 static const unsigned int SAMPLE_RATES[];
748
749 enum { FAILURE, SUCCESS };
750
751 enum StreamState {
752 STREAM_STOPPED,
753 STREAM_STOPPING,
754 STREAM_RUNNING,
755 STREAM_CLOSED = -50
756 };
757
758 enum StreamMode {
759 OUTPUT,
760 INPUT,
761 DUPLEX,
762 UNINITIALIZED = -75
763 };
764
765 // A protected structure used for buffer conversion.
766 struct ConvertInfo {
767 int channels;
768 int inJump, outJump;
769 RtAudioFormat inFormat, outFormat;
770 std::vector<int> inOffset;
771 std::vector<int> outOffset;
772 };
773
774 // A protected structure for audio streams.
775 struct RtApiStream {
776 unsigned int device[2]; // Playback and record, respectively.
777 void *apiHandle; // void pointer for API specific stream handle information
778 StreamMode mode; // OUTPUT, INPUT, or DUPLEX.
779 StreamState state; // STOPPED, RUNNING, or CLOSED
780 char *userBuffer[2]; // Playback and record, respectively.
781 char *deviceBuffer;
782 bool doConvertBuffer[2]; // Playback and record, respectively.
783 bool userInterleaved;
784 bool deviceInterleaved[2]; // Playback and record, respectively.
785 bool doByteSwap[2]; // Playback and record, respectively.
786 unsigned int sampleRate;
787 unsigned int bufferSize;
788 unsigned int nBuffers;
789 unsigned int nUserChannels[2]; // Playback and record, respectively.
790 unsigned int nDeviceChannels[2]; // Playback and record channels, respectively.
791 unsigned int channelOffset[2]; // Playback and record, respectively.
792 unsigned long latency[2]; // Playback and record, respectively.
793 RtAudioFormat userFormat;
794 RtAudioFormat deviceFormat[2]; // Playback and record, respectively.
795 StreamMutex mutex;
796 CallbackInfo callbackInfo;
797 ConvertInfo convertInfo[2];
798 double streamTime; // Number of elapsed seconds since the stream started.
799
800#if defined(HAVE_GETTIMEOFDAY)
801 struct timeval lastTickTimestamp;
802#endif
803
804 RtApiStream()
805 :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
806 };
807
808 typedef S24 Int24;
809 typedef signed short Int16;
810 typedef signed int Int32;
811 typedef float Float32;
812 typedef double Float64;
813
814 std::ostringstream errorStream_;
815 std::string errorText_;
816 bool showWarnings_;
817 RtApiStream stream_;
818 bool firstErrorOccurred_;
819
827 virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
828 unsigned int firstChannel, unsigned int sampleRate,
829 RtAudioFormat format, unsigned int *bufferSize,
830 RtAudio::StreamOptions *options );
831
833 void tickStreamTime( void );
834
836 void clearStreamInfo();
837
842 void verifyStream( void );
843
845 void error( RtAudioError::Type type );
846
851 void convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info );
852
854 void byteSwapBuffer( char *buffer, unsigned int samples, RtAudioFormat format );
855
857 unsigned int formatBytes( RtAudioFormat format );
858
860 void setConvertInfo( StreamMode mode, unsigned int firstChannel );
861};
862
863// **************************************************************** //
864//
865// Inline RtAudio definitions.
866//
867// **************************************************************** //
868
869inline RtAudio::Api RtAudio :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
870inline unsigned int RtAudio :: getDeviceCount( void ) { return rtapi_->getDeviceCount(); }
871inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int device ) { return rtapi_->getDeviceInfo( device ); }
872inline unsigned int RtAudio :: getDefaultInputDevice( void ) { return rtapi_->getDefaultInputDevice(); }
873inline unsigned int RtAudio :: getDefaultOutputDevice( void ) { return rtapi_->getDefaultOutputDevice(); }
874inline void RtAudio :: closeStream( void ) { return rtapi_->closeStream(); }
875inline void RtAudio :: startStream( void ) { return rtapi_->startStream(); }
876inline void RtAudio :: stopStream( void ) { return rtapi_->stopStream(); }
877inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
878inline bool RtAudio :: isStreamOpen( void ) const { return rtapi_->isStreamOpen(); }
879inline bool RtAudio :: isStreamRunning( void ) const { return rtapi_->isStreamRunning(); }
880inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
881inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); }
882inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
883inline void RtAudio :: setStreamTime( double time ) { return rtapi_->setStreamTime( time ); }
884inline void RtAudio :: showWarnings( bool value ) { rtapi_->showWarnings( value ); }
885
886// RtApi Subclass prototypes.
887
888#if defined(__MACOSX_CORE__)
889
890#include <CoreAudio/AudioHardware.h>
891
892class RtApiCore: public RtApi
893{
894public:
895
896 RtApiCore();
897 ~RtApiCore();
898 RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; }
899 unsigned int getDeviceCount( void );
900 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
901 unsigned int getDefaultOutputDevice( void );
902 unsigned int getDefaultInputDevice( void );
903 void closeStream( void );
904 void startStream( void );
905 void stopStream( void );
906 void abortStream( void );
907
908 // This function is intended for internal use only. It must be
909 // public because it is called by the internal callback handler,
910 // which is not a member of RtAudio. External use of this function
911 // will most likely produce highly undesireable results!
912 bool callbackEvent( AudioDeviceID deviceId,
913 const AudioBufferList *inBufferList,
914 const AudioBufferList *outBufferList );
915
916 private:
917
918 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
919 unsigned int firstChannel, unsigned int sampleRate,
920 RtAudioFormat format, unsigned int *bufferSize,
921 RtAudio::StreamOptions *options );
922 static const char* getErrorCode( OSStatus code );
923};
924
925#endif
926
927#if defined(__UNIX_JACK__)
928
929class RtApiJack: public RtApi
930{
931public:
932
933 RtApiJack();
934 ~RtApiJack();
935 RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; }
936 unsigned int getDeviceCount( void );
937 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
938 void closeStream( void );
939 void startStream( void );
940 void stopStream( void );
941 void abortStream( void );
942
943 // This function is intended for internal use only. It must be
944 // public because it is called by the internal callback handler,
945 // which is not a member of RtAudio. External use of this function
946 // will most likely produce highly undesireable results!
947 bool callbackEvent( unsigned long nframes );
948
949 private:
950
951 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
952 unsigned int firstChannel, unsigned int sampleRate,
953 RtAudioFormat format, unsigned int *bufferSize,
954 RtAudio::StreamOptions *options );
955
956 bool shouldAutoconnect_;
957};
958
959#endif
960
961#if defined(__WINDOWS_ASIO__)
962
963class RtApiAsio: public RtApi
964{
965public:
966
967 RtApiAsio();
968 ~RtApiAsio();
969 RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; }
970 unsigned int getDeviceCount( void );
971 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
972 void closeStream( void );
973 void startStream( void );
974 void stopStream( void );
975 void abortStream( void );
976
977 // This function is intended for internal use only. It must be
978 // public because it is called by the internal callback handler,
979 // which is not a member of RtAudio. External use of this function
980 // will most likely produce highly undesireable results!
981 bool callbackEvent( long bufferIndex );
982
983 private:
984
985 std::vector<RtAudio::DeviceInfo> devices_;
986 void saveDeviceInfo( void );
987 bool coInitialized_;
988 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
989 unsigned int firstChannel, unsigned int sampleRate,
990 RtAudioFormat format, unsigned int *bufferSize,
991 RtAudio::StreamOptions *options );
992};
993
994#endif
995
996#if defined(__WINDOWS_DS__)
997
998class RtApiDs: public RtApi
999{
1000public:
1001
1002 RtApiDs();
1003 ~RtApiDs();
1004 RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; }
1005 unsigned int getDeviceCount( void );
1006 unsigned int getDefaultOutputDevice( void );
1007 unsigned int getDefaultInputDevice( void );
1008 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1009 void closeStream( void );
1010 void startStream( void );
1011 void stopStream( void );
1012 void abortStream( void );
1013
1014 // This function is intended for internal use only. It must be
1015 // public because it is called by the internal callback handler,
1016 // which is not a member of RtAudio. External use of this function
1017 // will most likely produce highly undesireable results!
1018 void callbackEvent( void );
1019
1020 private:
1021
1022 bool coInitialized_;
1023 bool buffersRolling;
1024 long duplexPrerollBytes;
1025 std::vector<struct DsDevice> dsDevices;
1026 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1027 unsigned int firstChannel, unsigned int sampleRate,
1028 RtAudioFormat format, unsigned int *bufferSize,
1029 RtAudio::StreamOptions *options );
1030};
1031
1032#endif
1033
1034#if defined(__WINDOWS_WASAPI__)
1035
1036struct IMMDeviceEnumerator;
1037
1038class RtApiWasapi : public RtApi
1039{
1040public:
1041 RtApiWasapi();
1042 virtual ~RtApiWasapi();
1043
1044 RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_WASAPI; }
1045 unsigned int getDeviceCount( void );
1046 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1047 unsigned int getDefaultOutputDevice( void );
1048 unsigned int getDefaultInputDevice( void );
1049 void closeStream( void );
1050 void startStream( void );
1051 void stopStream( void );
1052 void abortStream( void );
1053
1054private:
1055 bool coInitialized_;
1056 IMMDeviceEnumerator* deviceEnumerator_;
1057
1058 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1059 unsigned int firstChannel, unsigned int sampleRate,
1060 RtAudioFormat format, unsigned int* bufferSize,
1061 RtAudio::StreamOptions* options );
1062
1063 static DWORD WINAPI runWasapiThread( void* wasapiPtr );
1064 static DWORD WINAPI stopWasapiThread( void* wasapiPtr );
1065 static DWORD WINAPI abortWasapiThread( void* wasapiPtr );
1066 void wasapiThread();
1067};
1068
1069#endif
1070
1071#if defined(__LINUX_ALSA__)
1072
1073class RtApiAlsa: public RtApi
1074{
1075public:
1076
1077 RtApiAlsa();
1078 ~RtApiAlsa();
1079 RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; }
1080 unsigned int getDeviceCount( void );
1081 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1082 void closeStream( void );
1083 void startStream( void );
1084 void stopStream( void );
1085 void abortStream( void );
1086
1087 // This function is intended for internal use only. It must be
1088 // public because it is called by the internal callback handler,
1089 // which is not a member of RtAudio. External use of this function
1090 // will most likely produce highly undesireable results!
1091 void callbackEvent( void );
1092
1093 private:
1094
1095 std::vector<RtAudio::DeviceInfo> devices_;
1096 void saveDeviceInfo( void );
1097 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1098 unsigned int firstChannel, unsigned int sampleRate,
1099 RtAudioFormat format, unsigned int *bufferSize,
1100 RtAudio::StreamOptions *options );
1101};
1102
1103#endif
1104
1105#if defined(__LINUX_PULSE__)
1106
1107class RtApiPulse: public RtApi
1108{
1109public:
1110 ~RtApiPulse();
1111 RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; }
1112 unsigned int getDeviceCount( void );
1113 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1114 void closeStream( void );
1115 void startStream( void );
1116 void stopStream( void );
1117 void abortStream( void );
1118
1119 // This function is intended for internal use only. It must be
1120 // public because it is called by the internal callback handler,
1121 // which is not a member of RtAudio. External use of this function
1122 // will most likely produce highly undesireable results!
1123 void callbackEvent( void );
1124
1125 private:
1126
1127 std::vector<RtAudio::DeviceInfo> devices_;
1128 void saveDeviceInfo( void );
1129 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1130 unsigned int firstChannel, unsigned int sampleRate,
1131 RtAudioFormat format, unsigned int *bufferSize,
1132 RtAudio::StreamOptions *options );
1133};
1134
1135#endif
1136
1137#if defined(__LINUX_OSS__)
1138
1139class RtApiOss: public RtApi
1140{
1141public:
1142
1143 RtApiOss();
1144 ~RtApiOss();
1145 RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; }
1146 unsigned int getDeviceCount( void );
1147 RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1148 void closeStream( void );
1149 void startStream( void );
1150 void stopStream( void );
1151 void abortStream( void );
1152
1153 // This function is intended for internal use only. It must be
1154 // public because it is called by the internal callback handler,
1155 // which is not a member of RtAudio. External use of this function
1156 // will most likely produce highly undesireable results!
1157 void callbackEvent( void );
1158
1159 private:
1160
1161 bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1162 unsigned int firstChannel, unsigned int sampleRate,
1163 RtAudioFormat format, unsigned int *bufferSize,
1164 RtAudio::StreamOptions *options );
1165};
1166
1167#endif
1168
1169#if defined(__RTAUDIO_DUMMY__)
1170
1171class RtApiDummy: public RtApi
1172{
1173public:
1174
1175 RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); }
1176 RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; }
1177 unsigned int getDeviceCount( void ) { return 0; }
1178 RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) { RtAudio::DeviceInfo info; return info; }
1179 void closeStream( void ) {}
1180 void startStream( void ) {}
1181 void stopStream( void ) {}
1182 void abortStream( void ) {}
1183
1184 private:
1185
1186 bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
1187 unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
1188 RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
1189 RtAudio::StreamOptions * /*options*/ ) { return false; }
1190};
1191
1192#endif
1193
1194#endif
1195
1196// Indentation settings for Vim and Emacs
1197//
1198// Local Variables:
1199// c-basic-offset: 2
1200// indent-tabs-mode: nil
1201// End:
1202//
1203// vim: et sts=2 sw=2
void(* RtAudioErrorCallback)(RtAudioError::Type type, const std::string &errorText)
RtAudio error callback function prototype.
Definition RtAudio.h:262
unsigned int RtAudioStreamFlags
RtAudio stream option flags.
Definition RtAudio.h:140
unsigned int RtAudioStreamStatus
RtAudio stream status (over- or underflow) flags.
Definition RtAudio.h:159
int(* RtAudioCallback)(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData)
RtAudio callback function prototype.
Definition RtAudio.h:203
unsigned long RtAudioFormat
RtAudio data format type.
Definition RtAudio.h:86
Exception handling class for RtAudio.
Definition RtAudio.h:220
RtAudioError(const std::string &message, Type type=RtAudioError::UNSPECIFIED)
The constructor.
Definition RtAudio.h:238
virtual const std::string getMessage(void) const
Returns the thrown error message string.
Definition RtAudio.h:250
Type
Defined RtAudioError types.
Definition RtAudio.h:223
@ INVALID_DEVICE
Definition RtAudio.h:228
@ MEMORY_ERROR
Definition RtAudio.h:229
@ WARNING
Definition RtAudio.h:224
@ UNSPECIFIED
Definition RtAudio.h:226
@ DRIVER_ERROR
Definition RtAudio.h:232
@ NO_DEVICES_FOUND
Definition RtAudio.h:227
@ INVALID_USE
Definition RtAudio.h:231
@ INVALID_PARAMETER
Definition RtAudio.h:230
@ DEBUG_WARNING
Definition RtAudio.h:225
@ SYSTEM_ERROR
Definition RtAudio.h:233
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition RtAudio.h:247
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition RtAudio.h:243
Realtime audio i/o C++ classes.
Definition RtAudio.h:280
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 getApiName(RtAudio::Api api)
Return the name of a specified compiled audio API.
static std::string getApiDisplayName(RtAudio::Api api)
Return the display name of a specified compiled audio API.
~RtAudio()
The destructor.
static RtAudio::Api getCompiledApiByName(const std::string &name)
Return the compiled audio API having the given name.
Api
Audio API specifier arguments.
Definition RtAudio.h:284
@ WINDOWS_ASIO
Definition RtAudio.h:292
@ WINDOWS_DS
Definition RtAudio.h:293
@ LINUX_OSS
Definition RtAudio.h:288
@ UNIX_JACK
Definition RtAudio.h:289
@ MACOSX_CORE
Definition RtAudio.h:290
@ UNSPECIFIED
Definition RtAudio.h:285
@ LINUX_ALSA
Definition RtAudio.h:286
@ RTAUDIO_DUMMY
Definition RtAudio.h:294
@ WINDOWS_WASAPI
Definition RtAudio.h:291
@ LINUX_PULSE
Definition RtAudio.h:287
static void getCompiledApi(std::vector< RtAudio::Api > &apis)
A static function to determine the available compiled audio APIs.
RtAudio(RtAudio::Api api=UNSPECIFIED)
The class constructor.
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:299
RtAudioFormat nativeFormats
Definition RtAudio.h:309
std::string name
Definition RtAudio.h:301
unsigned int duplexChannels
Definition RtAudio.h:304
bool isDefaultOutput
Definition RtAudio.h:305
unsigned int inputChannels
Definition RtAudio.h:303
bool isDefaultInput
Definition RtAudio.h:306
unsigned int outputChannels
Definition RtAudio.h:302
bool probed
Definition RtAudio.h:300
unsigned int preferredSampleRate
Definition RtAudio.h:308
std::vector< unsigned int > sampleRates
Definition RtAudio.h:307
The structure for specifying stream options.
Definition RtAudio.h:385
RtAudioStreamFlags flags
Definition RtAudio.h:386
std::string streamName
Definition RtAudio.h:388
unsigned int numberOfBuffers
Definition RtAudio.h:387
int priority
Definition RtAudio.h:389
The structure for specifying input or ouput stream parameters.
Definition RtAudio.h:318
unsigned int nChannels
Definition RtAudio.h:320
unsigned int deviceId
Definition RtAudio.h:319
unsigned int firstChannel
Definition RtAudio.h:321

©2001-2019 Gary P. Scavone, McGill University. All Rights Reserved.
Maintained by Gary P. Scavone.