More detailed error message.
[rtaudio-cdist.git] / RtAudio.h
1 /************************************************************************/
2 /*! \class RtAudio
3     \brief Realtime audio i/o C++ classes.
4
5     RtAudio provides a common API (Application Programming Interface)
6     for realtime audio input/output across Linux (native ALSA, Jack,
7     and OSS), Macintosh OS X (CoreAudio and Jack), and Windows
8     (DirectSound, ASIO and WASAPI) operating systems.
9
10     RtAudio WWW site: http://www.music.mcgill.ca/~gary/rtaudio/
11
12     RtAudio: realtime audio i/o C++ classes
13     Copyright (c) 2001-2017 Gary P. Scavone
14
15     Permission is hereby granted, free of charge, to any person
16     obtaining a copy of this software and associated documentation files
17     (the "Software"), to deal in the Software without restriction,
18     including without limitation the rights to use, copy, modify, merge,
19     publish, distribute, sublicense, and/or sell copies of the Software,
20     and to permit persons to whom the Software is furnished to do so,
21     subject to the following conditions:
22
23     The above copyright notice and this permission notice shall be
24     included in all copies or substantial portions of the Software.
25
26     Any person wishing to distribute modifications to the Software is
27     asked to send the modifications to the original developer so that
28     they can be incorporated into the canonical version.  This is,
29     however, not a binding provision of this license.
30
31     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34     IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
35     ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
36     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39 /************************************************************************/
40
41 /*!
42   \file RtAudio.h
43  */
44
45 #ifndef __RTAUDIO_H
46 #define __RTAUDIO_H
47
48 #define RTAUDIO_VERSION "5.0.0"
49
50 #if defined _WIN32 || defined __CYGWIN__
51   #if defined(RTAUDIO_EXPORT)
52     #define RTAUDIO_DLL_PUBLIC __declspec(dllexport)
53   #else
54     #define RTAUDIO_DLL_PUBLIC
55   #endif
56 #else
57   #if __GNUC__ >= 4
58     #define RTAUDIO_DLL_PUBLIC __attribute__( (visibility( "default" )) )
59   #else
60     #define RTAUDIO_DLL_PUBLIC
61   #endif
62 #endif
63
64 #include <string>
65 #include <vector>
66 #include <stdexcept>
67 #include <iostream>
68
69 /*! \typedef typedef unsigned long RtAudioFormat;
70     \brief RtAudio data format type.
71
72     Support for signed integers and floats.  Audio data fed to/from an
73     RtAudio stream is assumed to ALWAYS be in host byte order.  The
74     internal routines will automatically take care of any necessary
75     byte-swapping between the host format and the soundcard.  Thus,
76     endian-ness is not a concern in the following format definitions.
77
78     - \e RTAUDIO_SINT8:   8-bit signed integer.
79     - \e RTAUDIO_SINT16:  16-bit signed integer.
80     - \e RTAUDIO_SINT24:  24-bit signed integer.
81     - \e RTAUDIO_SINT32:  32-bit signed integer.
82     - \e RTAUDIO_FLOAT32: Normalized between plus/minus 1.0.
83     - \e RTAUDIO_FLOAT64: Normalized between plus/minus 1.0.
84 */
85 typedef unsigned long RtAudioFormat;
86 static const RtAudioFormat RTAUDIO_SINT8 = 0x1;    // 8-bit signed integer.
87 static const RtAudioFormat RTAUDIO_SINT16 = 0x2;   // 16-bit signed integer.
88 static const RtAudioFormat RTAUDIO_SINT24 = 0x4;   // 24-bit signed integer.
89 static const RtAudioFormat RTAUDIO_SINT32 = 0x8;   // 32-bit signed integer.
90 static const RtAudioFormat RTAUDIO_FLOAT32 = 0x10; // Normalized between plus/minus 1.0.
91 static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; // Normalized between plus/minus 1.0.
92
93 /*! \typedef typedef unsigned long RtAudioStreamFlags;
94     \brief RtAudio stream option flags.
95
96     The following flags can be OR'ed together to allow a client to
97     make changes to the default stream behavior:
98
99     - \e RTAUDIO_NONINTERLEAVED:   Use non-interleaved buffers (default = interleaved).
100     - \e RTAUDIO_MINIMIZE_LATENCY: Attempt to set stream parameters for lowest possible latency.
101     - \e RTAUDIO_HOG_DEVICE:       Attempt grab device for exclusive use.
102     - \e RTAUDIO_ALSA_USE_DEFAULT: Use the "default" PCM device (ALSA only).
103     - \e RTAUDIO_JACK_DONT_CONNECT: Do not automatically connect ports (JACK only).
104
105     By default, RtAudio streams pass and receive audio data from the
106     client in an interleaved format.  By passing the
107     RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio
108     data will instead be presented in non-interleaved buffers.  In
109     this case, each buffer argument in the RtAudioCallback function
110     will point to a single array of data, with \c nFrames samples for
111     each channel concatenated back-to-back.  For example, the first
112     sample of data for the second channel would be located at index \c
113     nFrames (assuming the \c buffer pointer was recast to the correct
114     data type for the stream).
115
116     Certain audio APIs offer a number of parameters that influence the
117     I/O latency of a stream.  By default, RtAudio will attempt to set
118     these parameters internally for robust (glitch-free) performance
119     (though some APIs, like Windows DirectSound, make this difficult).
120     By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream()
121     function, internal stream settings will be influenced in an attempt
122     to minimize stream latency, though possibly at the expense of stream
123     performance.
124
125     If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to
126     open the input and/or output stream device(s) for exclusive use.
127     Note that this is not possible with all supported audio APIs.
128
129     If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt
130     to select realtime scheduling (round-robin) for the callback thread.
131
132     If the RTAUDIO_ALSA_USE_DEFAULT flag is set, RtAudio will attempt to
133     open the "default" PCM device when using the ALSA API. Note that this
134     will override any specified input or output device id.
135
136     If the RTAUDIO_JACK_DONT_CONNECT flag is set, RtAudio will not attempt
137     to automatically connect the ports of the client to the audio device.
138 */
139 typedef unsigned int RtAudioStreamFlags;
140 static const RtAudioStreamFlags RTAUDIO_NONINTERLEAVED = 0x1;    // Use non-interleaved buffers (default = interleaved).
141 static const RtAudioStreamFlags RTAUDIO_MINIMIZE_LATENCY = 0x2;  // Attempt to set stream parameters for lowest possible latency.
142 static const RtAudioStreamFlags RTAUDIO_HOG_DEVICE = 0x4;        // Attempt grab device and prevent use by others.
143 static const RtAudioStreamFlags RTAUDIO_SCHEDULE_REALTIME = 0x8; // Try to select realtime scheduling for callback thread.
144 static const RtAudioStreamFlags RTAUDIO_ALSA_USE_DEFAULT = 0x10; // Use the "default" PCM device (ALSA only).
145 static const RtAudioStreamFlags RTAUDIO_JACK_DONT_CONNECT = 0x20; // Do not automatically connect ports (JACK only).
146
147 /*! \typedef typedef unsigned long RtAudioStreamStatus;
148     \brief RtAudio stream status (over- or underflow) flags.
149
150     Notification of a stream over- or underflow is indicated by a
151     non-zero stream \c status argument in the RtAudioCallback function.
152     The stream status can be one of the following two options,
153     depending on whether the stream is open for output and/or input:
154
155     - \e RTAUDIO_INPUT_OVERFLOW:   Input data was discarded because of an overflow condition at the driver.
156     - \e RTAUDIO_OUTPUT_UNDERFLOW: The output buffer ran low, likely producing a break in the output sound.
157 */
158 typedef unsigned int RtAudioStreamStatus;
159 static const RtAudioStreamStatus RTAUDIO_INPUT_OVERFLOW = 0x1;    // Input data was discarded because of an overflow condition at the driver.
160 static const RtAudioStreamStatus RTAUDIO_OUTPUT_UNDERFLOW = 0x2;  // The output buffer ran low, likely causing a gap in the output sound.
161
162 //! RtAudio callback function prototype.
163 /*!
164    All RtAudio clients must create a function of type RtAudioCallback
165    to read and/or write data from/to the audio stream.  When the
166    underlying audio system is ready for new input or output data, this
167    function will be invoked.
168
169    \param outputBuffer For output (or duplex) streams, the client
170           should write \c nFrames of audio sample frames into this
171           buffer.  This argument should be recast to the datatype
172           specified when the stream was opened.  For input-only
173           streams, this argument will be NULL.
174
175    \param inputBuffer For input (or duplex) streams, this buffer will
176           hold \c nFrames of input audio sample frames.  This
177           argument should be recast to the datatype specified when the
178           stream was opened.  For output-only streams, this argument
179           will be NULL.
180
181    \param nFrames The number of sample frames of input or output
182           data in the buffers.  The actual buffer size in bytes is
183           dependent on the data type and number of channels in use.
184
185    \param streamTime The number of seconds that have elapsed since the
186           stream was started.
187
188    \param status If non-zero, this argument indicates a data overflow
189           or underflow condition for the stream.  The particular
190           condition can be determined by comparison with the
191           RtAudioStreamStatus flags.
192
193    \param userData A pointer to optional data provided by the client
194           when opening the stream (default = NULL).
195
196    To continue normal stream operation, the RtAudioCallback function
197    should return a value of zero.  To stop the stream and drain the
198    output buffer, the function should return a value of one.  To abort
199    the stream immediately, the client should return a value of two.
200  */
201 typedef int (*RtAudioCallback)( void *outputBuffer, void *inputBuffer,
202                                 unsigned int nFrames,
203                                 double streamTime,
204                                 RtAudioStreamStatus status,
205                                 void *userData );
206
207 /************************************************************************/
208 /*! \class RtAudioError
209     \brief Exception handling class for RtAudio.
210
211     The RtAudioError class is quite simple but it does allow errors to be
212     "caught" by RtAudioError::Type. See the RtAudio documentation to know
213     which methods can throw an RtAudioError.
214 */
215 /************************************************************************/
216
217 class RTAUDIO_DLL_PUBLIC RtAudioError : public std::runtime_error
218 {
219  public:
220   //! Defined RtAudioError types.
221   enum Type {
222     WARNING,           /*!< A non-critical error. */
223     DEBUG_WARNING,     /*!< A non-critical error which might be useful for debugging. */
224     UNSPECIFIED,       /*!< The default, unspecified error type. */
225     NO_DEVICES_FOUND,  /*!< No devices found on system. */
226     INVALID_DEVICE,    /*!< An invalid device ID was specified. */
227     MEMORY_ERROR,      /*!< An error occured during memory allocation. */
228     INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
229     INVALID_USE,       /*!< The function was called incorrectly. */
230     DRIVER_ERROR,      /*!< A system driver error occured. */
231     SYSTEM_ERROR,      /*!< A system error occured. */
232     THREAD_ERROR       /*!< A thread error occured. */
233   };
234
235   //! The constructor.
236   RtAudioError( const std::string& message,
237                 Type type = RtAudioError::UNSPECIFIED )
238     : std::runtime_error(message), type_(type) {}
239
240   //! Prints thrown error message to stderr.
241   virtual void printMessage( void ) const
242     { std::cerr << '\n' << what() << "\n\n"; }
243
244   //! Returns the thrown error message type.
245   virtual const Type& getType(void) const { return type_; }
246
247   //! Returns the thrown error message string.
248   virtual const std::string getMessage(void) const
249     { return std::string(what()); }
250
251  protected:
252   Type type_;
253 };
254
255 //! RtAudio error callback function prototype.
256 /*!
257     \param type Type of error.
258     \param errorText Error description.
259  */
260 typedef void (*RtAudioErrorCallback)( RtAudioError::Type type, const std::string &errorText );
261
262 // **************************************************************** //
263 //
264 // RtAudio class declaration.
265 //
266 // RtAudio is a "controller" used to select an available audio i/o
267 // interface.  It presents a common API for the user to call but all
268 // functionality is implemented by the class RtApi and its
269 // subclasses.  RtAudio creates an instance of an RtApi subclass
270 // based on the user's API choice.  If no choice is made, RtAudio
271 // attempts to make a "logical" API selection.
272 //
273 // **************************************************************** //
274
275 class RtApi;
276
277 class RTAUDIO_DLL_PUBLIC RtAudio
278 {
279  public:
280
281   //! Audio API specifier arguments.
282   enum Api {
283     UNSPECIFIED,    /*!< Search for a working compiled API. */
284     LINUX_ALSA,     /*!< The Advanced Linux Sound Architecture API. */
285     LINUX_PULSE,    /*!< The Linux PulseAudio API. */
286     LINUX_OSS,      /*!< The Linux Open Sound System API. */
287     UNIX_JACK,      /*!< The Jack Low-Latency Audio Server API. */
288     MACOSX_CORE,    /*!< Macintosh OS-X Core Audio API. */
289     WINDOWS_WASAPI, /*!< The Microsoft WASAPI API. */
290     WINDOWS_ASIO,   /*!< The Steinberg Audio Stream I/O API. */
291     WINDOWS_DS,     /*!< The Microsoft DirectSound API. */
292     RTAUDIO_DUMMY,  /*!< A compilable but non-functional API. */
293     NUM_APIS        /*!< Number of values in this enum. */
294   };
295
296   //! The public device information structure for returning queried values.
297   struct DeviceInfo {
298     bool probed;                  /*!< true if the device capabilities were successfully probed. */
299     std::string name;             /*!< Character string device identifier. */
300     unsigned int outputChannels;  /*!< Maximum output channels supported by device. */
301     unsigned int inputChannels;   /*!< Maximum input channels supported by device. */
302     unsigned int duplexChannels;  /*!< Maximum simultaneous input/output channels supported by device. */
303     bool isDefaultOutput;         /*!< true if this is the default output device. */
304     bool isDefaultInput;          /*!< true if this is the default input device. */
305     std::vector<unsigned int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */
306     unsigned int preferredSampleRate; /*!< Preferred sample rate, e.g. for WASAPI the system sample rate. */
307     RtAudioFormat nativeFormats;  /*!< Bit mask of supported data formats. */
308
309     // Default constructor.
310     DeviceInfo()
311       :probed(false), outputChannels(0), inputChannels(0), duplexChannels(0),
312        isDefaultOutput(false), isDefaultInput(false), preferredSampleRate(0), nativeFormats(0) {}
313   };
314
315   //! The structure for specifying input or ouput stream parameters.
316   struct StreamParameters {
317     unsigned int deviceId;     /*!< Device index (0 to getDeviceCount() - 1). */
318     unsigned int nChannels;    /*!< Number of channels. */
319     unsigned int firstChannel; /*!< First channel index on device (default = 0). */
320
321     // Default constructor.
322     StreamParameters()
323       : deviceId(0), nChannels(0), firstChannel(0) {}
324   };
325
326   //! The structure for specifying stream options.
327   /*!
328     The following flags can be OR'ed together to allow a client to
329     make changes to the default stream behavior:
330
331     - \e RTAUDIO_NONINTERLEAVED:    Use non-interleaved buffers (default = interleaved).
332     - \e RTAUDIO_MINIMIZE_LATENCY:  Attempt to set stream parameters for lowest possible latency.
333     - \e RTAUDIO_HOG_DEVICE:        Attempt grab device for exclusive use.
334     - \e RTAUDIO_SCHEDULE_REALTIME: Attempt to select realtime scheduling for callback thread.
335     - \e RTAUDIO_ALSA_USE_DEFAULT:  Use the "default" PCM device (ALSA only).
336
337     By default, RtAudio streams pass and receive audio data from the
338     client in an interleaved format.  By passing the
339     RTAUDIO_NONINTERLEAVED flag to the openStream() function, audio
340     data will instead be presented in non-interleaved buffers.  In
341     this case, each buffer argument in the RtAudioCallback function
342     will point to a single array of data, with \c nFrames samples for
343     each channel concatenated back-to-back.  For example, the first
344     sample of data for the second channel would be located at index \c
345     nFrames (assuming the \c buffer pointer was recast to the correct
346     data type for the stream).
347
348     Certain audio APIs offer a number of parameters that influence the
349     I/O latency of a stream.  By default, RtAudio will attempt to set
350     these parameters internally for robust (glitch-free) performance
351     (though some APIs, like Windows DirectSound, make this difficult).
352     By passing the RTAUDIO_MINIMIZE_LATENCY flag to the openStream()
353     function, internal stream settings will be influenced in an attempt
354     to minimize stream latency, though possibly at the expense of stream
355     performance.
356
357     If the RTAUDIO_HOG_DEVICE flag is set, RtAudio will attempt to
358     open the input and/or output stream device(s) for exclusive use.
359     Note that this is not possible with all supported audio APIs.
360
361     If the RTAUDIO_SCHEDULE_REALTIME flag is set, RtAudio will attempt
362     to select realtime scheduling (round-robin) for the callback thread.
363     The \c priority parameter will only be used if the RTAUDIO_SCHEDULE_REALTIME
364     flag is set. It defines the thread's realtime priority.
365
366     If the RTAUDIO_ALSA_USE_DEFAULT flag is set, RtAudio will attempt to
367     open the "default" PCM device when using the ALSA API. Note that this
368     will override any specified input or output device id.
369
370     The \c numberOfBuffers parameter can be used to control stream
371     latency in the Windows DirectSound, Linux OSS, and Linux Alsa APIs
372     only.  A value of two is usually the smallest allowed.  Larger
373     numbers can potentially result in more robust stream performance,
374     though likely at the cost of stream latency.  The value set by the
375     user is replaced during execution of the RtAudio::openStream()
376     function by the value actually used by the system.
377
378     The \c streamName parameter can be used to set the client name
379     when using the Jack API.  By default, the client name is set to
380     RtApiJack.  However, if you wish to create multiple instances of
381     RtAudio with Jack, each instance must have a unique client name.
382   */
383   struct StreamOptions {
384     RtAudioStreamFlags flags;      /*!< A bit-mask of stream flags (RTAUDIO_NONINTERLEAVED, RTAUDIO_MINIMIZE_LATENCY, RTAUDIO_HOG_DEVICE, RTAUDIO_ALSA_USE_DEFAULT). */
385     unsigned int numberOfBuffers;  /*!< Number of stream buffers. */
386     std::string streamName;        /*!< A stream name (currently used only in Jack). */
387     int priority;                  /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */
388
389     // Default constructor.
390     StreamOptions()
391     : flags(0), numberOfBuffers(0), priority(0) {}
392   };
393
394   //! A static function to determine the current RtAudio version.
395   static std::string getVersion( void );
396
397   //! A static function to determine the available compiled audio APIs.
398   /*!
399     The values returned in the std::vector can be compared against
400     the enumerated list values.  Note that there can be more than one
401     API compiled for certain operating systems.
402   */
403   static void getCompiledApi( std::vector<RtAudio::Api> &apis );
404
405   //! Return the name of a specified compiled audio API.
406   /*!
407     This obtains a short lower-case name used for identification purposes.
408     This value is guaranteed to remain identical across library versions.
409     If the API is unknown, this function will return the empty string.
410   */
411   static std::string getApiName( RtAudio::Api api );
412
413   //! Return the display name of a specified compiled audio API.
414   /*!
415     This obtains a long name used for display purposes.
416     If the API is unknown, this function will return the empty string.
417   */
418   static std::string getApiDisplayName( RtAudio::Api api );
419
420   //! Return the compiled audio API having the given name.
421   /*!
422     A case insensitive comparison will check the specified name
423     against the list of compiled APIs, and return the one which
424     matches. On failure, the function returns UNSPECIFIED.
425   */
426   static RtAudio::Api getCompiledApiByName( const std::string &name );
427
428   //! The class constructor.
429   /*!
430     The constructor performs minor initialization tasks.  An exception
431     can be thrown if no API support is compiled.
432
433     If no API argument is specified and multiple API support has been
434     compiled, the default order of use is JACK, ALSA, OSS (Linux
435     systems) and ASIO, DS (Windows systems).
436   */
437   RtAudio( RtAudio::Api api=UNSPECIFIED );
438
439   //! The destructor.
440   /*!
441     If a stream is running or open, it will be stopped and closed
442     automatically.
443   */
444   ~RtAudio();
445
446   //! Returns the audio API specifier for the current instance of RtAudio.
447   RtAudio::Api getCurrentApi( void );
448
449   //! A public function that queries for the number of audio devices available.
450   /*!
451     This function performs a system query of available devices each time it
452     is called, thus supporting devices connected \e after instantiation. If
453     a system error occurs during processing, a warning will be issued.
454   */
455   unsigned int getDeviceCount( void );
456
457   //! Return an RtAudio::DeviceInfo structure for a specified device number.
458   /*!
459
460     Any device integer between 0 and getDeviceCount() - 1 is valid.
461     If an invalid argument is provided, an RtAudioError (type = INVALID_USE)
462     will be thrown.  If a device is busy or otherwise unavailable, the
463     structure member "probed" will have a value of "false" and all
464     other members are undefined.  If the specified device is the
465     current default input or output device, the corresponding
466     "isDefault" member will have a value of "true".
467   */
468   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
469
470   //! A function that returns the index of the default output device.
471   /*!
472     If the underlying audio API does not provide a "default
473     device", or if no devices are available, the return value will be
474     0.  Note that this is a valid device identifier and it is the
475     client's responsibility to verify that a device is available
476     before attempting to open a stream.
477   */
478   unsigned int getDefaultOutputDevice( void );
479
480   //! A function that returns the index of the default input device.
481   /*!
482     If the underlying audio API does not provide a "default
483     device", or if no devices are available, the return value will be
484     0.  Note that this is a valid device identifier and it is the
485     client's responsibility to verify that a device is available
486     before attempting to open a stream.
487   */
488   unsigned int getDefaultInputDevice( void );
489
490   //! A public function for opening a stream with the specified parameters.
491   /*!
492     An RtAudioError (type = SYSTEM_ERROR) is thrown if a stream cannot be
493     opened with the specified parameters or an error occurs during
494     processing.  An RtAudioError (type = INVALID_USE) is thrown if any
495     invalid device ID or channel number parameters are specified.
496
497     \param outputParameters Specifies output stream parameters to use
498            when opening a stream, including a device ID, number of channels,
499            and starting channel number.  For input-only streams, this
500            argument should be NULL.  The device ID is an index value between
501            0 and getDeviceCount() - 1.
502     \param inputParameters Specifies input stream parameters to use
503            when opening a stream, including a device ID, number of channels,
504            and starting channel number.  For output-only streams, this
505            argument should be NULL.  The device ID is an index value between
506            0 and getDeviceCount() - 1.
507     \param format An RtAudioFormat specifying the desired sample data format.
508     \param sampleRate The desired sample rate (sample frames per second).
509     \param *bufferFrames A pointer to a value indicating the desired
510            internal buffer size in sample frames.  The actual value
511            used by the device is returned via the same pointer.  A
512            value of zero can be specified, in which case the lowest
513            allowable value is determined.
514     \param callback A client-defined function that will be invoked
515            when input data is available and/or output data is needed.
516     \param userData An optional pointer to data that can be accessed
517            from within the callback function.
518     \param options An optional pointer to a structure containing various
519            global stream options, including a list of OR'ed RtAudioStreamFlags
520            and a suggested number of stream buffers that can be used to
521            control stream latency.  More buffers typically result in more
522            robust performance, though at a cost of greater latency.  If a
523            value of zero is specified, a system-specific median value is
524            chosen.  If the RTAUDIO_MINIMIZE_LATENCY flag bit is set, the
525            lowest allowable value is used.  The actual value used is
526            returned via the structure argument.  The parameter is API dependent.
527     \param errorCallback A client-defined function that will be invoked
528            when an error has occured.
529   */
530   void openStream( RtAudio::StreamParameters *outputParameters,
531                    RtAudio::StreamParameters *inputParameters,
532                    RtAudioFormat format, unsigned int sampleRate,
533                    unsigned int *bufferFrames, RtAudioCallback callback,
534                    void *userData = NULL, RtAudio::StreamOptions *options = NULL, RtAudioErrorCallback errorCallback = NULL );
535
536   //! A function that closes a stream and frees any associated stream memory.
537   /*!
538     If a stream is not open, this function issues a warning and
539     returns (no exception is thrown).
540   */
541   void closeStream( void );
542
543   //! A function that starts a stream.
544   /*!
545     An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
546     during processing.  An RtAudioError (type = INVALID_USE) is thrown if a
547     stream is not open.  A warning is issued if the stream is already
548     running.
549   */
550   void startStream( void );
551
552   //! Stop a stream, allowing any samples remaining in the output queue to be played.
553   /*!
554     An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
555     during processing.  An RtAudioError (type = INVALID_USE) is thrown if a
556     stream is not open.  A warning is issued if the stream is already
557     stopped.
558   */
559   void stopStream( void );
560
561   //! Stop a stream, discarding any samples remaining in the input/output queue.
562   /*!
563     An RtAudioError (type = SYSTEM_ERROR) is thrown if an error occurs
564     during processing.  An RtAudioError (type = INVALID_USE) is thrown if a
565     stream is not open.  A warning is issued if the stream is already
566     stopped.
567   */
568   void abortStream( void );
569
570   //! Returns true if a stream is open and false if not.
571   bool isStreamOpen( void ) const;
572
573   //! Returns true if the stream is running and false if it is stopped or not open.
574   bool isStreamRunning( void ) const;
575
576   //! Returns the number of elapsed seconds since the stream was started.
577   /*!
578     If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.
579   */
580   double getStreamTime( void );
581
582   //! Set the stream time to a time in seconds greater than or equal to 0.0.
583   /*!
584     If a stream is not open, an RtAudioError (type = INVALID_USE) will be thrown.
585   */
586   void setStreamTime( double time );
587
588   //! Returns the internal stream latency in sample frames.
589   /*!
590     The stream latency refers to delay in audio input and/or output
591     caused by internal buffering by the audio system and/or hardware.
592     For duplex streams, the returned value will represent the sum of
593     the input and output latencies.  If a stream is not open, an
594     RtAudioError (type = INVALID_USE) will be thrown.  If the API does not
595     report latency, the return value will be zero.
596   */
597   long getStreamLatency( void );
598
599  //! Returns actual sample rate in use by the stream.
600  /*!
601    On some systems, the sample rate used may be slightly different
602    than that specified in the stream parameters.  If a stream is not
603    open, an RtAudioError (type = INVALID_USE) will be thrown.
604  */
605   unsigned int getStreamSampleRate( void );
606
607   //! Specify whether warning messages should be printed to stderr.
608   void showWarnings( bool value = true );
609
610  protected:
611
612   void openRtApi( RtAudio::Api api );
613   RtApi *rtapi_;
614 };
615
616 // Operating system dependent thread functionality.
617 #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) || defined(__WINDOWS_WASAPI__)
618
619   #ifndef NOMINMAX
620     #define NOMINMAX
621   #endif
622   #include <windows.h>
623   #include <process.h>
624   #include <stdint.h>
625
626   typedef uintptr_t ThreadHandle;
627   typedef CRITICAL_SECTION StreamMutex;
628
629 #elif defined(__LINUX_ALSA__) || defined(__LINUX_PULSE__) || defined(__UNIX_JACK__) || defined(__LINUX_OSS__) || defined(__MACOSX_CORE__)
630   // Using pthread library for various flavors of unix.
631   #include <pthread.h>
632
633   typedef pthread_t ThreadHandle;
634   typedef pthread_mutex_t StreamMutex;
635
636 #else // Setup for "dummy" behavior
637
638   #define __RTAUDIO_DUMMY__
639   typedef int ThreadHandle;
640   typedef int StreamMutex;
641
642 #endif
643
644 // This global structure type is used to pass callback information
645 // between the private RtAudio stream structure and global callback
646 // handling functions.
647 struct CallbackInfo {
648   void *object;    // Used as a "this" pointer.
649   ThreadHandle thread;
650   void *callback;
651   void *userData;
652   void *errorCallback;
653   void *apiInfo;   // void pointer for API specific callback information
654   bool isRunning;
655   bool doRealtime;
656   int priority;
657
658   // Default constructor.
659   CallbackInfo()
660   :object(0), callback(0), userData(0), errorCallback(0), apiInfo(0), isRunning(false), doRealtime(false), priority(0) {}
661 };
662
663 // **************************************************************** //
664 //
665 // RtApi class declaration.
666 //
667 // Subclasses of RtApi contain all API- and OS-specific code necessary
668 // to fully implement the RtAudio API.
669 //
670 // Note that RtApi is an abstract base class and cannot be
671 // explicitly instantiated.  The class RtAudio will create an
672 // instance of an RtApi subclass (RtApiOss, RtApiAlsa,
673 // RtApiJack, RtApiCore, RtApiDs, or RtApiAsio).
674 //
675 // **************************************************************** //
676
677 #pragma pack(push, 1)
678 class S24 {
679
680  protected:
681   unsigned char c3[3];
682
683  public:
684   S24() {}
685
686   S24& operator = ( const int& i ) {
687     c3[0] = (i & 0x000000ff);
688     c3[1] = (i & 0x0000ff00) >> 8;
689     c3[2] = (i & 0x00ff0000) >> 16;
690     return *this;
691   }
692
693   S24( const double& d ) { *this = (int) d; }
694   S24( const float& f ) { *this = (int) f; }
695   S24( const signed short& s ) { *this = (int) s; }
696   S24( const char& c ) { *this = (int) c; }
697
698   int asInt() {
699     int i = c3[0] | (c3[1] << 8) | (c3[2] << 16);
700     if (i & 0x800000) i |= ~0xffffff;
701     return i;
702   }
703 };
704 #pragma pack(pop)
705
706 #if defined( HAVE_GETTIMEOFDAY )
707   #include <sys/time.h>
708 #endif
709
710 #include <sstream>
711
712 class RTAUDIO_DLL_PUBLIC RtApi
713 {
714 public:
715
716   RtApi();
717   virtual ~RtApi();
718   virtual RtAudio::Api getCurrentApi( void ) = 0;
719   virtual unsigned int getDeviceCount( void ) = 0;
720   virtual RtAudio::DeviceInfo getDeviceInfo( unsigned int device ) = 0;
721   virtual unsigned int getDefaultInputDevice( void );
722   virtual unsigned int getDefaultOutputDevice( void );
723   void openStream( RtAudio::StreamParameters *outputParameters,
724                    RtAudio::StreamParameters *inputParameters,
725                    RtAudioFormat format, unsigned int sampleRate,
726                    unsigned int *bufferFrames, RtAudioCallback callback,
727                    void *userData, RtAudio::StreamOptions *options,
728                    RtAudioErrorCallback errorCallback );
729   virtual void closeStream( void );
730   virtual void startStream( void ) = 0;
731   virtual void stopStream( void ) = 0;
732   virtual void abortStream( void ) = 0;
733   long getStreamLatency( void );
734   unsigned int getStreamSampleRate( void );
735   virtual double getStreamTime( void );
736   virtual void setStreamTime( double time );
737   bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
738   bool isStreamRunning( void ) const { return stream_.state == STREAM_RUNNING; }
739   void showWarnings( bool value ) { showWarnings_ = value; }
740
741
742 protected:
743
744   static const unsigned int MAX_SAMPLE_RATES;
745   static const unsigned int SAMPLE_RATES[];
746
747   enum { FAILURE, SUCCESS };
748
749   enum StreamState {
750     STREAM_STOPPED,
751     STREAM_STOPPING,
752     STREAM_RUNNING,
753     STREAM_CLOSED = -50
754   };
755
756   enum StreamMode {
757     OUTPUT,
758     INPUT,
759     DUPLEX,
760     UNINITIALIZED = -75
761   };
762
763   // A protected structure used for buffer conversion.
764   struct ConvertInfo {
765     int channels;
766     int inJump, outJump;
767     RtAudioFormat inFormat, outFormat;
768     std::vector<int> inOffset;
769     std::vector<int> outOffset;
770   };
771
772   // A protected structure for audio streams.
773   struct RtApiStream {
774     unsigned int device[2];    // Playback and record, respectively.
775     void *apiHandle;           // void pointer for API specific stream handle information
776     StreamMode mode;           // OUTPUT, INPUT, or DUPLEX.
777     StreamState state;         // STOPPED, RUNNING, or CLOSED
778     char *userBuffer[2];       // Playback and record, respectively.
779     char *deviceBuffer;
780     bool doConvertBuffer[2];   // Playback and record, respectively.
781     bool userInterleaved;
782     bool deviceInterleaved[2]; // Playback and record, respectively.
783     bool doByteSwap[2];        // Playback and record, respectively.
784     unsigned int sampleRate;
785     unsigned int bufferSize;
786     unsigned int nBuffers;
787     unsigned int nUserChannels[2];    // Playback and record, respectively.
788     unsigned int nDeviceChannels[2];  // Playback and record channels, respectively.
789     unsigned int channelOffset[2];    // Playback and record, respectively.
790     unsigned long latency[2];         // Playback and record, respectively.
791     RtAudioFormat userFormat;
792     RtAudioFormat deviceFormat[2];    // Playback and record, respectively.
793     StreamMutex mutex;
794     CallbackInfo callbackInfo;
795     ConvertInfo convertInfo[2];
796     double streamTime;         // Number of elapsed seconds since the stream started.
797
798 #if defined(HAVE_GETTIMEOFDAY)
799     // The gettimeofday() when tickStreamTime was last called, or both
800     // fields at 0 if tickStreamTime has not been called since the last
801     // startStream().
802     struct timeval lastTickTimestamp;
803 #endif
804
805     RtApiStream()
806       :apiHandle(0), deviceBuffer(0) { device[0] = 11111; device[1] = 11111; }
807   };
808
809   typedef S24 Int24;
810   typedef signed short Int16;
811   typedef signed int Int32;
812   typedef float Float32;
813   typedef double Float64;
814
815   std::ostringstream errorStream_;
816   std::string errorText_;
817   bool showWarnings_;
818   RtApiStream stream_;
819   bool firstErrorOccurred_;
820
821   /*!
822     Protected, api-specific method that attempts to open a device
823     with the given parameters.  This function MUST be implemented by
824     all subclasses.  If an error is encountered during the probe, a
825     "warning" message is reported and FAILURE is returned. A
826     successful probe is indicated by a return value of SUCCESS.
827   */
828   virtual bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
829                                 unsigned int firstChannel, unsigned int sampleRate,
830                                 RtAudioFormat format, unsigned int *bufferSize,
831                                 RtAudio::StreamOptions *options );
832
833   //! A protected function used to increment the stream time.
834   void tickStreamTime( void );
835
836   //! Protected common method to clear an RtApiStream structure.
837   void clearStreamInfo();
838
839   /*!
840     Protected common method that throws an RtAudioError (type =
841     INVALID_USE) if a stream is not open.
842   */
843   void verifyStream( void );
844
845   //! Protected common error method to allow global control over error handling.
846   void error( RtAudioError::Type type );
847
848   /*!
849     Protected method used to perform format, channel number, and/or interleaving
850     conversions between the user and device buffers.
851   */
852   void convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info );
853
854   //! Protected common method used to perform byte-swapping on buffers.
855   void byteSwapBuffer( char *buffer, unsigned int samples, RtAudioFormat format );
856
857   //! Protected common method that returns the number of bytes for a given format.
858   unsigned int formatBytes( RtAudioFormat format );
859
860   //! Protected common method that sets up the parameters for buffer conversion.
861   void setConvertInfo( StreamMode mode, unsigned int firstChannel );
862 };
863
864 // **************************************************************** //
865 //
866 // Inline RtAudio definitions.
867 //
868 // **************************************************************** //
869
870 inline RtAudio::Api RtAudio :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
871 inline unsigned int RtAudio :: getDeviceCount( void ) { return rtapi_->getDeviceCount(); }
872 inline RtAudio::DeviceInfo RtAudio :: getDeviceInfo( unsigned int device ) { return rtapi_->getDeviceInfo( device ); }
873 inline unsigned int RtAudio :: getDefaultInputDevice( void ) { return rtapi_->getDefaultInputDevice(); }
874 inline unsigned int RtAudio :: getDefaultOutputDevice( void ) { return rtapi_->getDefaultOutputDevice(); }
875 inline void RtAudio :: closeStream( void ) { return rtapi_->closeStream(); }
876 inline void RtAudio :: startStream( void ) { return rtapi_->startStream(); }
877 inline void RtAudio :: stopStream( void )  { return rtapi_->stopStream(); }
878 inline void RtAudio :: abortStream( void ) { return rtapi_->abortStream(); }
879 inline bool RtAudio :: isStreamOpen( void ) const { return rtapi_->isStreamOpen(); }
880 inline bool RtAudio :: isStreamRunning( void ) const { return rtapi_->isStreamRunning(); }
881 inline long RtAudio :: getStreamLatency( void ) { return rtapi_->getStreamLatency(); }
882 inline unsigned int RtAudio :: getStreamSampleRate( void ) { return rtapi_->getStreamSampleRate(); }
883 inline double RtAudio :: getStreamTime( void ) { return rtapi_->getStreamTime(); }
884 inline void RtAudio :: setStreamTime( double time ) { return rtapi_->setStreamTime( time ); }
885 inline void RtAudio :: showWarnings( bool value ) { rtapi_->showWarnings( value ); }
886
887 // RtApi Subclass prototypes.
888
889 #if defined(__MACOSX_CORE__)
890
891 #include <CoreAudio/AudioHardware.h>
892
893 class RtApiCore: public RtApi
894 {
895 public:
896
897   RtApiCore();
898   ~RtApiCore();
899   RtAudio::Api getCurrentApi( void ) { return RtAudio::MACOSX_CORE; }
900   unsigned int getDeviceCount( void );
901   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
902   unsigned int getDefaultOutputDevice( void );
903   unsigned int getDefaultInputDevice( void );
904   void closeStream( void );
905   void startStream( void );
906   void stopStream( void );
907   void abortStream( void );
908
909   // This function is intended for internal use only.  It must be
910   // public because it is called by the internal callback handler,
911   // which is not a member of RtAudio.  External use of this function
912   // will most likely produce highly undesireable results!
913   bool callbackEvent( AudioDeviceID deviceId,
914                       const AudioBufferList *inBufferList,
915                       const AudioBufferList *outBufferList );
916
917   private:
918
919   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
920                         unsigned int firstChannel, unsigned int sampleRate,
921                         RtAudioFormat format, unsigned int *bufferSize,
922                         RtAudio::StreamOptions *options );
923   static const char* getErrorCode( OSStatus code );
924 };
925
926 #endif
927
928 #if defined(__UNIX_JACK__)
929
930 class RtApiJack: public RtApi
931 {
932 public:
933
934   RtApiJack();
935   ~RtApiJack();
936   RtAudio::Api getCurrentApi( void ) { return RtAudio::UNIX_JACK; }
937   unsigned int getDeviceCount( void );
938   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
939   void closeStream( void );
940   void startStream( void );
941   void stopStream( void );
942   void abortStream( void );
943
944   // This function is intended for internal use only.  It must be
945   // public because it is called by the internal callback handler,
946   // which is not a member of RtAudio.  External use of this function
947   // will most likely produce highly undesireable results!
948   bool callbackEvent( unsigned long nframes );
949
950   private:
951
952   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
953                         unsigned int firstChannel, unsigned int sampleRate,
954                         RtAudioFormat format, unsigned int *bufferSize,
955                         RtAudio::StreamOptions *options );
956
957   bool shouldAutoconnect_;
958 };
959
960 #endif
961
962 #if defined(__WINDOWS_ASIO__)
963
964 class RtApiAsio: public RtApi
965 {
966 public:
967
968   RtApiAsio();
969   ~RtApiAsio();
970   RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_ASIO; }
971   unsigned int getDeviceCount( void );
972   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
973   void closeStream( void );
974   void startStream( void );
975   void stopStream( void );
976   void abortStream( 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   bool callbackEvent( long bufferIndex );
983
984   private:
985
986   std::vector<RtAudio::DeviceInfo> devices_;
987   void saveDeviceInfo( void );
988   bool coInitialized_;
989   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
990                         unsigned int firstChannel, unsigned int sampleRate,
991                         RtAudioFormat format, unsigned int *bufferSize,
992                         RtAudio::StreamOptions *options );
993 };
994
995 #endif
996
997 #if defined(__WINDOWS_DS__)
998
999 class RtApiDs: public RtApi
1000 {
1001 public:
1002
1003   RtApiDs();
1004   ~RtApiDs();
1005   RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_DS; }
1006   unsigned int getDeviceCount( void );
1007   unsigned int getDefaultOutputDevice( void );
1008   unsigned int getDefaultInputDevice( void );
1009   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1010   void closeStream( void );
1011   void startStream( void );
1012   void stopStream( void );
1013   void abortStream( void );
1014
1015   // This function is intended for internal use only.  It must be
1016   // public because it is called by the internal callback handler,
1017   // which is not a member of RtAudio.  External use of this function
1018   // will most likely produce highly undesireable results!
1019   void callbackEvent( void );
1020
1021   private:
1022
1023   bool coInitialized_;
1024   bool buffersRolling;
1025   long duplexPrerollBytes;
1026   std::vector<struct DsDevice> dsDevices;
1027   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1028                         unsigned int firstChannel, unsigned int sampleRate,
1029                         RtAudioFormat format, unsigned int *bufferSize,
1030                         RtAudio::StreamOptions *options );
1031 };
1032
1033 #endif
1034
1035 #if defined(__WINDOWS_WASAPI__)
1036
1037 struct IMMDeviceEnumerator;
1038
1039 class RtApiWasapi : public RtApi
1040 {
1041 public:
1042   RtApiWasapi();
1043   virtual ~RtApiWasapi();
1044
1045   RtAudio::Api getCurrentApi( void ) { return RtAudio::WINDOWS_WASAPI; }
1046   unsigned int getDeviceCount( void );
1047   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1048   unsigned int getDefaultOutputDevice( void );
1049   unsigned int getDefaultInputDevice( void );
1050   void closeStream( void );
1051   void startStream( void );
1052   void stopStream( void );
1053   void abortStream( void );
1054
1055 private:
1056   bool coInitialized_;
1057   IMMDeviceEnumerator* deviceEnumerator_;
1058
1059   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1060                         unsigned int firstChannel, unsigned int sampleRate,
1061                         RtAudioFormat format, unsigned int* bufferSize,
1062                         RtAudio::StreamOptions* options );
1063
1064   static DWORD WINAPI runWasapiThread( void* wasapiPtr );
1065   static DWORD WINAPI stopWasapiThread( void* wasapiPtr );
1066   static DWORD WINAPI abortWasapiThread( void* wasapiPtr );
1067   void wasapiThread();
1068 };
1069
1070 #endif
1071
1072 #if defined(__LINUX_ALSA__)
1073
1074 class RtApiAlsa: public RtApi
1075 {
1076 public:
1077
1078   RtApiAlsa();
1079   ~RtApiAlsa();
1080   RtAudio::Api getCurrentApi() { return RtAudio::LINUX_ALSA; }
1081   unsigned int getDeviceCount( void );
1082   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1083   void closeStream( void );
1084   void startStream( void );
1085   void stopStream( void );
1086   void abortStream( void );
1087
1088   // This function is intended for internal use only.  It must be
1089   // public because it is called by the internal callback handler,
1090   // which is not a member of RtAudio.  External use of this function
1091   // will most likely produce highly undesireable results!
1092   void callbackEvent( void );
1093
1094   private:
1095
1096   std::vector<RtAudio::DeviceInfo> devices_;
1097   void saveDeviceInfo( void );
1098   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1099                         unsigned int firstChannel, unsigned int sampleRate,
1100                         RtAudioFormat format, unsigned int *bufferSize,
1101                         RtAudio::StreamOptions *options );
1102 };
1103
1104 #endif
1105
1106 #if defined(__LINUX_PULSE__)
1107
1108 struct pa_context;
1109 struct pa_sink_info;
1110 struct pa_threaded_mainloop;
1111
1112 class RtApiPulse: public RtApi
1113 {
1114 public:
1115   RtApiPulse() : mainloop_(0), channels_(2) {}
1116   ~RtApiPulse();
1117   RtAudio::Api getCurrentApi() { return RtAudio::LINUX_PULSE; }
1118   unsigned int getDeviceCount( void );
1119   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1120   void closeStream( void );
1121   void startStream( void );
1122   void stopStream( void );
1123   void abortStream( void );
1124
1125   // This function is intended for internal use only.  It must be
1126   // public because it is called by the internal callback handler,
1127   // which is not a member of RtAudio.  External use of this function
1128   // will most likely produce highly undesireable results!
1129   void callbackEvent( void );
1130
1131   private:
1132
1133   std::vector<RtAudio::DeviceInfo> devices_;
1134   void saveDeviceInfo( void );
1135   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1136                         unsigned int firstChannel, unsigned int sampleRate,
1137                         RtAudioFormat format, unsigned int *bufferSize,
1138                         RtAudio::StreamOptions *options );
1139   static void sinkInfoCallback(pa_context* c, const pa_sink_info* info, int eol, void* arg);
1140   static void contextStateCallback(pa_context* c, void* arg);
1141   pa_threaded_mainloop* mainloop_;
1142   int channels_;
1143 };
1144
1145 #endif
1146
1147 #if defined(__LINUX_OSS__)
1148
1149 class RtApiOss: public RtApi
1150 {
1151 public:
1152
1153   RtApiOss();
1154   ~RtApiOss();
1155   RtAudio::Api getCurrentApi() { return RtAudio::LINUX_OSS; }
1156   unsigned int getDeviceCount( void );
1157   RtAudio::DeviceInfo getDeviceInfo( unsigned int device );
1158   void closeStream( void );
1159   void startStream( void );
1160   void stopStream( void );
1161   void abortStream( void );
1162
1163   // This function is intended for internal use only.  It must be
1164   // public because it is called by the internal callback handler,
1165   // which is not a member of RtAudio.  External use of this function
1166   // will most likely produce highly undesireable results!
1167   void callbackEvent( void );
1168
1169   private:
1170
1171   bool probeDeviceOpen( unsigned int device, StreamMode mode, unsigned int channels,
1172                         unsigned int firstChannel, unsigned int sampleRate,
1173                         RtAudioFormat format, unsigned int *bufferSize,
1174                         RtAudio::StreamOptions *options );
1175 };
1176
1177 #endif
1178
1179 #if defined(__RTAUDIO_DUMMY__)
1180
1181 class RtApiDummy: public RtApi
1182 {
1183 public:
1184
1185   RtApiDummy() { errorText_ = "RtApiDummy: This class provides no functionality."; error( RtAudioError::WARNING ); }
1186   RtAudio::Api getCurrentApi( void ) { return RtAudio::RTAUDIO_DUMMY; }
1187   unsigned int getDeviceCount( void ) { return 0; }
1188   RtAudio::DeviceInfo getDeviceInfo( unsigned int /*device*/ ) { RtAudio::DeviceInfo info; return info; }
1189   void closeStream( void ) {}
1190   void startStream( void ) {}
1191   void stopStream( void ) {}
1192   void abortStream( void ) {}
1193
1194   private:
1195
1196   bool probeDeviceOpen( unsigned int /*device*/, StreamMode /*mode*/, unsigned int /*channels*/,
1197                         unsigned int /*firstChannel*/, unsigned int /*sampleRate*/,
1198                         RtAudioFormat /*format*/, unsigned int * /*bufferSize*/,
1199                         RtAudio::StreamOptions * /*options*/ ) { return false; }
1200 };
1201
1202 #endif
1203
1204 #endif
1205
1206 // Indentation settings for Vim and Emacs
1207 //
1208 // Local Variables:
1209 // c-basic-offset: 2
1210 // indent-tabs-mode: nil
1211 // End:
1212 //
1213 // vim: et sts=2 sw=2