Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to read wav file header with QFile
QtWS25 Last Chance

How to read wav file header with QFile

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 303 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kayakaan02
    wrote on 2 Feb 2023, 11:46 last edited by
    #1

    I want to read a wav files header because I want to see the size located at the 40-44 bytes of 44 byte header as unsigned long.

    Header data is like this:

        char                RIFF[4];
        unsigned long       ChunkSize;
        char                WAVE[4];
        char                fmt[4];
        unsigned long       Subchunk1Size;
        unsigned short      AudioFormat;
        unsigned short      NumOfChan;
        unsigned long       SamplesPerSec;
        unsigned long       bytesPerSec;
        unsigned short      blockAlign;
        unsigned short      bitsPerSample;
        char                Subchunk2ID[4];
        unsigned long       Subchunk2Size;
    

    Subchunk2Size is where the data size is stored but I cannot access it with QFile and .read() etc.

    How can I do it, I guess QDataStream can be useful but I don't know how.

    Thanks in advance.

    J J 2 Replies Last reply 2 Feb 2023, 12:14
    0
    • K kayakaan02
      2 Feb 2023, 11:46

      I want to read a wav files header because I want to see the size located at the 40-44 bytes of 44 byte header as unsigned long.

      Header data is like this:

          char                RIFF[4];
          unsigned long       ChunkSize;
          char                WAVE[4];
          char                fmt[4];
          unsigned long       Subchunk1Size;
          unsigned short      AudioFormat;
          unsigned short      NumOfChan;
          unsigned long       SamplesPerSec;
          unsigned long       bytesPerSec;
          unsigned short      blockAlign;
          unsigned short      bitsPerSample;
          char                Subchunk2ID[4];
          unsigned long       Subchunk2Size;
      

      Subchunk2Size is where the data size is stored but I cannot access it with QFile and .read() etc.

      How can I do it, I guess QDataStream can be useful but I don't know how.

      Thanks in advance.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Feb 2023, 12:14 last edited by jsulm 2 Feb 2023, 12:41
      #2

      @kayakaan02 Since you know at which position you need to read and how many bytes use https://doc.qt.io/qt-6/qiodevice.html#seek and https://doc.qt.io/qt-6/qiodevice.html#read to read it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • K kayakaan02
        2 Feb 2023, 11:46

        I want to read a wav files header because I want to see the size located at the 40-44 bytes of 44 byte header as unsigned long.

        Header data is like this:

            char                RIFF[4];
            unsigned long       ChunkSize;
            char                WAVE[4];
            char                fmt[4];
            unsigned long       Subchunk1Size;
            unsigned short      AudioFormat;
            unsigned short      NumOfChan;
            unsigned long       SamplesPerSec;
            unsigned long       bytesPerSec;
            unsigned short      blockAlign;
            unsigned short      bitsPerSample;
            char                Subchunk2ID[4];
            unsigned long       Subchunk2Size;
        

        Subchunk2Size is where the data size is stored but I cannot access it with QFile and .read() etc.

        How can I do it, I guess QDataStream can be useful but I don't know how.

        Thanks in advance.

        J Offline
        J Offline
        JonB
        wrote on 2 Feb 2023, 14:36 last edited by JonB 2 Feb 2023, 14:38
        #3

        @kayakaan02 said in How to read wav file header with QFile:

        Subchunk2Size is where the data size is stored but I cannot access it with QFile and .read() etc.

        Yes you can! Follow @jsulm's links. You don't even have to seek() if you don't want to, you can just read the first 44 bytes and inspect the last 4.

        I guess QDataStream can be useful but I don't know how.

        QDataStream is useful where you exchange data between 2 Qt programs. It is not to be used where the format is produced by anything other than Qt using QDataStream, such as your .wav file format.

        1 Reply Last reply
        1

        1/3

        2 Feb 2023, 11:46

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved