How to play raw audio with QBuffer and QAudioOutput?



  • Here's my code

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QBuffer buffer;
        buffer.open(QIODevice::ReadWrite);
        QDataStream opt(&buffer);
        Decoder dcdr;//this is my class, convert silkv3 to raw.it works.
        dcdr.decodeSilk("msg1.amr",&opt);
        qDebug()<<buffer.buffer().length();
        QAudioFormat fmt;
        fmt.setCodec("audio/pcm");
        fmt.setSampleRate(24000);
        fmt.setSampleSize(8);
        fmt.setChannelCount(1);
        fmt.setSampleType(QAudioFormat::UnSignedInt);
        fmt.setByteOrder(QAudioFormat::LittleEndian);
        QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
        if (!info.isFormatSupported(fmt)) {
            qWarning()<<"raw audio format not supported by backend, cannot play audio.";
        }
    
        QAudioOutput *player=new QAudioOutput(fmt);
        //player->setVolume(1);
        player->start(&buffer);
        qDebug()<<player->state();
        return 0;
    }
    

    But I can't hear any sound while it running.

    Thanks!


  • Lifetime Qt Champion

    Hi,

    You're not letting the event loop run so basically, you start the player and the program ends right after that.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.