From ecf14d8c3218210a1413a8967ef7deb686fe737f Mon Sep 17 00:00:00 2001 From: TheM14 Date: Sat, 31 Oct 2026 02:29:23 +0800 Subject: [PATCH] Sync the Rosella filterbank choice into the plugin and the fork The kernel can now render the Rosella path through either bank; expose that choice in both front ends with the same values and the same default. - plugin: joc-rosella-filterbank = 1|2 (public|captured); unset means the kernel default (the public bank), and it applies only to joc-hrtf-source=rosella, logging a warning otherwise - fork: --ad-joc-rosella-filterbank, the same values and default; it sits in the ad_joc option group, so it is read only when ad_joc decodes a Rosella model - log the bank actually selected (public|captured) on both paths - add a bank-2 case to tools/verify_parity.ps1 - document the key in both READMEs and the example config Checked: the plugin builds, the option parser covers the numeric and named spellings plus invalid values, and for both banks the plugin's PCM is bit-identical to joc_cli with --rosella-filterbank 1|2. --- README.en.md | 1 + README.md | 1 + config/cplugin-mpv.conf.example | 4 ++++ fork/README.md | 6 ++++++ fork/files/audio/decode/ad_joc.c | 13 +++++++++++++ fork/files/audio/decode/ad_joc.h | 1 + src/cplugin_main.cpp | 8 ++++++++ src/joc_decode.cpp | 7 +++++++ src/joc_decode.h | 3 +++ src/plugin/config.cpp | 8 ++++++++ src/plugin/config.h | 3 +++ tools/verify_parity.ps1 | 9 +++++++++ 12 files changed, 64 insertions(+) diff --git a/README.en.md b/README.en.md index 35c8ccc..07d3f68 100644 --- a/README.en.md +++ b/README.en.md @@ -86,6 +86,7 @@ ignored and reported in `joc_decoder.log`. | `joc-output` | binaural / speaker | binaural | output form | | `joc-layout` | 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 | 7.1 | speaker layout; used only with `speaker` | | `joc-hrtf-source` | sofa / rosella | sofa | binaural HRTF input | +| `joc-rosella-filterbank` | 1 / 2 (or public / captured) | 1 | Rosella filterbank: 1 = the public 13-tap / 6-slot bank, 2 = the captured 11-tap / 3-slot bank that matches the reference renderer; only read with `joc-hrtf-source=rosella` | | `joc-hrtf` | path | empty | empty: default name under `\\HRTF\\` or `\\..\\HRTF\\` | | `joc-mode` | near / mid / far | mid | binaural mode | | `joc-gain-db` | float (dB) | 0 | render gain (binaural can exceed full scale) | diff --git a/README.md b/README.md index b6a1ae1..81595b7 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ mpv --script="C:\\path\\to\\joc_mpv.dll" --script-opts=joc-output=speaker,joc-la | `joc-output` | binaural / speaker | binaural | 输出形式 | | `joc-layout` | 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 | 7.1 | 扬声器布局;仅 `speaker` 使用 | | `joc-hrtf-source` | sofa / rosella | sofa | 双耳用哪种 HRTF 输入 | +| `joc-rosella-filterbank` | 1 / 2(或 public / captured) | 1 | Rosella 滤波器组:1=13 taps/6 slots 的公开版,2=11 taps/3 slots 的捕获版(与参考渲染器一致);仅 `joc-hrtf-source=rosella` 使用 | | `joc-hrtf` | 路径 | 空 | 空则用 `<插件目录>\\HRTF\\` 或 `<插件目录>\\..\\HRTF\\` 下的默认文件名 | | `joc-mode` | near / mid / far | mid | 双耳模式 | | `joc-gain-db` | 浮点(dB) | 0 | 渲染增益;双耳可能超过满刻度,需要时在这里衰减 | diff --git a/config/cplugin-mpv.conf.example b/config/cplugin-mpv.conf.example index 2cbc588..94b7b22 100644 --- a/config/cplugin-mpv.conf.example +++ b/config/cplugin-mpv.conf.example @@ -18,6 +18,10 @@ script-opts=joc-output=binaural,joc-hrtf-source=sofa,joc-mode=mid,joc-gain-db=0 # 指定 HRTF 文件(默认找 \HRTF\binaural.sofa): # script-opts-append=joc-hrtf=D:/hrtf/MyMeasurements.sofa # +# Rosella 模型用捕获版滤波器组(与参考渲染器一致;默认 1 = 公开版): +# script-opts-append=joc-hrtf-source=rosella +# script-opts-append=joc-rosella-filterbank=2 +# # 交付 24bit 定点: # script-opts-append=joc-int24=yes # diff --git a/fork/README.md b/fork/README.md index 6556084..b09635a 100644 --- a/fork/README.md +++ b/fork/README.md @@ -129,6 +129,7 @@ ad-joc-binaural = yes # 默认就是 yes(双声道输出) ad-joc-hrtf = C:/HRTF/binaural.sofa # 可省:会自动找 ad-joc-layout = 7.1 # 仅 binaural=no 时使用 ad-joc-mode = mid +ad-joc-rosella-filterbank = 1 # Rosella 输入:1=公开版(默认),2=捕获版 ad-joc-gain-db = 0 ``` @@ -140,9 +141,14 @@ ad-joc-gain-db = 0 | `--ad-joc-hrtf` | SOFA / Rosella / `.jochrtf` 路径 | 空(自动搜索) | | `--ad-joc-layout` | `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`| 7.1 | | `--ad-joc-mode` | near / far / mid | mid | +| `--ad-joc-rosella-filterbank` | 1 / 2(或 public / captured) | 1(公开版) | | `--ad-joc-gain-db` | -60 … 12 | 0 | | `--ad-joc-int24` | yes / no | no | +`--ad-joc-rosella-filterbank=2` 只在 `--ad-joc-hrtf` 指向 `.personalized_headphone` 时生效: +`1` 是 13 taps / 6 slots 的公开滤波器组,`2` 是 11 taps / 3 slots 的捕获版(与参考渲染器 +一致、延迟 448 samples)。SOFA 与 `.jochrtf` 输入忽略该选项并给一条 warning。 + `--ad-joc-int24` 把输出量化到渲染器的 24-bit 规则(与上游前端的 int24 交付一致): clip 到 [-1,1]、乘 8388607、向零截断、取低 24 位,再按 `n / 2^23` 读回。默认关闭, 输出就是渲染器的 float32。 diff --git a/fork/files/audio/decode/ad_joc.c b/fork/files/audio/decode/ad_joc.c index 95bd1a8..e29f318 100644 --- a/fork/files/audio/decode/ad_joc.c +++ b/fork/files/audio/decode/ad_joc.c @@ -66,6 +66,9 @@ const struct m_sub_options ad_joc_conf = { {"layout", OPT_STRING(layout), .flags = M_OPT_FILE}, {"mode", OPT_CHOICE(binaural_mode, {"near", 1}, {"far", 2}, {"mid", 3})}, + {"rosella-filterbank", OPT_CHOICE(rosella_filterbank, + {"1", 1}, {"public", 1}, + {"2", 2}, {"captured", 2})}, {"gain-db", OPT_DOUBLE(gain_db), M_RANGE(-60.0, 12.0)}, {"int24", OPT_BOOL(int24)}, {0} @@ -77,6 +80,7 @@ const struct m_sub_options ad_joc_conf = { .hrtf = "", .layout = "7.1", .binaural_mode = 3, + .rosella_filterbank = 0, .gain_db = 0.0, }, }; @@ -790,6 +794,15 @@ static struct mp_decoder *create(struct mp_filter *parent, cfg.input = JOC_STREAM_IN_EAC3; cfg.output = binaural ? JOC_STREAM_OUT_BINAURAL : JOC_STREAM_OUT_SPEAKER; cfg.binaural_mode = (uint32_t)opts->binaural_mode; + /* 0 is the kernel's default (the public bank); a SOFA or .jochrtf input + * ignores the field, so say so instead of leaving the option a no-op. */ + cfg.rosella_filterbank = (uint32_t)opts->rosella_filterbank; + if (binaural && hrtf_kind != HRTF_ROSELLA && opts->rosella_filterbank != 0) + MP_WARN(da, "--ad-joc-rosella-filterbank only applies to a Rosella " + "(.personalized_headphone) HRTF; ignoring it\n"); + if (binaural && hrtf_kind == HRTF_ROSELLA) + MP_VERBOSE(da, "rosella filterbank: %s\n", + opts->rosella_filterbank == 2 ? "captured" : "public"); cfg.gain_db = opts->gain_db; cfg.object_delay_samples = 1473; if (binaural) { diff --git a/fork/files/audio/decode/ad_joc.h b/fork/files/audio/decode/ad_joc.h index f0582c7..da69d81 100644 --- a/fork/files/audio/decode/ad_joc.h +++ b/fork/files/audio/decode/ad_joc.h @@ -21,6 +21,7 @@ struct ad_joc_params { char *layout; /* speaker layout name, e.g. "7.1" or "9.1.6" */ bool int24; /* quantise the output to the renderer's int24 rule */ int binaural_mode; /* JOC_BINAURAL_NEAR(1) / FAR(2) / MID(3) */ + int rosella_filterbank; /* Rosella filterbank: 0 default (public), 2 captured */ double gain_db; }; diff --git a/src/cplugin_main.cpp b/src/cplugin_main.cpp index 8cb433a..46e55ef 100644 --- a/src/cplugin_main.cpp +++ b/src/cplugin_main.cpp @@ -317,6 +317,14 @@ struct Plugin { settings.speaker_layout = config.layout; settings.hrtf_source = (config.hrtf_source == 0) ? joc_decode::HrtfSource::kSofa : joc_decode::HrtfSource::kRosella; + settings.rosella_filterbank = + static_cast(config.rosella_filterbank); + if (config.rosella_filterbank != 0 && + settings.hrtf_source != joc_decode::HrtfSource::kRosella) { + joc_log::line("config: joc-rosella-filterbank=%d ignored: it applies to " + "joc-hrtf-source=rosella only", + config.rosella_filterbank); + } settings.hrtf_file = config.hrtf_file; if (settings.hrtf_file.empty() && settings.output == joc_decode::Output::kBinaural) { settings.hrtf_file = default_hrtf_file(config); diff --git a/src/joc_decode.cpp b/src/joc_decode.cpp index 724b61f..e93b52f 100644 --- a/src/joc_decode.cpp +++ b/src/joc_decode.cpp @@ -1025,6 +1025,8 @@ bool Engine::start(const std::string& input_path, const Settings& settings, std: config.speaker_layout_name = settings.speaker_layout.c_str(); config.speaker_metadata_offset = 0; config.binaural_mode = settings.binaural_mode; + // 0 selects the kernel's default (the public bank); the SOFA path ignores it. + config.rosella_filterbank = settings.rosella_filterbank; // The filter bank tables live in the library (hrtf::builtin_kernels in // kernel_tables.cpp), so there is no table path to configure and none is // passed: the field stays null. The same goes for the compiled-HRTF cache: @@ -1087,6 +1089,11 @@ bool Engine::start(const std::string& input_path, const Settings& settings, std: joc_log::line("core: stream created, %u output channel(s), layout=%s, hrtf=%s", impl.channels, settings.speaker_layout.c_str(), hrtf_in_use.empty() ? "(none)" : hrtf_in_use.c_str()); + if (settings.output == Output::kBinaural && + settings.hrtf_source == HrtfSource::kRosella) { + joc_log::line("core: rosella filterbank=%s", + settings.rosella_filterbank == 2u ? "captured" : "public"); + } // ffmpeg's stderr lands next to the component rather than in whatever working // directory the host process happens to have. The two children write separate diff --git a/src/joc_decode.h b/src/joc_decode.h index 6bfd19b..0266b92 100644 --- a/src/joc_decode.h +++ b/src/joc_decode.h @@ -65,6 +65,9 @@ struct Settings { unsigned audio_index = 0; std::string speaker_layout = "7.1"; HrtfSource hrtf_source = HrtfSource::kSofa; + // Filterbank of the Rosella path: 0 = the renderer's default (public bank), + // 2 = the captured bank. Only the Rosella input reads it. + std::uint32_t rosella_filterbank = 0; // Empty means the default file in the default folder, see resolve_hrtf_file(). std::string hrtf_file; std::string hrtf_cache_dir; // SOFA compile cache (disk policy) diff --git a/src/plugin/config.cpp b/src/plugin/config.cpp index bef822a..1edfdf1 100644 --- a/src/plugin/config.cpp +++ b/src/plugin/config.cpp @@ -91,6 +91,14 @@ Config parse_config(const std::string& script_opts, std::string* warnings) { } else { unsupported(key + "=" + value); } + } else if (key == "joc-rosella-filterbank") { + if (value == "1" || value == "public") { + config.rosella_filterbank = 1; + } else if (value == "2" || value == "captured") { + config.rosella_filterbank = 2; + } else { + unsupported(key + "=" + value); + } } else if (key == "joc-hrtf") { config.hrtf_file = value; } else if (key == "joc-mode") { diff --git a/src/plugin/config.h b/src/plugin/config.h index 67bad3c..88327b0 100644 --- a/src/plugin/config.h +++ b/src/plugin/config.h @@ -13,6 +13,9 @@ struct Config { std::string layout = "7.1"; // 0 = SOFA, 1 = Rosella personalized headphone model. int hrtf_source = 0; + // Rosella filterbank: 0 = the renderer's default (public bank), 2 = captured. + // Only the Rosella input reads it; the SOFA and .jochrtf paths ignore it. + int rosella_filterbank = 0; std::string hrtf_file; // empty: \\HRTF\\binaural. // 1 = near, 2 = far, 3 = mid (the renderer's own default). int binaural_mode = 3; diff --git a/tools/verify_parity.ps1 b/tools/verify_parity.ps1 index 640220d..8a68c40 100644 --- a/tools/verify_parity.ps1 +++ b/tools/verify_parity.ps1 @@ -61,6 +61,15 @@ if ($Rosella -ne "") { Invoke-Capture "joc-int24=yes,joc-hrtf-source=rosella,joc-hrtf=$Rosella" $actual & $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference if ($LASTEXITCODE -ne 0) { $failures++ } + + Write-Output "=== binaural float32 (Rosella, captured filterbank) ===" + $reference = Join-Path $WorkDir "reference.binaural.bank2.f32.wav" + $actual = Join-Path $WorkDir "plugin.binaural.bank2.f32.wav" + & $JocCli $Media --binaural --personalized-headphone $Rosella ` + --rosella-filterbank 2 --binaural-format float32 --binaural-output $reference | Out-Null + Invoke-Capture "joc-hrtf-source=rosella,joc-hrtf=$Rosella,joc-rosella-filterbank=2" $actual + & $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference + if ($LASTEXITCODE -ne 0) { $failures++ } } foreach ($layout in @("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")) {