How to read wav file header with QFile
-
wrote on 2 Feb 2023, 11:46 last edited by
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.
-
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.
Lifetime Qt Championwrote on 2 Feb 2023, 12:14 last edited by jsulm 2 Feb 2023, 12:41@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.
-
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.
wrote on 2 Feb 2023, 14:36 last edited by JonB 2 Feb 2023, 14:38@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 usingQDataStream
, such as your.wav
file format.
1/3