From e1b949e31871691586ef0ca93b7a3f5cbaac7f92 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 2 Mar 2010 18:22:55 +0000 Subject: [PATCH] fix for m-audio ASIO driver --- ChangeLog | 2 + windows/sound.cpp | 102 ++++++++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9ba2fb9..7b5058e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ - improvement of network buffer (jitter buffer) in case of small buffer sizes +- bug fix for M-Audio Delta ASIO driver + 3.0.3 diff --git a/windows/sound.cpp b/windows/sound.cpp index 84127674..101e7f8e 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -337,49 +337,71 @@ int CSound::GetActualBufferSize ( const int iDesiredBufferSizeMono ) } else { - // General case ------------------------------------------------ - // initialization - int iTrialBufSize = HWBufferInfo.lMinSize; - int iLastTrialBufSize = HWBufferInfo.lMinSize; - bool bSizeFound = false; - - // test loop - while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) ) + if ( HWBufferInfo.lGranularity <= 0 ) { - if ( iTrialBufSize >= iDesiredBufferSizeMono ) - { - // test which buffer size fits better: the old one or the - // current one - if ( ( iTrialBufSize - iDesiredBufferSizeMono ) > - ( iDesiredBufferSizeMono - iLastTrialBufSize ) ) - { - iTrialBufSize = iLastTrialBufSize; - } - - // exit while loop - bSizeFound = true; - } - - if ( !bSizeFound ) - { - // store old trial buffer size - iLastTrialBufSize = iTrialBufSize; - - // increment trial buffer size (check for special case first) - if ( HWBufferInfo.lGranularity == -1 ) - { - // special case: buffer sizes are a power of 2 - iTrialBufSize *= 2; - } - else - { - iTrialBufSize += HWBufferInfo.lGranularity; - } - } + // Special case (seen for EMU audio cards): granularity is + // zero or less than zero. + // There is no definition of this case in the ASIO SDK + // document. We assume here that all buffer sizes in between + // minimum and maximum buffer sizes are allowed. + iActualBufferSizeMono = iDesiredBufferSizeMono; } + else + { + // General case -------------------------------------------- + // initialization + int iTrialBufSize = HWBufferInfo.lMinSize; + int iLastTrialBufSize = HWBufferInfo.lMinSize; + bool bSizeFound = false; - // set ASIO buffer size - iActualBufferSizeMono = iTrialBufSize; + // test loop + while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) ) + { + if ( iTrialBufSize >= iDesiredBufferSizeMono ) + { + // test which buffer size fits better: the old one or the + // current one + if ( ( iTrialBufSize - iDesiredBufferSizeMono ) > + ( iDesiredBufferSizeMono - iLastTrialBufSize ) ) + { + iTrialBufSize = iLastTrialBufSize; + } + + // exit while loop + bSizeFound = true; + } + + if ( !bSizeFound ) + { + // store old trial buffer size + iLastTrialBufSize = iTrialBufSize; + + // increment trial buffer size (check for special + // case first) + if ( HWBufferInfo.lGranularity == -1 ) + { + // special case: buffer sizes are a power of 2 + iTrialBufSize *= 2; + } + else + { + iTrialBufSize += HWBufferInfo.lGranularity; + } + } + } + + // clip trial buffer size (it may happen in the while + // routine that "iTrialBufSize" is larger than "lMaxSize" in + // case "lMaxSize - lMinSize" is not divisible by the + // granularity) + if ( iTrialBufSize > HWBufferInfo.lMaxSize ) + { + iTrialBufSize = HWBufferInfo.lMaxSize; + } + + // set ASIO buffer size + iActualBufferSizeMono = iTrialBufSize; + } } } }