Fix QAudioOutput volume on OSX.

Change-Id: I142ca638d3dc0839f7c5b103f03edac6715a0bb6
Reviewed-by: Ling Hu <ling.hu@nokia.com>
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
Michael Goddard
2012-06-20 15:53:39 +10:00
committed by Qt by Nokia
parent 84ca713760
commit eb92be7ede
2 changed files with 29 additions and 0 deletions

View File

@@ -297,6 +297,8 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray& device)
stateCode = QAudio::StoppedState; stateCode = QAudio::StoppedState;
audioThreadState.store(Stopped); audioThreadState.store(Stopped);
cachedVolume = (qreal)1.;
intervalTimer = new QTimer(this); intervalTimer = new QTimer(this);
intervalTimer->setInterval(1000); intervalTimer->setInterval(1000);
connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify()));
@@ -408,6 +410,8 @@ bool QAudioOutputPrivate::open()
isOpen = true; isOpen = true;
setVolume(cachedVolume);
return true; return true;
} }
@@ -661,6 +665,27 @@ void QAudioOutputPrivate::stopTimers()
intervalTimer->stop(); intervalTimer->stop();
} }
void QAudioOutputPrivate::setVolume(qreal v)
{
const qreal normalizedVolume = qBound(qreal(0.0), v, qreal(1.0));
if (!isOpen) {
cachedVolume = normalizedVolume;
return;
}
if (AudioUnitSetParameter(audioUnit,
kHALOutputParam_Volume,
kAudioUnitScope_Global,
0 /* bus */,
(float)normalizedVolume,
0) == noErr)
cachedVolume = normalizedVolume;
}
qreal QAudioOutputPrivate::volume() const
{
return cachedVolume;
}
void QAudioOutputPrivate::deviceStopped() void QAudioOutputPrivate::deviceStopped()
{ {

View File

@@ -106,6 +106,7 @@ public:
QMutex mutex; QMutex mutex;
QTimer* intervalTimer; QTimer* intervalTimer;
QAbstractAudioDeviceInfo *audioDeviceInfo; QAbstractAudioDeviceInfo *audioDeviceInfo;
qreal cachedVolume;
QAudio::Error errorCode; QAudio::Error errorCode;
QAudio::State stateCode; QAudio::State stateCode;
@@ -152,6 +153,9 @@ public:
void startTimers(); void startTimers();
void stopTimers(); void stopTimers();
void setVolume(qreal);
qreal volume() const;
private slots: private slots:
void deviceStopped(); void deviceStopped();
void inputReady(); void inputReady();