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.
126 lines
5.0 KiB
C++
126 lines
5.0 KiB
C++
#include "speaker/speaker_step.h"
|
|
|
|
#include <cstdio>
|
|
|
|
namespace joc::speaker {
|
|
|
|
Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
|
const oamd::OamdUpdate* update, std::string* error) {
|
|
if (context == nullptr || context->handle == nullptr) {
|
|
return Status::fail(JOC_ERR_STATE, stage::kRender, "speaker renderer is not open");
|
|
}
|
|
if (objects16_planar.size() !=
|
|
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES) {
|
|
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
|
"objects16 must be [16][1536]");
|
|
}
|
|
context->interleaved.assign(static_cast<std::size_t>(JOC_FRAME_SAMPLES) * JOC_OUTPUT_CHANNELS,
|
|
0.0f);
|
|
for (std::size_t n = 0; n < JOC_FRAME_SAMPLES; ++n) {
|
|
for (std::size_t c = 0; c < JOC_OUTPUT_CHANNELS; ++c) {
|
|
context->interleaved[n * JOC_OUTPUT_CHANNELS + c] =
|
|
objects16_planar[c * JOC_FRAME_SAMPLES + n];
|
|
}
|
|
}
|
|
context->output.assign(
|
|
static_cast<std::size_t>(JOC_FRAME_SAMPLES) * context->layout.channel_count, 0.0);
|
|
|
|
context->last_had_payload = update != nullptr;
|
|
if (!context->controls_ready) {
|
|
const Status status =
|
|
parameters_from_oamd(nullptr, context->layout, &context->controls);
|
|
if (!status.ok()) {
|
|
if (error != nullptr) {
|
|
*error = status.message();
|
|
}
|
|
return status;
|
|
}
|
|
context->controls_ready = true;
|
|
}
|
|
if (update != nullptr && update->has_trim) {
|
|
const Status status =
|
|
parameters_from_oamd(&update->trim, context->layout, &context->controls);
|
|
if (!status.ok()) {
|
|
if (error != nullptr) {
|
|
*error = status.message();
|
|
}
|
|
return status;
|
|
}
|
|
context->trim = update->trim;
|
|
context->has_trim = true;
|
|
context->raw_trim_mode = update->trim.global_trim_mode;
|
|
}
|
|
|
|
const bool metadata_frame =
|
|
update != nullptr && update->has_frame_state &&
|
|
update->frame_state.object_count != 0u;
|
|
if (metadata_frame || context->meta_engaged) {
|
|
if (!context->meta_configured) {
|
|
const Status configured = context->meta.configure(context->layout);
|
|
if (!configured.ok()) {
|
|
if (error != nullptr) {
|
|
*error = configured.message();
|
|
}
|
|
return configured;
|
|
}
|
|
context->meta_configured = true;
|
|
}
|
|
const oamd::OamdTrim* trim = context->has_trim ? &context->trim : nullptr;
|
|
const Status processed = context->meta.process_frame(
|
|
context->handle, context->interleaved.data(), JOC_FRAME_SAMPLES,
|
|
metadata_frame ? update : nullptr, context->metadata_offset,
|
|
context->controls, trim, context->raw_trim_mode, 0u,
|
|
context->output.data());
|
|
if (!processed.ok()) {
|
|
if (error != nullptr) {
|
|
*error = processed.message();
|
|
}
|
|
return processed;
|
|
}
|
|
context->meta_engaged = context->meta.engaged();
|
|
return Status::success();
|
|
}
|
|
|
|
std::uint32_t ramp = 0;
|
|
if (update != nullptr) {
|
|
context->state.apply(*update);
|
|
ramp = update->ramp_duration_samples;
|
|
context->last_block_offset = update->block_offset_samples;
|
|
context->last_ramp_duration = update->ramp_duration_samples;
|
|
context->last_object_count = update->object_count;
|
|
}
|
|
|
|
std::uint16_t positions[oamd::kObjects][3] = {};
|
|
context->state.object_positions_q15(positions);
|
|
for (int object = 0; object < oamd::kObjects; ++object) {
|
|
if (!context->bed_override[object]) {
|
|
continue;
|
|
}
|
|
for (int axis = 0; axis < oamd::kAxes; ++axis) {
|
|
positions[object][axis] = context->bed_positions[object][axis];
|
|
}
|
|
}
|
|
// A frame without OAMD must not touch the gains at all (no event), otherwise a
|
|
// pending ramp would snap - matching the reference exactly.
|
|
const std::uint32_t event_count = context->last_had_payload ? 1u : 0u;
|
|
const std::uint32_t offset = context->metadata_offset;
|
|
const int result = ejoc_speaker_renderer_process(
|
|
context->handle, context->interleaved.data(), JOC_FRAME_SAMPLES, event_count,
|
|
event_count != 0u ? &offset : nullptr, event_count != 0u ? &ramp : nullptr,
|
|
event_count != 0u ? &positions[0][0] : nullptr, nullptr, nullptr, nullptr,
|
|
&context->controls, context->output.data());
|
|
if (result != 0) {
|
|
const char* message = ejoc_speaker_renderer_last_error(context->handle);
|
|
const std::string text =
|
|
"ejoc_speaker_renderer_process failed (" + std::to_string(result) + "): " +
|
|
(message != nullptr ? message : "unknown");
|
|
if (error != nullptr) {
|
|
*error = text;
|
|
}
|
|
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender, text);
|
|
}
|
|
return Status::success();
|
|
}
|
|
|
|
} // namespace joc::speaker
|