Read the OAMD trim element into speaker rendering and ADM
ci / ubuntu-latest (push) Failing after 16s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s

The OAMD parser reads the trim element: warp mode, global trim mode, the
nine per-configuration records (centre, surround and height level, the two
front-back balances) and the per-object bypass flags. OamdUpdate carries
it, so the file task and the streaming step see the same state; a payload
without the element keeps the previous controls, and an absent element
starts at warp 0 with automatic trim.

Speaker rendering reads the controls from OAMD only; neither the CLI nor
the frontends offer an override. Eligible layouts leave the floor Y alone
at warp 0 and use clamp(2Y, 0, 1) at warp 1, the height layer is never
scaled, and warp 2/3 is reported as unsupported where the speaker
consumes it. Floor, height and trim evaluation keep separate coordinates:
floor Y is balance(warp(Y)), while height Y and trim Y are balance(Y). An
explicit configuration contributes a position-dependent scalar for each
object, applied before accumulation instead of to the output channels
after the mix; automatic, disabled and explicit are mutually exclusive, and
a bypassed object keeps its warp but loses balance and trim. Automatic
still uses the layout position compensation, disabled uses unity, and
layouts without trim semantics stay disabled. LFE passes through, and ADM
source positions and binaural rendering are unchanged.

The controls travel in ejoc_speaker_controls, a C struct a future decoder
can fill without knowing the layout; the layout table now carries the
surround and height channel counts and the seven layouts that have trim
semantics. The internal ABI goes to version 3 for the new process
parameter.

The ADM writer mirrors the element into both carriers. AXML gains
DolbyAtmosMasterFile with DolbyMasterContentInfo, DolbyTrimModeSetup (one
record per configuration, zero values for a disabled one) and
DolbyWarpMode. dbmd segment 10 carries the nine 15-byte records (automatic
flag, three float32 levels and two sign-magnitude balances), and segment 9
writes the warp code into the low three bits of at[152] while keeping the
other packed fields. The task scans the first 64 audio frames for the
element, as the reference does, so a duration-limited render still writes
it.

The bilingual mathematical notes describe the configuration index, the
balance map, the three coordinates and the evaluation order; the READMEs
state that the controls come from OAMD and that warp 2/3 is refused. ctest
covers the element parse, configuration selection, warp 0/1 with the Q15
clamp, the height coordinate, explicit trim and balance, per-object
bypass, LFE passthrough, the step's metadata updates and the exact
dbmd/AXML bytes. Speaker output over the same objects16 stream is
byte-identical to the reference for the seven trimmed layouts and the
wider ones, and both ADM carriers of a rendered BWF are byte-identical to
the reference writer.

The product version goes to 1.2.0; the public ABI stays at 5.
This commit is contained in:
TheM14 committed 2026-11-03 01:34:15 +08:00
1 parent 20f2e77664
commit 58e3403642
21 files changed
+1597 -48

No files matched your search

+477
View File
@@ -29,6 +29,8 @@
#include "io/wav_writer.h"
#include "io/zip_reader.h"
#include "oamd/oamd_parser.h"
#include "speaker/speaker_layout_lookup.h"
#include "speaker/speaker_trim.h"
#include "stream/stream.h"
#include "task/task.h"
@@ -47,6 +49,86 @@ void check(bool condition, const char* expression, const char* file, int line) {
#define CHECK(expression) check((expression), #expression, __FILE__, __LINE__)
std::vector<std::uint8_t> from_hex(const char* text) {
auto digit = [](char c) {
return static_cast<std::uint8_t>(c <= '9' ? c - '0' : (c | 0x20) - 'a' + 10);
};
std::vector<std::uint8_t> out;
for (std::size_t i = 0; text[i] != '\0' && text[i + 1] != '\0'; i += 2) {
out.push_back(static_cast<std::uint8_t>((digit(text[i]) << 4) | digit(text[i + 1])));
}
return out;
}
std::string bytes_to_string(const std::vector<std::uint8_t>& bytes) {
return std::string(reinterpret_cast<const char*>(bytes.data()), bytes.size());
}
ejoc_speaker_controls speaker_controls(std::uint32_t warp, std::uint32_t trim_mode) {
ejoc_speaker_controls controls{};
controls.struct_size = sizeof(controls);
controls.struct_version = EJOC_SPEAKER_CONTROLS_VERSION;
controls.warp_mode = warp;
controls.trim_mode = trim_mode;
return controls;
}
// Gain vector of one object, in standard output-channel order. The object sits
// at (u, v, z) Q15 and contributes a single unit sample so the value read back
// from sample 0 is the target gain.
std::vector<double> speaker_gains(const joc::speaker::LayoutInfo& layout,
const ejoc_speaker_controls& controls, std::uint16_t u,
std::uint16_t v, std::uint16_t z,
bool bypass_object = false) {
std::vector<double> gains(layout.channel_count, 0.0);
ejoc_speaker_renderer_handle handle =
ejoc_speaker_renderer_create(layout.speaker_bitfield);
CHECK(handle != nullptr);
if (handle == nullptr) {
return gains;
}
std::vector<float> input(static_cast<std::size_t>(EJOC_SPEAKER_BLOCK_SAMPLES) *
JOC_OUTPUT_CHANNELS,
0.0f);
input[1] = 1.0f; // object slot 1, sample 0
std::uint16_t positions[joc::oamd::kObjects][3] = {};
positions[0][0] = u;
positions[0][1] = v;
positions[0][2] = z;
const std::uint32_t offset = 0;
const std::uint32_t ramp = 0;
ejoc_speaker_controls applied = controls;
if (bypass_object) {
applied.trim_bypass[1] = 1;
}
std::vector<double> output(static_cast<std::size_t>(EJOC_SPEAKER_BLOCK_SAMPLES) *
layout.channel_count,
0.0);
const int result = ejoc_speaker_renderer_process(
handle, input.data(), EJOC_SPEAKER_BLOCK_SAMPLES, 1, &offset, &ramp,
&positions[0][0], nullptr, nullptr, nullptr, &applied, output.data());
CHECK(result == 0);
for (std::uint32_t channel = 0; channel < layout.channel_count; ++channel) {
gains[channel] = output[channel];
}
ejoc_speaker_renderer_destroy(handle);
return gains;
}
void check_gains(const std::vector<double>& actual, const std::vector<double>& expected) {
CHECK(actual.size() == expected.size());
if (actual.size() != expected.size()) {
return;
}
for (std::size_t channel = 0; channel < actual.size(); ++channel) {
if (std::fabs(actual[channel] - expected[channel]) > 1e-13) {
std::printf(" channel %zu actual %.17g expected %.17g\n", channel,
actual[channel], expected[channel]);
}
CHECK(std::fabs(actual[channel] - expected[channel]) <= 1e-13);
}
}
void test_sha256() {
CHECK(joc::crypto::sha256_hex("", 0) ==
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
@@ -350,6 +432,396 @@ void test_dbmd_auto_trim() {
}
}
// OAMD trim element parsing: warp mode, global trim mode, the nine
// configuration records and the per-object bypass flags. The payloads are
// generated by the reference parser's own bit layout.
void test_oamd_trim_parse() {
// warp 2, global trim mode 2; config 0 default, 1 disabled, 2 explicit
// (centre 6 dB, surround -15 dB, height -36 dB, balance +1 / -0.5), the
// rest default; objects 1 and 5 bypassed.
const std::vector<std::uint8_t> explicit_payload = from_hex("1f049c8a9f0eff9ffa2000");
joc::oamd::OamdTrim trim;
bool present = false;
CHECK(joc::oamd::parse_trim(explicit_payload.data(), explicit_payload.size(), &trim,
&present)
.ok());
CHECK(present);
CHECK(trim.warp_mode == 2);
CHECK(trim.global_trim_mode == 2);
CHECK(trim.object_count == 16);
CHECK(trim.configs[0].kind == joc::oamd::TrimConfigKind::kDefault);
CHECK(trim.configs[1].kind == joc::oamd::TrimConfigKind::kDisabled);
CHECK(trim.configs[2].kind == joc::oamd::TrimConfigKind::kExplicit);
CHECK(trim.configs[2].presence == 0x1F);
CHECK(trim.configs[2].centre == 6.0);
CHECK(trim.configs[2].surround == -15.0);
CHECK(trim.configs[2].height == -36.0);
CHECK(trim.configs[2].balance_overhead == 1.0);
CHECK(trim.configs[2].balance_listener == -0.5);
CHECK(trim.configs[3].kind == joc::oamd::TrimConfigKind::kDefault);
CHECK(trim.configs[8].kind == joc::oamd::TrimConfigKind::kDefault);
CHECK(trim.disable_per_object[1]);
CHECK(trim.disable_per_object[5]);
CHECK(!trim.disable_per_object[0]);
CHECK(!trim.disable_per_object[2]);
// warp 1, automatic trim, no configuration records and no bypass table.
const std::vector<std::uint8_t> auto_payload = from_hex("1f048040");
CHECK(joc::oamd::parse_trim(auto_payload.data(), auto_payload.size(), &trim, &present)
.ok());
CHECK(present);
CHECK(trim.warp_mode == 1);
CHECK(trim.global_trim_mode == 0);
for (int index = 0; index < joc::oamd::kTrimConfigs; ++index) {
CHECK(trim.configs[index].kind == joc::oamd::TrimConfigKind::kAbsent);
}
for (int slot = 0; slot < joc::oamd::kMaxSlots; ++slot) {
CHECK(!trim.disable_per_object[slot]);
}
}
void test_speaker_trim_parameters() {
joc::speaker::LayoutInfo layout51{};
joc::speaker::LayoutInfo layout71{};
joc::speaker::LayoutInfo layout40{};
joc::speaker::LayoutInfo layout20{};
joc::speaker::LayoutInfo layout512{};
joc::speaker::LayoutInfo layout514{};
joc::speaker::LayoutInfo layout714{};
CHECK(joc::speaker::layout_by_name("5.1", &layout51));
CHECK(joc::speaker::layout_by_name("7.1", &layout71));
CHECK(joc::speaker::layout_by_name("4.0", &layout40));
CHECK(joc::speaker::layout_by_name("2.0", &layout20));
CHECK(joc::speaker::layout_by_name("5.1.2", &layout512));
CHECK(joc::speaker::layout_by_name("5.1.4", &layout514));
CHECK(joc::speaker::layout_by_name("7.1.4", &layout714));
CHECK(joc::speaker::trim_config_index(layout20) == 0);
CHECK(joc::speaker::trim_config_index(layout40) == 1);
CHECK(joc::speaker::trim_config_index(layout51) == 1);
CHECK(joc::speaker::trim_config_index(layout71) == 2);
CHECK(joc::speaker::trim_config_index(layout512) == 4);
CHECK(joc::speaker::trim_config_index(layout514) == 7);
ejoc_speaker_controls controls{};
CHECK(joc::speaker::parameters_from_oamd(nullptr, layout51, &controls).ok());
CHECK(controls.warp_mode == 0);
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_AUTOMATIC);
CHECK(joc::speaker::parameters_from_oamd(nullptr, layout714, &controls).ok());
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_DISABLED);
joc::oamd::OamdTrim trim{};
trim.warp_mode = 1;
trim.global_trim_mode = 1;
CHECK(joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
CHECK(controls.warp_mode == 1);
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_DISABLED);
trim = joc::oamd::OamdTrim{};
trim.global_trim_mode = 2;
trim.configs[1].kind = joc::oamd::TrimConfigKind::kDefault;
CHECK(joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_AUTOMATIC);
trim.configs[1].kind = joc::oamd::TrimConfigKind::kDisabled;
CHECK(joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_DISABLED);
trim.configs[1].kind = joc::oamd::TrimConfigKind::kExplicit;
trim.configs[1].centre = 1.5;
trim.configs[1].surround = 3.0;
trim.configs[1].height = -6.0;
trim.configs[1].balance_listener = -0.5;
trim.configs[1].balance_overhead = 0.25;
trim.disable_per_object[1] = true;
CHECK(joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_EXPLICIT);
CHECK(controls.centre_db == 1.5);
CHECK(controls.surround_db == 0.0);
CHECK(controls.height_db == -6.0);
CHECK(controls.listener_balance == -0.5);
CHECK(controls.overhead_balance == 0.25);
CHECK(controls.trim_bypass[1] == 1);
CHECK(controls.trim_bypass[2] == 0);
trim.configs[1].balance_listener = 1.5;
CHECK(!joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
trim.configs[1].balance_listener = -0.5;
trim.configs[1].centre = std::numeric_limits<double>::quiet_NaN();
CHECK(!joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
trim.configs[1].centre = 1.5;
trim.warp_mode = 2;
const joc::Status warp2 = joc::speaker::parameters_from_oamd(&trim, layout51, &controls);
CHECK(!warp2.ok());
CHECK(warp2.code() == JOC_ERR_NOT_SUPPORTED);
trim.warp_mode = 3;
CHECK(!joc::speaker::parameters_from_oamd(&trim, layout714, &controls).ok());
trim.warp_mode = 0;
trim.global_trim_mode = 3;
CHECK(!joc::speaker::parameters_from_oamd(&trim, layout51, &controls).ok());
// A layout without trim semantics settles on disabled before the reserved
// global mode is looked at.
CHECK(joc::speaker::parameters_from_oamd(&trim, layout714, &controls).ok());
CHECK(controls.trim_mode == EJOC_SPEAKER_TRIM_DISABLED);
}
void test_speaker_warp_and_trim() {
joc::speaker::LayoutInfo layout51{};
joc::speaker::LayoutInfo layout514{};
CHECK(joc::speaker::layout_by_name("5.1", &layout51));
CHECK(joc::speaker::layout_by_name("5.1.4", &layout514));
ejoc_speaker_controls automatic51{};
CHECK(joc::speaker::parameters_from_oamd(nullptr, layout51, &automatic51).ok());
ejoc_speaker_controls automatic514{};
CHECK(joc::speaker::parameters_from_oamd(nullptr, layout514, &automatic514).ok());
// Warp 0 leaves the floor Y alone; warp 1 doubles it before the clamp.
const std::vector<double> warp0 = {0.9126902722074105, 0, 0, 0, 0.18155106823708969, 0};
const std::vector<double> warp1 = {0.85973219419392444, 0, 0, 0, 0.35612480624995158, 0};
const std::vector<double> clamped = {0, 0, 0, 0, 0.70794578438413791, 0};
check_gains(speaker_gains(layout51, automatic51, 0, 4096, 0), warp0);
ejoc_speaker_controls warped = automatic51;
warped.warp_mode = 1;
check_gains(speaker_gains(layout51, warped, 0, 4096, 0), warp1);
check_gains(speaker_gains(layout51, warped, 0, 24576, 0), clamped);
// The height layer is not warped.
const std::vector<double> height_top = {0, 0, 0, 0, 0, 0, 0.84139514164519513, 0, 0, 0};
const std::vector<double> height_warp0 =
speaker_gains(layout514, automatic514, 0, 4096, 32767);
ejoc_speaker_controls warped514 = automatic514;
warped514.warp_mode = 1;
check_gains(height_warp0, height_top);
check_gains(speaker_gains(layout514, warped514, 0, 4096, 32767), height_top);
// Explicit trim with balance: warp then balance for the floor, balance on
// the original Y for the trim evaluation.
ejoc_speaker_controls explicit_controls = speaker_controls(
1, EJOC_SPEAKER_TRIM_EXPLICIT);
explicit_controls.surround_db = -6.0;
explicit_controls.listener_balance = 9.0 / 16.0;
explicit_controls.overhead_balance = -9.0 / 16.0;
const std::vector<double> trimmed = {0.68117911059016056, 0, 0, 0, 0.41744281702545366, 0};
check_gains(speaker_gains(layout51, explicit_controls, 0, 4096, 0), trimmed);
// Per-object bypass keeps warp but drops balance and trim.
const std::vector<double> bypassed = {0.92387494614065435, 0, 0, 0, 0.38269450465561039, 0};
check_gains(speaker_gains(layout51, explicit_controls, 0, 4096, 0, true), bypassed);
// Centre trim is local to the front-centre region; height trim scales with Z.
ejoc_speaker_controls centre_controls = speaker_controls(0, EJOC_SPEAKER_TRIM_EXPLICIT);
centre_controls.centre_db = -6.0;
const std::vector<double> centre = {3.0688867071757785e-17, 0, 0.50118723362727224, 0, 0, 0};
check_gains(speaker_gains(layout51, centre_controls, 16384, 0, 0), centre);
ejoc_speaker_controls height_controls = speaker_controls(0, EJOC_SPEAKER_TRIM_EXPLICIT);
height_controls.height_db = -6.0;
const std::vector<double> height_half = {0.50059326485045341, 0, 0, 0, 0,
0, 0.50059326485045341, 0, 0, 0};
check_gains(speaker_gains(layout514, height_controls, 0, 0, 16384), height_half);
// LFE passes straight through, untouched by warp, trim or balance.
ejoc_speaker_renderer_handle handle =
ejoc_speaker_renderer_create(layout51.speaker_bitfield);
CHECK(handle != nullptr);
if (handle != nullptr) {
std::vector<float> input(static_cast<std::size_t>(EJOC_SPEAKER_BLOCK_SAMPLES) *
JOC_OUTPUT_CHANNELS,
0.0f);
for (std::uint32_t sample = 0; sample < EJOC_SPEAKER_BLOCK_SAMPLES; ++sample) {
input[sample * JOC_OUTPUT_CHANNELS] = 0.25f;
}
std::vector<double> output(static_cast<std::size_t>(EJOC_SPEAKER_BLOCK_SAMPLES) *
layout51.channel_count,
0.0);
CHECK(ejoc_speaker_renderer_process(handle, input.data(), EJOC_SPEAKER_BLOCK_SAMPLES,
0, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, &explicit_controls, output.data()) == 0);
for (std::uint32_t sample = 0; sample < EJOC_SPEAKER_BLOCK_SAMPLES; ++sample) {
for (std::uint32_t channel = 0; channel < layout51.channel_count; ++channel) {
const double value = output[sample * layout51.channel_count + channel];
CHECK(channel == 3 ? std::fabs(value - 0.25) <= 1e-15 : value == 0.0);
}
}
// Reserved warp modes are rejected before any rendering happens.
ejoc_speaker_controls reserved = speaker_controls(2, EJOC_SPEAKER_TRIM_DISABLED);
CHECK(ejoc_speaker_renderer_process(handle, input.data(), EJOC_SPEAKER_BLOCK_SAMPLES,
0, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, &reserved, output.data()) != 0);
ejoc_speaker_renderer_destroy(handle);
}
}
// The speaker step takes the OAMD trim element from each payload; a payload
// without it keeps the previous controls.
void test_speaker_step_trim_events() {
joc::speaker::SpeakerStep step;
CHECK(joc::speaker::layout_by_name("5.1", &step.layout));
step.handle = ejoc_speaker_renderer_create(step.layout.speaker_bitfield);
CHECK(step.handle != nullptr);
if (step.handle == nullptr) {
return;
}
std::vector<float> frame(static_cast<std::size_t>(JOC_FRAME_SAMPLES) * JOC_OUTPUT_CHANNELS,
0.0f);
for (std::uint32_t sample = 0; sample < JOC_FRAME_SAMPLES; ++sample) {
frame[1u * JOC_FRAME_SAMPLES + sample] = 1.0f;
}
std::string error;
const std::size_t read = 1472u * step.layout.channel_count;
joc::oamd::OamdUpdate update;
update.slots[1].q2 = 4096;
update.has_trim = true;
update.trim.warp_mode = 1;
update.trim.global_trim_mode = 0;
update.trim.object_count = 16;
CHECK(joc::speaker::step(&step, frame, &update, &error).ok());
const std::vector<double> warp1 = {0.85973219419392444, 0, 0, 0, 0.35612480624995158, 0};
std::vector<double> gains(step.layout.channel_count);
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
}
check_gains(gains, warp1);
// No trim element: warp 1 and automatic trim stay in effect.
update = joc::oamd::OamdUpdate{};
update.slots[1].q2 = 2048;
CHECK(joc::speaker::step(&step, frame, &update, &error).ok());
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
}
const std::vector<double> half_warp1 = {0.9461247896349676, 0, 0, 0,
0.18820181552760662, 0};
check_gains(gains, half_warp1);
// A new trim element switches the controls back to warp 0.
update = joc::oamd::OamdUpdate{};
update.slots[1].q2 = 2048;
update.has_trim = true;
update.trim.warp_mode = 0;
update.trim.global_trim_mode = 0;
update.trim.object_count = 16;
CHECK(joc::speaker::step(&step, frame, &update, &error).ok());
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
}
const std::vector<double> half_warp0 = {0.96001622724230795, 0, 0, 0,
0.094556249720175942, 0};
check_gains(gains, half_warp0);
ejoc_speaker_renderer_destroy(step.handle);
}
void test_dbmd_and_axml_trim() {
joc::oamd::OamdTrim trim{};
trim.warp_mode = 2;
trim.global_trim_mode = 2;
trim.object_count = 16;
trim.configs[0].kind = joc::oamd::TrimConfigKind::kDefault;
trim.configs[1].kind = joc::oamd::TrimConfigKind::kDisabled;
trim.configs[2].kind = joc::oamd::TrimConfigKind::kExplicit;
trim.configs[2].presence = 0x1F;
trim.configs[2].centre = 6.0;
trim.configs[2].surround = -15.0;
trim.configs[2].height = -36.0;
trim.configs[2].balance_overhead = 1.0;
trim.configs[2].balance_listener = -0.5;
for (int index = 3; index < joc::oamd::kTrimConfigs; ++index) {
trim.configs[index].kind = joc::oamd::TrimConfigKind::kDefault;
}
std::string dbmd;
CHECK(joc::adm::build_dbmd(25, joc::adm::BinauralMode::Mid, &dbmd, &trim).ok());
std::string segment9;
std::string segment10;
std::size_t offset = 4;
while (offset + 2 < dbmd.size() && static_cast<unsigned char>(dbmd[offset]) != 0) {
const std::size_t size =
static_cast<std::size_t>(static_cast<unsigned char>(dbmd[offset + 1])) |
(static_cast<std::size_t>(static_cast<unsigned char>(dbmd[offset + 2])) << 8);
const std::size_t start = offset + 3;
unsigned sum = static_cast<unsigned>(size);
for (std::size_t i = 0; i < size; ++i) {
sum += static_cast<unsigned char>(dbmd[start + i]);
}
sum += static_cast<unsigned char>(dbmd[start + size]);
CHECK((sum & 0xFFu) == 0u);
const unsigned id = static_cast<unsigned char>(dbmd[offset]);
if (id == 9u) {
segment9 = dbmd.substr(start, size);
} else if (id == 10u) {
segment10 = dbmd.substr(start, size);
}
offset = start + size + 1;
}
CHECK(segment9.size() == 248);
CHECK(static_cast<unsigned char>(segment9[152]) == 2);
CHECK(segment10.size() == 292);
const std::string expected_configs = bytes_to_string(from_hex(
"010000000000000000000000000000"
"000000000000000000000000000000"
"000000c040000070c1000010c27fc0"
"010000000000000000000000000000"
"010000000000000000000000000000"
"010000000000000000000000000000"
"010000000000000000000000000000"
"010000000000000000000000000000"
"010000000000000000000000000000"));
CHECK(segment10.substr(7, 135) == expected_configs);
// The bypass table and headphone modes stay untouched.
for (std::size_t i = 7 + 9 * 15; i < 7 + 9 * 15 + 2 * 25; ++i) {
const unsigned char expected =
(i >= 7 + 9 * 15 + 25 + 10) ? 0x03u : 0x00u;
CHECK(static_cast<unsigned char>(segment10[i]) == expected);
}
// Without a trim element the warp field keeps the template's zero.
std::string plain;
CHECK(joc::adm::build_dbmd(25, joc::adm::BinauralMode::Mid, &plain).ok());
CHECK(plain.size() > 4);
std::string plain_segment9;
offset = 4;
while (offset + 2 < plain.size() && static_cast<unsigned char>(plain[offset]) != 0) {
const std::size_t size =
static_cast<std::size_t>(static_cast<unsigned char>(plain[offset + 1])) |
(static_cast<std::size_t>(static_cast<unsigned char>(plain[offset + 2])) << 8);
const std::size_t start = offset + 3;
if (static_cast<unsigned char>(plain[offset]) == 9u) {
plain_segment9 = plain.substr(start, size);
}
offset = start + size + 1;
}
CHECK(plain_segment9.size() == 248);
CHECK(static_cast<unsigned char>(plain_segment9[152]) == 0u);
std::vector<joc::adm::Track> tracks(15);
for (std::size_t i = 0; i < tracks.size(); ++i) {
tracks[i].name = "obj" + std::to_string(i);
}
const std::string axml = joc::adm::build_axml(tracks, 1.0, 48000, &trim);
const std::string expected_block =
"<DolbyAtmosMasterFile><DolbyMasterContentInfo><render_warp_mode>2</render_warp_mode>"
"</DolbyMasterContentInfo><DolbyTrimModeSetup>"
"<records><type>0</type></records>"
"<records><type>1</type><centerTrim>0.000000</centerTrim>"
"<surroundTrim>0.000000</surroundTrim><heightTrim>0.000000</heightTrim>"
"<balanceOverhead>0.000000</balanceOverhead>"
"<balanceListener>0.000000</balanceListener></records>"
"<records><type>2</type><centerTrim>6.000000</centerTrim>"
"<surroundTrim>-15.000000</surroundTrim><heightTrim>-36.000000</heightTrim>"
"<balanceOverhead>1.000000</balanceOverhead>"
"<balanceListener>-0.500000</balanceListener></records>"
"<records><type>3</type></records><records><type>4</type></records>"
"<records><type>5</type></records><records><type>6</type></records>"
"<records><type>7</type></records><records><type>8</type></records>"
"</DolbyTrimModeSetup><DolbyWarpMode>2</DolbyWarpMode></DolbyAtmosMasterFile>";
const std::size_t found = axml.find(expected_block);
CHECK(found != std::string::npos);
CHECK(found < axml.find("</audioFormatExtended>"));
const std::string plain_axml = joc::adm::build_axml(tracks, 1.0, 48000);
CHECK(plain_axml.find("<DolbyAtmosMasterFile>") == std::string::npos);
}
void test_int24_packing() {
// Interleaved (L,R) for two frames: 0.0, +1.0, -1.0, +2.0 (clips).
const float values[4] = {0.0f, 1.0f, -1.0f, 2.0f};
@@ -891,6 +1363,11 @@ int main() {
test_npy();
test_oamd_and_adm_helpers();
test_dbmd_auto_trim();
test_oamd_trim_parse();
test_speaker_trim_parameters();
test_speaker_warp_and_trim();
test_speaker_step_trim_events();
test_dbmd_and_axml_trim();
test_int24_packing();
test_utf8_paths();
test_process_runner();