diff --git a/README.en.md b/README.en.md index 2e847db..4cf6fad 100644 --- a/README.en.md +++ b/README.en.md @@ -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 "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-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-hrtf` | path | empty | empty: default name under `\\HRTF\\` or `\\..\\HRTF\\` | | `joc-mode` | near / mid / far | mid | binaural mode | @@ -105,9 +105,51 @@ ignored and reported in `joc_decoder.log`. | `joc-verbose` | yes / no | no | log every HTTP request and reposition | | `joc-log` | path | empty | log file; empty: `\\joc_decoder.log` | -Layouts wider than 7.1 cannot reach a WASAPI endpoint (8 channels maximum), so -`9.1.4` / `9.1.6` are delivered without a channel mask and will normally not map -correctly; use `7.1.4` or below. +## Speaker layouts and channel order + +`joc-layout` accepts the eleven layouts below, and the PCM the plugin hands to mpv follows the order +in the table: + +| Layout | Channel order | +|---|---| +| 2.0 | L, R | +| 3.1 | L, R, C, LFE | +| 4.0 | L, R, Lrs, Rrs | +| 5.1 | L, R, C, LFE, Ls, Rs | +| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs | +| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm | +| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr | +| 7.1.2 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltm, Rtm | +| 7.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltf, Rtf, Ltr, Rtr | +| 9.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltr, Rtr | +| 9.1.6 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltm, Rtm, Ltr, Rtr | + +`4.0` is the quad layout this project adds (the traditional `FL FR BL BR`, here `L R Lrs Rrs`); it is +not part of the Dolby layout set. Every other layout and channel order follows the Dolby +specifications. + +The plugin serves the renderer's output to mpv as an ordinary WAV track over loopback HTTP. That WAV +uses `WAVE_FORMAT_EXTENSIBLE` with `dwChannelMask = 0`: it declares no Windows speaker positions, and +the PCM order is exactly the table above, never rearranged into mask-bit order. **The plugin changes +none of mpv's channel-layout settings**, and it does not affect mpv's native layout support for any +other audio format. + +With no mask, FFmpeg gives the stream a default layout for its channel count (4 channels become +`fl-fr-fc-bc`, 8 become `fl-fr-fc-lfe-bl-br-sl-sr`, wider counts stay unspecified), and mpv reads the +channels from that. In other words, the loopback WAV only guarantees that the PCM matches the table +above channel for channel; the speaker positions follow mpv's own default layout. + +To have mpv play the real layout, use the `ad_joc` decoder: it sets the channel map per frame (in the +order of the table above), so mpv's filter chain, remixing and the WASAPI mask all use the right +positions. An `ao=pcm` capture is byte-identical to `joc_cli`'s WAV. + +Mapping the channels to a device (WASAPI shared/exclusive, ASIO, HDMI) is up to the user; this +project guarantees the content and numbering of each PCM channel, not that a downstream player or +device recognises Dolby speaker positions on its own. A WASAPI endpoint takes at most eight channels, +so `9.1.4` / `9.1.6` normally need ASIO or an external renderer. + +`joc-layout` accepts only the eleven names in the table; anything else is reported and the default +`7.1` is kept. ## How it works @@ -122,7 +164,7 @@ mpv — video and subtitles as usual ▲ E-AC-3 syncframes + core PCM from ffmpeg │ ┌───────────┴────────────┐ - │ rendered as WAV (float32 / int24, with a channel mask) + │ rendered as WAV (float32 / int24, dwChannelMask = 0) │ served by an in-process loopback HTTP endpoint with Range support └───────────┬────────────┘ ▼ diff --git a/README.md b/README.md index 24a1079..f4d6245 100644 --- a/README.md +++ b/README.md @@ -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 "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-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-hrtf` | 路径 | 空 | 空则用 `<插件目录>\\HRTF\\` 或 `<插件目录>\\..\\HRTF\\` 下的默认文件名 | | `joc-mode` | near / mid / far | mid | 双耳模式 | @@ -119,8 +119,44 @@ mpv --script="C:\\path\\to\\joc_mpv.dll" --script-opts=joc-output=speaker,joc-la | `joc-verbose` | yes / no | no | 在日志里记录每个 HTTP 请求与跳转 | | `joc-log` | 路径 | 空 | 日志文件;空则写 `\\joc_decoder.log` | -扬声器布局与 WASAPI:WASAPI 端点最多 8 个声道,所以 `9.1.4` / `9.1.6` 这类布局在本插件里 -只能用没有声道掩码的普通 WAV 交付,实际设备上通常拿不到正确映射——需要时请用 `7.1.4` 及以下。 +## 扬声器布局与声道顺序 + +`joc-layout` 只接受下表 11 个布局,插件交给 mpv 的 PCM 顺序就是表里的顺序: + +| 布局 | 声道顺序 | +|---|---| +| 2.0 | L, R | +| 3.1 | L, R, C, LFE | +| 4.0 | L, R, Lrs, Rrs | +| 5.1 | L, R, C, LFE, Ls, Rs | +| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs | +| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm | +| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr | +| 7.1.2 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltm, Rtm | +| 7.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltf, Rtf, Ltr, Rtr | +| 9.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltr, Rtr | +| 9.1.6 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltm, Rtm, Ltr, Rtr | + +`4.0` 是本项目补充的 Quad 布局(传统 Quad 的 `FL FR BL BR`),声道为 `L R Lrs Rrs`,不在杜比 +文档的布局列表里;除它以外的布局及声道顺序均依据杜比相关规范定义。 + +插件通过回环 HTTP 把渲染结果作为一条普通 WAV 轨交给 mpv。这个 WAV 使用 +`WAVE_FORMAT_EXTENSIBLE` 且 `dwChannelMask = 0`:它不声明 Windows 扬声器位置,PCM 顺序严格按 +上表,不按掩码位序重排。**插件不改动 mpv 的任何声道布局设置**,也不影响 mpv 对其他音频格式的 +原生布局支持。 + +没有掩码时 FFmpeg 会按声道数给这条流套一个默认布局(4 声道是 `fl-fr-fc-bc`,8 声道是 +`fl-fr-fc-lfe-bl-br-sl-sr`,更多声道保持未指定),mpv 据此解释它的声道。也就是说,回环 WAV 这条 +路只保证“PCM 逐声道与上表一致”;扬声器位置取决于 mpv 自己的默认布局。 + +要让 mpv 按真实布局播放,请用 `ad_joc` 解码器:它逐帧设置 chmap(顺序与上表一致),mpv 的滤镜 +链、重混与 WASAPI 掩码都按正确位置处理。实测 `ao=pcm` 输出与 `joc_cli` 的 WAV 逐字节一致。 + +设备端的输出映射(WASAPI 共享/独占、ASIO、HDMI)仍由用户按声道编号自行确认;本项目保证各 PCM +声道的内容和编号符合上表,不保证下游播放器或设备自动识别杜比扬声器位置。WASAPI 端点最多 8 个 +声道,`9.1.4` / `9.1.6` 这类布局通常需要 ASIO 或外部渲染器。 + +`joc-layout` 只接受上表 11 个名字;其它值记一条警告并保持默认 `7.1`。 ## 实现 @@ -134,7 +170,7 @@ mpv ── 视频/字幕照常 ▲ E-AC-3 同步帧 + ffmpeg 解出的核心 PCM │ ┌───────────┴────────────┐ - │ 渲染成 WAV(float32 / int24,带声道掩码) + │ 渲染成 WAV(float32 / int24,dwChannelMask = 0) │ 由进程内的 loopback HTTP 端点提供,支持 Range └───────────┬────────────┘ ▼ @@ -147,7 +183,7 @@ WASAPI 输出和跳转都不用改。 启动顺序:`start-file` 时就开始探测并创建渲染器(此时 mpv 还在打开文件),同时把文件自带的 音轨静音;`file-loaded` 时把渲染轨 `audio-add ... select` 进去,然后恢复原来的静音状态。 探测判定不是 JOC 的输入立刻恢复,不会留下静音(带 E-AC-3 轨但不是 JOC 的容器会经历一次 -约 100 ms 的 ffmpeg 探测,期间是静音;`joc-mute-until-ready=no` 可关掉这一行为)。实测(30 秒 7.1.4 素材):冷启动约 0.6 秒、 +约 100 ms 的 ffmpeg 探测,期间是静音;`joc-mute-until-ready=no` 可关掉这一行为)。实测:冷启动约 0.6 秒、 HRTF 编译结果命中磁盘缓存后约 0.37 秒;这段是静音而不是普通 bed,且 mpv 在切轨时会暂停音频时钟, 所以不会跳过内容。插件只在请求的字节位置和渲染位置不一致时让渲染器重新进入码流 (与组件的 seek 策略相同:目标帧减去 64 帧预滚,再丢掉目标之前的输出)。 @@ -173,7 +209,7 @@ AVPacket,所以不需要改 FFmpeg,内核仍是 `joc_core.dll`。这条路 ## 一致性验证 `tools/verify_parity.ps1` 用 `joc_cli` 生成参考 WAV,再从插件取回实际交付的字节逐字节比较。 -本机(mpv v0.41.0,FFmpeg 8.0,30 秒 7.1.4 JOC 素材)的结果: +本机(mpv v0.41.0,FFmpeg 8.0)的结果: | 组合 | 结果 | |---|---| diff --git a/fork/README.md b/fork/README.md index 844fcd2..6556084 100644 --- a/fork/README.md +++ b/fork/README.md @@ -138,7 +138,7 @@ ad-joc-gain-db = 0 |---|---|---| | `--ad-joc-binaural` | yes / no | yes | | `--ad-joc-hrtf` | SOFA / Rosella / `.jochrtf` 路径 | 空(自动搜索) | -| `--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-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-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 09a2fe1..95bd1a8 100644 --- a/fork/files/audio/decode/ad_joc.c +++ b/fork/files/audio/decode/ad_joc.c @@ -549,34 +549,26 @@ static const struct mp_filter_info ad_joc_filter = { .destroy = ad_joc_destroy, }; -/* 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. - * - * 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. */ +/* The layouts the core renders, with the channel order it writes them in, spelled + * with mpv's speaker names. The order is per channel and is not the order of a + * WAVE channel mask: 7.1 and up write the side pair before the rear pair, so mpv + * names up to 7.1 are not used as they are. The core's 4.0 is the quad layout + * (front and back pair). */ static const struct { const char *name; const char *speakers; } layout_names[] = { {"2.0", "fl-fr"}, - {"3.0", "fl-fr-fc"}, {"3.1", "fl-fr-fc-lfe"}, - {"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"}, + {"4.0", "fl-fr-bl-br"}, {"5.1", "fl-fr-fc-lfe-bl-br"}, - {"5.1.2", "fl-fr-fc-lfe-bl-br-tfl-tfr"}, + {"7.1", "fl-fr-fc-lfe-sl-sr-bl-br"}, + {"5.1.2", "fl-fr-fc-lfe-bl-br-tsl-tsr"}, {"5.1.4", "fl-fr-fc-lfe-bl-br-tfl-tfr-tbl-tbr"}, - {"6.1", "fl-fr-fc-lfe-bc-sl-sr"}, - {"7.0", "fl-fr-fc-bl-br-sl-sr"}, - {"7.1", "fl-fr-fc-lfe-bl-br-sl-sr"}, - {"7.1.2", "fl-fr-fc-lfe-bl-br-sl-sr-tfl-tfr"}, - {"7.1.4", "fl-fr-fc-lfe-bl-br-sl-sr-tfl-tfr-tbl-tbr"}, - {"9.1.4", "fl-fr-fc-lfe-bl-br-sl-sr-wl-wr-tfl-tfr-tbl-tbr"}, - {"9.1.6", "fl-fr-fc-lfe-bl-br-sl-sr-wl-wr-tfl-tfr-tsl-tsr-tbl-tbr"}, + {"7.1.2", "fl-fr-fc-lfe-sl-sr-bl-br-tsl-tsr"}, + {"7.1.4", "fl-fr-fc-lfe-sl-sr-bl-br-tfl-tfr-tbl-tbr"}, + {"9.1.4", "fl-fr-fc-lfe-sl-sr-bl-br-wl-wr-tfl-tfr-tbl-tbr"}, + {"9.1.6", "fl-fr-fc-lfe-sl-sr-bl-br-wl-wr-tfl-tfr-tsl-tsr-tbl-tbr"}, }; static bool layout_chmap(struct mp_chmap *chmap, const char *layout, int channels) @@ -752,6 +744,8 @@ static struct mp_decoder *create(struct mp_filter *parent, struct priv *p = da->priv; struct ad_joc_params *opts = mp_get_config_group(p, da->global, &ad_joc_conf); bool binaural = opts->binaural; + /* The layout name the core is asked for. */ + const char *layout = opts->layout; char *hrtf_path = NULL; enum hrtf_kind hrtf_kind = HRTF_UNKNOWN; if (binaural) { @@ -820,7 +814,7 @@ static struct mp_decoder *create(struct mp_filter *parent, cfg.hrtf_cache_policy = 1; } } else { - cfg.speaker_layout_name = opts->layout; + cfg.speaker_layout_name = layout; } p->cfg = cfg; if (joc_stream_create(&cfg, &p->stream) != JOC_OK) { @@ -842,8 +836,8 @@ static struct mp_decoder *create(struct mp_filter *parent, struct mp_chmap chmap; if (binaural) { mp_chmap_from_channels(&chmap, 2); - } else if (!layout_chmap(&chmap, opts->layout, channels)) { - MP_ERR(da, "unknown speaker layout '%s'\n", opts->layout); + } else if (!layout_chmap(&chmap, layout, channels)) { + MP_ERR(da, "unknown speaker layout '%s'\n", layout); talloc_free(da); return NULL; } @@ -862,7 +856,7 @@ static struct mp_decoder *create(struct mp_filter *parent, p->int24 = opts->int24; codec->codec_desc = "E-AC-3 JOC (joc_core renderer)"; MP_VERBOSE(da, "renderer: %s, %d channel(s)%s%s\n", - binaural ? "binaural" : opts->layout, p->out_channels, + binaural ? "binaural" : layout, p->out_channels, binaural ? ", hrtf: " : "", binaural ? hrtf_path : ""); if (p->int24) MP_INFO(da, "int24: quantising the output to the renderer's 24-bit rule\n"); diff --git a/fork/mpv.conf.example b/fork/mpv.conf.example index c4de1f8..0ae7bb3 100644 --- a/fork/mpv.conf.example +++ b/fork/mpv.conf.example @@ -14,7 +14,7 @@ ad-joc-hrtf = # Speaker layout, used when ad-joc-binaural=no (and as the fallback when no # HRTF can be found; mpv then downmixes it to whatever the device wants). -# 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 +# 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 ad-joc-layout = 7.1 # Binaural rendering mode: near | mid | far. diff --git a/src/cplugin_main.cpp b/src/cplugin_main.cpp index 40ed5f5..8cb433a 100644 --- a/src/cplugin_main.cpp +++ b/src/cplugin_main.cpp @@ -395,10 +395,9 @@ struct Plugin { auto created = std::make_shared(); created->source = source; - const std::string mask_layout = (config.output == 0) ? "2.0" : config.layout; created->header = joc_mpv::wav_header( source->channels(), source->bits_per_sample(), - joc_mpv::channel_mask(mask_layout, source->channels()), source->data_bytes()); + joc_mpv::channel_mask(source->channels()), source->data_bytes()); created->total_bytes = created->header.size() + source->data_bytes(); const double per_write = config.chunk_seconds * 48000.0 * static_cast(source->bytes_per_frame()); diff --git a/src/joc_decode.cpp b/src/joc_decode.cpp index 21fd97f..724b61f 100644 --- a/src/joc_decode.cpp +++ b/src/joc_decode.cpp @@ -354,14 +354,26 @@ private: HANDLE handle_ = INVALID_HANDLE_VALUE; }; -// 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}; +// The layouts the core accepts, with their channel counts. The counts have to +// stay in step with the core's table. +struct LayoutEntry { + const char* name; + unsigned channels; +}; + +const LayoutEntry kLayouts[] = { + {"2.0", 2}, + {"3.1", 4}, + {"4.0", 4}, + {"5.1", 6}, + {"7.1", 8}, + {"5.1.2", 8}, + {"5.1.4", 10}, + {"7.1.2", 10}, + {"7.1.4", 12}, + {"9.1.4", 14}, + {"9.1.6", 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 @@ -410,14 +422,9 @@ std::int64_t sample_of_seconds(double seconds) { } // namespace -const char* const* speaker_layouts(std::size_t* count) { - if (count != nullptr) *count = sizeof(kLayouts) / sizeof(kLayouts[0]); - return kLayouts; -} - unsigned speaker_channels(const std::string& layout) { - for (std::size_t i = 0; i < sizeof(kLayouts) / sizeof(kLayouts[0]); ++i) { - if (layout == kLayouts[i]) return kLayoutChannels[i]; + for (const LayoutEntry& entry : kLayouts) { + if (layout == entry.name) return entry.channels; } return 0; } diff --git a/src/joc_decode.h b/src/joc_decode.h index 5181878..6bfd19b 100644 --- a/src/joc_decode.h +++ b/src/joc_decode.h @@ -120,9 +120,6 @@ std::string component_directory(); // component directory cannot be determined. std::string resolve_hrtf_file(const Settings& settings); -// Every layout the core accepts, in the order a settings page should list them. -const char* const* speaker_layouts(std::size_t* count); - // Result of examining a file without rendering anything. struct FileProbe { bool readable = false; diff --git a/src/plugin/config.cpp b/src/plugin/config.cpp index 8992bcf..bef822a 100644 --- a/src/plugin/config.cpp +++ b/src/plugin/config.cpp @@ -29,28 +29,16 @@ 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", "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; -} +const char* const kLayouts[] = {"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"}; } // namespace -const char* layout_list() { - 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 layout == "4.0"; + return false; } Config parse_config(const std::string& script_opts, std::string* warnings) { @@ -91,7 +79,7 @@ Config parse_config(const std::string& script_opts, std::string* warnings) { } } else if (key == "joc-layout") { if (valid_layout(value)) { - config.layout = canonical_layout(value); + config.layout = value; } else { unsupported(key + "=" + value); } diff --git a/src/plugin/config.h b/src/plugin/config.h index f40771e..67bad3c 100644 --- a/src/plugin/config.h +++ b/src/plugin/config.h @@ -50,7 +50,6 @@ struct Config { // keys are ignored so an mpv.conf written for a newer build still loads. Config parse_config(const std::string& script_opts, std::string* warnings); -const char* layout_list(); bool valid_layout(const std::string& layout); } // namespace joc_mpv diff --git a/src/plugin/wav.cpp b/src/plugin/wav.cpp index 76d6d09..750a1e9 100644 --- a/src/plugin/wav.cpp +++ b/src/plugin/wav.cpp @@ -7,17 +7,6 @@ namespace { constexpr std::uint32_t kFl = 0x00000001u; constexpr std::uint32_t kFr = 0x00000002u; -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; -constexpr std::uint32_t kTfr = 0x00004000u; -constexpr std::uint32_t kTbl = 0x00008000u; -constexpr std::uint32_t kTbr = 0x00020000u; void put_u16(std::string* out, std::uint16_t value) { char bytes[2]; @@ -65,29 +54,10 @@ void put_fmt(std::string* out, unsigned channels, unsigned bits, std::uint32_t m } // namespace -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; - if (layout == "5.1.4") { - return kFl | kFr | kFc | kLfe | kBl | kBr | kTfl | kTfr | kTbl | kTbr; - } - if (layout == "7.1.2") { - return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr | kTfl | kTfr; - } - if (layout == "7.1.4") { - return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr | kTfl | kTfr | kTbl | kTbr; - } - // 2-channel binaural output is plain stereo. - if (channels == 2) return kFl | kFr; - return 0; +std::uint32_t channel_mask(unsigned channels) { + // No mask above stereo: the channel order is the renderer's, and a WAVE mask + // would claim a different one. Two channels are plain stereo. + return channels == 2 ? (kFl | kFr) : 0; } std::string wav_header(unsigned channels, unsigned bits_per_sample, std::uint32_t mask, diff --git a/src/plugin/wav.h b/src/plugin/wav.h index 8b90e5a..e23b4a2 100644 --- a/src/plugin/wav.h +++ b/src/plugin/wav.h @@ -5,11 +5,10 @@ namespace joc_mpv { -// Channel mask for a layout the renderer can produce. The renderer emits its -// channels in the standard WAVE order for that layout, so a WAVE_FORMAT_EXTENSIBLE -// mask tells mpv exactly which speaker each channel belongs to. Layouts wider -// than 7.1 return 0 (no mask): they cannot reach a WASAPI endpoint anyway. -std::uint32_t channel_mask(const std::string& layout, unsigned channels); +// Channel mask for the served WAV. The PCM follows the renderer's channel order, +// which no WAVE mask describes, so anything wider than stereo is declared with no +// speaker positions at all (mask 0). Two channels are FL/FR in either definition. +std::uint32_t channel_mask(unsigned channels); // 68-byte WAVE_FORMAT_EXTENSIBLE header, or a 104-byte RF64 header when the data // chunk would not fit a 32-bit size. diff --git a/tools/verify_parity.ps1 b/tools/verify_parity.ps1 index 39dc0bb..640220d 100644 --- a/tools/verify_parity.ps1 +++ b/tools/verify_parity.ps1 @@ -62,7 +62,8 @@ if ($Rosella -ne "") { & $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")) { +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")) { Write-Output "=== speaker $layout float32 ===" $tag = $layout -replace " ", "_" $reference = Join-Path $WorkDir "reference.$tag.f32.wav"