From c22c264123d9437c67293f5043f15434f9abffd9 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 15 Aug 2013 19:15:01 +0000 Subject: [PATCH] Support for three audio quality settings (a new high quality rate is introduced) --- ChangeLog | 2 + src/client.cpp | 56 +++-- src/client.h | 35 +-- src/clientsettingsdlg.cpp | 49 +++-- src/clientsettingsdlg.h | 2 +- src/clientsettingsdlgbase.ui | 404 +++++++++++++++++------------------ src/settings.cpp | 13 +- src/util.h | 10 + 8 files changed, 287 insertions(+), 284 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c057811..432bcf29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ TODO: This feature is disabled for now since it does not work as expected (we DISABLED: - the connection setup dialog can now be opened during a connection +- support for three audio quality settings: low, normal and high + 3.3.1 diff --git a/src/client.cpp b/src/client.cpp index d05e3386..64f4eeb5 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -33,8 +33,8 @@ CClient::CClient ( const quint16 iPortNumber ) : vecStoredFaderLevels ( MAX_NUM_STORED_FADER_LEVELS, AUD_MIX_FADER_MAX ), Channel ( false ), /* we need a client channel -> "false" */ eAudioCompressionType ( CT_OPUS ), - iCeltNumCodedBytes ( CELT_NUM_BYTES_MONO_NORMAL_QUALITY ), - bCeltDoHighQuality ( false ), + iCeltNumCodedBytes ( CELT_NUM_BYTES_MONO_LOW_QUALITY ), + eAudioQuality ( AQ_LOW ), bUseStereo ( false ), bIsInitializationPhase ( true ), Socket ( &Channel, iPortNumber ), @@ -424,7 +424,7 @@ void CClient::SetAudoCompressiontype ( const EAudComprType eNAudCompressionType } } -void CClient::SetCELTHighQuality ( const bool bNCeltHighQualityFlag ) +void CClient::SetAudioQuality ( const EAudioQuality eNAudioQuality ) { // init with new parameter, if client was running then first // stop it and restart again after new initialization @@ -435,7 +435,7 @@ void CClient::SetCELTHighQuality ( const bool bNCeltHighQualityFlag ) } // set new parameter - bCeltDoHighQuality = bNCeltHighQualityFlag; + eAudioQuality = eNAudioQuality; Init(); if ( bWasRunning ) @@ -744,29 +744,29 @@ void CClient::Init() AudioReverbL.Init ( SYSTEM_SAMPLE_RATE_HZ ); AudioReverbR.Init ( SYSTEM_SAMPLE_RATE_HZ ); - // inits for CELT coding - if ( bCeltDoHighQuality ) + // inits for audio coding + if ( eAudioCompressionType == CT_CELT ) { if ( bUseStereo ) { - if ( eAudioCompressionType == CT_CELT ) + if ( eAudioQuality == AQ_LOW ) { - iCeltNumCodedBytes = CELT_NUM_BYTES_STEREO_HIGH_QUALITY; + iCeltNumCodedBytes = CELT_NUM_BYTES_STEREO_LOW_QUALITY; } else { - iCeltNumCodedBytes = OPUS_NUM_BYTES_STEREO_HIGH_QUALITY; + iCeltNumCodedBytes = CELT_NUM_BYTES_STEREO_NORMAL_QUALITY; } } else { - if ( eAudioCompressionType == CT_CELT ) + if ( eAudioQuality == AQ_LOW ) { - iCeltNumCodedBytes = CELT_NUM_BYTES_MONO_HIGH_QUALITY; + iCeltNumCodedBytes = CELT_NUM_BYTES_MONO_LOW_QUALITY; } else { - iCeltNumCodedBytes = OPUS_NUM_BYTES_MONO_HIGH_QUALITY; + iCeltNumCodedBytes = CELT_NUM_BYTES_MONO_NORMAL_QUALITY; } } } @@ -774,24 +774,36 @@ void CClient::Init() { if ( bUseStereo ) { - if ( eAudioCompressionType == CT_CELT ) - { - iCeltNumCodedBytes = CELT_NUM_BYTES_STEREO_NORMAL_QUALITY; - } - else + switch ( eAudioQuality ) { + case AQ_LOW: + iCeltNumCodedBytes = OPUS_NUM_BYTES_STEREO_LOW_QUALITY; + break; + + case AQ_NORMAL: iCeltNumCodedBytes = OPUS_NUM_BYTES_STEREO_NORMAL_QUALITY; + break; + + case AQ_HIGH: + iCeltNumCodedBytes = OPUS_NUM_BYTES_STEREO_HIGH_QUALITY; + break; } } else { - if ( eAudioCompressionType == CT_CELT ) - { - iCeltNumCodedBytes = CELT_NUM_BYTES_MONO_NORMAL_QUALITY; - } - else + switch ( eAudioQuality ) { + case AQ_LOW: + iCeltNumCodedBytes = OPUS_NUM_BYTES_MONO_LOW_QUALITY; + break; + + case AQ_NORMAL: iCeltNumCodedBytes = OPUS_NUM_BYTES_MONO_NORMAL_QUALITY; + break; + + case AQ_HIGH: + iCeltNumCodedBytes = OPUS_NUM_BYTES_MONO_HIGH_QUALITY; + break; } } } diff --git a/src/client.h b/src/client.h index a80f17db..afc15a0c 100755 --- a/src/client.h +++ b/src/client.h @@ -65,17 +65,16 @@ #define AUD_REVERB_MAX 100 // CELT number of coded bytes per audio packet -// 24: mono low/normal quality 156 kbps (128) / 114 kbps (256) -// 44: mono high quality 216 kbps (128) / 174 kbps (256) +// 24: mono low quality 156 kbps (128) / 114 kbps (256) +// 44: mono normal quality 216 kbps (128) / 174 kbps (256) // NOTE: Must be > CELT_MINIMUM_NUM_BYTES (greater, not equal to!) -#define CELT_NUM_BYTES_MONO_NORMAL_QUALITY 24 -#define CELT_NUM_BYTES_MONO_HIGH_QUALITY 44 - -// 46: stereo low/normal quality 222 kbps (128) / 180 kbps (256) -// 70: stereo high quality 294 kbps (128) / 252 kbps (256) -#define CELT_NUM_BYTES_STEREO_NORMAL_QUALITY 46 -#define CELT_NUM_BYTES_STEREO_HIGH_QUALITY 70 +#define CELT_NUM_BYTES_MONO_LOW_QUALITY 24 +#define CELT_NUM_BYTES_MONO_NORMAL_QUALITY 44 +// 46: stereo low quality 222 kbps (128) / 180 kbps (256) +// 70: stereo normal quality 294 kbps (128) / 252 kbps (256) +#define CELT_NUM_BYTES_STEREO_LOW_QUALITY 46 +#define CELT_NUM_BYTES_STEREO_NORMAL_QUALITY 70 // OPUS number of coded bytes per audio packet // TODO we have to use new numbers for OPUS to avoid that old CELT packets @@ -88,11 +87,13 @@ // Fs: sampling rate (SYSTEM_SAMPLE_RATE_HZ) // L: number of samples per packet (SYSTEM_FRAME_SIZE_SAMPLES) // N: number of bytes per packet (values below) +#define OPUS_NUM_BYTES_MONO_LOW_QUALITY 25 +#define OPUS_NUM_BYTES_MONO_NORMAL_QUALITY 45 +#define OPUS_NUM_BYTES_MONO_HIGH_QUALITY 71 -#define OPUS_NUM_BYTES_MONO_NORMAL_QUALITY 25 -#define OPUS_NUM_BYTES_MONO_HIGH_QUALITY 45 -#define OPUS_NUM_BYTES_STEREO_NORMAL_QUALITY 47 -#define OPUS_NUM_BYTES_STEREO_HIGH_QUALITY 71 +#define OPUS_NUM_BYTES_STEREO_LOW_QUALITY 47 +#define OPUS_NUM_BYTES_STEREO_NORMAL_QUALITY 71 +#define OPUS_NUM_BYTES_STEREO_HIGH_QUALITY 142 /* Classes ********************************************************************/ @@ -115,10 +116,10 @@ public: void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; } EGUIDesign GetGUIDesign() const { return eGUIDesign; } - void SetGUIDesign ( const EGUIDesign bNGD ) { eGUIDesign = bNGD; } + void SetGUIDesign ( const EGUIDesign eNGD ) { eGUIDesign = eNGD; } - bool GetCELTHighQuality() const { return bCeltDoHighQuality; } - void SetCELTHighQuality ( const bool bNCeltHighQualityFlag ); + EAudioQuality GetAudioQuality() const { return eAudioQuality; } + void SetAudioQuality ( const EAudioQuality eNAudioQuality ); bool GetUseStereo() const { return bUseStereo; } void SetUseStereo ( const bool bNUseStereo ); @@ -303,7 +304,7 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType ); OpusCustomDecoder* OpusDecoderStereo; EAudComprType eAudioCompressionType; int iCeltNumCodedBytes; - bool bCeltDoHighQuality; + EAudioQuality eAudioQuality; bool bUseStereo; bool bIsInitializationPhase; CVector vecCeltData; diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 92863696..29dc1089 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -192,15 +192,17 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, chbGUIDesignFancy->setAccessibleName ( tr ( "Fancy skin check box" ) ); - // use high quality audio - chbUseHighQualityAudio->setWhatsThis ( tr ( "Use High Quality Audio: " - "If enabled, it will improve the audio quality " - "by increasing the audio stream data rate. Make sure that the current " + // audio quality + QString strAudioQuality = tr ( "Audio Quality: " + "Select the desired audio quality. A low, normal or high audio " + "quality can be selected. The higher the audio quality, the higher " + "the audio stream data rate. Make sure that the current " "upload rate does not exceed the available bandwidth of your " - "internet connection." ) ); + "internet connection." ); - chbUseHighQualityAudio->setAccessibleName ( tr ( "Use high quality audio " - "check box" ) ); + lblAudioQuality->setWhatsThis ( strAudioQuality ); + cbxAudioQuality->setWhatsThis ( strAudioQuality ); + cbxAudioQuality->setAccessibleName ( tr ( "Audio quality combo box" ) ); // use stereo chbUseStereo->setWhatsThis ( tr ( "Stereo Streaming " @@ -311,15 +313,12 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, chbGUIDesignFancy->setCheckState ( Qt::Checked ); } - // "High Quality Audio" check box - if ( pClient->GetCELTHighQuality() ) - { - chbUseHighQualityAudio->setCheckState ( Qt::Checked ); - } - else - { - chbUseHighQualityAudio->setCheckState ( Qt::Unchecked ); - } + // "Audio Quality" combo box + cbxAudioQuality->clear(); + cbxAudioQuality->addItem ( "Low" ); // AQ_LOW + cbxAudioQuality->addItem ( "Normal" ); // AQ_NORMAL + cbxAudioQuality->addItem ( "High" ); // AQ_HIGH + cbxAudioQuality->setCurrentIndex ( static_cast ( pClient->GetAudioQuality() ) ); // "Stereo" check box if ( pClient->GetUseStereo() ) @@ -380,9 +379,6 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, QObject::connect ( chbGUIDesignFancy, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnGUIDesignFancyStateChanged ( int ) ) ); - QObject::connect ( chbUseHighQualityAudio, SIGNAL ( stateChanged ( int ) ), - this, SLOT ( OnUseHighQualityAudioStateChanged ( int ) ) ); - QObject::connect ( chbUseStereo, SIGNAL ( stateChanged ( int ) ), this, SLOT ( OnUseStereoStateChanged ( int ) ) ); @@ -412,6 +408,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent, QObject::connect ( cbxROutChan, SIGNAL ( activated ( int ) ), this, SLOT ( OnROutChanActivated ( int ) ) ); + QObject::connect ( cbxAudioQuality, SIGNAL ( activated ( int ) ), + this, SLOT ( OnAudioQualityActivated ( int ) ) ); + // buttons QObject::connect ( butDriverSetup, SIGNAL ( clicked() ), this, SLOT ( OnDriverSetupClicked() ) ); @@ -631,6 +630,12 @@ void CClientSettingsDlg::OnROutChanActivated ( int iChanIdx ) UpdateSoundChannelSelectionFrame(); } +void CClientSettingsDlg::OnAudioQualityActivated ( int iQualityIdx ) +{ + pClient->SetAudioQuality ( static_cast ( iQualityIdx ) ); + UpdateDisplay(); // upload rate will be changed +} + void CClientSettingsDlg::OnAutoJitBufStateChanged ( int value ) { pClient->SetDoAutoSockBufSize ( value == Qt::Checked ); @@ -657,12 +662,6 @@ void CClientSettingsDlg::OnGUIDesignFancyStateChanged ( int value ) UpdateDisplay(); } -void CClientSettingsDlg::OnUseHighQualityAudioStateChanged ( int value ) -{ - pClient->SetCELTHighQuality ( value == Qt::Checked ); - UpdateDisplay(); // upload rate will be changed -} - void CClientSettingsDlg::OnUseStereoStateChanged ( int value ) { pClient->SetUseStereo ( value == Qt::Checked ); diff --git a/src/clientsettingsdlg.h b/src/clientsettingsdlg.h index 85b4bbe6..b5afac75 100755 --- a/src/clientsettingsdlg.h +++ b/src/clientsettingsdlg.h @@ -83,7 +83,6 @@ protected: void OnAutoJitBufStateChanged ( int value ); void OnOpenChatOnNewMessageStateChanged ( int value ); void OnGUIDesignFancyStateChanged ( int value ); - void OnUseHighQualityAudioStateChanged ( int value ); void OnUseStereoStateChanged ( int value ); void OnDefaultCentralServerStateChanged ( int value ); void OnCentralServerAddressEditingFinished(); @@ -93,6 +92,7 @@ protected: void OnRInChanActivated ( int iChanIdx ); void OnLOutChanActivated ( int iChanIdx ); void OnROutChanActivated ( int iChanIdx ); + void OnAudioQualityActivated ( int iQualityIdx ); void OnDriverSetupClicked(); signals: diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index ee700923..71d216ae 100755 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -1,7 +1,8 @@ - + + CClientSettingsDlgBase - - + + 0 0 @@ -9,38 +10,39 @@ 351 - + General Settings - - :/png/main/res/mainicon.png + + + :/png/main/res/mainicon.png:/png/main/res/mainicon.png - + true - + - - + + Soundcard - + - - + + Device - - - + + + 0 0 - + 153 0 @@ -49,68 +51,59 @@ - - - + + + 0 0 - + QFrame::NoFrame - + QFrame::Plain - - - 0 - - - 0 - - - 0 - - + + 0 - - + + Input Channel Mapping - - + + 3 - + - - - + + + 0 0 - + L - - - + + + 0 0 - + R @@ -118,56 +111,56 @@ - - + + 3 - + - + - - + + Output Channel Mapping - - + + 3 - + - - - + + + 0 0 - + L - - - + + + 0 0 - + R @@ -175,15 +168,15 @@ - - + + 3 - + - + @@ -194,10 +187,10 @@ - + Qt::Vertical - + 153 0 @@ -206,38 +199,38 @@ - - + + Buffer Delay - + - - + + (preferred) - - + + (default) - - + + (safe) - - + + Driver Setup - + false @@ -249,54 +242,54 @@ - - + + Jitter Buffer - + - - + + Auto - + - - + + 50 0 - + Local - + Qt::AlignCenter - + false - - + + 50 0 - + Server - + Qt::AlignCenter - + false @@ -304,41 +297,41 @@ - + - - + + 50 0 - + Size - + Qt::AlignCenter - + false - - + + 50 0 - + Size - + Qt::AlignCenter - + false @@ -346,31 +339,16 @@ - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - + - + Qt::Horizontal - + QSizePolicy::Minimum - + 0 0 @@ -379,27 +357,27 @@ - - + + 1 - + Qt::Vertical - + QSlider::TicksBothSides - + Qt::Horizontal - + QSizePolicy::Minimum - + 0 0 @@ -408,14 +386,14 @@ - - + + 1 - + Qt::Vertical - + QSlider::TicksBothSides @@ -423,16 +401,16 @@ - + - + Qt::Horizontal - + QSizePolicy::Minimum - + 0 0 @@ -441,20 +419,20 @@ - - - + + + 0 0 - + 20 20 - + 20 20 @@ -464,13 +442,13 @@ - + Qt::Horizontal - + QSizePolicy::Minimum - + 0 0 @@ -484,57 +462,58 @@ - - + + Misc - + - - + + Open Chat on New Message - - + + Fancy Skin - - - Qt::NonModal - - - Use High Quality Audio - - - - - - - Qt::NonModal - - + + Stereo Streaming - + - - + + + Audio Quality + + + + + + + + + + + + + Central Server Address: - - + + Default @@ -542,9 +521,9 @@ - - - + + + 0 0 @@ -553,10 +532,10 @@ - + Qt::Vertical - + 201 21 @@ -565,23 +544,23 @@ - + - - + + Audio Stream Rate - - + + 0 20 - + val @@ -589,29 +568,29 @@ - + - - + + Ping Time - - - + + + 0 0 - + 50 20 - + val @@ -619,53 +598,53 @@ - + - - + + Overall Delay - - + + 3 - - - + + + 0 0 - + 50 20 - + val - - - + + + 0 0 - + 20 20 - + 20 20 @@ -704,13 +683,12 @@ sldNetBufServer chbOpenChatOnNewMessage chbGUIDesignFancy - chbUseHighQualityAudio chbUseStereo chbDefaultCentralServer edtCentralServerAddress - + diff --git a/src/settings.cpp b/src/settings.cpp index 11b04437..ccfe2ef6 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -212,10 +212,11 @@ void CSettings::Load() pClient->SetGUIDesign ( static_cast ( iValue ) ); } - // flag whether using high quality audio or not - if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) ) + // audio quality + if ( GetNumericIniSet ( IniXMLDocument, "client", "audioquality", + 0, 2 /* AQ_HIGH */, iValue ) ) { - pClient->SetCELTHighQuality ( bValue ); + pClient->SetAudioQuality ( static_cast ( iValue ) ); } // flag whether stereo mode is used @@ -376,9 +377,9 @@ void CSettings::Save() SetNumericIniSet ( IniXMLDocument, "client", "guidesign", static_cast ( pClient->GetGUIDesign() ) ); - // flag whether using high quality audio or not - SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", - pClient->GetCELTHighQuality() ); + // audio quality + SetNumericIniSet ( IniXMLDocument, "client", "audioquality", + static_cast ( pClient->GetAudioQuality() ) ); // flag whether stereo mode is used SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", diff --git a/src/util.h b/src/util.h index c6ac170e..9f794204 100755 --- a/src/util.h +++ b/src/util.h @@ -450,6 +450,16 @@ enum EAudComprType }; +// Audio quality enum ---------------------------------------------------------- +enum EAudioQuality +{ + // used for settings and the comobo box index -> enum values must be fixed! + AQ_LOW = 0, + AQ_NORMAL = 1, + AQ_HIGH = 2 +}; + + // Get data status enum -------------------------------------------------------- enum EGetDataStat {