Fix JOC passthrough layout and no-previous-state interpolation
Interpolate the second half of a two-data-point frame from dp0 to dp1 when the object has no previous matrix; a single data point keeps the hard cut. Rebuild the passthrough frame as the 8-plane core order L, R, C, LFE, Ls, Rs, (Lrs, Rrs) written to output slots 0..7, all delayed by 1217 samples, and keep that 8-plane history updated on every frame. Frames without JOC metadata always take this passthrough path, and a core channel count change clears the LFE ring while keeping the clipgain ramp state. Reject unsupported downmix configurations with a structured variant error in the metadata scan, and score ID14 payloads by the frame status instead of accepting any lenient parse. Update the math notes and README for the two-data-point interpolation without a previous state and the 8-plane passthrough output.
This commit is contained in:
1 parent
0820444f45
commit
17e52a531c
7 files changed
+68
-34
No files matched your search
+1
-1
@@ -311,7 +311,7 @@ See the [mathematical notes](docs/math.en.md) for the equations used by the deco
|
||||
- All `joc_dmx_config_idx` values 0..4 are covered ($N=5,7,7,5,7$; the phase switch $\sigma(k)$ gates the Ls/Rs $-j$ rotation and the band-0 FIR together). The 7-channel configurations need an 8-channel bed and a dependent-substream `chanmap` to identify the extra pair: a missing independent substream or a missing `chanmap` is still a variant error, while a `chanmap` that disagrees with $k$ about the extra pair, or an OAMD bed mask that does, is recorded as a diagnostic and the frame still renders. The extra pair's **identity** is metadata only and never reaches the DSP (section 10.1); the bed mapping follows the channel codes the `chanmap` declares.
|
||||
- When one audio frame holds several EMDF containers carrying ID11/ID14 (one of them may be something other than the frame's JOC parameters: its ID14 may declare more objects than its bytes can hold, and its ID11 may carry no group id), the container is chosen by the association rule of ETSI TS 103 420 section 8.2 and its Table 56: **the container whose OAMD and JOC payloads share a group id and whose ID14 parses completely** wins, then one whose ID14 merely parses; only a unique best score is used, the others are recorded as a diagnostic (`emdf/extra_container_ignored`), and a tie or all-zero score stays a variant error.
|
||||
- The extra pair's identity follows TS 103 420 Table 47/Table 48 ($k=1\to$Lb/Rb, $k\in\{2,4\}\to$Tfl/Tfr, $N=5,7,7,5,7$); Annex E.3 requires a dependent-substream `chanmap`, when present, to indicate one of the Table 47 configurations, so `*_5_1_2top_*` (chanmap says Lts/Rts) does not satisfy that "shall". Such material is tolerated with a diagnostic instead of being refused.
|
||||
- E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. If an individual audio frame has no JOC EMDF, the implementation falls back to the decode state machine (hold the previous matrices while normal rendering was active, otherwise pass through the core PCM delayed by 1217 samples) and records `joc_frame_missing` in `diagnostics`.
|
||||
- E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. If an individual audio frame has no JOC EMDF, that frame passes the core PCM through (the 8 core planes are written to output slots 0..7 by identity, each delayed by 1217 samples) and records `joc_frame_missing` in `diagnostics`.
|
||||
- The speaker and SOFA binaural paths currently cover ordinary point objects; extent, spread, diffuse, divergence, channel lock, and similar controls are outside the supported scope.
|
||||
- Speaker rendering reads warp, trims and front/back balance from OAMD, with no CLI warp override. Generic rendering parameters support warp 0/1 and modes 2/3, which render to 7.1.x before PLIIx or Standard (Lo/Ro) folding to 5.1.x; calibration always follows the final target layout. Source trajectories and binaural do not bake in these speaker controls; see [mathematics §12](docs/math.en.md) for parameters and evaluation order.
|
||||
- Multi-data-point streams, uncommon band configurations, and unusual OAMD scheduling have less coverage than common 12-band, single-data-point material.
|
||||
|
||||
@@ -273,7 +273,7 @@ JustOneCacophony/
|
||||
- 覆盖 `joc_dmx_config_idx` 0..4 的全部档位($N=5,7,7,5,7$,相位开关 $\sigma(k)$ 同时门控 Ls/Rs 的 $-j$ 旋转与 band-0 FIR)。7 通道档位必须解出 8 通道床,且需要依赖子流的 `chanmap` 才能确定额外那一对:缺少核心子流或缺少 `chanmap` 仍按变体报错;`chanmap` 声明的额外对与 $k$ 不一致、或 OAMD bed 掩码与 $k$ 不一致时,只记入 `diagnostics` 并继续解码——额外那对的**身份**只进元数据、不进 DSP(§10.1),床映射按 `chanmap` 的通道码做。
|
||||
- 同一音频帧里出现多个含 ID11/ID14 的 EMDF 容器时(其中一个容器可能不是本帧的 JOC 参数:ID14 声明的对象数超出其字节所能容纳的范围,ID11 也可能没有 groupid),按 ETSI TS 103 420 §8.2 + Table 56 的关联规则打分选取:**OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析**的容器优先,其次只看 ID14 能否完整解析;只有唯一最高分才采用,其余记入 `diagnostics`(`emdf/extra_container_ignored`),并列或全部为 0 仍报变体。
|
||||
- 额外那一对的身份以 TS 103 420 Table 47/Table 48 为准($k=1\to$Lb/Rb,$k\in\{2,4\}\to$Tfl/Tfr,$N=5,7,7,5,7$);Annex E.3 规定依赖子流的 `chanmap`(若存在)**应**指明 Table 47 的某种配置,因此 `*_5_1_2top_*`(chanmap 写 Lts/Rts)属于不满足 "shall" 的素材,我们按"记诊断 + 继续解码"容错处理。
|
||||
- 不含 JOC 元数据(ID11 + ID14)的 E-AC-3 输入不在支持范围;解码过程中若个别音频帧没有 JOC EMDF,当前实现按状态机兜底(进入该帧前处于正常渲染时保持渲染,否则直通延迟 1217 采样的核心 PCM),并以 `joc_frame_missing` 记入 `diagnostics`。
|
||||
- 不含 JOC 元数据(ID11 + ID14)的 E-AC-3 输入不在支持范围;解码过程中若个别音频帧没有 JOC EMDF,该帧输出核心 PCM 直通(8 路核心按 identity 写入输出槽 0..7,每路延迟 1217 采样),并以 `joc_frame_missing` 记入 `diagnostics`。
|
||||
- 扬声器与 SOFA 双耳路径当前只覆盖普通点对象;extent、spread、diffuse、divergence、channel lock 等对象控制不在支持范围内。
|
||||
- 扬声器渲染从 OAMD 元数据读取 warp、trim 和 front/back balance;命令行不提供 warp 覆盖。通用渲染参数支持 warp 0/1,以及先渲染到 7.1.x 再按 PLIIx 或 Standard(Lo/Ro)折回 5.1.x 的 warp 2/3;校准参数始终按最终目标布局选择。原始对象轨迹与 binaural 不预处理这些扬声器控制,参数和顺序见 [数学说明 §12](docs/math.md)。
|
||||
- 多数据点、少见参数带配置和特殊 OAMD 调度的覆盖度低于常见 12-band、单数据点素材。
|
||||
|
||||
+6
-6
@@ -193,12 +193,10 @@ Thus $p(b)=k$ if and only if $b\in\mathcal B_k$. Other parameter-band counts use
|
||||
### 3.2 One-data-point interpolation
|
||||
|
||||
Let $P_{o,c,b}$ be the previous frame-end value and $D_{o,c,p(b)}$ the current target. When the object
|
||||
has no previous state yet (the first frame of the stream, or the object's first appearance), all 24 slots
|
||||
take the current target directly (hard cut, no fade-in from zero):
|
||||
|
||||
$$
|
||||
M_{o,c,b,t}=D_{o,c,p(b)},\qquad t=0\ldots23.
|
||||
$$
|
||||
has no previous state yet (the first frame of the stream, or the object's first appearance), a single
|
||||
data point keeps all 24 slots at $D_{o,c,p(b)}$ (hard cut, no fade-in from zero); with two data points,
|
||||
the first 12 slots stay at $D_0$ and the last 12 slots still interpolate from $D_0$ to $D_1$ using the
|
||||
second segment of section 3.3 (with $P$ set to $D_0$).
|
||||
|
||||
With a previous state, for slot $t=0\ldots23$:
|
||||
|
||||
@@ -237,6 +235,8 @@ D_{0}, & t=11,\\[1mm]
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
When no previous state exists, the same formulas apply with $P_{o,c,b}$ set to $D_0$.
|
||||
|
||||
Step mode (`slope_idx=1`) switches targets directly at the designated slots: for $t<o_0$ it keeps the
|
||||
previous frame-end value $P_{o,c,b}$ (or $D_0$ when no previous state exists), for $o_0\le t<o_1$ it
|
||||
uses $D_0$, and for $t\ge o_1$ it uses $D_1$; with a single data point it keeps $P$ for $t<o_0$ and uses
|
||||
|
||||
+5
-5
@@ -191,11 +191,9 @@ $$
|
||||
### 3.2 单数据点插值
|
||||
|
||||
令上一帧末值为 $P_{o,c,b}$,当前目标值为 $D_{o,c,p(b)}$。对象没有 previous 状态时
|
||||
(整条流第一帧或对象首次出现),24 个时槽直接取当前目标(硬切,不从零淡入):
|
||||
|
||||
$$
|
||||
M_{o,c,b,t}=D_{o,c,p(b)},\qquad t=0\ldots23.
|
||||
$$
|
||||
(整条流第一帧或对象首次出现):单数据点情形 24 个时槽恒为 $D_{o,c,p(b)}$(硬切,
|
||||
不从零淡入);双数据点情形前 12 个时槽为 $D_0$,后 12 个时槽按 §3.3 的第二段公式
|
||||
从 $D_0$ 插值到 $D_1$(把该节的 $P$ 取为 $D_0$)。
|
||||
|
||||
有 previous 状态时,对时槽 $t=0\ldots23$:
|
||||
|
||||
@@ -232,6 +230,8 @@ D_{0}, & t=11,\\[1mm]
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
没有 previous 状态时同样使用上面的公式,只是把 $P_{o,c,b}$ 取为 $D_0$。
|
||||
|
||||
阶跃模式(`slope_idx=1`)在指定时槽直接切换目标:$t<o_0$ 保持上一帧末值 $P_{o,c,b}$
|
||||
(没有 previous 时取 $D_0$),$o_0\le t<o_1$ 取 $D_0$,$t\ge o_1$ 取 $D_1$;
|
||||
单数据点时 $t<o_0$ 保持 $P$、$t\ge o_0$ 取 $D_0$。
|
||||
|
||||
+10
-3
@@ -37,8 +37,9 @@ def sb_to_pb_table(n_bands):
|
||||
def interp_matrix(obj_info, dq, prev=None, n_ts=24):
|
||||
"""按数据点和跨帧状态插值,返回 ``[channel,subband,timeslot]``。
|
||||
|
||||
``prev`` 是上一帧末时槽的矩阵;``prev`` 为 None 表示该对象还没有历史,
|
||||
此时所有时槽直接使用本帧第一个数据点(硬切,不从零淡入)。
|
||||
``prev`` 是上一帧末时槽的矩阵;``prev`` 为 None 表示该对象还没有历史:
|
||||
单数据点全部取 ``dp0``(硬切);双数据点前一半取 ``dp0``,后一半仍从 ``dp0``
|
||||
插值到 ``dp1``。
|
||||
"""
|
||||
dq_sb = np.asarray(dq, dtype=np.float64)[:, :, sb_to_pb_table(dq.shape[2])]
|
||||
previous = None if prev is None else np.asarray(prev, dtype=np.float64)
|
||||
@@ -46,7 +47,13 @@ def interp_matrix(obj_info, dq, prev=None, n_ts=24):
|
||||
slope = obj_info["slope_idx"]
|
||||
if slope == 0:
|
||||
if previous is None:
|
||||
return np.repeat(dq_sb[0, :, :, None], n_ts, axis=2)
|
||||
if n_dp == 1:
|
||||
return np.repeat(dq_sb[0, :, :, None], n_ts, axis=2)
|
||||
half = n_ts // 2
|
||||
a1 = (np.arange(n_ts - half, dtype=np.float64) + 1.0) / (n_ts - half)
|
||||
first = np.repeat(dq_sb[0, :, :, None], half, axis=2)
|
||||
second = dq_sb[0, :, :, None] * (1.0 - a1) + dq_sb[1, :, :, None] * a1
|
||||
return np.concatenate((first, second), axis=2)
|
||||
if n_dp == 1:
|
||||
alpha = (np.arange(n_ts, dtype=np.float64) + 1.0) / n_ts
|
||||
return previous[:, :, None] * (1.0 - alpha) + dq_sb[0, :, :, None] * alpha
|
||||
|
||||
+11
-3
@@ -30,9 +30,10 @@ def _joc_pair_score(container):
|
||||
payload = container.payloads.get(14)
|
||||
if payload is None or 11 not in container.payloads:
|
||||
return 0
|
||||
parses = True
|
||||
parses = False
|
||||
try:
|
||||
parse_joc(payload)
|
||||
parsed = parse_joc(payload)
|
||||
parses = parsed["status"] not in (2, 4)
|
||||
except (IndexError, ValueError):
|
||||
parses = False
|
||||
group_ids = getattr(container, "group_ids", None) or {}
|
||||
@@ -297,7 +298,14 @@ class DirectPayloadIndex:
|
||||
continue
|
||||
|
||||
if 14 in container.payloads:
|
||||
parsed = parse_joc_header(container.payloads[14])
|
||||
parsed = parse_joc_header(container.payloads[14], strict=False)
|
||||
if parsed["n_channels"] is None:
|
||||
raise UnsupportedVariantError(
|
||||
"joc", "downmix_config_unsupported",
|
||||
"ID14 的 joc_dmx_config_idx 不受支持(合法值 0..4)",
|
||||
frame=frame_number,
|
||||
details={"dmx_config_idx": parsed["dmx_config_idx"],
|
||||
"payload": bytes_descriptor(container.payloads[14])})
|
||||
parsed["payload"] = container.payloads[14]
|
||||
frame_bed = (program_bed_summary(container.payloads[11])
|
||||
if 11 in container.payloads else None)
|
||||
|
||||
+34
-15
@@ -5,9 +5,10 @@
|
||||
→ 对象时域组装(前步、64 点 FFT、旋转、合成窗)→ ×16 + clamp
|
||||
→ LFE 专用 1217-sample 环形延迟(逐点乘 clipgain 斜坡)
|
||||
→ 16ch(ch0 = LFE, ch1-15 = 15 对象)→ ×output_scale
|
||||
无元数据帧改为 8 路核心 PCM identity 直通(槽 0..7,每路延迟 1217),槽 8..15 为零。
|
||||
|
||||
跨帧状态:seq 状态机(state/expected/无效帧计数)、每对象的 prev 矩阵与存在标记、
|
||||
QMF 分析与合成状态、LFE 延迟环、直通渲染的核心 PCM 历史。
|
||||
QMF 分析与合成状态、LFE 延迟环、直通渲染的 8 路核心 PCM 历史。
|
||||
|
||||
output_scale:
|
||||
默认 1.0(0 dB)。用户选择的 dB 在命令行转换为 float32 系数;该系数
|
||||
@@ -24,6 +25,8 @@ CORE_CHANNELS = [0, 1, 2, 4, 5] # L R C Ls Rs(EAC3 5.1 核心顺序)
|
||||
FRAME_SAMPLES = 1536
|
||||
MAX_OBJECTS = 15
|
||||
MAX_CORE_CHANNELS = 7
|
||||
CORE_OUT_CHANNELS = 8
|
||||
LFE_SLOT = 3
|
||||
LFE_DELAY = 1217
|
||||
SEQ_MODULUS = 1024
|
||||
# 没有 JOC 元数据的帧:状态机短路分支使用这个状态码。
|
||||
@@ -59,8 +62,8 @@ class JocRenderer:
|
||||
# 逐点增益斜坡在写入延迟环之前乘上,读出后不再乘任何增益。
|
||||
self._lfe_delay = np.zeros(LFE_DELAY, dtype=np.float64)
|
||||
self._lfe_clipgain = None # LFE 增益斜坡的起点;None = 还没有历史
|
||||
# 直通渲染的核心 PCM 延迟历史:保存上一帧输入。
|
||||
self._core_hist = np.zeros((MAX_CORE_CHANNELS, FRAME_SAMPLES), dtype=np.float64)
|
||||
# 直通渲染的 8 路核心 PCM 延迟历史:保存上一帧输入。
|
||||
self._core_hist = np.zeros((CORE_OUT_CHANNELS, FRAME_SAMPLES), dtype=np.float64)
|
||||
# seq 状态机与逐帧分派所需的跨帧状态。
|
||||
self._state = 0
|
||||
self._expected = 0
|
||||
@@ -150,11 +153,15 @@ class JocRenderer:
|
||||
return
|
||||
self._analysis_fifo[n_channels:] = 0.0
|
||||
self._prev_mtx[:, n_channels:, :] = 0.0
|
||||
self._core_hist[n_channels:] = 0.0
|
||||
if n_channels == 5:
|
||||
# N=5 不用额外那一对,10 时隙延迟线 3、4 号槽不再推进。
|
||||
self._analysis_delay[3:] = 0.0
|
||||
|
||||
def _maybe_clear_lfe_ring(self, status):
|
||||
"""声明声道数与实际核心声道数失配(本帧 status=9)时清空 LFE 环。"""
|
||||
if status == STATUS_CORE_CHANNEL_CHANGE:
|
||||
self._lfe_delay.fill(0.0)
|
||||
|
||||
def _advance_state(self, status, seq):
|
||||
"""按 seq 推进状态机,返回进入本帧前的 ``state``。
|
||||
|
||||
@@ -394,14 +401,24 @@ class JocRenderer:
|
||||
raise ValueError(f"核心帧应为 (5,1536) 或 (7,1536),实际 {pcm.shape}")
|
||||
return pcm
|
||||
|
||||
@staticmethod
|
||||
def _core8(core, lfe):
|
||||
"""JOC 输入序 5/7 路(不含 LFE)→ 8 平面核心序 L,R,C,LFE,Ls,Rs,(Lrs,Rrs)。"""
|
||||
out = np.zeros((CORE_OUT_CHANNELS, FRAME_SAMPLES), dtype=np.float64)
|
||||
out[0:3] = core[0:3]
|
||||
out[LFE_SLOT] = lfe
|
||||
rest = core.shape[0] - 3
|
||||
if rest > 0:
|
||||
out[4:4 + rest] = core[3:]
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def _delayed_core(hist, current):
|
||||
"""直通渲染:把核心 PCM 延迟 1217 个采样(只处理实际有的声道数)。"""
|
||||
n_channels = current.shape[0]
|
||||
out = np.zeros((MAX_CORE_CHANNELS, FRAME_SAMPLES), dtype=np.float64)
|
||||
out[:n_channels, :LFE_DELAY] = hist[:n_channels, 319:]
|
||||
out[:n_channels, LFE_DELAY:] = current[:, :FRAME_SAMPLES - LFE_DELAY]
|
||||
return out[:n_channels]
|
||||
"""直通渲染:8 路核心 PCM 各延迟 1217 个采样。"""
|
||||
out = np.empty((CORE_OUT_CHANNELS, FRAME_SAMPLES), dtype=np.float64)
|
||||
out[:, :LFE_DELAY] = hist[:, FRAME_SAMPLES - LFE_DELAY:]
|
||||
out[:, LFE_DELAY:] = current[:, :FRAME_SAMPLES - LFE_DELAY]
|
||||
return out
|
||||
|
||||
def _render_frame(self, *, status, seq, out, mix_dq, bed_pcm, lfe_pcm,
|
||||
config_idx=None):
|
||||
@@ -410,11 +427,12 @@ class JocRenderer:
|
||||
n_channels = pcm.shape[0]
|
||||
if self._n_channels_prev is not None and n_channels != self._n_channels_prev:
|
||||
self._clear_unused_channels(n_channels)
|
||||
pre_state = self._advance_state(status, seq)
|
||||
self._advance_state(status, seq)
|
||||
state = self._state
|
||||
self._maybe_clear_lfe_ring(status)
|
||||
|
||||
if status == STATUS_NO_METADATA:
|
||||
mode = "hold" if pre_state == 1 else "passthrough"
|
||||
mode = "passthrough"
|
||||
elif state == 4:
|
||||
mode = "hard_cut"
|
||||
elif state in (2, 3):
|
||||
@@ -447,6 +465,7 @@ class JocRenderer:
|
||||
if lfe_pcm is None else np.asarray(lfe_pcm, dtype=np.float64))
|
||||
if lfe.shape != (FRAME_SAMPLES,):
|
||||
raise ValueError(f"LFE 帧应为 (1536,),实际 {lfe.shape}")
|
||||
core8 = self._core8(pcm, lfe)
|
||||
|
||||
x = self.qmf_x(pcm, phase_new=phase_new, apply_dc_filter=sigma, rotate=sigma)
|
||||
self._last_x = x.copy()
|
||||
@@ -475,15 +494,15 @@ class JocRenderer:
|
||||
z_all = self._zero_objects()
|
||||
self.dll_synth_objects(z_all)
|
||||
self.decode_lfe(lfe, clipgain)
|
||||
pcm16[:n_channels] = self._delayed_core(self._core_hist, pcm)
|
||||
pcm16[:CORE_OUT_CHANNELS] = self._delayed_core(self._core_hist, core8)
|
||||
|
||||
self._core_hist[:n_channels] = pcm
|
||||
self._core_hist[:] = core8
|
||||
self._n_channels_prev = n_channels
|
||||
pcm16_f32 = np.asarray(pcm16, dtype=np.float32)
|
||||
return np.multiply(pcm16_f32, self.output_scale, dtype=np.float32), z_all
|
||||
|
||||
def render_missing_frame(self, bed_pcm, lfe_pcm=None, config_idx=3):
|
||||
"""没有 JOC 元数据的音频帧:按状态机结果保持渲染或直通核心 PCM。"""
|
||||
"""没有 JOC 元数据的音频帧:8 路核心 PCM identity 直通(每路延迟 1217 采样)。"""
|
||||
return self._render_frame(status=STATUS_NO_METADATA, seq=None,
|
||||
out=None, mix_dq=None,
|
||||
bed_pcm=bed_pcm, lfe_pcm=lfe_pcm,
|
||||
|
||||
Reference in new issue
Block a user