added automatic sound card buffer length selection on new device

This commit is contained in:
Volker Fischer 2008-11-02 08:31:48 +00:00
parent 8de53c301a
commit 4370c208e6
3 changed files with 68 additions and 25 deletions

View file

@ -76,13 +76,15 @@
#define MAX_NET_BUF_SIZE_NUM_BL 10 // number of blocks #define MAX_NET_BUF_SIZE_NUM_BL 10 // number of blocks
// default network buffer size // default network buffer size
#define DEF_NET_BUF_SIZE_NUM_BL 5 // number of blocks #define DEF_NET_BUF_SIZE_NUM_BL 6 // number of blocks
// number of ticks of audio in/out buffer sliders // number of ticks of audio in/out buffer sliders
#define AUD_SLIDER_LENGTH 8 #define AUD_SLIDER_LENGTH 8
// maximum number of recognized sound cards installed in the system // maximum number of recognized sound cards installed in the system,
// definition for "no device"
#define MAX_NUMBER_SOUND_CARDS 10 #define MAX_NUMBER_SOUND_CARDS 10
#define INVALID_SNC_CARD_DEVICE -1
// maximum number of internet connections (channels) // maximum number of internet connections (channels)
// if you want to change this paramter, there has to be done code modifications // if you want to change this paramter, there has to be done code modifications

View file

@ -87,8 +87,9 @@ void CSettings::ReadIniFile ( const QString& sFileName )
} }
else else
{ {
// default setting: use first sound card in system // use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
pClient->GetSndInterface()->SetDev ( 0 ); // device selection was done previously
pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE );
} }
// sound card in number of buffers // sound card in number of buffers

View file

@ -71,6 +71,7 @@ int iCurNumSndBufIn;
int iCurNumSndBufOut; int iCurNumSndBufOut;
int iNewNumSndBufIn; int iNewNumSndBufIn;
int iNewNumSndBufOut; int iNewNumSndBufOut;
bool bSetNumSndBufToMinimumValue;
// we must implement these functions here to get access to global variables // we must implement these functions here to get access to global variables
int CSound::GetOutNumBuf() { return iNewNumSndBufOut; } int CSound::GetOutNumBuf() { return iNewNumSndBufOut; }
@ -251,6 +252,10 @@ void CSound::SetDev ( const int iNewDev )
// check if an ASIO driver was already initialized // check if an ASIO driver was already initialized
if ( lCurDev >= 0 ) if ( lCurDev >= 0 )
{ {
// the new driver was not selected before, use default settings for
// buffer sizes
bSetNumSndBufToMinimumValue = true;
// a device was already been initialized and is used, kill working // a device was already been initialized and is used, kill working
// thread and clean up // thread and clean up
// stop driver // stop driver
@ -276,6 +281,14 @@ void CSound::SetDev ( const int iNewDev )
if ( !strErrorMessage.empty() ) if ( !strErrorMessage.empty() )
{ {
// The new driver initializing was not successful, try to preserve
// the old buffer settings -> this is possible, if errornous driver
// had failed before the buffer setting was done. If it failed after
// setting the minimum buffer sizes, the following flag modification
// does not have any effect which means the old settings cannot be
// recovered anymore (TODO better solution)
bSetNumSndBufToMinimumValue = false;
// loading and initializing the new driver failed, go back to original // loading and initializing the new driver failed, go back to original
// driver and display error message // driver and display error message
LoadAndInitializeDriver ( lCurDev ); LoadAndInitializeDriver ( lCurDev );
@ -286,6 +299,8 @@ void CSound::SetDev ( const int iNewDev )
InitRecordingAndPlayback(); InitRecordingAndPlayback();
} }
else else
{
if ( iNewDev != INVALID_SNC_CARD_DEVICE )
{ {
// This is the first time a driver is to be initialized, we first try // This is the first time a driver is to be initialized, we first try
// to load the selected driver, if this fails, we try to load the first // to load the selected driver, if this fails, we try to load the first
@ -304,6 +319,19 @@ void CSound::SetDev ( const int iNewDev )
} }
} }
} }
else
{
// the new driver was not selected before, use default settings for
// buffer sizes
bSetNumSndBufToMinimumValue = true;
// try to find one usable driver (select the first valid driver)
if ( !LoadAndInitializeFirstValidDriver() )
{
throw CGenErr ( "No usable ASIO audio device (driver) found." );
}
}
}
} }
std::string CSound::LoadAndInitializeDriver ( int iDriverIdx ) std::string CSound::LoadAndInitializeDriver ( int iDriverIdx )
@ -492,15 +520,24 @@ if ( iASIOBufferSizeMono == 256 )
{ {
iMinNumSndBuf = 4; iMinNumSndBuf = 4;
} }
Q_ASSERT ( iMinNumSndBuf < MAX_SND_BUF_IN ); Q_ASSERT ( iMinNumSndBuf < MAX_SND_BUF_IN );
Q_ASSERT ( iMinNumSndBuf < MAX_SND_BUF_OUT ); Q_ASSERT ( iMinNumSndBuf < MAX_SND_BUF_OUT );
// set or just check the sound card buffer sizes
if ( bSetNumSndBufToMinimumValue )
{
// use minimum buffer sizes as default
iNewNumSndBufIn = iMinNumSndBuf;
iNewNumSndBufOut = iMinNumSndBuf;
}
else
{
// correct number of sound card buffers if required // correct number of sound card buffers if required
iCurNumSndBufIn = max ( iMinNumSndBuf, iCurNumSndBufIn ); iNewNumSndBufIn = max ( iMinNumSndBuf, iNewNumSndBufIn );
iCurNumSndBufOut = max ( iMinNumSndBuf, iCurNumSndBufOut ); iNewNumSndBufOut = max ( iMinNumSndBuf, iNewNumSndBufOut );
iNewNumSndBufIn = iCurNumSndBufIn; }
iNewNumSndBufOut = iCurNumSndBufOut; iCurNumSndBufIn = iNewNumSndBufIn;
iCurNumSndBufOut = iNewNumSndBufOut;
// display warning in case the ASIO buffer is too big // display warning in case the ASIO buffer is too big
if ( iMinNumSndBuf > 6 ) if ( iMinNumSndBuf > 6 )
@ -511,7 +548,9 @@ if ( iASIOBufferSizeMono == 256 )
QString ( " samples which is too large. Please try to modify " QString ( " samples which is too large. Please try to modify "
"the ASIO buffer size value in your ASIO driver settings (most ASIO " "the ASIO buffer size value in your ASIO driver settings (most ASIO "
"drivers like ASIO4All or kx driver allow to change the ASIO buffer size). " "drivers like ASIO4All or kx driver allow to change the ASIO buffer size). "
"Recommended settings are 96 or 128 samples." ), "Ok", 0 ); "Recommended settings are 96 or 128 samples. Please make sure that "
"before you try to change the ASIO driver buffer size all ASIO "
"applications including llcon are closed." ), "Ok", 0 );
} }
// prepare input channels // prepare input channels
@ -680,9 +719,10 @@ CSound::CSound ( const int iNewBufferSizeStereo )
// create event // create event
m_ASIOEvent = CreateEvent ( NULL, FALSE, FALSE, NULL ); m_ASIOEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
// init flags (initiate init for first run) // init flags
bChangParamIn = true; bChangParamIn = false;
bChangParamOut = true; bChangParamOut = false;
bSetNumSndBufToMinimumValue = false;
} }
CSound::~CSound() CSound::~CSound()