diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2016-06-07 16:29:35 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@qt.io> | 2016-06-14 09:43:46 +0000 |
commit | 8815920e7f2351ddb989f2f6ee1616f418e638c0 (patch) | |
tree | 1ef15eeda09d52c4d582c425e2c0500111feef1e | |
parent | 618936fc5afc386413caf0915782d4bd4402d115 (diff) | |
download | qtmultimedia-8815920e7f2351ddb989f2f6ee1616f418e638c0.tar.gz |
DirectShow: fix media player volume.
The Qt volume was interpreted as a logarithmic factor but it should
actually be linear.
Change-Id: I0f3e742e934261742bd96f5e3ca3fb42f310864c
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r-- | src/plugins/directshow/player/directshowplayercontrol.cpp | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/plugins/directshow/player/directshowplayercontrol.cpp b/src/plugins/directshow/player/directshowplayercontrol.cpp index d4fd0c8be..fce488af2 100644 --- a/src/plugins/directshow/player/directshowplayercontrol.cpp +++ b/src/plugins/directshow/player/directshowplayercontrol.cpp @@ -45,21 +45,7 @@ #include <QtCore/qcoreapplication.h> #include <QtCore/qmath.h> - -static int volumeToDecibels(int volume) -{ - if (volume == 0) { - return -10000; - } else if (volume == 100) { - return 0; -#ifdef QT_USE_MATH_H_FLOATS - } else if (sizeof(qreal) == sizeof(float)) { - return qRound(::log10f(float(volume) / 100) * 5000); -#endif - } else { - return qRound(::log10(qreal(volume) / 100) * 5000); - } -} +#include <qaudio.h> DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *service, QObject *parent) : QMediaPlayerControl(parent) @@ -168,7 +154,18 @@ void DirectShowPlayerControl::setVolumeHelper(int volume) if (!m_audio) return; - m_audio->put_Volume(volumeToDecibels(volume)); + long adjustedVolume; + if (volume == 0) { + adjustedVolume = -10000; // -100 dB (lower limit for put_Volume()) + } else if (volume == 100) { + adjustedVolume = 0; + } else { + adjustedVolume = QAudio::convertVolume(volume / qreal(100), + QAudio::LinearVolumeScale, + QAudio::DecibelVolumeScale) * 100; + } + + m_audio->put_Volume(adjustedVolume); } int DirectShowPlayerControl::bufferStatus() const |