KaitaiStructWorkshop/08_enums.ksy

149 lines
3.2 KiB
Plaintext

meta:
id: wav
file-extension: wav
encoding: ascii
endian: le
seq:
- id: magic
# Could assert using contents here, but
# just make sections conditional later
#contents: "RIFF"
type: u4be
enum: fourcc
- id: size
type: u4
- id: wave_str
#contents: "WAVE"
type: u4be
enum: fourcc
- id: sections
type: section
repeat: eos
if: 'magic == fourcc::riff and wave_str == fourcc::wave'
instances: {}
types:
section:
seq:
- id: name
type: u4be # Big endian!
enum: fourcc
- id: size
type: u4
- id: content
size: size
type:
switch-on: name
cases:
'fourcc::fmt': fmt
'fourcc::data': data
'fourcc::fact': fact
'fourcc::peak': peak
'fourcc::list': list
fmt:
seq:
- id: type
type: u2
enum: encoding_type_enum
- id: channels
type: u2
- id: samplerate
type: u4
- id: datarate
type: u4
doc: Might also be datarate per channel
- id: bytes_per_sample
type: u2
- id: bits_per_unit
type: u2
data:
seq:
- id: content
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)
_: u1
repeat: eos
types:
sample:
params:
- id: encoding_type
type: u2
enum: encoding_type_enum
- id: encoding_size
type: u2
seq:
- id: data
type:
switch-on: encoding_type
cases:
'encoding_type_enum::float': float_type
'encoding_type_enum::int': int_type
repeat: expr
repeat-expr: _root.sections[0].content.\
as<fmt>.channels
types:
float_type:
seq:
- id: data
type:
switch-on: _parent.encoding_size
cases:
32: f4
64: f8
int_type:
seq:
- id: data
type:
switch-on: _parent.encoding_size
cases:
8: u1
16: s2
32: s4
fact:
seq:
- id: samples
type: u4
peak:
seq:
- id: unknown_0
type: u4
- id: timestamp
type: u4
- id: peak
type: f4
- id: index
type: u4
list:
seq:
- id: info_str
type: str
size: 4
- id: contents
repeat: eos
type: content
types:
content:
seq:
- id: name
type: str
size: 4
- id: size
type: u4
- id: content
type: strz
size: size
enums:
fourcc:
0x52494646: 'riff'
0x57415645: 'wave'
0x666d7420: 'fmt'
0x66616374: 'fact'
0x5045414b: 'peak'
0x64617461: 'data'
0x4c495354: 'list'
encoding_type_enum:
1: 'int'
3: 'float'
doc: Hello, world
doc-ref: https://example.com