Comments and stuff

master
Valentin Ochs 2020-12-30 08:15:28 +01:00
parent 50accfafa1
commit 630d94c1ee
4 changed files with 30 additions and 14 deletions

View File

@ -7,11 +7,16 @@ seq:
- id: magic
type: str
size: 4
# We don't actually handle invalid files here.
# If we wanted, we could also use this key:
# contents: "RIFF"
# But then we could not use the type key...
- id: size
type: u4
- id: wave_str
type: str
size: 4
# Same as with the magic field
instances: {}
types: {}
enums: {}

View File

@ -14,6 +14,7 @@ seq:
size: 4
- id: sections
type: section
# Repeat until the end of the stream
repeat: eos
instances: {}
types:
@ -26,6 +27,8 @@ types:
type: u4
- id: content
size: size
# No type yet - just read in a byte array of the given
# size, which refers to the size field just before
enums: {}
doc: Hello, world
doc-ref: https://example.com

View File

@ -59,6 +59,9 @@ types:
seq:
- id: data
type:
# I don't mention this in the video, but you
# can use arithmetic expressions here as well
# I just did this to show value instances :)
switch-on: _root.sections[0].content.\
as<fmt>.combined_type
cases:

View File

@ -8,24 +8,32 @@ seq:
# Could assert using contents here, but
# just make sections conditional later
#contents: "RIFF"
# Not using contents means we can give this a type
# Big endian, because we store the 4-character string
# 'RIFF' (0x52 0x49 0x46 0x46) as enum value 0x52494646
type: u4be
# Integers can have an optional enum key
enum: fourcc
- id: size
type: u4
- id: wave_str
# Same as the magic field
#contents: "WAVE"
type: u4be
enum: fourcc
- id: sections
type: section
repeat: eos
# Only try to decode this if this looks like a wave file
if: 'magic == fourcc::riff and wave_str == fourcc::wave'
instances: {}
types:
section:
seq:
- id: name
type: u4be # Big endian!
type: u4be # Big endian, same reason as above
enum: fourcc
- id: size
type: u4
@ -43,7 +51,7 @@ types:
seq:
- id: type
type: u2
enum: encoding_type_enum
enum: encoding
- id: channels
type: u2
- id: samplerate
@ -61,24 +69,21 @@ types:
type:
switch-on: _root.sections[0].name
cases:
'fourcc::fmt': sample(_root.sections[0].content.as<fmt>.type, _root.sections[0].content.as<fmt>.bits_per_unit)
'fourcc::fmt': sample(_root.sections[0].content.as<fmt>)
_: u1
repeat: eos
types:
sample:
params:
- id: encoding_type
type: u2
enum: encoding_type_enum
- id: encoding_size
type: u2
- id: fmt
type: fmt
seq:
- id: data
type:
switch-on: encoding_type
switch-on: fmt.type
cases:
'encoding_type_enum::float': float_type
'encoding_type_enum::int': int_type
'encoding::float': float_type
'encoding::int': int_type
repeat: expr
repeat-expr: _root.sections[0].content.\
as<fmt>.channels
@ -87,7 +92,7 @@ types:
seq:
- id: data
type:
switch-on: _parent.encoding_size
switch-on: _parent.fmt.bits_per_unit
cases:
32: f4
64: f8
@ -95,7 +100,7 @@ types:
seq:
- id: data
type:
switch-on: _parent.encoding_size
switch-on: _parent.fmt.bits_per_unit
cases:
8: u1
16: s2
@ -142,7 +147,7 @@ enums:
0x5045414b: 'peak'
0x64617461: 'data'
0x4c495354: 'list'
encoding_type_enum:
encoding:
1: 'int'
3: 'float'
doc: Hello, world