diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2016-10-04 13:56:02 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@qt.io> | 2016-11-02 13:40:35 +0000 |
commit | 4663063d021a76e7662813438f72fcfb42ff2252 (patch) | |
tree | 19f208517caf9018653356b42c648691e96442ce /src/plugins | |
parent | c671c09b037277e9d61068d6f6dd97073217946d (diff) | |
download | qtmultimedia-4663063d021a76e7662813438f72fcfb42ff2252.tar.gz |
WindowsAudio: fix volume when using multiple QAudioOutputs
We were using Windows' waveOutSetVolume() function to set the volume
on an audio stream. That function applies the volume on the sound
device and not on a particular stream, meaning all QAudioOutputs and
QSoundEffects were sharing the same volume. All Qt audio streams are
supposed to have their volume controllable separately; in order to
respect that, we now apply the volume ourselves on the data before
writing it to the device.
Task-number: QTBUG-43765
Task-number: QTBUG-48049
Change-Id: I407588ca40cf4216454431fe3e6ce4d8740f391d
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/windowsaudio/qwindowsaudiooutput.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp b/src/plugins/windowsaudio/qwindowsaudiooutput.cpp index 22746a63a..b0de6bf47 100644 --- a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp +++ b/src/plugins/windowsaudio/qwindowsaudiooutput.cpp @@ -47,6 +47,7 @@ #include "qwindowsaudioutils.h" #include <QtEndian> #include <QtCore/QDataStream> +#include <private/qaudiohelpers_p.h> //#define DEBUG_AUDIO 1 @@ -66,7 +67,7 @@ QWindowsAudioOutput::QWindowsAudioOutput(const QByteArray &device) audioSource = 0; pullMode = true; finished = false; - volumeCache = (qreal)1.; + volumeCache = qreal(1.0); } QWindowsAudioOutput::~QWindowsAudioOutput() @@ -274,8 +275,6 @@ bool QWindowsAudioOutput::open() timeStampOpened.restart(); elapsedTimeOffset = 0; - setVolume(volumeCache); - errorState = QAudio::NoError; if(pullMode) { deviceState = QAudio::ActiveState; @@ -401,7 +400,11 @@ qint64 QWindowsAudioOutput::write( const char *data, qint64 len ) remain = l; else remain = period_size; - memcpy(current->lpData, p, remain); + + if (volumeCache < qreal(1.0)) + QAudioHelperInternal::qMultiplySamples(volumeCache, settings, p, current->lpData, remain); + else + memcpy(current->lpData, p, remain); l -= remain; p += remain; @@ -589,16 +592,10 @@ QAudio::State QWindowsAudioOutput::state() const void QWindowsAudioOutput::setVolume(qreal v) { - const qreal normalizedVolume = qBound(qreal(0.0), v, qreal(1.0)); - if (deviceState != QAudio::ActiveState) { - volumeCache = normalizedVolume; + if (qFuzzyCompare(volumeCache, v)) return; - } - const quint16 scaled = normalizedVolume * 0xFFFF; - DWORD vol = MAKELONG(scaled, scaled); - MMRESULT res = waveOutSetVolume(hWaveOut, vol); - if (res == MMSYSERR_NOERROR) - volumeCache = normalizedVolume; + + volumeCache = qBound(qreal(0), v, qreal(1)); } qreal QWindowsAudioOutput::volume() const |