Place CBA bed channels at the positions their labels define

A bed channel is a fixed source: its PCM is an object at the position its
OAMD speaker label names, so the coordinate comes only from the label
(ETSI TS 103 420 V1.2.1 clause B.2.1.4 table B.10) and never from the
target output layout.

- src/bed_layout.py carries table B.10 for all seventeen labels, including
  Tfl/Tfr at (±1, 1, 1), Tbl/Tbr at (±1, -1, 1) and Lw/Rw at Y = 21/31
  (0,677419); LFE and LFE2 are recorded but stay out of the object slots
- src/speaker_renderer.py sends the bed slots through the same point-source
  path as dynamic objects at those fixed positions; the layout region-0
  anchor lookup is gone, so every layout and the binaural timeline share
  one source position per bed channel
- src/oamd_bits.py expands the 17-bit non-standard bed mask in table 12
  channel order (RC_L first, RC_LFE2 last); both mask expansions are now
  single helpers, standard_bed_channels and nonstandard_bed_channels
- src/metadata.py reports the bed coverage mismatch only when a bed is
  declared, so an object-only program no longer logs it on every frame
- README.md and README.en.md describe bed rendering by channel label
  instead of by output layout

Checked: table B.10 coordinates, table 12/13 channel order and masks,
object slot order, identical source positions across all eleven speaker
layouts plus the binaural timeline and the ADM tracks, and LFE passthrough;
a 180 s 9.1.6 bed stream renders to 25-channel ADM BWF with all fifteen
objects static at those positions.
This commit is contained in:
TheM14 committed 2026-11-01 01:34:05 +08:00
1 parent faf8a921c2
commit 26e84569c2
6 files changed
+71 -93

No files matched your search

+4 -2
View File
@@ -14,8 +14,10 @@ This is research code, not a complete, standards-compliant, or production-grade
- Parse ID14 dense / sparse JOC parameters, Huffman data, differential matrices, and `joc_clipgain`.
- Parse ID11 OAMD position updates and build object trajectories.
- Read the bed layout the OAMD declares (5.1, 7.1, 7.1.2, 7.1.4, 9.1.4, 9.1.6, ...): for
bed-only content the 15 object slots are the bed channels, rendered at that layout's
fixed bed positions.
bed-only content the 15 object slots are the bed channels, each rendered as a point
source at the fixed position its channel label defines (ETSI TS 103 420 table B.10);
speaker and binaural output share those source positions and never re-place them per
layout, while LFE keeps its separate path.
- Reconstruct LFE plus 15 object channels through analysis QMF, parameter interpolation, the object matrix, and inverse QMF.
- Write a 25-channel ADM BWF: a 10-channel 7.1.2 bed (silent except for LFE) plus 15 objects.
- Render directly to `2.0`, `3.1`, `4.0`, `5.1`, `7.1`, `5.1.2`, `5.1.4`, `7.1.2`, `7.1.4`, `9.1.4`
+2 -1
View File
@@ -14,7 +14,8 @@
- 解析 ID14 dense / sparse JOC 参数、Huffman 数据、差分矩阵与 `joc_clipgain`;
- 解析 ID11 OAMD 位置更新并生成对象轨迹;
- 读取 OAMD 声明的 bed 布局(5.1、7.1、7.1.2、7.1.4、9.1.4、9.1.6 等):bed-only 内容的
15 路对象就是 bed 声道,按布局的固定方位渲染;
15 路对象就是 bed 声道,每个声道按其声道标签的固定方位(ETSI TS 103 420 Table B.10)
作为点声源渲染,扬声器与双耳共用同一组源位置,不随输出布局改变;LFE 独立处理;
- 通过 analysis QMF、参数插值、对象矩阵和 inverse QMF 重建 LFE + 15 路对象 PCM;
- 输出 25 声道 ADM BWF:10 声道 7.1.2 bed(除 LFE 外静音)+ 15 个对象;
- 直接渲染 `2.0`、`3.1`、`4.0`、`5.1`、`7.1`、`5.1.2`、`5.1.4`、`7.1.2`、`7.1.4`、`9.1.4`、
+28 -24
View File
@@ -79,27 +79,34 @@ BED_CHANNEL_NAMES = {
"RC_TBL": "Ltr", "RC_TBR": "Rtr", "RC_LW": "Lw", "RC_RW": "Rw",
}
# 每个 bed 声道的固定方位(ADM 笛卡尔坐标,x 向右、y 向前、z 向上)。
# bed 声道是固定位置,不是可移动对象;渲染时按这里的位置摆位,而不是沿用 OAMD 的
# 对象坐标(bed 对象在 OAMD 里没有位置字段)。
# 每个 bed 声道的固定方位(ADM 笛卡尔坐标,x 向右、y 向前、z 向上),取自
# ETSI TS 103 420 V1.2.1 clause B.2.1.4 Table B.10:speakerLabel 各自对应唯一的
# position(X,Y,Z),与目标扬声器布局无关。bed 对象在 OAMD 里没有位置字段,位置只由
# 声明的声道标签决定。
# Table B.10 把 Lw/Rw 的 Y 记作 0,677419,即 ADM 62 级网格上的 42/62 = 21/31。
BED_CHANNEL_ADM_POSITION = {
"RC_L": (-1.0, 1.0, 0.0),
"RC_R": (1.0, 1.0, 0.0),
"RC_C": (0.0, 1.0, 0.0),
"RC_LFE": (-1.0, 1.0, -1.0),
"RC_LS": (-1.0, 0.0, 0.0),
"RC_RS": (1.0, 0.0, 0.0),
"RC_LB": (-1.0, -1.0, 0.0),
"RC_RB": (1.0, -1.0, 0.0),
"RC_LW": (-1.0, 0.5, 0.0),
"RC_RW": (1.0, 0.5, 0.0),
"RC_TFL": (-0.5, 0.5, 1.0),
"RC_TFR": (0.5, 0.5, 1.0),
"RC_TFL": (-1.0, 1.0, 1.0),
"RC_TFR": (1.0, 1.0, 1.0),
"RC_TSL": (-1.0, 0.0, 1.0),
"RC_TSR": (1.0, 0.0, 1.0),
"RC_TBL": (-0.5, -0.5, 1.0),
"RC_TBR": (0.5, -0.5, 1.0),
"RC_TBL": (-1.0, -1.0, 1.0),
"RC_TBR": (1.0, -1.0, 1.0),
"RC_LW": (-1.0, 21.0 / 31.0, 0.0),
"RC_RW": (1.0, 21.0 / 31.0, 0.0),
"RC_LFE2": (1.0, 1.0, -1.0),
}
# LFE 不是空间声源:它的 PCM 走独立通路,不参与对象摆位。
BED_LFE_LABELS = frozenset(("RC_LFE", "RC_LFE2"))
# 标准 bed 布局名:由声明声道的集合唯一确定(9.1.6 这类常用叫法即由此得来)。
BED_LAYOUT_NAMES = {
frozenset(("L", "R")): "2.0",
@@ -139,6 +146,11 @@ def adm_xyz_to_q(x, y, z):
return clamp(q1), clamp(q2), clamp(q3)
def adm_xyz_to_render_coordinates(x, y, z):
"""ADM 笛卡尔坐标 → 渲染器方位 ``(u, v, w)``(u 向右、v 向后、w 向上,0..1)。"""
return ((float(x) + 1.0) * 0.5, (1.0 - float(y)) * 0.5, float(z))
def declared_bed_channels(assignments):
"""把 ``program_assignment()`` 的 bed 声明展开成有序的标准声道标签。
@@ -173,7 +185,7 @@ def bed_layout(assignments):
labels = declared_bed_channels(assignments)
if not labels:
return None
channels = [label for label in labels if label not in ("RC_LFE", "RC_LFE2")]
channels = [label for label in labels if label not in BED_LFE_LABELS]
return {
"name": bed_layout_name(labels),
"labels": list(labels),
@@ -184,31 +196,23 @@ def bed_layout(assignments):
def bed_object_positions(labels):
"""JOC 对象槽 → 固定 ADM 位置:(1..15) 对应未含 LFE 的 bed 声道。
bed 对象在 OAMD 里没有位置字段,位置由声明的 bed 布局决定。返回的字典只包含
能给出固定位置的标准声道;不是 bed 声道的对象不在其中,仍按 OAMD 坐标渲染。
positions 由声道标签唯一决定(Table B.10),与目标输出布局无关——同一个 bed 声道
在扬声器布局和双耳渲染里都落在同一个源位置。返回的字典只包含能给出固定位置的
标准声道;不是 bed 声道的对象不在其中,仍按 OAMD 坐标渲染。LFE 走独立通路,
不出现在对象槽里。
"""
positions = {}
for index, label in enumerate(labels, 1):
if index > 15:
break
if label in BED_LFE_LABELS:
continue
position = BED_CHANNEL_ADM_POSITION.get(label)
if position is not None:
positions[index] = position
return positions
def bed_object_names(labels):
"""JOC 对象槽 → 扬声器布局短名(用于把 bed 声道直接落到同名扬声器)。"""
names = {}
for index, label in enumerate(labels, 1):
if index > 15:
break
name = BED_CHANNEL_NAMES.get(label)
if name is not None and name != "LFE":
names[index] = name
return names
def joc_input_indices(locations, pair):
"""返回 JOC 输入序 (L, R, C, Ls, Rs, 额外对…) 在床 PCM 里的下标。"""
if pair is None:
+3 -2
View File
@@ -163,7 +163,8 @@ def check_cross_layer(parsed, *, frame, transport=None, bed_channels=None, bed_l
"子流声明的全频段通道数与 joc_dmx_config_idx 不一致",
frame=frame, details=details)
if bed_channels is not None:
# 没有 bed 声明(空列表)时这项不适用:动态对象 program 没有 bed 槽位可记录。
if bed_channels:
core_positions = []
if transport is not None:
core_positions = list(transport["core_locations"])
@@ -208,7 +209,7 @@ class DirectPayloadIndex:
self.diagnostics = diagnostics if diagnostics is not None else []
self.config_idx = config_idx
self.n_channels = n_channels
# OAMD bed 声明(内容声床布局):bed 对象没有位置字段,位置由布局决定。
# OAMD bed 声明(内容声床布局):bed 对象没有位置字段,位置由声道标签决定。
self.bed_assignments = bed_assignments if bed_assignments is not None else []
self.bed_layout = bed_layout(self.bed_assignments)
self.bed_only = bool(bed_only)
+26 -13
View File
@@ -20,20 +20,39 @@ RAMP_DURATION_INDEX = (
OBJECT_ELEMENT_ID = 1
# 5.6.0.11 Table 11b:ISF 类型 → 对象数。
ISF_OBJECT_COUNTS = (4, 8, 10, 14, 15, 30)
# 5.6.1.1.4 Table 12:10 bit 标准 bed 掩码按位对应的声道(LSB = RC_L/RC_R)。
# 5.6.1.1.4 Table 12:10 bit 标准 bed 掩码。array position 9(RC_L/RC_R)是 channel
# order 的第一项,字段按 array position 0→9 逐位传输,读成整数后 position 9 落在 LSB,
# 因此按 LSB→MSB 展开即得 channel order:(L,R), C, LFE, (Ls,Rs), … , LFE2。
BED_CHANNEL_LABELS = (
"RC_L/RC_R", "RC_C", "RC_LFE", "RC_LS/RC_RS", "RC_LB/RC_RB",
"RC_TFL/RC_TFR", "RC_TSL/RC_TSR", "RC_TBL/RC_TBR", "RC_LW/RC_RW", "RC_LFE2",
)
# 5.6.1.1.5 Table 13:17 bit 非标准 bed 掩码按位对应的声道标签。
# 5.6.1.1.5 Table 13:17 bit 非标准 bed 掩码,同样按 channel order 排列(RC_L 最先,
# 对应 array position 16 = LSB)。
NONSTD_BED_LABELS = (
"RC_LFE2", "RC_RW", "RC_LW", "RC_TBR", "RC_TBL", "RC_TSR", "RC_TSL",
"RC_TFR", "RC_TFL", "RC_RB", "RC_LB", "RC_RS", "RC_LS", "RC_LFE", "RC_C",
"RC_R", "RC_L",
"RC_L", "RC_R", "RC_C", "RC_LFE", "RC_LS", "RC_RS", "RC_LB", "RC_RB",
"RC_TFL", "RC_TFR", "RC_TSL", "RC_TSR", "RC_TBL", "RC_TBR", "RC_LW", "RC_RW",
"RC_LFE2",
)
MAX_SLOTS = 16
def standard_bed_channels(bed_mask):
"""5.6.1.1.4:标准 bed 掩码 → 按 channel order 排列的声道标签(LFE 留在原位)。"""
channels = []
for bit, labels in enumerate(BED_CHANNEL_LABELS):
if (int(bed_mask) >> bit) & 1:
channels.extend(labels.split("/"))
return channels
def nonstandard_bed_channels(bed_mask):
"""5.6.1.1.5:非标准 bed 掩码 → 按 channel order 排列的声道标签。"""
mask = int(bed_mask)
return [label for bit, label in enumerate(NONSTD_BED_LABELS)
if (mask >> bit) & 1]
def q_of(k, n):
q = int(np.floor(32768.0 * k / n + 0.5))
return min(32767, q)
@@ -181,21 +200,15 @@ def _parse_program_assignment(reader, raw_payload):
continue
if reader.read(1): # b_standard_chan_assign
bed_mask = reader.read(10)
channels = []
for bit in range(10):
if (bed_mask >> bit) & 1:
channels.extend(BED_CHANNEL_LABELS[bit].split("/"))
program["bed_assignments"].append({
"instance": instance, "lfe_only": False, "standard": True,
"mask": bed_mask, "channels": channels,
"mask": bed_mask, "channels": standard_bed_channels(bed_mask),
})
else:
bed_mask = reader.read(17)
channels = [NONSTD_BED_LABELS[bit]
for bit in range(17) if (bed_mask >> bit) & 1]
program["bed_assignments"].append({
"instance": instance, "lfe_only": False, "standard": False,
"mask": bed_mask, "channels": channels,
"mask": bed_mask, "channels": nonstandard_bed_channels(bed_mask),
})
program["num_bed_objects"] = sum(
len(assignment["channels"]) for assignment in program["bed_assignments"])
+8 -51
View File
@@ -19,61 +19,18 @@ Q15_SCALE = 32768.0
Q15_MAX = 32767.0 / Q15_SCALE
GAIN_SNAP_THRESHOLD = 1.0e-4
# 每个布局 region 0 控制点 → 该点上唯一响应的声道。床声道用这个锚点直接落到目标
# 布局的同名扬声器上(床声道是一路固定通道,不是需要声像的对象)。
_ANCHOR_CACHE: dict[str, dict[str, tuple[float, float, float]]] = {}
def layout_channel_anchors(layout: SpeakerLayout) -> dict[str, tuple[float, float, float]]:
"""返回 ``{声道名: (u, v, w)}``:把点对象放在这里时该声道增益为 1。
坐标取自布局自己的 region 0 控制点,因此锚点与布局的声像模型一致;目标布局没
有的声道不会出现在结果里。
"""
cached = _ANCHOR_CACHE.get(layout.name)
if cached is not None:
return cached
anchors: dict[str, tuple[float, float, float]] = {}
region = layout.regions[0]
for coordinates in region.coordinates_q15:
u, v, w = (coordinate / 32767.0 for coordinate in coordinates)
gains = render_point_gains(layout, u, v, w, standard_order=True)
best = int(np.argmax(gains))
dominant = float(gains[best])
if dominant < 0.99:
continue
others = np.delete(gains, best)
if others.size and float(np.max(np.abs(others))) > 1.0e-3:
continue
anchors.setdefault(layout.channels[best], (u, v, w))
_ANCHOR_CACHE[layout.name] = anchors
return anchors
def bed_object_anchors(layout: SpeakerLayout, bed_channels) -> dict[int, tuple[float, float, float]]:
def bed_object_targets(bed_channels) -> dict[int, tuple[float, float, float]]:
"""JOC 对象槽 → 固定方位 ``(u, v, w)``;只包含 bed 声道。
目标布局有同名扬声器时用该扬声器的锚点(床声道直连同名声道);目标布局没有这
个声道时退回 bed 布局给出的标准方位,由声像模型摆位。
bed 声道的方位由声道标签定义(ETSI TS 103 420 Table B.10),与目标扬声器布局
无关:同一个声道无论输出哪种布局都落在同一个源位置,再交给与动态对象相同的
点声源渲染路径。LFE 不占对象槽,单独处理。
"""
from bed_layout import BED_CHANNEL_ADM_POSITION, BED_CHANNEL_NAMES
from bed_layout import adm_xyz_to_render_coordinates, bed_object_positions
anchors = layout_channel_anchors(layout)
result: dict[int, tuple[float, float, float]] = {}
for object_index, label in enumerate(bed_channels or (), 1):
if object_index > 15:
break
name = BED_CHANNEL_NAMES.get(label)
if name is None or name == "LFE":
continue
if name in anchors:
result[object_index] = anchors[name]
continue
position = BED_CHANNEL_ADM_POSITION.get(label)
if position is not None:
x, y, z = position
result[object_index] = ((x + 1.0) * 0.5, (1.0 - y) * 0.5, z)
return result
return {slot: adm_xyz_to_render_coordinates(*xyz)
for slot, xyz in bed_object_positions(bed_channels or ()).items()}
def _all_object_targets(layout: SpeakerLayout, state: JocFieldState,
@@ -258,7 +215,7 @@ class PythonSpeakerRenderer:
self.block_size = int(block_size)
if self.block_size <= 0:
raise ValueError("block_size must be positive")
self.bed_targets = bed_object_anchors(self.layout, bed_channels)
self.bed_targets = bed_object_targets(bed_channels)
self.reset()
def reset(self):