faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.08k stars 151 forks source link

Fix FileSize for saving .wav #144

Open skitaoka opened 2 years ago

skitaoka commented 2 years ago

FileSize must be (file size) - 8 (except the size field itself and the chunk identifier).

cf. https://en.wikipedia.org/wiki/Resource_Interchange_File_Format

MarkKremer commented 1 year ago

The change is correct but I think the referenced Wikipedia article is a little ambiguous about if they're referencing the filesize/RIFF chunk or subchunks.

This article from Microsoft is a bit clearer:

The RIFF header has the following form:

'RIFF' fileSize fileType (data)

where 'RIFF' is the literal FOURCC code 'RIFF', fileSize is a 4-byte value giving the size of the data in the file, and fileType is a FOURCC that identifies the specific file type. The value of fileSize includes the size of the fileType FOURCC plus the size of the data that follows, but does not include the size of the 'RIFF' FOURCC or the size of fileSize. The file data consists of chunks and lists, in any order.

So the filesize is the size of the whole file except the "RIFF" (4 bytes) and the fileSize itself (4 bytes). This agrees with what you've changed. :)


As an addition, this the decode function is broken too and should be fixed. I'm wrong :)

I'm bringing the new fork gopxl/beep up-to-date & I'll include these changes. Tnx!