1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
from pkg_resources import parse_version
from .kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO
from enum import Enum
import collections
if parse_version(ks_version) < parse_version('0.7'):
raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))
class Wav(KaitaiStruct):
"""The WAVE file format is a subset of Microsoft's RIFF specification for the
storage of multimedia files. A RIFF file starts out with a file header
followed by a sequence of data chunks. A WAVE file is often just a RIFF
file with a single "WAVE" chunk which consists of two sub-chunks --
a "fmt " chunk specifying the data format and a "data" chunk containing
the actual sample data.
This Kaitai implementation was written by John Byrd of Gigantic Software
(jbyrd@giganticsoftware.com), and it is likely to contain bugs.
.. seealso::
Source - https://www.loc.gov/preservation/digital/formats/fdd/fdd000001.shtml
"""
class WFormatTagType(Enum):
unknown = 0
pcm = 1
adpcm = 2
ieee_float = 3
alaw = 6
mulaw = 7
dvi_adpcm = 17
dolby_ac3_spdif = 146
extensible = 65534
development = 65535
class ChunkType(Enum):
fmt = 544501094
bext = 1650817140
cue = 1668637984
data = 1684108385
minf = 1835626086
regn = 1919248238
umid = 1970104676
SEQ_FIELDS = ["riff_id", "file_size", "wave_id", "chunks"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['riff_id']['start'] = self._io.pos()
self.riff_id = self._io.ensure_fixed_contents(b"\x52\x49\x46\x46")
self._debug['riff_id']['end'] = self._io.pos()
self._debug['file_size']['start'] = self._io.pos()
self.file_size = self._io.read_u4le()
self._debug['file_size']['end'] = self._io.pos()
self._debug['wave_id']['start'] = self._io.pos()
self.wave_id = self._io.ensure_fixed_contents(b"\x57\x41\x56\x45")
self._debug['wave_id']['end'] = self._io.pos()
self._debug['chunks']['start'] = self._io.pos()
self._raw_chunks = self._io.read_bytes((self.file_size - 5))
io = KaitaiStream(BytesIO(self._raw_chunks))
self.chunks = self._root.ChunksType(io, self, self._root)
self.chunks._read()
self._debug['chunks']['end'] = self._io.pos()
class SampleType(KaitaiStruct):
SEQ_FIELDS = ["sample"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['sample']['start'] = self._io.pos()
self.sample = self._io.read_u2le()
self._debug['sample']['end'] = self._io.pos()
class FormatChunkType(KaitaiStruct):
SEQ_FIELDS = ["w_format_tag", "n_channels", "n_samples_per_sec", "n_avg_bytes_per_sec", "n_block_align", "w_bits_per_sample", "cb_size", "w_valid_bits_per_sample", "channel_mask_and_subformat"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['w_format_tag']['start'] = self._io.pos()
self.w_format_tag = KaitaiStream.resolve_enum(self._root.WFormatTagType, self._io.read_u2le())
self._debug['w_format_tag']['end'] = self._io.pos()
self._debug['n_channels']['start'] = self._io.pos()
self.n_channels = self._io.read_u2le()
self._debug['n_channels']['end'] = self._io.pos()
self._debug['n_samples_per_sec']['start'] = self._io.pos()
self.n_samples_per_sec = self._io.read_u4le()
self._debug['n_samples_per_sec']['end'] = self._io.pos()
self._debug['n_avg_bytes_per_sec']['start'] = self._io.pos()
self.n_avg_bytes_per_sec = self._io.read_u4le()
self._debug['n_avg_bytes_per_sec']['end'] = self._io.pos()
self._debug['n_block_align']['start'] = self._io.pos()
self.n_block_align = self._io.read_u2le()
self._debug['n_block_align']['end'] = self._io.pos()
self._debug['w_bits_per_sample']['start'] = self._io.pos()
self.w_bits_per_sample = self._io.read_u2le()
self._debug['w_bits_per_sample']['end'] = self._io.pos()
if not (self.is_basic_pcm):
self._debug['cb_size']['start'] = self._io.pos()
self.cb_size = self._io.read_u2le()
self._debug['cb_size']['end'] = self._io.pos()
if self.is_cb_size_meaningful:
self._debug['w_valid_bits_per_sample']['start'] = self._io.pos()
self.w_valid_bits_per_sample = self._io.read_u2le()
self._debug['w_valid_bits_per_sample']['end'] = self._io.pos()
if self.is_extensible:
self._debug['channel_mask_and_subformat']['start'] = self._io.pos()
self.channel_mask_and_subformat = self._root.ChannelMaskAndSubformatType(self._io, self, self._root)
self.channel_mask_and_subformat._read()
self._debug['channel_mask_and_subformat']['end'] = self._io.pos()
@property
def is_extensible(self):
if hasattr(self, '_m_is_extensible'):
return self._m_is_extensible if hasattr(self, '_m_is_extensible') else None
self._m_is_extensible = self.w_format_tag == self._root.WFormatTagType.extensible
return self._m_is_extensible if hasattr(self, '_m_is_extensible') else None
@property
def is_basic_pcm(self):
if hasattr(self, '_m_is_basic_pcm'):
return self._m_is_basic_pcm if hasattr(self, '_m_is_basic_pcm') else None
self._m_is_basic_pcm = self.w_format_tag == self._root.WFormatTagType.pcm
return self._m_is_basic_pcm if hasattr(self, '_m_is_basic_pcm') else None
@property
def is_basic_float(self):
if hasattr(self, '_m_is_basic_float'):
return self._m_is_basic_float if hasattr(self, '_m_is_basic_float') else None
self._m_is_basic_float = self.w_format_tag == self._root.WFormatTagType.ieee_float
return self._m_is_basic_float if hasattr(self, '_m_is_basic_float') else None
@property
def is_cb_size_meaningful(self):
if hasattr(self, '_m_is_cb_size_meaningful'):
return self._m_is_cb_size_meaningful if hasattr(self, '_m_is_cb_size_meaningful') else None
self._m_is_cb_size_meaningful = ((not (self.is_basic_pcm)) and (self.cb_size != 0))
return self._m_is_cb_size_meaningful if hasattr(self, '_m_is_cb_size_meaningful') else None
class GuidType(KaitaiStruct):
SEQ_FIELDS = ["data1", "data2", "data3", "data4", "data4a"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['data1']['start'] = self._io.pos()
self.data1 = self._io.read_u4le()
self._debug['data1']['end'] = self._io.pos()
self._debug['data2']['start'] = self._io.pos()
self.data2 = self._io.read_u2le()
self._debug['data2']['end'] = self._io.pos()
self._debug['data3']['start'] = self._io.pos()
self.data3 = self._io.read_u2le()
self._debug['data3']['end'] = self._io.pos()
self._debug['data4']['start'] = self._io.pos()
self.data4 = self._io.read_u4be()
self._debug['data4']['end'] = self._io.pos()
self._debug['data4a']['start'] = self._io.pos()
self.data4a = self._io.read_u4be()
self._debug['data4a']['end'] = self._io.pos()
class CuePointType(KaitaiStruct):
SEQ_FIELDS = ["dw_name", "dw_position", "fcc_chunk", "dw_chunk_start", "dw_block_start", "dw_sample_offset"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['dw_name']['start'] = self._io.pos()
self.dw_name = self._io.read_u4le()
self._debug['dw_name']['end'] = self._io.pos()
self._debug['dw_position']['start'] = self._io.pos()
self.dw_position = self._io.read_u4le()
self._debug['dw_position']['end'] = self._io.pos()
self._debug['fcc_chunk']['start'] = self._io.pos()
self.fcc_chunk = self._io.read_u4le()
self._debug['fcc_chunk']['end'] = self._io.pos()
self._debug['dw_chunk_start']['start'] = self._io.pos()
self.dw_chunk_start = self._io.read_u4le()
self._debug['dw_chunk_start']['end'] = self._io.pos()
self._debug['dw_block_start']['start'] = self._io.pos()
self.dw_block_start = self._io.read_u4le()
self._debug['dw_block_start']['end'] = self._io.pos()
self._debug['dw_sample_offset']['start'] = self._io.pos()
self.dw_sample_offset = self._io.read_u4le()
self._debug['dw_sample_offset']['end'] = self._io.pos()
class DataChunkType(KaitaiStruct):
SEQ_FIELDS = ["data"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['data']['start'] = self._io.pos()
self.data = self._io.read_bytes_full()
self._debug['data']['end'] = self._io.pos()
class SamplesType(KaitaiStruct):
SEQ_FIELDS = ["samples"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['samples']['start'] = self._io.pos()
self.samples = self._io.read_u4le()
self._debug['samples']['end'] = self._io.pos()
class ChannelMaskAndSubformatType(KaitaiStruct):
SEQ_FIELDS = ["dw_channel_mask", "subformat"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['dw_channel_mask']['start'] = self._io.pos()
self.dw_channel_mask = self._root.ChannelMaskType(self._io, self, self._root)
self.dw_channel_mask._read()
self._debug['dw_channel_mask']['end'] = self._io.pos()
self._debug['subformat']['start'] = self._io.pos()
self.subformat = self._root.GuidType(self._io, self, self._root)
self.subformat._read()
self._debug['subformat']['end'] = self._io.pos()
class ChunksType(KaitaiStruct):
SEQ_FIELDS = ["chunk"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['chunk']['start'] = self._io.pos()
self.chunk = []
i = 0
while not self._io.is_eof():
if not 'arr' in self._debug['chunk']:
self._debug['chunk']['arr'] = []
self._debug['chunk']['arr'].append({'start': self._io.pos()})
_t_chunk = self._root.ChunkType(self._io, self, self._root)
_t_chunk._read()
self.chunk.append(_t_chunk)
self._debug['chunk']['arr'][len(self.chunk) - 1]['end'] = self._io.pos()
i += 1
self._debug['chunk']['end'] = self._io.pos()
class CueChunkType(KaitaiStruct):
SEQ_FIELDS = ["dw_cue_points", "cue_points"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['dw_cue_points']['start'] = self._io.pos()
self.dw_cue_points = self._io.read_u4le()
self._debug['dw_cue_points']['end'] = self._io.pos()
if self.dw_cue_points != 0:
self._debug['cue_points']['start'] = self._io.pos()
self.cue_points = [None] * (self.dw_cue_points)
for i in range(self.dw_cue_points):
if not 'arr' in self._debug['cue_points']:
self._debug['cue_points']['arr'] = []
self._debug['cue_points']['arr'].append({'start': self._io.pos()})
_t_cue_points = self._root.CuePointType(self._io, self, self._root)
_t_cue_points._read()
self.cue_points[i] = _t_cue_points
self._debug['cue_points']['arr'][i]['end'] = self._io.pos()
self._debug['cue_points']['end'] = self._io.pos()
class ChannelMaskType(KaitaiStruct):
SEQ_FIELDS = ["front_right_of_center", "front_left_of_center", "back_right", "back_left", "low_frequency", "front_center", "front_right", "front_left", "top_center", "side_right", "side_left", "back_center", "top_back_left", "top_front_right", "top_front_center", "top_front_left", "unused1", "top_back_right", "top_back_center", "unused2"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['front_right_of_center']['start'] = self._io.pos()
self.front_right_of_center = self._io.read_bits_int(1) != 0
self._debug['front_right_of_center']['end'] = self._io.pos()
self._debug['front_left_of_center']['start'] = self._io.pos()
self.front_left_of_center = self._io.read_bits_int(1) != 0
self._debug['front_left_of_center']['end'] = self._io.pos()
self._debug['back_right']['start'] = self._io.pos()
self.back_right = self._io.read_bits_int(1) != 0
self._debug['back_right']['end'] = self._io.pos()
self._debug['back_left']['start'] = self._io.pos()
self.back_left = self._io.read_bits_int(1) != 0
self._debug['back_left']['end'] = self._io.pos()
self._debug['low_frequency']['start'] = self._io.pos()
self.low_frequency = self._io.read_bits_int(1) != 0
self._debug['low_frequency']['end'] = self._io.pos()
self._debug['front_center']['start'] = self._io.pos()
self.front_center = self._io.read_bits_int(1) != 0
self._debug['front_center']['end'] = self._io.pos()
self._debug['front_right']['start'] = self._io.pos()
self.front_right = self._io.read_bits_int(1) != 0
self._debug['front_right']['end'] = self._io.pos()
self._debug['front_left']['start'] = self._io.pos()
self.front_left = self._io.read_bits_int(1) != 0
self._debug['front_left']['end'] = self._io.pos()
self._debug['top_center']['start'] = self._io.pos()
self.top_center = self._io.read_bits_int(1) != 0
self._debug['top_center']['end'] = self._io.pos()
self._debug['side_right']['start'] = self._io.pos()
self.side_right = self._io.read_bits_int(1) != 0
self._debug['side_right']['end'] = self._io.pos()
self._debug['side_left']['start'] = self._io.pos()
self.side_left = self._io.read_bits_int(1) != 0
self._debug['side_left']['end'] = self._io.pos()
self._debug['back_center']['start'] = self._io.pos()
self.back_center = self._io.read_bits_int(1) != 0
self._debug['back_center']['end'] = self._io.pos()
self._debug['top_back_left']['start'] = self._io.pos()
self.top_back_left = self._io.read_bits_int(1) != 0
self._debug['top_back_left']['end'] = self._io.pos()
self._debug['top_front_right']['start'] = self._io.pos()
self.top_front_right = self._io.read_bits_int(1) != 0
self._debug['top_front_right']['end'] = self._io.pos()
self._debug['top_front_center']['start'] = self._io.pos()
self.top_front_center = self._io.read_bits_int(1) != 0
self._debug['top_front_center']['end'] = self._io.pos()
self._debug['top_front_left']['start'] = self._io.pos()
self.top_front_left = self._io.read_bits_int(1) != 0
self._debug['top_front_left']['end'] = self._io.pos()
self._debug['unused1']['start'] = self._io.pos()
self.unused1 = self._io.read_bits_int(6)
self._debug['unused1']['end'] = self._io.pos()
self._debug['top_back_right']['start'] = self._io.pos()
self.top_back_right = self._io.read_bits_int(1) != 0
self._debug['top_back_right']['end'] = self._io.pos()
self._debug['top_back_center']['start'] = self._io.pos()
self.top_back_center = self._io.read_bits_int(1) != 0
self._debug['top_back_center']['end'] = self._io.pos()
self._debug['unused2']['start'] = self._io.pos()
self.unused2 = self._io.read_bits_int(8)
self._debug['unused2']['end'] = self._io.pos()
class ChunkType(KaitaiStruct):
SEQ_FIELDS = ["chunk_id", "len", "data"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['chunk_id']['start'] = self._io.pos()
self.chunk_id = self._io.read_u4be()
self._debug['chunk_id']['end'] = self._io.pos()
self._debug['len']['start'] = self._io.pos()
self.len = self._io.read_u4le()
self._debug['len']['end'] = self._io.pos()
self._debug['data']['start'] = self._io.pos()
_on = self.chunk_id
if _on == 1684108385:
self._raw_data = self._io.read_bytes(self.len)
io = KaitaiStream(BytesIO(self._raw_data))
self.data = self._root.DataChunkType(io, self, self._root)
self.data._read()
elif _on == 1668637984:
self._raw_data = self._io.read_bytes(self.len)
io = KaitaiStream(BytesIO(self._raw_data))
self.data = self._root.CueChunkType(io, self, self._root)
self.data._read()
elif _on == 1650817140:
self._raw_data = self._io.read_bytes(self.len)
io = KaitaiStream(BytesIO(self._raw_data))
self.data = self._root.BextChunkType(io, self, self._root)
self.data._read()
elif _on == 1718449184:
self._raw_data = self._io.read_bytes(self.len)
io = KaitaiStream(BytesIO(self._raw_data))
self.data = self._root.FormatChunkType(io, self, self._root)
self.data._read()
else:
self.data = self._io.read_bytes(self.len)
self._debug['data']['end'] = self._io.pos()
class BextChunkType(KaitaiStruct):
SEQ_FIELDS = ["description", "originator", "originator_reference", "origination_date", "origination_time", "time_reference_low", "time_reference_high", "version", "umid", "loudness_value", "loudness_range", "max_true_peak_level", "max_momentary_loudness", "max_short_term_loudness"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['description']['start'] = self._io.pos()
self.description = (self._io.read_bytes(256)).decode(u"ASCII")
self._debug['description']['end'] = self._io.pos()
self._debug['originator']['start'] = self._io.pos()
self.originator = (self._io.read_bytes(32)).decode(u"ASCII")
self._debug['originator']['end'] = self._io.pos()
self._debug['originator_reference']['start'] = self._io.pos()
self.originator_reference = (self._io.read_bytes(32)).decode(u"ASCII")
self._debug['originator_reference']['end'] = self._io.pos()
self._debug['origination_date']['start'] = self._io.pos()
self.origination_date = (self._io.read_bytes(10)).decode(u"ASCII")
self._debug['origination_date']['end'] = self._io.pos()
self._debug['origination_time']['start'] = self._io.pos()
self.origination_time = (self._io.read_bytes(8)).decode(u"ASCII")
self._debug['origination_time']['end'] = self._io.pos()
self._debug['time_reference_low']['start'] = self._io.pos()
self.time_reference_low = self._io.read_u4le()
self._debug['time_reference_low']['end'] = self._io.pos()
self._debug['time_reference_high']['start'] = self._io.pos()
self.time_reference_high = self._io.read_u4le()
self._debug['time_reference_high']['end'] = self._io.pos()
self._debug['version']['start'] = self._io.pos()
self.version = self._io.read_u2le()
self._debug['version']['end'] = self._io.pos()
self._debug['umid']['start'] = self._io.pos()
self.umid = self._io.read_bytes(64)
self._debug['umid']['end'] = self._io.pos()
self._debug['loudness_value']['start'] = self._io.pos()
self.loudness_value = self._io.read_u2le()
self._debug['loudness_value']['end'] = self._io.pos()
self._debug['loudness_range']['start'] = self._io.pos()
self.loudness_range = self._io.read_u2le()
self._debug['loudness_range']['end'] = self._io.pos()
self._debug['max_true_peak_level']['start'] = self._io.pos()
self.max_true_peak_level = self._io.read_u2le()
self._debug['max_true_peak_level']['end'] = self._io.pos()
self._debug['max_momentary_loudness']['start'] = self._io.pos()
self.max_momentary_loudness = self._io.read_u2le()
self._debug['max_momentary_loudness']['end'] = self._io.pos()
self._debug['max_short_term_loudness']['start'] = self._io.pos()
self.max_short_term_loudness = self._io.read_u2le()
self._debug['max_short_term_loudness']['end'] = self._io.pos()
@property
def format_chunk(self):
if hasattr(self, '_m_format_chunk'):
return self._m_format_chunk if hasattr(self, '_m_format_chunk') else None
self._m_format_chunk = self.chunks.chunk[0].data
return self._m_format_chunk if hasattr(self, '_m_format_chunk') else None
|