From 1697b8f9cd5b3cf170dd0c128a1c741b088f0c2c Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 8 Mar 2009 17:14:37 +0000 Subject: [PATCH] bug fix with sound card device selection, show red text if actual sound card buffer size differs from preffered value --- linux/sound.h | 6 +++--- src/client.cpp | 6 ++++-- src/client.h | 2 +- src/clientsettingsdlg.cpp | 43 ++++++++++++++++++++++++--------------- windows/sound.cpp | 10 ++++++--- windows/sound.h | 2 +- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/linux/sound.h b/linux/sound.h index e29369fb..94d37354 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -58,7 +58,7 @@ public: // not implemented yet, always return one device and default string int GetNumDev() { return 1; } 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; } virtual int Init ( const int iNewPrefMonoBufferSize ); @@ -85,7 +85,7 @@ public: // not implemented yet, always return one device and default string int GetNumDev() { return 1; } 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; } virtual int Init ( const int iNewPrefMonoBufferSize ) @@ -136,7 +136,7 @@ public: // not used int GetNumDev() { return 1; } 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; } // dummy definitions diff --git a/src/client.cpp b/src/client.cpp index 47ee83eb..661598de 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -181,7 +181,7 @@ void CClient::SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx ) Channel.CreateNetTranspPropsMessFromCurrentSettings(); } -void CClient::SetSndCrdDev ( const int iNewDev ) +QString CClient::SetSndCrdDev ( const int iNewDev ) { // if client was running then first // stop it and restart again after new initialization @@ -191,7 +191,7 @@ void CClient::SetSndCrdDev ( const int iNewDev ) Sound.Stop(); } - Sound.SetDev ( iNewDev ); + const QString strReturn = Sound.SetDev ( iNewDev ).c_str(); // init again because the sound card actual buffer size might // be changed on new device @@ -201,6 +201,8 @@ void CClient::SetSndCrdDev ( const int iNewDev ) { Sound.Start(); } + + return strReturn; } void CClient::Start() diff --git a/src/client.h b/src/client.h index 69951c48..05334c59 100755 --- a/src/client.h +++ b/src/client.h @@ -120,7 +120,7 @@ public: std::string GetSndCrdDeviceName ( const int iDiD ) { return Sound.GetDeviceName ( iDiD ); } - void SetSndCrdDev ( const int iNewDev ); + QString SetSndCrdDev ( const int iNewDev ); int GetSndCrdDev() { return Sound.GetDev(); } void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); } diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index ba1ab473..dcee7e86 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -164,21 +164,34 @@ void CClientSettingsDlg::UpdateJitterBufferFrame() void CClientSettingsDlg::UpdateSoundCardFrame() { // update slider value and text - const int iCurPrefBufIdx = pClient->GetSndCrdPreferredMonoBlSizeIndex(); - const int iCurActualBufIdx = pClient->GetSndCrdActualMonoBlSize(); + const int iCurPrefBufIdx = pClient->GetSndCrdPreferredMonoBlSizeIndex(); + const int iCurActualBufSize = pClient->GetSndCrdActualMonoBlSize(); SliderSndCrdBufferDelay->setValue ( iCurPrefBufIdx ); // preferred size - TextLabelPreferredSndCrdBufDelay->setText ( - QString().setNum ( (double) CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx ) * - 1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" + - QString().setNum ( CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx ) ) + ")" ); + const int iPrefBufSize = + CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurPrefBufIdx ); - // actual size - TextLabelActualSndCrdBufDelay->setText ( - QString().setNum ( (double) iCurActualBufIdx * + TextLabelPreferredSndCrdBufDelay->setText ( + QString().setNum ( (double) iPrefBufSize * 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 ( "" + + strActSizeValues + "" ); + } + else + { + TextLabelActualSndCrdBufDelay->setText ( strActSizeValues ); + } } void CClientSettingsDlg::showEvent ( QShowEvent* showEvent ) @@ -214,15 +227,13 @@ void CClientSettingsDlg::OnSliderSndCrdBufferDelay ( int value ) void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx ) { - try - { - pClient->SetSndCrdDev ( iSndDevIdx ); - } - catch ( CGenErr generr ) + const QString strError = pClient->SetSndCrdDev ( iSndDevIdx ); + + if ( !strError.isEmpty() ) { QMessageBox::critical ( 0, APP_NAME, 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 ); // recover old selection diff --git a/windows/sound.cpp b/windows/sound.cpp index a6efdcac..ba0be53b 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -57,8 +57,10 @@ CSound* pSound; /******************************************************************************\ * 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 if ( lCurDev >= 0 ) { @@ -77,9 +79,9 @@ void CSound::SetDev ( const int iNewDev ) // loading and initializing the new driver failed, go back to // original driver and display error message LoadAndInitializeDriver ( lCurDev ); - Init ( iASIOBufferSizeStereo ); - throw CGenErr ( strErrorMessage.c_str() ); + // store error return message + strReturn = strErrorMessage; } Init ( iASIOBufferSizeStereo ); @@ -114,6 +116,8 @@ void CSound::SetDev ( const int iNewDev ) } } } + + return strReturn; } bool CSound::LoadAndInitializeFirstValidDriver() diff --git a/windows/sound.h b/windows/sound.h index 5a293525..0b6b2862 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -68,7 +68,7 @@ public: int GetNumDev() { return lNumDevs; } std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } - void SetDev ( const int iNewDev ); + std::string SetDev ( const int iNewDev ); int GetDev() { return lCurDev; } protected: