From: Gary Scavone Date: Fri, 25 Apr 2014 02:36:42 +0000 (-0400) Subject: Bug fix in Core, Jack, ASIO, and DS for internal draining in INPUT mode only; Added... X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=9a920447e15eeaf8cf8f6002c120e6fb168caa6f;hp=4ca315146dd2b5ddb5fc859dd33c229c6ddd53bf;p=rtaudio-cdist.git Bug fix in Core, Jack, ASIO, and DS for internal draining in INPUT mode only; Added some mutexes in DS to fix input-only errors; Added libraries to CMakeLists.txt for MinGW compile of WASAPI. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 136ab8d..8c8ccf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/RtAudio.cpp b/RtAudio.cpp index 28e8020..039b5d0 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -1682,11 +1682,12 @@ bool RtApiCore :: callbackEvent( AudioDeviceID deviceId, } } } + } - if ( handle->drainCounter ) { - handle->drainCounter++; - goto unlock; - } + // Don't bother draining input + if ( handle->drainCounter ) { + handle->drainCounter++; + goto unlock; } AudioDeviceID inputDevice; @@ -2572,11 +2573,12 @@ bool RtApiJack :: callbackEvent( unsigned long nframes ) memcpy( jackbuffer, &stream_.userBuffer[0][i*bufferBytes], bufferBytes ); } } + } - if ( handle->drainCounter ) { - handle->drainCounter++; - goto unlock; - } + // Don't bother draining input + if ( handle->drainCounter ) { + handle->drainCounter++; + goto unlock; } if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) { @@ -3403,11 +3405,12 @@ bool RtApiAsio :: callbackEvent( long bufferIndex ) } } + } - if ( handle->drainCounter ) { - handle->drainCounter++; - goto unlock; - } + // Don't bother draining input + if ( handle->drainCounter ) { + handle->drainCounter++; + goto unlock; } if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) { @@ -6063,6 +6066,8 @@ void RtApiDs :: stopStream() stream_.state = STREAM_STOPPED; + MUTEX_LOCK( &stream_.mutex ); + // Stop the buffer and clear memory LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0]; result = buffer->Stop(); @@ -6103,6 +6108,9 @@ void RtApiDs :: stopStream() stream_.state = STREAM_STOPPED; + if ( stream_.mode != DUPLEX ) + MUTEX_LOCK( &stream_.mutex ); + result = buffer->Stop(); if ( FAILED( result ) ) { errorStream_ << "RtApiDs::stopStream: error (" << getErrorString( result ) << ") stopping input buffer!"; @@ -6136,6 +6144,8 @@ void RtApiDs :: stopStream() unlock: timeEndPeriod( 1 ); // revert to normal scheduler frequency on lesser windows. + MUTEX_UNLOCK( &stream_.mutex ); + if ( FAILED( result ) ) error( RtAudioError::SYSTEM_ERROR ); } @@ -6222,6 +6232,12 @@ void RtApiDs :: callbackEvent() char *buffer; long bufferBytes; + MUTEX_LOCK( &stream_.mutex ); + if ( stream_.state == STREAM_STOPPED ) { + MUTEX_UNLOCK( &stream_.mutex ); + return; + } + if ( buffersRolling == false ) { if ( stream_.mode == DUPLEX ) { //assert( handle->dsBufferSize[0] == handle->dsBufferSize[1] ); @@ -6402,11 +6418,12 @@ void RtApiDs :: callbackEvent() } nextWritePointer = ( nextWritePointer + bufferSize1 + bufferSize2 ) % dsBufferSize; handle->bufferPointer[0] = nextWritePointer; + } - if ( handle->drainCounter ) { - handle->drainCounter++; - goto unlock; - } + // Don't bother draining input + if ( handle->drainCounter ) { + handle->drainCounter++; + goto unlock; } if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) { @@ -6545,6 +6562,7 @@ void RtApiDs :: callbackEvent() } unlock: + MUTEX_UNLOCK( &stream_.mutex ); RtApi::tickStreamTime(); }