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