Deliver the renderer's channel order with the host's channel map
build / windows (push) Canceled after 0s
build / release (push) Canceled after 0s

This commit is contained in:
TheM14 committed 2026-10-29 01:02:56 +08:00
1 parent 8c7d253d47
commit 9dca991e03
15 files changed
+197 -582

No files matched your search

+49 -53
View File
@@ -88,62 +88,57 @@ No control on the page is disabled, and the status line states what is in effect
above are the English ones; the Chinese page names the same controls 输出, 扬声器布局, 双耳模式,
HRTF 文件, 增益.
### Speaker layouts and channel order
| Layout | Channels | Channel mask | Delivered order (declared speaker positions) |
|---|---|---|---|
| 2.0 | 2 | `0x3` | FL FR |
| 3.1 | 4 | `0xF` | FL FR FC LFE |
| 4.0 Surround | 4 | `0x107` | FL FR FC BC |
| 4.0 Quad | 4 | `0x33` | FL FR BL BR |
| 5.1 | 6 | `0x3F` | FL FR FC LFE BL BR |
| 7.1 | 8 | `0x63F` | FL FR FC LFE BL BR SL SR |
| 5.1.2 | 8 | `0x560F` | FL FR FC LFE SL SR TFL TFR |
| 5.1.4 | 10 | `0x2D60F` | FL FR FC LFE SL SR TFL TFR TBL TBR |
| 7.1.2 | 10 | `0x563F` | FL FR FC LFE BL BR SL SR TFL TFR |
| 7.1.4 | 12 | `0x2D63F` | FL FR FC LFE BL BR SL SR TFL TFR TBL TBR |
| 9.1.4 | 14 | `0x2D6FF` | FL FR FC LFE BL BR FCL FCR SL SR TFL TFR TBL TBR |
| 9.1.6 | 16 | `0x3F6FF` | FL FR FC LFE BL BR FCL FCR SL SR TFL TFC TFR TBL TBC TBR |
**There are two 4.0 layouts, and they are different speaker sets, not two spellings of one layout.**
**4.0 Surround** is a front trio plus one back-centre speaker (`FL FR FC BC`; the renderer calls the
channels `L R C Cs`). **4.0 Quad** is a front and a back pair (`FL FR BL BR`; `L R Lrs Rrs`) with
neither a centre nor an LFE — an object straight ahead is a phantom image of the front pair, and the
LFE in the input has no output channel in this layout, so by the core's rule it is not mixed into
the others. Older builds had only the name `4.0`, which always meant the surround layout: the core
resolves `4.0` as an alias for `4.0 Surround` (the page shows `4.0 Surround`, and an applied page
stores the explicit name), and Quad has to be asked for as `4.0 Quad`.
The renderer emits the reference implementation's channel order (for 9.1.4: L R C LFE Lrs Rrs Ls Rs
Ltf Rtf Ltr Rtr Lw Rw), while foobar2000 defines the interleaved order as the ascending order of the
channel mask's speaker bits. The two agree for 2.0 through 7.1.4 (both 4.0 layouts included); 9.1.4
and 9.1.6 carry the wide pair last, so the channels are permuted into mask order before delivery
(the log says `channels permuted into mask order`). The table above is that order; Properties shows
the matching `WAVEFORMATEXTENSIBLE_CHANNEL_MASK`, and the Converter writes files in the same order.
The mask follows ffmpeg's definition of the same layout name (`5.1` is BL/BR, `5.1.2` and up are
SL/SR, the wide pair is FCL/FCR, `4.0` is FL FR FC BC), so a layout name means the same thing in the
component, in a converted file and in other tools. **9.1.6's top-middle pair (Ltm/Rtm) has no WAVE
position** — ffmpeg places it at TSL/TSR, beyond a 32-bit mask — so it is delivered at the two centre
positions the mask has left, TFC and TBC: the mask still has exactly one bit per channel and the
order is the one in the table, at the cost of those two channels being labelled top front centre /
top back centre in foobar2000's channel lists.
**Windows itself has only the 2.0 / 5.1 / 7.1 speaker configurations, so every other layout (3.1,
both 4.0 layouts, anything with height or wide channels) needs ASIO (or an exclusive output that
accepts the layout) on shared and exclusive output.** ASIO has no such limit and maps the channels
in the order the component delivers them (assign them by name in fb2k's ASIO channel mapping). With
such a layout on a system-configured output the core downmixes the extra channels — audible, but
those channels are not heard; the Converter is not bound by the output device and writes 4-, 14- or
16-channel files as configured. The preferences status line says "needs ASIO output" when such a
layout is selected.
### 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
need none. Binaural rendering without an HRTF fails with a message naming the file it looked for.
## Speaker layouts and channel order
The PCM this component hands to foobar2000, and the multichannel WAV files the Converter writes,
follow the renderer's channel order:
| 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`): a
front and a back pair with neither a centre nor an LFE — an object straight ahead is a phantom image
of the front pair, and the LFE in the input has no output channel in this layout, so by the core's
rule it is not mixed into the others. Every other layout and channel order follows the Dolby
specifications.
**Channel order and the foobar2000 limitation.** The component hands the renderer's PCM over
unchanged, in the order of the table above; when that stream is written to WAV (the playback chunk or
a Converter output), the order of the 1–16 channels follows the Dolby documentation exactly. The
channel *definitions*, however, are not guaranteed to correspond fully: foobar2000's WAVE writer can
only declare a Windows speaker mask, which has no slot for top-middle (`Ts`) or wide (`Ww`) and cannot
express an order such as 7.1's `Ls Rs Lrs Rrs`. This is a foobar2000 limitation, not a problem with
the rendered order. Properties declares the channel count and no speaker positions; the chunk used
while playing carries foobar2000's default map for that channel count (an unspecified map is rejected
as an invalid audio stream specification and playback fails).
For a multichannel WAV with `dwChannelMask = 0`, download the CLI from
[github.com/TheM14/JustOneCacophony](https://github.com/TheM14/JustOneCacophony) and export with it: it
writes `WAVE_FORMAT_EXTENSIBLE` with `dwChannelMask = 0` and the order above.
Mapping the channels to a player, ASIO, a DAW or a device is up to the user; the component guarantees
the content and numbering of each PCM channel as listed above.
Layout names in the configuration follow the table above; a name that cannot be resolved is logged
and falls back to `7.1`.
## Building
```powershell
@@ -175,9 +170,10 @@ every container in the library, which is where the volume comes from.
* ADM BWF output is not implemented.
* Speaker layouts go up to 9.1.6 (16 channels), which is the renderer's own limit — there is no
22.2. Layouts other than 2.0 / 5.1 / 7.1 need ASIO (or an exclusive output that accepts the
layout); see [Speaker layouts and channel order](#speaker-layouts-and-channel-order).
* 9.1.6's top-middle pair has no WAVE channel position and is delivered at TFC/TBC (same section).
22.2, see [Speaker layouts and channel order](#speaker-layouts-and-channel-order).
* A multichannel layout declares no speaker positions in Properties, and the per-chunk map used for
playback is only foobar2000's default for the channel count; output mapping is up to the user's
channel assignment (same section).
* All five $joc\_dmx\_config\_idx$ configurations are supported: the bed is paired per audio
frame, and its channel count follows the configuration (6 channels for 0/3, 8 for 1/2/4), with
`-ac 6` passed to ffmpeg only for the 6-channel ones. An AC-3 core plus a dependent substream
+41 -46
View File
@@ -71,54 +71,48 @@ Preferences → Tools → **JOC 解码器**:
页面上的控件都不禁用,状态行会说明当前生效的是什么。中文页面的控件名与上表一致,英文页面是同一些
控件的译文(例如 **Output**、**Speaker layout**、**Binaural mode**、**HRTF file**、**Apply gain**)。
### 扬声器布局与声道顺序
| 布局 | 声道 | 通道掩码 | 交付顺序(声明的声道位置) |
|---|---|---|---|
| 2.0 | 2 | `0x3` | FL FR |
| 3.1 | 4 | `0xF` | FL FR FC LFE |
| 4.0 Surround | 4 | `0x107` | FL FR FC BC |
| 4.0 Quad | 4 | `0x33` | FL FR BL BR |
| 5.1 | 6 | `0x3F` | FL FR FC LFE BL BR |
| 7.1 | 8 | `0x63F` | FL FR FC LFE BL BR SL SR |
| 5.1.2 | 8 | `0x560F` | FL FR FC LFE SL SR TFL TFR |
| 5.1.4 | 10 | `0x2D60F` | FL FR FC LFE SL SR TFL TFR TBL TBR |
| 7.1.2 | 10 | `0x563F` | FL FR FC LFE BL BR SL SR TFL TFR |
| 7.1.4 | 12 | `0x2D63F` | FL FR FC LFE BL BR SL SR TFL TFR TBL TBR |
| 9.1.4 | 14 | `0x2D6FF` | FL FR FC LFE BL BR FCL FCR SL SR TFL TFR TBL TBR |
| 9.1.6 | 16 | `0x3F6FF` | FL FR FC LFE BL BR FCL FCR SL SR TFL TFC TFR TBL TBC TBR |
**4.0 有两个布局,它们是不同的扬声器集合,不是同一个布局的两种叫法。** **4.0 Surround** 是前置
三声道加一只后中(`FL FR FC BC`,渲染内核里的名字是 `L R C Cs`);**4.0 Quad** 是前后各一对
(`FL FR BL BR`,内核里是 `L R Lrs Rrs`),既没有中置也没有 LFE——对象在正前方时由左右两只音箱
合成幻像中置,输入里的 LFE 在这种布局下没有输出声道,按内核规则不混入其它声道。旧版本只有 `4.0`
一个名字,含义一直是 Surround,因此读到 `4.0` 时按 `4.0 Surround` 处理(设置页显示为
`4.0 Surround`,应用一次设置后存的就是显式名字);要 Quad 必须写 `4.0 Quad`。
渲染内核按参考实现的顺序产生声道(9.1.4 是 L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr Lw Rw),
而 foobar2000 规定"帧内声道顺序 = 通道掩码中声道位的升序"。两者对 2.0 到 7.1.4(含两种 4.0)恰好
一致;9.1.4 与 9.1.6 的宽声道排在后面,所以交付前按掩码顺序重排(日志里写 `channels permuted into
mask order`)。上表就是这个顺序;Properties 里能看到对应的 `WAVEFORMATEXTENSIBLE_CHANNEL_MASK`,
转换器写文件时也按同一个顺序落盘。
掩码取 ffmpeg 对同名布局的定义(`5.1` 是 BL/BR,`5.1.2` 起是 SL/SR,宽声道是 FCL/FCR,`4.0` 是
FL FR FC BC),这样同一个布局名在组件、转换产物与其它工具里含义一致。**9.1.6 的顶层中间声道对
(Ltm/Rtm)在 WAVE 的 18 个声道位里没有对应位置**(ffmpeg 用 32 位掩码之外的 TSL/TSR),因此按
TFL/TFC/TFR/TBL/TBC/TBR 中剩下的两个居中位置 TFC 与 TBC 交付:掩码仍然是一位声道一个位,顺序如
上表,代价是这两路在 foobar2000 的声道列表里显示为顶前排中、顶后排中。
**Windows 自己只有 2.0 / 5.1 / 7.1 三种扬声器配置,其余布局(3.1、两种 4.0、所有带高度或宽声道的
布局)的共享与独占输出都需要 ASIO(或接受该布局的独占输出)。** 高度声道、宽声道、后中与超过 8
声道的布局 ASIO 没有限制,声道按组件交付的顺序对应到设备的输出通道(用 fb2k 的 ASIO 声道映射按名称
分配)。用这样的布局而输出仍走系统配置时,核心会把多出来的声道下混——能听到声音,但听不到那几路;
转换器(Converter)不受输出设备限制,可以按布局写出 4/14/16 声道的文件。设置页的状态行在选中这类
布局时会写"需要 ASIO 输出"。
### HRTF 数据
SOFA 测量集或个性化耳机模型由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。
扬声器布局不需要 HRTF。双耳渲染缺少 HRTF 时会报错并指出它找的是哪个文件。
## 扬声器布局与声道顺序
组件交给 foobar2000 的 PCM 与转换器写出的多声道 WAV 都按渲染内核的声道顺序排列:
| 布局 | 声道顺序 |
|---|---|
| 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`:前后各一对,
既没有中置也没有 LFE——对象在正前方时由左右两只音箱合成幻像中置,输入里的 LFE 在这种布局下没有
输出声道,按内核规则不混入其它声道。除 `4.0` 外,其余布局及声道顺序均依据杜比相关规范定义。
**声道顺序与 foobar2000 的限制。** 组件把渲染内核的 PCM 原样交出,声道顺序就是上表;写进 WAV 时
(播放的 chunk 或转换器的产物),这 1–16 个声道的排列顺序与杜比规范严格对应。但 foobar2000 的
WAVE 写出只能用一套 Windows 扬声器掩码,它没有 `Ts`(top middle)和 `Ww`(wide)的位置,也无法
表达 7.1 `Ls Rs Lrs Rrs` 这种顺序,所以**声道的定义(掩码/扬声器位置)不保证完全对应**——这是
foobar2000 的限制,不是渲染顺序的问题。Properties 只声明声道数、不声明位置;播放时 chunk 携带
foobar2000 对该声道数的默认映射(未指定掩码会被判“无效的音频流规范”,播放直接失败)。
需要 `dwChannelMask = 0` 的多声道 WAV 时,请自行到
[github.com/TheM14/JustOneCacophony](https://github.com/TheM14/JustOneCacophony) 下载对应的 CLI
程序导出:它写 `WAVE_FORMAT_EXTENSIBLE` + `dwChannelMask = 0`,声道顺序同上表。
播放器、ASIO、DAW 或设备的输出映射要按声道编号自行完成;组件保证各 PCM 声道的内容和编号符合上表。
配置里的布局名按上表读取;无法识别的名字会记一条日志并回落到 `7.1`。
## 构建
```powershell
@@ -142,9 +136,10 @@ pwsh -File tools/package.ps1 # 两个架构,打包到 dist\*.fb2k-c
## 已知限制
* 不实现 ADM BWF 输出。
* 扬声器布局到 9.1.6(16 声道)为止;内核输出上限就是 16 声道,没有 22.2。2.0/5.1/7.1 之外的
布局需要 ASIO(或接受该布局的独占输出),见[扬声器布局与声道顺序](#扬声器布局与声道顺序)。
* 9.1.6 的顶层中间声道对在 WAVE 的声道位里没有对应位置,按 TFC/TBC 交付(同上)。
* 扬声器布局到 9.1.6(16 声道)为止;内核输出上限就是 16 声道,没有 22.2,见
[扬声器布局与声道顺序](#扬声器布局与声道顺序)。
* 多声道布局在 Properties 里不声明扬声器位置,播放时的块内映射只是 foobar2000 对该声道数的
默认值;输出映射要按声道编号自行完成(同上)。
* $joc\_dmx\_config\_idx$ 全部五个档位都支持:取床按音频帧配对,床通道数由档位决定(0/3
为 6 通道,1/2/4 为 8 通道),ffmpeg 只在 6 通道档位传 `-ac 6`。AC-3 核心 + 依赖子流
(`strmtyp=1`)与"首个音频帧没有 JOC"都按正常情况处理。
+1 -1
View File
@@ -84,7 +84,7 @@ struct Options {
};
const char* kLayoutChoices =
"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";
"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";
void print_usage() {
std::printf(
+1 -15
View File
@@ -15,8 +15,7 @@ struct FrozenLayout {
constexpr FrozenLayout kLayouts[kLayoutCount] = {
{"2.0", 0, 1},
{"3.1", 3, 7},
{"4.0 Surround", 0xFF, 35},
{"4.0 Quad", 0xFF, 9},
{"4.0", 0xFF, 9},
{"5.1", 7, 15},
{"7.1", 11, 31},
{"5.1.2", 13, 1039},
@@ -27,14 +26,6 @@ constexpr FrozenLayout kLayouts[kLayoutCount] = {
{"9.1.6", 20, 3743},
};
// Spellings accepted in addition to the names above.
constexpr struct {
const char* alias;
const char* name;
} kAliases[] = {
{"4.0", "4.0 Surround"},
};
void fill(const FrozenLayout& source, LayoutInfo* out) {
out->name = source.name;
out->out_ch_config = source.out_ch_config;
@@ -62,11 +53,6 @@ bool layout_by_name(const char* name, LayoutInfo* out) {
return true;
}
}
for (const auto& alias : kAliases) {
if (std::strcmp(name, alias.alias) == 0) {
return layout_by_name(alias.name, out);
}
}
return false;
}
+6 -6
View File
@@ -8,7 +8,7 @@
namespace joc::speaker {
inline constexpr int kLayoutCount = 12;
inline constexpr int kLayoutCount = 11;
struct LayoutInfo {
const char* name = "";
@@ -17,13 +17,13 @@ struct LayoutInfo {
std::uint32_t channel_count = 0;
};
// All twelve layouts in the reference's order (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).
// All eleven layouts in the reference's order (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).
bool layout_at(int index, LayoutInfo* out);
// False when the name is unknown (case-sensitive, as the reference CLI). The
// legacy spelling "4.0" resolves to 4.0 Surround, which is what that name meant
// before the two 4.0 layouts were told apart.
// False when the name is unknown (case-sensitive, as the reference CLI). "4.0"
// is the quad layout (L R Lrs Rrs); a stored value is normalized by the caller
// before the name is looked up here.
bool layout_by_name(const char* name, LayoutInfo* out);
bool layout_by_bitfield(std::uint32_t bitfield, LayoutInfo* out);
+1 -49
View File
@@ -39,7 +39,7 @@ struct LayoutGeometry {
std::array<RegionGeometry, 7> regions{};
};
inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
inline constexpr std::array<LayoutGeometry, 11> kLayouts{{
LayoutGeometry{
0x1u, 0, 2,
{{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
@@ -136,54 +136,6 @@ inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
}
}}
},
LayoutGeometry{
0x23u, 0xFFu, 4,
{{0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{{
RegionGeometry{
4, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{16384, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{1, {3, 0, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
3, 1, 1, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
4, 2, 2, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{16384, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{1, {3, 0, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
2, 2, 2, 0,
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{16384, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{1, {1, 0, 0}}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
3, 1, 1, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
1, 1, 1, 0,
{{SpeakerPoint{{16384, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
},
RegionGeometry{
3, 1, 1, 0,
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
}
}}
},
LayoutGeometry{
0x9u, 0xFFu, 4,
{{0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+19 -72
View File
@@ -197,46 +197,16 @@ void read_local_tags(file::ptr const& source, file_info& info, abort_callback& a
}
}
// What the host is told about the delivered stream, and the order the renderer's
// channels have to be arranged in to match. The layout table says both; the
// engine's own channel count decides, because a mask must have exactly one bit per
// channel. A disagreement is logged and left unmasked rather than declared with a
// mask that does not describe the data.
joc_decode::LayoutDelivery delivery_for(const joc_decode::Settings& settings,
unsigned channels) {
constexpr unsigned kMaxChannels = joc_decode::kMaxLayoutChannels;
joc_decode::LayoutDelivery delivery;
delivery.channels = channels;
if (channels > kMaxChannels) {
for (unsigned channel = 0; channel < kMaxChannels; ++channel) {
delivery.order[channel] = channel;
}
joc_log::line("decoder: %u channel(s) is more than a layout is described for; "
"delivering unmasked",
channels);
return delivery;
}
if (settings.output == joc_decode::Output::kBinaural) {
delivery.mask = (channels == 2) ? (joc_decode::kSpeakerFrontLeft |
joc_decode::kSpeakerFrontRight)
: 0u;
for (unsigned channel = 0; channel < channels; ++channel) {
delivery.order[channel] = channel;
}
return delivery;
}
joc_decode::LayoutDelivery table;
if (joc_decode::layout_delivery(settings.speaker_layout, &table) &&
table.channels == channels) {
return table;
}
for (unsigned channel = 0; channel < channels; ++channel) {
delivery.order[channel] = channel;
}
joc_log::line("decoder: layout %s and the %u rendered channel(s) disagree; "
"delivering unmasked",
settings.speaker_layout.c_str(), channels);
return delivery;
// The chunk channel map handed to the host while playing. A map of zero (the
// SDK's "unspecified") is accepted by audio_chunk but rejected further down the
// output chain ("invalid audio stream specification"), and no WAVE map describes
// the renderer's order for the wider layouts, so the chunks carry the map the
// host itself uses for that channel count: it only transports the channel count
// and makes no claim about Dolby positions. The file properties stay unspecified
// (see get_info), so nothing downstream is told a position this layout does not
// have; the PCM keeps the layout table's order either way.
unsigned channel_map_for(unsigned channels) {
return audio_chunk::g_guess_channel_config(channels);
}
std::string mask_text(unsigned mask) {
@@ -394,7 +364,6 @@ public:
: ((duration > 0.0) ? static_cast<std::uint64_t>(duration * 48000.0 / 1536.0) : 0);
unsigned channels = 2;
unsigned mask = joc_decode::kSpeakerFrontLeft | joc_decode::kSpeakerFrontRight;
std::string render;
if (settings.output == joc_decode::Output::kBinaural) {
channels = 2;
@@ -403,10 +372,8 @@ public:
const unsigned layout_channels = joc_decode::speaker_channels(settings.speaker_layout);
channels = layout_channels != 0 ? layout_channels : 6;
render = "speaker " + settings.speaker_layout;
joc_decode::LayoutDelivery delivery;
mask = joc_decode::layout_delivery(settings.speaker_layout, &delivery) ? delivery.mask
: 0u;
}
const unsigned mask = channel_map_for(channels);
// The custom field and the log line state the delivery format, because it
// is the one thing about the output that a listener cannot hear.
if (settings.force_int24) render += ", 24-bit delivery";
@@ -415,11 +382,10 @@ public:
info.info_set("codec_long", "E-AC-3 JOC (Dolby Atmos)");
info.info_set("encoding", "lossy");
info.info_set_int("samplerate", kSampleRate);
// Channel count and mask together: a layout wider than stereo says which
// speaker each channel is, and the host keeps that as the file's
// WAVEFORMATEXTENSIBLE channel mask. The mask the decoder delivers is the
// same one, so what Properties says and what the output receives agree.
info.info_set_channels_ex(channels, mask);
// Properties declares the channel count but no channel map: the delivered
// order is not a WAVE speaker order for most layouts, and the chunk map
// used for playback only carries the count (see channel_map_for).
info.info_set_channels_ex(channels, channels == 2 ? mask : 0u);
// What the component hands over, which is what the host keeps if it writes a
// file from this stream: float32 by default, int24 when forced. This is also
// what foobar2000's own lossless-conversion warning reads
@@ -527,14 +493,9 @@ public:
}
m_channels = m_engine.channels();
if (m_channels == 0) m_channels = 2;
// The mask and the channel order come from the layout the file is being
// rendered to; binaural is plain stereo and needs neither.
m_delivery = delivery_for(m_settings, m_channels);
m_channel_config = m_delivery.mask != 0
? m_delivery.mask
: audio_chunk::g_guess_channel_config(m_channels);
// Only the map the component can describe is declared; see channel_map_for().
m_channel_config = channel_map_for(m_channels);
m_buffer.resize(kRunFrames * m_channels);
if (m_delivery.reordered) m_delivery_buffer.resize(kRunFrames * m_channels);
m_frames_delivered = 0;
m_reported = false;
m_delivery_mismatches = 0;
@@ -543,10 +504,9 @@ public:
// about everything this component handed over.
m_clipped_samples = 0;
m_clip_reported = false;
joc_log::line("decoder: engine ready, %u output channel(s), mask=%s%s, %u frames per "
joc_log::line("decoder: engine ready, %u output channel(s), mask=%s, %u frames per "
"read, delivery=%s",
m_channels, mask_text(m_channel_config).c_str(),
m_delivery.reordered ? " (channels permuted into mask order)" : "",
static_cast<unsigned>(kRunFrames),
m_settings.force_int24 ? "int24" : "float32");
}
@@ -581,16 +541,7 @@ public:
// the pipeline sees is the 24-bit grid rather than the renderer's float -- which
// is the whole point of the option. The quantisation happens here and nowhere
// else, so a sample is rounded once.
//
// 9.1.4 and 9.1.6 arrive in the renderer's order and have to be handed over in
// the order their channel mask implies; every other layout is already in that
// order, and then this is just the renderer's own buffer.
const float* samples = m_buffer.data();
if (m_delivery.reordered) {
joc_decode::apply_delivery_order(m_delivery, m_buffer.data(), frames,
m_delivery_buffer.data());
samples = m_delivery_buffer.data();
}
double expected_delivered_peak = 0.0;
if (m_settings.force_int24) {
@@ -745,12 +696,8 @@ private:
unsigned m_audio_index = 0;
joc_container::Result m_container;
std::vector<float> m_buffer;
// What the host is told about the stream (channel mask) and how the renderer's
// channels have to be arranged to match it; see joc_decode.h.
joc_decode::LayoutDelivery m_delivery;
// What the host is told about the stream's channel map; see channel_map_for().
unsigned m_channel_config = 0;
// Only used by the layouts whose renderer order differs from mask order.
std::vector<float> m_delivery_buffer;
// int24 delivery: the packed bytes handed to the host, and what the clip caught.
std::vector<std::uint8_t> m_int24;
std::uint64_t m_clipped_samples = 0;
+26 -127
View File
@@ -301,95 +301,34 @@ private:
HANDLE handle_ = INVALID_HANDLE_VALUE;
};
// The layouts the core accepts, in the core's own channel order. `speakers` are
// the reference table's names for the channels the renderer emits, `flags` are the
// WAVE speaker positions those channels are delivered as. The two lists are per
// channel, so a wrong entry shows up as a speaker name that does not belong to the
// flag next to it (tests/layout_table_test.cpp checks them against the kernel).
// The layouts the core accepts, with the channels in the order the renderer
// emits them. `speakers` are the reference table's names for those channels;
// the kernel is the authority on the list and on the channel counts, and
// tests/layout_table_test.cpp checks both.
//
// Where a name has two WAVE equivalents the reference table's own layout decides:
// the surround pair of 5.1 sits behind the listener (BL/BR, which is also what
// "5.1" means to ffmpeg), while 5.1.2 and up use the side pair (SL/SR). The wide
// pair of 9.1.x has one home only: FCL/FCR (ffmpeg spells the same two FLC/FRC).
//
// The two 4.0 layouts are different speaker sets, not two spellings of one layout:
// 4.0 Surround is a front trio plus one back-centre speaker (0x107), 4.0 Quad is a
// front pair and a back pair with neither centre nor LFE (0x33). The bare name
// "4.0" has always meant the former, so the kernel resolves it as an alias for it
// and a stored value is migrated to the explicit name.
//
// 9.1.6 is the one layout WAVE cannot describe completely: it has three height
// pairs, and the mask has positions for two (TFL/TFR, TBL/TBR) plus single centre
// positions. The top-middle pair -- ffmpeg's TSL/TSR, above a 32-bit mask -- is
// therefore delivered as the top front/back centre positions. Every mask here has
// exactly as many bits as the layout has channels, which is what the host and the
// converter require; the order the channels actually arrive in is the flags' own
// ascending order, see layout_delivery().
// 5.1's surround pair sits behind the listener (which is what the core's geometry
// says and what "5.1" means to WAVE), while 7.1 and up have a separate side pair
// and a rear pair. 9.1.x adds the wide pair in front. The two 5.1.x top pairs
// and the 7.1.x top pair sit above the listener's sides, and 9.1.6 adds the
// top-middle pair.
const LayoutSpec kLayouts[] = {
{"2.0", 2, {"L", "R"}, {kSpeakerFrontLeft, kSpeakerFrontRight}},
{"3.1",
4,
{"L", "R", "C", "LFE"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe}},
{"4.0 Surround",
4,
{"L", "R", "C", "Cs"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerBackCenter}},
{"4.0 Quad",
4,
{"L", "R", "Lrs", "Rrs"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerBackLeft, kSpeakerBackRight}},
{"5.1",
6,
{"L", "R", "C", "LFE", "Ls", "Rs"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight}},
{"7.1",
8,
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight}},
{"5.1.2",
8,
{"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerSideLeft, kSpeakerSideRight, kSpeakerTopFrontLeft, kSpeakerTopFrontRight}},
{"5.1.4",
10,
{"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerSideLeft, kSpeakerSideRight, kSpeakerTopFrontLeft, kSpeakerTopFrontRight,
kSpeakerTopBackLeft, kSpeakerTopBackRight}},
{"7.1.2",
10,
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltm", "Rtm"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
kSpeakerTopFrontLeft, kSpeakerTopFrontRight}},
{"7.1.4",
12,
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
kSpeakerTopBackRight}},
{"9.1.4",
14,
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr", "Lw",
"Rw"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
kSpeakerTopBackRight, kSpeakerFrontCenterLeft, kSpeakerFrontCenterRight}},
{"9.1.6",
16,
{"L", "R", "C", "LFE", "Lrs", "Rrs", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr", "Ltm",
"Rtm", "Lw", "Rw"},
{kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe,
kSpeakerBackLeft, kSpeakerBackRight, kSpeakerSideLeft, kSpeakerSideRight,
kSpeakerTopFrontLeft, kSpeakerTopFrontRight, kSpeakerTopBackLeft,
kSpeakerTopBackRight, kSpeakerTopFrontCenter, kSpeakerTopBackCenter,
kSpeakerFrontCenterLeft, kSpeakerFrontCenterRight}},
{"2.0", 2, {"L", "R"}},
{"3.1", 4, {"L", "R", "C", "LFE"}},
{"4.0", 4, {"L", "R", "Lrs", "Rrs"}},
{"5.1", 6, {"L", "R", "C", "LFE", "Ls", "Rs"}},
{"7.1", 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"}},
{"5.1.2", 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"}},
{"5.1.4", 10, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"}},
{"7.1.2", 10,
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltm", "Rtm"}},
{"7.1.4", 12,
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltf", "Rtf", "Ltr", "Rtr"}},
{"9.1.4", 14,
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw", "Ltf", "Rtf", "Ltr",
"Rtr"}},
{"9.1.6", 16,
{"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw", "Ltf", "Rtf", "Ltm",
"Rtm", "Ltr", "Rtr"}},
};
constexpr std::size_t kLayoutCount = sizeof(kLayouts) / sizeof(kLayouts[0]);
@@ -448,46 +387,6 @@ unsigned speaker_channels(const std::string& layout) {
return spec != nullptr ? spec->channels : 0;
}
bool layout_delivery(const std::string& layout, LayoutDelivery* out) {
const LayoutSpec* spec = find_layout(layout);
if (spec == nullptr || out == nullptr || spec->channels == 0 ||
spec->channels > kMaxLayoutChannels) {
return false;
}
LayoutDelivery delivery;
delivery.channels = spec->channels;
bool taken[kMaxLayoutChannels] = {};
for (unsigned channel = 0; channel < delivery.channels; ++channel) {
delivery.mask |= spec->flags[channel];
// The host reads the channels in the ascending order of their flags, so
// the channel delivered at position i is the i-th smallest flag.
unsigned best = delivery.channels;
for (unsigned candidate = 0; candidate < delivery.channels; ++candidate) {
if (taken[candidate]) continue;
if (best == delivery.channels || spec->flags[candidate] < spec->flags[best]) {
best = candidate;
}
}
delivery.order[channel] = best;
taken[best] = true;
if (best != channel) delivery.reordered = true;
}
*out = delivery;
return true;
}
void apply_delivery_order(const LayoutDelivery& delivery, const float* source,
std::size_t frames, float* target) {
const std::size_t channels = delivery.channels;
for (std::size_t frame = 0; frame < frames; ++frame) {
const float* in = source + frame * channels;
float* out = target + frame * channels;
for (std::size_t channel = 0; channel < channels; ++channel) {
out[channel] = in[delivery.order[channel]];
}
}
}
namespace {
// The core's conversion, reproduced: kernel/src/io/wav_writer.cpp:to_int32.
+12 -51
View File
@@ -106,49 +106,27 @@ struct Settings {
// ---- speaker delivery ------------------------------------------------------
//
// The renderer emits a layout in the reference table's own channel order. What
// foobar2000 receives has to be ordered by its channel mask instead, because the
// host defines the interleaved channel order as the ascending order of the mask's
// speaker flags (SDK audio_chunk.h: "order of interleaved channel data in the
// stream is same as order of these flags"). For most layouts both orders agree;
// 9.1.4 and 9.1.6 are the ones where they do not, and the channels are permuted
// here rather than declaring a mask that says the wrong thing about them.
//
// The flag values are the WAVE speaker positions, which is also what
// audio_chunk's channel map uses, so a mask can be handed to the host unchanged.
enum SpeakerFlag : unsigned {
kSpeakerFrontLeft = 0x1,
kSpeakerFrontRight = 0x2,
kSpeakerFrontCenter = 0x4,
kSpeakerLfe = 0x8,
kSpeakerBackLeft = 0x10,
kSpeakerBackRight = 0x20,
kSpeakerFrontCenterLeft = 0x40, // the wide pair of 9.1.x
kSpeakerFrontCenterRight = 0x80,
kSpeakerBackCenter = 0x100,
kSpeakerSideLeft = 0x200,
kSpeakerSideRight = 0x400,
kSpeakerTopCenter = 0x800,
kSpeakerTopFrontLeft = 0x1000,
kSpeakerTopFrontCenter = 0x2000,
kSpeakerTopFrontRight = 0x4000,
kSpeakerTopBackLeft = 0x8000,
kSpeakerTopBackCenter = 0x10000,
kSpeakerTopBackRight = 0x20000,
};
// The renderer emits a layout in the order the reference table defines for it,
// and that order is what foobar2000 receives. The host defines the interleaved
// channel order of a chunk as the ascending order of the channel map's speaker
// flags (SDK audio_chunk.h: "order of interleaved channel data in the stream is
// same as order of these flags"), so a channel map may only be declared when it
// describes exactly that order. Only stereo does, so the component declares no
// map for the file and gives each chunk the host's own default map for the channel
// count (see input_joc.cpp): the map carries the count, not positions, and the PCM
// is handed over unchanged. Channel numbers are the positions in the layout table
// below; mapping them to physical speakers belongs to the player or the user.
// The widest layout the core renders; the channel arrays below are sized for it.
inline constexpr unsigned kMaxLayoutChannels = 16;
// A layout the core accepts, with its channels in the order the renderer emits
// them. The names are the reference table's speaker names; the flags are the
// WAVE positions they are delivered as. Both are listed for the same channel, so
// the correspondence can be checked against the reference renderer's table.
// them. The names are the reference table's speaker names, so a channel can be
// checked against the kernel's table and against the reference renderer.
struct LayoutSpec {
const char* name;
unsigned channels;
const char* speakers[kMaxLayoutChannels];
unsigned flags[kMaxLayoutChannels];
};
// Every layout the core accepts, in the order a settings page should list them.
@@ -158,23 +136,6 @@ const LayoutSpec* layout_table(std::size_t* count);
// layouts the core accepts.
unsigned speaker_channels(const std::string& layout);
// What the host has to be told about a layout, and how the renderer's channels
// have to be arranged to match: delivered channel i is renderer channel order[i].
struct LayoutDelivery {
unsigned channels = 0;
unsigned mask = 0;
unsigned order[kMaxLayoutChannels] = {};
bool reordered = false;
};
// Fills *out for a layout the core accepts; returns false for anything else.
bool layout_delivery(const std::string& layout, LayoutDelivery* out);
// One interleaved block, renderer order -> delivery order. `source` and
// `target` may be the same buffer only when the layout needs no permutation.
void apply_delivery_order(const LayoutDelivery& delivery, const float* source,
std::size_t frames, float* target);
// Directory this component's DLL was loaded from. The default HRTF folder is
// <that directory>\HRTF, the same place the reference CLI looks next to its exe.
std::string component_directory();
+1 -2
View File
@@ -31,8 +31,7 @@ constexpr Entry kTexts[] = {
{Text::kLabelTail, "房间尾音(秒)", "Room tail (s)"},
{Text::kCheckInt24, "强制 24bit 输出(int24)", "Force 24-bit output (int24)"},
{Text::kInt24Hint, "切换后需刷新文件信息", "reload file info after switching"},
{Text::kSpeakerStatus, "扬声器布局 %s(%u 声道%s)", "Speaker layout %s (%u ch%s)"},
{Text::kSpeakerStatusAsio, ",需要 ASIO 输出", ", needs ASIO"},
{Text::kSpeakerStatus, "扬声器布局 %s", "Speaker layout %s"},
{Text::kGroupHrtf, "HRTF", "HRTF"},
{Text::kRadioSofa, "SOFA 文件", "SOFA file"},
{Text::kRadioRosella, "Rosella 个性化模型", "Rosella personalized model"},
-1
View File
@@ -33,7 +33,6 @@ enum class Text {
kCheckInt24,
kInt24Hint,
kSpeakerStatus,
kSpeakerStatusAsio,
kGroupHrtf,
kRadioSofa,
kRadioRosella,
+3 -19
View File
@@ -67,13 +67,6 @@ void set_text(HWND control, const std::string& text) {
SetWindowTextW(control, wide(text).c_str());
}
// The speaker configurations Windows itself has are 2.0, 5.1 and 7.1. Anything
// else -- a height channel, either 4.0 layout, more than eight channels -- is not
// carried by a shared or exclusive output, so the status line points at ASIO.
bool windows_speaker_config(unsigned mask) {
return mask == 0x3u || mask == 0x3Fu || mask == 0x63Fu;
}
// A drop-down list's items are rebuilt whenever the language changes, and the
// selection has to survive that.
void fill_combo(HWND combo, const std::vector<std::string>& items, int selected) {
@@ -451,9 +444,7 @@ private:
}
}
// The list comes from the core-facing table, so the page cannot offer a
// layout the decoder rejects. Offering one is not a promise that an output
// can play it: shared and exclusive outputs follow the Windows speaker
// configuration, ASIO passes any channel count through.
// layout the decoder rejects.
fill_combo(GetDlgItem(m_hwnd, IDC_COMBO_LAYOUT), names, layout_index);
apply_texts();
}
@@ -504,16 +495,9 @@ private:
std::string output_status;
if (values.output != 0) {
char text[192] = {};
const unsigned channels = joc_decode::speaker_channels(values.speaker_layout);
joc_decode::LayoutDelivery delivery;
const bool plain =
joc_decode::layout_delivery(values.speaker_layout, &delivery) &&
windows_speaker_config(delivery.mask);
std::snprintf(
text, sizeof(text),
std::snprintf(text, sizeof(text),
joc_lang::get(language, joc_lang::Text::kSpeakerStatus),
values.speaker_layout.c_str(), channels,
plain ? "" : joc_lang::get(language, joc_lang::Text::kSpeakerStatusAsio));
values.speaker_layout.c_str());
output_status = text;
}
set_text(GetDlgItem(m_hwnd, IDC_LABEL_OUTPUT_STATUS), output_status);
+2 -14
View File
@@ -34,7 +34,6 @@ constexpr GUID kGuidObjectDelay = {0x5b2e9c18, 0xa640, 0x4d7b, {0x92, 0x0e, 0x37
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}};
constexpr GUID kGuidLanguage = {0x58e17a04, 0x3d92, 0x4f6b, {0xa1, 0x27, 0x94, 0xc8, 0x0b, 0x6d, 0x53, 0xe1}};
cfg_uint g_output(kGuidOutput, 0);
cfg_string g_layout(kGuidLayout, "7.1");
// 0 = SOFA, 1 = Rosella model, 2 = compiled .jochrtf (advanced)
@@ -115,21 +114,10 @@ const char* hrtf_default_file_name(HrtfSource source) {
Values defaults() { return Values(); }
namespace {
// The layout name the decoder should use for a stored or overridden value: "4.0"
// is the spelling older configurations use for the layout the table calls 4.0
// Surround, so every caller sees one of the names in the layout table.
std::string canonical_layout(const std::string& layout) {
return (layout == "4.0") ? std::string("4.0 Surround") : layout;
}
} // namespace
Values read() {
Values values;
values.output = static_cast<int>(static_cast<unsigned>(g_output));
values.speaker_layout = canonical_layout(g_layout.get_ptr());
values.speaker_layout = g_layout.get_ptr();
// A layout the core does not accept (an old build offered several it never
// accepted) would fail when the renderer is created, and the page cannot show it
// either, because its list is the core's own table. Falling back here makes the
@@ -192,7 +180,7 @@ joc_decode::Settings current() {
std::string text;
if (env_string("JOC_OUTPUT", &text)) values.output = (text == "speaker") ? 1 : 0;
if (env_string("JOC_LAYOUT", &text)) values.speaker_layout = canonical_layout(text);
if (env_string("JOC_LAYOUT", &text)) values.speaker_layout = text;
(void)env_string("JOC_HRTF", &values.hrtf_file);
if (env_string("JOC_HRTF_SOURCE", &text)) {
values.hrtf_source = (text == "rosella") ? HrtfSource::kRosella : HrtfSource::kSofa;
+31 -110
View File
@@ -4,17 +4,13 @@
//
// The table in src/joc_decode.cpp is the one place that says which channels a
// layout has, what each of them is, and in which order they reach foobar2000. It
// is checked from three sides:
// is checked from two sides:
//
// * against the kernel's own frozen name table -- the names the renderer accepts
// and the channel counts it reports, so a layout the component offers that the
// kernel would reject (or a count that drifted apart) fails here;
// * against the reference renderer's channel order, which is written out below
// for every layout: the component's table lists the renderer's order, and the
// delivered order is that order permuted into the mask's ascending bit order;
// * against the host's contract: the mask has exactly one bit per channel, the
// delivered channel i is the i-th smallest flag, and apply_delivery_order()
// produces exactly that permutation.
// for every layout: the component hands the PCM over in exactly that order.
//
// No rendering and no files are involved, so this runs everywhere the kernel
// archive builds.
@@ -37,57 +33,28 @@ void check(bool condition, const char* what, const std::string& detail) {
std::printf("FAIL %s: %s\n", what, detail.c_str());
}
unsigned popcount(unsigned value) {
unsigned count = 0;
while (value != 0) {
count += value & 1u;
value >>= 1;
}
return count;
}
// What the reference renderer emits for each layout, in a space-separated form:
// the names in the order the renderer writes its channels (the reference table's
// `internal_to_standard` gathered names), the delivered order that follows from the
// mask's ascending bit order, and the mask the component must declare. The mask is
// the WAVE mask of the layout name, i.e. the one ffmpeg uses for the same name, with
// 9.1.6's top-middle pair at the only WAVE positions left for it (TFC/TBC).
// What the reference renderer emits for each layout, as a space-separated list:
// the names in the order the renderer writes its channels. The PCM handed to the
// host is that order unchanged (the chunk map is the host default for the count).
struct Expected {
const char* name;
const char* reference_order;
const char* delivered_order;
unsigned mask;
const char* order;
};
const Expected kExpected[] = {
{"2.0", "L R", "L R", 0x3},
{"3.1", "L R C LFE", "L R C LFE", 0xF},
{"4.0 Surround", "L R C Cs", "L R C Cs", 0x107},
{"4.0 Quad", "L R Lrs Rrs", "L R Lrs Rrs", 0x33},
{"5.1", "L R C LFE Ls Rs", "L R C LFE Ls Rs", 0x3F},
{"7.1", "L R C LFE Lrs Rrs Ls Rs", "L R C LFE Lrs Rrs Ls Rs", 0x63F},
{"5.1.2", "L R C LFE Ls Rs Ltm Rtm", "L R C LFE Ls Rs Ltm Rtm", 0x560F},
{"5.1.4", "L R C LFE Ls Rs Ltf Rtf Ltr Rtr", "L R C LFE Ls Rs Ltf Rtf Ltr Rtr", 0x2D60F},
{"7.1.2", "L R C LFE Lrs Rrs Ls Rs Ltm Rtm", "L R C LFE Lrs Rrs Ls Rs Ltm Rtm", 0x563F},
{"7.1.4", "L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr",
"L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr", 0x2D63F},
{"9.1.4", "L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr Lw Rw",
"L R C LFE Lrs Rrs Lw Rw Ls Rs Ltf Rtf Ltr Rtr", 0x2D6FF},
{"9.1.6", "L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr Ltm Rtm Lw Rw",
"L R C LFE Lrs Rrs Lw Rw Ls Rs Ltf Ltm Rtf Ltr Rtm Rtr", 0x3F6FF},
{"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"},
};
// The channel names of a layout as the component will deliver them: the renderer's
// order permuted into the mask's ascending bit order.
std::vector<std::string> delivered_names(const joc_decode::LayoutSpec& spec,
const joc_decode::LayoutDelivery& delivery) {
std::vector<std::string> names;
for (unsigned i = 0; i < delivery.channels; ++i) {
names.push_back(spec.speakers[delivery.order[i]]);
}
return names;
}
std::string join(const std::vector<std::string>& words) {
std::string text;
for (const std::string& word : words) {
@@ -108,14 +75,10 @@ void check_layout(const Expected& expected) {
check(spec != nullptr, "layout is in the table", name);
if (spec == nullptr) return;
joc_decode::LayoutDelivery delivery;
check(joc_decode::layout_delivery(name, &delivery), "layout_delivery", name);
check(delivery.channels == spec->channels, "channel count", name);
check(popcount(delivery.mask) == delivery.channels, "mask has one bit per channel",
name + " mask=" + std::to_string(delivery.mask));
check(delivery.mask == expected.mask,
"mask", name + " expected " + std::to_string(expected.mask) + " got " +
std::to_string(delivery.mask));
check(spec->channels == joc_decode::speaker_channels(name),
"channel count matches speaker_channels()", name);
check(spec->channels <= joc_decode::kMaxLayoutChannels, "channel count fits the table",
name);
// The kernel is the authority on which names exist and how wide they are.
joc::speaker::LayoutInfo kernel;
@@ -127,50 +90,13 @@ void check_layout(const Expected& expected) {
// The table lists the reference renderer's order, and the reference order is
// what the expected list says.
std::vector<std::string> reference;
for (unsigned i = 0; i < spec->channels; ++i) reference.push_back(spec->speakers[i]);
check(join(reference) == expected.reference_order,
"reference channel order", name + " got " + join(reference));
// Delivered order: a permutation of [0, channels), the flag at position i is
// strictly below the flag at position i + 1, and the names come out as listed.
std::vector<bool> seen(delivery.channels, false);
for (unsigned i = 0; i < delivery.channels; ++i) {
check(delivery.order[i] < delivery.channels, "order index in range", name);
if (delivery.order[i] < delivery.channels) {
check(!seen[delivery.order[i]], "order is a permutation", name);
seen[delivery.order[i]] = true;
}
if (i != 0) {
const unsigned previous = spec->flags[delivery.order[i - 1]];
const unsigned current = spec->flags[delivery.order[i]];
check(previous < current, "delivered order follows the mask", name);
}
}
const std::string delivered = join(delivered_names(*spec, delivery));
check(delivered == expected.delivered_order,
"delivered order", name + " got " + delivered);
check(delivery.reordered == (delivered != expected.reference_order), "reordered flag",
name);
// apply_delivery_order has to do exactly what order[] says, on a block whose
// samples are the channel index.
const std::size_t frames = 2;
std::vector<float> source(frames * delivery.channels);
for (std::size_t frame = 0; frame < frames; ++frame) {
for (unsigned channel = 0; channel < delivery.channels; ++channel) {
source[frame * delivery.channels + channel] = static_cast<float>(channel);
}
}
std::vector<float> target(source.size(), -1.0f);
joc_decode::apply_delivery_order(delivery, source.data(), frames, target.data());
for (std::size_t frame = 0; frame < frames; ++frame) {
for (unsigned channel = 0; channel < delivery.channels; ++channel) {
const float value = target[frame * delivery.channels + channel];
check(value == static_cast<float>(delivery.order[channel]),
"apply_delivery_order", name);
}
std::vector<std::string> channels;
for (unsigned i = 0; i < spec->channels; ++i) {
check(spec->speakers[i] != nullptr && spec->speakers[i][0] != '\0',
"channel has a name", name + " channel " + std::to_string(i));
channels.push_back(spec->speakers[i] != nullptr ? spec->speakers[i] : "");
}
check(join(channels) == expected.order, "channel order", name + " got " + join(channels));
}
} // namespace
@@ -199,17 +125,12 @@ int main() {
for (const Expected& expected : kExpected) check_layout(expected);
// Names the table must not claim: the page used to offer these, and the kernel
// rejects every one of them. ("4.0" is not in this list: the kernel resolves it
// to 4.0 Surround for old configurations, and the settings migration rewrites it
// to the explicit name.)
for (const char* rejected : {"3.0", "5.0", "6.1", "7.0", "22.2", ""}) {
// Names the table must not claim: the component and the kernel treat every one
// of them as an unknown layout.
for (const char* rejected : {"3.0", "5.0", "6.1", "7.0", "22.2", "4.0 Surround",
"4.0 Quad", ""}) {
check(joc_decode::speaker_channels(rejected) == 0, "unsupported layout rejected",
rejected);
joc_decode::LayoutDelivery delivery;
check(!joc_decode::layout_delivery(rejected, &delivery), "unsupported layout has no "
"delivery",
rejected);
}
if (g_failures == 0) {
+4 -16
View File
@@ -4,7 +4,7 @@
// ui_text_fit_test <path to foo_input_joc.dll>
//
// The page is bilingual, and the wider language is not always the translated one:
// "4.0 Surround" does not fit where "4.0" did. This check creates the dialog from
// the English label is sometimes the longer one. This check creates the dialog from
// the component's own resource (the same way the component does), then measures
// each string with the control's own font and compares it with the space that
// control has. Multi-line static controls are wrapped at word boundaries, so a
@@ -174,10 +174,6 @@ std::size_t index_of(joc_lang::Text text) {
return static_cast<std::size_t>(-1);
}
bool windows_speaker_config(unsigned mask) {
return mask == 0x3u || mask == 0x3Fu || mask == 0x63Fu;
}
void check_control(Measurer& measurer, HWND dialog, const Binding& binding,
const std::string& language) {
HWND control = GetDlgItem(dialog, binding.control);
@@ -257,10 +253,9 @@ void check_combo(Measurer& measurer, HWND control, const std::string& language,
}
}
std::string format(const char* pattern, const char* layout, unsigned channels,
const char* suffix) {
std::string format(const char* pattern, const char* layout) {
char buffer[256] = {};
std::snprintf(buffer, sizeof(buffer), pattern, layout, channels, suffix);
std::snprintf(buffer, sizeof(buffer), pattern, layout);
return buffer;
}
@@ -347,16 +342,9 @@ int main(int argc, char** argv) {
// Status lines the page writes at run time.
const HWND output_status = GetDlgItem(dialog, IDC_LABEL_OUTPUT_STATUS);
for (std::size_t i = 0; i < layout_count; ++i) {
joc_decode::LayoutDelivery delivery;
const bool plain =
joc_decode::layout_delivery(layouts[i].name, &delivery) &&
windows_speaker_config(delivery.mask);
check_line(measurer, output_status, language,
format(joc_lang::get(resolved, joc_lang::Text::kSpeakerStatus),
layouts[i].name, layouts[i].channels,
plain ? ""
: joc_lang::get(resolved,
joc_lang::Text::kSpeakerStatusAsio)));
layouts[i].name));
}
// The page shortens the path line before it is shown, so only the two-line
// envelope of the status field is measured: the label, and the longest text