mirror of
https://github.com/iluvcapra/wavinfo.git
synced 2026-01-02 18:00:41 +00:00
Axml implementation
This commit is contained in:
@@ -1,14 +1,54 @@
|
|||||||
|
"""
|
||||||
|
ADM Reader
|
||||||
|
"""
|
||||||
|
|
||||||
|
from struct import unpack, unpack_from, calcsize
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from lxml import etree as ET
|
from lxml import etree as ET
|
||||||
from collections import namedtuple
|
|
||||||
|
@dataclass
|
||||||
|
class ChannelEntry:
|
||||||
|
"""
|
||||||
|
A `chna` chunk table entry.
|
||||||
|
"""
|
||||||
|
|
||||||
|
track_index: int
|
||||||
|
"Track index (indexed from 1)"
|
||||||
|
|
||||||
|
uid: str
|
||||||
|
"audioTrackUID"
|
||||||
|
|
||||||
|
track_ref: str
|
||||||
|
"audioTrackFormatID"
|
||||||
|
|
||||||
|
pack_ref: str
|
||||||
|
"audioPackFormatID"
|
||||||
|
|
||||||
|
|
||||||
class WaveAxmlReader:
|
class WavAxmlReader:
|
||||||
"""
|
"""
|
||||||
Reads XML data from an EBU ADM (Audio Definiton Model) WAV File.
|
Reads XML data from an EBU ADM (Audio Definiton Model) WAV File.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, axml_data, ) -> None:
|
def __init__(self, axml_data: bytes, chna_data: bytes) -> None:
|
||||||
pass
|
header_fmt = "<HH"
|
||||||
|
uid_fmt = "<H12s14s11sx"
|
||||||
|
|
||||||
|
self.axml = ET.fromstring(axml_data)
|
||||||
|
|
||||||
|
self.track_count, uid_count = unpack(header_fmt, chna_data)
|
||||||
|
|
||||||
|
self.channel_uids = []
|
||||||
|
|
||||||
|
offset = calcsize(header_fmt)
|
||||||
|
for _ in range(uid_count):
|
||||||
|
|
||||||
|
track_index, uid, track_ref, pack_ref = unpack_from(uid_fmt, chna_data, offset)
|
||||||
|
|
||||||
|
# these values are either ascii or all null
|
||||||
|
|
||||||
|
self.channel_uids.append(ChannelEntry(track_index,
|
||||||
|
uid.decode('ascii') , track_ref.decode('ascii'), pack_ref.decode('ascii')))
|
||||||
|
|
||||||
|
offset += calcsize(uid_fmt)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from .riff_parser import parse_chunk, ChunkDescriptor, ListChunkDescriptor
|
|||||||
from .wave_ixml_reader import WavIXMLFormat
|
from .wave_ixml_reader import WavIXMLFormat
|
||||||
from .wave_bext_reader import WavBextReader
|
from .wave_bext_reader import WavBextReader
|
||||||
from .wave_info_reader import WavInfoChunkReader
|
from .wave_info_reader import WavInfoChunkReader
|
||||||
|
from .wave_axml_reader import WavAxmlReader
|
||||||
|
|
||||||
#: Calculated statistics about the audio data.
|
#: Calculated statistics about the audio data.
|
||||||
WavDataDescriptor = namedtuple('WavDataDescriptor', 'byte_count frame_count')
|
WavDataDescriptor = namedtuple('WavDataDescriptor', 'byte_count frame_count')
|
||||||
@@ -75,6 +76,9 @@ class WavInfoReader:
|
|||||||
#: :class:`wavinfo.wave_ixml_reader.WavIXMLFormat` with iXML metadata
|
#: :class:`wavinfo.wave_ixml_reader.WavIXMLFormat` with iXML metadata
|
||||||
self.ixml = self._get_ixml(wavfile)
|
self.ixml = self._get_ixml(wavfile)
|
||||||
|
|
||||||
|
#: :class:`wavinfo.wave_axml_reader.WavAxmlReader` with ADM metadata
|
||||||
|
self.adm = self._get_axml(wavfile)
|
||||||
|
|
||||||
#: :class:`wavinfo.wave_info_reader.WavInfoChunkReader` with RIFF INFO metadata
|
#: :class:`wavinfo.wave_info_reader.WavInfoChunkReader` with RIFF INFO metadata
|
||||||
self.info = self._get_info(wavfile, encoding=self.info_encoding)
|
self.info = self._get_info(wavfile, encoding=self.info_encoding)
|
||||||
self.data = self._describe_data()
|
self.data = self._describe_data()
|
||||||
@@ -130,6 +134,11 @@ class WavInfoReader:
|
|||||||
bext_data = self._find_chunk_data(b'bext', f, default_none=True)
|
bext_data = self._find_chunk_data(b'bext', f, default_none=True)
|
||||||
return WavBextReader(bext_data, encoding) if bext_data else None
|
return WavBextReader(bext_data, encoding) if bext_data else None
|
||||||
|
|
||||||
|
def _get_axml(self, f):
|
||||||
|
axml = self._find_chunk_data(b'axml', f, default_none=True)
|
||||||
|
chna = self._find_chunk_data(b'chna', f, default_none=True)
|
||||||
|
return WavAxmlReader(axml_data=axml, chna_data=chna)
|
||||||
|
|
||||||
def _get_ixml(self, f):
|
def _get_ixml(self, f):
|
||||||
ixml_data = self._find_chunk_data(b'iXML', f, default_none=True)
|
ixml_data = self._find_chunk_data(b'iXML', f, default_none=True)
|
||||||
return None if ixml_data is None else WavIXMLFormat(ixml_data.rstrip(b'\0'))
|
return None if ixml_data is None else WavIXMLFormat(ixml_data.rstrip(b'\0'))
|
||||||
|
|||||||
Reference in New Issue
Block a user