From 679639c1189cc2ca2fbb8b55f8b5ba5ba7b431d7 Mon Sep 17 00:00:00 2001 From: fritsch Date: Wed, 2 Apr 2014 08:59:24 +0200 Subject: [PATCH] AE: User per cent volume by default --- xbmc/Application.cpp | 11 +---------- xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp | 6 ++++-- xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h | 3 ++- xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp | 4 +--- xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp | 9 --------- xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h | 5 +---- xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp | 4 ++-- xbmc/cores/AudioEngine/Utils/AEUtil.h | 6 +++++- 8 files changed, 16 insertions(+), 32 deletions(-) diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 2f832b8016174..4f9df59f0ddc4 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -5352,16 +5352,7 @@ void CApplication::SetHardwareVolume(float hardwareVolume) hardwareVolume = std::max(VOLUME_MINIMUM, std::min(VOLUME_MAXIMUM, hardwareVolume)); m_volumeLevel = hardwareVolume; - float value = 0.0f; - if (hardwareVolume > VOLUME_MINIMUM) - { - float dB = CAEUtil::PercentToGain(hardwareVolume); - value = CAEUtil::GainToScale(dB); - } - if (value >= 0.99f) - value = 1.0f; - - CAEFactory::SetVolume(value); + CAEFactory::SetVolume(hardwareVolume); } float CApplication::GetVolume(bool percentage /* = true */) const diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp index dfac0a43cdbb0..f60c9d7ff9431 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp @@ -149,6 +149,7 @@ CActiveAE::CActiveAE() : m_vizBuffers = NULL; m_vizBuffersInput = NULL; m_volume = 1.0; + m_volumeScaled = 1.0; m_aeVolume = 1.0; m_muted = false; m_aeMuted = false; @@ -225,6 +226,7 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg) return; case CActiveAEControlProtocol::VOLUME: m_volume = *(float*)msg->data; + m_volumeScaled = CAEUtil::GainToScale(CAEUtil::PercentToGain(m_volume)); if (m_sinkHasVolume) m_sink.m_controlPort.SendOutMessage(CSinkControlProtocol::VOLUME, &m_volume, sizeof(float)); return; @@ -2068,11 +2070,11 @@ void CActiveAE::MixSounds(CSoundPacket &dstSample) void CActiveAE::Deamplify(CSoundPacket &dstSample) { - if (m_volume < 1.0 || m_muted) + if (m_volumeScaled < 1.0 || m_muted) { float *buffer; int nb_floats = dstSample.nb_samples * dstSample.config.channels / dstSample.planes; - float volume = m_muted ? 0.0f : m_volume; + float volume = m_muted ? 0.0f : m_volumeScaled; for(int j=0; j m_sounds_playing; std::vector m_sounds; - float m_volume; + float m_volume; // volume on a 0..1 scale corresponding to a proportion along the dB scale + float m_volumeScaled; // multiplier to scale samples in order to achieve the volume specified in m_volume bool m_muted; bool m_sinkHasVolume; diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp index c1d0d1dc0a7a8..7750dbafaee52 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp @@ -217,9 +217,7 @@ void CAESinkAUDIOTRACK::SetVolume(float scale) if (!m_at_jni) return; - // Android uses fixed steps, reverse scale back to percent - float gain = CAEUtil::ScaleToGain(scale); - m_volume = CAEUtil::GainToPercent(gain); + m_volume = scale; if (!m_passthrough) { CXBMCApp::SetSystemVolume(xbmc_jnienv(), m_volume); diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp index 8814eaaca4b2f..973d94423c4f8 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp @@ -724,7 +724,6 @@ bool CAESinkDARWINIOS::Initialize(AEAudioFormat &format, std::string &device) format.m_sampleRate = m_audioSink->getRealisedSampleRate(); m_format = format; - m_volume_changed = false; m_audioSink->play(false); return true; @@ -799,14 +798,6 @@ bool CAESinkDARWINIOS::HasVolume() return false; } -void CAESinkDARWINIOS::SetVolume(float scale) -{ - // CoreAudio uses fixed steps, reverse scale back to percent - float gain = CAEUtil::ScaleToGain(scale); - m_volume = CAEUtil::GainToPercent(gain); - m_volume_changed = true; -} - void CAESinkDARWINIOS::EnumerateDevicesEx(AEDeviceInfoList &list, bool force) { m_devices.clear(); diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h index f1fec67e25eb0..108924593cc91 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h +++ b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h @@ -51,18 +51,15 @@ class CAESinkDARWINIOS : public IAESink virtual unsigned int AddPackets (uint8_t *data, unsigned int frames, bool hasAudio, bool blocking = false); virtual void Drain (); virtual bool HasVolume (); - virtual void SetVolume (float scale); static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false); private: static AEDeviceInfoList m_devices; CAEDeviceInfo m_info; AEAudioFormat m_format; - double m_volume; - bool m_volume_changed; CAAudioUnitSink *m_audioSink; #if DO_440HZ_TONE_TEST SineWaveGenerator m_SineWaveGenerator; #endif -}; \ No newline at end of file +}; diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp index 573e4686f7100..751516704a179 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp @@ -812,8 +812,8 @@ void CAESinkPULSE::SetVolume(float volume) { if (m_IsAllocated && !m_passthrough) { - // undo internal Engine pseudo gain calculation - float per_cent_volume = CAEUtil::GainToPercent(CAEUtil::ScaleToGain(volume)); + // clamp possibly too large / low values + float per_cent_volume = std::max(0.0f, std::min(volume, 1.0f)); pa_threaded_mainloop_lock(m_MainLoop); bool external_change = false; diff --git a/xbmc/cores/AudioEngine/Utils/AEUtil.h b/xbmc/cores/AudioEngine/Utils/AEUtil.h index c6a31841e4ca5..62581d084640b 100644 --- a/xbmc/cores/AudioEngine/Utils/AEUtil.h +++ b/xbmc/cores/AudioEngine/Utils/AEUtil.h @@ -108,7 +108,11 @@ class CAEUtil */ static inline const float GainToScale(const float dB) { - return pow(10.0f, dB/20); + float val = pow(10.0f, dB/20); + if (val >= 0.99f) + val = 1.0f; + + return val; } /*! \brief convert a scale factor to dB gain for audio manipulation