Home   Class/Enum List   File List   Compound Members  

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

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