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