QAudioOutput plays only buffered data on resume
-
Hello.
I've written simple .wav player using QAudioOutput class. I've created simple QIODevice class which is used by QAudioOutput object. It works fine except when I want to suspend and resume the playback. After resuming only buffered data are played and then there is silence. The funny thing is that data are still being fetched from QIODevice object (QAudioOutput calls readData() on QIODevice), there is just no sound. Suspending and resuming playback second time brings everything back to normal.
-
Hi and welcome to devnet,
You should add which version of Qt you are using on which OS
-
Latest 4.8.6 ?
-
Then you should get 4.8.6 to check whether you still have that problem
-
It would be problematic, I would need to install Qt from sources. Moreover I see no point in trying 4.8.6 as there were no changes to Qt Multimedia (pulseaudio part) since 2011 and 4.8.2 was released in 2012.
The problem is as follows:
- playback is resumed
- state is changed to Active
- there are 2 reads from QIODevice
- sound is played for a very short time
- there is a buffer underflow
- state is changed to Idle
- there are still reads from QIODevice but there is no sound. I think this is due to this code from qaudiooutput_pulse.cpp:
@
l = m_audioSource->read(buffer, m_periodSize);
if (l > 0) {
if (m_deviceState != QAudio::ActiveState)
return true;
qint64 bytesWritten = write(buffer, l);
Q_UNUSED(bytesWritten);
}
@
This explains the funny behaviour when data are read from supplied device but not played back. Once the state is changed to Idle, there is no chance for data to be written to buffer although they are still fetched from QIODevice. Anyway the bigger problem is why there is buffer underflow just after resume although the device always returns data.