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.
82 lines
3.4 KiB
C++
82 lines
3.4 KiB
C++
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "joc_core.h"
|
|
#include "foundation/status.h"
|
|
|
|
namespace joc::emdf {
|
|
|
|
inline constexpr std::uint16_t kSyncword = 0x5838;
|
|
inline constexpr std::uint8_t kIdOamd = 11;
|
|
inline constexpr std::uint8_t kIdJoc = 14;
|
|
inline constexpr std::size_t kMaxPayloads = JOC_MAX_EMDF_PAYLOADS;
|
|
|
|
struct Payload {
|
|
std::uint8_t id = 0;
|
|
std::uint32_t sample_offset = 0; // EMDF outer smpoffst: variable_bits(11)
|
|
std::size_t bit_offset = 0; // MSB-first bit position of the payload bytes
|
|
std::size_t size = 0; // payload byte count
|
|
// Payload configuration data (ETSI TS 102 366 H.2.2.3). Spec section 8.2 and
|
|
// its Table 56 associate the OAMD and JOC payloads of one frame by an equal
|
|
// group id, which is how several containers in one syncframe are told apart.
|
|
std::uint8_t group_id = 0;
|
|
std::uint8_t has_group_id = 0;
|
|
};
|
|
|
|
struct Container {
|
|
std::size_t start_bit = 0;
|
|
std::size_t raw_size = 0;
|
|
std::size_t payload_count = 0;
|
|
Payload payloads[kMaxPayloads] = {};
|
|
|
|
const Payload* find(std::uint8_t id) const {
|
|
for (std::size_t i = 0; i < payload_count; ++i) {
|
|
if (payloads[i].id == id) {
|
|
return &payloads[i];
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
Status parse_at(const std::uint8_t* data, std::size_t size, std::size_t start_bit, Container* out);
|
|
|
|
// All candidate 0x5838 bit offsets over the eight alignments, ascending.
|
|
void marker_offsets(const std::uint8_t* data, std::size_t size, std::vector<std::size_t>* out);
|
|
|
|
// Scores how well a candidate container can serve as the frame's metadata when a
|
|
// syncframe carries more than one: 0 = not at all, higher = more credible. A null
|
|
// predicate keeps the strict behaviour: several top-level candidates are an error,
|
|
// never a choice.
|
|
using ContainerPredicate = int (*)(const std::uint8_t* data, std::size_t size,
|
|
const Container& container);
|
|
|
|
// When a syncframe holds several top-level candidates and `usable` leaves exactly
|
|
// one with the highest non-zero score, that one is returned and `ignored_extra` is
|
|
// set; otherwise the frame stays an ambiguity error.
|
|
Status find_joc_emdf(const std::uint8_t* data, std::size_t size, Container* out,
|
|
ContainerPredicate usable = nullptr, bool* ignored_extra = nullptr);
|
|
|
|
// Like find_joc_emdf(), but a syncframe that carries no EMDF marker at all is a
|
|
// normal "absent" result rather than an error. A syncframe that does carry
|
|
// markers but no usable JOC container still fails, so a real transport problem
|
|
// is never mistaken for a core substream.
|
|
Status find_joc_emdf_optional(const std::uint8_t* data, std::size_t size, bool* present,
|
|
Container* out, ContainerPredicate usable = nullptr,
|
|
bool* ignored_extra = nullptr);
|
|
|
|
// Extract the container's bytes exactly as the bit reader sees them (identical
|
|
// to a memcpy for byte-aligned containers).
|
|
void extract_container_bytes(const std::uint8_t* data, std::size_t size, const Container& container,
|
|
std::vector<std::uint8_t>* out);
|
|
|
|
// Extract one payload's bytes with the same MSB-first semantics.
|
|
Status extract_payload_bytes(const std::uint8_t* data, std::size_t size, const Payload& payload,
|
|
std::vector<std::uint8_t>* out);
|
|
|
|
} // namespace joc::emdf
|