How to read wav file header with QFile
-
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
QFileand.read()etc.How can I do it, I guess
QDataStreamcan 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
QFileand.read()etc.How can I do it, I guess
QDataStreamcan be useful but I don't know how.Thanks in advance.
@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
QFileand.read()etc.How can I do it, I guess
QDataStreamcan be useful but I don't know how.Thanks in advance.
@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.
QDataStreamis 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.wavfile format.