[Interest] Only buzzing sound while playing wav file through QAudioOutput

Maurice Kalinowski Maurice.Kalinowski at qt.io
Fri Aug 12 13:08:13 CEST 2016


Hi,

Please note that a wav file is a _container_ format, meaning it starts with a header describing the audio format and then continues with chunks of data. For more details have a look here: https://de.wikipedia.org/wiki/RIFF_WAVE

This means that you will need to parse the header and provide the data, not just a file as QIODevice which is meant to be a data stream after you have set up the format correctly.

Maurice


From: Interest [mailto:interest-bounces+maurice.kalinowski=qt.io at qt-project.org] On Behalf Of Anisha Kaul
Sent: Friday, August 12, 2016 12:31 PM
To: interest at qt-project.org
Subject: [Interest] Only buzzing sound while playing wav file through QAudioOutput

Hi,

This time I tried playing a wav file, but I cannot hear anything else than a buzzing sound.
Platform is windows if that matters.

This time the code is in main.cpp.

Please guide.
***********************************************************************************************

#include <QCoreApplication>

#include <QAudioOutput>

#include <QFile>

#include <QDebug>



int main(int argc, char *argv[])

{

    QCoreApplication a(argc, argv);



    QAudioOutput* audioOutpu;



    QFile sourceFile;

    sourceFile.setFileName("c.wav");

    bool p = sourceFile.open(QIODevice::ReadOnly);

    if (p == false)

        qDebug() << "no file";

    else

        qDebug() << "yes file";





    QAudioDeviceInfo d1;

    QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput);



    qDebug() << "======================================================";

    qDebug() << l1.first().supportedCodecs();

    qDebug() << l1.first().supportedChannelCounts();

    qDebug() << l1.first().supportedSampleTypes();

    qDebug() << l1.first().supportedSampleRates();

    qDebug() << l1.first().supportedSampleSizes();



    QAudioFormat desiredFormat1;

    desiredFormat1.setChannelCount(2);

    desiredFormat1.setByteOrder(QAudioFormat::LittleEndian);

    desiredFormat1.setCodec("audio/pcm");

    desiredFormat1.setSampleType(QAudioFormat::SignedInt);

    desiredFormat1.setSampleRate(44100);

    desiredFormat1.setSampleSize(16);



    QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());

    if (!info1.isFormatSupported(desiredFormat1))

    {

           qWarning() << "Default format not supported, trying to use the nearest.";

           desiredFormat1 = info1.preferredFormat();

    }



    audioOutpu = new QAudioOutput(desiredFormat1);

    audioOutpu->setVolume(1.0);



    audioOutpu->start(&sourceFile);

    qDebug() << "bbbbbbbbbb";



    return a.exec();

}


**************************************************************************************************
Output:


("audio/pcm")

(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)

(SignedInt, UnSignedInt, Float)

(8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 192000)

(8, 16, 24, 32, 48, 64)

bbbbbbbbbb




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160812/8f2d34a9/attachment.html>


More information about the Interest mailing list