Audio plugin host https://kx.studio/carla
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.

RtAudio.h 46KB

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