Compile the fork decoder against the kernel that takes one HRTF input

ad_joc.c still asked the stream config for hrtf_sofa_path, hrtf_cache_dir and
hrtf_cache_policy, which the kernel no longer has; the same file is compiled by
the Windows and the Android build, so both stopped there.

The decoder now recognises only the Rosella model -- a JSON file containing a
personalized_hrtf object -- and passes its path to personalized_headphone_path.
The SOFA magic sniffing, the .jochrtf extension branch, the default cache
directory and the disk-cache retry path are gone, the default lookup is
HRTF/binaural.personalized_headphone, and the format warning for the frame length
uses %zu. The README, the fork docs and the example configs name the model file
instead of binaural.sofa.
This commit is contained in:
TheM14 committed 2026-11-01 19:59:08 +08:00
1 parent 19b4a49407
commit a2471ce502
8 files changed
+26 -83

No files matched your search

+2 -2
View File
@@ -55,7 +55,7 @@ One renderer (`joc_core.dll`), two integration shapes:
```text
<mpv>\\scripts\\joc_mpv.dll the plugin
<mpv>\\joc_core.dll the renderer (same binary as JustOneCacophonyCXX)
<mpv>\\HRTF\\binaural.sofa default binaural data
<mpv>\\HRTF\\binaural.personalized_headphone default binaural data
<mpv>\\HRTF\\binaural.personalized_headphone (Rosella model, either one)
```
@@ -250,7 +250,7 @@ because mpv would try to load it as a script. `--msg-level=all=info` shows the
* **No JOC message, just plain E-AC-3** — the file has no JOC metadata, or the
container's audio track is not E-AC-3; mpv keeps playing the original track.
* **"cannot find the HRTF file"** — put `binaural.sofa` in `<mpv>\\HRTF\\` or
* **"cannot find the HRTF file"** — put `binaural.personalized_headphone` in `<mpv>\\HRTF\\` or
point `joc-hrtf` at it.
* **Which track is in use?** — `joc-verbose=yes` and read the `probe:` / `start:`
lines.
+2 -2
View File
@@ -69,7 +69,7 @@ mpv-joc/
```text
<mpv>\\scripts\\joc_mpv.dll 插件本体
<mpv>\\joc_core.dll 渲染内核(与 JustOneCacophonyCXX 同一个二进制)
<mpv>\\HRTF\\binaural.sofa 双耳渲染默认数据
<mpv>\\HRTF\\binaural.personalized_headphone 双耳渲染默认数据
<mpv>\\HRTF\\binaural.personalized_headphone (Rosella 模型,二选一)
```
@@ -246,7 +246,7 @@ cmake --build build --config Release
* **没有任何 JOC 提示、听起来是普通 E-AC-3** —— 文件没有 JOC 元数据,或者容器的音频轨不是
E-AC-3;插件不接管时 mpv 会照常播放原始轨。
* **双耳报错"找不到 HRTF 文件"** —— 把 `binaural.sofa` 放到 `<mpv>\\HRTF\\`,或用
* **双耳报错"找不到 HRTF 文件"** —— 把 `binaural.personalized_headphone` 放到 `<mpv>\\HRTF\\`,或用
`joc-hrtf` 指定路径。
* **想确认用的是哪条轨道** —— `joc-verbose=yes` 后看日志里的 `probe:` 与 `start:` 行。
+1 -1
View File
@@ -15,7 +15,7 @@ script-opts=joc-output=binaural,joc-mode=mid,joc-gain-db=0
# script-opts-append=joc-output=speaker
# script-opts-append=joc-layout=7.1
#
# 指定 HRTF 文件(默认找 <mpv>\HRTF\binaural.sofa):
# 指定 HRTF 模型文件(默认找 <mpv>\HRTF\binaural.personalized_headphone):
# script-opts-append=joc-hrtf=D:/hrtf/MyMeasurements.sofa
#
# Rosella 模型用捕获版滤波器组(与参考渲染器一致;默认 1 = 公开版):
+8 -20
View File
@@ -126,7 +126,7 @@ ninja -C build
# mpv.conf
ad = joc
ad-joc-binaural = yes # 默认就是 yes(双声道输出)
ad-joc-hrtf = C:/HRTF/binaural.sofa # 可省:会自动找
ad-joc-hrtf = C:/HRTF/binaural.personalized_headphone # 可省:会自动找
ad-joc-layout = 7.1 # 仅 binaural=no 时使用
ad-joc-mode = mid
ad-joc-rosella-filterbank = 1 # Rosella 输入:1=公开版(默认),2=捕获版
@@ -153,31 +153,19 @@ ad-joc-gain-db = 0
clip 到 [-1,1]、乘 8388607、向零截断、取低 24 位,再按 `n / 2^23` 读回。默认关闭,
输出就是渲染器的 float32。
本仓库**不附带任何 HRTF 文件**:SOFA、Rosella 模型、编译出的 `.jochrtf` 缓存都不随仓库或发布包
分发,需要自备。
本仓库**不附带任何 HRTF 文件**:Rosella 模型不随仓库或发布包分发,需要自备。
### HRTF 的三种输入与自动判断
### HRTF 输入
`--ad-joc-hrtf` 不需要说明类型,按文件内容判断(扩展名只作兜底):
| 输入 | 判断依据 | 交给渲染器 |
|---|---|---|
| SOFA | HDF5 魔数 `89 48 44 46 0D 0A 1A 0A` | `hrtf_sofa_path` |
| Rosella 个性化模型 | 首字符 `{` 且含 `"personalized_hrtf"` | `personalized_headphone_path` |
| 已编译核 | 扩展名 `.jochrtf` | `hrtf_path` |
SOFA 编译结果会缓存成 `.jochrtf`(本机首帧 320 ms 左右,命中缓存后 110 ms 左右),
缓存目录是 `<config>/cache/joc-hrtf-cache`,没有 config 目录时用 `<mpv.exe>/joc-hrtf-cache`。
`--ad-joc-hrtf` 指向 Rosella `.personalized_headphone` 模型;解码器按文件内容确认
(首字符 `{` 且含 `"personalized_hrtf"`),不认识的输入会打印提示并退回扬声器布局渲染。
### 不写 `--ad-joc-hrtf` 时
按下面的顺序找,找到即用:
1. `<mpv.exe>/HRTF/binaural.sofa`
2. `<mpv.exe>/HRTF/binaural.personalized_headphone`
3. `<mpv.exe>/HRTF/binaural.jochrtf`
4. `<config>/joc-hrtf/binaural.sofa`
5. `<config>/joc-hrtf/binaural.personalized_headphone`
1. `<mpv.exe>/HRTF/binaural.personalized_headphone`
2. `<config>/joc-hrtf/binaural.personalized_headphone`
都找不到就打印一行提示,退回扬声器布局渲染(默认 7.1),由 mpv 按输出设备下混——双声道
设备上仍然是双声道输出,不会没声音。
@@ -223,7 +211,7 @@ bash tools/bundle_dlls.sh /c/path/to/mpv-src/build # 递归 ldd,把 /mingw64
它们可以预滚 64 帧,AD 拿不到这些帧。
* 只注册 `eac3`(`ac3` 没有 JOC)。非 JOC 的 E-AC-3 会自动回退,代价是开头约 0.26 s
(8 帧)的判定窗口。
* 双耳需要 HRTF:给 `--ad-joc-hrtf`,或把 `binaural.sofa` 放在 `mpv.exe` 旁边;都没有时
* 双耳需要 HRTF:给 `--ad-joc-hrtf`,或把 `binaural.personalized_headphone` 放在 `mpv.exe` 旁边;都没有时
退回扬声器布局,不再报错退出。
* 每换一个 mpv 版本都要重新对齐 patch(AD 接口和注册点在 mpv 内部,不在稳定 ABI 里)。
+1 -1
View File
@@ -44,7 +44,7 @@
|---|---|
| armv7l | `JOC_ARCH` 只认 x86_64/x86_32/aarch64,armv7 会退回标量内核:能播,慢。首选 arm64 |
| `std::filesystem` | NDK 的 libc++ 在 API 23 支持;core 里用到的地方(SOFA 缓存、task、io)需要实际编一遍确认 |
| HRTF 路径 | Android 上 `exe_dir()` 为空,必须由 app 传 `--ad-joc-hrtf=/data/user/0/<pkg>/files/binaural.sofa` |
| HRTF 路径 | Android 上 `exe_dir()` 为空,必须由 app 传 `--ad-joc-hrtf=/data/user/0/<pkg>/files/binaural.personalized_headphone` |
| 缓存目录 | `mp_find_user_file(global, "cache", ...)` 在 Android 上可能拿不到 → 代码已自动退回内存缓存 |
| 许可 | LGPL:动态链接 libmpv.so + libjoc_core.so 合规;发布需附对应源码/补丁 |
| 未验证 | NDK 编 joc_core 的真实报错、NEON 内核在手机上的数值正确性、实时性能 |
+9 -54
View File
@@ -610,7 +610,7 @@ static float quantize_int24(float v)
return (float)written / 8388608.0f;
}
enum hrtf_kind { HRTF_UNKNOWN, HRTF_SOFA, HRTF_ROSELLA, HRTF_KERNELS };
enum hrtf_kind { HRTF_UNKNOWN, HRTF_ROSELLA };
static bool file_exists(const char *path)
{
@@ -623,20 +623,6 @@ static bool file_exists(const char *path)
return true;
}
static bool ends_with_ci(const char *s, const char *suffix)
{
size_t a = strlen(s), b = strlen(suffix);
if (a < b)
return false;
for (size_t i = 0; i < b; i++) {
char x = s[a - b + i], y = suffix[i];
if (x >= 'A' && x <= 'Z') x += 32;
if (y >= 'A' && y <= 'Z') y += 32;
if (x != y)
return false;
}
return true;
}
static bool contains(const void *hay, size_t n, const char *needle)
{
@@ -650,16 +636,13 @@ static bool contains(const void *hay, size_t n, const char *needle)
return false;
}
/* The renderer takes three kinds of HRTF input and the user should not have to
* say which: SOFA is HDF5, the Rosella model is JSON with a personalized_hrtf
* object, and a compiled kernel is a .jochrtf. Look at the extension first
* (conclusive for kernels), then at the file signature. */
/* The renderer takes the Rosella model; a compiled .jochrtf is an internal
* artifact and is never named here, so the only input this decoder recognises is
* the JSON model with a personalized_hrtf object. */
static enum hrtf_kind hrtf_kind_of(const char *path)
{
if (!path || !path[0])
return HRTF_UNKNOWN;
if (ends_with_ci(path, ".jochrtf"))
return HRTF_KERNELS;
unsigned char head[4096];
FILE *fp = fopen(path, "rb");
@@ -668,8 +651,6 @@ static enum hrtf_kind hrtf_kind_of(const char *path)
size_t n = fread(head, 1, sizeof(head), fp);
fclose(fp);
if (n >= 8 && memcmp(head, "\x89HDF\r\n\x1a\n", 8) == 0)
return HRTF_SOFA;
for (size_t i = 0; i < n; i++) {
if (head[i] == ' ' || head[i] == '\t' || head[i] == '\r' || head[i] == '\n')
continue;
@@ -677,8 +658,6 @@ static enum hrtf_kind hrtf_kind_of(const char *path)
return HRTF_ROSELLA;
break;
}
if (ends_with_ci(path, ".sofa"))
return HRTF_SOFA;
return HRTF_UNKNOWN;
}
@@ -698,7 +677,7 @@ static char *exe_dir(void *ta)
}
/* Explicit --ad-joc-hrtf wins; otherwise look where the standalone renderer
* looks: HRTF/binaural.sofa or HRTF/binaural.personalized_headphone next to
* looks: HRTF/binaural.personalized_headphone next to
* mpv.exe, then the same names under the mpv config directory. */
static char *find_hrtf(struct mp_filter *da, struct ad_joc_params *opts)
{
@@ -712,10 +691,7 @@ static char *find_hrtf(struct mp_filter *da, struct ad_joc_params *opts)
}
static const char *const names[] = {
"HRTF/binaural.sofa",
"HRTF/binaural.personalized_headphone",
"HRTF/binaural.jochrtf",
"joc-hrtf/binaural.sofa",
"joc-hrtf/binaural.personalized_headphone",
};
char *dir = exe_dir(p);
@@ -758,7 +734,7 @@ static struct mp_decoder *create(struct mp_filter *parent,
if (hrtf_kind == HRTF_UNKNOWN) {
MP_WARN(da, "no usable HRTF found%s%s; rendering the speaker layout "
"instead (mpv downmixes it to stereo). Place "
"HRTF/binaural.sofa next to mpv.exe or set --ad-joc-hrtf.\n",
"HRTF/binaural.personalized_headphone next to mpv.exe or set --ad-joc-hrtf.\n",
hrtf_path ? ": " : "", hrtf_path ? hrtf_path : "");
binaural = false;
}
@@ -794,36 +770,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. */
/* 0 is the kernel's default (the public bank). */
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)
if (binaural)
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) {
if (hrtf_kind == HRTF_SOFA)
cfg.hrtf_sofa_path = hrtf_path;
else if (hrtf_kind == HRTF_ROSELLA)
cfg.personalized_headphone_path = hrtf_path;
else if (hrtf_kind == HRTF_KERNELS)
cfg.hrtf_path = hrtf_path;
/* Compiling a SOFA is expensive; keep the kernels between runs. */
char *cache = mp_find_user_file(p, da->global, "cache", "joc-hrtf-cache");
if (!cache) {
char *dir = exe_dir(p);
if (dir)
cache = mp_path_join(p, dir, "joc-hrtf-cache");
}
if (cache) {
mp_mkdirp(cache);
cfg.hrtf_cache_dir = cache;
cfg.hrtf_cache_policy = 2;
} else {
cfg.personalized_headphone_path = hrtf_path;
cfg.hrtf_cache_policy = 1;
}
} else {
+2 -2
View File
@@ -8,7 +8,7 @@ ad-joc-binaural = yes
# HRTF input: SOFA, a Rosella .personalized_headphone, or a compiled .jochrtf.
# The kind is detected from the file, so do not name it here.
# Leave empty to search <mpv.exe>/HRTF/binaural.sofa, then the same names under
# Leave empty to search <mpv.exe>/HRTF/binaural.personalized_headphone, then the same name under
# the mpv config dir.
ad-joc-hrtf =
@@ -34,4 +34,4 @@ ad-joc-int24 = no
# Android: there is no executable directory to search, so ad-joc-hrtf must be
# a full path the app can read.
# ad-joc-hrtf = /sdcard/Download/binaural.sofa
# ad-joc-hrtf = /sdcard/Download/binaural.personalized_headphone
+1 -1
View File
@@ -496,7 +496,7 @@ std::string resolve_hrtf_file(const Settings& settings) {
const std::string directory = component_directory();
if (directory.empty()) return {};
// Same convention as the reference CLI next to its executable:
// <base>\HRTF\binaural.sofa or <base>\HRTF\binaural.personalized_headphone.
// <base>\HRTF\binaural.personalized_headphone.
const char* name = "binaural.personalized_headphone";
return directory + "\\HRTF\\" + name;
}