fix for m-audio ASIO driver

This commit is contained in:
Volker Fischer 2010-03-02 18:22:55 +00:00
parent 3b4eb7f605
commit e1b949e318
2 changed files with 64 additions and 40 deletions

View file

@ -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

View file

@ -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;
}
}
}
}