4 Commits
Author SHA1 Message Date
TheM14 8be8e895c0 Bump foo_input_joc to 0.6.3 and fix long PCM playback
build / windows (push) Canceled after 0s
build / release (push) Canceled after 0s
- Bump JOC_VERSION to 0.6.3.
- Give each PcmSource a unique temp WAV name (PID + serial + tick) so
  info, playback and next-track instances cannot overwrite or delete each
  other's decoded file.
- Cap read() at the decoded file length so the binaural room tail is not
  delivered as extra playback time.
- Reset the emitted-frame counter on seek.
2026-11-13 13:32:47 +08:00
TheM14 b52b384145 Bump component to 0.6.2 and add Dolby Dialnorm loudness control
build / windows (push) Canceled after 0s
build / release (push) Canceled after 0s
- Bump JOC_VERSION to 0.6.2.
- Add a "Dolby Dialnorm loudness (-31 dBFS)" preference switch.
- Persist the setting as dialnorm and allow JOC_DIALNORM to override it.
- Apply -target_level -31 only to the ffmpeg-decoded 5.1 E-AC-3 core; leave
  the 7-channel core and ordinary PCM takeover paths unchanged.
- Remove stale SOFA measurement-set wording from the READMEs.
- Rebuild and deploy both x86 and x64 components.
2026-11-12 14:53:32 +08:00
TheM14 b0751d82b6 Add ffmpeg PCM and non-JOC E-AC-3/TrueHD takeover
build / windows (push) Canceled after 0s
build / release (push) Canceled after 0s
- Add the take_over_pcm preference, persistence and input registration.
- Decode takeover sources with ffmpeg to 48 kHz float32 and feed the kernel
  PCM_LAYOUT stream for binaural output.
- Keep JOC priority: bare E-AC-3/EC3 and MP4/Matroska/WebM are probed first,
  then non-JOC audio falls back to ffmpeg.
- Cover AC3, DTS/DTS-HD, WavPack, APE, TTA, MPC, AU/SND/CAF and TrueHD/MLP;
  TrueHD in containers follows the same fallback.
- Sync the kernel to 1.3.3 with the virtual_speaker module and fix the PCM
  gain path.
- Update the preferences UI, HRTF hint and README.
2026-11-12 14:32:45 +08:00
TheM14 5c0f9ea2ff Sync the 1.3.1 kernel and read the stream until its first JOC frame
build / windows (push) Canceled after 0s
build / release (push) Canceled after 0s
The kernel copy follows JustOneCacophonyCXX 1.3.1: a frame without JOC metadata
mid-stream now holds the previous matrices instead of switching to the core
planes, which removes the clicks the 6.0 kernels produced on encoders that drop
the JOC metadata for single frames.

resolve_bed_channels() called ReadFile once and scanned that single chunk.  A
read returns only the bytes that are available (a pipe hands over a partial
chunk), and an encoder may leave the first audio frames without JOC metadata,
so the first JOC frame could sit past the window.  The scan then fell back to 6
bed channels, and the first JOC frame (joc_dmx_config_idx=1, 8 channels) was
rejected with core_channel_count_mismatch.  The scan now reads 64 KiB chunks
until the first syncframe carrying the JOC EMDF container is seen, keeps the
trailing partial frame between reads, and rewinds the stream as before; the
container path and the bare-file path both use it.

Bump the component version to 0.6.1, and pin the kernel notices to 1.3.1.

Verified with the offline harness: the reported GNR M4A now reports
"joc_dmx_config_idx=1 -> 8 bed channel(s)" and decodes the whole track (8906
frames), and the Smooth Criminal opening no longer steps at the two frames
without metadata (6.016 s and 7.328 s).
2026-11-10 15:35:32 +08:00
27 changed files with 1067 additions and 49 deletions

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ name: build
# 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
# renderer sources are part of this repository (kernel/, synced from JustOneCacophonyCXX
# commit abce8465f8edda3356738e1a1db7cb1b33191c72), so nothing else is needed.
# version 1.3.1), so nothing else is needed.
on:
push:
+4 -5
View File
@@ -96,8 +96,8 @@ HRTF 文件, 增益.
### HRTF data
A SOFA measurement set or a personalised headphone model is supplied by whoever runs the
component, and is listed in `.gitignore` so it cannot be committed by accident. Speaker layouts
A personalised headphone model (`HRTF\binaural.personalized_headphone`) is supplied by whoever
runs the 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.
## Speaker layouts and channel order
@@ -208,6 +208,5 @@ every container in the library, which is where the volume comes from.
## Licence
`LICENSE` is the upstream MIT licence, copied unchanged; `kernel/` is a copy of the upstream
rendering core sources, synced to JustOneCacophonyCXX commit
`abce8465f8edda3356738e1a1db7cb1b33191c72` (the `v1.2.0` tag points at an older commit and is not
the sync baseline), and keeps their notices. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
rendering core sources, synced to JustOneCacophonyCXX 1.3.1, and keeps their notices. See
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
+12 -3
View File
@@ -67,6 +67,15 @@ Preferences → Tools → **JOC 解码器**:
对调(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 的后两个槽位是天空声道,不会被误换。
它只改交付 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** 可执行文件路径。
* **界面语言** —— **跟随系统** / **简体中文** / **English**。设置页的全部文字、状态行和用户可见的
错误信息都用这一项选定的语言,切换后立刻生效;选择存在组件自己的配置里。"跟随系统"按 Windows 的
@@ -77,7 +86,7 @@ Preferences → Tools → **JOC 解码器**:
### HRTF 数据
SOFA 测量集或个性化耳机模型由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。
个性化耳机模型(`HRTF\binaural.personalized_headphone`)由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。
扬声器布局不需要 HRTF。双耳渲染缺少 HRTF 时会报错并指出它找的是哪个文件。
## 扬声器布局与声道顺序
@@ -162,6 +171,6 @@ pwsh -File tools/package.ps1 # 两个架构,打包到 dist\*.fb2k-c
## 许可
`LICENSE` 是上游 MIT 许可,原样复制;`kernel/` 是上游渲染内核源码的副本,同步自 JustOneCacophonyCXX 的提交
`abce8465f8edda3356738e1a1db7cb1b33191c72`(`v1.2.0` tag 指向更早的提交,不作为同步基准),保留其声明。见
`LICENSE` 是上游 MIT 许可,原样复制;`kernel/` 是上游渲染内核源码的副本,同步自 JustOneCacophonyCXX 的
1.3.1 版本,保留其声明。见
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
+1 -3
View File
@@ -5,9 +5,7 @@
(`kernel/src/joc_bitstream/joc_huffman_tables.h`)的公开标准来源,以及 HRTF 数据与
专利的边界说明。
`kernel/` 整体是 JustOneCacophonyCXX 在提交
`abce8465f8edda3356738e1a1db7cb1b33191c72`(版本号 1.3.0)的逐字副本;
`v1.2.0` tag 指向更早的提交 a276028,不作为同步基准。
`kernel/` 整体是 JustOneCacophonyCXX 1.3.1 的逐字副本。
## 公开标准来源
+3 -1
View File
@@ -80,7 +80,7 @@
-->
<PreprocessorDefinitions>NDEBUG;_WINDLL;WIN32_LEAN_AND_MEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;JOC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ForcedIncludeFiles>$(ProjectDir)src\joc_pch.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<AdditionalIncludeDirectories>$(ProjectDir)src;$(ProjectDir)SDK\foobar2000;$(ProjectDir)SDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)src;$(ProjectDir)kernel\include;$(ProjectDir)kernel\src;$(ProjectDir)SDK\foobar2000;$(ProjectDir)SDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4100;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
@@ -99,6 +99,7 @@
<ClCompile Include="src\eac3_scan.cpp" />
<ClCompile Include="src\input_joc.cpp" />
<ClCompile Include="src\joc_decode.cpp" />
<ClCompile Include="src\pcm_source.cpp" />
<ClCompile Include="src\lang.cpp" />
<ClCompile Include="src\log.cpp" />
<ClCompile Include="src\main.cpp" />
@@ -110,6 +111,7 @@
<ClInclude Include="src\container_scan.h" />
<ClInclude Include="src\eac3_scan.h" />
<ClInclude Include="src\joc_decode.h" />
<ClInclude Include="src\pcm_source.h" />
<ClInclude Include="src\joc_pch.h" />
<ClInclude Include="src\lang.h" />
<ClInclude Include="src\log.h" />
+4 -1
View File
@@ -40,7 +40,8 @@ typedef struct joc_stream joc_stream;
typedef enum joc_stream_input {
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_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;
typedef enum joc_stream_output {
@@ -68,6 +69,8 @@ typedef struct joc_stream_config {
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
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;
typedef struct joc_stream_buffer {
+2 -2
View File
@@ -10,7 +10,7 @@
#define JOC_VERSION_MAJOR 1
#define JOC_VERSION_MINOR 3
#define JOC_VERSION_PATCH 0
#define JOC_VERSION_STRING "1.3.0"
#define JOC_VERSION_PATCH 3
#define JOC_VERSION_STRING "1.3.3"
#endif /* JOC_VERSION_H */
+2 -1
View File
@@ -5,7 +5,7 @@
shipping and loading joc_core.dll.
The sources under kernel\src and kernel\include are a verbatim copy of the
upstream library at commit abce8465f8edda3356738e1a1db7cb1b33191c72 (see
upstream library at version 1.3.1 (see
JustOneCacophonyCXX\CMakeLists.txt): nothing under either
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
@@ -185,6 +185,7 @@
<ClCompile Include="src\speaker\speaker_step.cpp" />
<ClCompile Include="src\speaker\speaker_trim.cpp" />
<ClCompile Include="src\stream\stream.cpp" />
<ClCompile Include="src\virtual_speaker\virtual_speaker.cpp" />
<ClCompile Include="src\task\task.cpp" />
<ClCompile Include="src\telemetry\event_bus.cpp" />
<ClCompile Include="src\timeline\position_timeline.cpp" />
+14
View File
@@ -46,6 +46,7 @@ joc::stream::Config to_config(const joc_stream_config& config) {
if (config.rosella_filterbank != 0u) {
out.rosella_filterbank = config.rosella_filterbank;
}
if (config.pcm_layout != nullptr) { out.pcm_layout = config.pcm_layout; }
return out;
}
@@ -95,6 +96,19 @@ joc_error JOC_CALL joc_stream_push(joc_stream* stream, const joc_stream_buffer*
}
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;
const std::uint32_t channels = input->channels != 0u ? input->channels : 6u;
const joc::Status pushed =
+27 -1
View File
@@ -800,9 +800,35 @@ private:
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) {
return FrameMode::Passthrough;
// 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;
+67 -6
View File
@@ -6,6 +6,7 @@
#include "adm/adm_metadata.h"
#include "foundation/status.h"
#include "virtual_speaker/virtual_speaker.h"
#include "hrtf/jochrtf.h"
#include "hrtf/rosella_model.h"
#include "joc_bitstream/bed_layout_map.h"
@@ -45,6 +46,7 @@ void Stream::reset_state() {
bed_pending_.clear();
bed_read_offset_ = 0;
objects16_.clear();
pcm_input_.reset();
objects_pending_.clear();
objects_read_offset_ = 0;
output_.clear();
@@ -77,7 +79,7 @@ Status Stream::create(const Config& config) {
return Status::fail(JOC_ERR_STATE, stage::kRender, "stream already created");
}
config_ = config;
if (config_.input > JOC_STREAM_IN_PCM_OBJECTS16 ||
if (config_.input > JOC_STREAM_IN_PCM_LAYOUT ||
config_.output > JOC_STREAM_OUT_BINAURAL) {
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender, "unknown stream kind");
}
@@ -87,6 +89,20 @@ Status Stream::create(const Config& config) {
"objects16 input with objects16 output would do nothing");
}
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) {
rebuilder_ = ejoc_renderer_create();
@@ -453,6 +469,47 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
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) {
constexpr std::size_t kFrameValues =
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * kFrameSamples;
@@ -590,9 +647,11 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
if (speaker_enabled_) {
std::string error;
const Status stepped =
speaker::step(&speaker_, objects16, pending_metadata_.has_update
? &pending_metadata_.update
: nullptr,
speaker::step(&speaker_, objects16,
pending_metadata_.has_update
? &pending_metadata_.update
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update()
: nullptr),
&error);
if (!stepped.ok()) {
return Status::fail(stepped.code(), stage::kRender, error);
@@ -611,7 +670,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
const Status submitted =
binaural_.submit_frame(objects16.data(),
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
pending_metadata_.has_update ? &pending_metadata_.update
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
static_cast<std::int64_t>(info_.frames_out),
pending_metadata_.outer_offset,
static_cast<std::int64_t>(config_.object_delay_samples));
@@ -638,7 +698,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
Status Stream::render_rosella_objects16(const std::vector<float>& objects16) {
const Status submitted =
rosella_.submit_frame(objects16.data(),
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
pending_metadata_.has_update ? &pending_metadata_.update
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
static_cast<std::int64_t>(info_.frames_out),
pending_metadata_.outer_offset,
static_cast<std::int64_t>(config_.object_delay_samples));
+7
View File
@@ -15,6 +15,7 @@
#include "joc_stream.h"
#include "oamd/oamd_parser.h"
#include "speaker/speaker_step.h"
#include "virtual_speaker/virtual_speaker.h"
namespace joc::stream {
@@ -34,6 +35,7 @@ struct Config {
// (.jochrtf).
std::string personalized_headphone_path;
std::uint32_t jochrtf_room = 1;
std::string pcm_layout;
// Filterbank of the Rosella path; the other binaural inputs ignore it.
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
};
@@ -99,6 +101,8 @@ public:
Status push_bed(const float* interleaved, std::size_t samples, std::uint32_t channels,
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 flush();
Status reset();
@@ -160,6 +164,9 @@ private:
std::size_t bed_read_offset_ = 0;
std::vector<float> bed5_;
std::vector<float> lfe_;
virtual_speaker::Input pcm_input_;
oamd::OamdUpdate fixed_update_{};
bool has_fixed_update_ = false;
std::vector<float> objects_pending_;
std::size_t objects_read_offset_ = 0;
std::vector<float> objects_frame_;
@@ -0,0 +1,161 @@
#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
@@ -0,0 +1,57 @@
// 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
+159 -9
View File
@@ -27,6 +27,7 @@
#include "eac3_scan.h"
#include "joc_decode.h"
#include "log.h"
#include "pcm_source.h"
#include "prefs.h"
#include "settings.h"
@@ -36,6 +37,22 @@ constexpr std::size_t kSniffBytes = 256u * 1024u;
constexpr std::size_t kRunFrames = 4096u;
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().
template <typename Sample>
double peak_of(const Sample* values, std::size_t count) {
@@ -253,11 +270,21 @@ public:
const char* extension = std::strrchr(m_native_path.get_ptr(), '.');
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)) {
open_container(extension);
open_container(extension, abort);
} else {
open_bare(abort);
}
if (m_pcm_mode) return;
// 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
@@ -271,10 +298,49 @@ 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
// 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,
// 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) {
m_stream_start = leading_tag_bytes(m_file, abort);
if (m_stream_start != 0) {
@@ -293,9 +359,8 @@ public:
static_cast<unsigned long long>(scan.frames_with_joc));
if (scan.joc != joc_eac3::JocState::kYes) {
// Hand the file to the next entry in the priority table.
decline("decoder: yielding to the built-in decoder (%s)", scan.detail);
throw exception_io_unsupported_format();
open_pcm_fallback(abort, 0, scan.detail);
return;
}
joc_log::line("decoder: claiming this file as E-AC-3 JOC (bare stream)");
g_claimed.fetch_add(1, std::memory_order_relaxed);
@@ -306,9 +371,15 @@ public:
// 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
// the track). Either "no" hands the file to the next decoder in the table.
void open_container(const char* extension) {
void open_container(const char* extension, abort_callback& abort) {
m_container = joc_container::scan(m_native_path.get_ptr());
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)",
m_container.detail.c_str());
throw exception_io_unsupported_format();
@@ -319,14 +390,16 @@ public:
std::string detail;
if (!joc_decode::probe_container_joc(settings.ffmpeg_path, m_native_path.get_ptr(),
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());
throw exception_io_unsupported_format();
}
if (!joc) {
decline("decoder: yielding to the built-in decoder (E-AC-3 track %u carries "
"no JOC: %s)",
m_container.audio_index, detail.c_str());
throw exception_io_unsupported_format();
open_pcm_fallback(abort, m_container.audio_index, detail.c_str());
return;
}
joc_log::line("decoder: claiming this file as E-AC-3 JOC (%s, audio track %u, .%s)",
@@ -348,6 +421,32 @@ public:
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 =
joc_decode::probe_file(m_native_path.get_ptr(), 0, m_stream_start);
const joc_decode::Settings settings = joc_settings::current();
@@ -462,6 +561,19 @@ public:
void decode_initialize(unsigned flags, abort_callback& 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.input_kind = m_input_kind;
m_settings.audio_index = m_audio_index;
@@ -521,6 +633,26 @@ public:
bool decode_run(audio_chunk& chunk, abort_callback& abort) {
(void)abort;
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);
if (frames == 0) {
if (!error.empty()) {
@@ -606,6 +738,19 @@ public:
void decode_seek(double seconds, abort_callback& abort) {
// Walking the syncframe index of a long file is the only part of a seek
// 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(); });
std::string error;
const bool ok = m_engine.seek(seconds, m_length, &error);
@@ -671,6 +816,9 @@ public:
// track is commonly wrapped in MP4 or Matroska; the container walk in
// open() is what keeps the other files cheap to decline.
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) &&
((stricmp_utf8(extension, "eac3") == 0) || (stricmp_utf8(extension, "ec3") == 0));
}
@@ -700,6 +848,8 @@ private:
pfc::string8 m_native_path;
joc_decode::Settings m_settings;
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
// container is extracted by ffmpeg before it reaches the renderer.
joc_decode::InputKind m_input_kind = joc_decode::InputKind::kBare;
+56 -5
View File
@@ -41,6 +41,11 @@ constexpr std::size_t kMaxBedChannels = 8;
// can ever hold.
constexpr std::size_t kBedReadBytes = 48u * 1024u;
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;
// The decoded bed has to stay on the E-AC-3 frame grid that the JOC matrix and the
@@ -93,6 +98,45 @@ bool seven_channel_config(int config) {
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.
//
@@ -866,22 +910,23 @@ bool Engine::Impl::position_bare(std::uint64_t frame, std::string* error) {
bool Engine::Impl::resolve_bed_channels(std::string* error) {
bed_channels = kDefaultBedChannels;
std::vector<std::uint8_t> buffer(1u << 20);
int config = -1;
if (eac3_from_pipe) {
// 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.
if (!start_metadata(error)) return false;
const std::size_t got = eac3_pipe.read(buffer.data(), buffer.size());
config = scan_config_idx_streaming(
[this](void* data, std::size_t bytes) { return eac3_pipe.read(data, bytes); },
kScanChunkBytes);
eac3_pipe.stop();
config = scan_config_idx(buffer.data(), got);
} else {
if (!eac3.is_open() && !eac3.open(input_path)) {
if (error != nullptr) *error = "cannot open the input file";
return false;
}
const std::size_t got = eac3.read(buffer.data(), buffer.size());
config = scan_config_idx(buffer.data(), got);
config = scan_config_idx_streaming(
[this](void* data, std::size_t bytes) { return eac3.read(data, bytes); },
kScanChunkBytes);
// Put the file back where the feed loop expects it.
if (!eac3.seek(index_base)) {
if (error != nullptr) *error = "cannot position the input file";
@@ -902,6 +947,8 @@ 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.
// -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.
// 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
// into 5.1 and drops the extra pair, and `-ac 8` would remap 5.1.2 into 7.1.
@@ -913,6 +960,10 @@ 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
// play-through rather than a misalignment: the position stays exact.
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";
const std::wstring offset = seek_time(source_sample);
if (!offset.empty()) input_arguments += L" -ss " + offset;
+4
View File
@@ -95,6 +95,10 @@ struct Settings {
// 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.
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 ------------------------------------------------------
+6 -3
View File
@@ -30,6 +30,7 @@ constexpr Entry kTexts[] = {
{Text::kComboModeFar, "far(远场)", "far"},
{Text::kLabelTail, "房间尾音(秒)", "Room tail (s)"},
{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::kSpeakerStatus, "扬声器布局 %s", "Speaker layout %s"},
{Text::kGroupHrtf, "HRTF", "HRTF"},
@@ -38,16 +39,18 @@ constexpr Entry kTexts[] = {
{Text::kLabelHrtfFile, "HRTF 文件", "HRTF file"},
{Text::kButtonBrowse, "浏览…", "Browse…"},
{Text::kHrtfHint,
"留空时读组件目录下 HRTF\\binaural.sofa 或 HRTF\\binaural.personalized_headphone。",
"Empty means HRTF\\binaural.sofa or binaural.personalized_headphone next to "
"留空时读组件目录下 HRTF\\binaural.personalized_headphone(Rosella 模型)。",
"Empty means HRTF\\binaural.personalized_headphone (Rosella model) next to "
"the component."},
{Text::kHrtfSourceSofa, "SOFA", "SOFA"},
{Text::kHrtfSourceRosella, "Rosella 个性化模型", "Rosella personalized model"},
{Text::kHrtfDefault, "默认", "default"},
{Text::kHrtfDefaultUnknown, "无法确定默认路径",
"cannot resolve the default location"},
{Text::kGroupGain, "增益", "Gain"},
{Text::kGroupGain, "增益 / 响度", "Gain / loudness"},
{Text::kCheckGain, "应用增益", "Apply gain"},
{Text::kCheckDialnorm, "Dolby Dialnorm 响度均衡(-31 dBFS)",
"Dolby Dialnorm loudness (-31 dBFS)"},
{Text::kLabelGainUnit, "dB", "dB"},
{Text::kGainStatusOn, "增益开 %.2f dB", "gain on, %.2f dB"},
{Text::kGainStatusOff, "增益关(输出不衰减)", "gain off (no attenuation)"},
+2
View File
@@ -31,6 +31,7 @@ enum class Text {
kComboModeFar,
kLabelTail,
kCheckInt24,
kCheckPcm,
kInt24Hint,
kSpeakerStatus,
kGroupHrtf,
@@ -45,6 +46,7 @@ enum class Text {
kHrtfDefaultUnknown,
kGroupGain,
kCheckGain,
kCheckDialnorm,
kLabelGainUnit,
kGainStatusOn,
kGainStatusOff,
+1 -1
View File
@@ -14,7 +14,7 @@
// Kept in one place: the string reported to foobar2000 and written to the log
// must not drift apart.
#define JOC_VERSION "0.6.0"
#define JOC_VERSION "0.6.3"
DECLARE_COMPONENT_VERSION("JOC decoder (E-AC-3 JOC)", JOC_VERSION,
"Plays E-AC-3 JOC (Dolby Atmos) files: the JOC objects are "
+371
View File
@@ -0,0 +1,371 @@
#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
+69
View File
@@ -0,0 +1,69 @@
// 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
+15 -4
View File
@@ -285,7 +285,8 @@ private:
return TRUE;
}
if (id == IDC_CHECK_GAIN || id == IDC_CHECK_INT24 ||
id == IDC_CHECK_SWAP_SIDE_REAR) {
id == IDC_CHECK_SWAP_SIDE_REAR || id == IDC_CHECK_PCM ||
id == IDC_CHECK_DIALNORM) {
update_status();
notify();
return TRUE;
@@ -369,7 +370,7 @@ private:
label(IDC_LABEL_TAIL, joc_lang::Text::kLabelTail);
label(IDC_CHECK_INT24, joc_lang::Text::kCheckInt24);
label(IDC_CHECK_SWAP_SIDE_REAR, joc_lang::Text::kCheckSwapSideRear);
label(IDC_LABEL_INT24_HINT, joc_lang::Text::kInt24Hint);
label(IDC_CHECK_PCM, joc_lang::Text::kCheckPcm);
label(IDC_GROUP_HRTF, joc_lang::Text::kGroupHrtf);
label(IDC_RADIO_HRTF_ROSELLA, joc_lang::Text::kRadioRosella);
label(IDC_LABEL_HRTF, joc_lang::Text::kLabelHrtfFile);
@@ -378,7 +379,7 @@ private:
label(IDC_GROUP_GAIN, joc_lang::Text::kGroupGain);
label(IDC_CHECK_GAIN, joc_lang::Text::kCheckGain);
label(IDC_LABEL_GAIN, joc_lang::Text::kLabelGainUnit);
label(IDC_LABEL_GAIN_HINT, joc_lang::Text::kGainHint);
label(IDC_CHECK_DIALNORM, joc_lang::Text::kCheckDialnorm);
label(IDC_GROUP_MISC, joc_lang::Text::kGroupOther);
label(IDC_LABEL_LANGUAGE, joc_lang::Text::kLabelLanguage);
label(IDC_LABEL_FFMPEG, joc_lang::Text::kLabelFfmpeg);
@@ -406,9 +407,13 @@ private:
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_GAIN), BM_SETCHECK,
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,
values.force_int24 ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_SWAP_SIDE_REAR), BM_SETCHECK,
SendMessageW(GetDlgItem(m_hwnd, IDC_CHECK_PCM), 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);
// The item lists are language-dependent, so they are built (in the stored
@@ -459,10 +464,14 @@ private:
values.gain_db = std::atof(get_text(GetDlgItem(m_hwnd, IDC_EDIT_GAIN)).c_str());
values.gain_enabled =
IsDlgButtonChecked(m_hwnd, IDC_CHECK_GAIN) == BST_CHECKED;
values.dialnorm =
IsDlgButtonChecked(m_hwnd, IDC_CHECK_DIALNORM) == BST_CHECKED;
values.force_int24 =
IsDlgButtonChecked(m_hwnd, IDC_CHECK_INT24) == BST_CHECKED;
values.swap_side_rear =
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();
// Advanced values are not on this page; keep whatever is stored.
const joc_settings::Values stored = joc_settings::read();
@@ -524,8 +533,10 @@ private:
if (now.hrtf_file != m_initial.hrtf_file) return true;
if (now.binaural_mode != m_initial.binaural_mode) 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.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.tail_seconds != m_initial.tail_seconds) return true;
if (now.ffmpeg_path != m_initial.ffmpeg_path) return true;
+4 -3
View File
@@ -36,7 +36,8 @@ BEGIN
LTEXT "", IDC_LABEL_OUTPUT_STATUS, 16, 53, 300, 10
CONTROL "强制 24bit 输出(int24)", IDC_CHECK_INT24, "Button",
BS_AUTOCHECKBOX | WS_TABSTOP, 16, 65, 156, 10
LTEXT "切换后需刷新文件信息", IDC_LABEL_INT24_HINT, 176, 65, 136, 10
CONTROL "接管普通 PCM 源(ffmpeg 解码)", IDC_CHECK_PCM, "Button",
BS_AUTOCHECKBOX | WS_TABSTOP, 176, 65, 140, 10
GROUPBOX "HRTF", IDC_GROUP_HRTF, 7, 79, 316, 92
LTEXT "Rosella 个性化模型", IDC_RADIO_HRTF_ROSELLA, 16, 91, 146, 10
@@ -53,8 +54,8 @@ BEGIN
LTEXT "dB", IDC_LABEL_GAIN, 68, 187, 12, 10
EDITTEXT IDC_EDIT_GAIN, 84, 184, 44, 13, ES_AUTOHSCROLL
LTEXT "", IDC_LABEL_GAIN_STATUS, 134, 187, 182, 10
LTEXT "双耳渲染后可能超过 0 dBFS,可用负值衰减。",
IDC_LABEL_GAIN_HINT, 16, 202, 300, 10
CONTROL "Dolby Dialnorm 响度均衡(-31 dBFS)", IDC_CHECK_DIALNORM, "Button",
BS_AUTOCHECKBOX | WS_TABSTOP, 16, 202, 300, 10
GROUPBOX "其它", IDC_GROUP_MISC, 7, 219, 316, 48
CONTROL "交换侧环绕与后环绕声道", IDC_CHECK_SWAP_SIDE_REAR, "Button",
+2
View File
@@ -14,6 +14,7 @@
#define IDC_LABEL_OUTPUT_STATUS 2019
// Delivery format, in the same group: what the decoder hands to foobar2000.
#define IDC_CHECK_INT24 2050
#define IDC_CHECK_PCM 2052
#define IDC_LABEL_INT24_HINT 2051
#define IDC_GROUP_HRTF 2020
@@ -31,6 +32,7 @@
#define IDC_EDIT_GAIN 2033
#define IDC_LABEL_GAIN_HINT 2034
#define IDC_LABEL_GAIN_STATUS 2035
#define IDC_CHECK_DIALNORM 2036
#define IDC_GROUP_MISC 2040
#define IDC_LABEL_FFMPEG 2041
+12
View File
@@ -30,6 +30,8 @@ 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 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 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 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}};
@@ -48,6 +50,8 @@ cfg_uint g_tail_ms(kGuidTail, 5000);
cfg_bool g_force_int24(kGuidForceInt24, false);
// Swap the side and rear surround pairs in the delivered PCM.
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_threads(kGuidThreads, 0);
cfg_string g_ffmpeg(kGuidFfmpeg, "ffmpeg");
@@ -128,6 +132,8 @@ Values read() {
values.tail_seconds = static_cast<double>(static_cast<unsigned>(g_tail_ms)) / 1000.0;
values.force_int24 = static_cast<bool>(g_force_int24);
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.native_threads = static_cast<unsigned>(g_threads);
values.ffmpeg_path = g_ffmpeg.get_ptr();
@@ -158,6 +164,8 @@ void write(const Values& values) {
g_tail_ms = static_cast<unsigned>(values.tail_seconds * 1000.0 + 0.5);
g_force_int24 = values.force_int24;
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_threads = values.native_threads;
g_ffmpeg = values.ffmpeg_path.c_str();
@@ -180,6 +188,8 @@ joc_decode::Settings current() {
(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_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_THREADS", &values.native_threads);
@@ -196,6 +206,8 @@ joc_decode::Settings current() {
settings.tail_seconds = values.tail_seconds;
settings.force_int24 = values.force_int24;
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.native_threads = values.native_threads;
settings.ffmpeg_path = values.ffmpeg_path.empty() ? "ffmpeg" : values.ffmpeg_path;
+4
View File
@@ -36,6 +36,10 @@ struct Values {
// Swap Ls with Lrs and Rs with Rrs in the delivered speaker PCM; a layout
// without both pairs is delivered unchanged.
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 native_threads = 0;
std::string ffmpeg_path = "ffmpeg";