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.

716 lines
25KB

  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), SGI, Macintosh OS X (CoreAudio), and Windows
  7. (DirectSound and ASIO) operating systems.
  8. RtAudio WWW site: http://music.mcgill.ca/~gary/rtaudio/
  9. RtAudio: a realtime audio i/o C++ class
  10. Copyright (c) 2001-2004 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. requested to send the modifications to the original developer so that
  22. they can be incorporated into the canonical version.
  23. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  27. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  28. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. */
  31. /************************************************************************/
  32. // RtAudio: Version 3.0, 11 March 2004
  33. #ifndef __RTAUDIO_H
  34. #define __RTAUDIO_H
  35. #include "RtError.h"
  36. #include <string>
  37. #include <vector>
  38. // Operating system dependent thread functionality.
  39. #if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
  40. #include <windows.h>
  41. #include <process.h>
  42. typedef unsigned long ThreadHandle;
  43. typedef CRITICAL_SECTION StreamMutex;
  44. #else // Various unix flavors with pthread support.
  45. #include <pthread.h>
  46. typedef pthread_t ThreadHandle;
  47. typedef pthread_mutex_t StreamMutex;
  48. #endif
  49. // This global structure type is used to pass callback information
  50. // between the private RtAudio stream structure and global callback
  51. // handling functions.
  52. struct CallbackInfo {
  53. void *object; // Used as a "this" pointer.
  54. ThreadHandle thread;
  55. bool usingCallback;
  56. void *callback;
  57. void *userData;
  58. void *apiInfo; // void pointer for API specific callback information
  59. // Default constructor.
  60. CallbackInfo()
  61. :object(0), usingCallback(false), callback(0),
  62. userData(0), apiInfo(0) {}
  63. };
  64. // Support for signed integers and floats. Audio data fed to/from
  65. // the tickStream() routine is assumed to ALWAYS be in host
  66. // byte order. The internal routines will automatically take care of
  67. // any necessary byte-swapping between the host format and the
  68. // soundcard. Thus, endian-ness is not a concern in the following
  69. // format definitions.
  70. typedef unsigned long RtAudioFormat;
  71. static const RtAudioFormat RTAUDIO_SINT8 = 0x1; /*!< 8-bit signed integer. */
  72. static const RtAudioFormat RTAUDIO_SINT16 = 0x2; /*!< 16-bit signed integer. */
  73. static const RtAudioFormat RTAUDIO_SINT24 = 0x4; /*!< Upper 3 bytes of 32-bit signed integer. */
  74. static const RtAudioFormat RTAUDIO_SINT32 = 0x8; /*!< 32-bit signed integer. */
  75. static const RtAudioFormat RTAUDIO_FLOAT32 = 0x10; /*!< Normalized between plus/minus 1.0. */
  76. static const RtAudioFormat RTAUDIO_FLOAT64 = 0x20; /*!< Normalized between plus/minus 1.0. */
  77. typedef int (*RtAudioCallback)(char *buffer, int bufferSize, void *userData);
  78. //! The public device information structure for returning queried values.
  79. struct RtAudioDeviceInfo {
  80. std::string name; /*!< Character string device identifier. */
  81. bool probed; /*!< true if the device capabilities were successfully probed. */
  82. int outputChannels; /*!< Maximum output channels supported by device. */
  83. int inputChannels; /*!< Maximum input channels supported by device. */
  84. int duplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */
  85. bool isDefault; /*!< true if this is the default output or input device. */
  86. std::vector<int> sampleRates; /*!< Supported sample rates (queried from list of standard rates). */
  87. RtAudioFormat nativeFormats; /*!< Bit mask of supported data formats. */
  88. // Default constructor.
  89. RtAudioDeviceInfo()
  90. :probed(false), outputChannels(0), inputChannels(0),
  91. duplexChannels(0), isDefault(false), nativeFormats(0) {}
  92. };
  93. // **************************************************************** //
  94. //
  95. // RtApi class declaration.
  96. //
  97. // Note that RtApi is an abstract base class and cannot be
  98. // explicitly instantiated. The class RtAudio will create an
  99. // instance of an RtApi subclass (RtApiOss, RtApiAlsa,
  100. // RtApiJack, RtApiCore, RtApiAl, RtApiDs, or RtApiAsio).
  101. //
  102. // **************************************************************** //
  103. class RtApi
  104. {
  105. public:
  106. RtApi();
  107. virtual ~RtApi();
  108. void openStream( int outputDevice, int outputChannels,
  109. int inputDevice, int inputChannels,
  110. RtAudioFormat format, int sampleRate,
  111. int *bufferSize, int numberOfBuffers );
  112. virtual void setStreamCallback( RtAudioCallback callback, void *userData ) = 0;
  113. virtual void cancelStreamCallback() = 0;
  114. int getDeviceCount(void);
  115. RtAudioDeviceInfo getDeviceInfo( int device );
  116. char * const getStreamBuffer();
  117. virtual void tickStream() = 0;
  118. virtual void closeStream();
  119. virtual void startStream() = 0;
  120. virtual void stopStream() = 0;
  121. virtual void abortStream() = 0;
  122. protected:
  123. static const unsigned int MAX_SAMPLE_RATES;
  124. static const unsigned int SAMPLE_RATES[];
  125. enum { FAILURE, SUCCESS };
  126. enum StreamMode {
  127. OUTPUT,
  128. INPUT,
  129. DUPLEX,
  130. UNINITIALIZED = -75
  131. };
  132. enum StreamState {
  133. STREAM_STOPPED,
  134. STREAM_RUNNING
  135. };
  136. // A protected structure for audio streams.
  137. struct RtApiStream {
  138. int device[2]; // Playback and record, respectively.
  139. void *apiHandle; // void pointer for API specific stream handle information
  140. StreamMode mode; // OUTPUT, INPUT, or DUPLEX.
  141. StreamState state; // STOPPED or RUNNING
  142. char *userBuffer;
  143. char *deviceBuffer;
  144. bool doConvertBuffer[2]; // Playback and record, respectively.
  145. bool deInterleave[2]; // Playback and record, respectively.
  146. bool doByteSwap[2]; // Playback and record, respectively.
  147. int sampleRate;
  148. int bufferSize;
  149. int nBuffers;
  150. int nUserChannels[2]; // Playback and record, respectively.
  151. int nDeviceChannels[2]; // Playback and record channels, respectively.
  152. RtAudioFormat userFormat;
  153. RtAudioFormat deviceFormat[2]; // Playback and record, respectively.
  154. StreamMutex mutex;
  155. CallbackInfo callbackInfo;
  156. RtApiStream()
  157. :apiHandle(0), userBuffer(0), deviceBuffer(0) {}
  158. // :apiHandle(0), mode(UNINITIALIZED), state(STREAM_STOPPED),
  159. // userBuffer(0), deviceBuffer(0) {}
  160. };
  161. // A protected device structure for audio devices.
  162. struct RtApiDevice {
  163. std::string name; /*!< Character string device identifier. */
  164. bool probed; /*!< true if the device capabilities were successfully probed. */
  165. void *apiDeviceId; // void pointer for API specific device information
  166. int maxOutputChannels; /*!< Maximum output channels supported by device. */
  167. int maxInputChannels; /*!< Maximum input channels supported by device. */
  168. int maxDuplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */
  169. int minOutputChannels; /*!< Minimum output channels supported by device. */
  170. int minInputChannels; /*!< Minimum input channels supported by device. */
  171. int minDuplexChannels; /*!< Minimum simultaneous input/output channels supported by device. */
  172. bool hasDuplexSupport; /*!< true if device supports duplex mode. */
  173. bool isDefault; /*!< true if this is the default output or input device. */
  174. std::vector<int> sampleRates; /*!< Supported sample rates. */
  175. RtAudioFormat nativeFormats; /*!< Bit mask of supported data formats. */
  176. // Default constructor.
  177. RtApiDevice()
  178. :probed(false), apiDeviceId(0), maxOutputChannels(0), maxInputChannels(0),
  179. maxDuplexChannels(0), minOutputChannels(0), minInputChannels(0),
  180. minDuplexChannels(0), isDefault(false), nativeFormats(0) {}
  181. };
  182. typedef signed short Int16;
  183. typedef signed int Int32;
  184. typedef float Float32;
  185. typedef double Float64;
  186. char message_[256];
  187. int nDevices_;
  188. std::vector<RtApiDevice> devices_;
  189. RtApiStream stream_;
  190. /*!
  191. Protected, api-specific method to count and identify the system
  192. audio devices. This function MUST be implemented by all subclasses.
  193. */
  194. virtual void initialize(void) = 0;
  195. /*!
  196. Protected, api-specific method which attempts to fill an
  197. RtAudioDevice structure for a given device. This function MUST be
  198. implemented by all subclasses. If an error is encountered during
  199. the probe, a "warning" message is reported and the value of
  200. "probed" remains false (no exception is thrown). A successful
  201. probe is indicated by probed = true.
  202. */
  203. virtual void probeDeviceInfo( RtApiDevice *info );
  204. /*!
  205. Protected, api-specific method which attempts to open a device
  206. with the given parameters. This function MUST be implemented by
  207. all subclasses. If an error is encountered during the probe, a
  208. "warning" message is reported and FAILURE is returned (no
  209. exception is thrown). A successful probe is indicated by a return
  210. value of SUCCESS.
  211. */
  212. virtual bool probeDeviceOpen( int device, StreamMode mode, int channels,
  213. int sampleRate, RtAudioFormat format,
  214. int *bufferSize, int numberOfBuffers );
  215. /*!
  216. Protected method which returns the index in the devices array to
  217. the default input device.
  218. */
  219. virtual int getDefaultInputDevice(void);
  220. /*!
  221. Protected method which returns the index in the devices array to
  222. the default output device.
  223. */
  224. virtual int getDefaultOutputDevice(void);
  225. //! Protected common method to clear an RtApiDevice structure.
  226. void clearDeviceInfo( RtApiDevice *info );
  227. //! Protected common method to clear an RtApiStream structure.
  228. void clearStreamInfo();
  229. //! Protected common error method to allow global control over error handling.
  230. void error( RtError::Type type );
  231. /*!
  232. Protected common method used to check whether a stream is open.
  233. If not, an "invalid identifier" exception is thrown.
  234. */
  235. void verifyStream();
  236. /*!
  237. Protected method used to perform format, channel number, and/or interleaving
  238. conversions between the user and device buffers.
  239. */
  240. void convertStreamBuffer( StreamMode mode );
  241. //! Protected common method used to perform byte-swapping on buffers.
  242. void byteSwapBuffer( char *buffer, int samples, RtAudioFormat format );
  243. //! Protected common method which returns the number of bytes for a given format.
  244. int formatBytes( RtAudioFormat format );
  245. };
  246. // **************************************************************** //
  247. //
  248. // RtAudio class declaration.
  249. //
  250. // RtAudio is a "controller" used to select an available audio i/o
  251. // interface. It presents a common API for the user to call but all
  252. // functionality is implemented by the class RtAudioApi and its
  253. // subclasses. RtAudio creates an instance of an RtAudioApi subclass
  254. // based on the user's API choice. If no choice is made, RtAudio
  255. // attempts to make a "logical" API selection.
  256. //
  257. // **************************************************************** //
  258. class RtAudio
  259. {
  260. public:
  261. //! Audio API specifier arguments.
  262. enum RtAudioApi {
  263. UNSPECIFIED, /*!< Search for a working compiled API. */
  264. LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
  265. LINUX_OSS, /*!< The Linux Open Sound System API. */
  266. LINUX_JACK, /*!< The Linux Jack Low-Latency Audio Server API. */
  267. MACOSX_CORE, /*!< Macintosh OS-X Core Audio API. */
  268. IRIX_AL, /*!< The Irix Audio Library API. */
  269. WINDOWS_ASIO, /*!< The Steinberg Audio Stream I/O API. */
  270. WINDOWS_DS /*!< The Microsoft Direct Sound API. */
  271. };
  272. //! The default class constructor.
  273. /*!
  274. Probes the system to make sure at least one audio input/output
  275. device is available and determines the api-specific identifier for
  276. each device found. An RtError error can be thrown if no devices
  277. are found or if a memory allocation error occurs.
  278. If no API argument is specified and multiple API support has been
  279. compiled, the default order of use is JACK, ALSA, OSS (Linux
  280. systems) and ASIO, DS (Windows systems).
  281. */
  282. RtAudio( RtAudioApi api=UNSPECIFIED );
  283. //! A constructor which can be used to open a stream during instantiation.
  284. /*!
  285. The specified output and/or input device identifiers correspond
  286. to those enumerated via the getDeviceInfo() method. If device =
  287. 0, the default or first available devices meeting the given
  288. parameters is selected. If an output or input channel value is
  289. zero, the corresponding device value is ignored. When a stream is
  290. successfully opened, its identifier is returned via the "streamId"
  291. pointer. An RtError can be thrown if no devices are found
  292. for the given parameters, if a memory allocation error occurs, or
  293. if a driver error occurs. \sa openStream()
  294. */
  295. RtAudio( int outputDevice, int outputChannels,
  296. int inputDevice, int inputChannels,
  297. RtAudioFormat format, int sampleRate,
  298. int *bufferSize, int numberOfBuffers, RtAudioApi api=UNSPECIFIED );
  299. //! The destructor.
  300. /*!
  301. Stops and closes an open stream and devices and deallocates
  302. buffer and structure memory.
  303. */
  304. ~RtAudio();
  305. //! A public method for opening a stream with the specified parameters.
  306. /*!
  307. An RtError is thrown if a stream cannot be opened.
  308. \param outputDevice: If equal to 0, the default or first device
  309. found meeting the given parameters is opened. Otherwise, the
  310. device number should correspond to one of those enumerated via
  311. the getDeviceInfo() method.
  312. \param outputChannels: The desired number of output channels. If
  313. equal to zero, the outputDevice identifier is ignored.
  314. \param inputDevice: If equal to 0, the default or first device
  315. found meeting the given parameters is opened. Otherwise, the
  316. device number should correspond to one of those enumerated via
  317. the getDeviceInfo() method.
  318. \param inputChannels: The desired number of input channels. If
  319. equal to zero, the inputDevice identifier is ignored.
  320. \param format: An RtAudioFormat specifying the desired sample data format.
  321. \param sampleRate: The desired sample rate (sample frames per second).
  322. \param *bufferSize: A pointer value indicating the desired internal buffer
  323. size in sample frames. The actual value used by the device is
  324. returned via the same pointer. A value of zero can be specified,
  325. in which case the lowest allowable value is determined.
  326. \param numberOfBuffers: A value which can be used to help control device
  327. latency. More buffers typically result in more robust performance,
  328. though at a cost of greater latency. A value of zero can be
  329. specified, in which case the lowest allowable value is used.
  330. */
  331. void openStream( int outputDevice, int outputChannels,
  332. int inputDevice, int inputChannels,
  333. RtAudioFormat format, int sampleRate,
  334. int *bufferSize, int numberOfBuffers );
  335. //! A public method which sets a user-defined callback function for a given stream.
  336. /*!
  337. This method assigns a callback function to a previously opened
  338. stream for non-blocking stream functionality. A separate process
  339. is initiated, though the user function is called only when the
  340. stream is "running" (between calls to the startStream() and
  341. stopStream() methods, respectively). The callback process remains
  342. active for the duration of the stream and is automatically
  343. shutdown when the stream is closed (via the closeStream() method
  344. or by object destruction). The callback process can also be
  345. shutdown and the user function de-referenced through an explicit
  346. call to the cancelStreamCallback() method. Note that the stream
  347. can use only blocking or callback functionality at a particular
  348. time, though it is possible to alternate modes on the same stream
  349. through the use of the setStreamCallback() and
  350. cancelStreamCallback() methods (the blocking tickStream() method
  351. can be used before a callback is set and/or after a callback is
  352. cancelled). An RtError will be thrown if called when no stream is
  353. open or a thread errors occurs.
  354. */
  355. void setStreamCallback(RtAudioCallback callback, void *userData) { rtapi_->setStreamCallback( callback, userData ); };
  356. //! A public method which cancels a callback process and function for the stream.
  357. /*!
  358. This method shuts down a callback process and de-references the
  359. user function for the stream. Callback functionality can
  360. subsequently be restarted on the stream via the
  361. setStreamCallback() method. An RtError will be thrown if called
  362. when no stream is open.
  363. */
  364. void cancelStreamCallback() { rtapi_->cancelStreamCallback(); };
  365. //! A public method which returns the number of audio devices found.
  366. int getDeviceCount(void) { return rtapi_->getDeviceCount(); };
  367. //! Return an RtAudioDeviceInfo structure for a specified device number.
  368. /*!
  369. Any device integer between 1 and getDeviceCount() is valid. If
  370. a device is busy or otherwise unavailable, the structure member
  371. "probed" will have a value of "false" and all other members are
  372. undefined. If the specified device is the current default input
  373. or output device, the "isDefault" member will have a value of
  374. "true". An RtError will be thrown for an invalid device argument.
  375. */
  376. RtAudioDeviceInfo getDeviceInfo(int device) { return rtapi_->getDeviceInfo( device ); };
  377. //! A public method which returns a pointer to the buffer for an open stream.
  378. /*!
  379. The user should fill and/or read the buffer data in interleaved format
  380. and then call the tickStream() method. An RtError will be
  381. thrown if called when no stream is open.
  382. */
  383. char * const getStreamBuffer() { return rtapi_->getStreamBuffer(); };
  384. //! Public method used to trigger processing of input/output data for a stream.
  385. /*!
  386. This method blocks until all buffer data is read/written. An
  387. RtError will be thrown if a driver error occurs or if called when
  388. no stream is open.
  389. */
  390. void tickStream() { rtapi_->tickStream(); };
  391. //! Public method which closes a stream and frees any associated buffers.
  392. /*!
  393. If a stream is not open, this method issues a warning and
  394. returns (an RtError is not thrown).
  395. */
  396. void closeStream() { rtapi_->closeStream(); };
  397. //! Public method which starts a stream.
  398. /*!
  399. An RtError will be thrown if a driver error occurs or if called
  400. when no stream is open.
  401. */
  402. void startStream() { rtapi_->startStream(); };
  403. //! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
  404. /*!
  405. An RtError will be thrown if a driver error occurs or if called
  406. when no stream is open.
  407. */
  408. void stopStream() { rtapi_->stopStream(); };
  409. //! Stop a stream, discarding any samples remaining in the input/output queue.
  410. /*!
  411. An RtError will be thrown if a driver error occurs or if called
  412. when no stream is open.
  413. */
  414. void abortStream() { rtapi_->abortStream(); };
  415. protected:
  416. void initialize( RtAudioApi api );
  417. RtApi *rtapi_;
  418. };
  419. // RtApi Subclass prototypes.
  420. #if defined(__LINUX_ALSA__)
  421. class RtApiAlsa: public RtApi
  422. {
  423. public:
  424. RtApiAlsa();
  425. ~RtApiAlsa();
  426. void tickStream();
  427. void closeStream();
  428. void startStream();
  429. void stopStream();
  430. void abortStream();
  431. int streamWillBlock();
  432. void setStreamCallback( RtAudioCallback callback, void *userData );
  433. void cancelStreamCallback();
  434. private:
  435. void initialize(void);
  436. void probeDeviceInfo( RtApiDevice *info );
  437. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  438. int sampleRate, RtAudioFormat format,
  439. int *bufferSize, int numberOfBuffers );
  440. };
  441. #endif
  442. #if defined(__LINUX_JACK__)
  443. class RtApiJack: public RtApi
  444. {
  445. public:
  446. RtApiJack();
  447. ~RtApiJack();
  448. void tickStream();
  449. void closeStream();
  450. void startStream();
  451. void stopStream();
  452. void abortStream();
  453. void setStreamCallback( RtAudioCallback callback, void *userData );
  454. void cancelStreamCallback();
  455. // This function is intended for internal use only. It must be
  456. // public because it is called by the internal callback handler,
  457. // which is not a member of RtAudio. External use of this function
  458. // will most likely produce highly undesireable results!
  459. void callbackEvent( unsigned long nframes );
  460. private:
  461. void initialize(void);
  462. void probeDeviceInfo( RtApiDevice *info );
  463. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  464. int sampleRate, RtAudioFormat format,
  465. int *bufferSize, int numberOfBuffers );
  466. };
  467. #endif
  468. #if defined(__LINUX_OSS__)
  469. class RtApiOss: public RtApi
  470. {
  471. public:
  472. RtApiOss();
  473. ~RtApiOss();
  474. void tickStream();
  475. void closeStream();
  476. void startStream();
  477. void stopStream();
  478. void abortStream();
  479. int streamWillBlock();
  480. void setStreamCallback( RtAudioCallback callback, void *userData );
  481. void cancelStreamCallback();
  482. private:
  483. void initialize(void);
  484. void probeDeviceInfo( RtApiDevice *info );
  485. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  486. int sampleRate, RtAudioFormat format,
  487. int *bufferSize, int numberOfBuffers );
  488. };
  489. #endif
  490. #if defined(__MACOSX_CORE__)
  491. #include <CoreAudio/AudioHardware.h>
  492. class RtApiCore: public RtApi
  493. {
  494. public:
  495. RtApiCore();
  496. ~RtApiCore();
  497. int getDefaultOutputDevice(void);
  498. int getDefaultInputDevice(void);
  499. void tickStream();
  500. void closeStream();
  501. void startStream();
  502. void stopStream();
  503. void abortStream();
  504. void setStreamCallback( RtAudioCallback callback, void *userData );
  505. void cancelStreamCallback();
  506. // This function is intended for internal use only. It must be
  507. // public because it is called by the internal callback handler,
  508. // which is not a member of RtAudio. External use of this function
  509. // will most likely produce highly undesireable results!
  510. void callbackEvent( AudioDeviceID deviceId, void *inData, void *outData );
  511. private:
  512. void initialize(void);
  513. void probeDeviceInfo( RtApiDevice *info );
  514. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  515. int sampleRate, RtAudioFormat format,
  516. int *bufferSize, int numberOfBuffers );
  517. };
  518. #endif
  519. #if defined(__WINDOWS_DS__)
  520. class RtApiDs: public RtApi
  521. {
  522. public:
  523. RtApiDs();
  524. ~RtApiDs();
  525. int getDefaultOutputDevice(void);
  526. int getDefaultInputDevice(void);
  527. void tickStream();
  528. void closeStream();
  529. void startStream();
  530. void stopStream();
  531. void abortStream();
  532. int streamWillBlock();
  533. void setStreamCallback( RtAudioCallback callback, void *userData );
  534. void cancelStreamCallback();
  535. private:
  536. void initialize(void);
  537. void probeDeviceInfo( RtApiDevice *info );
  538. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  539. int sampleRate, RtAudioFormat format,
  540. int *bufferSize, int numberOfBuffers );
  541. };
  542. #endif
  543. #if defined(__WINDOWS_ASIO__)
  544. class RtApiAsio: public RtApi
  545. {
  546. public:
  547. RtApiAsio();
  548. ~RtApiAsio();
  549. void tickStream();
  550. void closeStream();
  551. void startStream();
  552. void stopStream();
  553. void abortStream();
  554. void setStreamCallback( RtAudioCallback callback, void *userData );
  555. void cancelStreamCallback();
  556. // This function is intended for internal use only. It must be
  557. // public because it is called by the internal callback handler,
  558. // which is not a member of RtAudio. External use of this function
  559. // will most likely produce highly undesireable results!
  560. void callbackEvent( long bufferIndex );
  561. private:
  562. void initialize(void);
  563. void probeDeviceInfo( RtApiDevice *info );
  564. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  565. int sampleRate, RtAudioFormat format,
  566. int *bufferSize, int numberOfBuffers );
  567. };
  568. #endif
  569. #if defined(__IRIX_AL__)
  570. class RtApiAl: public RtApi
  571. {
  572. public:
  573. RtApiAl();
  574. ~RtApiAl();
  575. int getDefaultOutputDevice(void);
  576. int getDefaultInputDevice(void);
  577. void tickStream();
  578. void closeStream();
  579. void startStream();
  580. void stopStream();
  581. void abortStream();
  582. int streamWillBlock();
  583. void setStreamCallback( RtAudioCallback callback, void *userData );
  584. void cancelStreamCallback();
  585. private:
  586. void initialize(void);
  587. void probeDeviceInfo( RtApiDevice *info );
  588. bool probeDeviceOpen( int device, StreamMode mode, int channels,
  589. int sampleRate, RtAudioFormat format,
  590. int *bufferSize, int numberOfBuffers );
  591. };
  592. #endif
  593. // Define the following flag to have extra information spewed to stderr.
  594. //#define __RTAUDIO_DEBUG__
  595. #endif