reading data from wav files
Hello
For my application I need to read the sound data from a "wav" file. I found some older C programs doing so, but I was wondering whether or not Qt provides some support for it.
(My application is software for a software defined radio which is using the soundcard, but from time to time I need to tune the software using prerecorded sound streams. The current mode of operation is that on one computer I play the sound file, and through the soundcards - i.e. out on one computer, in on the other - I read back the sound. I am sure that that can be done simpler, reading a file rather than the sound card)
any help, i.e. example code or pointers to code or readable descriptions, is appreciated
best
jan
Re: reading data from wav files
Hello!
First, I would read header data to find out the parameters of recorded data (sampling frequency, sample size, mono/stereo, etc.). Then I would just read samples.
But this is traditional C way as you mentioned.
However I have got question for you. What kind of demodulators do you use, and do you write your own demodulators or using some SDR libraries?
Re: reading data from wav files
I found somewhere the format for wav files, my question was whether or not Qt provided some support in reading and interpreting, e.g. some object that abstracts from the layout of the file. I have been looking around and intend to write a simple object with just some functions for opening, closing and reading the data.
Wrt your question, the demodulators I support are analog, rtty, psk, mfsk, navtex, cw, and fax. All to a certain extent, and most of them based on or at least inspired by other software. All software - apart from the FFT library that I am using (fftw) - is written by me. I started the development as a hobby project, and it still is.
The gui is qt based, the supported device is the elektor card from 2007 (including the extension with an antenna filter.
Soundcard support is using portaudio, Qaudio doesn't work with alsa.
Re: reading data from wav files
Re: reading data from wav files
Thanks, but I do not see how to get access to the actual sample data
best
jan
Re: reading data from wav files
I don't think this is supported by Qt, as it is very specialized - this is something you will have to implement your self.
Re: reading data from wav files
If someone else needs:
void readWAV(QString wavFile)
QFile m_WAVFile;
m_WAVFile.setFileName(wavFile);
m_WAVFile.open(QIODevice::ReadWrite);
char* strm;
QVector<double> m_DATA;
qDebug()<<m_WAVFile.read(4);//RIFF
// m_WAVHeader.RIFF = m_WAVFile.read(4).data();
m_WAVFile.read(strm,4);//chunk size
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,4);//format
qDebug()<<strm;
m_WAVFile.read(strm,4);//subchunk1 id
qDebug()<<strm;
m_WAVFile.read(strm,4);//subchunk1 size
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,2);//audio format
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,2);//NumChannels
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,4);//Sample rate
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,4);//Byte rate
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,2);//Block Allign
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,2);//BPS
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
m_WAVFile.read(strm,4);//subchunk2 id
qDebug()<<strm;
m_WAVFile.read(strm,4);//subchunk2 size
qDebug()<<qFromLittleEndian<quint32>((uchar*)strm) ;
while(!m_WAVFile.atEnd())
{
m_WAVFile.read(strm,2);
if(qFromLittleEndian<short>((uchar*)strm))
m_DATA << (qFromLittleEndian<short>((uchar*)strm));
}