Add new implementation of QSound class
Added a re-implementation of QSound, using functionality derived from QSoundEffect. QSound API remains the same as the original 4.x version. It offers both a static interface (with auto resource cleanup on sound completion), as well as an object instance interface for more detailed control. Change-Id: I85c00dd88547f8dea9b1e1ef2da31d2f2e28a172 Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
c13a13c486
commit
f9ec11a25e
@@ -410,7 +410,7 @@ void QSoundEffectPrivate::setSource(const QUrl &url)
|
||||
m_sampleReady = false;
|
||||
|
||||
PulseDaemonLocker locker;
|
||||
m_runningCount = 0;
|
||||
setLoopsRemaining(0);
|
||||
if (m_pulseStream && !pa_stream_is_corked(m_pulseStream)) {
|
||||
pa_stream_set_write_callback(m_pulseStream, 0, 0);
|
||||
pa_stream_set_underflow_callback(m_pulseStream, 0, 0);
|
||||
@@ -444,6 +444,11 @@ int QSoundEffectPrivate::loopCount() const
|
||||
return m_loopCount;
|
||||
}
|
||||
|
||||
int QSoundEffectPrivate::loopsRemaining() const
|
||||
{
|
||||
return m_runningCount;
|
||||
}
|
||||
|
||||
void QSoundEffectPrivate::setLoopCount(int loopCount)
|
||||
{
|
||||
if (loopCount == 0)
|
||||
@@ -542,6 +547,17 @@ void QSoundEffectPrivate::setStatus(QSoundEffect::Status status)
|
||||
emit loadedChanged();
|
||||
}
|
||||
|
||||
void QSoundEffectPrivate::setLoopsRemaining(int loopsRemaining)
|
||||
{
|
||||
#ifdef QT_PA_DEBUG
|
||||
qDebug() << this << "setLoopsRemaining " << loopsRemaining;
|
||||
#endif
|
||||
if (m_runningCount == loopsRemaining)
|
||||
return;
|
||||
m_runningCount = loopsRemaining;
|
||||
emit loopsRemainingChanged();
|
||||
}
|
||||
|
||||
void QSoundEffectPrivate::play()
|
||||
{
|
||||
#ifdef QT_PA_DEBUG
|
||||
@@ -561,7 +577,7 @@ void QSoundEffectPrivate::play()
|
||||
#ifdef QT_PA_DEBUG
|
||||
qDebug() << this << "restart playing";
|
||||
#endif
|
||||
m_runningCount = 0;
|
||||
setLoopsRemaining(0);
|
||||
m_playQueued = true;
|
||||
Q_ASSERT(m_pulseStream);
|
||||
emptyStream();
|
||||
@@ -708,7 +724,7 @@ void QSoundEffectPrivate::prepare()
|
||||
}
|
||||
if (m_playQueued) {
|
||||
m_playQueued = false;
|
||||
m_runningCount = m_loopCount;
|
||||
setLoopsRemaining(m_loopCount);
|
||||
playSample();
|
||||
}
|
||||
}
|
||||
@@ -727,7 +743,7 @@ void QSoundEffectPrivate::uploadSample()
|
||||
if (m_position == m_sample->data().size()) {
|
||||
m_position = 0;
|
||||
if (m_runningCount > 0)
|
||||
m_runningCount--;
|
||||
setLoopsRemaining(m_runningCount - 1);
|
||||
if (m_runningCount == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -745,7 +761,7 @@ void QSoundEffectPrivate::uploadSample()
|
||||
if (m_position == m_sample->data().size()) {
|
||||
m_position = 0;
|
||||
if (m_runningCount > 0)
|
||||
m_runningCount--;
|
||||
setLoopsRemaining(m_runningCount - 1);
|
||||
if (m_runningCount != 0 && firstPartLength < writableSize)
|
||||
{
|
||||
while (writtenBytes < writableSize) {
|
||||
@@ -760,7 +776,7 @@ void QSoundEffectPrivate::uploadSample()
|
||||
break;
|
||||
}
|
||||
if (m_runningCount > 0)
|
||||
m_runningCount--;
|
||||
setLoopsRemaining(m_runningCount - 1);
|
||||
if (m_runningCount == 0)
|
||||
break;
|
||||
}
|
||||
@@ -793,7 +809,7 @@ void QSoundEffectPrivate::stop()
|
||||
m_stopping = true;
|
||||
if (m_pulseStream)
|
||||
emptyStream();
|
||||
m_runningCount = 0;
|
||||
setLoopsRemaining(0);
|
||||
m_position = 0;
|
||||
m_playQueued = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user