Skip to content

Commit

Permalink
fileio/adm: fix stream and track format ID generation
Browse files Browse the repository at this point in the history
These are supposed to be based on the type (from the channel/pack
format), but were based on the format (i.e. always PCM, or 0001).

closes #76
  • Loading branch information
tomjnixon committed Jul 27, 2024
1 parent e2086e7 commit 9b4ae56
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
21 changes: 19 additions & 2 deletions ear/fileio/adm/generate_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ def _stream_track_formats(adm, stream_format):
yield track_format


def _stream_type_definition(stream_format):
"""get the TypeDefinition from the channel or pack format linked to a stream format"""
if stream_format.audioChannelFormat is not None:
return stream_format.audioChannelFormat.type
elif stream_format.audioPackFormat is not None:
return stream_format.audioPackFormat.type
else:
assert False, (
"can not generate IDs for an audioStreamFormat not linked"
"to an audioChannelFormats or an audioPackFormat; run validation first"
)


def generate_ids(adm):
"""regenerate ids for all elements in adm
Expand Down Expand Up @@ -42,10 +55,14 @@ def generate_ids(adm):
block.id = "AB_{type.value:04X}{id:04X}_{block_id:08X}".format(id=id, type=element.type, block_id=block_id)

for id, element in enumerate(non_common(adm.audioStreamFormats), 0x1001):
element.id = "AS_{format.value:04X}{id:04X}".format(id=id, format=element.format)
type_id = _stream_type_definition(element).value

element.id = "AS_{type_id:04X}{id:04X}".format(id=id, type_id=type_id)

for track_id, element in enumerate(_stream_track_formats(adm, element), 0x1):
element.id = "AT_{format.value:04X}{id:04X}_{track_id:02X}".format(id=id, format=element.format, track_id=track_id)
element.id = "AT_{type_id:04X}{id:04X}_{track_id:02X}".format(
id=id, type_id=type_id, track_id=track_id
)

for id, element in enumerate(adm.audioTrackUIDs, 0x1):
element.id = "ATU_{id:08X}".format(id=id)
Expand Down
10 changes: 5 additions & 5 deletions ear/fileio/adm/test/test_adm_files/defaults_v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
<audioPackFormat audioPackFormatID="AP_00031001" audioPackFormatName="MyObject 1" typeLabel="0003" typeDefinition="Objects">
<audioChannelFormatIDRef>AC_00031001</audioChannelFormatIDRef>
</audioPackFormat>
<audioStreamFormat audioStreamFormatID="AS_00011001" audioStreamFormatName="MyObject 1" formatLabel="0001" formatDefinition="PCM">
<audioTrackFormatIDRef>AT_00011001_01</audioTrackFormatIDRef>
<audioStreamFormat audioStreamFormatID="AS_00031001" audioStreamFormatName="MyObject 1" formatLabel="0001" formatDefinition="PCM">
<audioTrackFormatIDRef>AT_00031001_01</audioTrackFormatIDRef>
<audioChannelFormatIDRef>AC_00031001</audioChannelFormatIDRef>
</audioStreamFormat>
<audioTrackFormat audioTrackFormatID="AT_00011001_01" audioTrackFormatName="MyObject 1" formatLabel="0001" formatDefinition="PCM">
<audioStreamFormatIDRef>AS_00011001</audioStreamFormatIDRef>
<audioTrackFormat audioTrackFormatID="AT_00031001_01" audioTrackFormatName="MyObject 1" formatLabel="0001" formatDefinition="PCM">
<audioStreamFormatIDRef>AS_00031001</audioStreamFormatIDRef>
</audioTrackFormat>
<audioTrackUID UID="ATU_00000001">
<audioTrackFormatIDRef>AT_00011001_01</audioTrackFormatIDRef>
<audioTrackFormatIDRef>AT_00031001_01</audioTrackFormatIDRef>
<audioPackFormatIDRef>AP_00031001</audioPackFormatIDRef>
</audioTrackUID>
</audioFormatExtended>
Expand Down
4 changes: 2 additions & 2 deletions ear/fileio/adm/test/test_generate_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def test_generate_ids():
assert acf.id == "AC_00031001"
assert acf.audioBlockFormats[0].id == "AB_00031001_00000001"

assert builder.adm.audioStreamFormats[0].id == "AS_00011001"
assert builder.adm.audioStreamFormats[0].id == "AS_00031001"

assert builder.adm.audioTrackFormats[0].id == "AT_00011001_01"
assert builder.adm.audioTrackFormats[0].id == "AT_00031001_01"

assert builder.adm.audioTrackUIDs[0].id == "ATU_00000001"
Binary file modified ear/test/data/test_bwf.wav
Binary file not shown.

0 comments on commit 9b4ae56

Please sign in to comment.