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.

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