Fix JOC clipgain, offset_ts, frame status, and renderer state machine

Decode clipgain multiplicatively as 2^(x-4)*(1 + y/32), keep the raw
5-bit offset_ts values and reject frames whose offsets leave 0..23 or are
not strictly increasing, and read the EMDF sample offset as
variable_bits(11). Report parse errors through the frame status: 2
unsupported downmix configuration, 3 object count clamped, 4 parameter
band index, 5 invalid offset_ts, 6 trailing data after byte padding.
Correct the 15/9/5/3 subband-to-parameter-band rows.

Apply the clipgain ramp to the LFE samples before the 1217-sample delay,
stop fading objects in from zero when they have no previous matrix, and
keep disappeared objects published with an all-zero matrix until they
reappear.

Render each frame through the seq state machine: hold the previous
matrices while the decoder is unsynchronized, hard cut on seq 0 or a core
channel count change, and pass the delayed core PCM through when no JOC
metadata is present. Keep the 16-channel output as LFE + 15 objects so
CBA bed channels stay on the fixed-position object path that the ADM,
speaker, and binaural backends already consume.

Update the math notes and README for the multiplicative clipgain, the
no-previous-state interpolation, the LFE gain ramp, and the frame-level
decoding behavior. State that E-AC-3 input without JOC metadata is
outside the supported scope.
This commit is contained in:
TheM14 committed 2026-11-06 11:35:59 +08:00
1 parent 4aef8db36e
commit 0820444f45
8 files changed
+469 -138

No files matched your search

+46 -12
View File
@@ -147,15 +147,17 @@ If the clipgain field consists of integer $x$ and mantissa $y$, then
$$
G_{\mathrm{clip}}=
1+\frac{y}{32}2^{x-4}.
2^{x-4}\left(1+\frac{y}{32}\right).
$$
It is folded into the analysis-side scalar $S=\frac{1}{16}G_{\mathrm{clip}}$, which multiplies
every core-bed sample before the QMF analysis; the $\times16$ after the object inverse QMF cancels the
$1/16$, so the net effect is a multiply by $G_{\mathrm{clip}}$ and the $[-1,1]$ clamp sits **after** the
gain. The scalar keeps two per-frame slots: the first 256 samples of a frame ramp linearly from the
previous frame's value to this frame's value and the rest stays constant, and the first frame after a
reset takes the new value directly. LFE bypasses this scalar.
Its range is $[0.0625,15.75]$; at $x=4$ it reduces to $1+y/32$. It is folded into the analysis-side
scalar $S=\frac{1}{16}G_{\mathrm{clip}}$, which multiplies every core-bed sample before the QMF
analysis; the $\times16$ after the object inverse QMF cancels the $1/16$, so the net effect is a multiply
by $G_{\mathrm{clip}}$ and the $[-1,1]$ clamp sits **after** the gain. The scalar keeps two per-frame
slots: the first 256 samples of a frame ramp linearly from the previous frame's value to this frame's
value and the rest stays constant, and the first frame after a reset takes the new value directly. LFE
uses a separate path but applies the same full $G_{\mathrm{clip}}$ as a sample-wise ramp before its
1217-sample delay; see section 8.
## 3. Parameter-band expansion and time interpolation
@@ -190,7 +192,15 @@ 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. For slot $t=0\ldots23$:
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.
$$
With a previous state, for slot $t=0\ldots23$:
$$
\alpha_t=\frac{t+1}{24},
@@ -208,11 +218,29 @@ $$
M_{o,c,b,23}=D_{o,c,p(b)}.
$$
This value then becomes the previous state for the next frame.
This value then becomes the previous state for the next frame. Once an object's present flag goes from 1
to 0, it keeps being published with an all-zero matrix and its previous state is updated to zero until it
becomes present again.
### 3.3 Multiple data points
When a frame contains two data points, `offset_ts` gives the segment boundary. Each segment uses the same linear relation between the previous and next targets; step mode switches targets at the designated slot.
`offset_ts` gives the first slot at which each data point becomes active, using the raw 5-bit value
(legal range $0\ldots23$); the values of one object must be strictly increasing. In the default mode
(`slope_idx=0`), two data points $D_0$ and $D_1$ interpolate as
$$
M_{o,c,b,t}=
\begin{cases}
(1-\alpha_t)P_{o,c,b}+\alpha_tD_{0}, & t=0\ldots10,\ \alpha_t=\dfrac{t+1}{12},\\[1mm]
D_{0}, & t=11,\\[1mm]
(1-\beta_t)D_{0}+\beta_tD_{1}, & t=12\ldots23,\ \beta_t=\dfrac{t-11}{12}.
\end{cases}
$$
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
$D_0$ from $o_0$ on.
## 4. Analysis QMF for core PCM
@@ -337,15 +365,21 @@ where $r=0\ldots63$. Synthesis state must advance continuously by slot.
## 8. LFE path
LFE bypasses the object matrix and inverse QMF and uses a 1217-sample delay. After the input and output scale factors cancel:
LFE bypasses the object matrix and inverse QMF. The core LFE samples are first multiplied by the
sample-wise gain ramp $G[n]$ (the same full $G_{\mathrm{clip}}$ as section 2.4: for $n<256$,
$G[n]=G_{\mathrm{old}}+n(G_{\mathrm{new}}-G_{\mathrm{old}})/256$; for $n\ge256$, $G[n]=G_{\mathrm{new}}$;
on the first frame or after a reset, $G_{\mathrm{old}}=G_{\mathrm{new}}$). The scaled samples then
enter the 1217-sample delay, and the read-out is only clamped, with no further gain:
$$
y_{\mathrm{LFE}}[n]=
\mathrm{clip}\left(
x_{\mathrm{LFE,core}}[n-1217],-1,1
x_{\mathrm{LFE,core}}[n-1217]\cdot G[n-1217],-1,1
\right).
$$
Here $G[k]$ uses the frame-local position of input sample $k$, i.e. $k\bmod1536$.
## 9. OAMD coordinates
The lateral and longitudinal grids use $N=62$; the height grid uses $N=15$. The quantizer is
+37 -8
View File
@@ -147,13 +147,15 @@ $$
$$
G_{\mathrm{clip}}=
1+\frac{y}{32}2^{x-4}.
2^{x-4}\left(1+\frac{y}{32}\right).
$$
它并入分析端标量 $S=\frac{1}{16}G_{\mathrm{clip}}$,乘在核心 bed 的每个采样上(QMF 分析之前);
值域为 $[0.0625,15.75]$;$x=4$ 时化为 $1+y/32$。它并入分析端标量
$S=\frac{1}{16}G_{\mathrm{clip}}$,乘在核心 bed 的每个采样上(QMF 分析之前);
对象 inverse QMF 之后的 $\times16$ 抵消 $1/16$,净效果是乘 $G_{\mathrm{clip}}$,因此钳位 $[-1,1]$
处在增益**之后**。标量按帧保留两个槽,本帧前 256 个采样从上一帧值线性过渡到本帧值、之后为常数,
复位后的第一帧直接取新值。LFE 走旁通通路,不参与该标量。
复位后的第一帧直接取新值。LFE 走独立通路,但使用同一个完整 $G_{\mathrm{clip}}$ 的逐点斜坡:
斜坡在进入 1217-sample 延迟之前乘到 LFE 采样上,见 §8。
## 3. 参数带展开与时间插值
@@ -188,7 +190,14 @@ $$
### 3.2 单数据点插值
令上一帧末值为 $P_{o,c,b}$,当前目标值为 $D_{o,c,p(b)}$。对时槽 $t=0\ldots23$:
令上一帧末值为 $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.
$$
有 previous 状态时,对时槽 $t=0\ldots23$:
$$
\alpha_t=\frac{t+1}{24},
@@ -206,11 +215,26 @@ $$
M_{o,c,b,23}=D_{o,c,p(b)}.
$$
该值随后成为下一帧的 previous 状态。
该值随后成为下一帧的 previous 状态。对象 present 由 1 变 0 后,从该帧起继续按全零矩阵发布,
并把 previous 更新为零矩阵,直到它重新 present=1。
### 3.3 多数据点
当一帧含两个数据点时,`offset_ts` 给出分段边界。每一段在上一目标和下一目标之间使用相同的线性关系;阶跃模式则在指定时槽直接切换目标。
`offset_ts` 给出各数据点开始生效的时隙序号,取原始 5 bit 值(合法范围 $0\ldots23$);
同一对象的数据点必须严格递增。默认模式(`slope_idx=0`)下,两个数据点 $D_0,D_1$ 的插值为
$$
M_{o,c,b,t}=
\begin{cases}
(1-\alpha_t)P_{o,c,b}+\alpha_tD_{0}, & t=0\ldots10,\ \alpha_t=\dfrac{t+1}{12},\\[1mm]
D_{0}, & t=11,\\[1mm]
(1-\beta_t)D_{0}+\beta_tD_{1}, & t=12\ldots23,\ \beta_t=\dfrac{t-11}{12}.
\end{cases}
$$
阶跃模式(`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$。
## 4. 核心 PCM 的 analysis QMF
@@ -334,15 +358,20 @@ $$
## 8. LFE 路径
LFE 不经过对象矩阵或 inverse QMF,而是使用 1217-sample 延迟。输入与输出端的比例因子抵消后:
LFE 不经过对象矩阵或 inverse QMF。核心 LFE 先乘逐点增益斜坡 $G[n]$(与 §2.4 同一个完整
$G_{\mathrm{clip}}$:$n<256$ 时 $G[n]=G_{\mathrm{old}}+n(G_{\mathrm{new}}-G_{\mathrm{old}})/256$,
$n\ge256$ 时 $G[n]=G_{\mathrm{new}}$,首帧或复位后 $G_{\mathrm{old}}=G_{\mathrm{new}}$),
再进入 1217-sample 延迟;读出后只做钳位,不再乘任何增益:
$$
y_{\mathrm{LFE}}[n]=
\mathrm{clip}\left(
x_{\mathrm{LFE,core}}[n-1217],-1,1
x_{\mathrm{LFE,core}}[n-1217]\cdot G[n-1217],-1,1
\right).
$$
其中 $G[k]$ 取输入采样 $k$ 所在帧内的位置,即 $k\bmod1536$。
## 9. OAMD 坐标
横向和纵向网格使用 $N=62$,高度网格使用 $N=15$。量化函数为