diff --git a/src/adm/adm_metadata.cpp b/src/adm/adm_metadata.cpp index fa9329d..4240162 100644 --- a/src/adm/adm_metadata.cpp +++ b/src/adm/adm_metadata.cpp @@ -151,6 +151,14 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou for (std::size_t i = 5u + 262u; i < segment10.size(); ++i) { segment10[i] = static_cast(0x84); } + // Nine 15-byte configuration trims start at byte 7; the first byte of each + // carries the auto-trim flag in bit 0 (1 = automatic, 0 = manual). The + // default is automatic, so a freshly rendered master opens with automatic + // trims in the renderer. + for (std::size_t layout = 0; layout < 9; ++layout) { + const std::size_t flag = 7u + 15u * layout; + segment10[flag] = static_cast(static_cast(segment10[flag]) | 0x01u); + } const std::size_t object_modes = 4u + 2u + 1u + 9u * 15u + object_count; for (std::uint32_t i = 10; i < std::min(object_count, 10u + kObjectCount); ++i) { const std::size_t index = object_modes + i; diff --git a/tests/test_core.cpp b/tests/test_core.cpp index 7f19d17..d1e74eb 100644 --- a/tests/test_core.cpp +++ b/tests/test_core.cpp @@ -291,6 +291,68 @@ void test_oamd_and_adm_helpers() { CHECK(x == 1.0 && y == 1.0 && z == 0.0); } +// DBMD segment 10: the nine configuration trims must default to automatic (bit 0 +// of each trim's first byte), and every other field of the block must keep the +// layout the writer has always produced. +void test_dbmd_auto_trim() { + std::string dbmd; + CHECK(joc::adm::build_dbmd(25, joc::adm::BinauralMode::Mid, &dbmd).ok()); + + std::string segment10; + std::size_t offset = 4; + while (offset + 2 < dbmd.size() && static_cast(dbmd[offset]) != 0) { + const std::size_t size = + static_cast(static_cast(dbmd[offset + 1])) | + (static_cast(static_cast(dbmd[offset + 2])) << 8); + const std::size_t start = offset + 3; + CHECK(start + size + 1 <= dbmd.size()); + unsigned sum = static_cast(size); + for (std::size_t i = 0; i < size; ++i) { + sum += static_cast(dbmd[start + i]); + } + sum += static_cast(dbmd[start + size]); + CHECK((sum & 0xFFu) == 0u); + if (static_cast(dbmd[offset]) == 10) { + segment10 = dbmd.substr(start, size); + } + offset = start + size + 1; + } + + CHECK(segment10.size() == 292); + CHECK(static_cast(segment10[0]) == 0xBD); + CHECK(static_cast(segment10[1]) == 0x6F); + CHECK(static_cast(segment10[2]) == 0x72); + CHECK(static_cast(segment10[3]) == 0xF8); + CHECK(static_cast(segment10[4]) == 25); + CHECK(static_cast(segment10[5]) == 0); + CHECK(static_cast(segment10[6]) == 0); + + // Nine 15-byte configuration trims: automatic, payload untouched. + for (std::size_t layout = 0; layout < 9; ++layout) { + const std::size_t flag = 7 + 15 * layout; + CHECK(static_cast(segment10[flag]) == 0x01); + for (std::size_t i = 1; i < 15; ++i) { + CHECK(static_cast(segment10[flag + i]) == 0); + } + } + // One trim-bypass byte per track stays clear. + for (std::size_t i = 7 + 9 * 15; i < 7 + 9 * 15 + 25; ++i) { + CHECK(static_cast(segment10[i]) == 0); + } + // Headphone modes: bed tracks clear, the object slots carry the mode value. + for (std::size_t i = 0; i < 25; ++i) { + const unsigned char expected = i < 10 ? 0x00 : 0x03; + CHECK(static_cast(segment10[7 + 9 * 15 + 25 + i]) == expected); + } + // Nothing between the mode array and the trailing template fill changed. + for (std::size_t i = 7 + 9 * 15 + 2 * 25; i < 5 + 262; ++i) { + CHECK(static_cast(segment10[i]) == 0); + } + for (std::size_t i = 5 + 262; i < segment10.size(); ++i) { + CHECK(static_cast(segment10[i]) == 0x84); + } +} + 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}; @@ -1052,6 +1114,7 @@ int main() { test_task_result_json(); test_npy(); test_oamd_and_adm_helpers(); + test_dbmd_auto_trim(); test_int24_packing(); test_utf8_paths(); test_process_runner();