Don't use integers to describe volume internally in QSoundEffect.
The public api takes floating point values and so does most of the back- ends. Conversion should be done in the back-ends that expect other value types to avoid unnecessary float -> int -> float conversions. Change-Id: I0ee1bfbe350f985294c20f897ffa3bd55288b4c9 Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
1cf737648b
commit
0fd995ac8b
@@ -265,7 +265,7 @@ int QSoundEffect::loopsRemaining() const
|
|||||||
*/
|
*/
|
||||||
qreal QSoundEffect::volume() const
|
qreal QSoundEffect::volume() const
|
||||||
{
|
{
|
||||||
return qreal(d->volume()) / 100;
|
return d->volume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -273,15 +273,15 @@ qreal QSoundEffect::volume() const
|
|||||||
*/
|
*/
|
||||||
void QSoundEffect::setVolume(qreal volume)
|
void QSoundEffect::setVolume(qreal volume)
|
||||||
{
|
{
|
||||||
if (volume < 0 || volume > 1) {
|
if (volume < qreal(0.0) || volume > qreal(1.0)) {
|
||||||
qWarning("SoundEffect: volume should be between 0.0 and 1.0");
|
qWarning("SoundEffect: volume should be between 0.0 and 1.0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int iVolume = qRound(volume * 100);
|
|
||||||
if (d->volume() == iVolume)
|
if (qFuzzyCompare(d->volume(), volume))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d->setVolume(iVolume);
|
d->setVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent):
|
|||||||
m_muted(false),
|
m_muted(false),
|
||||||
m_playQueued(false),
|
m_playQueued(false),
|
||||||
m_stopping(false),
|
m_stopping(false),
|
||||||
m_volume(100),
|
m_volume(1.0),
|
||||||
m_loopCount(1),
|
m_loopCount(1),
|
||||||
m_runningCount(0),
|
m_runningCount(0),
|
||||||
m_reloadCategory(false),
|
m_reloadCategory(false),
|
||||||
@@ -517,12 +517,12 @@ void QSoundEffectPrivate::setLoopCount(int loopCount)
|
|||||||
m_loopCount = loopCount;
|
m_loopCount = loopCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSoundEffectPrivate::volume() const
|
qreal QSoundEffectPrivate::volume() const
|
||||||
{
|
{
|
||||||
return m_volume;
|
return m_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSoundEffectPrivate::setVolume(int volume)
|
void QSoundEffectPrivate::setVolume(qreal volume)
|
||||||
{
|
{
|
||||||
m_volume = volume;
|
m_volume = volume;
|
||||||
emit volumeChanged();
|
emit volumeChanged();
|
||||||
@@ -537,7 +537,7 @@ void QSoundEffectPrivate::updateVolume()
|
|||||||
pa_cvolume volume;
|
pa_cvolume volume;
|
||||||
volume.channels = m_pulseSpec.channels;
|
volume.channels = m_pulseSpec.channels;
|
||||||
if (pulseDaemon()->context())
|
if (pulseDaemon()->context())
|
||||||
pa_operation_unref(pa_context_set_sink_input_volume(pulseDaemon()->context(), m_sinkInputId, pulseDaemon()->calcVolume(&volume, m_volume), setvolume_callback, m_ref->getRef()));
|
pa_operation_unref(pa_context_set_sink_input_volume(pulseDaemon()->context(), m_sinkInputId, pulseDaemon()->calcVolume(&volume, qRound(m_volume * 100)), setvolume_callback, m_ref->getRef()));
|
||||||
Q_ASSERT(pa_cvolume_valid(&volume));
|
Q_ASSERT(pa_cvolume_valid(&volume));
|
||||||
#ifdef QT_PA_DEBUG
|
#ifdef QT_PA_DEBUG
|
||||||
qDebug() << this << "updateVolume =" << pa_cvolume_max(&volume);
|
qDebug() << this << "updateVolume =" << pa_cvolume_max(&volume);
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ public:
|
|||||||
int loopCount() const;
|
int loopCount() const;
|
||||||
int loopsRemaining() const;
|
int loopsRemaining() const;
|
||||||
void setLoopCount(int loopCount);
|
void setLoopCount(int loopCount);
|
||||||
int volume() const;
|
qreal volume() const;
|
||||||
void setVolume(int volume);
|
void setVolume(qreal volume);
|
||||||
bool isMuted() const;
|
bool isMuted() const;
|
||||||
void setMuted(bool muted);
|
void setMuted(bool muted);
|
||||||
bool isLoaded() const;
|
bool isLoaded() const;
|
||||||
@@ -153,7 +153,7 @@ private:
|
|||||||
bool m_muted;
|
bool m_muted;
|
||||||
bool m_playQueued;
|
bool m_playQueued;
|
||||||
bool m_stopping;
|
bool m_stopping;
|
||||||
int m_volume;
|
qreal m_volume;
|
||||||
int m_loopCount;
|
int m_loopCount;
|
||||||
int m_runningCount;
|
int m_runningCount;
|
||||||
QUrl m_source;
|
QUrl m_source;
|
||||||
|
|||||||
@@ -175,20 +175,20 @@ void QSoundEffectPrivate::setLoopCount(int loopCount)
|
|||||||
d->m_runningCount = loopCount;
|
d->m_runningCount = loopCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QSoundEffectPrivate::volume() const
|
qreal QSoundEffectPrivate::volume() const
|
||||||
{
|
{
|
||||||
if (d->m_audioOutput && !d->m_muted)
|
if (d->m_audioOutput && !d->m_muted)
|
||||||
return d->m_audioOutput->volume()*100.0f;
|
return d->m_audioOutput->volume();
|
||||||
|
|
||||||
return d->m_volume;
|
return d->m_volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSoundEffectPrivate::setVolume(int volume)
|
void QSoundEffectPrivate::setVolume(qreal volume)
|
||||||
{
|
{
|
||||||
d->m_volume = volume;
|
d->m_volume = volume;
|
||||||
|
|
||||||
if (d->m_audioOutput && !d->m_muted)
|
if (d->m_audioOutput && !d->m_muted)
|
||||||
d->m_audioOutput->setVolume(volume/100.0f);
|
d->m_audioOutput->setVolume(volume);
|
||||||
|
|
||||||
emit volumeChanged();
|
emit volumeChanged();
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ void QSoundEffectPrivate::setMuted(bool muted)
|
|||||||
if (muted && d->m_audioOutput)
|
if (muted && d->m_audioOutput)
|
||||||
d->m_audioOutput->setVolume(0);
|
d->m_audioOutput->setVolume(0);
|
||||||
else if (!muted && d->m_audioOutput && d->m_muted)
|
else if (!muted && d->m_audioOutput && d->m_muted)
|
||||||
d->m_audioOutput->setVolume(d->m_volume/100.0f);
|
d->m_audioOutput->setVolume(d->m_volume);
|
||||||
|
|
||||||
d->m_muted = muted;
|
d->m_muted = muted;
|
||||||
emit mutedChanged();
|
emit mutedChanged();
|
||||||
@@ -314,7 +314,7 @@ PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate* s):
|
|||||||
m_audioOutput(0),
|
m_audioOutput(0),
|
||||||
m_sample(0),
|
m_sample(0),
|
||||||
m_muted(false),
|
m_muted(false),
|
||||||
m_volume(100),
|
m_volume(1.0),
|
||||||
m_sampleReady(false),
|
m_sampleReady(false),
|
||||||
m_offset(0)
|
m_offset(0)
|
||||||
{
|
{
|
||||||
@@ -337,7 +337,7 @@ void PrivateSoundSource::sampleReady()
|
|||||||
m_audioOutput = new QAudioOutput(m_sample->format());
|
m_audioOutput = new QAudioOutput(m_sample->format());
|
||||||
connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
|
connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
|
||||||
if (!m_muted)
|
if (!m_muted)
|
||||||
m_audioOutput->setVolume(m_volume/100.0f);
|
m_audioOutput->setVolume(m_volume);
|
||||||
else
|
else
|
||||||
m_audioOutput->setVolume(0);
|
m_audioOutput->setVolume(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ private:
|
|||||||
QAudioOutput *m_audioOutput;
|
QAudioOutput *m_audioOutput;
|
||||||
QSample *m_sample;
|
QSample *m_sample;
|
||||||
bool m_muted;
|
bool m_muted;
|
||||||
int m_volume;
|
qreal m_volume;
|
||||||
bool m_sampleReady;
|
bool m_sampleReady;
|
||||||
qint64 m_offset;
|
qint64 m_offset;
|
||||||
QString m_category;
|
QString m_category;
|
||||||
@@ -113,8 +113,8 @@ public:
|
|||||||
int loopCount() const;
|
int loopCount() const;
|
||||||
int loopsRemaining() const;
|
int loopsRemaining() const;
|
||||||
void setLoopCount(int loopCount);
|
void setLoopCount(int loopCount);
|
||||||
int volume() const;
|
qreal volume() const;
|
||||||
void setVolume(int volume);
|
void setVolume(qreal volume);
|
||||||
bool isMuted() const;
|
bool isMuted() const;
|
||||||
void setMuted(bool muted);
|
void setMuted(bool muted);
|
||||||
bool isLoaded() const;
|
bool isLoaded() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user