From 3de59579ec988474c85ef982b1f44e9a2685fa2b Mon Sep 17 00:00:00 2001 From: Thomas Nixon Date: Sat, 27 Jul 2024 16:24:16 +0100 Subject: [PATCH] fileio/adm: fix stream and track format ID generation 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 --- CHANGELOG.md | 2 ++ ear/fileio/adm/generate_ids.py | 21 ++++++++++++++++-- .../adm/test/test_adm_files/defaults_v1.xml | 10 ++++----- ear/fileio/adm/test/test_generate_ids.py | 4 ++-- ear/test/data/test_bwf.wav | Bin 153890 -> 153890 bytes 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eed7d10..8565587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]. @@ -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 diff --git a/ear/fileio/adm/generate_ids.py b/ear/fileio/adm/generate_ids.py index f1e7812..2cacf2d 100644 --- a/ear/fileio/adm/generate_ids.py +++ b/ear/fileio/adm/generate_ids.py @@ -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 @@ -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) diff --git a/ear/fileio/adm/test/test_adm_files/defaults_v1.xml b/ear/fileio/adm/test/test_adm_files/defaults_v1.xml index 41d26c4..3ae038f 100644 --- a/ear/fileio/adm/test/test_adm_files/defaults_v1.xml +++ b/ear/fileio/adm/test/test_adm_files/defaults_v1.xml @@ -21,15 +21,15 @@ AC_00031001 - - AT_00011001_01 + + AT_00031001_01 AC_00031001 - - AS_00011001 + + AS_00031001 - AT_00011001_01 + AT_00031001_01 AP_00031001 diff --git a/ear/fileio/adm/test/test_generate_ids.py b/ear/fileio/adm/test/test_generate_ids.py index 978b230..ffb0709 100644 --- a/ear/fileio/adm/test/test_generate_ids.py +++ b/ear/fileio/adm/test/test_generate_ids.py @@ -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" diff --git a/ear/test/data/test_bwf.wav b/ear/test/data/test_bwf.wav index d601d0f6857e54d094f3c586b03b16a4afd3e964..e67e02df5c5eceb2a904057929404e81d75a3981 100644 GIT binary patch delta 142 zcmZ3qiF45=&IuWe#uGEu8I3nibQWhdHZ(9WoV-z{gwc4ipTr(8-w4Eqvi3>2Zayn1 z%mS2tC|eCAW99OoQWF)+p{zu?yv@7hZ!>|-Fqr&bm}~L{r73U|bf6*v&Fhuh*DEt_ KU$4wmYzhF5=`JAv delta 132 zcmZ3qiF45=&IuWeh7&W@84Wj1bQYiNAjQIHIC-N?#pFPVonW33h{tF&d7qT)=ChK* zAnAv))j%>^~#Lf*DEs>n*soLV=Sov