diff --git a/README.en.md b/README.en.md index 5aeb33a..2e847db 100644 --- a/README.en.md +++ b/README.en.md @@ -7,7 +7,7 @@ the engine and the settings are the same ones the upstream frontends the upstream project's command-line frontend uses, so the samples delivered to the player are **bit-identical**. -* Output: binaural (HRTF) or a 2.0 – 7.1 speaker layout; +* Output: binaural (HRTF) or a 2.0 – 9.1.6 speaker layout; * Output device: mpv's own audio output, i.e. WASAPI on Windows (optionally forced, optionally exclusive); * Configuration: mpv's own configuration file, with one `joc-*` option namespace; @@ -84,7 +84,7 @@ ignored and reported in `joc_decoder.log`. |---|---|---|---| | `joc-enabled` | yes / no | yes | disable the plugin entirely | | `joc-output` | binaural / speaker | binaural | output form | -| `joc-layout` | 2.0 3.1 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 | +| `joc-layout` | 2.0 3.1 "4.0 Surround" "4.0 Quad" 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; quote a name that has a space in it, and the old `4.0` still means `4.0 Surround` | | `joc-hrtf-source` | sofa / rosella | sofa | binaural HRTF input | | `joc-hrtf` | path | empty | empty: default name under `\\HRTF\\` or `\\..\\HRTF\\` | | `joc-mode` | near / mid / far | mid | binaural mode | diff --git a/README.md b/README.md index e0733b3..24a1079 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ mpv C 插件(cplugins)。它把 E-AC-3 JOC 码流里的对象音频交给 上游项目的命令行前端相同的引擎、相同的设置、相同的 `joc_core.dll`, 因此同一个文件在两个前端上得到的采样**逐字节一致**。 -- 输出:双耳(HRTF)或 2.0 – 7.1 的扬声器布局; +- 输出:双耳(HRTF)或 2.0 – 9.1.6 的扬声器布局; - 输出设备:照常走 mpv 的音频输出,Windows 上即 WASAPI(可强制 `ao=wasapi`、可开独占); - 配置:mpv 自己的配置文件,新增 `joc-*` 这一个选项命名空间(见下); - 输入:裸流 `.eac3` / `.ec3`,或 MP4 / Matroska 里的 E-AC-3 JOC 轨(有视频也照常播); @@ -98,7 +98,7 @@ mpv --script="C:\\path\\to\\joc_mpv.dll" --script-opts=joc-output=speaker,joc-la |---|---|---|---| | `joc-enabled` | yes / no | yes | 关掉后插件完全不介入 | | `joc-output` | binaural / speaker | binaural | 输出形式 | -| `joc-layout` | 2.0 3.1 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-layout` | 2.0 3.1 "4.0 Surround" "4.0 Quad" 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` 使用。带空格的布局名整体加引号;旧值 `4.0` 仍按 `4.0 Surround` 处理 | | `joc-hrtf-source` | sofa / rosella | sofa | 双耳用哪种 HRTF 输入 | | `joc-hrtf` | 路径 | 空 | 空则用 `<插件目录>\\HRTF\\` 或 `<插件目录>\\..\\HRTF\\` 下的默认文件名 | | `joc-mode` | near / mid / far | mid | 双耳模式 | diff --git a/fork/README.md b/fork/README.md index e344a32..851a027 100644 --- a/fork/README.md +++ b/fork/README.md @@ -136,7 +136,7 @@ ad-joc-gain-db = 0 |---|---|---| | `--ad-joc-binaural` | yes / no | yes | | `--ad-joc-hrtf` | SOFA / Rosella / `.jochrtf` 路径 | 空(自动搜索) | -| `--ad-joc-layout` | `2.0` `3.0` `3.1` `4.0` `5.0` `5.1` `5.1.2` `5.1.4` `6.1` `7.0` `7.1` `7.1.2` `7.1.4` `9.1.4` `9.1.6` | 7.1 | +| `--ad-joc-layout` | `2.0` `3.1` `4.0 Surround` `4.0 Quad` `5.1` `7.1` `5.1.2` `5.1.4` `7.1.2` `7.1.4` `9.1.4` `9.1.6`(旧值 `4.0` 仍按 `4.0 Surround`) | 7.1 | | `--ad-joc-mode` | near / far / mid | mid | | `--ad-joc-gain-db` | -60 … 12 | 0 | | `--ad-joc-int24` | yes / no | no | diff --git a/fork/files/audio/decode/ad_joc.c b/fork/files/audio/decode/ad_joc.c index a0dd6d5..09a2fe1 100644 --- a/fork/files/audio/decode/ad_joc.c +++ b/fork/files/audio/decode/ad_joc.c @@ -551,7 +551,11 @@ static const struct mp_filter_info ad_joc_filter = { /* mpv names layouts up to 7.1 itself; the renderer goes further (it is a Dolby * Atmos renderer, so 5.1.2 … 9.1.6 follow the usual speaker order). Spell the - * wider ones out as speaker lists so mpv knows which channel is which. */ + * wider ones out as speaker lists so mpv knows which channel is which. + * + * The two 4.0 layouts are different speaker sets: Surround is a front trio plus a + * back-centre speaker, Quad is a front and a back pair. "4.0" is the name the + * option used before they were told apart and still means the Surround layout. */ static const struct { const char *name; const char *speakers; @@ -559,7 +563,9 @@ static const struct { {"2.0", "fl-fr"}, {"3.0", "fl-fr-fc"}, {"3.1", "fl-fr-fc-lfe"}, - {"4.0", "fl-fr-fc-bc"}, + {"4.0", "fl-fr-fc-bc"}, + {"4.0 Surround", "fl-fr-fc-bc"}, + {"4.0 Quad", "fl-fr-bl-br"}, {"5.0", "fl-fr-fc-bl-br"}, {"5.1", "fl-fr-fc-lfe-bl-br"}, {"5.1.2", "fl-fr-fc-lfe-bl-br-tfl-tfr"}, diff --git a/src/joc_decode.cpp b/src/joc_decode.cpp index 29fc866..21fd97f 100644 --- a/src/joc_decode.cpp +++ b/src/joc_decode.cpp @@ -354,10 +354,14 @@ private: HANDLE handle_ = INVALID_HANDLE_VALUE; }; -const char* const kLayouts[] = {"2.0", "3.0", "3.1", "4.0", "5.0", "5.1", "5.1.2", - "5.1.4", "6.1", "7.0", "7.1", "7.1.2", "7.1.4", "9.1.4", - "9.1.6"}; -const unsigned kLayoutChannels[] = {2, 3, 4, 4, 5, 6, 8, 10, 7, 7, 8, 10, 12, 14, 16}; +// The layouts the core accepts, with their channel counts. "4.0" is the old +// spelling of 4.0 Surround and is resolved to it before the core is asked, but the +// count table keeps it too so an old configuration still logs its real width. +const char* const kLayouts[] = {"2.0", "3.1", + "4.0 Surround", "4.0 Quad", "4.0", + "5.1", "7.1", "5.1.2", "5.1.4", + "7.1.2", "7.1.4", "9.1.4", "9.1.6"}; +const unsigned kLayoutChannels[] = {2, 4, 4, 4, 4, 6, 8, 8, 10, 10, 12, 14, 16}; // Every ffmpeg child writes its diagnostics next to the component rather than into // whatever working directory the host process happens to have; separate files so diff --git a/src/plugin/config.cpp b/src/plugin/config.cpp index bfc0e3c..8992bcf 100644 --- a/src/plugin/config.cpp +++ b/src/plugin/config.cpp @@ -29,20 +29,28 @@ bool truthy(const std::string& value) { } // The layout names the renderer accepts, in the order its reference lists them. -const char* const kLayouts[] = {"2.0", "3.1", "5.1", "7.1", "5.1.2", - "5.1.4", "7.1.2", "7.1.4", "9.1.4", "9.1.6"}; +const char* const kLayouts[] = {"2.0", "3.1", "4.0 Surround", "4.0 Quad", + "5.1", "7.1", "5.1.2", "5.1.4", + "7.1.2", "7.1.4", "9.1.4", "9.1.6"}; + +// "4.0" is the spelling the option had before the two 4.0 layouts were told +// apart; it has always meant the layout now called 4.0 Surround. +std::string canonical_layout(const std::string& layout) { + return layout == "4.0" ? "4.0 Surround" : layout; +} } // namespace const char* layout_list() { - return "2.0, 3.1, 5.1, 7.1, 5.1.2, 5.1.4, 7.1.2, 7.1.4, 9.1.4, 9.1.6"; + return "2.0, 3.1, 4.0 Surround, 4.0 Quad, 5.1, 7.1, 5.1.2, 5.1.4, 7.1.2, 7.1.4, " + "9.1.4, 9.1.6"; } bool valid_layout(const std::string& layout) { for (const char* name : kLayouts) { if (layout == name) return true; } - return false; + return layout == "4.0"; } Config parse_config(const std::string& script_opts, std::string* warnings) { @@ -83,7 +91,7 @@ Config parse_config(const std::string& script_opts, std::string* warnings) { } } else if (key == "joc-layout") { if (valid_layout(value)) { - config.layout = value; + config.layout = canonical_layout(value); } else { unsupported(key + "=" + value); } diff --git a/src/plugin/wav.cpp b/src/plugin/wav.cpp index 34d7ce3..76d6d09 100644 --- a/src/plugin/wav.cpp +++ b/src/plugin/wav.cpp @@ -11,6 +11,7 @@ constexpr std::uint32_t kFc = 0x00000004u; constexpr std::uint32_t kLfe = 0x00000008u; constexpr std::uint32_t kBl = 0x00000010u; constexpr std::uint32_t kBr = 0x00000020u; +constexpr std::uint32_t kBc = 0x00000100u; constexpr std::uint32_t kSl = 0x00000200u; constexpr std::uint32_t kSr = 0x00000400u; constexpr std::uint32_t kTfl = 0x00001000u; @@ -67,6 +68,11 @@ void put_fmt(std::string* out, unsigned channels, unsigned bits, std::uint32_t m std::uint32_t channel_mask(const std::string& layout, unsigned channels) { if (layout == "2.0") return kFl | kFr; if (layout == "3.1") return kFl | kFr | kFc | kLfe; + // The two 4.0 layouts differ in their speaker set, not only in their name: + // Surround has a front trio and one back-centre speaker, Quad has a front and + // a back pair and neither centre nor LFE. "4.0" is the old name of the former. + if (layout == "4.0 Surround" || layout == "4.0") return kFl | kFr | kFc | kBc; + if (layout == "4.0 Quad") return kFl | kFr | kBl | kBr; if (layout == "5.1") return kFl | kFr | kFc | kLfe | kBl | kBr; if (layout == "7.1") return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr; if (layout == "5.1.2") return kFl | kFr | kFc | kLfe | kBl | kBr | kTfl | kTfr; diff --git a/tools/verify_parity.ps1 b/tools/verify_parity.ps1 index c072c85..39dc0bb 100644 --- a/tools/verify_parity.ps1 +++ b/tools/verify_parity.ps1 @@ -18,9 +18,13 @@ $log = Join-Path (Split-Path $Plugin) "joc_decoder.log" function Invoke-Capture([string]$options, [string]$output) { Remove-Item -Force $log -ErrorAction SilentlyContinue + # Start-Process joins the array with spaces and quotes nothing, so an option + # value with a space in it (a layout name such as "4.0 Surround") has to be + # quoted here or mpv would receive it as two arguments. + $script_opts = "joc-verbose=yes,joc-attach=no,joc-log=$log,$options" $arguments = @("--no-config", "--ao=null", "--vo=null", "--pause=yes", - "--script=$Plugin", "--script-opts=joc-verbose=yes,joc-attach=no,joc-log=$log,$options", - "--msg-level=all=info", $Media) + "--script=$Plugin", "--script-opts=`"$script_opts`"", + "--msg-level=all=info", "`"$Media`"") Start-Process -FilePath $mpv -ArgumentList $arguments -PassThru -WindowStyle Hidden | Out-Null $url = $null for ($i = 0; $i -lt 120; $i++) { @@ -58,13 +62,16 @@ if ($Rosella -ne "") { & $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference if ($LASTEXITCODE -ne 0) { $failures++ } } -Write-Output "=== speaker 7.1 float32 ===" -$reference = Join-Path $WorkDir "reference.7.1.f32.wav" -$actual = Join-Path $WorkDir "plugin.7.1.f32.wav" -& $JocCli $Media --speaker-layout 7.1 --speaker-format float32 --speaker-output $reference | Out-Null -Invoke-Capture "joc-output=speaker,joc-layout=7.1" $actual -& $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference -if ($LASTEXITCODE -ne 0) { $failures++ } +foreach ($layout in @("7.1", "4.0 Surround", "4.0 Quad")) { + Write-Output "=== speaker $layout float32 ===" + $tag = $layout -replace " ", "_" + $reference = Join-Path $WorkDir "reference.$tag.f32.wav" + $actual = Join-Path $WorkDir "plugin.$tag.f32.wav" + & $JocCli $Media --speaker-layout $layout --speaker-format float32 --speaker-output $reference | Out-Null + Invoke-Capture "joc-output=speaker,joc-layout=$layout" $actual + & $Python (Join-Path $PSScriptRoot "compare_wav.py") $actual $reference + if ($LASTEXITCODE -ne 0) { $failures++ } +} if ($failures -ne 0) { throw "$failures comparison(s) failed" } Write-Output "all comparisons passed"