RtAudio.h 46 KB

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