Results 1 to 7 of 7

Thread: reading data from wav files

  1. #1
    Join Date
    Mar 2008
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Platforms
    Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Jan 2010
    Location
    Poland Warsaw
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  3. #3
    Join Date
    Mar 2008
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: reading data from wav files

    It looks like Phonon has a built in support for playing wav files:
    http://doc.trolltech.com/4.7/phonon-audiooutput.html
    http://doc.trolltech.com/4.7/phonon-...honon-overview
    Last edited by high_flyer; 9th February 2011 at 09:14.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2008
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Platforms
    Unix/X11 Windows

    Default Re: reading data from wav files

    Thanks, but I do not see how to get access to the actual sample data

    best
    jan

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Sep 2013
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default 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));
    }

Similar Threads

  1. Reading .plist files on Windows
    By alexivanov91 in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2010, 10:07
  2. Reading files from a perticular folder
    By suneel1310 in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2009, 10:02
  3. Reading files in C++
    By maverick_pol in forum General Programming
    Replies: 2
    Last Post: 15th May 2008, 08:53
  4. Reading Binary Files
    By archanasubodh in forum Newbie
    Replies: 1
    Last Post: 27th February 2008, 12:31
  5. reading files
    By baray98 in forum Newbie
    Replies: 2
    Last Post: 20th September 2007, 12:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.