# JustOneCacophony — E-AC-3 JOC decoding and rendering mathematics [中文](math.md) · [Back to README](../README.en.md) This document covers only the signal model and formulas used in the JustOneCacophony research path: how JOC parameters combine with core PCM to reconstruct object signals, and how OAMD coordinates become speaker gains. The formulas describe the JOC matrix parameters (both the dense and the sparse differential syntax) and the ordinary point-object paths studied by the project. They are not a complete definition of every E-AC-3 JOC variant. ## 1. Overall path and notation Object reconstruction: ```text E-AC-3 core 5.1 PCM + ID14 JOC matrix parameters → analysis QMF → parameter-band expansion and time interpolation → object matrix → inverse QMF → LFE + 15 object PCM channels ``` Speaker rendering: ```text LFE + 15 object PCM channels + ID11 OAMD coordinates and update timing → target-layout region → equal-power panning → position compensation → sample-wise gain ramp → speaker PCM ``` Main notation: | Symbol | Meaning | |---|---| | $c=0\ldots4$ | core channels L, R, C, Ls, Rs | | $o=0\ldots14$ | 15 JOC objects | | $b=0\ldots63$ | complex QMF subbands | | $t=0\ldots23$ | 24 64-sample slots per frame | | $p(b)$ | JOC parameter band corresponding to QMF subband $b$ | | $X_{c,b,t}$ | analysis-QMF value for a core channel | | $M_{o,c,b,t}$ | object-matrix coefficient | | $Z_{o,b,t}$ | inverse-QMF input for an object | | $y_o[n]$ | time-domain object PCM | The number of samples in one frame is $$ N_f=1536=24\times64. $$ ## 2. JOC matrix parameters For every object and data point, the quantized matrix `joc_mix_mtx_q` is defined on $N_q$ quantization levels. The `b_joc_sparse` flag selects one of two differential syntaxes: dense sends one MTX difference per core channel, while sparse sends one active channel plus one coefficient difference per parameter band. ### 2.1 Dense differential reconstruction Let `quant_idx` be $q_i\in\{0,1\}$. The number of quantization levels is $$ N_q= \begin{cases} 96, & q_i=0,\\ 192, & q_i=1. \end{cases} $$ The center offset is $$ O_q=\frac{N_q}{2}. $$ For object $o$, data point $d$, core channel $c$, and parameter band $p$, the coded difference $\Delta_{o,d,c,p}$ reconstructs to $$ Q_{o,d,c,0}= \left(O_q+\Delta_{o,d,c,0}\right)\bmod N_q, $$ $$ Q_{o,d,c,p}= \left(Q_{o,d,c,p-1}+\Delta_{o,d,c,p}\right)\bmod N_q, \qquad p>0. $$ ### 2.2 Sparse differential reconstruction Let $I_{o,d,p}$ be the `joc_channel_idx` symbol (IDX), $V_{o,d,p}$ the `joc_vec` symbol (VEC), and $N_c\in\lbrace5,7\rbrace$ the number of core channels. Each parameter band has exactly one active channel: $$ A_{o,d,p}= \begin{cases} I_{o,d,0}, & p=0,\\ \left(A_{o,d,p-1}+I_{o,d,p}\right)\bmod N_c, & p>0, \end{cases} $$ where $I_{o,d,0}$ is a 3-bit absolute channel index and every later IDX symbol is an increment relative to the previous **active channel**. The coefficient is a single accumulator running across parameter bands: $$ \kappa_{o,d,-1}=O^{(s)}_q,\qquad \kappa_{o,d,p}= \left(\kappa_{o,d,p-1}+V_{o,d,p}\right)\bmod N_q, $$ with a sparse starting point two quantization levels above the dense center offset: $$ O^{(s)}_q= \begin{cases} 50, & q_i=0,\\ 100, & q_i=1. \end{cases} $$ The accumulator is **not** reset when the active channel changes. The complete matrix is $$ Q_{o,d,c,p}= \begin{cases} \kappa_{o,d,p}, & c=A_{o,d,p},\\ \dfrac{N_q}{2}, & c\neq A_{o,d,p}. \end{cases} $$ Non-active entries take $N_q/2$, which dequantizes to exactly 0. ### 2.3 Dequantization The dequantized matrix coefficient is $$ D_{o,d,c,p}= \left(Q_{o,d,c,p}-\frac{N_q}{2}\right) \frac{820}{4096(1+q_i)}. $$ The effective denominator is therefore 4096 in coarse mode and 8192 in fine mode. ### 2.4 JOC clipgain If the clipgain field consists of integer $x$ and mantissa $y$, then $$ G_{\mathrm{clip}}= 2^{x-4}\left(1+\frac{y}{32}\right). $$ 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 ### 3.1 Parameter bands to QMF subbands The JOC matrix is coded in parameter bands, while the QMF contains 64 subbands. Let $p(b)$ identify the parameter band containing subband $b$. A parameter-band coefficient expands as $$ D_{o,d,c,b}=D_{o,d,c,p(b)}. $$ The common 12-band mapping is $$ \begin{aligned} \mathcal B_0 &= \{0\}, & \mathcal B_1 &= \{1\}, & \mathcal B_2 &= \{2\}, & \mathcal B_3 &= \{3\},\\ \mathcal B_4 &= \{4,5\}, & \mathcal B_5 &= \{6,7\}, & \mathcal B_6 &= \{8,9,10\}, & \mathcal B_7 &= \{11,12,13\},\\ \mathcal B_8 &= \{14,15,16,17\}, & \mathcal B_9 &= \{18,\ldots,22\},\\ \mathcal B_{10} &= \{23,\ldots,34\}, & \mathcal B_{11} &= \{35,\ldots,63\}. \end{aligned} $$ Thus $p(b)=k$ if and only if $b\in\mathcal B_k$. Other parameter-band counts use their corresponding subband boundaries. ### 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. $$ With a previous state, for slot $t=0\ldots23$: $$ \alpha_t=\frac{t+1}{24}, $$ $$ M_{o,c,b,t}= (1-\alpha_t)P_{o,c,b} +\alpha_tD_{o,c,p(b)}. $$ The first slot has therefore advanced by $1/24$ of the ramp, while the last slot equals the current target: $$ M_{o,c,b,23}=D_{o,c,p(b)}. $$ 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 `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 $t0$ and the band-0 21-tap complex FIR are gated by the **same switch** $\sigma(k)=1\iff k\in\{3,4\}$: $$ \widehat X_{c,b,t}= \begin{cases} -j\,X_{c,b,t-10}, & \sigma(k)=1,\ c\in\{Ls,Rs\},\ b>0,\\[1mm] \sum_{m=0}^{20}h_mX_{c,0,t-m}, & \sigma(k)=1,\ c\in\{Ls,Rs\},\ b=0,\\[1mm] X_{c,b,t-10}, & \text{otherwise}. \end{cases} $$ For $N=7$ the sixth and seventh core channels (Lb/Rb or Tfl/Tfr) behave like the front channels and only take the ten-slot delay: channel identity affects metadata and rendering, not the DSP. These delays and filter histories are decoder state and cannot be reset independently for every frame. ## 6. Object matrix For each object $o$, subband $b$, and slot $t$, the object's frequency-domain value is a linear combination of the $N$ core channels: $$ Z_{o,b,t}= \sum_{c=0}^{N-1} M_{o,c,b,t}\widehat X_{c,b,t}. $$ The $1/16$ analysis-input scale is canceled by the $\times16$ factor after inverse QMF, so the matrix itself needs no additional empirical gain. ## 7. Object inverse QMF ### 7.1 Subband reorder Write the 64 complex subbands as 128 interleaved real values in `src`. For $k=0\ldots31$: $$ \begin{aligned} \mathrm{zone}[2k] &= \mathrm{src}[4k],\\ \mathrm{zone}[2k+1] &= -\mathrm{src}[4k+1],\\ \mathrm{zone}[126-2k] &= \mathrm{src}[4k+2],\\ \mathrm{zone}[127-2k] &= \mathrm{src}[4k+3]. \end{aligned} $$ Treat `zone` as 64 complex values and apply an unnormalized 64-point FFT: $$ F_k= \sum_{n=0}^{63} \mathrm{zone}_n \exp\left(-j\frac{2\pi kn}{64}\right). $$ ### 7.2 Modulation and synthesis Define the rotation coefficient $$ r_k= \frac12\left( \sin\frac{\pi k}{128} +j\cos\frac{\pi k}{128} \right), $$ and compute $$ R_k=2F_kr_k. $$ Let $\mathcal S$ denote polyphase synthesis with a 640-value synthesis window and cross-slot state: $$ \mathbf y_{o,t}= \mathcal S\left( \mathbf R_{o,t},W,\mathbf s^{\mathrm S}_{o,t} \right). $$ Object output is $$ y_o[64t+r]= \mathrm{clip}\left( 16\,\mathbf y_{o,t}[r],-1,1 \right)G_{\mathrm{clip}}, $$ where $r=0\ldots63$. Synthesis state must advance continuously by slot. ## 8. LFE path 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]\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 $$ q_N(k)= \min\left( 32767, \left\lfloor\frac{32768k}{N}+\frac12\right\rfloor \right). $$ OAR coordinates are $$ u=\frac{q_1}{32768}, \qquad v=\frac{q_2}{32768}, \qquad w=\frac{q_3}{32768}. $$ Their maximum runtime value is $32767/32768$, not exactly 1. For conversion to the ADM grid: $$ k_1=\mathrm{round}\left(\frac{62q_1}{32767}\right), \quad k_2=\mathrm{round}\left(\frac{62q_2}{32767}\right), \quad k_3=\mathrm{round}\left(\frac{15q_3}{32767}\right), $$ $$ X=2\frac{k_1}{62}-1, \qquad Y=1-2\frac{k_2}{62}, \qquad Z=\frac{k_3}{15}. $$ The continuous-coordinate relation is $$ u=\frac{X+1}{2}, \qquad v=\frac{1-Y}{2}, \qquad w=Z. $$ ## 10. Equal-power speaker panning ### 10.1 One-dimensional interpolation Let adjacent speaker coordinates be $a_00,\\[2pt] (1-s)(y-0.5)+0.5+0.45s, & 0.5\le y<0.95,\ b>0,\\[2pt] (1-s)y+0.05s, & 0.05