dr_libs icon indicating copy to clipboard operation
dr_libs copied to clipboard

dr_wav does not detect if data chunk size is incorrect

Open DeeJayLSP opened this issue 10 months ago • 2 comments

I have a pull request that aims to implement dr_wav.h in Godot for the purpose of adding AIFF support.

For a bit of context, Godot doesn't play WAV files directly. Instead, it extracts all necessary info (bit depth, channels, sample rate) and the PCM data, does some convertions, then stores it into its internal file format. That's where dr_wav comes in, doing the job and working as expected.

However, a certain open issue, which isn't that severe nowadays, gets much worse with dr_wav.

The issue above has a minimal reproduction project with a broken WAV file. Using the default implementation, it imports normally, but reports that the chunk size is smaller than expected:

Set compress/mode
  WARNING: scene/resources/audio_stream_wav.cpp:751 - File size 53104 is smaller than the expected size 2147479596.
  WARNING: scene/resources/audio_stream_wav.cpp:841 - Data chunk size is smaller than expected. Proceeding with actual data size.

When injecting dr_wav into the importer, which completely replaces the process that emits the warning above, the detection doesn't happen, and it seems to take the full size of 2147479596 bytes into consideration: Image

The file initially plays normally, but the rest is silent.

This has been tested with f69c5fcf975979bfd12cae40414ae0d58402f851, which is versions ahead of my PR.

I'm assuming this is a dr_wav issue, so I'd like to ask to test the file. If you don't find anything wrong, maybe the issue could be on my implementation.

DeeJayLSP avatar Mar 11 '25 02:03 DeeJayLSP

Thanks. I haven't tested the file yet, but this seems like a logical thing to check for. The only thing is I'll need to break the API to add support for an onTell callback so that dr_wav has a way of determining the size of the file. Will report back.

mackron avatar Mar 12 '25 06:03 mackron

I realized dr_wav provides dataChunkDataPos, so I was able to reimplement the engine check exactly how it was before.

It consists in checking if fileSize - dataChunkDataPos is lower than the informed data chunk size.

I'll keep this open as you might still be interested on addressing.

DeeJayLSP avatar Jun 08 '25 16:06 DeeJayLSP

This should be addressed in the master branch. Would you be able to give that a try? Note the API changes down the bottom of dr_wav.h or in the commit history.

mackron avatar Jul 03 '25 21:07 mackron

Seems to work nicely.

DeeJayLSP avatar Jul 04 '25 01:07 DeeJayLSP