Port the OAMD metadata rendering and the frame-level JOC core
ci / ubuntu-latest (push) Failing after 19s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s

The JOC bitstream reports a per-frame parse status instead of treating every
anomaly as an exception: an unsupported downmix configuration, a clamped
object count, an unknown parameter-band count, bad offset_ts values and
trailing bytes each get their own status. The raw 5-bit offset_ts values are
kept as coded and validated to be strictly increasing per object, and the
clipgain uses 2^(x-4) * (1 + y/32).

The JOC core gains a frame-level state machine. It keeps the per-object
previous matrix and its presence marker, the seq counter, the 8-plane
passthrough history, the LFE clipgain ramp start and the previous actual
core-channel count. Normal, hold, hard-cut and passthrough frames are
distinguished: a frame without a previous state interpolates per the
data-point rules, an object that disappears keeps publishing a zero matrix,
a frame without metadata passes the 8 core planes through to slots 0..7 with
the 1217-sample delay, and a declared core-channel-count change hard-cuts and
clears the LFE ring while the clipgain ramp state is kept. The core LFE
applies the full clipgain as a sample-wise ramp before its delay.

The OAMD parser exposes the full frame state: every object's state in every
position block, the programme assignment and the trim element, with multiple
blocks and up to 30 declared objects accepted. The speaker renderer applies
this state: per-block gain/inactive, zone/elevation, the size kernel, snap,
divergence, element 5 refinement, the priority size budget, ISF basis
matrices and bed channel distribution, scheduled on the 32-sample metadata
grid with block alignment and gain ramps. The size kernel, ISF basis
assembly, bed routing and compensation are computed in oamd_math from the
speaker layout geometry; bed labels and reference positions derive from the
layout tables. The six ISF configurations and twelve layout descriptors are
compiled in as static tables (oamd/isf_tables.h); the JSON loader and the
configure-time embedding are gone. The layout tables gain 6.0, and the layout
lookup, bed map and trim probe follow.

The binaural position timeline consumes the full frame state as well: every
position block is scheduled at its own offset and ramp, and its track list
grows with the declared object count, so multi-block and over-16-object
programmes are rendered instead of rejected. The JOC binaural input stays one
LFE plus fifteen object sources; the extra tracks are followed but not
panned.

The file task and the stream parse the full state for speaker and binaural,
while the ADM export keeps the 15-track single-block view. The public headers
carry the new status values, the frame-level entry point and the raw offset_ts
description; the internal ABI versions go to 6 (joc_core), 2 (frame params and
EMDF info) and 4 (eac3joc).

ctest covers the frame-level core (clipgain formula and LFE ramp, offset_ts
validation, frame statuses, the 8-plane passthrough, the seq state machine and
the no-previous-state interpolation), the OAMD parser state, the compiled-in
ISF tables and the binaural timeline. The READMEs and the mathematical notes
describe the 6.0 layout, the frame state machine, the metadata application and
the ISF lookup tables.
This commit is contained in:
TheM14 committed 2026-11-08 14:04:21 +08:00
1 parent a2760286b0
commit 0bb82e4115
41 files changed
+8182 -678

No files matched your search

+23 -5
View File
@@ -81,11 +81,13 @@ if(MSVC AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_CL_SHOWINCLUDES_PREFIX
"messages in the language CMake probes for.")
endif()
# Verbatim copies of the upstream native library; see THIRD_PARTY_NOTICES.md.
# These files are never edited: they are the validated DSP kernels.
# Sources copied verbatim from the upstream native library; see
# THIRD_PARTY_NOTICES.md. binaural_renderer.cpp is still an unmodified copy and
# is never edited; the unchanged reused headers include/eac3joc_core.h and
# src/joc_bitstream/joc_huffman_tables.h belong to the same set. The JOC core,
# the speaker renderer and the remaining tables started as copies and are
# maintained in-tree now, so they are listed as internal sources below.
set(JOC_REUSED_SOURCES
src/joc_core/eac3joc_core.cpp
src/speaker/speaker_renderer.cpp
src/binaural/binaural_renderer.cpp
)
@@ -119,8 +121,12 @@ set(JOC_INTERNAL_SOURCES
src/io/zip_reader.cpp
src/joc_bitstream/bed_layout_map.cpp
src/joc_bitstream/joc_parser.cpp
src/joc_core/eac3joc_core.cpp
src/joc_core/objects16.cpp
src/oamd/oamd_math.cpp
src/oamd/oamd_params.cpp
src/oamd/oamd_parser.cpp
src/speaker/speaker_renderer.cpp
src/speaker/speaker_layout_lookup.cpp
src/speaker/speaker_step.cpp
src/speaker/speaker_trim.cpp
@@ -236,6 +242,12 @@ if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS)
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src"
)
target_link_libraries(joc_core_impl PUBLIC Threads::Threads)
# The same sources back both the shared library and this static archive. In
# the archive the C entry points are plain definitions: EJOC_STATIC stops the
# kernel sources that carry their own EJOC_BUILD_DLL define from marking them
# as dllexports, which would collide with the DLL import library in a link
# that uses both libraries (the tests do).
target_compile_definitions(joc_core_impl PUBLIC EJOC_STATIC)
endif()
add_library(joc_core SHARED
@@ -291,6 +303,10 @@ if(JOC_BUILD_TESTS)
target_link_libraries(joc_rosella_filterbank_tests PRIVATE joc_core_impl)
target_include_directories(joc_rosella_filterbank_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
add_test(NAME rosella_filterbank COMMAND joc_rosella_filterbank_tests)
add_executable(joc_oamd_metadata_tests tests/test_oamd_metadata.cpp)
target_link_libraries(joc_oamd_metadata_tests PRIVATE joc_core_impl)
target_include_directories(joc_oamd_metadata_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
add_test(NAME oamd_metadata COMMAND joc_oamd_metadata_tests)
# The public headers must stay valid C and C++: these targets exist to prove it.
add_library(joc_headers_c OBJECT tests/test_headers.c)
target_include_directories(joc_headers_c PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
@@ -317,7 +333,8 @@ if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS)
list(APPEND JOC_MSVC_TARGETS joc_core_impl)
endif()
if(JOC_BUILD_TESTS)
list(APPEND JOC_MSVC_TARGETS joc_tests joc_rosella_filterbank_tests joc_headers_c joc_headers_cpp)
list(APPEND JOC_MSVC_TARGETS joc_tests joc_rosella_filterbank_tests
joc_oamd_metadata_tests joc_headers_c joc_headers_cpp)
endif()
if(JOC_BUILD_DEVTOOLS)
endif()
@@ -358,6 +375,7 @@ target_sources(joc_core PRIVATE
include/eac3joc_core.h
src/joc_bitstream/joc_huffman_tables.h
src/joc_core/qmf_tables.h
src/oamd/oamd_parser.h
src/speaker/speaker_layouts.h
)
+80 -12
View File
@@ -113,7 +113,7 @@ This build adds `--bed` (pre-decoded
## Speaker layouts and channel order
`--speaker-layout` accepts the eleven layouts below, and the PCM/WAV channel order is the order in
`--speaker-layout` accepts the twelve layouts below, and the PCM/WAV channel order is the order in
the table:
| Layout | Channel order |
@@ -122,6 +122,7 @@ the table:
| 3.1 | L, R, C, LFE |
| 4.0 | L, R, Lrs, Rrs |
| 5.1 | L, R, C, LFE, Ls, Rs |
| 6.0 | L, R, Ls, Rs, Lrs, Rrs |
| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs |
| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm |
| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr |
@@ -140,7 +141,7 @@ into mask-bit order. Players, ASIO, DAWs and other devices have to map the chann
themselves; this project guarantees the content and numbering of each PCM channel, not that a
downstream player recognises Dolby speaker positions on its own.
`--speaker-layout` accepts only the eleven names in the table; anything else fails as an unknown
`--speaker-layout` accepts only the twelve names in the table; anything else fails as an unknown
layout.
Speaker rendering reads warp, trim and front/back balance from the OAMD metadata; the CLI has no
@@ -149,6 +150,18 @@ then fold back to 5.1.x with PLIIx or Standard (Lo/Ro) coefficients, and calibra
follows the final target layout. Source trajectories and binaural rendering do not pre-apply
these controls; see [mathematics §12](docs/math.en.md) for the parameters and evaluation order.
Speaker rendering also applies the OAMD object attributes: per-block gain/inactive,
zone/elevation, size/snap/divergence, the priority size budget, element 5 position
refinement, ISF basis matrices, and bed distribution. ADM export and the binaural
paths still place point objects and do not apply these speaker target coefficients.
Object position updates are scheduled from the complete `frame_state`: speaker and
binaural rendering both accept multiple position blocks and programmes with more than
16 objects and schedule every block at its own time and ramp. The binaural audio input
is still one LFE plus fifteen object sources; the extra position tracks are followed
but not panned. ADM export keeps the 15-track single-block position view and rejects
anything larger as an unsupported variant.
## Library integration
The engine and the file task are exposed by `joc_core.h`: `joc_task_validate` /
@@ -191,18 +204,49 @@ tests/ unit tests (CTest, self-contained, no external data)
docs/ mathematics, the binaural rendering flow and SIMD dispatch
```
Eight files under `src/` are byte-identical copies of the upstream JustOneCacophony
native library and are never edited (see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)).
The QMF and binaural tables and the JOC Huffman tables under `src/` are written from
publicly documented standards; [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) records
their sources.
The ISF compressed base coefficients and layout descriptors are obtained from
lookup tables stored in the generated header (`src/oamd/isf_tables.h`), which is
compiled into the binary with the code, so nothing reads a data file at run
time. Gain, size, priority, position, divergence, delta and refinement values are
computed in code, while the size kernel is generated from the speaker layout
region geometry and bed routing is derived from those layouts.
## Mathematical implementation
The main documented stages are:
- dense JOC differential reconstruction and dequantization;
- parameter-band mapping to 64 QMF subbands;
- cross-frame parameter interpolation (hard cut when no previous state exists, zero-matrix publishing after an object disappears);
- the frame-level JOC state machine (normal, hold, hard cut, core passthrough);
- analysis/inverse QMF, surround delay, and FIR state;
- the 1217-sample LFE delay with its sample-wise clipgain ramp;
- OAMD Q15 coordinate conversion;
- equal-power panning over target-layout regions;
- OAMD metadata application (per-block gain and inactive, zone/elevation, size kernel, snap, divergence, position refinement, priority size budget, ISF matrices, bed distribution);
- layout-dependent position compensation and sample-wise gain ramps;
- float32 and PCM24 output quantization;
- Rosella and compiled `.jochrtf` binaural rendering, with exactly-once delay/phase and special LFE.
See the [mathematical notes](docs/math.en.md) for the equations used by the decoding
and rendering process.
## Compatibility note
### How `joc_clipgain` is applied
`joc_clipgain` is folded into the **analysis-side scalar**: `scalar = 1/16 x g` (`g = 1 + (y/32)·2^(x-4)`,
from the 8-bit field `x:3 | y:5`). The x16 at the output cancels the 1/16, so the net effect is a multiply
by `g` and the clamp therefore sits **after** the gain (`clamp(16·IQMF·g_interp)`). The scalar is kept in
two per-frame slots: the first 256 samples of a frame ramp linearly from the previous value, the rest stays
constant, and the first frame after a reset takes the new value directly. For `g = 1` the interpolation is the identity and `clamp(x)·1 == clamp(x·1)`.
`joc_clipgain` is folded into the **analysis-side scalar**: `scalar = 1/16 x g`, with
`g = 2^(x-4)·(1 + y/32)` from the 8-bit field `x:3 | y:5`; the range is 0.0625..15.75. The x16 at the
output cancels the 1/16, so the net effect is a multiply by `g` and the clamp therefore sits **after**
the gain (`clamp(16·IQMF·g_interp)`). The scalar is kept in two per-frame slots: the first 256 samples
of a frame ramp linearly from the previous value, the rest stays constant, and the first frame after a
reset takes the new value directly. For `g = 1` the interpolation is the identity and
`clamp(x)·1 == clamp(x·1)`. LFE bypasses the analysis but applies the same full `g` as a sample-wise
ramp before its 1217-sample delay.
`object_delay_samples` defaults to **1473**, preserving the behaviour of the existing
implementation; it is a configurable field and changing it changes the OAMD/ADM time
@@ -239,9 +283,33 @@ only a unique best score is used and the others are recorded as a diagnostic
$k\in\{2,4\}\to8/9$) is recorded, but bed channels are not output channels under the current
contract.
An audio frame with no JOC EMDF at all (for example when the encoder wrote none for the first
frame) emits silent object channels while the QMF analysis and synthesis state keep advancing,
and it is counted separately in the statistics.
### Frame status and the JOC decode state machine
Every frame carries a status; a non-zero status is reported as a diagnostic. A non-zero status
makes the frame invalid for rendering, so the renderer holds the previous matrices or passes the
core PCM through instead of decoding that frame's matrix: 2 unsupported downmix configuration,
3 object count clamped to 15, 4 unknown parameter-band index, 5 invalid `offset_ts`, and 6
trailing data after byte padding. A file task refuses a `joc_dmx_config_idx` outside 0..4
earlier, in the metadata scan, as an unsupported variant. Status 3 still yields the clamped
object list for diagnostics, while status 2 and 4 stop the parse at the failing header field.
Rendering then runs a per-frame state machine: normal, hold, hard cut, and core passthrough. An
unusable-JOC frame that arrives during normal rendering enters hold, where the previous frame-end
matrices keep being published; six consecutive unusable frames move the internal hold state on but
stay in hold, and a valid frame resynchronises the sequence number. A sequence number of 0 after
the renderer left its initial state, a sequence mismatch, or a change of the declared core channel
count is a hard cut: every object matrix is zeroed and each object's previous state becomes
the zero matrix, while a core channel count change also clears the LFE delay ring but keeps
the clipgain ramp state. Before the first valid frame the renderer passes the core PCM
through.
A frame with no JOC EMDF at all (for example when the encoder wrote none for the first frame)
always takes the passthrough path: the eight core planes L, R, C, LFE, Ls, Rs, (Lrs, Rrs) are
written to output slots 0..7 by identity, each delayed by 1217 samples, slots 8..15 stay zero,
and the 8-plane history keeps advancing. Those frames are counted separately in the statistics,
and E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. While hold or
passthrough runs without fresh parameters, the analysis scalar and the LFE ramp keep the
currently held clipgain.
## License
+58 -9
View File
@@ -99,7 +99,7 @@ joc_cli input.eac3 --metadata-only --print-metadata summary # 只解析并打
## 扬声器布局与声道顺序
`--speaker-layout` 只接受下表 11 个布局,PCM/WAV 的声道顺序就是表里的顺序:
`--speaker-layout` 只接受下表 12 个布局,PCM/WAV 的声道顺序就是表里的顺序:
| 布局 | 声道顺序 |
|---|---|
@@ -107,6 +107,7 @@ joc_cli input.eac3 --metadata-only --print-metadata summary # 只解析并打
| 3.1 | L, R, C, LFE |
| 4.0 | L, R, Lrs, Rrs |
| 5.1 | L, R, C, LFE, Ls, Rs |
| 6.0 | L, R, Ls, Rs, Lrs, Rrs |
| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs |
| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm |
| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr |
@@ -122,13 +123,21 @@ joc_cli input.eac3 --metadata-only --print-metadata summary # 只解析并打
PCM 声道顺序严格按上表,不按掩码位序重排。播放器、ASIO、DAW 或其他设备需要按声道编号自行完成
输出映射;本项目保证各 PCM 声道的内容和编号符合上表,不保证下游播放器自动识别杜比扬声器位置。
`--speaker-layout` 只接受上表 11 个名字;其它名字按未知布局报错。
`--speaker-layout` 只接受上表 12 个名字;其它名字按未知布局报错。
扬声器渲染从 OAMD 元数据读取 warp、trim 和 front/back balance;命令行不提供 warp 覆盖。
warp 0/1 直接渲染;warp 2/3 先渲染到 7.1.x 中间布局,再按 PLIIx 或 Standard(Lo/Ro)
折回 5.1.x,校准参数始终按最终目标布局选择。原始对象轨迹与双耳渲染不预处理这些控制,
参数与求值顺序见[数学说明 §12](docs/math.md)。
扬声器渲染还会应用 OAMD 的对象属性:每块增益/inactive、zone/elevation、size/snap/divergence、
priority 尺寸预算、element 5 位置细化、ISF 基矩阵和 bed distribute。ADM 导出与双耳路径仍按点
对象放置,不应用这些扬声器目标系数。
对象位置的调度按完整 `frame_state` 进行:扬声器与双耳渲染都接受多 position block 和超过 16
个对象的节目,按各块的时间与 ramp 逐个调度;双耳渲染的音频输入仍是 1 LFE + 15 对象,多出的
位置轨道只跟踪不参与声像。ADM 导出仍使用 15 轨、单 block 的对象位置视图,超出时按变体报错。
## 库集成
引擎与文件任务使用 `joc_core.h`:`joc_task_validate` / `joc_task_execute` 跑一个文件任务并
@@ -164,17 +173,41 @@ tests/ 单元测试(CTest,自足,不需要外部素材)
docs/ 数学说明、双耳渲染流程与 SIMD 派发
```
`src/` 下 8 个文件是 JustOneCacophony 原生库的逐字节副本,永不修改(见
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md))。
`src/` 下的 QMF/双耳表与 JOC Huffman 表按公开标准实现;来源记录见
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
ISF 压缩基系数与布局描述以查表方式提供:表数据写在生成头文件 `src/oamd/isf_tables.h` 中,
与代码一起编译进二进制,运行时不读取数据文件。gain、size、priority、位置、divergence
与差分/细化值都在代码中计算,size 核由扬声器布局的 region 几何生成,bed 路由由布局表推导。
## 数学实现
主要文档化阶段:
- dense JOC 差分还原与去量化;
- 参数带到 64 个 QMF 子带的映射;
- 跨帧参数插值(无上一帧时硬切,对象消失后按零矩阵发布);
- 帧级 JOC 状态机(正常 / 保持 / 硬切 / 核心直通);
- analysis / inverse QMF、环绕声道延迟与 FIR 状态;
- LFE 1217-sample 延迟与逐点 clipgain 斜坡;
- OAMD Q15 坐标转换;
- 基于目标布局 region 的等功率声像;
- OAMD 元数据应用(每块增益与 inactive、zone/elevation、size 核、snap、divergence、位置细化、priority 尺寸预算、ISF 矩阵、bed 分配);
- 布局位置补偿与逐样本增益斜坡;
- float32 与 PCM24 输出量化;
- Rosella 与编译好的 `.jochrtf` 双耳渲染,含 exactly-once delay/phase 与 special LFE。
解码与渲染所用的公式见[数学说明](docs/math.md)。
## 兼容性说明
### `joc_clipgain` 的施加方式
`joc_clipgain` 在**分析端**并入分析标量:`标量 = 1/16 × g`(`g = 1 + (y/32)·2^(x−4)`,8 bit 字段
`x:3 | y:5`)。出口的 ×16 抵消 1/16,净效果是 `×g`,因此 clamp 处在增益**之后**
`joc_clipgain` 在**分析端**并入分析标量:`标量 = 1/16 × g`(`g = 2^(x−4)·(1 + y/32)`,8 bit 字段
`x:3 | y:5`,值域 0.0625..15.75)。出口的 ×16 抵消 1/16,净效果是 `×g`,因此 clamp 处在增益**之后**
(`clamp(16·IQMF·g_interp)`)。标量按帧保存在两个槽里:本帧前 256 个采样从上一帧值线性过渡、之后为
常数,复位后的第一帧直接取新值。`g = 1` 时插值恒等,且 `clamp(x)·1 == clamp(x·1)`。
常数,复位后的第一帧直接取新值。`g = 1` 时插值恒等,且 `clamp(x)·1 == clamp(x·1)`。LFE 走独立
通路,但使用同一个完整 `g` 的逐点斜坡,并乘在 1217-sample 延迟之前。
`object_delay_samples` 默认 **1473**,与既有实现的行为保持一致;它是可配置字段,改动它会
改变 OAMD/ADM 时间对齐。上游调查认为该值应为 0,本项目为保持逐字节等价暂不改默认值。
@@ -202,8 +235,24 @@ OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只
其余记入 diagnostics(`emdf/extra_container_ignored`)。额外那一对在 10 槽 ADM 骨架上的落位
($k=1\to6/7$、$k\in\{2,4\}\to8/9$)会被记录,但床通道按现行契约不作为输出通道。
音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧的对象通道静音,
QMF 分析与合成状态照常推进,并在统计里单独计数。
### 帧状态与 JOC 解码状态机
每个帧都带一个状态,非零状态按诊断报告。非零状态使该帧不能用于渲染,渲染器因此保持上一帧矩阵或输出
核心 PCM 直通,而不还原该帧的矩阵:2 不支持的下混配置,3 对象数截断到 15,4 未知参数带索引,
5 非法 `offset_ts`,6 字节对齐后存在尾随数据。文件任务对 `joc_dmx_config_idx` 超出 0..4 的
输入更早在元数据扫描阶段按不支持变体拒绝。状态 3 仍给出截断后的对象列表(供诊断),状态 2、4
在出错的头字段处停止解析。
渲染随后按帧级状态机运行:正常、保持、硬切、核心直通。正常渲染期间出现 JOC 参数不可用的帧时
进入保持,继续发布上一帧末的矩阵;连续六个不可用帧只把内部保持状态推进一档、仍保持;出现有效
帧后重新对齐序号。渲染器离开初始状态后序号回到 0、序号不匹配、或声明的核心声道数变化都
触发硬切:所有对象矩阵清零、每个对象的 previous 状态置零,核心声道数变化还清空 LFE 延迟环
但保留 clipgain 斜坡状态。首个有效帧之前,渲染器输出核心 PCM 直通。
音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧一律走直通路径:8 路核心平面
L、R、C、LFE、Ls、Rs、(Lrs, Rrs) 按 identity 写入输出槽 0..7,每路延迟 1217 采样,槽 8..15
保持零,8 平面历史照常推进。这类帧在统计里单独计数;不含 JOC 元数据(ID11 + ID14)的 E-AC-3
输入不在支持范围。保持或直通期间没有新参数时,分析标量与 LFE 斜坡沿用当前保持的 clipgain。
## 许可
+6 -8
View File
@@ -26,7 +26,7 @@ performs no parsing or conversion of measurement data formats.
```powershell
joc_cli input.m4a --binaural `
--compiled-hrtf-cache path\to\subject.jochrtf `
--kernels data\rosella_kernels.npz `
--kernels path\to\rosella_kernels.npz `
--binaural-mode mid --binaural-tail-seconds 5.0
```
@@ -95,8 +95,8 @@ compiler does not sample 77 FFT bins. Defaults are `1e-3` projection ridge and
`1e-5` SH ridge. Coincident directions are merged before a spherical-Voronoi
weighted ridge fit.
The fixed resource is `data/rosella_kernels.npz`, which implements publicly
standardized filter banks, computable from the following formulas.
The fixed tables implement publicly standardized filter banks, compile into the
sources, and are computable from the following formulas.
The hybrid analysis kernels are defined in [3GPP TS 26.405 / ETSI TS 126 405](https://www.etsi.org/deliver/etsi_ts/126400_126499/126405/06.00.00_60/ts_126405v060000p.pdf),
Section 5.2.2 (Table 1 $Q=8$/
@@ -125,11 +125,9 @@ $8+4+4$ child partition):
$$Y_p = \sum_{q\in C_p}\Bigl(\mathrm{Re}X_q + j\,s_q\,\mathrm{Im}X_q\Bigr),\qquad s_q\in\{\pm1\}$$
The loader verifies the archive and every array by SHA-256; the table version,
all array hashes, and the 77 reference band-center values are part of the cache
key. Public availability of a standard does not by itself grant permission to
practice related patent claims. See
[`data/README.en.md`](../data/README.en.md) and
The tables are fixed at compile time, so no external archive is loaded and
nothing enters a cache key at run time. Public availability of a standard does
not by itself grant permission to practice related patent claims. See
[`THIRD_PARTY_NOTICES.md`](../THIRD_PARTY_NOTICES.md) for the sources and the
rights boundary.
+4 -5
View File
@@ -24,7 +24,7 @@ cache,不是交换格式。
```powershell
joc_cli input.m4a --binaural `
--compiled-hrtf-cache path\to\subject.jochrtf `
--kernels data\rosella_kernels.npz `
--kernels path\to\rosella_kernels.npz `
--jochrtf-room on `
--binaural-mode mid --binaural-tail-seconds 5.0
joc_cli input.m4a --binaural --personalized-headphone HRTF\binaural.personalized_headphone
@@ -78,7 +78,7 @@ joc_cli input.m4a --binaural --personalized-headphone HRTF\binaural.personalized
ridge 为 `1e-3`,SH ridge 为 `1e-5`。同方向 measurement 先合并,再用球面 Voronoi
面积权重做 ridge fit。
固定表位于 `data/rosella_kernels.npz`,实现公开标准化的滤波器组,各表可由如下
固定表按公开标准化的滤波器组实现并编译进源码,各表可由如下
公式计算。
hybrid 分析核定义于 [3GPP TS 26.405 / ETSI TS 126 405](https://www.etsi.org/deliver/etsi_ts/126400_126499/126405/06.00.00_60/ts_126405v060000p.pdf)
@@ -106,9 +106,8 @@ $8+4+4$ 子带划分):
$$Y_p = \sum_{q\in C_p}\Bigl(\mathrm{Re}X_q + j\,s_q\,\mathrm{Im}X_q\Bigr),\qquad s_q\in\{\pm1\}$$
loader 校验 archive 和每个数组的 SHA-256;table version、所有数组 hash 与
77 个 band-center 参考值都属于 cache key。标准可公开获取不等于获准实施相关
专利;更多来源信息见 [`data/README.md`](../data/README.md) 与
固定表在编译期确定,运行时不加载外部 archive,也不参与缓存键。标准可公开
获取不等于获准实施相关专利;来源与权利边界见
[`THIRD_PARTY_NOTICES.md`](../THIRD_PARTY_NOTICES.md)。
## `.jochrtf`
+95 -13
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,13 @@ 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), 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$:
$$
\alpha_t=\frac{t+1}{24},
@@ -208,11 +216,31 @@ $$
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}
$$
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
$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
@@ -358,7 +392,7 @@ q_N(k)=
\right).
$$
OAR coordinates are
The normalized room coordinates are
$$
u=\frac{q_1}{32768},
@@ -800,3 +834,51 @@ $$
- Multiple OAMD position blocks must be scheduled in time order.
- A limiter is separate post-processing and is not included in the mixing equations above.
- Trim and front-back balance affect speaker rendering only; binaural rendering does not read them.
## 16. OAMD metadata application (speaker path)
When mapping object PCM to the target layout, speaker rendering applies the OAMD
object attributes in addition to the geometric panning:
- per-block integer gain `Qg` (unity 4096) and `inactive`; the gain is applied to
the target coefficients once, and the LFE uses its owning metadata object's
gain/active state;
- full basic/render status 0/1/2/3 block expansion, same-object previous-block
inheritance, and local mask updates;
- `zone_constraints_idx` region selection mapped through `[0,1,2,3,4,5,6,0]`;
`enable_elevation=0` forces z=0 before position compensation and size spread;
- `object_size_idx` 5-bit sizes, the `size_curve` piecewise mapping, and the size
kernel; the kernel is generated at runtime from region geometry with
equal-power grouped panning, the S448 weight and a power sum (20/20/8
virtual points, 20 size nodes, 35/4 position nodes; boundary rows
X(0), X(1), Y(0), Y(1), Z(1));
- `snap` first-argmax speaker snapping, `divergence` left/right point-source
combination, and element 5 high-precision position refinement;
- `default_priority`/`priority_bits` choose which size objects keep their size
when the size budget is limited;
- `isf_idx` basis matrices (signed coefficients, no per-column normalization)
with the per-basis compensation;
- `b_bed_chan_distribute` label candidates, weight normalization, missing-channel
fallback, and the direct/distribute compensation.
The ISF path orders the N ISF object audio essences into the column vector t
according to the M.U.L.Z order of `isf_config`, selects the input configuration
by `isf_idx` and the matrix M for the target output layout, and evaluates
y = M·t: each ISF channel is distributed over the speakers by the corresponding
matrix row, LFE bypasses the matrix, and each basis carries its own
compensation. The matrix coefficients and layout descriptors are obtained from
lookup tables stored in the compiled-in `src/oamd/isf_tables.h`; nothing reads a
data file at run time.
Gain, size, priority, position, divergence, delta and refinement values are
computed in code (`src/oamd/oamd_parser.*`) from formulas or fixed constants; the
size kernel (`src/oamd/oamd_math.*`) is generated at runtime from region geometry
with grouped equal-power panning, the S448 weight and a power sum. Bed labels,
routing and reference positions are derived from the speaker layout tables
(`src/speaker/speaker_layouts.h`) by
`src/joc_bitstream/bed_layout_map.{h,cpp}`.
ADM export and the binaural paths still use object positions only and do not apply
these speaker target coefficients. The binaural path schedules positions from the
complete `frame_state`: multiple position blocks and programmes with more than 16
objects are scheduled block by block at their own time and ramp, and its position
track list is not limited to 16; ADM export keeps the 15-track single-block view.
+73 -9
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,12 @@ $$
### 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 个时槽恒为 $D_{o,c,p(b)}$(硬切,
不从零淡入);双数据点情形前 12 个时槽为 $D_0$,后 12 个时槽按 §3.3 的第二段公式
从 $D_0$ 插值到 $D_1$(把该节的 $P$ 取为 $D_0$)。
有 previous 状态时,对时槽 $t=0\ldots23$:
$$
\alpha_t=\frac{t+1}{24},
@@ -206,11 +213,28 @@ $$
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}
$$
没有 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$。
## 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$。量化函数为
@@ -355,7 +384,7 @@ q_N(k)=
\right).
$$
OAR 坐标为
归一化房间坐标为
$$
u=\frac{q_1}{32768},
@@ -774,3 +803,38 @@ $$
- 多个 OAMD position block 必须按其时间顺序调度。
- limiter 属于独立后处理,不包含在上述混音公式中。
- trim 与前后平衡只作用于扬声器渲染;双耳渲染不读取它们。
## 16. OAMD 元数据应用(扬声器路径)
扬声器渲染把对象 PCM 映射到目标布局时,除几何声像外还应用 OAMD 的对象属性:
- 每块整数增益 `Qg`(单位增益 4096)与 `inactive`;增益在生成目标系数时乘一次,
LFE 使用所属元数据对象的增益/活动状态;
- basic/render 状态 0/1/2/3 的完整块展开、同对象前一块继承与局部 mask 更新;
- `zone_constraints_idx` 选择区域,映射为 `[0,1,2,3,4,5,6,0]`;`enable_elevation=0`
在位置补偿和尺寸扩散前令 z=0;
- `object_size_idx` 的 5 bit 尺寸、`size_curve` 分段线性映射与尺寸扩散核;
尺寸核按分组等功率声像、S448 权重和幂和,在运行时用区域几何生成:
20/20/8 个虚拟点、20 个尺寸节点、35/4 个位置节点,边界表为
X(0)、X(1)、Y(0)、Y(1)、Z(1);
- `snap` 的首个最大系数扬声器吸附、`divergence` 的左右两点合成、
element 5 的高精度位置补充;
- `default_priority`/`priority_bits` 在 size 数量预算不足时决定保留尺寸的对象;
- `isf_idx` 的 ISF 基矩阵(可含负系数,不做逐列归一化)与逐 basis 补偿;
- `b_bed_chan_distribute` 的 bed 标签候选筛选、权重归一化、缺失声道 fallback 和
直达/distribute 的补偿。
ISF 路径把 N 路 ISF object audio essences 按 `isf_config` 的 M.U.L.Z 顺序组成
列向量 t,按 `isf_idx` 选输入配置、按目标输出布局选矩阵 M,再计算 y = M·t:
每个 ISF 声道按矩阵对应的一行分配到目标扬声器,LFE 不参与矩阵、直接旁路,
每个 basis 另有补偿。矩阵系数与布局描述通过查表获得,表数据写在编译进源码的
`src/oamd/isf_tables.h` 中,运行时不读取数据文件。
gain、size、priority、位置、divergence 与差分/细化值由 `src/oamd/oamd_parser.*`
按公式或固定常量计算,size 扩散核由 `src/oamd/oamd_math.*` 从区域几何生成
(分组等功率声像 + S448 权重 + 幂和)。bed 标签、路由和参考位置由
`src/joc_bitstream/bed_layout_map.*` 从 `src/speaker/speaker_layouts.h` 的布局表
推导。
ADM 导出与双耳路径仍只使用对象位置,不应用这些扬声器目标系数。双耳路径按完整
`frame_state` 调度位置:多 position block 与超过 16 个对象的节目都按各块的时间与 ramp
逐个调度,双耳位置轨道数不限于 16;ADM 导出保持 15 轨单 block 视图。
+75 -1
View File
@@ -23,13 +23,15 @@ extern "C" {
#endif
enum {
EJOC_ABI_VERSION = 3,
EJOC_ABI_VERSION = 4,
EJOC_FRAME_SAMPLES = 1536,
EJOC_TIMESLOTS = 24,
EJOC_SUBBANDS = 64,
EJOC_CORE_CHANNELS = 5, /* downmix configurations 0 and 3 */
EJOC_MAX_CORE_CHANNELS = 7, /* downmix configurations 1, 2 and 4 */
EJOC_OUTPUT_CHANNELS = 16,
EJOC_CORE_OUT_CHANNELS = 8, /* passthrough order: L,R,C,LFE,Ls,Rs,(Lrs,Rrs) */
EJOC_LFE_SLOT = 3, /* LFE slot of the passthrough order */
EJOC_MAX_OBJECTS = 15,
EJOC_MAX_DPOINTS = 2,
EJOC_MAX_PARAMETER_BANDS = 23,
@@ -43,6 +45,21 @@ enum {
EJOC_BINAURAL_HYBRID_BANDS = 77
};
/* Per-frame status of ejoc_renderer_render_frame(). A status outside 0..6 is
* the renderer's own no-metadata marker; the parse-status values match
* joc_frame_params.status (JOC_FRAME_STATUS_* in joc_core.h). Any non-zero
* status makes the frame invalid for matrix rendering: the renderer holds the
* previous matrices or passes the core PCM through instead of decoding it. */
enum {
EJOC_FRAME_STATUS_OK = 0,
EJOC_FRAME_STATUS_UNSUPPORTED_DMX = 2,
EJOC_FRAME_STATUS_OBJECTS_CLAMPED = 3,
EJOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4,
EJOC_FRAME_STATUS_BAD_OFFSET_TS = 5,
EJOC_FRAME_STATUS_TRAILING_DATA = 6,
EJOC_FRAME_STATUS_NO_METADATA = 8
};
typedef void* ejoc_renderer_handle;
typedef void* ejoc_speaker_renderer_handle;
typedef void* ejoc_binaural_renderer_handle;
@@ -103,6 +120,63 @@ EJOC_API int EJOC_CALL ejoc_renderer_process(
float output_scale,
float* output16_planar);
/*
Frame-level entry point: one E-AC-3 audio frame per call, with the seq state
machine and the per-object previous-matrix state kept inside the renderer. This
is what produces the 16-channel object result for the ADM, speaker and binaural
backends; ejoc_renderer_process() stays as a single-frame kernel for A/B tests.
Fixed array layouts, identical to ejoc_renderer_process():
bed_planar [core_channel_count][1536] (JOC lane order L,R,C,Ls,Rs,(pair))
lfe [1536] or NULL (zeros; the LFE delay ring still advances)
n_bands, n_dpoints, slope_idx [15]
offset_ts [15][2] (raw 5-bit JOC offsets, 0..23)
dq [15][2][7][23]
output16 [16][1536] (ch0 = LFE, ch1..15 = objects)
frame_status is a JOC_FRAME_STATUS_* / EJOC_FRAME_STATUS_* value. has_metadata
is 0 for an audio frame without a JOC EMDF container (frame_status must then be
EJOC_FRAME_STATUS_NO_METADATA); such a frame always passes the 8 core planes
through to output slots 0..7, delayed by 1217 samples, with slots 8..15 zero.
declared_core_channels is the JOC header's n_channels (0 when unknown); a declared
change against the previous frame's actual count turns the frame into a hard cut
with the LFE ring cleared. phase_shift is sigma(k) = (k in {3,4}) for the frame's
downmix configuration; phase_shift_valid = 0 keeps the previous switch (an
unsupported downmix configuration has no usable one). clipgain is the frame's
joc_clipgain when frame_status == 0. seq is the 10-bit JOC sequence counter.
When has_metadata is 0 the object descriptors are ignored.
Slot 0 of output16 is the LFE, slots 1..15 are the 15 objects; each frame's
values are float32(clamped PCM) * output_scale, exactly like the reference.
*/
typedef struct ejoc_frame_input {
uint32_t struct_size;
uint32_t struct_version;
const float* bed_planar;
const float* lfe;
uint32_t core_channel_count;
uint32_t declared_core_channels;
uint32_t phase_shift;
uint32_t phase_shift_valid;
uint32_t frame_status;
uint32_t seq;
uint32_t has_metadata;
uint32_t object_mask;
const uint8_t* n_bands;
const uint8_t* n_dpoints;
const uint8_t* slope_idx;
const uint8_t* offset_ts;
const double* dq;
double clipgain;
float output_scale;
float* output16_planar;
} ejoc_frame_input;
enum { EJOC_FRAME_INPUT_VERSION = 1 };
EJOC_API int EJOC_CALL ejoc_renderer_render_frame(ejoc_renderer_handle handle,
const ejoc_frame_input* input);
/*
High-precision object-to-speaker renderer.
+25 -8
View File
@@ -36,9 +36,9 @@
#include "joc_version.h"
#define JOC_ABI_VERSION 5u
#define JOC_FRAME_PARAMS_VERSION 1u
#define JOC_EMDF_INFO_VERSION 1u
#define JOC_ABI_VERSION 6u
#define JOC_FRAME_PARAMS_VERSION 2u
#define JOC_EMDF_INFO_VERSION 2u
#define JOC_TASK_CONFIG_VERSION 4u
#define JOC_TASK_RESULT_VERSION 2u
#define JOC_EVENT_VERSION 1u
@@ -152,8 +152,7 @@ JOC_API const char* JOC_CALL joc_last_error_detail(void);
typedef struct joc_emdf_payload_info {
uint8_t id;
uint8_t reserved[3];
uint16_t sample_offset; /* EMDF outer smpoffst, 11 bits */
uint16_t reserved2;
uint32_t sample_offset; /* EMDF outer smpoffst: variable_bits(11) */
uint32_t bit_offset;
uint32_t size; /* payload bytes */
} joc_emdf_payload_info;
@@ -170,7 +169,8 @@ typedef struct joc_emdf_info {
/* Per-object ID14/JOC descriptor plus its dequantized matrix.
* dq[dp][ch][pb] is zero filled outside [0,n_dpoints) x [0,n_channels) x
* [0,n_bands). Absent objects are entirely zero. */
* [0,n_bands). Absent objects are entirely zero. offset_ts holds the raw
* 5-bit JOC offsets (legal range 0..23, strictly increasing per object). */
typedef struct joc_object_params {
uint8_t present;
uint8_t num_bands_idx;
@@ -185,6 +185,21 @@ typedef struct joc_object_params {
double dq[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS];
} joc_object_params;
/* Per-frame JOC parse status (joc_frame_params.status). A non-zero status makes
* the frame invalid for rendering: the renderer holds the previous matrices or
* passes the core PCM through instead of decoding the matrix. Only status 3
* still carries a complete object list (object count clamped to 15) for
* diagnostics; statuses 2 and 4 stop the parse after the failing header field. */
enum {
JOC_FRAME_STATUS_OK = 0,
JOC_FRAME_STATUS_UNSUPPORTED_DMX = 2, /* joc_dmx_config_idx outside 0..4 */
JOC_FRAME_STATUS_OBJECTS_CLAMPED = 3, /* declared object count above 15 */
JOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4, /* unknown num_bands index */
JOC_FRAME_STATUS_BAD_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */
/* strictly increasing */
JOC_FRAME_STATUS_TRAILING_DATA = 6 /* bytes after joc_data alignment */
};
typedef struct joc_frame_params {
uint32_t struct_size;
uint32_t struct_version;
@@ -196,12 +211,14 @@ typedef struct joc_frame_params {
uint8_t clipgain_x_bits;
uint8_t clipgain_y_bits;
uint8_t objects_clamped; /* num_objects_bits+1 exceeded 15 */
uint32_t seq_count; /* 10-bit JOC sequence counter, parsed only */
uint32_t seq_count; /* 10-bit JOC sequence counter */
uint32_t present_mask; /* bit i == object i present */
uint8_t status; /* JOC_FRAME_STATUS_* */
uint8_t reserved[3];
uint32_t data_end_bits; /* bit position just after joc_data */
uint32_t trailing_bits; /* bits left after joc_data (padding/ext) */
uint8_t tail_bytes[8]; /* first up to 8 trailing bytes, for A/B */
double clipgain; /* 1 + (y/32) * 2^(x-4), bit-exact */
double clipgain; /* 2^(x-4) * (1 + y/32), bit-exact */
joc_object_params objects[JOC_MAX_OBJECTS];
} joc_frame_params;
+2 -1
View File
@@ -98,7 +98,8 @@ Status JochrtfRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kerne
Status JochrtfRuntime::process_block() {
double positions[timeline::kTimelineObjects][3] = {};
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
positions);
&positions[0][0],
timeline::kTimelineObjects);
if (!queried.ok()) {
return queried;
}
+2 -2
View File
@@ -83,7 +83,7 @@ struct Options {
};
const char* kLayoutChoices =
"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 9.1.6";
"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 9.1.6 6.0";
void print_usage() {
std::printf(
@@ -97,7 +97,7 @@ void print_usage() {
" input 输入 .m4a/.eac3/.ec3\n"
"\n"
"模式(默认输出 ADM BWF):\n"
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、7.1.2\n"
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、6.0、7.1.2\n"
" 可选值: %s\n"
" --binaural 直接双耳渲染;不生成临时 ADM BWF\n"
"\n"
+8 -2
View File
@@ -102,9 +102,15 @@ Status parse_at(const std::uint8_t* data, std::size_t size, std::size_t start_bi
}
const std::uint32_t has_sample_offset = reader.read(1);
std::uint16_t sample_offset = 0;
std::uint32_t sample_offset = 0;
if (has_sample_offset != 0u) {
sample_offset = static_cast<std::uint16_t>(reader.read(12) >> 1);
std::uint32_t value = 0;
if (!bits::variable_bits(reader, 11, 8, &value)) {
return reader.error() == JOC_ERR_BITSTREAM_TRUNCATED
? truncated_fail(reader)
: syntax_fail(reader.error_message());
}
sample_offset = value;
}
if (reader.read(1) != 0u) {
std::uint32_t ignored = 0;
+1 -1
View File
@@ -17,7 +17,7 @@ inline constexpr std::size_t kMaxPayloads = JOC_MAX_EMDF_PAYLOADS;
struct Payload {
std::uint8_t id = 0;
std::uint16_t sample_offset = 0;
std::uint32_t sample_offset = 0; // EMDF outer smpoffst: variable_bits(11)
std::size_t bit_offset = 0; // MSB-first bit position of the payload bytes
std::size_t size = 0; // payload byte count
// Payload configuration data (ETSI TS 102 366 H.2.2.3). Spec section 8.2 and
+2 -1
View File
@@ -1120,7 +1120,8 @@ struct RosellaRuntime::Impl {
// rosella_binaural_renderer._set_block_parameters.
Status set_block_parameters(std::int64_t sample) {
double positions[timeline::kTimelineObjects][3] = {};
Status status = timeline.positions_at(sample, positions);
Status status = timeline.positions_at(sample, &positions[0][0],
timeline::kTimelineObjects);
if (!status.ok()) {
return status;
}
+301
View File
@@ -1,6 +1,7 @@
#include "joc_bitstream/bed_layout_map.h"
#include <cmath>
#include <cstring>
#include "speaker/speaker_layouts.h"
@@ -100,6 +101,9 @@ constexpr LayoutName kLayoutNames[] = {
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe), "5.1"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround), "6.0"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
@@ -328,4 +332,301 @@ bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
return false;
}
namespace {
// ETSI TS 103 420 Table B.10: the fixed ADM position of every Table 12 bed
// channel. bed_output_description() matches these points against the target
// layout; the kChannels table above keeps the ADM/binaural path's coordinates.
struct TableB10Position {
BedChannel channel;
double xyz[3];
};
constexpr TableB10Position kTableB10[oamd::kBedLabelCount] = {
{BedChannel::kLeft, {-1.0, 1.0, 0.0}},
{BedChannel::kRight, {1.0, 1.0, 0.0}},
{BedChannel::kCenter, {0.0, 1.0, 0.0}},
{BedChannel::kLfe, {-1.0, 1.0, -1.0}},
{BedChannel::kLeftSurround, {-1.0, 0.0, 0.0}},
{BedChannel::kRightSurround, {1.0, 0.0, 0.0}},
{BedChannel::kLeftRearSurround, {-1.0, -1.0, 0.0}},
{BedChannel::kRightRearSurround, {1.0, -1.0, 0.0}},
{BedChannel::kTopFrontLeft, {-1.0, 1.0, 1.0}},
{BedChannel::kTopFrontRight, {1.0, 1.0, 1.0}},
{BedChannel::kTopSideLeft, {-1.0, 0.0, 1.0}},
{BedChannel::kTopSideRight, {1.0, 0.0, 1.0}},
{BedChannel::kTopBackLeft, {-1.0, -1.0, 1.0}},
{BedChannel::kTopBackRight, {1.0, -1.0, 1.0}},
{BedChannel::kLeftWide, {-1.0, 21.0 / 31.0, 0.0}},
{BedChannel::kRightWide, {1.0, 21.0 / 31.0, 0.0}},
{BedChannel::kLfe2, {1.0, 1.0, -1.0}},
};
// bed_layout.BED_REFERENCE_POSITIONS_Q15; index 3 is the non-spatial sentinel.
constexpr std::int32_t kReferencePositions[kBedReferencePositionCount][3] = {
{0, 0, 0}, {32767, 0, 0}, {16384, 0, 0}, {-1, -1, -1},
{0, 16384, 0}, {32767, 16384, 0}, {0, 32767, 0}, {32767, 32767, 0},
{16384, 32767, 0}, {5285, 0, 0}, {27483, 0, 0}, {0, 5285, 0},
{32767, 5285, 0}, {7928, 0, 32767}, {24840, 0, 32767}, {7928, 7928, 32767},
{24840, 7928, 32767}, {7928, 16384, 32767}, {24840, 16384, 32767},
{7928, 24840, 32767}, {24840, 24840, 32767}, {7928, 32767, 32767},
{24840, 32767, 32767}, {11099, 0, 0}, {21669, 0, 0}, {0, 11099, 0},
{32767, 11099, 0}, {0, 21669, 0}, {32767, 21669, 0}, {0, 27483, 0},
{32767, 27483, 0}, {5285, 32767, 0}, {27483, 32767, 0}, {11099, 32767, 0},
{21669, 32767, 0}, {16384, 0, 32767}, {16384, 16384, 32767},
{16384, 32767, 32767},
};
// 自动 trim 的每个布局基准衰减,单位 dB。
struct AttenuationEntry {
const char* compact_name;
double db;
};
constexpr AttenuationEntry kAttenuation[] = {
{"20", -4.5}, {"31", -4.5}, {"40", -3.0}, {"51", -3.0},
{"60", -1.5}, {"71", -1.5}, {"512", -2.25}, {"514", -1.5},
{"712", -0.75}, {"714", 0.0}, {"914", 0.0}, {"916", 0.0},
};
constexpr int kMaxChannels = static_cast<int>(ejoc::speaker_tables::kMaxChannels);
void set_sentinel(std::int32_t coordinate[3]) {
coordinate[0] = -1;
coordinate[1] = -1;
coordinate[2] = -1;
}
bool is_sentinel(const std::int32_t coordinate[3]) {
return coordinate[0] == -1 && coordinate[1] == -1 && coordinate[2] == -1;
}
bool is_lfe_label(BedChannel channel) {
return channel == BedChannel::kLfe || channel == BedChannel::kLfe2;
}
const TableB10Position* table_b10(BedChannel channel) {
for (const TableB10Position& entry : kTableB10) {
if (entry.channel == channel) {
return &entry;
}
}
return nullptr;
}
// ADM 笛卡尔坐标 -> 渲染器方位 (u 右, v 后, w 上)。
void render_coordinates(const double xyz[3], double out[3]) {
out[0] = (xyz[0] + 1.0) * 0.5;
out[1] = (1.0 - xyz[1]) * 0.5;
out[2] = xyz[2];
}
// 渲染器方位的欧氏距离,比较的是归一化到 0..1 的坐标。
double render_distance(const double left[3], const double right[3]) {
const double du = left[0] - right[0];
const double dv = left[1] - right[1];
const double dw = left[2] - right[2];
return std::sqrt(du * du + dv * dv + dw * dw);
}
// Reference-position matching: the non-spatial sentinel resolves to index 3.
int nearest_reference(const std::int32_t coordinate[3]) {
if (is_sentinel(coordinate)) {
return 3;
}
const double position[3] = {
static_cast<double>(coordinate[0]) / 32768.0,
static_cast<double>(coordinate[1]) / 32768.0,
static_cast<double>(coordinate[2]) / 32768.0,
};
int best = 3;
double best_distance = 0.0;
bool have_best = false;
for (int index = 0; index < kBedReferencePositionCount; ++index) {
const std::int32_t* candidate = kReferencePositions[index];
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
continue;
}
const double point[3] = {
static_cast<double>(candidate[0]) / 32768.0,
static_cast<double>(candidate[1]) / 32768.0,
static_cast<double>(candidate[2]) / 32768.0,
};
const double distance = render_distance(position, point);
if (!have_best || distance < best_distance) {
best = index;
best_distance = distance;
have_best = true;
}
}
return best;
}
// 目标布局里离 desired 最近、且在 0.05 容差内的输出声道;没有返回 -1。
int nearest_channel(const double desired[3], const std::int32_t positions[][3],
std::uint32_t channel_count) {
int best = -1;
double best_distance = 0.0;
bool have_best = false;
for (std::uint32_t index = 0; index < channel_count; ++index) {
if (is_sentinel(positions[index])) {
continue;
}
const double point[3] = {
static_cast<double>(positions[index][0]) / 32768.0,
static_cast<double>(positions[index][1]) / 32768.0,
static_cast<double>(positions[index][2]) / 32768.0,
};
const double distance = render_distance(desired, point);
if (!have_best || distance < best_distance) {
best = static_cast<int>(index);
best_distance = distance;
have_best = true;
}
}
if (have_best && best_distance <= 0.05) {
return best;
}
return -1;
}
// 输出声道 index -> 该声道的 Q15 方位;LFE 与非空间声道给 sentinel。
void channel_positions(const speaker::LayoutInfo& layout,
std::int32_t positions[][3]) {
for (int index = 0; index < kMaxChannels; ++index) {
set_sentinel(positions[index]);
}
const auto* geometry = ejoc::speaker_tables::find_layout(layout.speaker_bitfield);
if (geometry != nullptr) {
bool known[kMaxChannels] = {};
std::int32_t found[kMaxChannels][3];
for (int index = 0; index < kMaxChannels; ++index) {
set_sentinel(found[index]);
}
for (const auto& region : geometry->regions) {
for (std::size_t point = 0; point < region.point_count; ++point) {
const auto speaker = static_cast<int>(region.points[point].speaker_id);
if (speaker < 0 || speaker >= kMaxChannels || known[speaker]) {
continue;
}
for (int axis = 0; axis < 3; ++axis) {
found[speaker][axis] =
static_cast<std::int32_t>(region.points[point].coordinate_q15[axis]);
}
known[speaker] = true;
}
}
const std::uint32_t count =
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
? layout.channel_count
: static_cast<std::uint32_t>(kMaxChannels);
for (std::uint32_t index = 0; index < count; ++index) {
const char* name = layout.channel_names != nullptr ? layout.channel_names[index]
: nullptr;
if (name != nullptr && std::strcmp(name, "LFE") == 0) {
continue;
}
if (known[index]) {
for (int axis = 0; axis < 3; ++axis) {
positions[index][axis] = found[index][axis];
}
}
}
}
}
int channel_index(const speaker::LayoutInfo& layout, const char* name) {
if (name == nullptr || layout.channel_names == nullptr) {
return -1;
}
for (std::uint32_t index = 0; index < layout.channel_count; ++index) {
if (std::strcmp(layout.channel_names[index], name) == 0) {
return static_cast<int>(index);
}
}
return -1;
}
double attenuation_db(const speaker::LayoutInfo& layout) {
for (const AttenuationEntry& entry : kAttenuation) {
if (std::strcmp(entry.compact_name, layout.compact_name) == 0) {
return entry.db;
}
}
return 0.0;
}
} // namespace
const std::int32_t (*bed_reference_positions_q15())[3] {
return kReferencePositions;
}
BedOutputDescription bed_output_description(const speaker::LayoutInfo& layout) {
BedOutputDescription description;
std::int32_t positions[kMaxChannels][3];
channel_positions(layout, positions);
const std::uint32_t output_count =
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
? layout.channel_count
: static_cast<std::uint32_t>(kMaxChannels);
description.output_labels.reserve(output_count);
for (std::uint32_t index = 0; index < output_count; ++index) {
description.output_labels.push_back(nearest_reference(positions[index]));
}
for (int label = 0; label < oamd::kBedLabelCount; ++label) {
const BedChannel channel = static_cast<BedChannel>(label);
const char* name = channel == BedChannel::kLfe2 ? nullptr
: bed_channel_short_name(channel);
int slot = -1;
if (name != nullptr && name[0] != '\0') {
slot = channel_index(layout, name);
}
if (slot < 0 && channel == BedChannel::kLfe2) {
slot = channel_index(layout, "LFE");
}
const TableB10Position* position = table_b10(channel);
double desired[3] = {0.0, 0.0, 0.0};
if (position != nullptr) {
render_coordinates(position->xyz, desired);
}
if (slot < 0 && position != nullptr) {
slot = nearest_channel(desired, positions, output_count);
}
if (slot < 0) {
description.label_to_slot[label] = is_lfe_label(channel) ? -1 : -2;
} else {
description.label_to_slot[label] = slot;
}
if (is_lfe_label(channel)) {
description.direct_output_labels[label] = 3;
} else {
int best = 3;
double best_distance = 0.0;
bool have_best = false;
for (int index = 0; index < kBedReferencePositionCount; ++index) {
const std::int32_t* candidate = kReferencePositions[index];
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
continue;
}
const double point[3] = {
static_cast<double>(candidate[0]) / 32768.0,
static_cast<double>(candidate[1]) / 32768.0,
static_cast<double>(candidate[2]) / 32768.0,
};
const double distance = render_distance(desired, point);
if (!have_best || distance < best_distance) {
best = index;
best_distance = distance;
have_best = true;
}
}
description.direct_output_labels[label] = best;
}
}
description.automatic_attenuation_db = attenuation_db(layout);
return description;
}
} // namespace joc::joc
+24 -23
View File
@@ -6,31 +6,12 @@
#include <vector>
#include "oamd/oamd_parser.h"
#include "speaker/speaker_layout_lookup.h"
namespace joc::joc {
// OAMD Table 12 的标准 bed 声道。LSB 顺序与声明顺序一致:L/R、C、LFE、
// Ls/Rs、Lrs/Rrs、TFL/TFR、TSL/TSR、TBL/TBR、LW/RW、LFE2。
enum class BedChannel : std::uint8_t {
kLeft = 0,
kRight,
kCenter,
kLfe,
kLeftSurround,
kRightSurround,
kLeftRearSurround,
kRightRearSurround,
kTopFrontLeft,
kTopFrontRight,
kTopSideLeft,
kTopSideRight,
kTopBackLeft,
kTopBackRight,
kLeftWide,
kRightWide,
kLfe2,
kCount,
};
// BedChannel lives in oamd/oamd_parser.h: the enum is the OAMD Table 12
// label order and OAMD frame state carries it directly.
// 内容声明的 bed 布局。bed 对象在 OAMD 里没有位置字段,位置由这里的布局决定。
struct BedLayout {
@@ -61,8 +42,28 @@ bool bed_channel_adm_position(BedChannel channel, double xyz[3]);
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]);
// 目标布局里同名扬声器的 Q15 方位:bed 声道直连到该扬声器,而不是参与声像。
// 目标布局没有这个声道时返回 false。
// 目标布局没有这个声道时返回 false。4.0 与 6.0 共用未分配的 out_ch_config
// 0xFF,因此这里按 4.0 的声道集合解释 0xFF。
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
std::uint16_t q15[3]);
// 参考位置网格 ``BED_REFERENCE_POSITIONS_Q15``:bed 标签与输出 slots 的最近邻
// 匹配都用这一组固定 Q15 点。索引 3 是 (-1,-1,-1),表示 LFE 那样的非空间声源。
inline constexpr int kBedReferencePositionCount = 38;
const std::int32_t (*bed_reference_positions_q15())[3];
// 一个目标扬声器布局的 bed 路由描述(bed_layout.bed_output_description):
// 按标准 bed 标签序(Table 12 的 17 个标签)给出目标 layout 的输出参考位置、
// 每个标签的输出 slot 与直连参考位置,以及该布局的自动 trim 基准衰减。
struct BedOutputDescription {
std::vector<int> output_labels; // 每个输出声道最近邻的参考位置索引
int label_to_slot[oamd::kBedLabelCount] = {}; // -2 不可达,-1 LFE 通路
int direct_output_labels[oamd::kBedLabelCount] = {};
double automatic_attenuation_db = 0.0;
};
// 由布局名/几何派生 bed 路由描述;``layout.channel_names`` 必须按标准声道
// 顺序给出 ``layout.channel_count`` 个名字。
BedOutputDescription bed_output_description(const speaker::LayoutInfo& layout);
} // namespace joc::joc
+155 -38
View File
@@ -182,6 +182,55 @@ std::int16_t num_bands_for_index(std::uint32_t num_bands_idx) {
return -1;
}
namespace {
// Reads the 12-bit joc_header at the start of the payload. Mirrors
// parse_joc_header(): a downmix configuration outside 0..4 is a frame status,
// not an exception, because a metadata scan records it as an unsupported
// variant while the frame itself stays classified.
Status parse_id14_header(const std::uint8_t* payload, std::size_t payload_size,
joc_frame_params* out) {
bits::BitReader reader(payload, payload_size);
out->dmx_config_idx = static_cast<std::uint8_t>(reader.read(3));
out->num_objects_bits = static_cast<std::uint8_t>(reader.read(6));
out->ext_config_idx = static_cast<std::uint8_t>(reader.read(3));
if (reader.failed()) {
return truncated_fail(reader);
}
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
if (n_channels < 0) {
// The core channel count decides how the object syntax expands, so an
// unknown configuration stops the parse after the header fields.
out->status = JOC_FRAME_STATUS_UNSUPPORTED_DMX;
out->objects_clamped = 0u;
out->n_objects = 0u;
return Status::success();
}
out->n_channels = static_cast<std::uint8_t>(n_channels);
const std::uint32_t declared = static_cast<std::uint32_t>(out->num_objects_bits) + 1u;
out->objects_clamped = declared > JOC_MAX_OBJECTS ? 1u : 0u;
out->n_objects = static_cast<std::uint8_t>(
std::min<std::uint32_t>(declared, static_cast<std::uint32_t>(JOC_MAX_OBJECTS)));
if (out->objects_clamped != 0u) {
out->status = JOC_FRAME_STATUS_OBJECTS_CLAMPED;
}
return Status::success();
}
// Records where joc_data ends and the first trailing bytes, like _tail_info().
void tail_info(joc_frame_params* out, const bits::BitReader& reader, const std::uint8_t* payload,
std::size_t payload_size) {
out->data_end_bits = static_cast<std::uint32_t>(reader.position());
out->trailing_bits = static_cast<std::uint32_t>(payload_size * 8u - reader.position());
const std::size_t tail_offset = reader.position() / 8u;
if (tail_offset < payload_size) {
const std::size_t tail_bytes = std::min<std::size_t>(8u, payload_size - tail_offset);
std::memcpy(out->tail_bytes, payload + tail_offset, tail_bytes);
}
}
} // namespace
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out,
FrameSymbols* symbols) {
if (payload == nullptr || out == nullptr) {
@@ -195,45 +244,53 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
FrameSymbols& capture = (symbols != nullptr) ? *symbols : local_symbols;
std::memset(&capture, 0, sizeof(capture));
bits::BitReader reader(payload, payload_size);
out->dmx_config_idx = static_cast<std::uint8_t>(reader.read(3));
out->num_objects_bits = static_cast<std::uint8_t>(reader.read(6));
out->ext_config_idx = static_cast<std::uint8_t>(reader.read(3));
const std::uint32_t declared_objects = static_cast<std::uint32_t>(out->num_objects_bits) + 1u;
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
if (n_channels < 0) {
return syntax_fail("unknown JOC downmix configuration " +
std::to_string(out->dmx_config_idx));
const Status header = parse_id14_header(payload, payload_size, out);
if (!header.ok()) {
return header;
}
out->n_channels = static_cast<std::uint8_t>(n_channels);
// A declared object count above 15 is clamped to 15: the frame is parsed for
// 15 objects only, and the clamp is reported separately.
out->objects_clamped = declared_objects > JOC_MAX_OBJECTS ? 1u : 0u;
const std::uint32_t n_objects =
std::min<std::uint32_t>(declared_objects, JOC_MAX_OBJECTS);
out->n_objects = static_cast<std::uint8_t>(n_objects);
bits::BitReader reader(payload, payload_size);
reader.skip(12);
out->clipgain_x_bits = static_cast<std::uint8_t>(reader.read(3));
out->clipgain_y_bits = static_cast<std::uint8_t>(reader.read(5));
out->seq_count = reader.read(10);
// clipgain = 1 + (y/32) * 2^(x-4); ldexp builds the power of two exactly
// over the whole legal range.
out->clipgain = 1.0 + static_cast<double>(out->clipgain_y_bits) / 32.0 *
std::ldexp(1.0, static_cast<int>(out->clipgain_x_bits) - 4);
if (reader.failed()) {
return truncated_fail(reader);
}
// clipgain = 2^(x-4) * (1 + y/32); ldexp builds the power of two exactly
// over the whole legal range, so the result is bit-exact to the reference.
out->clipgain = std::ldexp(1.0, static_cast<int>(out->clipgain_x_bits) - 4) *
(1.0 + static_cast<double>(out->clipgain_y_bits) / 32.0);
if (out->status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
tail_info(out, reader, payload, payload_size);
return Status::success();
}
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
const std::uint32_t n_objects = out->n_objects;
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
joc_object_params& info = out->objects[obj];
info.present = static_cast<std::uint8_t>(reader.read(1));
if (reader.failed()) {
return truncated_fail(reader);
}
if (info.present == 0u) {
continue;
}
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
if (reader.failed()) {
return truncated_fail(reader);
}
const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
if (bands < 0) {
return syntax_fail("unknown JOC num_bands index " +
std::to_string(info.num_bands_idx));
// The symbol count depends on the parameter-band count, so the rest
// of the payload cannot be parsed.
if (out->status == JOC_FRAME_STATUS_OK) {
out->status = JOC_FRAME_STATUS_BAD_PARAMETER_BAND;
}
tail_info(out, reader, payload, payload_size);
return Status::success();
}
info.n_bands = static_cast<std::uint8_t>(bands);
info.sparse = static_cast<std::uint8_t>(reader.read(1));
@@ -241,16 +298,42 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
info.slope_idx = static_cast<std::uint8_t>(reader.read(1));
info.num_dpoints_bits = static_cast<std::uint8_t>(reader.read(1));
info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u);
if (reader.failed()) {
return truncated_fail(reader);
}
if (info.slope_idx == 1u) {
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5) + 1u);
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5));
}
if (reader.failed()) {
return truncated_fail(reader);
}
// offset_ts is the raw 5-bit slot index (legal range 0..23) and one
// object's data points must be strictly increasing.
bool invalid = false;
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
if (info.offset_ts[dp] >= JOC_TIMESLOTS) {
invalid = true;
break;
}
}
if (!invalid && info.n_dpoints > 1u) {
for (std::uint32_t dp = 1; dp < info.n_dpoints; ++dp) {
if (info.offset_ts[dp] <= info.offset_ts[dp - 1u]) {
invalid = true;
break;
}
}
}
if (invalid && out->status == JOC_FRAME_STATUS_OK) {
out->status = JOC_FRAME_STATUS_BAD_OFFSET_TS;
}
}
}
if (reader.failed()) {
return truncated_fail(reader);
}
// joc_data (Huffman): dense reads MTX per channel and band, sparse reads IDX
// then VEC. A frame whose status is already non-zero dequantizes below but
// is never rendered, so a misaligned parse cannot reach the DSP.
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
const joc_object_params& info = out->objects[obj];
if (info.present == 0u) {
@@ -300,12 +383,16 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
}
}
out->data_end_bits = static_cast<std::uint32_t>(reader.position());
out->trailing_bits = static_cast<std::uint32_t>(payload_size * 8u - reader.position());
const std::size_t tail_offset = reader.position() / 8u;
if (tail_offset < payload_size) {
const std::size_t tail_bytes = std::min<std::size_t>(8u, payload_size - tail_offset);
std::memcpy(out->tail_bytes, payload + tail_offset, tail_bytes);
tail_info(out, reader, payload, payload_size);
if (out->status == JOC_FRAME_STATUS_OK && out->ext_config_idx == 0u) {
// The tail pads with zero bits up to the next byte; a whole byte after
// that alignment is unexpected data.
const std::uint32_t pad =
(8u - (static_cast<std::uint32_t>(reader.position()) % 8u)) % 8u;
const std::uint32_t total_bits = static_cast<std::uint32_t>(payload_size * 8u);
if (total_bits > static_cast<std::uint32_t>(reader.position()) + pad) {
out->status = JOC_FRAME_STATUS_TRAILING_DATA;
}
}
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
@@ -313,8 +400,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
if (info.present == 0u) {
continue;
}
std::uint32_t mask_bit = 1u << obj;
out->present_mask |= mask_bit;
out->present_mask |= 1u << obj;
const std::int64_t nquant = (info.quant_idx == 0u) ? 96 : 192;
std::int64_t q[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS] = {};
@@ -372,7 +458,13 @@ int score_container_as_joc(const std::uint8_t* data, std::size_t size,
if (emdf::extract_payload_bytes(data, size, *payload, &bytes).ok()) {
joc_frame_params params;
FrameSymbols symbols;
parses = parse_id14(bytes.data(), bytes.size(), &params, &symbols).ok();
if (parse_id14(bytes.data(), bytes.size(), &params, &symbols).ok()) {
// The reference scores a payload by the frame status: an unsupported
// downmix configuration (2) or an unknown parameter-band count (4)
// leaves the syntax unparsable and must not win the container choice.
parses = params.status != JOC_FRAME_STATUS_UNSUPPORTED_DMX &&
params.status != JOC_FRAME_STATUS_BAD_PARAMETER_BAND;
}
}
const bool associated = oamd->has_group_id != 0u && payload->has_group_id != 0u &&
oamd->group_id == payload->group_id;
@@ -406,7 +498,20 @@ Status parse_eac3_frame(const std::uint8_t* frame, std::size_t frame_size, joc_f
if (!extract.ok()) {
return extract;
}
return parse_id14(bytes.data(), bytes.size(), out, symbols);
const Status parsed = parse_id14(bytes.data(), bytes.size(), out, symbols);
if (!parsed.ok()) {
return parsed;
}
// A metadata scan rejects an unsupported downmix configuration outright: the
// core channel count decides how every later frame is expanded, so this is a
// variant error rather than a per-frame status.
if (out->status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
const std::string message =
"downmix_config_unsupported: ID14 declares joc_dmx_config_idx=" +
std::to_string(out->dmx_config_idx) + " (legal values are 0..4)";
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc, message);
}
return Status::success();
}
Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
@@ -417,6 +522,17 @@ Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
if (!status.ok()) {
return status;
}
// The two statuses that stop the parse early leave the payload without a
// joc_data end position, so they keep reporting the syntax failure they
// reported before the frame-status split.
if (params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc,
"downmix_config_unsupported: joc_dmx_config_idx outside 0..4");
}
if (params.status == JOC_FRAME_STATUS_BAD_PARAMETER_BAND) {
return Status::fail(JOC_ERR_JOC_SYNTAX, stage::kJoc,
"unknown JOC num_bands index stops the payload");
}
if (out_trailing_bits != nullptr) {
*out_trailing_bits = params.trailing_bits;
}
@@ -861,6 +977,7 @@ Status check_cross_layer(const joc_frame_params& params, const eac3::Frame* core
std::uint16_t chanmap,
const std::vector<oamd::BedAssignment>* bed_assignments,
std::string* error, CrossLayerNotes* notes) {
(void)has_dependent;
const std::uint8_t config_idx = params.dmx_config_idx;
const int core_channels = params.n_channels;
std::vector<Position> wanted;
+537 -30
View File
@@ -69,6 +69,19 @@ public:
std::memset(synthesis_state_, 0, sizeof(synthesis_state_));
std::memset(x_, 0, sizeof(x_));
std::memset(z_, 0, sizeof(z_));
// Frame-level state: per-object previous matrices and presence markers,
// the seq state machine, the 8-plane passthrough history, the LFE ramp
// start value and the previous actual core-channel count.
std::memset(prev_matrix_, 0, sizeof(prev_matrix_));
std::memset(prev_present_, 0, sizeof(prev_present_));
std::memset(core_history_, 0, sizeof(core_history_));
state_ = 0;
expected_seq_ = 0;
invalid_count_ = 0;
last_frame_valid_ = false;
n_channels_prev_ = -1;
has_lfe_clipgain_ = false;
lfe_clipgain_ = 0.0;
// Sentinel: the first frame after reset takes the new scalar directly,
// without an intra-frame transition.
analysis_phase_ = -0.5f;
@@ -174,13 +187,22 @@ public:
}
std::memset(output16, 0, sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
analysis(bed_planar, phase_new, clipgain);
render_lfe(lfe, output_scale, output16);
// Analysis-side scalar = the structural 1/16 times this frame's clipgain.
// clipgain enters the analysis at this stage and the x16 at the output
// cancels the 1/16, so the net effect is a multiply by joc_clipgain.
analysis(bed_planar, static_cast<float>(phase_new * clipgain));
decode_lfe(lfe, clipgain, output16, output_scale);
process_objects(object_mask, n_bands, n_dpoints, slope_idx, offset_ts,
dq, output_scale, output16);
return 0;
}
// Frame-level entry point; the state machine and per-object history live
// inside the renderer (see render_frame_impl()).
int render_frame(const ejoc_frame_input& input) noexcept {
return render_frame_impl(input);
}
private:
void initialize_tables() noexcept {
for (int i = 0; i < 64; ++i) {
@@ -378,13 +400,12 @@ private:
}
}
void analysis(const float* bed_planar, const float phase_new, const double clipgain) noexcept {
// Frames the analysis QMF of the core PCM with the given analysis-side
// scalar (the structural 1/16 times joc_clipgain). The scalar ramps over the
// frame's first 256 samples from the previous frame's value; the first frame
// after a reset takes it directly.
void analysis(const float* bed_planar, const float scalar) noexcept {
job_bed_ = bed_planar;
// Analysis-side scalar = the structural 1/16 times this frame's clipgain.
// clipgain enters the analysis at this stage and the x16 at the output
// cancels the 1/16, so the net effect is a multiply by joc_clipgain; the
// previous frame's scalar is the ramp start.
const float scalar = static_cast<float>(phase_new * clipgain);
job_phase_old_ = analysis_phase_;
if (job_phase_old_ <= 0.0f && job_phase_old_ != 0.0f) {
job_phase_old_ = scalar;
@@ -509,11 +530,11 @@ private:
}
qmf5_step(state, rotated, pcm64);
for (int sample = 0; sample < 64; ++sample) {
// The clamp is on the ×16 object PCM; joc_clipgain already
// entered the analysis, so only the user output gain remains, and
// it is a float32 multiply like the reference.
const double clipped = clamp_unit(16.0 * pcm64[sample]);
// joc_clipgain already entered the analysis (see analysis()); what
// remains here is the user output gain.
const float value = static_cast<float>(clipped * output_scale);
destination[timeslot * 64 + sample] = value;
destination[timeslot * 64 + sample] = static_cast<float>(clipped) * output_scale;
}
}
}
@@ -533,8 +554,10 @@ private:
const int item = job_objects_[index];
if (job_kind_ == JobKind::Analysis) {
analysis_channel(item);
} else {
} else if (job_kind_ == JobKind::Objects) {
process_one_object(item);
} else {
process_one_object_frame(item);
}
}
}
@@ -620,24 +643,477 @@ private:
dispatch_jobs();
}
void render_lfe(const float* lfe, const float output_scale, float* output16) noexcept {
if (!lfe) {
return;
// Core LFE: the full joc_clipgain is applied as a sample-wise ramp before the
// 1217-sample delay, and the read-out is only clamped. The ramp is
// G_old + n*(G_new-G_old)/256 for n < 256 and G_new afterwards; the first
// frame after a reset uses G_old = G_new.
void decode_lfe(const float* lfe, const double clipgain, float* output16,
const float output_scale) noexcept {
const double new_gain = clipgain;
const double old_gain = has_lfe_clipgain_ ? lfe_clipgain_ : new_gain;
const bool ramped = old_gain != new_gain;
const double step = (new_gain - old_gain) / 256.0;
double ramp[256];
for (int n = 0; n < 256; ++n) {
ramp[n] = ramped ? old_gain + static_cast<double>(n) * step : new_gain;
}
has_lfe_clipgain_ = true;
lfe_clipgain_ = new_gain;
float* channel0 = output16;
for (int sample = 0; sample < kLfeDelay; ++sample) {
channel0[sample] =
static_cast<float>(clamp_unit(lfe_delay_[sample])) * output_scale;
}
for (int sample = kLfeDelay; sample < EJOC_FRAME_SAMPLES; ++sample) {
const int input = sample - kLfeDelay;
const double gain = input < 256 ? ramp[input] : new_gain;
const double value = (lfe != nullptr) ? static_cast<double>(lfe[input]) : 0.0;
channel0[sample] =
static_cast<float>(clamp_unit(value * gain)) * output_scale;
}
for (int sample = 0; sample < kLfeDelay; ++sample) {
const float value = static_cast<float>(clamp_unit(lfe_delay_[sample]));
output16[sample] = static_cast<float>(value * output_scale);
}
for (int sample = kLfeDelay; sample < 1536; ++sample) {
const float value = static_cast<float>(clamp_unit(static_cast<double>(lfe[sample - kLfeDelay])));
output16[sample] = static_cast<float>(value * output_scale);
}
for (int sample = 0; sample < kLfeDelay; ++sample) {
lfe_delay_[sample] = static_cast<double>(lfe[sample + (1536 - kLfeDelay)]);
const int input = sample + (EJOC_FRAME_SAMPLES - kLfeDelay);
const double gain = input < 256 ? ramp[input] : new_gain;
const double value = (lfe != nullptr) ? static_cast<double>(lfe[input]) : 0.0;
lfe_delay_[sample] = value * gain;
}
}
enum class JobKind : uint8_t { Analysis, Objects };
enum class FrameMode : uint8_t { Normal, Hold, HardCut, Passthrough };
// ---- frame-level state machine ------------------------------------- //
// The Renderer owns the seq state machine (normal / hold / hard cut /
// passthrough), the per-object previous matrix and its presence marker, the
// analysis/synthesis state, the LFE delay ring with its clipgain ramp, and
// the 8-plane core history of the passthrough path, so one audio frame in
// produces the complete 16-channel object frame.
float held_analysis_scalar() const noexcept {
// Sentinel: a renderer that has not seen a JOC frame yet reports the
// structural 1/16, i.e. clipgain 1.0.
return (analysis_phase_ <= 0.0f && analysis_phase_ != 0.0f) ? 0.0625f
: analysis_phase_;
}
double held_clipgain() const noexcept {
return static_cast<double>(held_analysis_scalar()) * 16.0;
}
// The 10-bit JOC sequence counter wraps from 1023 back to 1.
static uint32_t next_seq(const uint32_t value) noexcept {
return value == 1023u ? 1u : value + 1u;
}
// Drops the state of the core channels a smaller layout does not use.
void clear_unused_channels(const uint32_t n_channels) noexcept {
if (n_channels >= EJOC_MAX_CORE_CHANNELS) {
return;
}
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
std::memset(analysis_fifo_[channel], 0, sizeof(analysis_fifo_[channel]));
}
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
std::memset(prev_matrix_[object][channel], 0,
sizeof(prev_matrix_[object][channel]));
}
}
if (n_channels == 5u) {
// A 5-channel frame does not drive the extra-pair delay lanes.
std::memset(analysis_delay_[3], 0, sizeof(analysis_delay_[3]));
std::memset(analysis_delay_[4], 0, sizeof(analysis_delay_[4]));
}
}
// A declared core-channel-count change (renderer status 9) clears the LFE
// ring; the clipgain ramp state is kept, so the gain does not retune.
void maybe_clear_lfe_ring(const uint32_t status) noexcept {
if (status == 9u) {
std::memset(lfe_delay_, 0, sizeof(lfe_delay_));
}
}
// Advances the seq state machine for this frame and reports the state the
// renderer was in before the frame. status 8 (no metadata) neither advances
// the expected counter nor compares the sequence.
uint32_t advance_state(const uint32_t status, const uint32_t seq) noexcept {
const uint32_t pre_state = state_;
const bool valid = status == 0u || status == 9u;
if (status == EJOC_FRAME_STATUS_NO_METADATA && pre_state != 0u) {
state_ = 3;
return pre_state;
}
expected_seq_ = next_seq(expected_seq_);
if (valid && seq == 0u && pre_state != 0u) {
// The programme restarted: hard cut and drop the object history.
state_ = 4;
return pre_state;
}
uint32_t state = state_;
if (state == 0u) {
if (valid) {
state = 1u;
expected_seq_ = seq;
}
} else if (state == 1u) {
if (valid) {
if (seq != expected_seq_) {
state = 4u;
}
} else {
state = 2u;
invalid_count_ = 1u;
}
} else if (state == 2u) {
if (valid) {
state = 1u;
expected_seq_ = seq;
} else if (invalid_count_ == 5u) {
state = 3u;
} else {
++invalid_count_;
}
} else if (state == 3u) {
if (valid) {
state = 1u;
expected_seq_ = seq;
} else {
++invalid_count_;
}
} else {
// state 4: the hard cut lasted one frame; a valid frame resyncs and
// an invalid one starts the invalid-frame count.
if (valid) {
state = 1u;
expected_seq_ = seq;
} else {
state = 2u;
invalid_count_ = 1u;
}
}
state_ = state;
if (status == 9u) {
state_ = 4u;
}
last_frame_valid_ = valid;
return pre_state;
}
FrameMode select_mode(const uint32_t status) const noexcept {
if (status == EJOC_FRAME_STATUS_NO_METADATA) {
return FrameMode::Passthrough;
}
if (state_ == 4u) {
return FrameMode::HardCut;
}
if (state_ == 2u || state_ == 3u) {
return FrameMode::Hold;
}
if (state_ == 1u && status == 0u) {
return FrameMode::Normal;
}
return FrameMode::Passthrough;
}
// JOC input order 5/7 channels (without LFE) -> 8-plane core order
// L,R,C,LFE,Ls,Rs,(Lrs,Rrs). Used by the passthrough path and its history.
void build_core8(const float* bed_planar, const float* lfe,
const uint32_t n_channels) noexcept {
std::memset(core8_, 0, sizeof(core8_));
for (uint32_t channel = 0; channel < 3u && channel < n_channels; ++channel) {
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
core8_[channel][sample] =
static_cast<double>(bed_planar[channel * EJOC_FRAME_SAMPLES + sample]);
}
}
if (lfe != nullptr) {
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
core8_[EJOC_LFE_SLOT][sample] = static_cast<double>(lfe[sample]);
}
}
const uint32_t rest = n_channels > 3u ? n_channels - 3u : 0u;
for (uint32_t index = 0; index < rest; ++index) {
const uint32_t channel = 3u + index;
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
core8_[4u + index][sample] =
static_cast<double>(bed_planar[channel * EJOC_FRAME_SAMPLES + sample]);
}
}
}
// Passthrough output: slots 0..7 take the previous frame's 8 core planes
// delayed by 1217 samples plus this frame's leading 319 samples; slots 8..15
// stay zero.
void write_passthrough(float* output16, const float output_scale) const noexcept {
for (int channel = 0; channel < EJOC_CORE_OUT_CHANNELS; ++channel) {
float* destination = output16 + channel * EJOC_FRAME_SAMPLES;
for (int sample = 0; sample < kLfeDelay; ++sample) {
destination[sample] = static_cast<float>(
core_history_[channel][EJOC_FRAME_SAMPLES - kLfeDelay + sample]) *
output_scale;
}
for (int sample = kLfeDelay; sample < EJOC_FRAME_SAMPLES; ++sample) {
destination[sample] =
static_cast<float>(core8_[channel][sample - kLfeDelay]) * output_scale;
}
}
}
// Normal rendering: interpolate the per-object matrix from its previous
// frame-end value (or hard cut when there is none) and publish objects that
// disappeared as an all-zero matrix until they come back.
void matrix_object_frame(const int object) noexcept {
std::memset(z_[object], 0, sizeof(z_[object]));
const int n_channels = static_cast<int>(core_channels_);
const bool present = (job_object_mask_ & (1u << object)) != 0u;
if (!present) {
if (prev_present_[object]) {
for (int channel = 0; channel < n_channels; ++channel) {
std::memset(prev_matrix_[object][channel], 0,
sizeof(prev_matrix_[object][channel]));
}
prev_present_[object] = true;
}
return;
}
const int bands = job_n_bands_[object];
const int points = job_n_dpoints_[object];
const int slope = job_slope_idx_[object];
const uint8_t* pb_map = parameter_band_map(bands);
const bool has_previous = prev_present_[object];
for (int channel = 0; channel < n_channels; ++channel) {
for (int subband = 0; subband < EJOC_SUBBANDS; ++subband) {
const int parameter_band = pb_map[subband];
const double target0 = job_dq_[dq_index(object, 0, channel, parameter_band)];
const double target1 = points == 2
? job_dq_[dq_index(object, 1, channel, parameter_band)]
: target0;
const double previous =
has_previous ? prev_matrix_[object][channel][subband] : 0.0;
double last = target0;
for (int timeslot = 0; timeslot < EJOC_TIMESLOTS; ++timeslot) {
double coefficient = 0.0;
if (slope == 0) {
if (!has_previous) {
if (points == 1 || timeslot < EJOC_TIMESLOTS / 2) {
// Hard cut: no fade-in from zero. With two data
// points the second half still interpolates.
coefficient = target0;
} else {
const double alpha =
static_cast<double>(timeslot - (EJOC_TIMESLOTS / 2 - 1)) /
static_cast<double>(EJOC_TIMESLOTS / 2);
coefficient = target0 * (1.0 - alpha) + target1 * alpha;
}
} else if (points == 1) {
const double alpha =
static_cast<double>(timeslot + 1) /
static_cast<double>(EJOC_TIMESLOTS);
coefficient = previous * (1.0 - alpha) + target0 * alpha;
} else if (timeslot < EJOC_TIMESLOTS / 2) {
const double alpha = static_cast<double>(timeslot + 1) /
(EJOC_TIMESLOTS / 2);
coefficient = previous * (1.0 - alpha) + target0 * alpha;
} else {
const double alpha =
static_cast<double>(timeslot - (EJOC_TIMESLOTS / 2 - 1)) /
static_cast<double>(EJOC_TIMESLOTS / 2);
coefficient = target0 * (1.0 - alpha) + target1 * alpha;
}
} else {
// Step mode switches targets at the raw offset slots.
const double base = has_previous ? previous : target0;
coefficient = timeslot < job_offset_ts_[object * EJOC_MAX_DPOINTS]
? base
: target0;
if (points == 2 &&
timeslot >= job_offset_ts_[object * EJOC_MAX_DPOINTS + 1]) {
coefficient = target1;
}
}
z_[object][subband][timeslot].re +=
x_[channel][subband][timeslot].re * coefficient;
z_[object][subband][timeslot].im +=
x_[channel][subband][timeslot].im * coefficient;
last = coefficient;
}
prev_matrix_[object][channel][subband] = last;
}
}
prev_present_[object] = true;
}
// Hold rendering: all 24 slots reuse the previous frame-end matrix and the
// previous state is not updated.
void matrix_object_hold(const int object) noexcept {
std::memset(z_[object], 0, sizeof(z_[object]));
const int n_channels = static_cast<int>(core_channels_);
for (int channel = 0; channel < n_channels; ++channel) {
for (int subband = 0; subband < EJOC_SUBBANDS; ++subband) {
const double previous = prev_matrix_[object][channel][subband];
for (int timeslot = 0; timeslot < EJOC_TIMESLOTS; ++timeslot) {
z_[object][subband][timeslot].re +=
x_[channel][subband][timeslot].re * previous;
z_[object][subband][timeslot].im +=
x_[channel][subband][timeslot].im * previous;
}
}
}
}
void process_one_object_frame(const int object) noexcept {
if (frame_mode_ == FrameMode::Normal) {
matrix_object_frame(object);
} else if (frame_mode_ == FrameMode::Hold) {
matrix_object_hold(object);
} else {
// Hard cut and passthrough publish silence, but every object slot is
// still synthesised so the synthesis state stays aligned.
std::memset(z_[object], 0, sizeof(z_[object]));
}
synthesis_object(object, job_output_scale_, job_output16_);
}
// One E-AC-3 audio frame: validates the description, advances the state
// machine and dispatches one of the four rendering modes.
int render_frame_impl(const ejoc_frame_input& input) noexcept {
error_[0] = '\0';
if (input.struct_size != sizeof(ejoc_frame_input) ||
input.struct_version != EJOC_FRAME_INPUT_VERSION) {
return fail("unsupported ejoc_frame_input struct version");
}
if (input.bed_planar == nullptr || input.output16_planar == nullptr) {
return fail("null bed or output pointer passed to ejoc_renderer_render_frame");
}
const uint32_t n_channels = input.core_channel_count;
if (n_channels != EJOC_CORE_CHANNELS && n_channels != EJOC_MAX_CORE_CHANNELS) {
return fail("core_channel_count must be 5 or 7");
}
if (!std::isfinite(input.clipgain) || !std::isfinite(input.output_scale)) {
return fail("clipgain and output_scale must be finite");
}
const bool has_metadata = input.has_metadata != 0u;
uint32_t status = input.frame_status;
if (!has_metadata) {
if (status != EJOC_FRAME_STATUS_NO_METADATA) {
return fail("a frame without JOC metadata must use frame_status 8");
}
} else if (status != 0u && (status < 2u || status > 6u)) {
return fail("frame_status is not a JOC parse status");
}
if ((input.object_mask & ~((1u << EJOC_MAX_OBJECTS) - 1u)) != 0u) {
return fail("object_mask contains an object index above 14");
}
if (has_metadata && status == 0u) {
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
if ((input.object_mask & (1u << object)) == 0u) {
continue;
}
if (parameter_band_map(input.n_bands[object]) == nullptr) {
return fail("unsupported parameter-band count");
}
if (input.n_dpoints[object] < 1u || input.n_dpoints[object] > 2u) {
return fail("n_dpoints must be 1 or 2");
}
if (input.slope_idx[object] > 1u) {
return fail("slope_idx must be 0 or 1");
}
if (input.slope_idx[object] == 1u) {
const uint8_t* offsets =
input.offset_ts + object * EJOC_MAX_DPOINTS;
for (uint32_t point = 0; point < input.n_dpoints[object]; ++point) {
if (offsets[point] >= EJOC_TIMESLOTS) {
return fail("offset_ts leaves the 0..23 range");
}
if (point != 0u && offsets[point] <= offsets[point - 1u]) {
return fail("offset_ts is not strictly increasing");
}
}
}
}
}
if (n_channels_prev_ >= 0 && n_channels != static_cast<uint32_t>(n_channels_prev_)) {
clear_unused_channels(n_channels);
}
// The parse status decides whether the frame's clipgain is usable; a
// declared-channel-count change (status 9) is only the renderer's own
// dispatch tag, so the new gain still applies to that frame.
const uint32_t parse_status = status;
// A declared core-channel-count change is the renderer's status 9: hard
// cut with the LFE ring cleared, while the clipgain ramp state is kept.
if (has_metadata && status == 0u && input.declared_core_channels != 0u &&
n_channels_prev_ >= 0 &&
input.declared_core_channels != static_cast<uint32_t>(n_channels_prev_)) {
status = 9u;
}
advance_state(status, input.seq);
maybe_clear_lfe_ring(status);
const FrameMode mode = select_mode(status);
if (input.phase_shift_valid != 0u) {
phase_shift_enabled_ = input.phase_shift != 0u;
}
const bool valid_metadata =
has_metadata && parse_status == 0u && input.declared_core_channels != 0u;
double clipgain;
float phase_new;
if ((mode == FrameMode::Normal || mode == FrameMode::HardCut) && valid_metadata) {
clipgain = input.clipgain;
phase_new = static_cast<float>(0.0625 * clipgain);
} else {
// Held frames reuse the current clipgain; they do not retune it.
clipgain = held_clipgain();
phase_new = held_analysis_scalar();
}
core_channels_ = n_channels;
std::memset(input.output16_planar, 0,
sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
build_core8(input.bed_planar, input.lfe, n_channels);
analysis(input.bed_planar, phase_new);
job_kind_ = JobKind::FrameObjects;
frame_mode_ = mode;
job_object_mask_ = mode == FrameMode::Normal ? input.object_mask : 0u;
job_n_bands_ = input.n_bands;
job_n_dpoints_ = input.n_dpoints;
job_slope_idx_ = input.slope_idx;
job_offset_ts_ = input.offset_ts;
job_dq_ = input.dq;
job_output_scale_ = input.output_scale;
job_output16_ = input.output16_planar;
job_count_ = EJOC_MAX_OBJECTS;
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
job_objects_[object] = object;
}
dispatch_jobs();
decode_lfe(input.lfe, clipgain, input.output16_planar, input.output_scale);
if (mode == FrameMode::HardCut) {
// All matrices are zero this frame; the presence markers stay set so
// the next valid frame fades in from zero.
std::memset(input.output16_planar, 0,
sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
prev_present_[object] = true;
for (int channel = 0; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
std::memset(prev_matrix_[object][channel], 0,
sizeof(prev_matrix_[object][channel]));
}
}
} else if (mode == FrameMode::Passthrough) {
write_passthrough(input.output16_planar, input.output_scale);
}
// The 8-plane history is updated on every frame so a later passthrough
// frame is continuous with the last core PCM.
std::memcpy(core_history_, core8_, sizeof(core_history_));
n_channels_prev_ = static_cast<int>(n_channels);
return 0;
}
enum class JobKind : uint8_t { Analysis, Objects, FrameObjects };
std::vector<std::thread> workers_;
std::unique_ptr<std::barrier<>> work_barrier_;
@@ -657,6 +1133,8 @@ private:
const double* job_dq_ = nullptr;
float job_output_scale_ = 1.0f;
float* job_output16_ = nullptr;
uint32_t job_object_mask_ = 0;
FrameMode frame_mode_ = FrameMode::Normal;
uint32_t core_channels_ = EJOC_CORE_CHANNELS;
alignas(64) double analysis_fifo_[EJOC_MAX_CORE_CHANNELS][9][64];
@@ -668,11 +1146,29 @@ private:
// sigma(k) switch; the caller sets it for downmix configurations 3 and 4.
bool phase_shift_enabled_ = true;
alignas(64) double lfe_delay_[kLfeDelay];
// LFE gain ramp start; cleared by reset() and cleared/unset only there, so a
// held frame keeps the last applied gain.
double lfe_clipgain_ = 0.0;
bool has_lfe_clipgain_ = false;
alignas(64) double matrix_previous_[15][EJOC_MAX_CORE_CHANNELS][64];
alignas(64) double synthesis_state_[15][640];
alignas(64) Complex x_[EJOC_MAX_CORE_CHANNELS][64][24];
alignas(64) Complex z_[15][64][24];
// Frame-level state: the seq state machine and the per-object interpolation
// previous matrix (frame-end timeslot of the last published matrix).
uint32_t state_ = 0;
uint32_t expected_seq_ = 0;
uint32_t invalid_count_ = 0;
bool last_frame_valid_ = false;
int n_channels_prev_ = -1;
alignas(64) double prev_matrix_[EJOC_MAX_OBJECTS][EJOC_MAX_CORE_CHANNELS][64];
bool prev_present_[EJOC_MAX_OBJECTS];
// Passthrough history: the 8 core planes of the previous frame and of this
// frame, in the order L,R,C,LFE,Ls,Rs,(Lrs,Rrs).
alignas(64) double core_history_[EJOC_CORE_OUT_CHANNELS][EJOC_FRAME_SAMPLES];
alignas(64) double core8_[EJOC_CORE_OUT_CHANNELS][EJOC_FRAME_SAMPLES];
uint8_t bit_reverse_[64];
Complex fft_twiddle_[32];
double rotation_sin_[64];
@@ -690,13 +1186,13 @@ uint32_t EJOC_CALL ejoc_abi_version(void) {
const char* EJOC_CALL ejoc_build_info(void) {
#if defined(_MSC_VER)
return "eac3joc-core abi=1 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
return "eac3joc-core abi=4 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
#elif defined(__clang__)
return "eac3joc-core abi=1 compiler=Clang fft=fixed64 speaker=double binaural=double";
return "eac3joc-core abi=4 compiler=Clang fft=fixed64 speaker=double binaural=double";
#elif defined(__GNUC__)
return "eac3joc-core abi=1 compiler=GCC fft=fixed64 speaker=double binaural=double";
return "eac3joc-core abi=4 compiler=GCC fft=fixed64 speaker=double binaural=double";
#else
return "eac3joc-core abi=1 compiler=unknown fft=fixed64 speaker=double binaural=double";
return "eac3joc-core abi=4 compiler=unknown fft=fixed64 speaker=double binaural=double";
#endif
}
@@ -760,4 +1256,15 @@ int EJOC_CALL ejoc_renderer_process(
slope_idx, offset_ts, dq, clipgain, phase_new, output_scale, output16_planar);
}
int EJOC_CALL ejoc_renderer_render_frame(ejoc_renderer_handle handle,
const ejoc_frame_input* input) {
if (!handle) {
return -1;
}
if (!input) {
return -1;
}
return static_cast<ejoc::Renderer*>(handle)->render_frame(*input);
}
} // extern "C"
+38 -14
View File
@@ -6,16 +6,17 @@
namespace joc::joc {
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
const float* bed_planar, const float* lfe, float gain,
const float* bed_planar, const float* lfe,
std::uint32_t core_channel_count, bool has_metadata, float gain,
std::vector<float>* out16, std::string* error) {
if (handle == nullptr || bed_planar == nullptr || out16 == nullptr) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kDsp, "null argument");
}
if (params.n_channels != JOC_CORE_CHANNELS &&
params.n_channels != JOC_MAX_CORE_CHANNELS) {
if (core_channel_count != JOC_CORE_CHANNELS &&
core_channel_count != JOC_MAX_CORE_CHANNELS) {
if (error != nullptr) {
*error = "the reused JOC kernel requires 5 or 7 core channels, frame declares " +
std::to_string(static_cast<unsigned>(params.n_channels));
*error = "the reused JOC kernel requires 5 or 7 core channels, the frame has " +
std::to_string(core_channel_count);
}
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kDsp, *error);
}
@@ -39,7 +40,7 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
offset_ts[obj * JOC_MAX_DPOINTS + dp] = object.offset_ts[dp];
}
for (unsigned dp = 0; dp < object.n_dpoints; ++dp) {
for (unsigned ch = 0; ch < params.n_channels; ++ch) {
for (unsigned ch = 0; ch < core_channel_count; ++ch) {
for (unsigned pb = 0; pb < object.n_bands; ++pb) {
const std::size_t index =
((static_cast<std::size_t>(obj) * JOC_MAX_DPOINTS + dp) *
@@ -53,19 +54,42 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
}
}
out16->assign(static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES, 0.0f);
ejoc_frame_input input{};
input.struct_size = sizeof(input);
input.struct_version = EJOC_FRAME_INPUT_VERSION;
input.bed_planar = bed_planar;
input.lfe = lfe;
input.core_channel_count = core_channel_count;
// A frame without metadata has no declared channel count; the renderer's
// status-9 path is gated on has_metadata, so the value is not consulted.
input.declared_core_channels =
has_metadata ? static_cast<std::uint32_t>(params.n_channels) : 0u;
// sigma(k) = (k in {3,4}) gates the Ls/Rs -j rotation and the band-0 21-tap
// DC compensation together; other configurations keep the common processing.
const std::uint32_t phase_shift =
(params.dmx_config_idx == 3 || params.dmx_config_idx == 4) ? 1u : 0u;
const int result = ejoc_renderer_process(
handle, bed_planar, lfe, params.n_channels, phase_shift, params.present_mask, n_bands,
n_dpoints, slope_idx, offset_ts, dq.data(), params.clipgain, 0.0625f, gain,
out16->data());
// An unsupported downmix configuration (status 2) has no usable switch, so
// the renderer keeps the previous one.
input.phase_shift =
(params.dmx_config_idx == 3u || params.dmx_config_idx == 4u) ? 1u : 0u;
input.phase_shift_valid = params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX ? 0u : 1u;
input.frame_status = has_metadata ? params.status : EJOC_FRAME_STATUS_NO_METADATA;
input.seq = params.seq_count;
input.has_metadata = has_metadata ? 1u : 0u;
input.object_mask = params.present_mask;
input.n_bands = n_bands;
input.n_dpoints = n_dpoints;
input.slope_idx = slope_idx;
input.offset_ts = offset_ts;
input.dq = dq.data();
input.clipgain = params.clipgain;
input.output_scale = gain;
out16->assign(static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES, 0.0f);
input.output16_planar = out16->data();
const int result = ejoc_renderer_render_frame(handle, &input);
if (result != 0) {
const char* detail = ejoc_renderer_last_error(handle);
const std::string message =
"ejoc_renderer_process failed (" + std::to_string(result) + "): " +
"ejoc_renderer_render_frame failed (" + std::to_string(result) + "): " +
(detail != nullptr ? detail : "unknown");
if (error != nullptr) {
*error = message;
+14 -3
View File
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
@@ -10,10 +11,20 @@
namespace joc::joc {
// [16][1536] planar float32. bed_planar is [params.n_channels][1536], where
// n_channels comes from joc_dmx_config_idx (5 or 7).
// Rebuilds the 16-channel object frame ([16][1536] planar float32) for one
// audio frame through the renderer's frame-level state machine. bed_planar is
// [core_channel_count][1536] in JOC lane order (L,R,C,Ls,Rs,(extra pair)), where
// core_channel_count is the actual bed lane count (5 or 7) and lfe is the
// separate core LFE plane (NULL = zeros; the LFE ring still advances).
//
// has_metadata is false for an audio frame without a JOC EMDF container: such a
// frame always passes the 8 core planes through to output slots 0..7. For a
// frame with metadata, params.status selects normal rendering or the invalid
// frame path (hold / hard cut), and params.seq_count drives the state machine.
// gain is the user output gain (not joc_clipgain).
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
const float* bed_planar, const float* lfe, float gain,
const float* bed_planar, const float* lfe,
std::uint32_t core_channel_count, bool has_metadata, float gain,
std::vector<float>* out16, std::string* error);
} // namespace joc::joc
+8 -8
View File
@@ -338,7 +338,7 @@ inline constexpr uint8_t kPbMap1[64] = {
};
inline constexpr uint8_t kPbMap3[64] = {
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@@ -346,8 +346,8 @@ inline constexpr uint8_t kPbMap3[64] = {
inline constexpr uint8_t kPbMap5[64] = {
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
};
@@ -359,8 +359,8 @@ inline constexpr uint8_t kPbMap7[64] = {
};
inline constexpr uint8_t kPbMap9[64] = {
0, 1, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
};
@@ -373,9 +373,9 @@ inline constexpr uint8_t kPbMap12[64] = {
};
inline constexpr uint8_t kPbMap15[64] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11,
12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
};
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+101
View File
@@ -0,0 +1,101 @@
// Port of src/oamd_math.py: float32 equations for the metadata application path.
//
// The routines implement the fixed float32 equations for the size tables, ISF
// basis assembly, bed channel routing and the position-dependent compensation.
// The size tables are generated from the region geometry with grouped equal-power
// panning, an S448 weight and a power sum; every operation is evaluated in
// float32 in a fixed order so the coefficients are reproducible.
//
// The caller passes the parameter mappings from oamd_params; this module does
// not read files itself.
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <vector>
#include "oamd/oamd_params.h"
#include "speaker/speaker_layout_lookup.h"
#include "speaker/speaker_layouts.h"
namespace joc::oamd {
// The specified 2**x approximation used by the compensation kernels.
float exp2_approx(float value);
// The specified x**power approximation; power is a float32.
float pow_approx(float value, float power);
// Stable float32 normalisation with the tiny-norm floor.
std::vector<float> norm(const std::vector<float>& vector);
// One boundary weight of the size kernel.
float boundary(int axis, int edge, float position, float t);
// Maps a scalar size in [0, 1] to t on the size curve.
float size_curve_value(double size);
// Size kernel response in region-speaker order (the region point order).
std::vector<float> size_kernel(const ::ejoc::speaker_tables::RegionGeometry& region,
const float position[3], float t, bool height);
// Size-kernel target vector in layout channel order.
std::vector<float> size_targets(const MetadataParams& meta,
const ::ejoc::speaker_tables::LayoutGeometry& layout,
int region_index, const double position[3],
double size, bool height);
// One assembled ISF basis matrix (row_count x layout output_count, row major).
struct IsfBasis {
int rows = 0;
int columns = 0;
std::vector<float> values;
float at(int row, int column) const {
return values[static_cast<std::size_t>(row) * static_cast<std::size_t>(columns) +
static_cast<std::size_t>(column)];
}
};
// Assembles one ISF basis matrix from the compressed base tables.
IsfBasis assemble_isf(const MetadataParams& meta, const char* layout_key, int isf_idx);
// Returns the per-basis ISF compensation gain.
float isf_compensation(const MetadataParams& meta, const char* layout_key, int isf_idx,
int row, bool disabled);
// Per-label bed redistribution weight, in the reference-position index space
// used by the layout descriptors.
float bed_weight(int label, std::uint32_t mask, int target_label);
// The five height-candidate flags for one input bed label.
std::array<int, 5> bed_candidates(int label, std::uint32_t mask,
const std::vector<int>& output_labels);
// Route and weights for one input bed label. route == -1 means the returned
// weights are the target; otherwise route is the reference position used to
// synthesise a point source.
struct BedDistribution {
int route = -1;
std::vector<float> weights;
};
// Derives the bed routing of one input bed label from the target layout.
BedDistribution bed_distribution(const ::joc::speaker::LayoutInfo& layout, int label,
std::uint32_t mask, bool distribute);
// Returns the Q15 reference position used by the bed fallback path.
void bed_reference_position(int index, int q15[3]);
// Returns the bed path compensation gain for one input bed label. ``mode`` is
// the trim mode (0 automatic, 1 disabled, 2 explicit) and ``levels`` holds the
// surround, height and centre levels in dB.
float bed_compensation(const ::joc::speaker::LayoutInfo& layout, int label, int mode,
bool bypass, const double levels[3]);
// Automatic attenuation of a target layout in dB.
float bed_attenuation_db(const ::joc::speaker::LayoutInfo& layout);
} // namespace joc::oamd
+108
View File
@@ -0,0 +1,108 @@
#include "oamd/oamd_params.h"
#include <cstddef>
#include <utility>
#include <vector>
#include "oamd/isf_tables.h"
namespace joc::oamd {
namespace {
namespace tables = isf_tables;
// Builds the renderer-facing view from the checked-in table header. There is no
// file I/O and no runtime parsing: the numbers are compiled in as static data.
MetadataParams build_params() {
MetadataParams params;
params.configs.reserve(tables::kConfigCount);
for (const tables::Config& source : tables::kConfigs) {
IsfConfig config;
for (std::size_t index = 0; index < config.counts.size(); ++index) {
config.counts[index] = source.counts[index];
}
const std::size_t rows = static_cast<std::size_t>(config.row_count());
config.primary_row_map.assign(source.primary_row_map, source.primary_row_map + rows);
config.secondary_row_map.assign(source.secondary_row_map,
source.secondary_row_map + rows);
const std::size_t coefficients = rows * static_cast<std::size_t>(tables::kMatrixColumns);
config.matrix.assign(source.matrix, source.matrix + coefficients);
params.configs.push_back(std::move(config));
}
params.layouts.reserve(tables::kLayoutCount);
for (const tables::Layout& source : tables::kLayouts) {
IsfLayout layout;
layout.output_count = source.output_count;
for (std::size_t index = 0; index < layout.selectors.size(); ++index) {
layout.selectors[index] = source.selectors[index];
}
layout.compensation_value = source.compensation_value;
layout.output_ids.assign(source.output_ids,
source.output_ids + tables::kOutputIdSlots);
params.layouts.emplace(source.key, std::move(layout));
}
const auto copy_groups = [](const tables::GroupRecord* records, int count,
std::vector<IsfGroupRecord>* out) {
out->reserve(static_cast<std::size_t>(count));
for (int index = 0; index < count; ++index) {
out->push_back(IsfGroupRecord{records[index].selector, records[index].begin,
records[index].end});
}
};
copy_groups(tables::kLayoutGroups.floor_a, tables::kLayoutGroups.floor_a_count,
&params.layout_groups.floor_a);
copy_groups(tables::kLayoutGroups.floor_b, tables::kLayoutGroups.floor_b_count,
&params.layout_groups.floor_b);
copy_groups(tables::kLayoutGroups.height, tables::kLayoutGroups.height_count,
&params.layout_groups.height);
copy_groups(tables::kLayoutGroups.additional, tables::kLayoutGroups.additional_count,
&params.layout_groups.additional);
params.paired_columns.assign(tables::kPairedColumns,
tables::kPairedColumns + tables::kPairedColumnCount);
return params;
}
const MetadataParams& loaded_params() {
static const MetadataParams params = build_params();
return params;
}
} // namespace
const std::vector<IsfGroupRecord>* IsfLayoutGroups::find(const char* name) const {
if (name == nullptr) {
return nullptr;
}
const std::string key(name);
if (key == "floor_a") {
return &floor_a;
}
if (key == "floor_b") {
return &floor_b;
}
if (key == "height") {
return &height;
}
if (key == "additional") {
return &additional;
}
return nullptr;
}
const IsfLayout* MetadataParams::layout(const char* key) const {
if (key == nullptr) {
return nullptr;
}
const auto found = layouts.find(key);
return found != layouts.end() ? &found->second : nullptr;
}
const MetadataParams* metadata_params() { return &loaded_params(); }
const char* metadata_params_error() { return ""; }
} // namespace joc::oamd
+82
View File
@@ -0,0 +1,82 @@
// Port of src/oamd_params.py: the static ISF lookup data of the metadata path.
//
// The numbers are compiled in as the generated header `oamd/isf_tables.h`:
// ISF base coefficients and layout descriptors, applied as lookup tables.
// The remaining values (gain, size, priority, position, delta and refinement
// tables) are computed in code; the size tables are generated from the region
// geometry at runtime, and bed routing is derived from the speaker layouts.
// The arrays are adapted once per process into the structures below; nothing
// reads a data file.
#pragma once
#include <array>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>
#include "foundation/status.h"
namespace joc::oamd {
// One ISF configuration: the compressed basis matrix and the two row maps
// that expand it to the layout output channels.
struct IsfConfig {
// mid, upper, lower, zenith, row_count (the reference's counts tuple).
std::array<int, 5> counts{};
std::vector<int> primary_row_map;
std::vector<int> secondary_row_map;
// row_count * 73 float32 coefficients, row major.
std::vector<float> matrix;
int row_count() const { return counts[4]; }
};
// One layout descriptor: how many output channels the basis has,
// the layout-group selectors and the automatic compensation value.
struct IsfLayout {
int output_count = 0;
std::array<int, 4> selectors{}; // floor_a, floor_b, height, additional
double compensation_value = 0.0;
// ISF channel id of each matrix output column, padded with zeros to 37.
std::vector<std::uint8_t> output_ids;
};
// One record of a layout group: selector id and the half-open column range
// [begin, end).
struct IsfGroupRecord {
int selector = 0;
int begin = 0;
int end = 0;
};
// The four layout groups of the ISF tables.
struct IsfLayoutGroups {
std::vector<IsfGroupRecord> floor_a;
std::vector<IsfGroupRecord> floor_b;
std::vector<IsfGroupRecord> height;
std::vector<IsfGroupRecord> additional;
const std::vector<IsfGroupRecord>* find(const char* name) const;
};
// The ISF lookup data in the shape the metadata renderer consumes.
struct MetadataParams {
std::vector<IsfConfig> configs;
std::unordered_map<std::string, IsfLayout> layouts;
IsfLayoutGroups layout_groups;
// One flag per matrix column: whether the column also contributes through
// the secondary row map.
std::vector<bool> paired_columns;
const IsfLayout* layout(const char* key) const;
};
// Returns the process-wide tables. They are compiled in, so the pointer is
// never null; ``metadata_params_error`` is kept for callers that log a load
// failure and always returns an empty string.
const MetadataParams* metadata_params();
const char* metadata_params_error();
} // namespace joc::oamd
+1067 -338
View File
File diff suppressed because it is too large. Load diff
+172 -11
View File
@@ -9,6 +9,34 @@
#include "foundation/status.h"
#include "joc_core.h"
namespace joc::joc {
// OAMD Table 12 的标准 bed 声道。LSB 顺序与声明顺序一致:L/R、C、LFE、
// Ls/Rs、Lrs/Rrs、TFL/TFR、TSL/TSR、TBL/TBR、LW/RW、LFE2。
// The enum values are the reference's BED_LABEL_INDEX - 1.
enum class BedChannel : std::uint8_t {
kLeft = 0,
kRight,
kCenter,
kLfe,
kLeftSurround,
kRightSurround,
kLeftRearSurround,
kRightRearSurround,
kTopFrontLeft,
kTopFrontRight,
kTopSideLeft,
kTopSideRight,
kTopBackLeft,
kTopBackRight,
kLeftWide,
kRightWide,
kLfe2,
kCount,
};
} // namespace joc::joc
namespace joc::oamd {
inline constexpr int kMaxSlots = 16;
@@ -17,8 +45,16 @@ inline constexpr int kAxes = 3;
inline constexpr int kNQ12 = 62;
inline constexpr int kNQ3 = 15;
inline constexpr int kQ15Scale = 32768;
// Largest ISF configuration of Table 11b (5.6.0.11). A frame cannot carry more
// objects than this through any of the standard programmes, but the parser does
// not reject a larger count: it only bounds the legacy 16-slot view.
inline constexpr int kMaxObjects = 30;
inline constexpr int kMaxBlocks = 8;
inline constexpr std::uint32_t kTrimElementId = 2;
inline constexpr std::uint32_t kObjectElementId = 1;
inline constexpr std::uint32_t kExtendedElementId = 5;
inline constexpr int kTrimConfigs = 9;
inline constexpr int kBedLabelCount = 17;
// One of the nine per-configuration trim records of the OAMD trim element.
// ``kAbsent`` means the configuration carries no data (the element only
@@ -50,6 +86,92 @@ struct OamdTrim {
bool disable_per_object[kMaxSlots] = {};
};
// OAMD object kind: the programme assigns objects to the bed, to an ISF
// configuration, or to the dynamic (positional) set, in that order.
enum class ObjectKind : std::uint8_t {
kBed = 0,
kIsf = 1,
kDynamic = 2,
};
// Render state of one object in one block (5.5.9 object_info_block).
struct ObjectRenderState {
bool not_active = false;
std::int32_t gain_q = 0; // integer gain, unity = 4096
std::int32_t priority_q = 0; // Q10 priority, 32767 = default
std::int32_t qx = 0; // Q15 room position, 0..32767
std::int32_t qy = 0; // Q15 room position, 0..32767
std::int32_t qz = 0; // signed Q15 elevation
std::uint8_t zone_idx = 0;
bool enable_elevation = true;
std::uint8_t size_mode = 0; // 0 none, 1 isotropic, 2 per-axis
std::uint16_t size_q[3] = {0, 0, 0}; // Q15 size per axis
bool snap = false;
std::uint16_t divergence_q = 0; // Q15 divergence width
};
struct ObjectBlockState {
ObjectRenderState render;
};
// One object of the frame: its kind and the state of every block.
struct ObjectElementState {
ObjectKind kind = ObjectKind::kDynamic;
std::vector<ObjectBlockState> blocks;
};
// Timing shared by every object of one block. ``block_offset_samples`` already
// includes the element's sample_offset, like the reference block dictionary.
struct BlockTiming {
std::uint32_t block_offset_samples = 0;
std::uint32_t ramp_duration_samples = 0;
};
// Program assignment (5.5.3) as consumed by the speaker renderer.
struct ProgramState {
bool dynamic_object_only = false;
bool lfe_present = false;
bool b_bed_chan_distribute = false;
// program_assignment() content_description flags.
bool content_reserved = false;
bool content_bed = false;
bool content_isf = false;
bool content_dynamic = false;
std::uint32_t num_bed_objects = 0;
std::uint32_t num_isf_objects = 0;
std::int32_t num_dynamic_objects = -1; // -1 when the frame declares none
std::uint32_t bed_mask = 0; // 17-bit non-standard bed mask
std::int32_t isf_idx = -1; // -1 when the frame declares none
// Declared bed labels in channel order, including LFE/LFE2. Index i is the
// label of object i for i < num_bed_objects.
std::vector<::joc::joc::BedChannel> bed_labels;
};
// One element whose parsed content ended past its declared size. The reference
// keeps parsing such elements and only records the difference.
struct ElementSizeMismatch {
std::uint32_t element_ordinal = 0;
std::uint32_t element_id = 0;
std::uint32_t declared_size_bytes = 0;
std::uint32_t declared_end_bit = 0;
std::uint32_t parsed_end_bit = 0;
};
// Full frame state (frame_state() in the reference): per-object per-block
// render state plus programme assignment, timing and trim.
struct FrameState {
std::uint32_t object_count = 0;
std::uint32_t block_count = 0;
std::uint32_t sample_offset = 0; // object_element sample offset
std::uint32_t ramp_duration_samples = 0; // block 0
std::vector<BlockTiming> blocks;
std::vector<ObjectElementState> objects;
ProgramState program;
bool has_trim = false;
OamdTrim trim;
std::vector<ElementSizeMismatch> size_mismatch;
};
// (the reference's None), i.e. hold the previous position.
struct SlotUpdate {
std::int16_t q1 = -1;
@@ -76,6 +198,12 @@ struct OamdUpdate {
// keeps whatever controls the caller already holds.
OamdTrim trim;
bool has_trim = false;
// Full per-object per-block state of this payload. ``has_frame_state`` is
// true whenever the parser produced it; the speaker metadata path and the
// binaural position timeline consume it, while the legacy slot fields above
// stay authoritative for ADM export and the point-renderer path.
bool has_frame_state = false;
FrameState frame_state;
};
class OamdState {
@@ -103,6 +231,23 @@ public:
std::int16_t q(int slot, int axis) const { return q_[slot][axis]; }
// Resolves one frame-state position block for one object. The legacy
// apply() entry above keeps the reference frame_update() view (16 slots,
// block 0); the binaural position timeline uses this entry so a frame may
// carry more objects and more blocks than that view can express. Callers
// skip inactive and non-dynamic objects themselves, exactly like the
// reference's frame_update() value construction.
void apply_render_state(int object_index, const ObjectRenderState& render) {
if (object_index < 0 || object_index >= kMaxObjects) {
return;
}
q_[object_index][0] = static_cast<std::int16_t>(render.qx);
q_[object_index][1] = static_cast<std::int16_t>(render.qy);
const std::int32_t elevation = render.enable_elevation ? render.qz : 0;
q_[object_index][2] =
static_cast<std::int16_t>(elevation > 0 ? elevation : 0);
}
// Objects 1..15 as q15 triples, the layout the speaker renderer consumes.
void object_positions_q15(std::uint16_t out[kObjects][kAxes]) const {
for (int object = 0; object < kObjects; ++object) {
@@ -113,25 +258,18 @@ public:
}
private:
std::int16_t q_[kMaxSlots][kAxes] = {};
std::int16_t q_[kMaxObjects][kAxes] = {};
};
// q_of(k, n) = min(32767, floor(32768 k / n + 0.5)), the reference's quantiser.
int q_of(int k, int n);
Status parse_id11(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
// Parses only the trim element of a payload. ``out`` receives the first trim
// element found; ``*present`` is false when the payload carries none. decode
// paths that need the OAMD calibration but no object state can use this
// without requiring an object element.
Status parse_trim(const std::uint8_t* payload, std::size_t payload_size, OamdTrim* out,
bool* present);
struct BedAssignment {
bool lfe_only = false;
bool standard = false;
std::uint32_t mask = 0;
std::uint32_t mask = 0; // 10-bit standard or 17-bit non-standard mask
// Declared channels in channel order; LFE is kept in place.
std::vector<::joc::joc::BedChannel> channels;
};
struct ParseTrace {
@@ -145,6 +283,26 @@ struct ParseTrace {
bool reserved_data_not_present = false;
};
// Legacy single-frame view (frame_update() in the reference): the 16-slot
// position update plus programme and trim. A payload carrying more than 16
// objects or more than one position block is rejected, exactly like the
// reference legacy entry point. The ADM export path keeps this view; the
// speaker and binaural renderers use parse_id11_state().
Status parse_id11(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
// Full frame_state() view: per-object per-block state, no 16-slot or
// single-block restriction. The legacy fields are filled as well whenever the
// frame fits them, so a caller can parse once and hand the same update to the
// renderers and to the ADM export path where its shape allows it.
Status parse_id11_state(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
// Parses only the trim element of a payload. ``out`` receives the first trim
// element found; ``*present`` is false when the payload carries none. decode
// paths that need the OAMD calibration but no object state can use this
// without requiring an object element.
Status parse_trim(const std::uint8_t* payload, std::size_t payload_size, OamdTrim* out,
bool* present);
Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out,
ParseTrace* trace);
@@ -153,4 +311,7 @@ Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size,
Status parse_id11_bed_assignments(const std::uint8_t* payload, std::size_t payload_size,
std::vector<BedAssignment>* out);
// 10-bit standard bed mask -> 17-bit non-standard bed mask (5.6.1.1.4).
std::uint32_t standard_bed_mask(std::uint32_t bed_mask);
} // namespace joc::oamd
+34 -11
View File
@@ -8,32 +8,55 @@ namespace {
struct FrozenLayout {
const char* name;
const char* compact_name;
std::uint32_t out_ch_config;
std::uint32_t speaker_bitfield;
std::uint32_t surround_channels;
std::uint32_t height_channels;
bool carries_trim;
const char* const* channel_names;
};
const char* const kChannels20[] = {"L", "R"};
const char* const kChannels31[] = {"L", "R", "C", "LFE"};
const char* const kChannels40[] = {"L", "R", "Lrs", "Rrs"};
const char* const kChannels51[] = {"L", "R", "C", "LFE", "Ls", "Rs"};
const char* const kChannels71[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"};
const char* const kChannels512[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"};
const char* const kChannels514[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf",
"Ltr", "Rtr"};
const char* const kChannels712[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Ltm", "Rtm"};
const char* const kChannels714[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Ltf", "Rtf", "Ltr", "Rtr"};
const char* const kChannels914[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Lw", "Rw", "Ltf", "Rtf", "Ltr", "Rtr"};
const char* const kChannels916[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Lw", "Rw", "Ltf", "Rtf", "Ltm", "Rtm", "Ltr", "Rtr"};
const char* const kChannels60[] = {"L", "R", "Ls", "Rs", "Lrs", "Rrs"};
constexpr FrozenLayout kLayouts[kLayoutCount] = {
{"2.0", 0, 1, 0, 0, true},
{"3.1", 3, 7, 0, 0, true},
{"4.0", 0xFF, 9, 2, 0, true},
{"5.1", 7, 15, 2, 0, true},
{"7.1", 11, 31, 4, 0, true},
{"5.1.2", 13, 1039, 2, 2, true},
{"5.1.4", 14, 2575, 2, 4, true},
{"7.1.2", 15, 1055, 4, 2, false},
{"7.1.4", 16, 2591, 4, 4, false},
{"9.1.4", 19, 2719, 4, 4, false},
{"9.1.6", 20, 3743, 4, 6, false},
{"2.0", "20", 0, 1, 0, 0, true, kChannels20},
{"3.1", "31", 3, 7, 0, 0, true, kChannels31},
{"4.0", "40", 0xFF, 9, 2, 0, true, kChannels40},
{"5.1", "51", 7, 15, 2, 0, true, kChannels51},
{"7.1", "71", 11, 31, 4, 0, true, kChannels71},
{"5.1.2", "512", 13, 1039, 2, 2, true, kChannels512},
{"5.1.4", "514", 14, 2575, 2, 4, true, kChannels514},
{"7.1.2", "712", 15, 1055, 4, 2, false, kChannels712},
{"7.1.4", "714", 16, 2591, 4, 4, false, kChannels714},
{"9.1.4", "914", 19, 2719, 4, 4, false, kChannels914},
{"9.1.6", "916", 20, 3743, 4, 6, false, kChannels916},
{"6.0", "60", 0xFF, 25, 4, 0, false, kChannels60},
};
void fill(const FrozenLayout& source, LayoutInfo* out) {
out->name = source.name;
out->compact_name = source.compact_name;
out->out_ch_config = source.out_ch_config;
out->speaker_bitfield = source.speaker_bitfield;
out->channel_count = ejoc_speaker_layout_channel_count(source.speaker_bitfield);
out->channel_names = source.channel_names;
out->surround_channels = source.surround_channels;
out->height_channels = source.height_channels;
out->carries_trim = source.carries_trim;
+8 -3
View File
@@ -8,13 +8,18 @@
namespace joc::speaker {
inline constexpr int kLayoutCount = 11;
inline constexpr int kLayoutCount = 12;
struct LayoutInfo {
const char* name = "";
// The reference's compact layout key ("2.0" -> "20", ...), the key of the
// automatic-attenuation and divide-by-default tables.
const char* compact_name = "";
std::uint32_t out_ch_config = 0;
std::uint32_t speaker_bitfield = 0;
std::uint32_t channel_count = 0;
// Standard channel names in output order, ``channel_count`` entries.
const char* const* channel_names = nullptr;
// Ls/Rs/Lrs/Rrs and Ltf/Rtf/Ltr/Rtr/Ltm/Rtm, the labels the OAMD trim
// configuration index counts.
std::uint32_t surround_channels = 0;
@@ -24,8 +29,8 @@ struct LayoutInfo {
bool carries_trim = false;
};
// All eleven layouts in the reference's order (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, 9.1.6).
// All twelve layouts in the reference's order (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, 9.1.6, 6.0).
bool layout_at(int index, LayoutInfo* out);
// False when the name is unknown (case-sensitive, as the reference CLI). "4.0"
+68 -20
View File
@@ -39,7 +39,7 @@ struct LayoutGeometry {
std::array<RegionGeometry, 7> regions{};
};
inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
LayoutGeometry{
0x1u, 0, 2,
{{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
@@ -159,9 +159,9 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
2, 1, 1, 0,
{{SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
4, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
@@ -190,25 +190,25 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
{{
RegionGeometry{
5, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
5, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
5, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
3, 2, 2, 0,
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
@@ -220,7 +220,7 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
},
RegionGeometry{
2, 1, 1, 0,
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
@@ -286,25 +286,25 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
{{
RegionGeometry{
7, 3, 2, 1,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
7, 3, 2, 1,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
7, 3, 2, 1,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
5, 3, 2, 1,
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
@@ -316,7 +316,7 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
},
RegionGeometry{
4, 3, 1, 1,
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
@@ -334,25 +334,25 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
{{
RegionGeometry{
9, 3, 2, 2,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
9, 3, 2, 2,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
9, 3, 2, 2,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
7, 3, 2, 2,
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {3, 4, 0}}, AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}}}
},
@@ -364,7 +364,7 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
},
RegionGeometry{
6, 3, 1, 2,
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{2, {2, 3, 0}}, AxisGroup{2, {4, 5, 0}}, AxisGroup{}, AxisGroup{}}}
},
@@ -567,7 +567,55 @@ inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
}
}}
}
},
LayoutGeometry{
0x19u, 0xFFu, 6,
{{0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{{
RegionGeometry{
6, 2, 3, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{2, {4, 5, 0}}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
4, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
4, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
2, 2, 1, 0,
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
2, 1, 1, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
4, 2, 2, 0,
{{SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
2, 1, 1, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
}
}}
},
}};
inline constexpr const LayoutGeometry* find_layout(const std::uint32_t speaker_bitfield) noexcept {
+90
View File
@@ -0,0 +1,90 @@
// Port of the metadata application path of src/speaker_renderer.py HEAD.
//
// The metadata path consumes the full per-object per-block OAMD frame state and
// schedules block targets frame by frame: object gain/inactive, zone/elevation,
// snap, divergence, size kernel fusion, priority size budget, ISF basis rows and
// bed channel distribution, with the same float64 gain ramps and block alignment
// as the reference renderer.
#pragma once
#include <cstdint>
#include <memory>
#include <vector>
#include "eac3joc_core.h"
#include "foundation/status.h"
#include "oamd/oamd_parser.h"
#include "speaker/speaker_layout_lookup.h"
#include "speaker/speaker_trim.h"
namespace joc::speaker {
// One metadata target matrix: object_count x layout channel_count in the
// renderer's internal channel order, before the ramp/timing stage.
struct MetadataTargets {
std::uint32_t object_count = 0;
std::uint32_t channel_count = 0;
std::vector<double> values; // object major
double at(std::uint32_t object, std::uint32_t channel) const {
return values[static_cast<std::size_t>(object) * channel_count + channel];
}
};
// Computes the metadata target matrix of one block of a parsed frame without
// touching renderer state: the reference's _init_meta validation plus
// _block_targets. ``trim`` carries the current programme trim (bypass flags),
// ``controls`` the derived per-layout controls, ``size_budget`` the priority
// budget (0 means unlimited, the production value).
Status metadata_block_targets(const LayoutInfo& layout, const oamd::OamdUpdate& update,
std::uint32_t block_index,
const ejoc_speaker_controls& controls,
const oamd::OamdTrim* trim, std::uint32_t size_budget,
MetadataTargets* out);
// Stateful metadata-path renderer. It owns the object target ramps and the
// cross-block pending schedule; the legacy point-renderer state stays in the
// C ABI renderer, which is used for the blocks of a frame that precede the first
// metadata targets (the reference renders those with its legacy block path).
class MetaRenderer {
public:
MetaRenderer();
~MetaRenderer();
MetaRenderer(MetaRenderer&&) noexcept;
MetaRenderer& operator=(MetaRenderer&&) noexcept;
MetaRenderer(const MetaRenderer&) = delete;
MetaRenderer& operator=(const MetaRenderer&) = delete;
// Binds the target layout. Must be called once before process_frame().
Status configure(const LayoutInfo& layout);
// Drops the ramp, schedule and metadata state (the layout stays bound).
Status reset();
bool configured() const;
// True once a metadata frame has been accepted (the reference's _meta_mode).
bool engaged() const;
const char* last_error() const;
Status process_frame(ejoc_speaker_renderer_handle legacy,
const float* objects16_interleaved, std::uint32_t sample_count,
const oamd::OamdUpdate* update, std::uint32_t metadata_offset,
const ejoc_speaker_controls& controls, const oamd::OamdTrim* trim,
std::uint32_t raw_trim_mode, std::uint32_t size_budget,
double* output_interleaved);
// Computes the target matrix of one block of ``update`` into ``out`` using a
// scratch context; unlike metadata_block_targets() this validates through
// the renderer's own state-independent path.
Status block_targets(const oamd::OamdUpdate& update, std::uint32_t block_index,
const ejoc_speaker_controls& controls, const oamd::OamdTrim* trim,
std::uint32_t size_budget, MetadataTargets* out) const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace joc::speaker
File diff suppressed because it is too large. Load diff
+44 -10
View File
@@ -37,18 +37,52 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
}
context->controls_ready = true;
}
if (update != nullptr && update->has_trim) {
const Status status =
parameters_from_oamd(&update->trim, context->layout, &context->controls);
if (!status.ok()) {
if (error != nullptr) {
*error = status.message();
}
return status;
}
context->trim = update->trim;
context->has_trim = true;
context->raw_trim_mode = update->trim.global_trim_mode;
}
const bool metadata_frame =
update != nullptr && update->has_frame_state &&
update->frame_state.object_count != 0u;
if (metadata_frame || context->meta_engaged) {
if (!context->meta_configured) {
const Status configured = context->meta.configure(context->layout);
if (!configured.ok()) {
if (error != nullptr) {
*error = configured.message();
}
return configured;
}
context->meta_configured = true;
}
const oamd::OamdTrim* trim = context->has_trim ? &context->trim : nullptr;
const Status processed = context->meta.process_frame(
context->handle, context->interleaved.data(), JOC_FRAME_SAMPLES,
metadata_frame ? update : nullptr, context->metadata_offset,
context->controls, trim, context->raw_trim_mode, 0u,
context->output.data());
if (!processed.ok()) {
if (error != nullptr) {
*error = processed.message();
}
return processed;
}
context->meta_engaged = context->meta.engaged();
return Status::success();
}
std::uint32_t ramp = 0;
if (update != nullptr) {
if (update->has_trim) {
const Status status = parameters_from_oamd(&update->trim, context->layout,
&context->controls);
if (!status.ok()) {
if (error != nullptr) {
*error = status.message();
}
return status;
}
}
context->state.apply(*update);
ramp = update->ramp_duration_samples;
context->last_block_offset = update->block_offset_samples;
+11
View File
@@ -9,6 +9,7 @@
#include "foundation/status.h"
#include "oamd/oamd_parser.h"
#include "speaker/speaker_layout_lookup.h"
#include "speaker/speaker_meta.h"
#include "speaker/speaker_trim.h"
namespace joc::speaker {
@@ -32,6 +33,16 @@ struct SpeakerStep {
// 对象槽 → Q15 方位;bed_override 为 false 的槽仍按 OAMD 坐标声像。
std::uint16_t bed_positions[oamd::kObjects][oamd::kAxes] = {};
bool bed_override[oamd::kObjects] = {};
// Metadata path: a frame that carries the full per-object block state
// switches the speaker output to the metadata renderer. The programme trim
// element and its raw global mode stay here because the metadata path needs
// the per-object bypass flags and the ISF compensation mode.
MetaRenderer meta;
bool meta_configured = false;
bool meta_engaged = false;
oamd::OamdTrim trim{};
bool has_trim = false;
std::uint32_t raw_trim_mode = 0;
};
Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
+12 -3
View File
@@ -343,7 +343,14 @@ Status Stream::push_eac3(const std::uint8_t* data, std::size_t size, std::size_t
if (!extracted.ok()) {
return extracted;
}
const Status oamd = oamd::parse_id11(bytes.data(), bytes.size(), &pending_frame_.update);
// Speaker and binaural consume the full per-object block state; the
// other stream paths keep the reference's legacy single-block view.
const bool full_metadata_state = speaker_enabled_ || binaural_enabled_;
const Status oamd =
full_metadata_state ? oamd::parse_id11_state(bytes.data(), bytes.size(),
&pending_frame_.update)
: oamd::parse_id11(bytes.data(), bytes.size(),
&pending_frame_.update);
if (!oamd.ok()) {
return oamd;
}
@@ -536,8 +543,10 @@ Status Stream::process_ready_frames(bool drain_all) {
compact_bed_pending();
std::string error;
const Status rebuilt = joc::rebuild_objects16(rebuilder_, entry.params, bed5_.data(),
lfe_.data(), gain_, &objects16_, &error);
const Status rebuilt = joc::rebuild_objects16(
rebuilder_, entry.params, bed5_.data(), lfe_.data(),
static_cast<std::uint32_t>(core_channels), entry.has_joc, gain_, &objects16_,
&error);
if (!rebuilt.ok()) {
return Status::fail(rebuilt.code(), stage::kDsp, error);
}
+53 -6
View File
@@ -348,7 +348,7 @@ Status probe_atmos_trim(const std::string& path, std::uint64_t max_frames,
continue;
}
oamd::OamdUpdate update;
if (!oamd::parse_id11(bytes.data(), bytes.size(), &update).ok() ||
if (!oamd::parse_id11_state(bytes.data(), bytes.size(), &update).ok() ||
!update.has_trim) {
continue;
}
@@ -1429,6 +1429,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
return finalize_with_error(seeded.code(), "render", seeded.message());
}
speaker.controls_ready = true;
// The metadata path needs the programme trim before its own event
// arrives; the probe above read it from the leading frames.
speaker.trim = initial_trim;
speaker.has_trim = true;
speaker.raw_trim_mode = initial_trim.global_trim_mode;
}
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER, JOC_LOG_INFO,
fmt("speaker renderer: %s, %u channels", speaker.layout.name,
@@ -1590,6 +1595,9 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
// container that is not this frame's JOC metadata.
std::uint64_t missing_joc_frames = 0;
std::uint64_t objects_clamped_frames = 0;
std::uint64_t bad_parameter_band_frames = 0;
std::uint64_t bad_offset_ts_frames = 0;
std::uint64_t trailing_data_frames = 0;
std::uint64_t extra_container_frames = 0;
std::uint64_t chanmap_pair_mismatch_frames = 0;
std::uint64_t bed_mask_mismatch_frames = 0;
@@ -1660,6 +1668,19 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
if (params.objects_clamped != 0u) {
++objects_clamped_frames;
}
switch (params.status) {
case JOC_FRAME_STATUS_BAD_PARAMETER_BAND:
++bad_parameter_band_frames;
break;
case JOC_FRAME_STATUS_BAD_OFFSET_TS:
++bad_offset_ts_frames;
break;
case JOC_FRAME_STATUS_TRAILING_DATA:
++trailing_data_frames;
break;
default:
break;
}
} else {
++missing_joc_frames;
}
@@ -1691,8 +1712,9 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
}
std::string dsp_error;
const Status rebuilt = ::joc::joc::rebuild_objects16(
rebuilder, params, bed5.data(), lfe.data(), gain, &objects16,
&dsp_error);
rebuilder, params, bed5.data(), lfe.data(),
static_cast<std::uint32_t>(resolved_core_channels), has_joc, gain,
&objects16, &dsp_error);
if (!rebuilt.ok()) {
return Status::fail(rebuilt.code(), "joc", dsp_error);
}
@@ -1819,8 +1841,16 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
stream_done = true;
break;
}
// The speaker and binaural renderers consume the full per-object
// block state (multi-block and every declared object); the ADM
// export path keeps the reference's 15-track single-block view.
const bool full_metadata_state = speaker_enabled || binaural_enabled;
const Status oamd =
::joc::oamd::parse_id11(bytes.data(), bytes.size(), &job.update);
full_metadata_state
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
&job.update)
: ::joc::oamd::parse_id11(bytes.data(), bytes.size(),
&job.update);
if (!oamd.ok()) {
failures.record(produced, StageRank::kJoc, oamd.code(), oamd.stage(),
"frame " + std::to_string(produced) + ": " +
@@ -2166,11 +2196,28 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
joiner.shutdown(false);
if (missing_joc_frames != 0u) {
bus.warning(std::to_string(missing_joc_frames) +
" audio frame(s) carried no JOC payload; their object channels stay silent");
" audio frame(s) carried no JOC payload; their core PCM was passed "
"through (8 core planes, 1217-sample delay)");
}
if (objects_clamped_frames != 0u) {
bus.warning(std::to_string(objects_clamped_frames) +
" audio frame(s) declared more than 15 objects; the count was clamped to 15");
" audio frame(s) declared more than 15 objects; the count was clamped "
"to 15 and the frame took the invalid-frame path");
}
if (bad_parameter_band_frames != 0u) {
bus.warning(std::to_string(bad_parameter_band_frames) +
" audio frame(s) declared an unknown JOC parameter-band count; the "
"frame took the invalid-frame path");
}
if (bad_offset_ts_frames != 0u) {
bus.warning(std::to_string(bad_offset_ts_frames) +
" audio frame(s) carried an invalid JOC offset_ts value; the frame "
"took the invalid-frame path");
}
if (trailing_data_frames != 0u) {
bus.warning(std::to_string(trailing_data_frames) +
" audio frame(s) carried JOC data after the byte-alignment padding; "
"the frame took the invalid-frame path");
}
if (extra_container_frames != 0u) {
bus.warning(std::to_string(extra_container_frames) +
+165 -41
View File
@@ -95,37 +95,100 @@ Status ObjectPositionTrack::position_at(std::int64_t sample, double out[3]) {
return Status::success();
}
OamdPositionTimeline::OamdPositionTimeline(int object_count) : object_count_(object_count) {
if (object_count != kTimelineObjects) {
object_count_ = kTimelineObjects;
OamdPositionTimeline::OamdPositionTimeline(int object_count)
: object_count_(std::clamp(object_count, 1, oamd::kMaxObjects - 1)) {
const std::size_t count = static_cast<std::size_t>(object_count_);
tracks_.resize(count);
previous_targets_.resize(count);
has_previous_.assign(count, false);
fixed_.assign(count, false);
fixed_xyz_.resize(count);
}
void OamdPositionTimeline::ensure_tracks(int count) {
const int capped = std::clamp(count, 1, oamd::kMaxObjects - 1);
if (capped <= object_count_) {
return;
}
const std::size_t size = static_cast<std::size_t>(capped);
object_count_ = capped;
tracks_.resize(size);
previous_targets_.resize(size);
has_previous_.resize(size, false);
fixed_.resize(size, false);
fixed_xyz_.resize(size);
}
void OamdPositionTimeline::set_fixed_position(int object_index, const double position[3]) {
if (object_index < 1 || object_index > object_count_) {
return;
}
const std::size_t index = static_cast<std::size_t>(object_index - 1);
fixed_[index] = true;
for (int axis = 0; axis < 3; ++axis) {
fixed_xyz_[index][static_cast<std::size_t>(axis)] = position[axis];
}
}
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
std::int64_t frame_start_sample,
std::int64_t outer_sample_offset,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"OAMD frame, outer offset and object delay must be non-negative");
void OamdPositionTimeline::reset() {
state_.reset();
for (int index = 0; index < object_count_; ++index) {
tracks_[static_cast<std::size_t>(index)] = ObjectPositionTrack();
has_previous_[static_cast<std::size_t>(index)] = false;
previous_targets_[static_cast<std::size_t>(index)] = {0.0, 0.0, 0.0};
}
state_.apply(update);
initialized_ = false;
payload_count_ = 0;
transition_count_ = 0;
last_coded_event_sample_ = -1;
}
double targets[kTimelineObjects][3] = {};
for (int index = 0; index < kTimelineObjects; ++index) {
if (fixed_[index]) {
std::memcpy(targets[index], fixed_xyz_[index], sizeof(targets[index]));
void OamdPositionTimeline::apply_block(const oamd::FrameState& state,
std::uint32_t block_index) {
// Track i reads OAMD object i + 1: object 0 is the LFE/bed slot the JOC
// renderers do not position. Bed and ISF objects carry no position field,
// and an inactive block keeps the previous position, exactly like the
// reference frame_update() value construction.
for (int track = 0; track < object_count_; ++track) {
const int object_index = track + 1;
if (object_index >= static_cast<int>(state.objects.size())) {
break;
}
const oamd::ObjectElementState& element =
state.objects[static_cast<std::size_t>(object_index)];
if (block_index >= element.blocks.size()) {
continue;
}
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
state_.q(index + 1, 2), &targets[index][0], &targets[index][1],
&targets[index][2]);
const oamd::ObjectRenderState& render =
element.blocks[static_cast<std::size_t>(block_index)].render;
if (render.not_active || element.kind != oamd::ObjectKind::kDynamic) {
continue;
}
state_.apply_render_state(object_index, render);
}
}
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset +
static_cast<std::int64_t>(update.block_offset_samples);
void OamdPositionTimeline::targets(std::vector<std::array<double, 3>>* out) const {
out->resize(static_cast<std::size_t>(object_count_));
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
if (fixed_[slot]) {
(*out)[slot] = fixed_xyz_[slot];
continue;
}
double x = 0.0;
double y = 0.0;
double z = 0.0;
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
state_.q(index + 1, 2), &x, &y, &z);
(*out)[slot] = {x, y, z};
}
}
Status OamdPositionTimeline::schedule(const std::vector<std::array<double, 3>>& targets,
std::int64_t coded_event, std::int64_t ramp_samples,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (coded_event < last_coded_event_sample_) {
return timeline_fail(JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
"non_monotonic_binaural_updates: event sample " +
@@ -141,44 +204,105 @@ Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
"sample " + std::to_string(processed_sample) +
" had been processed, so sample 0 cannot be backfilled");
}
for (int index = 0; index < kTimelineObjects; ++index) {
tracks_[index].set_initial(targets[index]);
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
has_previous_[index] = true;
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
tracks_[slot].set_initial(targets[slot].data());
previous_targets_[slot] = targets[slot];
has_previous_[slot] = true;
}
initialized_ = true;
++payload_count_;
return Status::success();
}
const std::int64_t effective_ramp =
std::max<std::int64_t>(0, static_cast<std::int64_t>(update.ramp_duration_samples));
const std::int64_t effective_ramp = std::max<std::int64_t>(0, ramp_samples);
const std::int64_t transition_start =
timing::align_metadata_sample(coded_event + object_delay_samples);
for (int index = 0; index < kTimelineObjects; ++index) {
const bool changed = !has_previous_[index] ||
std::memcmp(previous_targets_[index], targets[index],
sizeof(targets[index])) != 0;
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
const bool changed =
!has_previous_[slot] ||
std::memcmp(previous_targets_[slot].data(), targets[slot].data(),
sizeof(targets[slot])) != 0;
if (!changed) {
continue;
}
const Status status = tracks_[index].append(transition_start, effective_ramp,
targets[index], index + 1);
const Status status =
tracks_[slot].append(transition_start, effective_ramp, targets[slot].data(),
index + 1);
if (!status.ok()) {
return status;
}
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
has_previous_[index] = true;
previous_targets_[slot] = targets[slot];
has_previous_[slot] = true;
++transition_count_;
}
return Status::success();
}
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
std::int64_t frame_start_sample,
std::int64_t outer_sample_offset,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"OAMD frame, outer offset and object delay must be non-negative");
}
if (!update.has_frame_state) {
state_.apply(update);
targets(&targets_);
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset +
static_cast<std::int64_t>(update.block_offset_samples);
const Status status =
schedule(targets_, coded_event, update.ramp_duration_samples, object_delay_samples,
processed_sample);
if (status.ok()) {
++payload_count_;
}
return status;
}
const oamd::FrameState& state = update.frame_state;
ensure_tracks(state.object_count > 0u ? static_cast<int>(state.object_count) - 1 : 0);
const std::uint32_t block_count =
state.blocks.empty() ? 1u : static_cast<std::uint32_t>(state.blocks.size());
for (std::uint32_t block = 0; block < block_count; ++block) {
apply_block(state, block);
targets(&targets_);
std::int64_t block_offset = 0;
std::int64_t ramp_samples = 0;
if (block < state.blocks.size()) {
block_offset = static_cast<std::int64_t>(state.blocks[block].block_offset_samples);
ramp_samples = static_cast<std::int64_t>(state.blocks[block].ramp_duration_samples);
}
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset + block_offset;
const Status status = schedule(targets_, coded_event, ramp_samples,
object_delay_samples, processed_sample);
if (!status.ok()) {
return status;
}
}
++payload_count_;
return Status::success();
}
Status OamdPositionTimeline::positions_at(std::int64_t sample,
double positions[kTimelineObjects][3]) {
for (int index = 0; index < kTimelineObjects; ++index) {
const Status status = tracks_[index].position_at(sample, positions[index]);
Status OamdPositionTimeline::positions_at(std::int64_t sample, double* positions,
int count) {
if (positions == nullptr || count < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"binaural positions need a non-negative count and a buffer");
}
if (count > object_count_) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"binaural positions requested " + std::to_string(count) +
" objects but the timeline tracks " +
std::to_string(object_count_));
}
for (int index = 0; index < count; ++index) {
const Status status = tracks_[static_cast<std::size_t>(index)].position_at(
sample, positions + static_cast<std::size_t>(index) * 3u);
if (!status.ok()) {
return status;
}
+34 -31
View File
@@ -2,6 +2,7 @@
#pragma once
#include <array>
#include <cstdint>
#include <vector>
@@ -10,6 +11,11 @@
namespace joc::timeline {
// The JOC binaural renderers carry one LFE plus fifteen object sources, but the
// timeline is not tied to that product: it keeps one track per declared OAMD
// object (bounded only by oamd::kMaxObjects) and the renderer reads as many as
// its source layout consumes. A binaural output with a different source count
// (for example one fed by a TrueHD decode) can ask for more tracks.
inline constexpr int kTimelineObjects = 15;
struct PositionTransition {
@@ -42,56 +48,53 @@ class OamdPositionTimeline {
public:
explicit OamdPositionTimeline(int object_count = kTimelineObjects);
// Schedules one OAMD payload. A payload parsed by parse_id11_state() carries
// the full frame state: every position block is applied at its own offset and
// ramp, and the track list grows to cover every declared object. The legacy
// single-block slot view is still accepted for direct callers.
Status submit_update(const oamd::OamdUpdate& update, std::int64_t frame_start_sample,
std::int64_t outer_sample_offset, std::int64_t object_delay_samples,
std::int64_t processed_sample);
// positions[15][3]; queries must be monotonically increasing.
Status positions_at(std::int64_t sample, double positions[kTimelineObjects][3]);
// positions[count][3]; queries must be monotonically increasing.
Status positions_at(std::int64_t sample, double* positions, int count);
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
void set_fixed_position(int object_index, const double position[3]) {
if (object_index < 1 || object_index > kTimelineObjects) {
return;
}
fixed_[object_index - 1] = true;
fixed_xyz_[object_index - 1][0] = position[0];
fixed_xyz_[object_index - 1][1] = position[1];
fixed_xyz_[object_index - 1][2] = position[2];
}
void set_fixed_position(int object_index, const double position[3]);
// Drops the OAMD state and every transition but keeps the fixed bed positions:
// they describe the content, not the playback position.
void reset() {
state_.reset();
for (int index = 0; index < kTimelineObjects; ++index) {
tracks_[index] = ObjectPositionTrack();
has_previous_[index] = false;
for (int axis = 0; axis < 3; ++axis) {
previous_targets_[index][axis] = 0.0;
}
}
initialized_ = false;
payload_count_ = 0;
transition_count_ = 0;
last_coded_event_sample_ = -1;
}
void reset();
int object_count() const { return object_count_; }
std::uint64_t payload_count() const { return payload_count_; }
std::uint64_t transition_count() const { return transition_count_; }
bool initialized() const { return initialized_; }
const ObjectPositionTrack& track(int index) const { return tracks_[index]; }
const ObjectPositionTrack& track(int index) const { return tracks_[static_cast<std::size_t>(index)]; }
private:
// Grows the track list so every declared OAMD object has one (the JOC
// renderers use the first kTimelineObjects).
void ensure_tracks(int count);
// OAMD position state after applying one frame-state block.
void apply_block(const oamd::FrameState& state, std::uint32_t block_index);
// Current ADM cartesian target of every track.
void targets(std::vector<std::array<double, 3>>* out) const;
// Initialises from the first update or appends the changed transitions.
Status schedule(const std::vector<std::array<double, 3>>& targets,
std::int64_t coded_event, std::int64_t ramp_samples,
std::int64_t object_delay_samples, std::int64_t processed_sample);
int object_count_;
oamd::OamdState state_;
ObjectPositionTrack tracks_[kTimelineObjects];
std::vector<ObjectPositionTrack> tracks_;
bool initialized_ = false;
double previous_targets_[kTimelineObjects][3] = {};
bool has_previous_[kTimelineObjects] = {};
bool fixed_[kTimelineObjects] = {};
double fixed_xyz_[kTimelineObjects][3] = {};
std::vector<std::array<double, 3>> previous_targets_;
std::vector<bool> has_previous_;
std::vector<bool> fixed_;
std::vector<std::array<double, 3>> fixed_xyz_;
std::vector<std::array<double, 3>> targets_;
std::uint64_t payload_count_ = 0;
std::uint64_t transition_count_ = 0;
std::int64_t last_coded_event_sample_ = -1;
+725 -11
View File
@@ -19,6 +19,8 @@
#include "hrtf/jochrtf.h"
#include "hrtf/rosella_model.h"
#include "hrtf/rosella_renderer.h"
#include "joc_bitstream/joc_huffman_tables.h"
#include "joc_bitstream/joc_parser.h"
#include "foundation/mini_json.h"
#include "foundation/sha256.h"
#include "io/inflate.h"
@@ -33,6 +35,7 @@
#include "speaker/speaker_trim.h"
#include "stream/stream.h"
#include "task/task.h"
#include "timeline/position_timeline.h"
namespace {
@@ -580,8 +583,8 @@ void test_speaker_warp_and_trim() {
CHECK(joc::speaker::parameters_from_oamd(nullptr, layout514, &automatic514).ok());
// Warp 0 leaves the floor Y alone; warp 1 doubles it before the clamp.
const std::vector<double> warp0 = {0.9126902722074105, 0, 0, 0, 0.18155106823708969, 0};
const std::vector<double> warp1 = {0.85973219419392444, 0, 0, 0, 0.35612480624995158, 0};
const std::vector<double> warp0 = {0.85973646214220434, 0, 0, 0, 0.35611450268596406, 0};
const std::vector<double> warp1 = {0.65801380052399572, 0, 0, 0, 0.65801380052399572, 0};
const std::vector<double> clamped = {0, 0, 0, 0, 0.70794578438413791, 0};
check_gains(speaker_gains(layout51, automatic51, 0, 4096, 0), warp0);
ejoc_speaker_controls warped = automatic51;
@@ -605,10 +608,10 @@ void test_speaker_warp_and_trim() {
explicit_controls.surround_db = -6.0;
explicit_controls.listener_balance = 9.0 / 16.0;
explicit_controls.overhead_balance = -9.0 / 16.0;
const std::vector<double> trimmed = {0.68117911059016056, 0, 0, 0, 0.41744281702545366, 0};
const std::vector<double> trimmed = {0.36269933962647599, 0, 0, 0, 0.71183753429070229, 0};
check_gains(speaker_gains(layout51, explicit_controls, 0, 4096, 0), trimmed);
// Per-object bypass keeps warp but drops balance and trim.
const std::vector<double> bypassed = {0.92387494614065435, 0, 0, 0, 0.38269450465561039, 0};
const std::vector<double> bypassed = {0.70710678118654757, 0, 0, 0, 0.70710678118654757, 0};
check_gains(speaker_gains(layout51, explicit_controls, 0, 4096, 0, true), bypassed);
// Centre trim is local to the front-centre region; height trim scales with Z.
@@ -789,7 +792,7 @@ void test_speaker_step_trim_events() {
update.trim.global_trim_mode = 0;
update.trim.object_count = 16;
CHECK(joc::speaker::step(&step, frame, &update, &error).ok());
const std::vector<double> warp1 = {0.85973219419392444, 0, 0, 0, 0.35612480624995158, 0};
const std::vector<double> warp1 = {0.65801380052399572, 0, 0, 0, 0.65801380052399572, 0};
std::vector<double> gains(step.layout.channel_count);
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
@@ -803,8 +806,8 @@ void test_speaker_step_trim_events() {
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
}
const std::vector<double> half_warp1 = {0.9461247896349676, 0, 0, 0,
0.18820181552760662, 0};
const std::vector<double> half_warp1 = {0.89123112643513935, 0, 0, 0,
0.36916001977848539, 0};
check_gains(gains, half_warp1);
// A new trim element switches the controls back to warp 0.
@@ -818,8 +821,8 @@ void test_speaker_step_trim_events() {
for (std::uint32_t channel = 0; channel < step.layout.channel_count; ++channel) {
gains[channel] = step.output[read + channel];
}
const std::vector<double> half_warp0 = {0.96001622724230795, 0, 0, 0,
0.094556249720175942, 0};
const std::vector<double> half_warp0 = {0.94612591737884011, 0, 0, 0,
0.18819614606507579, 0};
check_gains(gains, half_warp0);
// A warp 2 element renders through the expanded layout and folds.
@@ -1399,8 +1402,20 @@ void test_clipgain_first_frame_uses_its_own_gain() {
// A fresh handle takes the current gain with no transition.
CHECK(peak > 1.0e-3f);
CHECK(scaled);
// LFE bypasses the scalar, so its samples are bit-identical.
CHECK(std::memcmp(unity.data(), doubled.data(), sizeof(float) * EJOC_FRAME_SAMPLES) == 0);
// The LFE now carries the same full clipgain: a fresh ring starts with 1217
// zero samples and the rest scales by the frame's gain (2x is exact).
bool lfe_scaled = true;
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
if (doubled[static_cast<std::size_t>(sample)] !=
2.0f * unity[static_cast<std::size_t>(sample)]) {
lfe_scaled = false;
break;
}
}
CHECK(lfe_scaled);
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(unity[static_cast<std::size_t>(sample)] == 0.0f);
}
}
void test_clipgain_change_applies_to_the_current_frame() {
@@ -1480,6 +1495,698 @@ void test_clipgain_reset_clears_the_previous_gain() {
sizeof(float) * after_reset.size()) == 0);
}
// ---------------------------------------------------------------------------
// JOC frame-level core: clipgain formula, frame status, offset_ts validation,
// LFE clipgain ramp, 8-plane passthrough, seq state machine and the
// no-previous-state interpolation rules.
// ---------------------------------------------------------------------------
struct JocBitWriter {
std::vector<std::uint8_t> bytes;
std::size_t bit_count = 0;
void write(std::uint32_t value, int count) {
for (int index = count - 1; index >= 0; --index) {
if ((bit_count & 7u) == 0u) {
bytes.push_back(0u);
}
if (((value >> index) & 1u) != 0u) {
bytes.back() |= static_cast<std::uint8_t>(1u << (7u - (bit_count & 7u)));
}
++bit_count;
}
}
};
bool huffman_path(const int (*nodes)[2], int count, int value, std::vector<int>* path) {
struct Entry {
int node;
std::vector<int> path;
};
std::vector<Entry> queue;
queue.push_back({0, {}});
for (std::size_t index = 0; index < queue.size() && index < 4096u; ++index) {
const int node = queue[index].node;
if (node < 0) {
if (-node - 1 == value) {
*path = queue[index].path;
return true;
}
continue;
}
if (node >= count) {
continue;
}
std::vector<int> left = queue[index].path;
left.push_back(0);
queue.push_back({nodes[node][0], std::move(left)});
std::vector<int> right = queue[index].path;
right.push_back(1);
queue.push_back({nodes[node][1], std::move(right)});
}
return false;
}
void write_huffman_symbol(JocBitWriter* writer, const int (*nodes)[2], int count, int value) {
std::vector<int> path;
CHECK(huffman_path(nodes, count, value, &path));
for (const int bit : path) {
writer->write(static_cast<std::uint32_t>(bit), 1);
}
}
// One synthetic ID14 payload with at most one present object (object 0), one
// parameter band, dense syntax and 5 core channels.
struct Id14Spec {
std::uint8_t dmx_config_idx = 3;
std::uint32_t num_objects_bits = 0; // declares one object
std::uint8_t ext_config_idx = 0;
std::uint8_t clipgain_x = 4;
std::uint8_t clipgain_y = 0;
std::uint32_t seq = 1;
bool present = false;
std::uint8_t n_bands_idx = 0; // one parameter band
std::uint8_t sparse = 0;
std::uint8_t quant = 0;
std::uint8_t slope = 0;
bool two_data_points = false;
std::uint8_t offset0 = 0;
std::uint8_t offset1 = 0;
bool trailing = false;
};
std::vector<std::uint8_t> make_id14_payload(const Id14Spec& spec) {
JocBitWriter writer;
writer.write(spec.dmx_config_idx, 3);
writer.write(spec.num_objects_bits, 6);
writer.write(spec.ext_config_idx, 3);
writer.write(spec.clipgain_x, 3);
writer.write(spec.clipgain_y, 5);
writer.write(spec.seq, 10);
const std::uint32_t declared = spec.num_objects_bits + 1u;
const std::uint32_t objects = declared > 15u ? 15u : declared;
for (std::uint32_t object = 0; object < objects; ++object) {
const bool present = object == 0u && spec.present;
writer.write(present ? 1u : 0u, 1);
if (!present) {
continue;
}
writer.write(spec.n_bands_idx, 3);
writer.write(spec.sparse, 1);
writer.write(spec.quant, 1);
writer.write(spec.slope, 1);
writer.write(spec.two_data_points ? 1u : 0u, 1);
if (spec.slope == 1u) {
writer.write(spec.offset0, 5);
if (spec.two_data_points) {
writer.write(spec.offset1, 5);
}
}
}
if (spec.present && spec.sparse == 0u) {
constexpr int kCount = static_cast<int>(sizeof(joc_huff_code_coarse_generic) /
sizeof(joc_huff_code_coarse_generic[0]));
const int points = spec.two_data_points ? 2 : 1;
for (int point = 0; point < points; ++point) {
for (int channel = 0; channel < 5; ++channel) {
write_huffman_symbol(&writer, joc_huff_code_coarse_generic, kCount, 0);
}
}
}
while ((writer.bit_count & 7u) != 0u) {
writer.write(0u, 1);
}
if (spec.trailing) {
writer.bytes.push_back(0u);
writer.bytes.push_back(0u);
}
return writer.bytes;
}
void test_joc_clipgain_formula() {
struct Case {
std::uint8_t x;
std::uint8_t y;
double expected;
};
const Case cases[] = {
{0, 0, 0.0625}, {2, 8, 0.3125}, {3, 0, 0.5}, {4, 0, 1.0},
{4, 16, 1.5}, {5, 16, 3.0}, {7, 31, 15.75},
};
for (const Case& item : cases) {
Id14Spec spec;
spec.clipgain_x = item.x;
spec.clipgain_y = item.y;
spec.seq = 7;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_OK);
CHECK(params.clipgain == item.expected);
CHECK(params.seq_count == 7u);
CHECK(params.n_channels == 5u);
}
}
void test_joc_parse_status_and_offset_ts() {
// Unsupported downmix configuration: status 2, and the object syntax is not
// expanded because the core channel count is unknown.
{
Id14Spec spec;
spec.dmx_config_idx = 5;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX);
CHECK(params.n_channels == 0u);
CHECK(params.n_objects == 0u);
}
// More than 15 declared objects: the count is clamped and the
// corresponding frame status is reported, while the frame still parses.
{
Id14Spec spec;
spec.num_objects_bits = 15; // declares 16 objects
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_OBJECTS_CLAMPED);
CHECK(params.objects_clamped == 1u);
CHECK(params.n_objects == 15u);
CHECK(params.n_channels == 5u);
}
// Legal raw 5-bit offset_ts values stay as coded (no +1).
{
Id14Spec spec;
spec.present = true;
spec.slope = 1;
spec.two_data_points = true;
spec.offset0 = 5;
spec.offset1 = 10;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_OK);
CHECK(params.objects[0].offset_ts[0] == 5u);
CHECK(params.objects[0].offset_ts[1] == 10u);
CHECK(params.objects[0].n_dpoints == 2u);
CHECK((params.present_mask & 1u) != 0u);
}
// offset_ts outside 0..23 -> status 5.
{
Id14Spec spec;
spec.present = true;
spec.slope = 1;
spec.two_data_points = true;
spec.offset0 = 24;
spec.offset1 = 25;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_BAD_OFFSET_TS);
CHECK(params.objects[0].offset_ts[0] == 24u);
}
// Non-increasing offset_ts -> status 5.
{
Id14Spec spec;
spec.present = true;
spec.slope = 1;
spec.two_data_points = true;
spec.offset0 = 10;
spec.offset1 = 10;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_BAD_OFFSET_TS);
}
// Data after the byte alignment of joc_data -> status 6.
{
Id14Spec spec;
spec.present = true;
spec.trailing = true;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_TRAILING_DATA);
CHECK(params.trailing_bits > 0u);
}
// The same payload without the extra bytes is a normal frame.
{
Id14Spec spec;
spec.present = true;
const std::vector<std::uint8_t> payload = make_id14_payload(spec);
joc_frame_params params{};
CHECK(joc::joc::parse_id14(payload.data(), payload.size(), &params, nullptr).ok());
CHECK(params.status == JOC_FRAME_STATUS_OK);
CHECK(params.objects[0].n_bands == 1u);
CHECK(params.present_mask == 1u);
}
}
// Synthetic audio frames driven through the frame-level kernel.
struct FrameCase {
ejoc_renderer_handle handle = nullptr;
std::vector<float> bed;
std::vector<float> lfe;
std::uint8_t n_bands[EJOC_MAX_OBJECTS] = {};
std::uint8_t n_dpoints[EJOC_MAX_OBJECTS] = {};
std::uint8_t slope[EJOC_MAX_OBJECTS] = {};
std::uint8_t offsets[EJOC_MAX_OBJECTS * EJOC_MAX_DPOINTS] = {};
std::vector<double> dq;
std::vector<float> out;
FrameCase()
: bed(static_cast<std::size_t>(EJOC_MAX_CORE_CHANNELS) * EJOC_FRAME_SAMPLES, 0.0f),
lfe(EJOC_FRAME_SAMPLES, 0.0f),
dq(static_cast<std::size_t>(EJOC_MAX_OBJECTS) * EJOC_MAX_DPOINTS *
EJOC_MAX_CORE_CHANNELS * EJOC_MAX_PARAMETER_BANDS,
0.0),
out(static_cast<std::size_t>(EJOC_OUTPUT_CHANNELS) * EJOC_FRAME_SAMPLES, 0.0f) {}
~FrameCase() {
if (handle != nullptr) {
ejoc_renderer_destroy(handle);
}
}
void create() {
handle = ejoc_renderer_create();
ejoc_renderer_set_threads(handle, 1);
}
static std::size_t dq_index(int object, int point, int channel, int band) {
return static_cast<std::size_t>(
(((object * EJOC_MAX_DPOINTS + point) * EJOC_MAX_CORE_CHANNELS + channel) *
EJOC_MAX_PARAMETER_BANDS) +
band);
}
float at(int channel, int sample) const {
return out[static_cast<std::size_t>(channel) * EJOC_FRAME_SAMPLES + sample];
}
bool silent_slots(int first_channel, int last_channel) const {
for (int channel = first_channel; channel <= last_channel; ++channel) {
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
if (at(channel, sample) != 0.0f) {
return false;
}
}
}
return true;
}
bool render(std::uint32_t core_channels, std::uint32_t declared_channels,
std::uint32_t status, std::uint32_t seq, bool has_metadata,
std::uint32_t object_mask, double clipgain) {
ejoc_frame_input input{};
input.struct_size = sizeof(input);
input.struct_version = EJOC_FRAME_INPUT_VERSION;
input.bed_planar = bed.data();
input.lfe = lfe.data();
input.core_channel_count = core_channels;
input.declared_core_channels = declared_channels;
input.phase_shift = 0u;
input.phase_shift_valid = 1u;
input.frame_status = status;
input.seq = seq;
input.has_metadata = has_metadata ? 1u : 0u;
input.object_mask = object_mask;
input.n_bands = n_bands;
input.n_dpoints = n_dpoints;
input.slope_idx = slope;
input.offset_ts = offsets;
input.dq = dq.data();
input.clipgain = clipgain;
input.output_scale = 1.0f;
input.output16_planar = out.data();
std::fill(out.begin(), out.end(), 0.0f);
return ejoc_renderer_render_frame(handle, &input) == 0;
}
};
void fill_frame_bed(FrameCase* frame, float step, float lfe_value) {
for (std::uint32_t channel = 0; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame->bed[static_cast<std::size_t>(channel) * EJOC_FRAME_SAMPLES + sample] =
step * static_cast<float>(channel + 1u);
}
}
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame->lfe[sample] = lfe_value;
}
}
bool near(float value, float expected, float tolerance) {
return std::fabs(value - expected) <= tolerance;
}
void test_joc_lfe_clipgain_ramp() {
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.01f, 0.1f);
// First frame: gain 1, the delay ring is empty.
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 0u, 1.0));
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(frame.at(0, sample) == 0.0f);
}
for (int sample = JOC_LFE_DELAY_SAMPLES; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(0, sample) == 0.1f);
}
// Second frame: gain 2 ramps over the frame-local first 256 samples before the
// delay; the read-out of the first frame is untouched by the new gain.
frame.lfe.assign(EJOC_FRAME_SAMPLES, 0.2f);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 2u, true, 0u, 2.0));
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(frame.at(0, sample) == 0.1f);
}
for (int input = 0; input < static_cast<int>(EJOC_FRAME_SAMPLES) - static_cast<int>(JOC_LFE_DELAY_SAMPLES); ++input) {
const double gain = input < 256
? 1.0 + static_cast<double>(input) * ((2.0 - 1.0) / 256.0)
: 2.0;
const double scaled = static_cast<double>(frame.lfe[static_cast<std::size_t>(input)]) *
gain;
const double clipped = scaled < -1.0 ? -1.0 : (scaled > 1.0 ? 1.0 : scaled);
CHECK(frame.at(0, JOC_LFE_DELAY_SAMPLES + input) ==
static_cast<float>(clipped));
}
// A held frame (invalid status while normal) reuses the held clipgain: the
// analysis scalar was 1/16*2, so the LFE gain stays 2 with no new ramp.
frame.lfe.assign(EJOC_FRAME_SAMPLES, 0.3f);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 5u, 3u, true, 0u, 2.0));
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(frame.at(0, sample) == 0.4f);
}
for (int sample = JOC_LFE_DELAY_SAMPLES; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(0, sample) == 0.6f);
}
}
void test_joc_passthrough_8_plane_layout() {
// 5-channel core: slots 0..5 = L,R,C,LFE,Ls,Rs and slots 6..7 stay zero.
{
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.1f, 0.25f);
CHECK(frame.render(EJOC_CORE_CHANNELS, 0u, EJOC_FRAME_STATUS_NO_METADATA, 0u, false,
0u, 1.0));
float expected[8] = {};
for (int channel = 0; channel < 3; ++channel) {
expected[channel] = frame.bed[static_cast<std::size_t>(channel) * EJOC_FRAME_SAMPLES];
}
expected[3] = frame.lfe[0];
for (int index = 0; index < 2; ++index) {
expected[4 + index] =
frame.bed[static_cast<std::size_t>(3 + index) * EJOC_FRAME_SAMPLES];
}
for (int channel = 0; channel < 8; ++channel) {
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(frame.at(channel, sample) == 0.0f);
}
for (int sample = JOC_LFE_DELAY_SAMPLES; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(channel, sample) == expected[channel]);
}
}
CHECK(frame.silent_slots(8, EJOC_OUTPUT_CHANNELS - 1));
// The 8-plane history is kept every frame: the next passthrough frame
// reads the previous frame's last 1217 samples.
fill_frame_bed(&frame, 0.05f, 0.125f);
CHECK(frame.render(EJOC_CORE_CHANNELS, 0u, EJOC_FRAME_STATUS_NO_METADATA, 0u, false,
0u, 1.0));
float previous[8] = {};
float current[8] = {};
for (int channel = 0; channel < 3; ++channel) {
current[channel] = frame.bed[static_cast<std::size_t>(channel) * EJOC_FRAME_SAMPLES];
}
current[3] = frame.lfe[0];
for (int index = 0; index < 2; ++index) {
current[4 + index] =
frame.bed[static_cast<std::size_t>(3 + index) * EJOC_FRAME_SAMPLES];
}
previous[0] = 0.1f;
previous[1] = 0.2f;
previous[2] = 0.3f;
previous[3] = 0.25f;
previous[4] = 0.4f;
previous[5] = 0.5f;
for (int channel = 0; channel < 8; ++channel) {
for (int sample = 0; sample < JOC_LFE_DELAY_SAMPLES; ++sample) {
CHECK(frame.at(channel, sample) == previous[channel]);
}
for (int sample = JOC_LFE_DELAY_SAMPLES; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(channel, sample) == current[channel]);
}
}
}
// 7-channel core: the extra pair is written to slots 6 and 7.
{
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.01f, 0.07f);
CHECK(frame.render(EJOC_MAX_CORE_CHANNELS, 0u, EJOC_FRAME_STATUS_NO_METADATA, 0u,
false, 0u, 1.0));
float expected[8] = {};
for (int channel = 0; channel < 3; ++channel) {
expected[channel] = frame.bed[static_cast<std::size_t>(channel) * EJOC_FRAME_SAMPLES];
}
expected[3] = frame.lfe[0];
for (int index = 0; index < 4; ++index) {
expected[4 + index] =
frame.bed[static_cast<std::size_t>(3 + index) * EJOC_FRAME_SAMPLES];
}
for (int channel = 0; channel < 8; ++channel) {
for (int sample = JOC_LFE_DELAY_SAMPLES; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(channel, sample) == expected[channel]);
}
}
CHECK(frame.silent_slots(8, EJOC_OUTPUT_CHANNELS - 1));
}
}
// One present object that passes core channel 0 through with an all-ones matrix,
// so normal rendering produces a non-zero object slot and every other mode does
// not.
void configure_passthrough_object(FrameCase* frame) {
frame->n_bands[0] = 1;
frame->n_dpoints[0] = 1;
frame->dq[FrameCase::dq_index(0, 0, 0, 0)] = 1.0;
}
float object_peak(const FrameCase& frame, int object_channel) {
float peak = 0.0f;
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
peak = std::max(peak, std::fabs(frame.at(object_channel, sample)));
}
return peak;
}
void test_joc_frame_state_machine() {
// seq 0 on the first frame is not a hard cut, and a mismatch later is.
{
FrameCase frame;
frame.create();
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame.bed[static_cast<std::size_t>(sample)] =
static_cast<float>(0.2 * std::sin(static_cast<double>(sample) * 0.05));
}
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 0u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
// Expected seq becomes 1; seq 2 is a mismatch -> hard cut publishes zeros.
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 2u, true, 1u, 1.0));
CHECK(frame.silent_slots(0, EJOC_OUTPUT_CHANNELS - 1));
// The next valid frame resyncs and renders normally again.
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 3u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
// A seq that restarts at 0 is a hard cut as well.
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 0u, true, 1u, 1.0));
CHECK(frame.silent_slots(0, EJOC_OUTPUT_CHANNELS - 1));
}
// A frame without JOC metadata always passes the core through, even while
// the renderer is in its normal state.
{
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.1f, 0.2f);
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
CHECK(frame.render(EJOC_CORE_CHANNELS, 0u, EJOC_FRAME_STATUS_NO_METADATA, 0u, false,
1u, 1.0));
CHECK(frame.silent_slots(8, EJOC_OUTPUT_CHANNELS - 1));
CHECK(frame.at(0, EJOC_FRAME_SAMPLES - 1) != 0.0f);
}
// Invalid frames hold the previous matrices; after six of them the state
// machine stays in hold and a valid frame still resyncs.
{
FrameCase frame;
frame.create();
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame.bed[static_cast<std::size_t>(sample)] =
static_cast<float>(0.2 * std::sin(static_cast<double>(sample) * 0.05));
}
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
for (int invalid = 0; invalid < 6; ++invalid) {
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 5u, 2u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
}
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 100u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
}
// A declared core-channel-count change is a hard cut that clears the LFE
// ring: the next frame reads only the samples written after the change.
{
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.1f, 0.1f);
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u, 1.0));
frame.lfe.assign(EJOC_FRAME_SAMPLES, 0.5f);
// The frame that declares the change keeps its own clipgain (2.0) even
// though it renders as a hard cut: it clears the LFE ring and refills it
// with the new gain before the next frame reads it out.
CHECK(frame.render(EJOC_MAX_CORE_CHANNELS, EJOC_MAX_CORE_CHANNELS, 0u, 2u, true, 1u,
2.0));
CHECK(frame.silent_slots(0, EJOC_OUTPUT_CHANNELS - 1));
CHECK(frame.render(EJOC_MAX_CORE_CHANNELS, EJOC_MAX_CORE_CHANNELS, 0u, 3u, true, 1u,
1.0));
CHECK(near(frame.at(0, 0), 1.0f, 1.0e-6f));
CHECK(near(frame.at(0, JOC_LFE_DELAY_SAMPLES), 1.0f, 1.0e-6f));
// Samples past the 256-sample ramp use the frame's own gain again.
CHECK(near(frame.at(0, JOC_LFE_DELAY_SAMPLES + 300), 0.5f, 1.0e-6f));
}
}
void test_joc_no_previous_interpolation() {
auto prepare = [](FrameCase* frame) {
frame->create();
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
frame->bed[static_cast<std::size_t>(sample)] =
static_cast<float>(0.2 * std::sin(static_cast<double>(sample) * 0.05));
}
frame->n_bands[0] = 1;
frame->dq[FrameCase::dq_index(0, 0, 0, 0)] = 0.0;
};
// A two-data-point frame without previous state keeps dp0 in the first half
// and still interpolates dp0 -> dp1 in the second half, exactly like the
// same frame with a previous state equal to dp0.
{
FrameCase with_previous;
prepare(&with_previous);
with_previous.n_dpoints[0] = 1;
CHECK(with_previous.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u,
1.0));
FrameCase without_previous;
prepare(&without_previous);
CHECK(without_previous.render(EJOC_CORE_CHANNELS, 0u,
EJOC_FRAME_STATUS_NO_METADATA, 0u, false, 1u, 1.0));
for (FrameCase* frame : {&with_previous, &without_previous}) {
frame->n_dpoints[0] = 2;
frame->dq[FrameCase::dq_index(0, 0, 0, 0)] = 0.0;
frame->dq[FrameCase::dq_index(0, 1, 0, 0)] = 1.0;
CHECK(frame->render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 2u, true, 1u,
1.0));
}
CHECK(with_previous.out == without_previous.out);
}
// A single data point without previous state is a hard cut, not a fade from
// zero: the same target with a previous state of zero ramps instead.
{
FrameCase with_previous;
prepare(&with_previous);
with_previous.n_dpoints[0] = 1;
CHECK(with_previous.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u,
1.0));
FrameCase without_previous;
prepare(&without_previous);
CHECK(without_previous.render(EJOC_CORE_CHANNELS, 0u,
EJOC_FRAME_STATUS_NO_METADATA, 0u, false, 1u, 1.0));
for (FrameCase* frame : {&with_previous, &without_previous}) {
frame->n_dpoints[0] = 1;
frame->dq[FrameCase::dq_index(0, 0, 0, 0)] = 1.0;
CHECK(frame->render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 2u, true, 1u,
1.0));
}
CHECK(with_previous.out != without_previous.out);
}
// An object that disappears keeps being published as an all-zero matrix:
// the synthesis state still advances, so only the window tail of the
// preceding frame is left in the object slot.
{
FrameCase frame;
frame.create();
fill_frame_bed(&frame, 0.1f, 0.1f);
configure_passthrough_object(&frame);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 1u, true, 1u, 1.0));
CHECK(object_peak(frame, 1) > 1.0e-3f);
CHECK(frame.render(EJOC_CORE_CHANNELS, EJOC_CORE_CHANNELS, 0u, 2u, true, 0u, 1.0));
for (int sample = 640; sample < EJOC_FRAME_SAMPLES; ++sample) {
CHECK(frame.at(1, sample) == 0.0f);
}
}
}
// The binaural position timeline consumes the full OAMD frame state: multi-block
// payloads and programmes past the 16-slot legacy view are scheduled instead of
// being rejected, and a renderer with a different source count can read more
// tracks than the fifteen JOC object sources.
void test_binaural_timeline_full_frame_state() {
// Two position blocks in one object element: the legacy frame_update() view
// rejects this, the full frame state schedules both blocks.
const std::vector<std::uint8_t> multiblock = from_hex("0104600800450132831d6a00");
joc::oamd::OamdUpdate update;
CHECK(joc::oamd::parse_id11_state(multiblock.data(), multiblock.size(), &update).ok());
CHECK(update.has_frame_state);
CHECK(update.frame_state.block_count == 2);
joc::timeline::OamdPositionTimeline timeline;
CHECK(timeline.submit_update(update, 0, 0, 1473, 0).ok());
CHECK(timeline.initialized());
CHECK(timeline.payload_count() == 1);
double positions[joc::timeline::kTimelineObjects][3] = {};
CHECK(timeline.positions_at(0, &positions[0][0], joc::timeline::kTimelineObjects).ok());
// Seventeen declared objects: the timeline grows one track per object instead
// of stopping at the 16-slot legacy view.
const char* many_objects_hex =
"21044E600022A29808054530100A8A60201514C0402A29808054530100A8A60201514C040"
"2A29808054530100A8A60201514C0402A29808054530100A8A60201514C0402A2980800";
const std::vector<std::uint8_t> many_objects = from_hex(many_objects_hex);
joc::oamd::OamdUpdate many;
CHECK(joc::oamd::parse_id11_state(many_objects.data(), many_objects.size(), &many).ok());
CHECK(many.frame_state.object_count == 17);
joc::timeline::OamdPositionTimeline wide;
CHECK(wide.submit_update(many, 0, 0, 1473, 0).ok());
CHECK(wide.object_count() == 16);
double wide_positions[16][3] = {};
CHECK(wide.positions_at(0, &wide_positions[0][0], 16).ok());
CHECK(wide.positions_at(0, &wide_positions[0][0], 17).code() ==
JOC_ERR_INVALID_ARGUMENT);
// The legacy slot view still works and matches the frame-state path for a
// single-block payload.
const std::vector<std::uint8_t> single = from_hex("0304680004545313880D45301000");
joc::oamd::OamdUpdate parsed;
CHECK(joc::oamd::parse_id11_state(single.data(), single.size(), &parsed).ok());
joc::timeline::OamdPositionTimeline full;
joc::timeline::OamdPositionTimeline legacy;
CHECK(full.submit_update(parsed, 0, 0, 1473, 0).ok());
joc::oamd::OamdUpdate slot_view = parsed;
slot_view.has_frame_state = false;
CHECK(legacy.submit_update(slot_view, 0, 0, 1473, 0).ok());
double frame_position[3] = {};
double slot_position[3] = {};
CHECK(full.positions_at(0, frame_position, 1).ok());
CHECK(legacy.positions_at(0, slot_position, 1).ok());
CHECK(frame_position[0] == slot_position[0] && frame_position[1] == slot_position[1] &&
frame_position[2] == slot_position[2]);
}
int main() {
test_sha256();
test_crc32_and_inflate();
@@ -1510,6 +2217,13 @@ int main() {
test_clipgain_first_frame_uses_its_own_gain();
test_clipgain_change_applies_to_the_current_frame();
test_clipgain_reset_clears_the_previous_gain();
test_joc_clipgain_formula();
test_joc_parse_status_and_offset_ts();
test_joc_lfe_clipgain_ramp();
test_joc_passthrough_8_plane_layout();
test_joc_frame_state_machine();
test_joc_no_previous_interpolation();
test_binaural_timeline_full_frame_state();
std::printf("%d checks, %d failure(s)\n", g_checks, g_failures);
return g_failures == 0 ? 0 : 1;
}
+437
View File
@@ -0,0 +1,437 @@
// State-only checks of the OAMD parser, ported from tests/oamd_metadata_test.py.
// The speaker-renderer targets are covered by the speaker tests; this file keeps
// the bitstream expansion, formula tables and programme parsing checks.
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <vector>
#include "oamd/oamd_params.h"
#include "oamd/oamd_parser.h"
namespace {
int failures = 0;
void check(bool passed, const char* name) {
if (!passed) {
std::fprintf(stderr, "FAIL: %s\n", name);
++failures;
}
}
std::vector<std::uint8_t> from_hex(const char* text) {
std::vector<std::uint8_t> bytes;
const std::size_t length = std::strlen(text);
for (std::size_t index = 0; index + 1 < length; index += 2) {
const auto high = static_cast<unsigned>(text[index]);
const auto low = static_cast<unsigned>(text[index + 1]);
const auto digit = [](unsigned value) -> unsigned {
if (value >= '0' && value <= '9') {
return value - '0';
}
if (value >= 'a' && value <= 'f') {
return value - 'a' + 10;
}
if (value >= 'A' && value <= 'F') {
return value - 'A' + 10;
}
return 0;
};
bytes.push_back(static_cast<std::uint8_t>((digit(high) << 4) | digit(low)));
}
return bytes;
}
joc::oamd::OamdUpdate parse_state(const char* hex) {
const std::vector<std::uint8_t> payload = from_hex(hex);
joc::oamd::OamdUpdate update;
const joc::Status status =
joc::oamd::parse_id11_state(payload.data(), payload.size(), &update);
check(status.ok(), "parse_id11_state succeeds");
if (!status.ok()) {
std::fprintf(stderr, " %s: %s\n", hex, status.message().c_str());
}
return update;
}
const joc::oamd::ObjectRenderState& block0(const joc::oamd::OamdUpdate& update,
int object) {
return update.frame_state.objects[static_cast<std::size_t>(object)]
.blocks[0]
.render;
}
// Two object blocks in one object element: block 0 is a full update, block 1 is
// an inactive block. Ported from test_multiblock_state_expansion.
void test_multiblock_state_expansion() {
const joc::oamd::OamdUpdate update = parse_state("0104600800450132831d6a00");
check(update.has_frame_state, "frame state present");
check(update.frame_state.object_count == 1, "one object");
check(update.frame_state.block_count == 2, "two blocks");
check(update.frame_state.objects.size() == 1, "one object state");
check(update.frame_state.objects[0].blocks.size() == 2, "two object blocks");
const joc::oamd::ObjectRenderState& first = block0(update, 0);
check(first.gain_q == 23033, "block 0 gain_q");
check(first.priority_q == 32767, "block 0 priority_q");
check(first.qx == 6342 && first.qy == 21141 && first.qz == -13107, "block 0 position");
check(first.zone_idx == 3 && first.enable_elevation, "block 0 zone/elevation");
check(first.size_mode == 1, "block 0 size mode");
check(first.snap, "block 0 snap");
const joc::oamd::ObjectRenderState& second =
update.frame_state.objects[0].blocks[1].render;
// The second block is active but carries basic_status 0: no gain update.
check(!second.not_active, "block 1 active");
check(second.gain_q == 0 && second.priority_q == 0, "block 1 gain/priority");
check(second.qx == 16384 && second.qy == 16384 && second.qz == 0,
"block 1 default position");
}
// Two objects with three blocks: the first object's block 1 is inactive, the
// second is a full update. Ported from test_multiblock_gain_inheritance.
void test_multiblock_gain_inheritance() {
const joc::oamd::OamdUpdate update =
parse_state("038474100040850146527514c0407c3e00");
check(update.frame_state.objects.size() == 2, "two objects");
check(update.frame_state.block_count == 3, "three blocks");
const std::int32_t expected_gain[3] = {23033, 0, 2052};
for (int block = 0; block < 3; ++block) {
check(update.frame_state.objects[0].blocks[static_cast<std::size_t>(block)]
.render.gain_q == expected_gain[block],
"first object gain inheritance");
check(update.frame_state.objects[1].blocks[static_cast<std::size_t>(block)]
.render.gain_q == expected_gain[block],
"second object gain inheritance");
}
check(update.frame_state.objects[0].blocks[1].render.not_active,
"first object block 1 inactive");
check(!update.frame_state.objects[1].blocks[1].render.not_active,
"second object block 1 active");
for (int block = 0; block < 3; ++block) {
check(update.frame_state.objects[0].blocks[static_cast<std::size_t>(block)]
.render.qx == 16384,
"first object holds centre x");
check(update.frame_state.objects[1].blocks[static_cast<std::size_t>(block)]
.render.qx == 10570,
"second object x");
}
}
// gain_idx 0/1/2: unity, mute and the 6-bit dB table.
void test_gain_formula() {
check(block0(parse_state("010458000501514C0400"), 0).gain_q == 23033, "gain bits 0");
check(block0(parse_state("01045800057F514C0400"), 0).gain_q == 14, "gain bits 63");
check(block0(parse_state("0104540004D4530100"), 0).gain_q == 0, "gain mute");
}
// size_idx 1/2: isotropic and per-axis Q15 sizes.
void test_size_formula() {
const joc::oamd::OamdUpdate size16 = parse_state("01045800045453016000");
check(block0(size16, 0).size_mode == 1, "size mode 1");
check(block0(size16, 0).size_q[0] == 16913, "size value 16");
check(block0(size16, 0).size_q[1] == 16913 && block0(size16, 0).size_q[2] == 16913,
"isotropic size");
const joc::oamd::OamdUpdate size31 = parse_state("01045800045453017E00");
check(block0(size31, 0).size_q[0] == 32767, "size value 31");
const joc::oamd::OamdUpdate size2 = parse_state("01045C00045453018AAA00");
check(block0(size2, 0).size_mode == 2, "size mode 2");
check(block0(size2, 0).size_q[0] == 5285 && block0(size2, 0).size_q[1] == 10570 &&
block0(size2, 0).size_q[2] == 21141,
"per-axis size");
}
// Position quantisation, zone/snap, elevation flag and signed z.
void test_position_formula() {
const joc::oamd::OamdUpdate base = parse_state("010454000454530100");
check(block0(base, 0).qx == 10570 && block0(base, 0).qy == 10570 &&
block0(base, 0).qz == 17476,
"coarse position");
check(block0(base, 0).enable_elevation, "elevation enabled");
check(block0(base, 0).zone_idx == 0, "zone 0");
const joc::oamd::OamdUpdate zone = parse_state("0104540004420A0B10");
check(block0(zone, 0).qx == 1057 && block0(zone, 0).qy == 1057 && block0(zone, 0).qz == 0,
"zone position");
check(block0(zone, 0).zone_idx == 5, "zone index");
check(block0(zone, 0).snap, "snap flag");
const joc::oamd::OamdUpdate height = parse_state("010454000454530000");
check(!block0(height, 0).enable_elevation, "elevation disabled");
const joc::oamd::OamdUpdate negative = parse_state("010454000454510100");
check(block0(negative, 0).qz == -17476, "signed elevation");
}
// Extended object element position refinement.
void test_refinement() {
const joc::oamd::OamdUpdate update = parse_state("010854000454530100A23E00");
check(block0(update, 0).qx == 10676, "refined x");
check(block0(update, 0).qy == 10676, "refined y");
check(block0(update, 0).qz == 17913, "refined z");
}
// Extended object element divergence table.
void test_divergence() {
check(block0(parse_state("010854000454530100A27400"), 0).divergence_q == 11548,
"divergence table value 32");
check(block0(parse_state("010854000454530100A277E0"), 0).divergence_q == 16384,
"divergence table value 63");
}
// Programme assignment: bed labels, ISF index, masks and distribution flag.
void test_program_assignment() {
const joc::oamd::OamdUpdate lfe = parse_state("018448000440");
check(lfe.frame_state.program.dynamic_object_only, "dynamic object only");
check(lfe.frame_state.program.lfe_present, "lfe present");
check(lfe.frame_state.program.num_bed_objects == 1, "one bed object");
check(lfe.frame_state.program.bed_labels.size() == 1 &&
lfe.frame_state.program.bed_labels[0] == joc::joc::BedChannel::kLfe,
"lfe bed label");
check(lfe.frame_state.program.bed_mask == 0x8u, "lfe bed mask");
check(lfe.frame_state.objects[0].kind == joc::oamd::ObjectKind::kBed, "bed object kind");
check(block0(lfe, 0).qx == 16384 && block0(lfe, 0).qy == 16384 && block0(lfe, 0).qz == 0,
"bed object holds centre");
const joc::oamd::OamdUpdate isf = parse_state("062011400011084200");
check(isf.frame_state.object_count == 4, "isf object count");
check(isf.frame_state.program.isf_idx == 0, "isf index");
check(isf.frame_state.program.num_isf_objects == 4, "isf object number");
for (int index = 0; index < 4; ++index) {
check(isf.frame_state.objects[static_cast<std::size_t>(index)].kind ==
joc::oamd::ObjectKind::kIsf,
"isf object kind");
}
const joc::oamd::OamdUpdate standard = parse_state("021100422600022100");
check(standard.frame_state.program.num_bed_objects == 2, "standard bed object number");
check(standard.frame_state.program.bed_mask == 0x3u, "standard bed wide mask");
check(standard.frame_state.program.bed_labels.size() == 2 &&
standard.frame_state.program.bed_labels[0] == joc::joc::BedChannel::kLeft &&
standard.frame_state.program.bed_labels[1] == joc::joc::BedChannel::kRight,
"standard bed labels");
const joc::oamd::OamdUpdate nonstandard = parse_state("001000800448000440");
check(nonstandard.frame_state.program.num_bed_objects == 1, "non-standard bed number");
check(nonstandard.frame_state.program.bed_mask == 0x100u, "non-standard bed mask");
check(nonstandard.frame_state.program.bed_labels.size() == 1 &&
nonstandard.frame_state.program.bed_labels[0] ==
joc::joc::BedChannel::kTopFrontLeft,
"non-standard bed label");
check(!nonstandard.frame_state.program.b_bed_chan_distribute, "distribution off");
const joc::oamd::OamdUpdate distributed = parse_state("001800800448000440");
check(distributed.frame_state.program.b_bed_chan_distribute, "distribution on");
}
// The parsed bed declaration keeps its expanded channels for the ADM check.
void test_bed_assignments() {
const std::vector<std::uint8_t> payload = from_hex("021100422600022100");
std::vector<joc::oamd::BedAssignment> assignments;
check(joc::oamd::parse_id11_bed_assignments(payload.data(), payload.size(),
&assignments)
.ok(),
"bed assignment parse");
check(assignments.size() == 1, "one assignment");
check(assignments[0].standard && !assignments[0].lfe_only, "standard assignment");
check(assignments[0].channels.size() == 2 &&
assignments[0].channels[0] == joc::joc::BedChannel::kLeft &&
assignments[0].channels[1] == joc::joc::BedChannel::kRight,
"assignment channels");
}
// Legacy frame_update() view: 16 slots from block 0, >16 objects and multi-block
// frames stay rejected; the full state accepts both.
void test_legacy_view() {
const std::vector<std::uint8_t> base_payload = from_hex("010454000454530100");
joc::oamd::OamdUpdate legacy;
check(joc::oamd::parse_id11(base_payload.data(), base_payload.size(), &legacy).ok(),
"legacy parse");
check(legacy.has_frame_state, "legacy carries frame state");
check(legacy.frame_state.block_count == 1, "legacy block count");
check(legacy.frame_state.blocks[0].block_offset_samples == 0 &&
legacy.frame_state.blocks[0].ramp_duration_samples == 0,
"legacy block timing");
check(legacy.slots[0].q1 == 10570 && legacy.slots[0].q2 == 10570 &&
legacy.slots[0].q3 == 17476,
"legacy slot position");
check(legacy.slots[1].q1 == -1 && legacy.slots[1].q2 == -1 && legacy.slots[1].q3 == -1,
"legacy unused slot hold");
// The legacy slot view never publishes a negative elevation.
const std::vector<std::uint8_t> negative = from_hex("010454000454510100");
check(joc::oamd::parse_id11(negative.data(), negative.size(), &legacy).ok(),
"negative legacy parse");
check(legacy.slots[0].q3 == 0, "legacy negative z clamps to side");
const std::vector<std::uint8_t> elevation_off = from_hex("010454000454530000");
check(joc::oamd::parse_id11(elevation_off.data(), elevation_off.size(), &legacy).ok(),
"elevation-off legacy parse");
check(legacy.slots[0].q3 == 0, "legacy elevation flag zeroes z");
// Bed objects have no position field: the slot keeps the previous position.
const std::vector<std::uint8_t> bed = from_hex("018448000440");
check(joc::oamd::parse_id11(bed.data(), bed.size(), &legacy).ok(), "bed legacy parse");
check(legacy.slots[0].q1 == -1 && legacy.slots[0].q2 == -1 && legacy.slots[0].q3 == -1,
"legacy bed slot holds");
const std::vector<std::uint8_t> multiblock = from_hex("0104600800450132831d6a00");
const joc::Status legacy_status =
joc::oamd::parse_id11(multiblock.data(), multiblock.size(), &legacy);
check(!legacy_status.ok() &&
legacy_status.code() == JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
"legacy rejects multiple blocks");
const char* many_objects_hex =
"21044E600022A29808054530100A8A60201514C0402A29808054530100A8A60201514C040"
"2A29808054530100A8A60201514C0402A29808054530100A8A60201514C0402A2980800";
const std::vector<std::uint8_t> many_objects = from_hex(many_objects_hex);
const joc::Status many_legacy =
joc::oamd::parse_id11(many_objects.data(), many_objects.size(), &legacy);
check(!many_legacy.ok() && many_legacy.code() == JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
"legacy rejects more than 16 objects");
joc::oamd::OamdUpdate many;
check(joc::oamd::parse_id11_state(many_objects.data(), many_objects.size(), &many).ok(),
"full state accepts more than 16 objects");
check(many.frame_state.object_count == 17, "full state object count");
check(many.frame_state.objects.size() == 17, "full state expands every object");
}
// Optional position fields must be consumed exactly: distance, screen reference
// and the priority mask.
void test_optional_fields() {
const joc::oamd::OamdUpdate distance = parse_state("0304680004545313880D45301000");
check(distance.frame_state.object_count == 2, "distance payload object count");
check(block0(distance, 0).qx == 10570, "distance payload keeps alignment");
check(block0(distance, 1).gain_q == 0, "distance payload second object");
const joc::oamd::OamdUpdate infinity = parse_state("010454000454531880");
check(block0(infinity, 0).qz == 17476, "infinite distance keeps alignment");
const joc::oamd::OamdUpdate screen = parse_state("01045800045453013600");
check(block0(screen, 0).qx == 10570 && block0(screen, 0).snap == false,
"screen reference keeps alignment");
const joc::oamd::OamdUpdate priority = parse_state("03046800043EA29808000A298080");
check(block0(priority, 0).priority_q == 31744, "priority bits");
check(block0(priority, 1).priority_q == 0, "priority zero");
const joc::oamd::OamdUpdate inactive = parse_state("010448000600");
check(block0(inactive, 0).not_active, "inactive object");
check(block0(inactive, 0).gain_q == 0 && block0(inactive, 0).priority_q == 0,
"inactive gain/priority");
check(block0(inactive, 0).qx == 16384 && block0(inactive, 0).qy == 16384 &&
block0(inactive, 0).qz == 0,
"inactive default position");
}
// The compiled-in ISF tables must be complete: six configurations, twelve
// layout descriptors, four layout groups, 73 paired column flags, and exact
// matrix coefficients.
void test_metadata_params() {
const joc::oamd::MetadataParams* params = joc::oamd::metadata_params();
check(params != nullptr, "metadata params");
if (params == nullptr) {
std::fprintf(stderr, " %s\n", joc::oamd::metadata_params_error());
return;
}
check(params->configs.size() == 6, "six ISF configurations");
check(params->layouts.size() == 12, "twelve ISF layout descriptors");
check(!params->layout_groups.floor_a.empty() && !params->layout_groups.floor_b.empty() &&
!params->layout_groups.height.empty() &&
!params->layout_groups.additional.empty(),
"four layout groups");
check(!params->paired_columns.empty(), "paired column flags");
for (const joc::oamd::IsfConfig& config : params->configs) {
check(config.counts[4] == static_cast<int>(config.primary_row_map.size()),
"isf row count");
// Every configuration stores its basis with a 73-column row stride.
check(config.matrix.size() ==
static_cast<std::size_t>(config.counts[4]) * 73u,
"isf matrix size");
}
const joc::oamd::IsfLayout* layout20 = params->layout("20");
const joc::oamd::IsfLayout* layout916 = params->layout("916");
check(layout20 != nullptr && layout20->output_count == 2 &&
layout20->compensation_value == -4.5,
"2.0 layout descriptor");
check(layout916 != nullptr && layout916->output_count == 16 &&
layout916->compensation_value == 0.0,
"9.1.6 layout descriptor");
check(params->layout("60") != nullptr && params->layout("60")->output_count == 6 &&
params->layout("60")->compensation_value == -1.5,
"6.0 layout descriptor");
check(!params->layout("unknown"), "unknown layout descriptor");
// Exact table contents: the config counts and the first coefficients pin
// the reference data, and the row/column structure follows from them.
const joc::oamd::IsfConfig& first = params->configs[0];
check(first.counts[0] == 3 && first.counts[1] == 1 && first.counts[2] == 0 &&
first.counts[3] == 0 && first.counts[4] == 4,
"first config counts");
check(first.matrix.size() == 4u * 73u && first.matrix[0] == 0.806554496f &&
first.matrix[1] == 0.55179733f && first.matrix[15] == -0.280463845f,
"first config coefficients");
check(first.primary_row_map.size() == 4 && first.primary_row_map[3] == 3 &&
first.secondary_row_map.size() == 4 && first.secondary_row_map[3] == 3,
"first config row maps");
const joc::oamd::IsfConfig& last = params->configs[5];
check(last.counts[0] == 15 && last.counts[1] == 9 && last.counts[2] == 5 &&
last.counts[3] == 1 && last.counts[4] == 30 &&
last.matrix.size() == 30u * 73u,
"last config shape");
check(params->layout("20")->output_ids.size() == 37 &&
params->layout("20")->output_ids[0] == 0 &&
params->layout("20")->output_ids[1] == 1 &&
params->layout("20")->output_ids[2] == 0,
"layout output ids");
check(params->layout_groups.floor_a.size() == 6 &&
params->layout_groups.floor_b.size() == 7 &&
params->layout_groups.height.size() == 6 &&
params->layout_groups.additional.size() == 5,
"layout group sizes");
check(params->layout_groups.floor_a[1].selector == 1 &&
params->layout_groups.floor_a[1].begin == 1 &&
params->layout_groups.floor_a[1].end == 3,
"layout group record");
const std::size_t paired = static_cast<std::size_t>(
std::count(params->paired_columns.begin(), params->paired_columns.end(), true));
check(params->paired_columns.size() == 73 && paired == 67, "paired column flags");
}
// q_of is the reference's Q15 quantiser.
void test_q_of() {
check(joc::oamd::q_of(0, 62) == 0, "q_of 0");
check(joc::oamd::q_of(62, 62) == 32767, "q_of max");
check(joc::oamd::q_of(31, 62) == 16384, "q_of centre");
check(joc::oamd::q_of(15, 15) == 32767, "q_of z max");
check(joc::oamd::q_of(20, 62) == 10570, "q_of 20/62");
check(joc::oamd::q_of(8, 15) == 17476, "q_of 8/15");
}
} // namespace
int main() {
test_multiblock_state_expansion();
test_multiblock_gain_inheritance();
test_gain_formula();
test_size_formula();
test_position_formula();
test_refinement();
test_divergence();
test_program_assignment();
test_bed_assignments();
test_legacy_view();
test_optional_fields();
test_metadata_params();
test_q_of();
if (failures != 0) {
std::fprintf(stderr, "%d OAMD metadata check(s) failed\n", failures);
return 1;
}
std::printf("OAMD metadata checks passed\n");
return 0;
}