1 Attachment(s)
Only buzzing sound while playing wav/mp3 files through QAudioOutput
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:
Code:
#include <QCoreApplication>
#include <QAudioOutput>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QAudioOutput* audioOutpu;
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";
QObject::connect(audioOutpu,
SIGNAL(stateChanged
(QAudio
::State)),
&loop,
SLOT(quit
()));
do {
loop.exec();
} while(audioOutpu->state() == QAudio::ActiveState);
return a.exec();
}
Output:
Attachment 12071
Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput
Is your input file in the format you are trying to play?
Have you tried a QMediaPlayer instead?
Cheers,
_
Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput
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.
Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput
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..