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.
This commit is contained in:
TheM14 committed 2026-11-08 16:11:57 +08:00
1 parent 5b41868e94
commit defe9538fe
39 files changed
+6714 -616

No files matched your search

+165 -41
View File
@@ -95,37 +95,100 @@ Status ObjectPositionTrack::position_at(std::int64_t sample, double out[3]) {
return Status::success();
}
OamdPositionTimeline::OamdPositionTimeline(int object_count) : object_count_(object_count) {
if (object_count != kTimelineObjects) {
object_count_ = kTimelineObjects;
OamdPositionTimeline::OamdPositionTimeline(int object_count)
: object_count_(std::clamp(object_count, 1, oamd::kMaxObjects - 1)) {
const std::size_t count = static_cast<std::size_t>(object_count_);
tracks_.resize(count);
previous_targets_.resize(count);
has_previous_.assign(count, false);
fixed_.assign(count, false);
fixed_xyz_.resize(count);
}
void OamdPositionTimeline::ensure_tracks(int count) {
const int capped = std::clamp(count, 1, oamd::kMaxObjects - 1);
if (capped <= object_count_) {
return;
}
const std::size_t size = static_cast<std::size_t>(capped);
object_count_ = capped;
tracks_.resize(size);
previous_targets_.resize(size);
has_previous_.resize(size, false);
fixed_.resize(size, false);
fixed_xyz_.resize(size);
}
void OamdPositionTimeline::set_fixed_position(int object_index, const double position[3]) {
if (object_index < 1 || object_index > object_count_) {
return;
}
const std::size_t index = static_cast<std::size_t>(object_index - 1);
fixed_[index] = true;
for (int axis = 0; axis < 3; ++axis) {
fixed_xyz_[index][static_cast<std::size_t>(axis)] = position[axis];
}
}
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
std::int64_t frame_start_sample,
std::int64_t outer_sample_offset,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"OAMD frame, outer offset and object delay must be non-negative");
void OamdPositionTimeline::reset() {
state_.reset();
for (int index = 0; index < object_count_; ++index) {
tracks_[static_cast<std::size_t>(index)] = ObjectPositionTrack();
has_previous_[static_cast<std::size_t>(index)] = false;
previous_targets_[static_cast<std::size_t>(index)] = {0.0, 0.0, 0.0};
}
state_.apply(update);
initialized_ = false;
payload_count_ = 0;
transition_count_ = 0;
last_coded_event_sample_ = -1;
}
double targets[kTimelineObjects][3] = {};
for (int index = 0; index < kTimelineObjects; ++index) {
if (fixed_[index]) {
std::memcpy(targets[index], fixed_xyz_[index], sizeof(targets[index]));
void OamdPositionTimeline::apply_block(const oamd::FrameState& state,
std::uint32_t block_index) {
// Track i reads OAMD object i + 1: object 0 is the LFE/bed slot the JOC
// renderers do not position. Bed and ISF objects carry no position field,
// and an inactive block keeps the previous position, exactly like the
// reference frame_update() value construction.
for (int track = 0; track < object_count_; ++track) {
const int object_index = track + 1;
if (object_index >= static_cast<int>(state.objects.size())) {
break;
}
const oamd::ObjectElementState& element =
state.objects[static_cast<std::size_t>(object_index)];
if (block_index >= element.blocks.size()) {
continue;
}
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
state_.q(index + 1, 2), &targets[index][0], &targets[index][1],
&targets[index][2]);
const oamd::ObjectRenderState& render =
element.blocks[static_cast<std::size_t>(block_index)].render;
if (render.not_active || element.kind != oamd::ObjectKind::kDynamic) {
continue;
}
state_.apply_render_state(object_index, render);
}
}
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset +
static_cast<std::int64_t>(update.block_offset_samples);
void OamdPositionTimeline::targets(std::vector<std::array<double, 3>>* out) const {
out->resize(static_cast<std::size_t>(object_count_));
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
if (fixed_[slot]) {
(*out)[slot] = fixed_xyz_[slot];
continue;
}
double x = 0.0;
double y = 0.0;
double z = 0.0;
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
state_.q(index + 1, 2), &x, &y, &z);
(*out)[slot] = {x, y, z};
}
}
Status OamdPositionTimeline::schedule(const std::vector<std::array<double, 3>>& targets,
std::int64_t coded_event, std::int64_t ramp_samples,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (coded_event < last_coded_event_sample_) {
return timeline_fail(JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
"non_monotonic_binaural_updates: event sample " +
@@ -141,44 +204,105 @@ Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
"sample " + std::to_string(processed_sample) +
" had been processed, so sample 0 cannot be backfilled");
}
for (int index = 0; index < kTimelineObjects; ++index) {
tracks_[index].set_initial(targets[index]);
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
has_previous_[index] = true;
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
tracks_[slot].set_initial(targets[slot].data());
previous_targets_[slot] = targets[slot];
has_previous_[slot] = true;
}
initialized_ = true;
++payload_count_;
return Status::success();
}
const std::int64_t effective_ramp =
std::max<std::int64_t>(0, static_cast<std::int64_t>(update.ramp_duration_samples));
const std::int64_t effective_ramp = std::max<std::int64_t>(0, ramp_samples);
const std::int64_t transition_start =
timing::align_metadata_sample(coded_event + object_delay_samples);
for (int index = 0; index < kTimelineObjects; ++index) {
const bool changed = !has_previous_[index] ||
std::memcmp(previous_targets_[index], targets[index],
sizeof(targets[index])) != 0;
for (int index = 0; index < object_count_; ++index) {
const std::size_t slot = static_cast<std::size_t>(index);
const bool changed =
!has_previous_[slot] ||
std::memcmp(previous_targets_[slot].data(), targets[slot].data(),
sizeof(targets[slot])) != 0;
if (!changed) {
continue;
}
const Status status = tracks_[index].append(transition_start, effective_ramp,
targets[index], index + 1);
const Status status =
tracks_[slot].append(transition_start, effective_ramp, targets[slot].data(),
index + 1);
if (!status.ok()) {
return status;
}
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
has_previous_[index] = true;
previous_targets_[slot] = targets[slot];
has_previous_[slot] = true;
++transition_count_;
}
return Status::success();
}
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
std::int64_t frame_start_sample,
std::int64_t outer_sample_offset,
std::int64_t object_delay_samples,
std::int64_t processed_sample) {
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"OAMD frame, outer offset and object delay must be non-negative");
}
if (!update.has_frame_state) {
state_.apply(update);
targets(&targets_);
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset +
static_cast<std::int64_t>(update.block_offset_samples);
const Status status =
schedule(targets_, coded_event, update.ramp_duration_samples, object_delay_samples,
processed_sample);
if (status.ok()) {
++payload_count_;
}
return status;
}
const oamd::FrameState& state = update.frame_state;
ensure_tracks(state.object_count > 0u ? static_cast<int>(state.object_count) - 1 : 0);
const std::uint32_t block_count =
state.blocks.empty() ? 1u : static_cast<std::uint32_t>(state.blocks.size());
for (std::uint32_t block = 0; block < block_count; ++block) {
apply_block(state, block);
targets(&targets_);
std::int64_t block_offset = 0;
std::int64_t ramp_samples = 0;
if (block < state.blocks.size()) {
block_offset = static_cast<std::int64_t>(state.blocks[block].block_offset_samples);
ramp_samples = static_cast<std::int64_t>(state.blocks[block].ramp_duration_samples);
}
const std::int64_t coded_event =
frame_start_sample + outer_sample_offset + block_offset;
const Status status = schedule(targets_, coded_event, ramp_samples,
object_delay_samples, processed_sample);
if (!status.ok()) {
return status;
}
}
++payload_count_;
return Status::success();
}
Status OamdPositionTimeline::positions_at(std::int64_t sample,
double positions[kTimelineObjects][3]) {
for (int index = 0; index < kTimelineObjects; ++index) {
const Status status = tracks_[index].position_at(sample, positions[index]);
Status OamdPositionTimeline::positions_at(std::int64_t sample, double* positions,
int count) {
if (positions == nullptr || count < 0) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"binaural positions need a non-negative count and a buffer");
}
if (count > object_count_) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
"binaural positions requested " + std::to_string(count) +
" objects but the timeline tracks " +
std::to_string(object_count_));
}
for (int index = 0; index < count; ++index) {
const Status status = tracks_[static_cast<std::size_t>(index)].position_at(
sample, positions + static_cast<std::size_t>(index) * 3u);
if (!status.ok()) {
return status;
}