From cb6ab0ca4612d4f2237339047acec028cbf7fd0f Mon Sep 17 00:00:00 2001 From: TheM14 Date: Wed, 28 Oct 2026 18:05:47 +0800 Subject: [PATCH] Port the OAMD ramp timing to the 32-sample metadata grid --- src/foundation/metadata_timing.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/foundation/metadata_timing.h diff --git a/src/foundation/metadata_timing.h b/src/foundation/metadata_timing.h new file mode 100644 index 0000000..83b2b56 --- /dev/null +++ b/src/foundation/metadata_timing.h @@ -0,0 +1,25 @@ +// Port of src/oamd_tracks.py align_metadata_sample: an OAMD position update is +// scheduled on the renderer's processing-block grid, the same 32-sample grid the +// speaker control blocks use. It lives in foundation because both the ADM track +// builder and the object position timeline need it, and the timeline must not +// depend on output. +#pragma once + +#include + +namespace joc::timing { + +inline constexpr std::int64_t kMetadataBlockSamples = 32; + +// Nearest block boundary, ties towards the earlier block; the negative branch +// floors like the reference's Python `//`. +inline std::int64_t align_metadata_sample(std::int64_t sample, + std::int64_t block_samples = kMetadataBlockSamples) { + const std::int64_t numerator = sample + block_samples / 2 - 1; + const std::int64_t quotient = + numerator >= 0 ? numerator / block_samples + : -((-numerator + block_samples - 1) / block_samples); + return block_samples * quotient; +} + +} // namespace joc::timing