cduffy
12th April 2013, 20:15
Given a sound file (e.g., .wav), is there a way in Qt 4.7 to extract the audio format from it?
I generate a sound in a way that essentially uses all this example code (http://doc.qt.digia.com/4.7/qaudiooutput.html#details) (from the detailed documentation to the QAudioOutput class).
This involves hard-coding the audio format with this helper method:
QAudioFormat audioFormat()
{
QAudioFormat format;
format.setSampleRate(8000);
format.setChannels(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setSampleType(QAudioFormat::UnSignedInt);
return format;
}
I give the format to the QAudioOutput instance:
QAudioFormat format = audioFormat();
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
audioOutput_ = new QAudioOutput(info, format, this); // audioOutput_ is defined already as a QAudioOutput*
My code works with a .wav file with the right sampling rate.
I would prefer to extract the format from the .wav file instead - that way, I'm not so constrained with what files I have to use. After getting the format, I could say:
format = info.nearestFormat(format);
to get the format to conform to my system. But how do I extract the format from the file?
Thanks!
I generate a sound in a way that essentially uses all this example code (http://doc.qt.digia.com/4.7/qaudiooutput.html#details) (from the detailed documentation to the QAudioOutput class).
This involves hard-coding the audio format with this helper method:
QAudioFormat audioFormat()
{
QAudioFormat format;
format.setSampleRate(8000);
format.setChannels(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setSampleType(QAudioFormat::UnSignedInt);
return format;
}
I give the format to the QAudioOutput instance:
QAudioFormat format = audioFormat();
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
audioOutput_ = new QAudioOutput(info, format, this); // audioOutput_ is defined already as a QAudioOutput*
My code works with a .wav file with the right sampling rate.
I would prefer to extract the format from the .wav file instead - that way, I'm not so constrained with what files I have to use. After getting the format, I could say:
format = info.nearestFormat(format);
to get the format to conform to my system. But how do I extract the format from the file?
Thanks!