PDA

View Full Version : How to play decoded audio buf using QIODevice



vijayQt
18th August 2011, 14:48
I am initializing audio device before writing to QIODevice.
Here is my code:
initAudioDevice() {
QAudioFormat audioFormat;
audioFormat.setChannelCount(mAudioCodecCtx->channels);
audioFormat.setSampleRate(mAudioCodecCtx->sample_rate);
audioFormat.setSampleSize(16);

audioFormat.setByteOrder(QAudioFormat::LittleEndia n);
audioFormat.setSampleType(QAudioFormat::SignedInt) ;

QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(audioFormat))
{
qWarning() << "Default format not supported - trying to use nearest";
audioFormat = info.nearestFormat(audioFormat);
}

mAudioOutput = new QAudioOutput(info, audioFormat, this);
mIOOutput = mAudioOutput->start();
}

I am using libavcodec decoder to decode audio frames and writting decoded audio buf to "mIOOutput->write()"
mIOOutput->write((char *)mAudioBuffer, mAudioSize);

Here my problem is, Audio is not playing properly.
1. Am I missing anything here?
2. I am feeling, while initializing I am missing some thing. Is it?

Please help me.

Thanks in advance.

ChrisW67
19th August 2011, 01:03
Here my problem is, Audio is not playing properly.
1. Am I missing anything here?

Yes,
tags, any of your code that writes to this device, and description of what "Audio is not playing properly" means.


2. I am feeling, while initializing I am missing some thing. Is it?

Just looking at the example in the QAudioOutput docs I can see you are not setting the codec in your QAudioFormat object.

vijayQt
19th August 2011, 05:58
Yes,
tags, any of your code that writes to this device, and description of what "Audio is not playing properly" means.
Full of noice and lot of breakings in-between :(. Is it becoz of codec or something else?


I can see you are not setting the codec in your QAudioFormat object.
libavcodec and Qt codec's are same or different?