Various WASAPI-related changes.
authorGary Scavone <gary@music.mcgill.ca>
Wed, 2 Apr 2014 17:06:01 +0000 (13:06 -0400)
committerGary Scavone <gary@music.mcgill.ca>
Wed, 2 Apr 2014 17:06:01 +0000 (13:06 -0400)
RtAudio.cpp
RtAudio.h
tests/audioprobe.cpp
tests/playraw.cpp
tests/playsaw.cpp
tests/record.cpp
tests/teststops.cpp

index d65a7acec0e3195a32ef5ad874cd7bad2cc4b9fa..c5a2a87afd99ed280a9881a3c8a89d348cbdb6aa 100644 (file)
@@ -159,7 +159,7 @@ void RtAudio :: openRtApi( RtAudio::Api api )
 #endif\r
 }\r
 \r
-RtAudio :: RtAudio( RtAudio::Api api ) throw()\r
+RtAudio :: RtAudio( RtAudio::Api api )\r
 {\r
   rtapi_ = 0;\r
 \r
@@ -3576,7 +3576,6 @@ static const char* getAsioErrorString( ASIOError result )
 \r
 #if defined(__WINDOWS_WASAPI__) // Windows WASAPI API\r
 \r
-#include "RtWasapi.inl"\r
 #include <audioclient.h>\r
 #include <avrt.h>\r
 #include <functiondiscoverykeys.h>\r
@@ -3585,7 +3584,7 @@ static const char* getAsioErrorString( ASIOError result )
 //=============================================================================\r
 \r
 #define EXIT_ON_ERROR( hr, errorType, errorText )\\r
-if( FAILED( hr ) )\\r
+if ( FAILED( hr ) )\\r
 {\\r
   errorText_ = __FUNCTION__ ": " errorText;\\r
   error( errorType );\\r
@@ -3593,7 +3592,7 @@ if( FAILED( hr ) )\
 }\r
 \r
 #define SAFE_RELEASE( objectPtr )\\r
-if( objectPtr )\\r
+if ( objectPtr )\\r
 {\\r
   objectPtr->Release();\\r
   objectPtr = NULL;\\r
@@ -3634,23 +3633,21 @@ public:
   // attempt to push a buffer into the ring buffer at the current "in" index\r
   bool pushBuffer( char* buffer, unsigned int bufferSize, RtAudioFormat format )\r
   {\r
-    if( !buffer ||                 // incoming buffer is NULL\r
-        bufferSize == 0 ||         // incoming buffer has no data\r
-        bufferSize > bufferSize_ ) // incoming buffer too large\r
+    if ( !buffer ||                 // incoming buffer is NULL\r
+         bufferSize == 0 ||         // incoming buffer has no data\r
+         bufferSize > bufferSize_ ) // incoming buffer too large\r
     {\r
       return false;\r
     }\r
 \r
     unsigned int relOutIndex = outIndex_;\r
     unsigned int inIndexEnd = inIndex_ + bufferSize;\r
-    if( relOutIndex < inIndex_ && inIndexEnd >= bufferSize_ )\r
-    {\r
+    if ( relOutIndex < inIndex_ && inIndexEnd >= bufferSize_ ) {\r
       relOutIndex += bufferSize_;\r
     }\r
 \r
     // "in" index can end on the "out" index but cannot begin at it\r
-    if( inIndex_ <= relOutIndex && inIndexEnd > relOutIndex )\r
-    {\r
+    if ( inIndex_ <= relOutIndex && inIndexEnd > relOutIndex ) {\r
       return false; // not enough space between "in" index and "out" index\r
     }\r
 \r
@@ -3697,23 +3694,21 @@ public:
   // attempt to pull a buffer from the ring buffer from the current "out" index\r
   bool pullBuffer( char* buffer, unsigned int bufferSize, RtAudioFormat format )\r
   {\r
-    if( !buffer ||                 // incoming buffer is NULL\r
-        bufferSize == 0 ||         // incoming buffer has no data\r
-        bufferSize > bufferSize_ ) // incoming buffer too large\r
+    if ( !buffer ||                 // incoming buffer is NULL\r
+         bufferSize == 0 ||         // incoming buffer has no data\r
+         bufferSize > bufferSize_ ) // incoming buffer too large\r
     {\r
       return false;\r
     }\r
 \r
     unsigned int relInIndex = inIndex_;\r
     unsigned int outIndexEnd = outIndex_ + bufferSize;\r
-    if( relInIndex < outIndex_ && outIndexEnd >= bufferSize_ )\r
-    {\r
+    if ( relInIndex < outIndex_ && outIndexEnd >= bufferSize_ ) {\r
       relInIndex += bufferSize_;\r
     }\r
 \r
     // "out" index can begin at and end on the "in" index\r
-    if( outIndex_ < relInIndex && outIndexEnd > relInIndex )\r
-    {\r
+    if ( outIndex_ < relInIndex && outIndexEnd > relInIndex ) {\r
       return false; // not enough space between "out" index and "in" index\r
     }\r
 \r
@@ -3791,11 +3786,11 @@ void convertBufferWasapi( char* outBuffer,
   outSampleCount = ( unsigned int ) ( inSampleCount * sampleRatio );\r
 \r
   // frame-by-frame, copy each relative input sample into it's corresponding output sample\r
-  for( unsigned int outSample = 0; outSample < outSampleCount; outSample++ )\r
+  for ( unsigned int outSample = 0; outSample < outSampleCount; outSample++ )\r
   {\r
     unsigned int inSample = ( unsigned int ) inSampleFraction;\r
 \r
-    switch( format )\r
+    switch ( format )\r
     {\r
       case RTAUDIO_SINT8:\r
         memcpy( &( ( char* ) outBuffer )[ outSample * outChannelCount ], &( ( char* ) inBuffer )[ inSample * inChannelCount ], commonChannelCount * sizeof( char ) );\r
@@ -3851,7 +3846,7 @@ RtApiWasapi::RtApiWasapi()
   // WASAPI can run either apartment or multi-threaded\r
   HRESULT hr = CoInitialize( NULL );\r
 \r
-  if( !FAILED( hr ) )\r
+  if ( !FAILED( hr ) )\r
     coInitialized_ = true;\r
 \r
   // instantiate device enumerator\r
@@ -3859,7 +3854,7 @@ RtApiWasapi::RtApiWasapi()
                          CLSCTX_ALL, __uuidof( IMMDeviceEnumerator ),\r
                          ( void** ) &deviceEnumerator_ );\r
 \r
-  if( FAILED( hr ) ) {\r
+  if ( FAILED( hr ) ) {\r
     errorText_ = "RtApiWasapi::RtApiWasapi: Unable to instantiate device enumerator";\r
     error( RtAudioError::DRIVER_ERROR );\r
   }\r
@@ -3870,13 +3865,11 @@ RtApiWasapi::RtApiWasapi()
 RtApiWasapi::~RtApiWasapi()\r
 {\r
   // if this object previously called CoInitialize()\r
-  if( coInitialized_ )\r
-  {\r
+  if ( coInitialized_ ) {\r
     CoUninitialize();\r
   }\r
 \r
-  if( stream_.state != STREAM_CLOSED )\r
-  {\r
+  if ( stream_.state != STREAM_CLOSED ) {\r
     closeStream();\r
   }\r
 \r
@@ -3962,14 +3955,17 @@ RtAudio::DeviceInfo RtApiWasapi::getDeviceInfo( unsigned int device )
     EXIT_ON_ERROR( -1, RtAudioError::INVALID_USE, "Invalid device index" );\r
 \r
   // determine whether index falls within capture or render devices\r
-  if ( device < captureDeviceCount ) {\r
-    hr = captureDevices->Item( device, &devicePtr );\r
+  //if ( device < captureDeviceCount ) {\r
+  if ( device >= renderDeviceCount ) {\r
+    //hr = captureDevices->Item( device, &devicePtr );\r
+    hr = captureDevices->Item( device - renderDeviceCount, &devicePtr );\r
     EXIT_ON_ERROR( hr, RtAudioError::DRIVER_ERROR, "Unable to retrieve capture device handle" );\r
 \r
     isCaptureDevice = true;\r
   }\r
   else {\r
-    hr = renderDevices->Item( device - captureDeviceCount, &devicePtr );\r
+    //hr = renderDevices->Item( device - captureDeviceCount, &devicePtr );\r
+    hr = renderDevices->Item( device, &devicePtr );\r
     EXIT_ON_ERROR( hr, RtAudioError::DRIVER_ERROR, "Unable to retrieve render device handle" );\r
 \r
     isCaptureDevice = false;\r
@@ -4342,14 +4338,16 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
     EXIT_ON_ERROR( -1, RtAudioError::INVALID_USE, "Invalid device index" );\r
 \r
   // determine whether index falls within capture or render devices\r
-  if ( device < captureDeviceCount ) {\r
+  //if ( device < captureDeviceCount ) {\r
+  if ( device >= renderDeviceCount ) {\r
     if ( mode != INPUT )\r
       EXIT_ON_ERROR( -1, RtAudioError::INVALID_USE, "Capture device selected as output device" );\r
 \r
     // retrieve captureAudioClient from devicePtr\r
     IAudioClient*& captureAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->captureAudioClient;\r
 \r
-    hr = captureDevices->Item( device, &devicePtr );\r
+    //hr = captureDevices->Item( device, &devicePtr );\r
+    hr = captureDevices->Item( device - renderDeviceCount, &devicePtr );\r
     EXIT_ON_ERROR( hr, RtAudioError::DRIVER_ERROR, "Unable to retrieve capture device handle" );\r
 \r
     hr = devicePtr->Activate( __uuidof( IAudioClient ), CLSCTX_ALL,\r
@@ -4369,7 +4367,8 @@ bool RtApiWasapi::probeDeviceOpen( unsigned int device, StreamMode mode, unsigne
     // retrieve renderAudioClient from devicePtr\r
     IAudioClient*& renderAudioClient = ( ( WasapiHandle* ) stream_.apiHandle )->renderAudioClient;\r
 \r
-    hr = renderDevices->Item( device - captureDeviceCount, &devicePtr );\r
+    //hr = renderDevices->Item( device - captureDeviceCount, &devicePtr );\r
+    hr = renderDevices->Item( device, &devicePtr );\r
     EXIT_ON_ERROR( hr, RtAudioError::DRIVER_ERROR, "Unable to retrieve render device handle" );\r
 \r
     hr = devicePtr->Activate( __uuidof( IAudioClient ), CLSCTX_ALL,\r
@@ -4913,7 +4912,8 @@ Exit:
   CoTaskMemFree( captureFormat );\r
   CoTaskMemFree( renderFormat );\r
 \r
-  delete convBuffer;\r
+  //delete convBuffer;\r
+  free ( convBuffer );\r
 \r
   CoUninitialize();\r
 \r
index ecb9b6a5bd3716832ef68d70ccc868a6ec0d5e64..a85578ef3766304e7a940f185bc09db7b5c92fd2 100644 (file)
--- a/RtAudio.h
+++ b/RtAudio.h
@@ -386,14 +386,14 @@ class RtAudio
 
   //! The class constructor.
   /*!
-    The constructor performs minor initialization tasks.  No exceptions
-    can be thrown.
+    The constructor performs minor initialization tasks.  An exception
+    can be thrown if no API support is compiled.
 
     If no API argument is specified and multiple API support has been
     compiled, the default order of use is JACK, ALSA, OSS (Linux
     systems) and ASIO, DS (Windows systems).
   */
-  RtAudio( RtAudio::Api api=UNSPECIFIED ) throw();
+  RtAudio( RtAudio::Api api=UNSPECIFIED );
 
   //! The destructor.
   /*!
index a69437f97db13b87de15b19f333d2b7ab0c4a6c8..1b93908748e3d8dd8ed5d3484e8d39bd223504ea 100644 (file)
@@ -18,6 +18,7 @@ int main()
   apiMap[RtAudio::MACOSX_CORE] = "OS-X Core Audio";
   apiMap[RtAudio::WINDOWS_ASIO] = "Windows ASIO";
   apiMap[RtAudio::WINDOWS_DS] = "Windows Direct Sound";
+  apiMap[RtAudio::WINDOWS_WASAPI] = "Windows WASAPI";
   apiMap[RtAudio::UNIX_JACK] = "Jack Client";
   apiMap[RtAudio::LINUX_ALSA] = "Linux ALSA";
   apiMap[RtAudio::LINUX_PULSE] = "Linux PulseAudio";
index 03212d78d332e0cf0c4345961f9e439fd780c26c..75e7d130410cbe22d8eeebce4928d76107f555d2 100644 (file)
@@ -44,7 +44,7 @@ typedef double  MY_TYPE;
 */
 
 // Platform-dependent sleep routines.
-#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )
+#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) || defined( __WINDOWS_WASAPI__ )
   #include <windows.h>
   #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
 #else // Unix variants
index dc36d4c3455cc34d34e25ab135590b77cee0175d..2be179bb1145a5500c53acfb89a29850333b14ba 100644 (file)
@@ -41,7 +41,7 @@ typedef double MY_TYPE;
 */
 
 // Platform-dependent sleep routines.
-#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )
+#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) || defined( __WINDOWS_WASAPI__ )
   #include <windows.h>
   #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
 #else // Unix variants
index 56b59b4eb1b30932e86b50471efdb37416291c69..d16ea4955efac57ea451753696fb2a88dbfdb863 100644 (file)
@@ -38,7 +38,7 @@ typedef double MY_TYPE;
 */
 
 // Platform-dependent sleep routines.
-#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )
+#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) || defined( __WINDOWS_WASAPI__ )
   #include <windows.h>
   #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
 #else // Unix variants
index 2cfccb49b7ad2501d07b3ec9b08a812e89363824..5c6ed384f85907331577ee7d69e99a9b0555482d 100644 (file)
@@ -21,7 +21,7 @@
 #define REPETITIONS 10\r
 \r
 // Platform-dependent sleep routines.\r
-#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )\r
+#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) || defined( __WINDOWS_WASAPI__ )\r
   #include <windows.h>\r
   #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) \r
 #else // Unix variants\r