bug fix in case max and min values for supported ASIO driver frame sizes are the same (software freezes in this case)

This commit is contained in:
Volker Fischer 2009-08-16 00:26:48 +00:00
parent 1fac1056ea
commit c549ae90f0

View file

@ -263,48 +263,59 @@ int CSound::GetActualBufferSize ( const int iDesiredBufferSizeMono )
} }
else else
{ {
// initialization // ASIO SDK 2.2: "Notes: When minimum and maximum buffer size are
int iTrialBufSize = HWBufferInfo.lMinSize; // equal, the preferred buffer size has to be the same value as
int iLastTrialBufSize = HWBufferInfo.lMinSize; // well; granularity should be 0 in this case."
bool bSizeFound = false; if ( HWBufferInfo.lMinSize == HWBufferInfo.lMaxSize )
// test loop
while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) )
{ {
if ( iTrialBufSize >= iDesiredBufferSizeMono ) iActualBufferSizeMono = HWBufferInfo.lMinSize;
{
// 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;
}
}
} }
else
{
// General case ------------------------------------------------
// initialization
int iTrialBufSize = HWBufferInfo.lMinSize;
int iLastTrialBufSize = HWBufferInfo.lMinSize;
bool bSizeFound = false;
// set ASIO buffer size // test loop
iActualBufferSizeMono = iTrialBufSize; 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;
}
}
}
// set ASIO buffer size
iActualBufferSizeMono = iTrialBufSize;
}
} }
} }