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.

629 lines
31KB

  1. /*! \mainpage The RtAudio Tutorial
  2. <BODY BGCOLOR="white">
  3. <CENTER>
  4. \ref intro &nbsp;&nbsp; \ref download &nbsp;&nbsp; \ref start &nbsp;&nbsp; \ref error &nbsp;&nbsp; \ref probing &nbsp;&nbsp; \ref settings &nbsp;&nbsp; \ref playbackb &nbsp;&nbsp; \ref playbackc &nbsp;&nbsp; \ref recording &nbsp;&nbsp; \ref duplex &nbsp;&nbsp; \ref methods &nbsp;&nbsp; \ref compiling &nbsp;&nbsp; \ref osnotes &nbsp;&nbsp; \ref acknowledge
  5. </CENTER>
  6. \section intro Introduction
  7. RtAudio is a C++ class which provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA and OSS), SGI, and Windows operating systems. RtAudio significantly simplifies the process of interacting with computer audio hardware. It was designed with the following goals:
  8. <UL>
  9. <LI>object oriented C++ design</LI>
  10. <LI>simple, common API across all supported platforms</LI>
  11. <LI>single independent header and source file for easy inclusion in programming projects (no libraries!)</LI>
  12. <LI>blocking functionality</LI>
  13. <LI>callback functionality</LI>
  14. <LI>extensive audio device parameter control</LI>
  15. <LI>audio device capability probing</LI>
  16. <LI>automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping</LI>
  17. <LI>control over multiple audio streams and devices with a single instance</LI>
  18. </UL>
  19. RtAudio incorporates the concept of audio streams, which represent audio output (playback) and/or input (recording). Available audio devices and their capabilities can be enumerated and then specified when opening a stream. Multiple streams can run at the same time and, when allowed by the underlying audio API, a single device can serve multiple streams.
  20. The RtAudio API provides both blocking (synchronous) and callback (asynchronous) functionality. Callbacks are typically used in conjunction with graphical user interfaces (GUI). Blocking functionality is often necessary for explicit control of multiple input/output stream synchronization or when audio must be synchronized with other system events.
  21. \section download Download
  22. Latest Release (22 January 2002): <A href="release/rtaudio-2.0.tgz">Version 2.0 (111 kB tar/gzipped)</A>
  23. \section start Getting Started
  24. The first thing that must be done when using RtAudio is to create an instance of the class. The default constructor RtAudio::RtAudio() scans the underlying audio system to verify that at least one device is available. RtAudio often uses C++ exceptions to report errors, necessitating try/catch blocks around most member functions. The following code example demonstrates default object construction and destruction:
  25. \code
  26. #include "RtAudio.h"
  27. int main()
  28. {
  29. RtAudio *audio;
  30. // Default RtAudio constructor
  31. try {
  32. audio = new RtAudio();
  33. }
  34. catch (RtAudioError &error) {
  35. // Handle the exception here
  36. }
  37. // Clean up
  38. delete audio;
  39. }
  40. \endcode
  41. Obviously, this example doesn't demonstrate any of the real functionality of RtAudio. However, all uses of RtAudio must begin with a constructor (either default or overloaded varieties) and must end with class destruction. Further, it is necessary that all class methods which can throw a C++ exception be called within a try/catch block.
  42. \section error Error Handling
  43. RtAudio uses a C++ exception handler called RtAudioError, which is declared and defined within the RtAudio class files. The RtAudioError class is quite simple but it does allow errors to be "caught" by RtAudioError::TYPE. Almost all RtAudio methods can "throw" an RtAudioError, most typically if an invalid stream identifier is supplied to a method or a driver error occurs. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a private RtAudio method, error(), which can be modified to globally control how these messages are handled and reported.
  44. \section probing Probing Device Capabilities
  45. A programmer may wish to query the available audio device capabilities before deciding which to use. The following example outlines how this can be done.
  46. \code
  47. // probe.cpp
  48. #include <iostream.h>
  49. #include "RtAudio.h"
  50. int main()
  51. {
  52. RtAudio *audio;
  53. // Default RtAudio constructor
  54. try {
  55. audio = new RtAudio();
  56. }
  57. catch (RtAudioError &error) {
  58. error.printMessage();
  59. exit(EXIT_FAILURE);
  60. }
  61. // Determine the number of devices available
  62. int devices = audio->getDeviceCount();
  63. // Scan through devices for various capabilities
  64. RtAudio::RTAUDIO_DEVICE info;
  65. for (int i=0; i<devices; i++) {
  66. try {
  67. audio->getDeviceInfo(i, &info);
  68. }
  69. catch (RtAudioError &error) {
  70. error.printMessage();
  71. break;
  72. }
  73. // Print, for example, the maximum number of output channels for each device
  74. cout << "device = " << i;
  75. cout << ": maximum output channels = " << info.maxOutputChannels << endl;
  76. }
  77. // Clean up
  78. delete audio;
  79. return 0;
  80. }
  81. \endcode
  82. The RTAUDIO_DEVICE structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device:
  83. \code
  84. typedef struct {
  85. char name[128];
  86. DEVICE_ID id[2]; // No value reported by getDeviceInfo().
  87. bool probed; // true if the device probe was successful.
  88. int maxOutputChannels;
  89. int maxInputChannels;
  90. int maxDuplexChannels;
  91. int minOutputChannels;
  92. int minInputChannels;
  93. int minDuplexChannels;
  94. bool hasDuplexSupport; // true if duplex supported
  95. int nSampleRates; // Number of discrete rates, or -1 if range supported.
  96. double sampleRates[MAX_SAMPLE_RATES]; // Supported sample rates, or {min, max} if range.
  97. RTAUDIO_FORMAT nativeFormats;
  98. } RTAUDIO_DEVICE;
  99. \endcode
  100. The following data formats are defined and fully supported by RtAudio:
  101. \code
  102. typedef unsigned long RTAUDIO_FORMAT;
  103. static const RTAUDIO_FORMAT RTAUDIO_SINT8; // Signed 8-bit integer
  104. static const RTAUDIO_FORMAT RTAUDIO_SINT16; // Signed 16-bit integer
  105. static const RTAUDIO_FORMAT RTAUDIO_SINT24; // Signed 24-bit integer
  106. static const RTAUDIO_FORMAT RTAUDIO_SINT32; // Signed 32-bit integer
  107. static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; // 32-bit float
  108. static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; // 64-bit double
  109. \endcode
  110. The <I>nativeFormats</I> member of the RtAudio::RTAUDIO_DEVICE structure is a bit mask of the above formats which are natively supported by the device. However, RtAudio will automatically provide format conversion if a particular format is not natively supported. When the <I>probed</I> member of the RTAUDIO_DEVICE structure is false, the remaining structure members are likely unknown and the device is probably unusable.
  111. In general, the user need not be concerned with the minimum channel values reported in the RTAUDIO_DEVICE structure. While some audio devices may require a minimum channel value > 1, RtAudio will provide automatic channel number compensation when the number of channels set by the user is less than that required by the device. Channel compensation is <I>NOT</I> possible when the number of channels set by the user is greater than that supported by the device.
  112. It should be noted that the capabilities reported by a device driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings.
  113. \section settings Device Settings
  114. The next step in using RtAudio is to open a stream with a particular set of device settings.
  115. \code
  116. #include "RtAudio.h"
  117. int main()
  118. {
  119. int channels = 2;
  120. int sample_rate = 44100;
  121. int buffer_size = 256; // 256 sample frames
  122. int n_buffers = 4; // number of internal buffers used by device
  123. int device = 0; // 0 indicates the default or first available device
  124. int stream; // our stream identifier
  125. RtAudio *audio;
  126. // Instantiate RtAudio and open a stream within a try/catch block
  127. try {
  128. audio = new RtAudio();
  129. stream = audio->openStream(device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
  130. sample_rate, &buffer_size, n_buffers);
  131. }
  132. catch (RtAudioError &error) {
  133. error.printMessage();
  134. exit(EXIT_FAILURE);
  135. }
  136. // Clean up
  137. delete audio;
  138. return 0;
  139. }
  140. \endcode
  141. The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. When successful, a stream identifier is returned. In this case, we attempt to open a playback stream on device 0 with two channels, 32-bit floating point data, a sample rate of 44100 Hz, a frame rate of 256 sample frames per read/write, and 4 internal device buffers. When device = 0, RtAudio first attempts to open the default audio device with the given parameters. If that attempt fails, an attempt is made to find a device or set of devices which will meet the given parameters. If all attempts are unsuccessful, an RtAudioError is thrown. When a non-zero device value is specified, an attempt is made to open that device only.
  142. RtAudio provides four signed integer and two floating point data formats which can be specified using the RtAudio::RTAUDIO_FORMAT parameter values mentioned earlier. If the opened device does not natively support the given format, RtAudio will automatically perform the necessary data format conversion.
  143. Buffer sizes in RtAudio are <I>ALWAYS</I> given in sample frame units. For example, if you open an output stream with 4 channels and set <I>bufferSize</I> to 512, you will have to write 2048 samples of data to the output buffer within your callback or between calls to RtAudio::tickStream(). In this case, a single sample frame of data contains 4 samples of data.
  144. The <I>bufferSize</I> parameter specifies the desired number of sample frames which will be written to and/or read from a device per write/read operation. The <I>nBuffers</I> parameter is used in setting the underlying device buffer parameters. Both the <I>bufferSize</I> and <I>nBuffers</I> parameters can be used to control stream latency though there is no guarantee that the passed values will be those used by a device. In general, lower values for both parameters will produce less latency but perhaps less robust performance. Both parameters can be specified with values of zero, in which case the smallest allowable values will be used. The <I>bufferSize</I> parameter is passed as a pointer and the actual value used by the stream is set during the device setup procedure. <I>bufferSize</I> values should be a power of two. Optimal and allowable buffer values tend to vary between systems and devices. Check the \ref osnotes section for general guidelines.
  145. As noted earlier, the device capabilities reported by a driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. Because of this, RtAudio does not attempt to query a device's capabilities or use previously reported values when opening a device. Instead, RtAudio simply attempts to set the given parameters on a specified device and then checks whether the setup is successful or not.
  146. \section playbackb Playback (blocking functionality)
  147. Once the device is open for playback, there are only a few final steps necessary for realtime audio output. We'll first provide an example (blocking functionality) and then discuss the details.
  148. \code
  149. // playback.cpp
  150. #include "RtAudio.h"
  151. int main()
  152. {
  153. int count;
  154. int channels = 2;
  155. int sample_rate = 44100;
  156. int buffer_size = 256; // 256 sample frames
  157. int n_buffers = 4; // number of internal buffers used by device
  158. float *buffer;
  159. int device = 0; // 0 indicates the default or first available device
  160. int stream; // our stream identifier
  161. RtAudio *audio;
  162. // Open a stream during RtAudio instantiation
  163. try {
  164. audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
  165. sample_rate, &buffer_size, n_buffers);
  166. }
  167. catch (RtAudioError &error) {
  168. error.printMessage();
  169. exit(EXIT_FAILURE);
  170. }
  171. try {
  172. // Get a pointer to the stream buffer
  173. buffer = (float *) audio->getStreamBuffer(stream);
  174. // Start the stream
  175. audio->startStream(stream);
  176. }
  177. catch (RtAudioError &error) {
  178. error.printMessage();
  179. goto cleanup;
  180. }
  181. // An example loop which runs for about 40000 sample frames
  182. count = 0;
  183. while (count < 40000) {
  184. // Generate your samples and fill the buffer with buffer_size sample frames of data
  185. ...
  186. // Trigger the output of the data buffer
  187. try {
  188. audio->tickStream(stream);
  189. }
  190. catch (RtAudioError &error) {
  191. error.printMessage();
  192. goto cleanup;
  193. }
  194. count += buffer_size;
  195. }
  196. try {
  197. // Stop and close the stream
  198. audio->stopStream(stream);
  199. audio->closeStream(stream);
  200. }
  201. catch (RtAudioError &error) {
  202. error.printMessage();
  203. }
  204. cleanup:
  205. delete audio;
  206. return 0;
  207. }
  208. \endcode
  209. The first thing to notice in this example is that we attempt to open a stream during class instantiation with an overloaded constructor. This constructor simply combines the functionality of the default constructor, used earlier, and the RtAudio::openStream() method. Again, we have specified a device value of 0, indicating that the default or first available device meeting the given parameters should be used. The integer identifier of the opened stream is returned via the <I>stream</I> pointer value. An attempt is made to open the stream with the specified <I>bufferSize</I> value. However, it is possible that the device will not accept this value, in which case the closest allowable size is used and returned via the pointer value. The constructor can fail if no available devices are found, or a memory allocation or device driver error occurs. Note that you should not call the RtAudio destructor if an exception is thrown during instantiation.
  210. Because RtAudio can be used to simultaneously control more than a single stream, it is necessary that the stream identifier be provided to nearly all public methods. Assuming the constructor is successful, it is necessary to get a pointer to the buffer, provided by RtAudio, for use in feeding data to/from the opened stream. Note that the user should <I>NOT</I> attempt to deallocate the stream buffer memory ... memory management for the stream buffer will be automatically controlled by RtAudio. After starting the stream with RtAudio::startStream(), one simply fills that buffer, which is of length equal to the returned <I>bufferSize</I> value, with interleaved audio data (in the specified format) for playback. Finally, a call to the RtAudio::tickStream() routine triggers a blocking write call for the stream.
  211. In general, one should call the RtAudio::stopStream() and RtAudio::closeStream() methods after finishing with a stream. However, both methods will implicitly be called during object destruction if necessary.
  212. \section playbackc Playback (callback functionality)
  213. The primary difference in using RtAudio with callback functionality involves the creation of a user-defined callback function. Here is an example which produces a sawtooth waveform for playback.
  214. \code
  215. #include <iostream.h>
  216. #include "RtAudio.h"
  217. // Two-channel sawtooth wave generator.
  218. int sawtooth(char *buffer, int buffer_size, void *data)
  219. {
  220. int i, j;
  221. double *my_buffer = (double *) buffer;
  222. double *my_data = (double *) data;
  223. // Write interleaved audio data.
  224. for (i=0; i<buffer_size; i++) {
  225. for (j=0; j<2; j++) {
  226. *my_buffer++ = my_data[j];
  227. my_data[j] += 0.005 * (j+1+(j*0.1));
  228. if (my_data[j] >= 1.0) my_data[j] -= 2.0;
  229. }
  230. }
  231. return 0;
  232. }
  233. int main()
  234. {
  235. int channels = 2;
  236. int sample_rate = 44100;
  237. int buffer_size = 256; // 256 sample frames
  238. int n_buffers = 4; // number of internal buffers used by device
  239. int device = 0; // 0 indicates the default or first available device
  240. int stream; // our stream identifier
  241. double data[2];
  242. char input;
  243. RtAudio *audio;
  244. // Open a stream during RtAudio instantiation
  245. try {
  246. audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT64,
  247. sample_rate, &buffer_size, n_buffers);
  248. }
  249. catch (RtAudioError &error) {
  250. error.printMessage();
  251. exit(EXIT_FAILURE);
  252. }
  253. try {
  254. // Set the stream callback function
  255. audio->setStreamCallback(stream, &sawtooth, (void *)data);
  256. // Start the stream
  257. audio->startStream(stream);
  258. }
  259. catch (RtAudioError &error) {
  260. error.printMessage();
  261. goto cleanup;
  262. }
  263. cout << "\nPlaying ... press <enter> to quit.\n";
  264. cin.get(input);
  265. try {
  266. // Stop and close the stream
  267. audio->stopStream(stream);
  268. audio->closeStream(stream);
  269. }
  270. catch (RtAudioError &error) {
  271. error.printMessage();
  272. }
  273. cleanup:
  274. delete audio;
  275. return 0;
  276. }
  277. \endcode
  278. After opening the device in exactly the same way as the previous example (except with a data format change), we must set our callback function for the stream using RtAudio::setStreamCallback(). This method will spawn a new process (or thread) which automatically calls the callback function when more data is needed. Note that the callback function is called only when the stream is "running" (between calls to the RtAudio::startStream() and RtAudio::stopStream() methods). The last argument to RtAudio::setStreamCallback() is a pointer to arbitrary data that you wish to access from within your callback function.
  279. In this example, we stop the stream with an explicit call to RtAudio::stopStream(). When using callback functionality, it is also possible to stop a stream by returning a non-zero value from the callback function.
  280. Once set with RtAudio::setStreamCallback, the callback process will continue to run for the life of the stream (until the stream is closed with RtAudio::closeStream() or the RtAudio instance is deleted). It is possible to disassociate a callback function and cancel its process for an open stream using the RtAudio::cancelStreamCallback() method. The stream can then be used with blocking functionality or a new callback can be associated with it.
  281. \section recording Recording
  282. Using RtAudio for audio input is almost identical to the way it is used for playback. Here's the blocking playback example rewritten for recording:
  283. \code
  284. // record.cpp
  285. #include "RtAudio.h"
  286. int main()
  287. {
  288. int count;
  289. int channels = 2;
  290. int sample_rate = 44100;
  291. int buffer_size = 256; // 256 sample frames
  292. int n_buffers = 4; // number of internal buffers used by device
  293. float *buffer;
  294. int device = 0; // 0 indicates the default or first available device
  295. int stream; // our stream identifier
  296. RtAudio *audio;
  297. // Instantiate RtAudio and open a stream.
  298. try {
  299. audio = new RtAudio(&stream, 0, 0, device, channels,
  300. RtAudio::RTAUDIO_FLOAT32, sample_rate, &buffer_size, n_buffers);
  301. }
  302. catch (RtAudioError &error) {
  303. error.printMessage();
  304. exit(EXIT_FAILURE);
  305. }
  306. try {
  307. // Get a pointer to the stream buffer
  308. buffer = (float *) audio->getStreamBuffer(stream);
  309. // Start the stream
  310. audio->startStream(stream);
  311. }
  312. catch (RtAudioError &error) {
  313. error.printMessage();
  314. goto cleanup;
  315. }
  316. // An example loop which runs for about 40000 sample frames
  317. count = 0;
  318. while (count < 40000) {
  319. // Read a buffer of data
  320. try {
  321. audio->tickStream(stream);
  322. }
  323. catch (RtAudioError &error) {
  324. error.printMessage();
  325. goto cleanup;
  326. }
  327. // Process the input samples (buffer_size sample frames) that were read
  328. ...
  329. count += buffer_size;
  330. }
  331. try {
  332. // Stop the stream
  333. audio->stopStream(stream);
  334. }
  335. catch (RtAudioError &error) {
  336. error.printMessage();
  337. }
  338. cleanup:
  339. delete audio;
  340. return 0;
  341. }
  342. \endcode
  343. In this example, the stream was opened for recording with a non-zero <I>inputChannels</I> value. The only other difference between this example and that for playback involves the order of data processing in the loop, where it is necessary to first read a buffer of input data before manipulating it.
  344. \section duplex Duplex Mode
  345. Finally, it is easy to use RtAudio for simultaneous audio input/output, or duplex operation. In this example, we use a callback function and pass our recorded data directly through for playback.
  346. \code
  347. // duplex.cpp
  348. #include <iostream.h>
  349. #include "RtAudio.h"
  350. // Pass-through function.
  351. int pass(char *buffer, int buffer_size, void *)
  352. {
  353. // Surprise!! We do nothing to pass the data through.
  354. return 0;
  355. }
  356. int main()
  357. {
  358. int channels = 2;
  359. int sample_rate = 44100;
  360. int buffer_size = 256; // 256 sample frames
  361. int n_buffers = 4; // number of internal buffers used by device
  362. int device = 0; // 0 indicates the default or first available device
  363. int stream; // our stream identifier
  364. double data[2];
  365. char input;
  366. RtAudio *audio;
  367. // Open a stream during RtAudio instantiation
  368. try {
  369. audio = new RtAudio(&stream, device, channels, device, channels, RtAudio::RTAUDIO_FLOAT64,
  370. sample_rate, &buffer_size, n_buffers);
  371. }
  372. catch (RtAudioError &error) {
  373. error.printMessage();
  374. exit(EXIT_FAILURE);
  375. }
  376. try {
  377. // Set the stream callback function
  378. audio->setStreamCallback(stream, &pass, NULL);
  379. // Start the stream
  380. audio->startStream(stream);
  381. }
  382. catch (RtAudioError &error) {
  383. error.printMessage();
  384. goto cleanup;
  385. }
  386. cout << "\nRunning duplex ... press <enter> to quit.\n";
  387. cin.get(input);
  388. try {
  389. // Stop and close the stream
  390. audio->stopStream(stream);
  391. audio->closeStream(stream);
  392. }
  393. catch (RtAudioError &error) {
  394. error.printMessage();
  395. }
  396. cleanup:
  397. delete audio;
  398. return 0;
  399. }
  400. \endcode
  401. When an RtAudio stream is running in duplex mode (nonzero input <I>AND</I> output channels), the audio write (playback) operation always occurs before the audio read (record) operation. This sequence allows the use of a single buffer to store both output and input data.
  402. As we see with this example, the write-read sequence of operations does not preclude the use of RtAudio in situations where input data is first processed and then output through a duplex stream. When the stream buffer is first allocated, it is initialized with zeros, which produces no audible result when output to the device. In this example, anything recorded by the audio stream input will be played out during the next round of audio processing.
  403. Note that duplex operation can also be achieved by opening one output stream and one input stream using the same or different devices. However, there may be timing problems when attempting to use two different devices, due to possible device clock variations. This becomes even more difficult to achieve using two separate callback streams because it is not possible to explicitly control the calling order of the callback functions.
  404. \section methods Summary of Methods
  405. The following is short summary of public methods (not including constructors and the destructor) provided by RtAudio:
  406. <UL>
  407. <LI>RtAudio::openStream(): opens a stream with the specified parameters.</LI>
  408. <LI>RtAudio::setStreamCallback(): sets a user-defined callback function for a given stream.</LI>
  409. <LI>RtAudio::cancelStreamCallback(): cancels a callback process and function for a given stream.</LI>
  410. <LI>RtAudio::getDeviceCount(): returns the number of audio devices available.</LI>
  411. <LI>RtAudio::getDeviceInfo(): fills a user-supplied RTAUDIO_DEVICE structure for a specified device.</LI>
  412. <LI>RtAudio::getStreamBuffer(): returns a pointer to the stream buffer.</LI>
  413. <LI>RtAudio::tickStream(): triggers processing of input/output data for a stream (blocking).</LI>
  414. <LI>RtAudio::closeStream(): closes the specified stream (implicitly called during object destruction). Once a stream is closed, the stream identifier is invalid and should not be used in calling any other RtAudio methods.</LI>
  415. <LI>RtAudio::startStream(): (re)starts the specified stream, typically after it has been stopped with either stopStream() or abortStream() or after first opening the stream.</LI>
  416. <LI>RtAudio::stopStream(): stops the specified stream, allowing any remaining samples in the queue to be played out and/or read in. This does not implicitly call RtAudio::closeStream().</LI>
  417. <LI>RtAudio::abortStream(): stops the specified stream, discarding any remaining samples in the queue. This does not implicitly call closeStream().</LI>
  418. <LI>RtAudio::streamWillBlock(): queries a stream to determine whether a call to the <I>tickStream()</I> method will block. A return value of 0 indicates that the stream will NOT block. A positive return value indicates the number of sample frames that cannot yet be processed without blocking.</LI>
  419. </UL>
  420. \section compiling Compiling
  421. In order to compile RtAudio for a specific OS and audio API, it is necessary to supply the appropriate preprocessor definition and library within the compiler statement:
  422. <P>
  423. <TABLE BORDER=2 COLS=5 WIDTH="100%">
  424. <TR BGCOLOR="beige">
  425. <TD WIDTH="5%"><B>OS:</B></TD>
  426. <TD WIDTH="5%"><B>Audio API:</B></TD>
  427. <TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>
  428. <TD WIDTH="5%"><B>Library:</B></TD>
  429. <TD><B>Example Compiler Statement:</B></TD>
  430. </TR>
  431. <TR>
  432. <TD>Linux</TD>
  433. <TD>ALSA</TD>
  434. <TD>__LINUX_ALSA_</TD>
  435. <TD><TT>libasound, libpthread</TT></TD>
  436. <TD><TT>g++ -Wall -D__LINUX_ALSA_ -o probe probe.cpp RtAudio.cpp -lasound -lpthread</TT></TD>
  437. </TR>
  438. <TR>
  439. <TD>Linux</TD>
  440. <TD>OSS</TD>
  441. <TD>__LINUX_OSS_</TD>
  442. <TD><TT>libpthread</TT></TD>
  443. <TD><TT>g++ -Wall -D__LINUX_OSS_ -o probe probe.cpp RtAudio.cpp -lpthread</TT></TD>
  444. </TR>
  445. <TR>
  446. <TD>Irix</TD>
  447. <TD>AL</TD>
  448. <TD>__IRIX_AL_</TD>
  449. <TD><TT>libaudio, libpthread</TT></TD>
  450. <TD><TT>CC -Wall -D__IRIX_AL_ -o probe probe.cpp RtAudio.cpp -laudio -lpthread</TT></TD>
  451. </TR>
  452. <TR>
  453. <TD>Windows</TD>
  454. <TD>Direct Sound</TD>
  455. <TD>__WINDOWS_DS_</TD>
  456. <TD><TT>dsound.lib (ver. 5.0 or higher), multithreaded</TT></TD>
  457. <TD><I>compiler specific</I></TD>
  458. </TR>
  459. </TABLE>
  460. <P>
  461. The example compiler statements above could be used to compile the <TT>probe.cpp</TT> example file, assuming that <TT>probe.cpp</TT>, <TT>RtAudio.h</TT>, and <TT>RtAudio.cpp</TT> all exist in the same directory.
  462. \section osnotes OS Notes
  463. RtAudio is designed to provide a common API across the various supported operating systems and audio libraries. Despite that, however, some issues need to be mentioned with regard to each.
  464. \subsection linux Linux:
  465. RtAudio for Linux was developed under Redhat distributions 7.0 - 7.2. Two different audio APIs are supported on Linux platforms: OSS and <A href="http://www.alsa-project.org/">ALSA</A>. The OSS API has existed for at least 6 years and the Linux kernel is distributed with free versions of OSS audio drivers. Therefore, a generic Linux system is most likely to have OSS support. The ALSA API is relatively new and at this time is not part of the Linux kernel distribution. Work is in progress to make ALSA part of the 2.5 development kernel series. Despite that, the ALSA API offers significantly better functionality than the OSS API. RtAudio provides support for the 0.9 and higher versions of ALSA. Input/output latency on the order of 15-20 milliseconds can typically be achieved under both OSS or ALSA by fine-tuning the RtAudio buffer parameters (without kernel modifications). Latencies on the order of 5 milliseconds or less can be achieved using a low-latency kernel patch and increasing FIFO scheduling priority. The pthread library, which is used for callback functionality, is a standard component of all Linux distributions.
  466. The ALSA library includes OSS emulation support. That means that you can run programs compiled for the OSS API even when using the ALSA drivers and library. It should be noted however that OSS emulation under ALSA is not perfect. Specifically, channel number queries seem to consistently produce invalid results. While OSS emulation is successful for the majority of RtAudio tests, it is recommended that the native ALSA implementation of RtAudio be used on systems which have ALSA drivers installed.
  467. The ALSA implementation of RtAudio makes no use of the ALSA "plug" interface. All necessary data format conversions, channel compensation, deinterleaving, and byte-swapping is handled by internal RtAudio routines.
  468. \subsection irix Irix (SGI):
  469. The Irix version of RtAudio was written and tested on an SGI Indy running Irix version 6.5 and the newer "al" audio library. RtAudio does not compile under Irix version 6.3 because the C++ compiler is too old. Despite the relatively slow speed of the Indy, RtAudio was found to behave quite well and input/output latency was very good. No problems were found with respect to using the pthread library.
  470. \subsection windows Windows:
  471. RtAudio under Windows is written using the DirectSound API. In order to compile RtAudio under Windows, you must have the header and source files for DirectSound version 0.5 or higher. As far as I know, you cannot compile RtAudio for Windows NT because there is not sufficient DirectSound support. Audio output latency with DirectSound can be reasonably good (on the order of 20 milliseconds). On the other hand, input audio latency tends to be terrible (100 milliseconds or more). Further, DirectSound drivers tend to crash easily when experimenting with buffer parameters. On my system, I found it necessary to use values around nBuffers = 8 and bufferSize = 512 to avoid crashing my system. RtAudio was developed with Visual C++ version 6.0. I was forced in several instances to modify code in order to get it to compile under the non-standard version of C++ that Microsoft so unprofessionally implemented. We can only hope that the developers of Visual C++ 7.0 will have time to read the C++ standard.
  472. \section acknowledge Acknowledgments
  473. The RtAudio API incorporates many of the concepts developed in the <A href="http://www.portaudio.com/">PortAudio</A> project by Phil Burk and Ross Bencina. Early development also incorporated ideas from Bill Schottstaedt's <A href="http://www-ccrma.stanford.edu/software/snd/sndlib/">sndlib</A>. The CCRMA <A href="http://www-ccrma.stanford.edu/groups/soundwire/">SoundWire group</A> provided valuable feedback during the API proposal stages.
  474. RtAudio was slowly developed over the course of many months while in residence at the <A href="http://www.iua.upf.es/">Institut Universitari de L'Audiovisual (IUA)</A> in Barcelona, Spain, the <A href="http://www.acoustics.hut.fi/">Laboratory of Acoustics and Audio Signal Processing</A> at the Helsinki University of Technology, Finland, and the <A href="http://www-ccrma.stanford.edu/">Center for Computer Research in Music and Acoustics (CCRMA)</A> at <A href="http://www.stanford.edu/">Stanford University</A>. This work was supported in part by the United States Air Force Office of Scientific Research (grant \#F49620-99-1-0293).
  475. These documentation files were generated using <A href="http://www.doxygen.org/">doxygen</A> by Dimitri van Heesch.
  476. */