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 3de5957
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Padding after data chunks in bw64 files was not written, and this error was silently ignored in the reader. This can be fixed with the new `ear-utils rewrite` command.
- Mutable default parameters in ADMBuilder could cause unexpected extra blocks to be added when this was used from other programs.
- ADM elements outside the `audioFormatExtended` were parsed, causing errors for some files containing non-standard ADM data.
- Generated IDs for audioStreamFormat and audioTrackFormat included the format (i.e. always PCM, or 0001), but should include the type of the linked channel/pack format. See [#78].

### Changed
- Added a warning for audioBlockFormats which have a duration but no rtime; previously these were fixed silently. See [#54].
Expand Down Expand Up @@ -163,6 +164,7 @@ Initial release.
[#62]: https://github.com/ebu/ebu_adm_renderer/pull/62
[#59]: https://github.com/ebu/ebu_adm_renderer/pull/59
[#58]: https://github.com/ebu/ebu_adm_renderer/issues/58
[#78]: https://github.com/ebu/ebu_adm_renderer/pull/78
[34b738a]: https://github.com/ebu/ebu_adm_renderer/commit/34b738a
[04533fc]: https://github.com/ebu/ebu_adm_renderer/commit/04533fc
[222374a]: https://github.com/ebu/ebu_adm_renderer/commit/222374a
Expand Down
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 audioChannelFormat 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 3de5957

Please sign in to comment.