Skip to content

Commit

Permalink
format,decode: Some crc and endian refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 24, 2021
1 parent fc76907 commit 4f8d037
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 172 deletions.
2 changes: 1 addition & 1 deletion format/flac/flac_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func frameDecode(d *decode.D, in interface{}) interface{} {

headerCRC := &crc.CRC{Bits: 8, Table: crc.ATM8Table}
d.MustCopy(headerCRC, d.BitBufRange(frameStart, d.Pos()-frameStart))
d.FieldRawLen("crc", 8, d.ValidateBitBuf(headerCRC.Sum(nil)), d.RawHex)
d.FieldU8("crc", d.ValidateUBytes(headerCRC.Sum(nil)), d.Hex)
})

var channelSamples [][]int64
Expand Down
2 changes: 1 addition & 1 deletion format/flac/testdata/frame.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ fq -d flac_frame verbose /frame
| | | end_of_header: {} 0x4-0x6.7 (3)
0x000| 00 | . | frame_number: 0 0x4-0x4.7 (1)
0x000| 01 b8 | .. | block_size: 441 0x5-0x6.7 (2)
0x000| 55 | U | crc: "55" (raw bits) (valid) 0x7-0x7.7 (1)
0x000| 55 | U | crc: 0x55 (valid) 0x7-0x7.7 (1)
| | | subframes: [1] 0x8-0x1fd.2 (501.3)
| | | [0]: subframe {} 0x8-0x1fd.2 (501.3)
0x000| 4e | N | zero_bit: 0 (valid) 0x8-0x8 (0.1)
Expand Down
12 changes: 6 additions & 6 deletions format/flac/testdata/mono16.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $ fq -d flac verbose /mono16.flac
0x2070| 08 | . | reserved1: 0 (valid) 0x2073.7-0x2073.7 (0.1)
| | | end_of_header: {} 0x2074-0x2074.7 (1)
0x2070| 00 | . | frame_number: 0 0x2074-0x2074.7 (1)
0x2070| 95 | . | crc: "95" (raw bits) (valid) 0x2075-0x2075.7 (1)
0x2070| 95 | . | crc: 0x95 (valid) 0x2075-0x2075.7 (1)
| | | subframes: [1] 0x2076-0x2078.7 (3)
| | | [0]: subframe {} 0x2076-0x2078.7 (3)
0x2070| 00 | . | zero_bit: 0 (valid) 0x2076-0x2076 (0.1)
Expand All @@ -80,7 +80,7 @@ $ fq -d flac verbose /mono16.flac
0x2070| 08 | . | reserved1: 0 (valid) 0x207e.7-0x207e.7 (0.1)
| | | end_of_header: {} 0x207f-0x207f.7 (1)
0x2070| 01| .| frame_number: 1 0x207f-0x207f.7 (1)
0x2080|92 |. | crc: "92" (raw bits) (valid) 0x2080-0x2080.7 (1)
0x2080|92 |. | crc: 0x92 (valid) 0x2080-0x2080.7 (1)
| | | subframes: [1] 0x2081-0x26d5.7 (1621)
| | | [0]: subframe {} 0x2081-0x26d5.7 (1621)
0x2080| 16 | . | zero_bit: 0 (valid) 0x2081-0x2081 (0.1)
Expand Down Expand Up @@ -206,7 +206,7 @@ $ fq -d flac verbose /mono16.flac
0x26d0| 08 | . | reserved1: 0 (valid) 0x26db.7-0x26db.7 (0.1)
| | | end_of_header: {} 0x26dc-0x26dc.7 (1)
0x26d0| 02 | . | frame_number: 2 0x26dc-0x26dc.7 (1)
0x26d0| 9b | . | crc: "9b" (raw bits) (valid) 0x26dd-0x26dd.7 (1)
0x26d0| 9b | . | crc: 0x9b (valid) 0x26dd-0x26dd.7 (1)
| | | subframes: [1] 0x26de-0x45e0.6 (7938.7)
| | | [0]: subframe {} 0x26de-0x45e0.6 (7938.7)
0x26d0| 10 | . | zero_bit: 0 (valid) 0x26de-0x26de (0.1)
Expand Down Expand Up @@ -427,7 +427,7 @@ $ fq -d flac verbose /mono16.flac
0x45e0| 08 | . | reserved1: 0 (valid) 0x45e6.7-0x45e6.7 (0.1)
| | | end_of_header: {} 0x45e7-0x45e7.7 (1)
0x45e0| 03 | . | frame_number: 3 0x45e7-0x45e7.7 (1)
0x45e0| 9c | . | crc: "9c" (raw bits) (valid) 0x45e8-0x45e8.7 (1)
0x45e0| 9c | . | crc: 0x9c (valid) 0x45e8-0x45e8.7 (1)
| | | subframes: [1] 0x45e9-0x5be9.6 (5632.7)
| | | [0]: subframe {} 0x45e9-0x5be9.6 (5632.7)
0x45e0| 12 | . | zero_bit: 0 (valid) 0x45e9-0x45e9 (0.1)
Expand Down Expand Up @@ -479,7 +479,7 @@ $ fq -d flac verbose /mono16.flac
0x5be0| 08| .| reserved1: 0 (valid) 0x5bef.7-0x5bef.7 (0.1)
| | | end_of_header: {} 0x5bf0-0x5bf0.7 (1)
0x5bf0|04 |. | frame_number: 4 0x5bf0-0x5bf0.7 (1)
0x5bf0| 89 | . | crc: "89" (raw bits) (valid) 0x5bf1-0x5bf1.7 (1)
0x5bf0| 89 | . | crc: 0x89 (valid) 0x5bf1-0x5bf1.7 (1)
| | | subframes: [1] 0x5bf2-0x799f (7597.1)
| | | [0]: subframe {} 0x5bf2-0x799f (7597.1)
0x5bf0| 40 | @ | zero_bit: 0 (valid) 0x5bf2-0x5bf2 (0.1)
Expand Down Expand Up @@ -608,7 +608,7 @@ $ fq -d flac verbose /mono16.flac
| | | end_of_header: {} 0x79a6-0x79a8.7 (3)
0x79a0| 05 | . | frame_number: 5 0x79a6-0x79a6.7 (1)
0x79a0| 06 21 | .! | block_size: 1570 0x79a7-0x79a8.7 (2)
0x79a0| 38 | 8 | crc: "38" (raw bits) (valid) 0x79a9-0x79a9.7 (1)
0x79a0| 38 | 8 | crc: 0x38 (valid) 0x79a9-0x79a9.7 (1)
| | | subframes: [1] 0x79aa-0x8595.7 (3052)
| | | [0]: subframe {} 0x79aa-0x8595.7 (3052)
0x79a0| 10 | . | zero_bit: 0 (valid) 0x79aa-0x79aa (0.1)
Expand Down
12 changes: 6 additions & 6 deletions format/flac/testdata/mono24.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $ fq -d flac verbose /mono24.flac
0x2090| 0c| .| reserved1: 0 (valid) 0x209f.7-0x209f.7 (0.1)
| | | end_of_header: {} 0x20a0-0x20a0.7 (1)
0x20a0|00 |. | frame_number: 0 0x20a0-0x20a0.7 (1)
0x20a0| c1 | . | crc: "c1" (raw bits) (valid) 0x20a1-0x20a1.7 (1)
0x20a0| c1 | . | crc: 0xc1 (valid) 0x20a1-0x20a1.7 (1)
| | | subframes: [1] 0x20a2-0x20a5.7 (4)
| | | [0]: subframe {} 0x20a2-0x20a5.7 (4)
0x20a0| 00 | . | zero_bit: 0 (valid) 0x20a2-0x20a2 (0.1)
Expand All @@ -85,7 +85,7 @@ $ fq -d flac verbose /mono24.flac
0x20a0| 0c | . | reserved1: 0 (valid) 0x20ab.7-0x20ab.7 (0.1)
| | | end_of_header: {} 0x20ac-0x20ac.7 (1)
0x20a0| 01 | . | frame_number: 1 0x20ac-0x20ac.7 (1)
0x20a0| c6 | . | crc: "c6" (raw bits) (valid) 0x20ad-0x20ad.7 (1)
0x20a0| c6 | . | crc: 0xc6 (valid) 0x20ad-0x20ad.7 (1)
| | | subframes: [1] 0x20ae-0x27dd.1 (1839.2)
| | | [0]: subframe {} 0x20ae-0x27dd.1 (1839.2)
0x20a0| 17 | . | zero_bit: 0 (valid) 0x20ae-0x20ae (0.1)
Expand Down Expand Up @@ -308,7 +308,7 @@ $ fq -d flac verbose /mono24.flac
0x27e0| 0c | . | reserved1: 0 (valid) 0x27e3.7-0x27e3.7 (0.1)
| | | end_of_header: {} 0x27e4-0x27e4.7 (1)
0x27e0| 02 | . | frame_number: 2 0x27e4-0x27e4.7 (1)
0x27e0| cf | . | crc: "cf" (raw bits) (valid) 0x27e5-0x27e5.7 (1)
0x27e0| cf | . | crc: 0xcf (valid) 0x27e5-0x27e5.7 (1)
| | | subframes: [1] 0x27e6-0x56ec.6 (12038.7)
| | | [0]: subframe {} 0x27e6-0x56ec.6 (12038.7)
0x27e0| 10 | . | zero_bit: 0 (valid) 0x27e6-0x27e6 (0.1)
Expand Down Expand Up @@ -529,7 +529,7 @@ $ fq -d flac verbose /mono24.flac
0x56f0| 0c | . | reserved1: 0 (valid) 0x56f2.7-0x56f2.7 (0.1)
| | | end_of_header: {} 0x56f3-0x56f3.7 (1)
0x56f0| 03 | . | frame_number: 3 0x56f3-0x56f3.7 (1)
0x56f0| c8 | . | crc: "c8" (raw bits) (valid) 0x56f4-0x56f4.7 (1)
0x56f0| c8 | . | crc: 0xc8 (valid) 0x56f4-0x56f4.7 (1)
| | | subframes: [1] 0x56f5-0x7cf7.2 (9730.3)
| | | [0]: subframe {} 0x56f5-0x7cf7.2 (9730.3)
0x56f0| 12 | . | zero_bit: 0 (valid) 0x56f5-0x56f5 (0.1)
Expand Down Expand Up @@ -581,7 +581,7 @@ $ fq -d flac verbose /mono24.flac
0x7cf0| 0c | . | reserved1: 0 (valid) 0x7cfd.7-0x7cfd.7 (0.1)
| | | end_of_header: {} 0x7cfe-0x7cfe.7 (1)
0x7cf0| 04 | . | frame_number: 4 0x7cfe-0x7cfe.7 (1)
0x7cf0| dd| .| crc: "dd" (raw bits) (valid) 0x7cff-0x7cff.7 (1)
0x7cf0| dd| .| crc: 0xdd (valid) 0x7cff-0x7cff.7 (1)
| | | subframes: [1] 0x7d00-0xaaaf.3 (11695.4)
| | | [0]: subframe {} 0x7d00-0xaaaf.3 (11695.4)
0x7d00|40 |@ | zero_bit: 0 (valid) 0x7d00-0x7d00 (0.1)
Expand Down Expand Up @@ -710,7 +710,7 @@ $ fq -d flac verbose /mono24.flac
| | | end_of_header: {} 0xaab6-0xaab8.7 (3)
0xaab0| 05 | . | frame_number: 5 0xaab6-0xaab6.7 (1)
0xaab0| 06 21 | .! | block_size: 1570 0xaab7-0xaab8.7 (2)
0xaab0| 60 | ` | crc: "60" (raw bits) (valid) 0xaab9-0xaab9.7 (1)
0xaab0| 60 | ` | crc: 0x60 (valid) 0xaab9-0xaab9.7 (1)
| | | subframes: [1] 0xaaba-0xbcc8 (4622.1)
| | | [0]: subframe {} 0xaaba-0xbcc8 (4622.1)
0xaab0| 10 | . | zero_bit: 0 (valid) 0xaaba-0xaaba (0.1)
Expand Down
12 changes: 6 additions & 6 deletions format/flac/testdata/mono8.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $ fq -d flac verbose /mono8.flac
0x2070| 02 | . | reserved1: 0 (valid) 0x2073.7-0x2073.7 (0.1)
| | | end_of_header: {} 0x2074-0x2074.7 (1)
0x2070| 00 | . | frame_number: 0 0x2074-0x2074.7 (1)
0x2070| 17 | . | crc: "17" (raw bits) (valid) 0x2075-0x2075.7 (1)
0x2070| 17 | . | crc: 0x17 (valid) 0x2075-0x2075.7 (1)
| | | subframes: [1] 0x2076-0x2077.7 (2)
| | | [0]: subframe {} 0x2076-0x2077.7 (2)
0x2070| 00 | . | zero_bit: 0 (valid) 0x2076-0x2076 (0.1)
Expand All @@ -80,7 +80,7 @@ $ fq -d flac verbose /mono8.flac
0x2070| 02 | . | reserved1: 0 (valid) 0x207d.7-0x207d.7 (0.1)
| | | end_of_header: {} 0x207e-0x207e.7 (1)
0x2070| 01 | . | frame_number: 1 0x207e-0x207e.7 (1)
0x2070| 10| .| crc: "10" (raw bits) (valid) 0x207f-0x207f.7 (1)
0x2070| 10| .| crc: 0x10 (valid) 0x207f-0x207f.7 (1)
| | | subframes: [1] 0x2080-0x23b7.7 (824)
| | | [0]: subframe {} 0x2080-0x23b7.7 (824)
0x2080|12 |. | zero_bit: 0 (valid) 0x2080-0x2080 (0.1)
Expand Down Expand Up @@ -120,7 +120,7 @@ $ fq -d flac verbose /mono8.flac
0x23b0| 02 | . | reserved1: 0 (valid) 0x23bd.7-0x23bd.7 (0.1)
| | | end_of_header: {} 0x23be-0x23be.7 (1)
0x23b0| 02 | . | frame_number: 2 0x23be-0x23be.7 (1)
0x23b0| 19| .| crc: "19" (raw bits) (valid) 0x23bf-0x23bf.7 (1)
0x23b0| 19| .| crc: 0x19 (valid) 0x23bf-0x23bf.7 (1)
| | | subframes: [1] 0x23c0-0x32c2.4 (3842.5)
| | | [0]: subframe {} 0x23c0-0x32c2.4 (3842.5)
0x23c0|10 |. | zero_bit: 0 (valid) 0x23c0-0x23c0 (0.1)
Expand Down Expand Up @@ -341,7 +341,7 @@ $ fq -d flac verbose /mono8.flac
0x32c0| 02 | . | reserved1: 0 (valid) 0x32c8.7-0x32c8.7 (0.1)
| | | end_of_header: {} 0x32c9-0x32c9.7 (1)
0x32c0| 03 | . | frame_number: 3 0x32c9-0x32c9.7 (1)
0x32c0| 1e | . | crc: "1e" (raw bits) (valid) 0x32ca-0x32ca.7 (1)
0x32c0| 1e | . | crc: 0x1e (valid) 0x32ca-0x32ca.7 (1)
| | | subframes: [1] 0x32cb-0x396b.6 (1696.7)
| | | [0]: subframe {} 0x32cb-0x396b.6 (1696.7)
0x32c0| 12 | . | zero_bit: 0 (valid) 0x32cb-0x32cb (0.1)
Expand Down Expand Up @@ -393,7 +393,7 @@ $ fq -d flac verbose /mono8.flac
0x3970| 02 | . | reserved1: 0 (valid) 0x3971.7-0x3971.7 (0.1)
| | | end_of_header: {} 0x3972-0x3972.7 (1)
0x3970| 04 | . | frame_number: 4 0x3972-0x3972.7 (1)
0x3970| 0b | . | crc: "0b" (raw bits) (valid) 0x3973-0x3973.7 (1)
0x3970| 0b | . | crc: 0xb (valid) 0x3973-0x3973.7 (1)
| | | subframes: [1] 0x3974-0x4719.4 (3493.5)
| | | [0]: subframe {} 0x3974-0x4719.4 (3493.5)
0x3970| 40 | @ | zero_bit: 0 (valid) 0x3974-0x3974 (0.1)
Expand Down Expand Up @@ -522,7 +522,7 @@ $ fq -d flac verbose /mono8.flac
| | | end_of_header: {} 0x4720-0x4722.7 (3)
0x4720|05 |. | frame_number: 5 0x4720-0x4720.7 (1)
0x4720| 06 21 | .! | block_size: 1570 0x4721-0x4722.7 (2)
0x4720| a4 | . | crc: "a4" (raw bits) (valid) 0x4723-0x4723.7 (1)
0x4720| a4 | . | crc: 0xa4 (valid) 0x4723-0x4723.7 (1)
| | | subframes: [1] 0x4724-0x4ced.5 (1481.6)
| | | [0]: subframe {} 0x4724-0x4ced.5 (1481.6)
0x4720| 10 | . | zero_bit: 0 (valid) 0x4724-0x4724 (0.1)
Expand Down
Loading

0 comments on commit 4f8d037

Please sign in to comment.