Version 2.1
authorGary Scavone <gary@music.mcgill.ca>
Wed, 9 Oct 2013 21:44:33 +0000 (23:44 +0200)
committerStephen Sinclair <sinclair@music.mcgill.ca>
Wed, 9 Oct 2013 23:08:39 +0000 (01:08 +0200)
71 files changed:
INSTALL [new file with mode: 0644]
README
RtAudio.cpp
RtAudio.h
config.guess [new file with mode: 0755]
config.sub [new file with mode: 0644]
configure.ac [new file with mode: 0644]
doc/Release.txt [deleted file]
doc/doxygen/Doxyfile
doc/doxygen/footer.html
doc/doxygen/header.html
doc/doxygen/tutorial.txt
doc/images/ccrma.gif [changed mode: 0644->0755]
doc/manual.pdf [deleted file]
doc/release.txt [new file with mode: 0644]
install.sh [new file with mode: 0644]
rtaudio.dsw [deleted file]
tests/DirectSound/Debug/.placeholder [new file with mode: 0644]
tests/DirectSound/Release/.placeholder [new file with mode: 0644]
tests/DirectSound/call_inout.dsp [new file with mode: 0755]
tests/DirectSound/call_playtwo.dsp [new file with mode: 0755]
tests/DirectSound/call_saw.dsp [new file with mode: 0755]
tests/DirectSound/call_twostreams.dsp [new file with mode: 0755]
tests/DirectSound/in_out.dsp [new file with mode: 0755]
tests/DirectSound/info.dsp [new file with mode: 0755]
tests/DirectSound/play_raw.dsp [new file with mode: 0755]
tests/DirectSound/play_saw.dsp [new file with mode: 0755]
tests/DirectSound/record_raw.dsp [new file with mode: 0755]
tests/DirectSound/rtaudio.dsw [new file with mode: 0755]
tests/DirectSound/twostreams.dsp [new file with mode: 0755]
tests/Makefile [deleted file]
tests/Makefile.in [new file with mode: 0644]
tests/asio/Debug/.placeholder [new file with mode: 0644]
tests/asio/Release/.placeholder [new file with mode: 0644]
tests/asio/asio.cpp [new file with mode: 0644]
tests/asio/asio.h [new file with mode: 0644]
tests/asio/asiodrivers.cpp [new file with mode: 0644]
tests/asio/asiodrivers.h [new file with mode: 0644]
tests/asio/asiodrvr.h [new file with mode: 0644]
tests/asio/asiolist.cpp [new file with mode: 0644]
tests/asio/asiolist.h [new file with mode: 0644]
tests/asio/asiosys.h [new file with mode: 0644]
tests/asio/call_inout.dsp [new file with mode: 0755]
tests/asio/call_saw.dsp [new file with mode: 0755]
tests/asio/ginclude.h [new file with mode: 0644]
tests/asio/iasiodrv.h [new file with mode: 0644]
tests/asio/in_out.dsp [new file with mode: 0755]
tests/asio/info.dsp [new file with mode: 0755]
tests/asio/play_raw.dsp [new file with mode: 0755]
tests/asio/play_saw.dsp [new file with mode: 0755]
tests/asio/record_raw.dsp [new file with mode: 0755]
tests/asio/rtaudio.dsw [new file with mode: 0755]
tests/call_inout.cpp
tests/call_inout.dsp [deleted file]
tests/call_playtwo.cpp [new file with mode: 0644]
tests/call_saw.cpp
tests/call_saw.dsp [deleted file]
tests/call_twostreams.cpp
tests/call_twostreams.dsp [deleted file]
tests/in_out.cpp
tests/in_out.dsp [deleted file]
tests/info.cpp
tests/info.dsp [deleted file]
tests/play_raw.cpp
tests/play_raw.dsp [deleted file]
tests/play_saw.cpp
tests/play_saw.dsp [deleted file]
tests/record_raw.cpp
tests/record_raw.dsp [deleted file]
tests/twostreams.cpp
tests/twostreams.dsp [deleted file]

diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..abef59e
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,28 @@
+RtAudio - a C++ class which provides a common API for realtime audio input/output across Linux (native ALSA and OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound and ASIO) operating systems.
+
+By Gary P. Scavone, 2002.
+
+To configure and compile (on Unix systems):
+
+1. Unpack the RtAudio distribution (tar -xzf rtaudio-2.x.tar.gz).
+2. From within the directory containing this file, run configure:
+
+   ./configure
+
+3. From within the "tests" directory, type "make".
+
+A few options can be passed to configure, including:
+
+  --enable-debug = enable various debug output
+  --with-alsa = choose native ALSA API support (linux only)
+
+Typing "./configure --help" will display all the available options.
+
+If you wish to use a different compiler than that selected by configure, specify that compiler in the command line (ex. to use CC):
+
+  ./configure CXX=CC
+
+
+For Windows Users:
+
+Visual C++ 6.0 project files are included for the test programs.  For projects using the DirectSound API, go to the /tests/DirectSound/ directory.  For projects using the ASIO API, go to the /tests/asio/ directory.
diff --git a/README b/README
index 1d0b4d391c46f80c75f913434345a8e29f692eb1..3dd5718f16daf157f7321cff6002456bcdff6e41 100644 (file)
--- a/README
+++ b/README
@@ -1,40 +1,63 @@
-RtAudio - a C++ class which provides a common API for realtime audio input/output across Linux (native ALSA and OSS), SGI, and Windows operating systems.\r
-\r
-By Gary P. Scavone, 2002.\r
-\r
-This distribution of the Synthesis ToolKit in C++ (STK) contains the following:\r
-\r
-doc:      RtAudio documentation\r
-tests:    example RtAudio programs\r
-\r
-\r
-OVERVIEW:\r
-\r
-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:\r
-\r
-  - object oriented C++ design\r
-  - simple, common API across all supported platforms\r
-  - single independent header and source file for easy inclusion in programming projects (no libraries!)\r
-  - blocking functionality\r
-  - callback functionality\r
-  - extensive audio device parameter control\r
-  - audio device capability probing\r
-  - automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping\r
-  - control over multiple audio streams and devices with a single instance\r
-\r
-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.\r
-\r
-The RtAudio API provides both blocking (synchronous) and callback (asyncronous) 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. \r
-\r
-\r
-LEGAL AND ETHICAL:\r
-\r
-This software was designed and created to be made publicly available for free, primarily for academic purposes, so if you use it, pass it on with this documentation, and for free.  \r
-\r
-If you make a million dollars with it, give me some.  If you make compositions with it, put me in the program notes.\r
-\r
-\r
-FURTHER READING:\r
-\r
-For complete documentation on RtAudio, see the doc directory of the distribution or surf to http://www-ccrma.stanford.edu/~gary/rtaudio/.\r
-\r
+RtAudio - a C++ class which provides a common API for realtime audio input/output across Linux (native ALSA and OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound and ASIO) operating systems.
+
+By Gary P. Scavone, 2002.
+
+This distribution of the Synthesis ToolKit in C++ (STK) contains the following:
+
+doc:      RtAudio documentation
+tests:    example RtAudio programs
+
+
+OVERVIEW:
+
+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, Macintosh OS X (CoreAudio), and Windows (DirectSound and ASIO) operating systems. RtAudio significantly simplifies the process of interacting with computer audio hardware. It was designed with the following goals:
+
+  - object oriented C++ design
+  - simple, common API across all supported platforms
+  - single independent header and source file for easy inclusion in programming projects
+  - blocking functionality
+  - callback functionality
+  - extensive audio device parameter control
+  - audio device capability probing
+  - automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping
+  - control over multiple audio streams and devices with a single instance
+
+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.
+
+The RtAudio API provides both blocking (synchronous) and callback (asyncronous) 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. 
+
+
+FURTHER READING:
+
+For complete documentation on RtAudio, see the doc directory of the distribution or surf to http://www-ccrma.stanford.edu/~gary/rtaudio/.
+
+
+LEGAL AND ETHICAL:
+
+The RtAudio license is similar to the the MIT License, with the added "feature" that modifications be sent to the developer.
+
+    RtAudio: a realtime audio i/o C++ class
+    Copyright (c) 2001-2002 Gary P. Scavone
+
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation files
+    (the "Software"), to deal in the Software without restriction,
+    including without limitation the rights to use, copy, modify, merge,
+    publish, distribute, sublicense, and/or sell copies of the Software,
+    and to permit persons to whom the Software is furnished to do so,
+    subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    Any person wishing to distribute modifications to the Software is
+    requested to send the modifications to the original developer so that
+    they can be incorporated into the canonical version.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
index fd116da372ecc5ac1568111819c188b23e13b3de..4a51baf75632e8d52038676d3214d0487c54e630 100644 (file)
-/******************************************/\r
-/*\r
-  RtAudio - realtime sound I/O C++ class\r
-  by Gary P. Scavone, 2001-2002.\r
-*/\r
-/******************************************/\r
-\r
-#include "RtAudio.h"\r
-#include <vector>\r
-#include <stdio.h>\r
-\r
-// Static variable definitions.\r
-const unsigned int RtAudio :: SAMPLE_RATES[] = {\r
-  4000, 5512, 8000, 9600, 11025, 16000, 22050,\r
-  32000, 44100, 48000, 88200, 96000, 176400, 192000\r
-};\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT8 = 1;\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT16 = 2;\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT24 = 4;\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT32 = 8;\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_FLOAT32 = 16;\r
-const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_FLOAT64 = 32;\r
-\r
-#if defined(__WINDOWS_DS__)\r
-  #define MUTEX_INITIALIZE(A) InitializeCriticalSection(A)\r
-  #define MUTEX_LOCK(A)       EnterCriticalSection(A)\r
-  #define MUTEX_UNLOCK(A)     LeaveCriticalSection(A)\r
-  typedef unsigned THREAD_RETURN;\r
-  typedef unsigned (__stdcall THREAD_FUNCTION)(void *);\r
-#else // pthread API\r
-  #define MUTEX_INITIALIZE(A) pthread_mutex_init(A, NULL)\r
-  #define MUTEX_LOCK(A)       pthread_mutex_lock(A)\r
-  #define MUTEX_UNLOCK(A)     pthread_mutex_unlock(A)\r
-  typedef void * THREAD_RETURN;\r
-#endif\r
-\r
-// *************************************************** //\r
-//\r
-// Public common (OS-independent) methods.\r
-//\r
-// *************************************************** //\r
-\r
-RtAudio :: RtAudio()\r
-{\r
-  initialize();\r
-\r
-  if (nDevices <= 0) {\r
-    sprintf(message, "RtAudio: no audio devices found!");\r
-    error(RtError::NO_DEVICES_FOUND);\r
- }\r
-}\r
-\r
-RtAudio :: RtAudio(int *streamId,\r
-                   int outputDevice, int outputChannels,\r
-                   int inputDevice, int inputChannels,\r
-                   RTAUDIO_FORMAT format, int sampleRate,\r
-                   int *bufferSize, int numberOfBuffers)\r
-{\r
-  initialize();\r
-\r
-  if (nDevices <= 0) {\r
-    sprintf(message, "RtAudio: no audio devices found!");\r
-    error(RtError::NO_DEVICES_FOUND);\r
-  }\r
-\r
-  try {\r
-    *streamId = openStream(outputDevice, outputChannels, inputDevice, inputChannels,\r
-                           format, sampleRate, bufferSize, numberOfBuffers);\r
-  }\r
-  catch (RtError &exception) {\r
-    // deallocate the RTAUDIO_DEVICE structures\r
-    if (devices) free(devices);\r
-    error(exception.getType());\r
-  }\r
-}\r
-\r
-RtAudio :: ~RtAudio()\r
-{\r
-  // close any existing streams\r
-  while ( streams.size() )\r
-    closeStream( streams.begin()->first );\r
-\r
-  // deallocate the RTAUDIO_DEVICE structures\r
-  if (devices) free(devices);\r
-}\r
-\r
-int RtAudio :: openStream(int outputDevice, int outputChannels,\r
-                          int inputDevice, int inputChannels,\r
-                          RTAUDIO_FORMAT format, int sampleRate,\r
-                          int *bufferSize, int numberOfBuffers)\r
-{\r
-  static int streamKey = 0; // Unique stream identifier ... OK for multiple instances.\r
-\r
-  if (outputChannels < 1 && inputChannels < 1) {\r
-    sprintf(message,"RtAudio: one or both 'channel' parameters must be greater than zero.");\r
-    error(RtError::INVALID_PARAMETER);\r
-  }\r
-\r
-  if ( formatBytes(format) == 0 ) {\r
-    sprintf(message,"RtAudio: 'format' parameter value is undefined.");\r
-    error(RtError::INVALID_PARAMETER);\r
-  }\r
-\r
-  if ( outputChannels > 0 ) {\r
-    if (outputDevice >= nDevices || outputDevice < 0) {\r
-      sprintf(message,"RtAudio: 'outputDevice' parameter value (%d) is invalid.", outputDevice);\r
-      error(RtError::INVALID_PARAMETER);\r
-    }\r
-  }\r
-\r
-  if ( inputChannels > 0 ) {\r
-    if (inputDevice >= nDevices || inputDevice < 0) {\r
-      sprintf(message,"RtAudio: 'inputDevice' parameter value (%d) is invalid.", inputDevice);\r
-      error(RtError::INVALID_PARAMETER);\r
-    }\r
-  }\r
-\r
-  // Allocate a new stream structure.\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) calloc(1, sizeof(RTAUDIO_STREAM));\r
-  if (stream == NULL) {\r
-    sprintf(message, "RtAudio: memory allocation error!");\r
-    error(RtError::MEMORY_ERROR);\r
-  }\r
-  streams[++streamKey] = (void *) stream;\r
-  stream->mode = UNINITIALIZED;\r
-  MUTEX_INITIALIZE(&stream->mutex);\r
-\r
-  bool result = SUCCESS;\r
-  int device;\r
-  STREAM_MODE mode;\r
-  int channels;\r
-  if ( outputChannels > 0 ) {\r
-\r
-    device = outputDevice;\r
-    mode = PLAYBACK;\r
-    channels = outputChannels;\r
-\r
-    if (device == 0) { // Try default device first.\r
-      for (int i=0; i<nDevices; i++) {\r
-        if (devices[i].probed == false) {\r
-          // If the device wasn't successfully probed before, try it\r
-          // again now.\r
-          clearDeviceInfo(&devices[i]);\r
-          probeDeviceInfo(&devices[i]);\r
-          if (devices[i].probed == false)\r
-            continue;\r
-        }\r
-        result = probeDeviceOpen(i, stream, mode, channels, sampleRate,\r
-                                 format, bufferSize, numberOfBuffers);\r
-        if (result == SUCCESS)\r
-          break;\r
-      }\r
-    }\r
-    else {\r
-      result = probeDeviceOpen(device, stream, mode, channels, sampleRate,\r
-                               format, bufferSize, numberOfBuffers);\r
-    }\r
-  }\r
-\r
-  if ( inputChannels > 0 && result == SUCCESS ) {\r
-\r
-    device = inputDevice;\r
-    mode = RECORD;\r
-    channels = inputChannels;\r
-\r
-    if (device == 0) { // Try default device first.\r
-      for (int i=0; i<nDevices; i++) {\r
-        if (devices[i].probed == false) {\r
-          // If the device wasn't successfully probed before, try it\r
-          // again now.\r
-          clearDeviceInfo(&devices[i]);\r
-          probeDeviceInfo(&devices[i]);\r
-          if (devices[i].probed == false)\r
-            continue;\r
-        }\r
-        result = probeDeviceOpen(i, stream, mode, channels, sampleRate,\r
-                                 format, bufferSize, numberOfBuffers);\r
-        if (result == SUCCESS)\r
-          break;\r
-      }\r
-    }\r
-    else {\r
-      result = probeDeviceOpen(device, stream, mode, channels, sampleRate,\r
-                               format, bufferSize, numberOfBuffers);\r
-    }\r
-  }\r
-\r
-  if ( result == SUCCESS )\r
-    return streamKey;\r
-\r
-  // If we get here, all attempted probes failed.  Close any opened\r
-  // devices and delete the allocated stream.\r
-  closeStream(streamKey);\r
-  sprintf(message,"RtAudio: no devices found for given parameters.");\r
-  error(RtError::INVALID_PARAMETER);\r
-\r
-  return -1;\r
-}\r
-\r
-int RtAudio :: getDeviceCount(void)\r
-{\r
-  return nDevices;\r
-}\r
-\r
-void RtAudio :: getDeviceInfo(int device, RTAUDIO_DEVICE *info)\r
-{\r
-  if (device >= nDevices || device < 0) {\r
-    sprintf(message, "RtAudio: invalid device specifier (%d)!", device);\r
-    error(RtError::INVALID_DEVICE);\r
-  }\r
-\r
-  // If the device wasn't successfully probed before, try it again.\r
-  if (devices[device].probed == false) {\r
-    clearDeviceInfo(&devices[device]);\r
-    probeDeviceInfo(&devices[device]);\r
-  }\r
-\r
-  // Clear the info structure.\r
-  memset(info, 0, sizeof(RTAUDIO_DEVICE));\r
-\r
-  strncpy(info->name, devices[device].name, 128);\r
-  info->probed = devices[device].probed;\r
-  if ( info->probed == true ) {\r
-    info->maxOutputChannels = devices[device].maxOutputChannels;\r
-    info->maxInputChannels = devices[device].maxInputChannels;\r
-    info->maxDuplexChannels = devices[device].maxDuplexChannels;\r
-    info->minOutputChannels = devices[device].minOutputChannels;\r
-    info->minInputChannels = devices[device].minInputChannels;\r
-    info->minDuplexChannels = devices[device].minDuplexChannels;\r
-    info->hasDuplexSupport = devices[device].hasDuplexSupport;\r
-    info->nSampleRates = devices[device].nSampleRates;\r
-    if (info->nSampleRates == -1) {\r
-      info->sampleRates[0] = devices[device].sampleRates[0];\r
-      info->sampleRates[1] = devices[device].sampleRates[1];\r
-    }\r
-    else {\r
-      for (int i=0; i<info->nSampleRates; i++)\r
-        info->sampleRates[i] = devices[device].sampleRates[i];\r
-    }\r
-    info->nativeFormats = devices[device].nativeFormats;\r
-  }\r
-\r
-  return;\r
-}\r
-\r
-char * const RtAudio :: getStreamBuffer(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  return stream->userBuffer;\r
-}\r
-\r
-// This global structure is used to pass information to the thread\r
-// function.  I tried other methods but had intermittent errors due to\r
-// variable persistence during thread startup.\r
-struct {\r
-  RtAudio *object;\r
-  int streamId;\r
-} thread_info;\r
-\r
-extern "C" THREAD_RETURN THREAD_TYPE callbackHandler(void * ptr);\r
-\r
-void RtAudio :: setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  stream->callback = callback;\r
-  stream->userData = userData;\r
-  stream->usingCallback = true;\r
-  thread_info.object = this;\r
-  thread_info.streamId = streamId;\r
-\r
-  int err = 0;\r
-#if defined(__WINDOWS_DS__)\r
-  unsigned thread_id;\r
-  stream->thread = _beginthreadex(NULL, 0, &callbackHandler,\r
-                                  &stream->usingCallback, 0, &thread_id);\r
-  if (stream->thread == 0) err = -1;\r
-  // When spawning multiple threads in quick succession, it appears to be\r
-  // necessary to wait a bit for each to initialize ... another windism!\r
-  Sleep(1);\r
-#else\r
-  err = pthread_create(&stream->thread, NULL, callbackHandler, &stream->usingCallback);\r
-#endif\r
-\r
-  if (err) {\r
-    stream->usingCallback = false;\r
-    sprintf(message, "RtAudio: error starting callback thread!");\r
-    error(RtError::THREAD_ERROR);\r
-  }\r
-}\r
-\r
-// *************************************************** //\r
-//\r
-// OS/API-specific methods.\r
-//\r
-// *************************************************** //\r
-\r
-#if defined(__LINUX_ALSA__)\r
-\r
-#define MAX_DEVICES 16\r
-\r
-void RtAudio :: initialize(void)\r
-{\r
-  int card, result, device;\r
-  char name[32];\r
-  char deviceNames[MAX_DEVICES][32];\r
-  snd_ctl_t *handle;\r
-  snd_ctl_card_info_t *info;\r
-  snd_ctl_card_info_alloca(&info);\r
-\r
-  // Count cards and devices\r
-  nDevices = 0;\r
-  card = -1;\r
-  snd_card_next(&card);\r
-  while ( card >= 0 ) {\r
-    sprintf(name, "hw:%d", card);\r
-    result = snd_ctl_open(&handle, name, 0);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: ALSA control open (%i): %s.", card, snd_strerror(result));\r
-      error(RtError::WARNING);\r
-      goto next_card;\r
-               }\r
-    result = snd_ctl_card_info(handle, info);\r
-               if (result < 0) {\r
-      sprintf(message, "RtAudio: ALSA control hardware info (%i): %s.", card, snd_strerror(result));\r
-      error(RtError::WARNING);\r
-      goto next_card;\r
-               }\r
-               device = -1;\r
-               while (1) {\r
-      result = snd_ctl_pcm_next_device(handle, &device);\r
-                       if (result < 0) {\r
-        sprintf(message, "RtAudio: ALSA control next device (%i): %s.", card, snd_strerror(result));\r
-        error(RtError::WARNING);\r
-        break;\r
-      }\r
-                       if (device < 0)\r
-        break;\r
-      sprintf( deviceNames[nDevices++], "hw:%d,%d", card, device );\r
-      if ( nDevices > MAX_DEVICES ) break;\r
-    }\r
-    if ( nDevices > MAX_DEVICES ) break;\r
-  next_card:\r
-    snd_ctl_close(handle);\r
-    snd_card_next(&card);\r
-  }\r
-\r
-  if (nDevices == 0) return;\r
-\r
-  //  Allocate the RTAUDIO_DEVICE structures.\r
-  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));\r
-  if (devices == NULL) {\r
-    sprintf(message, "RtAudio: memory allocation error!");\r
-    error(RtError::MEMORY_ERROR);\r
-  }\r
-\r
-  // Write device ascii identifiers to device structures and then\r
-  // probe the device capabilities.\r
-  for (int i=0; i<nDevices; i++) {\r
-    strncpy(devices[i].name, deviceNames[i], 32);\r
-    probeDeviceInfo(&devices[i]);\r
-  }\r
-\r
-  return;\r
-}\r
-\r
-void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)\r
-{\r
-  int err;\r
-  int open_mode = SND_PCM_ASYNC;\r
-  snd_pcm_t *handle;\r
-  snd_pcm_stream_t stream;\r
-\r
-  // First try for playback\r
-  stream = SND_PCM_STREAM_PLAYBACK;\r
-  err = snd_pcm_open(&handle, info->name, stream, open_mode);\r
-  if (err < 0) {\r
-    sprintf(message, "RtAudio: ALSA pcm playback open (%s): %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    goto capture_probe;\r
-  }\r
-\r
-  snd_pcm_hw_params_t *params;\r
-  snd_pcm_hw_params_alloca(&params);\r
-\r
-  // We have an open device ... allocate the parameter structure.\r
-  err = snd_pcm_hw_params_any(handle, params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA hardware probe error (%s): %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    goto capture_probe;\r
-  }\r
-\r
-  // Get output channel information.\r
-  info->minOutputChannels = snd_pcm_hw_params_get_channels_min(params);\r
-  info->maxOutputChannels = snd_pcm_hw_params_get_channels_max(params);\r
-\r
-  snd_pcm_close(handle);\r
-\r
- capture_probe:\r
-  // Now try for capture\r
-  stream = SND_PCM_STREAM_CAPTURE;\r
-  err = snd_pcm_open(&handle, info->name, stream, open_mode);\r
-  if (err < 0) {\r
-    sprintf(message, "RtAudio: ALSA pcm capture open (%s): %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    if (info->maxOutputChannels == 0)\r
-      // didn't open for playback either ... device invalid\r
-      return;\r
-    goto probe_parameters;\r
-  }\r
-\r
-  // We have an open capture device ... allocate the parameter structure.\r
-  err = snd_pcm_hw_params_any(handle, params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA hardware probe error (%s): %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    if (info->maxOutputChannels > 0)\r
-      goto probe_parameters;\r
-    else\r
-      return;\r
-  }\r
-\r
-  // Get input channel information.\r
-  info->minInputChannels = snd_pcm_hw_params_get_channels_min(params);\r
-  info->maxInputChannels = snd_pcm_hw_params_get_channels_max(params);\r
-\r
-  // If device opens for both playback and capture, we determine the channels.\r
-  if (info->maxOutputChannels == 0 || info->maxInputChannels == 0)\r
-    goto probe_parameters;\r
-\r
-  info->hasDuplexSupport = true;\r
-  info->maxDuplexChannels = (info->maxOutputChannels > info->maxInputChannels) ?\r
-    info->maxInputChannels : info->maxOutputChannels;\r
-  info->minDuplexChannels = (info->minOutputChannels > info->minInputChannels) ?\r
-    info->minInputChannels : info->minOutputChannels;\r
-\r
-  snd_pcm_close(handle);\r
-\r
- probe_parameters:\r
-  // At this point, we just need to figure out the supported data\r
-  // formats and sample rates.  We'll proceed by opening the device in\r
-  // the direction with the maximum number of channels, or playback if\r
-  // they are equal.  This might limit our sample rate options, but so\r
-  // be it.\r
-\r
-  if (info->maxOutputChannels >= info->maxInputChannels)\r
-    stream = SND_PCM_STREAM_PLAYBACK;\r
-  else\r
-    stream = SND_PCM_STREAM_CAPTURE;\r
-\r
-  err = snd_pcm_open(&handle, info->name, stream, open_mode);\r
-  if (err < 0) {\r
-    sprintf(message, "RtAudio: ALSA pcm (%s) won't reopen during probe: %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // We have an open device ... allocate the parameter structure.\r
-  err = snd_pcm_hw_params_any(handle, params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA hardware reopen probe error (%s): %s.",\r
-            info->name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // Test a non-standard sample rate to see if continuous rate is supported.\r
-  int dir = 0;\r
-  if (snd_pcm_hw_params_test_rate(handle, params, 35500, dir) == 0) {\r
-    // It appears that continuous sample rate support is available.\r
-    info->nSampleRates = -1;\r
-    info->sampleRates[0] = snd_pcm_hw_params_get_rate_min(params, &dir);\r
-    info->sampleRates[1] = snd_pcm_hw_params_get_rate_max(params, &dir);\r
-  }\r
-  else {\r
-    // No continuous rate support ... test our discrete set of sample rate values.\r
-    info->nSampleRates = 0;\r
-    for (int i=0; i<MAX_SAMPLE_RATES; i++) {\r
-      if (snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0) {\r
-        info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];\r
-        info->nSampleRates++;\r
-      }\r
-    }\r
-    if (info->nSampleRates == 0) {\r
-      snd_pcm_close(handle);\r
-      return;\r
-    }\r
-  }\r
-\r
-  // Probe the supported data formats ... we don't care about endian-ness just yet\r
-  snd_pcm_format_t format;\r
-  info->nativeFormats = 0;\r
-  format = SND_PCM_FORMAT_S8;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_SINT8;\r
-  format = SND_PCM_FORMAT_S16;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_SINT16;\r
-  format = SND_PCM_FORMAT_S24;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_SINT24;\r
-  format = SND_PCM_FORMAT_S32;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_SINT32;\r
-  format = SND_PCM_FORMAT_FLOAT;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_FLOAT32;\r
-  format = SND_PCM_FORMAT_FLOAT64;\r
-  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)\r
-    info->nativeFormats |= RTAUDIO_FLOAT64;\r
-\r
-  // Check that we have at least one supported format\r
-  if (info->nativeFormats == 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA PCM device (%s) data format not supported by RtAudio.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // That's all ... close the device and return\r
-  snd_pcm_close(handle);\r
-  info->probed = true;\r
-  return;\r
-}\r
-\r
-bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,\r
-                                STREAM_MODE mode, int channels, \r
-                                int sampleRate, RTAUDIO_FORMAT format,\r
-                                int *bufferSize, int numberOfBuffers)\r
-{\r
-#if defined(RTAUDIO_DEBUG)\r
-  snd_output_t *out;\r
-  snd_output_stdio_attach(&out, stderr, 0);\r
-#endif\r
-\r
-  // I'm not using the "plug" interface ... too much inconsistent behavior.\r
-  const char *name = devices[device].name;\r
-\r
-  snd_pcm_stream_t alsa_stream;\r
-  if (mode == PLAYBACK)\r
-    alsa_stream = SND_PCM_STREAM_PLAYBACK;\r
-  else\r
-    alsa_stream = SND_PCM_STREAM_CAPTURE;\r
-\r
-  int err;\r
-  snd_pcm_t *handle;\r
-  int alsa_open_mode = SND_PCM_ASYNC;\r
-  err = snd_pcm_open(&handle, name, alsa_stream, alsa_open_mode);\r
-  if (err < 0) {\r
-    sprintf(message,"RtAudio: ALSA pcm device (%s) won't open: %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Fill the parameter structure.\r
-  snd_pcm_hw_params_t *hw_params;\r
-  snd_pcm_hw_params_alloca(&hw_params);\r
-  err = snd_pcm_hw_params_any(handle, hw_params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error getting parameter handle (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-#if defined(RTAUDIO_DEBUG)\r
-  fprintf(stderr, "\nRtAudio: ALSA dump hardware params just after device open:\n\n");\r
-  snd_pcm_hw_params_dump(hw_params, out);\r
-#endif\r
-\r
-  // Set access ... try interleaved access first, then non-interleaved\r
-  err = snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);\r
-  if (err < 0) {\r
-    // No interleave support ... try non-interleave.\r
-               err = snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);\r
-    if (err < 0) {\r
-      snd_pcm_close(handle);\r
-      sprintf(message, "RtAudio: ALSA error setting access ( (%s): %s.",\r
-              name, snd_strerror(err));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-    stream->deInterleave[mode] = true;\r
-  }\r
-\r
-  // Determine how to set the device format.\r
-  stream->userFormat = format;\r
-  snd_pcm_format_t device_format;\r
-\r
-  if (format == RTAUDIO_SINT8)\r
-    device_format = SND_PCM_FORMAT_S8;\r
-  else if (format == RTAUDIO_SINT16)\r
-    device_format = SND_PCM_FORMAT_S16;\r
-  else if (format == RTAUDIO_SINT24)\r
-    device_format = SND_PCM_FORMAT_S24;\r
-  else if (format == RTAUDIO_SINT32)\r
-    device_format = SND_PCM_FORMAT_S32;\r
-  else if (format == RTAUDIO_FLOAT32)\r
-    device_format = SND_PCM_FORMAT_FLOAT;\r
-  else if (format == RTAUDIO_FLOAT64)\r
-    device_format = SND_PCM_FORMAT_FLOAT64;\r
-\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = format;\r
-    goto set_format;\r
-  }\r
-\r
-  // The user requested format is not natively supported by the device.\r
-  device_format = SND_PCM_FORMAT_FLOAT64;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_FLOAT64;\r
-    goto set_format;\r
-  }\r
-\r
-  device_format = SND_PCM_FORMAT_FLOAT;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;\r
-    goto set_format;\r
-  }\r
-\r
-  device_format = SND_PCM_FORMAT_S32;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-    goto set_format;\r
-  }\r
-\r
-  device_format = SND_PCM_FORMAT_S24;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT24;\r
-    goto set_format;\r
-  }\r
-\r
-  device_format = SND_PCM_FORMAT_S16;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-    goto set_format;\r
-  }\r
-\r
-  device_format = SND_PCM_FORMAT_S8;\r
-  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT8;\r
-    goto set_format;\r
-  }\r
-\r
-  // If we get here, no supported format was found.\r
-  sprintf(message,"RtAudio: ALSA pcm device (%s) data format not supported by RtAudio.", name);\r
-  snd_pcm_close(handle);\r
-  error(RtError::WARNING);\r
-  return FAILURE;\r
-\r
- set_format:\r
-  err = snd_pcm_hw_params_set_format(handle, hw_params, device_format);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error setting format (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Determine whether byte-swaping is necessary.\r
-  stream->doByteSwap[mode] = false;\r
-  if (device_format != SND_PCM_FORMAT_S8) {\r
-    err = snd_pcm_format_cpu_endian(device_format);\r
-    if (err == 0)\r
-      stream->doByteSwap[mode] = true;\r
-    else if (err < 0) {\r
-      snd_pcm_close(handle);\r
-      sprintf(message, "RtAudio: ALSA error getting format endian-ness (%s): %s.",\r
-              name, snd_strerror(err));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-  }\r
-\r
-  // Determine the number of channels for this device.  We support a possible\r
-  // minimum device channel number > than the value requested by the user.\r
-  stream->nUserChannels[mode] = channels;\r
-  int device_channels = snd_pcm_hw_params_get_channels_max(hw_params);\r
-  if (device_channels < channels) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: channels (%d) not supported by device (%s).",\r
-            channels, name);\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  device_channels = snd_pcm_hw_params_get_channels_min(hw_params);\r
-  if (device_channels < channels) device_channels = channels;\r
-  stream->nDeviceChannels[mode] = device_channels;\r
-\r
-  // Set the device channels.\r
-  err = snd_pcm_hw_params_set_channels(handle, hw_params, device_channels);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error setting channels (%d) on device (%s): %s.",\r
-            device_channels, name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the sample rate.\r
-  err = snd_pcm_hw_params_set_rate(handle, hw_params, (unsigned int)sampleRate, 0);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error setting sample rate (%d) on device (%s): %s.",\r
-            sampleRate, name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the buffer number, which in ALSA is referred to as the "period".\r
-  int dir;\r
-  int periods = numberOfBuffers;\r
-  // Even though the hardware might allow 1 buffer, it won't work reliably.\r
-  if (periods < 2) periods = 2;\r
-  err = snd_pcm_hw_params_get_periods_min(hw_params, &dir);\r
-  if (err > periods) periods = err;\r
-\r
-  err = snd_pcm_hw_params_set_periods(handle, hw_params, periods, 0);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error setting periods (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the buffer (or period) size.\r
-  err = snd_pcm_hw_params_get_period_size_min(hw_params, &dir);\r
-  if (err > *bufferSize) *bufferSize = err;\r
-\r
-  err = snd_pcm_hw_params_set_period_size(handle, hw_params, *bufferSize, 0);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error setting period size (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  stream->bufferSize = *bufferSize;\r
-\r
-  // Install the hardware configuration\r
-  err = snd_pcm_hw_params(handle, hw_params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error installing hardware configuration (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-#if defined(RTAUDIO_DEBUG)\r
-  fprintf(stderr, "\nRtAudio: ALSA dump hardware params after installation:\n\n");\r
-  snd_pcm_hw_params_dump(hw_params, out);\r
-#endif\r
-\r
-  /*\r
-  // Install the software configuration\r
-  snd_pcm_sw_params_t *sw_params = NULL;\r
-  snd_pcm_sw_params_alloca(&sw_params);\r
-  snd_pcm_sw_params_current(handle, sw_params);\r
-  err = snd_pcm_sw_params(handle, sw_params);\r
-  if (err < 0) {\r
-    snd_pcm_close(handle);\r
-    sprintf(message, "RtAudio: ALSA error installing software configuration (%s): %s.",\r
-            name, snd_strerror(err));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-  */\r
-\r
-  // Set handle and flags for buffer conversion\r
-  stream->handle[mode] = handle;\r
-  stream->doConvertBuffer[mode] = false;\r
-  if (stream->userFormat != stream->deviceFormat[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-  if (stream->nUserChannels[mode] > 1 && stream->deInterleave[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-\r
-  // Allocate necessary internal buffers\r
-  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {\r
-\r
-    long buffer_bytes;\r
-    if (stream->nUserChannels[0] >= stream->nUserChannels[1])\r
-      buffer_bytes = stream->nUserChannels[0];\r
-    else\r
-      buffer_bytes = stream->nUserChannels[1];\r
-\r
-    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);\r
-    if (stream->userBuffer) free(stream->userBuffer);\r
-    stream->userBuffer = (char *) calloc(buffer_bytes, 1);\r
-    if (stream->userBuffer == NULL)\r
-      goto memory_error;\r
-  }\r
-\r
-  if ( stream->doConvertBuffer[mode] ) {\r
-\r
-    long buffer_bytes;\r
-    bool makeBuffer = true;\r
-    if ( mode == PLAYBACK )\r
-      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-    else { // mode == RECORD\r
-      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);\r
-      if ( stream->mode == PLAYBACK ) {\r
-        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-        if ( buffer_bytes > bytes_out )\r
-          buffer_bytes = (buffer_bytes > bytes_out) ? buffer_bytes : bytes_out;\r
-        else\r
-          makeBuffer = false;\r
-      }\r
-    }\r
-\r
-    if ( makeBuffer ) {\r
-      buffer_bytes *= *bufferSize;\r
-      if (stream->deviceBuffer) free(stream->deviceBuffer);\r
-      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);\r
-      if (stream->deviceBuffer == NULL)\r
-        goto memory_error;\r
-    }\r
-  }\r
-\r
-  stream->device[mode] = device;\r
-  stream->state = STREAM_STOPPED;\r
-  if ( stream->mode == PLAYBACK && mode == RECORD )\r
-    // We had already set up an output stream.\r
-    stream->mode = DUPLEX;\r
-  else\r
-    stream->mode = mode;\r
-  stream->nBuffers = periods;\r
-  stream->sampleRate = sampleRate;\r
-\r
-  return SUCCESS;\r
-\r
- memory_error:\r
-  if (stream->handle[0]) {\r
-    snd_pcm_close(stream->handle[0]);\r
-    stream->handle[0] = 0;\r
-  }\r
-  if (stream->handle[1]) {\r
-    snd_pcm_close(stream->handle[1]);\r
-    stream->handle[1] = 0;\r
-  }\r
-  if (stream->userBuffer) {\r
-    free(stream->userBuffer);\r
-    stream->userBuffer = 0;\r
-  }\r
-  sprintf(message, "RtAudio: ALSA error allocating buffer memory (%s).", name);\r
-  error(RtError::WARNING);\r
-  return FAILURE;\r
-}\r
-\r
-void RtAudio :: cancelStreamCallback(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  if (stream->usingCallback) {\r
-    stream->usingCallback = false;\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-    stream->thread = 0;\r
-    stream->callback = NULL;\r
-    stream->userData = NULL;\r
-  }\r
-}\r
-\r
-void RtAudio :: closeStream(int streamId)\r
-{\r
-  // We don't want an exception to be thrown here because this\r
-  // function is called by our class destructor.  So, do our own\r
-  // streamId check.\r
-  if ( streams.find( streamId ) == streams.end() ) {\r
-    sprintf(message, "RtAudio: invalid stream identifier!");\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];\r
-\r
-  if (stream->usingCallback) {\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-  }\r
-\r
-  if (stream->state == STREAM_RUNNING) {\r
-    if (stream->mode == PLAYBACK || stream->mode == DUPLEX)\r
-      snd_pcm_drop(stream->handle[0]);\r
-    if (stream->mode == RECORD || stream->mode == DUPLEX)\r
-      snd_pcm_drop(stream->handle[1]);\r
-  }\r
-\r
-  pthread_mutex_destroy(&stream->mutex);\r
-\r
-  if (stream->handle[0])\r
-    snd_pcm_close(stream->handle[0]);\r
-\r
-  if (stream->handle[1])\r
-    snd_pcm_close(stream->handle[1]);\r
-\r
-  if (stream->userBuffer)\r
-    free(stream->userBuffer);\r
-\r
-  if (stream->deviceBuffer)\r
-    free(stream->deviceBuffer);\r
-\r
-  free(stream);\r
-  streams.erase(streamId);\r
-}\r
-\r
-void RtAudio :: startStream(int streamId)\r
-{\r
-  // This method calls snd_pcm_prepare if the device isn't already in that state.\r
-\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_RUNNING)\r
-    goto unlock;\r
-\r
-  int err;\r
-  snd_pcm_state_t state;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    state = snd_pcm_state(stream->handle[0]);\r
-    if (state != SND_PCM_STATE_PREPARED) {\r
-      err = snd_pcm_prepare(stream->handle[0]);\r
-      if (err < 0) {\r
-        sprintf(message, "RtAudio: ALSA error preparing pcm device (%s): %s.",\r
-                devices[stream->device[0]].name, snd_strerror(err));\r
-        MUTEX_UNLOCK(&stream->mutex);\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    state = snd_pcm_state(stream->handle[1]);\r
-    if (state != SND_PCM_STATE_PREPARED) {\r
-      err = snd_pcm_prepare(stream->handle[1]);\r
-      if (err < 0) {\r
-        sprintf(message, "RtAudio: ALSA error preparing pcm device (%s): %s.",\r
-                devices[stream->device[1]].name, snd_strerror(err));\r
-        MUTEX_UNLOCK(&stream->mutex);\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-    }\r
-  }\r
-  stream->state = STREAM_RUNNING;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: stopStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = snd_pcm_drain(stream->handle[0]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",\r
-              devices[stream->device[0]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    err = snd_pcm_drain(stream->handle[1]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",\r
-              devices[stream->device[1]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: abortStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = snd_pcm_drop(stream->handle[0]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",\r
-              devices[stream->device[0]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    err = snd_pcm_drop(stream->handle[1]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",\r
-              devices[stream->device[1]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-int RtAudio :: streamWillBlock(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  int err = 0, frames = 0;\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = snd_pcm_avail_update(stream->handle[0]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error getting available frames for device (%s): %s.",\r
-              devices[stream->device[0]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  frames = err;\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    err = snd_pcm_avail_update(stream->handle[1]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: ALSA error getting available frames for device (%s): %s.",\r
-              devices[stream->device[1]].name, snd_strerror(err));\r
-      MUTEX_UNLOCK(&stream->mutex);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    if (frames > err) frames = err;\r
-  }\r
-\r
-  frames = stream->bufferSize - frames;\r
-  if (frames < 0) frames = 0;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-  return frames;\r
-}\r
-\r
-void RtAudio :: tickStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  int stopStream = 0;\r
-  if (stream->state == STREAM_STOPPED) {\r
-    if (stream->usingCallback) usleep(50000); // sleep 50 milliseconds\r
-    return;\r
-  }\r
-  else if (stream->usingCallback) {\r
-    stopStream = stream->callback(stream->userBuffer, stream->bufferSize, stream->userData);\r
-  }\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  // The state might change while waiting on a mutex.\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err;\r
-  char *buffer;\r
-  int channels;\r
-  RTAUDIO_FORMAT format;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters and do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[0]) {\r
-      convertStreamBuffer(stream, PLAYBACK);\r
-      buffer = stream->deviceBuffer;\r
-      channels = stream->nDeviceChannels[0];\r
-      format = stream->deviceFormat[0];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      channels = stream->nUserChannels[0];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[0])\r
-      byteSwapBuffer(buffer, stream->bufferSize * channels, format);\r
-\r
-    // Write samples to device in interleaved/non-interleaved format.\r
-    if (stream->deInterleave[0]) {\r
-      void *bufs[channels];\r
-      size_t offset = stream->bufferSize * formatBytes(format);\r
-      for (int i=0; i<channels; i++)\r
-        bufs[i] = (void *) (buffer + (i * offset));\r
-      err = snd_pcm_writen(stream->handle[0], bufs, stream->bufferSize);\r
-    }\r
-    else\r
-      err = snd_pcm_writei(stream->handle[0], buffer, stream->bufferSize);\r
-\r
-    if (err < stream->bufferSize) {\r
-      // Either an error or underrun occured.\r
-      if (err == -EPIPE) {\r
-        snd_pcm_state_t state = snd_pcm_state(stream->handle[0]);\r
-        if (state == SND_PCM_STATE_XRUN) {\r
-          sprintf(message, "RtAudio: ALSA underrun detected.");\r
-          error(RtError::WARNING);\r
-          err = snd_pcm_prepare(stream->handle[0]);\r
-          if (err < 0) {\r
-            sprintf(message, "RtAudio: ALSA error preparing handle after underrun: %s.",\r
-                    snd_strerror(err));\r
-            MUTEX_UNLOCK(&stream->mutex);\r
-            error(RtError::DRIVER_ERROR);\r
-          }\r
-        }\r
-        else {\r
-          sprintf(message, "RtAudio: ALSA error, current state is %s.",\r
-                  snd_pcm_state_name(state));\r
-          MUTEX_UNLOCK(&stream->mutex);\r
-          error(RtError::DRIVER_ERROR);\r
-        }\r
-        goto unlock;\r
-      }\r
-      else {\r
-        sprintf(message, "RtAudio: ALSA audio write error for device (%s): %s.",\r
-                devices[stream->device[0]].name, snd_strerror(err));\r
-        MUTEX_UNLOCK(&stream->mutex);\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters.\r
-    if (stream->doConvertBuffer[1]) {\r
-      buffer = stream->deviceBuffer;\r
-      channels = stream->nDeviceChannels[1];\r
-      format = stream->deviceFormat[1];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      channels = stream->nUserChannels[1];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Read samples from device in interleaved/non-interleaved format.\r
-    if (stream->deInterleave[1]) {\r
-      void *bufs[channels];\r
-      size_t offset = stream->bufferSize * formatBytes(format);\r
-      for (int i=0; i<channels; i++)\r
-        bufs[i] = (void *) (buffer + (i * offset));\r
-      err = snd_pcm_readn(stream->handle[1], bufs, stream->bufferSize);\r
-    }\r
-    else\r
-      err = snd_pcm_readi(stream->handle[1], buffer, stream->bufferSize);\r
-\r
-    if (err < stream->bufferSize) {\r
-      // Either an error or underrun occured.\r
-      if (err == -EPIPE) {\r
-        snd_pcm_state_t state = snd_pcm_state(stream->handle[1]);\r
-        if (state == SND_PCM_STATE_XRUN) {\r
-          sprintf(message, "RtAudio: ALSA overrun detected.");\r
-          error(RtError::WARNING);\r
-          err = snd_pcm_prepare(stream->handle[1]);\r
-          if (err < 0) {\r
-            sprintf(message, "RtAudio: ALSA error preparing handle after overrun: %s.",\r
-                    snd_strerror(err));\r
-            MUTEX_UNLOCK(&stream->mutex);\r
-            error(RtError::DRIVER_ERROR);\r
-          }\r
-        }\r
-        else {\r
-          sprintf(message, "RtAudio: ALSA error, current state is %s.",\r
-                  snd_pcm_state_name(state));\r
-          MUTEX_UNLOCK(&stream->mutex);\r
-          error(RtError::DRIVER_ERROR);\r
-        }\r
-        goto unlock;\r
-      }\r
-      else {\r
-        sprintf(message, "RtAudio: ALSA audio read error for device (%s): %s.",\r
-                devices[stream->device[1]].name, snd_strerror(err));\r
-        MUTEX_UNLOCK(&stream->mutex);\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-    }\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[1])\r
-      byteSwapBuffer(buffer, stream->bufferSize * channels, format);\r
-\r
-    // Do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[1])\r
-      convertStreamBuffer(stream, RECORD);\r
-  }\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-\r
-  if (stream->usingCallback && stopStream)\r
-    this->stopStream(streamId);\r
-}\r
-\r
-extern "C" void *callbackHandler(void *ptr)\r
-{\r
-  RtAudio *object = thread_info.object;\r
-  int stream = thread_info.streamId;\r
-  bool *usingCallback = (bool *) ptr;\r
-\r
-  while ( *usingCallback ) {\r
-    pthread_testcancel();\r
-    try {\r
-      object->tickStream(stream);\r
-    }\r
-    catch (RtError &exception) {\r
-      fprintf(stderr, "\nCallback thread error (%s) ... closing thread.\n\n",\r
-              exception.getMessage());\r
-      break;\r
-    }\r
-  }\r
-\r
-  return 0;\r
-}\r
-\r
-//******************** End of __LINUX_ALSA__ *********************//\r
-\r
-#elif defined(__LINUX_OSS__)\r
-\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <sys/ioctl.h>\r
-#include <unistd.h>\r
-#include <fcntl.h>\r
-#include <sys/soundcard.h>\r
-#include <errno.h>\r
-#include <math.h>\r
-\r
-#define DAC_NAME "/dev/dsp"\r
-#define MAX_DEVICES 16\r
-#define MAX_CHANNELS 16\r
-\r
-void RtAudio :: initialize(void)\r
-{\r
-  // Count cards and devices\r
-  nDevices = 0;\r
-\r
-  // We check /dev/dsp before probing devices.  /dev/dsp is supposed to\r
-  // be a link to the "default" audio device, of the form /dev/dsp0,\r
-  // /dev/dsp1, etc...  However, I've seen one case where /dev/dsp was a\r
-  // real device, so we need to check for that.  Also, sometimes the\r
-  // link is to /dev/dspx and other times just dspx.  I'm not sure how\r
-  // the latter works, but it does.\r
-  char device_name[16];\r
-  struct stat dspstat;\r
-  int dsplink = -1;\r
-  int i = 0;\r
-  if (lstat(DAC_NAME, &dspstat) == 0) {\r
-    if (S_ISLNK(dspstat.st_mode)) {\r
-      i = readlink(DAC_NAME, device_name, sizeof(device_name));\r
-      if (i > 0) {\r
-        device_name[i] = '\0';\r
-        if (i > 8) { // check for "/dev/dspx"\r
-          if (!strncmp(DAC_NAME, device_name, 8))\r
-            dsplink = atoi(&device_name[8]);\r
-        }\r
-        else if (i > 3) { // check for "dspx"\r
-          if (!strncmp("dsp", device_name, 3))\r
-            dsplink = atoi(&device_name[3]);\r
-        }\r
-      }\r
-      else {\r
-        sprintf(message, "RtAudio: cannot read value of symbolic link %s.", DAC_NAME);\r
-        error(RtError::SYSTEM_ERROR);\r
-      }\r
-    }\r
-  }\r
-  else {\r
-    sprintf(message, "RtAudio: cannot stat %s.", DAC_NAME);\r
-    error(RtError::SYSTEM_ERROR);\r
-  }\r
-\r
-  // The OSS API doesn't provide a routine for determining the number\r
-  // of devices.  Thus, we'll just pursue a brute force method.  The\r
-  // idea is to start with /dev/dsp(0) and continue with higher device\r
-  // numbers until we reach MAX_DSP_DEVICES.  This should tell us how\r
-  // many devices we have ... it is not a fullproof scheme, but hopefully\r
-  // it will work most of the time.\r
-\r
-  int fd = 0;\r
-  char names[MAX_DEVICES][16];\r
-  for (i=-1; i<MAX_DEVICES; i++) {\r
-\r
-    // Probe /dev/dsp first, since it is supposed to be the default device.\r
-    if (i == -1)\r
-      sprintf(device_name, "%s", DAC_NAME);\r
-    else if (i == dsplink)\r
-      continue; // We've aready probed this device via /dev/dsp link ... try next device.\r
-    else\r
-      sprintf(device_name, "%s%d", DAC_NAME, i);\r
-\r
-    // First try to open the device for playback, then record mode.\r
-    fd = open(device_name, O_WRONLY | O_NONBLOCK);\r
-    if (fd == -1) {\r
-      // Open device for playback failed ... either busy or doesn't exist.\r
-      if (errno != EBUSY && errno != EAGAIN) {\r
-        // Try to open for capture\r
-        fd = open(device_name, O_RDONLY | O_NONBLOCK);\r
-        if (fd == -1) {\r
-          // Open device for record failed.\r
-          if (errno != EBUSY && errno != EAGAIN)\r
-            continue;\r
-          else {\r
-            sprintf(message, "RtAudio: OSS record device (%s) is busy.", device_name);\r
-            error(RtError::WARNING);\r
-            // still count it for now\r
-          }\r
-        }\r
-      }\r
-      else {\r
-        sprintf(message, "RtAudio: OSS playback device (%s) is busy.", device_name);\r
-        error(RtError::WARNING);\r
-        // still count it for now\r
-      }\r
-    }\r
-\r
-    if (fd >= 0) close(fd);\r
-    strncpy(names[nDevices], device_name, 16);\r
-    nDevices++;\r
-  }\r
-\r
-  if (nDevices == 0) return;\r
-\r
-  //  Allocate the RTAUDIO_DEVICE structures.\r
-  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));\r
-  if (devices == NULL) {\r
-    sprintf(message, "RtAudio: memory allocation error!");\r
-    error(RtError::MEMORY_ERROR);\r
-  }\r
-\r
-  // Write device ascii identifiers to device control structure and then probe capabilities.\r
-  for (i=0; i<nDevices; i++) {\r
-    strncpy(devices[i].name, names[i], 16);\r
-    probeDeviceInfo(&devices[i]);\r
-  }\r
-\r
-  return;\r
-}\r
-\r
-void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)\r
-{\r
-  int i, fd, channels, mask;\r
-\r
-  // The OSS API doesn't provide a means for probing the capabilities\r
-  // of devices.  Thus, we'll just pursue a brute force method.\r
-\r
-  // First try for playback\r
-  fd = open(info->name, O_WRONLY | O_NONBLOCK);\r
-  if (fd == -1) {\r
-    // Open device failed ... either busy or doesn't exist\r
-    if (errno == EBUSY || errno == EAGAIN)\r
-      sprintf(message, "RtAudio: OSS playback device (%s) is busy and cannot be probed.",\r
-              info->name);\r
-    else\r
-      sprintf(message, "RtAudio: OSS playback device (%s) open error.", info->name);\r
-    error(RtError::WARNING);\r
-    goto capture_probe;\r
-  }\r
-\r
-  // We have an open device ... see how many channels it can handle\r
-  for (i=MAX_CHANNELS; i>0; i--) {\r
-    channels = i;\r
-    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {\r
-      // This would normally indicate some sort of hardware error, but under ALSA's\r
-      // OSS emulation, it sometimes indicates an invalid channel value.  Further,\r
-      // the returned channel value is not changed. So, we'll ignore the possible\r
-      // hardware error.\r
-      continue; // try next channel number\r
-    }\r
-    // Check to see whether the device supports the requested number of channels\r
-    if (channels != i ) continue; // try next channel number\r
-    // If here, we found the largest working channel value\r
-    break;\r
-  }\r
-  info->maxOutputChannels = channels;\r
-\r
-  // Now find the minimum number of channels it can handle\r
-  for (i=1; i<=info->maxOutputChannels; i++) {\r
-    channels = i;\r
-    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)\r
-      continue; // try next channel number\r
-    // If here, we found the smallest working channel value\r
-    break;\r
-  }\r
-  info->minOutputChannels = channels;\r
-  close(fd);\r
-\r
- capture_probe:\r
-  // Now try for capture\r
-  fd = open(info->name, O_RDONLY | O_NONBLOCK);\r
-  if (fd == -1) {\r
-    // Open device for capture failed ... either busy or doesn't exist\r
-    if (errno == EBUSY || errno == EAGAIN)\r
-      sprintf(message, "RtAudio: OSS capture device (%s) is busy and cannot be probed.",\r
-              info->name);\r
-    else\r
-      sprintf(message, "RtAudio: OSS capture device (%s) open error.", info->name);\r
-    error(RtError::WARNING);\r
-    if (info->maxOutputChannels == 0)\r
-      // didn't open for playback either ... device invalid\r
-      return;\r
-    goto probe_parameters;\r
-  }\r
-\r
-  // We have the device open for capture ... see how many channels it can handle\r
-  for (i=MAX_CHANNELS; i>0; i--) {\r
-    channels = i;\r
-    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i) {\r
-      continue; // as above\r
-    }\r
-    // If here, we found a working channel value\r
-    break;\r
-  }\r
-  info->maxInputChannels = channels;\r
-\r
-  // Now find the minimum number of channels it can handle\r
-  for (i=1; i<=info->maxInputChannels; i++) {\r
-    channels = i;\r
-    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)\r
-      continue; // try next channel number\r
-    // If here, we found the smallest working channel value\r
-    break;\r
-  }\r
-  info->minInputChannels = channels;\r
-  close(fd);\r
-\r
-  // If device opens for both playback and capture, we determine the channels.\r
-  if (info->maxOutputChannels == 0 || info->maxInputChannels == 0)\r
-    goto probe_parameters;\r
-\r
-  fd = open(info->name, O_RDWR | O_NONBLOCK);\r
-  if (fd == -1)\r
-    goto probe_parameters;\r
-\r
-  ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);\r
-  ioctl(fd, SNDCTL_DSP_GETCAPS, &mask);\r
-  if (mask & DSP_CAP_DUPLEX) {\r
-    info->hasDuplexSupport = true;\r
-    // We have the device open for duplex ... see how many channels it can handle\r
-    for (i=MAX_CHANNELS; i>0; i--) {\r
-      channels = i;\r
-      if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)\r
-        continue; // as above\r
-      // If here, we found a working channel value\r
-      break;\r
-    }\r
-    info->maxDuplexChannels = channels;\r
-\r
-    // Now find the minimum number of channels it can handle\r
-    for (i=1; i<=info->maxDuplexChannels; i++) {\r
-      channels = i;\r
-      if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)\r
-        continue; // try next channel number\r
-      // If here, we found the smallest working channel value\r
-      break;\r
-    }\r
-    info->minDuplexChannels = channels;\r
-  }\r
-  close(fd);\r
-\r
- probe_parameters:\r
-  // At this point, we need to figure out the supported data formats\r
-  // and sample rates.  We'll proceed by openning the device in the\r
-  // direction with the maximum number of channels, or playback if\r
-  // they are equal.  This might limit our sample rate options, but so\r
-  // be it.\r
-\r
-  if (info->maxOutputChannels >= info->maxInputChannels) {\r
-    fd = open(info->name, O_WRONLY | O_NONBLOCK);\r
-    channels = info->maxOutputChannels;\r
-  }\r
-  else {\r
-    fd = open(info->name, O_RDONLY | O_NONBLOCK);\r
-    channels = info->maxInputChannels;\r
-  }\r
-\r
-  if (fd == -1) {\r
-    // We've got some sort of conflict ... abort\r
-    sprintf(message, "RtAudio: OSS device (%s) won't reopen during probe.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // We have an open device ... set to maximum channels.\r
-  i = channels;\r
-  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i) {\r
-    // We've got some sort of conflict ... abort\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) won't revert to previous channel setting.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  if (ioctl(fd, SNDCTL_DSP_GETFMTS, &mask) == -1) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) can't get supported audio formats.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // Probe the supported data formats ... we don't care about endian-ness just yet.\r
-  int format;\r
-  info->nativeFormats = 0;\r
-#if defined (AFMT_S32_BE)\r
-  // This format does not seem to be in the 2.4 kernel version of OSS soundcard.h\r
-  if (mask & AFMT_S32_BE) {\r
-    format = AFMT_S32_BE;\r
-    info->nativeFormats |= RTAUDIO_SINT32;\r
-  }\r
-#endif\r
-#if defined (AFMT_S32_LE)\r
-  /* This format is not in the 2.4.4 kernel version of OSS soundcard.h */\r
-  if (mask & AFMT_S32_LE) {\r
-    format = AFMT_S32_LE;\r
-    info->nativeFormats |= RTAUDIO_SINT32;\r
-  }\r
-#endif\r
-  if (mask & AFMT_S8) {\r
-    format = AFMT_S8;\r
-    info->nativeFormats |= RTAUDIO_SINT8;\r
-  }\r
-  if (mask & AFMT_S16_BE) {\r
-    format = AFMT_S16_BE;\r
-    info->nativeFormats |= RTAUDIO_SINT16;\r
-  }\r
-  if (mask & AFMT_S16_LE) {\r
-    format = AFMT_S16_LE;\r
-    info->nativeFormats |= RTAUDIO_SINT16;\r
-  }\r
-\r
-  // Check that we have at least one supported format\r
-  if (info->nativeFormats == 0) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) data format not supported by RtAudio.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // Set the format\r
-  i = format;\r
-  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1 || format != i) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) error setting data format.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // Probe the supported sample rates ... first get lower limit\r
-  int speed = 1;\r
-  if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {\r
-    // If we get here, we're probably using an ALSA driver with OSS-emulation,\r
-    // which doesn't conform to the OSS specification.  In this case,\r
-    // we'll probe our predefined list of sample rates for working values.\r
-    info->nSampleRates = 0;\r
-    for (i=0; i<MAX_SAMPLE_RATES; i++) {\r
-      speed = SAMPLE_RATES[i];\r
-      if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) != -1) {\r
-        info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];\r
-        info->nSampleRates++;\r
-      }\r
-    }\r
-    if (info->nSampleRates == 0) {\r
-      close(fd);\r
-      return;\r
-    }\r
-    goto finished;\r
-  }\r
-  info->sampleRates[0] = speed;\r
-\r
-  // Now get upper limit\r
-  speed = 1000000;\r
-  if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) error setting sample rate.",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-  info->sampleRates[1] = speed;\r
-  info->nSampleRates = -1;\r
-\r
- finished: // That's all ... close the device and return\r
-  close(fd);\r
-  info->probed = true;\r
-  return;\r
-}\r
-\r
-bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,\r
-                                STREAM_MODE mode, int channels, \r
-                                int sampleRate, RTAUDIO_FORMAT format,\r
-                                int *bufferSize, int numberOfBuffers)\r
-{\r
-  int buffers, buffer_bytes, device_channels, device_format;\r
-  int srate, temp, fd;\r
-\r
-  const char *name = devices[device].name;\r
-\r
-  if (mode == PLAYBACK)\r
-    fd = open(name, O_WRONLY | O_NONBLOCK);\r
-  else { // mode == RECORD\r
-    if (stream->mode == PLAYBACK && stream->device[0] == device) {\r
-      // We just set the same device for playback ... close and reopen for duplex (OSS only).\r
-      close(stream->handle[0]);\r
-      stream->handle[0] = 0;\r
-      // First check that the number previously set channels is the same.\r
-      if (stream->nUserChannels[0] != channels) {\r
-        sprintf(message, "RtAudio: input/output channels must be equal for OSS duplex device (%s).", name);\r
-        goto error;\r
-      }\r
-      fd = open(name, O_RDWR | O_NONBLOCK);\r
-    }\r
-    else\r
-      fd = open(name, O_RDONLY | O_NONBLOCK);\r
-  }\r
-\r
-  if (fd == -1) {\r
-    if (errno == EBUSY || errno == EAGAIN)\r
-      sprintf(message, "RtAudio: OSS device (%s) is busy and cannot be opened.",\r
-              name);\r
-    else\r
-      sprintf(message, "RtAudio: OSS device (%s) cannot be opened.", name);\r
-    goto error;\r
-  }\r
-\r
-  // Now reopen in blocking mode.\r
-  close(fd);\r
-  if (mode == PLAYBACK)\r
-    fd = open(name, O_WRONLY | O_SYNC);\r
-  else { // mode == RECORD\r
-    if (stream->mode == PLAYBACK && stream->device[0] == device)\r
-      fd = open(name, O_RDWR | O_SYNC);\r
-    else\r
-      fd = open(name, O_RDONLY | O_SYNC);\r
-  }\r
-\r
-  if (fd == -1) {\r
-    sprintf(message, "RtAudio: OSS device (%s) cannot be opened.", name);\r
-    goto error;\r
-  }\r
-\r
-  // Get the sample format mask\r
-  int mask;\r
-  if (ioctl(fd, SNDCTL_DSP_GETFMTS, &mask) == -1) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) can't get supported audio formats.",\r
-            name);\r
-    goto error;\r
-  }\r
-\r
-  // Determine how to set the device format.\r
-  stream->userFormat = format;\r
-  device_format = -1;\r
-  stream->doByteSwap[mode] = false;\r
-  if (format == RTAUDIO_SINT8) {\r
-    if (mask & AFMT_S8) {\r
-      device_format = AFMT_S8;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT8;\r
-    }\r
-  }\r
-  else if (format == RTAUDIO_SINT16) {\r
-    if (mask & AFMT_S16_NE) {\r
-      device_format = AFMT_S16_NE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-    }\r
-#if BYTE_ORDER == LITTLE_ENDIAN\r
-    else if (mask & AFMT_S16_BE) {\r
-      device_format = AFMT_S16_BE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#else\r
-    else if (mask & AFMT_S16_LE) {\r
-      device_format = AFMT_S16_LE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#endif\r
-  }\r
-#if defined (AFMT_S32_NE) && defined (AFMT_S32_LE) && defined (AFMT_S32_BE)\r
-  else if (format == RTAUDIO_SINT32) {\r
-    if (mask & AFMT_S32_NE) {\r
-      device_format = AFMT_S32_NE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-    }\r
-#if BYTE_ORDER == LITTLE_ENDIAN\r
-    else if (mask & AFMT_S32_BE) {\r
-      device_format = AFMT_S32_BE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#else\r
-    else if (mask & AFMT_S32_LE) {\r
-      device_format = AFMT_S32_LE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#endif\r
-  }\r
-#endif\r
-\r
-  if (device_format == -1) {\r
-    // The user requested format is not natively supported by the device.\r
-    if (mask & AFMT_S16_NE) {\r
-      device_format = AFMT_S16_NE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-    }\r
-#if BYTE_ORDER == LITTLE_ENDIAN\r
-    else if (mask & AFMT_S16_BE) {\r
-      device_format = AFMT_S16_BE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#else\r
-    else if (mask & AFMT_S16_LE) {\r
-      device_format = AFMT_S16_LE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#endif\r
-#if defined (AFMT_S32_NE) && defined (AFMT_S32_LE) && defined (AFMT_S32_BE)\r
-    else if (mask & AFMT_S32_NE) {\r
-      device_format = AFMT_S32_NE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-    }\r
-#if BYTE_ORDER == LITTLE_ENDIAN\r
-    else if (mask & AFMT_S32_BE) {\r
-      device_format = AFMT_S32_BE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#else\r
-    else if (mask & AFMT_S32_LE) {\r
-      device_format = AFMT_S32_LE;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT32;\r
-      stream->doByteSwap[mode] = true;\r
-    }\r
-#endif\r
-#endif\r
-    else if (mask & AFMT_S8) {\r
-      device_format = AFMT_S8;\r
-      stream->deviceFormat[mode] = RTAUDIO_SINT8;\r
-    }\r
-  }\r
-\r
-  if (stream->deviceFormat[mode] == 0) {\r
-    // This really shouldn't happen ...\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS device (%s) data format not supported by RtAudio.",\r
-            name);\r
-    goto error;\r
-  }\r
-\r
-  // Determine the number of channels for this device.  Note that the\r
-  // channel value requested by the user might be < min_X_Channels.\r
-  stream->nUserChannels[mode] = channels;\r
-  device_channels = channels;\r
-  if (mode == PLAYBACK) {\r
-    if (channels < devices[device].minOutputChannels)\r
-      device_channels = devices[device].minOutputChannels;\r
-  }\r
-  else { // mode == RECORD\r
-    if (stream->mode == PLAYBACK && stream->device[0] == device) {\r
-      // We're doing duplex setup here.\r
-      if (channels < devices[device].minDuplexChannels)\r
-        device_channels = devices[device].minDuplexChannels;\r
-    }\r
-    else {\r
-      if (channels < devices[device].minInputChannels)\r
-        device_channels = devices[device].minInputChannels;\r
-    }\r
-  }\r
-  stream->nDeviceChannels[mode] = device_channels;\r
-\r
-  // Attempt to set the buffer size.  According to OSS, the minimum\r
-  // number of buffers is two.  The supposed minimum buffer size is 16\r
-  // bytes, so that will be our lower bound.  The argument to this\r
-  // call is in the form 0xMMMMSSSS (hex), where the buffer size (in\r
-  // bytes) is given as 2^SSSS and the number of buffers as 2^MMMM.\r
-  // We'll check the actual value used near the end of the setup\r
-  // procedure.\r
-  buffer_bytes = *bufferSize * formatBytes(stream->deviceFormat[mode]) * device_channels;\r
-  if (buffer_bytes < 16) buffer_bytes = 16;\r
-  buffers = numberOfBuffers;\r
-  if (buffers < 2) buffers = 2;\r
-  temp = ((int) buffers << 16) + (int)(log10((double)buffer_bytes)/log10(2.0));\r
-  if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &temp)) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error setting fragment size for device (%s).",\r
-            name);\r
-    goto error;\r
-  }\r
-  stream->nBuffers = buffers;\r
-\r
-  // Set the data format.\r
-  temp = device_format;\r
-  if (ioctl(fd, SNDCTL_DSP_SETFMT, &device_format) == -1 || device_format != temp) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error setting data format for device (%s).",\r
-            name);\r
-    goto error;\r
-  }\r
-\r
-  // Set the number of channels.\r
-  temp = device_channels;\r
-  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &device_channels) == -1 || device_channels != temp) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error setting %d channels on device (%s).",\r
-            temp, name);\r
-    goto error;\r
-  }\r
-\r
-  // Set the sample rate.\r
-  srate = sampleRate;\r
-  temp = srate;\r
-  if (ioctl(fd, SNDCTL_DSP_SPEED, &srate) == -1) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error setting sample rate = %d on device (%s).",\r
-            temp, name);\r
-    goto error;\r
-  }\r
-\r
-  // Verify the sample rate setup worked.\r
-  if (abs(srate - temp) > 100) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error ... audio device (%s) doesn't support sample rate of %d.",\r
-            name, temp);\r
-    goto error;\r
-  }\r
-  stream->sampleRate = sampleRate;\r
-\r
-  if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &buffer_bytes) == -1) {\r
-    close(fd);\r
-    sprintf(message, "RtAudio: OSS error getting buffer size for device (%s).",\r
-            name);\r
-    goto error;\r
-  }\r
-\r
-  // Save buffer size (in sample frames).\r
-  *bufferSize = buffer_bytes / (formatBytes(stream->deviceFormat[mode]) * device_channels);\r
-  stream->bufferSize = *bufferSize;\r
-\r
-  if (mode == RECORD && stream->mode == PLAYBACK &&\r
-      stream->device[0] == device) {\r
-    // We're doing duplex setup here.\r
-    stream->deviceFormat[0] = stream->deviceFormat[1];\r
-    stream->nDeviceChannels[0] = device_channels;\r
-  }\r
-\r
-  // Set flags for buffer conversion\r
-  stream->doConvertBuffer[mode] = false;\r
-  if (stream->userFormat != stream->deviceFormat[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-\r
-  // Allocate necessary internal buffers\r
-  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {\r
-\r
-    long buffer_bytes;\r
-    if (stream->nUserChannels[0] >= stream->nUserChannels[1])\r
-      buffer_bytes = stream->nUserChannels[0];\r
-    else\r
-      buffer_bytes = stream->nUserChannels[1];\r
-\r
-    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);\r
-    if (stream->userBuffer) free(stream->userBuffer);\r
-    stream->userBuffer = (char *) calloc(buffer_bytes, 1);\r
-    if (stream->userBuffer == NULL) {\r
-      close(fd);\r
-      sprintf(message, "RtAudio: OSS error allocating user buffer memory (%s).",\r
-              name);\r
-      goto error;\r
-    }\r
-  }\r
-\r
-  if ( stream->doConvertBuffer[mode] ) {\r
-\r
-    long buffer_bytes;\r
-    bool makeBuffer = true;\r
-    if ( mode == PLAYBACK )\r
-      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-    else { // mode == RECORD\r
-      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);\r
-      if ( stream->mode == PLAYBACK ) {\r
-        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-        if ( buffer_bytes > bytes_out )\r
-          buffer_bytes = (buffer_bytes > bytes_out) ? buffer_bytes : bytes_out;\r
-        else\r
-          makeBuffer = false;\r
-      }\r
-    }\r
-\r
-    if ( makeBuffer ) {\r
-      buffer_bytes *= *bufferSize;\r
-      if (stream->deviceBuffer) free(stream->deviceBuffer);\r
-      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);\r
-      if (stream->deviceBuffer == NULL) {\r
-        close(fd);\r
-        free(stream->userBuffer);\r
-        sprintf(message, "RtAudio: OSS error allocating device buffer memory (%s).",\r
-                name);\r
-        goto error;\r
-      }\r
-    }\r
-  }\r
-\r
-  stream->device[mode] = device;\r
-  stream->handle[mode] = fd;\r
-  stream->state = STREAM_STOPPED;\r
-  if ( stream->mode == PLAYBACK && mode == RECORD ) {\r
-    stream->mode = DUPLEX;\r
-    if (stream->device[0] == device)\r
-      stream->handle[0] = fd;\r
-  }\r
-  else\r
-    stream->mode = mode;\r
-\r
-  return SUCCESS;\r
-\r
- error:\r
-  if (stream->handle[0]) {\r
-    close(stream->handle[0]);\r
-    stream->handle[0] = 0;\r
-  }\r
-  error(RtError::WARNING);\r
-  return FAILURE;\r
-}\r
-\r
-void RtAudio :: cancelStreamCallback(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  if (stream->usingCallback) {\r
-    stream->usingCallback = false;\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-    stream->thread = 0;\r
-    stream->callback = NULL;\r
-    stream->userData = NULL;\r
-  }\r
-}\r
-\r
-void RtAudio :: closeStream(int streamId)\r
-{\r
-  // We don't want an exception to be thrown here because this\r
-  // function is called by our class destructor.  So, do our own\r
-  // streamId check.\r
-  if ( streams.find( streamId ) == streams.end() ) {\r
-    sprintf(message, "RtAudio: invalid stream identifier!");\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];\r
-\r
-  if (stream->usingCallback) {\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-  }\r
-\r
-  if (stream->state == STREAM_RUNNING) {\r
-    if (stream->mode == PLAYBACK || stream->mode == DUPLEX)\r
-      ioctl(stream->handle[0], SNDCTL_DSP_RESET, 0);\r
-    if (stream->mode == RECORD || stream->mode == DUPLEX)\r
-      ioctl(stream->handle[1], SNDCTL_DSP_RESET, 0);\r
-  }\r
-\r
-  pthread_mutex_destroy(&stream->mutex);\r
-\r
-  if (stream->handle[0])\r
-    close(stream->handle[0]);\r
-\r
-  if (stream->handle[1])\r
-    close(stream->handle[1]);\r
-\r
-  if (stream->userBuffer)\r
-    free(stream->userBuffer);\r
-\r
-  if (stream->deviceBuffer)\r
-    free(stream->deviceBuffer);\r
-\r
-  free(stream);\r
-  streams.erase(streamId);\r
-}\r
-\r
-void RtAudio :: startStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  stream->state = STREAM_RUNNING;\r
-\r
-  // No need to do anything else here ... OSS automatically starts when fed samples.\r
-}\r
-\r
-void RtAudio :: stopStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = ioctl(stream->handle[0], SNDCTL_DSP_SYNC, 0);\r
-    if (err < -1) {\r
-      sprintf(message, "RtAudio: OSS error stopping device (%s).",\r
-              devices[stream->device[0]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  else {\r
-    err = ioctl(stream->handle[1], SNDCTL_DSP_SYNC, 0);\r
-    if (err < -1) {\r
-      sprintf(message, "RtAudio: OSS error stopping device (%s).",\r
-              devices[stream->device[1]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: abortStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = ioctl(stream->handle[0], SNDCTL_DSP_RESET, 0);\r
-    if (err < -1) {\r
-      sprintf(message, "RtAudio: OSS error aborting device (%s).",\r
-              devices[stream->device[0]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  else {\r
-    err = ioctl(stream->handle[1], SNDCTL_DSP_RESET, 0);\r
-    if (err < -1) {\r
-      sprintf(message, "RtAudio: OSS error aborting device (%s).",\r
-              devices[stream->device[1]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-int RtAudio :: streamWillBlock(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  int bytes = 0, channels = 0, frames = 0;\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  audio_buf_info info;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    ioctl(stream->handle[0], SNDCTL_DSP_GETOSPACE, &info);\r
-    bytes = info.bytes;\r
-    channels = stream->nDeviceChannels[0];\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    ioctl(stream->handle[1], SNDCTL_DSP_GETISPACE, &info);\r
-    if (stream->mode == DUPLEX ) {\r
-      bytes = (bytes < info.bytes) ? bytes : info.bytes;\r
-      channels = stream->nDeviceChannels[0];\r
-    }\r
-    else {\r
-      bytes = info.bytes;\r
-      channels = stream->nDeviceChannels[1];\r
-    }\r
-  }\r
-\r
-  frames = (int) (bytes / (channels * formatBytes(stream->deviceFormat[0])));\r
-  frames -= stream->bufferSize;\r
-  if (frames < 0) frames = 0;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-  return frames;\r
-}\r
-\r
-void RtAudio :: tickStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  int stopStream = 0;\r
-  if (stream->state == STREAM_STOPPED) {\r
-    if (stream->usingCallback) usleep(50000); // sleep 50 milliseconds\r
-    return;\r
-  }\r
-  else if (stream->usingCallback) {\r
-    stopStream = stream->callback(stream->userBuffer, stream->bufferSize, stream->userData);\r
-  }\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  // The state might change while waiting on a mutex.\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int result;\r
-  char *buffer;\r
-  int samples;\r
-  RTAUDIO_FORMAT format;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters and do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[0]) {\r
-      convertStreamBuffer(stream, PLAYBACK);\r
-      buffer = stream->deviceBuffer;\r
-      samples = stream->bufferSize * stream->nDeviceChannels[0];\r
-      format = stream->deviceFormat[0];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      samples = stream->bufferSize * stream->nUserChannels[0];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[0])\r
-      byteSwapBuffer(buffer, samples, format);\r
-\r
-    // Write samples to device.\r
-    result = write(stream->handle[0], buffer, samples * formatBytes(format));\r
-\r
-    if (result == -1) {\r
-      // This could be an underrun, but the basic OSS API doesn't provide a means for determining that.\r
-      sprintf(message, "RtAudio: OSS audio write error for device (%s).",\r
-              devices[stream->device[0]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters.\r
-    if (stream->doConvertBuffer[1]) {\r
-      buffer = stream->deviceBuffer;\r
-      samples = stream->bufferSize * stream->nDeviceChannels[1];\r
-      format = stream->deviceFormat[1];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      samples = stream->bufferSize * stream->nUserChannels[1];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Read samples from device.\r
-    result = read(stream->handle[1], buffer, samples * formatBytes(format));\r
-\r
-    if (result == -1) {\r
-      // This could be an overrun, but the basic OSS API doesn't provide a means for determining that.\r
-      sprintf(message, "RtAudio: OSS audio read error for device (%s).",\r
-              devices[stream->device[1]].name);\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[1])\r
-      byteSwapBuffer(buffer, samples, format);\r
-\r
-    // Do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[1])\r
-      convertStreamBuffer(stream, RECORD);\r
-  }\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-\r
-  if (stream->usingCallback && stopStream)\r
-    this->stopStream(streamId);\r
-}\r
-\r
-extern "C" void *callbackHandler(void *ptr)\r
-{\r
-  RtAudio *object = thread_info.object;\r
-  int stream = thread_info.streamId;\r
-  bool *usingCallback = (bool *) ptr;\r
-\r
-  while ( *usingCallback ) {\r
-    pthread_testcancel();\r
-    try {\r
-      object->tickStream(stream);\r
-    }\r
-    catch (RtError &exception) {\r
-      fprintf(stderr, "\nCallback thread error (%s) ... closing thread.\n\n",\r
-              exception.getMessage());\r
-      break;\r
-    }\r
-  }\r
-\r
-  return 0;\r
-}\r
-\r
-//******************** End of __LINUX_OSS__ *********************//\r
-\r
-#elif defined(__WINDOWS_DS__) // Windows DirectSound API\r
-\r
-#include <dsound.h>\r
-\r
-// Declarations for utility functions, callbacks, and structures\r
-// specific to the DirectSound implementation.\r
-static bool CALLBACK deviceCountCallback(LPGUID lpguid,\r
-                                         LPCSTR lpcstrDescription,\r
-                                         LPCSTR lpcstrModule,\r
-                                         LPVOID lpContext);\r
-\r
-static bool CALLBACK deviceInfoCallback(LPGUID lpguid,\r
-                                        LPCSTR lpcstrDescription,\r
-                                        LPCSTR lpcstrModule,\r
-                                        LPVOID lpContext);\r
-\r
-static char* getErrorString(int code);\r
-\r
-struct enum_info {\r
-  char name[64];\r
-  LPGUID id;\r
-  bool isInput;\r
-  bool isValid;\r
-};\r
-\r
-// RtAudio methods for DirectSound implementation.\r
-void RtAudio :: initialize(void)\r
-{\r
-  int i, ins = 0, outs = 0, count = 0;\r
-  int index = 0;\r
-  HRESULT result;\r
-  nDevices = 0;\r
-\r
-  // Count DirectSound devices.\r
-  result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceCountCallback, &outs);\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Unable to enumerate through sound playback devices: %s.",\r
-            getErrorString(result));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  // Count DirectSoundCapture devices.\r
-  result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceCountCallback, &ins);\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Unable to enumerate through sound capture devices: %s.",\r
-            getErrorString(result));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  count = ins + outs;\r
-  if (count == 0) return;\r
-\r
-  std::vector<enum_info> info(count);\r
-  for (i=0; i<count; i++) {\r
-    info[i].name[0] = '\0';\r
-    if (i < outs) info[i].isInput = false;\r
-    else info[i].isInput = true;\r
-  }\r
-\r
-  // Get playback device info and check capabilities.\r
-  result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceInfoCallback, &info[0]);\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Unable to enumerate through sound playback devices: %s.",\r
-            getErrorString(result));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  // Get capture device info and check capabilities.\r
-  result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceInfoCallback, &info[0]);\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Unable to enumerate through sound capture devices: %s.",\r
-            getErrorString(result));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  // Parse the devices and check validity.  Devices are considered\r
-  // invalid if they cannot be opened, they report no supported data\r
-  // formats, or they report < 1 supported channels.\r
-  for (i=0; i<count; i++) {\r
-    if (info[i].isValid && info[i].id == NULL ) // default device\r
-      nDevices++;\r
-  }\r
-\r
-  // We group the default input and output devices together (as one\r
-  // device) .\r
-  if (nDevices > 0) {\r
-    nDevices = 1;\r
-    index = 1;\r
-  }\r
-\r
-  // Non-default devices are listed separately.\r
-  for (i=0; i<count; i++) {\r
-    if (info[i].isValid && info[i].id != NULL )\r
-      nDevices++;\r
-  }\r
-\r
-  if (nDevices == 0) return;\r
-\r
-  //  Allocate the RTAUDIO_DEVICE structures.\r
-  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));\r
-  if (devices == NULL) {\r
-    sprintf(message, "RtAudio: memory allocation error!");\r
-    error(RtError::MEMORY_ERROR);\r
-  }\r
-\r
-  // Initialize the GUIDs to NULL for later validation.\r
-  for (i=0; i<nDevices; i++) {\r
-    devices[i].id[0] = NULL;\r
-    devices[i].id[1] = NULL;\r
-  }\r
-\r
-  // Rename the default device(s).\r
-  if (index)\r
-    strcpy(devices[0].name, "Default Input/Output Devices");\r
-\r
-  // Copy the names and GUIDs to our devices structures.\r
-  for (i=0; i<count; i++) {\r
-    if (info[i].isValid && info[i].id != NULL ) {\r
-      strncpy(devices[index].name, info[i].name, 64);\r
-      if (info[i].isInput)\r
-        devices[index].id[1] = info[i].id;\r
-      else\r
-        devices[index].id[0] = info[i].id;\r
-      index++;\r
-    }\r
-  }\r
-\r
-  for (i=0;i<nDevices; i++)\r
-    probeDeviceInfo(&devices[i]);\r
-\r
-  return;\r
-}\r
-\r
-void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)\r
-{\r
-  HRESULT result;\r
-\r
-  // Get the device index so that we can check the device handle.\r
-  int index;\r
-  for (index=0; index<nDevices; index++)\r
-    if ( info == &devices[index] ) break;\r
-\r
-  if ( index >= nDevices ) {\r
-    sprintf(message, "RtAudio: device (%s) indexing error in DirectSound probeDeviceInfo().",\r
-            info->name);\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  // Do capture probe first.  If this is not the default device (index\r
-  // = 0) _and_ GUID = NULL, then the capture handle is invalid.\r
-  if ( index != 0 && info->id[1] == NULL )\r
-    goto playback_probe;\r
-\r
-  LPDIRECTSOUNDCAPTURE  input;\r
-  result = DirectSoundCaptureCreate( info->id[0], &input, NULL );\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Could not create DirectSound capture object (%s): %s.",\r
-            info->name, getErrorString(result));\r
-    error(RtError::WARNING);\r
-    goto playback_probe;\r
-  }\r
-\r
-  DSCCAPS in_caps;\r
-  in_caps.dwSize = sizeof(in_caps);\r
-  result = input->GetCaps( &in_caps );\r
-  if ( FAILED(result) ) {\r
-    input->Release();\r
-    sprintf(message, "RtAudio: Could not get DirectSound capture capabilities (%s): %s.",\r
-            info->name, getErrorString(result));\r
-    error(RtError::WARNING);\r
-    goto playback_probe;\r
-  }\r
-\r
-  // Get input channel information.\r
-  info->minInputChannels = 1;\r
-  info->maxInputChannels = in_caps.dwChannels;\r
-\r
-  // Get sample rate and format information.\r
-  if( in_caps.dwChannels == 2 ) {\r
-    if( in_caps.dwFormats & WAVE_FORMAT_1S16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_2S16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_4S16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_1S08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_2S08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_4S08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-\r
-    if ( info->nativeFormats & RTAUDIO_SINT16 ) {\r
-      if( in_caps.dwFormats & WAVE_FORMAT_1S16 ) info->sampleRates[info->nSampleRates++] = 11025;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_2S16 ) info->sampleRates[info->nSampleRates++] = 22050;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_4S16 ) info->sampleRates[info->nSampleRates++] = 44100;\r
-    }\r
-    else if ( info->nativeFormats & RTAUDIO_SINT8 ) {\r
-      if( in_caps.dwFormats & WAVE_FORMAT_1S08 ) info->sampleRates[info->nSampleRates++] = 11025;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_2S08 ) info->sampleRates[info->nSampleRates++] = 22050;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_4S08 ) info->sampleRates[info->nSampleRates++] = 44100;\r
-    }\r
-  }\r
-  else if ( in_caps.dwChannels == 1 ) {\r
-    if( in_caps.dwFormats & WAVE_FORMAT_1M16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_2M16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_4M16 ) info->nativeFormats |= RTAUDIO_SINT16;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_1M08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_2M08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-    if( in_caps.dwFormats & WAVE_FORMAT_4M08 ) info->nativeFormats |= RTAUDIO_SINT8;\r
-\r
-    if ( info->nativeFormats & RTAUDIO_SINT16 ) {\r
-      if( in_caps.dwFormats & WAVE_FORMAT_1M16 ) info->sampleRates[info->nSampleRates++] = 11025;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_2M16 ) info->sampleRates[info->nSampleRates++] = 22050;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_4M16 ) info->sampleRates[info->nSampleRates++] = 44100;\r
-    }\r
-    else if ( info->nativeFormats & RTAUDIO_SINT8 ) {\r
-      if( in_caps.dwFormats & WAVE_FORMAT_1M08 ) info->sampleRates[info->nSampleRates++] = 11025;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_2M08 ) info->sampleRates[info->nSampleRates++] = 22050;\r
-      if( in_caps.dwFormats & WAVE_FORMAT_4M08 ) info->sampleRates[info->nSampleRates++] = 44100;\r
-    }\r
-  }\r
-  else info->minInputChannels = 0; // technically, this would be an error\r
-\r
-  input->Release();\r
-\r
- playback_probe:\r
-  LPDIRECTSOUND  output;\r
-  DSCAPS out_caps;\r
-\r
-  // Now do playback probe.  If this is not the default device (index\r
-  // = 0) _and_ GUID = NULL, then the playback handle is invalid.\r
-  if ( index != 0 && info->id[0] == NULL )\r
-    goto check_parameters;\r
-\r
-  result = DirectSoundCreate( info->id[0], &output, NULL );\r
-  if ( FAILED(result) ) {\r
-    sprintf(message, "RtAudio: Could not create DirectSound playback object (%s): %s.",\r
-            info->name, getErrorString(result));\r
-    error(RtError::WARNING);\r
-    goto check_parameters;\r
-  }\r
-\r
-  out_caps.dwSize = sizeof(out_caps);\r
-  result = output->GetCaps( &out_caps );\r
-  if ( FAILED(result) ) {\r
-    output->Release();\r
-    sprintf(message, "RtAudio: Could not get DirectSound playback capabilities (%s): %s.",\r
-            info->name, getErrorString(result));\r
-    error(RtError::WARNING);\r
-    goto check_parameters;\r
-  }\r
-\r
-  // Get output channel information.\r
-  info->minOutputChannels = 1;\r
-  info->maxOutputChannels = ( out_caps.dwFlags & DSCAPS_PRIMARYSTEREO ) ? 2 : 1;\r
-\r
-  // Get sample rate information.  Use capture device rate information\r
-  // if it exists.\r
-  if ( info->nSampleRates == 0 ) {\r
-    info->sampleRates[0] = (int) out_caps.dwMinSecondarySampleRate;\r
-    info->sampleRates[1] = (int) out_caps.dwMaxSecondarySampleRate;\r
-    if ( out_caps.dwFlags & DSCAPS_CONTINUOUSRATE )\r
-      info->nSampleRates = -1;\r
-    else if ( out_caps.dwMinSecondarySampleRate == out_caps.dwMaxSecondarySampleRate ) {\r
-      if ( out_caps.dwMinSecondarySampleRate == 0 ) {\r
-        // This is a bogus driver report ... fake the range and cross\r
-        // your fingers.\r
-        info->sampleRates[0] = 11025;\r
-                               info->sampleRates[1] = 48000;\r
-        info->nSampleRates = -1; /* continuous range */\r
-        sprintf(message, "RtAudio: bogus sample rates reported by DirectSound driver ... using defaults (%s).",\r
-                info->name);\r
-        error(RtError::WARNING);\r
-      }\r
-      else {\r
-        info->nSampleRates = 1;\r
-                       }\r
-    }\r
-    else if ( (out_caps.dwMinSecondarySampleRate < 1000.0) &&\r
-              (out_caps.dwMaxSecondarySampleRate > 50000.0) ) {\r
-      // This is a bogus driver report ... support for only two\r
-      // distant rates.  We'll assume this is a range.\r
-      info->nSampleRates = -1;\r
-      sprintf(message, "RtAudio: bogus sample rates reported by DirectSound driver ... using range (%s).",\r
-              info->name);\r
-      error(RtError::WARNING);\r
-    }\r
-    else info->nSampleRates = 2;\r
-  }\r
-  else {\r
-    // Check input rates against output rate range\r
-    for ( int i=info->nSampleRates-1; i>=0; i-- ) {\r
-      if ( info->sampleRates[i] <= out_caps.dwMaxSecondarySampleRate )\r
-        break;\r
-      info->nSampleRates--;\r
-    }\r
-    while ( info->sampleRates[0] < out_caps.dwMinSecondarySampleRate ) {\r
-      info->nSampleRates--;\r
-      for ( int i=0; i<info->nSampleRates; i++)\r
-        info->sampleRates[i] = info->sampleRates[i+1];\r
-      if ( info->nSampleRates <= 0 ) break;\r
-    }\r
-  }\r
-\r
-  // Get format information.\r
-  if ( out_caps.dwFlags & DSCAPS_PRIMARY16BIT ) info->nativeFormats |= RTAUDIO_SINT16;\r
-  if ( out_caps.dwFlags & DSCAPS_PRIMARY8BIT ) info->nativeFormats |= RTAUDIO_SINT8;\r
-\r
-  output->Release();\r
-\r
- check_parameters:\r
-  if ( info->maxInputChannels == 0 && info->maxOutputChannels == 0 )\r
-    return;\r
-  if ( info->nSampleRates == 0 || info->nativeFormats == 0 )\r
-    return;\r
-\r
-  // Determine duplex status.\r
-  if (info->maxInputChannels < info->maxOutputChannels)\r
-    info->maxDuplexChannels = info->maxInputChannels;\r
-  else\r
-    info->maxDuplexChannels = info->maxOutputChannels;\r
-  if (info->minInputChannels < info->minOutputChannels)\r
-    info->minDuplexChannels = info->minInputChannels;\r
-  else\r
-    info->minDuplexChannels = info->minOutputChannels;\r
-\r
-  if ( info->maxDuplexChannels > 0 ) info->hasDuplexSupport = true;\r
-  else info->hasDuplexSupport = false;\r
-\r
-  info->probed = true;\r
-\r
-  return;\r
-}\r
-\r
-bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,\r
-                                STREAM_MODE mode, int channels, \r
-                                int sampleRate, RTAUDIO_FORMAT format,\r
-                                int *bufferSize, int numberOfBuffers)\r
-{\r
-  HRESULT result;\r
-  HWND hWnd = GetForegroundWindow();\r
-  // According to a note in PortAudio, using GetDesktopWindow()\r
-  // instead of GetForegroundWindow() is supposed to avoid problems\r
-  // that occur when the application's window is not the foreground\r
-  // window.  Also, if the application window closes before the\r
-  // DirectSound buffer, DirectSound can crash.  However, for console\r
-  // applications, no sound was produced when using GetDesktopWindow().\r
-  long buffer_size;\r
-  LPVOID audioPtr;\r
-  DWORD dataLen;\r
-  int nBuffers;\r
-\r
-  // Check the numberOfBuffers parameter and limit the lowest value to\r
-  // two.  This is a judgement call and a value of two is probably too\r
-  // low for capture, but it should work for playback.\r
-  if (numberOfBuffers < 2)\r
-    nBuffers = 2;\r
-  else\r
-    nBuffers = numberOfBuffers;\r
-\r
-  // Define the wave format structure (16-bit PCM, srate, channels)\r
-  WAVEFORMATEX waveFormat;\r
-  ZeroMemory(&waveFormat, sizeof(WAVEFORMATEX));\r
-  waveFormat.wFormatTag = WAVE_FORMAT_PCM;\r
-  waveFormat.nChannels = channels;\r
-  waveFormat.nSamplesPerSec = (unsigned long) sampleRate;\r
-\r
-  // Determine the data format.\r
-  if ( devices[device].nativeFormats ) { // 8-bit and/or 16-bit support\r
-    if ( format == RTAUDIO_SINT8 ) {\r
-      if ( devices[device].nativeFormats & RTAUDIO_SINT8 )\r
-        waveFormat.wBitsPerSample = 8;\r
-      else\r
-        waveFormat.wBitsPerSample = 16;\r
-    }\r
-    else {\r
-      if ( devices[device].nativeFormats & RTAUDIO_SINT16 )\r
-        waveFormat.wBitsPerSample = 16;\r
-      else\r
-        waveFormat.wBitsPerSample = 8;\r
-    }\r
-  }\r
-  else {\r
-    sprintf(message, "RtAudio: no reported data formats for DirectSound device (%s).",\r
-            devices[device].name);\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;\r
-  waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;\r
-\r
-  if ( mode == PLAYBACK ) {\r
-\r
-    if ( devices[device].maxOutputChannels < channels )\r
-      return FAILURE;\r
-\r
-    LPGUID id = devices[device].id[0];\r
-    LPDIRECTSOUND  object;\r
-    LPDIRECTSOUNDBUFFER buffer;\r
-    DSBUFFERDESC bufferDescription;\r
-    \r
-    result = DirectSoundCreate( id, &object, NULL );\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Could not create DirectSound playback object (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Set cooperative level to DSSCL_EXCLUSIVE\r
-    result = object->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to set DirectSound cooperative level (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Even though we will write to the secondary buffer, we need to\r
-    // access the primary buffer to set the correct output format.\r
-    // The default is 8-bit, 22 kHz!\r
-    // Setup the DS primary buffer description.\r
-    ZeroMemory(&bufferDescription, sizeof(DSBUFFERDESC));\r
-    bufferDescription.dwSize = sizeof(DSBUFFERDESC);\r
-    bufferDescription.dwFlags = DSBCAPS_PRIMARYBUFFER;\r
-    // Obtain the primary buffer\r
-    result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to access DS primary buffer (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Set the primary DS buffer sound format.\r
-    result = buffer->SetFormat(&waveFormat);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to set DS primary buffer format (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Setup the secondary DS buffer description.\r
-    buffer_size = channels * *bufferSize * nBuffers * waveFormat.wBitsPerSample / 8;\r
-    ZeroMemory(&bufferDescription, sizeof(DSBUFFERDESC));\r
-    bufferDescription.dwSize = sizeof(DSBUFFERDESC);\r
-    bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS |\r
-                                  DSBCAPS_GETCURRENTPOSITION2 |\r
-                                  DSBCAPS_LOCHARDWARE );  // Force hardware mixing\r
-    bufferDescription.dwBufferBytes = buffer_size;\r
-    bufferDescription.lpwfxFormat = &waveFormat;\r
-\r
-    // Try to create the secondary DS buffer.  If that doesn't work,\r
-    // try to use software mixing.  Otherwise, there's a problem.\r
-    result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);\r
-    if ( FAILED(result) ) {\r
-      bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS |\r
-                                    DSBCAPS_GETCURRENTPOSITION2 |\r
-                                    DSBCAPS_LOCSOFTWARE );  // Force software mixing\r
-      result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);\r
-      if ( FAILED(result) ) {\r
-        object->Release();\r
-        sprintf(message, "RtAudio: Unable to create secondary DS buffer (%s): %s.",\r
-                devices[device].name, getErrorString(result));\r
-        error(RtError::WARNING);\r
-        return FAILURE;\r
-      }\r
-    }\r
-\r
-    // Get the buffer size ... might be different from what we specified.\r
-    DSBCAPS dsbcaps;\r
-    dsbcaps.dwSize = sizeof(DSBCAPS);\r
-    buffer->GetCaps(&dsbcaps);\r
-    buffer_size = dsbcaps.dwBufferBytes;\r
-\r
-    // Lock the DS buffer\r
-    result = buffer->Lock(0, buffer_size, &audioPtr, &dataLen, NULL, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to lock DS buffer (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Zero the DS buffer\r
-    ZeroMemory(audioPtr, dataLen);\r
-\r
-    // Unlock the DS buffer\r
-    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to unlock DS buffer(%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    stream->handle[0].object = (void *) object;\r
-    stream->handle[0].buffer = (void *) buffer;\r
-    stream->nDeviceChannels[0] = channels;\r
-  }\r
-\r
-  if ( mode == RECORD ) {\r
-\r
-    if ( devices[device].maxInputChannels < channels )\r
-      return FAILURE;\r
-\r
-    LPGUID id = devices[device].id[1];\r
-    LPDIRECTSOUNDCAPTURE  object;\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer;\r
-    DSCBUFFERDESC bufferDescription;\r
-\r
-    result = DirectSoundCaptureCreate( id, &object, NULL );\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Could not create DirectSound capture object (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Setup the secondary DS buffer description.\r
-    buffer_size = channels * *bufferSize * nBuffers * waveFormat.wBitsPerSample / 8;\r
-    ZeroMemory(&bufferDescription, sizeof(DSCBUFFERDESC));\r
-    bufferDescription.dwSize = sizeof(DSCBUFFERDESC);\r
-    bufferDescription.dwFlags = 0;\r
-    bufferDescription.dwReserved = 0;\r
-    bufferDescription.dwBufferBytes = buffer_size;\r
-    bufferDescription.lpwfxFormat = &waveFormat;\r
-\r
-    // Create the capture buffer.\r
-    result = object->CreateCaptureBuffer(&bufferDescription, &buffer, NULL);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to create DS capture buffer (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Lock the capture buffer\r
-    result = buffer->Lock(0, buffer_size, &audioPtr, &dataLen, NULL, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Zero the buffer\r
-    ZeroMemory(audioPtr, dataLen);\r
-\r
-    // Unlock the buffer\r
-    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      object->Release();\r
-      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",\r
-              devices[device].name, getErrorString(result));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    stream->handle[1].object = (void *) object;\r
-    stream->handle[1].buffer = (void *) buffer;\r
-    stream->nDeviceChannels[1] = channels;\r
-  }\r
-\r
-  stream->userFormat = format;\r
-  if ( waveFormat.wBitsPerSample == 8 )\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT8;\r
-  else\r
-    stream->deviceFormat[mode] = RTAUDIO_SINT16;\r
-  stream->nUserChannels[mode] = channels;\r
-  *bufferSize = buffer_size / (channels * nBuffers * waveFormat.wBitsPerSample / 8);\r
-  stream->bufferSize = *bufferSize;\r
-\r
-  // Set flags for buffer conversion\r
-  stream->doConvertBuffer[mode] = false;\r
-  if (stream->userFormat != stream->deviceFormat[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-\r
-  // Allocate necessary internal buffers\r
-  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {\r
-\r
-    long buffer_bytes;\r
-    if (stream->nUserChannels[0] >= stream->nUserChannels[1])\r
-      buffer_bytes = stream->nUserChannels[0];\r
-    else\r
-      buffer_bytes = stream->nUserChannels[1];\r
-\r
-    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);\r
-    if (stream->userBuffer) free(stream->userBuffer);\r
-    stream->userBuffer = (char *) calloc(buffer_bytes, 1);\r
-    if (stream->userBuffer == NULL)\r
-      goto memory_error;\r
-  }\r
-\r
-  if ( stream->doConvertBuffer[mode] ) {\r
-\r
-    long buffer_bytes;\r
-    bool makeBuffer = true;\r
-    if ( mode == PLAYBACK )\r
-      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-    else { // mode == RECORD\r
-      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);\r
-      if ( stream->mode == PLAYBACK ) {\r
-        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-        if ( buffer_bytes > bytes_out )\r
-          buffer_bytes = (buffer_bytes > bytes_out) ? buffer_bytes : bytes_out;\r
-        else\r
-          makeBuffer = false;\r
-      }\r
-    }\r
-\r
-    if ( makeBuffer ) {\r
-      buffer_bytes *= *bufferSize;\r
-      if (stream->deviceBuffer) free(stream->deviceBuffer);\r
-      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);\r
-      if (stream->deviceBuffer == NULL)\r
-        goto memory_error;\r
-    }\r
-  }\r
-\r
-  stream->device[mode] = device;\r
-  stream->state = STREAM_STOPPED;\r
-  if ( stream->mode == PLAYBACK && mode == RECORD )\r
-    // We had already set up an output stream.\r
-    stream->mode = DUPLEX;\r
-  else\r
-    stream->mode = mode;\r
-  stream->nBuffers = nBuffers;\r
-  stream->sampleRate = sampleRate;\r
-\r
-  return SUCCESS;\r
-\r
- memory_error:\r
-  if (stream->handle[0].object) {\r
-    LPDIRECTSOUND object = (LPDIRECTSOUND) stream->handle[0].object;\r
-    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    if (buffer) {\r
-      buffer->Release();\r
-      stream->handle[0].buffer = NULL;\r
-    }\r
-    object->Release();\r
-    stream->handle[0].object = NULL;\r
-  }\r
-  if (stream->handle[1].object) {\r
-    LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) stream->handle[1].object;\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    if (buffer) {\r
-      buffer->Release();\r
-      stream->handle[1].buffer = NULL;\r
-    }\r
-    object->Release();\r
-    stream->handle[1].object = NULL;\r
-  }\r
-  if (stream->userBuffer) {\r
-    free(stream->userBuffer);\r
-    stream->userBuffer = 0;\r
-  }\r
-  sprintf(message, "RtAudio: error allocating buffer memory (%s).",\r
-          devices[device].name);\r
-  error(RtError::WARNING);\r
-  return FAILURE;\r
-}\r
-\r
-void RtAudio :: cancelStreamCallback(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  if (stream->usingCallback) {\r
-    stream->usingCallback = false;\r
-    WaitForSingleObject( (HANDLE)stream->thread, INFINITE );\r
-    CloseHandle( (HANDLE)stream->thread );\r
-    stream->thread = 0;\r
-    stream->callback = NULL;\r
-    stream->userData = NULL;\r
-  }\r
-}\r
-\r
-void RtAudio :: closeStream(int streamId)\r
-{\r
-  // We don't want an exception to be thrown here because this\r
-  // function is called by our class destructor.  So, do our own\r
-  // streamId check.\r
-  if ( streams.find( streamId ) == streams.end() ) {\r
-    sprintf(message, "RtAudio: invalid stream identifier!");\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];\r
-\r
-  if (stream->usingCallback) {\r
-    stream->usingCallback = false;\r
-    WaitForSingleObject( (HANDLE)stream->thread, INFINITE );\r
-    CloseHandle( (HANDLE)stream->thread );\r
-  }\r
-\r
-  DeleteCriticalSection(&stream->mutex);\r
-\r
-  if (stream->handle[0].object) {\r
-    LPDIRECTSOUND object = (LPDIRECTSOUND) stream->handle[0].object;\r
-    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    if (buffer) {\r
-      buffer->Stop();\r
-      buffer->Release();\r
-    }\r
-    object->Release();\r
-  }\r
-\r
-  if (stream->handle[1].object) {\r
-    LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) stream->handle[1].object;\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    if (buffer) {\r
-      buffer->Stop();\r
-      buffer->Release();\r
-    }\r
-    object->Release();\r
-  }\r
-\r
-  if (stream->userBuffer)\r
-    free(stream->userBuffer);\r
-\r
-  if (stream->deviceBuffer)\r
-    free(stream->deviceBuffer);\r
-\r
-  free(stream);\r
-  streams.erase(streamId);\r
-}\r
-\r
-void RtAudio :: startStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_RUNNING)\r
-    goto unlock;\r
-\r
-  HRESULT result;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    result = buffer->Play(0, 0, DSBPLAY_LOOPING );\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to start DS buffer (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    result = buffer->Start(DSCBSTART_LOOPING );\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to start DS capture buffer (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_RUNNING;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: stopStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED) {\r
-    MUTEX_UNLOCK(&stream->mutex);\r
-    return;\r
-  }\r
-\r
-  // There is no specific DirectSound API call to "drain" a buffer\r
-  // before stopping.  We can hack this for playback by writing zeroes\r
-  // for another bufferSize * nBuffers frames.  For capture, the\r
-  // concept is less clear so we'll repeat what we do in the\r
-  // abortStream() case.\r
-  HRESULT result;\r
-  DWORD dsBufferSize;\r
-  LPVOID buffer1 = NULL;\r
-  LPVOID buffer2 = NULL;\r
-  DWORD bufferSize1 = 0;\r
-  DWORD bufferSize2 = 0;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    DWORD currentPos, safePos;\r
-    long buffer_bytes = stream->bufferSize * stream->nDeviceChannels[0];\r
-    buffer_bytes *= formatBytes(stream->deviceFormat[0]);\r
-\r
-    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    UINT nextWritePos = stream->handle[0].bufferPointer;\r
-    dsBufferSize = buffer_bytes * stream->nBuffers;\r
-\r
-    // Write zeroes for nBuffer counts.\r
-    for (int i=0; i<stream->nBuffers; i++) {\r
-\r
-      // Find out where the read and "safe write" pointers are.\r
-      result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);\r
-      if ( FAILED(result) ) {\r
-        sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",\r
-                devices[stream->device[0]].name, getErrorString(result));\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-\r
-      if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset\r
-      DWORD endWrite = nextWritePos + buffer_bytes;\r
-\r
-      // Check whether the entire write region is behind the play pointer.\r
-      while ( currentPos < endWrite ) {\r
-        float millis = (endWrite - currentPos) * 900.0;\r
-        millis /= ( formatBytes(stream->deviceFormat[0]) * stream->sampleRate);\r
-        if ( millis < 1.0 ) millis = 1.0;\r
-        Sleep( (DWORD) millis );\r
-\r
-        // Wake up, find out where we are now\r
-        result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );\r
-        if ( FAILED(result) ) {\r
-          sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",\r
-                  devices[stream->device[0]].name, getErrorString(result));\r
-          error(RtError::DRIVER_ERROR);\r
-        }\r
-        if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset\r
-      }\r
-\r
-      // Lock free space in the buffer\r
-      result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,\r
-                               &bufferSize1, &buffer2, &bufferSize2, 0);\r
-      if ( FAILED(result) ) {\r
-        sprintf(message, "RtAudio: Unable to lock DS buffer during playback (%s): %s.",\r
-                devices[stream->device[0]].name, getErrorString(result));\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-\r
-      // Zero the free space\r
-      ZeroMemory(buffer1, bufferSize1);\r
-      if (buffer2 != NULL) ZeroMemory(buffer2, bufferSize2);\r
-\r
-      // Update our buffer offset and unlock sound buffer\r
-      dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);\r
-      if ( FAILED(result) ) {\r
-        sprintf(message, "RtAudio: Unable to unlock DS buffer during playback (%s): %s.",\r
-                devices[stream->device[0]].name, getErrorString(result));\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-      nextWritePos = (nextWritePos + bufferSize1 + bufferSize2) % dsBufferSize;\r
-      stream->handle[0].bufferPointer = nextWritePos;\r
-    }\r
-\r
-    // If we play again, start at the beginning of the buffer.\r
-    stream->handle[0].bufferPointer = 0;\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    buffer1 = NULL;\r
-    bufferSize1 = 0;\r
-\r
-    result = buffer->Stop();\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to stop DS capture buffer (%s): %s",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[1];\r
-    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;\r
-\r
-    // Lock the buffer and clear it so that if we start to play again,\r
-    // we won't have old data playing.\r
-    result = buffer->Lock(0, dsBufferSize, &buffer1, &bufferSize1, NULL, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Zero the DS buffer\r
-    ZeroMemory(buffer1, bufferSize1);\r
-\r
-    // Unlock the DS buffer\r
-    result = buffer->Unlock(buffer1, bufferSize1, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // If we start recording again, we must begin at beginning of buffer.\r
-    stream->handle[1].bufferPointer = 0;\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: abortStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  HRESULT result;\r
-  long dsBufferSize;\r
-  LPVOID audioPtr;\r
-  DWORD dataLen;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    result = buffer->Stop();\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to stop DS buffer (%s): %s",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[0];\r
-    dsBufferSize *= formatBytes(stream->deviceFormat[0]) * stream->nBuffers;\r
-\r
-    // Lock the buffer and clear it so that if we start to play again,\r
-    // we won't have old data playing.\r
-    result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to lock DS buffer (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Zero the DS buffer\r
-    ZeroMemory(audioPtr, dataLen);\r
-\r
-    // Unlock the DS buffer\r
-    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to unlock DS buffer (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // If we start playing again, we must begin at beginning of buffer.\r
-    stream->handle[0].bufferPointer = 0;\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    audioPtr = NULL;\r
-    dataLen = 0;\r
-\r
-    result = buffer->Stop();\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to stop DS capture buffer (%s): %s",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[1];\r
-    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;\r
-\r
-    // Lock the buffer and clear it so that if we start to play again,\r
-    // we won't have old data playing.\r
-    result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Zero the DS buffer\r
-    ZeroMemory(audioPtr, dataLen);\r
-\r
-    // Unlock the DS buffer\r
-    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // If we start recording again, we must begin at beginning of buffer.\r
-    stream->handle[1].bufferPointer = 0;\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-int RtAudio :: streamWillBlock(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  int channels;\r
-  int frames = 0;\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  HRESULT result;\r
-  DWORD currentPos, safePos;\r
-  channels = 1;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    UINT nextWritePos = stream->handle[0].bufferPointer;\r
-    channels = stream->nDeviceChannels[0];\r
-    DWORD dsBufferSize = stream->bufferSize * channels;\r
-    dsBufferSize *= formatBytes(stream->deviceFormat[0]) * stream->nBuffers;\r
-\r
-    // Find out where the read and "safe write" pointers are.\r
-    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset\r
-    frames = currentPos - nextWritePos;\r
-    frames /= channels * formatBytes(stream->deviceFormat[0]);\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-\r
-    LPDIRECTSOUNDCAPTUREBUFFER dsBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    UINT nextReadPos = stream->handle[1].bufferPointer;\r
-    channels = stream->nDeviceChannels[1];\r
-    DWORD dsBufferSize = stream->bufferSize * channels;\r
-    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;\r
-\r
-    // Find out where the write and "safe read" pointers are.\r
-    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset\r
-\r
-    if (stream->mode == DUPLEX ) {\r
-      // Take largest value of the two.\r
-      int temp = safePos - nextReadPos;\r
-      temp /= channels * formatBytes(stream->deviceFormat[1]);\r
-      frames = ( temp > frames ) ? temp : frames;\r
-    }\r
-    else {\r
-      frames = safePos - nextReadPos;\r
-      frames /= channels * formatBytes(stream->deviceFormat[1]);\r
-    }\r
-  }\r
-\r
-  frames = stream->bufferSize - frames;\r
-  if (frames < 0) frames = 0;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-  return frames;\r
-}\r
-\r
-void RtAudio :: tickStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  int stopStream = 0;\r
-  if (stream->state == STREAM_STOPPED) {\r
-    if (stream->usingCallback) Sleep(50); // sleep 50 milliseconds\r
-    return;\r
-  }\r
-  else if (stream->usingCallback) {\r
-    stopStream = stream->callback(stream->userBuffer, stream->bufferSize, stream->userData);    \r
-  }\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  // The state might change while waiting on a mutex.\r
-  if (stream->state == STREAM_STOPPED) {\r
-    MUTEX_UNLOCK(&stream->mutex);\r
-    if (stream->usingCallback && stopStream)\r
-      this->stopStream(streamId);\r
-  }\r
-\r
-  HRESULT result;\r
-  DWORD currentPos, safePos;\r
-  LPVOID buffer1 = NULL;\r
-  LPVOID buffer2 = NULL;\r
-  DWORD bufferSize1 = 0;\r
-  DWORD bufferSize2 = 0;\r
-  char *buffer;\r
-  long buffer_bytes;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters and do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[0]) {\r
-      convertStreamBuffer(stream, PLAYBACK);\r
-      buffer = stream->deviceBuffer;\r
-      buffer_bytes = stream->bufferSize * stream->nDeviceChannels[0];\r
-      buffer_bytes *= formatBytes(stream->deviceFormat[0]);\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      buffer_bytes = stream->bufferSize * stream->nUserChannels[0];\r
-      buffer_bytes *= formatBytes(stream->userFormat);\r
-    }\r
-\r
-    // No byte swapping necessary in DirectSound implementation.\r
-\r
-    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;\r
-    UINT nextWritePos = stream->handle[0].bufferPointer;\r
-    DWORD dsBufferSize = buffer_bytes * stream->nBuffers;\r
-\r
-    // Find out where the read and "safe write" pointers are.\r
-    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset\r
-    DWORD endWrite = nextWritePos + buffer_bytes;\r
-\r
-    // Check whether the entire write region is behind the play pointer.\r
-    while ( currentPos < endWrite ) {\r
-      // If we are here, then we must wait until the play pointer gets\r
-      // beyond the write region.  The approach here is to use the\r
-      // Sleep() function to suspend operation until safePos catches\r
-      // up. Calculate number of milliseconds to wait as:\r
-      //   time = distance * (milliseconds/second) * fudgefactor /\r
-      //          ((bytes/sample) * (samples/second))\r
-      // A "fudgefactor" less than 1 is used because it was found\r
-      // that sleeping too long was MUCH worse than sleeping for\r
-      // several shorter periods.\r
-      float millis = (endWrite - currentPos) * 900.0;\r
-      millis /= ( formatBytes(stream->deviceFormat[0]) * stream->sampleRate);\r
-      if ( millis < 1.0 ) millis = 1.0;\r
-      Sleep( (DWORD) millis );\r
-\r
-      // Wake up, find out where we are now\r
-      result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );\r
-      if ( FAILED(result) ) {\r
-        sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-      if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset\r
-    }\r
-\r
-    // Lock free space in the buffer\r
-    result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,\r
-                             &bufferSize1, &buffer2, &bufferSize2, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to lock DS buffer during playback (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Copy our buffer into the DS buffer\r
-    CopyMemory(buffer1, buffer, bufferSize1);\r
-    if (buffer2 != NULL) CopyMemory(buffer2, buffer+bufferSize1, bufferSize2);\r
-\r
-    // Update our buffer offset and unlock sound buffer\r
-    dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to unlock DS buffer during playback (%s): %s.",\r
-              devices[stream->device[0]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    nextWritePos = (nextWritePos + bufferSize1 + bufferSize2) % dsBufferSize;\r
-    stream->handle[0].bufferPointer = nextWritePos;\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters.\r
-    if (stream->doConvertBuffer[1]) {\r
-      buffer = stream->deviceBuffer;\r
-      buffer_bytes = stream->bufferSize * stream->nDeviceChannels[1];\r
-      buffer_bytes *= formatBytes(stream->deviceFormat[1]);\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      buffer_bytes = stream->bufferSize * stream->nUserChannels[1];\r
-      buffer_bytes *= formatBytes(stream->userFormat);\r
-    }\r
-\r
-    LPDIRECTSOUNDCAPTUREBUFFER dsBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;\r
-    UINT nextReadPos = stream->handle[1].bufferPointer;\r
-    DWORD dsBufferSize = buffer_bytes * stream->nBuffers;\r
-\r
-    // Find out where the write and "safe read" pointers are.\r
-    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset\r
-    DWORD endRead = nextReadPos + buffer_bytes;\r
-\r
-    // Check whether the entire write region is behind the play pointer.\r
-    while ( safePos < endRead ) {\r
-      // See comments for playback.\r
-      float millis = (endRead - safePos) * 900.0;\r
-      millis /= ( formatBytes(stream->deviceFormat[1]) * stream->sampleRate);\r
-      if ( millis < 1.0 ) millis = 1.0;\r
-      Sleep( (DWORD) millis );\r
-\r
-      // Wake up, find out where we are now\r
-      result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );\r
-      if ( FAILED(result) ) {\r
-        sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",\r
-                devices[stream->device[1]].name, getErrorString(result));\r
-        error(RtError::DRIVER_ERROR);\r
-      }\r
-      \r
-      if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset\r
-    }\r
-\r
-    // Lock free space in the buffer\r
-    result = dsBuffer->Lock (nextReadPos, buffer_bytes, &buffer1,\r
-                             &bufferSize1, &buffer2, &bufferSize2, 0);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to lock DS buffer during capture (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-\r
-    // Copy our buffer into the DS buffer\r
-    CopyMemory(buffer, buffer1, bufferSize1);\r
-    if (buffer2 != NULL) CopyMemory(buffer+bufferSize1, buffer2, bufferSize2);\r
-\r
-    // Update our buffer offset and unlock sound buffer\r
-    nextReadPos = (nextReadPos + bufferSize1 + bufferSize2) % dsBufferSize;\r
-    dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);\r
-    if ( FAILED(result) ) {\r
-      sprintf(message, "RtAudio: Unable to unlock DS buffer during capture (%s): %s.",\r
-              devices[stream->device[1]].name, getErrorString(result));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    stream->handle[1].bufferPointer = nextReadPos;\r
-\r
-    // No byte swapping necessary in DirectSound implementation.\r
-\r
-    // Do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[1])\r
-      convertStreamBuffer(stream, RECORD);\r
-  }\r
-\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-\r
-  if (stream->usingCallback && stopStream)\r
-    this->stopStream(streamId);\r
-}\r
-\r
-// Definitions for utility functions and callbacks\r
-// specific to the DirectSound implementation.\r
-\r
-extern "C" unsigned __stdcall callbackHandler(void *ptr)\r
-{\r
-  RtAudio *object = thread_info.object;\r
-  int stream = thread_info.streamId;\r
-  bool *usingCallback = (bool *) ptr;\r
-\r
-  while ( *usingCallback ) {\r
-    try {\r
-      object->tickStream(stream);\r
-    }\r
-    catch (RtError &exception) {\r
-      fprintf(stderr, "\nCallback thread error (%s) ... closing thread.\n\n",\r
-              exception.getMessage());\r
-      break;\r
-    }\r
-  }\r
-\r
-  _endthreadex( 0 );\r
-  return 0;\r
-}\r
-\r
-static bool CALLBACK deviceCountCallback(LPGUID lpguid,\r
-                                         LPCSTR lpcstrDescription,\r
-                                         LPCSTR lpcstrModule,\r
-                                         LPVOID lpContext)\r
-{\r
-  int *pointer = ((int *) lpContext);\r
-  (*pointer)++;\r
-\r
-  return true;\r
-}\r
-\r
-static bool CALLBACK deviceInfoCallback(LPGUID lpguid,\r
-                                        LPCSTR lpcstrDescription,\r
-                                        LPCSTR lpcstrModule,\r
-                                        LPVOID lpContext)\r
-{\r
-  enum_info *info = ((enum_info *) lpContext);\r
-  while (strlen(info->name) > 0) info++;\r
-\r
-  strncpy(info->name, lpcstrDescription, 64);\r
-  info->id = lpguid;\r
-\r
-       HRESULT    hr;\r
-  info->isValid = false;\r
-  if (info->isInput == true) {\r
-    DSCCAPS               caps;\r
-    LPDIRECTSOUNDCAPTURE  object;\r
-\r
-    hr = DirectSoundCaptureCreate(  lpguid, &object,   NULL );\r
-    if( hr != DS_OK ) return true;\r
-\r
-    caps.dwSize = sizeof(caps);\r
-    hr = object->GetCaps( &caps );\r
-    if( hr == DS_OK ) {\r
-      if (caps.dwChannels > 0 && caps.dwFormats > 0)\r
-        info->isValid = true;\r
-    }\r
-    object->Release();\r
-  }\r
-  else {\r
-    DSCAPS         caps;\r
-    LPDIRECTSOUND  object;\r
-    hr = DirectSoundCreate(  lpguid, &object,   NULL );\r
-    if( hr != DS_OK ) return true;\r
-\r
-    caps.dwSize = sizeof(caps);\r
-    hr = object->GetCaps( &caps );\r
-    if( hr == DS_OK ) {\r
-      if ( caps.dwFlags & DSCAPS_PRIMARYMONO || caps.dwFlags & DSCAPS_PRIMARYSTEREO )\r
-        info->isValid = true;\r
-    }\r
-    object->Release();\r
-  }\r
-\r
-  return true;\r
-}\r
-\r
-static char* getErrorString(int code)\r
-{\r
-       switch (code) {\r
-\r
-  case DSERR_ALLOCATED:\r
-    return "Direct Sound already allocated";\r
-\r
-  case DSERR_CONTROLUNAVAIL:\r
-    return "Direct Sound control unavailable";\r
-\r
-  case DSERR_INVALIDPARAM:\r
-    return "Direct Sound invalid parameter";\r
-\r
-  case DSERR_INVALIDCALL:\r
-    return "Direct Sound invalid call";\r
-\r
-  case DSERR_GENERIC:\r
-    return "Direct Sound generic error";\r
-\r
-  case DSERR_PRIOLEVELNEEDED:\r
-    return "Direct Sound Priority level needed";\r
-\r
-  case DSERR_OUTOFMEMORY:\r
-    return "Direct Sound out of memory";\r
-\r
-  case DSERR_BADFORMAT:\r
-    return "Direct Sound bad format";\r
-\r
-  case DSERR_UNSUPPORTED:\r
-    return "Direct Sound unsupported error";\r
-\r
-  case DSERR_NODRIVER:\r
-    return "Direct Sound no driver error";\r
-\r
-  case DSERR_ALREADYINITIALIZED:\r
-    return "Direct Sound already initialized";\r
-\r
-  case DSERR_NOAGGREGATION:\r
-    return "Direct Sound no aggregation";\r
-\r
-  case DSERR_BUFFERLOST:\r
-    return "Direct Sound buffer lost";\r
-\r
-  case DSERR_OTHERAPPHASPRIO:\r
-    return "Direct Sound other app has priority";\r
-\r
-  case DSERR_UNINITIALIZED:\r
-    return "Direct Sound uninitialized";\r
-\r
-  default:\r
-    return "Direct Sound unknown error";\r
-       }\r
-}\r
-\r
-//******************** End of __WINDOWS_DS__ *********************//\r
-\r
-#elif defined(__IRIX_AL__) // SGI's AL API for IRIX\r
-\r
-#include <unistd.h>\r
-#include <errno.h>\r
-\r
-void RtAudio :: initialize(void)\r
-{\r
-\r
-  // Count cards and devices\r
-  nDevices = 0;\r
-\r
-  // Determine the total number of input and output devices.\r
-  nDevices = alQueryValues(AL_SYSTEM, AL_DEVICES, 0, 0, 0, 0);\r
-  if (nDevices < 0) {\r
-    sprintf(message, "RtAudio: AL error counting devices: %s.",\r
-            alGetErrorString(oserror()));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  if (nDevices <= 0) return;\r
-\r
-  ALvalue *vls = (ALvalue *) new ALvalue[nDevices];\r
-\r
-  // Add one for our default input/output devices.\r
-  nDevices++;\r
-\r
-  //  Allocate the RTAUDIO_DEVICE structures.\r
-  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));\r
-  if (devices == NULL) {\r
-    sprintf(message, "RtAudio: memory allocation error!");\r
-    error(RtError::MEMORY_ERROR);\r
-  }\r
-\r
-  // Write device ascii identifiers to device info structure.\r
-  char name[32];\r
-  int outs, ins, i;\r
-  ALpv pvs[1];\r
-  pvs[0].param = AL_NAME;\r
-  pvs[0].value.ptr = name;\r
-  pvs[0].sizeIn = 32;\r
-\r
-  strcpy(devices[0].name, "Default Input/Output Devices");\r
-\r
-  outs = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, vls, nDevices-1, 0, 0);\r
-  if (outs < 0) {\r
-    sprintf(message, "RtAudio: AL error getting output devices: %s.",\r
-            alGetErrorString(oserror()));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  for (i=0; i<outs; i++) {\r
-    if (alGetParams(vls[i].i, pvs, 1) < 0) {\r
-      sprintf(message, "RtAudio: AL error querying output devices: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    strncpy(devices[i+1].name, name, 32);\r
-    devices[i+1].id[0] = vls[i].i;\r
-  }\r
-\r
-  ins = alQueryValues(AL_SYSTEM, AL_DEFAULT_INPUT, &vls[outs], nDevices-outs-1, 0, 0);\r
-  if (ins < 0) {\r
-    sprintf(message, "RtAudio: AL error getting input devices: %s.",\r
-            alGetErrorString(oserror()));\r
-    error(RtError::DRIVER_ERROR);\r
-  }\r
-\r
-  for (i=outs; i<ins+outs; i++) {\r
-    if (alGetParams(vls[i].i, pvs, 1) < 0) {\r
-      sprintf(message, "RtAudio: AL error querying input devices: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    strncpy(devices[i+1].name, name, 32);\r
-    devices[i+1].id[1] = vls[i].i;\r
-  }\r
-\r
-  delete [] vls;\r
-\r
-  return;\r
-}\r
-\r
-void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)\r
-{\r
-  int resource, result, i;\r
-  ALvalue value;\r
-  ALparamInfo pinfo;\r
-\r
-  // Get output resource ID if it exists.\r
-  if ( !strncmp(info->name, "Default Input/Output Devices", 28) ) {\r
-    result = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, &value, 1, 0, 0);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting default output device id: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else\r
-      resource = value.i;\r
-  }\r
-  else\r
-    resource = info->id[0];\r
-\r
-  if (resource > 0) {\r
-\r
-    // Probe output device parameters.\r
-    result = alQueryValues(resource, AL_CHANNELS, &value, 1, 0, 0);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting device (%s) channels: %s.",\r
-              info->name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else {\r
-      info->maxOutputChannels = value.i;\r
-      info->minOutputChannels = 1;\r
-    }\r
-\r
-    result = alGetParamInfo(resource, AL_RATE, &pinfo);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting device (%s) rates: %s.",\r
-              info->name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else {\r
-      info->nSampleRates = 0;\r
-      for (i=0; i<MAX_SAMPLE_RATES; i++) {\r
-        if ( SAMPLE_RATES[i] >= pinfo.min.i && SAMPLE_RATES[i] <= pinfo.max.i ) {\r
-          info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];\r
-          info->nSampleRates++;\r
-        }\r
-      }\r
-    }\r
-\r
-    // The AL library supports all our formats, except 24-bit and 32-bit ints.\r
-    info->nativeFormats = (RTAUDIO_FORMAT) 51;\r
-  }\r
-\r
-  // Now get input resource ID if it exists.\r
-  if ( !strncmp(info->name, "Default Input/Output Devices", 28) ) {\r
-    result = alQueryValues(AL_SYSTEM, AL_DEFAULT_INPUT, &value, 1, 0, 0);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting default input device id: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else\r
-      resource = value.i;\r
-  }\r
-  else\r
-    resource = info->id[1];\r
-\r
-  if (resource > 0) {\r
-\r
-    // Probe input device parameters.\r
-    result = alQueryValues(resource, AL_CHANNELS, &value, 1, 0, 0);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting device (%s) channels: %s.",\r
-              info->name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else {\r
-      info->maxInputChannels = value.i;\r
-      info->minInputChannels = 1;\r
-    }\r
-\r
-    result = alGetParamInfo(resource, AL_RATE, &pinfo);\r
-    if (result < 0) {\r
-      sprintf(message, "RtAudio: AL error getting device (%s) rates: %s.",\r
-              info->name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-    }\r
-    else {\r
-      // In the case of the default device, these values will\r
-      // overwrite the rates determined for the output device.  Since\r
-      // the input device is most likely to be more limited than the\r
-      // output device, this is ok.\r
-      info->nSampleRates = 0;\r
-      for (i=0; i<MAX_SAMPLE_RATES; i++) {\r
-        if ( SAMPLE_RATES[i] >= pinfo.min.i && SAMPLE_RATES[i] <= pinfo.max.i ) {\r
-          info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];\r
-          info->nSampleRates++;\r
-        }\r
-      }\r
-    }\r
-\r
-    // The AL library supports all our formats, except 24-bit and 32-bit ints.\r
-    info->nativeFormats = (RTAUDIO_FORMAT) 51;\r
-  }\r
-\r
-  if ( info->maxInputChannels == 0 && info->maxOutputChannels == 0 )\r
-    return;\r
-  if ( info->nSampleRates == 0 )\r
-    return;\r
-\r
-  // Determine duplex status.\r
-  if (info->maxInputChannels < info->maxOutputChannels)\r
-    info->maxDuplexChannels = info->maxInputChannels;\r
-  else\r
-    info->maxDuplexChannels = info->maxOutputChannels;\r
-  if (info->minInputChannels < info->minOutputChannels)\r
-    info->minDuplexChannels = info->minInputChannels;\r
-  else\r
-    info->minDuplexChannels = info->minOutputChannels;\r
-\r
-  if ( info->maxDuplexChannels > 0 ) info->hasDuplexSupport = true;\r
-  else info->hasDuplexSupport = false;\r
-\r
-  info->probed = true;\r
-\r
-  return;\r
-}\r
-\r
-bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,\r
-                                STREAM_MODE mode, int channels, \r
-                                int sampleRate, RTAUDIO_FORMAT format,\r
-                                int *bufferSize, int numberOfBuffers)\r
-{\r
-  int result, resource, nBuffers;\r
-  ALconfig al_config;\r
-  ALport port;\r
-  ALpv pvs[2];\r
-\r
-  // Get a new ALconfig structure.\r
-  al_config = alNewConfig();\r
-  if ( !al_config ) {\r
-    sprintf(message,"RtAudio: can't get AL config: %s.",\r
-            alGetErrorString(oserror()));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the channels.\r
-  result = alSetChannels(al_config, channels);\r
-  if ( result < 0 ) {\r
-    sprintf(message,"RtAudio: can't set %d channels in AL config: %s.",\r
-            channels, alGetErrorString(oserror()));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the queue (buffer) size.\r
-  if ( numberOfBuffers < 1 )\r
-    nBuffers = 1;\r
-  else\r
-    nBuffers = numberOfBuffers;\r
-  long buffer_size = *bufferSize * nBuffers;\r
-  result = alSetQueueSize(al_config, buffer_size); // in sample frames\r
-  if ( result < 0 ) {\r
-    sprintf(message,"RtAudio: can't set buffer size (%ld) in AL config: %s.",\r
-            buffer_size, alGetErrorString(oserror()));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  // Set the data format.\r
-  stream->userFormat = format;\r
-  stream->deviceFormat[mode] = format;\r
-  if (format == RTAUDIO_SINT8) {\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_TWOSCOMP);\r
-    result = alSetWidth(al_config, AL_SAMPLE_8);\r
-  }\r
-  else if (format == RTAUDIO_SINT16) {\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_TWOSCOMP);\r
-    result = alSetWidth(al_config, AL_SAMPLE_16);\r
-  }\r
-  else if (format == RTAUDIO_SINT24) {\r
-    // Our 24-bit format assumes the upper 3 bytes of a 4 byte word.\r
-    // The AL library uses the lower 3 bytes, so we'll need to do our\r
-    // own conversion.\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);\r
-    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;\r
-  }\r
-  else if (format == RTAUDIO_SINT32) {\r
-    // The AL library doesn't seem to support the 32-bit integer\r
-    // format, so we'll need to do our own conversion.\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);\r
-    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;\r
-  }\r
-  else if (format == RTAUDIO_FLOAT32)\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);\r
-  else if (format == RTAUDIO_FLOAT64)\r
-    result = alSetSampFmt(al_config, AL_SAMPFMT_DOUBLE);\r
-\r
-  if ( result == -1 ) {\r
-    sprintf(message,"RtAudio: AL error setting sample format in AL config: %s.",\r
-            alGetErrorString(oserror()));\r
-    error(RtError::WARNING);\r
-    return FAILURE;\r
-  }\r
-\r
-  if (mode == PLAYBACK) {\r
-\r
-    // Set our device.\r
-    if (device == 0)\r
-      resource = AL_DEFAULT_OUTPUT;\r
-    else\r
-      resource = devices[device].id[0];\r
-    result = alSetDevice(al_config, resource);\r
-    if ( result == -1 ) {\r
-      sprintf(message,"RtAudio: AL error setting device (%s) in AL config: %s.",\r
-              devices[device].name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Open the port.\r
-    port = alOpenPort("RtAudio Output Port", "w", al_config);\r
-    if( !port ) {\r
-      sprintf(message,"RtAudio: AL error opening output port: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Set the sample rate\r
-    pvs[0].param = AL_MASTER_CLOCK;\r
-    pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;\r
-    pvs[1].param = AL_RATE;\r
-    pvs[1].value.ll = alDoubleToFixed((double)sampleRate);\r
-    result = alSetParams(resource, pvs, 2);\r
-    if ( result < 0 ) {\r
-      alClosePort(port);\r
-      sprintf(message,"RtAudio: AL error setting sample rate (%d) for device (%s): %s.",\r
-              sampleRate, devices[device].name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-  }\r
-  else { // mode == RECORD\r
-\r
-    // Set our device.\r
-    if (device == 0)\r
-      resource = AL_DEFAULT_INPUT;\r
-    else\r
-      resource = devices[device].id[1];\r
-    result = alSetDevice(al_config, resource);\r
-    if ( result == -1 ) {\r
-      sprintf(message,"RtAudio: AL error setting device (%s) in AL config: %s.",\r
-              devices[device].name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Open the port.\r
-    port = alOpenPort("RtAudio Output Port", "r", al_config);\r
-    if( !port ) {\r
-      sprintf(message,"RtAudio: AL error opening input port: %s.",\r
-              alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-\r
-    // Set the sample rate\r
-    pvs[0].param = AL_MASTER_CLOCK;\r
-    pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;\r
-    pvs[1].param = AL_RATE;\r
-    pvs[1].value.ll = alDoubleToFixed((double)sampleRate);\r
-    result = alSetParams(resource, pvs, 2);\r
-    if ( result < 0 ) {\r
-      alClosePort(port);\r
-      sprintf(message,"RtAudio: AL error setting sample rate (%d) for device (%s): %s.",\r
-              sampleRate, devices[device].name, alGetErrorString(oserror()));\r
-      error(RtError::WARNING);\r
-      return FAILURE;\r
-    }\r
-  }\r
-\r
-  alFreeConfig(al_config);\r
-\r
-  stream->nUserChannels[mode] = channels;\r
-  stream->nDeviceChannels[mode] = channels;\r
-\r
-  // Set handle and flags for buffer conversion\r
-  stream->handle[mode] = port;\r
-  stream->doConvertBuffer[mode] = false;\r
-  if (stream->userFormat != stream->deviceFormat[mode])\r
-    stream->doConvertBuffer[mode] = true;\r
-\r
-  // Allocate necessary internal buffers\r
-  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {\r
-\r
-    long buffer_bytes;\r
-    if (stream->nUserChannels[0] >= stream->nUserChannels[1])\r
-      buffer_bytes = stream->nUserChannels[0];\r
-    else\r
-      buffer_bytes = stream->nUserChannels[1];\r
-\r
-    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);\r
-    if (stream->userBuffer) free(stream->userBuffer);\r
-    stream->userBuffer = (char *) calloc(buffer_bytes, 1);\r
-    if (stream->userBuffer == NULL)\r
-      goto memory_error;\r
-  }\r
-\r
-  if ( stream->doConvertBuffer[mode] ) {\r
-\r
-    long buffer_bytes;\r
-    bool makeBuffer = true;\r
-    if ( mode == PLAYBACK )\r
-      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-    else { // mode == RECORD\r
-      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);\r
-      if ( stream->mode == PLAYBACK ) {\r
-        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);\r
-        if ( buffer_bytes > bytes_out )\r
-          buffer_bytes = (buffer_bytes > bytes_out) ? buffer_bytes : bytes_out;\r
-        else\r
-          makeBuffer = false;\r
-      }\r
-    }\r
-\r
-    if ( makeBuffer ) {\r
-      buffer_bytes *= *bufferSize;\r
-      if (stream->deviceBuffer) free(stream->deviceBuffer);\r
-      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);\r
-      if (stream->deviceBuffer == NULL)\r
-        goto memory_error;\r
-    }\r
-  }\r
-\r
-  stream->device[mode] = device;\r
-  stream->state = STREAM_STOPPED;\r
-  if ( stream->mode == PLAYBACK && mode == RECORD )\r
-    // We had already set up an output stream.\r
-    stream->mode = DUPLEX;\r
-  else\r
-    stream->mode = mode;\r
-  stream->nBuffers = nBuffers;\r
-  stream->bufferSize = *bufferSize;\r
-  stream->sampleRate = sampleRate;\r
-\r
-  return SUCCESS;\r
-\r
- memory_error:\r
-  if (stream->handle[0]) {\r
-    alClosePort(stream->handle[0]);\r
-    stream->handle[0] = 0;\r
-  }\r
-  if (stream->handle[1]) {\r
-    alClosePort(stream->handle[1]);\r
-    stream->handle[1] = 0;\r
-  }\r
-  if (stream->userBuffer) {\r
-    free(stream->userBuffer);\r
-    stream->userBuffer = 0;\r
-  }\r
-  sprintf(message, "RtAudio: ALSA error allocating buffer memory for device (%s).",\r
-          devices[device].name);\r
-  error(RtError::WARNING);\r
-  return FAILURE;\r
-}\r
-\r
-void RtAudio :: cancelStreamCallback(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  if (stream->usingCallback) {\r
-    stream->usingCallback = false;\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-    stream->thread = 0;\r
-    stream->callback = NULL;\r
-    stream->userData = NULL;\r
-  }\r
-}\r
-\r
-void RtAudio :: closeStream(int streamId)\r
-{\r
-  // We don't want an exception to be thrown here because this\r
-  // function is called by our class destructor.  So, do our own\r
-  // streamId check.\r
-  if ( streams.find( streamId ) == streams.end() ) {\r
-    sprintf(message, "RtAudio: invalid stream identifier!");\r
-    error(RtError::WARNING);\r
-    return;\r
-  }\r
-\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];\r
-\r
-  if (stream->usingCallback) {\r
-    pthread_cancel(stream->thread);\r
-    pthread_join(stream->thread, NULL);\r
-  }\r
-\r
-  pthread_mutex_destroy(&stream->mutex);\r
-\r
-  if (stream->handle[0])\r
-    alClosePort(stream->handle[0]);\r
-\r
-  if (stream->handle[1])\r
-    alClosePort(stream->handle[1]);\r
-\r
-  if (stream->userBuffer)\r
-    free(stream->userBuffer);\r
-\r
-  if (stream->deviceBuffer)\r
-    free(stream->deviceBuffer);\r
-\r
-  free(stream);\r
-  streams.erase(streamId);\r
-}\r
-\r
-void RtAudio :: startStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  if (stream->state == STREAM_RUNNING)\r
-    return;\r
-\r
-  // The AL port is ready as soon as it is opened.\r
-  stream->state = STREAM_RUNNING;\r
-}\r
-\r
-void RtAudio :: stopStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int result;\r
-  int buffer_size = stream->bufferSize * stream->nBuffers;\r
-\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX)\r
-    alZeroFrames(stream->handle[0], buffer_size);\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    result = alDiscardFrames(stream->handle[1], buffer_size);\r
-    if (result == -1) {\r
-      sprintf(message, "RtAudio: AL error draining stream device (%s): %s.",\r
-              devices[stream->device[1]].name, alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-void RtAudio :: abortStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    int buffer_size = stream->bufferSize * stream->nBuffers;\r
-    int result = alDiscardFrames(stream->handle[0], buffer_size);\r
-    if (result == -1) {\r
-      sprintf(message, "RtAudio: AL error aborting stream device (%s): %s.",\r
-              devices[stream->device[0]].name, alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  // There is no clear action to take on the input stream, since the\r
-  // port will continue to run in any event.\r
-  stream->state = STREAM_STOPPED;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-}\r
-\r
-int RtAudio :: streamWillBlock(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  int frames = 0;\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  int err = 0;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-    err = alGetFillable(stream->handle[0]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: AL error getting available frames for stream (%s): %s.",\r
-              devices[stream->device[0]].name, alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-  }\r
-\r
-  frames = err;\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-    err = alGetFilled(stream->handle[1]);\r
-    if (err < 0) {\r
-      sprintf(message, "RtAudio: AL error getting available frames for stream (%s): %s.",\r
-              devices[stream->device[1]].name, alGetErrorString(oserror()));\r
-      error(RtError::DRIVER_ERROR);\r
-    }\r
-    if (frames > err) frames = err;\r
-  }\r
-\r
-  frames = stream->bufferSize - frames;\r
-  if (frames < 0) frames = 0;\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-  return frames;\r
-}\r
-\r
-void RtAudio :: tickStream(int streamId)\r
-{\r
-  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);\r
-\r
-  int stopStream = 0;\r
-  if (stream->state == STREAM_STOPPED) {\r
-    if (stream->usingCallback) usleep(50000); // sleep 50 milliseconds\r
-    return;\r
-  }\r
-  else if (stream->usingCallback) {\r
-    stopStream = stream->callback(stream->userBuffer, stream->bufferSize, stream->userData);    \r
-  }\r
-\r
-  MUTEX_LOCK(&stream->mutex);\r
-\r
-  // The state might change while waiting on a mutex.\r
-  if (stream->state == STREAM_STOPPED)\r
-    goto unlock;\r
-\r
-  char *buffer;\r
-  int channels;\r
-  RTAUDIO_FORMAT format;\r
-  if (stream->mode == PLAYBACK || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters and do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[0]) {\r
-      convertStreamBuffer(stream, PLAYBACK);\r
-      buffer = stream->deviceBuffer;\r
-      channels = stream->nDeviceChannels[0];\r
-      format = stream->deviceFormat[0];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      channels = stream->nUserChannels[0];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[0])\r
-      byteSwapBuffer(buffer, stream->bufferSize * channels, format);\r
-\r
-    // Write interleaved samples to device.\r
-    alWriteFrames(stream->handle[0], buffer, stream->bufferSize);\r
-  }\r
-\r
-  if (stream->mode == RECORD || stream->mode == DUPLEX) {\r
-\r
-    // Setup parameters.\r
-    if (stream->doConvertBuffer[1]) {\r
-      buffer = stream->deviceBuffer;\r
-      channels = stream->nDeviceChannels[1];\r
-      format = stream->deviceFormat[1];\r
-    }\r
-    else {\r
-      buffer = stream->userBuffer;\r
-      channels = stream->nUserChannels[1];\r
-      format = stream->userFormat;\r
-    }\r
-\r
-    // Read interleaved samples from device.\r
-    alReadFrames(stream->handle[1], buffer, stream->bufferSize);\r
-\r
-    // Do byte swapping if necessary.\r
-    if (stream->doByteSwap[1])\r
-      byteSwapBuffer(buffer, stream->bufferSize * channels, format);\r
-\r
-    // Do buffer conversion if necessary.\r
-    if (stream->doConvertBuffer[1])\r
-      convertStreamBuffer(stream, RECORD);\r
-  }\r
-\r
- unlock:\r
-  MUTEX_UNLOCK(&stream->mutex);\r
-\r
-  if (stream->usingCallback && stopStream)\r
-    this->stopStream(streamId);\r
-}\r
-\r
-extern "C" void *callbackHandler(void *ptr)\r
-{\r
-  RtAudio *object = thread_info.object;\r
-  int stream = thread_info.streamId;\r
-  bool *usingCallback = (bool *) ptr;\r
-\r
-  while ( *usingCallback ) {\r
-    pthread_testcancel();\r
-    try {\r
-      object->tickStream(stream);\r
-    }\r
-    catch (RtError &exception) {\r
-      fprintf(stderr, "\nCallback thread error (%s) ... closing thread.\n\n",\r
-              exception.getMessage());\r
-      break;\r
-    }\r
-  }\r
-\r
-  return 0;\r
-}\r
-\r
-//******************** End of __IRIX_AL__ *********************//\r
-\r
-#endif\r
-\r
-\r
-// *************************************************** //\r
-//\r
-// Private common (OS-independent) RtAudio methods.\r
-//\r
-// *************************************************** //\r
-\r
-// This method can be modified to control the behavior of error\r
-// message reporting and throwing.\r
-void RtAudio :: error(RtError::TYPE type)\r
-{\r
-  if (type == RtError::WARNING) {\r
-#if defined(RTAUDIO_DEBUG)\r
-    fprintf(stderr, "\n%s\n\n", message);\r
-  else if (type == RtError::DEBUG_WARNING) {\r
-    fprintf(stderr, "\n%s\n\n", message);\r
-#endif\r
-  }\r
-  else {\r
-    fprintf(stderr, "\n%s\n\n", message);\r
-    throw RtError(message, type);\r
-  }\r
-}\r
-\r
-void *RtAudio :: verifyStream(int streamId)\r
-{\r
-  // Verify the stream key.\r
-  if ( streams.find( streamId ) == streams.end() ) {\r
-    sprintf(message, "RtAudio: invalid stream identifier!");\r
-    error(RtError::INVALID_STREAM);\r
-  }\r
-\r
-  return streams[streamId];\r
-}\r
-\r
-void RtAudio :: clearDeviceInfo(RTAUDIO_DEVICE *info)\r
-{\r
-  // Don't clear the name or DEVICE_ID fields here ... they are\r
-  // typically set prior to a call of this function.\r
-  info->probed = false;\r
-  info->maxOutputChannels = 0;\r
-  info->maxInputChannels = 0;\r
-  info->maxDuplexChannels = 0;\r
-  info->minOutputChannels = 0;\r
-  info->minInputChannels = 0;\r
-  info->minDuplexChannels = 0;\r
-  info->hasDuplexSupport = false;\r
-  info->nSampleRates = 0;\r
-  for (int i=0; i<MAX_SAMPLE_RATES; i++)\r
-    info->sampleRates[i] = 0;\r
-  info->nativeFormats = 0;\r
-}\r
-\r
-int RtAudio :: formatBytes(RTAUDIO_FORMAT format)\r
-{\r
-  if (format == RTAUDIO_SINT16)\r
-    return 2;\r
-  else if (format == RTAUDIO_SINT24 || format == RTAUDIO_SINT32 ||\r
-           format == RTAUDIO_FLOAT32)\r
-    return 4;\r
-  else if (format == RTAUDIO_FLOAT64)\r
-    return 8;\r
-  else if (format == RTAUDIO_SINT8)\r
-    return 1;\r
-\r
-  sprintf(message,"RtAudio: undefined format in formatBytes().");\r
-  error(RtError::WARNING);\r
-\r
-  return 0;\r
-}\r
-\r
-void RtAudio :: convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode)\r
-{\r
-  // This method does format conversion, input/output channel compensation, and\r
-  // data interleaving/deinterleaving.  24-bit integers are assumed to occupy\r
-  // the upper three bytes of a 32-bit integer.\r
-\r
-  int j, channels_in, channels_out, channels;\r
-  RTAUDIO_FORMAT format_in, format_out;\r
-  char *input, *output;\r
-\r
-  if (mode == RECORD) { // convert device to user buffer\r
-    input = stream->deviceBuffer;\r
-    output = stream->userBuffer;\r
-    channels_in = stream->nDeviceChannels[1];\r
-    channels_out = stream->nUserChannels[1];\r
-    format_in = stream->deviceFormat[1];\r
-    format_out = stream->userFormat;\r
-  }\r
-  else { // convert user to device buffer\r
-    input = stream->userBuffer;\r
-    output = stream->deviceBuffer;\r
-    channels_in = stream->nUserChannels[0];\r
-    channels_out = stream->nDeviceChannels[0];\r
-    format_in = stream->userFormat;\r
-    format_out = stream->deviceFormat[0];\r
-\r
-    // clear our device buffer when in/out duplex device channels are different\r
-    if ( stream->mode == DUPLEX &&\r
-         stream->nDeviceChannels[0] != stream->nDeviceChannels[1] )\r
-      memset(output, 0, stream->bufferSize * channels_out * formatBytes(format_out));\r
-  }\r
-\r
-  channels = (channels_in < channels_out) ? channels_in : channels_out;\r
-\r
-  // Set up the interleave/deinterleave offsets\r
-  std::vector<int> offset_in(channels);\r
-  std::vector<int> offset_out(channels);\r
-  if (mode == RECORD && stream->deInterleave[1]) {\r
-    for (int k=0; k<channels; k++) {\r
-      offset_in[k] = k * stream->bufferSize;\r
-      offset_out[k] = k;\r
-    }\r
-  }\r
-  else if (mode == PLAYBACK && stream->deInterleave[0]) {\r
-    for (int k=0; k<channels; k++) {\r
-      offset_in[k] = k;\r
-      offset_out[k] = k * stream->bufferSize;\r
-    }\r
-  }\r
-  else {\r
-    for (int k=0; k<channels; k++) {\r
-      offset_in[k] = k;\r
-      offset_out[k] = k;\r
-    }\r
-  }\r
-\r
-  if (format_out == RTAUDIO_FLOAT64) {\r
-    FLOAT64 scale;\r
-    FLOAT64 *out = (FLOAT64 *)output;\r
-\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      signed char *in = (signed char *)input;\r
-      scale = 1.0 / 128.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT16) {\r
-      INT16 *in = (INT16 *)input;\r
-      scale = 1.0 / 32768.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      INT32 *in = (INT32 *)input;\r
-      scale = 1.0 / 2147483648.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT64) (in[offset_in[j]] & 0xffffff00);\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      INT32 *in = (INT32 *)input;\r
-      scale = 1.0 / 2147483648.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-  else if (format_out == RTAUDIO_FLOAT32) {\r
-    FLOAT32 scale;\r
-    FLOAT32 *out = (FLOAT32 *)output;\r
-\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      signed char *in = (signed char *)input;\r
-      scale = 1.0 / 128.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT16) {\r
-      INT16 *in = (INT16 *)input;\r
-      scale = 1.0 / 32768.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      INT32 *in = (INT32 *)input;\r
-      scale = 1.0 / 2147483648.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT32) (in[offset_in[j]] & 0xffffff00);\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      INT32 *in = (INT32 *)input;\r
-      scale = 1.0 / 2147483648.0;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];\r
-          out[offset_out[j]] *= scale;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-  else if (format_out == RTAUDIO_SINT32) {\r
-    INT32 *out = (INT32 *)output;\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      signed char *in = (signed char *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) in[offset_in[j]];\r
-          out[offset_out[j]] <<= 24;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT16) {\r
-      INT16 *in = (INT16 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) in[offset_in[j]];\r
-          out[offset_out[j]] <<= 16;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-  else if (format_out == RTAUDIO_SINT24) {\r
-    INT32 *out = (INT32 *)output;\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      signed char *in = (signed char *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) in[offset_in[j]];\r
-          out[offset_out[j]] <<= 24;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT16) {\r
-      INT16 *in = (INT16 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) in[offset_in[j]];\r
-          out[offset_out[j]] <<= 16;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) (in[offset_in[j]] & 0xffffff00);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-  else if (format_out == RTAUDIO_SINT16) {\r
-    INT16 *out = (INT16 *)output;\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      signed char *in = (signed char *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT16) in[offset_in[j]];\r
-          out[offset_out[j]] <<= 8;\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT16) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      INT16 *in = (INT16 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT16) ((in[offset_in[j]] >> 16) & 0x0000ffff);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT16) ((in[offset_in[j]] >> 16) & 0x0000ffff);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT16) (in[offset_in[j]] * 32767.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (INT16) (in[offset_in[j]] * 32767.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-  else if (format_out == RTAUDIO_SINT8) {\r
-    signed char *out = (signed char *)output;\r
-    if (format_in == RTAUDIO_SINT8) {\r
-      // Channel compensation and/or (de)interleaving only.\r
-      signed char *in = (signed char *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = in[offset_in[j]];\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    if (format_in == RTAUDIO_SINT16) {\r
-      INT16 *in = (INT16 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 8) & 0x00ff);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT24) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 24) & 0x000000ff);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_SINT32) {\r
-      INT32 *in = (INT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 24) & 0x000000ff);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT32) {\r
-      FLOAT32 *in = (FLOAT32 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (signed char) (in[offset_in[j]] * 127.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-    else if (format_in == RTAUDIO_FLOAT64) {\r
-      FLOAT64 *in = (FLOAT64 *)input;\r
-      for (int i=0; i<stream->bufferSize; i++) {\r
-        for (j=0; j<channels; j++) {\r
-          out[offset_out[j]] = (signed char) (in[offset_in[j]] * 127.0);\r
-        }\r
-        in += channels_in;\r
-        out += channels_out;\r
-      }\r
-    }\r
-  }\r
-}\r
-\r
-void RtAudio :: byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format)\r
-{\r
-  register char val;\r
-  register char *ptr;\r
-\r
-  ptr = buffer;\r
-  if (format == RTAUDIO_SINT16) {\r
-    for (int i=0; i<samples; i++) {\r
-      // Swap 1st and 2nd bytes.\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+1);\r
-      *(ptr+1) = val;\r
-\r
-      // Increment 2 bytes.\r
-      ptr += 2;\r
-    }\r
-  }\r
-  else if (format == RTAUDIO_SINT24 ||\r
-           format == RTAUDIO_SINT32 ||\r
-           format == RTAUDIO_FLOAT32) {\r
-    for (int i=0; i<samples; i++) {\r
-      // Swap 1st and 4th bytes.\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+3);\r
-      *(ptr+3) = val;\r
-\r
-      // Swap 2nd and 3rd bytes.\r
-      ptr += 1;\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+1);\r
-      *(ptr+1) = val;\r
-\r
-      // Increment 4 bytes.\r
-      ptr += 4;\r
-    }\r
-  }\r
-  else if (format == RTAUDIO_FLOAT64) {\r
-    for (int i=0; i<samples; i++) {\r
-      // Swap 1st and 8th bytes\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+7);\r
-      *(ptr+7) = val;\r
-\r
-      // Swap 2nd and 7th bytes\r
-      ptr += 1;\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+5);\r
-      *(ptr+5) = val;\r
-\r
-      // Swap 3rd and 6th bytes\r
-      ptr += 1;\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+3);\r
-      *(ptr+3) = val;\r
-\r
-      // Swap 4th and 5th bytes\r
-      ptr += 1;\r
-      val = *(ptr);\r
-      *(ptr) = *(ptr+1);\r
-      *(ptr+1) = val;\r
-\r
-      // Increment 8 bytes.\r
-      ptr += 8;\r
-    }\r
-  }\r
-}\r
-\r
-\r
-// *************************************************** //\r
-//\r
-// RtError class definition.\r
-//\r
-// *************************************************** //\r
-\r
-RtError :: RtError(const char *p, TYPE tipe)\r
-{\r
-  type = tipe;\r
-  strncpy(error_message, p, 256);\r
-}\r
-\r
-RtError :: ~RtError()\r
-{\r
-}\r
-\r
-void RtError :: printMessage()\r
-{\r
-  printf("\n%s\n\n", error_message);\r
-}\r
+/************************************************************************/
+/*! \class RtAudio
+    \brief Realtime audio i/o C++ class.
+
+    RtAudio provides a common API (Application Programming Interface)
+    for realtime audio input/output across Linux (native ALSA and
+    OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound
+    and ASIO) operating systems.
+
+    RtAudio WWW site: http://www-ccrma.stanford.edu/~gary/rtaudio/
+
+    RtAudio: a realtime audio i/o C++ class
+    Copyright (c) 2001-2002 Gary P. Scavone
+
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation files
+    (the "Software"), to deal in the Software without restriction,
+    including without limitation the rights to use, copy, modify, merge,
+    publish, distribute, sublicense, and/or sell copies of the Software,
+    and to permit persons to whom the Software is furnished to do so,
+    subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    Any person wishing to distribute modifications to the Software is
+    requested to send the modifications to the original developer so that
+    they can be incorporated into the canonical version.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+/************************************************************************/
+
+
+#include "RtAudio.h"
+#include <vector>
+#include <stdio.h>
+#include <iostream.h>
+
+// Static variable definitions.
+const unsigned int RtAudio :: SAMPLE_RATES[] = {
+  4000, 5512, 8000, 9600, 11025, 16000, 22050,
+  32000, 44100, 48000, 88200, 96000, 176400, 192000
+};
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT8 = 1;
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT16 = 2;
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT24 = 4;
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_SINT32 = 8;
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_FLOAT32 = 16;
+const RtAudio::RTAUDIO_FORMAT RtAudio :: RTAUDIO_FLOAT64 = 32;
+
+#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
+  #define MUTEX_INITIALIZE(A) InitializeCriticalSection(A)
+  #define MUTEX_LOCK(A)       EnterCriticalSection(A)
+  #define MUTEX_UNLOCK(A)     LeaveCriticalSection(A)
+#else // pthread API
+  #define MUTEX_INITIALIZE(A) pthread_mutex_init(A, NULL)
+  #define MUTEX_LOCK(A)       pthread_mutex_lock(A)
+  #define MUTEX_UNLOCK(A)     pthread_mutex_unlock(A)
+#endif
+
+// *************************************************** //
+//
+// Public common (OS-independent) methods.
+//
+// *************************************************** //
+
+RtAudio :: RtAudio()
+{
+  initialize();
+
+  if (nDevices <= 0) {
+    sprintf(message, "RtAudio: no audio devices found!");
+    error(RtError::NO_DEVICES_FOUND);
+ }
+}
+
+RtAudio :: RtAudio(int *streamId,
+                   int outputDevice, int outputChannels,
+                   int inputDevice, int inputChannels,
+                   RTAUDIO_FORMAT format, int sampleRate,
+                   int *bufferSize, int numberOfBuffers)
+{
+  initialize();
+
+  if (nDevices <= 0) {
+    sprintf(message, "RtAudio: no audio devices found!");
+    error(RtError::NO_DEVICES_FOUND);
+  }
+
+  try {
+    *streamId = openStream(outputDevice, outputChannels, inputDevice, inputChannels,
+                           format, sampleRate, bufferSize, numberOfBuffers);
+  }
+  catch (RtError &exception) {
+    // deallocate the RTAUDIO_DEVICE structures
+    if (devices) free(devices);
+    throw exception;
+  }
+}
+
+RtAudio :: ~RtAudio()
+{
+  // close any existing streams
+  while ( streams.size() )
+    closeStream( streams.begin()->first );
+
+  // deallocate the RTAUDIO_DEVICE structures
+  if (devices) free(devices);
+}
+
+int RtAudio :: openStream(int outputDevice, int outputChannels,
+                          int inputDevice, int inputChannels,
+                          RTAUDIO_FORMAT format, int sampleRate,
+                          int *bufferSize, int numberOfBuffers)
+{
+  static int streamKey = 0; // Unique stream identifier ... OK for multiple instances.
+
+  if (outputChannels < 1 && inputChannels < 1) {
+    sprintf(message,"RtAudio: one or both 'channel' parameters must be greater than zero.");
+    error(RtError::INVALID_PARAMETER);
+  }
+
+  if ( formatBytes(format) == 0 ) {
+    sprintf(message,"RtAudio: 'format' parameter value is undefined.");
+    error(RtError::INVALID_PARAMETER);
+  }
+
+  if ( outputChannels > 0 ) {
+    if (outputDevice > nDevices || outputDevice < 0) {
+      sprintf(message,"RtAudio: 'outputDevice' parameter value (%d) is invalid.", outputDevice);
+      error(RtError::INVALID_PARAMETER);
+    }
+  }
+
+  if ( inputChannels > 0 ) {
+    if (inputDevice > nDevices || inputDevice < 0) {
+      sprintf(message,"RtAudio: 'inputDevice' parameter value (%d) is invalid.", inputDevice);
+      error(RtError::INVALID_PARAMETER);
+    }
+  }
+
+  // Allocate a new stream structure.
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) calloc(1, sizeof(RTAUDIO_STREAM));
+  if (stream == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+  stream->mode = UNINITIALIZED;
+  MUTEX_INITIALIZE(&stream->mutex);
+
+  bool result = FAILURE;
+  int device, defaultDevice = 0;
+  STREAM_MODE mode;
+  int channels;
+  if ( outputChannels > 0 ) {
+
+    mode = OUTPUT;
+    channels = outputChannels;
+
+    if ( outputDevice == 0 ) { // Try default device first.
+      defaultDevice = getDefaultOutputDevice();
+      device = defaultDevice;
+    }
+    else
+      device = outputDevice - 1;
+
+    for (int i=-1; i<nDevices; i++) {
+      if (i >= 0 ) { 
+        if ( i == defaultDevice ) continue;
+        device = i;
+      }
+      if (devices[device].probed == false) {
+        // If the device wasn't successfully probed before, try it
+        // again now.
+        clearDeviceInfo(&devices[device]);
+        probeDeviceInfo(&devices[device]);
+      }
+      if ( devices[device].probed )
+        result = probeDeviceOpen(device, stream, mode, channels, sampleRate,
+                                 format, bufferSize, numberOfBuffers);
+      if (result == SUCCESS) break;
+      if ( outputDevice > 0 ) break;
+    }
+  }
+
+  if ( inputChannels > 0 && ( result == SUCCESS || outputChannels <= 0 ) ) {
+
+    mode = INPUT;
+    channels = inputChannels;
+
+    if ( inputDevice == 0 ) { // Try default device first.
+      defaultDevice = getDefaultInputDevice();
+      device = defaultDevice;
+    }
+    else
+      device = inputDevice - 1;
+
+    for (int i=-1; i<nDevices; i++) {
+      if (i >= 0 ) { 
+        if ( i == defaultDevice ) continue;
+        device = i;
+      }
+      if (devices[device].probed == false) {
+        // If the device wasn't successfully probed before, try it
+        // again now.
+        clearDeviceInfo(&devices[device]);
+        probeDeviceInfo(&devices[device]);
+      }
+      if ( devices[device].probed )
+        result = probeDeviceOpen(device, stream, mode, channels, sampleRate,
+                                 format, bufferSize, numberOfBuffers);
+      if (result == SUCCESS) break;
+      if ( outputDevice > 0 ) break;
+    }
+  }
+
+  streams[++streamKey] = (void *) stream;
+  if ( result == SUCCESS )
+    return streamKey;
+
+  // If we get here, all attempted probes failed.  Close any opened
+  // devices and delete the allocated stream.
+  closeStream(streamKey);
+  if ( ( outputDevice == 0 && outputChannels > 0 )
+       || ( inputDevice == 0 && inputChannels > 0 ) )
+    sprintf(message,"RtAudio: no devices found for given parameters.");
+  else
+    sprintf(message,"RtAudio: unable to open specified device(s) with given stream parameters.");
+  error(RtError::INVALID_PARAMETER);
+
+  return -1;
+}
+
+int RtAudio :: getDeviceCount(void)
+{
+  return nDevices;
+}
+
+void RtAudio :: getDeviceInfo(int device, RTAUDIO_DEVICE *info)
+{
+  if (device > nDevices || device < 1) {
+    sprintf(message, "RtAudio: invalid device specifier (%d)!", device);
+    error(RtError::INVALID_DEVICE);
+  }
+
+  int deviceIndex = device - 1;
+
+  // If the device wasn't successfully probed before, try it now (or again).
+  if (devices[deviceIndex].probed == false) {
+    clearDeviceInfo(&devices[deviceIndex]);
+    probeDeviceInfo(&devices[deviceIndex]);
+  }
+
+  // Clear the info structure.
+  memset(info, 0, sizeof(RTAUDIO_DEVICE));
+
+  strncpy(info->name, devices[deviceIndex].name, 128);
+  info->probed = devices[deviceIndex].probed;
+  if ( info->probed == true ) {
+    info->maxOutputChannels = devices[deviceIndex].maxOutputChannels;
+    info->maxInputChannels = devices[deviceIndex].maxInputChannels;
+    info->maxDuplexChannels = devices[deviceIndex].maxDuplexChannels;
+    info->minOutputChannels = devices[deviceIndex].minOutputChannels;
+    info->minInputChannels = devices[deviceIndex].minInputChannels;
+    info->minDuplexChannels = devices[deviceIndex].minDuplexChannels;
+    info->hasDuplexSupport = devices[deviceIndex].hasDuplexSupport;
+    info->nSampleRates = devices[deviceIndex].nSampleRates;
+    if (info->nSampleRates == -1) {
+      info->sampleRates[0] = devices[deviceIndex].sampleRates[0];
+      info->sampleRates[1] = devices[deviceIndex].sampleRates[1];
+    }
+    else {
+      for (int i=0; i<info->nSampleRates; i++)
+        info->sampleRates[i] = devices[deviceIndex].sampleRates[i];
+    }
+    info->nativeFormats = devices[deviceIndex].nativeFormats;
+    if ( deviceIndex == getDefaultOutputDevice() ||
+         deviceIndex == getDefaultInputDevice() )
+      info->isDefault = true;
+  }
+
+  return;
+}
+
+char * const RtAudio :: getStreamBuffer(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  return stream->userBuffer;
+}
+
+#if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__IRIX_AL__)
+
+extern "C" void *callbackHandler(void * ptr);
+
+void RtAudio :: setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  CALLBACK_INFO *info = (CALLBACK_INFO *) &stream->callbackInfo;
+  if ( info->usingCallback ) {
+    sprintf(message, "RtAudio: A callback is already set for this stream!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  info->callback = (void *) callback;
+  info->userData = userData;
+  info->usingCallback = true;
+  info->object = (void *) this;
+  info->streamId = streamId;
+
+  int err = pthread_create(&info->thread, NULL, callbackHandler, &stream->callbackInfo);
+
+  if (err) {
+    info->usingCallback = false;
+    sprintf(message, "RtAudio: error starting callback thread!");
+    error(RtError::THREAD_ERROR);
+  }
+}
+
+void RtAudio :: cancelStreamCallback(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->callbackInfo.usingCallback) {
+
+    if (stream->state == STREAM_RUNNING)
+      stopStream( streamId );
+
+    MUTEX_LOCK(&stream->mutex);
+
+    stream->callbackInfo.usingCallback = false;
+    pthread_cancel(stream->callbackInfo.thread);
+    pthread_join(stream->callbackInfo.thread, NULL);
+    stream->callbackInfo.thread = 0;
+    stream->callbackInfo.callback = NULL;
+    stream->callbackInfo.userData = NULL;
+
+    MUTEX_UNLOCK(&stream->mutex);
+  }
+}
+
+#endif
+
+// *************************************************** //
+//
+// OS/API-specific methods.
+//
+// *************************************************** //
+
+#if defined(__MACOSX_CORE__)
+
+// The OS X CoreAudio API is designed to use a separate callback
+// procedure for each of its audio devices.  A single RtAudio duplex
+// stream using two different devices is supported here, though it
+// cannot be guaranteed to always behave correctly because we cannot
+// synchronize these two callbacks.  This same functionality can be
+// achieved with better synchrony by opening two separate streams for
+// the devices and using RtAudio blocking calls (i.e. tickStream()).
+//
+// The possibility of having multiple RtAudio streams accessing the
+// same CoreAudio device is not currently supported.  The problem
+// involves the inability to install our callbackHandler function for
+// the same device more than once.  I experimented with a workaround
+// for this, but it requires an additional buffer for mixing output
+// data before filling the CoreAudio device buffer.  In the end, I
+// decided it wasn't worth supporting.
+//
+// Property listeners are currently not used.  The issue is what could
+// be done if a critical stream parameter (buffer size, sample rate,
+// device disconnect) notification arrived.  The listeners entail
+// quite a bit of extra code and most likely, a user program wouldn't
+// be prepared for the result anyway.  Some initial listener code is
+// commented out.
+
+void RtAudio :: initialize(void)
+{
+  OSStatus err = noErr;
+  UInt32 dataSize;
+  AudioDeviceID        *deviceList = NULL;
+  nDevices = 0;
+
+  // Find out how many audio devices there are, if any.
+  err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &dataSize, NULL);
+  if (err != noErr) {
+    sprintf(message, "RtAudio: OSX error getting device info!");
+    error(RtError::SYSTEM_ERROR);
+  }
+
+  nDevices = dataSize / sizeof(AudioDeviceID);
+  if (nDevices == 0) return;
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Make space for the devices we are about to get.
+  deviceList = (AudioDeviceID  *) malloc( dataSize );
+  if (deviceList == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Get the array of AudioDeviceIDs.
+  err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &dataSize, (void *) deviceList);
+  if (err != noErr) {
+    free(deviceList);
+    sprintf(message, "RtAudio: OSX error getting device properties!");
+    error(RtError::SYSTEM_ERROR);
+  }
+
+  // Write device identifiers to device structures and then
+  // probe the device capabilities.
+  for (int i=0; i<nDevices; i++) {
+    devices[i].id[0] = deviceList[i];
+    //probeDeviceInfo(&devices[i]);
+  }
+
+  free(deviceList);
+}
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  AudioDeviceID id;
+  UInt32 dataSize = sizeof( AudioDeviceID );
+
+  OSStatus result = AudioHardwareGetProperty( kAudioHardwarePropertyDefaultInputDevice,
+                                              &dataSize, &id );
+
+  if (result != noErr) {
+    sprintf( message, "RtAudio: OSX error getting default input device." );
+    error(RtError::WARNING);
+    return 0;
+  }
+
+  for ( int i=0; i<nDevices; i++ ) {
+    if ( id == devices[i].id[0] ) return i;
+  }
+
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  AudioDeviceID id;
+  UInt32 dataSize = sizeof( AudioDeviceID );
+
+  OSStatus result = AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice,
+                                              &dataSize, &id );
+
+  if (result != noErr) {
+    sprintf( message, "RtAudio: OSX error getting default output device." );
+    error(RtError::WARNING);
+    return 0;
+  }
+
+  for ( int i=0; i<nDevices; i++ ) {
+    if ( id == devices[i].id[0] ) return i;
+  }
+
+  return 0;
+}
+
+static bool deviceSupportsFormat( AudioDeviceID id, bool isInput,
+                                  AudioStreamBasicDescription  *desc, bool isDuplex )
+{
+  OSStatus result = noErr;
+  UInt32 dataSize = sizeof( AudioStreamBasicDescription );
+
+  result = AudioDeviceGetProperty( id, 0, isInput,
+                                   kAudioDevicePropertyStreamFormatSupported,
+                                   &dataSize, desc );
+
+  if (result == kAudioHardwareNoError) {
+    if ( isDuplex ) {
+      result = AudioDeviceGetProperty( id, 0, true,
+                                       kAudioDevicePropertyStreamFormatSupported,
+                                       &dataSize, desc );
+
+
+      if (result != kAudioHardwareNoError)
+        return false;
+    }
+    return true;
+  }
+
+  return false;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  OSStatus err = noErr;
+
+  // Get the device manufacturer and name.
+  char name[256];
+  char fullname[512];
+  UInt32 dataSize = 256;
+  err = AudioDeviceGetProperty( info->id[0], 0, false,
+                                kAudioDevicePropertyDeviceManufacturer,
+                                &dataSize, name );
+  if (err != noErr) {
+    sprintf( message, "RtAudio: OSX error getting device manufacturer." );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+  strncpy(fullname, name, 256);
+  strcat(fullname, ": " );
+
+  dataSize = 256;
+  err = AudioDeviceGetProperty( info->id[0], 0, false,
+                                kAudioDevicePropertyDeviceName,
+                                &dataSize, name );
+  if (err != noErr) {
+    sprintf( message, "RtAudio: OSX error getting device name." );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+  strncat(fullname, name, 254);
+  strncat(info->name, fullname, 128);
+
+  // Get output channel information.
+  unsigned int i, minChannels, maxChannels, nStreams = 0;
+  AudioBufferList      *bufferList = nil;
+  err = AudioDeviceGetPropertyInfo( info->id[0], 0, false,
+                                    kAudioDevicePropertyStreamConfiguration,
+                                    &dataSize, NULL );
+  if (err == noErr && dataSize > 0) {
+    bufferList = (AudioBufferList *) malloc( dataSize );
+    if (bufferList == NULL) {
+      sprintf(message, "RtAudio: memory allocation error!");
+      error(RtError::DEBUG_WARNING);
+      return;
+    }
+
+    err = AudioDeviceGetProperty( info->id[0], 0, false,
+                                  kAudioDevicePropertyStreamConfiguration,
+                                  &dataSize, bufferList );
+    if (err == noErr) {
+      maxChannels = 0;
+      minChannels = 1000;
+      nStreams = bufferList->mNumberBuffers;
+      for ( i=0; i<nStreams; i++ ) {
+        maxChannels += bufferList->mBuffers[i].mNumberChannels;
+        if ( bufferList->mBuffers[i].mNumberChannels < minChannels )
+          minChannels = bufferList->mBuffers[i].mNumberChannels;
+      }
+    }
+  }
+  if (err != noErr || dataSize <= 0) {
+    sprintf( message, "RtAudio: OSX error getting output channels for device (%s).", info->name );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  free (bufferList);
+  if ( nStreams ) {
+    if ( maxChannels > 0 )
+      info->maxOutputChannels = maxChannels;
+    if ( minChannels > 0 )
+      info->minOutputChannels = minChannels;
+  }
+
+  // Get input channel information.
+  bufferList = nil;
+  err = AudioDeviceGetPropertyInfo( info->id[0], 0, true,
+                                    kAudioDevicePropertyStreamConfiguration,
+                                    &dataSize, NULL );
+  if (err == noErr && dataSize > 0) {
+    bufferList = (AudioBufferList *) malloc( dataSize );
+    if (bufferList == NULL) {
+      sprintf(message, "RtAudio: memory allocation error!");
+      error(RtError::DEBUG_WARNING);
+      return;
+    }
+    err = AudioDeviceGetProperty( info->id[0], 0, true,
+                                  kAudioDevicePropertyStreamConfiguration,
+                                  &dataSize, bufferList );
+    if (err == noErr) {
+      maxChannels = 0;
+      minChannels = 1000;
+      nStreams = bufferList->mNumberBuffers;
+      for ( i=0; i<nStreams; i++ ) {
+        if ( bufferList->mBuffers[i].mNumberChannels < minChannels )
+          minChannels = bufferList->mBuffers[i].mNumberChannels;
+        maxChannels += bufferList->mBuffers[i].mNumberChannels;
+      }
+    }
+  }
+  if (err != noErr || dataSize <= 0) {
+    sprintf( message, "RtAudio: OSX error getting input channels for device (%s).", info->name );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  free (bufferList);
+  if ( nStreams ) {
+    if ( maxChannels > 0 )
+      info->maxInputChannels = maxChannels;
+    if ( minChannels > 0 )
+      info->minInputChannels = minChannels;
+  }
+
+  // If device opens for both playback and capture, we determine the channels.
+  if (info->maxOutputChannels > 0 && info->maxInputChannels > 0) {
+    info->hasDuplexSupport = true;
+    info->maxDuplexChannels = (info->maxOutputChannels > info->maxInputChannels) ?
+      info->maxInputChannels : info->maxOutputChannels;
+    info->minDuplexChannels = (info->minOutputChannels > info->minInputChannels) ?
+      info->minInputChannels : info->minOutputChannels;
+  }
+
+  // Probe the device sample rate and data format parameters.  The
+  // core audio query mechanism is performed on a "stream"
+  // description, which can have a variable number of channels and
+  // apply to input or output only.
+
+  // Create a stream description structure.
+  AudioStreamBasicDescription  description;
+  dataSize = sizeof( AudioStreamBasicDescription );
+  memset(&description, 0, sizeof(AudioStreamBasicDescription));
+  bool isInput = false;
+  if ( info->maxOutputChannels == 0 ) isInput = true;
+  bool isDuplex = false;
+  if ( info->maxDuplexChannels > 0 ) isDuplex = true;
+
+  // Determine the supported sample rates.
+  info->nSampleRates = 0;
+  for (i=0; i<MAX_SAMPLE_RATES; i++) {
+    description.mSampleRate = (double) SAMPLE_RATES[i];
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->sampleRates[info->nSampleRates++] = SAMPLE_RATES[i];
+  }
+
+  if (info->nSampleRates == 0) {
+    sprintf( message, "RtAudio: No supported sample rates found for OSX device (%s).", info->name );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Check for continuous sample rate support.
+  description.mSampleRate = kAudioStreamAnyRate;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) ) {
+    info->sampleRates[1] = info->sampleRates[info->nSampleRates-1];
+    info->nSampleRates = -1;
+  }
+
+  // Determine the supported data formats.
+  info->nativeFormats = 0;
+  description.mFormatID = kAudioFormatLinearPCM;
+  description.mBitsPerChannel = 8;
+  description.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_SINT8;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_SINT8;
+  }
+
+  description.mBitsPerChannel = 16;
+  description.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_SINT16;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_SINT16;
+  }
+
+  description.mBitsPerChannel = 32;
+  description.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_SINT32;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_SINT32;
+  }
+
+  description.mBitsPerChannel = 24;
+  description.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsAlignedHigh | kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_SINT24;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_SINT24;
+  }
+
+  description.mBitsPerChannel = 32;
+  description.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_FLOAT32;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_FLOAT32;
+  }
+
+  description.mBitsPerChannel = 64;
+  description.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
+  if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+    info->nativeFormats |= RTAUDIO_FLOAT64;
+  else {
+    description.mFormatFlags &= ~kLinearPCMFormatFlagIsBigEndian;
+    if ( deviceSupportsFormat( info->id[0], isInput, &description, isDuplex ) )
+      info->nativeFormats |= RTAUDIO_FLOAT64;
+  }
+
+  // Check that we have at least one supported format.
+  if (info->nativeFormats == 0) {
+    sprintf(message, "RtAudio: OSX PCM device (%s) data format not supported by RtAudio.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  info->probed = true;
+}
+
+OSStatus callbackHandler(AudioDeviceID inDevice,
+                         const AudioTimeStamp* inNow,
+                         const AudioBufferList* inInputData,
+                         const AudioTimeStamp* inInputTime,
+                         AudioBufferList* outOutputData,
+                         const AudioTimeStamp* inOutputTime, 
+                         void* infoPointer)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) infoPointer;
+
+  RtAudio *object = (RtAudio *) info->object;
+  try {
+    object->callbackEvent( info->streamId, inDevice, (void *)inInputData, (void *)outOutputData );
+  }
+  catch (RtError &exception) {
+    fprintf(stderr, "\nCallback handler error (%s)!\n\n", exception.getMessage());
+    return kAudioHardwareUnspecifiedError;
+  }
+
+  return kAudioHardwareNoError;
+}
+
+/*
+OSStatus deviceListener(AudioDeviceID inDevice,
+                        UInt32 channel,
+                        Boolean isInput,
+                        AudioDevicePropertyID propertyID,
+                        void* infoPointer)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) infoPointer;
+
+  RtAudio *object = (RtAudio *) info->object;
+  try {
+    object->settingChange( info->streamId );
+  }
+  catch (RtError &exception) {
+    fprintf(stderr, "\nDevice listener error (%s)!\n\n", exception.getMessage());
+    return kAudioHardwareUnspecifiedError;
+  }
+
+  return kAudioHardwareNoError;
+}
+*/
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+  // Check to make sure we don't already have a stream accessing this device.
+  RTAUDIO_STREAM *streamPtr;
+  std::map<int, void *>::const_iterator i;
+  for ( i=streams.begin(); i!=streams.end(); ++i ) {
+    streamPtr = (RTAUDIO_STREAM *) i->second;
+    if ( streamPtr->device[0] == device || streamPtr->device[1] == device ) {
+      sprintf(message, "RtAudio: no current OS X support for multiple streams accessing the same device!");
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+  }
+
+  // Setup for stream mode.
+  bool isInput = false;
+  AudioDeviceID id = devices[device].id[0];
+  if ( mode == INPUT ) isInput = true;
+
+  // Search for a stream which contains the desired number of channels.
+  OSStatus err = noErr;
+  UInt32 dataSize;
+  unsigned int deviceChannels, nStreams;
+  UInt32 iChannel = 0, iStream = 0;
+  AudioBufferList      *bufferList = nil;
+  err = AudioDeviceGetPropertyInfo( id, 0, isInput,
+                                    kAudioDevicePropertyStreamConfiguration,
+                                    &dataSize, NULL );
+
+  if (err == noErr && dataSize > 0) {
+    bufferList = (AudioBufferList *) malloc( dataSize );
+    if (bufferList == NULL) {
+      sprintf(message, "RtAudio: memory allocation error!");
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+    err = AudioDeviceGetProperty( id, 0, isInput,
+                                  kAudioDevicePropertyStreamConfiguration,
+                                  &dataSize, bufferList );
+
+    if (err == noErr) {
+      stream->deInterleave[mode] = false;
+      nStreams = bufferList->mNumberBuffers;
+      for ( iStream=0; iStream<nStreams; iStream++ ) {
+        if ( bufferList->mBuffers[iStream].mNumberChannels >= (unsigned int) channels ) break;
+        iChannel += bufferList->mBuffers[iStream].mNumberChannels;
+      }
+      // If we didn't find a single stream above, see if we can meet
+      // the channel specification in mono mode (i.e. using separate
+      // non-interleaved buffers).  This can only work if there are N
+      // consecutive one-channel streams, where N is the number of
+      // desired channels.
+      iChannel = 0;
+      if ( iStream >= nStreams && nStreams >= (unsigned int) channels ) {
+        int counter = 0;
+        for ( iStream=0; iStream<nStreams; iStream++ ) {
+          if ( bufferList->mBuffers[iStream].mNumberChannels == 1 )
+            counter++;
+          else
+            counter = 0;
+          if ( counter == channels ) {
+            iStream -= channels - 1;
+            iChannel -= channels - 1;
+            stream->deInterleave[mode] = true;
+            break;
+          }
+          iChannel += bufferList->mBuffers[iStream].mNumberChannels;
+        }
+      }
+    }
+  }
+  if (err != noErr || dataSize <= 0) {
+    if ( bufferList ) free( bufferList );
+    sprintf( message, "RtAudio: OSX error getting channels for device (%s).", devices[device].name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  if (iStream >= nStreams) {
+    free (bufferList);
+    sprintf( message, "RtAudio: unable to find OSX audio stream on device (%s) for requested channels (%d).",
+             devices[device].name, channels );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // This is ok even for mono mode ... it gets updated later.
+  deviceChannels = bufferList->mBuffers[iStream].mNumberChannels;
+  free (bufferList);
+
+  // Determine the buffer size.
+  AudioValueRange      bufferRange;
+  dataSize = sizeof(AudioValueRange);
+  err = AudioDeviceGetProperty( id, 0, isInput,
+                                kAudioDevicePropertyBufferSizeRange,
+                                &dataSize, &bufferRange);
+  if (err != noErr) {
+    sprintf( message, "RtAudio: OSX error getting buffer size range for device (%s).",
+             devices[device].name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  long bufferBytes = *bufferSize * deviceChannels * formatBytes(RTAUDIO_FLOAT32);
+  if (bufferRange.mMinimum > bufferBytes) bufferBytes = (int) bufferRange.mMinimum;
+  else if (bufferRange.mMaximum < bufferBytes) bufferBytes = (int) bufferRange.mMaximum;
+
+  // Set the buffer size.  For mono mode, I'm assuming we only need to
+  // make this setting for the first channel.
+  UInt32 theSize = (UInt32) bufferBytes;
+  dataSize = sizeof( UInt32);
+  err = AudioDeviceSetProperty(id, NULL, 0, isInput,
+                               kAudioDevicePropertyBufferSize,
+                               dataSize, &theSize);
+  if (err != noErr) {
+    sprintf( message, "RtAudio: OSX error setting the buffer size for device (%s).",
+             devices[device].name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // If attempting to setup a duplex stream, the bufferSize parameter
+  // MUST be the same in both directions!
+  *bufferSize = bufferBytes / ( deviceChannels * formatBytes(RTAUDIO_FLOAT32) );
+  if ( stream->mode == OUTPUT && mode == INPUT && *bufferSize != stream->bufferSize ) {
+    sprintf( message, "RtAudio: OSX error setting buffer size for duplex stream on device (%s).",
+             devices[device].name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  stream->bufferSize = *bufferSize;
+  stream->nBuffers = 1;
+
+  // Set the stream format description.  Do for each channel in mono mode.
+  AudioStreamBasicDescription  description;
+  dataSize = sizeof( AudioStreamBasicDescription );
+  if ( stream->deInterleave[mode] ) nStreams = channels;
+  else nStreams = 1;
+  for ( unsigned int i=0; i<nStreams; i++, iChannel++ ) {
+
+    err = AudioDeviceGetProperty( id, iChannel, isInput,
+                                  kAudioDevicePropertyStreamFormat,
+                                  &dataSize, &description );
+    if (err != noErr) {
+      sprintf( message, "RtAudio: OSX error getting stream format for device (%s).", devices[device].name );
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    // Set the sample rate and data format id.
+    description.mSampleRate = (double) sampleRate;
+    description.mFormatID = kAudioFormatLinearPCM;
+    err = AudioDeviceSetProperty( id, NULL, iChannel, isInput,
+                                  kAudioDevicePropertyStreamFormat,
+                                  dataSize, &description );
+    if (err != noErr) {
+      sprintf( message, "RtAudio: OSX error setting sample rate or data format for device (%s).", devices[device].name );
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+  }
+
+  // Check whether we need byte-swapping (assuming OS X host is big-endian).
+  iChannel -= nStreams;
+  err = AudioDeviceGetProperty( id, iChannel, isInput,
+                                kAudioDevicePropertyStreamFormat,
+                                &dataSize, &description );
+  if (err != noErr) {
+    sprintf( message, "RtAudio: OSX error getting stream format for device (%s).", devices[device].name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  stream->doByteSwap[mode] = false;
+  if ( !description.mFormatFlags & kLinearPCMFormatFlagIsBigEndian )
+    stream->doByteSwap[mode] = true;
+
+  // From the CoreAudio documentation, PCM data must be supplied as
+  // 32-bit floats.
+  stream->userFormat = format;
+  stream->deviceFormat[mode] = RTAUDIO_FLOAT32;
+
+  if ( stream->deInterleave[mode] )
+    stream->nDeviceChannels[mode] = channels;
+  else
+    stream->nDeviceChannels[mode] = description.mChannelsPerFrame;
+  stream->nUserChannels[mode] = channels;
+
+  // Set handle and flags for buffer conversion.
+  stream->handle[mode] = iStream;
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] > 1 && stream->deInterleave[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers.
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL)
+      goto memory_error;
+  }
+
+  if ( stream->deInterleave[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL)
+        goto memory_error;
+
+      // If not de-interleaving, we point stream->deviceBuffer to the
+      // OS X supplied device buffer before doing any necessary data
+      // conversions.  This presents a problem if we have a duplex
+      // stream using one device which needs de-interleaving and
+      // another device which doesn't.  So, save a pointer to our own
+      // device buffer in the CALLBACK_INFO structure.
+      stream->callbackInfo.buffers = stream->deviceBuffer;
+    }
+  }
+
+  stream->sampleRate = sampleRate;
+  stream->device[mode] = device;
+  stream->state = STREAM_STOPPED;
+  stream->callbackInfo.object = (void *) this;
+  stream->callbackInfo.waitTime = (unsigned long) (200000.0 * stream->bufferSize / stream->sampleRate);
+  stream->callbackInfo.device[mode] = id;
+  if ( stream->mode == OUTPUT && mode == INPUT && stream->device[0] == device )
+    // Only one callback procedure per device.
+    stream->mode = DUPLEX;
+  else {
+    err = AudioDeviceAddIOProc( id, callbackHandler, (void *) &stream->callbackInfo );
+    if (err != noErr) {
+      sprintf( message, "RtAudio: OSX error setting callback for device (%s).", devices[device].name );
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+    if ( stream->mode == OUTPUT && mode == INPUT )
+      stream->mode = DUPLEX;
+    else
+      stream->mode = mode;
+  }
+
+  // If we wanted to use property listeners, they would be setup here.
+
+  return SUCCESS;
+
+ memory_error:
+  if (stream->userBuffer) {
+    free(stream->userBuffer);
+    stream->userBuffer = 0;
+  }
+  sprintf(message, "RtAudio: OSX error allocating buffer memory (%s).", devices[device].name);
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: cancelStreamCallback(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->callbackInfo.usingCallback) {
+
+    if (stream->state == STREAM_RUNNING)
+      stopStream( streamId );
+
+    MUTEX_LOCK(&stream->mutex);
+
+    stream->callbackInfo.usingCallback = false;
+    stream->callbackInfo.userData = NULL;
+    stream->state = STREAM_STOPPED;
+    stream->callbackInfo.callback = NULL;
+
+    MUTEX_UNLOCK(&stream->mutex);
+  }
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  AudioDeviceID id;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    id = devices[stream->device[0]].id[0];
+    if (stream->state == STREAM_RUNNING)
+      AudioDeviceStop( id, callbackHandler );
+    AudioDeviceRemoveIOProc( id, callbackHandler );
+  }
+
+  if (stream->mode == INPUT || ( stream->mode == DUPLEX && stream->device[0] != stream->device[1]) ) {
+    id = devices[stream->device[1]].id[0];
+    if (stream->state == STREAM_RUNNING)
+      AudioDeviceStop( id, callbackHandler );
+    AudioDeviceRemoveIOProc( id, callbackHandler );
+  }
+
+  pthread_mutex_destroy(&stream->mutex);
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if ( stream->deInterleave[0] || stream->deInterleave[1] )
+    free(stream->callbackInfo.buffers);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_RUNNING)
+    goto unlock;
+
+  OSStatus err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    err = AudioDeviceStart(devices[stream->device[0]].id[0], callbackHandler);
+    if (err != noErr) {
+      sprintf(message, "RtAudio: OSX error starting callback procedure on device (%s).",
+              devices[stream->device[0]].name);
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || ( stream->mode == DUPLEX && stream->device[0] != stream->device[1]) ) {
+
+    err = AudioDeviceStart(devices[stream->device[1]].id[0], callbackHandler);
+    if (err != noErr) {
+      sprintf(message, "RtAudio: OSX error starting input callback procedure on device (%s).",
+              devices[stream->device[0]].name);
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  stream->callbackInfo.streamId = streamId;
+  stream->state = STREAM_RUNNING;
+  stream->callbackInfo.blockTick = true;
+  stream->callbackInfo.stopStream = false;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  OSStatus err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    err = AudioDeviceStop(devices[stream->device[0]].id[0], callbackHandler);
+    if (err != noErr) {
+      sprintf(message, "RtAudio: OSX error stopping callback procedure on device (%s).",
+              devices[stream->device[0]].name);
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || ( stream->mode == DUPLEX && stream->device[0] != stream->device[1]) ) {
+
+    err = AudioDeviceStop(devices[stream->device[1]].id[0], callbackHandler);
+    if (err != noErr) {
+      sprintf(message, "RtAudio: OSX error stopping input callback procedure on device (%s).",
+              devices[stream->device[0]].name);
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  stopStream( streamId );
+}
+
+// I don't know how this function can be implemented.
+int RtAudio :: streamWillBlock(int streamId)
+{
+  sprintf(message, "RtAudio: streamWillBlock() cannot be implemented for OS X.");
+  error(RtError::WARNING);
+  return 0;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->state == STREAM_STOPPED)
+    return;
+
+  if (stream->callbackInfo.usingCallback) {
+    sprintf(message, "RtAudio: tickStream() should not be used when a callback function is set!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  // Block waiting here until the user data is processed in callbackEvent().
+  while ( stream->callbackInfo.blockTick )
+    usleep(stream->callbackInfo.waitTime);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  stream->callbackInfo.blockTick = true;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: callbackEvent( int streamId, DEVICE_ID deviceId, void *inData, void *outData )
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  CALLBACK_INFO *info;
+  AudioBufferList *inBufferList = (AudioBufferList *) inData;
+  AudioBufferList *outBufferList = (AudioBufferList *) outData;
+
+  if (stream->state == STREAM_STOPPED) return;
+
+  info = (CALLBACK_INFO *) &stream->callbackInfo;
+  if ( !info->usingCallback ) {
+    // Block waiting here until we get new user data in tickStream().
+    while ( !info->blockTick )
+      usleep(info->waitTime);
+  }
+  else if ( info->stopStream ) {
+    // Check if the stream should be stopped (via the previous user
+    // callback return value).  We stop the stream here, rather than
+    // after the function call, so that output data can first be
+    // processed.
+    this->stopStream(info->streamId);
+    return;
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if ( stream->mode == INPUT || ( stream->mode == DUPLEX && deviceId == info->device[1] ) ) {
+
+    if (stream->doConvertBuffer[1]) {
+
+      if ( stream->deInterleave[1] ) {
+        stream->deviceBuffer = (char *) stream->callbackInfo.buffers;
+        int bufferBytes = inBufferList->mBuffers[stream->handle[1]].mDataByteSize;
+        for ( int i=0; i<stream->nDeviceChannels[1]; i++ ) {
+          memcpy(&stream->deviceBuffer[i*bufferBytes],
+                 inBufferList->mBuffers[stream->handle[1]+i].mData, bufferBytes );
+        }
+      }
+      else
+        stream->deviceBuffer = (char *) inBufferList->mBuffers[stream->handle[1]].mData;
+
+      if ( stream->doByteSwap[1] )
+        byteSwapBuffer(stream->deviceBuffer,
+                       stream->bufferSize * stream->nDeviceChannels[1],
+                       stream->deviceFormat[1]);
+      convertStreamBuffer(stream, INPUT);
+
+    }
+    else {
+      memcpy(stream->userBuffer,
+             inBufferList->mBuffers[stream->handle[1]].mData,
+             inBufferList->mBuffers[stream->handle[1]].mDataByteSize );
+
+      if (stream->doByteSwap[1])
+        byteSwapBuffer(stream->userBuffer,
+                       stream->bufferSize * stream->nUserChannels[1],
+                       stream->userFormat);
+    }
+  }
+
+  // Don't invoke the user callback if duplex mode, the input/output
+  // devices are different, and this function is called for the output
+  // device.
+  if ( info->usingCallback && (stream->mode != DUPLEX || deviceId == info->device[1] ) ) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) info->callback;
+    info->stopStream = callback(stream->userBuffer, stream->bufferSize, info->userData);
+  }
+
+  if ( stream->mode == OUTPUT || ( stream->mode == DUPLEX && deviceId == info->device[0] ) ) {
+
+    if (stream->doConvertBuffer[0]) {
+
+      if ( !stream->deInterleave[0] )
+        stream->deviceBuffer = (char *) outBufferList->mBuffers[stream->handle[0]].mData;
+      else
+        stream->deviceBuffer = (char *) stream->callbackInfo.buffers;
+
+      convertStreamBuffer(stream, OUTPUT);
+      if ( stream->doByteSwap[0] )
+        byteSwapBuffer(stream->deviceBuffer,
+                       stream->bufferSize * stream->nDeviceChannels[0],
+                       stream->deviceFormat[0]);
+
+      if ( stream->deInterleave[0] ) {
+        int bufferBytes = outBufferList->mBuffers[stream->handle[0]].mDataByteSize;
+        for ( int i=0; i<stream->nDeviceChannels[0]; i++ ) {
+          memcpy(outBufferList->mBuffers[stream->handle[0]+i].mData,
+                 &stream->deviceBuffer[i*bufferBytes], bufferBytes );
+        }
+      }
+
+    }
+    else {
+      if (stream->doByteSwap[0])
+        byteSwapBuffer(stream->userBuffer,
+                       stream->bufferSize * stream->nUserChannels[0],
+                       stream->userFormat);
+
+      memcpy(outBufferList->mBuffers[stream->handle[0]].mData,
+             stream->userBuffer,
+             outBufferList->mBuffers[stream->handle[0]].mDataByteSize );
+    }
+  }
+
+  if ( !info->usingCallback && (stream->mode != DUPLEX || deviceId == info->device[1] ) )
+    info->blockTick = false;
+
+  MUTEX_UNLOCK(&stream->mutex);
+
+}
+
+void RtAudio :: setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  stream->callbackInfo.callback = (void *) callback;
+  stream->callbackInfo.userData = userData;
+  stream->callbackInfo.usingCallback = true;
+}
+
+//******************** End of __MACOSX_CORE__ *********************//
+
+#elif defined(__LINUX_ALSA__)
+
+#define MAX_DEVICES 16
+
+void RtAudio :: initialize(void)
+{
+  int card, result, device;
+  char name[32];
+  const char *cardId;
+  char deviceNames[MAX_DEVICES][32];
+  snd_ctl_t *handle;
+  snd_ctl_card_info_t *info;
+  snd_ctl_card_info_alloca(&info);
+
+  // Count cards and devices
+  nDevices = 0;
+  card = -1;
+  snd_card_next(&card);
+  while ( card >= 0 ) {
+    sprintf(name, "hw:%d", card);
+    result = snd_ctl_open(&handle, name, 0);
+    if (result < 0) {
+      sprintf(message, "RtAudio: ALSA control open (%i): %s.", card, snd_strerror(result));
+      error(RtError::DEBUG_WARNING);
+      goto next_card;
+               }
+    result = snd_ctl_card_info(handle, info);
+               if (result < 0) {
+      sprintf(message, "RtAudio: ALSA control hardware info (%i): %s.", card, snd_strerror(result));
+      error(RtError::DEBUG_WARNING);
+      goto next_card;
+               }
+    cardId = snd_ctl_card_info_get_id(info);
+               device = -1;
+               while (1) {
+      result = snd_ctl_pcm_next_device(handle, &device);
+                       if (result < 0) {
+        sprintf(message, "RtAudio: ALSA control next device (%i): %s.", card, snd_strerror(result));
+        error(RtError::DEBUG_WARNING);
+        break;
+      }
+                       if (device < 0)
+        break;
+      if ( strlen(cardId) )
+        sprintf( deviceNames[nDevices++], "hw:%s,%d", cardId, device );
+      else
+        sprintf( deviceNames[nDevices++], "hw:%d,%d", card, device );
+      if ( nDevices > MAX_DEVICES ) break;
+    }
+    if ( nDevices > MAX_DEVICES ) break;
+  next_card:
+    snd_ctl_close(handle);
+    snd_card_next(&card);
+  }
+
+  if (nDevices == 0) return;
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Write device ascii identifiers to device structures and then
+  // probe the device capabilities.
+  for (int i=0; i<nDevices; i++) {
+    strncpy(devices[i].name, deviceNames[i], 32);
+    //probeDeviceInfo(&devices[i]);
+  }
+}
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  // No ALSA API functions for default devices.
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  // No ALSA API functions for default devices.
+  return 0;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  int err;
+  int open_mode = SND_PCM_ASYNC;
+  snd_pcm_t *handle;
+  snd_ctl_t *chandle;
+  snd_pcm_stream_t stream;
+       snd_pcm_info_t *pcminfo;
+       snd_pcm_info_alloca(&pcminfo);
+  snd_pcm_hw_params_t *params;
+  snd_pcm_hw_params_alloca(&params);
+  char name[32];
+  char *card;
+
+  // Open the control interface for this card.
+  strncpy( name, info->name, 32 );
+  card = strtok(name, ",");
+  err = snd_ctl_open(&chandle, card, 0);
+  if (err < 0) {
+    sprintf(message, "RtAudio: ALSA control open (%s): %s.", card, snd_strerror(err));
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+  unsigned int dev = (unsigned int) atoi( strtok(NULL, ",") );
+
+  // First try for playback
+  stream = SND_PCM_STREAM_PLAYBACK;
+  snd_pcm_info_set_device(pcminfo, dev);
+  snd_pcm_info_set_subdevice(pcminfo, 0);
+  snd_pcm_info_set_stream(pcminfo, stream);
+
+  if ((err = snd_ctl_pcm_info(chandle, pcminfo)) < 0) {
+    if (err == -ENOENT) {
+      sprintf(message, "RtAudio: ALSA pcm device (%s) doesn't handle output!", info->name);
+      error(RtError::DEBUG_WARNING);
+    }
+    else {
+      sprintf(message, "RtAudio: ALSA snd_ctl_pcm_info error for device (%s) output: %s",
+              info->name, snd_strerror(err));
+      error(RtError::DEBUG_WARNING);
+    }
+    goto capture_probe;
+  }
+
+  err = snd_pcm_open(&handle, info->name, stream, open_mode | SND_PCM_NONBLOCK );
+  if (err < 0) {
+    if ( err == EBUSY )
+      sprintf(message, "RtAudio: ALSA pcm playback device (%s) is busy: %s.",
+              info->name, snd_strerror(err));
+    else
+      sprintf(message, "RtAudio: ALSA pcm playback open (%s) error: %s.",
+              info->name, snd_strerror(err));
+    error(RtError::DEBUG_WARNING);
+    goto capture_probe;
+  }
+
+  // We have an open device ... allocate the parameter structure.
+  err = snd_pcm_hw_params_any(handle, params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA hardware probe error (%s): %s.",
+            info->name, snd_strerror(err));
+    error(RtError::WARNING);
+    goto capture_probe;
+  }
+
+  // Get output channel information.
+  info->minOutputChannels = snd_pcm_hw_params_get_channels_min(params);
+  info->maxOutputChannels = snd_pcm_hw_params_get_channels_max(params);
+
+  snd_pcm_close(handle);
+
+ capture_probe:
+  // Now try for capture
+  stream = SND_PCM_STREAM_CAPTURE;
+  snd_pcm_info_set_stream(pcminfo, stream);
+
+  err = snd_ctl_pcm_info(chandle, pcminfo);
+  snd_ctl_close(chandle);
+  if ( err < 0 ) {
+    if (err == -ENOENT) {
+      sprintf(message, "RtAudio: ALSA pcm device (%s) doesn't handle input!", info->name);
+      error(RtError::DEBUG_WARNING);
+    }
+    else {
+      sprintf(message, "RtAudio: ALSA snd_ctl_pcm_info error for device (%s) input: %s",
+              info->name, snd_strerror(err));
+      error(RtError::DEBUG_WARNING);
+    }
+    if (info->maxOutputChannels == 0)
+      // didn't open for playback either ... device invalid
+      return;
+    goto probe_parameters;
+  }
+
+  err = snd_pcm_open(&handle, info->name, stream, open_mode | SND_PCM_NONBLOCK);
+  if (err < 0) {
+    if ( err == EBUSY )
+      sprintf(message, "RtAudio: ALSA pcm capture device (%s) is busy: %s.",
+              info->name, snd_strerror(err));
+    else
+      sprintf(message, "RtAudio: ALSA pcm capture open (%s) error: %s.",
+              info->name, snd_strerror(err));
+    error(RtError::DEBUG_WARNING);
+    if (info->maxOutputChannels == 0)
+      // didn't open for playback either ... device invalid
+      return;
+    goto probe_parameters;
+  }
+
+  // We have an open capture device ... allocate the parameter structure.
+  err = snd_pcm_hw_params_any(handle, params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA hardware probe error (%s): %s.",
+            info->name, snd_strerror(err));
+    error(RtError::WARNING);
+    if (info->maxOutputChannels > 0)
+      goto probe_parameters;
+    else
+      return;
+  }
+
+  // Get input channel information.
+  info->minInputChannels = snd_pcm_hw_params_get_channels_min(params);
+  info->maxInputChannels = snd_pcm_hw_params_get_channels_max(params);
+
+  snd_pcm_close(handle);
+
+  // If device opens for both playback and capture, we determine the channels.
+  if (info->maxOutputChannels == 0 || info->maxInputChannels == 0)
+    goto probe_parameters;
+
+  info->hasDuplexSupport = true;
+  info->maxDuplexChannels = (info->maxOutputChannels > info->maxInputChannels) ?
+    info->maxInputChannels : info->maxOutputChannels;
+  info->minDuplexChannels = (info->minOutputChannels > info->minInputChannels) ?
+    info->minInputChannels : info->minOutputChannels;
+
+ probe_parameters:
+  // At this point, we just need to figure out the supported data
+  // formats and sample rates.  We'll proceed by opening the device in
+  // the direction with the maximum number of channels, or playback if
+  // they are equal.  This might limit our sample rate options, but so
+  // be it.
+
+  if (info->maxOutputChannels >= info->maxInputChannels)
+    stream = SND_PCM_STREAM_PLAYBACK;
+  else
+    stream = SND_PCM_STREAM_CAPTURE;
+
+  err = snd_pcm_open(&handle, info->name, stream, open_mode);
+  if (err < 0) {
+    sprintf(message, "RtAudio: ALSA pcm (%s) won't reopen during probe: %s.",
+            info->name, snd_strerror(err));
+    error(RtError::WARNING);
+    return;
+  }
+
+  // We have an open device ... allocate the parameter structure.
+  err = snd_pcm_hw_params_any(handle, params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA hardware reopen probe error (%s): %s.",
+            info->name, snd_strerror(err));
+    error(RtError::WARNING);
+    return;
+  }
+
+  // Test a non-standard sample rate to see if continuous rate is supported.
+  int dir = 0;
+  if (snd_pcm_hw_params_test_rate(handle, params, 35500, dir) == 0) {
+    // It appears that continuous sample rate support is available.
+    info->nSampleRates = -1;
+    info->sampleRates[0] = snd_pcm_hw_params_get_rate_min(params, &dir);
+    info->sampleRates[1] = snd_pcm_hw_params_get_rate_max(params, &dir);
+  }
+  else {
+    // No continuous rate support ... test our discrete set of sample rate values.
+    info->nSampleRates = 0;
+    for (int i=0; i<MAX_SAMPLE_RATES; i++) {
+      if (snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0) {
+        info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];
+        info->nSampleRates++;
+      }
+    }
+    if (info->nSampleRates == 0) {
+      snd_pcm_close(handle);
+      return;
+    }
+  }
+
+  // Probe the supported data formats ... we don't care about endian-ness just yet
+  snd_pcm_format_t format;
+  info->nativeFormats = 0;
+  format = SND_PCM_FORMAT_S8;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_SINT8;
+  format = SND_PCM_FORMAT_S16;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_SINT16;
+  format = SND_PCM_FORMAT_S24;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_SINT24;
+  format = SND_PCM_FORMAT_S32;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_SINT32;
+  format = SND_PCM_FORMAT_FLOAT;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_FLOAT32;
+  format = SND_PCM_FORMAT_FLOAT64;
+  if (snd_pcm_hw_params_test_format(handle, params, format) == 0)
+    info->nativeFormats |= RTAUDIO_FLOAT64;
+
+  // Check that we have at least one supported format
+  if (info->nativeFormats == 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA PCM device (%s) data format not supported by RtAudio.",
+            info->name);
+    error(RtError::WARNING);
+    return;
+  }
+
+  // That's all ... close the device and return
+  snd_pcm_close(handle);
+  info->probed = true;
+  return;
+}
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+#if defined(__RTAUDIO_DEBUG__)
+  snd_output_t *out;
+  snd_output_stdio_attach(&out, stderr, 0);
+#endif
+
+  // I'm not using the "plug" interface ... too much inconsistent behavior.
+  const char *name = devices[device].name;
+
+  snd_pcm_stream_t alsa_stream;
+  if (mode == OUTPUT)
+    alsa_stream = SND_PCM_STREAM_PLAYBACK;
+  else
+    alsa_stream = SND_PCM_STREAM_CAPTURE;
+
+  int err;
+  snd_pcm_t *handle;
+  int alsa_open_mode = SND_PCM_ASYNC;
+  err = snd_pcm_open(&handle, name, alsa_stream, alsa_open_mode);
+  if (err < 0) {
+    sprintf(message,"RtAudio: ALSA pcm device (%s) won't open: %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Fill the parameter structure.
+  snd_pcm_hw_params_t *hw_params;
+  snd_pcm_hw_params_alloca(&hw_params);
+  err = snd_pcm_hw_params_any(handle, hw_params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error getting parameter handle (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+#if defined(__RTAUDIO_DEBUG__)
+  fprintf(stderr, "\nRtAudio: ALSA dump hardware params just after device open:\n\n");
+  snd_pcm_hw_params_dump(hw_params, out);
+#endif
+
+
+  // Set access ... try interleaved access first, then non-interleaved
+  if ( !snd_pcm_hw_params_test_access( handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED) ) {
+    err = snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
+  }
+  else if ( !snd_pcm_hw_params_test_access( handle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED) ) {
+               err = snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
+    stream->deInterleave[mode] = true;
+  }
+  else {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA device (%s) access not supported by RtAudio.", name);
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting access ( (%s): %s.", name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Determine how to set the device format.
+  stream->userFormat = format;
+  snd_pcm_format_t device_format;
+
+  if (format == RTAUDIO_SINT8)
+    device_format = SND_PCM_FORMAT_S8;
+  else if (format == RTAUDIO_SINT16)
+    device_format = SND_PCM_FORMAT_S16;
+  else if (format == RTAUDIO_SINT24)
+    device_format = SND_PCM_FORMAT_S24;
+  else if (format == RTAUDIO_SINT32)
+    device_format = SND_PCM_FORMAT_S32;
+  else if (format == RTAUDIO_FLOAT32)
+    device_format = SND_PCM_FORMAT_FLOAT;
+  else if (format == RTAUDIO_FLOAT64)
+    device_format = SND_PCM_FORMAT_FLOAT64;
+
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = format;
+    goto set_format;
+  }
+
+  // The user requested format is not natively supported by the device.
+  device_format = SND_PCM_FORMAT_FLOAT64;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT64;
+    goto set_format;
+  }
+
+  device_format = SND_PCM_FORMAT_FLOAT;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;
+    goto set_format;
+  }
+
+  device_format = SND_PCM_FORMAT_S32;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT32;
+    goto set_format;
+  }
+
+  device_format = SND_PCM_FORMAT_S24;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT24;
+    goto set_format;
+  }
+
+  device_format = SND_PCM_FORMAT_S16;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT16;
+    goto set_format;
+  }
+
+  device_format = SND_PCM_FORMAT_S8;
+  if (snd_pcm_hw_params_test_format(handle, hw_params, device_format) == 0) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT8;
+    goto set_format;
+  }
+
+  // If we get here, no supported format was found.
+  sprintf(message,"RtAudio: ALSA pcm device (%s) data format not supported by RtAudio.", name);
+  snd_pcm_close(handle);
+  error(RtError::WARNING);
+  return FAILURE;
+
+ set_format:
+  err = snd_pcm_hw_params_set_format(handle, hw_params, device_format);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting format (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Determine whether byte-swaping is necessary.
+  stream->doByteSwap[mode] = false;
+  if (device_format != SND_PCM_FORMAT_S8) {
+    err = snd_pcm_format_cpu_endian(device_format);
+    if (err == 0)
+      stream->doByteSwap[mode] = true;
+    else if (err < 0) {
+      snd_pcm_close(handle);
+      sprintf(message, "RtAudio: ALSA error getting format endian-ness (%s): %s.",
+              name, snd_strerror(err));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+  }
+
+  // Set the sample rate.
+  err = snd_pcm_hw_params_set_rate(handle, hw_params, (unsigned int)sampleRate, 0);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting sample rate (%d) on device (%s): %s.",
+            sampleRate, name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Determine the number of channels for this device.  We support a possible
+  // minimum device channel number > than the value requested by the user.
+  stream->nUserChannels[mode] = channels;
+  int device_channels = snd_pcm_hw_params_get_channels_max(hw_params);
+  if (device_channels < channels) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: channels (%d) not supported by device (%s).",
+            channels, name);
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  device_channels = snd_pcm_hw_params_get_channels_min(hw_params);
+  if (device_channels < channels) device_channels = channels;
+  stream->nDeviceChannels[mode] = device_channels;
+
+  // Set the device channels.
+  err = snd_pcm_hw_params_set_channels(handle, hw_params, device_channels);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting channels (%d) on device (%s): %s.",
+            device_channels, name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Set the buffer number, which in ALSA is referred to as the "period".
+  int dir;
+  int periods = numberOfBuffers;
+  // Even though the hardware might allow 1 buffer, it won't work reliably.
+  if (periods < 2) periods = 2;
+  err = snd_pcm_hw_params_get_periods_min(hw_params, &dir);
+  if (err > periods) periods = err;
+  err = snd_pcm_hw_params_get_periods_max(hw_params, &dir);
+  if (err < periods) periods = err;
+
+  err = snd_pcm_hw_params_set_periods(handle, hw_params, periods, 0);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting periods (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Set the buffer (or period) size.
+  err = snd_pcm_hw_params_get_period_size_min(hw_params, &dir);
+  if (err > *bufferSize) *bufferSize = err;
+
+  err = snd_pcm_hw_params_set_period_size(handle, hw_params, *bufferSize, 0);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error setting period size (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // If attempting to setup a duplex stream, the bufferSize parameter
+  // MUST be the same in both directions!
+  if ( stream->mode == OUTPUT && mode == INPUT && *bufferSize != stream->bufferSize ) {
+    sprintf( message, "RtAudio: ALSA error setting buffer size for duplex stream on device (%s).",
+             name );
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  stream->bufferSize = *bufferSize;
+
+  // Install the hardware configuration
+  err = snd_pcm_hw_params(handle, hw_params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error installing hardware configuration (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+#if defined(__RTAUDIO_DEBUG__)
+  fprintf(stderr, "\nRtAudio: ALSA dump hardware params after installation:\n\n");
+  snd_pcm_hw_params_dump(hw_params, out);
+#endif
+
+  /*
+  // Install the software configuration
+  snd_pcm_sw_params_t *sw_params = NULL;
+  snd_pcm_sw_params_alloca(&sw_params);
+  snd_pcm_sw_params_current(handle, sw_params);
+  err = snd_pcm_sw_params(handle, sw_params);
+  if (err < 0) {
+    snd_pcm_close(handle);
+    sprintf(message, "RtAudio: ALSA error installing software configuration (%s): %s.",
+            name, snd_strerror(err));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+  */
+
+  // Set handle and flags for buffer conversion
+  stream->handle[mode] = handle;
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] > 1 && stream->deInterleave[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL)
+      goto memory_error;
+  }
+
+  if ( stream->doConvertBuffer[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL)
+        goto memory_error;
+    }
+  }
+
+  stream->device[mode] = device;
+  stream->state = STREAM_STOPPED;
+  if ( stream->mode == OUTPUT && mode == INPUT )
+    // We had already set up an output stream.
+    stream->mode = DUPLEX;
+  else
+    stream->mode = mode;
+  stream->nBuffers = periods;
+  stream->sampleRate = sampleRate;
+
+  return SUCCESS;
+
+ memory_error:
+  if (stream->handle[0]) {
+    snd_pcm_close(stream->handle[0]);
+    stream->handle[0] = 0;
+  }
+  if (stream->handle[1]) {
+    snd_pcm_close(stream->handle[1]);
+    stream->handle[1] = 0;
+  }
+  if (stream->userBuffer) {
+    free(stream->userBuffer);
+    stream->userBuffer = 0;
+  }
+  sprintf(message, "RtAudio: ALSA error allocating buffer memory (%s).", name);
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  if (stream->callbackInfo.usingCallback) {
+    pthread_cancel(stream->callbackInfo.thread);
+    pthread_join(stream->callbackInfo.thread, NULL);
+  }
+
+  if (stream->state == STREAM_RUNNING) {
+    if (stream->mode == OUTPUT || stream->mode == DUPLEX)
+      snd_pcm_drop(stream->handle[0]);
+    if (stream->mode == INPUT || stream->mode == DUPLEX)
+      snd_pcm_drop(stream->handle[1]);
+  }
+
+  pthread_mutex_destroy(&stream->mutex);
+
+  if (stream->handle[0])
+    snd_pcm_close(stream->handle[0]);
+
+  if (stream->handle[1])
+    snd_pcm_close(stream->handle[1]);
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if (stream->deviceBuffer)
+    free(stream->deviceBuffer);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  // This method calls snd_pcm_prepare if the device isn't already in that state.
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_RUNNING)
+    goto unlock;
+
+  int err;
+  snd_pcm_state_t state;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    state = snd_pcm_state(stream->handle[0]);
+    if (state != SND_PCM_STATE_PREPARED) {
+      err = snd_pcm_prepare(stream->handle[0]);
+      if (err < 0) {
+        sprintf(message, "RtAudio: ALSA error preparing pcm device (%s): %s.",
+                devices[stream->device[0]].name, snd_strerror(err));
+        MUTEX_UNLOCK(&stream->mutex);
+        error(RtError::DRIVER_ERROR);
+      }
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    state = snd_pcm_state(stream->handle[1]);
+    if (state != SND_PCM_STATE_PREPARED) {
+      err = snd_pcm_prepare(stream->handle[1]);
+      if (err < 0) {
+        sprintf(message, "RtAudio: ALSA error preparing pcm device (%s): %s.",
+                devices[stream->device[1]].name, snd_strerror(err));
+        MUTEX_UNLOCK(&stream->mutex);
+        error(RtError::DRIVER_ERROR);
+      }
+    }
+  }
+  stream->state = STREAM_RUNNING;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_drain(stream->handle[0]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",
+              devices[stream->device[0]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_drain(stream->handle[1]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",
+              devices[stream->device[1]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_drop(stream->handle[0]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",
+              devices[stream->device[0]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_drop(stream->handle[1]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error draining pcm device (%s): %s.",
+              devices[stream->device[1]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+int RtAudio :: streamWillBlock(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  int err = 0, frames = 0;
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_avail_update(stream->handle[0]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error getting available frames for device (%s): %s.",
+              devices[stream->device[0]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  frames = err;
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    err = snd_pcm_avail_update(stream->handle[1]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: ALSA error getting available frames for device (%s): %s.",
+              devices[stream->device[1]].name, snd_strerror(err));
+      MUTEX_UNLOCK(&stream->mutex);
+      error(RtError::DRIVER_ERROR);
+    }
+    if (frames > err) frames = err;
+  }
+
+  frames = stream->bufferSize - frames;
+  if (frames < 0) frames = 0;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+  return frames;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  int stopStream = 0;
+  if (stream->state == STREAM_STOPPED) {
+    if (stream->callbackInfo.usingCallback) usleep(50000); // sleep 50 milliseconds
+    return;
+  }
+  else if (stream->callbackInfo.usingCallback) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) stream->callbackInfo.callback;
+    stopStream = callback(stream->userBuffer, stream->bufferSize, stream->callbackInfo.userData);
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+
+  // The state might change while waiting on a mutex.
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err;
+  char *buffer;
+  int channels;
+  RTAUDIO_FORMAT format;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters and do buffer conversion if necessary.
+    if (stream->doConvertBuffer[0]) {
+      convertStreamBuffer(stream, OUTPUT);
+      buffer = stream->deviceBuffer;
+      channels = stream->nDeviceChannels[0];
+      format = stream->deviceFormat[0];
+    }
+    else {
+      buffer = stream->userBuffer;
+      channels = stream->nUserChannels[0];
+      format = stream->userFormat;
+    }
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[0])
+      byteSwapBuffer(buffer, stream->bufferSize * channels, format);
+
+    // Write samples to device in interleaved/non-interleaved format.
+    if (stream->deInterleave[0]) {
+      void *bufs[channels];
+      size_t offset = stream->bufferSize * formatBytes(format);
+      for (int i=0; i<channels; i++)
+        bufs[i] = (void *) (buffer + (i * offset));
+      err = snd_pcm_writen(stream->handle[0], bufs, stream->bufferSize);
+    }
+    else
+      err = snd_pcm_writei(stream->handle[0], buffer, stream->bufferSize);
+
+    if (err < stream->bufferSize) {
+      // Either an error or underrun occured.
+      if (err == -EPIPE) {
+        snd_pcm_state_t state = snd_pcm_state(stream->handle[0]);
+        if (state == SND_PCM_STATE_XRUN) {
+          sprintf(message, "RtAudio: ALSA underrun detected.");
+          error(RtError::WARNING);
+          err = snd_pcm_prepare(stream->handle[0]);
+          if (err < 0) {
+            sprintf(message, "RtAudio: ALSA error preparing handle after underrun: %s.",
+                    snd_strerror(err));
+            MUTEX_UNLOCK(&stream->mutex);
+            error(RtError::DRIVER_ERROR);
+          }
+        }
+        else {
+          sprintf(message, "RtAudio: ALSA error, current state is %s.",
+                  snd_pcm_state_name(state));
+          MUTEX_UNLOCK(&stream->mutex);
+          error(RtError::DRIVER_ERROR);
+        }
+        goto unlock;
+      }
+      else {
+        sprintf(message, "RtAudio: ALSA audio write error for device (%s): %s.",
+                devices[stream->device[0]].name, snd_strerror(err));
+        MUTEX_UNLOCK(&stream->mutex);
+        error(RtError::DRIVER_ERROR);
+      }
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters.
+    if (stream->doConvertBuffer[1]) {
+      buffer = stream->deviceBuffer;
+      channels = stream->nDeviceChannels[1];
+      format = stream->deviceFormat[1];
+    }
+    else {
+      buffer = stream->userBuffer;
+      channels = stream->nUserChannels[1];
+      format = stream->userFormat;
+    }
+
+    // Read samples from device in interleaved/non-interleaved format.
+    if (stream->deInterleave[1]) {
+      void *bufs[channels];
+      size_t offset = stream->bufferSize * formatBytes(format);
+      for (int i=0; i<channels; i++)
+        bufs[i] = (void *) (buffer + (i * offset));
+      err = snd_pcm_readn(stream->handle[1], bufs, stream->bufferSize);
+    }
+    else
+      err = snd_pcm_readi(stream->handle[1], buffer, stream->bufferSize);
+
+    if (err < stream->bufferSize) {
+      // Either an error or underrun occured.
+      if (err == -EPIPE) {
+        snd_pcm_state_t state = snd_pcm_state(stream->handle[1]);
+        if (state == SND_PCM_STATE_XRUN) {
+          sprintf(message, "RtAudio: ALSA overrun detected.");
+          error(RtError::WARNING);
+          err = snd_pcm_prepare(stream->handle[1]);
+          if (err < 0) {
+            sprintf(message, "RtAudio: ALSA error preparing handle after overrun: %s.",
+                    snd_strerror(err));
+            MUTEX_UNLOCK(&stream->mutex);
+            error(RtError::DRIVER_ERROR);
+          }
+        }
+        else {
+          sprintf(message, "RtAudio: ALSA error, current state is %s.",
+                  snd_pcm_state_name(state));
+          MUTEX_UNLOCK(&stream->mutex);
+          error(RtError::DRIVER_ERROR);
+        }
+        goto unlock;
+      }
+      else {
+        sprintf(message, "RtAudio: ALSA audio read error for device (%s): %s.",
+                devices[stream->device[1]].name, snd_strerror(err));
+        MUTEX_UNLOCK(&stream->mutex);
+        error(RtError::DRIVER_ERROR);
+      }
+    }
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[1])
+      byteSwapBuffer(buffer, stream->bufferSize * channels, format);
+
+    // Do buffer conversion if necessary.
+    if (stream->doConvertBuffer[1])
+      convertStreamBuffer(stream, INPUT);
+  }
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+
+  if (stream->callbackInfo.usingCallback && stopStream)
+    this->stopStream(streamId);
+}
+
+extern "C" void *callbackHandler(void *ptr)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) ptr;
+  RtAudio *object = (RtAudio *) info->object;
+  int stream = info->streamId;
+  bool *usingCallback = &info->usingCallback;
+
+  while ( *usingCallback ) {
+    pthread_testcancel();
+    try {
+      object->tickStream(stream);
+    }
+    catch (RtError &exception) {
+      fprintf(stderr, "\nRtAudio: Callback thread error (%s) ... closing thread.\n\n",
+              exception.getMessage());
+      break;
+    }
+  }
+
+  return 0;
+}
+
+//******************** End of __LINUX_ALSA__ *********************//
+
+#elif defined(__LINUX_OSS__)
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/soundcard.h>
+#include <errno.h>
+#include <math.h>
+
+#define DAC_NAME "/dev/dsp"
+#define MAX_DEVICES 16
+#define MAX_CHANNELS 16
+
+void RtAudio :: initialize(void)
+{
+  // Count cards and devices
+  nDevices = 0;
+
+  // We check /dev/dsp before probing devices.  /dev/dsp is supposed to
+  // be a link to the "default" audio device, of the form /dev/dsp0,
+  // /dev/dsp1, etc...  However, I've seen many cases where /dev/dsp was a
+  // real device, so we need to check for that.  Also, sometimes the
+  // link is to /dev/dspx and other times just dspx.  I'm not sure how
+  // the latter works, but it does.
+  char device_name[16];
+  struct stat dspstat;
+  int dsplink = -1;
+  int i = 0;
+  if (lstat(DAC_NAME, &dspstat) == 0) {
+    if (S_ISLNK(dspstat.st_mode)) {
+      i = readlink(DAC_NAME, device_name, sizeof(device_name));
+      if (i > 0) {
+        device_name[i] = '\0';
+        if (i > 8) { // check for "/dev/dspx"
+          if (!strncmp(DAC_NAME, device_name, 8))
+            dsplink = atoi(&device_name[8]);
+        }
+        else if (i > 3) { // check for "dspx"
+          if (!strncmp("dsp", device_name, 3))
+            dsplink = atoi(&device_name[3]);
+        }
+      }
+      else {
+        sprintf(message, "RtAudio: cannot read value of symbolic link %s.", DAC_NAME);
+        error(RtError::SYSTEM_ERROR);
+      }
+    }
+  }
+  else {
+    sprintf(message, "RtAudio: cannot stat %s.", DAC_NAME);
+    error(RtError::SYSTEM_ERROR);
+  }
+
+  // The OSS API doesn't provide a routine for determining the number
+  // of devices.  Thus, we'll just pursue a brute force method.  The
+  // idea is to start with /dev/dsp(0) and continue with higher device
+  // numbers until we reach MAX_DSP_DEVICES.  This should tell us how
+  // many devices we have ... it is not a fullproof scheme, but hopefully
+  // it will work most of the time.
+
+  int fd = 0;
+  char names[MAX_DEVICES][16];
+  for (i=-1; i<MAX_DEVICES; i++) {
+
+    // Probe /dev/dsp first, since it is supposed to be the default device.
+    if (i == -1)
+      sprintf(device_name, "%s", DAC_NAME);
+    else if (i == dsplink)
+      continue; // We've aready probed this device via /dev/dsp link ... try next device.
+    else
+      sprintf(device_name, "%s%d", DAC_NAME, i);
+
+    // First try to open the device for playback, then record mode.
+    fd = open(device_name, O_WRONLY | O_NONBLOCK);
+    if (fd == -1) {
+      // Open device for playback failed ... either busy or doesn't exist.
+      if (errno != EBUSY && errno != EAGAIN) {
+        // Try to open for capture
+        fd = open(device_name, O_RDONLY | O_NONBLOCK);
+        if (fd == -1) {
+          // Open device for record failed.
+          if (errno != EBUSY && errno != EAGAIN)
+            continue;
+          else {
+            sprintf(message, "RtAudio: OSS record device (%s) is busy.", device_name);
+            error(RtError::WARNING);
+            // still count it for now
+          }
+        }
+      }
+      else {
+        sprintf(message, "RtAudio: OSS playback device (%s) is busy.", device_name);
+        error(RtError::WARNING);
+        // still count it for now
+      }
+    }
+
+    if (fd >= 0) close(fd);
+    strncpy(names[nDevices], device_name, 16);
+    nDevices++;
+  }
+
+  if (nDevices == 0) return;
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Write device ascii identifiers to device control structure and then probe capabilities.
+  for (i=0; i<nDevices; i++) {
+    strncpy(devices[i].name, names[i], 16);
+    //probeDeviceInfo(&devices[i]);
+  }
+
+  return;
+}
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  // No OSS API functions for default devices.
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  // No OSS API functions for default devices.
+  return 0;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  int i, fd, channels, mask;
+
+  // The OSS API doesn't provide a means for probing the capabilities
+  // of devices.  Thus, we'll just pursue a brute force method.
+
+  // First try for playback
+  fd = open(info->name, O_WRONLY | O_NONBLOCK);
+  if (fd == -1) {
+    // Open device failed ... either busy or doesn't exist
+    if (errno == EBUSY || errno == EAGAIN)
+      sprintf(message, "RtAudio: OSS playback device (%s) is busy and cannot be probed.",
+              info->name);
+    else
+      sprintf(message, "RtAudio: OSS playback device (%s) open error.", info->name);
+    error(RtError::DEBUG_WARNING);
+    goto capture_probe;
+  }
+
+  // We have an open device ... see how many channels it can handle
+  for (i=MAX_CHANNELS; i>0; i--) {
+    channels = i;
+    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
+      // This would normally indicate some sort of hardware error, but under ALSA's
+      // OSS emulation, it sometimes indicates an invalid channel value.  Further,
+      // the returned channel value is not changed. So, we'll ignore the possible
+      // hardware error.
+      continue; // try next channel number
+    }
+    // Check to see whether the device supports the requested number of channels
+    if (channels != i ) continue; // try next channel number
+    // If here, we found the largest working channel value
+    break;
+  }
+  info->maxOutputChannels = i;
+
+  // Now find the minimum number of channels it can handle
+  for (i=1; i<=info->maxOutputChannels; i++) {
+    channels = i;
+    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)
+      continue; // try next channel number
+    // If here, we found the smallest working channel value
+    break;
+  }
+  info->minOutputChannels = i;
+  close(fd);
+
+ capture_probe:
+  // Now try for capture
+  fd = open(info->name, O_RDONLY | O_NONBLOCK);
+  if (fd == -1) {
+    // Open device for capture failed ... either busy or doesn't exist
+    if (errno == EBUSY || errno == EAGAIN)
+      sprintf(message, "RtAudio: OSS capture device (%s) is busy and cannot be probed.",
+              info->name);
+    else
+      sprintf(message, "RtAudio: OSS capture device (%s) open error.", info->name);
+    error(RtError::DEBUG_WARNING);
+    if (info->maxOutputChannels == 0)
+      // didn't open for playback either ... device invalid
+      return;
+    goto probe_parameters;
+  }
+
+  // We have the device open for capture ... see how many channels it can handle
+  for (i=MAX_CHANNELS; i>0; i--) {
+    channels = i;
+    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i) {
+      continue; // as above
+    }
+    // If here, we found a working channel value
+    break;
+  }
+  info->maxInputChannels = i;
+
+  // Now find the minimum number of channels it can handle
+  for (i=1; i<=info->maxInputChannels; i++) {
+    channels = i;
+    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)
+      continue; // try next channel number
+    // If here, we found the smallest working channel value
+    break;
+  }
+  info->minInputChannels = i;
+  close(fd);
+
+  if (info->maxOutputChannels == 0 && info->maxInputChannels == 0) {
+    sprintf(message, "RtAudio: OSS device (%s) reports zero channels for input and output.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // If device opens for both playback and capture, we determine the channels.
+  if (info->maxOutputChannels == 0 || info->maxInputChannels == 0)
+    goto probe_parameters;
+
+  fd = open(info->name, O_RDWR | O_NONBLOCK);
+  if (fd == -1)
+    goto probe_parameters;
+
+  ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
+  ioctl(fd, SNDCTL_DSP_GETCAPS, &mask);
+  if (mask & DSP_CAP_DUPLEX) {
+    info->hasDuplexSupport = true;
+    // We have the device open for duplex ... see how many channels it can handle
+    for (i=MAX_CHANNELS; i>0; i--) {
+      channels = i;
+      if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)
+        continue; // as above
+      // If here, we found a working channel value
+      break;
+    }
+    info->maxDuplexChannels = i;
+
+    // Now find the minimum number of channels it can handle
+    for (i=1; i<=info->maxDuplexChannels; i++) {
+      channels = i;
+      if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i)
+        continue; // try next channel number
+      // If here, we found the smallest working channel value
+      break;
+    }
+    info->minDuplexChannels = i;
+  }
+  close(fd);
+
+ probe_parameters:
+  // At this point, we need to figure out the supported data formats
+  // and sample rates.  We'll proceed by openning the device in the
+  // direction with the maximum number of channels, or playback if
+  // they are equal.  This might limit our sample rate options, but so
+  // be it.
+
+  if (info->maxOutputChannels >= info->maxInputChannels) {
+    fd = open(info->name, O_WRONLY | O_NONBLOCK);
+    channels = info->maxOutputChannels;
+  }
+  else {
+    fd = open(info->name, O_RDONLY | O_NONBLOCK);
+    channels = info->maxInputChannels;
+  }
+
+  if (fd == -1) {
+    // We've got some sort of conflict ... abort
+    sprintf(message, "RtAudio: OSS device (%s) won't reopen during probe.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // We have an open device ... set to maximum channels.
+  i = channels;
+  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1 || channels != i) {
+    // We've got some sort of conflict ... abort
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) won't revert to previous channel setting.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  if (ioctl(fd, SNDCTL_DSP_GETFMTS, &mask) == -1) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) can't get supported audio formats.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Probe the supported data formats ... we don't care about endian-ness just yet.
+  int format;
+  info->nativeFormats = 0;
+#if defined (AFMT_S32_BE)
+  // This format does not seem to be in the 2.4 kernel version of OSS soundcard.h
+  if (mask & AFMT_S32_BE) {
+    format = AFMT_S32_BE;
+    info->nativeFormats |= RTAUDIO_SINT32;
+  }
+#endif
+#if defined (AFMT_S32_LE)
+  /* This format is not in the 2.4.4 kernel version of OSS soundcard.h */
+  if (mask & AFMT_S32_LE) {
+    format = AFMT_S32_LE;
+    info->nativeFormats |= RTAUDIO_SINT32;
+  }
+#endif
+  if (mask & AFMT_S8) {
+    format = AFMT_S8;
+    info->nativeFormats |= RTAUDIO_SINT8;
+  }
+  if (mask & AFMT_S16_BE) {
+    format = AFMT_S16_BE;
+    info->nativeFormats |= RTAUDIO_SINT16;
+  }
+  if (mask & AFMT_S16_LE) {
+    format = AFMT_S16_LE;
+    info->nativeFormats |= RTAUDIO_SINT16;
+  }
+
+  // Check that we have at least one supported format
+  if (info->nativeFormats == 0) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) data format not supported by RtAudio.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Set the format
+  i = format;
+  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1 || format != i) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) error setting data format.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Probe the supported sample rates ... first get lower limit
+  int speed = 1;
+  if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {
+    // If we get here, we're probably using an ALSA driver with OSS-emulation,
+    // which doesn't conform to the OSS specification.  In this case,
+    // we'll probe our predefined list of sample rates for working values.
+    info->nSampleRates = 0;
+    for (i=0; i<MAX_SAMPLE_RATES; i++) {
+      speed = SAMPLE_RATES[i];
+      if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) != -1) {
+        info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];
+        info->nSampleRates++;
+      }
+    }
+    if (info->nSampleRates == 0) {
+      close(fd);
+      return;
+    }
+    goto finished;
+  }
+  info->sampleRates[0] = speed;
+
+  // Now get upper limit
+  speed = 1000000;
+  if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) error setting sample rate.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+  info->sampleRates[1] = speed;
+  info->nSampleRates = -1;
+
+ finished: // That's all ... close the device and return
+  close(fd);
+  info->probed = true;
+  return;
+}
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+  int buffers, buffer_bytes, device_channels, device_format;
+  int srate, temp, fd;
+
+  const char *name = devices[device].name;
+
+  if (mode == OUTPUT)
+    fd = open(name, O_WRONLY | O_NONBLOCK);
+  else { // mode == INPUT
+    if (stream->mode == OUTPUT && stream->device[0] == device) {
+      // We just set the same device for playback ... close and reopen for duplex (OSS only).
+      close(stream->handle[0]);
+      stream->handle[0] = 0;
+      // First check that the number previously set channels is the same.
+      if (stream->nUserChannels[0] != channels) {
+        sprintf(message, "RtAudio: input/output channels must be equal for OSS duplex device (%s).", name);
+        goto error;
+      }
+      fd = open(name, O_RDWR | O_NONBLOCK);
+    }
+    else
+      fd = open(name, O_RDONLY | O_NONBLOCK);
+  }
+
+  if (fd == -1) {
+    if (errno == EBUSY || errno == EAGAIN)
+      sprintf(message, "RtAudio: OSS device (%s) is busy and cannot be opened.",
+              name);
+    else
+      sprintf(message, "RtAudio: OSS device (%s) cannot be opened.", name);
+    goto error;
+  }
+
+  // Now reopen in blocking mode.
+  close(fd);
+  if (mode == OUTPUT)
+    fd = open(name, O_WRONLY | O_SYNC);
+  else { // mode == INPUT
+    if (stream->mode == OUTPUT && stream->device[0] == device)
+      fd = open(name, O_RDWR | O_SYNC);
+    else
+      fd = open(name, O_RDONLY | O_SYNC);
+  }
+
+  if (fd == -1) {
+    sprintf(message, "RtAudio: OSS device (%s) cannot be opened.", name);
+    goto error;
+  }
+
+  // Get the sample format mask
+  int mask;
+  if (ioctl(fd, SNDCTL_DSP_GETFMTS, &mask) == -1) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) can't get supported audio formats.",
+            name);
+    goto error;
+  }
+
+  // Determine how to set the device format.
+  stream->userFormat = format;
+  device_format = -1;
+  stream->doByteSwap[mode] = false;
+  if (format == RTAUDIO_SINT8) {
+    if (mask & AFMT_S8) {
+      device_format = AFMT_S8;
+      stream->deviceFormat[mode] = RTAUDIO_SINT8;
+    }
+  }
+  else if (format == RTAUDIO_SINT16) {
+    if (mask & AFMT_S16_NE) {
+      device_format = AFMT_S16_NE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+    }
+#if BYTE_ORDER == LITTLE_ENDIAN
+    else if (mask & AFMT_S16_BE) {
+      device_format = AFMT_S16_BE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+      stream->doByteSwap[mode] = true;
+    }
+#else
+    else if (mask & AFMT_S16_LE) {
+      device_format = AFMT_S16_LE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+      stream->doByteSwap[mode] = true;
+    }
+#endif
+  }
+#if defined (AFMT_S32_NE) && defined (AFMT_S32_LE) && defined (AFMT_S32_BE)
+  else if (format == RTAUDIO_SINT32) {
+    if (mask & AFMT_S32_NE) {
+      device_format = AFMT_S32_NE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+    }
+#if BYTE_ORDER == LITTLE_ENDIAN
+    else if (mask & AFMT_S32_BE) {
+      device_format = AFMT_S32_BE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+      stream->doByteSwap[mode] = true;
+    }
+#else
+    else if (mask & AFMT_S32_LE) {
+      device_format = AFMT_S32_LE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+      stream->doByteSwap[mode] = true;
+    }
+#endif
+  }
+#endif
+
+  if (device_format == -1) {
+    // The user requested format is not natively supported by the device.
+    if (mask & AFMT_S16_NE) {
+      device_format = AFMT_S16_NE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+    }
+#if BYTE_ORDER == LITTLE_ENDIAN
+    else if (mask & AFMT_S16_BE) {
+      device_format = AFMT_S16_BE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+      stream->doByteSwap[mode] = true;
+    }
+#else
+    else if (mask & AFMT_S16_LE) {
+      device_format = AFMT_S16_LE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT16;
+      stream->doByteSwap[mode] = true;
+    }
+#endif
+#if defined (AFMT_S32_NE) && defined (AFMT_S32_LE) && defined (AFMT_S32_BE)
+    else if (mask & AFMT_S32_NE) {
+      device_format = AFMT_S32_NE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+    }
+#if BYTE_ORDER == LITTLE_ENDIAN
+    else if (mask & AFMT_S32_BE) {
+      device_format = AFMT_S32_BE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+      stream->doByteSwap[mode] = true;
+    }
+#else
+    else if (mask & AFMT_S32_LE) {
+      device_format = AFMT_S32_LE;
+      stream->deviceFormat[mode] = RTAUDIO_SINT32;
+      stream->doByteSwap[mode] = true;
+    }
+#endif
+#endif
+    else if (mask & AFMT_S8) {
+      device_format = AFMT_S8;
+      stream->deviceFormat[mode] = RTAUDIO_SINT8;
+    }
+  }
+
+  if (stream->deviceFormat[mode] == 0) {
+    // This really shouldn't happen ...
+    close(fd);
+    sprintf(message, "RtAudio: OSS device (%s) data format not supported by RtAudio.",
+            name);
+    goto error;
+  }
+
+  // Determine the number of channels for this device.  Note that the
+  // channel value requested by the user might be < min_X_Channels.
+  stream->nUserChannels[mode] = channels;
+  device_channels = channels;
+  if (mode == OUTPUT) {
+    if (channels < devices[device].minOutputChannels)
+      device_channels = devices[device].minOutputChannels;
+  }
+  else { // mode == INPUT
+    if (stream->mode == OUTPUT && stream->device[0] == device) {
+      // We're doing duplex setup here.
+      if (channels < devices[device].minDuplexChannels)
+        device_channels = devices[device].minDuplexChannels;
+    }
+    else {
+      if (channels < devices[device].minInputChannels)
+        device_channels = devices[device].minInputChannels;
+    }
+  }
+  stream->nDeviceChannels[mode] = device_channels;
+
+  // Attempt to set the buffer size.  According to OSS, the minimum
+  // number of buffers is two.  The supposed minimum buffer size is 16
+  // bytes, so that will be our lower bound.  The argument to this
+  // call is in the form 0xMMMMSSSS (hex), where the buffer size (in
+  // bytes) is given as 2^SSSS and the number of buffers as 2^MMMM.
+  // We'll check the actual value used near the end of the setup
+  // procedure.
+  buffer_bytes = *bufferSize * formatBytes(stream->deviceFormat[mode]) * device_channels;
+  if (buffer_bytes < 16) buffer_bytes = 16;
+  buffers = numberOfBuffers;
+  if (buffers < 2) buffers = 2;
+  temp = ((int) buffers << 16) + (int)(log10((double)buffer_bytes)/log10(2.0));
+  if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &temp)) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error setting fragment size for device (%s).",
+            name);
+    goto error;
+  }
+  stream->nBuffers = buffers;
+
+  // Set the data format.
+  temp = device_format;
+  if (ioctl(fd, SNDCTL_DSP_SETFMT, &device_format) == -1 || device_format != temp) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error setting data format for device (%s).",
+            name);
+    goto error;
+  }
+
+  // Set the number of channels.
+  temp = device_channels;
+  if (ioctl(fd, SNDCTL_DSP_CHANNELS, &device_channels) == -1 || device_channels != temp) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error setting %d channels on device (%s).",
+            temp, name);
+    goto error;
+  }
+
+  // Set the sample rate.
+  srate = sampleRate;
+  temp = srate;
+  if (ioctl(fd, SNDCTL_DSP_SPEED, &srate) == -1) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error setting sample rate = %d on device (%s).",
+            temp, name);
+    goto error;
+  }
+
+  // Verify the sample rate setup worked.
+  if (abs(srate - temp) > 100) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error ... audio device (%s) doesn't support sample rate of %d.",
+            name, temp);
+    goto error;
+  }
+  stream->sampleRate = sampleRate;
+
+  if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &buffer_bytes) == -1) {
+    close(fd);
+    sprintf(message, "RtAudio: OSS error getting buffer size for device (%s).",
+            name);
+    goto error;
+  }
+
+  // Save buffer size (in sample frames).
+  *bufferSize = buffer_bytes / (formatBytes(stream->deviceFormat[mode]) * device_channels);
+  stream->bufferSize = *bufferSize;
+
+  if (mode == INPUT && stream->mode == OUTPUT &&
+      stream->device[0] == device) {
+    // We're doing duplex setup here.
+    stream->deviceFormat[0] = stream->deviceFormat[1];
+    stream->nDeviceChannels[0] = device_channels;
+  }
+
+  // Set flags for buffer conversion
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL) {
+      close(fd);
+      sprintf(message, "RtAudio: OSS error allocating user buffer memory (%s).",
+              name);
+      goto error;
+    }
+  }
+
+  if ( stream->doConvertBuffer[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL) {
+        close(fd);
+        free(stream->userBuffer);
+        sprintf(message, "RtAudio: OSS error allocating device buffer memory (%s).",
+                name);
+        goto error;
+      }
+    }
+  }
+
+  stream->device[mode] = device;
+  stream->handle[mode] = fd;
+  stream->state = STREAM_STOPPED;
+  if ( stream->mode == OUTPUT && mode == INPUT ) {
+    stream->mode = DUPLEX;
+    if (stream->device[0] == device)
+      stream->handle[0] = fd;
+  }
+  else
+    stream->mode = mode;
+
+  return SUCCESS;
+
+ error:
+  if (stream->handle[0]) {
+    close(stream->handle[0]);
+    stream->handle[0] = 0;
+  }
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  if (stream->callbackInfo.usingCallback) {
+    pthread_cancel(stream->callbackInfo.thread);
+    pthread_join(stream->callbackInfo.thread, NULL);
+  }
+
+  if (stream->state == STREAM_RUNNING) {
+    if (stream->mode == OUTPUT || stream->mode == DUPLEX)
+      ioctl(stream->handle[0], SNDCTL_DSP_RESET, 0);
+    if (stream->mode == INPUT || stream->mode == DUPLEX)
+      ioctl(stream->handle[1], SNDCTL_DSP_RESET, 0);
+  }
+
+  pthread_mutex_destroy(&stream->mutex);
+
+  if (stream->handle[0])
+    close(stream->handle[0]);
+
+  if (stream->handle[1])
+    close(stream->handle[1]);
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if (stream->deviceBuffer)
+    free(stream->deviceBuffer);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  stream->state = STREAM_RUNNING;
+
+  // No need to do anything else here ... OSS automatically starts
+  // when fed samples.
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = ioctl(stream->handle[0], SNDCTL_DSP_SYNC, 0);
+    if (err < -1) {
+      sprintf(message, "RtAudio: OSS error stopping device (%s).",
+              devices[stream->device[0]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  else {
+    err = ioctl(stream->handle[1], SNDCTL_DSP_SYNC, 0);
+    if (err < -1) {
+      sprintf(message, "RtAudio: OSS error stopping device (%s).",
+              devices[stream->device[1]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = ioctl(stream->handle[0], SNDCTL_DSP_RESET, 0);
+    if (err < -1) {
+      sprintf(message, "RtAudio: OSS error aborting device (%s).",
+              devices[stream->device[0]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  else {
+    err = ioctl(stream->handle[1], SNDCTL_DSP_RESET, 0);
+    if (err < -1) {
+      sprintf(message, "RtAudio: OSS error aborting device (%s).",
+              devices[stream->device[1]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+int RtAudio :: streamWillBlock(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  int bytes = 0, channels = 0, frames = 0;
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  audio_buf_info info;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    ioctl(stream->handle[0], SNDCTL_DSP_GETOSPACE, &info);
+    bytes = info.bytes;
+    channels = stream->nDeviceChannels[0];
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    ioctl(stream->handle[1], SNDCTL_DSP_GETISPACE, &info);
+    if (stream->mode == DUPLEX ) {
+      bytes = (bytes < info.bytes) ? bytes : info.bytes;
+      channels = stream->nDeviceChannels[0];
+    }
+    else {
+      bytes = info.bytes;
+      channels = stream->nDeviceChannels[1];
+    }
+  }
+
+  frames = (int) (bytes / (channels * formatBytes(stream->deviceFormat[0])));
+  frames -= stream->bufferSize;
+  if (frames < 0) frames = 0;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+  return frames;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  int stopStream = 0;
+  if (stream->state == STREAM_STOPPED) {
+    if (stream->callbackInfo.usingCallback) usleep(50000); // sleep 50 milliseconds
+    return;
+  }
+  else if (stream->callbackInfo.usingCallback) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) stream->callbackInfo.callback;
+    stopStream = callback(stream->userBuffer, stream->bufferSize, stream->callbackInfo.userData);
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+
+  // The state might change while waiting on a mutex.
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int result;
+  char *buffer;
+  int samples;
+  RTAUDIO_FORMAT format;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters and do buffer conversion if necessary.
+    if (stream->doConvertBuffer[0]) {
+      convertStreamBuffer(stream, OUTPUT);
+      buffer = stream->deviceBuffer;
+      samples = stream->bufferSize * stream->nDeviceChannels[0];
+      format = stream->deviceFormat[0];
+    }
+    else {
+      buffer = stream->userBuffer;
+      samples = stream->bufferSize * stream->nUserChannels[0];
+      format = stream->userFormat;
+    }
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[0])
+      byteSwapBuffer(buffer, samples, format);
+
+    // Write samples to device.
+    result = write(stream->handle[0], buffer, samples * formatBytes(format));
+
+    if (result == -1) {
+      // This could be an underrun, but the basic OSS API doesn't provide a means for determining that.
+      sprintf(message, "RtAudio: OSS audio write error for device (%s).",
+              devices[stream->device[0]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters.
+    if (stream->doConvertBuffer[1]) {
+      buffer = stream->deviceBuffer;
+      samples = stream->bufferSize * stream->nDeviceChannels[1];
+      format = stream->deviceFormat[1];
+    }
+    else {
+      buffer = stream->userBuffer;
+      samples = stream->bufferSize * stream->nUserChannels[1];
+      format = stream->userFormat;
+    }
+
+    // Read samples from device.
+    result = read(stream->handle[1], buffer, samples * formatBytes(format));
+
+    if (result == -1) {
+      // This could be an overrun, but the basic OSS API doesn't provide a means for determining that.
+      sprintf(message, "RtAudio: OSS audio read error for device (%s).",
+              devices[stream->device[1]].name);
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[1])
+      byteSwapBuffer(buffer, samples, format);
+
+    // Do buffer conversion if necessary.
+    if (stream->doConvertBuffer[1])
+      convertStreamBuffer(stream, INPUT);
+  }
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+
+  if (stream->callbackInfo.usingCallback && stopStream)
+    this->stopStream(streamId);
+}
+
+extern "C" void *callbackHandler(void *ptr)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) ptr;
+  RtAudio *object = (RtAudio *) info->object;
+  int stream = info->streamId;
+  bool *usingCallback = &info->usingCallback;
+
+  while ( *usingCallback ) {
+    pthread_testcancel();
+    try {
+      object->tickStream(stream);
+    }
+    catch (RtError &exception) {
+      fprintf(stderr, "\nRtAudio: Callback thread error (%s) ... closing thread.\n\n",
+              exception.getMessage());
+      break;
+    }
+  }
+
+  return 0;
+}
+
+
+//******************** End of __LINUX_OSS__ *********************//
+
+#elif defined(__WINDOWS_ASIO__) // ASIO API on Windows
+
+// The ASIO API is designed around a callback scheme, so this
+// implementation is similar to that used for OS X CoreAudio.  The
+// primary constraint with ASIO is that it only allows access to a
+// single driver at a time.  Thus, it is not possible to have more
+// than one simultaneous RtAudio stream.
+//
+// This implementation also requires a number of external ASIO files
+// and a few global variables.  The ASIO callback scheme does not
+// allow for the passing of user data, so we must create a global
+// pointer to our callbackInfo structure.
+
+#include "asio/asiosys.h"
+#include "asio/asio.h"
+#include "asio/asiodrivers.h"
+#include <math.h>
+
+AsioDrivers drivers;
+ASIOCallbacks asioCallbacks;
+CALLBACK_INFO *asioCallbackInfo;
+ASIODriverInfo driverInfo;
+
+void RtAudio :: initialize(void)
+{
+  nDevices = drivers.asioGetNumDev();
+  if (nDevices <= 0) return;
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Write device driver names to device structures and then probe the
+  // device capabilities.
+  for (int i=0; i<nDevices; i++) {
+    if ( drivers.asioGetDriverName( i, devices[i].name, 128 ) == 0 )
+      //probeDeviceInfo(&devices[i]);
+      ;
+    else {
+      sprintf(message, "RtAudio: error getting ASIO driver name for device index %d!", i);
+      error(RtError::WARNING);
+    }
+  }
+
+  drivers.removeCurrentDriver();
+  driverInfo.asioVersion = 2;
+  // See note in DirectSound implementation about GetDesktopWindow().
+  driverInfo.sysRef = GetForegroundWindow();
+}
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  return 0;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  // Don't probe if a stream is already open.
+  if ( streams.size() > 0 ) {
+    sprintf(message, "RtAudio: unable to probe ASIO driver while a stream is open.");
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  if ( !drivers.loadDriver( info->name ) ) {
+    sprintf(message, "RtAudio: ASIO error loading driver (%s).", info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  ASIOError result = ASIOInit( &driverInfo );
+  if ( result != ASE_OK ) {
+    char details[32];
+    if ( result == ASE_HWMalfunction )
+      sprintf(details, "hardware malfunction");
+    else if ( result == ASE_NoMemory )
+      sprintf(details, "no memory");
+    else if ( result == ASE_NotPresent )
+      sprintf(details, "driver/hardware not present");
+    else
+      sprintf(details, "unspecified");
+    sprintf(message, "RtAudio: ASIO error (%s) initializing driver (%s).", details, info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Determine the device channel information.
+  long inputChannels, outputChannels;
+  result = ASIOGetChannels( &inputChannels, &outputChannels );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO error getting input/output channel count (%s).", info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  info->maxOutputChannels = outputChannels;
+  if ( outputChannels > 0 ) info->minOutputChannels = 1;
+
+  info->maxInputChannels = inputChannels;
+  if ( inputChannels > 0 ) info->minInputChannels = 1;
+
+  // If device opens for both playback and capture, we determine the channels.
+  if (info->maxOutputChannels > 0 && info->maxInputChannels > 0) {
+    info->hasDuplexSupport = true;
+    info->maxDuplexChannels = (info->maxOutputChannels > info->maxInputChannels) ?
+      info->maxInputChannels : info->maxOutputChannels;
+    info->minDuplexChannels = (info->minOutputChannels > info->minInputChannels) ?
+      info->minInputChannels : info->minOutputChannels;
+  }
+
+  // Determine the supported sample rates.
+  info->nSampleRates = 0;
+  for (int i=0; i<MAX_SAMPLE_RATES; i++) {
+    result = ASIOCanSampleRate( (ASIOSampleRate) SAMPLE_RATES[i] );
+    if ( result == ASE_OK )
+      info->sampleRates[info->nSampleRates++] = SAMPLE_RATES[i];
+  }
+
+  if (info->nSampleRates == 0) {
+    drivers.removeCurrentDriver();
+    sprintf( message, "RtAudio: No supported sample rates found for ASIO driver (%s).", info->name );
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  // Determine supported data types ... just check first channel and assume rest are the same.
+  ASIOChannelInfo channelInfo;
+  channelInfo.channel = 0;
+  channelInfo.isInput = true;
+  if ( info->maxInputChannels <= 0 ) channelInfo.isInput = false;
+  result = ASIOGetChannelInfo( &channelInfo );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO error getting driver (%s) channel information.", info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  if ( channelInfo.type == ASIOSTInt16MSB || channelInfo.type == ASIOSTInt16LSB )
+    info->nativeFormats |= RTAUDIO_SINT16;
+  else if ( channelInfo.type == ASIOSTInt32MSB || channelInfo.type == ASIOSTInt32LSB )
+    info->nativeFormats |= RTAUDIO_SINT32;
+  else if ( channelInfo.type == ASIOSTFloat32MSB || channelInfo.type == ASIOSTFloat32LSB )
+    info->nativeFormats |= RTAUDIO_FLOAT32;
+  else if ( channelInfo.type == ASIOSTFloat64MSB || channelInfo.type == ASIOSTFloat64LSB )
+    info->nativeFormats |= RTAUDIO_FLOAT64;
+
+       // Check that we have at least one supported format.
+  if (info->nativeFormats == 0) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) data format not supported by RtAudio.",
+            info->name);
+    error(RtError::DEBUG_WARNING);
+    return;
+  }
+
+  info->probed = true;
+  drivers.removeCurrentDriver();
+}
+
+void bufferSwitch(long index, ASIOBool processNow)
+{
+  RtAudio *object = (RtAudio *) asioCallbackInfo->object;
+  try {
+    object->callbackEvent( asioCallbackInfo->streamId, index, (void *)NULL, (void *)NULL );
+  }
+  catch (RtError &exception) {
+    fprintf(stderr, "\nCallback handler error (%s)!\n\n", exception.getMessage());
+    return;
+  }
+
+  return;
+}
+
+void sampleRateChanged(ASIOSampleRate sRate)
+{
+  // The ASIO documentation says that this usually only happens during
+  // external sync.  Audio processing is not stopped by the driver,
+  // actual sample rate might not have even changed, maybe only the
+  // sample rate status of an AES/EBU or S/PDIF digital input at the
+  // audio device.
+
+  RtAudio *object = (RtAudio *) asioCallbackInfo->object;
+  try {
+    object->stopStream( asioCallbackInfo->streamId );
+  }
+  catch (RtError &exception) {
+    fprintf(stderr, "\nRtAudio: sampleRateChanged() error (%s)!\n\n", exception.getMessage());
+    return;
+  }
+
+  fprintf(stderr, "\nRtAudio: ASIO driver reports sample rate changed to %d ... stream stopped!!!", (int) sRate);
+}
+
+long asioMessages(long selector, long value, void* message, double* opt)
+{
+  long ret = 0;
+  switch(selector) {
+  case kAsioSelectorSupported:
+    if(value == kAsioResetRequest
+       || value == kAsioEngineVersion
+       || value == kAsioResyncRequest
+       || value == kAsioLatenciesChanged
+       // The following three were added for ASIO 2.0, you don't
+       // necessarily have to support them.
+       || value == kAsioSupportsTimeInfo
+       || value == kAsioSupportsTimeCode
+       || value == kAsioSupportsInputMonitor)
+      ret = 1L;
+    break;
+  case kAsioResetRequest:
+    // Defer the task and perform the reset of the driver during the
+    // next "safe" situation.  You cannot reset the driver right now,
+    // as this code is called from the driver.  Reset the driver is
+    // done by completely destruct is. I.e. ASIOStop(),
+    // ASIODisposeBuffers(), Destruction Afterwards you initialize the
+    // driver again.
+    fprintf(stderr, "\nRtAudio: ASIO driver reset requested!!!");
+    ret = 1L;
+    break;
+  case kAsioResyncRequest:
+    // This informs the application that the driver encountered some
+    // non-fatal data loss.  It is used for synchronization purposes
+    // of different media.  Added mainly to work around the Win16Mutex
+    // problems in Windows 95/98 with the Windows Multimedia system,
+    // which could lose data because the Mutex was held too long by
+    // another thread.  However a driver can issue it in other
+    // situations, too.
+    fprintf(stderr, "\nRtAudio: ASIO driver resync requested!!!");
+    ret = 1L;
+    break;
+  case kAsioLatenciesChanged:
+    // This will inform the host application that the drivers were
+    // latencies changed.  Beware, it this does not mean that the
+    // buffer sizes have changed!  You might need to update internal
+    // delay data.
+    fprintf(stderr, "\nRtAudio: ASIO driver latency may have changed!!!");
+    ret = 1L;
+    break;
+  case kAsioEngineVersion:
+    // Return the supported ASIO version of the host application.  If
+    // a host application does not implement this selector, ASIO 1.0
+    // is assumed by the driver.
+    ret = 2L;
+    break;
+  case kAsioSupportsTimeInfo:
+    // Informs the driver whether the
+    // asioCallbacks.bufferSwitchTimeInfo() callback is supported.
+    // For compatibility with ASIO 1.0 drivers the host application
+    // should always support the "old" bufferSwitch method, too.
+    ret = 0;
+    break;
+  case kAsioSupportsTimeCode:
+    // Informs the driver wether application is interested in time
+    // code info.  If an application does not need to know about time
+    // code, the driver has less work to do.
+    ret = 0;
+    break;
+  }
+  return ret;
+}
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+  // Don't attempt to load another driver if a stream is already open.
+  if ( streams.size() > 0 ) {
+    sprintf(message, "RtAudio: unable to load ASIO driver while a stream is open.");
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // For ASIO, a duplex stream MUST use the same driver.
+  if ( mode == INPUT && stream->mode == OUTPUT && stream->device[0] != device ) {
+    sprintf(message, "RtAudio: ASIO duplex stream must use the same device for input and output.");
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Only load the driver once for duplex stream.
+  ASIOError result;
+  if ( mode != INPUT || stream->mode != OUTPUT ) {
+    if ( !drivers.loadDriver( devices[device].name ) ) {
+      sprintf(message, "RtAudio: ASIO error loading driver (%s).", devices[device].name);
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    result = ASIOInit( &driverInfo );
+    if ( result != ASE_OK ) {
+      char details[32];
+      if ( result == ASE_HWMalfunction )
+        sprintf(details, "hardware malfunction");
+      else if ( result == ASE_NoMemory )
+        sprintf(details, "no memory");
+      else if ( result == ASE_NotPresent )
+        sprintf(details, "driver/hardware not present");
+      else
+        sprintf(details, "unspecified");
+      sprintf(message, "RtAudio: ASIO error (%s) initializing driver (%s).", details, devices[device].name);
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+  }
+
+  // Check the device channel count.
+  long inputChannels, outputChannels;
+  result = ASIOGetChannels( &inputChannels, &outputChannels );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO error getting input/output channel count (%s).",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  if ( ( mode == OUTPUT && channels > outputChannels) ||
+       ( mode == INPUT && channels > inputChannels) ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) does not support requested channel count (%d).",
+            devices[device].name, channels);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+  stream->nDeviceChannels[mode] = channels;
+  stream->nUserChannels[mode] = channels;
+
+  // Verify the sample rate is supported.
+  result = ASIOCanSampleRate( (ASIOSampleRate) sampleRate );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) does not support requested sample rate (%d).",
+            devices[device].name, sampleRate);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // Set the sample rate.
+  result = ASIOSetSampleRate( (ASIOSampleRate) sampleRate );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) error setting sample rate (%d).",
+            devices[device].name, sampleRate);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // Determine the driver data type.
+  ASIOChannelInfo channelInfo;
+  channelInfo.channel = 0;
+  if ( mode == OUTPUT ) channelInfo.isInput = false;
+  else channelInfo.isInput = true;
+  result = ASIOGetChannelInfo( &channelInfo );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) error getting data format.",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // Assuming WINDOWS host is always little-endian.
+  stream->doByteSwap[mode] = false;
+  stream->userFormat = format;
+  stream->deviceFormat[mode] = 0;
+  if ( channelInfo.type == ASIOSTInt16MSB || channelInfo.type == ASIOSTInt16LSB ) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT16;
+    if ( channelInfo.type == ASIOSTInt16MSB ) stream->doByteSwap[mode] = true;
+  }
+  else if ( channelInfo.type == ASIOSTInt32MSB || channelInfo.type == ASIOSTInt32LSB ) {
+    stream->deviceFormat[mode] = RTAUDIO_SINT32;
+    if ( channelInfo.type == ASIOSTInt32MSB ) stream->doByteSwap[mode] = true;
+  }
+  else if ( channelInfo.type == ASIOSTFloat32MSB || channelInfo.type == ASIOSTFloat32LSB ) {
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;
+    if ( channelInfo.type == ASIOSTFloat32MSB ) stream->doByteSwap[mode] = true;
+  }
+  else if ( channelInfo.type == ASIOSTFloat64MSB || channelInfo.type == ASIOSTFloat64LSB ) {
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT64;
+    if ( channelInfo.type == ASIOSTFloat64MSB ) stream->doByteSwap[mode] = true;
+  }
+
+  if ( stream->deviceFormat[mode] == 0 ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) data format not supported by RtAudio.",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // Set the buffer size.  For a duplex stream, this will end up
+  // setting the buffer size based on the input constraints, which
+  // should be ok.
+  long minSize, maxSize, preferSize, granularity;
+  result = ASIOGetBufferSize( &minSize, &maxSize, &preferSize, &granularity );
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) error getting buffer size.",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  if ( *bufferSize < minSize ) *bufferSize = minSize;
+  else if ( *bufferSize > maxSize ) *bufferSize = maxSize;
+  else if ( granularity == -1 ) {
+    // Make sure bufferSize is a power of two.
+    double power = log10( *bufferSize ) / log10( 2.0 );
+    *bufferSize = pow( 2.0, floor(power+0.5) );
+    if ( *bufferSize < minSize ) *bufferSize = minSize;
+    else if ( *bufferSize > maxSize ) *bufferSize = maxSize;
+    else *bufferSize = preferSize;
+  }
+
+  if ( mode == INPUT && stream->mode == OUTPUT && stream->bufferSize != *bufferSize )
+    cout << "possible input/output buffersize discrepancy" << endl;
+
+  stream->bufferSize = *bufferSize;
+  stream->nBuffers = 2;
+
+  // ASIO always uses deinterleaved channels.
+  stream->deInterleave[mode] = true;
+
+  // Create the ASIO internal buffers.  Since RtAudio sets up input
+  // and output separately, we'll have to dispose of previously
+  // created output buffers for a duplex stream.
+  if ( mode == INPUT && stream->mode == OUTPUT ) {
+    free(stream->callbackInfo.buffers);
+    result = ASIODisposeBuffers();
+    if ( result != ASE_OK ) {
+      drivers.removeCurrentDriver();
+      sprintf(message, "RtAudio: ASIO driver (%s) error disposing previously allocated buffers.",
+              devices[device].name);
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+  }
+
+  // Allocate, initialize, and save the bufferInfos in our stream callbackInfo structure.
+  int i, nChannels = stream->nDeviceChannels[0] + stream->nDeviceChannels[1];
+  stream->callbackInfo.buffers = 0;
+  ASIOBufferInfo *bufferInfos = (ASIOBufferInfo *) malloc( nChannels * sizeof(ASIOBufferInfo) );
+  stream->callbackInfo.buffers = (void *) bufferInfos;
+  ASIOBufferInfo *infos = bufferInfos;
+  for ( i=0; i<stream->nDeviceChannels[1]; i++, infos++ ) {
+    infos->isInput = ASIOTrue;
+    infos->channelNum = i;
+    infos->buffers[0] = infos->buffers[1] = 0;
+  }
+
+  for ( i=0; i<stream->nDeviceChannels[0]; i++, infos++ ) {
+    infos->isInput = ASIOFalse;
+    infos->channelNum = i;
+    infos->buffers[0] = infos->buffers[1] = 0;
+  }
+
+  // Set up the ASIO callback structure and create the ASIO data buffers.
+  asioCallbacks.bufferSwitch = &bufferSwitch;
+  asioCallbacks.sampleRateDidChange = &sampleRateChanged;
+  asioCallbacks.asioMessage = &asioMessages;
+  asioCallbacks.bufferSwitchTimeInfo = NULL;
+  result = ASIOCreateBuffers( bufferInfos, nChannels, stream->bufferSize, &asioCallbacks);
+  if ( result != ASE_OK ) {
+    drivers.removeCurrentDriver();
+    sprintf(message, "RtAudio: ASIO driver (%s) error creating buffers.",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  // Set flags for buffer conversion.
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] > 1 && stream->deInterleave[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL)
+      goto memory_error;
+  }
+
+  if ( stream->doConvertBuffer[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL)
+        goto memory_error;
+    }
+  }
+
+  stream->device[mode] = device;
+  stream->state = STREAM_STOPPED;
+  if ( stream->mode == OUTPUT && mode == INPUT )
+    // We had already set up an output stream.
+    stream->mode = DUPLEX;
+  else
+    stream->mode = mode;
+  stream->sampleRate = sampleRate;
+  asioCallbackInfo = &stream->callbackInfo;
+  stream->callbackInfo.object = (void *) this;
+  stream->callbackInfo.waitTime = (unsigned long) (200.0 * stream->bufferSize / stream->sampleRate);
+
+  return SUCCESS;
+
+ memory_error:
+  ASIODisposeBuffers();
+  drivers.removeCurrentDriver();
+
+  if (stream->callbackInfo.buffers)
+    free(stream->callbackInfo.buffers);
+  stream->callbackInfo.buffers = 0;
+
+  if (stream->userBuffer) {
+    free(stream->userBuffer);
+    stream->userBuffer = 0;
+  }
+  sprintf(message, "RtAudio: error allocating buffer memory (%s).",
+          devices[device].name);
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: cancelStreamCallback(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->callbackInfo.usingCallback) {
+
+    if (stream->state == STREAM_RUNNING)
+      stopStream( streamId );
+
+    MUTEX_LOCK(&stream->mutex);
+
+    stream->callbackInfo.usingCallback = false;
+    stream->callbackInfo.userData = NULL;
+    stream->state = STREAM_STOPPED;
+    stream->callbackInfo.callback = NULL;
+
+    MUTEX_UNLOCK(&stream->mutex);
+  }
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  if (stream->state == STREAM_RUNNING)
+    ASIOStop();
+
+  ASIODisposeBuffers();
+  //ASIOExit();
+  drivers.removeCurrentDriver();
+
+  DeleteCriticalSection(&stream->mutex);
+
+  if (stream->callbackInfo.buffers)
+    free(stream->callbackInfo.buffers);
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if (stream->deviceBuffer)
+    free(stream->deviceBuffer);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_RUNNING) {
+    MUTEX_UNLOCK(&stream->mutex);
+    return;
+  }
+
+  stream->callbackInfo.blockTick = true;
+  stream->callbackInfo.stopStream = false;
+  stream->callbackInfo.streamId = streamId;
+  ASIOError result = ASIOStart();
+  if ( result != ASE_OK ) {
+    sprintf(message, "RtAudio: ASIO error starting device (%s).",
+              devices[stream->device[0]].name);
+    MUTEX_UNLOCK(&stream->mutex);
+    error(RtError::DRIVER_ERROR);
+  }
+  stream->state = STREAM_RUNNING;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED) {
+    MUTEX_UNLOCK(&stream->mutex);
+    return;
+  }
+
+  ASIOError result = ASIOStop();
+  if ( result != ASE_OK ) {
+    sprintf(message, "RtAudio: ASIO error stopping device (%s).",
+              devices[stream->device[0]].name);
+    MUTEX_UNLOCK(&stream->mutex);
+    error(RtError::DRIVER_ERROR);
+  }
+  stream->state = STREAM_STOPPED;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  stopStream( streamId );
+}
+
+// I don't know how this function can be implemented.
+int RtAudio :: streamWillBlock(int streamId)
+{
+  sprintf(message, "RtAudio: streamWillBlock() cannot be implemented for ASIO.");
+  error(RtError::WARNING);
+  return 0;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->state == STREAM_STOPPED)
+    return;
+
+  if (stream->callbackInfo.usingCallback) {
+    sprintf(message, "RtAudio: tickStream() should not be used when a callback function is set!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  // Block waiting here until the user data is processed in callbackEvent().
+  while ( stream->callbackInfo.blockTick )
+    Sleep(stream->callbackInfo.waitTime);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  stream->callbackInfo.blockTick = true;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: callbackEvent(int streamId, int bufferIndex, void *inData, void *outData)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  CALLBACK_INFO *info = asioCallbackInfo;
+  if ( !info->usingCallback ) {
+    // Block waiting here until we get new user data in tickStream().
+    while ( !info->blockTick )
+      Sleep(info->waitTime);
+  }
+  else if ( info->stopStream ) {
+    // Check if the stream should be stopped (via the previous user
+    // callback return value).  We stop the stream here, rather than
+    // after the function call, so that output data can first be
+    // processed.
+    this->stopStream(asioCallbackInfo->streamId);
+    return;
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+  int nChannels = stream->nDeviceChannels[0] + stream->nDeviceChannels[1];
+  int bufferBytes;
+  ASIOBufferInfo *bufferInfos = (ASIOBufferInfo *) info->buffers;
+  if ( stream->mode == INPUT || stream->mode == DUPLEX ) {
+
+    bufferBytes = stream->bufferSize * formatBytes(stream->deviceFormat[1]);
+    if (stream->doConvertBuffer[1]) {
+
+      // Always interleave ASIO input data.
+      for ( int i=0; i<stream->nDeviceChannels[1]; i++, bufferInfos++ )
+        memcpy(&stream->deviceBuffer[i*bufferBytes], bufferInfos->buffers[bufferIndex], bufferBytes );
+
+      if ( stream->doByteSwap[1] )
+        byteSwapBuffer(stream->deviceBuffer,
+                       stream->bufferSize * stream->nDeviceChannels[1],
+                       stream->deviceFormat[1]);
+      convertStreamBuffer(stream, INPUT);
+
+    }
+    else { // single channel only
+      memcpy(stream->userBuffer, bufferInfos->buffers[bufferIndex], bufferBytes );
+
+      if (stream->doByteSwap[1])
+        byteSwapBuffer(stream->userBuffer,
+                       stream->bufferSize * stream->nUserChannels[1],
+                       stream->userFormat);
+    }
+  }
+
+  if ( info->usingCallback ) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) info->callback;
+    if ( callback(stream->userBuffer, stream->bufferSize, info->userData) )
+      info->stopStream = true;
+  }
+
+  if ( stream->mode == OUTPUT || stream->mode == DUPLEX ) {
+
+    bufferBytes = stream->bufferSize * formatBytes(stream->deviceFormat[0]);
+    if (stream->doConvertBuffer[0]) {
+
+      convertStreamBuffer(stream, OUTPUT);
+      if ( stream->doByteSwap[0] )
+        byteSwapBuffer(stream->deviceBuffer,
+                       stream->bufferSize * stream->nDeviceChannels[0],
+                       stream->deviceFormat[0]);
+
+      // Always de-interleave ASIO output data.
+      for ( int i=0; i<stream->nDeviceChannels[0]; i++, bufferInfos++ ) {
+        memcpy(bufferInfos->buffers[bufferIndex],
+               &stream->deviceBuffer[i*bufferBytes], bufferBytes );
+      }
+    }
+    else { // single channel only
+
+      if (stream->doByteSwap[0])
+        byteSwapBuffer(stream->userBuffer,
+                       stream->bufferSize * stream->nUserChannels[0],
+                       stream->userFormat);
+
+      memcpy(bufferInfos->buffers[bufferIndex], stream->userBuffer, bufferBytes );
+    }
+  }
+
+  if ( !info->usingCallback )
+    info->blockTick = false;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  stream->callbackInfo.callback = (void *) callback;
+  stream->callbackInfo.userData = userData;
+  stream->callbackInfo.usingCallback = true;
+}
+
+//******************** End of __WINDOWS_ASIO__ *********************//
+
+#elif defined(__WINDOWS_DS__) // Windows DirectSound API
+
+#include <dsound.h>
+
+// Declarations for utility functions, callbacks, and structures
+// specific to the DirectSound implementation.
+static bool CALLBACK deviceCountCallback(LPGUID lpguid,
+                                         LPCSTR lpcstrDescription,
+                                         LPCSTR lpcstrModule,
+                                         LPVOID lpContext);
+
+static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
+                                        LPCSTR lpcstrDescription,
+                                        LPCSTR lpcstrModule,
+                                        LPVOID lpContext);
+
+static bool CALLBACK defaultDeviceCallback(LPGUID lpguid,
+                                           LPCSTR lpcstrDescription,
+                                           LPCSTR lpcstrModule,
+                                           LPVOID lpContext);
+
+static bool CALLBACK deviceIdCallback(LPGUID lpguid,
+                                      LPCSTR lpcstrDescription,
+                                      LPCSTR lpcstrModule,
+                                      LPVOID lpContext);
+
+static char* getErrorString(int code);
+
+struct enum_info {
+  char name[64];
+  LPGUID id;
+  bool isInput;
+  bool isValid;
+};
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  enum_info info;
+  info.name[0] = '\0';
+
+  // Enumerate through devices to find the default output.
+  HRESULT result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)defaultDeviceCallback, &info);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Error performing default input device enumeration: %s.",
+            getErrorString(result));
+    error(RtError::WARNING);
+    return 0;
+  }
+
+  for ( int i=0; i<nDevices; i++ )
+    if ( strncmp( devices[i].name, info.name, 64 ) == 0 ) return i;
+
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  enum_info info;
+  info.name[0] = '\0';
+
+  // Enumerate through devices to find the default output.
+  HRESULT result = DirectSoundEnumerate((LPDSENUMCALLBACK)defaultDeviceCallback, &info);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Error performing default output device enumeration: %s.",
+            getErrorString(result));
+    error(RtError::WARNING);
+    return 0;
+  }
+
+  for ( int i=0; i<nDevices; i++ )
+    if ( strncmp(devices[i].name, info.name, 64 ) == 0 ) return i;
+
+  return 0;
+}
+
+void RtAudio :: initialize(void)
+{
+  int i, ins = 0, outs = 0, count = 0;
+  HRESULT result;
+  nDevices = 0;
+
+  // Count DirectSound devices.
+  result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceCountCallback, &outs);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Unable to enumerate through sound playback devices: %s.",
+            getErrorString(result));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  // Count DirectSoundCapture devices.
+  result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceCountCallback, &ins);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Unable to enumerate through sound capture devices: %s.",
+            getErrorString(result));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  count = ins + outs;
+  if (count == 0) return;
+
+  std::vector<enum_info> info(count);
+  for (i=0; i<count; i++) {
+    info[i].name[0] = '\0';
+    if (i < outs) info[i].isInput = false;
+    else info[i].isInput = true;
+  }
+
+  // Get playback device info and check capabilities.
+  result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceInfoCallback, &info[0]);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Unable to enumerate through sound playback devices: %s.",
+            getErrorString(result));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  // Get capture device info and check capabilities.
+  result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceInfoCallback, &info[0]);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Unable to enumerate through sound capture devices: %s.",
+            getErrorString(result));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  // Parse the devices and check validity.  Devices are considered
+  // invalid if they cannot be opened, they report < 1 supported
+  // channels, or they report no supported data (capture only).
+  for (i=0; i<count; i++)
+    if ( info[i].isValid ) nDevices++;
+
+  if (nDevices == 0) return;
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Copy the names to our devices structures.
+  int index = 0;
+  for (i=0; i<count; i++) {
+    if ( info[i].isValid )
+      strncpy(devices[index++].name, info[i].name, 64);
+  }
+
+  //for (i=0;i<nDevices; i++)
+  //probeDeviceInfo(&devices[i]);
+
+  return;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  enum_info dsinfo;
+  strncpy( dsinfo.name, info->name, 64 );
+  dsinfo.isValid = false;
+
+  // Enumerate through input devices to find the id (if it exists).
+  HRESULT result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceIdCallback, &dsinfo);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Error performing input device id enumeration: %s.",
+            getErrorString(result));
+    error(RtError::WARNING);
+    return;
+  }
+
+  // Do capture probe first.
+  if ( dsinfo.isValid == false )
+    goto playback_probe;
+
+  LPDIRECTSOUNDCAPTURE  input;
+  result = DirectSoundCaptureCreate( dsinfo.id, &input, NULL );
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Could not create DirectSound capture object (%s): %s.",
+            info->name, getErrorString(result));
+    error(RtError::WARNING);
+    goto playback_probe;
+  }
+
+  DSCCAPS in_caps;
+  in_caps.dwSize = sizeof(in_caps);
+  result = input->GetCaps( &in_caps );
+  if ( FAILED(result) ) {
+    input->Release();
+    sprintf(message, "RtAudio: Could not get DirectSound capture capabilities (%s): %s.",
+            info->name, getErrorString(result));
+    error(RtError::WARNING);
+    goto playback_probe;
+  }
+
+  // Get input channel information.
+  info->minInputChannels = 1;
+  info->maxInputChannels = in_caps.dwChannels;
+
+  // Get sample rate and format information.
+  if( in_caps.dwChannels == 2 ) {
+    if( in_caps.dwFormats & WAVE_FORMAT_1S16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_2S16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_4S16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_1S08 ) info->nativeFormats |= RTAUDIO_SINT8;
+    if( in_caps.dwFormats & WAVE_FORMAT_2S08 ) info->nativeFormats |= RTAUDIO_SINT8;
+    if( in_caps.dwFormats & WAVE_FORMAT_4S08 ) info->nativeFormats |= RTAUDIO_SINT8;
+
+    if ( info->nativeFormats & RTAUDIO_SINT16 ) {
+      if( in_caps.dwFormats & WAVE_FORMAT_1S16 ) info->sampleRates[info->nSampleRates++] = 11025;
+      if( in_caps.dwFormats & WAVE_FORMAT_2S16 ) info->sampleRates[info->nSampleRates++] = 22050;
+      if( in_caps.dwFormats & WAVE_FORMAT_4S16 ) info->sampleRates[info->nSampleRates++] = 44100;
+    }
+    else if ( info->nativeFormats & RTAUDIO_SINT8 ) {
+      if( in_caps.dwFormats & WAVE_FORMAT_1S08 ) info->sampleRates[info->nSampleRates++] = 11025;
+      if( in_caps.dwFormats & WAVE_FORMAT_2S08 ) info->sampleRates[info->nSampleRates++] = 22050;
+      if( in_caps.dwFormats & WAVE_FORMAT_4S08 ) info->sampleRates[info->nSampleRates++] = 44100;
+    }
+  }
+  else if ( in_caps.dwChannels == 1 ) {
+    if( in_caps.dwFormats & WAVE_FORMAT_1M16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_2M16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_4M16 ) info->nativeFormats |= RTAUDIO_SINT16;
+    if( in_caps.dwFormats & WAVE_FORMAT_1M08 ) info->nativeFormats |= RTAUDIO_SINT8;
+    if( in_caps.dwFormats & WAVE_FORMAT_2M08 ) info->nativeFormats |= RTAUDIO_SINT8;
+    if( in_caps.dwFormats & WAVE_FORMAT_4M08 ) info->nativeFormats |= RTAUDIO_SINT8;
+
+    if ( info->nativeFormats & RTAUDIO_SINT16 ) {
+      if( in_caps.dwFormats & WAVE_FORMAT_1M16 ) info->sampleRates[info->nSampleRates++] = 11025;
+      if( in_caps.dwFormats & WAVE_FORMAT_2M16 ) info->sampleRates[info->nSampleRates++] = 22050;
+      if( in_caps.dwFormats & WAVE_FORMAT_4M16 ) info->sampleRates[info->nSampleRates++] = 44100;
+    }
+    else if ( info->nativeFormats & RTAUDIO_SINT8 ) {
+      if( in_caps.dwFormats & WAVE_FORMAT_1M08 ) info->sampleRates[info->nSampleRates++] = 11025;
+      if( in_caps.dwFormats & WAVE_FORMAT_2M08 ) info->sampleRates[info->nSampleRates++] = 22050;
+      if( in_caps.dwFormats & WAVE_FORMAT_4M08 ) info->sampleRates[info->nSampleRates++] = 44100;
+    }
+  }
+  else info->minInputChannels = 0; // technically, this would be an error
+
+  input->Release();
+
+ playback_probe:
+
+  dsinfo.isValid = false;
+
+  // Enumerate through output devices to find the id (if it exists).
+  result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceIdCallback, &dsinfo);
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Error performing output device id enumeration: %s.",
+            getErrorString(result));
+    error(RtError::WARNING);
+    return;
+  }
+
+  // Now do playback probe.
+  if ( dsinfo.isValid == false )
+    goto check_parameters;
+
+  LPDIRECTSOUND  output;
+  DSCAPS out_caps;
+  result = DirectSoundCreate( dsinfo.id, &output, NULL );
+  if ( FAILED(result) ) {
+    sprintf(message, "RtAudio: Could not create DirectSound playback object (%s): %s.",
+            info->name, getErrorString(result));
+    error(RtError::WARNING);
+    goto check_parameters;
+  }
+
+  out_caps.dwSize = sizeof(out_caps);
+  result = output->GetCaps( &out_caps );
+  if ( FAILED(result) ) {
+    output->Release();
+    sprintf(message, "RtAudio: Could not get DirectSound playback capabilities (%s): %s.",
+            info->name, getErrorString(result));
+    error(RtError::WARNING);
+    goto check_parameters;
+  }
+
+  // Get output channel information.
+  info->minOutputChannels = 1;
+  info->maxOutputChannels = ( out_caps.dwFlags & DSCAPS_PRIMARYSTEREO ) ? 2 : 1;
+
+  // Get sample rate information.  Use capture device rate information
+  // if it exists.
+  if ( info->nSampleRates == 0 ) {
+    info->sampleRates[0] = (int) out_caps.dwMinSecondarySampleRate;
+    info->sampleRates[1] = (int) out_caps.dwMaxSecondarySampleRate;
+    if ( out_caps.dwFlags & DSCAPS_CONTINUOUSRATE )
+      info->nSampleRates = -1;
+    else if ( out_caps.dwMinSecondarySampleRate == out_caps.dwMaxSecondarySampleRate ) {
+      if ( out_caps.dwMinSecondarySampleRate == 0 ) {
+        // This is a bogus driver report ... fake the range and cross
+        // your fingers.
+        info->sampleRates[0] = 11025;
+                               info->sampleRates[1] = 48000;
+        info->nSampleRates = -1; /* continuous range */
+        sprintf(message, "RtAudio: bogus sample rates reported by DirectSound driver ... using defaults (%s).",
+                info->name);
+        error(RtError::DEBUG_WARNING);
+      }
+      else {
+        info->nSampleRates = 1;
+                       }
+    }
+    else if ( (out_caps.dwMinSecondarySampleRate < 1000.0) &&
+              (out_caps.dwMaxSecondarySampleRate > 50000.0) ) {
+      // This is a bogus driver report ... support for only two
+      // distant rates.  We'll assume this is a range.
+      info->nSampleRates = -1;
+      sprintf(message, "RtAudio: bogus sample rates reported by DirectSound driver ... using range (%s).",
+              info->name);
+      error(RtError::WARNING);
+    }
+    else info->nSampleRates = 2;
+  }
+  else {
+    // Check input rates against output rate range
+    for ( int i=info->nSampleRates-1; i>=0; i-- ) {
+      if ( info->sampleRates[i] <= out_caps.dwMaxSecondarySampleRate )
+        break;
+      info->nSampleRates--;
+    }
+    while ( info->sampleRates[0] < out_caps.dwMinSecondarySampleRate ) {
+      info->nSampleRates--;
+      for ( int i=0; i<info->nSampleRates; i++)
+        info->sampleRates[i] = info->sampleRates[i+1];
+      if ( info->nSampleRates <= 0 ) break;
+    }
+  }
+
+  // Get format information.
+  if ( out_caps.dwFlags & DSCAPS_PRIMARY16BIT ) info->nativeFormats |= RTAUDIO_SINT16;
+  if ( out_caps.dwFlags & DSCAPS_PRIMARY8BIT ) info->nativeFormats |= RTAUDIO_SINT8;
+
+  output->Release();
+
+ check_parameters:
+  if ( info->maxInputChannels == 0 && info->maxOutputChannels == 0 )
+    return;
+  if ( info->nSampleRates == 0 || info->nativeFormats == 0 )
+    return;
+
+  // Determine duplex status.
+  if (info->maxInputChannels < info->maxOutputChannels)
+    info->maxDuplexChannels = info->maxInputChannels;
+  else
+    info->maxDuplexChannels = info->maxOutputChannels;
+  if (info->minInputChannels < info->minOutputChannels)
+    info->minDuplexChannels = info->minInputChannels;
+  else
+    info->minDuplexChannels = info->minOutputChannels;
+
+  if ( info->maxDuplexChannels > 0 ) info->hasDuplexSupport = true;
+  else info->hasDuplexSupport = false;
+
+  info->probed = true;
+
+  return;
+}
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+  HRESULT result;
+  HWND hWnd = GetForegroundWindow();
+  // According to a note in PortAudio, using GetDesktopWindow()
+  // instead of GetForegroundWindow() is supposed to avoid problems
+  // that occur when the application's window is not the foreground
+  // window.  Also, if the application window closes before the
+  // DirectSound buffer, DirectSound can crash.  However, for console
+  // applications, no sound was produced when using GetDesktopWindow().
+  long buffer_size;
+  LPVOID audioPtr;
+  DWORD dataLen;
+  int nBuffers;
+
+  // Check the numberOfBuffers parameter and limit the lowest value to
+  // two.  This is a judgement call and a value of two is probably too
+  // low for capture, but it should work for playback.
+  if (numberOfBuffers < 2)
+    nBuffers = 2;
+  else
+    nBuffers = numberOfBuffers;
+
+  // Define the wave format structure (16-bit PCM, srate, channels)
+  WAVEFORMATEX waveFormat;
+  ZeroMemory(&waveFormat, sizeof(WAVEFORMATEX));
+  waveFormat.wFormatTag = WAVE_FORMAT_PCM;
+  waveFormat.nChannels = channels;
+  waveFormat.nSamplesPerSec = (unsigned long) sampleRate;
+
+  // Determine the data format.
+  if ( devices[device].nativeFormats ) { // 8-bit and/or 16-bit support
+    if ( format == RTAUDIO_SINT8 ) {
+      if ( devices[device].nativeFormats & RTAUDIO_SINT8 )
+        waveFormat.wBitsPerSample = 8;
+      else
+        waveFormat.wBitsPerSample = 16;
+    }
+    else {
+      if ( devices[device].nativeFormats & RTAUDIO_SINT16 )
+        waveFormat.wBitsPerSample = 16;
+      else
+        waveFormat.wBitsPerSample = 8;
+    }
+  }
+  else {
+    sprintf(message, "RtAudio: no reported data formats for DirectSound device (%s).",
+            devices[device].name);
+    error(RtError::DEBUG_WARNING);
+    return FAILURE;
+  }
+
+  waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
+  waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
+
+  enum_info dsinfo;
+  strncpy( dsinfo.name, devices[device].name, 64 );
+  dsinfo.isValid = false;
+  if ( mode == OUTPUT ) {
+
+    if ( devices[device].maxOutputChannels < channels )
+      return FAILURE;
+
+    // Enumerate through output devices to find the id (if it exists).
+    result = DirectSoundEnumerate((LPDSENUMCALLBACK)deviceIdCallback, &dsinfo);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Error performing output device id enumeration: %s.",
+              getErrorString(result));
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    if ( dsinfo.isValid == false ) {
+      sprintf(message, "RtAudio: DS output device (%s) id not found!", devices[device].name);
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    LPGUID id = dsinfo.id;
+    LPDIRECTSOUND  object;
+    LPDIRECTSOUNDBUFFER buffer;
+    DSBUFFERDESC bufferDescription;
+    
+    result = DirectSoundCreate( id, &object, NULL );
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Could not create DirectSound playback object (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    // Set cooperative level to DSSCL_EXCLUSIVE
+    result = object->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to set DirectSound cooperative level (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Even though we will write to the secondary buffer, we need to
+    // access the primary buffer to set the correct output format.
+    // The default is 8-bit, 22 kHz!
+    // Setup the DS primary buffer description.
+    ZeroMemory(&bufferDescription, sizeof(DSBUFFERDESC));
+    bufferDescription.dwSize = sizeof(DSBUFFERDESC);
+    bufferDescription.dwFlags = DSBCAPS_PRIMARYBUFFER;
+    // Obtain the primary buffer
+    result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to access DS primary buffer (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Set the primary DS buffer sound format.
+    result = buffer->SetFormat(&waveFormat);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to set DS primary buffer format (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Setup the secondary DS buffer description.
+    buffer_size = channels * *bufferSize * nBuffers * waveFormat.wBitsPerSample / 8;
+    ZeroMemory(&bufferDescription, sizeof(DSBUFFERDESC));
+    bufferDescription.dwSize = sizeof(DSBUFFERDESC);
+    bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS |
+                                  DSBCAPS_GETCURRENTPOSITION2 |
+                                  DSBCAPS_LOCHARDWARE );  // Force hardware mixing
+    bufferDescription.dwBufferBytes = buffer_size;
+    bufferDescription.lpwfxFormat = &waveFormat;
+
+    // Try to create the secondary DS buffer.  If that doesn't work,
+    // try to use software mixing.  Otherwise, there's a problem.
+    result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);
+    if ( FAILED(result) ) {
+      bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS |
+                                    DSBCAPS_GETCURRENTPOSITION2 |
+                                    DSBCAPS_LOCSOFTWARE );  // Force software mixing
+      result = object->CreateSoundBuffer(&bufferDescription, &buffer, NULL);
+      if ( FAILED(result) ) {
+        object->Release();
+        sprintf(message, "RtAudio: Unable to create secondary DS buffer (%s): %s.",
+                devices[device].name, getErrorString(result));
+        error(RtError::WARNING);
+        return FAILURE;
+      }
+    }
+
+    // Get the buffer size ... might be different from what we specified.
+    DSBCAPS dsbcaps;
+    dsbcaps.dwSize = sizeof(DSBCAPS);
+    buffer->GetCaps(&dsbcaps);
+    buffer_size = dsbcaps.dwBufferBytes;
+
+    // Lock the DS buffer
+    result = buffer->Lock(0, buffer_size, &audioPtr, &dataLen, NULL, NULL, 0);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to lock DS buffer (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Zero the DS buffer
+    ZeroMemory(audioPtr, dataLen);
+
+    // Unlock the DS buffer
+    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to unlock DS buffer(%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    stream->handle[0].object = (void *) object;
+    stream->handle[0].buffer = (void *) buffer;
+    stream->nDeviceChannels[0] = channels;
+  }
+
+  if ( mode == INPUT ) {
+
+    if ( devices[device].maxInputChannels < channels )
+      return FAILURE;
+
+    // Enumerate through input devices to find the id (if it exists).
+    result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)deviceIdCallback, &dsinfo);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Error performing input device id enumeration: %s.",
+              getErrorString(result));
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    if ( dsinfo.isValid == false ) {
+      sprintf(message, "RtAudio: DS input device (%s) id not found!", devices[device].name);
+      error(RtError::DEBUG_WARNING);
+      return FAILURE;
+    }
+
+    LPGUID id = dsinfo.id;
+    LPDIRECTSOUNDCAPTURE  object;
+    LPDIRECTSOUNDCAPTUREBUFFER buffer;
+    DSCBUFFERDESC bufferDescription;
+
+    result = DirectSoundCaptureCreate( id, &object, NULL );
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Could not create DirectSound capture object (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Setup the secondary DS buffer description.
+    buffer_size = channels * *bufferSize * nBuffers * waveFormat.wBitsPerSample / 8;
+    ZeroMemory(&bufferDescription, sizeof(DSCBUFFERDESC));
+    bufferDescription.dwSize = sizeof(DSCBUFFERDESC);
+    bufferDescription.dwFlags = 0;
+    bufferDescription.dwReserved = 0;
+    bufferDescription.dwBufferBytes = buffer_size;
+    bufferDescription.lpwfxFormat = &waveFormat;
+
+    // Create the capture buffer.
+    result = object->CreateCaptureBuffer(&bufferDescription, &buffer, NULL);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to create DS capture buffer (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Lock the capture buffer
+    result = buffer->Lock(0, buffer_size, &audioPtr, &dataLen, NULL, NULL, 0);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Zero the buffer
+    ZeroMemory(audioPtr, dataLen);
+
+    // Unlock the buffer
+    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
+    if ( FAILED(result) ) {
+      object->Release();
+      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",
+              devices[device].name, getErrorString(result));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    stream->handle[1].object = (void *) object;
+    stream->handle[1].buffer = (void *) buffer;
+    stream->nDeviceChannels[1] = channels;
+  }
+
+  stream->userFormat = format;
+  if ( waveFormat.wBitsPerSample == 8 )
+    stream->deviceFormat[mode] = RTAUDIO_SINT8;
+  else
+    stream->deviceFormat[mode] = RTAUDIO_SINT16;
+  stream->nUserChannels[mode] = channels;
+  *bufferSize = buffer_size / (channels * nBuffers * waveFormat.wBitsPerSample / 8);
+  stream->bufferSize = *bufferSize;
+
+  // Set flags for buffer conversion
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+  if (stream->nUserChannels[mode] < stream->nDeviceChannels[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL)
+      goto memory_error;
+  }
+
+  if ( stream->doConvertBuffer[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL)
+        goto memory_error;
+    }
+  }
+
+  stream->device[mode] = device;
+  stream->state = STREAM_STOPPED;
+  if ( stream->mode == OUTPUT && mode == INPUT )
+    // We had already set up an output stream.
+    stream->mode = DUPLEX;
+  else
+    stream->mode = mode;
+  stream->nBuffers = nBuffers;
+  stream->sampleRate = sampleRate;
+
+  return SUCCESS;
+
+ memory_error:
+  if (stream->handle[0].object) {
+    LPDIRECTSOUND object = (LPDIRECTSOUND) stream->handle[0].object;
+    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    if (buffer) {
+      buffer->Release();
+      stream->handle[0].buffer = NULL;
+    }
+    object->Release();
+    stream->handle[0].object = NULL;
+  }
+  if (stream->handle[1].object) {
+    LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) stream->handle[1].object;
+    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    if (buffer) {
+      buffer->Release();
+      stream->handle[1].buffer = NULL;
+    }
+    object->Release();
+    stream->handle[1].object = NULL;
+  }
+  if (stream->userBuffer) {
+    free(stream->userBuffer);
+    stream->userBuffer = 0;
+  }
+  sprintf(message, "RtAudio: error allocating buffer memory (%s).",
+          devices[device].name);
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: cancelStreamCallback(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->callbackInfo.usingCallback) {
+
+    if (stream->state == STREAM_RUNNING)
+      stopStream( streamId );
+
+    MUTEX_LOCK(&stream->mutex);
+
+    stream->callbackInfo.usingCallback = false;
+    WaitForSingleObject( (HANDLE)stream->callbackInfo.thread, INFINITE );
+    CloseHandle( (HANDLE)stream->callbackInfo.thread );
+    stream->callbackInfo.thread = 0;
+    stream->callbackInfo.callback = NULL;
+    stream->callbackInfo.userData = NULL;
+
+    MUTEX_UNLOCK(&stream->mutex);
+  }
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  if (stream->callbackInfo.usingCallback) {
+    stream->callbackInfo.usingCallback = false;
+    WaitForSingleObject( (HANDLE)stream->callbackInfo.thread, INFINITE );
+    CloseHandle( (HANDLE)stream->callbackInfo.thread );
+  }
+
+  DeleteCriticalSection(&stream->mutex);
+
+  if (stream->handle[0].object) {
+    LPDIRECTSOUND object = (LPDIRECTSOUND) stream->handle[0].object;
+    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    if (buffer) {
+      buffer->Stop();
+      buffer->Release();
+    }
+    object->Release();
+  }
+
+  if (stream->handle[1].object) {
+    LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) stream->handle[1].object;
+    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    if (buffer) {
+      buffer->Stop();
+      buffer->Release();
+    }
+    object->Release();
+  }
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if (stream->deviceBuffer)
+    free(stream->deviceBuffer);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_RUNNING)
+    goto unlock;
+
+  HRESULT result;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    result = buffer->Play(0, 0, DSBPLAY_LOOPING );
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to start DS buffer (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    result = buffer->Start(DSCBSTART_LOOPING );
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to start DS capture buffer (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_RUNNING;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED) {
+    MUTEX_UNLOCK(&stream->mutex);
+    return;
+  }
+
+  // There is no specific DirectSound API call to "drain" a buffer
+  // before stopping.  We can hack this for playback by writing zeroes
+  // for another bufferSize * nBuffers frames.  For capture, the
+  // concept is less clear so we'll repeat what we do in the
+  // abortStream() case.
+  HRESULT result;
+  DWORD dsBufferSize;
+  LPVOID buffer1 = NULL;
+  LPVOID buffer2 = NULL;
+  DWORD bufferSize1 = 0;
+  DWORD bufferSize2 = 0;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    DWORD currentPos, safePos;
+    long buffer_bytes = stream->bufferSize * stream->nDeviceChannels[0];
+    buffer_bytes *= formatBytes(stream->deviceFormat[0]);
+
+    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    UINT nextWritePos = stream->handle[0].bufferPointer;
+    dsBufferSize = buffer_bytes * stream->nBuffers;
+
+    // Write zeroes for nBuffer counts.
+    for (int i=0; i<stream->nBuffers; i++) {
+
+      // Find out where the read and "safe write" pointers are.
+      result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
+      if ( FAILED(result) ) {
+        sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",
+                devices[stream->device[0]].name, getErrorString(result));
+        error(RtError::DRIVER_ERROR);
+      }
+
+      if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
+      DWORD endWrite = nextWritePos + buffer_bytes;
+
+      // Check whether the entire write region is behind the play pointer.
+      while ( currentPos < endWrite ) {
+        float millis = (endWrite - currentPos) * 900.0;
+        millis /= ( formatBytes(stream->deviceFormat[0]) * stream->sampleRate);
+        if ( millis < 1.0 ) millis = 1.0;
+        Sleep( (DWORD) millis );
+
+        // Wake up, find out where we are now
+        result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );
+        if ( FAILED(result) ) {
+          sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",
+                  devices[stream->device[0]].name, getErrorString(result));
+          error(RtError::DRIVER_ERROR);
+        }
+        if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
+      }
+
+      // Lock free space in the buffer
+      result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,
+                               &bufferSize1, &buffer2, &bufferSize2, 0);
+      if ( FAILED(result) ) {
+        sprintf(message, "RtAudio: Unable to lock DS buffer during playback (%s): %s.",
+                devices[stream->device[0]].name, getErrorString(result));
+        error(RtError::DRIVER_ERROR);
+      }
+
+      // Zero the free space
+      ZeroMemory(buffer1, bufferSize1);
+      if (buffer2 != NULL) ZeroMemory(buffer2, bufferSize2);
+
+      // Update our buffer offset and unlock sound buffer
+      dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);
+      if ( FAILED(result) ) {
+        sprintf(message, "RtAudio: Unable to unlock DS buffer during playback (%s): %s.",
+                devices[stream->device[0]].name, getErrorString(result));
+        error(RtError::DRIVER_ERROR);
+      }
+      nextWritePos = (nextWritePos + bufferSize1 + bufferSize2) % dsBufferSize;
+      stream->handle[0].bufferPointer = nextWritePos;
+    }
+
+    // If we play again, start at the beginning of the buffer.
+    stream->handle[0].bufferPointer = 0;
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    buffer1 = NULL;
+    bufferSize1 = 0;
+
+    result = buffer->Stop();
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to stop DS capture buffer (%s): %s",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[1];
+    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;
+
+    // Lock the buffer and clear it so that if we start to play again,
+    // we won't have old data playing.
+    result = buffer->Lock(0, dsBufferSize, &buffer1, &bufferSize1, NULL, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Zero the DS buffer
+    ZeroMemory(buffer1, bufferSize1);
+
+    // Unlock the DS buffer
+    result = buffer->Unlock(buffer1, bufferSize1, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // If we start recording again, we must begin at beginning of buffer.
+    stream->handle[1].bufferPointer = 0;
+  }
+  stream->state = STREAM_STOPPED;
+
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  HRESULT result;
+  long dsBufferSize;
+  LPVOID audioPtr;
+  DWORD dataLen;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    result = buffer->Stop();
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to stop DS buffer (%s): %s",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[0];
+    dsBufferSize *= formatBytes(stream->deviceFormat[0]) * stream->nBuffers;
+
+    // Lock the buffer and clear it so that if we start to play again,
+    // we won't have old data playing.
+    result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to lock DS buffer (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Zero the DS buffer
+    ZeroMemory(audioPtr, dataLen);
+
+    // Unlock the DS buffer
+    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to unlock DS buffer (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // If we start playing again, we must begin at beginning of buffer.
+    stream->handle[0].bufferPointer = 0;
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    audioPtr = NULL;
+    dataLen = 0;
+
+    result = buffer->Stop();
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to stop DS capture buffer (%s): %s",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    dsBufferSize = stream->bufferSize * stream->nDeviceChannels[1];
+    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;
+
+    // Lock the buffer and clear it so that if we start to play again,
+    // we won't have old data playing.
+    result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to lock DS capture buffer (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Zero the DS buffer
+    ZeroMemory(audioPtr, dataLen);
+
+    // Unlock the DS buffer
+    result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to unlock DS capture buffer (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // If we start recording again, we must begin at beginning of buffer.
+    stream->handle[1].bufferPointer = 0;
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+int RtAudio :: streamWillBlock(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  int channels;
+  int frames = 0;
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  HRESULT result;
+  DWORD currentPos, safePos;
+  channels = 1;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    UINT nextWritePos = stream->handle[0].bufferPointer;
+    channels = stream->nDeviceChannels[0];
+    DWORD dsBufferSize = stream->bufferSize * channels;
+    dsBufferSize *= formatBytes(stream->deviceFormat[0]) * stream->nBuffers;
+
+    // Find out where the read and "safe write" pointers are.
+    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
+    frames = currentPos - nextWritePos;
+    frames /= channels * formatBytes(stream->deviceFormat[0]);
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+
+    LPDIRECTSOUNDCAPTUREBUFFER dsBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    UINT nextReadPos = stream->handle[1].bufferPointer;
+    channels = stream->nDeviceChannels[1];
+    DWORD dsBufferSize = stream->bufferSize * channels;
+    dsBufferSize *= formatBytes(stream->deviceFormat[1]) * stream->nBuffers;
+
+    // Find out where the write and "safe read" pointers are.
+    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset
+
+    if (stream->mode == DUPLEX ) {
+      // Take largest value of the two.
+      int temp = safePos - nextReadPos;
+      temp /= channels * formatBytes(stream->deviceFormat[1]);
+      frames = ( temp > frames ) ? temp : frames;
+    }
+    else {
+      frames = safePos - nextReadPos;
+      frames /= channels * formatBytes(stream->deviceFormat[1]);
+    }
+  }
+
+  frames = stream->bufferSize - frames;
+  if (frames < 0) frames = 0;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+  return frames;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  int stopStream = 0;
+  if (stream->state == STREAM_STOPPED) {
+    if (stream->callbackInfo.usingCallback) Sleep(50); // sleep 50 milliseconds
+    return;
+  }
+  else if (stream->callbackInfo.usingCallback) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) stream->callbackInfo.callback;
+    stopStream = callback(stream->userBuffer, stream->bufferSize, stream->callbackInfo.userData);
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+
+  // The state might change while waiting on a mutex.
+  if (stream->state == STREAM_STOPPED) {
+    MUTEX_UNLOCK(&stream->mutex);
+    return;
+  }
+
+  HRESULT result;
+  DWORD currentPos, safePos;
+  LPVOID buffer1 = NULL;
+  LPVOID buffer2 = NULL;
+  DWORD bufferSize1 = 0;
+  DWORD bufferSize2 = 0;
+  char *buffer;
+  long buffer_bytes;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters and do buffer conversion if necessary.
+    if (stream->doConvertBuffer[0]) {
+      convertStreamBuffer(stream, OUTPUT);
+      buffer = stream->deviceBuffer;
+      buffer_bytes = stream->bufferSize * stream->nDeviceChannels[0];
+      buffer_bytes *= formatBytes(stream->deviceFormat[0]);
+    }
+    else {
+      buffer = stream->userBuffer;
+      buffer_bytes = stream->bufferSize * stream->nUserChannels[0];
+      buffer_bytes *= formatBytes(stream->userFormat);
+    }
+
+    // No byte swapping necessary in DirectSound implementation.
+
+    LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) stream->handle[0].buffer;
+    UINT nextWritePos = stream->handle[0].bufferPointer;
+    DWORD dsBufferSize = buffer_bytes * stream->nBuffers;
+
+    // Find out where the read and "safe write" pointers are.
+    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
+    DWORD endWrite = nextWritePos + buffer_bytes;
+
+    // Check whether the entire write region is behind the play pointer.
+    while ( currentPos < endWrite ) {
+      // If we are here, then we must wait until the play pointer gets
+      // beyond the write region.  The approach here is to use the
+      // Sleep() function to suspend operation until safePos catches
+      // up. Calculate number of milliseconds to wait as:
+      //   time = distance * (milliseconds/second) * fudgefactor /
+      //          ((bytes/sample) * (samples/second))
+      // A "fudgefactor" less than 1 is used because it was found
+      // that sleeping too long was MUCH worse than sleeping for
+      // several shorter periods.
+      float millis = (endWrite - currentPos) * 900.0;
+      millis /= ( formatBytes(stream->deviceFormat[0]) * stream->sampleRate);
+      if ( millis < 1.0 ) millis = 1.0;
+      Sleep( (DWORD) millis );
+
+      // Wake up, find out where we are now
+      result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );
+      if ( FAILED(result) ) {
+        sprintf(message, "RtAudio: Unable to get current DS position (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+        error(RtError::DRIVER_ERROR);
+      }
+      if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
+    }
+
+    // Lock free space in the buffer
+    result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,
+                             &bufferSize1, &buffer2, &bufferSize2, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to lock DS buffer during playback (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Copy our buffer into the DS buffer
+    CopyMemory(buffer1, buffer, bufferSize1);
+    if (buffer2 != NULL) CopyMemory(buffer2, buffer+bufferSize1, bufferSize2);
+
+    // Update our buffer offset and unlock sound buffer
+    dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to unlock DS buffer during playback (%s): %s.",
+              devices[stream->device[0]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+    nextWritePos = (nextWritePos + bufferSize1 + bufferSize2) % dsBufferSize;
+    stream->handle[0].bufferPointer = nextWritePos;
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters.
+    if (stream->doConvertBuffer[1]) {
+      buffer = stream->deviceBuffer;
+      buffer_bytes = stream->bufferSize * stream->nDeviceChannels[1];
+      buffer_bytes *= formatBytes(stream->deviceFormat[1]);
+    }
+    else {
+      buffer = stream->userBuffer;
+      buffer_bytes = stream->bufferSize * stream->nUserChannels[1];
+      buffer_bytes *= formatBytes(stream->userFormat);
+    }
+
+    LPDIRECTSOUNDCAPTUREBUFFER dsBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) stream->handle[1].buffer;
+    UINT nextReadPos = stream->handle[1].bufferPointer;
+    DWORD dsBufferSize = buffer_bytes * stream->nBuffers;
+
+    // Find out where the write and "safe read" pointers are.
+    result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset
+    DWORD endRead = nextReadPos + buffer_bytes;
+
+    // Check whether the entire write region is behind the play pointer.
+    while ( safePos < endRead ) {
+      // See comments for playback.
+      float millis = (endRead - safePos) * 900.0;
+      millis /= ( formatBytes(stream->deviceFormat[1]) * stream->sampleRate);
+      if ( millis < 1.0 ) millis = 1.0;
+      Sleep( (DWORD) millis );
+
+      // Wake up, find out where we are now
+      result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );
+      if ( FAILED(result) ) {
+        sprintf(message, "RtAudio: Unable to get current DS capture position (%s): %s.",
+                devices[stream->device[1]].name, getErrorString(result));
+        error(RtError::DRIVER_ERROR);
+      }
+      
+      if ( safePos < nextReadPos ) safePos += dsBufferSize; // unwrap offset
+    }
+
+    // Lock free space in the buffer
+    result = dsBuffer->Lock (nextReadPos, buffer_bytes, &buffer1,
+                             &bufferSize1, &buffer2, &bufferSize2, 0);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to lock DS buffer during capture (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+
+    // Copy our buffer into the DS buffer
+    CopyMemory(buffer, buffer1, bufferSize1);
+    if (buffer2 != NULL) CopyMemory(buffer+bufferSize1, buffer2, bufferSize2);
+
+    // Update our buffer offset and unlock sound buffer
+    nextReadPos = (nextReadPos + bufferSize1 + bufferSize2) % dsBufferSize;
+    dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);
+    if ( FAILED(result) ) {
+      sprintf(message, "RtAudio: Unable to unlock DS buffer during capture (%s): %s.",
+              devices[stream->device[1]].name, getErrorString(result));
+      error(RtError::DRIVER_ERROR);
+    }
+    stream->handle[1].bufferPointer = nextReadPos;
+
+    // No byte swapping necessary in DirectSound implementation.
+
+    // Do buffer conversion if necessary.
+    if (stream->doConvertBuffer[1])
+      convertStreamBuffer(stream, INPUT);
+  }
+
+  MUTEX_UNLOCK(&stream->mutex);
+
+  if (stream->callbackInfo.usingCallback && stopStream)
+    this->stopStream(streamId);
+}
+
+// Definitions for utility functions and callbacks
+// specific to the DirectSound implementation.
+
+extern "C" unsigned __stdcall callbackHandler(void *ptr)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) ptr;
+  RtAudio *object = (RtAudio *) info->object;
+  int stream = info->streamId;
+  bool *usingCallback = &info->usingCallback;
+
+  while ( *usingCallback ) {
+    try {
+      object->tickStream(stream);
+    }
+    catch (RtError &exception) {
+      fprintf(stderr, "\nRtAudio: Callback thread error (%s) ... closing thread.\n\n",
+              exception.getMessage());
+      break;
+    }
+  }
+
+  _endthreadex( 0 );
+  return 0;
+}
+
+void RtAudio :: setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  CALLBACK_INFO *info = (CALLBACK_INFO *) &stream->callbackInfo;
+  if ( info->usingCallback ) {
+    sprintf(message, "RtAudio: A callback is already set for this stream!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  info->callback = (void *) callback;
+  info->userData = userData;
+  info->usingCallback = true;
+  info->object = (void *) this;
+  info->streamId = streamId;
+
+  unsigned thread_id;
+  info->thread = _beginthreadex(NULL, 0, &callbackHandler,
+                                &stream->callbackInfo, 0, &thread_id);
+  if (info->thread == 0) {
+    info->usingCallback = false;
+    sprintf(message, "RtAudio: error starting callback thread!");
+    error(RtError::THREAD_ERROR);
+  }
+
+  // When spawning multiple threads in quick succession, it appears to be
+  // necessary to wait a bit for each to initialize ... another windoism!
+  Sleep(1);
+}
+
+static bool CALLBACK deviceCountCallback(LPGUID lpguid,
+                                         LPCSTR lpcstrDescription,
+                                         LPCSTR lpcstrModule,
+                                         LPVOID lpContext)
+{
+  int *pointer = ((int *) lpContext);
+  (*pointer)++;
+
+  return true;
+}
+
+static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
+                                        LPCSTR lpcstrDescription,
+                                        LPCSTR lpcstrModule,
+                                        LPVOID lpContext)
+{
+  enum_info *info = ((enum_info *) lpContext);
+  while (strlen(info->name) > 0) info++;
+
+  strncpy(info->name, lpcstrDescription, 64);
+  info->id = lpguid;
+
+       HRESULT    hr;
+  info->isValid = false;
+  if (info->isInput == true) {
+    DSCCAPS               caps;
+    LPDIRECTSOUNDCAPTURE  object;
+
+    hr = DirectSoundCaptureCreate(  lpguid, &object,   NULL );
+    if( hr != DS_OK ) return true;
+
+    caps.dwSize = sizeof(caps);
+    hr = object->GetCaps( &caps );
+    if( hr == DS_OK ) {
+      if (caps.dwChannels > 0 && caps.dwFormats > 0)
+        info->isValid = true;
+    }
+    object->Release();
+  }
+  else {
+    DSCAPS         caps;
+    LPDIRECTSOUND  object;
+    hr = DirectSoundCreate(  lpguid, &object,   NULL );
+    if( hr != DS_OK ) return true;
+
+    caps.dwSize = sizeof(caps);
+    hr = object->GetCaps( &caps );
+    if( hr == DS_OK ) {
+      if ( caps.dwFlags & DSCAPS_PRIMARYMONO || caps.dwFlags & DSCAPS_PRIMARYSTEREO )
+        info->isValid = true;
+    }
+    object->Release();
+  }
+
+  return true;
+}
+
+static bool CALLBACK defaultDeviceCallback(LPGUID lpguid,
+                                           LPCSTR lpcstrDescription,
+                                           LPCSTR lpcstrModule,
+                                           LPVOID lpContext)
+{
+  enum_info *info = ((enum_info *) lpContext);
+
+  if ( lpguid == NULL ) {
+    strncpy(info->name, lpcstrDescription, 64);
+    return false;
+  }
+
+  return true;
+}
+
+static bool CALLBACK deviceIdCallback(LPGUID lpguid,
+                                      LPCSTR lpcstrDescription,
+                                      LPCSTR lpcstrModule,
+                                      LPVOID lpContext)
+{
+  enum_info *info = ((enum_info *) lpContext);
+
+  if ( strncmp( info->name, lpcstrDescription, 64 ) == 0 ) {
+    info->id = lpguid;
+    info->isValid = true;
+    return false;
+  }
+
+  return true;
+}
+
+static char* getErrorString(int code)
+{
+       switch (code) {
+
+  case DSERR_ALLOCATED:
+    return "Direct Sound already allocated";
+
+  case DSERR_CONTROLUNAVAIL:
+    return "Direct Sound control unavailable";
+
+  case DSERR_INVALIDPARAM:
+    return "Direct Sound invalid parameter";
+
+  case DSERR_INVALIDCALL:
+    return "Direct Sound invalid call";
+
+  case DSERR_GENERIC:
+    return "Direct Sound generic error";
+
+  case DSERR_PRIOLEVELNEEDED:
+    return "Direct Sound Priority level needed";
+
+  case DSERR_OUTOFMEMORY:
+    return "Direct Sound out of memory";
+
+  case DSERR_BADFORMAT:
+    return "Direct Sound bad format";
+
+  case DSERR_UNSUPPORTED:
+    return "Direct Sound unsupported error";
+
+  case DSERR_NODRIVER:
+    return "Direct Sound no driver error";
+
+  case DSERR_ALREADYINITIALIZED:
+    return "Direct Sound already initialized";
+
+  case DSERR_NOAGGREGATION:
+    return "Direct Sound no aggregation";
+
+  case DSERR_BUFFERLOST:
+    return "Direct Sound buffer lost";
+
+  case DSERR_OTHERAPPHASPRIO:
+    return "Direct Sound other app has priority";
+
+  case DSERR_UNINITIALIZED:
+    return "Direct Sound uninitialized";
+
+  default:
+    return "Direct Sound unknown error";
+       }
+}
+
+//******************** End of __WINDOWS_DS__ *********************//
+
+#elif defined(__IRIX_AL__) // SGI's AL API for IRIX
+
+#include <unistd.h>
+#include <errno.h>
+
+void RtAudio :: initialize(void)
+{
+  // Count cards and devices
+  nDevices = 0;
+
+  // Determine the total number of input and output devices.
+  nDevices = alQueryValues(AL_SYSTEM, AL_DEVICES, 0, 0, 0, 0);
+  if (nDevices < 0) {
+    sprintf(message, "RtAudio: AL error counting devices: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  if (nDevices <= 0) return;
+
+  ALvalue *vls = (ALvalue *) new ALvalue[nDevices];
+
+  //  Allocate the RTAUDIO_DEVICE structures.
+  devices = (RTAUDIO_DEVICE *) calloc(nDevices, sizeof(RTAUDIO_DEVICE));
+  if (devices == NULL) {
+    sprintf(message, "RtAudio: memory allocation error!");
+    error(RtError::MEMORY_ERROR);
+  }
+
+  // Write device ascii identifiers and resource ids to device info
+  // structure.
+  char name[32];
+  int outs, ins, i;
+  ALpv pvs[1];
+  pvs[0].param = AL_NAME;
+  pvs[0].value.ptr = name;
+  pvs[0].sizeIn = 32;
+
+  outs = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, vls, nDevices, 0, 0);
+  if (outs < 0) {
+    sprintf(message, "RtAudio: AL error getting output devices: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  for (i=0; i<outs; i++) {
+    if (alGetParams(vls[i].i, pvs, 1) < 0) {
+      sprintf(message, "RtAudio: AL error querying output devices: %s.",
+              alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+    strncpy(devices[i].name, name, 32);
+    devices[i].id[0] = vls[i].i;
+  }
+
+  ins = alQueryValues(AL_SYSTEM, AL_DEFAULT_INPUT, &vls[outs], nDevices-outs, 0, 0);
+  if (ins < 0) {
+    sprintf(message, "RtAudio: AL error getting input devices: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::DRIVER_ERROR);
+  }
+
+  for (i=outs; i<ins+outs; i++) {
+    if (alGetParams(vls[i].i, pvs, 1) < 0) {
+      sprintf(message, "RtAudio: AL error querying input devices: %s.",
+              alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+    strncpy(devices[i].name, name, 32);
+    devices[i].id[1] = vls[i].i;
+  }
+
+  delete [] vls;
+
+  return;
+}
+
+int RtAudio :: getDefaultInputDevice(void)
+{
+  ALvalue value;
+  int result = alQueryValues(AL_SYSTEM, AL_DEFAULT_INPUT, &value, 1, 0, 0);
+  if (result < 0) {
+    sprintf(message, "RtAudio: AL error getting default input device id: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::WARNING);
+  }
+  else {
+    for ( int i=0; i<nDevices; i++ )
+      if ( devices[i].id[1] == value.i ) return i;
+  }
+
+  return 0;
+}
+
+int RtAudio :: getDefaultOutputDevice(void)
+{
+  ALvalue value;
+  int result = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, &value, 1, 0, 0);
+  if (result < 0) {
+    sprintf(message, "RtAudio: AL error getting default output device id: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::WARNING);
+  }
+  else {
+    for ( int i=0; i<nDevices; i++ )
+      if ( devices[i].id[0] == value.i ) return i;
+  }
+
+  return 0;
+}
+
+void RtAudio :: probeDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  int resource, result, i;
+  ALvalue value;
+  ALparamInfo pinfo;
+
+  // Get output resource ID if it exists.
+  resource = info->id[0];
+  if (resource > 0) {
+
+    // Probe output device parameters.
+    result = alQueryValues(resource, AL_CHANNELS, &value, 1, 0, 0);
+    if (result < 0) {
+      sprintf(message, "RtAudio: AL error getting device (%s) channels: %s.",
+              info->name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+    }
+    else {
+      info->maxOutputChannels = value.i;
+      info->minOutputChannels = 1;
+    }
+
+    result = alGetParamInfo(resource, AL_RATE, &pinfo);
+    if (result < 0) {
+      sprintf(message, "RtAudio: AL error getting device (%s) rates: %s.",
+              info->name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+    }
+    else {
+      info->nSampleRates = 0;
+      for (i=0; i<MAX_SAMPLE_RATES; i++) {
+        if ( SAMPLE_RATES[i] >= pinfo.min.i && SAMPLE_RATES[i] <= pinfo.max.i ) {
+          info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];
+          info->nSampleRates++;
+        }
+      }
+    }
+
+    // The AL library supports all our formats, except 24-bit and 32-bit ints.
+    info->nativeFormats = (RTAUDIO_FORMAT) 51;
+  }
+
+  // Now get input resource ID if it exists.
+  resource = info->id[1];
+  if (resource > 0) {
+
+    // Probe input device parameters.
+    result = alQueryValues(resource, AL_CHANNELS, &value, 1, 0, 0);
+    if (result < 0) {
+      sprintf(message, "RtAudio: AL error getting device (%s) channels: %s.",
+              info->name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+    }
+    else {
+      info->maxInputChannels = value.i;
+      info->minInputChannels = 1;
+    }
+
+    result = alGetParamInfo(resource, AL_RATE, &pinfo);
+    if (result < 0) {
+      sprintf(message, "RtAudio: AL error getting device (%s) rates: %s.",
+              info->name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+    }
+    else {
+      // In the case of the default device, these values will
+      // overwrite the rates determined for the output device.  Since
+      // the input device is most likely to be more limited than the
+      // output device, this is ok.
+      info->nSampleRates = 0;
+      for (i=0; i<MAX_SAMPLE_RATES; i++) {
+        if ( SAMPLE_RATES[i] >= pinfo.min.i && SAMPLE_RATES[i] <= pinfo.max.i ) {
+          info->sampleRates[info->nSampleRates] = SAMPLE_RATES[i];
+          info->nSampleRates++;
+        }
+      }
+    }
+
+    // The AL library supports all our formats, except 24-bit and 32-bit ints.
+    info->nativeFormats = (RTAUDIO_FORMAT) 51;
+  }
+
+  if ( info->maxInputChannels == 0 && info->maxOutputChannels == 0 )
+    return;
+  if ( info->nSampleRates == 0 )
+    return;
+
+  // Determine duplex status.
+  if (info->maxInputChannels < info->maxOutputChannels)
+    info->maxDuplexChannels = info->maxInputChannels;
+  else
+    info->maxDuplexChannels = info->maxOutputChannels;
+  if (info->minInputChannels < info->minOutputChannels)
+    info->minDuplexChannels = info->minInputChannels;
+  else
+    info->minDuplexChannels = info->minOutputChannels;
+
+  if ( info->maxDuplexChannels > 0 ) info->hasDuplexSupport = true;
+  else info->hasDuplexSupport = false;
+
+  info->probed = true;
+
+  return;
+}
+
+bool RtAudio :: probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                                STREAM_MODE mode, int channels, 
+                                int sampleRate, RTAUDIO_FORMAT format,
+                                int *bufferSize, int numberOfBuffers)
+{
+  int result, resource, nBuffers;
+  ALconfig al_config;
+  ALport port;
+  ALpv pvs[2];
+
+  // Get a new ALconfig structure.
+  al_config = alNewConfig();
+  if ( !al_config ) {
+    sprintf(message,"RtAudio: can't get AL config: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Set the channels.
+  result = alSetChannels(al_config, channels);
+  if ( result < 0 ) {
+    sprintf(message,"RtAudio: can't set %d channels in AL config: %s.",
+            channels, alGetErrorString(oserror()));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  // Attempt to set the queue size.  The al API doesn't provide a
+  // means for querying the minimum/maximum buffer size of a device,
+  // so if the specified size doesn't work, take whatever the
+  // al_config structure returns.
+  if ( numberOfBuffers < 1 )
+    nBuffers = 1;
+  else
+    nBuffers = numberOfBuffers;
+  long buffer_size = *bufferSize * nBuffers;
+  result = alSetQueueSize(al_config, buffer_size); // in sample frames
+  if ( result < 0 ) {
+    // Get the buffer size specified by the al_config and try that.
+    buffer_size = alGetQueueSize(al_config);
+    result = alSetQueueSize(al_config, buffer_size);
+    if ( result < 0 ) {
+      sprintf(message,"RtAudio: can't set buffer size (%ld) in AL config: %s.",
+              buffer_size, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+    *bufferSize = buffer_size / nBuffers;
+  }
+
+  // Set the data format.
+  stream->userFormat = format;
+  stream->deviceFormat[mode] = format;
+  if (format == RTAUDIO_SINT8) {
+    result = alSetSampFmt(al_config, AL_SAMPFMT_TWOSCOMP);
+    result = alSetWidth(al_config, AL_SAMPLE_8);
+  }
+  else if (format == RTAUDIO_SINT16) {
+    result = alSetSampFmt(al_config, AL_SAMPFMT_TWOSCOMP);
+    result = alSetWidth(al_config, AL_SAMPLE_16);
+  }
+  else if (format == RTAUDIO_SINT24) {
+    // Our 24-bit format assumes the upper 3 bytes of a 4 byte word.
+    // The AL library uses the lower 3 bytes, so we'll need to do our
+    // own conversion.
+    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;
+  }
+  else if (format == RTAUDIO_SINT32) {
+    // The AL library doesn't seem to support the 32-bit integer
+    // format, so we'll need to do our own conversion.
+    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);
+    stream->deviceFormat[mode] = RTAUDIO_FLOAT32;
+  }
+  else if (format == RTAUDIO_FLOAT32)
+    result = alSetSampFmt(al_config, AL_SAMPFMT_FLOAT);
+  else if (format == RTAUDIO_FLOAT64)
+    result = alSetSampFmt(al_config, AL_SAMPFMT_DOUBLE);
+
+  if ( result == -1 ) {
+    sprintf(message,"RtAudio: AL error setting sample format in AL config: %s.",
+            alGetErrorString(oserror()));
+    error(RtError::WARNING);
+    return FAILURE;
+  }
+
+  if (mode == OUTPUT) {
+
+    // Set our device.
+    if (device == 0)
+      resource = AL_DEFAULT_OUTPUT;
+    else
+      resource = devices[device].id[0];
+    result = alSetDevice(al_config, resource);
+    if ( result == -1 ) {
+      sprintf(message,"RtAudio: AL error setting device (%s) in AL config: %s.",
+              devices[device].name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Open the port.
+    port = alOpenPort("RtAudio Output Port", "w", al_config);
+    if( !port ) {
+      sprintf(message,"RtAudio: AL error opening output port: %s.",
+              alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Set the sample rate
+    pvs[0].param = AL_MASTER_CLOCK;
+    pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;
+    pvs[1].param = AL_RATE;
+    pvs[1].value.ll = alDoubleToFixed((double)sampleRate);
+    result = alSetParams(resource, pvs, 2);
+    if ( result < 0 ) {
+      alClosePort(port);
+      sprintf(message,"RtAudio: AL error setting sample rate (%d) for device (%s): %s.",
+              sampleRate, devices[device].name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+  }
+  else { // mode == INPUT
+
+    // Set our device.
+    if (device == 0)
+      resource = AL_DEFAULT_INPUT;
+    else
+      resource = devices[device].id[1];
+    result = alSetDevice(al_config, resource);
+    if ( result == -1 ) {
+      sprintf(message,"RtAudio: AL error setting device (%s) in AL config: %s.",
+              devices[device].name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Open the port.
+    port = alOpenPort("RtAudio Output Port", "r", al_config);
+    if( !port ) {
+      sprintf(message,"RtAudio: AL error opening input port: %s.",
+              alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+
+    // Set the sample rate
+    pvs[0].param = AL_MASTER_CLOCK;
+    pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;
+    pvs[1].param = AL_RATE;
+    pvs[1].value.ll = alDoubleToFixed((double)sampleRate);
+    result = alSetParams(resource, pvs, 2);
+    if ( result < 0 ) {
+      alClosePort(port);
+      sprintf(message,"RtAudio: AL error setting sample rate (%d) for device (%s): %s.",
+              sampleRate, devices[device].name, alGetErrorString(oserror()));
+      error(RtError::WARNING);
+      return FAILURE;
+    }
+  }
+
+  alFreeConfig(al_config);
+
+  stream->nUserChannels[mode] = channels;
+  stream->nDeviceChannels[mode] = channels;
+
+  // Set handle and flags for buffer conversion
+  stream->handle[mode] = port;
+  stream->doConvertBuffer[mode] = false;
+  if (stream->userFormat != stream->deviceFormat[mode])
+    stream->doConvertBuffer[mode] = true;
+
+  // Allocate necessary internal buffers
+  if ( stream->nUserChannels[0] != stream->nUserChannels[1] ) {
+
+    long buffer_bytes;
+    if (stream->nUserChannels[0] >= stream->nUserChannels[1])
+      buffer_bytes = stream->nUserChannels[0];
+    else
+      buffer_bytes = stream->nUserChannels[1];
+
+    buffer_bytes *= *bufferSize * formatBytes(stream->userFormat);
+    if (stream->userBuffer) free(stream->userBuffer);
+    stream->userBuffer = (char *) calloc(buffer_bytes, 1);
+    if (stream->userBuffer == NULL)
+      goto memory_error;
+  }
+
+  if ( stream->doConvertBuffer[mode] ) {
+
+    long buffer_bytes;
+    bool makeBuffer = true;
+    if ( mode == OUTPUT )
+      buffer_bytes = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+    else { // mode == INPUT
+      buffer_bytes = stream->nDeviceChannels[1] * formatBytes(stream->deviceFormat[1]);
+      if ( stream->mode == OUTPUT && stream->deviceBuffer ) {
+        long bytes_out = stream->nDeviceChannels[0] * formatBytes(stream->deviceFormat[0]);
+        if ( buffer_bytes < bytes_out ) makeBuffer = false;
+      }
+    }
+
+    if ( makeBuffer ) {
+      buffer_bytes *= *bufferSize;
+      if (stream->deviceBuffer) free(stream->deviceBuffer);
+      stream->deviceBuffer = (char *) calloc(buffer_bytes, 1);
+      if (stream->deviceBuffer == NULL)
+        goto memory_error;
+    }
+  }
+
+  stream->device[mode] = device;
+  stream->state = STREAM_STOPPED;
+  if ( stream->mode == OUTPUT && mode == INPUT )
+    // We had already set up an output stream.
+    stream->mode = DUPLEX;
+  else
+    stream->mode = mode;
+  stream->nBuffers = nBuffers;
+  stream->bufferSize = *bufferSize;
+  stream->sampleRate = sampleRate;
+
+  return SUCCESS;
+
+ memory_error:
+  if (stream->handle[0]) {
+    alClosePort(stream->handle[0]);
+    stream->handle[0] = 0;
+  }
+  if (stream->handle[1]) {
+    alClosePort(stream->handle[1]);
+    stream->handle[1] = 0;
+  }
+  if (stream->userBuffer) {
+    free(stream->userBuffer);
+    stream->userBuffer = 0;
+  }
+  sprintf(message, "RtAudio: ALSA error allocating buffer memory for device (%s).",
+          devices[device].name);
+  error(RtError::WARNING);
+  return FAILURE;
+}
+
+void RtAudio :: closeStream(int streamId)
+{
+  // We don't want an exception to be thrown here because this
+  // function is called by our class destructor.  So, do our own
+  // streamId check.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::WARNING);
+    return;
+  }
+
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) streams[streamId];
+
+  if (stream->callbackInfo.usingCallback) {
+    pthread_cancel(stream->callbackInfo.thread);
+    pthread_join(stream->callbackInfo.thread, NULL);
+  }
+
+  pthread_mutex_destroy(&stream->mutex);
+
+  if (stream->handle[0])
+    alClosePort(stream->handle[0]);
+
+  if (stream->handle[1])
+    alClosePort(stream->handle[1]);
+
+  if (stream->userBuffer)
+    free(stream->userBuffer);
+
+  if (stream->deviceBuffer)
+    free(stream->deviceBuffer);
+
+  free(stream);
+  streams.erase(streamId);
+}
+
+void RtAudio :: startStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  if (stream->state == STREAM_RUNNING)
+    return;
+
+  // The AL port is ready as soon as it is opened.
+  stream->state = STREAM_RUNNING;
+}
+
+void RtAudio :: stopStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int result;
+  int buffer_size = stream->bufferSize * stream->nBuffers;
+
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX)
+    alZeroFrames(stream->handle[0], buffer_size);
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    result = alDiscardFrames(stream->handle[1], buffer_size);
+    if (result == -1) {
+      sprintf(message, "RtAudio: AL error draining stream device (%s): %s.",
+              devices[stream->device[1]].name, alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+void RtAudio :: abortStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    int buffer_size = stream->bufferSize * stream->nBuffers;
+    int result = alDiscardFrames(stream->handle[0], buffer_size);
+    if (result == -1) {
+      sprintf(message, "RtAudio: AL error aborting stream device (%s): %s.",
+              devices[stream->device[0]].name, alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  // There is no clear action to take on the input stream, since the
+  // port will continue to run in any event.
+  stream->state = STREAM_STOPPED;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+}
+
+int RtAudio :: streamWillBlock(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  MUTEX_LOCK(&stream->mutex);
+
+  int frames = 0;
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  int err = 0;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+    err = alGetFillable(stream->handle[0]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: AL error getting available frames for stream (%s): %s.",
+              devices[stream->device[0]].name, alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+  }
+
+  frames = err;
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+    err = alGetFilled(stream->handle[1]);
+    if (err < 0) {
+      sprintf(message, "RtAudio: AL error getting available frames for stream (%s): %s.",
+              devices[stream->device[1]].name, alGetErrorString(oserror()));
+      error(RtError::DRIVER_ERROR);
+    }
+    if (frames > err) frames = err;
+  }
+
+  frames = stream->bufferSize - frames;
+  if (frames < 0) frames = 0;
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+  return frames;
+}
+
+void RtAudio :: tickStream(int streamId)
+{
+  RTAUDIO_STREAM *stream = (RTAUDIO_STREAM *) verifyStream(streamId);
+
+  int stopStream = 0;
+  if (stream->state == STREAM_STOPPED) {
+    if (stream->callbackInfo.usingCallback) usleep(50000); // sleep 50 milliseconds
+    return;
+  }
+  else if (stream->callbackInfo.usingCallback) {
+    RTAUDIO_CALLBACK callback = (RTAUDIO_CALLBACK) stream->callbackInfo.callback;
+    stopStream = callback(stream->userBuffer, stream->bufferSize, stream->callbackInfo.userData);
+  }
+
+  MUTEX_LOCK(&stream->mutex);
+
+  // The state might change while waiting on a mutex.
+  if (stream->state == STREAM_STOPPED)
+    goto unlock;
+
+  char *buffer;
+  int channels;
+  RTAUDIO_FORMAT format;
+  if (stream->mode == OUTPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters and do buffer conversion if necessary.
+    if (stream->doConvertBuffer[0]) {
+      convertStreamBuffer(stream, OUTPUT);
+      buffer = stream->deviceBuffer;
+      channels = stream->nDeviceChannels[0];
+      format = stream->deviceFormat[0];
+    }
+    else {
+      buffer = stream->userBuffer;
+      channels = stream->nUserChannels[0];
+      format = stream->userFormat;
+    }
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[0])
+      byteSwapBuffer(buffer, stream->bufferSize * channels, format);
+
+    // Write interleaved samples to device.
+    alWriteFrames(stream->handle[0], buffer, stream->bufferSize);
+  }
+
+  if (stream->mode == INPUT || stream->mode == DUPLEX) {
+
+    // Setup parameters.
+    if (stream->doConvertBuffer[1]) {
+      buffer = stream->deviceBuffer;
+      channels = stream->nDeviceChannels[1];
+      format = stream->deviceFormat[1];
+    }
+    else {
+      buffer = stream->userBuffer;
+      channels = stream->nUserChannels[1];
+      format = stream->userFormat;
+    }
+
+    // Read interleaved samples from device.
+    alReadFrames(stream->handle[1], buffer, stream->bufferSize);
+
+    // Do byte swapping if necessary.
+    if (stream->doByteSwap[1])
+      byteSwapBuffer(buffer, stream->bufferSize * channels, format);
+
+    // Do buffer conversion if necessary.
+    if (stream->doConvertBuffer[1])
+      convertStreamBuffer(stream, INPUT);
+  }
+
+ unlock:
+  MUTEX_UNLOCK(&stream->mutex);
+
+  if (stream->callbackInfo.usingCallback && stopStream)
+    this->stopStream(streamId);
+}
+
+extern "C" void *callbackHandler(void *ptr)
+{
+  CALLBACK_INFO *info = (CALLBACK_INFO *) ptr;
+  RtAudio *object = (RtAudio *) info->object;
+  int stream = info->streamId;
+  bool *usingCallback = &info->usingCallback;
+
+  while ( *usingCallback ) {
+    pthread_testcancel();
+    try {
+      object->tickStream(stream);
+    }
+    catch (RtError &exception) {
+      fprintf(stderr, "\nRtAudio: Callback thread error (%s) ... closing thread.\n\n",
+              exception.getMessage());
+      break;
+    }
+  }
+
+  return 0;
+}
+
+//******************** End of __IRIX_AL__ *********************//
+
+#endif
+
+
+// *************************************************** //
+//
+// Private common (OS-independent) RtAudio methods.
+//
+// *************************************************** //
+
+// This method can be modified to control the behavior of error
+// message reporting and throwing.
+void RtAudio :: error(RtError::TYPE type)
+{
+  if (type == RtError::WARNING) {
+    fprintf(stderr, "\n%s\n\n", message);
+  }
+  else if (type == RtError::DEBUG_WARNING) {
+#if defined(__RTAUDIO_DEBUG__)
+    fprintf(stderr, "\n%s\n\n", message);
+#endif
+  }
+  else {
+    fprintf(stderr, "\n%s\n\n", message);
+    throw RtError(message, type);
+  }
+}
+
+void *RtAudio :: verifyStream(int streamId)
+{
+  // Verify the stream key.
+  if ( streams.find( streamId ) == streams.end() ) {
+    sprintf(message, "RtAudio: invalid stream identifier!");
+    error(RtError::INVALID_STREAM);
+  }
+
+  return streams[streamId];
+}
+
+void RtAudio :: clearDeviceInfo(RTAUDIO_DEVICE *info)
+{
+  // Don't clear the name or DEVICE_ID fields here ... they are
+  // typically set prior to a call of this function.
+  info->probed = false;
+  info->maxOutputChannels = 0;
+  info->maxInputChannels = 0;
+  info->maxDuplexChannels = 0;
+  info->minOutputChannels = 0;
+  info->minInputChannels = 0;
+  info->minDuplexChannels = 0;
+  info->hasDuplexSupport = false;
+  info->nSampleRates = 0;
+  for (int i=0; i<MAX_SAMPLE_RATES; i++)
+    info->sampleRates[i] = 0;
+  info->nativeFormats = 0;
+}
+
+int RtAudio :: formatBytes(RTAUDIO_FORMAT format)
+{
+  if (format == RTAUDIO_SINT16)
+    return 2;
+  else if (format == RTAUDIO_SINT24 || format == RTAUDIO_SINT32 ||
+           format == RTAUDIO_FLOAT32)
+    return 4;
+  else if (format == RTAUDIO_FLOAT64)
+    return 8;
+  else if (format == RTAUDIO_SINT8)
+    return 1;
+
+  sprintf(message,"RtAudio: undefined format in formatBytes().");
+  error(RtError::WARNING);
+
+  return 0;
+}
+
+void RtAudio :: convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode)
+{
+  // This method does format conversion, input/output channel compensation, and
+  // data interleaving/deinterleaving.  24-bit integers are assumed to occupy
+  // the upper three bytes of a 32-bit integer.
+
+  int j, jump_in, jump_out, channels;
+  RTAUDIO_FORMAT format_in, format_out;
+  char *input, *output;
+
+  if (mode == INPUT) { // convert device to user buffer
+    input = stream->deviceBuffer;
+    output = stream->userBuffer;
+    jump_in = stream->nDeviceChannels[1];
+    jump_out = stream->nUserChannels[1];
+    format_in = stream->deviceFormat[1];
+    format_out = stream->userFormat;
+  }
+  else { // convert user to device buffer
+    input = stream->userBuffer;
+    output = stream->deviceBuffer;
+    jump_in = stream->nUserChannels[0];
+    jump_out = stream->nDeviceChannels[0];
+    format_in = stream->userFormat;
+    format_out = stream->deviceFormat[0];
+
+    // clear our device buffer when in/out duplex device channels are different
+    if ( stream->mode == DUPLEX &&
+         stream->nDeviceChannels[0] != stream->nDeviceChannels[1] )
+      memset(output, 0, stream->bufferSize * jump_out * formatBytes(format_out));
+  }
+
+  channels = (jump_in < jump_out) ? jump_in : jump_out;
+
+  // Set up the interleave/deinterleave offsets
+  std::vector<int> offset_in(channels);
+  std::vector<int> offset_out(channels);
+  if (mode == INPUT && stream->deInterleave[1]) {
+    for (int k=0; k<channels; k++) {
+      offset_in[k] = k * stream->bufferSize;
+      offset_out[k] = k;
+      jump_in = 1;
+    }
+  }
+  else if (mode == OUTPUT && stream->deInterleave[0]) {
+    for (int k=0; k<channels; k++) {
+      offset_in[k] = k;
+      offset_out[k] = k * stream->bufferSize;
+      jump_out = 1;
+    }
+  }
+  else {
+    for (int k=0; k<channels; k++) {
+      offset_in[k] = k;
+      offset_out[k] = k;
+    }
+  }
+
+  if (format_out == RTAUDIO_FLOAT64) {
+    FLOAT64 scale;
+    FLOAT64 *out = (FLOAT64 *)output;
+
+    if (format_in == RTAUDIO_SINT8) {
+      signed char *in = (signed char *)input;
+      scale = 1.0 / 128.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT16) {
+      INT16 *in = (INT16 *)input;
+      scale = 1.0 / 32768.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      INT32 *in = (INT32 *)input;
+      scale = 1.0 / 2147483648.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT64) (in[offset_in[j]] & 0xffffff00);
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      INT32 *in = (INT32 *)input;
+      scale = 1.0 / 2147483648.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT64) in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      // Channel compensation and/or (de)interleaving only.
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+  else if (format_out == RTAUDIO_FLOAT32) {
+    FLOAT32 scale;
+    FLOAT32 *out = (FLOAT32 *)output;
+
+    if (format_in == RTAUDIO_SINT8) {
+      signed char *in = (signed char *)input;
+      scale = 1.0 / 128.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT16) {
+      INT16 *in = (INT16 *)input;
+      scale = 1.0 / 32768.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      INT32 *in = (INT32 *)input;
+      scale = 1.0 / 2147483648.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT32) (in[offset_in[j]] & 0xffffff00);
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      INT32 *in = (INT32 *)input;
+      scale = 1.0 / 2147483648.0;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];
+          out[offset_out[j]] *= scale;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      // Channel compensation and/or (de)interleaving only.
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (FLOAT32) in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+  else if (format_out == RTAUDIO_SINT32) {
+    INT32 *out = (INT32 *)output;
+    if (format_in == RTAUDIO_SINT8) {
+      signed char *in = (signed char *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) in[offset_in[j]];
+          out[offset_out[j]] <<= 24;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT16) {
+      INT16 *in = (INT16 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) in[offset_in[j]];
+          out[offset_out[j]] <<= 16;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      // Channel compensation and/or (de)interleaving only.
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+  else if (format_out == RTAUDIO_SINT24) {
+    INT32 *out = (INT32 *)output;
+    if (format_in == RTAUDIO_SINT8) {
+      signed char *in = (signed char *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) in[offset_in[j]];
+          out[offset_out[j]] <<= 24;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT16) {
+      INT16 *in = (INT16 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) in[offset_in[j]];
+          out[offset_out[j]] <<= 16;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      // Channel compensation and/or (de)interleaving only.
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) (in[offset_in[j]] & 0xffffff00);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT32) (in[offset_in[j]] * 2147483647.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+  else if (format_out == RTAUDIO_SINT16) {
+    INT16 *out = (INT16 *)output;
+    if (format_in == RTAUDIO_SINT8) {
+      signed char *in = (signed char *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT16) in[offset_in[j]];
+          out[offset_out[j]] <<= 8;
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT16) {
+      // Channel compensation and/or (de)interleaving only.
+      INT16 *in = (INT16 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT16) ((in[offset_in[j]] >> 16) & 0x0000ffff);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT16) ((in[offset_in[j]] >> 16) & 0x0000ffff);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT16) (in[offset_in[j]] * 32767.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (INT16) (in[offset_in[j]] * 32767.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+  else if (format_out == RTAUDIO_SINT8) {
+    signed char *out = (signed char *)output;
+    if (format_in == RTAUDIO_SINT8) {
+      // Channel compensation and/or (de)interleaving only.
+      signed char *in = (signed char *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = in[offset_in[j]];
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    if (format_in == RTAUDIO_SINT16) {
+      INT16 *in = (INT16 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 8) & 0x00ff);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT24) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 24) & 0x000000ff);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_SINT32) {
+      INT32 *in = (INT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (signed char) ((in[offset_in[j]] >> 24) & 0x000000ff);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT32) {
+      FLOAT32 *in = (FLOAT32 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (signed char) (in[offset_in[j]] * 127.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+    else if (format_in == RTAUDIO_FLOAT64) {
+      FLOAT64 *in = (FLOAT64 *)input;
+      for (int i=0; i<stream->bufferSize; i++) {
+        for (j=0; j<channels; j++) {
+          out[offset_out[j]] = (signed char) (in[offset_in[j]] * 127.0);
+        }
+        in += jump_in;
+        out += jump_out;
+      }
+    }
+  }
+}
+
+void RtAudio :: byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format)
+{
+  register char val;
+  register char *ptr;
+
+  ptr = buffer;
+  if (format == RTAUDIO_SINT16) {
+    for (int i=0; i<samples; i++) {
+      // Swap 1st and 2nd bytes.
+      val = *(ptr);
+      *(ptr) = *(ptr+1);
+      *(ptr+1) = val;
+
+      // Increment 2 bytes.
+      ptr += 2;
+    }
+  }
+  else if (format == RTAUDIO_SINT24 ||
+           format == RTAUDIO_SINT32 ||
+           format == RTAUDIO_FLOAT32) {
+    for (int i=0; i<samples; i++) {
+      // Swap 1st and 4th bytes.
+      val = *(ptr);
+      *(ptr) = *(ptr+3);
+      *(ptr+3) = val;
+
+      // Swap 2nd and 3rd bytes.
+      ptr += 1;
+      val = *(ptr);
+      *(ptr) = *(ptr+1);
+      *(ptr+1) = val;
+
+      // Increment 4 bytes.
+      ptr += 4;
+    }
+  }
+  else if (format == RTAUDIO_FLOAT64) {
+    for (int i=0; i<samples; i++) {
+      // Swap 1st and 8th bytes
+      val = *(ptr);
+      *(ptr) = *(ptr+7);
+      *(ptr+7) = val;
+
+      // Swap 2nd and 7th bytes
+      ptr += 1;
+      val = *(ptr);
+      *(ptr) = *(ptr+5);
+      *(ptr+5) = val;
+
+      // Swap 3rd and 6th bytes
+      ptr += 1;
+      val = *(ptr);
+      *(ptr) = *(ptr+3);
+      *(ptr+3) = val;
+
+      // Swap 4th and 5th bytes
+      ptr += 1;
+      val = *(ptr);
+      *(ptr) = *(ptr+1);
+      *(ptr+1) = val;
+
+      // Increment 8 bytes.
+      ptr += 8;
+    }
+  }
+}
+
+
+// *************************************************** //
+//
+// RtError class definition.
+//
+// *************************************************** //
+
+RtError :: RtError(const char *p, TYPE tipe)
+{
+  type = tipe;
+  strncpy(error_message, p, 256);
+}
+
+RtError :: ~RtError()
+{
+}
+
+void RtError :: printMessage()
+{
+  printf("\n%s\n\n", error_message);
+}
index d9fac56fe60c392f90a9c2878bba737da63cadf4..a9a2a9ae79415b905c64536d1c9628082e7193d3 100644 (file)
--- a/RtAudio.h
+++ b/RtAudio.h
-/******************************************/\r
-/*\r
-  RtAudio - realtime sound I/O C++ class\r
-  by Gary P. Scavone, 2001-2002.\r
-*/\r
-/******************************************/\r
-\r
-#if !defined(__RTAUDIO_H)\r
-#define __RTAUDIO_H\r
-\r
-#include <map>\r
-\r
-#if defined(__LINUX_ALSA__)\r
-  #include <alsa/asoundlib.h>\r
-  #include <pthread.h>\r
-  #include <unistd.h>\r
-\r
-  #define THREAD_TYPE\r
-  typedef snd_pcm_t *AUDIO_HANDLE;\r
-  typedef int DEVICE_ID;\r
-  typedef pthread_t THREAD_HANDLE;\r
-  typedef pthread_mutex_t MUTEX;\r
-\r
-#elif defined(__LINUX_OSS__)\r
-  #include <pthread.h>\r
-  #include <unistd.h>\r
-\r
-  #define THREAD_TYPE\r
-  typedef int AUDIO_HANDLE;\r
-  typedef int DEVICE_ID;\r
-  typedef pthread_t THREAD_HANDLE;\r
-  typedef pthread_mutex_t MUTEX;\r
-\r
-#elif defined(__WINDOWS_DS__)\r
-  #include <windows.h>\r
-  #include <process.h>\r
-\r
-  // The following struct is used to hold the extra variables\r
-  // specific to the DirectSound implementation.\r
-  typedef struct {\r
-    void * object;\r
-    void * buffer;\r
-    UINT bufferPointer;\r
-  } AUDIO_HANDLE;\r
-\r
-  #define THREAD_TYPE __stdcall\r
-  typedef LPGUID DEVICE_ID;\r
-  typedef unsigned long THREAD_HANDLE;\r
-  typedef CRITICAL_SECTION MUTEX;\r
-\r
-#elif defined(__IRIX_AL__)\r
-  #include <dmedia/audio.h>\r
-  #include <pthread.h>\r
-  #include <unistd.h>\r
-\r
-  #define THREAD_TYPE\r
-  typedef ALport AUDIO_HANDLE;\r
-  typedef int DEVICE_ID;\r
-  typedef pthread_t THREAD_HANDLE;\r
-  typedef pthread_mutex_t MUTEX;\r
-\r
-#endif\r
-\r
-\r
-// *************************************************** //\r
-//\r
-// RtError class declaration.\r
-//\r
-// *************************************************** //\r
-\r
-class RtError\r
-{\r
-public:\r
-  enum TYPE {\r
-    WARNING,\r
-    DEBUG_WARNING,\r
-    UNSPECIFIED,\r
-    NO_DEVICES_FOUND,\r
-    INVALID_DEVICE,\r
-    INVALID_STREAM,\r
-    MEMORY_ERROR,\r
-    INVALID_PARAMETER,\r
-    DRIVER_ERROR,\r
-    SYSTEM_ERROR,\r
-    THREAD_ERROR\r
-  };\r
-\r
-protected:\r
-  char error_message[256];\r
-  TYPE type;\r
-\r
-public:\r
-  //! The constructor.\r
-  RtError(const char *p, TYPE tipe = RtError::UNSPECIFIED);\r
-\r
-  //! The destructor.\r
-  virtual ~RtError(void);\r
-\r
-  //! Prints "thrown" error message to stdout.\r
-  virtual void printMessage(void);\r
-\r
-  //! Returns the "thrown" error message TYPE.\r
-  virtual const TYPE& getType(void) { return type; }\r
-\r
-  //! Returns the "thrown" error message string.\r
-  virtual const char *getMessage(void) { return error_message; }\r
-};\r
-\r
-\r
-// *************************************************** //\r
-//\r
-// RtAudio class declaration.\r
-//\r
-// *************************************************** //\r
-\r
-class RtAudio\r
-{\r
-public:\r
-\r
-  // Support for signed integers and floats.  Audio data fed to/from\r
-  // the tickStream() routine is assumed to ALWAYS be in host\r
-  // byte order.  The internal routines will automatically take care of\r
-  // any necessary byte-swapping between the host format and the\r
-  // soundcard.  Thus, endian-ness is not a concern in the following\r
-  // format definitions.\r
-  typedef unsigned long RTAUDIO_FORMAT;\r
-  static const RTAUDIO_FORMAT RTAUDIO_SINT8;\r
-  static const RTAUDIO_FORMAT RTAUDIO_SINT16;\r
-  static const RTAUDIO_FORMAT RTAUDIO_SINT24; /*!< Upper 3 bytes of 32-bit integer. */\r
-  static const RTAUDIO_FORMAT RTAUDIO_SINT32;\r
-  static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; /*!< Normalized between plus/minus 1.0. */\r
-  static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; /*!< Normalized between plus/minus 1.0. */\r
-\r
-  //static const int MAX_SAMPLE_RATES = 14;\r
-  enum { MAX_SAMPLE_RATES = 14 };\r
-\r
-  typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);\r
-\r
-  typedef struct {\r
-    char name[128];\r
-    DEVICE_ID id[2];  /*!< No value reported by getDeviceInfo(). */\r
-    bool probed;       /*!< true if the device capabilities were successfully probed. */\r
-    int maxOutputChannels;\r
-    int maxInputChannels;\r
-    int maxDuplexChannels;\r
-    int minOutputChannels;\r
-    int minInputChannels;\r
-    int minDuplexChannels;\r
-    bool hasDuplexSupport; /*!< true if device supports duplex mode. */\r
-    int nSampleRates;      /*!< Number of discrete rates or -1 if range supported. */\r
-    int sampleRates[MAX_SAMPLE_RATES]; /*!< Supported rates or (min, max) if range. */\r
-    RTAUDIO_FORMAT nativeFormats;     /*!< Bit mask of supported data formats. */\r
-  } RTAUDIO_DEVICE;\r
-\r
-  //! The default constructor.\r
-  /*!\r
-    Probes the system to make sure at least one audio\r
-    input/output device is available and determines\r
-    the api-specific identifier for each device found.\r
-    An RtError error can be thrown if no devices are\r
-    found or if a memory allocation error occurs.\r
-  */\r
-  RtAudio();\r
-\r
-  //! A constructor which can be used to open a stream during instantiation.\r
-  /*!\r
-    The specified output and/or input device identifiers correspond\r
-    to those enumerated via the getDeviceInfo() method.  If device =\r
-    0, the default or first available devices meeting the given\r
-    parameters is selected.  If an output or input channel value is\r
-    zero, the corresponding device value is ignored.  When a stream is\r
-    successfully opened, its identifier is returned via the "streamId"\r
-    pointer.  An RtError can be thrown if no devices are found\r
-    for the given parameters, if a memory allocation error occurs, or\r
-    if a driver error occurs. \sa openStream()\r
-  */\r
-  RtAudio(int *streamId,\r
-          int outputDevice, int outputChannels,\r
-          int inputDevice, int inputChannels,\r
-          RTAUDIO_FORMAT format, int sampleRate,\r
-          int *bufferSize, int numberOfBuffers);\r
-\r
-  //! The destructor.\r
-  /*!\r
-    Stops and closes any open streams and devices and deallocates\r
-    buffer and structure memory.\r
-  */\r
-  ~RtAudio();\r
-\r
-  //! A public method for opening a stream with the specified parameters.\r
-  /*!\r
-    If successful, the opened stream ID is returned.  Otherwise, an\r
-    RtError is thrown.\r
-\r
-    \param outputDevice: If equal to 0, the default or first device\r
-           found meeting the given parameters is opened.  Otherwise, the\r
-           device number should correspond to one of those enumerated via\r
-           the getDeviceInfo() method.\r
-    \param outputChannels: The desired number of output channels.  If\r
-           equal to zero, the outputDevice identifier is ignored.\r
-    \param inputDevice: If equal to 0, the default or first device\r
-           found meeting the given parameters is opened.  Otherwise, the\r
-           device number should correspond to one of those enumerated via\r
-           the getDeviceInfo() method.\r
-    \param inputChannels: The desired number of input channels.  If\r
-           equal to zero, the inputDevice identifier is ignored.\r
-    \param format: An RTAUDIO_FORMAT specifying the desired sample data format.\r
-    \param sampleRate: The desired sample rate (sample frames per second).\r
-    \param *bufferSize: A pointer value indicating the desired internal buffer\r
-           size in sample frames.  The actual value used by the device is\r
-           returned via the same pointer.  A value of zero can be specified,\r
-           in which case the lowest allowable value is determined.\r
-    \param numberOfBuffers: A value which can be used to help control device\r
-           latency.  More buffers typically result in more robust performance,\r
-           though at a cost of greater latency.  A value of zero can be\r
-           specified, in which case the lowest allowable value is used.\r
-  */\r
-  int openStream(int outputDevice, int outputChannels,\r
-                 int inputDevice, int inputChannels,\r
-                 RTAUDIO_FORMAT format, int sampleRate,\r
-                 int *bufferSize, int numberOfBuffers);\r
-\r
-  //! A public method which sets a user-defined callback function for a given stream.\r
-  /*!\r
-    This method assigns a callback function to a specific,\r
-    previously opened stream for non-blocking stream functionality.  A\r
-    separate process is initiated, though the user function is called\r
-    only when the stream is "running" (between calls to the\r
-    startStream() and stopStream() methods, respectively).  The\r
-    callback process remains active for the duration of the stream and\r
-    is automatically shutdown when the stream is closed (via the\r
-    closeStream() method or by object destruction).  The callback\r
-    process can also be shutdown and the user function de-referenced\r
-    through an explicit call to the cancelStreamCallback() method.\r
-    Note that a single stream can use only blocking or callback\r
-    functionality at the same time, though it is possible to alternate\r
-    modes on the same stream through the use of the\r
-    setStreamCallback() and cancelStreamCallback() methods (the\r
-    blocking tickStream() method can be used before a callback is set\r
-    and/or after a callback is cancelled).  An RtError will be\r
-    thrown for an invalid device argument.\r
-  */\r
-  void setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData);\r
-\r
-  //! A public method which cancels a callback process and function for a given stream.\r
-  /*!\r
-    This method shuts down a callback process and de-references the\r
-    user function for a specific stream.  Callback functionality can\r
-    subsequently be restarted on the stream via the\r
-    setStreamCallback() method.  An RtError will be thrown for an\r
-    invalid device argument.\r
-   */\r
-  void cancelStreamCallback(int streamId);\r
-\r
-  //! A public method which returns the number of audio devices found.\r
-  int getDeviceCount(void);\r
-\r
-  //! Fill a user-supplied RTAUDIO_DEVICE structure for a specified device.\r
-  /*!\r
-    Any device between 0 and getDeviceCount()-1 is valid.  If a\r
-    device is busy or otherwise unavailable, the structure member\r
-    "probed" has a value of "false".  The system default input and\r
-    output devices are referenced by device identifier = 0.  On\r
-    systems which allow dynamic default device settings, the default\r
-    devices are not identified by name (specific device enumerations\r
-    are assigned device identifiers > 0).  An RtError will be\r
-    thrown for an invalid device argument.\r
-  */\r
-  void getDeviceInfo(int device, RTAUDIO_DEVICE *info);\r
-\r
-  //! A public method which returns a pointer to the buffer for an open stream.\r
-  /*!\r
-    The user should fill and/or read the buffer data in interleaved format\r
-    and then call the tickStream() method.  An RtError will be\r
-    thrown for an invalid stream identifier.\r
-  */\r
-  char * const getStreamBuffer(int streamId);\r
-\r
-  //! Public method used to trigger processing of input/output data for a stream.\r
-  /*!\r
-    This method blocks until all buffer data is read/written.  An\r
-    RtError will be thrown for an invalid stream identifier or if\r
-    a driver error occurs.\r
-  */\r
-  void tickStream(int streamId);\r
-\r
-  //! Public method which closes a stream and frees any associated buffers.\r
-  /*!\r
-    If an invalid stream identifier is specified, this method\r
-    issues a warning and returns (an RtError is not thrown).\r
-  */\r
-  void closeStream(int streamId);\r
-\r
-  //! Public method which starts a stream.\r
-  /*!\r
-    An RtError will be thrown for an invalid stream identifier\r
-    or if a driver error occurs.\r
-  */\r
-  void startStream(int streamId);\r
-\r
-  //! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.\r
-  /*!\r
-    An RtError will be thrown for an invalid stream identifier\r
-    or if a driver error occurs.\r
-  */\r
-  void stopStream(int streamId);\r
-\r
-  //! Stop a stream, discarding any samples remaining in the input/output queue.\r
-  /*!\r
-    An RtError will be thrown for an invalid stream identifier\r
-    or if a driver error occurs.\r
-  */\r
-  void abortStream(int streamId);\r
-\r
-  //! Queries a stream to determine whether a call to the tickStream() method will block.\r
-  /*!\r
-    A return value of 0 indicates that the stream will NOT block.  A positive\r
-    return value indicates the number of sample frames that cannot yet be\r
-    processed without blocking.\r
-  */\r
-  int streamWillBlock(int streamId);\r
-\r
-protected:\r
-\r
-private:\r
-\r
-  static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];\r
-\r
-  enum { FAILURE, SUCCESS };\r
-\r
-  enum STREAM_MODE {\r
-    PLAYBACK,\r
-    RECORD,\r
-    DUPLEX,\r
-    UNINITIALIZED = -75\r
-  };\r
-\r
-  enum STREAM_STATE {\r
-    STREAM_STOPPED,\r
-    STREAM_RUNNING\r
-  };\r
-\r
-  typedef struct {\r
-    int device[2];          // Playback and record, respectively.\r
-    STREAM_MODE mode;       // PLAYBACK, RECORD, or DUPLEX.\r
-    AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.\r
-    STREAM_STATE state;     // STOPPED or RUNNING\r
-    char *userBuffer;\r
-    char *deviceBuffer;\r
-    bool doConvertBuffer[2]; // Playback and record, respectively.\r
-    bool deInterleave[2];    // Playback and record, respectively.\r
-    bool doByteSwap[2];      // Playback and record, respectively.\r
-    int sampleRate;\r
-    int bufferSize;\r
-    int nBuffers;\r
-    int nUserChannels[2];    // Playback and record, respectively.\r
-    int nDeviceChannels[2];  // Playback and record channels, respectively.\r
-    RTAUDIO_FORMAT userFormat;\r
-    RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.\r
-    bool usingCallback;\r
-    THREAD_HANDLE thread;\r
-    MUTEX mutex;\r
-    RTAUDIO_CALLBACK callback;\r
-    void *userData;\r
-  } RTAUDIO_STREAM;\r
-\r
-  typedef signed short INT16;\r
-  typedef signed int INT32;\r
-  typedef float FLOAT32;\r
-  typedef double FLOAT64;\r
-\r
-  char message[256];\r
-  int nDevices;\r
-  RTAUDIO_DEVICE *devices;\r
-\r
-  std::map<int, void *> streams;\r
-\r
-  //! Private error method to allow global control over error handling.\r
-  void error(RtError::TYPE type);\r
-\r
-  /*!\r
-    Private method to count the system audio devices, allocate the\r
-    RTAUDIO_DEVICE structures, and probe the device capabilities.\r
-  */\r
-  void initialize(void);\r
-\r
-  //! Private method to clear an RTAUDIO_DEVICE structure.\r
-  void clearDeviceInfo(RTAUDIO_DEVICE *info);\r
-\r
-  /*!\r
-    Private method which attempts to fill an RTAUDIO_DEVICE\r
-    structure for a given device.  If an error is encountered during\r
-    the probe, a "warning" message is reported and the value of\r
-    "probed" remains false (no exception is thrown).  A successful\r
-    probe is indicated by probed = true.\r
-  */\r
-  void probeDeviceInfo(RTAUDIO_DEVICE *info);\r
-\r
-  /*!\r
-    Private method which attempts to open a device with the given parameters.\r
-    If an error is encountered during the probe, a "warning" message is\r
-    reported and FAILURE is returned (no exception is thrown). A\r
-    successful probe is indicated by a return value of SUCCESS.\r
-  */\r
-  bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,\r
-                       STREAM_MODE mode, int channels, \r
-                       int sampleRate, RTAUDIO_FORMAT format,\r
-                       int *bufferSize, int numberOfBuffers);\r
-\r
-  /*!\r
-    Private common method used to check validity of a user-passed\r
-    stream ID.  When the ID is valid, this method returns a pointer to\r
-    an RTAUDIO_STREAM structure (in the form of a void pointer).\r
-    Otherwise, an "invalid identifier" exception is thrown.\r
-  */\r
-  void *verifyStream(int streamId);\r
-\r
-  /*!\r
-    Private method used to perform format, channel number, and/or interleaving\r
-    conversions between the user and device buffers.\r
-  */\r
-  void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);\r
-\r
-  //! Private method used to perform byte-swapping on buffers.\r
-  void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);\r
-\r
-  //! Private method which returns the number of bytes for a given format.\r
-  int formatBytes(RTAUDIO_FORMAT format);\r
-};\r
-\r
-// Uncomment the following definition to have extra information spewed to stderr.\r
-//#define RTAUDIO_DEBUG\r
-\r
-#endif\r
+/************************************************************************/
+/*! \class RtAudio
+    \brief Realtime audio i/o C++ class.
+
+    RtAudio provides a common API (Application Programming Interface)
+    for realtime audio input/output across Linux (native ALSA and
+    OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound
+    and ASIO) operating systems.
+
+    RtAudio WWW site: http://www-ccrma.stanford.edu/~gary/rtaudio/
+
+    RtAudio: a realtime audio i/o C++ class
+    Copyright (c) 2001-2002 Gary P. Scavone
+
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation files
+    (the "Software"), to deal in the Software without restriction,
+    including without limitation the rights to use, copy, modify, merge,
+    publish, distribute, sublicense, and/or sell copies of the Software,
+    and to permit persons to whom the Software is furnished to do so,
+    subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    Any person wishing to distribute modifications to the Software is
+    requested to send the modifications to the original developer so that
+    they can be incorporated into the canonical version.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+/************************************************************************/
+
+#if !defined(__RTAUDIO_H)
+#define __RTAUDIO_H
+
+#include <map>
+
+#if defined(__LINUX_ALSA__)
+  #include <alsa/asoundlib.h>
+  #include <pthread.h>
+  #include <unistd.h>
+
+  typedef snd_pcm_t *AUDIO_HANDLE;
+  typedef int DEVICE_ID;
+  typedef pthread_t THREAD_HANDLE;
+  typedef pthread_mutex_t MUTEX;
+
+#elif defined(__LINUX_OSS__)
+  #include <pthread.h>
+  #include <unistd.h>
+
+  typedef int AUDIO_HANDLE;
+  typedef int DEVICE_ID;
+  typedef pthread_t THREAD_HANDLE;
+  typedef pthread_mutex_t MUTEX;
+
+#elif defined(__WINDOWS_DS__)
+  #include <windows.h>
+  #include <process.h>
+
+  // The following struct is used to hold the extra variables
+  // specific to the DirectSound implementation.
+  typedef struct {
+    void * object;
+    void * buffer;
+    UINT bufferPointer;
+  } AUDIO_HANDLE;
+
+  typedef LPGUID DEVICE_ID;
+  typedef unsigned long THREAD_HANDLE;
+  typedef CRITICAL_SECTION MUTEX;
+
+#elif defined(__WINDOWS_ASIO__)
+  #include <windows.h>
+  #include <process.h>
+
+  typedef int AUDIO_HANDLE;
+  typedef int DEVICE_ID;
+  typedef unsigned long THREAD_HANDLE;
+  typedef CRITICAL_SECTION MUTEX;
+
+#elif defined(__IRIX_AL__)
+  #include <dmedia/audio.h>
+  #include <pthread.h>
+  #include <unistd.h>
+
+  typedef ALport AUDIO_HANDLE;
+  typedef long DEVICE_ID;
+  typedef pthread_t THREAD_HANDLE;
+  typedef pthread_mutex_t MUTEX;
+
+#elif defined(__MACOSX_CORE__)
+
+  #include <CoreAudio/AudioHardware.h>
+  #include <pthread.h>
+
+  typedef unsigned int AUDIO_HANDLE;
+  typedef AudioDeviceID DEVICE_ID;
+  typedef pthread_t THREAD_HANDLE;
+  typedef pthread_mutex_t MUTEX;
+
+#endif
+
+
+/************************************************************************/
+/*! \class RtError
+    \brief Exception handling class for RtAudio.
+
+    The RtError class is quite simple but it does allow errors to be
+    "caught" by RtError::TYPE. Almost all RtAudio methods can "throw"
+    an RtError, 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.
+*/
+/************************************************************************/
+
+class RtError
+{
+public:
+  //! Defined RtError types.
+  enum TYPE {
+    WARNING,
+    DEBUG_WARNING,
+    UNSPECIFIED,
+    NO_DEVICES_FOUND,
+    INVALID_DEVICE,
+    INVALID_STREAM,
+    MEMORY_ERROR,
+    INVALID_PARAMETER,
+    DRIVER_ERROR,
+    SYSTEM_ERROR,
+    THREAD_ERROR
+  };
+
+protected:
+  char error_message[256];
+  TYPE type;
+
+public:
+  //! The constructor.
+  RtError(const char *p, TYPE tipe = RtError::UNSPECIFIED);
+
+  //! The destructor.
+  virtual ~RtError(void);
+
+  //! Prints "thrown" error message to stdout.
+  virtual void printMessage(void);
+
+  //! Returns the "thrown" error message TYPE.
+  virtual const TYPE& getType(void) { return type; }
+
+  //! Returns the "thrown" error message string.
+  virtual const char *getMessage(void) { return error_message; }
+};
+
+
+// This public structure type is used to pass callback information
+// between the private RtAudio stream structure and global callback
+// handling functions.
+typedef struct {
+  void *object;  // Used as a "this" pointer.
+  int streamId;
+  DEVICE_ID device[2];
+  THREAD_HANDLE thread;
+  void *callback;
+  void *buffers;
+  unsigned long waitTime;
+  bool blockTick;
+  bool stopStream;
+  bool usingCallback;
+  void *userData;
+} CALLBACK_INFO;
+
+
+// *************************************************** //
+//
+// RtAudio class declaration.
+//
+// *************************************************** //
+
+class RtAudio
+{
+public:
+
+  // Support for signed integers and floats.  Audio data fed to/from
+  // the tickStream() routine is assumed to ALWAYS be in host
+  // byte order.  The internal routines will automatically take care of
+  // any necessary byte-swapping between the host format and the
+  // soundcard.  Thus, endian-ness is not a concern in the following
+  // format definitions.
+  typedef unsigned long RTAUDIO_FORMAT;
+  static const RTAUDIO_FORMAT RTAUDIO_SINT8; /*!< 8-bit signed integer. */
+  static const RTAUDIO_FORMAT RTAUDIO_SINT16; /*!< 16-bit signed integer. */
+  static const RTAUDIO_FORMAT RTAUDIO_SINT24; /*!< Upper 3 bytes of 32-bit signed integer. */
+  static const RTAUDIO_FORMAT RTAUDIO_SINT32; /*!< 32-bit signed integer. */
+  static const RTAUDIO_FORMAT RTAUDIO_FLOAT32; /*!< Normalized between plus/minus 1.0. */
+  static const RTAUDIO_FORMAT RTAUDIO_FLOAT64; /*!< Normalized between plus/minus 1.0. */
+
+  //static const int MAX_SAMPLE_RATES = 14;
+  enum { MAX_SAMPLE_RATES = 14 };
+
+  typedef int (*RTAUDIO_CALLBACK)(char *buffer, int bufferSize, void *userData);
+
+  //! The public device information structure for passing queried values.
+  typedef struct {
+    char name[128];    /*!< Character string device identifier. */
+    DEVICE_ID id[2];  /* No value reported by getDeviceInfo(). */
+    bool probed;       /*!< true if the device capabilities were successfully probed. */
+    int maxOutputChannels; /*!< Maximum output channels supported by device. */
+    int maxInputChannels;  /*!< Maximum input channels supported by device. */
+    int maxDuplexChannels; /*!< Maximum simultaneous input/output channels supported by device. */
+    int minOutputChannels; /*!< Minimum output channels supported by device. */
+    int minInputChannels;  /*!< Minimum input channels supported by device. */
+    int minDuplexChannels; /*!< Minimum simultaneous input/output channels supported by device. */
+    bool hasDuplexSupport; /*!< true if device supports duplex mode. */
+    bool isDefault;        /*!< true if this is the default output or input device. */
+    int nSampleRates;      /*!< Number of discrete rates or -1 if range supported. */
+    int sampleRates[MAX_SAMPLE_RATES]; /*!< Supported rates or (min, max) if range. */
+    RTAUDIO_FORMAT nativeFormats;     /*!< Bit mask of supported data formats. */
+  } RTAUDIO_DEVICE;
+
+  //! The default constructor.
+  /*!
+    Probes the system to make sure at least one audio input/output
+    device is available and determines the api-specific identifier for
+    each device found.  An RtError error can be thrown if no devices
+    are found or if a memory allocation error occurs.
+  */
+  RtAudio();
+
+  //! A constructor which can be used to open a stream during instantiation.
+  /*!
+    The specified output and/or input device identifiers correspond
+    to those enumerated via the getDeviceInfo() method.  If device =
+    0, the default or first available devices meeting the given
+    parameters is selected.  If an output or input channel value is
+    zero, the corresponding device value is ignored.  When a stream is
+    successfully opened, its identifier is returned via the "streamId"
+    pointer.  An RtError can be thrown if no devices are found
+    for the given parameters, if a memory allocation error occurs, or
+    if a driver error occurs. \sa openStream()
+  */
+  RtAudio(int *streamId,
+          int outputDevice, int outputChannels,
+          int inputDevice, int inputChannels,
+          RTAUDIO_FORMAT format, int sampleRate,
+          int *bufferSize, int numberOfBuffers);
+
+  //! The destructor.
+  /*!
+    Stops and closes any open streams and devices and deallocates
+    buffer and structure memory.
+  */
+  ~RtAudio();
+
+  //! A public method for opening a stream with the specified parameters.
+  /*!
+    If successful, the opened stream ID is returned.  Otherwise, an
+    RtError is thrown.
+
+    \param outputDevice: If equal to 0, the default or first device
+           found meeting the given parameters is opened.  Otherwise, the
+           device number should correspond to one of those enumerated via
+           the getDeviceInfo() method.
+    \param outputChannels: The desired number of output channels.  If
+           equal to zero, the outputDevice identifier is ignored.
+    \param inputDevice: If equal to 0, the default or first device
+           found meeting the given parameters is opened.  Otherwise, the
+           device number should correspond to one of those enumerated via
+           the getDeviceInfo() method.
+    \param inputChannels: The desired number of input channels.  If
+           equal to zero, the inputDevice identifier is ignored.
+    \param format: An RTAUDIO_FORMAT specifying the desired sample data format.
+    \param sampleRate: The desired sample rate (sample frames per second).
+    \param *bufferSize: A pointer value indicating the desired internal buffer
+           size in sample frames.  The actual value used by the device is
+           returned via the same pointer.  A value of zero can be specified,
+           in which case the lowest allowable value is determined.
+    \param numberOfBuffers: A value which can be used to help control device
+           latency.  More buffers typically result in more robust performance,
+           though at a cost of greater latency.  A value of zero can be
+           specified, in which case the lowest allowable value is used.
+  */
+  int openStream(int outputDevice, int outputChannels,
+                 int inputDevice, int inputChannels,
+                 RTAUDIO_FORMAT format, int sampleRate,
+                 int *bufferSize, int numberOfBuffers);
+
+  //! A public method which sets a user-defined callback function for a given stream.
+  /*!
+    This method assigns a callback function to a specific,
+    previously opened stream for non-blocking stream functionality.  A
+    separate process is initiated, though the user function is called
+    only when the stream is "running" (between calls to the
+    startStream() and stopStream() methods, respectively).  The
+    callback process remains active for the duration of the stream and
+    is automatically shutdown when the stream is closed (via the
+    closeStream() method or by object destruction).  The callback
+    process can also be shutdown and the user function de-referenced
+    through an explicit call to the cancelStreamCallback() method.
+    Note that a single stream can use only blocking or callback
+    functionality at the same time, though it is possible to alternate
+    modes on the same stream through the use of the
+    setStreamCallback() and cancelStreamCallback() methods (the
+    blocking tickStream() method can be used before a callback is set
+    and/or after a callback is cancelled).  An RtError will be thrown
+    for an invalid device argument.
+  */
+  void setStreamCallback(int streamId, RTAUDIO_CALLBACK callback, void *userData);
+
+  //! A public method which cancels a callback process and function for a given stream.
+  /*!
+    This method shuts down a callback process and de-references the
+    user function for a specific stream.  Callback functionality can
+    subsequently be restarted on the stream via the
+    setStreamCallback() method.  An RtError will be thrown for an
+    invalid device argument.
+   */
+  void cancelStreamCallback(int streamId);
+
+  //! A public method which returns the number of audio devices found.
+  int getDeviceCount(void);
+
+  //! Fill a user-supplied RTAUDIO_DEVICE structure for a specified device number.
+  /*!
+    Any device integer between 1 and getDeviceCount() is valid.  If
+    a device is busy or otherwise unavailable, the structure member
+    "probed" will have a value of "false" and all other members are
+    undefined.  If the specified device is the current default input
+    or output device, the "isDefault" member will have a value of
+    "true".  An RtError will be thrown for an invalid device argument.
+  */
+  void getDeviceInfo(int device, RTAUDIO_DEVICE *info);
+
+  //! A public method which returns a pointer to the buffer for an open stream.
+  /*!
+    The user should fill and/or read the buffer data in interleaved format
+    and then call the tickStream() method.  An RtError will be
+    thrown for an invalid stream identifier.
+  */
+  char * const getStreamBuffer(int streamId);
+
+  //! Public method used to trigger processing of input/output data for a stream.
+  /*!
+    This method blocks until all buffer data is read/written.  An
+    RtError will be thrown for an invalid stream identifier or if
+    a driver error occurs.
+  */
+  void tickStream(int streamId);
+
+  //! Public method which closes a stream and frees any associated buffers.
+  /*!
+    If an invalid stream identifier is specified, this method
+    issues a warning and returns (an RtError is not thrown).
+  */
+  void closeStream(int streamId);
+
+  //! Public method which starts a stream.
+  /*!
+    An RtError will be thrown for an invalid stream identifier
+    or if a driver error occurs.
+  */
+  void startStream(int streamId);
+
+  //! Stop a stream, allowing any samples remaining in the queue to be played out and/or read in.
+  /*!
+    An RtError will be thrown for an invalid stream identifier
+    or if a driver error occurs.
+  */
+  void stopStream(int streamId);
+
+  //! Stop a stream, discarding any samples remaining in the input/output queue.
+  /*!
+    An RtError will be thrown for an invalid stream identifier
+    or if a driver error occurs.
+  */
+  void abortStream(int streamId);
+
+  //! Queries a stream to determine whether a call to the tickStream() 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.
+  */
+  int streamWillBlock(int streamId);
+
+#if (defined(__MACOSX_CORE__) || defined(__WINDOWS_ASIO__))
+  // This function is intended for internal use only.  It must be
+  // public because it is called by the internal callback handler,
+  // which is not a member of RtAudio.  External use of this function
+  // will most likely produce highly undesireable results!
+  void callbackEvent(int streamId, DEVICE_ID deviceId, void *inData, void *outData);
+#endif
+
+protected:
+
+private:
+
+  static const unsigned int SAMPLE_RATES[MAX_SAMPLE_RATES];
+
+  enum { FAILURE, SUCCESS };
+
+  enum STREAM_MODE {
+    OUTPUT,
+    INPUT,
+    DUPLEX,
+    UNINITIALIZED = -75
+  };
+
+  enum STREAM_STATE {
+    STREAM_STOPPED,
+    STREAM_RUNNING
+  };
+
+  typedef struct {
+    int device[2];          // Playback and record, respectively.
+    STREAM_MODE mode;       // OUTPUT, INPUT, or DUPLEX.
+    AUDIO_HANDLE handle[2]; // Playback and record handles, respectively.
+    STREAM_STATE state;     // STOPPED or RUNNING
+    char *userBuffer;
+    char *deviceBuffer;
+    bool doConvertBuffer[2]; // Playback and record, respectively.
+    bool deInterleave[2];    // Playback and record, respectively.
+    bool doByteSwap[2];      // Playback and record, respectively.
+    int sampleRate;
+    int bufferSize;
+    int nBuffers;
+    int nUserChannels[2];    // Playback and record, respectively.
+    int nDeviceChannels[2];  // Playback and record channels, respectively.
+    RTAUDIO_FORMAT userFormat;
+    RTAUDIO_FORMAT deviceFormat[2]; // Playback and record, respectively.
+    MUTEX mutex;
+    CALLBACK_INFO callbackInfo;
+  } RTAUDIO_STREAM;
+
+  typedef signed short INT16;
+  typedef signed int INT32;
+  typedef float FLOAT32;
+  typedef double FLOAT64;
+
+  char message[256];
+  int nDevices;
+  RTAUDIO_DEVICE *devices;
+
+  std::map<int, void *> streams;
+
+  //! Private error method to allow global control over error handling.
+  void error(RtError::TYPE type);
+
+  /*!
+    Private method to count the system audio devices, allocate the
+    RTAUDIO_DEVICE structures, and probe the device capabilities.
+  */
+  void initialize(void);
+
+  /*!
+    Private method which returns the index in the devices array to
+    the default input device.
+  */
+  int getDefaultInputDevice(void);
+
+  /*!
+    Private method which returns the index in the devices array to
+    the default output device.
+  */
+  int getDefaultOutputDevice(void);
+
+  //! Private method to clear an RTAUDIO_DEVICE structure.
+  void clearDeviceInfo(RTAUDIO_DEVICE *info);
+
+  /*!
+    Private method which attempts to fill an RTAUDIO_DEVICE
+    structure for a given device.  If an error is encountered during
+    the probe, a "warning" message is reported and the value of
+    "probed" remains false (no exception is thrown).  A successful
+    probe is indicated by probed = true.
+  */
+  void probeDeviceInfo(RTAUDIO_DEVICE *info);
+
+  /*!
+    Private method which attempts to open a device with the given parameters.
+    If an error is encountered during the probe, a "warning" message is
+    reported and FAILURE is returned (no exception is thrown). A
+    successful probe is indicated by a return value of SUCCESS.
+  */
+  bool probeDeviceOpen(int device, RTAUDIO_STREAM *stream,
+                       STREAM_MODE mode, int channels, 
+                       int sampleRate, RTAUDIO_FORMAT format,
+                       int *bufferSize, int numberOfBuffers);
+
+  /*!
+    Private common method used to check validity of a user-passed
+    stream ID.  When the ID is valid, this method returns a pointer to
+    an RTAUDIO_STREAM structure (in the form of a void pointer).
+    Otherwise, an "invalid identifier" exception is thrown.
+  */
+  void *verifyStream(int streamId);
+
+  /*!
+    Private method used to perform format, channel number, and/or interleaving
+    conversions between the user and device buffers.
+  */
+  void convertStreamBuffer(RTAUDIO_STREAM *stream, STREAM_MODE mode);
+
+  //! Private method used to perform byte-swapping on buffers.
+  void byteSwapBuffer(char *buffer, int samples, RTAUDIO_FORMAT format);
+
+  //! Private method which returns the number of bytes for a given format.
+  int formatBytes(RTAUDIO_FORMAT format);
+};
+
+// Define the following flag to have extra information spewed to stderr.
+//#define __RTAUDIO_DEBUG__
+
+#endif
diff --git a/config.guess b/config.guess
new file mode 100755 (executable)
index 0000000..ba66165
--- /dev/null
@@ -0,0 +1,1371 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+#   Free Software Foundation, Inc.
+
+timestamp='2001-04-20'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Written by Per Bothner <bothner@cygnus.com>.
+# Please send patches to <config-patches@gnu.org>.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2000
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit 0 ;;
+    --version | -v )
+       echo "$version" ; exit 0 ;;
+    --help | --h* | -h )
+       echo "$usage"; exit 0 ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+
+dummy=dummy-$$
+trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script.
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int dummy(){}" > $dummy.c
+       for c in cc gcc c89 ; do
+         ($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1
+         if test $? = 0 ; then
+            CC_FOR_BUILD="$c"; break
+         fi
+       done
+       rm -f $dummy.c $dummy.o $dummy.rel
+       if test x"$CC_FOR_BUILD" = x ; then
+         CC_FOR_BUILD=no_compiler_found
+       fi
+       ;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 8/24/94.)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+       PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+       # Netbsd (nbsd) targets should (where applicable) match one or
+       # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+       # *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+       # switched to ELF, *-*-netbsd* would select the old
+       # object file format.  This provides both forward
+       # compatibility and a consistent mechanism for selecting the
+       # object file format.
+       # Determine the machine/vendor (is the vendor relevant).
+       case "${UNAME_MACHINE}" in
+           amiga) machine=m68k-unknown ;;
+           arm32) machine=arm-unknown ;;
+           atari*) machine=m68k-atari ;;
+           sun3*) machine=m68k-sun ;;
+           mac68k) machine=m68k-apple ;;
+           macppc) machine=powerpc-apple ;;
+           hp3[0-9][05]) machine=m68k-hp ;;
+           ibmrt|romp-ibm) machine=romp-ibm ;;
+           *) machine=${UNAME_MACHINE}-unknown ;;
+       esac
+       # The Operating System including object format, if it has switched
+       # to ELF recently, or will in the future.
+       case "${UNAME_MACHINE}" in
+           i386|sparc|amiga|arm*|hp300|mvme68k|vax|atari|luna68k|mac68k|news68k|next68k|pc532|sun3*|x68k)
+               if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+                       | grep __ELF__ >/dev/null
+               then
+                   # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+                   # Return netbsd for either.  FIX?
+                   os=netbsd
+               else
+                   os=netbsdelf
+               fi
+               ;;
+           *)
+               os=netbsd
+               ;;
+       esac
+       # The OS release
+       release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+       # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+       # contains redundant information, the shorter form:
+       # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+       echo "${machine}-${os}${release}"
+       exit 0 ;;
+    alpha:OSF1:*:*)
+       if test $UNAME_RELEASE = "V4.0"; then
+               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+       fi
+       # A Vn.n version is a released version.
+       # A Tn.n version is a released field test version.
+       # A Xn.n version is an unreleased experimental baselevel.
+       # 1.2 uses "1.2" for uname -r.
+       cat <<EOF >$dummy.s
+       .data
+\$Lformat:
+       .byte 37,100,45,37,120,10,0     # "%d-%x\n"
+
+       .text
+       .globl main
+       .align 4
+       .ent main
+main:
+       .frame \$30,16,\$26,0
+       ldgp \$29,0(\$27)
+       .prologue 1
+       .long 0x47e03d80 # implver \$0
+       lda \$2,-1
+       .long 0x47e20c21 # amask \$2,\$1
+       lda \$16,\$Lformat
+       mov \$0,\$17
+       not \$1,\$18
+       jsr \$26,printf
+       ldgp \$29,0(\$26)
+       mov 0,\$16
+       jsr \$26,exit
+       .end main
+EOF
+       $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
+       if test "$?" = 0 ; then
+               case `./$dummy` in
+                       0-0)
+                               UNAME_MACHINE="alpha"
+                               ;;
+                       1-0)
+                               UNAME_MACHINE="alphaev5"
+                               ;;
+                       1-1)
+                               UNAME_MACHINE="alphaev56"
+                               ;;
+                       1-101)
+                               UNAME_MACHINE="alphapca56"
+                               ;;
+                       2-303)
+                               UNAME_MACHINE="alphaev6"
+                               ;;
+                       2-307)
+                               UNAME_MACHINE="alphaev67"
+                               ;;
+               esac
+       fi
+       rm -f $dummy.s $dummy
+       echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+       exit 0 ;;
+    Alpha\ *:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # Should we change UNAME_MACHINE based on the output of uname instead
+       # of the specific Alpha model?
+       echo alpha-pc-interix
+       exit 0 ;;
+    21064:Windows_NT:50:3)
+       echo alpha-dec-winnt3.5
+       exit 0 ;;
+    Amiga*:UNIX_System_V:4.0:*)
+       echo m68k-unknown-sysv4
+       exit 0;;
+    amiga:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+       echo ${UNAME_MACHINE}-unknown-amigaos
+       exit 0 ;;
+    arc64:OpenBSD:*:*)
+       echo mips64el-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    arc:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    hkmips:OpenBSD:*:*)
+       echo mips-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    pmax:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    sgi:OpenBSD:*:*)
+       echo mips-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    wgrisc:OpenBSD:*:*)
+       echo mipsel-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    *:OS/390:*:*)
+       echo i370-ibm-openedition
+       exit 0 ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+       echo arm-acorn-riscix${UNAME_RELEASE}
+       exit 0;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+       echo hppa1.1-hitachi-hiuxmpp
+       exit 0;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+       # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+       if test "`(/bin/universe) 2>/dev/null`" = att ; then
+               echo pyramid-pyramid-sysv3
+       else
+               echo pyramid-pyramid-bsd
+       fi
+       exit 0 ;;
+    NILE*:*:*:dcosx)
+       echo pyramid-pyramid-svr4
+       exit 0 ;;
+    sun4H:SunOS:5.*:*)
+       echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+       echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    i86pc:SunOS:5.*:*)
+       echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:6*:*)
+       # According to config.sub, this is the proper way to canonicalize
+       # SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+       # it's likely to be more like Solaris than SunOS4.
+       echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    sun4*:SunOS:*:*)
+       case "`/usr/bin/arch -k`" in
+           Series*|S4*)
+               UNAME_RELEASE=`uname -v`
+               ;;
+       esac
+       # Japanese Language versions have a version number like `4.1.3-JL'.
+       echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+       exit 0 ;;
+    sun3*:SunOS:*:*)
+       echo m68k-sun-sunos${UNAME_RELEASE}
+       exit 0 ;;
+    sun*:*:4.2BSD:*)
+       UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+       test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+       case "`/bin/arch`" in
+           sun3)
+               echo m68k-sun-sunos${UNAME_RELEASE}
+               ;;
+           sun4)
+               echo sparc-sun-sunos${UNAME_RELEASE}
+               ;;
+       esac
+       exit 0 ;;
+    aushp:SunOS:*:*)
+       echo sparc-auspex-sunos${UNAME_RELEASE}
+       exit 0 ;;
+    atari*:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit 0 ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+       echo m68k-atari-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+       exit 0 ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit 0 ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit 0 ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit 0 ;;
+    sun3*:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mac68k:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mvme68k:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    mvme88k:OpenBSD:*:*)
+       echo m88k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    powerpc:machten:*:*)
+       echo powerpc-apple-machten${UNAME_RELEASE}
+       exit 0 ;;
+    RISC*:Mach:*:*)
+       echo mips-dec-mach_bsd4.3
+       exit 0 ;;
+    RISC*:ULTRIX:*:*)
+       echo mips-dec-ultrix${UNAME_RELEASE}
+       exit 0 ;;
+    VAX*:ULTRIX*:*:*)
+       echo vax-dec-ultrix${UNAME_RELEASE}
+       exit 0 ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+       echo clipper-intergraph-clix${UNAME_RELEASE}
+       exit 0 ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+       sed 's/^        //' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+       #if defined (host_mips) && defined (MIPSEB)
+       #if defined (SYSTYPE_SYSV)
+         printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_SVR4)
+         printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+       #endif
+       #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+         printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+       #endif
+       #endif
+         exit (-1);
+       }
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy \
+         && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
+         && rm -f $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       echo mips-mips-riscos${UNAME_RELEASE}
+       exit 0 ;;
+    Motorola:PowerMAX_OS:*:*)
+       echo powerpc-motorola-powermax
+       exit 0 ;;
+    Night_Hawk:Power_UNIX:*:*)
+       echo powerpc-harris-powerunix
+       exit 0 ;;
+    m88k:CX/UX:7*:*)
+       echo m88k-harris-cxux7
+       exit 0 ;;
+    m88k:*:4*:R4*)
+       echo m88k-motorola-sysv4
+       exit 0 ;;
+    m88k:*:3*:R3*)
+       echo m88k-motorola-sysv3
+       exit 0 ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+       if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+       then
+           if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+              [ ${TARGET_BINARY_INTERFACE}x = x ]
+           then
+               echo m88k-dg-dgux${UNAME_RELEASE}
+           else
+               echo m88k-dg-dguxbcs${UNAME_RELEASE}
+           fi
+       else
+           echo i586-dg-dgux${UNAME_RELEASE}
+       fi
+       exit 0 ;;
+    M88*:DolphinOS:*:*)        # DolphinOS (SVR3)
+       echo m88k-dolphin-sysv3
+       exit 0 ;;
+    M88*:*:R3*:*)
+       # Delta 88k system running SVR3
+       echo m88k-motorola-sysv3
+       exit 0 ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+       echo m88k-tektronix-sysv3
+       exit 0 ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+       echo m68k-tektronix-bsd
+       exit 0 ;;
+    *:IRIX*:*:*)
+       echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+       exit 0 ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+       echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
+       exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+       echo i386-ibm-aix
+       exit 0 ;;
+    ia64:AIX:*:*)
+       if [ -x /usr/bin/oslevel ] ; then
+               IBM_REV=`/usr/bin/oslevel`
+       else
+               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+       fi
+       echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+       exit 0 ;;
+    *:AIX:2:3)
+       if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+               sed 's/^                //' << EOF >$dummy.c
+               #include <sys/systemcfg.h>
+
+               main()
+                       {
+                       if (!__power_pc())
+                               exit(1);
+                       puts("powerpc-ibm-aix3.2.5");
+                       exit(0);
+                       }
+EOF
+               $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
+               rm -f $dummy.c $dummy
+               echo rs6000-ibm-aix3.2.5
+       elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+               echo rs6000-ibm-aix3.2.4
+       else
+               echo rs6000-ibm-aix3.2
+       fi
+       exit 0 ;;
+    *:AIX:*:[45])
+       IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
+       if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+               IBM_ARCH=rs6000
+       else
+               IBM_ARCH=powerpc
+       fi
+       if [ -x /usr/bin/oslevel ] ; then
+               IBM_REV=`/usr/bin/oslevel`
+       else
+               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+       fi
+       echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+       exit 0 ;;
+    *:AIX:*:*)
+       echo rs6000-ibm-aix
+       exit 0 ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+       echo romp-ibm-bsd4.4
+       exit 0 ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+       echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+       exit 0 ;;                           # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+       echo rs6000-bull-bosx
+       exit 0 ;;
+    DPX/2?00:B.O.S.:*:*)
+       echo m68k-bull-sysv3
+       exit 0 ;;
+    9000/[34]??:4.3bsd:1.*:*)
+       echo m68k-hp-bsd
+       exit 0 ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+       echo m68k-hp-bsd4.4
+       exit 0 ;;
+    9000/[34678]??:HP-UX:*:*)
+       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+       case "${UNAME_MACHINE}" in
+           9000/31? )            HP_ARCH=m68000 ;;
+           9000/[34]?? )         HP_ARCH=m68k ;;
+           9000/[678][0-9][0-9])
+              case "${HPUX_REV}" in
+                11.[0-9][0-9])
+                  if [ -x /usr/bin/getconf ]; then
+                    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+                    case "${sc_cpu_version}" in
+                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+                      532)                      # CPU_PA_RISC2_0
+                        case "${sc_kernel_bits}" in
+                          32) HP_ARCH="hppa2.0n" ;;
+                          64) HP_ARCH="hppa2.0w" ;;
+                        esac ;;
+                    esac
+                  fi ;;
+              esac
+              if [ "${HP_ARCH}" = "" ]; then
+              sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+               {
+               case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+               case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+               case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+                   switch (bits)
+                       {
+                       case 64: puts ("hppa2.0w"); break;
+                       case 32: puts ("hppa2.0n"); break;
+                       default: puts ("hppa2.0"); break;
+                       } break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+                   puts ("hppa2.0"); break;
+              #endif
+               default: puts ("hppa1.0"); break;
+               }
+                  exit (0);
+              }
+EOF
+       (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy`
+       if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi
+       rm -f $dummy.c $dummy
+       fi ;;
+       esac
+       echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+       exit 0 ;;
+    ia64:HP-UX:*:*)
+       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+       echo ia64-hp-hpux${HPUX_REV}
+       exit 0 ;;
+    3050*:HI-UX:*:*)
+       sed 's/^        //' << EOF >$dummy.c
+       #include <unistd.h>
+       int
+       main ()
+       {
+         long cpu = sysconf (_SC_CPU_VERSION);
+         /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+            true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+            results, however.  */
+         if (CPU_IS_PA_RISC (cpu))
+           {
+             switch (cpu)
+               {
+                 case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+                 case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+                 default: puts ("hppa-hitachi-hiuxwe2"); break;
+               }
+           }
+         else if (CPU_IS_HP_MC68K (cpu))
+           puts ("m68k-hitachi-hiuxwe2");
+         else puts ("unknown-hitachi-hiuxwe2");
+         exit (0);
+       }
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       echo unknown-hitachi-hiuxwe2
+       exit 0 ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+       echo hppa1.1-hp-bsd
+       exit 0 ;;
+    9000/8??:4.3bsd:*:*)
+       echo hppa1.0-hp-bsd
+       exit 0 ;;
+    *9??*:MPE/iX:*:*)
+       echo hppa1.0-hp-mpeix
+       exit 0 ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+       echo hppa1.1-hp-osf
+       exit 0 ;;
+    hp8??:OSF1:*:*)
+       echo hppa1.0-hp-osf
+       exit 0 ;;
+    i*86:OSF1:*:*)
+       if [ -x /usr/sbin/sysversion ] ; then
+           echo ${UNAME_MACHINE}-unknown-osf1mk
+       else
+           echo ${UNAME_MACHINE}-unknown-osf1
+       fi
+       exit 0 ;;
+    parisc*:Lites*:*:*)
+       echo hppa1.1-hp-lites
+       exit 0 ;;
+    hppa*:OpenBSD:*:*)
+       echo hppa-unknown-openbsd
+       exit 0 ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+       echo c1-convex-bsd
+        exit 0 ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+        exit 0 ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+       echo c34-convex-bsd
+        exit 0 ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+       echo c38-convex-bsd
+        exit 0 ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+       echo c4-convex-bsd
+        exit 0 ;;
+    CRAY*X-MP:*:*:*)
+       echo xmp-cray-unicos
+        exit 0 ;;
+    CRAY*Y-MP:*:*:*)
+       echo ymp-cray-unicos${UNAME_RELEASE}
+       exit 0 ;;
+    CRAY*[A-Z]90:*:*:*)
+       echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+       | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+             -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
+       exit 0 ;;
+    CRAY*TS:*:*:*)
+       echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY*T3D:*:*:*)
+       echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY*T3E:*:*:*)
+       echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY*SV1:*:*:*)
+       echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+       exit 0 ;;
+    CRAY-2:*:*:*)
+       echo cray2-cray-unicos
+        exit 0 ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+       FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit 0 ;;
+    hp300:OpenBSD:*:*)
+       echo m68k-unknown-openbsd${UNAME_RELEASE}
+       exit 0 ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+       echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    sparc*:BSD/OS:*:*)
+       echo sparc-unknown-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    *:BSD/OS:*:*)
+       echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+       exit 0 ;;
+    *:FreeBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+       exit 0 ;;
+    *:OpenBSD:*:*)
+       echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+       exit 0 ;;
+    i*:CYGWIN*:*)
+       echo ${UNAME_MACHINE}-pc-cygwin
+       exit 0 ;;
+    i*:MINGW*:*)
+       echo ${UNAME_MACHINE}-pc-mingw32
+       exit 0 ;;
+    i*:PW*:*)
+       echo ${UNAME_MACHINE}-pc-pw32
+       exit 0 ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+       # How do we know it's Interix rather than the generic POSIX subsystem?
+       # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+       # UNAME_MACHINE based on the output of uname instead of i386?
+       echo i386-pc-interix
+       exit 0 ;;
+    i*:UWIN*:*)
+       echo ${UNAME_MACHINE}-pc-uwin
+       exit 0 ;;
+    p*:CYGWIN*:*)
+       echo powerpcle-unknown-cygwin
+       exit 0 ;;
+    prep*:SunOS:5.*:*)
+       echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+       exit 0 ;;
+    *:GNU:*:*)
+       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+       exit 0 ;;
+    i*86:Minix:*:*)
+       echo ${UNAME_MACHINE}-pc-minix
+       exit 0 ;;
+    arm*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit 0 ;;
+    ia64:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux
+       exit 0 ;;
+    m68*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit 0 ;;
+    mips:Linux:*:*)
+       cat >$dummy.c <<EOF
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+int main (int argc, char *argv[]) {
+#else
+int main (argc, argv) int argc; char *argv[]; {
+#endif
+#ifdef __MIPSEB__
+  printf ("%s-unknown-linux-gnu\n", argv[1]);
+#endif
+#ifdef __MIPSEL__
+  printf ("%sel-unknown-linux-gnu\n", argv[1]);
+#endif
+  return 0;
+}
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       ;;
+    ppc:Linux:*:*)
+       # Determine Lib Version
+       cat >$dummy.c <<EOF
+#include <features.h>
+#if defined(__GLIBC__)
+extern char __libc_version[];
+extern char __libc_release[];
+#endif
+main(argc, argv)
+     int argc;
+     char *argv[];
+{
+#if defined(__GLIBC__)
+  printf("%s %s\n", __libc_version, __libc_release);
+#else
+  printf("unknown\n");
+#endif
+  return 0;
+}
+EOF
+       LIBC=""
+       $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null
+       if test "$?" = 0 ; then
+               ./$dummy | grep 1\.99 > /dev/null
+               if test "$?" = 0 ; then LIBC="libc1" ; fi
+       fi
+       rm -f $dummy.c $dummy
+       echo powerpc-unknown-linux-gnu${LIBC}
+       exit 0 ;;
+    alpha:Linux:*:*)
+       cat <<EOF >$dummy.s
+         .data
+         \$Lformat:
+               .byte 37,100,45,37,120,10,0     # "%d-%x\n"
+          .text
+               .globl main
+               .align 4
+               .ent main
+           main:
+               .frame \$30,16,\$26,0
+               ldgp \$29,0(\$27)
+               .prologue 1
+               .long 0x47e03d80 # implver \$0
+               lda \$2,-1
+               .long 0x47e20c21 # amask \$2,\$1
+               lda \$16,\$Lformat
+               mov \$0,\$17
+               not \$1,\$18
+               jsr \$26,printf
+               ldgp \$29,0(\$26)
+               mov 0,\$16
+               jsr \$26,exit
+               .end main
+EOF
+       LIBC=""
+       $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
+       if test "$?" = 0 ; then
+               case `./$dummy` in
+               0-0)    UNAME_MACHINE="alpha" ;;
+               1-0)    UNAME_MACHINE="alphaev5" ;;
+               1-1)    UNAME_MACHINE="alphaev56" ;;
+               1-101)  UNAME_MACHINE="alphapca56" ;;
+               2-303)  UNAME_MACHINE="alphaev6" ;;
+               2-307)  UNAME_MACHINE="alphaev67" ;;
+               esac
+               objdump --private-headers $dummy | \
+                 grep ld.so.1 > /dev/null
+               if test "$?" = 0 ; then
+                       LIBC="libc1"
+               fi
+       fi
+       rm -f $dummy.s $dummy
+       echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+       exit 0 ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+       # Look for CPU level
+       case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+         PA7*) echo hppa1.1-unknown-linux-gnu ;;
+         PA8*) echo hppa2.0-unknown-linux-gnu ;;
+         *)    echo hppa-unknown-linux-gnu ;;
+       esac
+       exit 0 ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+       echo hppa64-unknown-linux-gnu
+       exit 0 ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+       echo ${UNAME_MACHINE}-ibm-linux
+       exit 0 ;;
+    sh*:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit 0 ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+       echo ${UNAME_MACHINE}-unknown-linux-gnu
+       exit 0 ;;
+    x86_64:Linux:*:*)
+       echo x86_64-unknown-linux-gnu
+       exit 0 ;;
+    i*86:Linux:*:*)
+       # The BFD linker knows what the default object file format is, so
+       # first see if it will tell us. cd to the root directory to prevent
+       # problems with other programs or directories called `ld' in the path.
+       ld_supported_emulations=`cd /; ld --help 2>&1 \
+                        | sed -ne '/supported emulations:/!d
+                                   s/[         ][      ]*/ /g
+                                   s/.*supported emulations: *//
+                                   s/ .*//
+                                   p'`
+        case "$ld_supported_emulations" in
+         i*86linux)
+               echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+               exit 0
+               ;;
+         elf_i*86)
+               TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+               ;;
+         i*86coff)
+               echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+               exit 0
+               ;;
+       esac
+       # Either a pre-BFD a.out linker (linux-gnuoldld)
+       # or one that does not give us useful --help.
+       # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout.
+       # If ld does not provide *any* "supported emulations:"
+       # that means it is gnuoldld.
+       test -z "$ld_supported_emulations" && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0
+       case "${UNAME_MACHINE}" in
+       i*86)
+         VENDOR=pc;
+         ;;
+       *)
+         VENDOR=unknown;
+         ;;
+       esac
+       # Determine whether the default compiler is a.out or elf
+       cat >$dummy.c <<EOF
+#include <features.h>
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+       int main (int argc, char *argv[]) {
+#else
+       int main (argc, argv) int argc; char *argv[]; {
+#endif
+#ifdef __ELF__
+# ifdef __GLIBC__
+#  if __GLIBC__ >= 2
+    printf ("%s-${VENDOR}-linux-gnu\n", argv[1]);
+#  else
+    printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+#  endif
+# else
+   printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
+# endif
+#else
+  printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]);
+#endif
+  return 0;
+}
+EOF
+       $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0
+       rm -f $dummy.c $dummy
+       test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
+       ;;
+# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.  earlier versions
+# are messed up and put the nodename in both sysname and nodename.
+    i*86:DYNIX/ptx:4*:*)
+       echo i386-sequent-sysv4
+       exit 0 ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+       # I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+       echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+       exit 0 ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+       UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+       if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+               echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+       else
+               echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+       fi
+       exit 0 ;;
+    i*86:*:5:7*)
+        # Fixed at (any) Pentium or better
+        UNAME_MACHINE=i586
+        if [ ${UNAME_SYSTEM} = "UnixWare" ] ; then
+           echo ${UNAME_MACHINE}-sco-sysv${UNAME_RELEASE}uw${UNAME_VERSION}
+       else
+           echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE}
+       fi
+       exit 0 ;;
+    i*86:*:3.2:*)
+       if test -f /usr/options/cb.name; then
+               UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+               echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+       elif /bin/uname -X 2>/dev/null >/dev/null ; then
+               UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
+               (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
+               (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
+                       && UNAME_MACHINE=i586
+               (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \
+                       && UNAME_MACHINE=i686
+               echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+       else
+               echo ${UNAME_MACHINE}-pc-sysv32
+       fi
+       exit 0 ;;
+    i*86:*DOS:*:*)
+       echo ${UNAME_MACHINE}-pc-msdosdjgpp
+       exit 0 ;;
+    pc:*:*:*)
+       # Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i386.
+       echo i386-pc-msdosdjgpp
+        exit 0 ;;
+    Intel:Mach:3*:*)
+       echo i386-pc-mach3
+       exit 0 ;;
+    paragon:*:*:*)
+       echo i860-intel-osf1
+       exit 0 ;;
+    i860:*:4.*:*) # i860-SVR4
+       if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+         echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+       else # Add other i860-SVR4 vendors below as they are discovered.
+         echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+       fi
+       exit 0 ;;
+    mini*:CTIX:SYS*5:*)
+       # "miniframe"
+       echo m68010-convergent-sysv
+       exit 0 ;;
+    M68*:*:R3V[567]*:*)
+       test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
+    3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
+       OS_REL=''
+       test -r /etc/.relid \
+       && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+         && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+         && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && echo i486-ncr-sysv4 && exit 0 ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+       echo m68k-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    mc68030:UNIX_System_V:4.*:*)
+       echo m68k-atari-sysv4
+       exit 0 ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+       echo i386-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    TSUNAMI:LynxOS:2.*:*)
+       echo sparc-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    rs6000:LynxOS:2.*:*)
+       echo rs6000-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+       echo powerpc-unknown-lynxos${UNAME_RELEASE}
+       exit 0 ;;
+    SM[BE]S:UNIX_SV:*:*)
+       echo mips-dde-sysv${UNAME_RELEASE}
+       exit 0 ;;
+    RM*:ReliantUNIX-*:*:*)
+       echo mips-sni-sysv4
+       exit 0 ;;
+    RM*:SINIX-*:*:*)
+       echo mips-sni-sysv4
+       exit 0 ;;
+    *:SINIX-*:*:*)
+       if uname -p 2>/dev/null >/dev/null ; then
+               UNAME_MACHINE=`(uname -p) 2>/dev/null`
+               echo ${UNAME_MACHINE}-sni-sysv4
+       else
+               echo ns32k-sni-sysv
+       fi
+       exit 0 ;;
+    PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                           # says <Richard.M.Bartel@ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit 0 ;;
+    *:UNIX_System_V:4*:FTX*)
+       # From Gerald Hewes <hewes@openmarket.com>.
+       # How about differentiating between stratus architectures? -djm
+       echo hppa1.1-stratus-sysv4
+       exit 0 ;;
+    *:*:*:FTX*)
+       # From seanf@swdc.stratus.com.
+       echo i860-stratus-sysv4
+       exit 0 ;;
+    mc68*:A/UX:*:*)
+       echo m68k-apple-aux${UNAME_RELEASE}
+       exit 0 ;;
+    news*:NEWS-OS:6*:*)
+       echo mips-sony-newsos6
+       exit 0 ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+       if [ -d /usr/nec ]; then
+               echo mips-nec-sysv${UNAME_RELEASE}
+       else
+               echo mips-unknown-sysv${UNAME_RELEASE}
+       fi
+        exit 0 ;;
+    BeBox:BeOS:*:*)    # BeOS running on hardware made by Be, PPC only.
+       echo powerpc-be-beos
+       exit 0 ;;
+    BeMac:BeOS:*:*)    # BeOS running on Mac or Mac clone, PPC only.
+       echo powerpc-apple-beos
+       exit 0 ;;
+    BePC:BeOS:*:*)     # BeOS running on Intel PC compatible.
+       echo i586-pc-beos
+       exit 0 ;;
+    SX-4:SUPER-UX:*:*)
+       echo sx4-nec-superux${UNAME_RELEASE}
+       exit 0 ;;
+    SX-5:SUPER-UX:*:*)
+       echo sx5-nec-superux${UNAME_RELEASE}
+       exit 0 ;;
+    Power*:Rhapsody:*:*)
+       echo powerpc-apple-rhapsody${UNAME_RELEASE}
+       exit 0 ;;
+    *:Rhapsody:*:*)
+       echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+       exit 0 ;;
+    *:Darwin:*:*)
+       echo `uname -p`-apple-darwin${UNAME_RELEASE}
+       exit 0 ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+       if test "${UNAME_MACHINE}" = "x86pc"; then
+               UNAME_MACHINE=pc
+       fi
+       echo `uname -p`-${UNAME_MACHINE}-nto-qnx
+       exit 0 ;;
+    *:QNX:*:4*)
+       echo i386-pc-qnx
+       exit 0 ;;
+    NSR-[KW]:NONSTOP_KERNEL:*:*)
+       echo nsr-tandem-nsk${UNAME_RELEASE}
+       exit 0 ;;
+    *:NonStop-UX:*:*)
+       echo mips-compaq-nonstopux
+       exit 0 ;;
+    BS2000:POSIX*:*:*)
+       echo bs2000-siemens-sysv
+       exit 0 ;;
+    DS/*:UNIX_System_V:*:*)
+       echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+       exit 0 ;;
+    *:Plan9:*:*)
+       # "uname -m" is not consistent, so use $cputype instead. 386
+       # is converted to i386 for consistency with other x86
+       # operating systems.
+       if test "$cputype" = "386"; then
+           UNAME_MACHINE=i386
+       else
+           UNAME_MACHINE="$cputype"
+       fi
+       echo ${UNAME_MACHINE}-unknown-plan9
+       exit 0 ;;
+    i*86:OS/2:*:*)
+       # If we were able to find `uname', then EMX Unix compatibility
+       # is probably installed.
+       echo ${UNAME_MACHINE}-pc-os2-emx
+       exit 0 ;;
+    *:TOPS-10:*:*)
+       echo pdp10-unknown-tops10
+       exit 0 ;;
+    *:TENEX:*:*)
+       echo pdp10-unknown-tenex
+       exit 0 ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+       echo pdp10-dec-tops20
+       exit 0 ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+       echo pdp10-xkl-tops20
+       exit 0 ;;
+    *:TOPS-20:*:*)
+       echo pdp10-unknown-tops20
+       exit 0 ;;
+    *:ITS:*:*)
+       echo pdp10-unknown-its
+       exit 0 ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+         ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+       printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+       printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0
+rm -f $dummy.c $dummy
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+       echo c1-convex-bsd
+       exit 0 ;;
+    c2*)
+       if getsysinfo -f scalar_acc
+       then echo c32-convex-bsd
+       else echo c2-convex-bsd
+       fi
+       exit 0 ;;
+    c34*)
+       echo c34-convex-bsd
+       exit 0 ;;
+    c38*)
+       echo c38-convex-bsd
+       exit 0 ;;
+    c4*)
+       echo c4-convex-bsd
+       exit 0 ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+    ftp://ftp.gnu.org/pub/gnu/config/
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches@gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/config.sub b/config.sub
new file mode 100644 (file)
index 0000000..a06a480
--- /dev/null
@@ -0,0 +1,1362 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+#   Free Software Foundation, Inc.
+
+timestamp='2001-04-20'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Please send patches to <config-patches@gnu.org>.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#      CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#      CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit 0 ;;
+    --version | -v )
+       echo "$version" ; exit 0 ;;
+    --help | --h* | -h )
+       echo "$usage"; exit 0 ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit 0;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | storm-chaos* | os2-emx*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+       -sun*os*)
+               # Prevent following clause from handling this invalid input.
+               ;;
+       -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+       -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+       -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+       -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+       -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+       -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+       -apple | -axis)
+               os=
+               basic_machine=$1
+               ;;
+       -sim | -cisco | -oki | -wec | -winbond)
+               os=
+               basic_machine=$1
+               ;;
+       -scout)
+               ;;
+       -wrs)
+               os=-vxworks
+               basic_machine=$1
+               ;;
+       -hiux*)
+               os=-hiuxwe2
+               ;;
+       -sco5)
+               os=-sco3.2v5
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco4)
+               os=-sco3.2v4
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2.[4-9]*)
+               os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco3.2v[4-9]*)
+               # Don't forget version if it is 3.2v4 or newer.
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -sco*)
+               os=-sco3.2v2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -udk*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -isc)
+               os=-isc2.2
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -clix*)
+               basic_machine=clipper-intergraph
+               ;;
+       -isc*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+               ;;
+       -lynx*)
+               os=-lynxos
+               ;;
+       -ptx*)
+               basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+               ;;
+       -windowsnt*)
+               os=`echo $os | sed -e 's/windowsnt/winnt/'`
+               ;;
+       -psos*)
+               os=-psos
+               ;;
+       -mint | -mint[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+       # Recognize the basic CPU types without company name.
+       # Some are omitted here because they have special meanings below.
+       tahoe | i860 | ia64 | m32r | m68k | m68000 | m88k | ns32k | arc \
+               | arm | arme[lb] | arm[bl]e | armv[2345] | armv[345][lb] | strongarm | xscale \
+               | pyramid | mn10200 | mn10300 | tron | a29k \
+               | 580 | i960 | h8300 \
+               | x86 | ppcbe | mipsbe | mipsle | shbe | shle \
+               | hppa | hppa1.0 | hppa1.1 | hppa2.0 | hppa2.0w | hppa2.0n \
+               | hppa64 \
+               | alpha | alphaev[4-8] | alphaev56 | alphapca5[67] \
+               | alphaev6[78] \
+               | we32k | ns16k | clipper | i370 | sh | sh[34] \
+               | powerpc | powerpcle \
+               | 1750a | dsp16xx | pdp10 | pdp11 \
+               | mips16 | mips64 | mipsel | mips64el \
+               | mips64orion | mips64orionel | mipstx39 | mipstx39el \
+               | mips64vr4300 | mips64vr4300el | mips64vr4100 | mips64vr4100el \
+               | mips64vr5000 | miprs64vr5000el | mcore | s390 | s390x \
+               | sparc | sparclet | sparclite | sparc64 | sparcv9 | sparcv9b \
+               | v850 | c4x \
+               | thumb | d10v | d30v | fr30 | avr | openrisc | tic80 \
+               | pj | pjl | h8500)
+               basic_machine=$basic_machine-unknown
+               ;;
+       m6811 | m68hc11 | m6812 | m68hc12)
+               # Motorola 68HC11/12.
+               basic_machine=$basic_machine-unknown
+               os=-none
+               ;;
+       m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | z8k | v70 | w65)
+               ;;
+
+       # We use `pc' rather than `unknown'
+       # because (1) that's what they normally are, and
+       # (2) the word "unknown" tends to confuse beginning users.
+       i*86 | x86_64)
+         basic_machine=$basic_machine-pc
+         ;;
+       # Object if more than one company name word.
+       *-*-*)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+       # Recognize the basic CPU types with company name.
+       # FIXME: clean up the formatting here.
+       vax-* | tahoe-* | i*86-* | i860-* | ia64-* | m32r-* | m68k-* | m68000-* \
+             | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | c[123]* \
+             | arm-*  | armbe-* | armle-* | armv*-* | strongarm-* | xscale-* \
+             | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \
+             | power-* | none-* | 580-* | cray2-* | h8300-* | h8500-* | i960-* \
+             | xmp-* | ymp-* \
+             | x86-* | ppcbe-* | mipsbe-* | mipsle-* | shbe-* | shle-* \
+             | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* | hppa2.0w-* \
+             | hppa2.0n-* | hppa64-* \
+             | alpha-* | alphaev[4-8]-* | alphaev56-* | alphapca5[67]-* \
+             | alphaev6[78]-* \
+             | we32k-* | cydra-* | ns16k-* | pn-* | np1-* | xps100-* \
+             | clipper-* | orion-* \
+             | sparclite-* | pdp10-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \
+             | sparc64-* | sparcv9-* | sparcv9b-* | sparc86x-* \
+             | mips16-* | mips64-* | mipsel-* \
+             | mips64el-* | mips64orion-* | mips64orionel-* \
+             | mips64vr4100-* | mips64vr4100el-* | mips64vr4300-* | mips64vr4300el-* \
+             | mipstx39-* | mipstx39el-* | mcore-* \
+             | f30[01]-* | f700-* | s390-* | s390x-* | sv1-* | t3e-* \
+             | [cjt]90-* \
+             | m88110-* | m680[01234]0-* | m683?2-* | m68360-* | z8k-* | d10v-* \
+             | thumb-* | v850-* | d30v-* | tic30-* | tic80-* | c30-* | fr30-* \
+             | bs2000-* | tic54x-* | c54x-* | x86_64-* | pj-* | pjl-*)
+               ;;
+       # Recognize the various machine names and aliases which stand
+       # for a CPU type and a company and sometimes even an OS.
+       386bsd)
+               basic_machine=i386-unknown
+               os=-bsd
+               ;;
+       3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+               basic_machine=m68000-att
+               ;;
+       3b*)
+               basic_machine=we32k-att
+               ;;
+       a29khif)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       adobe68k)
+               basic_machine=m68010-adobe
+               os=-scout
+               ;;
+       alliant | fx80)
+               basic_machine=fx80-alliant
+               ;;
+       altos | altos3068)
+               basic_machine=m68k-altos
+               ;;
+       am29k)
+               basic_machine=a29k-none
+               os=-bsd
+               ;;
+       amdahl)
+               basic_machine=580-amdahl
+               os=-sysv
+               ;;
+       amiga | amiga-*)
+               basic_machine=m68k-unknown
+               ;;
+       amigaos | amigados)
+               basic_machine=m68k-unknown
+               os=-amigaos
+               ;;
+       amigaunix | amix)
+               basic_machine=m68k-unknown
+               os=-sysv4
+               ;;
+       apollo68)
+               basic_machine=m68k-apollo
+               os=-sysv
+               ;;
+       apollo68bsd)
+               basic_machine=m68k-apollo
+               os=-bsd
+               ;;
+       aux)
+               basic_machine=m68k-apple
+               os=-aux
+               ;;
+       balance)
+               basic_machine=ns32k-sequent
+               os=-dynix
+               ;;
+       convex-c1)
+               basic_machine=c1-convex
+               os=-bsd
+               ;;
+       convex-c2)
+               basic_machine=c2-convex
+               os=-bsd
+               ;;
+       convex-c32)
+               basic_machine=c32-convex
+               os=-bsd
+               ;;
+       convex-c34)
+               basic_machine=c34-convex
+               os=-bsd
+               ;;
+       convex-c38)
+               basic_machine=c38-convex
+               os=-bsd
+               ;;
+       cray | ymp)
+               basic_machine=ymp-cray
+               os=-unicos
+               ;;
+       cray2)
+               basic_machine=cray2-cray
+               os=-unicos
+               ;;
+       [cjt]90)
+               basic_machine=${basic_machine}-cray
+               os=-unicos
+               ;;
+       crds | unos)
+               basic_machine=m68k-crds
+               ;;
+       cris | cris-* | etrax*)
+               basic_machine=cris-axis
+               ;;
+       da30 | da30-*)
+               basic_machine=m68k-da30
+               ;;
+       decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+               basic_machine=mips-dec
+               ;;
+       delta | 3300 | motorola-3300 | motorola-delta \
+             | 3300-motorola | delta-motorola)
+               basic_machine=m68k-motorola
+               ;;
+       delta88)
+               basic_machine=m88k-motorola
+               os=-sysv3
+               ;;
+       dpx20 | dpx20-*)
+               basic_machine=rs6000-bull
+               os=-bosx
+               ;;
+       dpx2* | dpx2*-bull)
+               basic_machine=m68k-bull
+               os=-sysv3
+               ;;
+       ebmon29k)
+               basic_machine=a29k-amd
+               os=-ebmon
+               ;;
+       elxsi)
+               basic_machine=elxsi-elxsi
+               os=-bsd
+               ;;
+       encore | umax | mmax)
+               basic_machine=ns32k-encore
+               ;;
+       es1800 | OSE68k | ose68k | ose | OSE)
+               basic_machine=m68k-ericsson
+               os=-ose
+               ;;
+       fx2800)
+               basic_machine=i860-alliant
+               ;;
+       genix)
+               basic_machine=ns32k-ns
+               ;;
+       gmicro)
+               basic_machine=tron-gmicro
+               os=-sysv
+               ;;
+       go32)
+               basic_machine=i386-pc
+               os=-go32
+               ;;
+       h3050r* | hiux*)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       h8300hms)
+               basic_machine=h8300-hitachi
+               os=-hms
+               ;;
+       h8300xray)
+               basic_machine=h8300-hitachi
+               os=-xray
+               ;;
+       h8500hms)
+               basic_machine=h8500-hitachi
+               os=-hms
+               ;;
+       harris)
+               basic_machine=m88k-harris
+               os=-sysv3
+               ;;
+       hp300-*)
+               basic_machine=m68k-hp
+               ;;
+       hp300bsd)
+               basic_machine=m68k-hp
+               os=-bsd
+               ;;
+       hp300hpux)
+               basic_machine=m68k-hp
+               os=-hpux
+               ;;
+       hp3k9[0-9][0-9] | hp9[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k2[0-9][0-9] | hp9k31[0-9])
+               basic_machine=m68000-hp
+               ;;
+       hp9k3[2-9][0-9])
+               basic_machine=m68k-hp
+               ;;
+       hp9k6[0-9][0-9] | hp6[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hp9k7[0-79][0-9] | hp7[0-79][0-9])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k78[0-9] | hp78[0-9])
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+               # FIXME: really hppa2.0-hp
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][13679] | hp8[0-9][13679])
+               basic_machine=hppa1.1-hp
+               ;;
+       hp9k8[0-9][0-9] | hp8[0-9][0-9])
+               basic_machine=hppa1.0-hp
+               ;;
+       hppa-next)
+               os=-nextstep3
+               ;;
+       hppaosf)
+               basic_machine=hppa1.1-hp
+               os=-osf
+               ;;
+       hppro)
+               basic_machine=hppa1.1-hp
+               os=-proelf
+               ;;
+       i370-ibm* | ibm*)
+               basic_machine=i370-ibm
+               ;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+       i*86v32)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv32
+               ;;
+       i*86v4*)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv4
+               ;;
+       i*86v)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-sysv
+               ;;
+       i*86sol2)
+               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+               os=-solaris2
+               ;;
+       i386mach)
+               basic_machine=i386-mach
+               os=-mach
+               ;;
+       i386-vsta | vsta)
+               basic_machine=i386-unknown
+               os=-vsta
+               ;;
+       iris | iris4d)
+               basic_machine=mips-sgi
+               case $os in
+                   -irix*)
+                       ;;
+                   *)
+                       os=-irix4
+                       ;;
+               esac
+               ;;
+       isi68 | isi)
+               basic_machine=m68k-isi
+               os=-sysv
+               ;;
+       m88k-omron*)
+               basic_machine=m88k-omron
+               ;;
+       magnum | m3230)
+               basic_machine=mips-mips
+               os=-sysv
+               ;;
+       merlin)
+               basic_machine=ns32k-utek
+               os=-sysv
+               ;;
+       mingw32)
+               basic_machine=i386-pc
+               os=-mingw32
+               ;;
+       miniframe)
+               basic_machine=m68000-convergent
+               ;;
+       *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+               basic_machine=m68k-atari
+               os=-mint
+               ;;
+       mipsel*-linux*)
+               basic_machine=mipsel-unknown
+               os=-linux-gnu
+               ;;
+       mips*-linux*)
+               basic_machine=mips-unknown
+               os=-linux-gnu
+               ;;
+       mips3*-*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+               ;;
+       mips3*)
+               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+               ;;
+       mmix*)
+               basic_machine=mmix-knuth
+               os=-mmixware
+               ;;
+       monitor)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       msdos)
+               basic_machine=i386-pc
+               os=-msdos
+               ;;
+       mvs)
+               basic_machine=i370-ibm
+               os=-mvs
+               ;;
+       ncr3000)
+               basic_machine=i486-ncr
+               os=-sysv4
+               ;;
+       netbsd386)
+               basic_machine=i386-unknown
+               os=-netbsd
+               ;;
+       netwinder)
+               basic_machine=armv4l-rebel
+               os=-linux
+               ;;
+       news | news700 | news800 | news900)
+               basic_machine=m68k-sony
+               os=-newsos
+               ;;
+       news1000)
+               basic_machine=m68030-sony
+               os=-newsos
+               ;;
+       news-3600 | risc-news)
+               basic_machine=mips-sony
+               os=-newsos
+               ;;
+       necv70)
+               basic_machine=v70-nec
+               os=-sysv
+               ;;
+       next | m*-next )
+               basic_machine=m68k-next
+               case $os in
+                   -nextstep* )
+                       ;;
+                   -ns2*)
+                     os=-nextstep2
+                       ;;
+                   *)
+                     os=-nextstep3
+                       ;;
+               esac
+               ;;
+       nh3000)
+               basic_machine=m68k-harris
+               os=-cxux
+               ;;
+       nh[45]000)
+               basic_machine=m88k-harris
+               os=-cxux
+               ;;
+       nindy960)
+               basic_machine=i960-intel
+               os=-nindy
+               ;;
+       mon960)
+               basic_machine=i960-intel
+               os=-mon960
+               ;;
+       nonstopux)
+               basic_machine=mips-compaq
+               os=-nonstopux
+               ;;
+       np1)
+               basic_machine=np1-gould
+               ;;
+       nsr-tandem)
+               basic_machine=nsr-tandem
+               ;;
+       op50n-* | op60c-*)
+               basic_machine=hppa1.1-oki
+               os=-proelf
+               ;;
+       OSE68000 | ose68000)
+               basic_machine=m68000-ericsson
+               os=-ose
+               ;;
+       os68k)
+               basic_machine=m68k-none
+               os=-os68k
+               ;;
+       pa-hitachi)
+               basic_machine=hppa1.1-hitachi
+               os=-hiuxwe2
+               ;;
+       paragon)
+               basic_machine=i860-intel
+               os=-osf
+               ;;
+       pbd)
+               basic_machine=sparc-tti
+               ;;
+       pbb)
+               basic_machine=m68k-tti
+               ;;
+        pc532 | pc532-*)
+               basic_machine=ns32k-pc532
+               ;;
+       pentium | p5 | k5 | k6 | nexgen)
+               basic_machine=i586-pc
+               ;;
+       pentiumpro | p6 | 6x86 | athlon)
+               basic_machine=i686-pc
+               ;;
+       pentiumii | pentium2)
+               basic_machine=i686-pc
+               ;;
+       pentium-* | p5-* | k5-* | k6-* | nexgen-*)
+               basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumpro-* | p6-* | 6x86-* | athlon-*)
+               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pentiumii-* | pentium2-*)
+               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       pn)
+               basic_machine=pn-gould
+               ;;
+       power)  basic_machine=power-ibm
+               ;;
+       ppc)    basic_machine=powerpc-unknown
+               ;;
+       ppc-*)  basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ppcle | powerpclittle | ppc-le | powerpc-little)
+               basic_machine=powerpcle-unknown
+               ;;
+       ppcle-* | powerpclittle-*)
+               basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+               ;;
+       ps2)
+               basic_machine=i386-ibm
+               ;;
+       pw32)
+               basic_machine=i586-unknown
+               os=-pw32
+               ;;
+       rom68k)
+               basic_machine=m68k-rom68k
+               os=-coff
+               ;;
+       rm[46]00)
+               basic_machine=mips-siemens
+               ;;
+       rtpc | rtpc-*)
+               basic_machine=romp-ibm
+               ;;
+       sa29200)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       sequent)
+               basic_machine=i386-sequent
+               ;;
+       sh)
+               basic_machine=sh-hitachi
+               os=-hms
+               ;;
+       sparclite-wrs)
+               basic_machine=sparclite-wrs
+               os=-vxworks
+               ;;
+       sps7)
+               basic_machine=m68k-bull
+               os=-sysv2
+               ;;
+       spur)
+               basic_machine=spur-unknown
+               ;;
+       st2000)
+               basic_machine=m68k-tandem
+               ;;
+       stratus)
+               basic_machine=i860-stratus
+               os=-sysv4
+               ;;
+       sun2)
+               basic_machine=m68000-sun
+               ;;
+       sun2os3)
+               basic_machine=m68000-sun
+               os=-sunos3
+               ;;
+       sun2os4)
+               basic_machine=m68000-sun
+               os=-sunos4
+               ;;
+       sun3os3)
+               basic_machine=m68k-sun
+               os=-sunos3
+               ;;
+       sun3os4)
+               basic_machine=m68k-sun
+               os=-sunos4
+               ;;
+       sun4os3)
+               basic_machine=sparc-sun
+               os=-sunos3
+               ;;
+       sun4os4)
+               basic_machine=sparc-sun
+               os=-sunos4
+               ;;
+       sun4sol2)
+               basic_machine=sparc-sun
+               os=-solaris2
+               ;;
+       sun3 | sun3-*)
+               basic_machine=m68k-sun
+               ;;
+       sun4)
+               basic_machine=sparc-sun
+               ;;
+       sun386 | sun386i | roadrunner)
+               basic_machine=i386-sun
+               ;;
+       sv1)
+               basic_machine=sv1-cray
+               os=-unicos
+               ;;
+       symmetry)
+               basic_machine=i386-sequent
+               os=-dynix
+               ;;
+       t3e)
+               basic_machine=t3e-cray
+               os=-unicos
+               ;;
+       tic54x | c54x*)
+               basic_machine=tic54x-unknown
+               os=-coff
+               ;;
+       tx39)
+               basic_machine=mipstx39-unknown
+               ;;
+       tx39el)
+               basic_machine=mipstx39el-unknown
+               ;;
+       tower | tower-32)
+               basic_machine=m68k-ncr
+               ;;
+       udi29k)
+               basic_machine=a29k-amd
+               os=-udi
+               ;;
+       ultra3)
+               basic_machine=a29k-nyu
+               os=-sym1
+               ;;
+       v810 | necv810)
+               basic_machine=v810-nec
+               os=-none
+               ;;
+       vaxv)
+               basic_machine=vax-dec
+               os=-sysv
+               ;;
+       vms)
+               basic_machine=vax-dec
+               os=-vms
+               ;;
+       vpp*|vx|vx-*)
+               basic_machine=f301-fujitsu
+               ;;
+       vxworks960)
+               basic_machine=i960-wrs
+               os=-vxworks
+               ;;
+       vxworks68)
+               basic_machine=m68k-wrs
+               os=-vxworks
+               ;;
+       vxworks29k)
+               basic_machine=a29k-wrs
+               os=-vxworks
+               ;;
+       w65*)
+               basic_machine=w65-wdc
+               os=-none
+               ;;
+       w89k-*)
+               basic_machine=hppa1.1-winbond
+               os=-proelf
+               ;;
+       xmp)
+               basic_machine=xmp-cray
+               os=-unicos
+               ;;
+        xps | xps100)
+               basic_machine=xps100-honeywell
+               ;;
+       z8k-*-coff)
+               basic_machine=z8k-unknown
+               os=-sim
+               ;;
+       none)
+               basic_machine=none-none
+               os=-none
+               ;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+       w89k)
+               basic_machine=hppa1.1-winbond
+               ;;
+       op50n)
+               basic_machine=hppa1.1-oki
+               ;;
+       op60c)
+               basic_machine=hppa1.1-oki
+               ;;
+       mips)
+               if [ x$os = x-linux-gnu ]; then
+                       basic_machine=mips-unknown
+               else
+                       basic_machine=mips-mips
+               fi
+               ;;
+       romp)
+               basic_machine=romp-ibm
+               ;;
+       rs6000)
+               basic_machine=rs6000-ibm
+               ;;
+       vax)
+               basic_machine=vax-dec
+               ;;
+       pdp10)
+               # there are many clones, so DEC is not a safe bet
+               basic_machine=pdp10-unknown
+               ;;
+       pdp11)
+               basic_machine=pdp11-dec
+               ;;
+       we32k)
+               basic_machine=we32k-att
+               ;;
+       sh3 | sh4)
+               basic_machine=sh-unknown
+               ;;
+       sparc | sparcv9 | sparcv9b)
+               basic_machine=sparc-sun
+               ;;
+        cydra)
+               basic_machine=cydra-cydrome
+               ;;
+       orion)
+               basic_machine=orion-highlevel
+               ;;
+       orion105)
+               basic_machine=clipper-highlevel
+               ;;
+       mac | mpw | mac-mpw)
+               basic_machine=m68k-apple
+               ;;
+       pmac | pmac-mpw)
+               basic_machine=powerpc-apple
+               ;;
+       c4x*)
+               basic_machine=c4x-none
+               os=-coff
+               ;;
+       *-unknown)
+               # Make sure to match an already-canonicalized machine name.
+               ;;
+       *)
+               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+       *-digital*)
+               basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+               ;;
+       *-commodore*)
+               basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+               ;;
+       *)
+               ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+       # -solaris* is a basic system type, with this one exception.
+       -solaris1 | -solaris1.*)
+               os=`echo $os | sed -e 's|solaris1|sunos4|'`
+               ;;
+       -solaris)
+               os=-solaris2
+               ;;
+       -svr4*)
+               os=-sysv4
+               ;;
+       -unixware*)
+               os=-sysv4.2uw
+               ;;
+       -gnu/linux*)
+               os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+               ;;
+       # First accept the basic system types.
+       # The portable systems comes first.
+       # Each alternative MUST END IN A *, to match a version number.
+       # -sysv* is not here because it comes later, after sysvr4.
+       -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+             | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+             | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+             | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+             | -aos* \
+             | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+             | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+             | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
+             | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+             | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+             | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+             | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+             | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
+             | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
+             | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+             | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* | -os2*)
+       # Remember, each alternative MUST END IN *, to match a version number.
+               ;;
+       -qnx*)
+               case $basic_machine in
+                   x86-* | i*86-*)
+                       ;;
+                   *)
+                       os=-nto$os
+                       ;;
+               esac
+               ;;
+       -nto*)
+               os=-nto-qnx
+               ;;
+       -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+             | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
+             | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+               ;;
+       -mac*)
+               os=`echo $os | sed -e 's|mac|macos|'`
+               ;;
+       -linux*)
+               os=`echo $os | sed -e 's|linux|linux-gnu|'`
+               ;;
+       -sunos5*)
+               os=`echo $os | sed -e 's|sunos5|solaris2|'`
+               ;;
+       -sunos6*)
+               os=`echo $os | sed -e 's|sunos6|solaris3|'`
+               ;;
+       -opened*)
+               os=-openedition
+               ;;
+       -wince*)
+               os=-wince
+               ;;
+       -osfrose*)
+               os=-osfrose
+               ;;
+       -osf*)
+               os=-osf
+               ;;
+       -utek*)
+               os=-bsd
+               ;;
+       -dynix*)
+               os=-bsd
+               ;;
+       -acis*)
+               os=-aos
+               ;;
+       -386bsd)
+               os=-bsd
+               ;;
+       -ctix* | -uts*)
+               os=-sysv
+               ;;
+       -ns2 )
+               os=-nextstep2
+               ;;
+       -nsk*)
+               os=-nsk
+               ;;
+       # Preserve the version number of sinix5.
+       -sinix5.*)
+               os=`echo $os | sed -e 's|sinix|sysv|'`
+               ;;
+       -sinix*)
+               os=-sysv4
+               ;;
+       -triton*)
+               os=-sysv3
+               ;;
+       -oss*)
+               os=-sysv3
+               ;;
+       -svr4)
+               os=-sysv4
+               ;;
+       -svr3)
+               os=-sysv3
+               ;;
+       -sysvr4)
+               os=-sysv4
+               ;;
+       # This must come after -sysvr4.
+       -sysv*)
+               ;;
+       -ose*)
+               os=-ose
+               ;;
+       -es1800*)
+               os=-ose
+               ;;
+       -xenix)
+               os=-xenix
+               ;;
+        -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+               os=-mint
+               ;;
+       -none)
+               ;;
+       *)
+               # Get rid of the `-' at the beginning of $os.
+               os=`echo $os | sed 's/[^-]*-//'`
+               echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+               exit 1
+               ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+       *-acorn)
+               os=-riscix1.2
+               ;;
+       arm*-rebel)
+               os=-linux
+               ;;
+       arm*-semi)
+               os=-aout
+               ;;
+       pdp10-*)
+               os=-tops20
+               ;;
+        pdp11-*)
+               os=-none
+               ;;
+       *-dec | vax-*)
+               os=-ultrix4.2
+               ;;
+       m68*-apollo)
+               os=-domain
+               ;;
+       i386-sun)
+               os=-sunos4.0.2
+               ;;
+       m68000-sun)
+               os=-sunos3
+               # This also exists in the configure program, but was not the
+               # default.
+               # os=-sunos4
+               ;;
+       m68*-cisco)
+               os=-aout
+               ;;
+       mips*-cisco)
+               os=-elf
+               ;;
+       mips*-*)
+               os=-elf
+               ;;
+       *-tti)  # must be before sparc entry or we get the wrong os.
+               os=-sysv3
+               ;;
+       sparc-* | *-sun)
+               os=-sunos4.1.1
+               ;;
+       *-be)
+               os=-beos
+               ;;
+       *-ibm)
+               os=-aix
+               ;;
+       *-wec)
+               os=-proelf
+               ;;
+       *-winbond)
+               os=-proelf
+               ;;
+       *-oki)
+               os=-proelf
+               ;;
+       *-hp)
+               os=-hpux
+               ;;
+       *-hitachi)
+               os=-hiux
+               ;;
+       i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+               os=-sysv
+               ;;
+       *-cbm)
+               os=-amigaos
+               ;;
+       *-dg)
+               os=-dgux
+               ;;
+       *-dolphin)
+               os=-sysv3
+               ;;
+       m68k-ccur)
+               os=-rtu
+               ;;
+       m88k-omron*)
+               os=-luna
+               ;;
+       *-next )
+               os=-nextstep
+               ;;
+       *-sequent)
+               os=-ptx
+               ;;
+       *-crds)
+               os=-unos
+               ;;
+       *-ns)
+               os=-genix
+               ;;
+       i370-*)
+               os=-mvs
+               ;;
+       *-next)
+               os=-nextstep3
+               ;;
+        *-gould)
+               os=-sysv
+               ;;
+        *-highlevel)
+               os=-bsd
+               ;;
+       *-encore)
+               os=-bsd
+               ;;
+        *-sgi)
+               os=-irix
+               ;;
+        *-siemens)
+               os=-sysv4
+               ;;
+       *-masscomp)
+               os=-rtu
+               ;;
+       f30[01]-fujitsu | f700-fujitsu)
+               os=-uxpv
+               ;;
+       *-rom68k)
+               os=-coff
+               ;;
+       *-*bug)
+               os=-coff
+               ;;
+       *-apple)
+               os=-macos
+               ;;
+       *-atari*)
+               os=-mint
+               ;;
+       *)
+               os=-none
+               ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+       *-unknown)
+               case $os in
+                       -riscix*)
+                               vendor=acorn
+                               ;;
+                       -sunos*)
+                               vendor=sun
+                               ;;
+                       -aix*)
+                               vendor=ibm
+                               ;;
+                       -beos*)
+                               vendor=be
+                               ;;
+                       -hpux*)
+                               vendor=hp
+                               ;;
+                       -mpeix*)
+                               vendor=hp
+                               ;;
+                       -hiux*)
+                               vendor=hitachi
+                               ;;
+                       -unos*)
+                               vendor=crds
+                               ;;
+                       -dgux*)
+                               vendor=dg
+                               ;;
+                       -luna*)
+                               vendor=omron
+                               ;;
+                       -genix*)
+                               vendor=ns
+                               ;;
+                       -mvs* | -opened*)
+                               vendor=ibm
+                               ;;
+                       -ptx*)
+                               vendor=sequent
+                               ;;
+                       -vxsim* | -vxworks*)
+                               vendor=wrs
+                               ;;
+                       -aux*)
+                               vendor=apple
+                               ;;
+                       -hms*)
+                               vendor=hitachi
+                               ;;
+                       -mpw* | -macos*)
+                               vendor=apple
+                               ;;
+                       -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+                               vendor=atari
+                               ;;
+               esac
+               basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+               ;;
+esac
+
+echo $basic_machine$os
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..909cf95
--- /dev/null
@@ -0,0 +1,68 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT(RtAudio, 2.1, gary@ccrma.stanford.edu, rtaudio)
+AC_CONFIG_SRCDIR(RtAudio.cpp)
+AC_CONFIG_FILES(tests/Makefile)
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX(CC g++ c++ cxx)
+
+# Checks for libraries.
+AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS(sys/ioctl.h unistd.h)
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+
+# Check for debug
+AC_MSG_CHECKING(whether to compile debug version)
+AC_ARG_ENABLE(debug,
+  [  --enable-debug = enable various debug output],
+  [AC_SUBST( debug, [-D__RTAUDIO_DEBUG__] ) AC_SUBST( cflags, [-g] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
+  [AC_SUBST( debug, [] ) AC_SUBST( cflags, [-O2] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
+
+# Check compiler and use -Wall if gnu.
+if test $GXX = "yes" ; then
+  AC_SUBST( warn, [-Wall] )
+fi
+
+# Checks for package options and external software
+AC_CANONICAL_HOST
+AC_MSG_CHECKING(for audio API)
+case $host in
+  *-*-linux*)
+  AC_ARG_WITH(alsa, [  --with-alsa = choose native ALSA API support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_ALSA__] ) AC_MSG_RESULT(using ALSA) ], [AC_SUBST( sound_api, [-D__LINUX_OSS__] ) AC_MSG_RESULT(using OSS)])
+
+  if test $sound_api = -D__LINUX_ALSA__; then
+    AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))
+  fi
+  ;;
+
+  *-sgi*)
+  AC_SUBST( sound_api, [-D__IRIX_AL__] )
+  AC_MSG_RESULT(using IRIX AL)
+  AC_CHECK_LIB(audio, alOpenPort, , AC_MSG_ERROR(IRIX audio support requires the audio library!) )
+  ;;
+
+  *-apple*)
+  # Check for CoreAudio framework
+  AC_CHECK_HEADER(CoreAudio/CoreAudio.h,
+    [AC_SUBST( sound_api, [-D__MACOSX_CORE__] )],
+    [AC_MSG_ERROR(CoreAudio header files not found!)] )
+  AC_SUBST( frameworks, ["-framework CoreAudio"] )
+  AC_CHECK_LIB(stdc++, printf, , AC_MSG_ERROR(RtAudio requires the C++ library!) )
+  ;;
+
+  *)
+  # Default case for unknown realtime systems.
+  AC_MSG_ERROR(Unknown system type for realtime support!)
+  ;;
+esac
+
+# Checks for library functions.
+AC_PROG_GCC_TRADITIONAL
+
+AC_OUTPUT
diff --git a/doc/Release.txt b/doc/Release.txt
deleted file mode 100644 (file)
index 5b25661..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-RtAudio - a C++ class which provides a common API for realtime audio input/output across Linux (native ALSA and OSS), SGI, and Windows operating systems.\r
-\r
-By Gary P. Scavone, 2002.\r
-\r
-\r
-v2.01: (27 April 2002)\r
-- Windows destructor bug fix when no devices available\r
-- RtAudioError class renamed to RtError\r
-- Preprocessor definitions changed slightly (i.e. __LINUX_OSS_ to __LINUX_OSS__) to conform with new Synthesis ToolKit distribution\r
-\r
-v2.0: (22 January 2002)\r
-- first release of new independent class\r
-\r
index 3c22d86156e8dbc94eec21db9acf5d66aabe7094..c65a58cff411cace677c5a9edd7d3157628975b7 100644 (file)
-# Doxyfile 1.2.6\r
-\r
-#---------------------------------------------------------------------------\r
-# General configuration options\r
-#---------------------------------------------------------------------------\r
-PROJECT_NAME           = RtAudio\r
-PROJECT_NUMBER         = \r
-OUTPUT_DIRECTORY       = .\r
-OUTPUT_LANGUAGE        = English\r
-EXTRACT_ALL            = YES\r
-EXTRACT_PRIVATE        = NO\r
-EXTRACT_STATIC         = NO\r
-HIDE_UNDOC_MEMBERS     = NO\r
-HIDE_UNDOC_CLASSES     = NO\r
-BRIEF_MEMBER_DESC      = YES\r
-REPEAT_BRIEF           = YES\r
-ALWAYS_DETAILED_SEC    = NO\r
-FULL_PATH_NAMES        = NO\r
-STRIP_FROM_PATH        = \r
-INTERNAL_DOCS          = NO\r
-CLASS_DIAGRAMS         = YES\r
-SOURCE_BROWSER         = NO\r
-INLINE_SOURCES         = NO\r
-STRIP_CODE_COMMENTS    = YES\r
-CASE_SENSE_NAMES       = YES\r
-HIDE_SCOPE_NAMES       = NO\r
-VERBATIM_HEADERS       = YES\r
-SHOW_INCLUDE_FILES     = YES\r
-JAVADOC_AUTOBRIEF      = NO\r
-INHERIT_DOCS           = YES\r
-INLINE_INFO            = YES\r
-SORT_MEMBER_DOCS       = NO\r
-DISTRIBUTE_GROUP_DOC   = NO\r
-TAB_SIZE               = 8\r
-ENABLED_SECTIONS       = \r
-GENERATE_TODOLIST      = YES\r
-GENERATE_TESTLIST      = YES\r
-GENERATE_BUGLIST       = YES\r
-ALIASES                = \r
-MAX_INITIALIZER_LINES  = 30\r
-OPTIMIZE_OUTPUT_FOR_C  = NO\r
-SHOW_USED_FILES        = YES\r
-#---------------------------------------------------------------------------\r
-# configuration options related to warning and progress messages\r
-#---------------------------------------------------------------------------\r
-QUIET                  = NO\r
-WARNINGS               = YES\r
-WARN_IF_UNDOCUMENTED   = YES\r
-WARN_FORMAT            = "$file:$line: $text"\r
-WARN_LOGFILE           = \r
-#---------------------------------------------------------------------------\r
-# configuration options related to the input files\r
-#---------------------------------------------------------------------------\r
-INPUT                  = tutorial.txt ../../RtAudio.h\r
-FILE_PATTERNS          = \r
-RECURSIVE              = NO\r
-EXCLUDE                = \r
-EXCLUDE_PATTERNS       = \r
-EXAMPLE_PATH           = \r
-EXAMPLE_PATTERNS       = \r
-IMAGE_PATH             = \r
-INPUT_FILTER           = \r
-FILTER_SOURCE_FILES    = NO\r
-#---------------------------------------------------------------------------\r
-# configuration options related to the alphabetical class index\r
-#---------------------------------------------------------------------------\r
-ALPHABETICAL_INDEX     = NO\r
-COLS_IN_ALPHA_INDEX    = 5\r
-IGNORE_PREFIX          = \r
-#---------------------------------------------------------------------------\r
-# configuration options related to the HTML output\r
-#---------------------------------------------------------------------------\r
-GENERATE_HTML          = YES\r
-HTML_OUTPUT            = ../html\r
-HTML_HEADER            = header.html\r
-HTML_FOOTER            = footer.html\r
-HTML_STYLESHEET        = \r
-HTML_ALIGN_MEMBERS     = YES\r
-GENERATE_HTMLHELP      = NO\r
-GENERATE_CHI           = NO\r
-BINARY_TOC             = NO\r
-TOC_EXPAND             = NO\r
-DISABLE_INDEX          = YES\r
-ENUM_VALUES_PER_LINE   = 4\r
-GENERATE_TREEVIEW      = NO\r
-TREEVIEW_WIDTH         = 250\r
-#---------------------------------------------------------------------------\r
-# configuration options related to the LaTeX output\r
-#---------------------------------------------------------------------------\r
-GENERATE_LATEX         = YES\r
-LATEX_OUTPUT           = latex\r
-COMPACT_LATEX          = NO\r
-PAPER_TYPE             = letter\r
-EXTRA_PACKAGES         = \r
-LATEX_HEADER           = \r
-PDF_HYPERLINKS         = NO\r
-USE_PDFLATEX           = YES\r
-LATEX_BATCHMODE        = NO\r
-#---------------------------------------------------------------------------\r
-# configuration options related to the RTF output\r
-#---------------------------------------------------------------------------\r
-GENERATE_RTF           = NO\r
-RTF_OUTPUT             = rtf\r
-COMPACT_RTF            = NO\r
-RTF_HYPERLINKS         = NO\r
-RTF_STYLESHEET_FILE    = \r
-#---------------------------------------------------------------------------\r
-# configuration options related to the man page output\r
-#---------------------------------------------------------------------------\r
-GENERATE_MAN           = NO\r
-MAN_OUTPUT             = man\r
-MAN_EXTENSION          = .3\r
-#---------------------------------------------------------------------------\r
-# Configuration options related to the preprocessor   \r
-#---------------------------------------------------------------------------\r
-ENABLE_PREPROCESSING   = YES\r
-MACRO_EXPANSION        = NO\r
-EXPAND_ONLY_PREDEF     = NO\r
-SEARCH_INCLUDES        = YES\r
-INCLUDE_PATH           = \r
-INCLUDE_FILE_PATTERNS  = \r
-PREDEFINED             = \r
-EXPAND_AS_DEFINED      = \r
-#---------------------------------------------------------------------------\r
-# Configuration::addtions related to external references   \r
-#---------------------------------------------------------------------------\r
-TAGFILES               = \r
-GENERATE_TAGFILE       = \r
-ALLEXTERNALS           = NO\r
-PERL_PATH              = /usr/bin/perl\r
-#---------------------------------------------------------------------------\r
-# Configuration options related to the dot tool   \r
-#---------------------------------------------------------------------------\r
-HAVE_DOT               = NO\r
-CLASS_GRAPH            = YES\r
-COLLABORATION_GRAPH    = YES\r
-INCLUDE_GRAPH          = YES\r
-INCLUDED_BY_GRAPH      = YES\r
-GRAPHICAL_HIERARCHY    = YES\r
-DOT_PATH               = \r
-MAX_DOT_GRAPH_WIDTH    = 1024\r
-MAX_DOT_GRAPH_HEIGHT   = 1024\r
-GENERATE_LEGEND        = YES\r
-DOT_CLEANUP            = YES\r
-#---------------------------------------------------------------------------\r
-# Configuration::addtions related to the search engine   \r
-#---------------------------------------------------------------------------\r
-SEARCHENGINE           = NO\r
-CGI_NAME               = search.cgi\r
-CGI_URL                = \r
-DOC_URL                = \r
-DOC_ABSPATH            = \r
-BIN_ABSPATH            = /usr/local/bin/\r
-EXT_DOC_PATHS          = \r
-\r
+# Doxyfile 1.2.6
+
+#---------------------------------------------------------------------------
+# General configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME           = RtAudio
+PROJECT_NUMBER         = 
+OUTPUT_DIRECTORY       = .
+OUTPUT_LANGUAGE        = English
+EXTRACT_ALL            = NO
+EXTRACT_PRIVATE        = NO
+EXTRACT_STATIC         = NO
+HIDE_UNDOC_MEMBERS     = YES
+HIDE_UNDOC_CLASSES     = NO
+BRIEF_MEMBER_DESC      = YES
+REPEAT_BRIEF           = YES
+ALWAYS_DETAILED_SEC    = NO
+FULL_PATH_NAMES        = NO
+STRIP_FROM_PATH        = 
+INTERNAL_DOCS          = NO
+CLASS_DIAGRAMS         = YES
+SOURCE_BROWSER         = NO
+INLINE_SOURCES         = NO
+STRIP_CODE_COMMENTS    = YES
+CASE_SENSE_NAMES       = YES
+HIDE_SCOPE_NAMES       = NO
+VERBATIM_HEADERS       = YES
+SHOW_INCLUDE_FILES     = YES
+JAVADOC_AUTOBRIEF      = NO
+INHERIT_DOCS           = YES
+INLINE_INFO            = YES
+SORT_MEMBER_DOCS       = NO
+DISTRIBUTE_GROUP_DOC   = NO
+TAB_SIZE               = 8
+ENABLED_SECTIONS       = 
+GENERATE_TODOLIST      = YES
+GENERATE_TESTLIST      = YES
+GENERATE_BUGLIST       = YES
+ALIASES                = 
+MAX_INITIALIZER_LINES  = 30
+OPTIMIZE_OUTPUT_FOR_C  = NO
+SHOW_USED_FILES        = YES
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET                  = NO
+WARNINGS               = YES
+WARN_IF_UNDOCUMENTED   = YES
+WARN_FORMAT            = "$file:$line: $text"
+WARN_LOGFILE           = 
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT                  = tutorial.txt ../../RtAudio.h
+FILE_PATTERNS          = 
+RECURSIVE              = NO
+EXCLUDE                = 
+EXCLUDE_PATTERNS       = 
+EXAMPLE_PATH           = 
+EXAMPLE_PATTERNS       = 
+IMAGE_PATH             = 
+INPUT_FILTER           = 
+FILTER_SOURCE_FILES    = NO
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX     = NO
+COLS_IN_ALPHA_INDEX    = 5
+IGNORE_PREFIX          = 
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML          = YES
+HTML_OUTPUT            = ../html
+HTML_HEADER            = header.html
+HTML_FOOTER            = footer.html
+HTML_STYLESHEET        = 
+HTML_ALIGN_MEMBERS     = YES
+GENERATE_HTMLHELP      = NO
+GENERATE_CHI           = NO
+BINARY_TOC             = NO
+TOC_EXPAND             = NO
+DISABLE_INDEX          = YES
+ENUM_VALUES_PER_LINE   = 4
+GENERATE_TREEVIEW      = NO
+TREEVIEW_WIDTH         = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX         = NO
+LATEX_OUTPUT           = latex
+COMPACT_LATEX          = NO
+PAPER_TYPE             = letter
+EXTRA_PACKAGES         = 
+LATEX_HEADER           = 
+PDF_HYPERLINKS         = NO
+USE_PDFLATEX           = YES
+LATEX_BATCHMODE        = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF           = NO
+RTF_OUTPUT             = rtf
+COMPACT_RTF            = NO
+RTF_HYPERLINKS         = NO
+RTF_STYLESHEET_FILE    = 
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN           = NO
+MAN_OUTPUT             = man
+MAN_EXTENSION          = .3
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor   
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING   = YES
+MACRO_EXPANSION        = NO
+EXPAND_ONLY_PREDEF     = NO
+SEARCH_INCLUDES        = YES
+INCLUDE_PATH           = 
+INCLUDE_FILE_PATTERNS  = 
+PREDEFINED             = 
+EXPAND_AS_DEFINED      = 
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references   
+#---------------------------------------------------------------------------
+TAGFILES               = 
+GENERATE_TAGFILE       = 
+ALLEXTERNALS           = NO
+PERL_PATH              = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool   
+#---------------------------------------------------------------------------
+HAVE_DOT               = NO
+CLASS_GRAPH            = YES
+COLLABORATION_GRAPH    = YES
+INCLUDE_GRAPH          = YES
+INCLUDED_BY_GRAPH      = YES
+GRAPHICAL_HIERARCHY    = YES
+DOT_PATH               = 
+MAX_DOT_GRAPH_WIDTH    = 1024
+MAX_DOT_GRAPH_HEIGHT   = 1024
+GENERATE_LEGEND        = YES
+DOT_CLEANUP            = YES
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine   
+#---------------------------------------------------------------------------
+SEARCHENGINE           = NO
+CGI_NAME               = search.cgi
+CGI_URL                = 
+DOC_URL                = 
+DOC_ABSPATH            = 
+BIN_ABSPATH            = /usr/local/bin/
+EXT_DOC_PATHS          = 
+
index eb4756924af1b35d8b9843a35ab7aa03e0918faf..b34356f58f9cb438b92f9e98fb54036b87d454a3 100644 (file)
@@ -1,9 +1,9 @@
-<HR>\r
-\r
-<table><tr><td><img src="../images/ccrma.gif">\r
-  <td>&copy;2001-2002 CCRMA, Stanford University. All Rights Reserved.<br>\r
-  Maintained by Gary P. Scavone, <a href="mailto:gary@ccrma.stanford.edu">gary@ccrma.stanford.edu</a><P>\r
-</table>\r
-\r
-</BODY>\r
+<HR>
+
+<table><tr><td><img src="../images/ccrma.gif">
+  <td>&copy;2001-2002 Gary P. Scavone, CCRMA, Stanford University. All Rights Reserved.<br>
+  Maintained by Gary P. Scavone, <a href="mailto:gary@ccrma.stanford.edu">gary@ccrma.stanford.edu</a><P>
+</table>
+
+</BODY>
 </HTML>
\ No newline at end of file
index ab47e24b3f9682e38d8d6290e57b4c5e08266a06..8458ac9717ab1df5aa2cbabda023cdfa3cdd0f75 100644 (file)
@@ -1,9 +1,9 @@
-<HTML>\r
-<HEAD>\r
-<TITLE>The RtAudio Tutorial</TITLE>\r
-<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">\r
-</HEAD>\r
-<BODY BGCOLOR="#FFFFFF">\r
-<CENTER>\r
-<a class="qindex" href="index.html">Tutorial</a> &nbsp; <a class="qindex" href="annotated.html">Class/Enum List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </CENTER>\r
+<HTML>
+<HEAD>
+<TITLE>The RtAudio Tutorial</TITLE>
+<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
+</HEAD>
+<BODY BGCOLOR="#FFFFFF">
+<CENTER>
+<a class="qindex" href="index.html">Tutorial</a> &nbsp; <a class="qindex" href="annotated.html">Class/Enum List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </CENTER>
 <HR>
\ No newline at end of file
index 951b28b79fdb9c8df709bb4e63a7644bd3363b2f..db703ac9d40d61ccc096c807085d334a6d0a11a0 100644 (file)
-/*! \mainpage The RtAudio Tutorial\r
-\r
-<BODY BGCOLOR="white">\r
-\r
-- \ref intro\r
-- \ref start\r
-- \ref error\r
-- \ref probing\r
-- \ref settings\r
-- \ref playbackb\r
-- \ref playbackc\r
-- \ref recording\r
-- \ref duplex\r
-- \ref methods\r
-- \ref compiling\r
-- \ref osnotes\r
-- \ref acknowledge\r
-\r
-\section intro Introduction\r
-\r
-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:\r
-\r
-<UL>\r
-  <LI>object oriented C++ design</LI>\r
-  <LI>simple, common API across all supported platforms</LI>\r
-  <LI>single independent header and source file for easy inclusion in programming projects (no libraries!)</LI>\r
-  <LI>blocking functionality</LI>\r
-  <LI>callback functionality</LI>\r
-  <LI>extensive audio device parameter control</LI>\r
-  <LI>audio device capability probing</LI>\r
-  <LI>automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping</LI>\r
-  <LI>control over multiple audio streams and devices with a single instance</LI>\r
-</UL>\r
-\r
-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.\r
-\r
-The RtAudio API provides both blocking (synchronous) and callback (asyncronous) 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.\r
-\r
-\section start Getting Started\r
-\r
-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:\r
-\r
-\code\r
-\r
-#include "RtAudio.h"\r
-\r
-int main()\r
-{\r
-  RtAudio *audio;\r
-\r
-  // Default RtAudio constructor\r
-  try {\r
-    audio = new RtAudio();\r
-  }\r
-  catch (RtError &error) {\r
-    // Handle the exception here\r
-  }\r
-\r
-  // Clean up\r
-  delete audio;\r
-}\r
-\endcode\r
-\r
-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.\r
-\r
-\r
-\section error Error Handling\r
-\r
-RtAudio uses a C++ exception handler called RtError, which is declared and defined within the RtAudio class files.  The RtError class is quite simple but it does allow errors to be "caught" by RtError::TYPE.  Almost all RtAudio methods can "throw" an RtError, 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.\r
-\r
-\r
-\section probing Probing Device Capabilities\r
-\r
-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.\r
-\r
-\code\r
-\r
-// probe.cpp\r
-\r
-#include <iostream>\r
-#include "RtAudio.h"\r
-\r
-int main()\r
-{\r
-  RtAudio *audio;\r
-\r
-  // Default RtAudio constructor\r
-  try {\r
-    audio = new RtAudio();\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  // Determine the number of devices available\r
-  int devices = audio->getDeviceCount();\r
-\r
-  // Scan through devices for various capabilities\r
-  RtAudio::RTAUDIO_DEVICE info;\r
-  for (int i=0; i<devices; i++) {\r
-\r
-    try {\r
-      audio->getDeviceInfo(i, &info);\r
-    }\r
-    catch (RtError &error) {\r
-      error.printMessage();\r
-      break;\r
-    }\r
-\r
-    // Print, for example, the maximum number of output channels for each device\r
-    cout << "device = " << i;\r
-    cout << ": maximum output channels = " << info.maxOutputChannels << "\n";\r
-  }\r
-\r
-  // Clean up\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-The RTAUDIO_DEVICE structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device:\r
-\r
-\code\r
-  typedef struct {\r
-    char name[128];\r
-    DEVICE_ID id[2];                      // No value reported by getDeviceInfo().\r
-    bool probed;                          // true if the device probe was successful.\r
-    int maxOutputChannels;\r
-    int maxInputChannels;\r
-    int maxDuplexChannels;\r
-    int minOutputChannels;\r
-    int minInputChannels;\r
-    int minDuplexChannels;\r
-    bool hasDuplexSupport;                // true if duplex supported\r
-    int nSampleRates;                     // Number of discrete rates, or -1 if range supported.\r
-    double sampleRates[MAX_SAMPLE_RATES]; // Supported sample rates, or {min, max} if range.\r
-    RTAUDIO_FORMAT nativeFormats;\r
-  } RTAUDIO_DEVICE;\r
-\endcode\r
-\r
-The following data formats are defined and fully supported by RtAudio:\r
-\r
-\code\r
-  typedef unsigned long RTAUDIO_FORMAT;\r
-  static const RTAUDIO_FORMAT  RTAUDIO_SINT8;   // Signed 8-bit integer\r
-  static const RTAUDIO_FORMAT  RTAUDIO_SINT16;  // Signed 16-bit integer\r
-  static const RTAUDIO_FORMAT  RTAUDIO_SINT24;  // Signed 24-bit integer\r
-  static const RTAUDIO_FORMAT  RTAUDIO_SINT32;  // Signed 32-bit integer\r
-  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT32; // 32-bit float\r
-  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT64; // 64-bit double\r
-\endcode\r
-\r
-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 unuseable.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\r
-\section settings Device Settings\r
-\r
-The next step in using RtAudio is to open a stream with a particular set of device settings.\r
-\r
-\code\r
-\r
-#include "RtAudio.h"\r
-\r
-int main()\r
-{\r
-  int channels = 2;\r
-  int sample_rate = 44100;\r
-  int buffer_size = 256;  // 256 sample frames\r
-  int n_buffers = 4;      // number of internal buffers used by device\r
-  int device = 0;         // 0 indicates the default or first available device\r
-  int stream;             // our stream identifier\r
-  RtAudio *audio;\r
-\r
-  // Instantiate RtAudio and open a stream within a try/catch block\r
-  try {\r
-    audio = new RtAudio();\r
-    stream = audio->openStream(device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,\r
-                               sample_rate, &buffer_size, n_buffers);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  // Clean up\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-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 RtError is thrown.  When a non-zero device value is specified, an attempt is made to open that device only.\r
-\r
-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.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\r
-\section playbackb Playback (blocking functionality)\r
-\r
-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.\r
-\r
-\code\r
-// playback.cpp\r
-\r
-#include "RtAudio.h"\r
-\r
-int main()\r
-{\r
-  int count;\r
-  int channels = 2;\r
-  int sample_rate = 44100;\r
-  int buffer_size = 256;  // 256 sample frames\r
-  int n_buffers = 4;      // number of internal buffers used by device\r
-  float *buffer;\r
-  int device = 0;         // 0 indicates the default or first available device\r
-  int stream;             // our stream identifier\r
-  RtAudio *audio;\r
-\r
-  // Open a stream during RtAudio instantiation\r
-  try {\r
-    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,\r
-                        sample_rate, &buffer_size, n_buffers);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  try {\r
-    // Get a pointer to the stream buffer\r
-    buffer = (float *) audio->getStreamBuffer(stream);\r
-\r
-    // Start the stream\r
-    audio->startStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    goto cleanup;\r
-  }\r
-\r
-  // An example loop which runs for about 40000 sample frames\r
-  count = 0;\r
-  while (count < 40000) {\r
-    // Generate your samples and fill the buffer with buffer_size sample frames of data\r
-    ...\r
-\r
-    // Trigger the output of the data buffer\r
-    try {\r
-      audio->tickStream(stream);\r
-    }\r
-    catch (RtError &error) {\r
-      error.printMessage();\r
-      goto cleanup;\r
-    }\r
-\r
-    count += buffer_size;\r
-  }\r
-\r
-  try {\r
-    // Stop and close the stream\r
-    audio->stopStream(stream);\r
-    audio->closeStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-  }\r
-\r
- cleanup:\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-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.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\r
-\section playbackc Playback (callback functionality)\r
-\r
-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.\r
-\r
-\code\r
-\r
-#include <iostream>\r
-#include "RtAudio.h"\r
-\r
-// Two-channel sawtooth wave generator.\r
-int sawtooth(char *buffer, int buffer_size, void *data)\r
-{\r
-  int i, j;\r
-  double *my_buffer = (double *) buffer;\r
-  double *my_data = (double *) data;\r
-\r
-  // Write interleaved audio data.\r
-  for (i=0; i<buffer_size; i++) {\r
-    for (j=0; j<2; j++) {\r
-      *my_buffer++ = my_data[j];\r
-\r
-      my_data[j] += 0.005 * (j+1+(j*0.1));\r
-      if (my_data[j] >= 1.0) my_data[j] -= 2.0;\r
-    }\r
-  }\r
-\r
-  return 0;\r
-}\r
-\r
-int main()\r
-{\r
-  int channels = 2;\r
-  int sample_rate = 44100;\r
-  int buffer_size = 256;  // 256 sample frames\r
-  int n_buffers = 4;      // number of internal buffers used by device\r
-  int device = 0;         // 0 indicates the default or first available device\r
-  int stream;             // our stream identifier\r
-  double data[2];\r
-  char input;\r
-  RtAudio *audio;\r
-\r
-  // Open a stream during RtAudio instantiation\r
-  try {\r
-    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT64,\r
-                        sample_rate, &buffer_size, n_buffers);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  try {\r
-    // Set the stream callback function\r
-    audio->setStreamCallback(stream, &sawtooth, (void *)data);\r
-\r
-    // Start the stream\r
-    audio->startStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    goto cleanup;\r
-  }\r
-\r
-  cout << "\nPlaying ... press <enter> to quit.\n";\r
-  cin.get(input);\r
-\r
-  try {\r
-    // Stop and close the stream\r
-    audio->stopStream(stream);\r
-    audio->closeStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-  }\r
-\r
- cleanup:\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-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.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\r
-\section recording Recording\r
-\r
-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:\r
-\r
-\code\r
-// record.cpp\r
-\r
-#include "RtAudio.h"\r
-\r
-int main()\r
-{\r
-  int count;\r
-  int channels = 2;\r
-  int sample_rate = 44100;\r
-  int buffer_size = 256;  // 256 sample frames\r
-  int n_buffers = 4;      // number of internal buffers used by device\r
-  float *buffer;\r
-  int device = 0;         // 0 indicates the default or first available device\r
-  int stream;             // our stream identifier\r
-  RtAudio *audio;\r
-\r
-  // Instantiate RtAudio and open a stream.\r
-  try {\r
-    audio = new RtAudio(&stream, 0, 0, device, channels,\r
-                        RtAudio::RTAUDIO_FLOAT32, sample_rate, &buffer_size, n_buffers);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  try {\r
-    // Get a pointer to the stream buffer\r
-    buffer = (float *) audio->getStreamBuffer(stream);\r
-\r
-    // Start the stream\r
-    audio->startStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    goto cleanup;\r
-  }\r
-\r
-  // An example loop which runs for about 40000 sample frames\r
-  count = 0;\r
-  while (count < 40000) {\r
-\r
-    // Read a buffer of data\r
-    try {\r
-      audio->tickStream(stream);\r
-    }\r
-    catch (RtError &error) {\r
-      error.printMessage();\r
-      goto cleanup;\r
-    }\r
-\r
-    // Process the input samples (buffer_size sample frames) that were read\r
-    ...\r
-\r
-    count += buffer_size;\r
-  }\r
-\r
-  try {\r
-    // Stop the stream\r
-    audio->stopStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-  }\r
-\r
- cleanup:\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-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.\r
-\r
-\r
-\section duplex Duplex Mode\r
-\r
-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.\r
-\r
-\code\r
-// duplex.cpp\r
-\r
-#include <iostream>\r
-#include "RtAudio.h"\r
-\r
-// Pass-through function.\r
-int pass(char *buffer, int buffer_size, void *)\r
-{\r
-  // Surprise!!  We do nothing to pass the data through.\r
-  return 0;\r
-}\r
-\r
-int main()\r
-{\r
-  int channels = 2;\r
-  int sample_rate = 44100;\r
-  int buffer_size = 256;  // 256 sample frames\r
-  int n_buffers = 4;      // number of internal buffers used by device\r
-  int device = 0;         // 0 indicates the default or first available device\r
-  int stream;             // our stream identifier\r
-  double data[2];\r
-  char input;\r
-  RtAudio *audio;\r
-\r
-  // Open a stream during RtAudio instantiation\r
-  try {\r
-    audio = new RtAudio(&stream, device, channels, device, channels, RtAudio::RTAUDIO_FLOAT64,\r
-                        sample_rate, &buffer_size, n_buffers);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    exit(EXIT_FAILURE);\r
-  }\r
-\r
-  try {\r
-    // Set the stream callback function\r
-    audio->setStreamCallback(stream, &pass, NULL);\r
-\r
-    // Start the stream\r
-    audio->startStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-    goto cleanup;\r
-  }\r
-\r
-  cout << "\nRunning duplex ... press <enter> to quit.\n";\r
-  cin.get(input);\r
-\r
-  try {\r
-    // Stop and close the stream\r
-    audio->stopStream(stream);\r
-    audio->closeStream(stream);\r
-  }\r
-  catch (RtError &error) {\r
-    error.printMessage();\r
-  }\r
-\r
- cleanup:\r
-  delete audio;\r
-\r
-  return 0;\r
-}\r
-\endcode\r
-\r
-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.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\r
-\section methods Summary of Methods\r
-\r
-The following is short summary of public methods (not including constructors and the destructor) provided by RtAudio:\r
-\r
-<UL>\r
-<LI>RtAudio::openStream(): opens a stream with the specified parameters.</LI>\r
-<LI>RtAudio::setStreamCallback(): sets a user-defined callback function for a given stream.</LI>\r
-<LI>RtAudio::cancelStreamCallback(): cancels a callback process and function for a given stream.</LI>\r
-<LI>RtAudio::getDeviceCount(): returns the number of audio devices available.</LI>\r
-<LI>RtAudio::getDeviceInfo(): fills a user-supplied RTAUDIO_DEVICE structure for a specified device.</LI>\r
-<LI>RtAudio::getStreamBuffer(): returns a pointer to the stream buffer.</LI>\r
-<LI>RtAudio::tickStream(): triggers processing of input/output data for a stream (blocking).</LI>\r
-<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>\r
-<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>\r
-<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>\r
-<LI>RtAudio::abortStream(): stops the specified stream, discarding any remaining samples in the queue.  This does not implicitly call closeStream().</LI>\r
-<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>\r
-</UL>\r
-\r
-\r
-\section compiling Compiling\r
-\r
-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:\r
-<P>\r
-\r
-<TABLE BORDER=2 COLS=5 WIDTH="100%">\r
-<TR BGCOLOR="beige">\r
-  <TD WIDTH="5%"><B>OS:</B></TD>\r
-  <TD WIDTH="5%"><B>Audio API:</B></TD>\r
-  <TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>\r
-  <TD WIDTH="5%"><B>Library:</B></TD>\r
-  <TD><B>Example Compiler Statement:</B></TD>\r
-</TR>\r
-<TR>\r
-  <TD>Linux</TD>\r
-  <TD>ALSA</TD>\r
-  <TD>__LINUX_ALSA__</TD>\r
-  <TD><TT>libasound, libpthread</TT></TD>\r
-  <TD><TT>g++ -Wall -D__LINUX_ALSA__ -o probe probe.cpp RtAudio.cpp -lasound -lpthread</TT></TD>\r
-</TR>\r
-<TR>\r
-  <TD>Linux</TD>\r
-  <TD>OSS</TD>\r
-  <TD>__LINUX_OSS__</TD>\r
-  <TD><TT>libpthread</TT></TD>\r
-  <TD><TT>g++ -Wall -D__LINUX_OSS__ -o probe probe.cpp RtAudio.cpp -lpthread</TT></TD>\r
-</TR>\r
-<TR>\r
-  <TD>Irix</TD>\r
-  <TD>AL</TD>\r
-  <TD>__IRIX_AL__</TD>\r
-  <TD><TT>libaudio, libpthread</TT></TD>\r
-  <TD><TT>CC -Wall -D__IRIX_AL__ -o probe probe.cpp RtAudio.cpp -laudio -lpthread</TT></TD>\r
-</TR>\r
-<TR>\r
-  <TD>Windows</TD>\r
-  <TD>Direct Sound</TD>\r
-  <TD>__WINDOWS_DS__</TD>\r
-  <TD><TT>dsound.lib (ver. 5.0 or higher), multithreaded</TT></TD>\r
-  <TD><I>compiler specific</I></TD>\r
-</TR>\r
-</TABLE>\r
-<P>\r
-\r
-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.\r
-\r
-\section osnotes OS Notes\r
-\r
-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.\r
-\r
-\subsection linux Linux:\r
-\r
-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, although relatively new, is now part of the Linux development kernel and 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 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.\r
-\r
-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.\r
-\r
-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.\r
-\r
-\subsection irix Irix (SGI):\r
-\r
-The Irix version of RtAudio was written and tested on an SGI Indy running Irix version 6.5.4 and the newer "al" audio library.  RtAudio does not compile under Irix version 6.3, mainly 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.\r
-\r
-\subsection windows Windows:\r
-\r
-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 5.0 or higher.  As far as I know, there is no DirectSoundCapture support for Windows NT (in which case, you cannot use RtAudio).  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. \r
-\r
-\r
-\section acknowledge Acknowledgements\r
-\r
-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.\r
-\r
-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).\r
-\r
-*/\r
+/*! \mainpage The RtAudio Tutorial
+
+<BODY BGCOLOR="white">
+
+- \ref intro
+- \ref download
+- \ref start
+- \ref error
+- \ref probing
+- \ref settings
+- \ref playbackb
+- \ref playbackc
+- \ref recording
+- \ref duplex
+- \ref methods
+- \ref compiling
+- \ref debug
+- \ref osnotes
+- \ref acknowledge
+- \ref license
+
+\section intro Introduction
+
+RtAudio is a C++ class which provides a common API (Application Programming Interface) for realtime audio input/output across Linux (native ALSA and OSS), Macintosh OS X, SGI, and Windows (DirectSound and ASIO) operating systems.  RtAudio significantly simplifies the process of interacting with computer audio hardware.  It was designed with the following goals:
+
+<UL>
+  <LI>object oriented C++ design</LI>
+  <LI>simple, common API across all supported platforms</LI>
+  <LI>single independent header and source file for easy inclusion in programming projects</LI>
+  <LI>blocking functionality</LI>
+  <LI>callback functionality</LI>
+  <LI>extensive audio device parameter control</LI>
+  <LI>audio device capability probing</LI>
+  <LI>automatic internal conversion for data format, channel number compensation, de-interleaving, and byte-swapping</LI>
+  <LI>control over multiple audio streams and devices with a single instance</LI>
+</UL>
+
+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.  When allowed by the underlying audio API, multiple streams can run at the same time and a single device can serve multiple streams.  See the \ref osnotes section for information specific to each of the supported audio APIs.
+
+The RtAudio API provides both blocking (synchronous) and callback (asyncronous) 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.
+
+\section download Download
+
+Latest Release (7 October 2002): <A href="http://www-ccrma.stanford.edu/~gary/rtaudio/release/rtaudio-2.1.tar.gz">Version 2.1 (165 kB tar/gzipped)</A>
+
+
+\section start Getting Started
+
+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:
+
+\code
+
+#include "RtAudio.h"
+
+int main()
+{
+  RtAudio *audio;
+
+  // Default RtAudio constructor
+  try {
+    audio = new RtAudio();
+  }
+  catch (RtError &error) {
+    // Handle the exception here
+  }
+
+  // Clean up
+  delete audio;
+}
+\endcode
+
+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.
+
+
+\section error Error Handling
+
+RtAudio uses a C++ exception handler called RtError, which is declared and defined within the RtAudio class files.  The RtError class is quite simple but it does allow errors to be "caught" by RtError::TYPE.  Almost all RtAudio methods can "throw" an RtError, 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.
+
+
+\section probing Probing Device Capabilities
+
+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.
+
+\code
+
+// probe.cpp
+
+#include <iostream>
+#include "RtAudio.h"
+
+int main()
+{
+  RtAudio *audio;
+
+  // Default RtAudio constructor
+  try {
+    audio = new RtAudio();
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  // Determine the number of devices available
+  int devices = audio->getDeviceCount();
+
+  // Scan through devices for various capabilities
+  RtAudio::RTAUDIO_DEVICE info;
+  for (int i=1; i<=devices; i++) {
+
+    try {
+      audio->getDeviceInfo(i, &info);
+    }
+    catch (RtError &error) {
+      error.printMessage();
+      break;
+    }
+
+    // Print, for example, the maximum number of output channels for each device
+    cout << "device = " << i;
+    cout << ": maximum output channels = " << info.maxOutputChannels << "\n";
+  }
+
+  // Clean up
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+The RTAUDIO_DEVICE structure is defined in RtAudio.h and provides a variety of information useful in assessing the capabilities of a device:
+
+\code
+  typedef struct {
+    char name[128];
+    bool probed;                          // true if the device probe was successful.
+    int maxOutputChannels;
+    int maxInputChannels;
+    int maxDuplexChannels;
+    int minOutputChannels;
+    int minInputChannels;
+    int minDuplexChannels;
+    bool hasDuplexSupport;                // true if duplex mode is supported.
+    bool isDefault;                       // true if this is the default output or input device.
+    int nSampleRates;                     // Number of discrete rates, or -1 if range supported.
+    double sampleRates[MAX_SAMPLE_RATES]; // Supported sample rates, or {min, max} if range.
+    RTAUDIO_FORMAT nativeFormats;
+  } RTAUDIO_DEVICE;
+\endcode
+
+The following data formats are defined and fully supported by RtAudio:
+
+\code
+  typedef unsigned long RTAUDIO_FORMAT;
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT8;   // Signed 8-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT16;  // Signed 16-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT24;  // Signed 24-bit integer (upper 3 bytes of 32-bit signed integer.)
+  static const RTAUDIO_FORMAT  RTAUDIO_SINT32;  // Signed 32-bit integer
+  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT32; // 32-bit float normalized between +/- 1.0
+  static const RTAUDIO_FORMAT  RTAUDIO_FLOAT64; // 64-bit double normalized between +/- 1.0
+\endcode
+
+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 undefined and the device is probably unuseable.
+
+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.
+
+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.  For this reason, RtAudio does not rely on the reported values when attempting to open a stream.
+
+
+\section settings Device Settings
+
+The next step in using RtAudio is to open a stream with particular device and parameter settings.
+
+\code
+
+#include "RtAudio.h"
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Instantiate RtAudio and open a stream within a try/catch block
+  try {
+    audio = new RtAudio();
+    stream = audio->openStream(device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
+                               sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  // Clean up
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+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 two channel playback stream with the default output device, 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, RtAudio searches through the remaining available devices in an effort to find a device which will meet the given parameters.  If all attempts are unsuccessful, an RtError is thrown.  When a non-zero device value is specified, an attempt is made to open that device only (device = 1 specifies the first identified device, as reported by RtAudio::getDeviceInfo()).
+
+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.
+
+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 (the <I>nBuffers</I> parameter is ignored when using the OS X CoreAudio and the Windows ASIO APIs).  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.
+
+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.
+
+
+\section playbackb Playback (blocking functionality)
+
+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.
+
+\code
+// playback.cpp
+
+#include "RtAudio.h"
+
+int main()
+{
+  int count;
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  float *buffer;
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT32,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Get a pointer to the stream buffer
+    buffer = (float *) audio->getStreamBuffer(stream);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  // An example loop which runs for about 40000 sample frames
+  count = 0;
+  while (count < 40000) {
+    // Generate your samples and fill the buffer with buffer_size sample frames of data
+    ...
+
+    // Trigger the output of the data buffer
+    try {
+      audio->tickStream(stream);
+    }
+    catch (RtError &error) {
+      error.printMessage();
+      goto cleanup;
+    }
+
+    count += buffer_size;
+  }
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+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.
+
+Because RtAudio can typically 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.
+
+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.
+
+
+\section playbackc Playback (callback functionality)
+
+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.
+
+\code
+
+#include <iostream>
+#include "RtAudio.h"
+
+// Two-channel sawtooth wave generator.
+int sawtooth(char *buffer, int buffer_size, void *data)
+{
+  int i, j;
+  double *my_buffer = (double *) buffer;
+  double *my_data = (double *) data;
+
+  // Write interleaved audio data.
+  for (i=0; i<buffer_size; i++) {
+    for (j=0; j<2; j++) {
+      *my_buffer++ = my_data[j];
+
+      my_data[j] += 0.005 * (j+1+(j*0.1));
+      if (my_data[j] >= 1.0) my_data[j] -= 2.0;
+    }
+  }
+
+  return 0;
+}
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  double data[2];
+  char input;
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, 0, 0, RtAudio::RTAUDIO_FLOAT64,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Set the stream callback function
+    audio->setStreamCallback(stream, &sawtooth, (void *)data);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  cout << "\nPlaying ... press <enter> to quit.\n";
+  cin.get(input);
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+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().  When the underlying audio API uses blocking calls (OSS, ALSA, SGI, and Windows DirectSound), this method will spawn a new process (or thread) which automatically calls the callback function when more data is needed.  Callback-based audio APIs (OS X CoreAudio and ASIO) implement their own event notification schemes.  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.
+
+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.
+
+Once set with RtAudio::setStreamCallback, the callback process exists 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.
+
+
+\section recording Recording
+
+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:
+
+\code
+// record.cpp
+
+#include "RtAudio.h"
+
+int main()
+{
+  int count;
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  float *buffer;
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  RtAudio *audio;
+
+  // Instantiate RtAudio and open a stream.
+  try {
+    audio = new RtAudio(&stream, 0, 0, device, channels,
+                        RtAudio::RTAUDIO_FLOAT32, sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Get a pointer to the stream buffer
+    buffer = (float *) audio->getStreamBuffer(stream);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  // An example loop which runs for about 40000 sample frames
+  count = 0;
+  while (count < 40000) {
+
+    // Read a buffer of data
+    try {
+      audio->tickStream(stream);
+    }
+    catch (RtError &error) {
+      error.printMessage();
+      goto cleanup;
+    }
+
+    // Process the input samples (buffer_size sample frames) that were read
+    ...
+
+    count += buffer_size;
+  }
+
+  try {
+    // Stop the stream
+    audio->stopStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+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.
+
+
+\section duplex Duplex Mode
+
+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.
+
+\code
+// duplex.cpp
+
+#include <iostream>
+#include "RtAudio.h"
+
+// Pass-through function.
+int pass(char *buffer, int buffer_size, void *)
+{
+  // Surprise!!  We do nothing to pass the data through.
+  return 0;
+}
+
+int main()
+{
+  int channels = 2;
+  int sample_rate = 44100;
+  int buffer_size = 256;  // 256 sample frames
+  int n_buffers = 4;      // number of internal buffers used by device
+  int device = 0;         // 0 indicates the default or first available device
+  int stream;             // our stream identifier
+  double data[2];
+  char input;
+  RtAudio *audio;
+
+  // Open a stream during RtAudio instantiation
+  try {
+    audio = new RtAudio(&stream, device, channels, device, channels, RtAudio::RTAUDIO_FLOAT64,
+                        sample_rate, &buffer_size, n_buffers);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    // Set the stream callback function
+    audio->setStreamCallback(stream, &pass, NULL);
+
+    // Start the stream
+    audio->startStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+    goto cleanup;
+  }
+
+  cout << "\nRunning duplex ... press <enter> to quit.\n";
+  cin.get(input);
+
+  try {
+    // Stop and close the stream
+    audio->stopStream(stream);
+    audio->closeStream(stream);
+  }
+  catch (RtError &error) {
+    error.printMessage();
+  }
+
+ cleanup:
+  delete audio;
+
+  return 0;
+}
+\endcode
+
+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.
+
+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.
+
+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, unless a common external "sync" is provided.  This becomes even more difficult to achieve using two separate callback streams because it is not possible to <I>explicitly</I> control the calling order of the callback functions.
+
+
+\section methods Summary of Methods
+
+The following is short summary of public methods (not including constructors and the destructor) provided by RtAudio:
+
+<UL>
+<LI>RtAudio::openStream(): opens a stream with the specified parameters.</LI>
+<LI>RtAudio::setStreamCallback(): sets a user-defined callback function for a given stream.</LI>
+<LI>RtAudio::cancelStreamCallback(): cancels a callback process and function for a given stream.</LI>
+<LI>RtAudio::getDeviceCount(): returns the number of audio devices available.</LI>
+<LI>RtAudio::getDeviceInfo(): fills a user-supplied RTAUDIO_DEVICE structure for a specified device.</LI>
+<LI>RtAudio::getStreamBuffer(): returns a pointer to the stream buffer.</LI>
+<LI>RtAudio::tickStream(): triggers processing of input/output data for a stream (blocking).</LI>
+<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>
+<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>
+<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>
+<LI>RtAudio::abortStream(): stops the specified stream, discarding any remaining samples in the queue.  This does not implicitly call closeStream().</LI>
+<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>
+</UL>
+
+
+\section compiling Compiling
+
+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:
+<P>
+
+<TABLE BORDER=2 COLS=5 WIDTH="100%">
+<TR BGCOLOR="beige">
+  <TD WIDTH="5%"><B>OS:</B></TD>
+  <TD WIDTH="5%"><B>Audio API:</B></TD>
+  <TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>
+  <TD WIDTH="5%"><B>Library or Framework:</B></TD>
+  <TD><B>Example Compiler Statement:</B></TD>
+</TR>
+<TR>
+  <TD>Linux</TD>
+  <TD>ALSA</TD>
+  <TD>__LINUX_ALSA__</TD>
+  <TD><TT>asound, pthread</TT></TD>
+  <TD><TT>g++ -Wall -D__LINUX_ALSA__ -o probe probe.cpp RtAudio.cpp -lasound -lpthread</TT></TD>
+</TR>
+<TR>
+  <TD>Linux</TD>
+  <TD>OSS</TD>
+  <TD>__LINUX_OSS__</TD>
+  <TD><TT>pthread</TT></TD>
+  <TD><TT>g++ -Wall -D__LINUX_OSS__ -o probe probe.cpp RtAudio.cpp -lpthread</TT></TD>
+</TR>
+<TR>
+  <TD>Macintosh OS X</TD>
+  <TD>CoreAudio</TD>
+  <TD>__MACOSX_CORE__</TD>
+  <TD><TT>pthread, stdc++, CoreAudio</TT></TD>
+  <TD><TT>cc -Wall -D__MACOSX_CORE__ -o probe probe.cpp RtAudio.cpp -framework CoreAudio -lstdc++ -lpthread</TT></TD>
+</TR>
+<TR>
+  <TD>Irix</TD>
+  <TD>AL</TD>
+  <TD>__IRIX_AL__</TD>
+  <TD><TT>audio, pthread</TT></TD>
+  <TD><TT>CC -Wall -D__IRIX_AL__ -o probe probe.cpp RtAudio.cpp -laudio -lpthread</TT></TD>
+</TR>
+<TR>
+  <TD>Windows</TD>
+  <TD>Direct Sound</TD>
+  <TD>__WINDOWS_DS__</TD>
+  <TD><TT>dsound.lib (ver. 5.0 or higher), multithreaded</TT></TD>
+  <TD><I>compiler specific</I></TD>
+</TR>
+<TR>
+  <TD>Windows</TD>
+  <TD>ASIO</TD>
+  <TD>__WINDOWS_ASIO__</TD>
+  <TD><I>various ASIO header and source files</I></TD>
+  <TD><I>compiler specific</I></TD>
+</TR>
+</TABLE>
+<P>
+
+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.
+
+\section debug Debugging
+
+If you are having problems getting RtAudio to run on your system, try passing the preprocessor definition <TT>__RTAUDIO_DEBUG__</TT> to the compiler (or uncomment the definition at the bottom of RtAudio.h).  A variety of warning messages will be displayed which may help in determining the problem.
+
+\section osnotes OS Notes
+
+RtAudio is designed to provide a common API across the various supported operating systems and audio libraries.  Despite that, some issues need to be mentioned with regard to each.
+
+\subsection linux Linux:
+
+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, although relatively new, is now part of the Linux development kernel and 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 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.
+
+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.
+
+The ALSA implementation of RtAudio makes no use of the ALSA "plug" interface.  All necessary data format conversions, channel compensation, de-interleaving, and byte-swapping is handled by internal RtAudio routines.
+
+\subsection macosx Macintosh OS X (CoreAudio):
+
+The Apple CoreAudio API is based on a callback scheme.  RtAudio provides blocking functionality, in addition to callback functionality, within the context of that behavior.  CoreAudio is designed to use a separate callback procedure for each of its audio devices.  A single RtAudio duplex stream using two different devices is supported, though it cannot be guaranteed to always behave correctly because we cannot synchronize these two callbacks.  This same functionality can be achieved with better synchrony by opening two separate streams for the devices and using RtAudio blocking calls (i.e. RtAudio::tickStream()).  The <I>numberOfBuffers</I> parameter to the RtAudio::openStream() function has no affect in this implementation.  It is not currently possible to have multiple simultaneous RtAudio streams accessing the same device.
+
+\subsection irix Irix (SGI):
+
+The Irix version of RtAudio was written and tested on an SGI Indy running Irix version 6.5.4 and the newer "al" audio library.  RtAudio does not compile under Irix version 6.3, mainly 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.
+
+\subsection windowsds Windows (DirectSound):
+
+In order to compile RtAudio under Windows for the DirectSound API, you must have the header and source files for DirectSound version 5.0 or higher.  As far as I know, there is no DirectSoundCapture support for Windows NT.  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 crashes.  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.  Unfortunately, it appears they are continuing to undermine the C++ standard with more recent compiler releases.
+
+\subsection windowsasio Windows (ASIO):
+
+The Steinberg ASIO audio API is based on a callback scheme.  In addition, the API allows only a single device driver to be loaded and accessed at a time.  Therefore, it is not possible to have multiple simultaneous RtAudio streams running concurrently with this API.  ASIO device drivers must be supplied by audio hardware manufacturers, though ASIO emulation is possible on top of systems with DirectSound drivers.  The <I>numberOfBuffers</I> parameter to the RtAudio::openStream() function has no affect in this implementation.
+
+A number of ASIO source and header files are required for use with RtAudio.  Specifically, an RtAudio project must include the following files: <TT>asio.h,cpp; asiodrivers.h,cpp; asiolist.h,cpp; asiodrvr.h; asiosys.h; ginclude.h; iasiodrv.h</TT>.  See the <TT>/tests/asio/</TT> directory for example Visual C++ 6.0 projects.
+
+
+\section acknowledge Acknowledgements
+
+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.
+
+RtAudio, version 2.0, 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).
+
+\section license License
+
+    RtAudio: a realtime audio i/o C++ class<BR>
+    Copyright (c) 2001-2002 Gary P. Scavone
+
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation files
+    (the "Software"), to deal in the Software without restriction,
+    including without limitation the rights to use, copy, modify, merge,
+    publish, distribute, sublicense, and/or sell copies of the Software,
+    and to permit persons to whom the Software is furnished to do so,
+    subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    Any person wishing to distribute modifications to the Software is
+    requested to send the modifications to the original developer so that
+    they can be incorporated into the canonical version.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/doc/manual.pdf b/doc/manual.pdf
deleted file mode 100644 (file)
index c31d0eb..0000000
Binary files a/doc/manual.pdf and /dev/null differ
diff --git a/doc/release.txt b/doc/release.txt
new file mode 100644 (file)
index 0000000..d388256
--- /dev/null
@@ -0,0 +1,20 @@
+RtAudio - a C++ class which provides a common API for realtime audio input/output across Linux (native ALSA and OSS), SGI, Macintosh OS X (CoreAudio), and Windows (DirectSound and ASIO) operating systems.
+
+By Gary P. Scavone, 2002.
+
+v2.1: (7 October 2002)
+- added Mac OS X CoreAudio support
+- added Windows ASIO support
+- API change to getDeviceInfo(): device argument must be an integer between 1 - getDeviceCount().
+- "configure" support added for unix systems
+- adopted MIT-like license
+- various internal structural changes and bug fixes
+
+v2.01: (27 April 2002)
+- Windows destructor bug fix when no devices available
+- RtAudioError class renamed to RtError
+- Preprocessor definitions changed slightly (i.e. __LINUX_OSS_ to __LINUX_OSS__) to conform with new Synthesis ToolKit distribution
+
+v2.0: (22 January 2002)
+- first release of new independent class
+
diff --git a/install.sh b/install.sh
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/rtaudio.dsw b/rtaudio.dsw
deleted file mode 100644 (file)
index 2d6a46c..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00\r
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
-\r
-###############################################################################\r
-\r
-Project: "call_inout"=.\tests\call_inout.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "call_saw"=.\tests\call_saw.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "call_twostreams"=.\tests\call_twostreams.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "in_out"=.\tests\in_out.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "info"=.\tests\info.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "play_raw"=.\tests\play_raw.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "play_saw"=.\tests\play_saw.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "record_raw"=.\tests\record_raw.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Project: "twostreams"=.\tests\twostreams.dsp - Package Owner=<4>\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<4>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
-Global:\r
-\r
-Package=<5>\r
-{{{\r
-}}}\r
-\r
-Package=<3>\r
-{{{\r
-}}}\r
-\r
-###############################################################################\r
-\r
diff --git a/tests/DirectSound/Debug/.placeholder b/tests/DirectSound/Debug/.placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/DirectSound/Release/.placeholder b/tests/DirectSound/Release/.placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/DirectSound/call_inout.dsp b/tests/DirectSound/call_inout.dsp
new file mode 100755 (executable)
index 0000000..fdebf94
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="call_inout" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_inout - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_inout.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_inout.mak" CFG="call_inout - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_inout - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_inout - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_inout - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_inout - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_inout - Win32 Release"\r
+# Name "call_inout - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\call_inout.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/call_playtwo.dsp b/tests/DirectSound/call_playtwo.dsp
new file mode 100755 (executable)
index 0000000..1c9966b
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="call_playtwo" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_playtwo - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_playtwo.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_playtwo.mak" CFG="call_playtwo - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_playtwo - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_playtwo - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_playtwo - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_playtwo - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_playtwo - Win32 Release"\r
+# Name "call_playtwo - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\call_playtwo.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/call_saw.dsp b/tests/DirectSound/call_saw.dsp
new file mode 100755 (executable)
index 0000000..1e3b866
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="call_saw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_saw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_saw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_saw.mak" CFG="call_saw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_saw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_saw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_saw - Win32 Release"\r
+# Name "call_saw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\call_saw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/call_twostreams.dsp b/tests/DirectSound/call_twostreams.dsp
new file mode 100755 (executable)
index 0000000..16da2e5
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="call_twostreams" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_twostreams - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_twostreams.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_twostreams.mak" CFG="call_twostreams - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_twostreams - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_twostreams - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_twostreams - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_twostreams - Win32 Release"\r
+# Name "call_twostreams - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\call_twostreams.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/in_out.dsp b/tests/DirectSound/in_out.dsp
new file mode 100755 (executable)
index 0000000..f8585e6
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="in_out" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=in_out - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "in_out.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "in_out.mak" CFG="in_out - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "in_out - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "in_out - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "in_out - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "in_out - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "in_out - Win32 Release"\r
+# Name "in_out - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\in_out.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/info.dsp b/tests/DirectSound/info.dsp
new file mode 100755 (executable)
index 0000000..3bf97c6
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="info" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=info - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "info.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "info.mak" CFG="info - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "info - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "info - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "info - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "info - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "info - Win32 Release"\r
+# Name "info - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\info.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/play_raw.dsp b/tests/DirectSound/play_raw.dsp
new file mode 100755 (executable)
index 0000000..7915897
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="play_raw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=play_raw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_raw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_raw.mak" CFG="play_raw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "play_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "play_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "play_raw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "play_raw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "play_raw - Win32 Release"\r
+# Name "play_raw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\play_raw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/play_saw.dsp b/tests/DirectSound/play_saw.dsp
new file mode 100755 (executable)
index 0000000..bbe59b4
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="play_saw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=play_saw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_saw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_saw.mak" CFG="play_saw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "play_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "play_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "play_saw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "play_saw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "play_saw - Win32 Release"\r
+# Name "play_saw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\play_saw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/record_raw.dsp b/tests/DirectSound/record_raw.dsp
new file mode 100755 (executable)
index 0000000..18e66bc
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="record_raw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=record_raw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "record_raw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "record_raw.mak" CFG="record_raw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "record_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "record_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "record_raw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "record_raw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "record_raw - Win32 Release"\r
+# Name "record_raw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\record_raw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/DirectSound/rtaudio.dsw b/tests/DirectSound/rtaudio.dsw
new file mode 100755 (executable)
index 0000000..f276a43
--- /dev/null
@@ -0,0 +1,137 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00\r
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
+\r
+###############################################################################\r
+\r
+Project: "call_inout"=.\call_inout.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "call_playtwo"=.\call_playtwo.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "call_saw"=.\call_saw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "call_twostreams"=.\call_twostreams.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "in_out"=.\in_out.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "info"=.\info.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "play_raw"=.\play_raw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "play_saw"=.\play_saw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "record_raw"=.\record_raw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "twostreams"=.\twostreams.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Global:\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<3>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
diff --git a/tests/DirectSound/twostreams.dsp b/tests/DirectSound/twostreams.dsp
new file mode 100755 (executable)
index 0000000..54c9bc6
--- /dev/null
@@ -0,0 +1,110 @@
+# Microsoft Developer Studio Project File - Name="twostreams" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=twostreams - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "twostreams.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "twostreams.mak" CFG="twostreams - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "twostreams - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "twostreams - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "twostreams - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "twostreams - Win32 Release"\r
+# Name "twostreams - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=..\twostreams.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/Makefile b/tests/Makefile
deleted file mode 100644 (file)
index b6e1e90..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-
-OS = $(shell uname)
-
-RM = /bin/rm
-
-ifeq ($(OS),Linux) # These are for Linux
-       INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams
-       CC = g++ -Wall -D__LINUX_OSS__# -g -pg -O3
-       LIBRARY = -lpthread
-#      CC = g++ -g -Wall -D__LINUX_ALSA__ # -g -pg -O3
-#      LIBRARY = -lpthread -lasound
-       INCLUDE = -I../
-endif
-
-ifeq ($(OS),IRIX) # These are for SGI
-       INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams
-       CC = CC -D__IRIX_AL__ # -g -fullwarn -D__SGI_CC__ -O2
-       LIBRARY = -laudio -lpthread
-       INCLUDE = -I../
-endif
-
-all: $(INSTR)
-
-clean :
-       rm $(INSTR) *~ *.raw core *.o 
-
-cleanIns : 
-       rm $(INSTR)
-
-strip : 
-       strip $(INSTR)
-
-info: info.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o info info.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-play_saw: play_saw.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o play_saw play_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-play_raw: play_raw.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o play_raw play_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-record_raw: record_raw.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o record_raw record_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-in_out: in_out.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o in_out in_out.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-twostreams: twostreams.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o twostreams twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-call_saw: call_saw.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o call_saw call_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-call_inout: call_inout.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o call_inout call_inout.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
-
-call_twostreams: call_twostreams.cpp ../RtAudio.cpp ../RtAudio.h
-       $(CC) -o call_twostreams call_twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
\ No newline at end of file
diff --git a/tests/Makefile.in b/tests/Makefile.in
new file mode 100644 (file)
index 0000000..3bacb8c
--- /dev/null
@@ -0,0 +1,61 @@
+### RtAudio tests Makefile - for various flavors of unix
+
+PROGRAMS = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams call_playtwo
+RM = /bin/rm
+SRC_PATH = ../
+INCLUDE = ../
+OBJECT_PATH = @object_path@
+vpath %.o $(OBJECT_PATH)
+
+OBJECTS        =       RtAudio.o
+
+CC       = @CXX@
+DEFS     = @debug@
+DEFS    += @sound_api@
+CFLAGS   = @cflags@
+CFLAGS  += @warn@ -I$(INCLUDE)
+LIBRARY  = @LIBS@
+LIBRARY += @frameworks@
+
+%.o : $(SRC_PATH)/%.cpp
+       $(CC) $(CFLAGS) $(DEFS) -c $(<) -o $(OBJECT_PATH)/$@
+
+all : $(PROGRAMS)
+
+info : info.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o info info.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+play_saw : play_saw.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o play_saw play_saw.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+play_raw : play_raw.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o play_raw play_raw.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+record_raw : record_raw.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o record_raw record_raw.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+in_out : in_out.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o in_out in_out.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+twostreams : twostreams.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o twostreams twostreams.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+call_saw : call_saw.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o call_saw call_saw.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+call_inout : call_inout.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o call_inout call_inout.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+call_twostreams : call_twostreams.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o call_twostreams call_twostreams.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+call_playtwo : call_playtwo.cpp $(OBJECTS)
+       $(CC) $(CFLAGS) $(DEFS) -o call_playtwo call_playtwo.cpp $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+
+clean : 
+       -rm $(OBJECT_PATH)/*.o
+       -rm $(PROGRAMS)
+       -rm -f *~
+
+strip : 
+       strip $(PROGRAMS)
diff --git a/tests/asio/Debug/.placeholder b/tests/asio/Debug/.placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/asio/Release/.placeholder b/tests/asio/Release/.placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/asio/asio.cpp b/tests/asio/asio.cpp
new file mode 100644 (file)
index 0000000..b241663
--- /dev/null
@@ -0,0 +1,257 @@
+/*\r
+       Steinberg Audio Stream I/O API\r
+       (c) 1996, Steinberg Soft- und Hardware GmbH\r
+\r
+       asio.cpp\r
+       \r
+       asio functions entries which translate the\r
+       asio interface to the asiodrvr class methods\r
+*/ \r
+       \r
+#include <string.h>\r
+#include "asiosys.h"           // platform definition\r
+#include "asio.h"\r
+\r
+#if MAC\r
+#include "asiodrvr.h"\r
+\r
+#pragma export on\r
+\r
+AsioDriver *theAsioDriver = 0;\r
+\r
+extern "C"\r
+{\r
+\r
+long main()\r
+{\r
+       return 'ASIO';\r
+}\r
+\r
+#elif WINDOWS\r
+\r
+#include "windows.h"\r
+#include "iasiodrv.h"\r
+#include "asiodrivers.h"\r
+\r
+IASIO *theAsioDriver = 0;\r
+extern AsioDrivers *asioDrivers;\r
+\r
+#elif SGI || SUN || BEOS || LINUX\r
+#include "asiodrvr.h"\r
+static AsioDriver *theAsioDriver = 0;\r
+#endif\r
+\r
+//-----------------------------------------------------------------------------------------------------\r
+ASIOError ASIOInit(ASIODriverInfo *info)\r
+{\r
+#if MAC || SGI || SUN || BEOS || LINUX\r
+       if(theAsioDriver)\r
+       {\r
+               delete theAsioDriver;\r
+               theAsioDriver = 0;\r
+       }               \r
+       info->driverVersion = 0;\r
+       strcpy(info->name, "No ASIO Driver");\r
+       theAsioDriver = getDriver();\r
+       if(!theAsioDriver)\r
+       {\r
+               strcpy(info->errorMessage, "Not enough memory for the ASIO driver!"); \r
+               return ASE_NotPresent;\r
+       }\r
+       if(!theAsioDriver->init(info->sysRef))\r
+       {\r
+               theAsioDriver->getErrorMessage(info->errorMessage);\r
+               delete theAsioDriver;\r
+               theAsioDriver = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       strcpy(info->errorMessage, "No ASIO Driver Error");\r
+       theAsioDriver->getDriverName(info->name);\r
+       info->driverVersion = theAsioDriver->getDriverVersion();\r
+       return ASE_OK;\r
+\r
+#else\r
+\r
+       info->driverVersion = 0;\r
+       strcpy(info->name, "No ASIO Driver");\r
+       if(theAsioDriver)       // must be loaded!\r
+       {\r
+               if(!theAsioDriver->init(info->sysRef))\r
+               {\r
+                       theAsioDriver->getErrorMessage(info->errorMessage);\r
+                       theAsioDriver = 0;\r
+                       return ASE_NotPresent;\r
+               }               \r
+\r
+               strcpy(info->errorMessage, "No ASIO Driver Error");\r
+               theAsioDriver->getDriverName(info->name);\r
+               info->driverVersion = theAsioDriver->getDriverVersion();\r
+               return ASE_OK;\r
+       }\r
+       return ASE_NotPresent;\r
+\r
+#endif // !MAC\r
+}\r
+\r
+ASIOError ASIOExit(void)\r
+{\r
+       if(theAsioDriver)\r
+       {\r
+#if WINDOWS\r
+               asioDrivers->removeCurrentDriver();\r
+#else\r
+               delete theAsioDriver;\r
+#endif\r
+       }               \r
+       theAsioDriver = 0;\r
+       return ASE_OK;\r
+}\r
+\r
+ASIOError ASIOStart(void)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->start();\r
+}\r
+\r
+ASIOError ASIOStop(void)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->stop();\r
+}\r
+\r
+ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               *numInputChannels = *numOutputChannels = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->getChannels(numInputChannels, numOutputChannels);\r
+}\r
+\r
+ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               *inputLatency = *outputLatency = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->getLatencies(inputLatency, outputLatency);\r
+}\r
+\r
+ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               *minSize = *maxSize = *preferredSize = *granularity = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->getBufferSize(minSize, maxSize, preferredSize, granularity);\r
+}\r
+\r
+ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->canSampleRate(sampleRate);\r
+}\r
+\r
+ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->getSampleRate(currentRate);\r
+}\r
+\r
+ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->setSampleRate(sampleRate);\r
+}\r
+\r
+ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               *numSources = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->getClockSources(clocks, numSources);\r
+}\r
+\r
+ASIOError ASIOSetClockSource(long reference)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->setClockSource(reference);\r
+}\r
+\r
+ASIOError ASIOGetSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->getSamplePosition(sPos, tStamp);\r
+}\r
+\r
+ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               info->channelGroup = -1;\r
+               info->type = ASIOSTInt16MSB;\r
+               strcpy(info->name, "None");\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->getChannelInfo(info);\r
+}\r
+\r
+ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,\r
+       long bufferSize, ASIOCallbacks *callbacks)\r
+{\r
+       if(!theAsioDriver)\r
+       {\r
+               ASIOBufferInfo *info = bufferInfos;\r
+               for(long i = 0; i < numChannels; i++, info++)\r
+                       info->buffers[0] = info->buffers[1] = 0;\r
+               return ASE_NotPresent;\r
+       }\r
+       return theAsioDriver->createBuffers(bufferInfos, numChannels, bufferSize, callbacks);\r
+}\r
+\r
+ASIOError ASIODisposeBuffers(void)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->disposeBuffers();\r
+}\r
+\r
+ASIOError ASIOControlPanel(void)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->controlPanel();\r
+}\r
+\r
+ASIOError ASIOFuture(long selector, void *opt)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->future(selector, opt);\r
+}\r
+\r
+ASIOError ASIOOutputReady(void)\r
+{\r
+       if(!theAsioDriver)\r
+               return ASE_NotPresent;\r
+       return theAsioDriver->outputReady();\r
+}\r
+\r
+#if MAC\r
+}      // extern "C"\r
+#pragma export off\r
+#endif\r
+\r
+\r
diff --git a/tests/asio/asio.h b/tests/asio/asio.h
new file mode 100644 (file)
index 0000000..3003130
--- /dev/null
@@ -0,0 +1,955 @@
+//---------------------------------------------------------------------------------------------------\r
+//---------------------------------------------------------------------------------------------------\r
+\r
+/*\r
+       Steinberg Audio Stream I/O API\r
+       (c) 1997 - 1999, Steinberg Soft- und Hardware GmbH\r
+\r
+       ASIO Interface Specification v 2.0\r
+\r
+       basic concept is an i/o synchronous double-buffer scheme:\r
+       \r
+       on bufferSwitch(index == 0), host will read/write:\r
+\r
+               after ASIOStart(), the\r
+  read  first input buffer A (index 0)\r
+       |   will be invalid (empty)\r
+       *   ------------------------\r
+       |------------------------|-----------------------|\r
+       |                        |                       |\r
+       |  Input Buffer A (0)    |   Input Buffer B (1)  |\r
+       |                        |                       |\r
+       |------------------------|-----------------------|\r
+       |                        |                       |\r
+       |  Output Buffer A (0)   |   Output Buffer B (1) |\r
+       |                        |                       |\r
+       |------------------------|-----------------------|\r
+       *                        -------------------------\r
+       |                        before calling ASIOStart(),\r
+  write                      host will have filled output\r
+                             buffer B (index 1) already\r
+\r
+  *please* take special care of proper statement of input\r
+  and output latencies (see ASIOGetLatencies()), these\r
+  control sequencer sync accuracy\r
+\r
+*/\r
+\r
+//---------------------------------------------------------------------------------------------------\r
+//---------------------------------------------------------------------------------------------------\r
+\r
+/*\r
+\r
+prototypes summary:\r
+\r
+ASIOError ASIOInit(ASIODriverInfo *info);\r
+ASIOError ASIOExit(void);\r
+ASIOError ASIOStart(void);\r
+ASIOError ASIOStop(void);\r
+ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);\r
+ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);\r
+ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);\r
+ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);\r
+ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);\r
+ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);\r
+ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);\r
+ASIOError ASIOSetClockSource(long reference);\r
+ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);\r
+ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);\r
+ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,\r
+       long bufferSize, ASIOCallbacks *callbacks);\r
+ASIOError ASIODisposeBuffers(void);\r
+ASIOError ASIOControlPanel(void);\r
+void *ASIOFuture(long selector, void *params);\r
+ASIOError ASIOOutputReady(void);\r
+\r
+*/\r
+\r
+//---------------------------------------------------------------------------------------------------\r
+//---------------------------------------------------------------------------------------------------\r
+\r
+#ifndef __ASIO_H\r
+#define __ASIO_H\r
+\r
+// force 4 byte alignment\r
+#if defined(_MSC_VER) && !defined(__MWERKS__) \r
+#pragma pack(push,4)\r
+#elif PRAGMA_ALIGN_SUPPORTED\r
+#pragma options align = native\r
+#endif\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Type definitions\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+// number of samples data type is 64 bit integer\r
+#if NATIVE_INT64\r
+       typedef long long int ASIOSamples;\r
+#else\r
+       typedef struct ASIOSamples {\r
+               unsigned long hi;\r
+               unsigned long lo;\r
+       } ASIOSamples;\r
+#endif\r
+\r
+// Timestamp data type is 64 bit integer,\r
+// Time format is Nanoseconds.\r
+#if NATIVE_INT64\r
+       typedef long long int ASIOTimeStamp ;\r
+#else\r
+       typedef struct ASIOTimeStamp {\r
+               unsigned long hi;\r
+               unsigned long lo;\r
+       } ASIOTimeStamp;\r
+#endif\r
+\r
+// Samplerates are expressed in IEEE 754 64 bit double float,\r
+// native format as host computer\r
+#if IEEE754_64FLOAT\r
+       typedef double ASIOSampleRate;\r
+#else\r
+       typedef struct ASIOSampleRate {\r
+               char ieee[8];\r
+       } ASIOSampleRate;\r
+#endif\r
+\r
+// Boolean values are expressed as long\r
+typedef long ASIOBool;\r
+enum {\r
+       ASIOFalse = 0,\r
+       ASIOTrue = 1\r
+};\r
+\r
+// Sample Types are expressed as long\r
+typedef long ASIOSampleType;\r
+enum {\r
+       ASIOSTInt16MSB   = 0,\r
+       ASIOSTInt24MSB   = 1,           // used for 20 bits as well\r
+       ASIOSTInt32MSB   = 2,\r
+       ASIOSTFloat32MSB = 3,           // IEEE 754 32 bit float\r
+       ASIOSTFloat64MSB = 4,           // IEEE 754 64 bit double float\r
+\r
+       // these are used for 32 bit data buffer, with different alignment of the data inside\r
+       // 32 bit PCI bus systems can be more easily used with these\r
+       ASIOSTInt32MSB16 = 8,           // 32 bit data with 18 bit alignment\r
+       ASIOSTInt32MSB18 = 9,           // 32 bit data with 18 bit alignment\r
+       ASIOSTInt32MSB20 = 10,          // 32 bit data with 20 bit alignment\r
+       ASIOSTInt32MSB24 = 11,          // 32 bit data with 24 bit alignment\r
+       \r
+       ASIOSTInt16LSB   = 16,\r
+       ASIOSTInt24LSB   = 17,          // used for 20 bits as well\r
+       ASIOSTInt32LSB   = 18,\r
+       ASIOSTFloat32LSB = 19,          // IEEE 754 32 bit float, as found on Intel x86 architecture\r
+       ASIOSTFloat64LSB = 20,          // IEEE 754 64 bit double float, as found on Intel x86 architecture\r
+\r
+       // these are used for 32 bit data buffer, with different alignment of the data inside\r
+       // 32 bit PCI bus systems can more easily used with these\r
+       ASIOSTInt32LSB16 = 24,          // 32 bit data with 18 bit alignment\r
+       ASIOSTInt32LSB18 = 25,          // 32 bit data with 18 bit alignment\r
+       ASIOSTInt32LSB20 = 26,          // 32 bit data with 20 bit alignment\r
+       ASIOSTInt32LSB24 = 27           // 32 bit data with 24 bit alignment\r
+};\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Error codes\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+typedef long ASIOError;\r
+enum {\r
+       ASE_OK = 0,             // This value will be returned whenever the call succeeded\r
+       ASE_SUCCESS = 0x3f4847a0,       // unique success return value for ASIOFuture calls\r
+       ASE_NotPresent = -1000, // hardware input or output is not present or available\r
+       ASE_HWMalfunction,      // hardware is malfunctioning (can be returned by any ASIO function)\r
+       ASE_InvalidParameter,   // input parameter invalid\r
+       ASE_InvalidMode,        // hardware is in a bad mode or used in a bad mode\r
+       ASE_SPNotAdvancing,     // hardware is not running when sample position is inquired\r
+       ASE_NoClock,            // sample clock or rate cannot be determined or is not present\r
+       ASE_NoMemory            // not enough memory for completing the request\r
+};\r
+\r
+//---------------------------------------------------------------------------------------------------\r
+//---------------------------------------------------------------------------------------------------\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Time Info support\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+typedef struct ASIOTimeCode\r
+{       \r
+       double          speed;                  // speed relation (fraction of nominal speed)\r
+                                               // optional; set to 0. or 1. if not supported\r
+       ASIOSamples     timeCodeSamples;        // time in samples\r
+       unsigned long   flags;                  // some information flags (see below)\r
+       char future[64];\r
+} ASIOTimeCode;\r
+\r
+typedef enum ASIOTimeCodeFlags\r
+{\r
+       kTcValid                = 1,\r
+       kTcRunning              = 1 << 1,\r
+       kTcReverse              = 1 << 2,\r
+       kTcOnspeed              = 1 << 3,\r
+       kTcStill                = 1 << 4,\r
+       \r
+       kTcSpeedValid           = 1 << 8\r
+}  ASIOTimeCodeFlags;\r
+\r
+typedef struct AsioTimeInfo\r
+{\r
+       double          speed;                  // absolute speed (1. = nominal)\r
+       ASIOTimeStamp   systemTime;             // system time related to samplePosition, in nanoseconds\r
+                                               // on mac, must be derived from Microseconds() (not UpTime()!)\r
+                                               // on windows, must be derived from timeGetTime()\r
+       ASIOSamples     samplePosition;\r
+       ASIOSampleRate  sampleRate;             // current rate\r
+       unsigned long flags;                    // (see below)\r
+       char reserved[12];\r
+} AsioTimeInfo;\r
+\r
+typedef enum AsioTimeInfoFlags\r
+{\r
+       kSystemTimeValid        = 1,            // must always be valid\r
+       kSamplePositionValid    = 1 << 1,       // must always be valid\r
+       kSampleRateValid        = 1 << 2,\r
+       kSpeedValid             = 1 << 3,\r
+       \r
+       kSampleRateChanged      = 1 << 4,\r
+       kClockSourceChanged     = 1 << 5\r
+} AsioTimeInfoFlags;\r
+\r
+typedef struct ASIOTime                          // both input/output\r
+{\r
+       long reserved[4];                       // must be 0\r
+       struct AsioTimeInfo     timeInfo;       // required\r
+       struct ASIOTimeCode     timeCode;       // optional, evaluated if (timeCode.flags & kTcValid)\r
+} ASIOTime;\r
+\r
+/*\r
+\r
+using time info:\r
+it is recommended to use the new method with time info even if the asio\r
+device does not support timecode; continuous calls to ASIOGetSamplePosition\r
+and ASIOGetSampleRate are avoided, and there is a more defined relationship\r
+between callback time and the time info.\r
+\r
+see the example below.\r
+to initiate time info mode, after you have received the callbacks pointer in\r
+ASIOCreateBuffers, you will call the asioMessage callback with kAsioSupportsTimeInfo\r
+as the argument. if this returns 1, host has accepted time info mode.\r
+now host expects the new callback bufferSwitchTimeInfo to be used instead\r
+of the old bufferSwitch method. the ASIOTime structure is assumed to be valid\r
+and accessible until the callback returns.\r
+\r
+using time code:\r
+if the device supports reading time code, it will call host's asioMessage callback\r
+with kAsioSupportsTimeCode as the selector. it may then fill the according\r
+fields and set the kTcValid flag.\r
+host will call the future method with the kAsioEnableTimeCodeRead selector when\r
+it wants to enable or disable tc reading by the device. you should also support\r
+the kAsioCanTimeInfo and kAsioCanTimeCode selectors in ASIOFuture (see example).\r
+\r
+note:\r
+the AsioTimeInfo/ASIOTimeCode pair is supposed to work in both directions.\r
+as a matter of convention, the relationship between the sample\r
+position counter and the time code at buffer switch time is\r
+(ignoring offset between tc and sample pos when tc is running):\r
+\r
+on input:      sample 0 -> input  buffer sample 0 -> time code 0\r
+on output:     sample 0 -> output buffer sample 0 -> time code 0\r
+\r
+this means that for 'real' calculations, one has to take into account\r
+the according latencies.\r
+\r
+example:\r
+\r
+ASIOTime asioTime;\r
+\r
+in createBuffers()\r
+{\r
+       memset(&asioTime, 0, sizeof(ASIOTime));\r
+       AsioTimeInfo* ti = &asioTime.timeInfo;\r
+       ti->sampleRate = theSampleRate;\r
+       ASIOTimeCode* tc = &asioTime.timeCode;\r
+       tc->speed = 1.;\r
+       timeInfoMode = false;\r
+       canTimeCode = false;\r
+       if(callbacks->asioMessage(kAsioSupportsTimeInfo, 0, 0, 0) == 1)\r
+       {\r
+               timeInfoMode = true;\r
+#if kCanTimeCode\r
+               if(callbacks->asioMessage(kAsioSupportsTimeCode, 0, 0, 0) == 1)\r
+                       canTimeCode = true;\r
+#endif\r
+       }\r
+}\r
+\r
+void switchBuffers(long doubleBufferIndex, bool processNow)\r
+{\r
+       if(timeInfoMode)\r
+       {\r
+               AsioTimeInfo* ti = &asioTime.timeInfo;\r
+               ti->flags =     kSystemTimeValid | kSamplePositionValid | kSampleRateValid;\r
+               ti->systemTime = theNanoSeconds;\r
+               ti->samplePosition = theSamplePosition;\r
+               if(ti->sampleRate != theSampleRate)\r
+                       ti->flags |= kSampleRateChanged;\r
+               ti->sampleRate = theSampleRate;\r
+\r
+#if kCanTimeCode\r
+               if(canTimeCode && timeCodeEnabled)\r
+               {\r
+                       ASIOTimeCode* tc = &asioTime.timeCode;\r
+                       tc->timeCodeSamples = tcSamples;                                                // tc in samples\r
+                       tc->flags = kTcValid | kTcRunning | kTcOnspeed;                 // if so...\r
+               }\r
+               ASIOTime* bb = callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);\r
+#else\r
+               callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);\r
+#endif\r
+       }\r
+       else\r
+               callbacks->bufferSwitch(doubleBufferIndex, ASIOFalse);\r
+}\r
+\r
+ASIOError ASIOFuture(long selector, void *params)\r
+{\r
+       switch(selector)\r
+       {\r
+               case kAsioEnableTimeCodeRead:\r
+                       timeCodeEnabled = true;\r
+                       return ASE_SUCCESS;\r
+               case kAsioDisableTimeCodeRead:\r
+                       timeCodeEnabled = false;\r
+                       return ASE_SUCCESS;\r
+               case kAsioCanTimeInfo:\r
+                       return ASE_SUCCESS;\r
+               #if kCanTimeCode\r
+               case kAsioCanTimeCode:\r
+                       return ASE_SUCCESS;\r
+               #endif\r
+       }\r
+       return ASE_NotPresent;\r
+};\r
+\r
+*/\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// application's audio stream handler callbacks\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+typedef struct ASIOCallbacks\r
+{\r
+       void (*bufferSwitch) (long doubleBufferIndex, ASIOBool directProcess);\r
+               // bufferSwitch indicates that both input and output are to be processed.\r
+               // the current buffer half index (0 for A, 1 for B) determines\r
+               // - the output buffer that the host should start to fill. the other buffer\r
+               //   will be passed to output hardware regardless of whether it got filled\r
+               //   in time or not.\r
+               // - the input buffer that is now filled with incoming data. Note that\r
+               //   because of the synchronicity of i/o, the input always has at\r
+               //   least one buffer latency in relation to the output.\r
+               // directProcess suggests to the host whether it should immedeately\r
+               // start processing (directProcess == ASIOTrue), or whether its process\r
+               // should be deferred because the call comes from a very low level\r
+               // (for instance, a high level priority interrupt), and direct processing\r
+               // would cause timing instabilities for the rest of the system. If in doubt,\r
+               // directProcess should be set to ASIOFalse.\r
+               // Note: bufferSwitch may be called at interrupt time for highest efficiency.\r
+\r
+       void (*sampleRateDidChange) (ASIOSampleRate sRate);\r
+               // gets called when the AudioStreamIO detects a sample rate change\r
+               // If sample rate is unknown, 0 is passed (for instance, clock loss\r
+               // when externally synchronized).\r
+\r
+       long (*asioMessage) (long selector, long value, void* message, double* opt);\r
+               // generic callback for various purposes, see selectors below.\r
+               // note this is only present if the asio version is 2 or higher\r
+\r
+       ASIOTime* (*bufferSwitchTimeInfo) (ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess);\r
+               // new callback with time info. makes ASIOGetSamplePosition() and various\r
+               // calls to ASIOGetSampleRate obsolete,\r
+               // and allows for timecode sync etc. to be preferred; will be used if\r
+               // the driver calls asioMessage with selector kAsioSupportsTimeInfo.\r
+} ASIOCallbacks;\r
+\r
+// asioMessage selectors\r
+enum\r
+{\r
+       kAsioSelectorSupported = 1,     // selector in <value>, returns 1L if supported,\r
+                                                               // 0 otherwise\r
+    kAsioEngineVersion,                        // returns engine (host) asio implementation version,\r
+                                                               // 2 or higher\r
+       kAsioResetRequest,                      // request driver reset. if accepted, this\r
+                                                               // will close the driver (ASIO_Exit() ) and\r
+                                                               // re-open it again (ASIO_Init() etc). some\r
+                                                               // drivers need to reconfigure for instance\r
+                                                               // when the sample rate changes, or some basic\r
+                                                               // changes have been made in ASIO_ControlPanel().\r
+                                                               // returns 1L; note the request is merely passed\r
+                                                               // to the application, there is no way to determine\r
+                                                               // if it gets accepted at this time (but it usually\r
+                                                               // will be).\r
+       kAsioBufferSizeChange,          // not yet supported, will currently always return 0L.\r
+                                                               // for now, use kAsioResetRequest instead.\r
+                                                               // once implemented, the new buffer size is expected\r
+                                                               // in <value>, and on success returns 1L\r
+       kAsioResyncRequest,                     // the driver went out of sync, such that\r
+                                                               // the timestamp is no longer valid. this\r
+                                                               // is a request to re-start the engine and\r
+                                                               // slave devices (sequencer). returns 1 for ok,\r
+                                                               // 0 if not supported.\r
+       kAsioLatenciesChanged,          // the drivers latencies have changed. The engine\r
+                                                               // will refetch the latencies.\r
+       kAsioSupportsTimeInfo,          // if host returns true here, it will expect the\r
+                                                               // callback bufferSwitchTimeInfo to be called instead\r
+                                                               // of bufferSwitch\r
+       kAsioSupportsTimeCode,          // supports time code reading/writing\r
+\r
+       kAsioSupportsInputMonitor,      // supports input monitoring\r
+\r
+       kAsioNumMessageSelectors\r
+};\r
+\r
+//---------------------------------------------------------------------------------------------------\r
+//---------------------------------------------------------------------------------------------------\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// (De-)Construction\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+typedef struct ASIODriverInfo\r
+{\r
+       long asioVersion;               // currently, 2\r
+       long driverVersion;             // driver specific\r
+       char name[32];\r
+       char errorMessage[124];\r
+       void *sysRef;                   // on input: system reference\r
+                                                       // (Windows: application main window handle, Mac & SGI: 0)\r
+} ASIODriverInfo;\r
+\r
+ASIOError ASIOInit(ASIODriverInfo *info);\r
+/* Purpose:\r
+         Initialize the AudioStreamIO.\r
+       Parameter:\r
+         info: pointer to an ASIODriver structure:\r
+           - asioVersion:\r
+                       - on input, the host version. *** Note *** this is 0 for earlier asio\r
+                       implementations, and the asioMessage callback is implemeted\r
+                       only if asioVersion is 2 or greater. sorry but due to a design fault\r
+                       the driver doesn't have access to the host version in ASIOInit :-(\r
+                       added selector for host (engine) version in the asioMessage callback\r
+                       so we're ok from now on.\r
+                       - on return, asio implementation version.\r
+                         older versions are 1\r
+                         if you support this version (namely, ASIO_outputReady() )\r
+                         this should be 2 or higher. also see the note in\r
+                         ASIO_getTimeStamp() !\r
+           - version: on return, the driver version (format is driver specific)\r
+           - name: on return, a null-terminated string containing the driver's name\r
+               - error message: on return, should contain a user message describing\r
+                 the type of error that occured during ASIOInit(), if any.\r
+               - sysRef: platform specific\r
+       Returns:\r
+         If neither input nor output is present ASE_NotPresent\r
+         will be returned.\r
+         ASE_NoMemory, ASE_HWMalfunction are other possible error conditions\r
+*/\r
+\r
+ASIOError ASIOExit(void);\r
+/* Purpose:\r
+         Terminates the AudioStreamIO.\r
+       Parameter:\r
+         None.\r
+       Returns:\r
+         If neither input nor output is present ASE_NotPresent\r
+         will be returned.\r
+       Notes: this implies ASIOStop() and ASIODisposeBuffers(),\r
+         meaning that no host callbacks must be accessed after ASIOExit().\r
+*/\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Start/Stop\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+ASIOError ASIOStart(void);\r
+/* Purpose:\r
+         Start input and output processing synchronously.\r
+         This will\r
+         - reset the sample counter to zero\r
+         - start the hardware (both input and output)\r
+           The first call to the hosts' bufferSwitch(index == 0) then tells\r
+           the host to read from input buffer A (index 0), and start\r
+           processing to output buffer A while output buffer B (which\r
+           has been filled by the host prior to calling ASIOStart())\r
+           is possibly sounding (see also ASIOGetLatencies()) \r
+       Parameter:\r
+         None.\r
+       Returns:\r
+         If neither input nor output is present, ASE_NotPresent\r
+         will be returned.\r
+         If the hardware fails to start, ASE_HWMalfunction will be returned.\r
+       Notes:\r
+         There is no restriction on the time that ASIOStart() takes\r
+         to perform (that is, it is not considered a realtime trigger).\r
+*/\r
+\r
+ASIOError ASIOStop(void);\r
+/* Purpose:\r
+         Stops input and output processing altogether.\r
+       Parameter:\r
+         None.\r
+       Returns:\r
+         If neither input nor output is present ASE_NotPresent\r
+         will be returned.\r
+       Notes:\r
+         On return from ASIOStop(), the driver must in no\r
+         case call the hosts' bufferSwitch() routine.\r
+*/\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Inquiry methods and sample rate\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);\r
+/* Purpose:\r
+         Returns number of individual input/output channels.\r
+       Parameter:\r
+         numInputChannels will hold the number of available input channels\r
+         numOutputChannels will hold the number of available output channels\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+         If only inputs, or only outputs are available, the according\r
+         other parameter will be zero, and ASE_OK is returned.\r
+*/\r
+\r
+ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);\r
+/* Purpose:\r
+         Returns the input and output latencies. This includes\r
+         device specific delays, like FIFOs etc.\r
+       Parameter:\r
+         inputLatency will hold the 'age' of the first sample frame\r
+         in the input buffer when the hosts reads it in bufferSwitch()\r
+         (this is theoretical, meaning it does not include the overhead\r
+         and delay between the actual physical switch, and the time\r
+         when bufferSitch() enters).\r
+         This will usually be the size of one block in sample frames, plus\r
+         device specific latencies.\r
+\r
+         outputLatency will specify the time between the buffer switch,\r
+         and the time when the next play buffer will start to sound.\r
+         The next play buffer is defined as the one the host starts\r
+         processing after (or at) bufferSwitch(), indicated by the\r
+         index parameter (0 for buffer A, 1 for buffer B).\r
+         It will usually be either one block, if the host writes directly\r
+         to a dma buffer, or two or more blocks if the buffer is 'latched' by\r
+         the driver. As an example, on ASIOStart(), the host will have filled\r
+         the play buffer at index 1 already; when it gets the callback (with\r
+         the parameter index == 0), this tells it to read from the input\r
+         buffer 0, and start to fill the play buffer 0 (assuming that now\r
+         play buffer 1 is already sounding). In this case, the output\r
+         latency is one block. If the driver decides to copy buffer 1\r
+         at that time, and pass it to the hardware at the next slot (which\r
+         is most commonly done, but should be avoided), the output latency\r
+         becomes two blocks instead, resulting in a total i/o latency of at least\r
+         3 blocks. As memory access is the main bottleneck in native dsp processing,\r
+         and to acheive less latency, it is highly recommended to try to avoid\r
+         copying (this is also why the driver is the owner of the buffers). To\r
+         summarize, the minimum i/o latency can be acheived if the input buffer\r
+         is processed by the host into the output buffer which will physically\r
+         start to sound on the next time slice. Also note that the host expects\r
+         the bufferSwitch() callback to be accessed for each time slice in order\r
+         to retain sync, possibly recursively; if it fails to process a block in\r
+         time, it will suspend its operation for some time in order to recover.\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+*/\r
+\r
+ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);\r
+/* Purpose:\r
+         Returns min, max, and preferred buffer sizes for input/output\r
+       Parameter:\r
+         minSize will hold the minimum buffer size\r
+         maxSize will hold the maxium possible buffer size\r
+         preferredSize will hold the preferred buffer size (a size which\r
+         best fits performance and hardware requirements)\r
+         granularity will hold the granularity at which buffer sizes\r
+         may differ. Usually, the buffer size will be a power of 2;\r
+         in this case, granularity will hold -1 on return, signalling\r
+         possible buffer sizes starting from minSize, increased in\r
+         powers of 2 up to maxSize.\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+         When minimum and maximum buffer size are equal,\r
+         the preferred buffer size has to be the same value as well; granularity\r
+         should be 0 in this case.\r
+*/\r
+\r
+ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);\r
+/* Purpose:\r
+         Inquires the hardware for the available sample rates.\r
+       Parameter:\r
+         sampleRate is the rate in question.\r
+       Returns:\r
+         If the inquired sample rate is not supported, ASE_NoClock will be returned.\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+*/\r
+ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);\r
+/* Purpose:\r
+         Get the current sample Rate.\r
+       Parameter:\r
+         currentRate will hold the current sample rate on return.\r
+       Returns:\r
+         If sample rate is unknown, sampleRate will be 0 and ASE_NoClock will be returned.\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+*/\r
+\r
+ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);\r
+/* Purpose:\r
+         Set the hardware to the requested sample Rate. If sampleRate == 0,\r
+         enable external sync.\r
+       Parameter:\r
+         sampleRate: on input, the requested rate\r
+       Returns:\r
+         If sampleRate is unknown ASE_NoClock will be returned.\r
+         If the current clock is external, and sampleRate is != 0,\r
+         ASE_InvalidMode will be returned\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+*/\r
+\r
+typedef struct ASIOClockSource\r
+{\r
+       long index;                                     // as used for ASIOSetClockSource()\r
+       long associatedChannel;         // for instance, S/PDIF or AES/EBU\r
+       long associatedGroup;           // see channel groups (ASIOGetChannelInfo())\r
+       ASIOBool isCurrentSource;       // ASIOTrue if this is the current clock source\r
+       char name[32];                          // for user selection\r
+} ASIOClockSource;\r
+\r
+ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);\r
+/* Purpose:\r
+         Get the available external audio clock sources\r
+       Parameter:\r
+         clocks points to an array of ASIOClockSource structures:\r
+               - index: this is used to identify the clock source\r
+                 when ASIOSetClockSource() is accessed, should be\r
+                 an index counting from zero\r
+               - associatedInputChannel: the first channel of an associated\r
+                 input group, if any.\r
+               - associatedGroup: the group index of that channel.\r
+                 groups of channels are defined to seperate for\r
+                 instance analog, S/PDIF, AES/EBU, ADAT connectors etc,\r
+                 when present simultaniously. Note that associated channel\r
+                 is enumerated according to numInputs/numOutputs, means it\r
+                 is independant from a group (see also ASIOGetChannelInfo())\r
+                 inputs are associated to a clock if the physical connection\r
+                 transfers both data and clock (like S/PDIF, AES/EBU, or\r
+                 ADAT inputs). if there is no input channel associated with\r
+                 the clock source (like Word Clock, or internal oscillator), both\r
+                 associatedChannel and associatedGroup should be set to -1.\r
+               - isCurrentSource: on exit, ASIOTrue if this is the current clock\r
+                 source, ASIOFalse else\r
+               - name: a null-terminated string for user selection of the available sources.\r
+         numSources:\r
+             on input: the number of allocated array members\r
+             on output: the number of available clock sources, at least\r
+             1 (internal clock generator).\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+*/\r
+\r
+ASIOError ASIOSetClockSource(long index);\r
+/* Purpose:\r
+         Set the audio clock source\r
+       Parameter:\r
+         index as obtained from an inquiry to ASIOGetClockSources()\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+         If the clock can not be selected because an input channel which\r
+         carries the current clock source is active, ASE_InvalidMode\r
+         *may* be returned (this depends on the properties of the driver\r
+         and/or hardware).\r
+       Notes:\r
+         Should *not* return ASE_NoClock if there is no clock signal present\r
+         at the selected source; this will be inquired via ASIOGetSampleRate().\r
+         It should call the host callback procedure sampleRateHasChanged(),\r
+         if the switch causes a sample rate change, or if no external clock\r
+         is present at the selected source.\r
+*/\r
+\r
+ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);\r
+/* Purpose:\r
+         Inquires the sample position/time stamp pair.\r
+       Parameter:\r
+         sPos will hold the sample position on return. The sample\r
+         position is reset to zero when ASIOStart() gets called.\r
+         tStamp will hold the system time when the sample position\r
+         was latched.\r
+       Returns:\r
+         If no input/output is present, ASE_NotPresent will be returned.\r
+         If there is no clock, ASE_SPNotAdvancing will be returned.\r
+       Notes:\r
+\r
+         in order to be able to synchronise properly,\r
+         the sample position / time stamp pair must refer to the current block,\r
+         that is, the engine will call ASIOGetSamplePosition() in its bufferSwitch()\r
+         callback and expect the time for the current block. thus, when requested\r
+         in the very first bufferSwitch after ASIO_Start(), the sample position\r
+         should be zero, and the time stamp should refer to the very time where\r
+         the stream was started. it also means that the sample position must be\r
+         block aligned. the driver must ensure proper interpolation if the system\r
+         time can not be determined for the block position. the driver is responsible\r
+         for precise time stamps as it usually has most direct access to lower\r
+         level resources. proper behaviour of ASIO_GetSamplePosition() and ASIO_GetLatencies()\r
+         are essential for precise media synchronization!\r
+*/\r
+\r
+typedef struct ASIOChannelInfo\r
+{\r
+       long channel;                   // on input, channel index\r
+       ASIOBool isInput;               // on input\r
+       ASIOBool isActive;              // on exit\r
+       long channelGroup;              // dto\r
+       ASIOSampleType type;    // dto\r
+       char name[32];                  // dto\r
+} ASIOChannelInfo;\r
+\r
+ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);\r
+/* Purpose:\r
+         retreive information about the nature of a channel\r
+       Parameter:\r
+         info: pointer to a ASIOChannelInfo structure with\r
+               - channel: on input, the channel index of the channel in question.\r
+               - isInput: on input, ASIOTrue if info for an input channel is\r
+                 requested, else output\r
+               - channelGroup: on return, the channel group that the channel\r
+                 belongs to. For drivers which support different types of\r
+                 channels, like analog, S/PDIF, AES/EBU, ADAT etc interfaces,\r
+                 there should be a reasonable grouping of these types. Groups\r
+                 are always independant form a channel index, that is, a channel\r
+                 index always counts from 0 to numInputs/numOutputs regardless\r
+                 of the group it may belong to.\r
+                 There will always be at least one group (group 0). Please\r
+                 also note that by default, the host may decide to activate\r
+                 channels 0 and 1; thus, these should belong to the most\r
+                 useful type (analog i/o, if present).\r
+               - type: on return, contains the sample type of the channel\r
+               - isActive: on return, ASIOTrue if channel is active as it was\r
+                 installed by ASIOCreateBuffers(), ASIOFalse else\r
+               - name:  describing the type of channel in question. Used to allow\r
+                 for user selection, and enabling of specific channels. examples:\r
+             "Analog In", "SPDIF Out" etc\r
+       Returns:\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+         If possible, the string should be organised such that the first\r
+         characters are most significantly describing the nature of the\r
+         port, to allow for identification even if the view showing the\r
+         port name is too small to display more than 8 characters, for\r
+         instance.\r
+*/\r
+\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+// Buffer preparation\r
+//- - - - - - - - - - - - - - - - - - - - - - - - -\r
+\r
+typedef struct ASIOBufferInfo\r
+{\r
+       ASIOBool isInput;                       // on input:  ASIOTrue: input, else output\r
+       long channelNum;                        // on input:  channel index\r
+       void *buffers[2];                       // on output: double buffer addresses\r
+} ASIOBufferInfo;\r
+\r
+ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,\r
+       long bufferSize, ASIOCallbacks *callbacks);\r
+\r
+/* Purpose:\r
+         Allocates input/output buffers for all input and output channels to be activated.\r
+       Parameter:\r
+         bufferInfos is a pointer to an array of ASIOBufferInfo structures:\r
+           - isInput: on input, ASIOTrue if the buffer is to be allocated\r
+             for an input, output buffer else\r
+           - channelNum: on input, the index of the channel in question\r
+             (counting from 0)\r
+           - buffers: on exit, 2 pointers to the halves of the channels' double-buffer.\r
+             the size of the buffer(s) of course depend on both the ASIOSampleType\r
+             as obtained from ASIOGetChannelInfo(), and bufferSize\r
+         numChannels is the sum of all input and output channels to be created;\r
+         thus bufferInfos is a pointer to an array of numChannels ASIOBufferInfo\r
+         structures.\r
+         bufferSize selects one of the possible buffer sizes as obtained from\r
+         ASIOGetBufferSizes().\r
+         callbacks is a pointer to an ASIOCallbacks structure.\r
+       Returns:\r
+         If not enough memory is available ASE_NoMemory will be returned.\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+         If bufferSize is not supported, or one or more of the bufferInfos elements\r
+         contain invalid settings, ASE_InvalidMode will be returned.\r
+       Notes:\r
+         If individual channel selection is not possible but requested,\r
+         the driver has to handle this. namely, bufferSwitch() will only\r
+         have filled buffers of enabled outputs. If possible, processing\r
+         and buss activities overhead should be avoided for channels which\r
+         were not enabled here.\r
+*/\r
+\r
+ASIOError ASIODisposeBuffers(void);\r
+/* Purpose:\r
+         Releases all buffers for the device.\r
+       Parameter:\r
+         None.\r
+       Returns:\r
+         If no buffer were ever prepared, ASE_InvalidMode will be returned.\r
+         If no input/output is present ASE_NotPresent will be returned.\r
+       Notes:\r
+         This implies ASIOStop().\r
+*/\r
+\r
+ASIOError ASIOControlPanel(void);\r
+/* Purpose:\r
+         request the driver to start a control panel component\r
+         for device specific user settings. This will not be\r
+         accessed on some platforms (where the component is accessed\r
+         instead).\r
+       Parameter:\r
+         None.\r
+       Returns:\r
+         If no panel is available ASE_NotPresent will be returned.\r
+         Actually, the return code is ignored.\r
+       Notes:\r
+         if the user applied settings which require a re-configuration\r
+         of parts or all of the enigine and/or driver (such as a change of\r
+         the block size), the asioMessage callback can be used (see\r
+         ASIO_Callbacks).\r
+*/\r
+\r
+ASIOError ASIOFuture(long selector, void *params);\r
+/* Purpose:\r
+         various\r
+       Parameter:\r
+         selector: operation Code as to be defined. zero is reserved for\r
+         testing purposes.\r
+         params: depends on the selector; usually pointer to a structure\r
+         for passing and retreiving any type and amount of parameters.\r
+       Returns:\r
+         the return value is also selector dependant. if the selector\r
+         is unknown, ASE_InvalidParameter should be returned to prevent\r
+         further calls with this selector. on success, ASE_SUCCESS\r
+         must be returned (note: ASE_OK is *not* sufficient!)\r
+       Notes:\r
+         see selectors defined below.    \r
+*/\r
+\r
+enum\r
+{\r
+       kAsioEnableTimeCodeRead = 1,    // no arguments\r
+       kAsioDisableTimeCodeRead,               // no arguments\r
+       kAsioSetInputMonitor,                   // ASIOInputMonitor* in params\r
+       kAsioTransport,                                 // ASIOTransportParameters* in params\r
+       kAsioSetInputGain,                              // ASIOChannelControls* in params, apply gain\r
+       kAsioGetInputMeter,                             // ASIOChannelControls* in params, fill meter\r
+       kAsioSetOutputGain,                             // ASIOChannelControls* in params, apply gain\r
+       kAsioGetOutputMeter,                    // ASIOChannelControls* in params, fill meter\r
+       kAsioCanInputMonitor,                   // no arguments for kAsioCanXXX selectors\r
+       kAsioCanTimeInfo,\r
+       kAsioCanTimeCode,\r
+       kAsioCanTransport,\r
+       kAsioCanInputGain,\r
+       kAsioCanInputMeter,\r
+       kAsioCanOutputGain,\r
+       kAsioCanOutputMeter\r
+};\r
+\r
+typedef struct ASIOInputMonitor\r
+{\r
+       long input;             // this input was set to monitor (or off), -1: all\r
+       long output;    // suggested output for monitoring the input (if so)\r
+       long gain;              // suggested gain, ranging 0 - 0x7fffffffL (-inf to +12 dB)\r
+       ASIOBool state; // ASIOTrue => on, ASIOFalse => off\r
+       long pan;               // suggested pan, 0 => all left, 0x7fffffff => right\r
+} ASIOInputMonitor;\r
+\r
+typedef struct ASIOChannelControls\r
+{\r
+       long channel;                   // on input, channel index\r
+       ASIOBool isInput;               // on input\r
+       long gain;                              // on input,  ranges 0 thru 0x7fffffff\r
+       long meter;                             // on return, ranges 0 thru 0x7fffffff\r
+       char future[32];\r
+} ASIOChannelControls;\r
+\r
+typedef struct ASIOTransportParameters\r
+{\r
+       long command;           // see enum below\r
+       ASIOSamples samplePosition;\r
+       long track;\r
+       long trackSwitches[16];         // 512 tracks on/off\r
+       char future[64];\r
+} ASIOTransportParameters;\r
+\r
+enum\r
+{\r
+       kTransStart = 1,\r
+       kTransStop,\r
+       kTransLocate,           // to samplePosition\r
+       kTransPunchIn,\r
+       kTransPunchOut,\r
+       kTransArmOn,            // track\r
+       kTransArmOff,           // track\r
+       kTransMonitorOn,        // track\r
+       kTransMonitorOff,       // track\r
+       kTransArm,                      // trackSwitches\r
+       kTransMonitor           // trackSwitches\r
+};\r
+\r
+ASIOError ASIOOutputReady(void);\r
+/* Purpose:\r
+         this tells the driver that the host has completed processing\r
+         the output buffers. if the data format required by the hardware\r
+         differs from the supported asio formats, but the hardware\r
+         buffers are DMA buffers, the driver will have to convert\r
+         the audio stream data; as the bufferSwitch callback is\r
+         usually issued at dma block switch time, the driver will\r
+         have to convert the *previous* host buffer, which increases\r
+         the output latency by one block.\r
+         when the host finds out that ASIOOutputReady() returns\r
+         true, it will issue this call whenever it completed\r
+         output processing. then the driver can convert the\r
+         host data directly to the dma buffer to be played next,\r
+         reducing output latency by one block.\r
+         another way to look at it is, that the buffer switch is called\r
+         in order to pass the *input* stream to the host, so that it can\r
+         process the input into the output, and the output stream is passed\r
+         to the driver when the host has completed its process.\r
+       Parameter:\r
+               None\r
+       Returns:\r
+         only if the above mentioned scenario is given, and a reduction\r
+         of output latency can be acheived by this mechanism, should\r
+         ASE_OK be returned. otherwise (and usually), ASE_NotPresent\r
+         should be returned in order to prevent further calls to this\r
+         function. note that the host may want to determine if it is\r
+         to use this when the system is not yet fully initialized, so\r
+         ASE_OK should always be returned if the mechanism makes sense.          \r
+       Notes:\r
+         please remeber to adjust ASIOGetLatencies() according to\r
+         whether ASIOOutputReady() was ever called or not, if your\r
+         driver supports this scenario.\r
+         also note that the engine may fail to call ASIO_OutputReady()\r
+         in time in overload cases. as already mentioned, bufferSwitch\r
+      should be called for every block regardless of whether a block\r
+      could be processed in time.\r
+*/\r
+\r
+// restore old alignment\r
+#if defined(_MSC_VER) && !defined(__MWERKS__) \r
+#pragma pack(pop)\r
+#elif PRAGMA_ALIGN_SUPPORTED\r
+#pragma options align = reset\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/tests/asio/asiodrivers.cpp b/tests/asio/asiodrivers.cpp
new file mode 100644 (file)
index 0000000..5f56454
--- /dev/null
@@ -0,0 +1,186 @@
+#include <string.h>\r
+#include "asiodrivers.h"\r
+\r
+AsioDrivers* asioDrivers = 0;\r
+\r
+bool loadAsioDriver(char *name);\r
+\r
+bool loadAsioDriver(char *name)\r
+{\r
+       if(!asioDrivers)\r
+               asioDrivers = new AsioDrivers();\r
+       if(asioDrivers)\r
+               return asioDrivers->loadDriver(name);\r
+       return false;\r
+}\r
+\r
+//------------------------------------------------------------------------------------\r
+\r
+#if MAC\r
+\r
+bool resolveASIO(unsigned long aconnID);\r
+\r
+AsioDrivers::AsioDrivers() : CodeFragments("ASIO Drivers", 'AsDr', 'Asio')\r
+{\r
+       connID = -1;\r
+       curIndex = -1;\r
+}\r
+\r
+AsioDrivers::~AsioDrivers()\r
+{\r
+       removeCurrentDriver();\r
+}\r
+\r
+bool AsioDrivers::getCurrentDriverName(char *name)\r
+{\r
+       if(curIndex >= 0)\r
+               return getName(curIndex, name);\r
+       return false;\r
+}\r
+\r
+long AsioDrivers::getDriverNames(char **names, long maxDrivers)\r
+{\r
+       for(long i = 0; i < getNumFragments() && i < maxDrivers; i++)\r
+               getName(i, names[i]);\r
+       return getNumFragments() < maxDrivers ? getNumFragments() : maxDrivers;\r
+}\r
+\r
+bool AsioDrivers::loadDriver(char *name)\r
+{\r
+       char dname[64];\r
+       unsigned long newID;\r
+\r
+       for(long i = 0; i < getNumFragments(); i++)\r
+       {\r
+               if(getName(i, dname) && !strcmp(name, dname))\r
+               {\r
+                       if(newInstance(i, &newID))\r
+                       {\r
+                               if(resolveASIO(newID))\r
+                               {\r
+                                       if(connID != -1)\r
+                                               removeInstance(curIndex, connID);\r
+                                       curIndex = i;\r
+                                       connID = newID;\r
+                                       return true;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+void AsioDrivers::removeCurrentDriver()\r
+{\r
+       if(connID != -1)\r
+               removeInstance(curIndex, connID);\r
+       connID = -1;\r
+       curIndex = -1;\r
+}\r
+\r
+//------------------------------------------------------------------------------------\r
+\r
+#elif WINDOWS\r
+\r
+#include "iasiodrv.h"\r
+\r
+extern IASIO* theAsioDriver;\r
+\r
+AsioDrivers::AsioDrivers() : AsioDriverList()\r
+{\r
+       curIndex = -1;\r
+}\r
+\r
+AsioDrivers::~AsioDrivers()\r
+{\r
+}\r
+\r
+bool AsioDrivers::getCurrentDriverName(char *name)\r
+{\r
+       if(curIndex >= 0)\r
+               return asioGetDriverName(curIndex, name, 32) == 0 ? true : false;\r
+       name[0] = 0;\r
+       return false;\r
+}\r
+\r
+long AsioDrivers::getDriverNames(char **names, long maxDrivers)\r
+{\r
+       for(long i = 0; i < asioGetNumDev() && i < maxDrivers; i++)\r
+               asioGetDriverName(i, names[i], 32);\r
+       return asioGetNumDev() < maxDrivers ? asioGetNumDev() : maxDrivers;\r
+}\r
+\r
+bool AsioDrivers::loadDriver(char *name)\r
+{\r
+       char dname[64];\r
+       char curName[64];\r
+\r
+       for(long i = 0; i < asioGetNumDev(); i++)\r
+       {\r
+               if(!asioGetDriverName(i, dname, 32) && !strcmp(name, dname))\r
+               {\r
+                       curName[0] = 0;\r
+                       getCurrentDriverName(curName);  // in case we fail...\r
+                       removeCurrentDriver();\r
+\r
+                       if(!asioOpenDriver(i, (void **)&theAsioDriver))\r
+                       {\r
+                               curIndex = i;\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               theAsioDriver = 0;\r
+                               if(curName[0] && strcmp(dname, curName))\r
+                                       loadDriver(curName);    // try restore\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+       return false;\r
+}\r
+\r
+void AsioDrivers::removeCurrentDriver()\r
+{\r
+       if(curIndex != -1)\r
+               asioCloseDriver(curIndex);\r
+       curIndex = -1;\r
+}\r
+\r
+#elif SGI || BEOS\r
+\r
+#include "asiolist.h"\r
+\r
+AsioDrivers::AsioDrivers() \r
+       : AsioDriverList()\r
+{\r
+       curIndex = -1;\r
+}\r
+\r
+AsioDrivers::~AsioDrivers()\r
+{\r
+}\r
+\r
+bool AsioDrivers::getCurrentDriverName(char *name)\r
+{\r
+       return false;\r
+}\r
+\r
+long AsioDrivers::getDriverNames(char **names, long maxDrivers)\r
+{\r
+       return 0;\r
+}\r
+\r
+bool AsioDrivers::loadDriver(char *name)\r
+{\r
+       return false;\r
+}\r
+\r
+void AsioDrivers::removeCurrentDriver()\r
+{\r
+}\r
+\r
+#else\r
+#error implement me\r
+#endif\r
diff --git a/tests/asio/asiodrivers.h b/tests/asio/asiodrivers.h
new file mode 100644 (file)
index 0000000..2ddf7ad
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __AsioDrivers__\r
+#define __AsioDrivers__\r
+\r
+#include "ginclude.h"\r
+\r
+#if MAC\r
+#include "CodeFragments.hpp"\r
+\r
+class AsioDrivers : public CodeFragments\r
+\r
+#elif WINDOWS\r
+#include <windows.h>\r
+#include "asiolist.h"\r
+\r
+class AsioDrivers : public AsioDriverList\r
+\r
+#elif SGI || BEOS\r
+#include "asiolist.h"\r
+\r
+class AsioDrivers : public AsioDriverList\r
+\r
+#else\r
+#error implement me\r
+#endif\r
+\r
+{\r
+public:\r
+       AsioDrivers();\r
+       ~AsioDrivers();\r
+       \r
+       bool getCurrentDriverName(char *name);\r
+       long getDriverNames(char **names, long maxDrivers);\r
+       bool loadDriver(char *name);\r
+       void removeCurrentDriver();\r
+       long getCurrentDriverIndex() {return curIndex;}\r
+protected:\r
+       unsigned long connID;\r
+       long curIndex;\r
+};\r
+\r
+#endif\r
diff --git a/tests/asio/asiodrvr.h b/tests/asio/asiodrvr.h
new file mode 100644 (file)
index 0000000..663f75a
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+       Steinberg Audio Stream I/O API\r
+       (c) 1996, Steinberg Soft- und Hardware GmbH\r
+       charlie (May 1996)\r
+\r
+       asiodrvr.h\r
+       c++ superclass to implement asio functionality. from this,\r
+       you can derive whatever required\r
+*/\r
+\r
+#ifndef _asiodrvr_\r
+#define _asiodrvr_\r
+\r
+// cpu and os system we are running on\r
+#include "asiosys.h"\r
+// basic "C" interface\r
+#include "asio.h"\r
+\r
+class AsioDriver;\r
+extern AsioDriver *getDriver();                // for generic constructor \r
+\r
+#if WINDOWS\r
+#include <windows.h>\r
+#include "combase.h"\r
+#include "iasiodrv.h"\r
+class AsioDriver : public IASIO ,public CUnknown\r
+{\r
+public:\r
+       AsioDriver(LPUNKNOWN pUnk, HRESULT *phr);\r
+\r
+       DECLARE_IUNKNOWN\r
+       // Factory method\r
+       static CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr);\r
+       // IUnknown\r
+       virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid,void **ppvObject);\r
+\r
+#else\r
+\r
+class AsioDriver\r
+{\r
+public:\r
+       AsioDriver();\r
+#endif\r
+       virtual ~AsioDriver();\r
+\r
+       virtual ASIOBool init(void* sysRef);\r
+       virtual void getDriverName(char *name); // max 32 bytes incl. terminating zero\r
+       virtual long getDriverVersion();\r
+       virtual void getErrorMessage(char *string);     // max 124 bytes incl.\r
+\r
+       virtual ASIOError start();\r
+       virtual ASIOError stop();\r
+\r
+       virtual ASIOError getChannels(long *numInputChannels, long *numOutputChannels);\r
+       virtual ASIOError getLatencies(long *inputLatency, long *outputLatency);\r
+       virtual ASIOError getBufferSize(long *minSize, long *maxSize,\r
+               long *preferredSize, long *granularity);\r
+\r
+       virtual ASIOError canSampleRate(ASIOSampleRate sampleRate);\r
+       virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate);\r
+       virtual ASIOError setSampleRate(ASIOSampleRate sampleRate);\r
+       virtual ASIOError getClockSources(ASIOClockSource *clocks, long *numSources);\r
+       virtual ASIOError setClockSource(long reference);\r
+\r
+       virtual ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp);\r
+       virtual ASIOError getChannelInfo(ASIOChannelInfo *info);\r
+\r
+       virtual ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,\r
+               long bufferSize, ASIOCallbacks *callbacks);\r
+       virtual ASIOError disposeBuffers();\r
+\r
+       virtual ASIOError controlPanel();\r
+       virtual ASIOError future(long selector, void *opt);\r
+       virtual ASIOError outputReady();\r
+};\r
+#endif\r
diff --git a/tests/asio/asiolist.cpp b/tests/asio/asiolist.cpp
new file mode 100644 (file)
index 0000000..5a62f5b
--- /dev/null
@@ -0,0 +1,268 @@
+#include <windows.h>\r
+#include "iasiodrv.h"\r
+#include "asiolist.h"\r
+\r
+#define ASIODRV_DESC           "description"\r
+#define INPROC_SERVER          "InprocServer32"\r
+#define ASIO_PATH                      "software\\asio"\r
+#define COM_CLSID                      "clsid"\r
+\r
+// ******************************************************************\r
+// Local Functions \r
+// ******************************************************************\r
+static LONG findDrvPath (char *clsidstr,char *dllpath,int dllpathsize)\r
+{\r
+       HKEY                    hkEnum,hksub,hkpath;\r
+       char                    databuf[512];\r
+       LONG                    cr,rc = -1;\r
+       DWORD                   datatype,datasize;\r
+       DWORD                   index;\r
+       OFSTRUCT                ofs;\r
+       HFILE                   hfile;\r
+       BOOL                    found = FALSE;\r
+\r
+       CharLowerBuff(clsidstr,strlen(clsidstr));\r
+       if ((cr = RegOpenKey(HKEY_CLASSES_ROOT,COM_CLSID,&hkEnum)) == ERROR_SUCCESS) {\r
+\r
+               index = 0;\r
+               while (cr == ERROR_SUCCESS && !found) {\r
+                       cr = RegEnumKey(hkEnum,index++,(LPTSTR)databuf,512);\r
+                       if (cr == ERROR_SUCCESS) {\r
+                               CharLowerBuff(databuf,strlen(databuf));\r
+                               if (!(strcmp(databuf,clsidstr))) {\r
+                                       if ((cr = RegOpenKeyEx(hkEnum,(LPCTSTR)databuf,0,KEY_READ,&hksub)) == ERROR_SUCCESS) {\r
+                                               if ((cr = RegOpenKeyEx(hksub,(LPCTSTR)INPROC_SERVER,0,KEY_READ,&hkpath)) == ERROR_SUCCESS) {\r
+                                                       datatype = REG_SZ; datasize = (DWORD)dllpathsize;\r
+                                                       cr = RegQueryValueEx(hkpath,0,0,&datatype,(LPBYTE)dllpath,&datasize);\r
+                                                       if (cr == ERROR_SUCCESS) {\r
+                                                               memset(&ofs,0,sizeof(OFSTRUCT));\r
+                                                               ofs.cBytes = sizeof(OFSTRUCT); \r
+                                                               hfile = OpenFile(dllpath,&ofs,OF_EXIST);\r
+                                                               if (hfile) rc = 0; \r
+                                                       }\r
+                                                       RegCloseKey(hkpath);\r
+                                               }\r
+                                               RegCloseKey(hksub);\r
+                                       }\r
+                                       found = TRUE;   // break out \r
+                               }\r
+                       }\r
+               }                               \r
+               RegCloseKey(hkEnum);\r
+       }\r
+       return rc;\r
+}\r
+\r
+\r
+static LPASIODRVSTRUCT newDrvStruct (HKEY hkey,char *keyname,int drvID,LPASIODRVSTRUCT lpdrv)\r
+{\r
+       HKEY    hksub;\r
+       char    databuf[256];\r
+       char    dllpath[MAXPATHLEN];\r
+       WORD    wData[100];\r
+       CLSID   clsid;\r
+       DWORD   datatype,datasize;\r
+       LONG    cr,rc;\r
+\r
+       if (!lpdrv) {\r
+               if ((cr = RegOpenKeyEx(hkey,(LPCTSTR)keyname,0,KEY_READ,&hksub)) == ERROR_SUCCESS) {\r
+\r
+                       datatype = REG_SZ; datasize = 256;\r
+                       cr = RegQueryValueEx(hksub,COM_CLSID,0,&datatype,(LPBYTE)databuf,&datasize);\r
+                       if (cr == ERROR_SUCCESS) {\r
+                               rc = findDrvPath (databuf,dllpath,MAXPATHLEN);\r
+                               if (rc == 0) {\r
+                                       lpdrv = new ASIODRVSTRUCT[1];\r
+                                       if (lpdrv) {\r
+                                               memset(lpdrv,0,sizeof(ASIODRVSTRUCT));\r
+                                               lpdrv->drvID = drvID;\r
+                                               MultiByteToWideChar(CP_ACP,0,(LPCSTR)databuf,-1,(LPWSTR)wData,100);\r
+                                               if ((cr = CLSIDFromString((LPOLESTR)wData,(LPCLSID)&clsid)) == S_OK) {\r
+                                                       memcpy(&lpdrv->clsid,&clsid,sizeof(CLSID));\r
+                                               }\r
+\r
+                                               datatype = REG_SZ; datasize = 256;\r
+                                               cr = RegQueryValueEx(hksub,ASIODRV_DESC,0,&datatype,(LPBYTE)databuf,&datasize);\r
+                                               if (cr == ERROR_SUCCESS) {\r
+                                                       strcpy(lpdrv->drvname,databuf);\r
+                                               }\r
+                                               else strcpy(lpdrv->drvname,keyname);\r
+                                       }\r
+                               }\r
+                       }\r
+                       RegCloseKey(hksub);\r
+               }\r
+       }       \r
+       else lpdrv->next = newDrvStruct(hkey,keyname,drvID+1,lpdrv->next);\r
+\r
+       return lpdrv;\r
+}\r
+\r
+static void deleteDrvStruct (LPASIODRVSTRUCT lpdrv)\r
+{\r
+       IASIO   *iasio;\r
+\r
+       if (lpdrv != 0) {\r
+               deleteDrvStruct(lpdrv->next);\r
+               if (lpdrv->asiodrv) {\r
+                       iasio = (IASIO *)lpdrv->asiodrv;\r
+                       iasio->Release();\r
+               }\r
+               delete lpdrv;\r
+       }\r
+}\r
+\r
+\r
+static LPASIODRVSTRUCT getDrvStruct (int drvID,LPASIODRVSTRUCT lpdrv)\r
+{\r
+       while (lpdrv) {\r
+               if (lpdrv->drvID == drvID) return lpdrv;\r
+               lpdrv = lpdrv->next;\r
+       }\r
+       return 0;\r
+}\r
+// ******************************************************************\r
+\r
+\r
+// ******************************************************************\r
+//     AsioDriverList\r
+// ******************************************************************\r
+AsioDriverList::AsioDriverList ()\r
+{\r
+       HKEY                    hkEnum = 0;\r
+       char                    keyname[MAXDRVNAMELEN];\r
+       LPASIODRVSTRUCT pdl;\r
+       LONG                    cr;\r
+       DWORD                   index = 0;\r
+       BOOL                    fin = FALSE;\r
+\r
+       numdrv          = 0;\r
+       lpdrvlist       = 0;\r
+\r
+       cr = RegOpenKey(HKEY_LOCAL_MACHINE,ASIO_PATH,&hkEnum);\r
+       while (cr == ERROR_SUCCESS) {\r
+               if ((cr = RegEnumKey(hkEnum,index++,(LPTSTR)keyname,MAXDRVNAMELEN))== ERROR_SUCCESS) {\r
+                       lpdrvlist = newDrvStruct (hkEnum,keyname,0,lpdrvlist);\r
+               }\r
+               else fin = TRUE;\r
+       }\r
+       if (hkEnum) RegCloseKey(hkEnum);\r
+\r
+       pdl = lpdrvlist;\r
+       while (pdl) {\r
+               numdrv++;\r
+               pdl = pdl->next;\r
+       }\r
+\r
+       if (numdrv) CoInitialize(0);    // initialize COM\r
+}\r
+\r
+AsioDriverList::~AsioDriverList ()\r
+{\r
+       if (numdrv) {\r
+               deleteDrvStruct(lpdrvlist);\r
+               CoUninitialize();\r
+       }\r
+}\r
+\r
+\r
+LONG AsioDriverList::asioGetNumDev (VOID)\r
+{\r
+       return (LONG)numdrv;\r
+}\r
+\r
+\r
+LONG AsioDriverList::asioOpenDriver (int drvID,LPVOID *asiodrv)\r
+{\r
+       LPASIODRVSTRUCT lpdrv = 0;\r
+       long                    rc;\r
+\r
+       if (!asiodrv) return DRVERR_INVALID_PARAM;\r
+\r
+       if ((lpdrv = getDrvStruct(drvID,lpdrvlist)) != 0) {\r
+               if (!lpdrv->asiodrv) {\r
+                       rc = CoCreateInstance(lpdrv->clsid,0,CLSCTX_INPROC_SERVER,lpdrv->clsid,asiodrv);\r
+                       if (rc == S_OK) {\r
+                               lpdrv->asiodrv = *asiodrv;\r
+                               return 0;\r
+                       }\r
+                       // else if (rc == REGDB_E_CLASSNOTREG)\r
+                       //      strcpy (info->messageText, "Driver not registered in the Registration Database!");\r
+               }\r
+               else rc = DRVERR_DEVICE_ALREADY_OPEN;\r
+       }\r
+       else rc = DRVERR_DEVICE_NOT_FOUND;\r
+       \r
+       return rc;\r
+}\r
+\r
+\r
+LONG AsioDriverList::asioCloseDriver (int drvID)\r
+{\r
+       LPASIODRVSTRUCT lpdrv = 0;\r
+       IASIO                   *iasio;\r
+\r
+       if ((lpdrv = getDrvStruct(drvID,lpdrvlist)) != 0) {\r
+               if (lpdrv->asiodrv) {\r
+                       iasio = (IASIO *)lpdrv->asiodrv;\r
+                       iasio->Release();\r
+                       lpdrv->asiodrv = 0;\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+LONG AsioDriverList::asioGetDriverName (int drvID,char *drvname,int drvnamesize)\r
+{      \r
+       LPASIODRVSTRUCT                 lpdrv = 0;\r
+\r
+       if (!drvname) return DRVERR_INVALID_PARAM;\r
+\r
+       if ((lpdrv = getDrvStruct(drvID,lpdrvlist)) != 0) {\r
+               if (strlen(lpdrv->drvname) < (unsigned int)drvnamesize) {\r
+                       strcpy(drvname,lpdrv->drvname);\r
+               }\r
+               else {\r
+                       memcpy(drvname,lpdrv->drvname,drvnamesize-4);\r
+                       drvname[drvnamesize-4] = '.';\r
+                       drvname[drvnamesize-3] = '.';\r
+                       drvname[drvnamesize-2] = '.';\r
+                       drvname[drvnamesize-1] = 0;\r
+               }\r
+               return 0;\r
+       }\r
+       return DRVERR_DEVICE_NOT_FOUND;\r
+}\r
+\r
+LONG AsioDriverList::asioGetDriverPath (int drvID,char *dllpath,int dllpathsize)\r
+{\r
+       LPASIODRVSTRUCT                 lpdrv = 0;\r
+\r
+       if (!dllpath) return DRVERR_INVALID_PARAM;\r
+\r
+       if ((lpdrv = getDrvStruct(drvID,lpdrvlist)) != 0) {\r
+               if (strlen(lpdrv->dllpath) < (unsigned int)dllpathsize) {\r
+                       strcpy(dllpath,lpdrv->dllpath);\r
+                       return 0;\r
+               }\r
+               dllpath[0] = 0;\r
+               return DRVERR_INVALID_PARAM;\r
+       }\r
+       return DRVERR_DEVICE_NOT_FOUND;\r
+}\r
+\r
+LONG AsioDriverList::asioGetDriverCLSID (int drvID,CLSID *clsid)\r
+{\r
+       LPASIODRVSTRUCT                 lpdrv = 0;\r
+\r
+       if (!clsid) return DRVERR_INVALID_PARAM;\r
+\r
+       if ((lpdrv = getDrvStruct(drvID,lpdrvlist)) != 0) {\r
+               memcpy(clsid,&lpdrv->clsid,sizeof(CLSID));\r
+               return 0;\r
+       }\r
+       return DRVERR_DEVICE_NOT_FOUND;\r
+}\r
+\r
+\r
diff --git a/tests/asio/asiolist.h b/tests/asio/asiolist.h
new file mode 100644 (file)
index 0000000..01c64f0
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __asiolist__\r
+#define __asiolist__\r
+\r
+#define DRVERR                 -5000\r
+#define DRVERR_INVALID_PARAM           DRVERR-1\r
+#define DRVERR_DEVICE_ALREADY_OPEN     DRVERR-2\r
+#define DRVERR_DEVICE_NOT_FOUND                DRVERR-3\r
+\r
+#define MAXPATHLEN                     512\r
+#define MAXDRVNAMELEN          128\r
+\r
+struct asiodrvstruct\r
+{\r
+       int                                             drvID;\r
+       CLSID                                   clsid;\r
+       char                                    dllpath[MAXPATHLEN];\r
+       char                                    drvname[MAXDRVNAMELEN];\r
+       LPVOID                                  asiodrv;\r
+       struct asiodrvstruct    *next;\r
+};\r
+\r
+typedef struct asiodrvstruct ASIODRVSTRUCT;\r
+typedef ASIODRVSTRUCT  *LPASIODRVSTRUCT;\r
+\r
+class AsioDriverList {\r
+public:\r
+       AsioDriverList();\r
+       ~AsioDriverList();\r
+       \r
+       LONG asioOpenDriver (int,VOID **);\r
+       LONG asioCloseDriver (int);\r
+\r
+       // nice to have\r
+       LONG asioGetNumDev (VOID);\r
+       LONG asioGetDriverName (int,char *,int);                \r
+       LONG asioGetDriverPath (int,char *,int);\r
+       LONG asioGetDriverCLSID (int,CLSID *);\r
+\r
+       // or use directly access\r
+       LPASIODRVSTRUCT lpdrvlist;\r
+       int                             numdrv;\r
+};\r
+\r
+typedef class AsioDriverList *LPASIODRIVERLIST;\r
+\r
+#endif\r
diff --git a/tests/asio/asiosys.h b/tests/asio/asiosys.h
new file mode 100644 (file)
index 0000000..37f7a48
--- /dev/null
@@ -0,0 +1,82 @@
+#ifndef __asiosys__\r
+       #define __asiosys__\r
+\r
+       #ifdef WIN32\r
+               #undef MAC \r
+               #define PPC 0\r
+               #define WINDOWS 1\r
+               #define SGI 0\r
+               #define SUN 0\r
+               #define LINUX 0\r
+               #define BEOS 0\r
+\r
+               #define NATIVE_INT64 0\r
+               #define IEEE754_64FLOAT 1\r
+       \r
+       #elif BEOS\r
+               #define MAC 0\r
+               #define PPC 0\r
+               #define WINDOWS 0\r
+               #define PC 0\r
+               #define SGI 0\r
+               #define SUN 0\r
+               #define LINUX 0\r
+               \r
+               #define NATIVE_INT64 0\r
+               #define IEEE754_64FLOAT 1\r
+               \r
+               #ifndef DEBUG\r
+                       #define DEBUG 0\r
+                       #if DEBUG\r
+                               void DEBUGGERMESSAGE(char *string);\r
+                       #else\r
+                               #define DEBUGGERMESSAGE(a)\r
+                       #endif\r
+               #endif\r
+\r
+       #elif SGI\r
+               #define MAC 0\r
+               #define PPC 0\r
+               #define WINDOWS 0\r
+               #define PC 0\r
+               #define SUN 0\r
+               #define LINUX 0\r
+               #define BEOS 0\r
+               \r
+               #define NATIVE_INT64 0\r
+               #define IEEE754_64FLOAT 1\r
+               \r
+               #ifndef DEBUG\r
+                       #define DEBUG 0\r
+                       #if DEBUG\r
+                               void DEBUGGERMESSAGE(char *string);\r
+                       #else\r
+                               #define DEBUGGERMESSAGE(a)\r
+                       #endif\r
+               #endif\r
+\r
+       #else   // MAC\r
+\r
+               #define MAC 1\r
+               #define PPC 1\r
+               #define WINDOWS 0\r
+               #define PC 0\r
+               #define SGI 0\r
+               #define SUN 0\r
+               #define LINUX 0\r
+               #define BEOS 0\r
+\r
+               #define NATIVE_INT64 0\r
+               #define IEEE754_64FLOAT 1\r
+\r
+               #ifndef DEBUG\r
+                       #define DEBUG 0\r
+                       #if DEBUG\r
+                               void DEBUGGERMESSAGE(char *string);\r
+                       #else\r
+                               #define DEBUGGERMESSAGE(a)\r
+                       #endif\r
+               #endif\r
+       #endif\r
+\r
+#endif\r
diff --git a/tests/asio/call_inout.dsp b/tests/asio/call_inout.dsp
new file mode 100755 (executable)
index 0000000..97cc4d9
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="call_inout" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_inout - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_inout.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_inout.mak" CFG="call_inout - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_inout - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_inout - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_inout - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_inout - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_inout - Win32 Release"\r
+# Name "call_inout - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\call_inout.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/call_saw.dsp b/tests/asio/call_saw.dsp
new file mode 100755 (executable)
index 0000000..09fff2d
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="call_saw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=call_saw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_saw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "call_saw.mak" CFG="call_saw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "call_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "call_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "call_saw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "call_saw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "call_saw - Win32 Release"\r
+# Name "call_saw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\call_saw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/ginclude.h b/tests/asio/ginclude.h
new file mode 100644 (file)
index 0000000..b627dc2
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __gInclude__\r
+#define __gInclude__\r
+\r
+#if SGI \r
+       #undef BEOS \r
+       #undef MAC \r
+       #undef WINDOWS\r
+       //\r
+       #define ASIO_BIG_ENDIAN 1\r
+       #define ASIO_CPU_MIPS 1\r
+#elif defined WIN32\r
+       #undef BEOS \r
+       #undef MAC \r
+       #undef SGI\r
+       #define WINDOWS 1\r
+       #define ASIO_LITTLE_ENDIAN 1\r
+       #define ASIO_CPU_X86 1\r
+#elif BEOS\r
+       #undef MAC \r
+       #undef SGI\r
+       #undef WINDOWS\r
+       #define ASIO_LITTLE_ENDIAN 1\r
+       #define ASIO_CPU_X86 1\r
+       //\r
+#else\r
+       #define MAC 1\r
+       #undef BEOS \r
+       #undef WINDOWS\r
+       #undef SGI\r
+       #define ASIO_BIG_ENDIAN 1\r
+       #define ASIO_CPU_PPC 1\r
+#endif\r
+\r
+// always\r
+#define NATIVE_INT64 0\r
+#define IEEE754_64FLOAT 1\r
+\r
+#endif // __gInclude__\r
diff --git a/tests/asio/iasiodrv.h b/tests/asio/iasiodrv.h
new file mode 100644 (file)
index 0000000..64d2dbb
--- /dev/null
@@ -0,0 +1,37 @@
+#include "asiosys.h"\r
+#include "asio.h"\r
+\r
+/* Forward Declarations */ \r
+\r
+#ifndef __ASIODRIVER_FWD_DEFINED__\r
+#define __ASIODRIVER_FWD_DEFINED__\r
+typedef interface IASIO IASIO;\r
+#endif         /* __ASIODRIVER_FWD_DEFINED__ */\r
+\r
+interface IASIO : public IUnknown\r
+{\r
+\r
+       virtual ASIOBool init(void *sysHandle) = 0;\r
+       virtual void getDriverName(char *name) = 0;     \r
+       virtual long getDriverVersion() = 0;\r
+       virtual void getErrorMessage(char *string) = 0; \r
+       virtual ASIOError start() = 0;\r
+       virtual ASIOError stop() = 0;\r
+       virtual ASIOError getChannels(long *numInputChannels, long *numOutputChannels) = 0;\r
+       virtual ASIOError getLatencies(long *inputLatency, long *outputLatency) = 0;\r
+       virtual ASIOError getBufferSize(long *minSize, long *maxSize,\r
+               long *preferredSize, long *granularity) = 0;\r
+       virtual ASIOError canSampleRate(ASIOSampleRate sampleRate) = 0;\r
+       virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate) = 0;\r
+       virtual ASIOError setSampleRate(ASIOSampleRate sampleRate) = 0;\r
+       virtual ASIOError getClockSources(ASIOClockSource *clocks, long *numSources) = 0;\r
+       virtual ASIOError setClockSource(long reference) = 0;\r
+       virtual ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp) = 0;\r
+       virtual ASIOError getChannelInfo(ASIOChannelInfo *info) = 0;\r
+       virtual ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels,\r
+               long bufferSize, ASIOCallbacks *callbacks) = 0;\r
+       virtual ASIOError disposeBuffers() = 0;\r
+       virtual ASIOError controlPanel() = 0;\r
+       virtual ASIOError future(long selector,void *opt) = 0;\r
+       virtual ASIOError outputReady() = 0;\r
+};\r
diff --git a/tests/asio/in_out.dsp b/tests/asio/in_out.dsp
new file mode 100755 (executable)
index 0000000..a1036bc
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="in_out" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=in_out - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "in_out.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "in_out.mak" CFG="in_out - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "in_out - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "in_out - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "in_out - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "in_out - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "in_out - Win32 Release"\r
+# Name "in_out - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\in_out.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/info.dsp b/tests/asio/info.dsp
new file mode 100755 (executable)
index 0000000..1d18051
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="info" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=info - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "info.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "info.mak" CFG="info - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "info - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "info - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "info - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "info - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "info - Win32 Release"\r
+# Name "info - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\info.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/play_raw.dsp b/tests/asio/play_raw.dsp
new file mode 100755 (executable)
index 0000000..96ddffb
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="play_raw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=play_raw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_raw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_raw.mak" CFG="play_raw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "play_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "play_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "play_raw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "play_raw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "play_raw - Win32 Release"\r
+# Name "play_raw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\play_raw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/play_saw.dsp b/tests/asio/play_saw.dsp
new file mode 100755 (executable)
index 0000000..7aab9f1
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="play_saw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=play_saw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_saw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "play_saw.mak" CFG="play_saw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "play_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "play_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "play_saw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "play_saw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "play_saw - Win32 Release"\r
+# Name "play_saw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\play_saw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/record_raw.dsp b/tests/asio/record_raw.dsp
new file mode 100755 (executable)
index 0000000..f39827a
--- /dev/null
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="record_raw" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=record_raw - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "record_raw.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "record_raw.mak" CFG="record_raw - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "record_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "record_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "record_raw - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I "../../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /YX /FD /c\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "record_raw - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir ""\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_ASIO__" /D "__RTAUDIO_DEBUG__" /YX /FD /GZ  /c\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "record_raw - Win32 Release"\r
+# Name "record_raw - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\record_raw.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\asio.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrivers.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiodrvr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiolist.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\asiosys.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\ginclude.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\iasiodrv.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\RtAudio.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/tests/asio/rtaudio.dsw b/tests/asio/rtaudio.dsw
new file mode 100755 (executable)
index 0000000..c070e92
--- /dev/null
@@ -0,0 +1,101 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00\r
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r
+\r
+###############################################################################\r
+\r
+Project: "call_inout"=.\call_inout.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "call_saw"=.\call_saw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "in_out"=.\in_out.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "info"=.\info.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "play_raw"=.\play_raw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "play_saw"=.\play_saw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Project: "record_raw"=.\record_raw.dsp - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
+Global:\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<3>\r
+{{{\r
+}}}\r
+\r
+###############################################################################\r
+\r
index 2e92eb8074a5d6b9f8914a136315c68f00fe6b90..787a85658a023cf574fbb30360ccb1c6a66c2247 100644 (file)
@@ -37,9 +37,10 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: call_inout N fs\n";
+  cout << "\nuseage: call_inout N fs device\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
@@ -51,19 +52,20 @@ int inout(char *buffer, int buffer_size, void *)
 
 int main(int argc, char *argv[])
 {
-  int device, stream, chans, fs;
+  int stream, chans, fs, device = 0;
   RtAudio *audio;
   char input;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
   int buffer_size = 512;
-  device = 0; // default device
   try {
     audio = new RtAudio(&stream, device, chans, device, chans,
                         FORMAT, fs, &buffer_size, 8);
@@ -80,7 +82,7 @@ int main(int argc, char *argv[])
     goto cleanup;
   }
 
-  cout << "\nRunning ... press <enter> to quit.\n";
+  cout << "\nRunning ... press <enter> to quit (buffer size = " << buffer_size << ").\n";
   cin.get(input);
 
   try {
diff --git a/tests/call_inout.dsp b/tests/call_inout.dsp
deleted file mode 100644 (file)
index b3aef86..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="call_inout" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=call_inout - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_inout.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_inout.mak" CFG="call_inout - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "call_inout - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "call_inout - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "call_inout - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "call_inout___Win32_Release"\r
-# PROP BASE Intermediate_Dir "call_inout___Win32_Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "call_inout - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "call_inout___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "call_inout___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "call_inout - Win32 Release"\r
-# Name "call_inout - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\call_inout.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
diff --git a/tests/call_playtwo.cpp b/tests/call_playtwo.cpp
new file mode 100644 (file)
index 0000000..4364262
--- /dev/null
@@ -0,0 +1,178 @@
+/******************************************/
+/*
+  call_playtwo.cpp
+  by Gary P. Scavone, 2002.
+
+  Test executable using two streams with
+  callbacks.
+*/
+/******************************************/
+
+#include "RtAudio.h"
+#include <iostream.h>
+
+/*
+typedef signed long  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_SINT24
+#define SCALE  2147483647.0
+
+typedef char  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_SINT8
+#define SCALE  127.0
+
+typedef signed short  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_SINT16
+#define SCALE  32767.0
+
+typedef signed long  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_SINT32
+#define SCALE  2147483647.0
+
+typedef float  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_FLOAT32
+#define SCALE  1.0
+*/
+
+typedef double  MY_TYPE;
+#define FORMAT RtAudio::RTAUDIO_FLOAT64
+#define SCALE  1.0
+#define BASE_RATE1 0.005
+#define BASE_RATE2 0.004
+
+void usage(void) {
+  /* Error function in case of incorrect command-line
+     argument specifications
+  */
+  cout << "\nuseage: call_twostreams N fs\n";
+  cout << "    where N = number of channels,\n";
+  cout << "    and fs = the sample rate.\n\n";
+  exit(0);
+}
+
+int chans;
+
+int saw1(char *buffer, int buffer_size, void *data)
+{
+  int i, j;
+  extern int chans;
+  MY_TYPE *my_buffer = (MY_TYPE *) buffer;
+  double *my_data = (double *) data;
+
+  for (i=0; i<buffer_size; i++) {
+    for (j=0; j<chans; j++) {
+      *my_buffer++ = (MY_TYPE) (my_data[j] * SCALE);
+      my_data[j] += BASE_RATE1 * (j+1+(j*0.1));
+      if (my_data[j] >= 1.0) my_data[j] -= 2.0;
+    }
+  }
+
+  return 0;
+}
+
+int saw2(char *buffer, int buffer_size, void *data)
+{
+  int i, j;
+  extern int chans;
+  MY_TYPE *my_buffer = (MY_TYPE *) buffer;
+  double *my_data = (double *) data;
+
+  for (i=0; i<buffer_size; i++) {
+    for (j=0; j<chans; j++) {
+      *my_buffer++ = (MY_TYPE) (my_data[j] * SCALE);
+      my_data[j] += BASE_RATE2 * (j+1+(j*0.1));
+      if (my_data[j] >= 1.0) my_data[j] -= 2.0;
+    }
+  }
+
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+  int device, buffer_size, stream1 = 0, stream2 = 0, fs;
+  double *data1 = 0;
+  double *data2 = 0;
+  RtAudio *audio;
+  char input;
+
+  // minimal command-line checking
+  if (argc != 3) usage();
+
+  chans = (int) atoi(argv[1]);
+  fs = (int) atoi(argv[2]);
+
+  // Open the realtime output device
+  buffer_size = 512;
+  device = 0; // default device
+  try {
+    audio = new RtAudio();
+  }
+  catch (RtError &) {
+    exit(EXIT_FAILURE);
+  }
+
+  try {
+    stream1 = audio->openStream(device, chans, 0, 0,
+                                FORMAT, fs, &buffer_size, 8);
+    stream2 = audio->openStream(device, chans, 0, 0,
+                                FORMAT, fs, &buffer_size, 8);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
+  data1 = (double *) calloc(chans, sizeof(double));
+  data2 = (double *) calloc(chans, sizeof(double));
+
+  try {
+    audio->setStreamCallback(stream1, &saw1, (void *)data1);
+    audio->setStreamCallback(stream2, &saw2, (void *)data2);
+    audio->startStream(stream1);
+    audio->startStream(stream2);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
+  cout << "\nRunning two streams ... press <enter> to quit.\n";
+  cin.get(input);
+
+  cout << "\nStopping both streams.\n";
+  try {
+    audio->stopStream(stream1);
+    audio->stopStream(stream2);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
+  cout << "\nPress <enter> to restart streams:\n";
+  cin.get(input);
+
+  try {
+    audio->startStream(stream1);
+    audio->startStream(stream2);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
+  cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n";
+  cin.get(input);
+
+  try {
+    audio->stopStream(stream1);
+    audio->stopStream(stream2);
+  }
+  catch (RtError &) {
+  }
+
+ cleanup:
+  audio->closeStream(stream1);
+  audio->closeStream(stream2);
+  delete audio;
+  if (data1) free(data1);
+  if (data2) free(data2);
+
+  return 0;
+}
index af5c9e100e0315f2dbc31687413c371c82a8a3d4..fa1ca6594940876c3cf7ba85a078cfbc2ae6d6e2 100644 (file)
@@ -46,9 +46,10 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: call_saw N fs\n";
+  cout << "\nuseage: call_saw N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
@@ -74,20 +75,21 @@ int saw(char *buffer, int buffer_size, void *data)
 
 int main(int argc, char *argv[])
 {
-  int device, stream, buffer_size, fs;
+  int stream, buffer_size, fs, device = 0;
   RtAudio *audio;
   double *data;
   char input;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
-  buffer_size = 256;
-  device = 0; // default device
+  buffer_size = 1024;
   try {
     audio = new RtAudio(&stream, device, chans, 0, 0,
                         FORMAT, fs, &buffer_size, 4);
@@ -106,7 +108,7 @@ int main(int argc, char *argv[])
     goto cleanup;
   }
 
-  cout << "\nPlaying ... press <enter> to quit.\n";
+  cout << "\nPlaying ... press <enter> to quit (buffer size = " << buffer_size << ").\n";
   cin.get(input);
 
   // Stop the stream.
diff --git a/tests/call_saw.dsp b/tests/call_saw.dsp
deleted file mode 100644 (file)
index f86b0b0..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="call_saw" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=call_saw - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_saw.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_saw.mak" CFG="call_saw - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "call_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "call_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "call_saw - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "call_saw___Win32_Release"\r
-# PROP BASE Intermediate_Dir "call_saw___Win32_Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "call_saw - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "call_saw___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "call_saw___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "call_saw - Win32 Release"\r
-# Name "call_saw - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\call_saw.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index f13343a5747b99173e89240dfbce8a30da93b1ec..4af0eacad56018bea974bcec12155d33b51f548f 100644 (file)
@@ -3,7 +3,7 @@
   twostreams.cpp
   by Gary P. Scavone, 2001
 
-  Text executable using two streams with
+  Test executable using two streams with
   callbacks.
 */
 /******************************************/
@@ -41,9 +41,10 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: call_twostreams N fs\n";
+  cout << "\nuseage: call_twostreams N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
@@ -75,20 +76,21 @@ int out(char *buffer, int buffer_size, void *data)
 
 int main(int argc, char *argv[])
 {
-  int device, buffer_size, stream1, stream2, fs;
+  int buffer_size, stream1 = 0, stream2 = 0, fs, device = 0;
   MY_TYPE *data = 0;
   RtAudio *audio;
   char input;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
   buffer_size = 512;
-  device = 0; // default device
   try {
     audio = new RtAudio();
   }
diff --git a/tests/call_twostreams.dsp b/tests/call_twostreams.dsp
deleted file mode 100644 (file)
index 3e47390..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="call_twostreams" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=call_twostreams - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_twostreams.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "call_twostreams.mak" CFG="call_twostreams - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "call_twostreams - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "call_twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "call_twostreams - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "call_twostreams___Win32_Release"\r
-# PROP BASE Intermediate_Dir "call_twostreams___Win32_Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "call_twostreams - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "call_twostreams___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "call_twostreams___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "call_twostreams - Win32 Release"\r
-# Name "call_twostreams - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\call_twostreams.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index 131d57bf878b410c5c196fa53f6e95d108fcb4ad..053f620561e036e8335628819942c21608a17a4a 100644 (file)
@@ -39,28 +39,30 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: in_out N fs\n";
+  cout << "\nuseage: in_out N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
 int main(int argc, char *argv[])
 {
-  int chans, fs, device, buffer_size, stream;
+  int chans, fs, buffer_size, stream, device = 0;
   long frames, counter = 0;
   MY_TYPE *buffer;
   RtAudio *audio;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
   buffer_size = 512;
-  device = 0; // default device
   try {
     audio = new RtAudio(&stream, device, chans, device, chans,
                         FORMAT, fs, &buffer_size, 8);
diff --git a/tests/in_out.dsp b/tests/in_out.dsp
deleted file mode 100644 (file)
index ef5e0d9..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="in_out" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=in_out - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "in_out.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "in_out.mak" CFG="in_out - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "in_out - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "in_out - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "in_out - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "in_out___Win32_Release"\r
-# PROP BASE Intermediate_Dir "in_out___Win32_Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "in_out - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "in_out___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "in_out___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "in_out - Win32 Release"\r
-# Name "in_out - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\in_out.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index 9cd97387ab8995fc830c0f0b485debf8270ab8d8..fdde04982dc3d0e68691e9bbda49c1c4345fdd13 100644 (file)
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
   int devices = audio->getDeviceCount();
   cout << "\nFound " << devices << " devices ...\n";
 
-  for (int i=0; i<devices; i++) {
+  for (int i=1; i<=devices; i++) {
     try {
       audio->getDeviceInfo(i, &my_info);
     }
@@ -35,29 +35,32 @@ int main(int argc, char *argv[])
     }
 
     cout << "\nname = " << my_info.name << '\n';
-    if (my_info.probed == true)
+    if (my_info.probed == true) {
       cout << "probe successful\n";
+      cout << "maxOutputChans = " << my_info.maxOutputChannels << '\n';
+      cout << "minOutputChans = " << my_info.minOutputChannels << '\n';
+      cout << "maxInputChans = " << my_info.maxInputChannels << '\n';
+      cout << "minInputChans = " << my_info.minInputChannels << '\n';
+      cout << "maxDuplexChans = " << my_info.maxDuplexChannels << '\n';
+      cout << "minDuplexChans = " << my_info.minDuplexChannels << '\n';
+      if (my_info.hasDuplexSupport) cout << "duplex support = true\n";
+      else cout << "duplex support = false\n";
+      if (my_info.isDefault) cout << "is default device = true\n";
+      else cout << "is default device = false\n";
+      cout << "format = " << my_info.nativeFormats << '\n';
+      if (my_info.nSampleRates == -1) {
+        cout << "min_srate = " << my_info.sampleRates[0];
+        cout << ", max_srate = " << my_info.sampleRates[1] << '\n';
+      }
+      else {
+        cout << "sample rates = ";
+        for (int j=0; j<my_info.nSampleRates; j++)
+          cout << my_info.sampleRates[j] << " ";
+        cout << endl;
+      }
+    }
     else
       cout << "probe unsuccessful\n";
-    cout << "maxOutputChans = " << my_info.maxOutputChannels << '\n';
-    cout << "minOutputChans = " << my_info.minOutputChannels << '\n';
-    cout << "maxInputChans = " << my_info.maxInputChannels << '\n';
-    cout << "minInputChans = " << my_info.minInputChannels << '\n';
-    cout << "maxDuplexChans = " << my_info.maxDuplexChannels << '\n';
-    cout << "minDuplexChans = " << my_info.minDuplexChannels << '\n';
-    if (my_info.hasDuplexSupport)
-      cout << "duplex support = true\n";
-    else
-      cout << "duplex support = false\n";
-    cout << "format = " << my_info.nativeFormats << '\n';
-    if (my_info.nSampleRates == -1)
-      cout << "min_srate = " << my_info.sampleRates[0] << ", max_srate = " << my_info.sampleRates[1] << '\n';
-    else {
-      cout << "sample rates = ";
-      for (int j=0; j<my_info.nSampleRates; j++)
-        cout << my_info.sampleRates[j] << " ";
-      cout << endl;
-    }
   }
   cout << endl;
 
diff --git a/tests/info.dsp b/tests/info.dsp
deleted file mode 100644 (file)
index f285f23..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="info" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=info - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "info.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "info.mak" CFG="info - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "info - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "info - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "info - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "info - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "info___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "info___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "info - Win32 Release"\r
-# Name "info - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\info.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index b616571a343baa99200087f7988e50829ebfb983..f10347486671f40dbc15419db8a4cc373996b9bc 100644 (file)
@@ -29,30 +29,33 @@ typedef signed long  MY_TYPE;
 typedef signed long  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT32
 #define SCALE  2147483647.0
+*/
 
 typedef float  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT32
 #define SCALE  1.0;
-*/
 
+/*
 typedef double  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT64
 #define SCALE  1.0;
+*/
 
 void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: play_raw N fs file\n";
+  cout << "\nuseage: play_raw N fs file <device>\n";
   cout << "    where N = number of channels,\n";
   cout << "    fs = the sample rate, \n";
-  cout << "    and file = the raw file to play.\n\n"; 
+  cout << "    file = the raw file to play,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
 int main(int argc, char *argv[])
 {
-  int chans, fs, device, buffer_size, count, stream;
+  int chans, fs, buffer_size, count, stream, device = 0;
   long counter = 0;
   MY_TYPE *buffer;
   char *file;
@@ -60,11 +63,13 @@ int main(int argc, char *argv[])
   RtAudio *audio;
 
   // minimal command-line checking
-  if (argc != 4) usage();
+  if (argc != 4 && argc != 5 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
   file = argv[3];
+  if ( argc == 5 )
+    device = (int) atoi(argv[4]);
 
   fd = fopen(file,"rb");
   if (!fd) {
@@ -73,8 +78,7 @@ int main(int argc, char *argv[])
   }
 
   // Open the realtime output device
-  buffer_size = 256;
-  device = 0; // default device
+  buffer_size = 512;
   try {
     audio = new RtAudio(&stream, device, chans, 0, 0,
                         FORMAT, fs, &buffer_size, 2);
diff --git a/tests/play_raw.dsp b/tests/play_raw.dsp
deleted file mode 100644 (file)
index e01119f..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="play_raw" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=play_raw - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "play_raw.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "play_raw.mak" CFG="play_raw - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "play_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "play_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "play_raw - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "play_raw - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "play_raw___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "play_raw___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "play_raw - Win32 Release"\r
-# Name "play_raw - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\play_raw.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index 1b0d3bbe3bf1138ff72dcc3e6fa611aaf34bcc3e..d028be5f4b28984bec293732045e2925b4b6956a 100644 (file)
 typedef signed long  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT24
 #define SCALE  2147483647.0
+*/
 
 typedef char  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT8
 #define SCALE  127.0
 
+/*
 typedef signed short  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT16
 #define SCALE  32767.0
 
+
 typedef signed long  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT32
 #define SCALE  2147483647.0
-*/
+
 typedef float  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT32
 #define SCALE  1.0
 
-/*
 typedef double  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT64
 #define SCALE  1.0
@@ -43,32 +45,33 @@ typedef double  MY_TYPE;
 #define TIME   1.0
 
 void usage(void) {
-  /* Error function in case of incorrect command-line
-     argument specifications
-  */
-  cout << "\nuseage: play_saw N fs\n";
+  // Error function in case of incorrect command-line
+  // argument specifications.
+  cout << "\nuseage: play_saw N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
 int main(int argc, char *argv[])
 {
-  int chans, fs, device, buffer_size, stream;
+  int chans, fs, buffer_size, stream, device = 0;
   long frames, counter = 0, i, j;
   MY_TYPE *buffer;
   RtAudio *audio;
   double *data;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
-  buffer_size = 256;
-  device = 0; // default device
+  buffer_size = 512;
   try {
     audio = new RtAudio(&stream, device, chans, 0, 0,
                         FORMAT, fs, &buffer_size, 4);
@@ -88,7 +91,7 @@ int main(int argc, char *argv[])
     goto cleanup;
   }
 
-  cout << "\nPlaying for " << TIME << " seconds." << endl;
+  cout << "\nPlaying for " << TIME << " seconds ... buffer size = " << buffer_size << "." << endl;
   while (counter < frames) {
     for (i=0; i<buffer_size; i++) {
       for (j=0; j<chans; j++) {
diff --git a/tests/play_saw.dsp b/tests/play_saw.dsp
deleted file mode 100644 (file)
index 6e3f4ec..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="play_saw" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=play_saw - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "play_saw.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "play_saw.mak" CFG="play_saw - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "play_saw - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "play_saw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "play_saw - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "play_saw - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "play_saw___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "play_saw___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "play_saw - Win32 Release"\r
-# Name "play_saw - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\play_saw.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index 04041ee155117d8d7d659cb00557699f09579b1a..1b7964498a4b7b2eeb53479ca5cb632d93cc7290 100644 (file)
@@ -10,6 +10,7 @@
 /******************************************/
 
 #include "RtAudio.h"
+#include <iostream.h>
 #include <stdio.h>
 
 /*
@@ -24,13 +25,15 @@ typedef signed long  MY_TYPE;
 
 typedef signed long  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT32
+*/
 
 typedef float  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT32
-*/
 
+/*
 typedef double  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT64
+*/
 
 #define TIME   2.0
 
@@ -38,29 +41,31 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: record_raw N fs\n";
+  cout << "\nuseage: record_raw N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
 int main(int argc, char *argv[])
 {
-  int chans, fs, device, buffer_size, stream;
+  int chans, fs, buffer_size, stream, device = 0;
   long frames, counter = 0;
   MY_TYPE *buffer;
   FILE *fd;
   RtAudio *audio;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
   buffer_size = 512;
-  device = 0; // default device
   try {
     audio = new RtAudio(&stream, 0, 0, device, chans,
                         FORMAT, fs, &buffer_size, 8);
@@ -80,7 +85,7 @@ int main(int argc, char *argv[])
     goto cleanup;
   }
 
-  cout << "\nRecording for " << TIME << " seconds ... writing file test.raw." << endl;
+  cout << "\nRecording for " << TIME << " seconds ... writing file test.raw (buffer size = " << buffer_size << ")." << endl;
   while (counter < frames) {
 
     try {
diff --git a/tests/record_raw.dsp b/tests/record_raw.dsp
deleted file mode 100644 (file)
index f3a6050..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="record_raw" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=record_raw - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "record_raw.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "record_raw.mak" CFG="record_raw - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "record_raw - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "record_raw - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "record_raw - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "Release"\r
-# PROP BASE Intermediate_Dir "Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "record_raw - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "record_raw___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "record_raw___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "record_raw - Win32 Release"\r
-# Name "record_raw - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=.\record_raw.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r
index 2356a5fb978b3d4fb3699721945052ca4e19123a..94a036cd5ae65bcc3f0dca2ea1885be8251d53a9 100644 (file)
@@ -3,7 +3,7 @@
   twostreams.cpp
   by Gary P. Scavone, 2001
 
-  Text executable for audio playback,
+  Test executable for audio playback,
   recording, duplex operation, stopping,
   starting, and aborting operations.
   Takes number of channels and sample
@@ -33,15 +33,17 @@ typedef signed short  MY_TYPE;
 typedef signed long  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_SINT32
 #define SCALE  2147483647.0
+*/
 
 typedef float  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT32
 #define SCALE  1.0
-*/
 
+/*
 typedef double  MY_TYPE;
 #define FORMAT RtAudio::RTAUDIO_FLOAT64
 #define SCALE  1.0
+*/
 
 #define BASE_RATE 0.005
 #define TIME 2.0
@@ -50,30 +52,32 @@ void usage(void) {
   /* Error function in case of incorrect command-line
      argument specifications
   */
-  cout << "\nuseage: twostreams N fs\n";
+  cout << "\nuseage: twostreams N fs <device>\n";
   cout << "    where N = number of channels,\n";
-  cout << "    and fs = the sample rate.\n\n";
+  cout << "    fs = the sample rate,\n";
+  cout << "    and device = the device to use (default = 0).\n\n";
   exit(0);
 }
 
 int main(int argc, char *argv[])
 {
-  int chans, fs, device, buffer_size, stream1, stream2;
+  int chans, fs, buffer_size, stream1 = 0, stream2 = 0, device = 0;
   long frames, counter = 0, i, j;
   MY_TYPE *buffer1, *buffer2;
   RtAudio *audio;
   FILE *fd;
-  double *data;
+  double *data = 0;
 
   // minimal command-line checking
-  if (argc != 3) usage();
+  if (argc != 3 && argc != 4 ) usage();
 
   chans = (int) atoi(argv[1]);
   fs = (int) atoi(argv[2]);
+  if ( argc == 4 )
+    device = (int) atoi(argv[3]);
 
   // Open the realtime output device
   buffer_size = 512;
-  device = 0; // default device
   try {
     audio = new RtAudio();
   }
@@ -86,6 +90,12 @@ int main(int argc, char *argv[])
                                 FORMAT, fs, &buffer_size, 8);
     stream2 = audio->openStream(0, 0, device, chans,
                                 FORMAT, fs, &buffer_size, 8);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
+  try {
     buffer1 = (MY_TYPE *) audio->getStreamBuffer(stream1);
     buffer2 = (MY_TYPE *) audio->getStreamBuffer(stream2);
   }
@@ -126,7 +136,6 @@ int main(int argc, char *argv[])
   cout << "\nStopping playback stream." << endl;
   try {
     audio->stopStream(stream1);
-    audio->startStream(stream2);
   }
   catch (RtError &) {
     goto cleanup;
@@ -134,6 +143,13 @@ int main(int argc, char *argv[])
 
   fd = fopen("test.raw","wb");
 
+  try {
+    audio->startStream(stream2);
+  }
+  catch (RtError &) {
+    goto cleanup;
+  }
+
   counter = 0;
   cout << "\nStarting recording stream for " << TIME << " seconds." << endl;
   while (counter < frames) {
diff --git a/tests/twostreams.dsp b/tests/twostreams.dsp
deleted file mode 100644 (file)
index 8e7820a..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-# Microsoft Developer Studio Project File - Name="twostreams" - Package Owner=<4>\r
-# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
-# ** DO NOT EDIT **\r
-\r
-# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
-\r
-CFG=twostreams - Win32 Debug\r
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
-!MESSAGE use the Export Makefile command and run\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "twostreams.mak".\r
-!MESSAGE \r
-!MESSAGE You can specify a configuration when running NMAKE\r
-!MESSAGE by defining the macro CFG on the command line. For example:\r
-!MESSAGE \r
-!MESSAGE NMAKE /f "twostreams.mak" CFG="twostreams - Win32 Debug"\r
-!MESSAGE \r
-!MESSAGE Possible choices for configuration are:\r
-!MESSAGE \r
-!MESSAGE "twostreams - Win32 Release" (based on "Win32 (x86) Console Application")\r
-!MESSAGE "twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")\r
-!MESSAGE \r
-\r
-# Begin Project\r
-# PROP AllowPerConfigDependencies 0\r
-# PROP Scc_ProjName ""\r
-# PROP Scc_LocalPath ""\r
-CPP=cl.exe\r
-RSC=rc.exe\r
-\r
-!IF  "$(CFG)" == "twostreams - Win32 Release"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 0\r
-# PROP BASE Output_Dir "twostreams___Win32_Release"\r
-# PROP BASE Intermediate_Dir "twostreams___Win32_Release"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 0\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Release"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c\r
-# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /d "NDEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386\r
-\r
-!ELSEIF  "$(CFG)" == "twostreams - Win32 Debug"\r
-\r
-# PROP BASE Use_MFC 0\r
-# PROP BASE Use_Debug_Libraries 1\r
-# PROP BASE Output_Dir "twostreams___Win32_Debug"\r
-# PROP BASE Intermediate_Dir "twostreams___Win32_Debug"\r
-# PROP BASE Target_Dir ""\r
-# PROP Use_MFC 0\r
-# PROP Use_Debug_Libraries 1\r
-# PROP Output_Dir ""\r
-# PROP Intermediate_Dir "Debug"\r
-# PROP Ignore_Export_Lib 0\r
-# PROP Target_Dir ""\r
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c\r
-# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
-# ADD RSC /l 0x409 /d "_DEBUG"\r
-BSC32=bscmake.exe\r
-# ADD BASE BSC32 /nologo\r
-# ADD BSC32 /nologo\r
-LINK32=link.exe\r
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
-\r
-!ENDIF \r
-\r
-# Begin Target\r
-\r
-# Name "twostreams - Win32 Release"\r
-# Name "twostreams - Win32 Debug"\r
-# Begin Group "Source Files"\r
-\r
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.cpp\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\twostreams.cpp\r
-# End Source File\r
-# End Group\r
-# Begin Group "Header Files"\r
-\r
-# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
-# Begin Source File\r
-\r
-SOURCE=..\RtAudio.h\r
-# End Source File\r
-# End Group\r
-# Begin Group "Resource Files"\r
-\r
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
-# End Group\r
-# End Target\r
-# End Project\r