Question

I'm implementing Audio in my cross-plattform application framework and have some trouble while starting working with wave files.

UInt32 type = rd.ReadUInt32();
UInt32 size = rd.ReadUInt32();
UInt32 waveType = rd.ReadUInt32();
UInt32 fmtType = rd.ReadUInt32();

if (type != MAGIC_RIFF || waveType != MAGIC_WAVE || fmtType != MAGIC_fmt)
{
    throw new InvalidDataException("Data is not of WAVE format");
}

The "fmt " magic number is not correct it's actually 0x4b4e554a. Windows-Media-Player can play the files with ease but i didn't find any information what this chunk could be. By definition the "fmt " chunk must appear.
If i load another file the "fmt " chunk is appearing, so what information does the chunk actually contains ( cannot be the data chunk because it's value is 0x61746164.

Was it helpful?

Solution

The fmt chunk is not required to be the first chunk after the header. There is a easy solution to skip the chunks between the header and fmt chunk:

UInt32 fmtType = rd.ReadUInt32();

while (fmtType != MAGIC_fmt)
{
    rd.ReadBytes(rd.ReadInt32());
    fmtType = rd.ReadUInt32();

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top