diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 3cc2e838f..4d19c02f5 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -135,11 +135,10 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } const bool wasMuted = this->isMuted(); - if (volume > CSettings::OutMax) { volume = CSettings::OutMax; } - else if (volume < CSettings::OutMax) { volume = CSettings::OutMax; } + volume = CSettings::fixOutVolume(volume); const int currentVolume = m_voiceClient.getNormalizedOutputVolume(); - bool changedVoiceOutput = (currentVolume != volume); + const bool changedVoiceOutput = (currentVolume != volume); if (changedVoiceOutput) { m_voiceClient.setOutputVolumeDb(volume); diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index b06589b64..d2563579a 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -22,6 +22,20 @@ namespace BlackMisc { namespace Audio { + int CSettings::fixOutVolume(int v) + { + if (v > OutMax) { return OutMax; } + if (v < OutMin) { return OutMin; } + return v; + } + + int CSettings::fixInVolume(int v) + { + if (v > InMax) { return InMax; } + if (v < InMin) { return InMin; } + return v; + } + CSettings::CSettings() { this->initDefaultValues(); @@ -82,16 +96,12 @@ namespace BlackMisc void CSettings::setOutVolume(int volume) { - if (volume > OutMax) { volume = OutMax; } - else if (volume < OutMin) { volume = OutMin; } - m_outVolume = volume; + m_outVolume = fixOutVolume(volume); } void CSettings::setInVolume(int volume) { - if (volume > InMax) { volume = InMax; } - else if (volume < InMin) { volume = InMin; } - m_inVolume = volume; + m_inVolume = fixInVolume(volume); } QString CSettings::convertToQString(bool i18n) const diff --git a/src/blackmisc/audio/audiosettings.h b/src/blackmisc/audio/audiosettings.h index cce7ba401..322a1eb21 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -37,6 +37,11 @@ namespace BlackMisc static constexpr int OutMin = 0; //! @} + //! Make sure the volume is within the range @{ + static int fixOutVolume(int v); + static int fixInVolume(int v); + //! @} + //! Default constructor. CSettings(); @@ -112,8 +117,8 @@ namespace BlackMisc QString m_notificationSoundDir; int m_notification = static_cast(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) int m_notificationVolume = 90; //!< 0-90 - int m_outVolume = 100; //!< 0-300, AFV - int m_inVolume = 0; //!< AFV range + int m_outVolume = 50; //!< 0-100, AFV + int m_inVolume = 50; //!< AFV range bool m_audioEffects = true; //!< Audio effects en void initNotificationFlags(); //!< init flags