bug fix with sound card device selection, show red text if actual sound card buffer size differs from preffered value

This commit is contained in:
Volker Fischer 2009-03-08 17:14:37 +00:00
parent 81d119ba4a
commit 1697b8f9cd
6 changed files with 43 additions and 26 deletions

View file

@ -58,7 +58,7 @@ public:
// not implemented yet, always return one device and default string // not implemented yet, always return one device and default string
int GetNumDev() { return 1; } int GetNumDev() { return 1; }
std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; }
int SetDev ( const int iNewDev ) {} // dummy std::string SetDev ( const int iNewDev ) { return ""; } // dummy
int GetDev() { return 0; } int GetDev() { return 0; }
virtual int Init ( const int iNewPrefMonoBufferSize ); virtual int Init ( const int iNewPrefMonoBufferSize );
@ -85,7 +85,7 @@ public:
// not implemented yet, always return one device and default string // not implemented yet, always return one device and default string
int GetNumDev() { return 1; } int GetNumDev() { return 1; }
std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; }
int SetDev ( const int iNewDev ) {} // dummy std::string SetDev ( const int iNewDev ) { return ""; } // dummy
int GetDev() { return 0; } int GetDev() { return 0; }
virtual int Init ( const int iNewPrefMonoBufferSize ) virtual int Init ( const int iNewPrefMonoBufferSize )
@ -136,7 +136,7 @@ public:
// not used // not used
int GetNumDev() { return 1; } int GetNumDev() { return 1; }
std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; } std::string GetDeviceName ( const int iDiD ) { return "wave mapper"; }
int SetDev ( const int iNewDev ) {} // dummy std::string SetDev ( const int iNewDev ) { return ""; } // dummy
int GetDev() { return 0; } int GetDev() { return 0; }
// dummy definitions // dummy definitions

View file

@ -181,7 +181,7 @@ void CClient::SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx )
Channel.CreateNetTranspPropsMessFromCurrentSettings(); Channel.CreateNetTranspPropsMessFromCurrentSettings();
} }
void CClient::SetSndCrdDev ( const int iNewDev ) QString CClient::SetSndCrdDev ( const int iNewDev )
{ {
// if client was running then first // if client was running then first
// stop it and restart again after new initialization // stop it and restart again after new initialization
@ -191,7 +191,7 @@ void CClient::SetSndCrdDev ( const int iNewDev )
Sound.Stop(); Sound.Stop();
} }
Sound.SetDev ( iNewDev ); const QString strReturn = Sound.SetDev ( iNewDev ).c_str();
// init again because the sound card actual buffer size might // init again because the sound card actual buffer size might
// be changed on new device // be changed on new device
@ -201,6 +201,8 @@ void CClient::SetSndCrdDev ( const int iNewDev )
{ {
Sound.Start(); Sound.Start();
} }
return strReturn;
} }
void CClient::Start() void CClient::Start()

View file

@ -120,7 +120,7 @@ public:
std::string GetSndCrdDeviceName ( const int iDiD ) std::string GetSndCrdDeviceName ( const int iDiD )
{ return Sound.GetDeviceName ( iDiD ); } { return Sound.GetDeviceName ( iDiD ); }
void SetSndCrdDev ( const int iNewDev ); QString SetSndCrdDev ( const int iNewDev );
int GetSndCrdDev() { return Sound.GetDev(); } int GetSndCrdDev() { return Sound.GetDev(); }
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); } void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }

View file

@ -164,21 +164,34 @@ void CClientSettingsDlg::UpdateJitterBufferFrame()
void CClientSettingsDlg::UpdateSoundCardFrame() void CClientSettingsDlg::UpdateSoundCardFrame()
{ {
// update slider value and text // update slider value and text
const int iCurPrefBufIdx = pClient->GetSndCrdPreferredMonoBlSizeIndex(); const int iCurPrefBufIdx = pClient->GetSndCrdPreferredMonoBlSizeIndex();
const int iCurActualBufIdx = pClient->GetSndCrdActualMonoBlSize(); const int iCurActualBufSize = pClient->GetSndCrdActualMonoBlSize();
SliderSndCrdBufferDelay->setValue ( iCurPrefBufIdx ); SliderSndCrdBufferDelay->setValue ( iCurPrefBufIdx );
// preferred size // preferred size
TextLabelPreferredSndCrdBufDelay->setText ( const int iPrefBufSize =
QString().setNum ( (double) CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx ) * CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx );
1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" +
QString().setNum ( CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx ) ) + ")" );
// actual size TextLabelPreferredSndCrdBufDelay->setText (
TextLabelActualSndCrdBufDelay->setText ( QString().setNum ( (double) iPrefBufSize *
QString().setNum ( (double) iCurActualBufIdx *
1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" + 1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" +
QString().setNum ( iCurActualBufIdx ) + ")" ); QString().setNum ( iPrefBufSize ) + ")" );
// actual size (use yellow color if different from preferred size)
const QString strActSizeValues =
QString().setNum ( (double) iCurActualBufSize *
1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" +
QString().setNum ( iCurActualBufSize ) + ")";
if ( iPrefBufSize != iCurActualBufSize )
{
TextLabelActualSndCrdBufDelay->setText ( "<font color=""red"">" +
strActSizeValues + "</font>" );
}
else
{
TextLabelActualSndCrdBufDelay->setText ( strActSizeValues );
}
} }
void CClientSettingsDlg::showEvent ( QShowEvent* showEvent ) void CClientSettingsDlg::showEvent ( QShowEvent* showEvent )
@ -214,15 +227,13 @@ void CClientSettingsDlg::OnSliderSndCrdBufferDelay ( int value )
void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx ) void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
{ {
try const QString strError = pClient->SetSndCrdDev ( iSndDevIdx );
{
pClient->SetSndCrdDev ( iSndDevIdx ); if ( !strError.isEmpty() )
}
catch ( CGenErr generr )
{ {
QMessageBox::critical ( 0, APP_NAME, QMessageBox::critical ( 0, APP_NAME,
QString ( "The selected audio device could not be used because " QString ( "The selected audio device could not be used because "
"of the following error: " ) + generr.GetErrorText() + "of the following error: " ) + strError +
QString ( " The previous driver will be selected." ), "Ok", 0 ); QString ( " The previous driver will be selected." ), "Ok", 0 );
// recover old selection // recover old selection

View file

@ -57,8 +57,10 @@ CSound* pSound;
/******************************************************************************\ /******************************************************************************\
* Common * * Common *
\******************************************************************************/ \******************************************************************************/
void CSound::SetDev ( const int iNewDev ) std::string CSound::SetDev ( const int iNewDev )
{ {
std::string strReturn = ""; // init with no error
// check if an ASIO driver was already initialized // check if an ASIO driver was already initialized
if ( lCurDev >= 0 ) if ( lCurDev >= 0 )
{ {
@ -77,9 +79,9 @@ void CSound::SetDev ( const int iNewDev )
// loading and initializing the new driver failed, go back to // loading and initializing the new driver failed, go back to
// original driver and display error message // original driver and display error message
LoadAndInitializeDriver ( lCurDev ); LoadAndInitializeDriver ( lCurDev );
Init ( iASIOBufferSizeStereo );
throw CGenErr ( strErrorMessage.c_str() ); // store error return message
strReturn = strErrorMessage;
} }
Init ( iASIOBufferSizeStereo ); Init ( iASIOBufferSizeStereo );
@ -114,6 +116,8 @@ void CSound::SetDev ( const int iNewDev )
} }
} }
} }
return strReturn;
} }
bool CSound::LoadAndInitializeFirstValidDriver() bool CSound::LoadAndInitializeFirstValidDriver()

View file

@ -68,7 +68,7 @@ public:
int GetNumDev() { return lNumDevs; } int GetNumDev() { return lNumDevs; }
std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; }
void SetDev ( const int iNewDev ); std::string SetDev ( const int iNewDev );
int GetDev() { return lCurDev; } int GetDev() { return lCurDev; }
protected: protected: