diff --git a/README.en.md b/README.en.md index 59cacce..be1dbb2 100644 --- a/README.en.md +++ b/README.en.md @@ -5,7 +5,7 @@ A foobar2000 input component for **E-AC-3 JOC (Dolby Atmos)** files: the JOC object and OAMD metadata is taken from the E-AC-3 syncframes and paired with the core PCM that ffmpeg decodes (5.1 or 7 channels, following $joc\_dmx\_config\_idx$), then rendered in real time to headphones -(HRTF) or to a speaker layout up to 7.1. The +(HRTF) or to a speaker layout from 2.0 up to 9.1.6. The rendering core is compiled into the component, so there is nothing to install beside `foo_input_joc.dll`. @@ -59,7 +59,8 @@ Matroska/WebM Reader** in that list. Bare `.eac3` / `.ec3` files do not depend o Preferences → Tools → **JOC decoder**: -* **Output** — binaural, or a speaker layout from 2.0 to 7.1; +* **Output** — binaural, or a speaker layout from 2.0 to 9.1.6 (see + [Speaker layouts and channel order](#speaker-layouts-and-channel-order)); * **Binaural mode** (near / mid / far) and the room **tail** in seconds; * **HRTF source** — a **SOFA** file or a **Rosella** `.personalized_headphone` model. An empty path means the default location, `\HRTF\binaural.sofa` or @@ -79,6 +80,45 @@ Preferences → Tools → **JOC decoder**: No control on the page is disabled, and the status line states what is in effect. +### 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 | +| 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 | + +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; 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), 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. + +**Layouts other than 2.0 / 5.1 / 7.1 need ASIO (or an exclusive output that accepts the +layout).** foobar2000's shared and exclusive outputs follow the Windows speaker configuration, of +which those are the only multichannel ones; 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 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 @@ -99,9 +139,10 @@ byte-for-byte acceptance rests on, so it must not be changed. `foo_input_joc.vcx `kernel\joc_kernel.vcxproj` first through a project reference; the rendering core sources in `kernel/` are compiled with `JOC_STATIC` / `EJOC_STATIC`, so their entry points are neither imported nor exported. `tests\` holds the offline tools (bitstream self-test and cross-check, -render comparison, preferences-page layout check, container-probe check) and `tools\` the build -and test-bed scripts. Settings also read `JOC_*` environment overrides for one run (development -only); the list and what each one does is in `src\settings.cpp`. +render comparison, speaker-layout table and channel-order check, preferences-page layout check, +container-probe check) and `tools\` the build and test-bed scripts. Settings also read `JOC_*` +environment overrides for one run (development only); the list and what each one does is in +`src\settings.cpp`. To diagnose a problem, read `joc_decoder.log` beside the DLL: the component writes its own version, the core version and the log path there at start-up. The log is capped by **bytes**: a @@ -113,6 +154,10 @@ every container in the library, which is where the volume comes from. ## Known limitations * 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). * 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 diff --git a/README.md b/README.md index 0904dce..7aa1391 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [English](README.en.md) · [安装](#安装) · [设置](#设置) · [构建](#构建) · [已知限制](#已知限制) foobar2000 输入组件,播放 **E-AC-3 JOC(Dolby Atmos)** 文件:从 E-AC-3 同步帧里取出 JOC -对象与 OAMD 元数据,与 ffmpeg 解出的核心 PCM(按 $joc\_dmx\_config\_idx$ 为 5.1 或 7 通道)配对后实时渲染,输出双耳(HRTF)或最多 -7.1 的扬声器布局。渲染内核直接编译进组件,除 `foo_input_joc.dll` 之外不需要安装任何东西。 +对象与 OAMD 元数据,与 ffmpeg 解出的核心 PCM(按 $joc\_dmx\_config\_idx$ 为 5.1 或 7 通道)配对后实时渲染,输出双耳(HRTF)或 +2.0 到 9.1.6 的扬声器布局。渲染内核直接编译进组件,除 `foo_input_joc.dll` 之外不需要安装任何东西。 输入是裸流 `.eac3` / `.ec3`,或容器里的 E-AC-3 JOC 轨道(`.mp4` `.m4a` `.m4b` `.m4p` `.m4r` `.mov` `.mkv` `.mka` `.webm`)。文件里没有 JOC 就不接管:普通 AC-3 / E-AC-3、音频轨道 @@ -52,7 +52,7 @@ Matroska/WebM Reader** 之前。裸流 `.eac3` / `.ec3` 不受这个顺序影响 Preferences → Tools → **JOC decoder**: -* **Output** —— 双耳,或 2.0 到 7.1 的扬声器布局; +* **Output** —— 双耳,或 2.0 到 9.1.6 的扬声器布局(见[扬声器布局与声道顺序](#扬声器布局与声道顺序)); * **Binaural mode**(near / mid / far)与房间 **tail** 秒数; * **HRTF source** —— **SOFA** 文件或 **Rosella** `.personalized_headphone` 模型。路径留空表示 用默认位置 `<组件目录>\HRTF\` 下的 `binaural.sofa` 或 `binaural.personalized_headphone`; @@ -67,6 +67,39 @@ Preferences → Tools → **JOC decoder**: 页面上的控件都不禁用,状态行会说明当前生效的是什么。 +### 扬声器布局与声道顺序 + +| 布局 | 声道 | 通道掩码 | 交付顺序(声明的声道位置) | +|---|---|---|---| +| 2.0 | 2 | `0x3` | FL FR | +| 3.1 | 4 | `0xF` | FL FR FC LFE | +| 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 | + +渲染内核按参考实现的顺序产生声道(9.1.4 是 L R C LFE Lrs Rrs Ls Rs Ltf Rtf Ltr Rtr Lw Rw), +而 foobar2000 规定"帧内声道顺序 = 通道掩码中声道位的升序"。两者对 2.0 到 7.1.4 恰好一致; +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),这样同一 +个布局名在组件、转换产物与其它工具里含义一致。**9.1.6 的顶层中间声道对(Ltm/Rtm)在 WAVE 的 18 +个声道位里没有对应位置**(ffmpeg 用 32 位掩码之外的 TSL/TSR),因此按 TFL/TFC/TFR/TBL/TBC/TBR 中 +剩下的两个居中位置 TFC 与 TBC 交付:掩码仍然是一位声道一个位,顺序如上表,代价是这两路在 +foobar2000 的声道列表里显示为顶前排中、顶后排中。 + +**2.0 / 5.1 / 7.1 之外的布局需要 ASIO(或接受该布局的独占输出)。** foobar2000 的共享与独占输出 +跟随 Windows 的扬声器配置,只有这几个配置;高度声道、宽声道与超过 8 声道的布局 ASIO 没有限制,声道 +按组件交付的顺序对应到设备的输出通道(用 fb2k 的 ASIO 声道映射按名称分配)。用这样的布局而输出仍 +走系统配置时,核心会把多出来的声道下混——能听到声音,但听不到那几路;转换器(Converter)不受输出 +设备限制,可以按布局写出 14/16 声道的文件。设置页的状态行在选中这类布局时会写"需要 ASIO 输出"。 + ### HRTF 数据 SOFA 测量集或个性化耳机模型由使用组件的人自己提供,并且写在 `.gitignore` 里,避免误提交。 @@ -84,8 +117,8 @@ pwsh -File tools/package.ps1 # 两个架构,打包到 dist\*.fb2k-c 配置固定为 `Release-Static`(静态 CRT,`/MT`);`/fp:precise` 是逐字节验收的前提,不要改。 `foo_input_joc.vcxproj` 通过项目引用先构建 `kernel\joc_kernel.vcxproj`;`kernel/` 里的渲染内核 源码以 `JOC_STATIC` / `EJOC_STATIC` 编译,入口既不导入也不导出。`tests\` 是离线工具(码流 -自检与交叉核对、渲染比对、设置页布局检查、容器探测检查),`tools\` 是构建与测试床脚本。设置项 -另有 `JOC_*` 环境变量覆盖(仅用于开发运行),清单与含义在 `src\settings.cpp`。 +自检与交叉核对、渲染比对、布局表与频道顺序检查、设置页布局检查、容器探测检查),`tools\` 是构建 +与测试床脚本。设置项另有 `JOC_*` 环境变量覆盖(仅用于开发运行),清单与含义在 `src\settings.cpp`。 排查问题看 DLL 旁边的 `joc_decoder.log`;组件启动时会把自己的版本、核心版本、日志路径写在 里面。日志按**字节**封顶:单个文件写满 16 MiB 就滚到同目录的 `joc_decoder.log.1`(覆盖上一次 @@ -95,6 +128,9 @@ 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 交付(同上)。 * $joc\_dmx\_config\_idx$ 全部五个档位都支持:取床按音频帧配对,床通道数由档位决定(0/3 为 6 通道,1/2/4 为 8 通道),ffmpeg 只在 6 通道档位传 `-ac 6`。AC-3 核心 + 依赖子流 (`strmtyp=1`)与"首个音频帧没有 JOC"都按正常情况处理。 diff --git a/src/input_joc.cpp b/src/input_joc.cpp index 1fba448..fb5222f 100644 --- a/src/input_joc.cpp +++ b/src/input_joc.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -196,6 +197,54 @@ 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; +} + +std::string mask_text(unsigned mask) { + char text[16] = {}; + std::snprintf(text, sizeof(text), "0x%X", mask); + return text; +} + class input_joc : public input_stubs { public: void open(service_ptr_t hint, const char* path, t_input_open_reason reason, @@ -345,6 +394,7 @@ public: : ((duration > 0.0) ? static_cast(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; @@ -353,6 +403,9 @@ 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; } // 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. @@ -362,7 +415,11 @@ public: info.info_set("codec_long", "E-AC-3 JOC (Dolby Atmos)"); info.info_set("encoding", "lossy"); info.info_set_int("samplerate", kSampleRate); - info.info_set_int("channels", channels); + // 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); // 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 @@ -424,8 +481,10 @@ public: read_local_tags(m_file, info, abort); } - joc_log::line("decoder: get_info duration=%.3f s frames=%llu channels=%u render=%s%s", - duration, static_cast(frames), channels, render.c_str(), + joc_log::line("decoder: get_info duration=%.3f s frames=%llu channels=%u mask=%s " + "render=%s%s", + duration, static_cast(frames), channels, + mask_text(mask).c_str(), render.c_str(), container ? " (container)" : ""); } @@ -459,7 +518,14 @@ 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); 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; @@ -468,10 +534,12 @@ 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), %u frames per read, " - "delivery=%s", - m_channels, static_cast(kRunFrames), - m_settings.force_int24 ? "int24" : "float32"); + joc_log::line("decoder: engine ready, %u output channel(s), mask=%s%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(kRunFrames), + m_settings.force_int24 ? "int24" : "float32"); } bool decode_run(audio_chunk& chunk, abort_callback& abort) { @@ -504,11 +572,22 @@ 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) { m_int24.resize(frames * m_channels * 3); const joc_decode::Int24Block block = joc_decode::pack_int24( - m_buffer.data(), frames * m_channels, m_int24.data()); + samples, frames * m_channels, m_int24.data()); m_clipped_samples += block.clipped; if (block.clipped != 0 && !m_clip_reported) { m_clip_reported = true; @@ -518,13 +597,13 @@ public: static_cast(block.clipped)); } chunk.set_data_fixedpoint_signed(m_int24.data(), m_int24.size(), kSampleRate, - m_channels, 24, - audio_chunk::g_guess_channel_config(m_channels)); + m_channels, 24, m_channel_config); expected_delivered_peak = static_cast(block.peak) / joc_decode::kInt24ImportScale; } else { - chunk.set_data_32(m_buffer.data(), frames, m_channels, kSampleRate); - expected_delivered_peak = peak_of(m_buffer.data(), frames * m_channels); + chunk.set_data_32(samples, frames, + audio_chunk::makeSpec(kSampleRate, m_channels, m_channel_config)); + expected_delivered_peak = peak_of(samples, frames * m_channels); } m_frames_delivered += frames; @@ -652,6 +731,12 @@ private: unsigned m_audio_index = 0; joc_container::Result m_container; std::vector 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; + unsigned m_channel_config = 0; + // Only used by the layouts whose renderer order differs from mask order. + std::vector m_delivery_buffer; // int24 delivery: the packed bytes handed to the host, and what the clip caught. std::vector m_int24; std::uint64_t m_clipped_samples = 0; diff --git a/src/joc_decode.cpp b/src/joc_decode.cpp index b335d5d..5abf6b3 100644 --- a/src/joc_decode.cpp +++ b/src/joc_decode.cpp @@ -301,10 +301,91 @@ 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", "22.2"}; -const unsigned kLayoutChannels[] = {2, 3, 4, 4, 5, 6, 8, 10, 7, 7, 8, 10, 12, 14, 16, 24}; +// 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). +// +// 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). +// +// 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(). +const LayoutSpec kLayouts[] = { + {"2.0", 2, {"L", "R"}, {kSpeakerFrontLeft, kSpeakerFrontRight}}, + {"3.1", + 4, + {"L", "R", "C", "LFE"}, + {kSpeakerFrontLeft, kSpeakerFrontRight, kSpeakerFrontCenter, kSpeakerLfe}}, + {"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}}, +}; + +constexpr std::size_t kLayoutCount = sizeof(kLayouts) / sizeof(kLayouts[0]); + +const LayoutSpec* find_layout(const std::string& name) { + for (std::size_t i = 0; i < kLayoutCount; ++i) { + if (name == kLayouts[i].name) return &kLayouts[i]; + } + return nullptr; +} // 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 @@ -343,16 +424,54 @@ 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]); +const LayoutSpec* layout_table(std::size_t* count) { + if (count != nullptr) *count = kLayoutCount; 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]; + const LayoutSpec* spec = find_layout(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]]; + } } - return 0; } namespace { diff --git a/src/joc_decode.h b/src/joc_decode.h index e972f55..061d149 100644 --- a/src/joc_decode.h +++ b/src/joc_decode.h @@ -104,10 +104,77 @@ struct Settings { bool force_int24 = false; }; +// ---- 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 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. +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. +const LayoutSpec* layout_table(std::size_t* count); + // Channel count of a named layout, or 0 when the layout is not one of the // 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 // \HRTF, the same place the reference CLI looks next to its exe. std::string component_directory(); @@ -117,9 +184,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/main.cpp b/src/main.cpp index b3c2d1e..1274105 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,12 +12,12 @@ // Kept in one place: the string reported to foobar2000 and written to the log // must not drift apart. -#define JOC_VERSION "0.4.0" +#define JOC_VERSION "0.5.0" DECLARE_COMPONENT_VERSION("JOC decoder (E-AC-3 JOC)", JOC_VERSION, "Plays E-AC-3 JOC (Dolby Atmos) files: the JOC objects are " "rendered to binaural (SOFA or Rosella HRTF) or to a speaker " - "layout up to 7.1."); + "layout up to 9.1.6."); // Refuses to run when the file has been renamed; the troubleshooter relies on it. VALIDATE_COMPONENT_FILENAME("foo_input_joc.dll"); diff --git a/src/prefs.cpp b/src/prefs.cpp index adf1800..781c923 100644 --- a/src/prefs.cpp +++ b/src/prefs.cpp @@ -60,17 +60,18 @@ void set_text(HWND control, const std::string& text) { SetWindowTextW(control, wide(text).c_str()); } -// Layouts are offered up to 7.1 on purpose: output chains handle eight channels -// comfortably, and wider layouts are only meaningful when writing a file. -struct LayoutChoice { - const char* name; - const char* label; -}; -const LayoutChoice kLayoutChoices[] = { - {"2.0", "2.0 (立体声)"}, {"3.0", "3.0"}, {"3.1", "3.1"}, {"4.0", "4.0"}, - {"5.0", "5.0"}, {"5.1", "5.1"}, {"6.1", "6.1"}, {"7.0", "7.0"}, - {"7.1", "7.1"}, -}; +// The layouts the page offers come from the core-facing table (layout_table()), so +// it cannot offer one the decoder rejects. Offering them is not a promise that +// every output can play them: foobar2000's shared and exclusive outputs follow the +// Windows speaker configuration, while an ASIO output passes any channel count and +// any layout through. +// +// The speaker configurations Windows itself has are 2.0, 5.1 and 7.1. Anything +// else -- a height channel, the wide pair, 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; +} const char* const kModeNames[] = {"near", "far", "mid"}; const char* const kModeLabels[] = {"near(近场)", "far(远场)", "mid(默认)"}; @@ -270,11 +271,13 @@ private: HWND layout = GetDlgItem(m_hwnd, IDC_COMBO_LAYOUT); SendMessageW(layout, CB_RESETCONTENT, 0, 0); + std::size_t layout_count = 0; + const joc_decode::LayoutSpec* layouts = joc_decode::layout_table(&layout_count); int selected = 0; - for (unsigned i = 0; i < sizeof(kLayoutChoices) / sizeof(kLayoutChoices[0]); ++i) { + for (std::size_t i = 0; i < layout_count; ++i) { SendMessageW(layout, CB_ADDSTRING, 0, - reinterpret_cast(wide(kLayoutChoices[i].label).c_str())); - if (values.speaker_layout == kLayoutChoices[i].name) selected = static_cast(i); + reinterpret_cast(wide(layouts[i].name).c_str())); + if (values.speaker_layout == layouts[i].name) selected = static_cast(i); } SendMessageW(layout, CB_SETCURSEL, selected, 0); @@ -312,9 +315,10 @@ private: const int layout_index = static_cast(SendDlgItemMessageW(m_hwnd, IDC_COMBO_LAYOUT, CB_GETCURSEL, 0, 0)); - if (layout_index >= 0 && - layout_index < static_cast(sizeof(kLayoutChoices) / sizeof(kLayoutChoices[0]))) { - values.speaker_layout = kLayoutChoices[layout_index].name; + std::size_t layout_count = 0; + const joc_decode::LayoutSpec* layouts = joc_decode::layout_table(&layout_count); + if (layout_index >= 0 && static_cast(layout_index) < layout_count) { + values.speaker_layout = layouts[layout_index].name; } const int mode_sel = static_cast(SendDlgItemMessageW(m_hwnd, IDC_COMBO_MODE, CB_GETCURSEL, 0, 0)); @@ -350,10 +354,15 @@ private: const joc_settings::Values values = read_controls(); std::string output_status; if (values.output != 0) { - char text[96] = {}; + char text[160] = {}; const unsigned channels = joc_decode::speaker_channels(values.speaker_layout); - std::snprintf(text, sizeof(text), "扬声器布局 %s(%u 声道)", - values.speaker_layout.c_str(), channels); + 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), "扬声器布局 %s(%u 声道%s)", + values.speaker_layout.c_str(), channels, + plain ? "" : ",需要 ASIO 输出"); output_status = text; } set_text(GetDlgItem(m_hwnd, IDC_LABEL_OUTPUT_STATUS), output_status); diff --git a/src/settings.cpp b/src/settings.cpp index c8ce551..36d2fc9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -115,7 +116,19 @@ Values read() { Values values; values.output = static_cast(static_cast(g_output)); values.speaker_layout = g_layout.get_ptr(); - if (values.speaker_layout.empty()) values.speaker_layout = "7.1"; + // 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 + // stored value usable again and the page show what will actually be rendered. + if (joc_decode::speaker_channels(values.speaker_layout) == 0) { + static std::atomic warned{false}; + if (!warned.exchange(true, std::memory_order_relaxed)) { + joc_log::line("settings: stored speaker layout \"%s\" is not one the core " + "accepts; using 7.1", + values.speaker_layout.c_str()); + } + values.speaker_layout = "7.1"; + } const unsigned source = static_cast(g_hrtf_source); values.hrtf_source = (source == 1u) ? HrtfSource::kRosella : HrtfSource::kSofa; values.hrtf_file = g_hrtf_file.get_ptr(); diff --git a/tests/layout_table_test.cpp b/tests/layout_table_test.cpp new file mode 100644 index 0000000..864b825 --- /dev/null +++ b/tests/layout_table_test.cpp @@ -0,0 +1,217 @@ +// Offline check of the speaker-layout table the component delivers with. +// +// layout_table_test +// +// 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: +// +// * 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. +// +// No rendering and no files are involved, so this runs everywhere the kernel +// archive builds. + +#include +#include +#include +#include + +#include "../src/joc_decode.h" +#include "speaker/speaker_layout_lookup.h" + +namespace { + +int g_failures = 0; + +void check(bool condition, const char* what, const std::string& detail) { + if (condition) return; + ++g_failures; + 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). +struct Expected { + const char* name; + const char* reference_order; + const char* delivered_order; + unsigned mask; +}; + +const Expected kExpected[] = { + {"2.0", "L R", "L R", 0x3}, + {"3.1", "L R C LFE", "L R C LFE", 0xF}, + {"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}, +}; + +// 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 delivered_names(const joc_decode::LayoutSpec& spec, + const joc_decode::LayoutDelivery& delivery) { + std::vector 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& words) { + std::string text; + for (const std::string& word : words) { + if (!text.empty()) text += ' '; + text += word; + } + return text; +} + +void check_layout(const Expected& expected) { + const std::string name = expected.name; + const joc_decode::LayoutSpec* spec = nullptr; + std::size_t count = 0; + const joc_decode::LayoutSpec* table = joc_decode::layout_table(&count); + for (std::size_t i = 0; i < count; ++i) { + if (name == table[i].name) spec = &table[i]; + } + 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)); + + // The kernel is the authority on which names exist and how wide they are. + joc::speaker::LayoutInfo kernel; + check(joc::speaker::layout_by_name(name.c_str(), &kernel), "kernel accepts the layout", + name); + check(kernel.channel_count == spec->channels, "kernel channel count", + name + " kernel " + std::to_string(kernel.channel_count) + " table " + + std::to_string(spec->channels)); + + // The table lists the reference renderer's order, and the reference order is + // what the expected list says. + std::vector 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 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 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(channel); + } + } + std::vector 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(delivery.order[channel]), + "apply_delivery_order", name); + } + } +} + +} // namespace + +int main() { + // The component's table and the kernel's frozen table have to be the same list + // of layouts, in the same order: the preferences page shows one, the renderer + // accepts the other. + std::size_t count = 0; + const joc_decode::LayoutSpec* table = joc_decode::layout_table(&count); + check(count == static_cast(joc::speaker::kLayoutCount), + "layout count matches the kernel", + std::to_string(count) + " vs " + std::to_string(joc::speaker::kLayoutCount)); + const std::size_t expected_count = sizeof(kExpected) / sizeof(kExpected[0]); + check(count == expected_count, "layout count matches the expected list", + std::to_string(count) + " vs " + std::to_string(expected_count)); + for (std::size_t i = 0; i < count && i < expected_count; ++i) { + check(std::strcmp(table[i].name, kExpected[i].name) == 0, "layout order", + std::string(table[i].name) + " vs " + kExpected[i].name); + joc::speaker::LayoutInfo kernel; + if (joc::speaker::layout_at(static_cast(i), &kernel)) { + check(std::strcmp(table[i].name, kernel.name) == 0, "layout name at index", + std::string(table[i].name) + " vs " + kernel.name); + } + } + + 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. + for (const char* rejected : {"3.0", "4.0", "5.0", "6.1", "7.0", "22.2", ""}) { + 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) { + std::printf("layout_table_test: %zu layouts, 0 problem(s)\n", count); + return 0; + } + std::printf("layout_table_test: %d problem(s)\n", g_failures); + return 1; +} diff --git a/tools/build_tests.ps1 b/tools/build_tests.ps1 index 17f538b..0cac7e9 100644 --- a/tools/build_tests.ps1 +++ b/tools/build_tests.ps1 @@ -46,6 +46,7 @@ $lines = @( "cl $common /Fe:`"$outDir\prefs_layout_check.exe`" /Fo:`"$outDir\\`" tests\prefs_layout_check.cpp user32.lib gdi32.lib", "cl $common /Fe:`"$outDir\scan_crosscheck.exe`" /Fo:`"$outDir\\`" tests\scan_crosscheck.cpp src\eac3_scan.cpp `"$coreLib`" shell32.lib", "cl $common /Fe:`"$outDir\render_harness.exe`" /Fo:`"$outDir\\`" tests\render_harness.cpp src\joc_decode.cpp src\eac3_scan.cpp src\container_scan.cpp src\log.cpp `"$coreLib`" shell32.lib", + "cl $common /Fe:`"$outDir\layout_table_test.exe`" /Fo:`"$outDir\\`" tests\layout_table_test.cpp src\joc_decode.cpp src\eac3_scan.cpp src\container_scan.cpp src\log.cpp `"$coreLib`" shell32.lib", 'if errorlevel 1 exit /b 1', 'exit /b 0' )