0

I have the following setup,

audio_output = new QAudioOutput(*audio_format, this);
audio_device = audio_output->start(); // Return QIODevice
audio_device->open(QIODevice::ReadWrite);

I need a function that writes data to the end of the audio_device stream whilst it's playing. The problem is that as it's playing, it's changing the pos (tested this). I need to call,

audio_device->write(buffer, byte - buffer);

To write to the end of the written buffer. How can I have it play and write at the same time?

Many thanks for any help here.

__Edit__

Partial fix! It makes a slight crackle.

while (audio_device->write(buffer, byte - buffer) < 1)
    usleep(10);

Looks like it was failing to write the buffer. Is there a nicer way to do that?

Jacob
  • 1,335
  • 1
  • 14
  • 28
  • Can try to feed in an [QBuffer](http://qt-project.org/doc/qt-5.0/qtcore/qbuffer.html) to [QAudioOutput::start(QIODevice * device)](http://qt-project.org/doc/qt-5.0/qtmultimedia/qaudiooutput.html#start); From that, you should be able to stream data into the buffer instead of using audio_device's write(). – Son-Huy Pham Jul 08 '13 at 16:51
  • Wouldn't that still write at the position of the read? – Jacob Jul 08 '13 at 17:05
  • I expect that adding/appending to the buffer would not interrupt the play-back - it's worth trying. – Son-Huy Pham Jul 08 '13 at 17:16
  • That doesn't produce any output now. :S I used [link](http://pastebin.com/LsqYdwud) – Jacob Jul 08 '13 at 17:42
  • Would an empty buffer cause the audio_device to cease play-back? Can you make sure that there's data in the buffer before calling start()? – Son-Huy Pham Jul 08 '13 at 17:46
  • 1
    Empty data definitely stops the playback. Infact, I get a buffer underflow error. The issue is when the audio output reads, it changes the pos() in the audio_device, so when I write, I write exactly where it's reading. The result is garbled sounds at random points through the song for a second, then nothing. – Jacob Jul 08 '13 at 17:53
  • Ahhh, Sounds like you may have to implement some buffer "slices" (i.e. fragments) that you can feed to the audio_device when the it reaches the end of the current buffer - not sure how seamless this will be though - I haven't dealt with streaming data – Son-Huy Pham Jul 08 '13 at 18:05

0 Answers0