Indie dev efficiency3 min read

WAV Parser Can't Find data? Check Odd RIFF Chunk Padding

Use a three-byte JUNK chunk to check whether a WAV parser advances past the alignment byte.

WAV Parser Can't Find data? Check Odd RIFF Chunk Padding
A narrow spacer on a mechanical rail illustrates audio chunk alignment
Concept illustration

A sound plays in a media player, but your importer cannot locate its data chunk. Test chunk alignment before changing the codec or rebuilding the audio. This fixture is for ordinary little-endian RIFF/WAVE, excluding RF64 and RIFX.

Change the layout without changing the sound

Copy a short PCM WAV. Insert a JUNK chunk between fmt and data: the four-byte ID, a little-endian size field of 3, three arbitrary payload bytes and one padding byte. Add 12 to the enclosing RIFF size. Leave the audio data and its size unchanged. In a hex viewer, the next chunk should begin 12 bytes after the start of the JUNK header.

Walk chunks instead of scanning for a word

After each eight-byte chunk header, advance by the declared payload length and one extra byte if that length is odd. The padding byte is not part of the chunk's declared payload. Validate the header, payload and required pad against both the RIFF boundary and the file length. A raw text search for data can mistake bytes in an unrelated payload for a chunk ID.

Compare the import results

Both copies should expose the same PCM bytes and frame count. If only the padded copy fails, log chunk IDs and offsets. If both fail, inspect the PCM format, channels and bit depth next. The game sound effects generator can provide a listening sample; use a PCM copy for this format test and perform the binary edit separately.

Recommended tools

Ready to try "WAV Parser Can't Find data? Check Odd RIFF Chunk Padding"?

Use our online tools to apply this tutorial to your indie game project right away.