commit - 837319ae0f0e1c5ee99ae680598cf0484093dc45
commit + c30923a3bde846499b74a9d44110611f16760230
blob - 21cda9fcfa3140b729d6912115dfa50edf958cbc
blob + fa18da1e64943623fc8b26cedb1dba3089485bef
--- wav/wav.go
+++ wav/wav.go
func readHeader(rd io.Reader) (*header, error) {
var head header
- var fchunk fileChunk
- if err := binary.Read(rd, binary.LittleEndian, &fchunk); err != nil {
+ if err := binary.Read(rd, binary.LittleEndian, &head.File); err != nil {
return nil, fmt.Errorf("read file chunk: %w", err)
}
- if fchunk.ID != riffID {
- return nil, fmt.Errorf("bad RIFF id %x", fchunk.ID)
- } else if fchunk.FormatID != waveID {
- return nil, fmt.Errorf("bad WAVE file format id %x", fchunk.FormatID)
+ if head.File.ID != riffID {
+ return nil, fmt.Errorf("bad RIFF id %x", head.File.ID)
+ } else if head.File.FormatID != waveID {
+ return nil, fmt.Errorf("bad WAVE file format id %x", head.File.FormatID)
}
- head.File = fchunk
- var fmtchunk formatChunk
- if err := binary.Read(rd, binary.LittleEndian, &fmtchunk); err != nil {
+ if err := binary.Read(rd, binary.LittleEndian, &head.Format); err != nil {
return nil, fmt.Errorf("read file chunk: %w", err)
}
- if fmtchunk.ID != formatChunkID {
- return nil, fmt.Errorf("bad format chunk id %x", fmtchunk.ID)
+ if head.Format.ID != formatChunkID {
+ return nil, fmt.Errorf("bad format chunk id %x", head.Format.ID)
}
- head.Format = fmtchunk
- if fmtchunk.AudioFormat == AudioFormatExtensible {
+ if head.Format.AudioFormat == AudioFormatExtensible {
var ext FormatExtension
if err := binary.Read(rd, binary.LittleEndian, &ext); err != nil {
return nil, fmt.Errorf("read format chunk extension: %w", err)
head.FormatExtension = &ext
}
- var data dataChunk
- if err := binary.Read(rd, binary.LittleEndian, &data); err != nil {
+ if err := binary.Read(rd, binary.LittleEndian, &head.Data); err != nil {
return nil, fmt.Errorf("read data chunk: %w", err)
}
- head.Data = data
return &head, nil
}