fix for setting sound card device

This commit is contained in:
Volker Fischer 2009-03-07 20:45:00 +00:00
parent 029719fd1d
commit f38aa17ca6
7 changed files with 48 additions and 31 deletions

View file

@ -181,6 +181,28 @@ void CClient::SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx )
Channel.CreateNetTranspPropsMessFromCurrentSettings(); Channel.CreateNetTranspPropsMessFromCurrentSettings();
} }
void CClient::SetSndCrdDev ( const int iNewDev )
{
// if client was running then first
// stop it and restart again after new initialization
const bool bWasRunning = Sound.IsRunning();
if ( bWasRunning )
{
Sound.Stop();
}
Sound.SetDev ( iNewDev );
// init again because the sound card actual buffer size might
// be changed on new device
Init ( iSndCrdPreferredMonoBlSizeIndex );
if ( bWasRunning )
{
Sound.Start();
}
}
void CClient::Start() void CClient::Start()
{ {
// init object // init object

View file

@ -116,6 +116,14 @@ public:
int GetAudioBlockSizeIn() { return Channel.GetAudioBlockSizeIn(); } int GetAudioBlockSizeIn() { return Channel.GetAudioBlockSizeIn(); }
int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); }
int GetSndCrdNumDev() { return Sound.GetNumDev(); }
std::string GetSndCrdDeviceName ( const int iDiD )
{ return Sound.GetDeviceName ( iDiD ); }
void SetSndCrdDev ( const int iNewDev );
int GetSndCrdDev() { return Sound.GetDev(); }
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }
void SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx ); void SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx );
int GetSndCrdPreferredMonoBlSizeIndex() int GetSndCrdPreferredMonoBlSizeIndex()
{ return iSndCrdPreferredMonoBlSizeIndex; } { return iSndCrdPreferredMonoBlSizeIndex; }
@ -143,8 +151,7 @@ public:
void SendPingMess() void SendPingMess()
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); }; { Channel.CreatePingMes ( PreciseTime.elapsed() ); };
CSound* GetSndInterface() { return &Sound; } CChannel* GetChannel() { return &Channel; }
CChannel* GetChannel() { return &Channel; }
// settings // settings

View file

@ -71,11 +71,11 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
// init combo box containing all available sound cards in the system // init combo box containing all available sound cards in the system
cbSoundcard->clear(); cbSoundcard->clear();
for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndInterface()->GetNumDev(); iSndDevIdx++ ) for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ )
{ {
cbSoundcard->addItem ( pClient->GetSndInterface()->GetDeviceName ( iSndDevIdx ).c_str() ); cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ).c_str() );
} }
cbSoundcard->setCurrentIndex ( pClient->GetSndInterface()->GetDev() ); cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
// "OpenChatOnNewMessage" check box // "OpenChatOnNewMessage" check box
if ( pClient->GetOpenChatOnNewMessage() ) if ( pClient->GetOpenChatOnNewMessage() )
@ -196,7 +196,7 @@ void CClientSettingsDlg::hideEvent ( QHideEvent* hideEvent )
void CClientSettingsDlg::OnDriverSetupBut() void CClientSettingsDlg::OnDriverSetupBut()
{ {
pClient->GetSndInterface()->OpenDriverSetup(); pClient->OpenSndCrdDriverSetup();
} }
void CClientSettingsDlg::OnSliderNetBuf ( int value ) void CClientSettingsDlg::OnSliderNetBuf ( int value )
@ -215,7 +215,7 @@ void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
{ {
try try
{ {
pClient->GetSndInterface()->SetDev ( iSndDevIdx ); pClient->SetSndCrdDev ( iSndDevIdx );
} }
catch ( CGenErr generr ) catch ( CGenErr generr )
{ {
@ -225,7 +225,7 @@ void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
QString ( " The previous driver will be selected." ), "Ok", 0 ); QString ( " The previous driver will be selected." ), "Ok", 0 );
// recover old selection // recover old selection
cbSoundcard->setCurrentIndex ( pClient->GetSndInterface()->GetDev() ); cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
} }
UpdateDisplay(); UpdateDisplay();
} }

View file

@ -116,8 +116,8 @@ void CServer::Stop()
Timer.stop(); Timer.stop();
// logging // logging
const QString strLogStr = CLogTimeDate::toString() + ": server stopped " const QString strLogStr = CLogTimeDate::toString() + ",, server stopped "
"############################################"; "-------------------------------------";
qDebug() << strLogStr; // on console qDebug() << strLogStr; // on console
Logging << strLogStr; // in log file Logging << strLogStr; // in log file
@ -126,8 +126,8 @@ void CServer::Stop()
void CServer::OnNewChannel ( CHostAddress ChanAddr ) void CServer::OnNewChannel ( CHostAddress ChanAddr )
{ {
// logging of new connected channel // logging of new connected channel
const QString strLogStr = CLogTimeDate::toString() + ": " + const QString strLogStr = CLogTimeDate::toString() + ", " +
ChanAddr.InetAddr.toString() + " connected"; ChanAddr.InetAddr.toString() + ", connected";
qDebug() << strLogStr; // on console qDebug() << strLogStr; // on console
Logging << strLogStr; // in log file Logging << strLogStr; // in log file

View file

@ -84,13 +84,13 @@ void CSettings::ReadIniFile ( const QString& sFileName )
// initialized with a default setting defined here // initialized with a default setting defined here
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx", 1, MAX_NUMBER_SOUND_CARDS, iValue ) ) if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx", 1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{ {
pClient->GetSndInterface()->SetDev ( iValue ); pClient->SetSndCrdDev ( iValue );
} }
else else
{ {
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no // use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
// device selection was done previously // device selection was done previously
pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE ); pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
} }
// sound card preferred buffer size index // sound card preferred buffer size index
@ -161,7 +161,7 @@ void CSettings::WriteIniFile ( const QString& sFileName )
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan", pClient->IsReverbOnLeftChan() ); SetFlagIniSet ( IniXMLDocument, "client", "reverblchan", pClient->IsReverbOnLeftChan() );
// sound card selection // sound card selection
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", pClient->GetSndInterface()->GetDev() ); SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", pClient->GetSndCrdDev() );
// sound card preferred buffer size index // sound card preferred buffer size index
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", pClient->GetSndCrdPreferredMonoBlSizeIndex() ); SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", pClient->GetSndCrdPreferredMonoBlSizeIndex() );

View file

@ -550,10 +550,10 @@ public:
{ {
const QDateTime curDateTime = QDateTime::currentDateTime(); const QDateTime curDateTime = QDateTime::currentDateTime();
// format date and time output according to "3.9.2006 11:38:08: " // format date and time output according to "3.9.2006, 11:38:08"
return QString().setNum ( curDateTime.date().day() ) + "." + return QString().setNum ( curDateTime.date().day() ) + "." +
QString().setNum ( curDateTime.date().month() ) + "." + QString().setNum ( curDateTime.date().month() ) + "." +
QString().setNum ( curDateTime.date().year() ) + " " + QString().setNum ( curDateTime.date().year() ) + ", " +
curDateTime.time().toString(); curDateTime.time().toString();
} }
}; };

View file

@ -59,20 +59,10 @@ CSound* pSound;
\******************************************************************************/ \******************************************************************************/
void CSound::SetDev ( const int iNewDev ) void CSound::SetDev ( const int iNewDev )
{ {
// TODO do check if sound interface is running here, take action
// check if an ASIO driver was already initialized // check if an ASIO driver was already initialized
if ( lCurDev >= 0 ) if ( lCurDev >= 0 )
{ {
// a device was already been initialized and is used, kill working // a device was already been initialized and is used, first clean up
// thread and clean up
// stop driver
ASIOStop();
// dispose ASIO buffers // dispose ASIO buffers
ASIODisposeBuffers(); ASIODisposeBuffers();
@ -103,9 +93,7 @@ void CSound::SetDev ( const int iNewDev )
// available driver in the system. If this fails, too, we throw an error // available driver in the system. If this fails, too, we throw an error
// that no driver is available -> it does not make sense to start the llcon // that no driver is available -> it does not make sense to start the llcon
// software if no audio hardware is available // software if no audio hardware is available
const std::string strErrorMessage = LoadAndInitializeDriver ( iNewDev ); if ( !LoadAndInitializeDriver ( iNewDev ).empty() )
if ( !strErrorMessage.empty() )
{ {
// loading and initializing the new driver failed, try to find at // loading and initializing the new driver failed, try to find at
// least one usable driver // least one usable driver