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.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should add which version of Qt you are using on which OS



  • It's Qt 4.8 on Linux.


  • Lifetime Qt Champion

    Latest 4.8.6 ?



  • No, I installed Qt from packets and it's version 4.8.2.


  • Lifetime Qt Champion

    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:

    1. playback is resumed
    2. state is changed to Active
    3. there are 2 reads from QIODevice
    4. sound is played for a very short time
    5. there is a buffer underflow
    6. state is changed to Idle
    7. 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.