From 148caac0c11e150e13610075e8579aded608b12f Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Fri, 18 Apr 2014 16:01:48 +0200 Subject: [PATCH 1/4] Added an author header to the WASAPI section --- RtAudio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RtAudio.cpp b/RtAudio.cpp index dd06b52..3bd001a 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -3578,6 +3578,12 @@ static const char* getAsioErrorString( ASIOError result ) #if defined(__WINDOWS_WASAPI__) // Windows WASAPI API +// Authored by Marcus Tomlinson , April 2014 +// - Introduces support for the Windows WASAPI API +// - Aims to deliver bit streams to and from hardware at the lowest possible latency, via the absolute minimum buffer sizes required +// - Provides flexible stream configuration to an otherwise strict and inflexible WASAPI interface +// - Includes automatic internal conversion of sample rate, buffer size and channel count + #ifndef INITGUID #define INITGUID #endif From 8b7653b945cbe09610a6cd5902f439873db0d18e Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Fri, 18 Apr 2014 16:02:56 +0200 Subject: [PATCH 2/4] Fixed shutdown crash on certain sample rates --- RtAudio.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/RtAudio.cpp b/RtAudio.cpp index 3bd001a..44cf4ed 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -4626,7 +4626,8 @@ void RtApiWasapi::wasapiThread() // convBuffer is used to store converted buffers between WASAPI and the user char* convBuffer = NULL; - unsigned int deviceBufferSize = 0; + unsigned int convBuffSize = 0; + unsigned int deviceBuffSize = 0; errorText_.clear(); RtAudioError::Type errorType = RtAudioError::DRIVER_ERROR; @@ -4801,18 +4802,22 @@ void RtApiWasapi::wasapiThread() } if ( stream_.mode == INPUT ) { - deviceBufferSize = ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ); + convBuffSize = ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ); + deviceBuffSize = stream_.bufferSize * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ); } else if ( stream_.mode == OUTPUT ) { - deviceBufferSize = ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ); + convBuffSize = ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ); + deviceBuffSize = stream_.bufferSize * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ); } else if ( stream_.mode == DUPLEX ) { - deviceBufferSize = std::max( ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ), - ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) ); + convBuffSize = std::max( ( size_t ) ( stream_.bufferSize * captureSrRatio ) * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ), + ( size_t ) ( stream_.bufferSize * renderSrRatio ) * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) ); + deviceBuffSize = std::max( stream_.bufferSize * stream_.nDeviceChannels[INPUT] * formatBytes( stream_.deviceFormat[INPUT] ), + stream_.bufferSize * stream_.nDeviceChannels[OUTPUT] * formatBytes( stream_.deviceFormat[OUTPUT] ) ); } - convBuffer = ( char* ) malloc( deviceBufferSize ); - stream_.deviceBuffer = ( char* ) malloc( deviceBufferSize ); + convBuffer = ( char* ) malloc( convBuffSize ); + stream_.deviceBuffer = ( char* ) malloc( deviceBuffSize ); if ( !convBuffer || !stream_.deviceBuffer ) { errorType = RtAudioError::MEMORY_ERROR; errorText_ = "RtApiWasapi::wasapiThread: Error allocating device buffer memory."; From 27d53f8096cd5e531f74862b953f12ff8d21c76a Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Fri, 18 Apr 2014 16:03:11 +0200 Subject: [PATCH 3/4] Support all sample rates for WASAPI --- RtAudio.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/RtAudio.cpp b/RtAudio.cpp index 44cf4ed..43aaaa3 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -4096,18 +4096,9 @@ RtAudio::DeviceInfo RtApiWasapi::getDeviceInfo( unsigned int device ) // sample rates info.sampleRates.clear(); - // allow support for sample rates that are multiples of the base rate + // allow support for all sample rates as we have a built-in sample rate converter for ( unsigned int i = 0; i < MAX_SAMPLE_RATES; i++ ) { - if ( SAMPLE_RATES[i] < deviceFormat->nSamplesPerSec ) { - if ( deviceFormat->nSamplesPerSec % SAMPLE_RATES[i] == 0 ) { - info.sampleRates.push_back( SAMPLE_RATES[i] ); - } - } - else { - if ( SAMPLE_RATES[i] % deviceFormat->nSamplesPerSec == 0 ) { - info.sampleRates.push_back( SAMPLE_RATES[i] ); - } - } + info.sampleRates.push_back( SAMPLE_RATES[i] ); } // native format From e4a070b5fc0ea33abba209c1875d290919e2faa3 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Fri, 18 Apr 2014 16:14:54 +0200 Subject: [PATCH 4/4] Removed now irrelevant comment --- RtAudio.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RtAudio.cpp b/RtAudio.cpp index 43aaaa3..9760c7c 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -3768,8 +3768,7 @@ private: // channel counts between HW and the user. The convertBufferWasapi function is used to perform // these conversions between HwIn->UserIn and UserOut->HwOut during the stream callback loop. // This sample rate converter favors speed over quality, and works best with conversions between -// one rate and its multiple. RtApiWasapi will not populate a device's sample rate list with rates -// that may cause artifacts via this conversion. +// one rate and its multiple. void convertBufferWasapi( char* outBuffer, const char* inBuffer, const unsigned int& inChannelCount,