Skip to content

Commit

Permalink
Merge pull request #1034 from wader/wav-fmt-cbsize
Browse files Browse the repository at this point in the history
wav: Decode fmt chunk cb_size and bytes
  • Loading branch information
wader authored Nov 21, 2024
2 parents 95819c9 + 4a9f65d commit 8f9e84d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Binary file added format/riff/testdata/fmt_cb_size_unknown.wav
Binary file not shown.
17 changes: 17 additions & 0 deletions format/riff/testdata/fmt_cb_size_unknown.wav.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$ fq dv fmt_cb_size_unknown.wav
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: fmt_cb_size_unknown.wav (wav) 0x0-0x28 (40)
0x00|52 49 46 46 |RIFF | id: "RIFF" 0x0-0x4 (4)
0x00| 20 00 00 00 | ... | size: 32 0x4-0x8 (4)
0x00| 57 41 56 45 | WAVE | format: "WAVE" (valid) 0x8-0xc (4)
| | | chunks[0:1]: 0xc-0x28 (28)
| | | [0]{}: chunk 0xc-0x28 (28)
0x00| 66 6d 74 20| fmt | id: "fmt" 0xc-0x10 (4)
0x10|14 00 00 00 |.... | size: 20 0x10-0x14 (4)
0x10| 01 00 | .. | audio_format: "pcm_s16le" (1) 0x14-0x16 (2)
0x10| 02 00 | .. | num_channels: 2 0x16-0x18 (2)
0x10| 44 ac 00 00 | D... | sample_rate: 44100 0x18-0x1c (4)
0x10| 20 62 05 00| b..| byte_rate: 352800 0x1c-0x20 (4)
0x20|08 00 |.. | block_align: 8 0x20-0x22 (2)
0x20| 20 00 | . | bits_per_sample: 32 0x22-0x24 (2)
0x20| 02 00 | .. | cb_size: 2 0x24-0x26 (2)
0x20| 01 00| | ..| | unknown: raw bits 0x26-0x28 (2)
16 changes: 11 additions & 5 deletions format/riff/wav.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ func wavDecode(d *decode.D) any {
d.FieldU16("block_align")
d.FieldU16("bits_per_sample")

if audioFormat == formatExtensible && d.BitsLeft() > 0 {
d.FieldU16("extension_size")
d.FieldU16("valid_bits_per_sample")
d.FieldU32("channel_mask")
d.FieldRawLen("sub_format", 16*8, subFormatNames)
if d.BitsLeft() > 0 {
if audioFormat == formatExtensible {
d.FieldU16("extension_size")
d.FieldU16("valid_bits_per_sample")
d.FieldU32("channel_mask")
d.FieldRawLen("sub_format", 16*8, subFormatNames)
} else {
cbSize := d.FieldU16("cb_size")
d.FieldRawLen("unknown", int64(cbSize)*8)
}
}

return false, nil

case "data":
Expand Down

0 comments on commit 8f9e84d

Please sign in to comment.