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 - improvement of network buffer (jitter buffer) in case of small buffer sizes
- bug fix for M-Audio Delta ASIO driver
3.0.3 3.0.3

View file

@ -337,49 +337,71 @@ int CSound::GetActualBufferSize ( const int iDesiredBufferSizeMono )
} }
else else
{ {
// General case ------------------------------------------------ if ( HWBufferInfo.lGranularity <= 0 )
// initialization
int iTrialBufSize = HWBufferInfo.lMinSize;
int iLastTrialBufSize = HWBufferInfo.lMinSize;
bool bSizeFound = false;
// test loop
while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) )
{ {
if ( iTrialBufSize >= iDesiredBufferSizeMono ) // Special case (seen for EMU audio cards): granularity is
{ // zero or less than zero.
// test which buffer size fits better: the old one or the // There is no definition of this case in the ASIO SDK
// current one // document. We assume here that all buffer sizes in between
if ( ( iTrialBufSize - iDesiredBufferSizeMono ) > // minimum and maximum buffer sizes are allowed.
( iDesiredBufferSizeMono - iLastTrialBufSize ) ) iActualBufferSizeMono = iDesiredBufferSizeMono;
{
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;
}
}
}
// 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;
}
} }
} }
} }