Compare commits
1
Commits
v0.6.4
..
9c1bd7ba29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c1bd7ba29 |
No files matched your search
@@ -3,8 +3,7 @@ name: build
|
|||||||
# Builds both architectures, publishes the two installable component packages as
|
# Builds both architectures, publishes the two installable component packages as
|
||||||
# workflow artifacts, and — when a tag is pushed — turns them into a GitHub release.
|
# workflow artifacts, and — when a tag is pushed — turns them into a GitHub release.
|
||||||
# The SDK is fetched from foobar2000.org at build time (tools/setup_sdk.ps1) and the
|
# The SDK is fetched from foobar2000.org at build time (tools/setup_sdk.ps1) and the
|
||||||
# renderer sources are part of this repository (kernel/, synced from JustOneCacophonyCXX
|
# renderer sources are part of this repository (kernel/), so nothing else is needed.
|
||||||
# version 1.3.1), so nothing else is needed.
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|||||||
+3
-4
@@ -96,8 +96,8 @@ HRTF 文件, 增益.
|
|||||||
|
|
||||||
### HRTF data
|
### HRTF data
|
||||||
|
|
||||||
A personalised headphone model (`HRTF\binaural.personalized_headphone`) is supplied by whoever
|
A SOFA measurement set or a personalised headphone model is supplied by whoever runs the
|
||||||
runs the component, and is listed in `.gitignore` so it cannot be committed by accident. Speaker layouts
|
component, and is listed in `.gitignore` so it cannot be committed by accident. Speaker layouts
|
||||||
need none. Binaural rendering without an HRTF fails with a message naming the file it looked for.
|
need none. Binaural rendering without an HRTF fails with a message naming the file it looked for.
|
||||||
|
|
||||||
## Speaker layouts and channel order
|
## Speaker layouts and channel order
|
||||||
@@ -208,5 +208,4 @@ every container in the library, which is where the volume comes from.
|
|||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
`LICENSE` is the upstream MIT licence, copied unchanged; `kernel/` is a copy of the upstream
|
`LICENSE` is the upstream MIT licence, copied unchanged; `kernel/` is a copy of the upstream
|
||||||
rendering core sources, synced to JustOneCacophonyCXX 1.3.4, and keeps their notices. See
|
rendering core sources and keeps their notices. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
||||||
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
||||||
@@ -67,15 +67,6 @@ Preferences → Tools → **JOC 解码器**:
|
|||||||
对调(7.1 里是 5↔7、6↔8,从 1 数)。只在这种布局同时有侧环绕和后环绕时生效:
|
对调(7.1 里是 5↔7、6↔8,从 1 数)。只在这种布局同时有侧环绕和后环绕时生效:
|
||||||
7.1、7.1.2、7.1.4、9.1.4、9.1.6;5.1.2/5.1.4 的后两个槽位是天空声道,不会被误换。
|
7.1、7.1.2、7.1.4、9.1.4、9.1.6;5.1.2/5.1.4 的后两个槽位是天空声道,不会被误换。
|
||||||
它只改交付 PCM 的声道顺序,不动解码、对象位置与布局定义,float32 与 int24 交付都生效。
|
它只改交付 PCM 的声道顺序,不动解码、对象位置与布局定义,float32 与 int24 交付都生效。
|
||||||
* **接管普通 PCM 源(ffmpeg 解码)** —— 默认关闭。打开后接管
|
|
||||||
`wav/flac/mp3/aac/ogg/opus/wma/aif/aiff/ac3/dts/dtshd/dtsma/wv/ape/tta/mpc/au/snd/caf/thd/mlp/truehd`,
|
|
||||||
由 ffmpeg 唯一负责解码到 48 kHz float32,再交给内核的 PCM layout 输入做 2.0/5.1/7.1 的 binaural 渲染;
|
|
||||||
此时不再把这个文件交给其他解码器。TrueHD/MLP 也接管;带 Atmos 的 TrueHD 经 ffmpeg 解成 PCM 后对象信息会丢失,暂按普通多声道处理。TrueHD 在 MKV 等容器里同样走容器回退,不受扩展名列表限制。DSD(`.dsf/.dff`)不在接管范围。
|
|
||||||
`.mp4/.m4a/.mkv/.mka/.mov/.webm` 仍先做 JOC 检测,非 JOC 的 E-AC-3 音轨才回退到 ffmpeg。
|
|
||||||
如果内置解码器在 foobar2000 的 input priority 里排在前面,WAV/AC3/MP3 等文件会先被内置解码器拿走,
|
|
||||||
本组件不会收到 open 调用;需要把 **JOC decoder** 提到对应内置解码器之前。
|
|
||||||
* **Dolby Dialnorm 响度均衡(-31 dBFS)** —— 默认关闭。打开后只对 ffmpeg 解码的 E-AC-3 5.1 core 施加 `-target_level -31`,
|
|
||||||
用于按码流 dialnorm 做响度均衡;普通 PCM 和 7 声道 core 不受影响。
|
|
||||||
* **ffmpeg.exe** 可执行文件路径。
|
* **ffmpeg.exe** 可执行文件路径。
|
||||||
* **界面语言** —— **跟随系统** / **简体中文** / **English**。设置页的全部文字、状态行和用户可见的
|
* **界面语言** —— **跟随系统** / **简体中文** / **English**。设置页的全部文字、状态行和用户可见的
|
||||||
错误信息都用这一项选定的语言,切换后立刻生效;选择存在组件自己的配置里。"跟随系统"按 Windows 的
|
错误信息都用这一项选定的语言,切换后立刻生效;选择存在组件自己的配置里。"跟随系统"按 Windows 的
|
||||||
@@ -86,7 +77,7 @@ Preferences → Tools → **JOC 解码器**:
|
|||||||
|
|
||||||
### HRTF 数据
|
### HRTF 数据
|
||||||
|
|
||||||
个性化耳机模型(`HRTF\binaural.personalized_headphone`)由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。
|
SOFA 测量集或个性化耳机模型由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。
|
||||||
扬声器布局不需要 HRTF。双耳渲染缺少 HRTF 时会报错并指出它找的是哪个文件。
|
扬声器布局不需要 HRTF。双耳渲染缺少 HRTF 时会报错并指出它找的是哪个文件。
|
||||||
|
|
||||||
## 扬声器布局与声道顺序
|
## 扬声器布局与声道顺序
|
||||||
@@ -171,6 +162,5 @@ pwsh -File tools/package.ps1 # 两个架构,打包到 dist\*.fb2k-c
|
|||||||
|
|
||||||
## 许可
|
## 许可
|
||||||
|
|
||||||
`LICENSE` 是上游 MIT 许可,原样复制;`kernel/` 是上游渲染内核源码的副本,同步自 JustOneCacophonyCXX 的
|
`LICENSE` 是上游 MIT 许可,原样复制;`kernel/` 是上游渲染内核源码的副本,保留其声明。见
|
||||||
1.3.4 版本,保留其声明。见
|
|
||||||
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
(`kernel/src/joc_bitstream/joc_huffman_tables.h`)的公开标准来源,以及 HRTF 数据与
|
(`kernel/src/joc_bitstream/joc_huffman_tables.h`)的公开标准来源,以及 HRTF 数据与
|
||||||
专利的边界说明。
|
专利的边界说明。
|
||||||
|
|
||||||
`kernel/` 整体是 JustOneCacophonyCXX 1.3.4 的逐字副本。
|
|
||||||
|
|
||||||
## 公开标准来源
|
## 公开标准来源
|
||||||
|
|
||||||
64-QMF → 77-hybrid 结构与 13-tap 低带 prototype 定义于
|
64-QMF → 77-hybrid 结构与 13-tap 低带 prototype 定义于
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
-->
|
-->
|
||||||
<PreprocessorDefinitions>NDEBUG;_WINDLL;WIN32_LEAN_AND_MEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;JOC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_WINDLL;WIN32_LEAN_AND_MEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;JOC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ForcedIncludeFiles>$(ProjectDir)src\joc_pch.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
|
<ForcedIncludeFiles>$(ProjectDir)src\joc_pch.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src;$(ProjectDir)kernel\include;$(ProjectDir)kernel\src;$(ProjectDir)SDK\foobar2000;$(ProjectDir)SDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src;$(ProjectDir)SDK\foobar2000;$(ProjectDir)SDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<DisableSpecificWarnings>4100;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4100;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@@ -99,7 +99,6 @@
|
|||||||
<ClCompile Include="src\eac3_scan.cpp" />
|
<ClCompile Include="src\eac3_scan.cpp" />
|
||||||
<ClCompile Include="src\input_joc.cpp" />
|
<ClCompile Include="src\input_joc.cpp" />
|
||||||
<ClCompile Include="src\joc_decode.cpp" />
|
<ClCompile Include="src\joc_decode.cpp" />
|
||||||
<ClCompile Include="src\pcm_source.cpp" />
|
|
||||||
<ClCompile Include="src\lang.cpp" />
|
<ClCompile Include="src\lang.cpp" />
|
||||||
<ClCompile Include="src\log.cpp" />
|
<ClCompile Include="src\log.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
@@ -111,7 +110,6 @@
|
|||||||
<ClInclude Include="src\container_scan.h" />
|
<ClInclude Include="src\container_scan.h" />
|
||||||
<ClInclude Include="src\eac3_scan.h" />
|
<ClInclude Include="src\eac3_scan.h" />
|
||||||
<ClInclude Include="src\joc_decode.h" />
|
<ClInclude Include="src\joc_decode.h" />
|
||||||
<ClInclude Include="src\pcm_source.h" />
|
|
||||||
<ClInclude Include="src\joc_pch.h" />
|
<ClInclude Include="src\joc_pch.h" />
|
||||||
<ClInclude Include="src\lang.h" />
|
<ClInclude Include="src\lang.h" />
|
||||||
<ClInclude Include="src\log.h" />
|
<ClInclude Include="src\log.h" />
|
||||||
|
|||||||
@@ -3,22 +3,19 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* EJOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
/* EJOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
||||||
#if defined(_WIN32)
|
|
||||||
#define EJOC_CALL __cdecl
|
|
||||||
#else
|
|
||||||
#define EJOC_CALL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(EJOC_STATIC)
|
#if defined(EJOC_STATIC)
|
||||||
#define EJOC_API
|
#define EJOC_API
|
||||||
|
#define EJOC_CALL __cdecl
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#if defined(EJOC_BUILD_DLL)
|
#if defined(EJOC_BUILD_DLL)
|
||||||
#define EJOC_API __declspec(dllexport)
|
#define EJOC_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define EJOC_API __declspec(dllimport)
|
#define EJOC_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
|
#define EJOC_CALL __cdecl
|
||||||
#else
|
#else
|
||||||
#define EJOC_API __attribute__((visibility("default")))
|
#define EJOC_API __attribute__((visibility("default")))
|
||||||
|
#define EJOC_CALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -26,15 +23,13 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
EJOC_ABI_VERSION = 4,
|
EJOC_ABI_VERSION = 3,
|
||||||
EJOC_FRAME_SAMPLES = 1536,
|
EJOC_FRAME_SAMPLES = 1536,
|
||||||
EJOC_TIMESLOTS = 24,
|
EJOC_TIMESLOTS = 24,
|
||||||
EJOC_SUBBANDS = 64,
|
EJOC_SUBBANDS = 64,
|
||||||
EJOC_CORE_CHANNELS = 5, /* downmix configurations 0 and 3 */
|
EJOC_CORE_CHANNELS = 5, /* downmix configurations 0 and 3 */
|
||||||
EJOC_MAX_CORE_CHANNELS = 7, /* downmix configurations 1, 2 and 4 */
|
EJOC_MAX_CORE_CHANNELS = 7, /* downmix configurations 1, 2 and 4 */
|
||||||
EJOC_OUTPUT_CHANNELS = 16,
|
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_OBJECTS = 15,
|
||||||
EJOC_MAX_DPOINTS = 2,
|
EJOC_MAX_DPOINTS = 2,
|
||||||
EJOC_MAX_PARAMETER_BANDS = 23,
|
EJOC_MAX_PARAMETER_BANDS = 23,
|
||||||
@@ -48,21 +43,6 @@ enum {
|
|||||||
EJOC_BINAURAL_HYBRID_BANDS = 77
|
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_renderer_handle;
|
||||||
typedef void* ejoc_speaker_renderer_handle;
|
typedef void* ejoc_speaker_renderer_handle;
|
||||||
typedef void* ejoc_binaural_renderer_handle;
|
typedef void* ejoc_binaural_renderer_handle;
|
||||||
@@ -123,63 +103,6 @@ EJOC_API int EJOC_CALL ejoc_renderer_process(
|
|||||||
float output_scale,
|
float output_scale,
|
||||||
float* output16_planar);
|
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.
|
High-precision object-to-speaker renderer.
|
||||||
|
|
||||||
@@ -208,11 +131,8 @@ the three trim levels and the two front-back balances. trim_bypass is indexed
|
|||||||
by object slot (1..15); slot 0 carries the LFE and is unused.
|
by object slot (1..15); slot 0 carries the LFE and is unused.
|
||||||
|
|
||||||
warp_mode 0 leaves the floor Y coordinate unchanged; mode 1 maps it through
|
warp_mode 0 leaves the floor Y coordinate unchanged; mode 1 maps it through
|
||||||
clamp(2Y, 0, 1). Modes 2 and 3 render the 5.1-family and 4.0 layouts through an
|
clamp(2Y, 0, 1). warp modes 2 and 3 have no speaker implementation and are
|
||||||
expanded surround layout (7.1-family, or a rear pair added to 4.0 without a
|
rejected by the caller that builds this structure.
|
||||||
centre or LFE) and fold the rear pair into the target surround pair: mode 2
|
|
||||||
uses the PLIIx coefficients (sqrt(3)/2 and 1/2), mode 3 the Standard (Lo/Ro)
|
|
||||||
coefficients (1 and 0). Layouts without a single surround pair render directly.
|
|
||||||
|
|
||||||
trim_mode selects where the gain comes from: automatic applies the layout
|
trim_mode selects where the gain comes from: automatic applies the layout
|
||||||
position compensation, disabled applies no trim, and explicit applies the
|
position compensation, disabled applies no trim, and explicit applies the
|
||||||
|
|||||||
+14
-46
@@ -36,30 +36,27 @@
|
|||||||
|
|
||||||
#include "joc_version.h"
|
#include "joc_version.h"
|
||||||
|
|
||||||
#define JOC_ABI_VERSION 6u
|
#define JOC_ABI_VERSION 5u
|
||||||
#define JOC_FRAME_PARAMS_VERSION 2u
|
#define JOC_FRAME_PARAMS_VERSION 1u
|
||||||
#define JOC_EMDF_INFO_VERSION 2u
|
#define JOC_EMDF_INFO_VERSION 1u
|
||||||
#define JOC_TASK_CONFIG_VERSION 4u
|
#define JOC_TASK_CONFIG_VERSION 4u
|
||||||
#define JOC_TASK_RESULT_VERSION 2u
|
#define JOC_TASK_RESULT_VERSION 2u
|
||||||
#define JOC_EVENT_VERSION 1u
|
#define JOC_EVENT_VERSION 1u
|
||||||
|
|
||||||
/* JOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
/* JOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
||||||
#if defined(_WIN32)
|
|
||||||
#define JOC_CALL __cdecl
|
|
||||||
#else
|
|
||||||
#define JOC_CALL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(JOC_STATIC)
|
#if defined(JOC_STATIC)
|
||||||
#define JOC_API
|
#define JOC_API
|
||||||
|
#define JOC_CALL __cdecl
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#if defined(JOC_BUILD_DLL)
|
#if defined(JOC_BUILD_DLL)
|
||||||
#define JOC_API __declspec(dllexport)
|
#define JOC_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define JOC_API __declspec(dllimport)
|
#define JOC_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
|
#define JOC_CALL __cdecl
|
||||||
#else
|
#else
|
||||||
#define JOC_API __attribute__((visibility("default")))
|
#define JOC_API __attribute__((visibility("default")))
|
||||||
|
#define JOC_CALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -155,7 +152,8 @@ JOC_API const char* JOC_CALL joc_last_error_detail(void);
|
|||||||
typedef struct joc_emdf_payload_info {
|
typedef struct joc_emdf_payload_info {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
uint8_t reserved[3];
|
uint8_t reserved[3];
|
||||||
uint32_t sample_offset; /* EMDF outer smpoffst: variable_bits(11) */
|
uint16_t sample_offset; /* EMDF outer smpoffst, 11 bits */
|
||||||
|
uint16_t reserved2;
|
||||||
uint32_t bit_offset;
|
uint32_t bit_offset;
|
||||||
uint32_t size; /* payload bytes */
|
uint32_t size; /* payload bytes */
|
||||||
} joc_emdf_payload_info;
|
} joc_emdf_payload_info;
|
||||||
@@ -172,8 +170,7 @@ typedef struct joc_emdf_info {
|
|||||||
|
|
||||||
/* Per-object ID14/JOC descriptor plus its dequantized matrix.
|
/* 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
|
* dq[dp][ch][pb] is zero filled outside [0,n_dpoints) x [0,n_channels) x
|
||||||
* [0,n_bands). Absent objects are entirely zero. offset_ts holds the raw
|
* [0,n_bands). Absent objects are entirely zero. */
|
||||||
* 5-bit JOC offsets (legal range 0..23, strictly increasing per object). */
|
|
||||||
typedef struct joc_object_params {
|
typedef struct joc_object_params {
|
||||||
uint8_t present;
|
uint8_t present;
|
||||||
uint8_t num_bands_idx;
|
uint8_t num_bands_idx;
|
||||||
@@ -188,26 +185,6 @@ typedef struct joc_object_params {
|
|||||||
double dq[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS];
|
double dq[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS];
|
||||||
} joc_object_params;
|
} 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. Statuses 3 and 7
|
|
||||||
* still carry the complete header and object list for diagnostics; statuses 2
|
|
||||||
* and 4 stop the parse after the failing header field, and 7 stops inside
|
|
||||||
* joc_data, so only the per-object matrices are missing there. */
|
|
||||||
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 */
|
|
||||||
/* The ID14 payload ends before its joc_data is complete. The header,
|
|
||||||
* clipgain, sequence counter and object parameters are intact, so the frame
|
|
||||||
* stays classified and is concealed by holding the previous matrices. */
|
|
||||||
JOC_FRAME_STATUS_TRUNCATED = 7
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct joc_frame_params {
|
typedef struct joc_frame_params {
|
||||||
uint32_t struct_size;
|
uint32_t struct_size;
|
||||||
uint32_t struct_version;
|
uint32_t struct_version;
|
||||||
@@ -219,29 +196,21 @@ typedef struct joc_frame_params {
|
|||||||
uint8_t clipgain_x_bits;
|
uint8_t clipgain_x_bits;
|
||||||
uint8_t clipgain_y_bits;
|
uint8_t clipgain_y_bits;
|
||||||
uint8_t objects_clamped; /* num_objects_bits+1 exceeded 15 */
|
uint8_t objects_clamped; /* num_objects_bits+1 exceeded 15 */
|
||||||
uint32_t seq_count; /* 10-bit JOC sequence counter */
|
uint32_t seq_count; /* 10-bit JOC sequence counter, parsed only */
|
||||||
uint32_t present_mask; /* bit i == object i present */
|
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 data_end_bits; /* bit position just after joc_data */
|
||||||
uint32_t trailing_bits; /* bits left after joc_data (padding/ext) */
|
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 */
|
uint8_t tail_bytes[8]; /* first up to 8 trailing bytes, for A/B */
|
||||||
double clipgain; /* 2^(x-4) * (1 + y/32), bit-exact */
|
double clipgain; /* 1 + (y/32) * 2^(x-4), bit-exact */
|
||||||
joc_object_params objects[JOC_MAX_OBJECTS];
|
joc_object_params objects[JOC_MAX_OBJECTS];
|
||||||
} joc_frame_params;
|
} joc_frame_params;
|
||||||
|
|
||||||
/* Parse an EMDF ID14 (JOC) payload. A payload that ends inside joc_data is a
|
/* Parse an EMDF ID14 (JOC) payload. */
|
||||||
* damaged frame rather than a transport error: the call succeeds, the header and
|
|
||||||
* object parameters are filled in, and out_params->status is
|
|
||||||
* JOC_FRAME_STATUS_TRUNCATED. A payload too short for the 12-bit joc_header is
|
|
||||||
* unclassifiable and stays JOC_ERR_BITSTREAM_TRUNCATED. */
|
|
||||||
JOC_API joc_error JOC_CALL joc_parse_id14(const uint8_t* payload, size_t payload_size,
|
JOC_API joc_error JOC_CALL joc_parse_id14(const uint8_t* payload, size_t payload_size,
|
||||||
joc_frame_params* out_params);
|
joc_frame_params* out_params);
|
||||||
|
|
||||||
/* Locate the contiguous JOC EMDF container inside one E-AC-3 syncframe and
|
/* Locate the contiguous JOC EMDF container inside one E-AC-3 syncframe and
|
||||||
* parse its ID14 payload. out_emdf may be NULL. A damaged ID14 payload is
|
* parse its ID14 payload. out_emdf may be NULL. */
|
||||||
* reported through out_params->status like joc_parse_id14(); an incomplete
|
|
||||||
* container stays a transport error. */
|
|
||||||
JOC_API joc_error JOC_CALL joc_parse_eac3_frame(const uint8_t* frame, size_t frame_size,
|
JOC_API joc_error JOC_CALL joc_parse_eac3_frame(const uint8_t* frame, size_t frame_size,
|
||||||
joc_frame_params* out_params,
|
joc_frame_params* out_params,
|
||||||
joc_emdf_info* out_emdf);
|
joc_emdf_info* out_emdf);
|
||||||
@@ -262,8 +231,7 @@ JOC_API joc_error JOC_CALL joc_eac3_frame_bytes(const uint8_t* data, size_t size
|
|||||||
|
|
||||||
/* Strict trailing-bit check for the JOC payload (A/B robustness corpus).
|
/* Strict trailing-bit check for the JOC payload (A/B robustness corpus).
|
||||||
* Returns JOC_ERR_BITSTREAM_PADDING when more than 7 bits are left over or the
|
* Returns JOC_ERR_BITSTREAM_PADDING when more than 7 bits are left over or the
|
||||||
* leftover bits are not zero, and JOC_ERR_BITSTREAM_TRUNCATED when the payload
|
* leftover bits are not zero. */
|
||||||
* ends inside joc_data. */
|
|
||||||
JOC_API joc_error JOC_CALL joc_check_id14_padding(const uint8_t* payload, size_t payload_size,
|
JOC_API joc_error JOC_CALL joc_check_id14_padding(const uint8_t* payload, size_t payload_size,
|
||||||
uint32_t* out_trailing_bits);
|
uint32_t* out_trailing_bits);
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ typedef struct joc_stream joc_stream;
|
|||||||
typedef enum joc_stream_input {
|
typedef enum joc_stream_input {
|
||||||
JOC_STREAM_IN_EAC3 = 0, /* bare E-AC-3 syncframes (the metadata stream) */
|
JOC_STREAM_IN_EAC3 = 0, /* bare E-AC-3 syncframes (the metadata stream) */
|
||||||
JOC_STREAM_IN_PCM_OBJECTS16 = 1, /* objects16 frames, planar [16][1536] each */
|
JOC_STREAM_IN_PCM_OBJECTS16 = 1, /* objects16 frames, planar [16][1536] each */
|
||||||
JOC_STREAM_IN_CORE_PCM = 3, /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
JOC_STREAM_IN_CORE_PCM = 3 /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
||||||
JOC_STREAM_IN_PCM_LAYOUT = 4 /* interleaved 48k f32, mapped by pcm_layout */
|
|
||||||
} joc_stream_input;
|
} joc_stream_input;
|
||||||
|
|
||||||
typedef enum joc_stream_output {
|
typedef enum joc_stream_output {
|
||||||
@@ -69,8 +68,6 @@ typedef struct joc_stream_config {
|
|||||||
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
|
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
|
||||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||||
uint32_t jochrtf_room; /* non-zero enables the project room */
|
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||||
/* PCM_LAYOUT input: "2.0", "5.1", "7.1", or NULL/"" to infer by channels. */
|
|
||||||
const char* pcm_layout;
|
|
||||||
} joc_stream_config;
|
} joc_stream_config;
|
||||||
|
|
||||||
typedef struct joc_stream_buffer {
|
typedef struct joc_stream_buffer {
|
||||||
@@ -100,9 +97,8 @@ typedef struct joc_stream_status_info {
|
|||||||
uint64_t oamd_payloads;
|
uint64_t oamd_payloads;
|
||||||
uint64_t oamd_transitions;
|
uint64_t oamd_transitions;
|
||||||
/* Metadata the renderer had to work around, per audio frame: no JOC payload at
|
/* Metadata the renderer had to work around, per audio frame: no JOC payload at
|
||||||
* all, an ID14 payload that ends inside joc_data (that frame holds the previous
|
* all, a declared object count clamped to 15, and a syncframe carrying a second
|
||||||
* matrices), a declared object count clamped to 15, and a syncframe carrying a
|
* EMDF container that is not this frame's JOC metadata. */
|
||||||
* second EMDF container that is not this frame's JOC metadata. */
|
|
||||||
uint64_t missing_joc_frames;
|
uint64_t missing_joc_frames;
|
||||||
uint64_t objects_clamped_frames;
|
uint64_t objects_clamped_frames;
|
||||||
uint64_t extra_container_frames;
|
uint64_t extra_container_frames;
|
||||||
@@ -112,9 +108,6 @@ typedef struct joc_stream_status_info {
|
|||||||
uint64_t bed_mask_mismatch_frames;
|
uint64_t bed_mask_mismatch_frames;
|
||||||
uint32_t output_channels;
|
uint32_t output_channels;
|
||||||
uint32_t ended; /* 1 after flush() */
|
uint32_t ended; /* 1 after flush() */
|
||||||
/* Appended field: joc_stream_status() accepts the size that ends at `ended`
|
|
||||||
* as well, so a caller built against the previous header keeps working. */
|
|
||||||
uint64_t truncated_joc_frames;
|
|
||||||
} joc_stream_status_info;
|
} joc_stream_status_info;
|
||||||
|
|
||||||
JOC_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out);
|
JOC_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#define JOC_VERSION_H
|
#define JOC_VERSION_H
|
||||||
|
|
||||||
#define JOC_VERSION_MAJOR 1
|
#define JOC_VERSION_MAJOR 1
|
||||||
#define JOC_VERSION_MINOR 3
|
#define JOC_VERSION_MINOR 2
|
||||||
#define JOC_VERSION_PATCH 4
|
#define JOC_VERSION_PATCH 0
|
||||||
#define JOC_VERSION_STRING "1.3.4"
|
#define JOC_VERSION_STRING "1.2.0"
|
||||||
|
|
||||||
#endif /* JOC_VERSION_H */
|
#endif /* JOC_VERSION_H */
|
||||||
@@ -5,8 +5,7 @@
|
|||||||
shipping and loading joc_core.dll.
|
shipping and loading joc_core.dll.
|
||||||
|
|
||||||
The sources under kernel\src and kernel\include are a verbatim copy of the
|
The sources under kernel\src and kernel\include are a verbatim copy of the
|
||||||
upstream library at version 1.3.1 (see
|
upstream library (see JustOneCacophonyCXX\CMakeLists.txt): nothing under either
|
||||||
JustOneCacophonyCXX\CMakeLists.txt): nothing under either
|
|
||||||
tree is edited here, and both are kept identical to it, so a single core serves
|
tree is edited here, and both are kept identical to it, so a single core serves
|
||||||
the upstream tools and this component alike. The static build needs no branch
|
the upstream tools and this component alike. The static build needs no branch
|
||||||
of its own: JOC_STATIC (kernel\include\joc_core.h / joc_stream.h) and
|
of its own: JOC_STATIC (kernel\include\joc_core.h / joc_stream.h) and
|
||||||
@@ -178,14 +177,11 @@
|
|||||||
<ClCompile Include="src\joc_bitstream\bed_layout_map.cpp" />
|
<ClCompile Include="src\joc_bitstream\bed_layout_map.cpp" />
|
||||||
<ClCompile Include="src\joc_bitstream\joc_parser.cpp" />
|
<ClCompile Include="src\joc_bitstream\joc_parser.cpp" />
|
||||||
<ClCompile Include="src\joc_core\objects16.cpp" />
|
<ClCompile Include="src\joc_core\objects16.cpp" />
|
||||||
<ClCompile Include="src\oamd\oamd_math.cpp" />
|
|
||||||
<ClCompile Include="src\oamd\oamd_params.cpp" />
|
|
||||||
<ClCompile Include="src\oamd\oamd_parser.cpp" />
|
<ClCompile Include="src\oamd\oamd_parser.cpp" />
|
||||||
<ClCompile Include="src\speaker\speaker_layout_lookup.cpp" />
|
<ClCompile Include="src\speaker\speaker_layout_lookup.cpp" />
|
||||||
<ClCompile Include="src\speaker\speaker_step.cpp" />
|
<ClCompile Include="src\speaker\speaker_step.cpp" />
|
||||||
<ClCompile Include="src\speaker\speaker_trim.cpp" />
|
<ClCompile Include="src\speaker\speaker_trim.cpp" />
|
||||||
<ClCompile Include="src\stream\stream.cpp" />
|
<ClCompile Include="src\stream\stream.cpp" />
|
||||||
<ClCompile Include="src\virtual_speaker\virtual_speaker.cpp" />
|
|
||||||
<ClCompile Include="src\task\task.cpp" />
|
<ClCompile Include="src\task\task.cpp" />
|
||||||
<ClCompile Include="src\telemetry\event_bus.cpp" />
|
<ClCompile Include="src\telemetry\event_bus.cpp" />
|
||||||
<ClCompile Include="src\timeline\position_timeline.cpp" />
|
<ClCompile Include="src\timeline\position_timeline.cpp" />
|
||||||
@@ -260,9 +256,6 @@
|
|||||||
<ClInclude Include="src\joc_bitstream\joc_parser.h" />
|
<ClInclude Include="src\joc_bitstream\joc_parser.h" />
|
||||||
<ClInclude Include="src\joc_core\objects16.h" />
|
<ClInclude Include="src\joc_core\objects16.h" />
|
||||||
<ClInclude Include="src\joc_core\qmf_tables.h" />
|
<ClInclude Include="src\joc_core\qmf_tables.h" />
|
||||||
<ClInclude Include="src\oamd\isf_tables.h" />
|
|
||||||
<ClInclude Include="src\oamd\oamd_math.h" />
|
|
||||||
<ClInclude Include="src\oamd\oamd_params.h" />
|
|
||||||
<ClInclude Include="src\oamd\oamd_parser.h" />
|
<ClInclude Include="src\oamd\oamd_parser.h" />
|
||||||
<ClInclude Include="src\simd\cpu_probe.h" />
|
<ClInclude Include="src\simd\cpu_probe.h" />
|
||||||
<ClInclude Include="src\simd\simd.h" />
|
<ClInclude Include="src\simd\simd.h" />
|
||||||
@@ -271,7 +264,6 @@
|
|||||||
<ClInclude Include="src\speaker\speaker_trim.h" />
|
<ClInclude Include="src\speaker\speaker_trim.h" />
|
||||||
<ClInclude Include="src\speaker\speaker_layouts.h" />
|
<ClInclude Include="src\speaker\speaker_layouts.h" />
|
||||||
<ClInclude Include="src\speaker\speaker_step.h" />
|
<ClInclude Include="src\speaker\speaker_step.h" />
|
||||||
<ClInclude Include="src\speaker\speaker_meta.h" />
|
|
||||||
<ClInclude Include="src\stream\stream.h" />
|
<ClInclude Include="src\stream\stream.h" />
|
||||||
<ClInclude Include="src\task\task.h" />
|
<ClInclude Include="src\task\task.h" />
|
||||||
<ClInclude Include="src\telemetry\event_bus.h" />
|
<ClInclude Include="src\telemetry\event_bus.h" />
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <cstddef>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -46,7 +45,6 @@ joc::stream::Config to_config(const joc_stream_config& config) {
|
|||||||
if (config.rosella_filterbank != 0u) {
|
if (config.rosella_filterbank != 0u) {
|
||||||
out.rosella_filterbank = config.rosella_filterbank;
|
out.rosella_filterbank = config.rosella_filterbank;
|
||||||
}
|
}
|
||||||
if (config.pcm_layout != nullptr) { out.pcm_layout = config.pcm_layout; }
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,19 +94,6 @@ joc_error JOC_CALL joc_stream_push(joc_stream* stream, const joc_stream_buffer*
|
|||||||
}
|
}
|
||||||
return pushed;
|
return pushed;
|
||||||
}
|
}
|
||||||
if (input->kind == JOC_STREAM_IN_PCM_LAYOUT) {
|
|
||||||
if (input->sample_rate != 0u && input->sample_rate != 48000u) {
|
|
||||||
return joc::Status::fail(JOC_ERR_INVALID_ARGUMENT, joc::stage::kRender,
|
|
||||||
"PCM layout input must be 48 kHz");
|
|
||||||
}
|
|
||||||
std::size_t consumed = 0;
|
|
||||||
const joc::Status pushed = stream->instance.push_pcm_layout(
|
|
||||||
input->pcm, input->sample_count, input->channels, &consumed);
|
|
||||||
if (consumed_samples != nullptr) {
|
|
||||||
*consumed_samples = static_cast<std::uint32_t>(consumed);
|
|
||||||
}
|
|
||||||
return pushed;
|
|
||||||
}
|
|
||||||
std::size_t consumed = 0;
|
std::size_t consumed = 0;
|
||||||
const std::uint32_t channels = input->channels != 0u ? input->channels : 6u;
|
const std::uint32_t channels = input->channels != 0u ? input->channels : 6u;
|
||||||
const joc::Status pushed =
|
const joc::Status pushed =
|
||||||
@@ -155,13 +140,8 @@ joc_error JOC_CALL joc_stream_reset(joc_stream* stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status_info* out) {
|
joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status_info* out) {
|
||||||
// The info struct only grows by appending fields, so a caller built against
|
|
||||||
// the previous size still gets every field it knows about.
|
|
||||||
constexpr uint32_t kSizeBeforeTruncatedFrames = static_cast<uint32_t>(
|
|
||||||
offsetof(joc_stream_status_info, truncated_joc_frames));
|
|
||||||
if (stream == nullptr || out == nullptr ||
|
if (stream == nullptr || out == nullptr ||
|
||||||
(out->struct_size != sizeof(joc_stream_status_info) &&
|
out->struct_size != sizeof(joc_stream_status_info)) {
|
||||||
out->struct_size != kSizeBeforeTruncatedFrames)) {
|
|
||||||
return JOC_ERR_INVALID_ARGUMENT;
|
return JOC_ERR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
const joc::stream::Info& info = stream->instance.info();
|
const joc::stream::Info& info = stream->instance.info();
|
||||||
@@ -180,9 +160,6 @@ joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status
|
|||||||
out->bed_mask_mismatch_frames = info.bed_mask_mismatch_frames;
|
out->bed_mask_mismatch_frames = info.bed_mask_mismatch_frames;
|
||||||
out->output_channels = info.output_channels;
|
out->output_channels = info.output_channels;
|
||||||
out->ended = info.ended;
|
out->ended = info.ended;
|
||||||
if (out->struct_size > kSizeBeforeTruncatedFrames) {
|
|
||||||
out->truncated_joc_frames = info.truncated_joc_frames;
|
|
||||||
}
|
|
||||||
return JOC_OK;
|
return JOC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ Status JochrtfRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kerne
|
|||||||
Status JochrtfRuntime::process_block() {
|
Status JochrtfRuntime::process_block() {
|
||||||
double positions[timeline::kTimelineObjects][3] = {};
|
double positions[timeline::kTimelineObjects][3] = {};
|
||||||
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
|
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
|
||||||
&positions[0][0],
|
positions);
|
||||||
timeline::kTimelineObjects);
|
|
||||||
if (!queried.ok()) {
|
if (!queried.ok()) {
|
||||||
return queried;
|
return queried;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ struct Options {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char* kLayoutChoices =
|
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 6.0";
|
"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";
|
||||||
|
|
||||||
void print_usage() {
|
void print_usage() {
|
||||||
std::printf(
|
std::printf(
|
||||||
@@ -97,7 +97,7 @@ void print_usage() {
|
|||||||
" input 输入 .m4a/.eac3/.ec3\n"
|
" input 输入 .m4a/.eac3/.ec3\n"
|
||||||
"\n"
|
"\n"
|
||||||
"模式(默认输出 ADM BWF):\n"
|
"模式(默认输出 ADM BWF):\n"
|
||||||
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、6.0、7.1.2\n"
|
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、7.1.2\n"
|
||||||
" 可选值: %s\n"
|
" 可选值: %s\n"
|
||||||
" --binaural 直接双耳渲染;不生成临时 ADM BWF\n"
|
" --binaural 直接双耳渲染;不生成临时 ADM BWF\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|||||||
@@ -102,15 +102,9 @@ 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);
|
const std::uint32_t has_sample_offset = reader.read(1);
|
||||||
std::uint32_t sample_offset = 0;
|
std::uint16_t sample_offset = 0;
|
||||||
if (has_sample_offset != 0u) {
|
if (has_sample_offset != 0u) {
|
||||||
std::uint32_t value = 0;
|
sample_offset = static_cast<std::uint16_t>(reader.read(12) >> 1);
|
||||||
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) {
|
if (reader.read(1) != 0u) {
|
||||||
std::uint32_t ignored = 0;
|
std::uint32_t ignored = 0;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ inline constexpr std::size_t kMaxPayloads = JOC_MAX_EMDF_PAYLOADS;
|
|||||||
|
|
||||||
struct Payload {
|
struct Payload {
|
||||||
std::uint8_t id = 0;
|
std::uint8_t id = 0;
|
||||||
std::uint32_t sample_offset = 0; // EMDF outer smpoffst: variable_bits(11)
|
std::uint16_t sample_offset = 0;
|
||||||
std::size_t bit_offset = 0; // MSB-first bit position of the payload bytes
|
std::size_t bit_offset = 0; // MSB-first bit position of the payload bytes
|
||||||
std::size_t size = 0; // payload byte count
|
std::size_t size = 0; // payload byte count
|
||||||
// Payload configuration data (ETSI TS 102 366 H.2.2.3). Spec section 8.2 and
|
// Payload configuration data (ETSI TS 102 366 H.2.2.3). Spec section 8.2 and
|
||||||
|
|||||||
@@ -1120,8 +1120,7 @@ struct RosellaRuntime::Impl {
|
|||||||
// rosella_binaural_renderer._set_block_parameters.
|
// rosella_binaural_renderer._set_block_parameters.
|
||||||
Status set_block_parameters(std::int64_t sample) {
|
Status set_block_parameters(std::int64_t sample) {
|
||||||
double positions[timeline::kTimelineObjects][3] = {};
|
double positions[timeline::kTimelineObjects][3] = {};
|
||||||
Status status = timeline.positions_at(sample, &positions[0][0],
|
Status status = timeline.positions_at(sample, positions);
|
||||||
timeline::kTimelineObjects);
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#include "joc_bitstream/bed_layout_map.h"
|
#include "joc_bitstream/bed_layout_map.h"
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "speaker/speaker_layouts.h"
|
#include "speaker/speaker_layouts.h"
|
||||||
@@ -44,10 +43,6 @@ constexpr BedChannel kNonStandardBits[17] = {
|
|||||||
BedChannel::kLeft,
|
BedChannel::kLeft,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 每个 bed 声道的固定方位:speakerLabel 各自对应唯一的 ADM (X,Y,Z),与目标扬声器
|
|
||||||
// 布局无关。天空声道的 X 取墙边(±1):点声源的横向声像只在扬声器跨度的端点之间分摊,
|
|
||||||
// 取端点仍落在输出布局顶部声道的满功率区里,与顶部声道互相下混的结果一致。Lw/Rw 的 Y
|
|
||||||
// 记作 0,677419,即 42/62 = 21/31。LFE/LFE2 不参与摆位,位置记为原点。
|
|
||||||
struct ChannelSpec {
|
struct ChannelSpec {
|
||||||
BedChannel channel;
|
BedChannel channel;
|
||||||
const char* short_name;
|
const char* short_name;
|
||||||
@@ -64,14 +59,14 @@ constexpr ChannelSpec kChannels[] = {
|
|||||||
{BedChannel::kRightSurround, "Rs", "RC_RS", {1.0, 0.0, 0.0}},
|
{BedChannel::kRightSurround, "Rs", "RC_RS", {1.0, 0.0, 0.0}},
|
||||||
{BedChannel::kLeftRearSurround, "Lrs", "RC_LB", {-1.0, -1.0, 0.0}},
|
{BedChannel::kLeftRearSurround, "Lrs", "RC_LB", {-1.0, -1.0, 0.0}},
|
||||||
{BedChannel::kRightRearSurround, "Rrs", "RC_RB", {1.0, -1.0, 0.0}},
|
{BedChannel::kRightRearSurround, "Rrs", "RC_RB", {1.0, -1.0, 0.0}},
|
||||||
{BedChannel::kTopFrontLeft, "Ltf", "RC_TFL", {-1.0, 1.0, 1.0}},
|
{BedChannel::kTopFrontLeft, "Ltf", "RC_TFL", {-0.5, 0.5, 1.0}},
|
||||||
{BedChannel::kTopFrontRight, "Rtf", "RC_TFR", {1.0, 1.0, 1.0}},
|
{BedChannel::kTopFrontRight, "Rtf", "RC_TFR", {0.5, 0.5, 1.0}},
|
||||||
{BedChannel::kTopSideLeft, "Ltm", "RC_TSL", {-1.0, 0.0, 1.0}},
|
{BedChannel::kTopSideLeft, "Ltm", "RC_TSL", {-1.0, 0.0, 1.0}},
|
||||||
{BedChannel::kTopSideRight, "Rtm", "RC_TSR", {1.0, 0.0, 1.0}},
|
{BedChannel::kTopSideRight, "Rtm", "RC_TSR", {1.0, 0.0, 1.0}},
|
||||||
{BedChannel::kTopBackLeft, "Ltr", "RC_TBL", {-1.0, -1.0, 1.0}},
|
{BedChannel::kTopBackLeft, "Ltr", "RC_TBL", {-0.5, -0.5, 1.0}},
|
||||||
{BedChannel::kTopBackRight, "Rtr", "RC_TBR", {1.0, -1.0, 1.0}},
|
{BedChannel::kTopBackRight, "Rtr", "RC_TBR", {0.5, -0.5, 1.0}},
|
||||||
{BedChannel::kLeftWide, "Lw", "RC_LW", {-1.0, 21.0 / 31.0, 0.0}},
|
{BedChannel::kLeftWide, "Lw", "RC_LW", {-1.0, 0.5, 0.0}},
|
||||||
{BedChannel::kRightWide, "Rw", "RC_RW", {1.0, 21.0 / 31.0, 0.0}},
|
{BedChannel::kRightWide, "Rw", "RC_RW", {1.0, 0.5, 0.0}},
|
||||||
{BedChannel::kLfe2, "LFE2", "RC_LFE2", {0.0, 0.0, 0.0}},
|
{BedChannel::kLfe2, "LFE2", "RC_LFE2", {0.0, 0.0, 0.0}},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,9 +100,6 @@ constexpr LayoutName kLayoutNames[] = {
|
|||||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe), "5.1"},
|
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::kLeft) | bit(BedChannel::kRight) |
|
||||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||||
@@ -283,18 +275,12 @@ bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]) {
|
|||||||
if (!bed_channel_adm_position(channel, xyz) || q15 == nullptr) {
|
if (!bed_channel_adm_position(channel, xyz) || q15 == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Q15 满刻度是 32768(渲染器按 q / 32768 还原方位),所以用 32768 定标并四舍五入;
|
const double q1 = (xyz[0] + 1.0) * 0.5 * 32767.0;
|
||||||
// 截断会让半格位置(16384、7928)各低 1。
|
const double q2 = (1.0 - xyz[1]) * 0.5 * 32767.0;
|
||||||
const double q1 = (xyz[0] + 1.0) * 0.5 * 32768.0;
|
const double q3 = xyz[2] * 32767.0;
|
||||||
const double q2 = (1.0 - xyz[1]) * 0.5 * 32768.0;
|
q15[0] = static_cast<std::uint16_t>(q1 < 0.0 ? 0.0 : (q1 > 32767.0 ? 32767.0 : q1));
|
||||||
const double q3 = xyz[2] * 32768.0;
|
q15[1] = static_cast<std::uint16_t>(q2 < 0.0 ? 0.0 : (q2 > 32767.0 ? 32767.0 : q2));
|
||||||
const double rounded[3] = {q1 + 0.5, q2 + 0.5, q3 + 0.5};
|
q15[2] = static_cast<std::uint16_t>(q3 < 0.0 ? 0.0 : (q3 > 32767.0 ? 32767.0 : q3));
|
||||||
for (int axis = 0; axis < 3; ++axis) {
|
|
||||||
const double value = rounded[axis] < 0.0
|
|
||||||
? 0.0
|
|
||||||
: (rounded[axis] > 32767.0 ? 32767.0 : rounded[axis]);
|
|
||||||
q15[axis] = static_cast<std::uint16_t>(value);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,19 +304,17 @@ bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
|||||||
if (table == nullptr || geometry == nullptr) {
|
if (table == nullptr || geometry == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// channel_names 与区域几何同序(region 的 speaker_id 就是这里的下标),
|
int standard_index = -1;
|
||||||
// 因此同名声道不需要再经 standard_from_internal 换序。
|
|
||||||
int internal_index = -1;
|
|
||||||
for (std::uint32_t index = 0; index < table->count; ++index) {
|
for (std::uint32_t index = 0; index < table->count; ++index) {
|
||||||
if (std::strcmp(table->names[index], name) == 0) {
|
if (std::strcmp(table->names[index], name) == 0) {
|
||||||
internal_index = static_cast<int>(index);
|
standard_index = static_cast<int>(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (internal_index < 0) {
|
if (standard_index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const std::uint8_t internal = static_cast<std::uint8_t>(internal_index);
|
const std::uint8_t internal = geometry->standard_from_internal[standard_index];
|
||||||
const ejoc::speaker_tables::RegionGeometry& region = geometry->regions[0];
|
const ejoc::speaker_tables::RegionGeometry& region = geometry->regions[0];
|
||||||
for (std::uint32_t point = 0; point < region.point_count; ++point) {
|
for (std::uint32_t point = 0; point < region.point_count; ++point) {
|
||||||
if (region.points[point].speaker_id != internal) {
|
if (region.points[point].speaker_id != internal) {
|
||||||
@@ -344,301 +328,4 @@ bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
|||||||
return false;
|
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
|
} // namespace joc::joc
|
||||||
@@ -6,12 +6,31 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "oamd/oamd_parser.h"
|
#include "oamd/oamd_parser.h"
|
||||||
#include "speaker/speaker_layout_lookup.h"
|
|
||||||
|
|
||||||
namespace joc::joc {
|
namespace joc::joc {
|
||||||
|
|
||||||
// BedChannel lives in oamd/oamd_parser.h: the enum is the OAMD Table 12
|
// OAMD Table 12 的标准 bed 声道。LSB 顺序与声明顺序一致:L/R、C、LFE、
|
||||||
// label order and OAMD frame state carries it directly.
|
// 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,
|
||||||
|
};
|
||||||
|
|
||||||
// 内容声明的 bed 布局。bed 对象在 OAMD 里没有位置字段,位置由这里的布局决定。
|
// 内容声明的 bed 布局。bed 对象在 OAMD 里没有位置字段,位置由这里的布局决定。
|
||||||
struct BedLayout {
|
struct BedLayout {
|
||||||
@@ -42,28 +61,8 @@ bool bed_channel_adm_position(BedChannel channel, double xyz[3]);
|
|||||||
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]);
|
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]);
|
||||||
|
|
||||||
// 目标布局里同名扬声器的 Q15 方位:bed 声道直连到该扬声器,而不是参与声像。
|
// 目标布局里同名扬声器的 Q15 方位:bed 声道直连到该扬声器,而不是参与声像。
|
||||||
// 目标布局没有这个声道时返回 false。4.0 与 6.0 共用未分配的 out_ch_config
|
// 目标布局没有这个声道时返回 false。
|
||||||
// 0xFF,因此这里按 4.0 的声道集合解释 0xFF。
|
|
||||||
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
||||||
std::uint16_t q15[3]);
|
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
|
} // namespace joc::joc
|
||||||
@@ -182,77 +182,6 @@ std::int16_t num_bands_for_index(std::uint32_t num_bands_idx) {
|
|||||||
return -1;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A payload that runs out of bits after the joc_header is a damaged but
|
|
||||||
// identifiable JOC frame: the header, clipgain, sequence counter and object
|
|
||||||
// parameters are intact, so the frame keeps its identity and the renderer can
|
|
||||||
// hold the previous matrices instead of stopping the stream. A payload that
|
|
||||||
// ends before the header cannot be classified and stays a transport error; a
|
|
||||||
// Huffman walk that leaves the tree is a syntax error, never a truncation.
|
|
||||||
Status truncated_frame(const bits::BitReader& reader, joc_frame_params* out,
|
|
||||||
const std::uint8_t* payload, std::size_t payload_size) {
|
|
||||||
if (reader.error() != JOC_ERR_BITSTREAM_TRUNCATED) {
|
|
||||||
return syntax_fail(reader.error_message());
|
|
||||||
}
|
|
||||||
out->status = JOC_FRAME_STATUS_TRUNCATED;
|
|
||||||
out->present_mask = 0u;
|
|
||||||
for (std::uint32_t obj = 0; obj < out->n_objects; ++obj) {
|
|
||||||
if (out->objects[obj].present != 0u) {
|
|
||||||
out->present_mask |= 1u << obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tail_info(out, reader, payload, payload_size);
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out,
|
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out,
|
||||||
FrameSymbols* symbols) {
|
FrameSymbols* symbols) {
|
||||||
if (payload == nullptr || out == nullptr) {
|
if (payload == nullptr || out == nullptr) {
|
||||||
@@ -266,53 +195,45 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
FrameSymbols& capture = (symbols != nullptr) ? *symbols : local_symbols;
|
FrameSymbols& capture = (symbols != nullptr) ? *symbols : local_symbols;
|
||||||
std::memset(&capture, 0, sizeof(capture));
|
std::memset(&capture, 0, sizeof(capture));
|
||||||
|
|
||||||
const Status header = parse_id14_header(payload, payload_size, out);
|
|
||||||
if (!header.ok()) {
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
bits::BitReader reader(payload, payload_size);
|
bits::BitReader reader(payload, payload_size);
|
||||||
reader.skip(12);
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
out->clipgain_x_bits = static_cast<std::uint8_t>(reader.read(3));
|
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->clipgain_y_bits = static_cast<std::uint8_t>(reader.read(5));
|
||||||
out->seq_count = reader.read(10);
|
out->seq_count = reader.read(10);
|
||||||
if (reader.failed()) {
|
// clipgain = 1 + (y/32) * 2^(x-4); ldexp builds the power of two exactly
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
// over the whole legal range.
|
||||||
}
|
out->clipgain = 1.0 + static_cast<double>(out->clipgain_y_bits) / 32.0 *
|
||||||
// clipgain = 2^(x-4) * (1 + y/32); ldexp builds the power of two exactly
|
std::ldexp(1.0, static_cast<int>(out->clipgain_x_bits) - 4);
|
||||||
// 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) {
|
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||||
joc_object_params& info = out->objects[obj];
|
joc_object_params& info = out->objects[obj];
|
||||||
info.present = static_cast<std::uint8_t>(reader.read(1));
|
info.present = static_cast<std::uint8_t>(reader.read(1));
|
||||||
if (reader.failed()) {
|
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
|
||||||
}
|
|
||||||
if (info.present == 0u) {
|
if (info.present == 0u) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
|
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||||
if (reader.failed()) {
|
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
|
||||||
}
|
|
||||||
const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
|
const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
|
||||||
if (bands < 0) {
|
if (bands < 0) {
|
||||||
// The symbol count depends on the parameter-band count, so the rest
|
return syntax_fail("unknown JOC num_bands index " +
|
||||||
// of the payload cannot be parsed.
|
std::to_string(info.num_bands_idx));
|
||||||
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.n_bands = static_cast<std::uint8_t>(bands);
|
||||||
info.sparse = static_cast<std::uint8_t>(reader.read(1));
|
info.sparse = static_cast<std::uint8_t>(reader.read(1));
|
||||||
@@ -320,42 +241,16 @@ 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.slope_idx = static_cast<std::uint8_t>(reader.read(1));
|
||||||
info.num_dpoints_bits = 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);
|
info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u);
|
||||||
if (reader.failed()) {
|
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
|
||||||
}
|
|
||||||
if (info.slope_idx == 1u) {
|
if (info.slope_idx == 1u) {
|
||||||
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
|
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
|
||||||
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5));
|
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5) + 1u);
|
||||||
}
|
|
||||||
if (reader.failed()) {
|
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
|
||||||
}
|
|
||||||
// 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) {
|
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||||
const joc_object_params& info = out->objects[obj];
|
const joc_object_params& info = out->objects[obj];
|
||||||
if (info.present == 0u) {
|
if (info.present == 0u) {
|
||||||
@@ -372,13 +267,13 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
const Tree idx_tree = select_tree(info.quant_idx, SymbolKind::Idx, n_channels);
|
const Tree idx_tree = select_tree(info.quant_idx, SymbolKind::Idx, n_channels);
|
||||||
const std::uint32_t first = reader.read(3);
|
const std::uint32_t first = reader.read(3);
|
||||||
if (reader.failed()) {
|
if (reader.failed()) {
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
return truncated_fail(reader);
|
||||||
}
|
}
|
||||||
symbol->idx[dp][0] = static_cast<std::uint8_t>(first);
|
symbol->idx[dp][0] = static_cast<std::uint8_t>(first);
|
||||||
for (int pb = 1; pb < info.n_bands; ++pb) {
|
for (int pb = 1; pb < info.n_bands; ++pb) {
|
||||||
std::int16_t value = 0;
|
std::int16_t value = 0;
|
||||||
if (!huff_decode(idx_tree, reader, &value)) {
|
if (!huff_decode(idx_tree, reader, &value)) {
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
return truncated_fail(reader);
|
||||||
}
|
}
|
||||||
symbol->idx[dp][pb] = static_cast<std::uint8_t>(value);
|
symbol->idx[dp][pb] = static_cast<std::uint8_t>(value);
|
||||||
}
|
}
|
||||||
@@ -386,7 +281,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||||
std::int16_t value = 0;
|
std::int16_t value = 0;
|
||||||
if (!huff_decode(vec_tree, reader, &value)) {
|
if (!huff_decode(vec_tree, reader, &value)) {
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
return truncated_fail(reader);
|
||||||
}
|
}
|
||||||
symbol->vec[dp][pb] = value;
|
symbol->vec[dp][pb] = value;
|
||||||
}
|
}
|
||||||
@@ -396,7 +291,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||||
std::int16_t value = 0;
|
std::int16_t value = 0;
|
||||||
if (!huff_decode(mtx_tree, reader, &value)) {
|
if (!huff_decode(mtx_tree, reader, &value)) {
|
||||||
return truncated_frame(reader, out, payload, payload_size);
|
return truncated_fail(reader);
|
||||||
}
|
}
|
||||||
symbol->mtx[dp][ch][pb] = value;
|
symbol->mtx[dp][ch][pb] = value;
|
||||||
}
|
}
|
||||||
@@ -405,16 +300,12 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tail_info(out, reader, payload, payload_size);
|
out->data_end_bits = static_cast<std::uint32_t>(reader.position());
|
||||||
if (out->status == JOC_FRAME_STATUS_OK && out->ext_config_idx == 0u) {
|
out->trailing_bits = static_cast<std::uint32_t>(payload_size * 8u - reader.position());
|
||||||
// The tail pads with zero bits up to the next byte; a whole byte after
|
const std::size_t tail_offset = reader.position() / 8u;
|
||||||
// that alignment is unexpected data.
|
if (tail_offset < payload_size) {
|
||||||
const std::uint32_t pad =
|
const std::size_t tail_bytes = std::min<std::size_t>(8u, payload_size - tail_offset);
|
||||||
(8u - (static_cast<std::uint32_t>(reader.position()) % 8u)) % 8u;
|
std::memcpy(out->tail_bytes, payload + tail_offset, tail_bytes);
|
||||||
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) {
|
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||||
@@ -422,7 +313,8 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
|||||||
if (info.present == 0u) {
|
if (info.present == 0u) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
out->present_mask |= 1u << obj;
|
std::uint32_t mask_bit = 1u << obj;
|
||||||
|
out->present_mask |= mask_bit;
|
||||||
|
|
||||||
const std::int64_t nquant = (info.quant_idx == 0u) ? 96 : 192;
|
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] = {};
|
std::int64_t q[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS] = {};
|
||||||
@@ -480,16 +372,7 @@ int score_container_as_joc(const std::uint8_t* data, std::size_t size,
|
|||||||
if (emdf::extract_payload_bytes(data, size, *payload, &bytes).ok()) {
|
if (emdf::extract_payload_bytes(data, size, *payload, &bytes).ok()) {
|
||||||
joc_frame_params params;
|
joc_frame_params params;
|
||||||
FrameSymbols symbols;
|
FrameSymbols symbols;
|
||||||
if (parse_id14(bytes.data(), bytes.size(), ¶ms, &symbols).ok()) {
|
parses = parse_id14(bytes.data(), bytes.size(), ¶ms, &symbols).ok();
|
||||||
// The reference scores a payload by the frame status: an unsupported
|
|
||||||
// downmix configuration (2), an unknown parameter-band count (4) or a
|
|
||||||
// payload that ends inside joc_data (7) must not win the container
|
|
||||||
// choice, because another candidate may carry the frame's complete
|
|
||||||
// metadata.
|
|
||||||
parses = params.status != JOC_FRAME_STATUS_UNSUPPORTED_DMX &&
|
|
||||||
params.status != JOC_FRAME_STATUS_BAD_PARAMETER_BAND &&
|
|
||||||
params.status != JOC_FRAME_STATUS_TRUNCATED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const bool associated = oamd->has_group_id != 0u && payload->has_group_id != 0u &&
|
const bool associated = oamd->has_group_id != 0u && payload->has_group_id != 0u &&
|
||||||
oamd->group_id == payload->group_id;
|
oamd->group_id == payload->group_id;
|
||||||
@@ -523,20 +406,7 @@ Status parse_eac3_frame(const std::uint8_t* frame, std::size_t frame_size, joc_f
|
|||||||
if (!extract.ok()) {
|
if (!extract.ok()) {
|
||||||
return extract;
|
return extract;
|
||||||
}
|
}
|
||||||
const Status parsed = parse_id14(bytes.data(), bytes.size(), out, symbols);
|
return 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,
|
Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
||||||
@@ -547,21 +417,6 @@ Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
|||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
// The statuses that stop the parse early leave the payload without a
|
|
||||||
// joc_data end position, so they keep reporting the 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 (params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
|
||||||
return Status::fail(JOC_ERR_BITSTREAM_TRUNCATED, stage::kJoc,
|
|
||||||
"the ID14 payload ends before its joc_data is complete");
|
|
||||||
}
|
|
||||||
if (out_trailing_bits != nullptr) {
|
if (out_trailing_bits != nullptr) {
|
||||||
*out_trailing_bits = params.trailing_bits;
|
*out_trailing_bits = params.trailing_bits;
|
||||||
}
|
}
|
||||||
@@ -1006,7 +861,6 @@ Status check_cross_layer(const joc_frame_params& params, const eac3::Frame* core
|
|||||||
std::uint16_t chanmap,
|
std::uint16_t chanmap,
|
||||||
const std::vector<oamd::BedAssignment>* bed_assignments,
|
const std::vector<oamd::BedAssignment>* bed_assignments,
|
||||||
std::string* error, CrossLayerNotes* notes) {
|
std::string* error, CrossLayerNotes* notes) {
|
||||||
(void)has_dependent;
|
|
||||||
const std::uint8_t config_idx = params.dmx_config_idx;
|
const std::uint8_t config_idx = params.dmx_config_idx;
|
||||||
const int core_channels = params.n_channels;
|
const int core_channels = params.n_channels;
|
||||||
std::vector<Position> wanted;
|
std::vector<Position> wanted;
|
||||||
|
|||||||
@@ -69,19 +69,6 @@ public:
|
|||||||
std::memset(synthesis_state_, 0, sizeof(synthesis_state_));
|
std::memset(synthesis_state_, 0, sizeof(synthesis_state_));
|
||||||
std::memset(x_, 0, sizeof(x_));
|
std::memset(x_, 0, sizeof(x_));
|
||||||
std::memset(z_, 0, sizeof(z_));
|
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,
|
// Sentinel: the first frame after reset takes the new scalar directly,
|
||||||
// without an intra-frame transition.
|
// without an intra-frame transition.
|
||||||
analysis_phase_ = -0.5f;
|
analysis_phase_ = -0.5f;
|
||||||
@@ -187,22 +174,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::memset(output16, 0, sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
|
std::memset(output16, 0, sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
|
||||||
// Analysis-side scalar = the structural 1/16 times this frame's clipgain.
|
analysis(bed_planar, phase_new, clipgain);
|
||||||
// clipgain enters the analysis at this stage and the x16 at the output
|
render_lfe(lfe, output_scale, output16);
|
||||||
// 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,
|
process_objects(object_mask, n_bands, n_dpoints, slope_idx, offset_ts,
|
||||||
dq, output_scale, output16);
|
dq, output_scale, output16);
|
||||||
return 0;
|
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:
|
private:
|
||||||
void initialize_tables() noexcept {
|
void initialize_tables() noexcept {
|
||||||
for (int i = 0; i < 64; ++i) {
|
for (int i = 0; i < 64; ++i) {
|
||||||
@@ -400,12 +378,13 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frames the analysis QMF of the core PCM with the given analysis-side
|
void analysis(const float* bed_planar, const float phase_new, const double clipgain) noexcept {
|
||||||
// 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;
|
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_;
|
job_phase_old_ = analysis_phase_;
|
||||||
if (job_phase_old_ <= 0.0f && job_phase_old_ != 0.0f) {
|
if (job_phase_old_ <= 0.0f && job_phase_old_ != 0.0f) {
|
||||||
job_phase_old_ = scalar;
|
job_phase_old_ = scalar;
|
||||||
@@ -530,11 +509,11 @@ private:
|
|||||||
}
|
}
|
||||||
qmf5_step(state, rotated, pcm64);
|
qmf5_step(state, rotated, pcm64);
|
||||||
for (int sample = 0; sample < 64; ++sample) {
|
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]);
|
const double clipped = clamp_unit(16.0 * pcm64[sample]);
|
||||||
destination[timeslot * 64 + sample] = static_cast<float>(clipped) * output_scale;
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,10 +533,8 @@ private:
|
|||||||
const int item = job_objects_[index];
|
const int item = job_objects_[index];
|
||||||
if (job_kind_ == JobKind::Analysis) {
|
if (job_kind_ == JobKind::Analysis) {
|
||||||
analysis_channel(item);
|
analysis_channel(item);
|
||||||
} else if (job_kind_ == JobKind::Objects) {
|
|
||||||
process_one_object(item);
|
|
||||||
} else {
|
} else {
|
||||||
process_one_object_frame(item);
|
process_one_object(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -643,503 +620,24 @@ private:
|
|||||||
dispatch_jobs();
|
dispatch_jobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Core LFE: the full joc_clipgain is applied as a sample-wise ramp before the
|
void render_lfe(const float* lfe, const float output_scale, float* output16) noexcept {
|
||||||
// 1217-sample delay, and the read-out is only clamped. The ramp is
|
if (!lfe) {
|
||||||
// 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 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 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;
|
return;
|
||||||
}
|
}
|
||||||
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
|
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||||
std::memset(analysis_fifo_[channel], 0, sizeof(analysis_fifo_[channel]));
|
const float value = static_cast<float>(clamp_unit(lfe_delay_[sample]));
|
||||||
|
output16[sample] = static_cast<float>(value * output_scale);
|
||||||
}
|
}
|
||||||
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
|
for (int sample = kLfeDelay; sample < 1536; ++sample) {
|
||||||
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
|
const float value = static_cast<float>(clamp_unit(static_cast<double>(lfe[sample - kLfeDelay])));
|
||||||
std::memset(prev_matrix_[object][channel], 0,
|
output16[sample] = static_cast<float>(value * output_scale);
|
||||||
sizeof(prev_matrix_[object][channel]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (n_channels == 5u) {
|
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||||
// A 5-channel frame does not drive the extra-pair delay lanes.
|
lfe_delay_[sample] = static_cast<double>(lfe[sample + (1536 - kLfeDelay)]);
|
||||||
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
|
enum class JobKind : uint8_t { Analysis, Objects };
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compatibility note for frames without JOC metadata (status 8).
|
|
||||||
//
|
|
||||||
// The state machine used to map status 8 to Passthrough unconditionally,
|
|
||||||
// including in the middle of a stream. That is only meaningful before the
|
|
||||||
// first valid JOC frame: a plain E-AC-3 stream (or a stream whose first JOC
|
|
||||||
// frame comes late) has no object state yet, so the core planes are all
|
|
||||||
// there is and the delayed core PCM is the right output. In the middle of
|
|
||||||
// a JOC stream a frame without metadata is a damaged frame, not "no
|
|
||||||
// objects": the Passthrough output replaces the object render with the core
|
|
||||||
// planes, and the object synthesis restarts from silence on the next frame.
|
|
||||||
// Every such frame therefore produced a step at the frame boundary and a
|
|
||||||
// second one when the metadata came back; encoders that are not careful
|
|
||||||
// with the JOC EMDF container emit exactly those frames.
|
|
||||||
//
|
|
||||||
// After the change status 8 follows the state machine like the other
|
|
||||||
// invalid statuses: state 0 (no valid frame rendered yet) stays Passthrough,
|
|
||||||
// and state 3 (mid-stream) selects Hold, which reuses the previous object
|
|
||||||
// matrices and keeps the bed and object rendering continuous.
|
|
||||||
//
|
|
||||||
// This is a compatibility choice, not a claim about the normative reading
|
|
||||||
// of the specification: a frame without metadata can be argued to be the
|
|
||||||
// Passthrough case. It exists so that non-standard streams stay click-free;
|
|
||||||
// if the reference behaviour is preferred, re-add the unconditional
|
|
||||||
// Passthrough branch here.
|
|
||||||
FrameMode select_mode(const uint32_t status) const noexcept {
|
|
||||||
if (status == EJOC_FRAME_STATUS_NO_METADATA) {
|
|
||||||
// See the note above: only a stream that has not rendered a valid
|
|
||||||
// frame yet has nothing to hold.
|
|
||||||
return state_ == 0u ? FrameMode::Passthrough : FrameMode::Hold;
|
|
||||||
}
|
|
||||||
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 > 7u)) {
|
|
||||||
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::vector<std::thread> workers_;
|
||||||
std::unique_ptr<std::barrier<>> work_barrier_;
|
std::unique_ptr<std::barrier<>> work_barrier_;
|
||||||
@@ -1159,8 +657,6 @@ private:
|
|||||||
const double* job_dq_ = nullptr;
|
const double* job_dq_ = nullptr;
|
||||||
float job_output_scale_ = 1.0f;
|
float job_output_scale_ = 1.0f;
|
||||||
float* job_output16_ = nullptr;
|
float* job_output16_ = nullptr;
|
||||||
uint32_t job_object_mask_ = 0;
|
|
||||||
FrameMode frame_mode_ = FrameMode::Normal;
|
|
||||||
|
|
||||||
uint32_t core_channels_ = EJOC_CORE_CHANNELS;
|
uint32_t core_channels_ = EJOC_CORE_CHANNELS;
|
||||||
alignas(64) double analysis_fifo_[EJOC_MAX_CORE_CHANNELS][9][64];
|
alignas(64) double analysis_fifo_[EJOC_MAX_CORE_CHANNELS][9][64];
|
||||||
@@ -1172,29 +668,11 @@ private:
|
|||||||
// sigma(k) switch; the caller sets it for downmix configurations 3 and 4.
|
// sigma(k) switch; the caller sets it for downmix configurations 3 and 4.
|
||||||
bool phase_shift_enabled_ = true;
|
bool phase_shift_enabled_ = true;
|
||||||
alignas(64) double lfe_delay_[kLfeDelay];
|
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 matrix_previous_[15][EJOC_MAX_CORE_CHANNELS][64];
|
||||||
alignas(64) double synthesis_state_[15][640];
|
alignas(64) double synthesis_state_[15][640];
|
||||||
alignas(64) Complex x_[EJOC_MAX_CORE_CHANNELS][64][24];
|
alignas(64) Complex x_[EJOC_MAX_CORE_CHANNELS][64][24];
|
||||||
alignas(64) Complex z_[15][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];
|
uint8_t bit_reverse_[64];
|
||||||
Complex fft_twiddle_[32];
|
Complex fft_twiddle_[32];
|
||||||
double rotation_sin_[64];
|
double rotation_sin_[64];
|
||||||
@@ -1212,13 +690,13 @@ uint32_t EJOC_CALL ejoc_abi_version(void) {
|
|||||||
|
|
||||||
const char* EJOC_CALL ejoc_build_info(void) {
|
const char* EJOC_CALL ejoc_build_info(void) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
return "eac3joc-core abi=4 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
|
return "eac3joc-core abi=1 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
return "eac3joc-core abi=4 compiler=Clang fft=fixed64 speaker=double binaural=double";
|
return "eac3joc-core abi=1 compiler=Clang fft=fixed64 speaker=double binaural=double";
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
return "eac3joc-core abi=4 compiler=GCC fft=fixed64 speaker=double binaural=double";
|
return "eac3joc-core abi=1 compiler=GCC fft=fixed64 speaker=double binaural=double";
|
||||||
#else
|
#else
|
||||||
return "eac3joc-core abi=4 compiler=unknown fft=fixed64 speaker=double binaural=double";
|
return "eac3joc-core abi=1 compiler=unknown fft=fixed64 speaker=double binaural=double";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1282,15 +760,4 @@ int EJOC_CALL ejoc_renderer_process(
|
|||||||
slope_idx, offset_ts, dq, clipgain, phase_new, output_scale, output16_planar);
|
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"
|
} // extern "C"
|
||||||
@@ -6,17 +6,16 @@
|
|||||||
namespace joc::joc {
|
namespace joc::joc {
|
||||||
|
|
||||||
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
|
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
|
||||||
const float* bed_planar, const float* lfe,
|
const float* bed_planar, const float* lfe, float gain,
|
||||||
std::uint32_t core_channel_count, bool has_metadata, float gain,
|
|
||||||
std::vector<float>* out16, std::string* error) {
|
std::vector<float>* out16, std::string* error) {
|
||||||
if (handle == nullptr || bed_planar == nullptr || out16 == nullptr) {
|
if (handle == nullptr || bed_planar == nullptr || out16 == nullptr) {
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kDsp, "null argument");
|
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kDsp, "null argument");
|
||||||
}
|
}
|
||||||
if (core_channel_count != JOC_CORE_CHANNELS &&
|
if (params.n_channels != JOC_CORE_CHANNELS &&
|
||||||
core_channel_count != JOC_MAX_CORE_CHANNELS) {
|
params.n_channels != JOC_MAX_CORE_CHANNELS) {
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
*error = "the reused JOC kernel requires 5 or 7 core channels, the frame has " +
|
*error = "the reused JOC kernel requires 5 or 7 core channels, frame declares " +
|
||||||
std::to_string(core_channel_count);
|
std::to_string(static_cast<unsigned>(params.n_channels));
|
||||||
}
|
}
|
||||||
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kDsp, *error);
|
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kDsp, *error);
|
||||||
}
|
}
|
||||||
@@ -40,7 +39,7 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
|
|||||||
offset_ts[obj * JOC_MAX_DPOINTS + dp] = object.offset_ts[dp];
|
offset_ts[obj * JOC_MAX_DPOINTS + dp] = object.offset_ts[dp];
|
||||||
}
|
}
|
||||||
for (unsigned dp = 0; dp < object.n_dpoints; ++dp) {
|
for (unsigned dp = 0; dp < object.n_dpoints; ++dp) {
|
||||||
for (unsigned ch = 0; ch < core_channel_count; ++ch) {
|
for (unsigned ch = 0; ch < params.n_channels; ++ch) {
|
||||||
for (unsigned pb = 0; pb < object.n_bands; ++pb) {
|
for (unsigned pb = 0; pb < object.n_bands; ++pb) {
|
||||||
const std::size_t index =
|
const std::size_t index =
|
||||||
((static_cast<std::size_t>(obj) * JOC_MAX_DPOINTS + dp) *
|
((static_cast<std::size_t>(obj) * JOC_MAX_DPOINTS + dp) *
|
||||||
@@ -54,42 +53,19 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ejoc_frame_input input{};
|
out16->assign(static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES, 0.0f);
|
||||||
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
|
// 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.
|
// DC compensation together; other configurations keep the common processing.
|
||||||
// An unsupported downmix configuration (status 2) has no usable switch, so
|
const std::uint32_t phase_shift =
|
||||||
// the renderer keeps the previous one.
|
(params.dmx_config_idx == 3 || params.dmx_config_idx == 4) ? 1u : 0u;
|
||||||
input.phase_shift =
|
const int result = ejoc_renderer_process(
|
||||||
(params.dmx_config_idx == 3u || params.dmx_config_idx == 4u) ? 1u : 0u;
|
handle, bed_planar, lfe, params.n_channels, phase_shift, params.present_mask, n_bands,
|
||||||
input.phase_shift_valid = params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX ? 0u : 1u;
|
n_dpoints, slope_idx, offset_ts, dq.data(), params.clipgain, 0.0625f, gain,
|
||||||
input.frame_status = has_metadata ? params.status : EJOC_FRAME_STATUS_NO_METADATA;
|
out16->data());
|
||||||
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) {
|
if (result != 0) {
|
||||||
const char* detail = ejoc_renderer_last_error(handle);
|
const char* detail = ejoc_renderer_last_error(handle);
|
||||||
const std::string message =
|
const std::string message =
|
||||||
"ejoc_renderer_render_frame failed (" + std::to_string(result) + "): " +
|
"ejoc_renderer_process failed (" + std::to_string(result) + "): " +
|
||||||
(detail != nullptr ? detail : "unknown");
|
(detail != nullptr ? detail : "unknown");
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
*error = message;
|
*error = message;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -11,20 +10,10 @@
|
|||||||
|
|
||||||
namespace joc::joc {
|
namespace joc::joc {
|
||||||
|
|
||||||
// Rebuilds the 16-channel object frame ([16][1536] planar float32) for one
|
// [16][1536] planar float32. bed_planar is [params.n_channels][1536], where
|
||||||
// audio frame through the renderer's frame-level state machine. bed_planar is
|
// n_channels comes from joc_dmx_config_idx (5 or 7).
|
||||||
// [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,
|
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
|
||||||
const float* bed_planar, const float* lfe,
|
const float* bed_planar, const float* lfe, float gain,
|
||||||
std::uint32_t core_channel_count, bool has_metadata, float gain,
|
|
||||||
std::vector<float>* out16, std::string* error);
|
std::vector<float>* out16, std::string* error);
|
||||||
|
|
||||||
} // namespace joc::joc
|
} // namespace joc::joc
|
||||||
@@ -338,7 +338,7 @@ inline constexpr uint8_t kPbMap1[64] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr uint8_t kPbMap3[64] = {
|
inline constexpr uint8_t kPbMap3[64] = {
|
||||||
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
|
0, 0, 0, 1, 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, 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] = {
|
inline constexpr uint8_t kPbMap5[64] = {
|
||||||
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
|
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
|
||||||
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
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, 4, 4, 4,
|
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, 4, 4, 4, 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -359,8 +359,8 @@ inline constexpr uint8_t kPbMap7[64] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr uint8_t kPbMap9[64] = {
|
inline constexpr uint8_t kPbMap9[64] = {
|
||||||
0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7,
|
0, 1, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8,
|
||||||
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,
|
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, 8, 8, 8, 8, 8, 8, 8,
|
||||||
};
|
};
|
||||||
@@ -373,9 +373,9 @@ inline constexpr uint8_t kPbMap12[64] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr uint8_t kPbMap15[64] = {
|
inline constexpr uint8_t kPbMap15[64] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11,
|
||||||
11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
|
||||||
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,
|
||||||
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, 14, 14, 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,101 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
#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,
|
|
||||||
¶ms.layout_groups.floor_a);
|
|
||||||
copy_groups(tables::kLayoutGroups.floor_b, tables::kLayoutGroups.floor_b_count,
|
|
||||||
¶ms.layout_groups.floor_b);
|
|
||||||
copy_groups(tables::kLayoutGroups.height, tables::kLayoutGroups.height_count,
|
|
||||||
¶ms.layout_groups.height);
|
|
||||||
copy_groups(tables::kLayoutGroups.additional, tables::kLayoutGroups.additional_count,
|
|
||||||
¶ms.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
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
// 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
|
|
||||||
+348
-1077
File diff suppressed because it is too large.
Load diff
+11
-172
@@ -9,34 +9,6 @@
|
|||||||
#include "foundation/status.h"
|
#include "foundation/status.h"
|
||||||
#include "joc_core.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 {
|
namespace joc::oamd {
|
||||||
|
|
||||||
inline constexpr int kMaxSlots = 16;
|
inline constexpr int kMaxSlots = 16;
|
||||||
@@ -45,16 +17,8 @@ inline constexpr int kAxes = 3;
|
|||||||
inline constexpr int kNQ12 = 62;
|
inline constexpr int kNQ12 = 62;
|
||||||
inline constexpr int kNQ3 = 15;
|
inline constexpr int kNQ3 = 15;
|
||||||
inline constexpr int kQ15Scale = 32768;
|
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 kTrimElementId = 2;
|
||||||
inline constexpr std::uint32_t kObjectElementId = 1;
|
|
||||||
inline constexpr std::uint32_t kExtendedElementId = 5;
|
|
||||||
inline constexpr int kTrimConfigs = 9;
|
inline constexpr int kTrimConfigs = 9;
|
||||||
inline constexpr int kBedLabelCount = 17;
|
|
||||||
|
|
||||||
// One of the nine per-configuration trim records of the OAMD trim element.
|
// One of the nine per-configuration trim records of the OAMD trim element.
|
||||||
// ``kAbsent`` means the configuration carries no data (the element only
|
// ``kAbsent`` means the configuration carries no data (the element only
|
||||||
@@ -86,92 +50,6 @@ struct OamdTrim {
|
|||||||
bool disable_per_object[kMaxSlots] = {};
|
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.
|
// (the reference's None), i.e. hold the previous position.
|
||||||
struct SlotUpdate {
|
struct SlotUpdate {
|
||||||
std::int16_t q1 = -1;
|
std::int16_t q1 = -1;
|
||||||
@@ -198,12 +76,6 @@ struct OamdUpdate {
|
|||||||
// keeps whatever controls the caller already holds.
|
// keeps whatever controls the caller already holds.
|
||||||
OamdTrim trim;
|
OamdTrim trim;
|
||||||
bool has_trim = false;
|
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 {
|
class OamdState {
|
||||||
@@ -231,23 +103,6 @@ public:
|
|||||||
|
|
||||||
std::int16_t q(int slot, int axis) const { return q_[slot][axis]; }
|
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.
|
// Objects 1..15 as q15 triples, the layout the speaker renderer consumes.
|
||||||
void object_positions_q15(std::uint16_t out[kObjects][kAxes]) const {
|
void object_positions_q15(std::uint16_t out[kObjects][kAxes]) const {
|
||||||
for (int object = 0; object < kObjects; ++object) {
|
for (int object = 0; object < kObjects; ++object) {
|
||||||
@@ -258,18 +113,25 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::int16_t q_[kMaxObjects][kAxes] = {};
|
std::int16_t q_[kMaxSlots][kAxes] = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
// q_of(k, n) = min(32767, floor(32768 k / n + 0.5)), the reference's quantiser.
|
// q_of(k, n) = min(32767, floor(32768 k / n + 0.5)), the reference's quantiser.
|
||||||
int q_of(int k, int n);
|
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 {
|
struct BedAssignment {
|
||||||
bool lfe_only = false;
|
bool lfe_only = false;
|
||||||
bool standard = false;
|
bool standard = false;
|
||||||
std::uint32_t mask = 0; // 10-bit standard or 17-bit non-standard mask
|
std::uint32_t mask = 0;
|
||||||
// Declared channels in channel order; LFE is kept in place.
|
|
||||||
std::vector<::joc::joc::BedChannel> channels;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParseTrace {
|
struct ParseTrace {
|
||||||
@@ -283,26 +145,6 @@ struct ParseTrace {
|
|||||||
bool reserved_data_not_present = false;
|
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,
|
Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out,
|
||||||
ParseTrace* trace);
|
ParseTrace* trace);
|
||||||
|
|
||||||
@@ -311,7 +153,4 @@ 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,
|
Status parse_id11_bed_assignments(const std::uint8_t* payload, std::size_t payload_size,
|
||||||
std::vector<BedAssignment>* out);
|
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
|
} // namespace joc::oamd
|
||||||
@@ -8,55 +8,32 @@ namespace {
|
|||||||
|
|
||||||
struct FrozenLayout {
|
struct FrozenLayout {
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* compact_name;
|
|
||||||
std::uint32_t out_ch_config;
|
std::uint32_t out_ch_config;
|
||||||
std::uint32_t speaker_bitfield;
|
std::uint32_t speaker_bitfield;
|
||||||
std::uint32_t surround_channels;
|
std::uint32_t surround_channels;
|
||||||
std::uint32_t height_channels;
|
std::uint32_t height_channels;
|
||||||
bool carries_trim;
|
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] = {
|
constexpr FrozenLayout kLayouts[kLayoutCount] = {
|
||||||
{"2.0", "20", 0, 1, 0, 0, true, kChannels20},
|
{"2.0", 0, 1, 0, 0, true},
|
||||||
{"3.1", "31", 3, 7, 0, 0, true, kChannels31},
|
{"3.1", 3, 7, 0, 0, true},
|
||||||
{"4.0", "40", 0xFF, 9, 2, 0, true, kChannels40},
|
{"4.0", 0xFF, 9, 2, 0, true},
|
||||||
{"5.1", "51", 7, 15, 2, 0, true, kChannels51},
|
{"5.1", 7, 15, 2, 0, true},
|
||||||
{"7.1", "71", 11, 31, 4, 0, true, kChannels71},
|
{"7.1", 11, 31, 4, 0, true},
|
||||||
{"5.1.2", "512", 13, 1039, 2, 2, true, kChannels512},
|
{"5.1.2", 13, 1039, 2, 2, true},
|
||||||
{"5.1.4", "514", 14, 2575, 2, 4, true, kChannels514},
|
{"5.1.4", 14, 2575, 2, 4, true},
|
||||||
{"7.1.2", "712", 15, 1055, 4, 2, false, kChannels712},
|
{"7.1.2", 15, 1055, 4, 2, false},
|
||||||
{"7.1.4", "714", 16, 2591, 4, 4, false, kChannels714},
|
{"7.1.4", 16, 2591, 4, 4, false},
|
||||||
{"9.1.4", "914", 19, 2719, 4, 4, false, kChannels914},
|
{"9.1.4", 19, 2719, 4, 4, false},
|
||||||
{"9.1.6", "916", 20, 3743, 4, 6, false, kChannels916},
|
{"9.1.6", 20, 3743, 4, 6, false},
|
||||||
{"6.0", "60", 0xFF, 25, 4, 0, false, kChannels60},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void fill(const FrozenLayout& source, LayoutInfo* out) {
|
void fill(const FrozenLayout& source, LayoutInfo* out) {
|
||||||
out->name = source.name;
|
out->name = source.name;
|
||||||
out->compact_name = source.compact_name;
|
|
||||||
out->out_ch_config = source.out_ch_config;
|
out->out_ch_config = source.out_ch_config;
|
||||||
out->speaker_bitfield = source.speaker_bitfield;
|
out->speaker_bitfield = source.speaker_bitfield;
|
||||||
out->channel_count = ejoc_speaker_layout_channel_count(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->surround_channels = source.surround_channels;
|
||||||
out->height_channels = source.height_channels;
|
out->height_channels = source.height_channels;
|
||||||
out->carries_trim = source.carries_trim;
|
out->carries_trim = source.carries_trim;
|
||||||
|
|||||||
@@ -8,18 +8,13 @@
|
|||||||
|
|
||||||
namespace joc::speaker {
|
namespace joc::speaker {
|
||||||
|
|
||||||
inline constexpr int kLayoutCount = 12;
|
inline constexpr int kLayoutCount = 11;
|
||||||
|
|
||||||
struct LayoutInfo {
|
struct LayoutInfo {
|
||||||
const char* name = "";
|
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 out_ch_config = 0;
|
||||||
std::uint32_t speaker_bitfield = 0;
|
std::uint32_t speaker_bitfield = 0;
|
||||||
std::uint32_t channel_count = 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
|
// Ls/Rs/Lrs/Rrs and Ltf/Rtf/Ltr/Rtr/Ltm/Rtm, the labels the OAMD trim
|
||||||
// configuration index counts.
|
// configuration index counts.
|
||||||
std::uint32_t surround_channels = 0;
|
std::uint32_t surround_channels = 0;
|
||||||
@@ -29,8 +24,8 @@ struct LayoutInfo {
|
|||||||
bool carries_trim = false;
|
bool carries_trim = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// All twelve layouts in the reference's order (2.0, 3.1, 4.0, 5.1, 7.1, 5.1.2,
|
// 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, 6.0).
|
// 5.1.4, 7.1.2, 7.1.4, 9.1.4, 9.1.6).
|
||||||
bool layout_at(int index, LayoutInfo* out);
|
bool layout_at(int index, LayoutInfo* out);
|
||||||
|
|
||||||
// False when the name is unknown (case-sensitive, as the reference CLI). "4.0"
|
// False when the name is unknown (case-sensitive, as the reference CLI). "4.0"
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ struct LayoutGeometry {
|
|||||||
std::array<RegionGeometry, 7> regions{};
|
std::array<RegionGeometry, 7> regions{};
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
|
inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
|
||||||
LayoutGeometry{
|
LayoutGeometry{
|
||||||
0x1u, 0, 2,
|
0x1u, 0, 2,
|
||||||
{{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
{{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, 12> kLayouts{{
|
|||||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||||
},
|
},
|
||||||
RegionGeometry{
|
RegionGeometry{
|
||||||
4, 2, 2, 0,
|
2, 1, 1, 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{}}},
|
{{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{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||||
},
|
},
|
||||||
RegionGeometry{
|
RegionGeometry{
|
||||||
@@ -567,55 +567,7 @@ inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
|
|||||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
{{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 {
|
inline constexpr const LayoutGeometry* find_layout(const std::uint32_t speaker_bitfield) noexcept {
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
// 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
@@ -37,52 +37,18 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
|||||||
}
|
}
|
||||||
context->controls_ready = true;
|
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;
|
std::uint32_t ramp = 0;
|
||||||
if (update != nullptr) {
|
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);
|
context->state.apply(*update);
|
||||||
ramp = update->ramp_duration_samples;
|
ramp = update->ramp_duration_samples;
|
||||||
context->last_block_offset = update->block_offset_samples;
|
context->last_block_offset = update->block_offset_samples;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "foundation/status.h"
|
#include "foundation/status.h"
|
||||||
#include "oamd/oamd_parser.h"
|
#include "oamd/oamd_parser.h"
|
||||||
#include "speaker/speaker_layout_lookup.h"
|
#include "speaker/speaker_layout_lookup.h"
|
||||||
#include "speaker/speaker_meta.h"
|
|
||||||
#include "speaker/speaker_trim.h"
|
#include "speaker/speaker_trim.h"
|
||||||
|
|
||||||
namespace joc::speaker {
|
namespace joc::speaker {
|
||||||
@@ -33,16 +32,6 @@ struct SpeakerStep {
|
|||||||
// 对象槽 → Q15 方位;bed_override 为 false 的槽仍按 OAMD 坐标声像。
|
// 对象槽 → Q15 方位;bed_override 为 false 的槽仍按 OAMD 坐标声像。
|
||||||
std::uint16_t bed_positions[oamd::kObjects][oamd::kAxes] = {};
|
std::uint16_t bed_positions[oamd::kObjects][oamd::kAxes] = {};
|
||||||
bool bed_override[oamd::kObjects] = {};
|
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,
|
Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
||||||
|
|||||||
@@ -52,10 +52,11 @@ Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout
|
|||||||
controls.trim_bypass[slot] = trim->disable_per_object[slot] ? 1u : 0u;
|
controls.trim_bypass[slot] = trim->disable_per_object[slot] ? 1u : 0u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (controls.warp_mode > 3u) {
|
if (controls.warp_mode > 1u) {
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
return Status::fail(JOC_ERR_NOT_SUPPORTED, stage::kRender,
|
||||||
"speaker: invalid warp mode " +
|
"speaker: warp_mode_not_implemented: speaker rendering "
|
||||||
std::to_string(controls.warp_mode));
|
"implements warp modes 0/1; warp mode " +
|
||||||
|
std::to_string(controls.warp_mode) + " is reserved");
|
||||||
}
|
}
|
||||||
if (!layout.carries_trim) {
|
if (!layout.carries_trim) {
|
||||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ inline constexpr int kBalanceSteps = 16;
|
|||||||
// kappa_h: 0 -> 0, 2 -> 1, otherwise 2
|
// kappa_h: 0 -> 0, 2 -> 1, otherwise 2
|
||||||
int trim_config_index(const LayoutInfo& layout);
|
int trim_config_index(const LayoutInfo& layout);
|
||||||
|
|
||||||
// Converts OAMD calibration to the speaker controls of one layout. Warp 0
|
// Converts OAMD calibration to the speaker controls of one layout. Warp modes
|
||||||
// renders directly, 1 scales the floor Y, and 2/3 render through an expanded
|
// 2/3 and the reserved global trim mode are reported as unsupported. A null
|
||||||
// surround layout before folding; the reserved global trim mode is reported as
|
// trim selects warp 0 and automatic trim, or disabled trim for a layout that
|
||||||
// unsupported. A null trim selects warp 0 and automatic trim, or disabled trim
|
// carries no trim semantics.
|
||||||
// for a layout that carries no trim semantics.
|
|
||||||
Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout,
|
Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout,
|
||||||
ejoc_speaker_controls* out);
|
ejoc_speaker_controls* out);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "adm/adm_metadata.h"
|
#include "adm/adm_metadata.h"
|
||||||
#include "foundation/status.h"
|
#include "foundation/status.h"
|
||||||
#include "virtual_speaker/virtual_speaker.h"
|
|
||||||
#include "hrtf/jochrtf.h"
|
#include "hrtf/jochrtf.h"
|
||||||
#include "hrtf/rosella_model.h"
|
#include "hrtf/rosella_model.h"
|
||||||
#include "joc_bitstream/bed_layout_map.h"
|
#include "joc_bitstream/bed_layout_map.h"
|
||||||
@@ -46,7 +45,6 @@ void Stream::reset_state() {
|
|||||||
bed_pending_.clear();
|
bed_pending_.clear();
|
||||||
bed_read_offset_ = 0;
|
bed_read_offset_ = 0;
|
||||||
objects16_.clear();
|
objects16_.clear();
|
||||||
pcm_input_.reset();
|
|
||||||
objects_pending_.clear();
|
objects_pending_.clear();
|
||||||
objects_read_offset_ = 0;
|
objects_read_offset_ = 0;
|
||||||
output_.clear();
|
output_.clear();
|
||||||
@@ -79,7 +77,7 @@ Status Stream::create(const Config& config) {
|
|||||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "stream already created");
|
return Status::fail(JOC_ERR_STATE, stage::kRender, "stream already created");
|
||||||
}
|
}
|
||||||
config_ = config;
|
config_ = config;
|
||||||
if (config_.input > JOC_STREAM_IN_PCM_LAYOUT ||
|
if (config_.input > JOC_STREAM_IN_PCM_OBJECTS16 ||
|
||||||
config_.output > JOC_STREAM_OUT_BINAURAL) {
|
config_.output > JOC_STREAM_OUT_BINAURAL) {
|
||||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender, "unknown stream kind");
|
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender, "unknown stream kind");
|
||||||
}
|
}
|
||||||
@@ -89,20 +87,6 @@ Status Stream::create(const Config& config) {
|
|||||||
"objects16 input with objects16 output would do nothing");
|
"objects16 input with objects16 output would do nothing");
|
||||||
}
|
}
|
||||||
gain_ = static_cast<float>(std::pow(10.0, config_.gain_db / 20.0));
|
gain_ = static_cast<float>(std::pow(10.0, config_.gain_db / 20.0));
|
||||||
if (config_.input == JOC_STREAM_IN_PCM_LAYOUT && !config_.pcm_layout.empty() &&
|
|
||||||
config_.pcm_layout != "auto") {
|
|
||||||
const virtual_speaker::Layout* layout =
|
|
||||||
virtual_speaker::find_layout(config_.pcm_layout);
|
|
||||||
if (layout == nullptr) {
|
|
||||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender,
|
|
||||||
"unknown PCM layout: " + config_.pcm_layout);
|
|
||||||
}
|
|
||||||
const Status configured =
|
|
||||||
pcm_input_.configure(config_.pcm_layout, layout->channels, config_.gain_db);
|
|
||||||
if (!configured.ok()) {
|
|
||||||
return configured;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_.input == JOC_STREAM_IN_EAC3) {
|
if (config_.input == JOC_STREAM_IN_EAC3) {
|
||||||
rebuilder_ = ejoc_renderer_create();
|
rebuilder_ = ejoc_renderer_create();
|
||||||
@@ -262,9 +246,6 @@ Status Stream::flush_pending_frame() {
|
|||||||
if (entry.params.objects_clamped != 0u) {
|
if (entry.params.objects_clamped != 0u) {
|
||||||
++info_.objects_clamped_frames;
|
++info_.objects_clamped_frames;
|
||||||
}
|
}
|
||||||
if (entry.params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
|
||||||
++info_.truncated_joc_frames;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// No JOC metadata for this audio frame: the object channels stay silent
|
// No JOC metadata for this audio frame: the object channels stay silent
|
||||||
// while the kernel state still advances for the frame.
|
// while the kernel state still advances for the frame.
|
||||||
@@ -362,14 +343,7 @@ Status Stream::push_eac3(const std::uint8_t* data, std::size_t size, std::size_t
|
|||||||
if (!extracted.ok()) {
|
if (!extracted.ok()) {
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
// Speaker and binaural consume the full per-object block state; the
|
const Status oamd = oamd::parse_id11(bytes.data(), bytes.size(), &pending_frame_.update);
|
||||||
// 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()) {
|
if (!oamd.ok()) {
|
||||||
return oamd;
|
return oamd;
|
||||||
}
|
}
|
||||||
@@ -469,47 +443,6 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
|
|||||||
return process_objects16_frames(false);
|
return process_objects16_frames(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Stream::push_pcm_layout(const float* interleaved, std::size_t samples,
|
|
||||||
std::uint32_t channels, std::size_t* consumed) {
|
|
||||||
if (consumed != nullptr) {
|
|
||||||
*consumed = 0;
|
|
||||||
}
|
|
||||||
if (interleaved == nullptr || samples == 0u) {
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
if (pcm_input_.layout() == nullptr) {
|
|
||||||
const Status configured = pcm_input_.configure(config_.pcm_layout,
|
|
||||||
static_cast<int>(channels),
|
|
||||||
config_.gain_db);
|
|
||||||
if (!configured.ok()) {
|
|
||||||
return configured;
|
|
||||||
}
|
|
||||||
} else if (pcm_input_.channels() != static_cast<int>(channels)) {
|
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
|
||||||
"PCM channel count changed mid-stream");
|
|
||||||
}
|
|
||||||
Status status = pcm_input_.append(interleaved, samples);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
std::size_t processed = 0;
|
|
||||||
while (pcm_input_.frame_ready()) {
|
|
||||||
status = pcm_input_.take_frame(&objects_frame_);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
status = push_objects16(objects_frame_.data(), kFrameSamples, nullptr);
|
|
||||||
if (!status.ok()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
processed += kFrameSamples;
|
|
||||||
}
|
|
||||||
if (consumed != nullptr) {
|
|
||||||
*consumed = processed;
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
Status Stream::process_objects16_frames(bool drain_all) {
|
Status Stream::process_objects16_frames(bool drain_all) {
|
||||||
constexpr std::size_t kFrameValues =
|
constexpr std::size_t kFrameValues =
|
||||||
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * kFrameSamples;
|
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * kFrameSamples;
|
||||||
@@ -603,10 +536,8 @@ Status Stream::process_ready_frames(bool drain_all) {
|
|||||||
compact_bed_pending();
|
compact_bed_pending();
|
||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
const Status rebuilt = joc::rebuild_objects16(
|
const Status rebuilt = joc::rebuild_objects16(rebuilder_, entry.params, bed5_.data(),
|
||||||
rebuilder_, entry.params, bed5_.data(), lfe_.data(),
|
lfe_.data(), gain_, &objects16_, &error);
|
||||||
static_cast<std::uint32_t>(core_channels), entry.has_joc, gain_, &objects16_,
|
|
||||||
&error);
|
|
||||||
if (!rebuilt.ok()) {
|
if (!rebuilt.ok()) {
|
||||||
return Status::fail(rebuilt.code(), stage::kDsp, error);
|
return Status::fail(rebuilt.code(), stage::kDsp, error);
|
||||||
}
|
}
|
||||||
@@ -647,11 +578,9 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
|||||||
if (speaker_enabled_) {
|
if (speaker_enabled_) {
|
||||||
std::string error;
|
std::string error;
|
||||||
const Status stepped =
|
const Status stepped =
|
||||||
speaker::step(&speaker_, objects16,
|
speaker::step(&speaker_, objects16, pending_metadata_.has_update
|
||||||
pending_metadata_.has_update
|
? &pending_metadata_.update
|
||||||
? &pending_metadata_.update
|
: nullptr,
|
||||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update()
|
|
||||||
: nullptr),
|
|
||||||
&error);
|
&error);
|
||||||
if (!stepped.ok()) {
|
if (!stepped.ok()) {
|
||||||
return Status::fail(stepped.code(), stage::kRender, error);
|
return Status::fail(stepped.code(), stage::kRender, error);
|
||||||
@@ -670,8 +599,7 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
|||||||
|
|
||||||
const Status submitted =
|
const Status submitted =
|
||||||
binaural_.submit_frame(objects16.data(),
|
binaural_.submit_frame(objects16.data(),
|
||||||
pending_metadata_.has_update ? &pending_metadata_.update
|
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
|
||||||
static_cast<std::int64_t>(info_.frames_out),
|
static_cast<std::int64_t>(info_.frames_out),
|
||||||
pending_metadata_.outer_offset,
|
pending_metadata_.outer_offset,
|
||||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||||
@@ -698,8 +626,7 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
|||||||
Status Stream::render_rosella_objects16(const std::vector<float>& objects16) {
|
Status Stream::render_rosella_objects16(const std::vector<float>& objects16) {
|
||||||
const Status submitted =
|
const Status submitted =
|
||||||
rosella_.submit_frame(objects16.data(),
|
rosella_.submit_frame(objects16.data(),
|
||||||
pending_metadata_.has_update ? &pending_metadata_.update
|
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
|
||||||
static_cast<std::int64_t>(info_.frames_out),
|
static_cast<std::int64_t>(info_.frames_out),
|
||||||
pending_metadata_.outer_offset,
|
pending_metadata_.outer_offset,
|
||||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include "joc_stream.h"
|
#include "joc_stream.h"
|
||||||
#include "oamd/oamd_parser.h"
|
#include "oamd/oamd_parser.h"
|
||||||
#include "speaker/speaker_step.h"
|
#include "speaker/speaker_step.h"
|
||||||
#include "virtual_speaker/virtual_speaker.h"
|
|
||||||
|
|
||||||
namespace joc::stream {
|
namespace joc::stream {
|
||||||
|
|
||||||
@@ -35,7 +34,6 @@ struct Config {
|
|||||||
// (.jochrtf).
|
// (.jochrtf).
|
||||||
std::string personalized_headphone_path;
|
std::string personalized_headphone_path;
|
||||||
std::uint32_t jochrtf_room = 1;
|
std::uint32_t jochrtf_room = 1;
|
||||||
std::string pcm_layout;
|
|
||||||
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
||||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||||
};
|
};
|
||||||
@@ -49,9 +47,6 @@ struct Info {
|
|||||||
std::uint64_t oamd_payloads = 0;
|
std::uint64_t oamd_payloads = 0;
|
||||||
std::uint64_t oamd_transitions = 0;
|
std::uint64_t oamd_transitions = 0;
|
||||||
std::uint64_t missing_joc_frames = 0;
|
std::uint64_t missing_joc_frames = 0;
|
||||||
// Audio frames whose ID14 payload ended inside joc_data; they render as
|
|
||||||
// invalid frames and hold the previous matrices.
|
|
||||||
std::uint64_t truncated_joc_frames = 0;
|
|
||||||
std::uint64_t objects_clamped_frames = 0;
|
std::uint64_t objects_clamped_frames = 0;
|
||||||
// Audio frames whose syncframe held more than one top-level JOC container and
|
// Audio frames whose syncframe held more than one top-level JOC container and
|
||||||
// were decoded from the single one that carries a complete joc() payload.
|
// were decoded from the single one that carries a complete joc() payload.
|
||||||
@@ -101,8 +96,6 @@ public:
|
|||||||
Status push_bed(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
Status push_bed(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
||||||
std::size_t* consumed);
|
std::size_t* consumed);
|
||||||
Status push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed);
|
Status push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed);
|
||||||
Status push_pcm_layout(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
|
||||||
std::size_t* consumed);
|
|
||||||
Status pull(float* destination, std::size_t capacity_samples, std::size_t* produced);
|
Status pull(float* destination, std::size_t capacity_samples, std::size_t* produced);
|
||||||
Status flush();
|
Status flush();
|
||||||
Status reset();
|
Status reset();
|
||||||
@@ -164,9 +157,6 @@ private:
|
|||||||
std::size_t bed_read_offset_ = 0;
|
std::size_t bed_read_offset_ = 0;
|
||||||
std::vector<float> bed5_;
|
std::vector<float> bed5_;
|
||||||
std::vector<float> lfe_;
|
std::vector<float> lfe_;
|
||||||
virtual_speaker::Input pcm_input_;
|
|
||||||
oamd::OamdUpdate fixed_update_{};
|
|
||||||
bool has_fixed_update_ = false;
|
|
||||||
std::vector<float> objects_pending_;
|
std::vector<float> objects_pending_;
|
||||||
std::size_t objects_read_offset_ = 0;
|
std::size_t objects_read_offset_ = 0;
|
||||||
std::vector<float> objects_frame_;
|
std::vector<float> objects_frame_;
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ Status probe_atmos_trim(const std::string& path, std::uint64_t max_frames,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
oamd::OamdUpdate update;
|
oamd::OamdUpdate update;
|
||||||
if (!oamd::parse_id11_state(bytes.data(), bytes.size(), &update).ok() ||
|
if (!oamd::parse_id11(bytes.data(), bytes.size(), &update).ok() ||
|
||||||
!update.has_trim) {
|
!update.has_trim) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1429,11 +1429,6 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
return finalize_with_error(seeded.code(), "render", seeded.message());
|
return finalize_with_error(seeded.code(), "render", seeded.message());
|
||||||
}
|
}
|
||||||
speaker.controls_ready = true;
|
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,
|
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||||
fmt("speaker renderer: %s, %u channels", speaker.layout.name,
|
fmt("speaker renderer: %s, %u channels", speaker.layout.name,
|
||||||
@@ -1594,11 +1589,7 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
// count was clamped to 15, and frames whose syncframe carried a second EMDF
|
// count was clamped to 15, and frames whose syncframe carried a second EMDF
|
||||||
// container that is not this frame's JOC metadata.
|
// container that is not this frame's JOC metadata.
|
||||||
std::uint64_t missing_joc_frames = 0;
|
std::uint64_t missing_joc_frames = 0;
|
||||||
std::uint64_t truncated_joc_frames = 0;
|
|
||||||
std::uint64_t objects_clamped_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 extra_container_frames = 0;
|
||||||
std::uint64_t chanmap_pair_mismatch_frames = 0;
|
std::uint64_t chanmap_pair_mismatch_frames = 0;
|
||||||
std::uint64_t bed_mask_mismatch_frames = 0;
|
std::uint64_t bed_mask_mismatch_frames = 0;
|
||||||
@@ -1669,22 +1660,6 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
if (params.objects_clamped != 0u) {
|
if (params.objects_clamped != 0u) {
|
||||||
++objects_clamped_frames;
|
++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;
|
|
||||||
case JOC_FRAME_STATUS_TRUNCATED:
|
|
||||||
++truncated_joc_frames;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
++missing_joc_frames;
|
++missing_joc_frames;
|
||||||
}
|
}
|
||||||
@@ -1716,9 +1691,8 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
}
|
}
|
||||||
std::string dsp_error;
|
std::string dsp_error;
|
||||||
const Status rebuilt = ::joc::joc::rebuild_objects16(
|
const Status rebuilt = ::joc::joc::rebuild_objects16(
|
||||||
rebuilder, params, bed5.data(), lfe.data(),
|
rebuilder, params, bed5.data(), lfe.data(), gain, &objects16,
|
||||||
static_cast<std::uint32_t>(resolved_core_channels), has_joc, gain,
|
&dsp_error);
|
||||||
&objects16, &dsp_error);
|
|
||||||
if (!rebuilt.ok()) {
|
if (!rebuilt.ok()) {
|
||||||
return Status::fail(rebuilt.code(), "joc", dsp_error);
|
return Status::fail(rebuilt.code(), "joc", dsp_error);
|
||||||
}
|
}
|
||||||
@@ -1845,16 +1819,8 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
stream_done = true;
|
stream_done = true;
|
||||||
break;
|
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 =
|
const Status oamd =
|
||||||
full_metadata_state
|
::joc::oamd::parse_id11(bytes.data(), bytes.size(), &job.update);
|
||||||
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
|
|
||||||
&job.update)
|
|
||||||
: ::joc::oamd::parse_id11(bytes.data(), bytes.size(),
|
|
||||||
&job.update);
|
|
||||||
if (!oamd.ok()) {
|
if (!oamd.ok()) {
|
||||||
failures.record(produced, StageRank::kJoc, oamd.code(), oamd.stage(),
|
failures.record(produced, StageRank::kJoc, oamd.code(), oamd.stage(),
|
||||||
"frame " + std::to_string(produced) + ": " +
|
"frame " + std::to_string(produced) + ": " +
|
||||||
@@ -2200,33 +2166,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
joiner.shutdown(false);
|
joiner.shutdown(false);
|
||||||
if (missing_joc_frames != 0u) {
|
if (missing_joc_frames != 0u) {
|
||||||
bus.warning(std::to_string(missing_joc_frames) +
|
bus.warning(std::to_string(missing_joc_frames) +
|
||||||
" audio frame(s) carried no JOC payload; their core PCM was passed "
|
" audio frame(s) carried no JOC payload; their object channels stay silent");
|
||||||
"through (8 core planes, 1217-sample delay)");
|
|
||||||
}
|
}
|
||||||
if (objects_clamped_frames != 0u) {
|
if (objects_clamped_frames != 0u) {
|
||||||
bus.warning(std::to_string(objects_clamped_frames) +
|
bus.warning(std::to_string(objects_clamped_frames) +
|
||||||
" audio frame(s) declared more than 15 objects; the count was clamped "
|
" audio frame(s) declared more than 15 objects; the count was clamped to 15");
|
||||||
"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 (truncated_joc_frames != 0u) {
|
|
||||||
bus.warning(std::to_string(truncated_joc_frames) +
|
|
||||||
" audio frame(s) carried a JOC payload that ends inside joc_data; "
|
|
||||||
"the frame took the invalid-frame path and held the previous matrices");
|
|
||||||
}
|
}
|
||||||
if (extra_container_frames != 0u) {
|
if (extra_container_frames != 0u) {
|
||||||
bus.warning(std::to_string(extra_container_frames) +
|
bus.warning(std::to_string(extra_container_frames) +
|
||||||
|
|||||||
@@ -95,100 +95,37 @@ Status ObjectPositionTrack::position_at(std::int64_t sample, double out[3]) {
|
|||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
OamdPositionTimeline::OamdPositionTimeline(int object_count)
|
OamdPositionTimeline::OamdPositionTimeline(int object_count) : object_count_(object_count) {
|
||||||
: object_count_(std::clamp(object_count, 1, oamd::kMaxObjects - 1)) {
|
if (object_count != kTimelineObjects) {
|
||||||
const std::size_t count = static_cast<std::size_t>(object_count_);
|
object_count_ = kTimelineObjects;
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OamdPositionTimeline::reset() {
|
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
|
||||||
state_.reset();
|
std::int64_t frame_start_sample,
|
||||||
for (int index = 0; index < object_count_; ++index) {
|
std::int64_t outer_sample_offset,
|
||||||
tracks_[static_cast<std::size_t>(index)] = ObjectPositionTrack();
|
std::int64_t object_delay_samples,
|
||||||
has_previous_[static_cast<std::size_t>(index)] = false;
|
std::int64_t processed_sample) {
|
||||||
previous_targets_[static_cast<std::size_t>(index)] = {0.0, 0.0, 0.0};
|
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");
|
||||||
}
|
}
|
||||||
initialized_ = false;
|
state_.apply(update);
|
||||||
payload_count_ = 0;
|
|
||||||
transition_count_ = 0;
|
|
||||||
last_coded_event_sample_ = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OamdPositionTimeline::apply_block(const oamd::FrameState& state,
|
double targets[kTimelineObjects][3] = {};
|
||||||
std::uint32_t block_index) {
|
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||||
// Track i reads OAMD object i + 1: object 0 is the LFE/bed slot the JOC
|
if (fixed_[index]) {
|
||||||
// renderers do not position. Bed and ISF objects carry no position field,
|
std::memcpy(targets[index], fixed_xyz_[index], sizeof(targets[index]));
|
||||||
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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),
|
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
|
||||||
state_.q(index + 1, 2), &x, &y, &z);
|
state_.q(index + 1, 2), &targets[index][0], &targets[index][1],
|
||||||
(*out)[slot] = {x, y, z};
|
&targets[index][2]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Status OamdPositionTimeline::schedule(const std::vector<std::array<double, 3>>& targets,
|
const std::int64_t coded_event =
|
||||||
std::int64_t coded_event, std::int64_t ramp_samples,
|
frame_start_sample + outer_sample_offset +
|
||||||
std::int64_t object_delay_samples,
|
static_cast<std::int64_t>(update.block_offset_samples);
|
||||||
std::int64_t processed_sample) {
|
|
||||||
if (coded_event < last_coded_event_sample_) {
|
if (coded_event < last_coded_event_sample_) {
|
||||||
return timeline_fail(JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
|
return timeline_fail(JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
|
||||||
"non_monotonic_binaural_updates: event sample " +
|
"non_monotonic_binaural_updates: event sample " +
|
||||||
@@ -204,105 +141,44 @@ Status OamdPositionTimeline::schedule(const std::vector<std::array<double, 3>>&
|
|||||||
"sample " + std::to_string(processed_sample) +
|
"sample " + std::to_string(processed_sample) +
|
||||||
" had been processed, so sample 0 cannot be backfilled");
|
" had been processed, so sample 0 cannot be backfilled");
|
||||||
}
|
}
|
||||||
for (int index = 0; index < object_count_; ++index) {
|
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||||
const std::size_t slot = static_cast<std::size_t>(index);
|
tracks_[index].set_initial(targets[index]);
|
||||||
tracks_[slot].set_initial(targets[slot].data());
|
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
|
||||||
previous_targets_[slot] = targets[slot];
|
has_previous_[index] = true;
|
||||||
has_previous_[slot] = true;
|
|
||||||
}
|
}
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
++payload_count_;
|
||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::int64_t effective_ramp = std::max<std::int64_t>(0, ramp_samples);
|
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 transition_start =
|
const std::int64_t transition_start =
|
||||||
timing::align_metadata_sample(coded_event + object_delay_samples);
|
timing::align_metadata_sample(coded_event + object_delay_samples);
|
||||||
for (int index = 0; index < object_count_; ++index) {
|
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||||
const std::size_t slot = static_cast<std::size_t>(index);
|
const bool changed = !has_previous_[index] ||
|
||||||
const bool changed =
|
std::memcmp(previous_targets_[index], targets[index],
|
||||||
!has_previous_[slot] ||
|
sizeof(targets[index])) != 0;
|
||||||
std::memcmp(previous_targets_[slot].data(), targets[slot].data(),
|
|
||||||
sizeof(targets[slot])) != 0;
|
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Status status =
|
const Status status = tracks_[index].append(transition_start, effective_ramp,
|
||||||
tracks_[slot].append(transition_start, effective_ramp, targets[slot].data(),
|
targets[index], index + 1);
|
||||||
index + 1);
|
|
||||||
if (!status.ok()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
previous_targets_[slot] = targets[slot];
|
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
|
||||||
has_previous_[slot] = true;
|
has_previous_[index] = true;
|
||||||
++transition_count_;
|
++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_;
|
++payload_count_;
|
||||||
return Status::success();
|
return Status::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status OamdPositionTimeline::positions_at(std::int64_t sample, double* positions,
|
Status OamdPositionTimeline::positions_at(std::int64_t sample,
|
||||||
int count) {
|
double positions[kTimelineObjects][3]) {
|
||||||
if (positions == nullptr || count < 0) {
|
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
|
const Status status = tracks_[index].position_at(sample, positions[index]);
|
||||||
"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()) {
|
if (!status.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -11,11 +10,6 @@
|
|||||||
|
|
||||||
namespace joc::timeline {
|
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;
|
inline constexpr int kTimelineObjects = 15;
|
||||||
|
|
||||||
struct PositionTransition {
|
struct PositionTransition {
|
||||||
@@ -48,53 +42,56 @@ class OamdPositionTimeline {
|
|||||||
public:
|
public:
|
||||||
explicit OamdPositionTimeline(int object_count = kTimelineObjects);
|
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,
|
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 outer_sample_offset, std::int64_t object_delay_samples,
|
||||||
std::int64_t processed_sample);
|
std::int64_t processed_sample);
|
||||||
|
|
||||||
// positions[count][3]; queries must be monotonically increasing.
|
// positions[15][3]; queries must be monotonically increasing.
|
||||||
Status positions_at(std::int64_t sample, double* positions, int count);
|
Status positions_at(std::int64_t sample, double positions[kTimelineObjects][3]);
|
||||||
|
|
||||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
||||||
void set_fixed_position(int object_index, const double position[3]);
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
// Drops the OAMD state and every transition but keeps the fixed bed positions:
|
// Drops the OAMD state and every transition but keeps the fixed bed positions:
|
||||||
// they describe the content, not the playback position.
|
// they describe the content, not the playback position.
|
||||||
void reset();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
int object_count() const { return object_count_; }
|
|
||||||
std::uint64_t payload_count() const { return payload_count_; }
|
std::uint64_t payload_count() const { return payload_count_; }
|
||||||
std::uint64_t transition_count() const { return transition_count_; }
|
std::uint64_t transition_count() const { return transition_count_; }
|
||||||
bool initialized() const { return initialized_; }
|
bool initialized() const { return initialized_; }
|
||||||
|
|
||||||
const ObjectPositionTrack& track(int index) const { return tracks_[static_cast<std::size_t>(index)]; }
|
const ObjectPositionTrack& track(int index) const { return tracks_[index]; }
|
||||||
|
|
||||||
private:
|
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_;
|
int object_count_;
|
||||||
oamd::OamdState state_;
|
oamd::OamdState state_;
|
||||||
std::vector<ObjectPositionTrack> tracks_;
|
ObjectPositionTrack tracks_[kTimelineObjects];
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
std::vector<std::array<double, 3>> previous_targets_;
|
double previous_targets_[kTimelineObjects][3] = {};
|
||||||
std::vector<bool> has_previous_;
|
bool has_previous_[kTimelineObjects] = {};
|
||||||
std::vector<bool> fixed_;
|
bool fixed_[kTimelineObjects] = {};
|
||||||
std::vector<std::array<double, 3>> fixed_xyz_;
|
double fixed_xyz_[kTimelineObjects][3] = {};
|
||||||
std::vector<std::array<double, 3>> targets_;
|
|
||||||
std::uint64_t payload_count_ = 0;
|
std::uint64_t payload_count_ = 0;
|
||||||
std::uint64_t transition_count_ = 0;
|
std::uint64_t transition_count_ = 0;
|
||||||
std::int64_t last_coded_event_sample_ = -1;
|
std::int64_t last_coded_event_sample_ = -1;
|
||||||
|
|||||||
@@ -1,161 +0,0 @@
|
|||||||
#include "virtual_speaker/virtual_speaker.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include "joc_core.h"
|
|
||||||
|
|
||||||
namespace joc::virtual_speaker {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
constexpr std::size_t kFrameSamples = JOC_FRAME_SAMPLES;
|
|
||||||
constexpr std::size_t kSourceChannels = JOC_OUTPUT_CHANNELS;
|
|
||||||
|
|
||||||
// WAV order follows the ffmpeg layouts: 5.1 = L R C LFE BL BR,
|
|
||||||
// 7.1 = L R C LFE BL BR SL SR.
|
|
||||||
constexpr Layout kLayouts[] = {
|
|
||||||
{"2.0",
|
|
||||||
2,
|
|
||||||
{{false, -1.0, 1.0, 0.0},
|
|
||||||
{false, 1.0, 1.0, 0.0}}},
|
|
||||||
{"5.1",
|
|
||||||
6,
|
|
||||||
{{false, -1.0, 1.0, 0.0},
|
|
||||||
{false, 1.0, 1.0, 0.0},
|
|
||||||
{false, 0.0, 1.0, 0.0},
|
|
||||||
{true, 0.0, 1.0, 0.0},
|
|
||||||
{false, -1.0, -1.0, 0.0},
|
|
||||||
{false, 1.0, -1.0, 0.0}}},
|
|
||||||
{"7.1",
|
|
||||||
8,
|
|
||||||
{{false, -1.0, 1.0, 0.0},
|
|
||||||
{false, 1.0, 1.0, 0.0},
|
|
||||||
{false, 0.0, 1.0, 0.0},
|
|
||||||
{true, 0.0, 1.0, 0.0},
|
|
||||||
{false, -1.0, -1.0, 0.0},
|
|
||||||
{false, 1.0, -1.0, 0.0},
|
|
||||||
{false, -1.0, 0.0, 0.0},
|
|
||||||
{false, 1.0, 0.0, 0.0}}},
|
|
||||||
};
|
|
||||||
|
|
||||||
std::int16_t q_for_axis(double value) {
|
|
||||||
if (value <= -0.999) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (value >= 0.999) {
|
|
||||||
return 32767;
|
|
||||||
}
|
|
||||||
return 16384;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill_fixed_positions(const Layout& layout, oamd::OamdUpdate* update) {
|
|
||||||
update->object_count = static_cast<std::uint32_t>(kSourceChannels);
|
|
||||||
update->block_offset_samples = 0;
|
|
||||||
update->ramp_duration_samples = 0;
|
|
||||||
int slot = 1;
|
|
||||||
for (int channel = 0; channel < layout.channels; ++channel) {
|
|
||||||
const ChannelSpec& spec = layout.channel_specs[channel];
|
|
||||||
const int destination = spec.lfe ? 0 : slot++;
|
|
||||||
update->slots[destination].q1 = q_for_axis(spec.x);
|
|
||||||
update->slots[destination].q2 = q_for_axis(-spec.y);
|
|
||||||
update->slots[destination].q3 = q_for_axis(spec.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
const Layout* find_layout(const std::string& name) {
|
|
||||||
for (const Layout& layout : kLayouts) {
|
|
||||||
if (name == layout.name) {
|
|
||||||
return &layout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Layout* detect_layout(int channels) {
|
|
||||||
for (const Layout& layout : kLayouts) {
|
|
||||||
if (layout.channels == channels) {
|
|
||||||
return &layout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status Input::configure(const std::string& layout_name, int channels, double gain_db) {
|
|
||||||
const Layout* layout =
|
|
||||||
(layout_name.empty() || layout_name == "auto")
|
|
||||||
? detect_layout(channels)
|
|
||||||
: find_layout(layout_name);
|
|
||||||
if (layout == nullptr || layout->channels != channels) {
|
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
|
||||||
"PCM layout does not match the channel count");
|
|
||||||
}
|
|
||||||
layout_ = layout;
|
|
||||||
channels_ = channels;
|
|
||||||
gain_ = static_cast<double>(std::pow(10.0, gain_db / 20.0));
|
|
||||||
pending_.clear();
|
|
||||||
read_offset_ = 0;
|
|
||||||
fill_fixed_positions(*layout_, &fixed_update_);
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Input::reset() {
|
|
||||||
pending_.clear();
|
|
||||||
read_offset_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status Input::append(const float* interleaved, std::size_t frames) {
|
|
||||||
if (interleaved == nullptr || frames == 0u) {
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
if (layout_ == nullptr || channels_ <= 0) {
|
|
||||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
|
||||||
"virtual speaker input is not configured");
|
|
||||||
}
|
|
||||||
pending_.insert(pending_.end(), interleaved,
|
|
||||||
interleaved + frames * static_cast<std::size_t>(channels_));
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Input::frame_ready() const {
|
|
||||||
return layout_ != nullptr &&
|
|
||||||
pending_.size() - read_offset_ >=
|
|
||||||
kFrameSamples * static_cast<std::size_t>(channels_);
|
|
||||||
}
|
|
||||||
|
|
||||||
Status Input::take_frame(std::vector<float>* objects16) {
|
|
||||||
if (objects16 == nullptr) {
|
|
||||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
|
||||||
"objects16 output is null");
|
|
||||||
}
|
|
||||||
if (!frame_ready()) {
|
|
||||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
|
||||||
"no complete PCM frame is buffered");
|
|
||||||
}
|
|
||||||
objects16->assign(kSourceChannels * kFrameSamples, 0.0f);
|
|
||||||
const float* source = pending_.data() + read_offset_;
|
|
||||||
int slot = 1;
|
|
||||||
for (int channel = 0; channel < layout_->channels; ++channel) {
|
|
||||||
const int destination = layout_->channel_specs[channel].lfe ? 0 : slot++;
|
|
||||||
for (std::size_t sample = 0; sample < kFrameSamples; ++sample) {
|
|
||||||
(*objects16)[static_cast<std::size_t>(destination) * kFrameSamples + sample] =
|
|
||||||
source[sample * static_cast<std::size_t>(channels_) + channel] *
|
|
||||||
static_cast<float>(gain_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
read_offset_ += kFrameSamples * static_cast<std::size_t>(channels_);
|
|
||||||
if (read_offset_ == pending_.size()) {
|
|
||||||
pending_.clear();
|
|
||||||
read_offset_ = 0;
|
|
||||||
} else if (read_offset_ >= (1u << 20)) {
|
|
||||||
pending_.erase(pending_.begin(),
|
|
||||||
pending_.begin() + static_cast<std::ptrdiff_t>(read_offset_));
|
|
||||||
read_offset_ = 0;
|
|
||||||
}
|
|
||||||
return Status::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace joc::virtual_speaker
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
// Virtual speaker input: ordinary multichannel PCM as fixed-direction JOC
|
|
||||||
// objects. It owns only the layout mapping and the PCM-to-objects16 shape;
|
|
||||||
// decoding, speaker rendering and binaural rendering stay in their own modules.
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "foundation/status.h"
|
|
||||||
#include "oamd/oamd_parser.h"
|
|
||||||
|
|
||||||
namespace joc::virtual_speaker {
|
|
||||||
|
|
||||||
struct ChannelSpec {
|
|
||||||
bool lfe;
|
|
||||||
double x;
|
|
||||||
double y;
|
|
||||||
double z;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Layout {
|
|
||||||
const char* name;
|
|
||||||
int channels;
|
|
||||||
ChannelSpec channel_specs[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
const Layout* find_layout(const std::string& name);
|
|
||||||
const Layout* detect_layout(int channels);
|
|
||||||
|
|
||||||
class Input {
|
|
||||||
public:
|
|
||||||
// gain_db is the module's master attenuation; it is applied to every
|
|
||||||
// mapped channel once, before the objects16 frame leaves the module.
|
|
||||||
Status configure(const std::string& layout_name, int channels, double gain_db = 0.0);
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
const oamd::OamdUpdate& fixed_update() const { return fixed_update_; }
|
|
||||||
int channels() const { return channels_; }
|
|
||||||
const Layout* layout() const { return layout_; }
|
|
||||||
|
|
||||||
// Appends interleaved frames; take_frame() emits whole 1536-frame blocks.
|
|
||||||
Status append(const float* interleaved, std::size_t frames);
|
|
||||||
bool frame_ready() const;
|
|
||||||
Status take_frame(std::vector<float>* objects16);
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Layout* layout_ = nullptr;
|
|
||||||
int channels_ = 0;
|
|
||||||
double gain_ = 1.0;
|
|
||||||
oamd::OamdUpdate fixed_update_{};
|
|
||||||
std::vector<float> pending_;
|
|
||||||
std::size_t read_offset_ = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace joc::virtual_speaker
|
|
||||||
+9
-159
@@ -27,7 +27,6 @@
|
|||||||
#include "eac3_scan.h"
|
#include "eac3_scan.h"
|
||||||
#include "joc_decode.h"
|
#include "joc_decode.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "pcm_source.h"
|
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
@@ -37,22 +36,6 @@ constexpr std::size_t kSniffBytes = 256u * 1024u;
|
|||||||
constexpr std::size_t kRunFrames = 4096u;
|
constexpr std::size_t kRunFrames = 4096u;
|
||||||
constexpr unsigned kSampleRate = 48000;
|
constexpr unsigned kSampleRate = 48000;
|
||||||
|
|
||||||
// Formats the PCM takeover owns. Containers are deliberately absent: MP4/M4A
|
|
||||||
// may carry a JOC track, so those still go through the E-AC-3/JOC probe first.
|
|
||||||
bool is_pcm_takeover_extension(const char* extension) {
|
|
||||||
static const char* const kExtensions[] = {
|
|
||||||
// Decode to PCM; the kernel then maps 2.0/5.1/7.1. TrueHD/MLP is
|
|
||||||
// included too, but an Atmos TrueHD stream loses its objects when ffmpeg
|
|
||||||
// decodes it to PCM. DSD (DSF/DFF) is deliberately absent.
|
|
||||||
"wav", "flac", "mp3", "aac", "ogg", "opus", "wma", "aif", "aiff",
|
|
||||||
"ac3", "dts", "dtshd", "dtsma", "wv", "ape", "tta", "mpc", "au",
|
|
||||||
"snd", "caf", "thd", "mlp", "truehd"};
|
|
||||||
for (const char* candidate : kExtensions) {
|
|
||||||
if (extension != nullptr && stricmp_utf8(extension, candidate) == 0) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Largest magnitude in a block, for the delivery check in decode_run().
|
// Largest magnitude in a block, for the delivery check in decode_run().
|
||||||
template <typename Sample>
|
template <typename Sample>
|
||||||
double peak_of(const Sample* values, std::size_t count) {
|
double peak_of(const Sample* values, std::size_t count) {
|
||||||
@@ -270,21 +253,11 @@ public:
|
|||||||
const char* extension = std::strrchr(m_native_path.get_ptr(), '.');
|
const char* extension = std::strrchr(m_native_path.get_ptr(), '.');
|
||||||
extension = (extension != nullptr) ? extension + 1 : "";
|
extension = (extension != nullptr) ? extension + 1 : "";
|
||||||
|
|
||||||
const joc_decode::Settings current = joc_settings::current();
|
|
||||||
joc_log::line("decoder: PCM takeover=%s, extension=%s",
|
|
||||||
current.take_over_pcm ? "on" : "off",
|
|
||||||
extension != nullptr ? extension : "");
|
|
||||||
if (current.take_over_pcm && is_pcm_takeover_extension(extension)) {
|
|
||||||
open_pcm(current, abort);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (joc_container::is_container_extension(extension)) {
|
if (joc_container::is_container_extension(extension)) {
|
||||||
open_container(extension, abort);
|
open_container(extension);
|
||||||
} else {
|
} else {
|
||||||
open_bare(abort);
|
open_bare(abort);
|
||||||
}
|
}
|
||||||
if (m_pcm_mode) return;
|
|
||||||
|
|
||||||
// Whatever else happens, the tags of this file are read by the component
|
// Whatever else happens, the tags of this file are read by the component
|
||||||
// that owns its format; failing to find one is not fatal, the technical
|
// that owns its format; failing to find one is not fatal, the technical
|
||||||
@@ -298,49 +271,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A non-JOC E-AC-3 input (bare or in a container) can still be rendered:
|
|
||||||
// ffmpeg decodes it to 48 kHz float32 and the kernel's PCM_LAYOUT input maps
|
|
||||||
// the channels. JOC always wins; this only runs after the JOC probe said no.
|
|
||||||
void open_pcm_fallback(abort_callback& abort, unsigned audio_index,
|
|
||||||
const char* reason) {
|
|
||||||
joc_decode::Settings settings = joc_settings::current();
|
|
||||||
if (!settings.take_over_pcm) {
|
|
||||||
decline("decoder: yielding to the built-in decoder (%s)", reason);
|
|
||||||
throw exception_io_unsupported_format();
|
|
||||||
}
|
|
||||||
joc_log::line("decoder: no JOC (%s); routing audio track %u through ffmpeg",
|
|
||||||
reason, audio_index);
|
|
||||||
settings.audio_index = audio_index;
|
|
||||||
settings.take_over_pcm = true;
|
|
||||||
open_pcm(settings, abort);
|
|
||||||
}
|
|
||||||
|
|
||||||
// A bare stream is either read from the file or handed back. One thing has to
|
// A bare stream is either read from the file or handed back. One thing has to
|
||||||
// happen first: a tag area in front of the syncframes is not part of the
|
// happen first: a tag area in front of the syncframes is not part of the
|
||||||
// stream, and treating it as one would hand the file to the built-in decoder,
|
// stream, and treating it as one would hand the file to the built-in decoder,
|
||||||
// which plays it without the Atmos objects.
|
// which plays it without the Atmos objects.
|
||||||
// Ordinary PCM: ffmpeg is the only decoder. The kernel's PCM_LAYOUT stream
|
|
||||||
// maps 2.0/5.1/7.1 to fixed objects and renders binaural; this component does
|
|
||||||
// not hand the file to any other decoder.
|
|
||||||
void open_pcm(const joc_decode::Settings& settings, abort_callback& abort) {
|
|
||||||
std::string error;
|
|
||||||
if (!m_pcm.open(m_native_path.get_ptr(), settings, &error)) {
|
|
||||||
decline("decoder: PCM takeover could not decode the file (%s)", error.c_str());
|
|
||||||
throw exception_io_unsupported_format();
|
|
||||||
}
|
|
||||||
m_pcm_mode = true;
|
|
||||||
m_length = m_pcm.length_seconds();
|
|
||||||
m_channels = 2;
|
|
||||||
m_channel_config = channel_map_for(m_channels);
|
|
||||||
g_claimed.fetch_add(1, std::memory_order_relaxed);
|
|
||||||
joc_log::line("decoder: claiming PCM source via ffmpeg (%.3f s, binaural)",
|
|
||||||
m_length);
|
|
||||||
if (!open_forwarded(m_forward_reader, input_info_reader::class_guid,
|
|
||||||
m_path.c_str(), abort, &m_forward_name)) {
|
|
||||||
joc_log::line("decoder: no other component reads this file's tags");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void open_bare(abort_callback& abort) {
|
void open_bare(abort_callback& abort) {
|
||||||
m_stream_start = leading_tag_bytes(m_file, abort);
|
m_stream_start = leading_tag_bytes(m_file, abort);
|
||||||
if (m_stream_start != 0) {
|
if (m_stream_start != 0) {
|
||||||
@@ -359,8 +293,9 @@ public:
|
|||||||
static_cast<unsigned long long>(scan.frames_with_joc));
|
static_cast<unsigned long long>(scan.frames_with_joc));
|
||||||
|
|
||||||
if (scan.joc != joc_eac3::JocState::kYes) {
|
if (scan.joc != joc_eac3::JocState::kYes) {
|
||||||
open_pcm_fallback(abort, 0, scan.detail);
|
// Hand the file to the next entry in the priority table.
|
||||||
return;
|
decline("decoder: yielding to the built-in decoder (%s)", scan.detail);
|
||||||
|
throw exception_io_unsupported_format();
|
||||||
}
|
}
|
||||||
joc_log::line("decoder: claiming this file as E-AC-3 JOC (bare stream)");
|
joc_log::line("decoder: claiming this file as E-AC-3 JOC (bare stream)");
|
||||||
g_claimed.fetch_add(1, std::memory_order_relaxed);
|
g_claimed.fetch_add(1, std::memory_order_relaxed);
|
||||||
@@ -371,15 +306,9 @@ public:
|
|||||||
// the container's own headers, so a library scan pays nothing for the MP4s that
|
// the container's own headers, so a library scan pays nothing for the MP4s that
|
||||||
// hold AAC), and does that track carry JOC (answered from a copied prefix of
|
// hold AAC), and does that track carry JOC (answered from a copied prefix of
|
||||||
// the track). Either "no" hands the file to the next decoder in the table.
|
// the track). Either "no" hands the file to the next decoder in the table.
|
||||||
void open_container(const char* extension, abort_callback& abort) {
|
void open_container(const char* extension) {
|
||||||
m_container = joc_container::scan(m_native_path.get_ptr());
|
m_container = joc_container::scan(m_native_path.get_ptr());
|
||||||
if (!m_container.eac3) {
|
if (!m_container.eac3) {
|
||||||
const joc_decode::Settings settings = joc_settings::current();
|
|
||||||
if (settings.take_over_pcm) {
|
|
||||||
open_pcm_fallback(abort, m_container.audio_index,
|
|
||||||
m_container.detail.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
decline("decoder: yielding to the built-in decoder (%s)",
|
decline("decoder: yielding to the built-in decoder (%s)",
|
||||||
m_container.detail.c_str());
|
m_container.detail.c_str());
|
||||||
throw exception_io_unsupported_format();
|
throw exception_io_unsupported_format();
|
||||||
@@ -390,16 +319,14 @@ public:
|
|||||||
std::string detail;
|
std::string detail;
|
||||||
if (!joc_decode::probe_container_joc(settings.ffmpeg_path, m_native_path.get_ptr(),
|
if (!joc_decode::probe_container_joc(settings.ffmpeg_path, m_native_path.get_ptr(),
|
||||||
m_container.audio_index, &joc, &detail)) {
|
m_container.audio_index, &joc, &detail)) {
|
||||||
if (settings.take_over_pcm) {
|
|
||||||
open_pcm_fallback(abort, m_container.audio_index, detail.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
decline("decoder: cannot examine the E-AC-3 track (%s); yielding", detail.c_str());
|
decline("decoder: cannot examine the E-AC-3 track (%s); yielding", detail.c_str());
|
||||||
throw exception_io_unsupported_format();
|
throw exception_io_unsupported_format();
|
||||||
}
|
}
|
||||||
if (!joc) {
|
if (!joc) {
|
||||||
open_pcm_fallback(abort, m_container.audio_index, detail.c_str());
|
decline("decoder: yielding to the built-in decoder (E-AC-3 track %u carries "
|
||||||
return;
|
"no JOC: %s)",
|
||||||
|
m_container.audio_index, detail.c_str());
|
||||||
|
throw exception_io_unsupported_format();
|
||||||
}
|
}
|
||||||
|
|
||||||
joc_log::line("decoder: claiming this file as E-AC-3 JOC (%s, audio track %u, .%s)",
|
joc_log::line("decoder: claiming this file as E-AC-3 JOC (%s, audio track %u, .%s)",
|
||||||
@@ -421,32 +348,6 @@ public:
|
|||||||
throw exception_tagging_unsupported();
|
throw exception_tagging_unsupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pcm_mode) {
|
|
||||||
const joc_decode::Settings settings = joc_settings::current();
|
|
||||||
info.info_set("codec", "PCM");
|
|
||||||
info.info_set("codec_long", "PCM via ffmpeg (JOC binaural takeover)");
|
|
||||||
info.info_set_int("samplerate", kSampleRate);
|
|
||||||
info.info_set_channels_ex(2, channel_map_for(2));
|
|
||||||
info.info_set_bitspersample(32u, true);
|
|
||||||
info.set_length(m_length);
|
|
||||||
info.info_set("joc_render", "binaural (PCM takeover)");
|
|
||||||
info.info_set("joc_hrtf", settings.hrtf_file.empty()
|
|
||||||
? "(未设置)"
|
|
||||||
: file_name_of(settings.hrtf_file).c_str());
|
|
||||||
if (m_forward_reader.is_valid()) {
|
|
||||||
try {
|
|
||||||
file_info_impl tags;
|
|
||||||
m_forward_reader->get_info(0, tags, abort);
|
|
||||||
info.copy_meta(tags);
|
|
||||||
} catch (const pfc::exception& error) {
|
|
||||||
joc_log::line("decoder: reading this file's own tags failed: %s",
|
|
||||||
error.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
joc_log::line("decoder: get_info PCM takeover duration=%.3f s", m_length);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const joc_decode::FileProbe probe =
|
const joc_decode::FileProbe probe =
|
||||||
joc_decode::probe_file(m_native_path.get_ptr(), 0, m_stream_start);
|
joc_decode::probe_file(m_native_path.get_ptr(), 0, m_stream_start);
|
||||||
const joc_decode::Settings settings = joc_settings::current();
|
const joc_decode::Settings settings = joc_settings::current();
|
||||||
@@ -561,19 +462,6 @@ public:
|
|||||||
|
|
||||||
void decode_initialize(unsigned flags, abort_callback& abort) {
|
void decode_initialize(unsigned flags, abort_callback& abort) {
|
||||||
(void)abort;
|
(void)abort;
|
||||||
if (m_pcm_mode) {
|
|
||||||
m_settings = joc_settings::current();
|
|
||||||
m_channels = 2;
|
|
||||||
m_channel_config = channel_map_for(m_channels);
|
|
||||||
m_buffer.resize(kRunFrames * m_channels);
|
|
||||||
m_frames_delivered = 0;
|
|
||||||
m_reported = false;
|
|
||||||
m_delivery_mismatches = 0;
|
|
||||||
m_clipped_samples = 0;
|
|
||||||
m_clip_reported = false;
|
|
||||||
joc_log::line("decoder: PCM takeover ready (binaural, ffmpeg only)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_settings = joc_settings::current();
|
m_settings = joc_settings::current();
|
||||||
m_settings.input_kind = m_input_kind;
|
m_settings.input_kind = m_input_kind;
|
||||||
m_settings.audio_index = m_audio_index;
|
m_settings.audio_index = m_audio_index;
|
||||||
@@ -633,26 +521,6 @@ public:
|
|||||||
bool decode_run(audio_chunk& chunk, abort_callback& abort) {
|
bool decode_run(audio_chunk& chunk, abort_callback& abort) {
|
||||||
(void)abort;
|
(void)abort;
|
||||||
std::string error;
|
std::string error;
|
||||||
if (m_pcm_mode) {
|
|
||||||
const std::size_t pcm_frames = m_pcm.read(m_buffer.data(), kRunFrames, &error);
|
|
||||||
if (pcm_frames == 0) {
|
|
||||||
if (!error.empty()) {
|
|
||||||
joc_log::line("decoder: PCM read failed: %s", error.c_str());
|
|
||||||
throw exception_io_data(error.c_str());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
chunk.set_data_32(m_buffer.data(), pcm_frames,
|
|
||||||
audio_chunk::makeSpec(kSampleRate, m_channels,
|
|
||||||
m_channel_config));
|
|
||||||
m_frames_delivered += pcm_frames;
|
|
||||||
if (!m_reported) {
|
|
||||||
m_reported = true;
|
|
||||||
joc_log::line("decoder: first %llu PCM frames delivered (binaural)",
|
|
||||||
static_cast<unsigned long long>(pcm_frames));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const std::size_t frames = m_engine.read(m_buffer.data(), kRunFrames, &error);
|
const std::size_t frames = m_engine.read(m_buffer.data(), kRunFrames, &error);
|
||||||
if (frames == 0) {
|
if (frames == 0) {
|
||||||
if (!error.empty()) {
|
if (!error.empty()) {
|
||||||
@@ -738,19 +606,6 @@ public:
|
|||||||
void decode_seek(double seconds, abort_callback& abort) {
|
void decode_seek(double seconds, abort_callback& abort) {
|
||||||
// Walking the syncframe index of a long file is the only part of a seek
|
// Walking the syncframe index of a long file is the only part of a seek
|
||||||
// that can take a while, and it polls this.
|
// that can take a while, and it polls this.
|
||||||
if (m_pcm_mode) {
|
|
||||||
std::string error;
|
|
||||||
if (!m_pcm.seek(seconds, &error)) {
|
|
||||||
abort.check();
|
|
||||||
joc_log::line("decoder: PCM seek to %.6f s failed: %s", seconds, error.c_str());
|
|
||||||
throw exception_io_data(error.c_str());
|
|
||||||
}
|
|
||||||
m_frames_delivered = 0;
|
|
||||||
m_reported = false;
|
|
||||||
m_delivery_mismatches = 0;
|
|
||||||
joc_log::line("decoder: PCM seek to %.6f s", seconds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_engine.set_abort_check([&abort] { return !abort.is_aborting(); });
|
m_engine.set_abort_check([&abort] { return !abort.is_aborting(); });
|
||||||
std::string error;
|
std::string error;
|
||||||
const bool ok = m_engine.seek(seconds, m_length, &error);
|
const bool ok = m_engine.seek(seconds, m_length, &error);
|
||||||
@@ -816,9 +671,6 @@ public:
|
|||||||
// track is commonly wrapped in MP4 or Matroska; the container walk in
|
// track is commonly wrapped in MP4 or Matroska; the container walk in
|
||||||
// open() is what keeps the other files cheap to decline.
|
// open() is what keeps the other files cheap to decline.
|
||||||
if (joc_container::is_container_extension(extension)) return true;
|
if (joc_container::is_container_extension(extension)) return true;
|
||||||
if (joc_settings::read().take_over_pcm && is_pcm_takeover_extension(extension)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return (extension != nullptr) &&
|
return (extension != nullptr) &&
|
||||||
((stricmp_utf8(extension, "eac3") == 0) || (stricmp_utf8(extension, "ec3") == 0));
|
((stricmp_utf8(extension, "eac3") == 0) || (stricmp_utf8(extension, "ec3") == 0));
|
||||||
}
|
}
|
||||||
@@ -848,8 +700,6 @@ private:
|
|||||||
pfc::string8 m_native_path;
|
pfc::string8 m_native_path;
|
||||||
joc_decode::Settings m_settings;
|
joc_decode::Settings m_settings;
|
||||||
joc_decode::Engine m_engine;
|
joc_decode::Engine m_engine;
|
||||||
joc_pcm::Source m_pcm;
|
|
||||||
bool m_pcm_mode = false;
|
|
||||||
// Set by open(): a bare stream is read directly, an E-AC-3 track inside a
|
// Set by open(): a bare stream is read directly, an E-AC-3 track inside a
|
||||||
// container is extracted by ffmpeg before it reaches the renderer.
|
// container is extracted by ffmpeg before it reaches the renderer.
|
||||||
joc_decode::InputKind m_input_kind = joc_decode::InputKind::kBare;
|
joc_decode::InputKind m_input_kind = joc_decode::InputKind::kBare;
|
||||||
|
|||||||
+5
-57
@@ -41,11 +41,6 @@ constexpr std::size_t kMaxBedChannels = 8;
|
|||||||
// can ever hold.
|
// can ever hold.
|
||||||
constexpr std::size_t kBedReadBytes = 48u * 1024u;
|
constexpr std::size_t kBedReadBytes = 48u * 1024u;
|
||||||
constexpr std::size_t kBedPipeBytes = 1u << 20;
|
constexpr std::size_t kBedPipeBytes = 1u << 20;
|
||||||
// The open-time JOC scan reads in chunks: a pipe read returns what is available,
|
|
||||||
// not the whole request, and the first JOC frame can sit past the first chunk.
|
|
||||||
constexpr std::size_t kScanChunkBytes = 64u * 1024u;
|
|
||||||
// Cap on the trailing partial frame kept between reads.
|
|
||||||
constexpr std::size_t kMaxScanWindow = 1u << 20;
|
|
||||||
constexpr std::size_t kFrameSamples = JOC_FRAME_SAMPLES;
|
constexpr std::size_t kFrameSamples = JOC_FRAME_SAMPLES;
|
||||||
|
|
||||||
// The decoded bed has to stay on the E-AC-3 frame grid that the JOC matrix and the
|
// The decoded bed has to stay on the E-AC-3 frame grid that the JOC matrix and the
|
||||||
@@ -98,45 +93,6 @@ bool seven_channel_config(int config) {
|
|||||||
return config == 1 || config == 2 || config == 4;
|
return config == 1 || config == 2 || config == 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scans an E-AC-3 stream through `read` until a syncframe carrying the JOC EMDF
|
|
||||||
// container is seen, and returns its joc_dmx_config_idx. One read is not enough:
|
|
||||||
// ReadFile returns as soon as some bytes are available (a pipe hands over a
|
|
||||||
// partial chunk, not the whole request), and an encoder may leave the first
|
|
||||||
// audio frames without JOC metadata, so the first JOC frame can sit past the
|
|
||||||
// first read. Returns -1 when the stream ends without one.
|
|
||||||
template <typename ReadFn>
|
|
||||||
int scan_config_idx_streaming(ReadFn&& read, std::size_t chunk_bytes) {
|
|
||||||
std::vector<std::uint8_t> window;
|
|
||||||
std::vector<std::uint8_t> chunk(chunk_bytes);
|
|
||||||
while (true) {
|
|
||||||
const std::size_t got = read(chunk.data(), chunk.size());
|
|
||||||
if (got == 0) break;
|
|
||||||
window.insert(window.end(), chunk.begin(),
|
|
||||||
chunk.begin() + static_cast<std::ptrdiff_t>(got));
|
|
||||||
std::size_t offset = 0;
|
|
||||||
while (offset + 6u <= window.size()) {
|
|
||||||
const std::size_t bytes =
|
|
||||||
joc_eac3::frame_bytes_at(window.data(), window.size(), offset);
|
|
||||||
if (bytes == 0 || offset + bytes > window.size()) break;
|
|
||||||
if (joc_eac3::frame_has_joc(window.data() + offset, bytes)) {
|
|
||||||
unsigned config = 0;
|
|
||||||
if (joc_eac3::joc_config_idx(window.data() + offset, bytes, &config)) {
|
|
||||||
return static_cast<int>(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
offset += bytes;
|
|
||||||
}
|
|
||||||
// Only the trailing incomplete frame has to survive into the next read;
|
|
||||||
// the rest was examined above.
|
|
||||||
if (offset != 0) {
|
|
||||||
window.erase(window.begin(),
|
|
||||||
window.begin() + static_cast<std::ptrdiff_t>(offset));
|
|
||||||
}
|
|
||||||
if (window.size() > kMaxScanWindow) break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Kernel entry points.
|
// Kernel entry points.
|
||||||
//
|
//
|
||||||
@@ -375,7 +331,6 @@ const LayoutSpec kLayouts[] = {
|
|||||||
{"9.1.6", 16,
|
{"9.1.6", 16,
|
||||||
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw", "Ltf", "Rtf", "Ltm",
|
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw", "Ltf", "Rtf", "Ltm",
|
||||||
"Rtm", "Ltr", "Rtr"}},
|
"Rtm", "Ltr", "Rtr"}},
|
||||||
{"6.0", 6, {"L", "R", "Ls", "Rs", "Lrs", "Rrs"}},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::size_t kLayoutCount = sizeof(kLayouts) / sizeof(kLayouts[0]);
|
constexpr std::size_t kLayoutCount = sizeof(kLayouts) / sizeof(kLayouts[0]);
|
||||||
@@ -910,23 +865,22 @@ bool Engine::Impl::position_bare(std::uint64_t frame, std::string* error) {
|
|||||||
|
|
||||||
bool Engine::Impl::resolve_bed_channels(std::string* error) {
|
bool Engine::Impl::resolve_bed_channels(std::string* error) {
|
||||||
bed_channels = kDefaultBedChannels;
|
bed_channels = kDefaultBedChannels;
|
||||||
|
std::vector<std::uint8_t> buffer(1u << 20);
|
||||||
int config = -1;
|
int config = -1;
|
||||||
if (eac3_from_pipe) {
|
if (eac3_from_pipe) {
|
||||||
// The metadata stream has to run once to be sniffed; it is stopped again and
|
// The metadata stream has to run once to be sniffed; it is stopped again and
|
||||||
// restarted from the beginning, which costs one extra ffmpeg spawn per track.
|
// restarted from the beginning, which costs one extra ffmpeg spawn per track.
|
||||||
if (!start_metadata(error)) return false;
|
if (!start_metadata(error)) return false;
|
||||||
config = scan_config_idx_streaming(
|
const std::size_t got = eac3_pipe.read(buffer.data(), buffer.size());
|
||||||
[this](void* data, std::size_t bytes) { return eac3_pipe.read(data, bytes); },
|
|
||||||
kScanChunkBytes);
|
|
||||||
eac3_pipe.stop();
|
eac3_pipe.stop();
|
||||||
|
config = scan_config_idx(buffer.data(), got);
|
||||||
} else {
|
} else {
|
||||||
if (!eac3.is_open() && !eac3.open(input_path)) {
|
if (!eac3.is_open() && !eac3.open(input_path)) {
|
||||||
if (error != nullptr) *error = "cannot open the input file";
|
if (error != nullptr) *error = "cannot open the input file";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
config = scan_config_idx_streaming(
|
const std::size_t got = eac3.read(buffer.data(), buffer.size());
|
||||||
[this](void* data, std::size_t bytes) { return eac3.read(data, bytes); },
|
config = scan_config_idx(buffer.data(), got);
|
||||||
kScanChunkBytes);
|
|
||||||
// Put the file back where the feed loop expects it.
|
// Put the file back where the feed loop expects it.
|
||||||
if (!eac3.seek(index_base)) {
|
if (!eac3.seek(index_base)) {
|
||||||
if (error != nullptr) *error = "cannot position the input file";
|
if (error != nullptr) *error = "cannot position the input file";
|
||||||
@@ -947,8 +901,6 @@ bool Engine::Impl::start_bed(std::uint64_t source_sample, std::string* error) {
|
|||||||
// L R C LFE Ls Rs for 5.1 and L R C LFE BL BR SL SR for 7.1.
|
// L R C LFE Ls Rs for 5.1 and L R C LFE BL BR SL SR for 7.1.
|
||||||
// -drc_scale 0 -target_level 0: the bed is taken as stored, without the
|
// -drc_scale 0 -target_level 0: the bed is taken as stored, without the
|
||||||
// stream's dynrng or target-level metadata being applied by the decoder.
|
// stream's dynrng or target-level metadata being applied by the decoder.
|
||||||
// With Dialnorm enabled the 5.1 core is normalized to -31 dBFS; the 7-channel
|
|
||||||
// configurations keep the stored bed because this switch is specified for 5.1.
|
|
||||||
//
|
//
|
||||||
// -ac is only passed for the 5.1 configurations: `-ac 6` downmixes 5.1.2/7.1
|
// -ac is only passed for the 5.1 configurations: `-ac 6` downmixes 5.1.2/7.1
|
||||||
// into 5.1 and drops the extra pair, and `-ac 8` would remap 5.1.2 into 7.1.
|
// into 5.1 and drops the extra pair, and `-ac 8` would remap 5.1.2 into 7.1.
|
||||||
@@ -960,10 +912,6 @@ bool Engine::Impl::start_bed(std::uint64_t source_sample, std::string* error) {
|
|||||||
// at the start of the file, which is a low-level, noise-like difference from a
|
// at the start of the file, which is a low-level, noise-like difference from a
|
||||||
// play-through rather than a misalignment: the position stays exact.
|
// play-through rather than a misalignment: the position stays exact.
|
||||||
std::wstring input_arguments = L"-drc_scale 0 -target_level 0";
|
std::wstring input_arguments = L"-drc_scale 0 -target_level 0";
|
||||||
if (settings.dialnorm && bed_channels == kDefaultBedChannels) {
|
|
||||||
input_arguments = L"-drc_scale 0 -target_level -31";
|
|
||||||
joc_log::line("core bed: Dolby Dialnorm enabled (-target_level -31)");
|
|
||||||
}
|
|
||||||
if (has_mov_timeline(input_path)) input_arguments += L" -ignore_editlist 1";
|
if (has_mov_timeline(input_path)) input_arguments += L" -ignore_editlist 1";
|
||||||
const std::wstring offset = seek_time(source_sample);
|
const std::wstring offset = seek_time(source_sample);
|
||||||
if (!offset.empty()) input_arguments += L" -ss " + offset;
|
if (!offset.empty()) input_arguments += L" -ss " + offset;
|
||||||
|
|||||||
@@ -95,10 +95,6 @@ struct Settings {
|
|||||||
// carry both the side and the rear pair are affected, so a 5.1.x layout whose
|
// carry both the side and the rear pair are affected, so a 5.1.x layout whose
|
||||||
// rear slots hold top channels is left alone.
|
// rear slots hold top channels is left alone.
|
||||||
bool swap_side_rear = false;
|
bool swap_side_rear = false;
|
||||||
// ffmpeg is the sole decoder for this input; the kernel maps the channels.
|
|
||||||
bool take_over_pcm = false;
|
|
||||||
// Apply Dolby Dialnorm to the ffmpeg E-AC-3 5.1 core decode.
|
|
||||||
bool dialnorm = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---- speaker delivery ------------------------------------------------------
|
// ---- speaker delivery ------------------------------------------------------
|
||||||
|
|||||||
+3
-6
@@ -30,7 +30,6 @@ constexpr Entry kTexts[] = {
|
|||||||
{Text::kComboModeFar, "far(远场)", "far"},
|
{Text::kComboModeFar, "far(远场)", "far"},
|
||||||
{Text::kLabelTail, "房间尾音(秒)", "Room tail (s)"},
|
{Text::kLabelTail, "房间尾音(秒)", "Room tail (s)"},
|
||||||
{Text::kCheckInt24, "强制 24bit 输出(int24)", "Force 24-bit output (int24)"},
|
{Text::kCheckInt24, "强制 24bit 输出(int24)", "Force 24-bit output (int24)"},
|
||||||
{Text::kCheckPcm, "接管普通 PCM 源(ffmpeg 解码)", "Take over ordinary PCM (ffmpeg decode)"},
|
|
||||||
{Text::kInt24Hint, "切换后需刷新文件信息", "reload file info after switching"},
|
{Text::kInt24Hint, "切换后需刷新文件信息", "reload file info after switching"},
|
||||||
{Text::kSpeakerStatus, "扬声器布局 %s", "Speaker layout %s"},
|
{Text::kSpeakerStatus, "扬声器布局 %s", "Speaker layout %s"},
|
||||||
{Text::kGroupHrtf, "HRTF", "HRTF"},
|
{Text::kGroupHrtf, "HRTF", "HRTF"},
|
||||||
@@ -39,18 +38,16 @@ constexpr Entry kTexts[] = {
|
|||||||
{Text::kLabelHrtfFile, "HRTF 文件", "HRTF file"},
|
{Text::kLabelHrtfFile, "HRTF 文件", "HRTF file"},
|
||||||
{Text::kButtonBrowse, "浏览…", "Browse…"},
|
{Text::kButtonBrowse, "浏览…", "Browse…"},
|
||||||
{Text::kHrtfHint,
|
{Text::kHrtfHint,
|
||||||
"留空时读组件目录下 HRTF\\binaural.personalized_headphone(Rosella 模型)。",
|
"留空时读组件目录下 HRTF\\binaural.sofa 或 HRTF\\binaural.personalized_headphone。",
|
||||||
"Empty means HRTF\\binaural.personalized_headphone (Rosella model) next to "
|
"Empty means HRTF\\binaural.sofa or binaural.personalized_headphone next to "
|
||||||
"the component."},
|
"the component."},
|
||||||
{Text::kHrtfSourceSofa, "SOFA", "SOFA"},
|
{Text::kHrtfSourceSofa, "SOFA", "SOFA"},
|
||||||
{Text::kHrtfSourceRosella, "Rosella 个性化模型", "Rosella personalized model"},
|
{Text::kHrtfSourceRosella, "Rosella 个性化模型", "Rosella personalized model"},
|
||||||
{Text::kHrtfDefault, "默认", "default"},
|
{Text::kHrtfDefault, "默认", "default"},
|
||||||
{Text::kHrtfDefaultUnknown, "无法确定默认路径",
|
{Text::kHrtfDefaultUnknown, "无法确定默认路径",
|
||||||
"cannot resolve the default location"},
|
"cannot resolve the default location"},
|
||||||
{Text::kGroupGain, "增益 / 响度", "Gain / loudness"},
|
{Text::kGroupGain, "增益", "Gain"},
|
||||||
{Text::kCheckGain, "应用增益", "Apply gain"},
|
{Text::kCheckGain, "应用增益", "Apply gain"},
|
||||||
{Text::kCheckDialnorm, "Dolby Dialnorm 响度均衡(-31 dBFS)",
|
|
||||||
"Dolby Dialnorm loudness (-31 dBFS)"},
|
|
||||||
{Text::kLabelGainUnit, "dB", "dB"},
|
{Text::kLabelGainUnit, "dB", "dB"},
|
||||||
{Text::kGainStatusOn, "增益开 %.2f dB", "gain on, %.2f dB"},
|
{Text::kGainStatusOn, "增益开 %.2f dB", "gain on, %.2f dB"},
|
||||||
{Text::kGainStatusOff, "增益关(输出不衰减)", "gain off (no attenuation)"},
|
{Text::kGainStatusOff, "增益关(输出不衰减)", "gain off (no attenuation)"},
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ enum class Text {
|
|||||||
kComboModeFar,
|
kComboModeFar,
|
||||||
kLabelTail,
|
kLabelTail,
|
||||||
kCheckInt24,
|
kCheckInt24,
|
||||||
kCheckPcm,
|
|
||||||
kInt24Hint,
|
kInt24Hint,
|
||||||
kSpeakerStatus,
|
kSpeakerStatus,
|
||||||
kGroupHrtf,
|
kGroupHrtf,
|
||||||
@@ -46,7 +45,6 @@ enum class Text {
|
|||||||
kHrtfDefaultUnknown,
|
kHrtfDefaultUnknown,
|
||||||
kGroupGain,
|
kGroupGain,
|
||||||
kCheckGain,
|
kCheckGain,
|
||||||
kCheckDialnorm,
|
|
||||||
kLabelGainUnit,
|
kLabelGainUnit,
|
||||||
kGainStatusOn,
|
kGainStatusOn,
|
||||||
kGainStatusOff,
|
kGainStatusOff,
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
// Kept in one place: the string reported to foobar2000 and written to the log
|
// Kept in one place: the string reported to foobar2000 and written to the log
|
||||||
// must not drift apart.
|
// must not drift apart.
|
||||||
#define JOC_VERSION "0.6.4"
|
#define JOC_VERSION "0.5.0"
|
||||||
|
|
||||||
DECLARE_COMPONENT_VERSION("JOC decoder (E-AC-3 JOC)", JOC_VERSION,
|
DECLARE_COMPONENT_VERSION("JOC decoder (E-AC-3 JOC)", JOC_VERSION,
|
||||||
"Plays E-AC-3 JOC (Dolby Atmos) files: the JOC objects are "
|
"Plays E-AC-3 JOC (Dolby Atmos) files: the JOC objects are "
|
||||||
|
|||||||
@@ -1,371 +0,0 @@
|
|||||||
#include "pcm_source.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <atomic>
|
|
||||||
#include <cstring>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "joc_stream.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "win_path.h"
|
|
||||||
|
|
||||||
namespace joc_pcm {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
constexpr std::size_t kFrameSamples = 1536;
|
|
||||||
constexpr std::uint32_t kRate = 48000;
|
|
||||||
std::atomic<std::uint64_t> g_temp_serial{0};
|
|
||||||
|
|
||||||
std::uint16_t u16(const unsigned char* data) {
|
|
||||||
return static_cast<std::uint16_t>(data[0] | (data[1] << 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint32_t u32(const unsigned char* data) {
|
|
||||||
return static_cast<std::uint32_t>(data[0]) |
|
|
||||||
(static_cast<std::uint32_t>(data[1]) << 8) |
|
|
||||||
(static_cast<std::uint32_t>(data[2]) << 16) |
|
|
||||||
(static_cast<std::uint32_t>(data[3]) << 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool read_exact(std::FILE* file, void* data, std::size_t bytes) {
|
|
||||||
return std::fread(data, 1, bytes, file) == bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint64_t file_size(std::FILE* file) {
|
|
||||||
const long long current = _ftelli64(file);
|
|
||||||
_fseeki64(file, 0, SEEK_END);
|
|
||||||
const long long end = _ftelli64(file);
|
|
||||||
_fseeki64(file, current, SEEK_SET);
|
|
||||||
return end < 0 ? 0 : static_cast<std::uint64_t>(end);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Source::~Source() { close(); }
|
|
||||||
|
|
||||||
bool Source::decode_temp(const std::string& input_path, const std::string& ffmpeg,
|
|
||||||
unsigned audio_index, std::string* error) {
|
|
||||||
wchar_t directory[MAX_PATH] = {};
|
|
||||||
if (GetTempPathW(MAX_PATH, directory) == 0) {
|
|
||||||
if (error != nullptr) *error = "cannot locate the temp directory";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
std::wstring temp = directory;
|
|
||||||
if (!temp.empty() && temp.back() != L'\\') temp.push_back(L'\\');
|
|
||||||
temp += L"foo_input_joc_pcm_";
|
|
||||||
temp += std::to_wstring(GetCurrentProcessId());
|
|
||||||
temp += L"_";
|
|
||||||
temp += std::to_wstring(g_temp_serial.fetch_add(1, std::memory_order_relaxed));
|
|
||||||
temp += L"_";
|
|
||||||
temp += std::to_wstring(GetTickCount64());
|
|
||||||
temp += L".wav";
|
|
||||||
temp_path_ = joc_path::to_utf8(temp.c_str());
|
|
||||||
DeleteFileW(joc_path::to_wide_extended(temp_path_).c_str());
|
|
||||||
|
|
||||||
std::wstring command = L"\"" + joc_path::to_wide_extended(ffmpeg) + L"\"";
|
|
||||||
command += L" -hide_banner -loglevel error -nostdin -y -i \"";
|
|
||||||
command += joc_path::to_wide_extended(input_path);
|
|
||||||
command += L"\" -map 0:a:";
|
|
||||||
command += std::to_wstring(audio_index);
|
|
||||||
command += L" -af \"aresample=resampler=soxr:precision=28:osr=48000\" "
|
|
||||||
L"-c:a pcm_f32le \"";
|
|
||||||
command += joc_path::to_wide_extended(temp_path_);
|
|
||||||
command += L"\"";
|
|
||||||
SECURITY_ATTRIBUTES inheritable{};
|
|
||||||
inheritable.nLength = sizeof(inheritable);
|
|
||||||
inheritable.bInheritHandle = TRUE;
|
|
||||||
HANDLE null_input = CreateFileW(L"NUL", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
||||||
&inheritable, OPEN_EXISTING, 0, nullptr);
|
|
||||||
const std::wstring log_path = joc_path::to_wide_extended(temp_path_ + ".log");
|
|
||||||
HANDLE log = CreateFileW(log_path.c_str(), GENERIC_WRITE,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE, &inheritable,
|
|
||||||
CREATE_ALWAYS, 0, nullptr);
|
|
||||||
STARTUPINFOW startup{};
|
|
||||||
startup.cb = sizeof(startup);
|
|
||||||
startup.dwFlags = STARTF_USESTDHANDLES;
|
|
||||||
startup.hStdInput = null_input;
|
|
||||||
startup.hStdOutput = log;
|
|
||||||
startup.hStdError = (log != INVALID_HANDLE_VALUE) ? log : null_input;
|
|
||||||
PROCESS_INFORMATION process{};
|
|
||||||
std::vector<wchar_t> mutable_command(command.begin(), command.end());
|
|
||||||
mutable_command.push_back(L'\0');
|
|
||||||
const BOOL created = CreateProcessW(nullptr, mutable_command.data(), nullptr, nullptr,
|
|
||||||
TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &startup,
|
|
||||||
&process);
|
|
||||||
if (null_input != INVALID_HANDLE_VALUE) CloseHandle(null_input);
|
|
||||||
if (log != INVALID_HANDLE_VALUE) CloseHandle(log);
|
|
||||||
if (created == FALSE) {
|
|
||||||
if (error != nullptr) *error = "cannot start ffmpeg";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
WaitForSingleObject(process.hProcess, INFINITE);
|
|
||||||
DWORD exit_code = 1;
|
|
||||||
GetExitCodeProcess(process.hProcess, &exit_code);
|
|
||||||
CloseHandle(process.hThread);
|
|
||||||
CloseHandle(process.hProcess);
|
|
||||||
if (exit_code != 0) {
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA attributes{};
|
|
||||||
const bool wrote_output =
|
|
||||||
GetFileAttributesExW(temp.c_str(), GetFileExInfoStandard, &attributes) != FALSE &&
|
|
||||||
(static_cast<std::uint64_t>(attributes.nFileSizeHigh) << 32 |
|
|
||||||
attributes.nFileSizeLow) > 44u;
|
|
||||||
if (!wrote_output) {
|
|
||||||
std::FILE* log_file = _wfopen(log_path.c_str(), L"rb");
|
|
||||||
if (log_file != nullptr) {
|
|
||||||
char line[512];
|
|
||||||
while (std::fgets(line, sizeof(line), log_file) != nullptr) {
|
|
||||||
std::printf("ffmpeg: %s", line);
|
|
||||||
}
|
|
||||||
std::fclose(log_file);
|
|
||||||
}
|
|
||||||
if (error != nullptr) {
|
|
||||||
*error = "ffmpeg could not decode the PCM source (exit " +
|
|
||||||
std::to_string(exit_code) + ")";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
joc_log::line("pcm: ffmpeg exited with %lu but produced the WAV", exit_code);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Source::parse_wav(const std::string& path, Header* header, std::string* error) {
|
|
||||||
std::FILE* file = _wfopen(joc_path::to_wide_extended(path).c_str(), L"rb");
|
|
||||||
if (file == nullptr) {
|
|
||||||
if (error != nullptr) *error = "cannot open the decoded WAV";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
unsigned char riff[12] = {};
|
|
||||||
if (!read_exact(file, riff, sizeof(riff)) || std::memcmp(riff, "RIFF", 4) != 0 ||
|
|
||||||
std::memcmp(riff + 8, "WAVE", 4) != 0) {
|
|
||||||
std::fclose(file);
|
|
||||||
if (error != nullptr) *error = "ffmpeg did not produce a RIFF/WAVE file";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Header parsed{};
|
|
||||||
bool have_format = false;
|
|
||||||
for (;;) {
|
|
||||||
unsigned char chunk[8] = {};
|
|
||||||
if (!read_exact(file, chunk, sizeof(chunk))) break;
|
|
||||||
const std::uint32_t size = u32(chunk + 4);
|
|
||||||
const std::uint64_t payload = static_cast<std::uint64_t>(_ftelli64(file));
|
|
||||||
if (std::memcmp(chunk, "fmt ", 4) == 0 && size >= 16u) {
|
|
||||||
unsigned char fmt[40] = {};
|
|
||||||
const std::size_t fmt_bytes = std::min<std::size_t>(size, sizeof(fmt));
|
|
||||||
if (!read_exact(file, fmt, fmt_bytes)) break;
|
|
||||||
std::uint16_t format = u16(fmt);
|
|
||||||
parsed.channels = u16(fmt + 2);
|
|
||||||
parsed.sample_rate = u32(fmt + 4);
|
|
||||||
parsed.bits = u16(fmt + 14);
|
|
||||||
if (format == 0xFFFEu && fmt_bytes >= 40u) {
|
|
||||||
format = u16(fmt + 24); // WAVEFORMATEXTENSIBLE sub-format
|
|
||||||
}
|
|
||||||
if (format != 3u || parsed.bits != 32u) {
|
|
||||||
std::fclose(file);
|
|
||||||
if (error != nullptr) *error = "decoded WAV is not 32-bit float";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
have_format = true;
|
|
||||||
} else if (std::memcmp(chunk, "data", 4) == 0) {
|
|
||||||
parsed.data_offset = payload;
|
|
||||||
parsed.data_bytes = size;
|
|
||||||
}
|
|
||||||
_fseeki64(file, static_cast<long long>(payload + size + (size & 1u)), SEEK_SET);
|
|
||||||
}
|
|
||||||
const std::uint64_t file_bytes = file_size(file);
|
|
||||||
std::fclose(file);
|
|
||||||
if (!have_format || parsed.channels < 2 || parsed.channels > 8 ||
|
|
||||||
parsed.data_offset == 0) {
|
|
||||||
if (error != nullptr) *error = "decoded WAV has no usable audio data";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (parsed.data_bytes == 0u || parsed.data_bytes == 0xFFFFFFFFu ||
|
|
||||||
parsed.data_offset + parsed.data_bytes > file_bytes) {
|
|
||||||
parsed.data_bytes = file_bytes - parsed.data_offset;
|
|
||||||
}
|
|
||||||
*header = parsed;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Source::open(const std::string& input_path, const joc_decode::Settings& settings,
|
|
||||||
std::string* error) {
|
|
||||||
close();
|
|
||||||
if (!decode_temp(input_path, settings.ffmpeg_path, settings.audio_index, error)) return false;
|
|
||||||
Header header{};
|
|
||||||
if (!parse_wav(temp_path_, &header, error)) {
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (header.sample_rate != kRate) {
|
|
||||||
if (error != nullptr) *error = "ffmpeg did not produce 48 kHz audio";
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
header_ = header;
|
|
||||||
channels_ = header.channels;
|
|
||||||
file_ = _wfopen(joc_path::to_wide_extended(temp_path_).c_str(), L"rb");
|
|
||||||
if (file_ == nullptr) {
|
|
||||||
if (error != nullptr) *error = "cannot reopen the decoded WAV";
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
total_frames_ = header.data_bytes / (static_cast<std::uint64_t>(channels_) * 4u);
|
|
||||||
length_seconds_ = static_cast<double>(total_frames_) / kRate;
|
|
||||||
feed_.assign(kFrameSamples * static_cast<std::size_t>(channels_), 0.0f);
|
|
||||||
|
|
||||||
joc_stream_config config{};
|
|
||||||
config.struct_size = sizeof(config);
|
|
||||||
config.struct_version = 1;
|
|
||||||
config.input = JOC_STREAM_IN_PCM_LAYOUT;
|
|
||||||
config.output = JOC_STREAM_OUT_BINAURAL;
|
|
||||||
config.pcm_layout = "auto";
|
|
||||||
const std::string hrtf = joc_decode::resolve_hrtf_file(settings);
|
|
||||||
config.personalized_headphone_path = hrtf.c_str();
|
|
||||||
config.binaural_mode = settings.binaural_mode;
|
|
||||||
config.binaural_tail_seconds = settings.tail_seconds;
|
|
||||||
config.object_delay_samples = settings.object_delay_samples;
|
|
||||||
config.gain_db = settings.gain_db;
|
|
||||||
config.rosella_filterbank = 1u;
|
|
||||||
const joc_error created = joc_stream_create(&config, &stream_);
|
|
||||||
if (created != JOC_OK || stream_ == nullptr) {
|
|
||||||
if (error != nullptr) *error = "kernel PCM layout stream creation failed";
|
|
||||||
close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_fseeki64(file_, static_cast<long long>(header_.data_offset), SEEK_SET);
|
|
||||||
frames_read_ = 0;
|
|
||||||
emitted_frames_ = 0;
|
|
||||||
eof_ = false;
|
|
||||||
flushed_ = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Source::push_block(std::string* error) {
|
|
||||||
if (file_ == nullptr || stream_ == nullptr || eof_) return false;
|
|
||||||
std::size_t frames = kFrameSamples;
|
|
||||||
const std::uint64_t remaining = total_frames_ - frames_read_;
|
|
||||||
if (remaining < frames) frames = static_cast<std::size_t>(remaining);
|
|
||||||
std::fill(feed_.begin(), feed_.end(), 0.0f);
|
|
||||||
if (frames != 0u &&
|
|
||||||
std::fread(feed_.data(), sizeof(float), frames * static_cast<std::size_t>(channels_),
|
|
||||||
file_) != frames * static_cast<std::size_t>(channels_)) {
|
|
||||||
if (error != nullptr) *error = "cannot read the decoded WAV";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (frames != 0u) {
|
|
||||||
joc_stream_buffer input{};
|
|
||||||
input.struct_size = sizeof(input);
|
|
||||||
input.struct_version = 1;
|
|
||||||
input.kind = JOC_STREAM_IN_PCM_LAYOUT;
|
|
||||||
input.channels = static_cast<std::uint32_t>(channels_);
|
|
||||||
input.sample_rate = kRate;
|
|
||||||
input.sample_count = static_cast<std::uint32_t>(frames);
|
|
||||||
input.pcm = feed_.data();
|
|
||||||
std::uint32_t consumed = 0;
|
|
||||||
std::uint32_t consumed_bytes = 0;
|
|
||||||
if (joc_stream_push(stream_, &input, &consumed, &consumed_bytes) != JOC_OK) {
|
|
||||||
if (error != nullptr) *error = "kernel PCM layout push failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
frames_read_ += frames;
|
|
||||||
if (frames_read_ >= total_frames_ || frames == 0u) eof_ = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Source::pull(std::size_t frames, float* destination, std::size_t* produced,
|
|
||||||
std::string* error) {
|
|
||||||
*produced = 0;
|
|
||||||
if (stream_ == nullptr || frames == 0u) return true;
|
|
||||||
joc_stream_buffer output{};
|
|
||||||
output.struct_size = sizeof(output);
|
|
||||||
output.struct_version = 1;
|
|
||||||
output.out_pcm = destination;
|
|
||||||
output.sample_count = static_cast<std::uint32_t>(frames);
|
|
||||||
std::uint32_t rendered = 0;
|
|
||||||
if (joc_stream_pull(stream_, &output, &rendered) != JOC_OK) {
|
|
||||||
if (error != nullptr) *error = "kernel binaural pull failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*produced = rendered;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t Source::read(float* destination, std::size_t frames, std::string* error) {
|
|
||||||
if (stream_ == nullptr || destination == nullptr || frames == 0u) return 0;
|
|
||||||
if (emitted_frames_ >= total_frames_) return 0;
|
|
||||||
const std::size_t wanted = static_cast<std::size_t>(
|
|
||||||
std::min<std::uint64_t>(frames, total_frames_ - emitted_frames_));
|
|
||||||
std::size_t written = 0;
|
|
||||||
while (written < wanted) {
|
|
||||||
std::size_t produced = 0;
|
|
||||||
if (!pull(wanted - written, destination + written * 2u, &produced, error)) {
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
written += produced;
|
|
||||||
if (written == wanted) break;
|
|
||||||
if (!eof_) {
|
|
||||||
if (!push_block(error)) return written;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!flushed_) {
|
|
||||||
if (joc_stream_flush(stream_) != JOC_OK) {
|
|
||||||
if (error != nullptr) *error = "kernel flush failed";
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
flushed_ = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
emitted_frames_ += written;
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Source::seek(double seconds, std::string* error) {
|
|
||||||
if (stream_ == nullptr || file_ == nullptr) return false;
|
|
||||||
if (seconds < 0.0) seconds = 0.0;
|
|
||||||
std::uint64_t frame = static_cast<std::uint64_t>(seconds * kRate + 0.5);
|
|
||||||
frame = std::min(frame, total_frames_);
|
|
||||||
if (joc_stream_reset(stream_) != JOC_OK) {
|
|
||||||
if (error != nullptr) *error = "kernel reset failed";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_fseeki64(file_, static_cast<long long>(header_.data_offset +
|
|
||||||
frame * static_cast<std::uint64_t>(channels_) * 4u),
|
|
||||||
SEEK_SET);
|
|
||||||
frames_read_ = frame;
|
|
||||||
emitted_frames_ = frame;
|
|
||||||
eof_ = frames_read_ >= total_frames_;
|
|
||||||
flushed_ = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Source::close() {
|
|
||||||
if (stream_ != nullptr) {
|
|
||||||
joc_stream_destroy(stream_);
|
|
||||||
stream_ = nullptr;
|
|
||||||
}
|
|
||||||
if (file_ != nullptr) {
|
|
||||||
std::fclose(file_);
|
|
||||||
file_ = nullptr;
|
|
||||||
}
|
|
||||||
if (!temp_path_.empty()) {
|
|
||||||
DeleteFileW(joc_path::to_wide_extended(temp_path_).c_str());
|
|
||||||
DeleteFileW(joc_path::to_wide_extended(temp_path_ + ".log").c_str());
|
|
||||||
temp_path_.clear();
|
|
||||||
}
|
|
||||||
feed_.clear();
|
|
||||||
frames_read_ = 0;
|
|
||||||
emitted_frames_ = 0;
|
|
||||||
total_frames_ = 0;
|
|
||||||
length_seconds_ = 0.0;
|
|
||||||
eof_ = false;
|
|
||||||
flushed_ = false;
|
|
||||||
channels_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace joc_pcm
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
// Whole-file PCM takeover for foo_input_joc.
|
|
||||||
//
|
|
||||||
// ffmpeg is the only decoder here: it produces a 48 kHz float32 WAV, and the
|
|
||||||
// kernel's PCM_LAYOUT stream maps 2.0/5.1/7.1 to fixed objects and renders
|
|
||||||
// binaural. The temp WAV exists so the component can seek without a second
|
|
||||||
// decoder; it is deleted when the input closes.
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "joc_decode.h"
|
|
||||||
|
|
||||||
struct joc_stream;
|
|
||||||
|
|
||||||
namespace joc_pcm {
|
|
||||||
|
|
||||||
class Source {
|
|
||||||
public:
|
|
||||||
Source() = default;
|
|
||||||
~Source();
|
|
||||||
Source(const Source&) = delete;
|
|
||||||
Source& operator=(const Source&) = delete;
|
|
||||||
|
|
||||||
bool open(const std::string& input_path, const joc_decode::Settings& settings,
|
|
||||||
std::string* error);
|
|
||||||
// Fills interleaved stereo float32 frames; returns frames written.
|
|
||||||
std::size_t read(float* destination, std::size_t frames, std::string* error);
|
|
||||||
bool seek(double seconds, std::string* error);
|
|
||||||
void close();
|
|
||||||
|
|
||||||
double length_seconds() const { return length_seconds_; }
|
|
||||||
unsigned channels() const { return 2; }
|
|
||||||
unsigned sample_rate() const { return 48000; }
|
|
||||||
bool is_open() const { return stream_ != nullptr; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Header {
|
|
||||||
std::uint32_t sample_rate = 0;
|
|
||||||
std::uint16_t channels = 0;
|
|
||||||
std::uint16_t bits = 0;
|
|
||||||
std::uint64_t data_offset = 0;
|
|
||||||
std::uint64_t data_bytes = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool decode_temp(const std::string& input_path, const std::string& ffmpeg,
|
|
||||||
unsigned audio_index, std::string* error);
|
|
||||||
bool parse_wav(const std::string& path, Header* header, std::string* error);
|
|
||||||
bool push_block(std::string* error);
|
|
||||||
bool pull(std::size_t frames, float* destination, std::size_t* produced,
|
|
||||||
std::string* error);
|
|
||||||
|
|
||||||
std::FILE* file_ = nullptr;
|
|
||||||
joc_stream* stream_ = nullptr;
|
|
||||||
Header header_{};
|
|
||||||
std::string temp_path_;
|
|
||||||
std::vector<float> feed_;
|
|
||||||
std::uint64_t frames_read_ = 0;
|
|
||||||
std::uint64_t emitted_frames_ = 0;
|
|
||||||
std::uint64_t total_frames_ = 0;
|
|
||||||
double length_seconds_ = 0.0;
|
|
||||||
bool eof_ = false;
|
|
||||||
bool flushed_ = false;
|
|
||||||
int channels_ = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace joc_pcm
|
|
||||||
+4
-15
@@ -285,8 +285,7 @@ private:
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (id == IDC_CHECK_GAIN || id == IDC_CHECK_INT24 ||
|
if (id == IDC_CHECK_GAIN || id == IDC_CHECK_INT24 ||
|
||||||
id == IDC_CHECK_SWAP_SIDE_REAR || id == IDC_CHECK_PCM ||
|
id == IDC_CHECK_SWAP_SIDE_REAR) {
|
||||||
id == IDC_CHECK_DIALNORM) {
|
|
||||||
update_status();
|
update_status();
|
||||||
notify();
|
notify();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -370,7 +369,7 @@ private:
|
|||||||
label(IDC_LABEL_TAIL, joc_lang::Text::kLabelTail);
|
label(IDC_LABEL_TAIL, joc_lang::Text::kLabelTail);
|
||||||
label(IDC_CHECK_INT24, joc_lang::Text::kCheckInt24);
|
label(IDC_CHECK_INT24, joc_lang::Text::kCheckInt24);
|
||||||
label(IDC_CHECK_SWAP_SIDE_REAR, joc_lang::Text::kCheckSwapSideRear);
|
label(IDC_CHECK_SWAP_SIDE_REAR, joc_lang::Text::kCheckSwapSideRear);
|
||||||
label(IDC_CHECK_PCM, joc_lang::Text::kCheckPcm);
|
label(IDC_LABEL_INT24_HINT, joc_lang::Text::kInt24Hint);
|
||||||
label(IDC_GROUP_HRTF, joc_lang::Text::kGroupHrtf);
|
label(IDC_GROUP_HRTF, joc_lang::Text::kGroupHrtf);
|
||||||
label(IDC_RADIO_HRTF_ROSELLA, joc_lang::Text::kRadioRosella);
|
label(IDC_RADIO_HRTF_ROSELLA, joc_lang::Text::kRadioRosella);
|
||||||
label(IDC_LABEL_HRTF, joc_lang::Text::kLabelHrtfFile);
|
label(IDC_LABEL_HRTF, joc_lang::Text::kLabelHrtfFile);
|
||||||
@@ -379,7 +378,7 @@ private:
|
|||||||
label(IDC_GROUP_GAIN, joc_lang::Text::kGroupGain);
|
label(IDC_GROUP_GAIN, joc_lang::Text::kGroupGain);
|
||||||
label(IDC_CHECK_GAIN, joc_lang::Text::kCheckGain);
|
label(IDC_CHECK_GAIN, joc_lang::Text::kCheckGain);
|
||||||
label(IDC_LABEL_GAIN, joc_lang::Text::kLabelGainUnit);
|
label(IDC_LABEL_GAIN, joc_lang::Text::kLabelGainUnit);
|
||||||
label(IDC_CHECK_DIALNORM, joc_lang::Text::kCheckDialnorm);
|
label(IDC_LABEL_GAIN_HINT, joc_lang::Text::kGainHint);
|
||||||
label(IDC_GROUP_MISC, joc_lang::Text::kGroupOther);
|
label(IDC_GROUP_MISC, joc_lang::Text::kGroupOther);
|
||||||
label(IDC_LABEL_LANGUAGE, joc_lang::Text::kLabelLanguage);
|
label(IDC_LABEL_LANGUAGE, joc_lang::Text::kLabelLanguage);
|
||||||
label(IDC_LABEL_FFMPEG, joc_lang::Text::kLabelFfmpeg);
|
label(IDC_LABEL_FFMPEG, joc_lang::Text::kLabelFfmpeg);
|
||||||
@@ -407,13 +406,9 @@ private:
|
|||||||
|
|
||||||
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_GAIN), BM_SETCHECK,
|
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_GAIN), BM_SETCHECK,
|
||||||
values.gain_enabled ? BST_CHECKED : BST_UNCHECKED, 0);
|
values.gain_enabled ? BST_CHECKED : BST_UNCHECKED, 0);
|
||||||
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_DIALNORM), BM_SETCHECK,
|
|
||||||
values.dialnorm ? BST_CHECKED : BST_UNCHECKED, 0);
|
|
||||||
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_INT24), BM_SETCHECK,
|
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_INT24), BM_SETCHECK,
|
||||||
values.force_int24 ? BST_CHECKED : BST_UNCHECKED, 0);
|
values.force_int24 ? BST_CHECKED : BST_UNCHECKED, 0);
|
||||||
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_PCM), BM_SETCHECK,
|
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_SWAP_SIDE_REAR), BM_SETCHECK,
|
||||||
values.take_over_pcm ? BST_CHECKED : BST_UNCHECKED, 0);
|
|
||||||
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_SWAP_SIDE_REAR), BM_SETCHECK,
|
|
||||||
values.swap_side_rear ? BST_CHECKED : BST_UNCHECKED, 0);
|
values.swap_side_rear ? BST_CHECKED : BST_UNCHECKED, 0);
|
||||||
|
|
||||||
// The item lists are language-dependent, so they are built (in the stored
|
// The item lists are language-dependent, so they are built (in the stored
|
||||||
@@ -464,14 +459,10 @@ private:
|
|||||||
values.gain_db = std::atof(get_text(GetDlgItem(m_hwnd, IDC_EDIT_GAIN)).c_str());
|
values.gain_db = std::atof(get_text(GetDlgItem(m_hwnd, IDC_EDIT_GAIN)).c_str());
|
||||||
values.gain_enabled =
|
values.gain_enabled =
|
||||||
IsDlgButtonChecked(m_hwnd, IDC_CHECK_GAIN) == BST_CHECKED;
|
IsDlgButtonChecked(m_hwnd, IDC_CHECK_GAIN) == BST_CHECKED;
|
||||||
values.dialnorm =
|
|
||||||
IsDlgButtonChecked(m_hwnd, IDC_CHECK_DIALNORM) == BST_CHECKED;
|
|
||||||
values.force_int24 =
|
values.force_int24 =
|
||||||
IsDlgButtonChecked(m_hwnd, IDC_CHECK_INT24) == BST_CHECKED;
|
IsDlgButtonChecked(m_hwnd, IDC_CHECK_INT24) == BST_CHECKED;
|
||||||
values.swap_side_rear =
|
values.swap_side_rear =
|
||||||
IsDlgButtonChecked(m_hwnd, IDC_CHECK_SWAP_SIDE_REAR) == BST_CHECKED;
|
IsDlgButtonChecked(m_hwnd, IDC_CHECK_SWAP_SIDE_REAR) == BST_CHECKED;
|
||||||
values.take_over_pcm =
|
|
||||||
IsDlgButtonChecked(m_hwnd, IDC_CHECK_PCM) == BST_CHECKED;
|
|
||||||
values.language = selected_language();
|
values.language = selected_language();
|
||||||
// Advanced values are not on this page; keep whatever is stored.
|
// Advanced values are not on this page; keep whatever is stored.
|
||||||
const joc_settings::Values stored = joc_settings::read();
|
const joc_settings::Values stored = joc_settings::read();
|
||||||
@@ -533,10 +524,8 @@ private:
|
|||||||
if (now.hrtf_file != m_initial.hrtf_file) return true;
|
if (now.hrtf_file != m_initial.hrtf_file) return true;
|
||||||
if (now.binaural_mode != m_initial.binaural_mode) return true;
|
if (now.binaural_mode != m_initial.binaural_mode) return true;
|
||||||
if (now.gain_enabled != m_initial.gain_enabled) return true;
|
if (now.gain_enabled != m_initial.gain_enabled) return true;
|
||||||
if (now.dialnorm != m_initial.dialnorm) return true;
|
|
||||||
if (now.force_int24 != m_initial.force_int24) return true;
|
if (now.force_int24 != m_initial.force_int24) return true;
|
||||||
if (now.swap_side_rear != m_initial.swap_side_rear) return true;
|
if (now.swap_side_rear != m_initial.swap_side_rear) return true;
|
||||||
if (now.take_over_pcm != m_initial.take_over_pcm) return true;
|
|
||||||
if (now.gain_db != m_initial.gain_db) return true;
|
if (now.gain_db != m_initial.gain_db) return true;
|
||||||
if (now.tail_seconds != m_initial.tail_seconds) return true;
|
if (now.tail_seconds != m_initial.tail_seconds) return true;
|
||||||
if (now.ffmpeg_path != m_initial.ffmpeg_path) return true;
|
if (now.ffmpeg_path != m_initial.ffmpeg_path) return true;
|
||||||
|
|||||||
+3
-4
@@ -36,8 +36,7 @@ BEGIN
|
|||||||
LTEXT "", IDC_LABEL_OUTPUT_STATUS, 16, 53, 300, 10
|
LTEXT "", IDC_LABEL_OUTPUT_STATUS, 16, 53, 300, 10
|
||||||
CONTROL "强制 24bit 输出(int24)", IDC_CHECK_INT24, "Button",
|
CONTROL "强制 24bit 输出(int24)", IDC_CHECK_INT24, "Button",
|
||||||
BS_AUTOCHECKBOX | WS_TABSTOP, 16, 65, 156, 10
|
BS_AUTOCHECKBOX | WS_TABSTOP, 16, 65, 156, 10
|
||||||
CONTROL "接管普通 PCM 源(ffmpeg 解码)", IDC_CHECK_PCM, "Button",
|
LTEXT "切换后需刷新文件信息", IDC_LABEL_INT24_HINT, 176, 65, 136, 10
|
||||||
BS_AUTOCHECKBOX | WS_TABSTOP, 176, 65, 140, 10
|
|
||||||
|
|
||||||
GROUPBOX "HRTF", IDC_GROUP_HRTF, 7, 79, 316, 92
|
GROUPBOX "HRTF", IDC_GROUP_HRTF, 7, 79, 316, 92
|
||||||
LTEXT "Rosella 个性化模型", IDC_RADIO_HRTF_ROSELLA, 16, 91, 146, 10
|
LTEXT "Rosella 个性化模型", IDC_RADIO_HRTF_ROSELLA, 16, 91, 146, 10
|
||||||
@@ -54,8 +53,8 @@ BEGIN
|
|||||||
LTEXT "dB", IDC_LABEL_GAIN, 68, 187, 12, 10
|
LTEXT "dB", IDC_LABEL_GAIN, 68, 187, 12, 10
|
||||||
EDITTEXT IDC_EDIT_GAIN, 84, 184, 44, 13, ES_AUTOHSCROLL
|
EDITTEXT IDC_EDIT_GAIN, 84, 184, 44, 13, ES_AUTOHSCROLL
|
||||||
LTEXT "", IDC_LABEL_GAIN_STATUS, 134, 187, 182, 10
|
LTEXT "", IDC_LABEL_GAIN_STATUS, 134, 187, 182, 10
|
||||||
CONTROL "Dolby Dialnorm 响度均衡(-31 dBFS)", IDC_CHECK_DIALNORM, "Button",
|
LTEXT "双耳渲染后可能超过 0 dBFS,可用负值衰减。",
|
||||||
BS_AUTOCHECKBOX | WS_TABSTOP, 16, 202, 300, 10
|
IDC_LABEL_GAIN_HINT, 16, 202, 300, 10
|
||||||
|
|
||||||
GROUPBOX "其它", IDC_GROUP_MISC, 7, 219, 316, 48
|
GROUPBOX "其它", IDC_GROUP_MISC, 7, 219, 316, 48
|
||||||
CONTROL "交换侧环绕与后环绕声道", IDC_CHECK_SWAP_SIDE_REAR, "Button",
|
CONTROL "交换侧环绕与后环绕声道", IDC_CHECK_SWAP_SIDE_REAR, "Button",
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#define IDC_LABEL_OUTPUT_STATUS 2019
|
#define IDC_LABEL_OUTPUT_STATUS 2019
|
||||||
// Delivery format, in the same group: what the decoder hands to foobar2000.
|
// Delivery format, in the same group: what the decoder hands to foobar2000.
|
||||||
#define IDC_CHECK_INT24 2050
|
#define IDC_CHECK_INT24 2050
|
||||||
#define IDC_CHECK_PCM 2052
|
|
||||||
#define IDC_LABEL_INT24_HINT 2051
|
#define IDC_LABEL_INT24_HINT 2051
|
||||||
|
|
||||||
#define IDC_GROUP_HRTF 2020
|
#define IDC_GROUP_HRTF 2020
|
||||||
@@ -32,7 +31,6 @@
|
|||||||
#define IDC_EDIT_GAIN 2033
|
#define IDC_EDIT_GAIN 2033
|
||||||
#define IDC_LABEL_GAIN_HINT 2034
|
#define IDC_LABEL_GAIN_HINT 2034
|
||||||
#define IDC_LABEL_GAIN_STATUS 2035
|
#define IDC_LABEL_GAIN_STATUS 2035
|
||||||
#define IDC_CHECK_DIALNORM 2036
|
|
||||||
|
|
||||||
#define IDC_GROUP_MISC 2040
|
#define IDC_GROUP_MISC 2040
|
||||||
#define IDC_LABEL_FFMPEG 2041
|
#define IDC_LABEL_FFMPEG 2041
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ constexpr GUID kGuidGain = {0x6c04d8b2, 0xe75f, 0x4a39, {0x8d, 0x26, 0x51, 0xb3,
|
|||||||
constexpr GUID kGuidTail = {0x38f1b6a7, 0x0d24, 0x4e88, {0xb7, 0x95, 0x2c, 0x61, 0x4f, 0xd2, 0x08, 0xa3}};
|
constexpr GUID kGuidTail = {0x38f1b6a7, 0x0d24, 0x4e88, {0xb7, 0x95, 0x2c, 0x61, 0x4f, 0xd2, 0x08, 0xa3}};
|
||||||
constexpr GUID kGuidForceInt24 = {0xd2c67f41, 0x8b53, 0x4a2e, {0x97, 0x61, 0x0f, 0xc8, 0x35, 0xba, 0x64, 0x12}};
|
constexpr GUID kGuidForceInt24 = {0xd2c67f41, 0x8b53, 0x4a2e, {0x97, 0x61, 0x0f, 0xc8, 0x35, 0xba, 0x64, 0x12}};
|
||||||
constexpr GUID kGuidSwapSideRear = {0x2b7f6d18, 0x59c4, 0x4a83, {0x8e, 0x15, 0x73, 0xac, 0x06, 0xd9, 0x4b, 0x27}};
|
constexpr GUID kGuidSwapSideRear = {0x2b7f6d18, 0x59c4, 0x4a83, {0x8e, 0x15, 0x73, 0xac, 0x06, 0xd9, 0x4b, 0x27}};
|
||||||
constexpr GUID kGuidDialnorm = {0x47e2a9b3, 0x6c14, 0x4d78, {0x81, 0x5f, 0x2a, 0xc7, 0x90, 0x3e, 0x64, 0xb1}};
|
|
||||||
constexpr GUID kGuidTakeOverPcm = {0x9f2b6c41, 0x7d38, 0x4a05, {0x86, 0x1e, 0x52, 0xb9, 0x0c, 0x74, 0xe3, 0x28}};
|
|
||||||
constexpr GUID kGuidObjectDelay = {0x5b2e9c18, 0xa640, 0x4d7b, {0x92, 0x0e, 0x37, 0xc5, 0x81, 0x6b, 0x2a, 0x54}};
|
constexpr GUID kGuidObjectDelay = {0x5b2e9c18, 0xa640, 0x4d7b, {0x92, 0x0e, 0x37, 0xc5, 0x81, 0x6b, 0x2a, 0x54}};
|
||||||
constexpr GUID kGuidThreads = {0xcb7a4015, 0x3f98, 0x4c62, {0xa0, 0x8d, 0x1b, 0x74, 0x29, 0xe6, 0x53, 0x0f}};
|
constexpr GUID kGuidThreads = {0xcb7a4015, 0x3f98, 0x4c62, {0xa0, 0x8d, 0x1b, 0x74, 0x29, 0xe6, 0x53, 0x0f}};
|
||||||
constexpr GUID kGuidFfmpeg = {0x0e9d37c2, 0x5a18, 0x4b40, {0xb6, 0x3f, 0x88, 0x2d, 0x9a, 0x70, 0x1c, 0x65}};
|
constexpr GUID kGuidFfmpeg = {0x0e9d37c2, 0x5a18, 0x4b40, {0xb6, 0x3f, 0x88, 0x2d, 0x9a, 0x70, 0x1c, 0x65}};
|
||||||
@@ -50,8 +48,6 @@ cfg_uint g_tail_ms(kGuidTail, 5000);
|
|||||||
cfg_bool g_force_int24(kGuidForceInt24, false);
|
cfg_bool g_force_int24(kGuidForceInt24, false);
|
||||||
// Swap the side and rear surround pairs in the delivered PCM.
|
// Swap the side and rear surround pairs in the delivered PCM.
|
||||||
cfg_bool g_swap_side_rear(kGuidSwapSideRear, false);
|
cfg_bool g_swap_side_rear(kGuidSwapSideRear, false);
|
||||||
cfg_bool g_take_over_pcm(kGuidTakeOverPcm, false);
|
|
||||||
cfg_bool g_dialnorm(kGuidDialnorm, false);
|
|
||||||
cfg_uint g_object_delay(kGuidObjectDelay, 1473);
|
cfg_uint g_object_delay(kGuidObjectDelay, 1473);
|
||||||
cfg_uint g_threads(kGuidThreads, 0);
|
cfg_uint g_threads(kGuidThreads, 0);
|
||||||
cfg_string g_ffmpeg(kGuidFfmpeg, "ffmpeg");
|
cfg_string g_ffmpeg(kGuidFfmpeg, "ffmpeg");
|
||||||
@@ -132,8 +128,6 @@ Values read() {
|
|||||||
values.tail_seconds = static_cast<double>(static_cast<unsigned>(g_tail_ms)) / 1000.0;
|
values.tail_seconds = static_cast<double>(static_cast<unsigned>(g_tail_ms)) / 1000.0;
|
||||||
values.force_int24 = static_cast<bool>(g_force_int24);
|
values.force_int24 = static_cast<bool>(g_force_int24);
|
||||||
values.swap_side_rear = static_cast<bool>(g_swap_side_rear);
|
values.swap_side_rear = static_cast<bool>(g_swap_side_rear);
|
||||||
values.take_over_pcm = static_cast<bool>(g_take_over_pcm);
|
|
||||||
values.dialnorm = static_cast<bool>(g_dialnorm);
|
|
||||||
values.object_delay_samples = static_cast<unsigned>(g_object_delay);
|
values.object_delay_samples = static_cast<unsigned>(g_object_delay);
|
||||||
values.native_threads = static_cast<unsigned>(g_threads);
|
values.native_threads = static_cast<unsigned>(g_threads);
|
||||||
values.ffmpeg_path = g_ffmpeg.get_ptr();
|
values.ffmpeg_path = g_ffmpeg.get_ptr();
|
||||||
@@ -164,8 +158,6 @@ void write(const Values& values) {
|
|||||||
g_tail_ms = static_cast<unsigned>(values.tail_seconds * 1000.0 + 0.5);
|
g_tail_ms = static_cast<unsigned>(values.tail_seconds * 1000.0 + 0.5);
|
||||||
g_force_int24 = values.force_int24;
|
g_force_int24 = values.force_int24;
|
||||||
g_swap_side_rear = values.swap_side_rear;
|
g_swap_side_rear = values.swap_side_rear;
|
||||||
g_take_over_pcm = values.take_over_pcm;
|
|
||||||
g_dialnorm = values.dialnorm;
|
|
||||||
g_object_delay = values.object_delay_samples;
|
g_object_delay = values.object_delay_samples;
|
||||||
g_threads = values.native_threads;
|
g_threads = values.native_threads;
|
||||||
g_ffmpeg = values.ffmpeg_path.c_str();
|
g_ffmpeg = values.ffmpeg_path.c_str();
|
||||||
@@ -188,8 +180,6 @@ joc_decode::Settings current() {
|
|||||||
(void)env_double("JOC_TAIL_SECONDS", &values.tail_seconds);
|
(void)env_double("JOC_TAIL_SECONDS", &values.tail_seconds);
|
||||||
if (env_string("JOC_FORCE_INT24", &text)) values.force_int24 = (text != "0");
|
if (env_string("JOC_FORCE_INT24", &text)) values.force_int24 = (text != "0");
|
||||||
if (env_string("JOC_SWAP_SIDE_REAR", &text)) values.swap_side_rear = (text != "0");
|
if (env_string("JOC_SWAP_SIDE_REAR", &text)) values.swap_side_rear = (text != "0");
|
||||||
if (env_string("JOC_TAKE_OVER_PCM", &text)) values.take_over_pcm = (text != "0");
|
|
||||||
if (env_string("JOC_DIALNORM", &text)) values.dialnorm = (text != "0");
|
|
||||||
(void)env_uint("JOC_OBJECT_DELAY", &values.object_delay_samples);
|
(void)env_uint("JOC_OBJECT_DELAY", &values.object_delay_samples);
|
||||||
(void)env_uint("JOC_THREADS", &values.native_threads);
|
(void)env_uint("JOC_THREADS", &values.native_threads);
|
||||||
|
|
||||||
@@ -206,8 +196,6 @@ joc_decode::Settings current() {
|
|||||||
settings.tail_seconds = values.tail_seconds;
|
settings.tail_seconds = values.tail_seconds;
|
||||||
settings.force_int24 = values.force_int24;
|
settings.force_int24 = values.force_int24;
|
||||||
settings.swap_side_rear = values.swap_side_rear;
|
settings.swap_side_rear = values.swap_side_rear;
|
||||||
settings.take_over_pcm = values.take_over_pcm;
|
|
||||||
settings.dialnorm = values.dialnorm;
|
|
||||||
settings.object_delay_samples = values.object_delay_samples;
|
settings.object_delay_samples = values.object_delay_samples;
|
||||||
settings.native_threads = values.native_threads;
|
settings.native_threads = values.native_threads;
|
||||||
settings.ffmpeg_path = values.ffmpeg_path.empty() ? "ffmpeg" : values.ffmpeg_path;
|
settings.ffmpeg_path = values.ffmpeg_path.empty() ? "ffmpeg" : values.ffmpeg_path;
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ struct Values {
|
|||||||
// Swap Ls with Lrs and Rs with Rrs in the delivered speaker PCM; a layout
|
// Swap Ls with Lrs and Rs with Rrs in the delivered speaker PCM; a layout
|
||||||
// without both pairs is delivered unchanged.
|
// without both pairs is delivered unchanged.
|
||||||
bool swap_side_rear = false;
|
bool swap_side_rear = false;
|
||||||
// Take over ordinary PCM files and render them binaurally through ffmpeg.
|
|
||||||
bool take_over_pcm = false;
|
|
||||||
// Apply Dolby Dialnorm to the ffmpeg E-AC-3 5.1 core decode (-target_level -31).
|
|
||||||
bool dialnorm = false;
|
|
||||||
unsigned object_delay_samples = 1473;
|
unsigned object_delay_samples = 1473;
|
||||||
unsigned native_threads = 0;
|
unsigned native_threads = 0;
|
||||||
std::string ffmpeg_path = "ffmpeg";
|
std::string ffmpeg_path = "ffmpeg";
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ const Expected kExpected[] = {
|
|||||||
{"7.1.4", "L R C LFE Ls Rs Lrs Rrs Ltf Rtf Ltr Rtr"},
|
{"7.1.4", "L R C LFE Ls Rs Lrs Rrs Ltf Rtf Ltr Rtr"},
|
||||||
{"9.1.4", "L R C LFE Ls Rs Lrs Rrs Lw Rw Ltf Rtf Ltr Rtr"},
|
{"9.1.4", "L R C LFE Ls Rs Lrs Rrs Lw Rw Ltf Rtf Ltr Rtr"},
|
||||||
{"9.1.6", "L R C LFE Ls Rs Lrs Rrs Lw Rw Ltf Rtf Ltm Rtm Ltr Rtr"},
|
{"9.1.6", "L R C LFE Ls Rs Lrs Rrs Lw Rw Ltf Rtf Ltm Rtm Ltr Rtr"},
|
||||||
{"6.0", "L R Ls Rs Lrs Rrs"},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string join(const std::vector<std::string>& words) {
|
std::string join(const std::vector<std::string>& words) {
|
||||||
|
|||||||
Reference in new issue
Block a user