Carry the OAMD trim element into the ADM BWF metadata

Parse the trim element: warp_mode, global_trim_mode, the nine
per-configuration trim_balance_presence records, and the per-object
bypass flags.  Select the configuration that applies to a layout from
its surround and height speaker counts:

    cfg = kappa_f(surrounds) + 3 * kappa_h(heights)

    kappa_f: 0 -> 0, 2..3 -> 1, otherwise 2
    kappa_h: 0 -> 0, 2 -> 1, otherwise 2

Write the configuration to both carriers:

  * AXML gets a DolbyAtmosMasterFile container holding
    DolbyMasterContentInfo, DolbyTrimModeSetup (one records entry per
    configuration with centerTrim, surroundTrim, heightTrim and the two
    balance fields) and DolbyWarpMode.
  * Segment 10 of the dbmd chunk gets the nine 15-byte records: bit 0
    is the automatic flag, and an explicit record carries three float32
    trims followed by two sign-magnitude balance bytes.

Configurations left at default keep the automatic flag and carry no
value elements.
This commit is contained in:
TheM14 committed 2026-11-02 17:00:24 +08:00
1 parent 07a26b41fe
commit 220e791ce9
6 files changed
+266 -11

No files matched your search

+18 -1
View File
@@ -3,7 +3,7 @@ import math
from adm_atmos import q_to_adm_xyz
from bed_layout import bed_object_positions
from oamd_bits import JocFieldState, frame_update
from oamd_bits import JocFieldState, frame_update, parse_trim
from variant_error import UnsupportedVariantError
# 元数据更新时刻按渲染器处理块对齐,与 Dolby 的 processing_block_size 及
@@ -192,6 +192,23 @@ def _expand_events(events, total_samples, rate, update_block_samples,
object_delay_samples, object_index)
raise ValueError(f"未知 trajectory_mode: {trajectory_mode}")
def read_atmos_meta(index, frames=None, max_scan=64):
"""从 OAMD payload 读取 trim/warp 配置。
trim element 描述整段节目的校准意图,跨帧恒定,因此扫到第一帧含 trim 的
payload 即可。返回 ``None`` 表示该节目没有 trim element。
"""
rows = index.rows if frames is None else frames
for row in rows[:max_scan]:
subs = index.subpayloads(row)
if not subs or 11 not in subs:
continue
meta = parse_trim(subs[11])
if meta is not None:
return meta
return None
def build_adm_tracks(index, frames=None, rate=48000, frame_samples=1536,
update_block_samples=METADATA_BLOCK_SAMPLES,
object_delay_samples=1473, trajectory_mode="compact"):