Results 1 to 7 of 7

Thread: Appending data to the buffer of a QAudioOutput

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Appending data to the buffer of a QAudioOutput

    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.

    Qt Code:
    1. Buffer = new QBuffer;
    2. Buffer->open(QIODevice::ReadWrite);
    3.  
    4. Output = new QAudioOutput(*Format);
    5.  
    6. Buffer->seek(0);
    7. Buffer->write(Array->data(), Array->length());
    8. Buffer->seek(0);
    9.  
    10. 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:

    Qt Code:
    1. qint64 ActPos = Buffer->pos();
    2. Buffer->seek(Buffer->size());
    3. Buffer->write(Array->data(), Array->length());
    4. 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!

  2. The following user says thank you to PLM for this useful post:

    suspiria (19th March 2012)

Similar Threads

  1. QAudioOutput Play Audio Buffer chat voice ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2011, 19:35
  2. QaudioOutput play buffer audio real time disconnect network ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2011, 12:20
  3. Clear QTcpSocket buffer before using receiving new data
    By tbscope in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2011, 06:50
  4. QAudioOutput buffer underrun
    By BartBlackMagic in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2010, 17:44
  5. data is not appending to the file
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 3rd April 2008, 12:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.