PDA

View Full Version : Only buzzing sound while playing wav/mp3 files through QAudioOutput



TheIndependentAquarius
16th August 2016, 08:53
Using Qt 5.5.1 on a Windows 7 desktop and a laptop.

I have tried the following program with mp3, wav, flac files. I can only hear the buzzing sound, nothing else. Please guide.

The reproducable example:



#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::LittleEn dian);
desiredFormat1.setCodec("audio/pcm");
desiredFormat1.setSampleType(QAudioFormat::SignedI nt);
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";
QEventLoop loop;
QObject::connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
do {
loop.exec();
} while(audioOutpu->state() == QAudio::ActiveState);

return a.exec();
}


Output:
12071

anda_skoa
17th August 2016, 19:14
Is your input file in the format you are trying to play?

Have you tried a QMediaPlayer instead?

Cheers,
_

TheIndependentAquarius
19th August 2016, 09:19
I realised that the wav file which I was running was not actually a wav file. It was a mpeg compressed file with the extension wav.
With a real wav file, this example works fine.

hakanaktanasis
17th June 2019, 15:46
I know it has been long time.
Would someone tell me how to play wav file with QAudioOutput ?
File format is wrong i think but i do not know how to fix it.
I am using Qt 4.8 and having same buzz problem.

thanx in advance..