PDA

View Full Version : Playing ulaw file with QAudioOutput



sulliwk06
17th December 2013, 15:57
So I'm trying to set up a simple working example to play a ulaw file and the audio seems to be distorted. I thought someone here might have encountered this before and immediately know what I'm doing wrong.

the ulaw file is:
sample rate - 8 khz
mono
sample size - 8

When the ulaw file plays, I can still make out everything, its just fairly distorted, like listening to a radio station going out of range.

I tried using sox to convert it to a wav file, I played it in windows media player just to make sure the file was good, and it sounded fine. Then I used my code to play the wav file after chopping off the header. And it sounds just as distorted as it did with the ulaw file.

I don't know how to tell what codec windows media player is using to play the file, but the only codec I get from supportedCodecs() is "audio/pcm".

Let me know if anything wrong jumps out at you. I'm still pretty new to all this audio stuff.




m_format.setSampleRate(8000);
m_format.setChannelCount(1);
m_format.setSampleSize(8);
m_format.setCodec("audio/pcm");

QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(m_format))
{
m_format = info.nearestFormat(m_format);
}

QAudioOutput output(m_device, m_format, this);

QFile audio_file("C:\\track1_in1.ul");

if(audio_file.open(QIODevice::ReadOnly))
{
// audio_file.seek(44); //for when I tried to do the same with a WAV file
QByteArray audio_data = audio_file.readAll();
audio_file.close();

QBuffer audio_buffer(&audio_data);
audio_buffer.open(QIODevice::ReadOnly);
output.start(&audio_buffer);

QEventLoop loop;
QObject::connect(&output, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
do
{
loop.exec();
} while(output.state() == QAudio::ActiveState);
}

rsafir
20th June 2014, 08:27
I am having the same problem. Did you find a solution?
Many thanks!!

sulliwk06
23rd June 2014, 13:41
I am having the same problem. Did you find a solution?
Many thanks!!

I ended up converting my ulaw file to a wav in the code (its not hard, just adding a header) and played it with QMediaPlayer.