Skip to content

Commit

Permalink
Update decode.go
Browse files Browse the repository at this point in the history
From https://sites.google.com/site/musicgapi/technical-documents/wav-file-format.
```
One tricky thing about RIFF file chunks is that they must be word aligned. This means that their total size must be a multiple of 2 bytes (ie. 2, 4, 6, 8, and so on). If a chunk contains an odd number of data bytes, causing it not to be word aligned, an extra padding byte with a value of zero must follow the last data byte. This extra padding byte is not counted in the chunk size, therefor a program must always word align a chunk headers size value in order to calculate the offset of the following chunk. 
```
  • Loading branch information
hyperturtle committed Apr 23, 2020
1 parent b573886 commit f819e08
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wav/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func Decode(r io.Reader) (s beep.StreamSeekCloser, format beep.Format, err error
if err := binary.Read(r, binary.LittleEndian, &fs); err != nil {
return nil, beep.Format{}, errors.Wrap(err, "wav: missing unknown chunk size")
}
if fs % 2 != 0 {
fs = fs + 1
}
trash := make([]byte, fs)
if err := binary.Read(r, binary.LittleEndian, trash); err != nil {
return nil, beep.Format{}, errors.Wrap(err, "wav: missing unknown chunk body")
Expand Down

0 comments on commit f819e08

Please sign in to comment.