Files
foo_input_joc/tests/layout_table_test.cpp
TheM14 defe9538fe Sync the kernel copy with the OAMD frame-level core
The kernel copy follows the new kernel. The renderer has a frame-level state
machine (normal, hold, hard cut and passthrough, the 8-plane passthrough, the
LFE clipgain ramp and interpolation when no previous state exists), the OAMD
parser carries the complete frame state (several blocks, more than 16 objects)
and the speaker renderer applies the metadata (gain and inactive flags,
zone/elevation, size, snap, divergence, ISF and bed distribution). oamd_math and
oamd_params are new modules, the ISF tables are compiled in now that the
upstream data/ directory is gone, and the binaural timeline accepts a complete
frame state. joc_core.h moves to ABI 6 (frame parameters and EMDF payload info
at v2, JOC_FRAME_STATUS_*, raw 5-bit offset_ts) and eac3joc_core.h to EJOC ABI 4
(EJOC_FRAME_STATUS_*, ejoc_frame_input v1, ejoc_renderer_render_frame,
EJOC_CORE_OUT_CHANNELS and EJOC_LFE_SLOT; the old ejoc_renderer_process stays).
joc_stream.h and joc_version.h are unchanged.

joc_kernel.vcxproj lists the two new translation units and the four new
headers. The component's layout table gains the kernel's 6.0 layout (L R Ls Rs
Lrs Rrs) after 9.1.6, and layout_table_test expects twelve layouts, so the list
the preferences page shows and the list the renderer accepts are the same
again. README, THIRD_PARTY_NOTICES and the CI comment pin the copy to commit
3f0d5e87fe41b90d9350528d2dca2ca82a637a3f; tag v1.2.0 points at the older
a276028 and is not the sync baseline.

Builds Release-Static|x64 and |Win32 with no errors. The offline test tools
build and pass on both architectures: layout_table_test reports 12 layouts, and
channel_swap_test, log_rotation_test and long_path_test pass. scan_crosscheck
agrees with the core on the upstream test material, and the render harness
delivers 7.1.4 speaker output and binaural output on both architectures, with
the speaker-path WAV byte-identical between them.

The core is still vendored under kernel/; building it from the upstream
checkout at build time is a separate change.
2026-11-08 16:11:57 +08:00

144 lines
5.7 KiB
C++

// 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 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 hands the PCM over in exactly that order.
//
// No rendering and no files are involved, so this runs everywhere the kernel
// archive builds.
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#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());
}
// 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* order;
};
const Expected kExpected[] = {
{"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"},
{"6.0", "L R Ls Rs Lrs Rrs"},
};
std::string join(const std::vector<std::string>& 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;
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;
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<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
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<std::size_t>(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<int>(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 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);
}
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;
}