Skip to content

Commit

Permalink
Changed indexing of tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Nov 27, 2022
1 parent 00728f5 commit f8ce7b9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions wavinfo/wave_adm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class WavADMReader:
"""
Reads XML data from an EBU ADM (Audio Definiton Model) WAV File.
"""

def __init__(self, axml_data: bytes, chna_data: bytes):
Expand All @@ -26,7 +27,12 @@ def __init__(self, axml_data: bytes, chna_data: bytes):
_, uid_count = unpack(header_fmt, chna_data[0:4])

#: A list of :class:`ChannelEntry` objects parsed from the
#: `chna` metadata chunk.
#: `chna` metadata chunk.
#:
#: .. note::
#: In-file, the `chna` track indexes start at 1. However, this interface
#: numbers the first track 0, in order to maintain consistency with other
#: libraries.
self.channel_uids = []

offset = calcsize(header_fmt)
Expand All @@ -36,7 +42,7 @@ def __init__(self, axml_data: bytes, chna_data: bytes):

# these values are either ascii or all null

self.channel_uids.append(ChannelEntry(track_index,
self.channel_uids.append(ChannelEntry(track_index - 1,
uid.decode('ascii') , track_ref.decode('ascii'), pack_ref.decode('ascii')))

offset += calcsize(uid_fmt)
Expand Down Expand Up @@ -97,7 +103,7 @@ def track_info(self, index):
:returns: a dictionary with *content_name*, *content_id*, *object_name*, *object_id*,
*pack_format_name*, *pack_type*, *channel_format_name*
"""
channel_info = next((x for x in self.channel_uids if x.track_index == index + 1), None)
channel_info = next((x for x in self.channel_uids if x.track_index == index), None)

if channel_info is None:
return None
Expand Down Expand Up @@ -152,7 +158,7 @@ def to_dict(self):

def make_entry(channel_uid_rec):
rd = channel_uid_rec._asdict()
rd.update(self.track_info(channel_uid_rec.track_index - 1))
rd.update(self.track_info(channel_uid_rec.track_index))
return rd

return dict(channel_entries=list(map(lambda z: make_entry(z), self.channel_uids)),
Expand Down

0 comments on commit f8ce7b9

Please sign in to comment.