Hi,
I'm writing an application which plays audio using QAudioOutput.
The audio is decoded by libavcodec in a separate thread and passed to the main thread in pieces.
The main thread starts playing the audio that was already decoded and keeps playing while new audio data is appended to the buffer.
To do so I am using a QBuffer opened in ReadWrite-mode.
Output = new QAudioOutput(*Format);
Buffer->seek(0);
Buffer->write(Array->data(), Array->length());
Buffer->seek(0);
Output->start(Buffer);
Buffer = new QBuffer;
Buffer->open(QIODevice::ReadWrite);
Output = new QAudioOutput(*Format);
Buffer->seek(0);
Buffer->write(Array->data(), Array->length());
Buffer->seek(0);
Output->start(Buffer);
To copy to clipboard, switch view to plain text mode
When I append data to the buffer after having called start() I need to reset the position where data is read and written to it's initial value:
qint64 ActPos = Buffer->pos();
Buffer->seek(Buffer->size());
Buffer->write(Array->data(), Array->length());
Buffer->seek(ActPos);
qint64 ActPos = Buffer->pos();
Buffer->seek(Buffer->size());
Buffer->write(Array->data(), Array->length());
Buffer->seek(ActPos);
To copy to clipboard, switch view to plain text mode
This seems to work as far as I can't hear any disruptions in the played audio, but I doubt that this is the optimum method.
How does QAudioOutput manage this buffer?
Does it grab the bytes one by one or are they copied to the audio memory in chunks?
Does it matter if the buffer isn't available for a short moment e.g. while I am writing to it?
Thanks in advance for your answers!
Bookmarks