fix volume handling on Windows
volume handling for QAudioOutput is broken currently as it fallbacks to the default implementation. Need to cache the volume, as hWaveOut is invalid while the output is not in active state. Task-number: QTBUG-25454 Change-Id: I2adb28a5e6719a5d3c360553abd70af46b646080 Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
4bbbffeebc
commit
6d2883e7ed
@@ -117,6 +117,7 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device)
|
||||
audioSource = 0;
|
||||
pullMode = true;
|
||||
finished = false;
|
||||
volumeCache = (qreal)1.;
|
||||
}
|
||||
|
||||
QAudioOutputPrivate::~QAudioOutputPrivate()
|
||||
@@ -380,6 +381,8 @@ bool QAudioOutputPrivate::open()
|
||||
timeStampOpened.restart();
|
||||
elapsedTimeOffset = 0;
|
||||
|
||||
setVolume(volumeCache);
|
||||
|
||||
errorState = QAudio::NoError;
|
||||
if(pullMode) {
|
||||
deviceState = QAudio::ActiveState;
|
||||
@@ -667,6 +670,25 @@ QAudio::State QAudioOutputPrivate::state() const
|
||||
return deviceState;
|
||||
}
|
||||
|
||||
void QAudioOutputPrivate::setVolume(qreal v)
|
||||
{
|
||||
const qreal normalizedVolume = qBound(qreal(0.0), v, qreal(1.0));
|
||||
if (deviceState != QAudio::ActiveState) {
|
||||
volumeCache = normalizedVolume;
|
||||
return;
|
||||
}
|
||||
const qint16 scaled = normalizedVolume * 0xFFFF;
|
||||
DWORD vol = MAKELONG(scaled, scaled);
|
||||
MMRESULT res = waveOutSetVolume(hWaveOut, vol);
|
||||
if (res == MMSYSERR_NOERROR)
|
||||
volumeCache = normalizedVolume;
|
||||
}
|
||||
|
||||
qreal QAudioOutputPrivate::volume() const
|
||||
{
|
||||
return volumeCache;
|
||||
}
|
||||
|
||||
void QAudioOutputPrivate::reset()
|
||||
{
|
||||
close();
|
||||
|
||||
@@ -112,6 +112,8 @@ public:
|
||||
qint64 elapsedUSecs() const;
|
||||
QAudio::Error error() const;
|
||||
QAudio::State state() const;
|
||||
void setVolume(qreal);
|
||||
qreal volume() const;
|
||||
|
||||
QIODevice* audioSource;
|
||||
QAudioFormat settings;
|
||||
@@ -134,6 +136,7 @@ private:
|
||||
qint64 totalTimeValue;
|
||||
bool pullMode;
|
||||
int intervalTime;
|
||||
qreal volumeCache;
|
||||
static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
|
||||
DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user