Files
JustOneCacophony/src/speaker/speaker_layout_lookup.cpp
T
TheM14 0bb82e4115
ci / ubuntu-latest (push) Failing after 19s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s
Port the OAMD metadata rendering and the frame-level JOC core
The JOC bitstream reports a per-frame parse status instead of treating every
anomaly as an exception: an unsupported downmix configuration, a clamped
object count, an unknown parameter-band count, bad offset_ts values and
trailing bytes each get their own status. The raw 5-bit offset_ts values are
kept as coded and validated to be strictly increasing per object, and the
clipgain uses 2^(x-4) * (1 + y/32).

The JOC core gains a frame-level state machine. It keeps the per-object
previous matrix and its presence marker, the seq counter, the 8-plane
passthrough history, the LFE clipgain ramp start and the previous actual
core-channel count. Normal, hold, hard-cut and passthrough frames are
distinguished: a frame without a previous state interpolates per the
data-point rules, an object that disappears keeps publishing a zero matrix,
a frame without metadata passes the 8 core planes through to slots 0..7 with
the 1217-sample delay, and a declared core-channel-count change hard-cuts and
clears the LFE ring while the clipgain ramp state is kept. The core LFE
applies the full clipgain as a sample-wise ramp before its delay.

The OAMD parser exposes the full frame state: every object's state in every
position block, the programme assignment and the trim element, with multiple
blocks and up to 30 declared objects accepted. The speaker renderer applies
this state: per-block gain/inactive, zone/elevation, the size kernel, snap,
divergence, element 5 refinement, the priority size budget, ISF basis
matrices and bed channel distribution, scheduled on the 32-sample metadata
grid with block alignment and gain ramps. The size kernel, ISF basis
assembly, bed routing and compensation are computed in oamd_math from the
speaker layout geometry; bed labels and reference positions derive from the
layout tables. The six ISF configurations and twelve layout descriptors are
compiled in as static tables (oamd/isf_tables.h); the JSON loader and the
configure-time embedding are gone. The layout tables gain 6.0, and the layout
lookup, bed map and trim probe follow.

The binaural position timeline consumes the full frame state as well: every
position block is scheduled at its own offset and ramp, and its track list
grows with the declared object count, so multi-block and over-16-object
programmes are rendered instead of rejected. The JOC binaural input stays one
LFE plus fifteen object sources; the extra tracks are followed but not
panned.

The file task and the stream parse the full state for speaker and binaural,
while the ADM export keeps the 15-track single-block view. The public headers
carry the new status values, the frame-level entry point and the raw offset_ts
description; the internal ABI versions go to 6 (joc_core), 2 (frame params and
EMDF info) and 4 (eac3joc).

ctest covers the frame-level core (clipgain formula and LFE ramp, offset_ts
validation, frame statuses, the 8-plane passthrough, the seq state machine and
the no-previous-state interpolation), the OAMD parser state, the compiled-in
ISF tables and the binaural timeline. The READMEs and the mathematical notes
describe the 6.0 layout, the frame state machine, the metadata application and
the ISF lookup tables.
2026-11-08 14:04:21 +08:00

102 lines
3.7 KiB
C++

#include "speaker/speaker_layout_lookup.h"
#include <cstring>
namespace joc::speaker {
namespace {
struct FrozenLayout {
const char* name;
const char* compact_name;
std::uint32_t out_ch_config;
std::uint32_t speaker_bitfield;
std::uint32_t surround_channels;
std::uint32_t height_channels;
bool carries_trim;
const char* const* channel_names;
};
const char* const kChannels20[] = {"L", "R"};
const char* const kChannels31[] = {"L", "R", "C", "LFE"};
const char* const kChannels40[] = {"L", "R", "Lrs", "Rrs"};
const char* const kChannels51[] = {"L", "R", "C", "LFE", "Ls", "Rs"};
const char* const kChannels71[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"};
const char* const kChannels512[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"};
const char* const kChannels514[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf",
"Ltr", "Rtr"};
const char* const kChannels712[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Ltm", "Rtm"};
const char* const kChannels714[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Ltf", "Rtf", "Ltr", "Rtr"};
const char* const kChannels914[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Lw", "Rw", "Ltf", "Rtf", "Ltr", "Rtr"};
const char* const kChannels916[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
"Lw", "Rw", "Ltf", "Rtf", "Ltm", "Rtm", "Ltr", "Rtr"};
const char* const kChannels60[] = {"L", "R", "Ls", "Rs", "Lrs", "Rrs"};
constexpr FrozenLayout kLayouts[kLayoutCount] = {
{"2.0", "20", 0, 1, 0, 0, true, kChannels20},
{"3.1", "31", 3, 7, 0, 0, true, kChannels31},
{"4.0", "40", 0xFF, 9, 2, 0, true, kChannels40},
{"5.1", "51", 7, 15, 2, 0, true, kChannels51},
{"7.1", "71", 11, 31, 4, 0, true, kChannels71},
{"5.1.2", "512", 13, 1039, 2, 2, true, kChannels512},
{"5.1.4", "514", 14, 2575, 2, 4, true, kChannels514},
{"7.1.2", "712", 15, 1055, 4, 2, false, kChannels712},
{"7.1.4", "714", 16, 2591, 4, 4, false, kChannels714},
{"9.1.4", "914", 19, 2719, 4, 4, false, kChannels914},
{"9.1.6", "916", 20, 3743, 4, 6, false, kChannels916},
{"6.0", "60", 0xFF, 25, 4, 0, false, kChannels60},
};
void fill(const FrozenLayout& source, LayoutInfo* out) {
out->name = source.name;
out->compact_name = source.compact_name;
out->out_ch_config = source.out_ch_config;
out->speaker_bitfield = source.speaker_bitfield;
out->channel_count = ejoc_speaker_layout_channel_count(source.speaker_bitfield);
out->channel_names = source.channel_names;
out->surround_channels = source.surround_channels;
out->height_channels = source.height_channels;
out->carries_trim = source.carries_trim;
}
} // namespace
bool layout_at(int index, LayoutInfo* out) {
if (out == nullptr || index < 0 || index >= kLayoutCount) {
return false;
}
fill(kLayouts[index], out);
return true;
}
bool layout_by_name(const char* name, LayoutInfo* out) {
if (name == nullptr || out == nullptr) {
return false;
}
for (int index = 0; index < kLayoutCount; ++index) {
if (std::strcmp(name, kLayouts[index].name) == 0) {
fill(kLayouts[index], out);
return true;
}
}
return false;
}
bool layout_by_bitfield(std::uint32_t bitfield, LayoutInfo* out) {
if (out == nullptr) {
return false;
}
for (int index = 0; index < kLayoutCount; ++index) {
if (kLayouts[index].speaker_bitfield == bitfield) {
fill(kLayouts[index], out);
return true;
}
}
return false;
}
} // namespace joc::speaker