added automatic sound card buffer length selection on new device
This commit is contained in:
parent
8de53c301a
commit
4370c208e6
3 changed files with 68 additions and 25 deletions
|
@ -76,13 +76,15 @@
|
|||
#define MAX_NET_BUF_SIZE_NUM_BL 10 // number of blocks
|
||||
|
||||
// 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
|
||||
# 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 INVALID_SNC_CARD_DEVICE -1
|
||||
|
||||
// maximum number of internet connections (channels)
|
||||
// if you want to change this paramter, there has to be done code modifications
|
||||
|
|
|
@ -87,8 +87,9 @@ void CSettings::ReadIniFile ( const QString& sFileName )
|
|||
}
|
||||
else
|
||||
{
|
||||
// default setting: use first sound card in system
|
||||
pClient->GetSndInterface()->SetDev ( 0 );
|
||||
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
|
||||
// device selection was done previously
|
||||
pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE );
|
||||
}
|
||||
|
||||
// sound card in number of buffers
|
||||
|
|
|
@ -71,6 +71,7 @@ int iCurNumSndBufIn;
|
|||
int iCurNumSndBufOut;
|
||||
int iNewNumSndBufIn;
|
||||
int iNewNumSndBufOut;
|
||||
bool bSetNumSndBufToMinimumValue;
|
||||
|
||||
// we must implement these functions here to get access to global variables
|
||||
int CSound::GetOutNumBuf() { return iNewNumSndBufOut; }
|
||||
|
@ -251,6 +252,10 @@ void CSound::SetDev ( const int iNewDev )
|
|||
// check if an ASIO driver was already initialized
|
||||
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
|
||||
// thread and clean up
|
||||
// stop driver
|
||||
|
@ -276,6 +281,14 @@ void CSound::SetDev ( const int iNewDev )
|
|||
|
||||
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
|
||||
// driver and display error message
|
||||
LoadAndInitializeDriver ( lCurDev );
|
||||
|
@ -286,6 +299,8 @@ void CSound::SetDev ( const int iNewDev )
|
|||
InitRecordingAndPlayback();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( iNewDev != INVALID_SNC_CARD_DEVICE )
|
||||
{
|
||||
// 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
|
||||
|
@ -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 )
|
||||
|
@ -492,15 +520,24 @@ if ( iASIOBufferSizeMono == 256 )
|
|||
{
|
||||
iMinNumSndBuf = 4;
|
||||
}
|
||||
|
||||
Q_ASSERT ( iMinNumSndBuf < MAX_SND_BUF_IN );
|
||||
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
|
||||
iCurNumSndBufIn = max ( iMinNumSndBuf, iCurNumSndBufIn );
|
||||
iCurNumSndBufOut = max ( iMinNumSndBuf, iCurNumSndBufOut );
|
||||
iNewNumSndBufIn = iCurNumSndBufIn;
|
||||
iNewNumSndBufOut = iCurNumSndBufOut;
|
||||
iNewNumSndBufIn = max ( iMinNumSndBuf, iNewNumSndBufIn );
|
||||
iNewNumSndBufOut = max ( iMinNumSndBuf, iNewNumSndBufOut );
|
||||
}
|
||||
iCurNumSndBufIn = iNewNumSndBufIn;
|
||||
iCurNumSndBufOut = iNewNumSndBufOut;
|
||||
|
||||
// display warning in case the ASIO buffer is too big
|
||||
if ( iMinNumSndBuf > 6 )
|
||||
|
@ -511,7 +548,9 @@ if ( iASIOBufferSizeMono == 256 )
|
|||
QString ( " samples which is too large. Please try to modify "
|
||||
"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). "
|
||||
"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
|
||||
|
@ -680,9 +719,10 @@ CSound::CSound ( const int iNewBufferSizeStereo )
|
|||
// create event
|
||||
m_ASIOEvent = CreateEvent ( NULL, FALSE, FALSE, NULL );
|
||||
|
||||
// init flags (initiate init for first run)
|
||||
bChangParamIn = true;
|
||||
bChangParamOut = true;
|
||||
// init flags
|
||||
bChangParamIn = false;
|
||||
bChangParamOut = false;
|
||||
bSetNumSndBufToMinimumValue = false;
|
||||
}
|
||||
|
||||
CSound::~CSound()
|
||||
|
|
Loading…
Reference in a new issue