Files
JustOneCacophony/src/timeline/position_timeline.h
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

104 lines
4.2 KiB
C++

// Port of src/binaural_metadata.py.
#pragma once
#include <array>
#include <cstdint>
#include <vector>
#include "foundation/status.h"
#include "oamd/oamd_parser.h"
namespace joc::timeline {
// The JOC binaural renderers carry one LFE plus fifteen object sources, but the
// timeline is not tied to that product: it keeps one track per declared OAMD
// object (bounded only by oamd::kMaxObjects) and the renderer reads as many as
// its source layout consumes. A binaural output with a different source count
// (for example one fed by a TrueHD decode) can ask for more tracks.
inline constexpr int kTimelineObjects = 15;
struct PositionTransition {
std::int64_t start_sample = 0;
std::int64_t duration_samples = 0;
double origin[3] = {};
double target[3] = {};
std::int64_t end_sample() const { return start_sample + duration_samples; }
};
class ObjectPositionTrack {
public:
void set_initial(const double position[3]);
Status append(std::int64_t start_sample, std::int64_t duration_samples, const double target[3],
int object_index);
// Monotonic queries only; out receives the interpolated position.
Status position_at(std::int64_t sample, double out[3]);
const std::vector<PositionTransition>& transitions() const { return transitions_; }
private:
double initial_[3] = {};
double last_target_[3] = {};
std::vector<PositionTransition> transitions_;
std::size_t cursor_ = 0;
std::int64_t last_query_sample_ = -1;
};
class OamdPositionTimeline {
public:
explicit OamdPositionTimeline(int object_count = kTimelineObjects);
// Schedules one OAMD payload. A payload parsed by parse_id11_state() carries
// the full frame state: every position block is applied at its own offset and
// ramp, and the track list grows to cover every declared object. The legacy
// single-block slot view is still accepted for direct callers.
Status 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);
// positions[count][3]; queries must be monotonically increasing.
Status positions_at(std::int64_t sample, double* positions, int count);
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
void set_fixed_position(int object_index, const double position[3]);
// Drops the OAMD state and every transition but keeps the fixed bed positions:
// they describe the content, not the playback position.
void reset();
int object_count() const { return object_count_; }
std::uint64_t payload_count() const { return payload_count_; }
std::uint64_t transition_count() const { return transition_count_; }
bool initialized() const { return initialized_; }
const ObjectPositionTrack& track(int index) const { return tracks_[static_cast<std::size_t>(index)]; }
private:
// Grows the track list so every declared OAMD object has one (the JOC
// renderers use the first kTimelineObjects).
void ensure_tracks(int count);
// OAMD position state after applying one frame-state block.
void apply_block(const oamd::FrameState& state, std::uint32_t block_index);
// Current ADM cartesian target of every track.
void targets(std::vector<std::array<double, 3>>* out) const;
// Initialises from the first update or appends the changed transitions.
Status 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);
int object_count_;
oamd::OamdState state_;
std::vector<ObjectPositionTrack> tracks_;
bool initialized_ = false;
std::vector<std::array<double, 3>> previous_targets_;
std::vector<bool> has_previous_;
std::vector<bool> fixed_;
std::vector<std::array<double, 3>> fixed_xyz_;
std::vector<std::array<double, 3>> targets_;
std::uint64_t payload_count_ = 0;
std::uint64_t transition_count_ = 0;
std::int64_t last_coded_event_sample_ = -1;
};
} // namespace joc::timeline