Skip to content

ADM / BW64 reading and writing: iclforge::adm

iclforge/adm/ac3adm.hpp, library iclforge::adm. A standalone BW64/RF64 + Audio Definition Model (ADM) parser and writer: the professional delivery format Netflix's and Apple's own Atmos ingest pipelines require. Like iclforge::containers::matroska, iclforge::containers::mp4 and iclforge::containers::mpegts, it links nothing from iclforge::ac3 — it has no idea AC-3, E-AC-3 or the JOC/Atmos object layer exist.

Mapping the graph this module parses onto iclforge::ac3::oba::AtmosEncoder (ADM → encode) or building it from a decoded iclforge::ac3::Eac3Decoder programme (decode → ADM) is a separate module, iclforge::adm; driving the read direction end to end — a real ADM BWF master straight to a DD+ JOC E-AC-3 stream — is forge atmos-adm, and the write direction is forge decode ... adm_out (see Commands) and examples/encode_adm.cpp. This page and examples/read_adm.cpp only demonstrate this module's own read-side API — opening a file and walking the parsed graph; encode_adm.cpp is the one that shows the full read-direction pipeline. See "Writing" below for write_bw64().

Opt-in, unlike every other module in this library. ICLFORGE_BUILD_ADM defaults off, and turning it on additionally needs -DVCPKG_MANIFEST_FEATURES=adm (see vcpkg.json) to resolve its Boost dependency:

cmake --preset config-windows-msvc-debug -DICLFORGE_BUILD_ADM=ON -DVCPKG_MANIFEST_FEATURES=adm

Every other target in this project — forge, forge-gui, the iclforge-<project>-tests binaries, every other example — builds identically whether ICLFORGE_BUILD_ADM is on or off; nothing links iclforge::adm unconditionally. See "Why opt-in" below for the reasoning.

const auto document = iclforge::adm::parse_bw64(fixture_path);
if (!document) {
    fmt::printf("parse_bw64 failed: %.*s\n", static_cast<int>(iclforge::adm::describe(document.error()).size()),
                iclforge::adm::describe(document.error()).data());
    return 1;
}
for (const auto& programme : document->model.programmes) {
    fmt::printf("  programme %s (%s) -> %zu content(s)\n", programme.id.c_str(), programme.name.c_str(),
                programme.content_refs.size());
}
for (const auto& object : document->model.objects) {
    fmt::printf("  object %s (%s), start=%.5fs, %zu track UID ref(s)\n", object.id.c_str(), object.name.c_str(),
                object.start_s, object.track_uid_refs.size());
}

Full program: examples/read_adm.cpp — writes a small but valid BW64 fixture (adapted from Recommendation ITU-R BS.2076-2's own worked "Car" object example) to a temp file, since a real ADM BWF master is production audio this project has no license to embed, then parses it back and prints what it found.

What gets parsed

  • The container (Recommendation ITU-R BS.2088-1, Annex 1): <fmt >/<data> integer PCM (8/16/24/32-bit) and IEEE float (32/64-bit — see "PCM formats" below), the <ds64> 64-bit size table for RF64/BW64-headed files, <chna> (the track-number ↔ ADM-ID join table) and <axml> (the embedded ADM XML document itself). A plain RIFF header is accepted too, for the (very common) case of a master that stays under the 4 GB threshold RF64 exists to lift.
  • The ADM object graph (Recommendation ITU-R BS.2076-2, Annex 1): audioProgramme → audioContent → audioObject → audioPackFormat/audioChannelFormat (with its audioBlockFormat time-divisions — position, gain, width/height/depth, channelLock, jumpPosition, zoneExclusion, objectDivergence, screenRef, headLocked, HOA order/degree/normalization/nfcRefDist/equation, a Matrix block's output channel and coefficients) → audioStreamFormat/audioTrackFormat → audioTrackUID. See iclforge/adm/model.hpp for exactly which sub-elements are carried and which are deliberately out of scope: loudness metadata (iclforge::ac3::meta::loudness already measures loudness independently), and the descriptive and interaction metadata (audioProgramme timing and reference screen, dialogue, interaction ranges, labels, headphoneVirtualise, channel frequency, DirectSpeakers position bounds), which nothing in an Atmos or AC-4 encode reads.

Some elements are read by this module, not by libadm. libadm's parser and writer both leave a TODO: zoneExclusion where it would go, its channel-format parser has the loop that would build a Matrix block commented out (so a Matrix channel arrives with no blocks at all), its Matrix block class has no parameter for the matrix, and its AudioPackFormat has no place for a Matrix pack's references; its XML tokenizer is private. parse_bw64 therefore scans the same <axml> text a second time (libs/adm/src/adm_xml_extras.cpp) and attaches:

  • each block's <zoneExclusion> zone children (label, and the six Cartesian bounds when given) to AudioBlockFormat::zone_exclusion;
  • every block of a Matrix channel (the AC_0002xxxx type label), whole: rtime, duration, gain and its gainUnit, importance, outputChannelFormatIDRef (or the legacy outputChannelIDRef BS.2076-3 Table A1-15 says a reader must also accept), jumpPosition, and the matrix's coefficients to AudioBlockFormat::matrix. A coefficient's text is the audioChannelFormatID it reads; gain is linear (converted from gainUnit="dB"), phase is in degrees, delay in milliseconds, and each has a *Var form that names a variable for a renderer to resolve and is held unresolved;
  • a pack's encodePackFormatIDRef, decodePackFormatIDRef, inputPackFormatIDRef and outputPackFormatIDRef (Table A1-24) and an HOA pack's normalization, nfcRefDist and screenRef (Table A1-25) to AudioPackFormat. libadm reads those three HOA defaults as XML attributes; the standard and the EBU's own renderer have them as sub-elements, and both spellings are accepted.

write_bw64 adds the same elements to libadm's output the same way. The scan runs only after libadm has accepted the document, so it does not validate anything, and a Matrix pack's references are carried as the IDs the file gave: nothing here applies a matrix (see the bridge). The other elements are libadm's own.

model always includes BS.2076-2 Annex A's "common definitions". libadm's own parseXml() starts every document from a copy already populated with the standard's ~940 predefined pack/channel/stream/track/block formats (one set per standard loudspeaker layout and first- to third-order HOA component) and merges the file's own content into it, so that a file referencing a common-definition ID (e.g. a stereo bed's pack format AP_00010002) without locally re-declaring it still resolves. This module keeps that merge rather than filtering it back out: iclforge::adm needs exactly this, a pack/channel/stream/track format reference that resolves regardless of whether the file re-declared it — so model.pack_formats/channel_formats/stream_formats/ track_formats are never just "what this one file defined". model.programmes/contents/ objects/track_uids are unaffected (the common set defines none of those four).

AdmDocument — the parse_bw64 result — holds all three pieces together: model (the graph above), chna (the join table, one ChnaEntry per physical-track-to-ADM-ID row), and audio (the decoded PCM, one std::vector<float> per channel, same [-1, 1) normalization convention iclforge::ac3::io::WavData uses). AdmError covers open/parse failure — kCannotOpen, kNotRiff, kMalformedXml, kMalformedAdm, kOther; see iclforge/adm/ac3adm.hpp for the full list. In practice, the two libraries underneath this module (see below) report almost everything through one broad exception family each, so most real failures surface as kCannotOpen (bad/truncated container), kMalformedXml (axml isn't well-formed XML) or kMalformedAdm (well-formed XML that isn't a valid ADM document) — see libs/adm/src/adm.cpp's own comments for exactly which library exception maps to which AdmError.

Writing

write_bw64(path, document) is the read side's mirror image: it turns an AdmModel (the same plain-data graph parse_bw64 produces) into a libadm adm::Document (a new translator, build_libadm_document() in libs/adm/src/adm_model.cpp, alongside the existing read-side build_adm_model()), serializes it with adm::writeXml(), and writes the BW64 container (<fmt >/<chna>/<axml>/<data>) with libbw64's Bw64Writer (bw64::writeFile()) — the same two vendored libraries as the read side, in the other direction. 24-bit integer PCM by default (iclforge::adm::kWriteBitDepth; EBU Tech 3306's own framing); a third argument, AdmWriteOptions{.bit_depth, .float_samples}, selects 16/24/32-bit integer or 32/64-bit IEEE float (anything else is AdmWriteError::kInvalidOptions, and no file is created). The sample rate is written at its full 32-bit width.

iclforge::adm::AdmDocument document;
// ... populate document.model / document.chna / document.audio ...
const auto written = iclforge::adm::write_bw64(path, document);
if (!written) {
    fmt::printf("write_bw64 failed: %.*s\n", static_cast<int>(iclforge::adm::describe(written.error()).size()),
                iclforge::adm::describe(written.error()).data());
    return 1;
}

One asymmetry from the read side: AdmModel's own ID strings (AudioObject::id, ChnaEntry::uid, ...) are used only as correlation keys while the object graph is wired together — they never appear literally in the written file. Real, BS.2076-2-formatted IDs come from libadm's own adm::reassignIds(), called once the whole graph is built; write_bw64 reads those back to build <chna>'s AudioId rows. A caller is therefore free to use any unique, stable strings for id/uid fields, not just the "AO_1001"-style ones parse_bw64 itself produces. ChnaEntry::track_ref/pack_ref are consequently read-path-only fields — write_bw64 derives the real trackRef/packRef strings itself, so a caller building a document purely to write it may leave both empty.

AudioTrackUid::has_bit_depth/bit_depth are not read on write either. Every audioTrackUID is written with bitDepth equal to the <fmt > chunk's bits per sample (AdmWriteOptions::bit_depth), whatever the model says, because a value carried over from another file (a 16-bit master the model was parsed from, say) would contradict the <fmt > chunk written beside it. The Dolby Atmos Master ADM Profile expects the two to agree: Dolby Encoding Engine refuses a master whose audioTrackUIDs leave bitDepth out ("Mismatched track bit depth between ADM and WAV"). sampleRate is written from the model wherever has_sample_rate is set. On the read side both attributes are optional (BS.2076-2 §5.9), and parse_bw64 reports which were present through has_sample_rate and has_bit_depth.

write_bw64 writes everything the model carries: audioProgramme → audioContent → audioObject (which may nest others) → audioPackFormat (DirectSpeakers, Objects, HOA, Binaural or Matrix, which may nest others) → audioChannelFormat (polar or cartesian audioBlockFormats; HOA's order, degree and extras; a Matrix block's output channel, jumpPosition and coefficients) → audioStreamFormat → audioTrackFormat → audioTrackUID. iclforge::adm::write() always populates the full audioStreamFormat/audioTrackFormat chain rather than BS.2076-2's plain-PCM shortcut (audioTrackUID referencing audioPackFormat/audioChannelFormat directly, with no stream/track format at all) — libadm's own adm::reassignIds() zeroes out any audioChannelFormat no audioStreamFormat references ("get an Id with the value zero and are thereby marked as ADM elements which should be ignored" - adm/utilities/id_assignment.hpp's own doc comment), which the shortcut alone triggers; every channel this writer produced collapsed to the same AC_00000000 id before this chain was added.

libadm formats a Matrix block as an element holding only its ID, rtime and duration, and an HOA pack through a subclass whose defaults it never writes. Both are completed in the text once reassignIds() has given every element its final ID, which is also when a Matrix coefficient's or pack reference's correlation key becomes the ID it names in the file. The matrix goes first in the block, as in the standard's sample code, then any gain or importance that is not the default.

AdmWriteError::kInvalidDocument covers: an unresolved *_refs entry, Matrix coefficient or Matrix pack reference; audioObjects or audioPackFormats that nest in a loop; a kUnknown or kUserCustom type, which has no element to become; an HOA block without its order or degree; a value libadm's own types refuse (an azimuth past 180 degrees, an importance past 10); and an audioTrackUID that names both an audioTrackFormat and an audioChannelFormat. A default-constructed AudioBlockFormat is not an error: its position starts as PolarPosition{} and is written as azimuth 0, elevation 0, distance 1. An exception libadm or libbw64 throws once the document is built comes back as kOther — adm::formatId() throws for an ID field that overflows, such as a 256th audioTrackFormat on one audioStreamFormat.

Built on the EBU's own reference implementations

Unlike every other module in this project, iclforge::adm is not a from-scratch implementation of its format. It is a thin translation layer over two vendored third-party libraries, fetched via CMake FetchContent (see libs/adm/CMakeLists.txt):

  • libbw64 (Apache-2.0, header-only, no dependency of its own) — the BW64/RF64 chunk-walking and PCM-decoding layer, including native IEEE-float support. Fetched from a maintained fork of the EBU's own github.com/ebu/libbw64, pinned to a commit rather than a tag or branch — see libs/adm/CMakeLists.txt for why the EBU's own repository is not what this module fetches, and the threat model for what the pin does and does not cover. Patched at populate time by libs/adm/patch_libbw64.cmake for two behaviours this module's own tests need that the pinned commit does not have by default (a truncated recording reading as far as it goes; 64-bit float actually reaching the decode this fork's own utilities already support) — see that script.
  • libadm (Apache-2.0) — the ADM XML object model: parsing, schema validation, and the full element graph.

libadm is the EBU/BBC/IRT team's own repository, the same team that authored the underlying ITU-R Recommendations (BS.2088-1, BS.2076-2) themselves; libbw64's fork carries that team's original code forward with fixes of its own on top. Using both means this module's own code only has to translate an already-validated object graph into iclforge::adm's own types (libs/adm/src/adm_model.cpp), rather than re-implementing container-walking and XML/schema validation this project has no comparative advantage in getting exactly right on the first try. An earlier attempt at exactly that hand-rolled approach is what prompted switching to these libraries instead.

Neither library's own types appear in iclforge::adm's public headers (iclforge/adm/ac3adm.hpp, iclforge/adm/model.hpp) — they are translated into this module's own types at the boundary and stay an implementation detail, the same way this project keeps every other vendored dependency (e.g. Catch2 in tests/) out of its own public API. One practical reason beyond the usual "don't leak a dependency's API" one: libadm's own public C++ namespace is adm, which is why this module's namespace is iclforge::adm, nested under the family's root, and every unqualified use of libadm's names in this project is written ::adm:: (adm::AudioObject, adm::TypeDefinition, adm::Position, ... are all defined by both).

Why opt-in

libadm needs several Boost header libraries (Optional, Variant, Range, Iterator, Functional, Format, Integer and Rational — the exact list confirmed by grepping libadm 0.14.0's own #include <boost/...> directives, not guessed from its README, which undersells it: Rational and Integer aren't mentioned there at all, but adm/utilities/time_conversion.hpp needs both). Every other dependency in this project is either in-tree or a single small vcpkg package (Catch2); pulling in Boost is a materially bigger footprint, so it is deliberately opt-in rather than default-on — ICLFORGE_BUILD_ADM defaults OFF (unlike ICLFORGE_BUILD_MATROSKA/ICLFORGE_BUILD_MP4/ICLFORGE_BUILD_MPEGTS, which default ON), and turning it on needs the dedicated adm vcpkg feature to resolve those Boost packages. A build with ICLFORGE_BUILD_ADM=OFF (the default) never touches find_package(Boost), never fetches libbw64/libadm, and behaves identically to a build of this project before this module existed.

iclforge::adm IS part of the installed find_package(iclforge) package (see the library overview), but shared-only — unlike every other module here, there is no iclforge::adm_static to link against, since a static archive would leave a downstream consumer with unresolved symbols into libbw64/libadm (neither installed/exported by this project in its own right); a self-contained .so absorbs both at its own build step instead. It is not wired into the Android/Shield NDK build — see libs/adm/CMakeLists.txt's own header comment for both points.

PCM formats

Integer PCM (8/16/24/32-bit) and IEEE float (32/64-bit) both read, through the vendored libbw64 directly, and both come back as the same [-1, 1) floats on PcmAudio::channels. bits_per_sample reports the container width and is not, on its own, a statement about which of the two it was.

This module used to need a second, hand-rolled container walk for float specifically: the EBU's own libbw64 refuses any <fmt > formatTag but PCM outright at open time ("format unsupported: <tag>"), and patching a dependency fetched at a pinned tag to teach it a feature of this project's own was judged a worse standing cost than a second, narrower reader. The pinned fork (see above) added native WAVE_FORMAT_IEEE_FLOAT support upstream of this module, so that second reader (float_pcm_bw64.hpp, retired) is no longer needed — both formats go through the identical libbw64 read and the identical libadm <axml> parse now, so there is exactly one place either one could come out differently depending on how the samples were stored, not two.

A file libbw64 opens and then rejects surfaces as AdmError::kCannotOpen; its exceptions carry no type this module could map to anything more specific — see ac3adm.hpp's own comment on AdmError.

Most real ADM BWF masters are 16- or 24-bit integer (EBU Tech 3306/BS.2088-1 Annex 2 §2's own PCM-only framing). Float ones exist too.


See also: File I/O — the plain-WAV reader this module's container-parsing deliberately does not share an implementation with, despite the family resemblance; ADM → Atmos bridging — iclforge::adm, which maps this graph onto iclforge::ac3::oba::AtmosEncoder; Spatial & Atmos objects — the iclforge::ac3::oba::AtmosEncoder/iclforge::objects::oba::motion surface that bridge drives.