Port the OAMD metadata rendering and the frame-level JOC core
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

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.
This commit is contained in:
TheM14 committed 2026-11-08 14:04:21 +08:00
1 parent a2760286b0
commit 0bb82e4115
41 files changed
+8182 -678

No files matched your search

+75 -1
View File
@@ -23,13 +23,15 @@ extern "C" {
#endif
enum {
EJOC_ABI_VERSION = 3,
EJOC_ABI_VERSION = 4,
EJOC_FRAME_SAMPLES = 1536,
EJOC_TIMESLOTS = 24,
EJOC_SUBBANDS = 64,
EJOC_CORE_CHANNELS = 5, /* downmix configurations 0 and 3 */
EJOC_MAX_CORE_CHANNELS = 7, /* downmix configurations 1, 2 and 4 */
EJOC_OUTPUT_CHANNELS = 16,
EJOC_CORE_OUT_CHANNELS = 8, /* passthrough order: L,R,C,LFE,Ls,Rs,(Lrs,Rrs) */
EJOC_LFE_SLOT = 3, /* LFE slot of the passthrough order */
EJOC_MAX_OBJECTS = 15,
EJOC_MAX_DPOINTS = 2,
EJOC_MAX_PARAMETER_BANDS = 23,
@@ -43,6 +45,21 @@ enum {
EJOC_BINAURAL_HYBRID_BANDS = 77
};
/* Per-frame status of ejoc_renderer_render_frame(). A status outside 0..6 is
* the renderer's own no-metadata marker; the parse-status values match
* joc_frame_params.status (JOC_FRAME_STATUS_* in joc_core.h). Any non-zero
* status makes the frame invalid for matrix rendering: the renderer holds the
* previous matrices or passes the core PCM through instead of decoding it. */
enum {
EJOC_FRAME_STATUS_OK = 0,
EJOC_FRAME_STATUS_UNSUPPORTED_DMX = 2,
EJOC_FRAME_STATUS_OBJECTS_CLAMPED = 3,
EJOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4,
EJOC_FRAME_STATUS_BAD_OFFSET_TS = 5,
EJOC_FRAME_STATUS_TRAILING_DATA = 6,
EJOC_FRAME_STATUS_NO_METADATA = 8
};
typedef void* ejoc_renderer_handle;
typedef void* ejoc_speaker_renderer_handle;
typedef void* ejoc_binaural_renderer_handle;
@@ -103,6 +120,63 @@ EJOC_API int EJOC_CALL ejoc_renderer_process(
float output_scale,
float* output16_planar);
/*
Frame-level entry point: one E-AC-3 audio frame per call, with the seq state
machine and the per-object previous-matrix state kept inside the renderer. This
is what produces the 16-channel object result for the ADM, speaker and binaural
backends; ejoc_renderer_process() stays as a single-frame kernel for A/B tests.
Fixed array layouts, identical to ejoc_renderer_process():
bed_planar [core_channel_count][1536] (JOC lane order L,R,C,Ls,Rs,(pair))
lfe [1536] or NULL (zeros; the LFE delay ring still advances)
n_bands, n_dpoints, slope_idx [15]
offset_ts [15][2] (raw 5-bit JOC offsets, 0..23)
dq [15][2][7][23]
output16 [16][1536] (ch0 = LFE, ch1..15 = objects)
frame_status is a JOC_FRAME_STATUS_* / EJOC_FRAME_STATUS_* value. has_metadata
is 0 for an audio frame without a JOC EMDF container (frame_status must then be
EJOC_FRAME_STATUS_NO_METADATA); such a frame always passes the 8 core planes
through to output slots 0..7, delayed by 1217 samples, with slots 8..15 zero.
declared_core_channels is the JOC header's n_channels (0 when unknown); a declared
change against the previous frame's actual count turns the frame into a hard cut
with the LFE ring cleared. phase_shift is sigma(k) = (k in {3,4}) for the frame's
downmix configuration; phase_shift_valid = 0 keeps the previous switch (an
unsupported downmix configuration has no usable one). clipgain is the frame's
joc_clipgain when frame_status == 0. seq is the 10-bit JOC sequence counter.
When has_metadata is 0 the object descriptors are ignored.
Slot 0 of output16 is the LFE, slots 1..15 are the 15 objects; each frame's
values are float32(clamped PCM) * output_scale, exactly like the reference.
*/
typedef struct ejoc_frame_input {
uint32_t struct_size;
uint32_t struct_version;
const float* bed_planar;
const float* lfe;
uint32_t core_channel_count;
uint32_t declared_core_channels;
uint32_t phase_shift;
uint32_t phase_shift_valid;
uint32_t frame_status;
uint32_t seq;
uint32_t has_metadata;
uint32_t object_mask;
const uint8_t* n_bands;
const uint8_t* n_dpoints;
const uint8_t* slope_idx;
const uint8_t* offset_ts;
const double* dq;
double clipgain;
float output_scale;
float* output16_planar;
} ejoc_frame_input;
enum { EJOC_FRAME_INPUT_VERSION = 1 };
EJOC_API int EJOC_CALL ejoc_renderer_render_frame(ejoc_renderer_handle handle,
const ejoc_frame_input* input);
/*
High-precision object-to-speaker renderer.
+25 -8
View File
@@ -36,9 +36,9 @@
#include "joc_version.h"
#define JOC_ABI_VERSION 5u
#define JOC_FRAME_PARAMS_VERSION 1u
#define JOC_EMDF_INFO_VERSION 1u
#define JOC_ABI_VERSION 6u
#define JOC_FRAME_PARAMS_VERSION 2u
#define JOC_EMDF_INFO_VERSION 2u
#define JOC_TASK_CONFIG_VERSION 4u
#define JOC_TASK_RESULT_VERSION 2u
#define JOC_EVENT_VERSION 1u
@@ -152,8 +152,7 @@ JOC_API const char* JOC_CALL joc_last_error_detail(void);
typedef struct joc_emdf_payload_info {
uint8_t id;
uint8_t reserved[3];
uint16_t sample_offset; /* EMDF outer smpoffst, 11 bits */
uint16_t reserved2;
uint32_t sample_offset; /* EMDF outer smpoffst: variable_bits(11) */
uint32_t bit_offset;
uint32_t size; /* payload bytes */
} joc_emdf_payload_info;
@@ -170,7 +169,8 @@ typedef struct joc_emdf_info {
/* Per-object ID14/JOC descriptor plus its dequantized matrix.
* dq[dp][ch][pb] is zero filled outside [0,n_dpoints) x [0,n_channels) x
* [0,n_bands). Absent objects are entirely zero. */
* [0,n_bands). Absent objects are entirely zero. offset_ts holds the raw
* 5-bit JOC offsets (legal range 0..23, strictly increasing per object). */
typedef struct joc_object_params {
uint8_t present;
uint8_t num_bands_idx;
@@ -185,6 +185,21 @@ typedef struct joc_object_params {
double dq[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS];
} joc_object_params;
/* Per-frame JOC parse status (joc_frame_params.status). A non-zero status makes
* the frame invalid for rendering: the renderer holds the previous matrices or
* passes the core PCM through instead of decoding the matrix. Only status 3
* still carries a complete object list (object count clamped to 15) for
* diagnostics; statuses 2 and 4 stop the parse after the failing header field. */
enum {
JOC_FRAME_STATUS_OK = 0,
JOC_FRAME_STATUS_UNSUPPORTED_DMX = 2, /* joc_dmx_config_idx outside 0..4 */
JOC_FRAME_STATUS_OBJECTS_CLAMPED = 3, /* declared object count above 15 */
JOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4, /* unknown num_bands index */
JOC_FRAME_STATUS_BAD_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */
/* strictly increasing */
JOC_FRAME_STATUS_TRAILING_DATA = 6 /* bytes after joc_data alignment */
};
typedef struct joc_frame_params {
uint32_t struct_size;
uint32_t struct_version;
@@ -196,12 +211,14 @@ typedef struct joc_frame_params {
uint8_t clipgain_x_bits;
uint8_t clipgain_y_bits;
uint8_t objects_clamped; /* num_objects_bits+1 exceeded 15 */
uint32_t seq_count; /* 10-bit JOC sequence counter, parsed only */
uint32_t seq_count; /* 10-bit JOC sequence counter */
uint32_t present_mask; /* bit i == object i present */
uint8_t status; /* JOC_FRAME_STATUS_* */
uint8_t reserved[3];
uint32_t data_end_bits; /* bit position just after joc_data */
uint32_t trailing_bits; /* bits left after joc_data (padding/ext) */
uint8_t tail_bytes[8]; /* first up to 8 trailing bytes, for A/B */
double clipgain; /* 1 + (y/32) * 2^(x-4), bit-exact */
double clipgain; /* 2^(x-4) * (1 + y/32), bit-exact */
joc_object_params objects[JOC_MAX_OBJECTS];
} joc_frame_params;