Important: Please read the Qt Code of Conduct -

QIODevice and QAudioOutput

  • Hi everyone,

    I'm trying to get QAudioOutput working in pull mode, so I can output audio buffers in real time. I have subclassed QIODevice and implemented the method readData(char *data, qint64 len). Then I passed this subclass to QAudioOutput::start(QIODevice* device). So far everything works as it should: My readData copies data from a QByteArray to the memory pointed to be the data argument, and I can hear the sine wave output. But len always has a value of 16384, regardless of how I setBufferSize on the QAudioOutput instance.

    For example, if I do setBufferSize(256) and afterwards do qDebug() << audioOutput->bufferSize(), it says 256. periodSize() returns 2048, which is logical for the size in bytes because it's 8 * 256. But still len has a value of 16384. Why is that?

    And how can I ask my QAudioOutput instance what len value it's going to give me before I start() it? I need to prepare my other program parts (qreal arrays) to the right size.

    [EDIT] After some more tests, it seems like QAudioOutput returns different values for bufferSize() before and after start(). Before start(), it returns 256, but after start() it returns 4096.

Log in to reply