From bf86e64726c9f8451c0e89b8e3d01774ce555ac6 Mon Sep 17 00:00:00 2001 From: Mark Kremer Date: Fri, 6 Sep 2024 21:57:55 +0200 Subject: [PATCH] Fix WAV pop sound after seek with unknown chunk in header When an unknown chunk is reached, the bytes that hold the chunk size weren't added to the total header size. After a seek to the start of the file, the seek position would end up before the sample data, interpreting part of the header as samples. --- wav/decode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wav/decode.go b/wav/decode.go index ffc3df8..f26c5e7 100644 --- a/wav/decode.go +++ b/wav/decode.go @@ -129,7 +129,7 @@ func Decode(r io.Reader) (s beep.StreamSeekCloser, format beep.Format, err error if err := binary.Read(r, binary.LittleEndian, trash); err != nil { return nil, beep.Format{}, errors.Wrap(err, "wav: missing unknown chunk body") } - d.hsz += 4 + fs //add size of (Unknown formtype + formsize) + d.hsz += 4 + 4 + fs //add size of (Unknown formtype + formsize + its trailing size) } }