From 5cbf5cfd130f297486b191d1e35e7bcdb2f3239f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 4 Mar 2009 07:57:44 +0000 Subject: [PATCH] some more work for sound card buffer size index implementation --- src/client.cpp | 20 +++++++++++++++++++- src/client.h | 6 ++++++ src/clientsettingsdlg.cpp | 35 +++++++++++++++++++---------------- src/settings.cpp | 9 +++++++++ src/util.h | 6 ++++++ 5 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index fb816008..81ec6acf 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -35,7 +35,8 @@ CClient::CClient ( const quint16 iPortNumber ) : bReverbOnLeftChan ( false ), strIPAddress ( "" ), strName ( "" ), bOpenChatOnNewMessage ( true ), - bDoAutoSockBufSize ( true ) + bDoAutoSockBufSize ( true ), + iSndCrdPreferredMonoBlSizeIndex ( CSndCrdBufferSizes::GetDefaultIndex() ) { // connection for protocol QObject::connect ( &Channel, @@ -149,6 +150,23 @@ bool CClient::SetServerAddr ( QString strNAddr ) return true; } + + + +void CClient::SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx ) +{ +// right now we simply set the internal value +if ( ( iNewIdx >= 0 ) && ( CSndCrdBufferSizes::GetNumOfBufferSizes() ) ) +{ + iSndCrdPreferredMonoBlSizeIndex = iNewIdx; +} + +// TODO take action on new parameter +} + + + + void CClient::Start() { // init object diff --git a/src/client.h b/src/client.h index 608499cd..90f6d641 100755 --- a/src/client.h +++ b/src/client.h @@ -118,6 +118,10 @@ public: int GetAudioBlockSizeIn() { return Channel.GetAudioBlockSizeIn(); } int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); } + void SetSndCrdPreferredMonoBlSizeIndex ( const int iNewIdx ); + int GetSndCrdPreferredMonoBlSizeIndex() + { return iSndCrdPreferredMonoBlSizeIndex; } + void SetAudioCompressionOut ( const EAudComprType eNewAudComprTypeOut ) { Channel.SetAudioCompressionOut ( eNewAudComprTypeOut ); @@ -172,6 +176,8 @@ protected: int iReverbLevel; CAudioReverb AudioReverb; + int iSndCrdPreferredMonoBlSizeIndex; + int iSndCrdMonoBlockSizeSam; int iSndCrdStereoBlockSizeSam; int iMonoBlockSizeSam; diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 342c484f..c1816716 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -52,11 +52,12 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, ButtonDriverSetup->hide(); #endif - // init delay information controls + // init delay and other information controls CLEDOverallDelay->SetUpdateTime ( 2 * PING_UPDATE_TIME ); CLEDOverallDelay->Reset(); TextLabelPingTime->setText ( "" ); TextLabelOverallDelay->setText ( "" ); + TextUpstreamValue->setText ( "" ); // init slider controls --- // network buffer @@ -160,7 +161,14 @@ void CClientSettingsDlg::UpdateJitterBufferFrame() void CClientSettingsDlg::UpdateSoundCardFrame() { - // TODO + // update slider value and text + const int iCurBufIdx = pClient->GetSndCrdPreferredMonoBlSizeIndex(); + SliderSndCrdBufferDelay->setValue ( iCurBufIdx ); + + TextLabelPreferredSndCrdBufDelay->setText ( + QString().setNum ( (double) CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurBufIdx ) * + 1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" + + QString().setNum ( CSndCrdBufferSizes::GetBufferSizeFromIndex ( iCurBufIdx ) ) + ")" ); } void CClientSettingsDlg::showEvent ( QShowEvent* showEvent ) @@ -188,15 +196,8 @@ void CClientSettingsDlg::OnSliderNetBuf ( int value ) void CClientSettingsDlg::OnSliderSndCrdBufferDelay ( int value ) { - // TODO - - -// TODO put this in the function "UpdateSoundCardFrame" -TextLabelPreferredSndCrdBufDelay->setText ( - QString().setNum ( (double) CSndCrdBufferSizes::GetBufferSizeFromIndex ( value ) * - 1000 / SND_CRD_SAMPLE_RATE, 'f', 2 ) + " ms (" + - QString().setNum ( CSndCrdBufferSizes::GetBufferSizeFromIndex ( value ) ) + ")" ); - + pClient->SetSndCrdPreferredMonoBlSizeIndex ( value ); + UpdateSoundCardFrame(); } void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx ) @@ -320,17 +321,19 @@ void CClientSettingsDlg::UpdateDisplay() { // update slider controls (settings might have been changed) UpdateJitterBufferFrame(); - - -// TEST -TextUpstreamValue->setText ( QString().setNum ( pClient->GetUploadRateKbps() ) + " kbps" ); - + UpdateSoundCardFrame(); if ( !pClient->IsRunning() ) { // clear text labels with client parameters TextLabelPingTime->setText ( "" ); TextLabelOverallDelay->setText ( "" ); + TextUpstreamValue->setText ( "" ); + } + else + { + // update upstream rate information label (only if client is running) + TextUpstreamValue->setText ( QString().setNum ( pClient->GetUploadRateKbps() ) + " kbps" ); } } diff --git a/src/settings.cpp b/src/settings.cpp index 2e8198bc..da98d2fc 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -93,6 +93,12 @@ void CSettings::ReadIniFile ( const QString& sFileName ) pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE ); } + // sound card preferred buffer size index + if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", 0, CSndCrdBufferSizes::GetNumOfBufferSizes(), iValue ) ) + { + pClient->SetSndCrdPreferredMonoBlSizeIndex ( iValue ); + } + // automatic network jitter buffer size setting if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) ) { @@ -157,6 +163,9 @@ void CSettings::WriteIniFile ( const QString& sFileName ) // sound card selection SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", pClient->GetSndInterface()->GetDev() ); + // sound card preferred buffer size index + SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", pClient->GetSndCrdPreferredMonoBlSizeIndex() ); + // automatic network jitter buffer size setting SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", pClient->GetDoAutoSockBufSize() ); diff --git a/src/util.h b/src/util.h index c27cef6e..6512805d 100755 --- a/src/util.h +++ b/src/util.h @@ -440,6 +440,12 @@ class CSndCrdBufferSizes { public: static int GetNumOfBufferSizes() { return 30; } + + // we use a conservative value as default, this value does not + // give perfekt latency results but should work ok on most + // sound cards and drivers + static int GetDefaultIndex() { return 5; } + static int GetBufferSizeFromIndex ( const int iIdx ) { if ( ( iIdx >= 0 ) && ( iIdx < 30 ) )