You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1203 lines
47KB

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