Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to write audio data while playing sound?



  • I want to append data to the existing buffer so that the sound comes out continuously .
    so I tried QIODevice::ReadWrite of Qbuffer's openmode but I do not hear anything.(If QIODevice::ReadOnly is work well.)

    QByteArray part;
    inputFile.open(QIODevice::ReadWrite);
    part=inputFile.read(inputFile.size()/4);
    buffer.write(part);
    audioOutput->setNotifyInterval(4000);
    connect(audioOutput,SIGNAL(notify()),this,SLOT(appendData()));
    audioOutput->start(&buffer);

    void Widget::appendData()
    {
    part=inputFile.read(inputFile.size()/4);
    buffer.write(part);
    }


  • Lifetime Qt Champion

    Hi,

    What is that buffer ?
    Where do you create it ?
    What version of Qt are you using ?
    What platform are you running Qt on ?



  • buffer is QBuffer. version 5.11.1 and windows10.
    I just want to append data in the sound buffer while the sound is playing. Like streaming.


  • Lifetime Qt Champion

    Are you checking the state of the audioOutput object for errors ?

    On a related note, why not pass inputFile to audioOutput->start rather than passing through a buffer ?



  • Since audioOutput returns ActiveState, it seems to be no problem.
    The reason I do not use inputfile(QFile) is to decode and play the file directly using libav(ffmpeg).



  • I solve it by using QDataStream. Thanks.


  • Lifetime Qt Champion

    HI @name101

    glad you solved it. So please mark this topic as SOLVED too. Thanks


Log in to reply