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
Forum Updated to NodeBB v4.3 + New Features

How to read wav file header with QFile

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 309 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 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.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • K kayakaan02

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #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

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #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

        • Login

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