Bug fix in Core, Jack, ASIO, and DS for internal draining in INPUT mode only; Added...
authorGary Scavone <gary@music.mcgill.ca>
Fri, 25 Apr 2014 02:36:42 +0000 (22:36 -0400)
committerGary Scavone <gary@music.mcgill.ca>
Fri, 25 Apr 2014 02:36:42 +0000 (22:36 -0400)
CMakeLists.txt
RtAudio.cpp

index 136ab8d89102071f1d9a27818d642f13e9bdd257..8c8ccf87f34b47206507dd0d56a3904fa7297a54 100644 (file)
@@ -91,15 +91,17 @@ if (WIN32)
     endif()
 
     include_directories(include)
-    list(APPEND LINKLIBS dsound winmm ole32)
+    list(APPEND LINKLIBS winmm ole32)
 
     if (AUDIO_WINDOWS_DS)
         add_definitions(-D__WINDOWS_DS__)
         message(STATUS "Using Windows DirectSound")
+        list(APPEND LINKLIBS dsound)
     endif (AUDIO_WINDOWS_DS)
     if (AUDIO_WINDOWS_WASAPI)
         add_definitions(-D__WINDOWS_WASAPI__)
         message(STATUS "Using Windows WASAPI")
+        list(APPEND LINKLIBS uuid ksuser)
     endif (AUDIO_WINDOWS_WASAPI)
     if (AUDIO_WINDOWS_ASIO)
         list(APPEND rtaudio_SOURCES
index 28e80202a8545508348da86c27d390b1a2336d2d..039b5d03a362d74fcbae609a7d2b534022549ccc 100644 (file)
@@ -1682,11 +1682,12 @@ bool RtApiCore :: callbackEvent( AudioDeviceID deviceId,
         }\r
       }\r
     }\r
+  }\r
 \r
-    if ( handle->drainCounter ) {\r
-      handle->drainCounter++;\r
-      goto unlock;\r
-    }\r
+  // Don't bother draining input\r
+  if ( handle->drainCounter ) {\r
+    handle->drainCounter++;\r
+    goto unlock;\r
   }\r
 \r
   AudioDeviceID inputDevice;\r
@@ -2572,11 +2573,12 @@ bool RtApiJack :: callbackEvent( unsigned long nframes )
         memcpy( jackbuffer, &stream_.userBuffer[0][i*bufferBytes], bufferBytes );\r
       }\r
     }\r
+  }\r
 \r
-    if ( handle->drainCounter ) {\r
-      handle->drainCounter++;\r
-      goto unlock;\r
-    }\r
+  // Don't bother draining input\r
+  if ( handle->drainCounter ) {\r
+    handle->drainCounter++;\r
+    goto unlock;\r
   }\r
 \r
   if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) {\r
@@ -3403,11 +3405,12 @@ bool RtApiAsio :: callbackEvent( long bufferIndex )
       }\r
 \r
     }\r
+  }\r
 \r
-    if ( handle->drainCounter ) {\r
-      handle->drainCounter++;\r
-      goto unlock;\r
-    }\r
+  // Don't bother draining input\r
+  if ( handle->drainCounter ) {\r
+    handle->drainCounter++;\r
+    goto unlock;\r
   }\r
 \r
   if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) {\r
@@ -6063,6 +6066,8 @@ void RtApiDs :: stopStream()
 \r
     stream_.state = STREAM_STOPPED;\r
 \r
+    MUTEX_LOCK( &stream_.mutex );\r
+\r
     // Stop the buffer and clear memory\r
     LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];\r
     result = buffer->Stop();\r
@@ -6103,6 +6108,9 @@ void RtApiDs :: stopStream()
 \r
     stream_.state = STREAM_STOPPED;\r
 \r
+    if ( stream_.mode != DUPLEX )\r
+      MUTEX_LOCK( &stream_.mutex );\r
+\r
     result = buffer->Stop();\r
     if ( FAILED( result ) ) {\r
       errorStream_ << "RtApiDs::stopStream: error (" << getErrorString( result ) << ") stopping input buffer!";\r
@@ -6136,6 +6144,8 @@ void RtApiDs :: stopStream()
 \r
  unlock:\r
   timeEndPeriod( 1 ); // revert to normal scheduler frequency on lesser windows.\r
+  MUTEX_UNLOCK( &stream_.mutex );\r
+\r
   if ( FAILED( result ) ) error( RtAudioError::SYSTEM_ERROR );\r
 }\r
 \r
@@ -6222,6 +6232,12 @@ void RtApiDs :: callbackEvent()
   char *buffer;\r
   long bufferBytes;\r
 \r
+  MUTEX_LOCK( &stream_.mutex );\r
+  if ( stream_.state == STREAM_STOPPED ) {\r
+    MUTEX_UNLOCK( &stream_.mutex );\r
+    return;\r
+  }\r
+\r
   if ( buffersRolling == false ) {\r
     if ( stream_.mode == DUPLEX ) {\r
       //assert( handle->dsBufferSize[0] == handle->dsBufferSize[1] );\r
@@ -6402,11 +6418,12 @@ void RtApiDs :: callbackEvent()
     }\r
     nextWritePointer = ( nextWritePointer + bufferSize1 + bufferSize2 ) % dsBufferSize;\r
     handle->bufferPointer[0] = nextWritePointer;\r
+  }\r
 \r
-    if ( handle->drainCounter ) {\r
-      handle->drainCounter++;\r
-      goto unlock;\r
-    }\r
+  // Don't bother draining input\r
+  if ( handle->drainCounter ) {\r
+    handle->drainCounter++;\r
+    goto unlock;\r
   }\r
 \r
   if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) {\r
@@ -6545,6 +6562,7 @@ void RtApiDs :: callbackEvent()
   }\r
 \r
  unlock:\r
+  MUTEX_UNLOCK( &stream_.mutex );\r
   RtApi::tickStreamTime();\r
 }\r
 \r