Write OAMD object render metadata into the ADM BWF
Port the Python reference ADM metadata change. The ADM export path now parses the full OAMD frame state, so the same block-0 render state the speaker renderer consumes is available to the trajectory builder. adm::ObjectMetadata (gain, width/depth/height size, divergence, snap) is attached to Keyframe and OamdEvent. TrajectoryBuilder updates the per-object state from frame_state, emits an event when position or metadata changes, and both compact and dense64 expansion modes carry the snapshot into every ADM block. The state is held across frames without a payload; inactive objects write gain 0. Divergence is taken from the current payload (0 when the extended element does not carry it), matching the speaker renderer instead of holding a stale value. build_axml writes width/height/depth (relative 0..1), gain in linear units and objectDivergence positionRange, omitting defaults. The ADM path requests parse_id11_state() so frame_state is populated. test_core adds coverage for the AXML fields and for the trajectory metadata and divergence reset. Bump JOC_VERSION to 1.3.2.
This commit is contained in:
1 parent
836d68c354
commit
787984afe5
7 files changed
+151
-19
No files matched your search
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#define JOC_VERSION_MAJOR 1
|
#define JOC_VERSION_MAJOR 1
|
||||||
#define JOC_VERSION_MINOR 3
|
#define JOC_VERSION_MINOR 3
|
||||||
#define JOC_VERSION_PATCH 1
|
#define JOC_VERSION_PATCH 2
|
||||||
#define JOC_VERSION_STRING "1.3.1"
|
#define JOC_VERSION_STRING "1.3.2"
|
||||||
|
|
||||||
#endif /* JOC_VERSION_H */
|
#endif /* JOC_VERSION_H */
|
||||||
@@ -363,6 +363,20 @@ std::string build_axml(const std::vector<Track>& tracks, double duration_sec, st
|
|||||||
out += "<position coordinate=\"Z\">" + pynum::format_fixed(block.z, 10) +
|
out += "<position coordinate=\"Z\">" + pynum::format_fixed(block.z, 10) +
|
||||||
"</position>";
|
"</position>";
|
||||||
}
|
}
|
||||||
|
const ObjectMetadata& meta = block.meta;
|
||||||
|
if (meta.size[0] > 0.0 || meta.size[1] > 0.0 || meta.size[2] > 0.0) {
|
||||||
|
out += "<width>" + pynum::format_fixed(meta.size[0], 6) + "</width>";
|
||||||
|
out += "<height>" + pynum::format_fixed(meta.size[2], 6) + "</height>";
|
||||||
|
out += "<depth>" + pynum::format_fixed(meta.size[1], 6) + "</depth>";
|
||||||
|
}
|
||||||
|
if (std::fabs(meta.gain - 1.0) > 1e-9) {
|
||||||
|
out += "<gain gainUnit=\"linear\">" + pynum::format_fixed(meta.gain, 6) +
|
||||||
|
"</gain>";
|
||||||
|
}
|
||||||
|
if (meta.divergence > 0.0) {
|
||||||
|
out += "<objectDivergence positionRange=\"" +
|
||||||
|
pynum::format_fixed(meta.divergence, 6) + "\"/>";
|
||||||
|
}
|
||||||
out += "<jumpPosition interpolationLength=\"" +
|
out += "<jumpPosition interpolationLength=\"" +
|
||||||
pynum::format_fixed(static_cast<double>(block.interpolation_samples) / scale,
|
pynum::format_fixed(static_cast<double>(block.interpolation_samples) / scale,
|
||||||
5) +
|
5) +
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ namespace joc::adm {
|
|||||||
inline constexpr int kObjectCount = 15;
|
inline constexpr int kObjectCount = 15;
|
||||||
inline constexpr std::uint32_t kTrackCount = 25;
|
inline constexpr std::uint32_t kTrackCount = 25;
|
||||||
|
|
||||||
|
// Per-block OAMD render metadata the ADM audioBlockFormat can express.
|
||||||
|
struct ObjectMetadata {
|
||||||
|
double gain = 1.0;
|
||||||
|
// OAMD order: width, depth, height (relative units 0..1).
|
||||||
|
double size[3] = {0.0, 0.0, 0.0};
|
||||||
|
double divergence = 0.0;
|
||||||
|
bool snap = false;
|
||||||
|
};
|
||||||
|
|
||||||
struct Keyframe {
|
struct Keyframe {
|
||||||
std::int64_t rtime_samples = 0;
|
std::int64_t rtime_samples = 0;
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
@@ -21,6 +30,7 @@ struct Keyframe {
|
|||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
std::int64_t duration_samples = 0;
|
std::int64_t duration_samples = 0;
|
||||||
std::int64_t interpolation_samples = 0;
|
std::int64_t interpolation_samples = 0;
|
||||||
|
ObjectMetadata meta;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Track {
|
struct Track {
|
||||||
|
|||||||
+61
-13
@@ -16,15 +16,22 @@ struct Point {
|
|||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
std::int64_t interpolation_samples = 0;
|
std::int64_t interpolation_samples = 0;
|
||||||
|
ObjectMetadata meta;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool same_meta(const ObjectMetadata& left, const ObjectMetadata& right) {
|
||||||
|
return left.gain == right.gain && left.size[0] == right.size[0] &&
|
||||||
|
left.size[1] == right.size[1] && left.size[2] == right.size[2] &&
|
||||||
|
left.divergence == right.divergence && left.snap == right.snap;
|
||||||
|
}
|
||||||
|
|
||||||
// otherwise (the reference drops silently).
|
// otherwise (the reference drops silently).
|
||||||
void append_point(std::vector<Point>* points, std::int64_t sample, double x, double y, double z,
|
void append_point(std::vector<Point>* points, std::int64_t sample, double x, double y, double z,
|
||||||
std::int64_t interpolation_samples) {
|
std::int64_t interpolation_samples, const ObjectMetadata& meta) {
|
||||||
if (!points->empty() && sample == points->back().sample) {
|
if (!points->empty() && sample == points->back().sample) {
|
||||||
points->back() = Point{sample, x, y, z, interpolation_samples};
|
points->back() = Point{sample, x, y, z, interpolation_samples, meta};
|
||||||
} else if (points->empty() || sample > points->back().sample) {
|
} else if (points->empty() || sample > points->back().sample) {
|
||||||
points->push_back(Point{sample, x, y, z, interpolation_samples});
|
points->push_back(Point{sample, x, y, z, interpolation_samples, meta});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +59,7 @@ void points_to_blocks(const std::vector<Point>& points, std::int64_t total_sampl
|
|||||||
keyframe.z = point.z;
|
keyframe.z = point.z;
|
||||||
keyframe.duration_samples = duration;
|
keyframe.duration_samples = duration;
|
||||||
keyframe.interpolation_samples = std::min(point.interpolation_samples, duration);
|
keyframe.interpolation_samples = std::min(point.interpolation_samples, duration);
|
||||||
|
keyframe.meta = point.meta;
|
||||||
out->push_back(keyframe);
|
out->push_back(keyframe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,7 +93,8 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
|||||||
|
|
||||||
std::vector<Point> points;
|
std::vector<Point> points;
|
||||||
double current[3] = {events[0].x, events[0].y, events[0].z};
|
double current[3] = {events[0].x, events[0].y, events[0].z};
|
||||||
append_point(&points, 0, current[0], current[1], current[2], 0);
|
ObjectMetadata current_meta = events[0].meta;
|
||||||
|
append_point(&points, 0, current[0], current[1], current[2], 0, current_meta);
|
||||||
|
|
||||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||||
const OamdEvent& event = events[index];
|
const OamdEvent& event = events[index];
|
||||||
@@ -131,10 +140,12 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
|||||||
target[2] = z;
|
target[2] = z;
|
||||||
interpolation = available;
|
interpolation = available;
|
||||||
}
|
}
|
||||||
append_point(&points, block_start, target[0], target[1], target[2], interpolation);
|
append_point(&points, block_start, target[0], target[1], target[2], interpolation,
|
||||||
|
event.meta);
|
||||||
current[0] = event.x;
|
current[0] = event.x;
|
||||||
current[1] = event.y;
|
current[1] = event.y;
|
||||||
current[2] = event.z;
|
current[2] = event.z;
|
||||||
|
current_meta = event.meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
points_to_blocks(points, total_samples, out);
|
points_to_blocks(points, total_samples, out);
|
||||||
@@ -156,7 +167,8 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
|||||||
|
|
||||||
std::vector<Point> points;
|
std::vector<Point> points;
|
||||||
double current[3] = {events[0].x, events[0].y, events[0].z};
|
double current[3] = {events[0].x, events[0].y, events[0].z};
|
||||||
append_point(&points, 0, current[0], current[1], current[2], 0);
|
ObjectMetadata current_meta = events[0].meta;
|
||||||
|
append_point(&points, 0, current[0], current[1], current[2], 0, current_meta);
|
||||||
|
|
||||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||||
const OamdEvent& event = events[index];
|
const OamdEvent& event = events[index];
|
||||||
@@ -171,14 +183,15 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
|||||||
points.back().sample);
|
points.back().sample);
|
||||||
}
|
}
|
||||||
if (start > points.back().sample) {
|
if (start > points.back().sample) {
|
||||||
append_point(&points, start, current[0], current[1], current[2], 0);
|
append_point(&points, start, current[0], current[1], current[2], 0, current_meta);
|
||||||
}
|
}
|
||||||
const std::int64_t ramp = std::max<std::int64_t>(0, event.ramp_samples);
|
const std::int64_t ramp = std::max<std::int64_t>(0, event.ramp_samples);
|
||||||
if (ramp == 0) {
|
if (ramp == 0) {
|
||||||
append_point(&points, start, event.x, event.y, event.z, 0);
|
append_point(&points, start, event.x, event.y, event.z, 0, event.meta);
|
||||||
current[0] = event.x;
|
current[0] = event.x;
|
||||||
current[1] = event.y;
|
current[1] = event.y;
|
||||||
current[2] = event.z;
|
current[2] = event.z;
|
||||||
|
current_meta = event.meta;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const std::int64_t steps = (ramp + update_block_samples - 1) / update_block_samples;
|
const std::int64_t steps = (ramp + update_block_samples - 1) / update_block_samples;
|
||||||
@@ -214,12 +227,13 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
append_point(&points, sample, position[0], position[1], position[2],
|
append_point(&points, sample, position[0], position[1], position[2],
|
||||||
update_block_samples);
|
update_block_samples, event.meta);
|
||||||
future -= update_block_samples;
|
future -= update_block_samples;
|
||||||
}
|
}
|
||||||
current[0] = event.x;
|
current[0] = event.x;
|
||||||
current[1] = event.y;
|
current[1] = event.y;
|
||||||
current[2] = event.z;
|
current[2] = event.z;
|
||||||
|
current_meta = event.meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
points_to_blocks(points, total_samples, out);
|
points_to_blocks(points, total_samples, out);
|
||||||
@@ -239,18 +253,52 @@ void TrajectoryBuilder::submit_frame(std::int64_t frame_index, const oamd::OamdU
|
|||||||
if (fixed_[object - 1]) {
|
if (fixed_[object - 1]) {
|
||||||
continue; // 固定 bed 声道:位置由布局给出,不跟 OAMD 更新
|
continue; // 固定 bed 声道:位置由布局给出,不跟 OAMD 更新
|
||||||
}
|
}
|
||||||
|
const int slot = object - 1;
|
||||||
|
// OAMD block 0 对动态对象显式携带 gain/size/snap;divergence 只在扩展
|
||||||
|
// 元素里出现,缺失时按 0 处理,与 speaker 渲染器的逐 payload 语义一致。
|
||||||
|
if (update != nullptr && update->has_frame_state &&
|
||||||
|
static_cast<std::size_t>(object) < update->frame_state.objects.size()) {
|
||||||
|
const oamd::ObjectElementState& element =
|
||||||
|
update->frame_state.objects[static_cast<std::size_t>(object)];
|
||||||
|
if (!element.blocks.empty() && element.kind == oamd::ObjectKind::kDynamic) {
|
||||||
|
const oamd::ObjectRenderState& render = element.blocks[0].render;
|
||||||
|
ObjectMetadata& meta = meta_[slot];
|
||||||
|
if (render.not_active) {
|
||||||
|
meta.gain = 0.0;
|
||||||
|
} else {
|
||||||
|
meta.gain = static_cast<double>(render.gain_q) / 4096.0;
|
||||||
|
if (render.size_mode == 1u || render.size_mode == 2u) {
|
||||||
|
for (int axis = 0; axis < 3; ++axis) {
|
||||||
|
meta.size[axis] = std::min(
|
||||||
|
std::max(static_cast<double>(render.size_q[axis]) / 32767.0, 0.0),
|
||||||
|
1.0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
meta.size[0] = 0.0;
|
||||||
|
meta.size[1] = 0.0;
|
||||||
|
meta.size[2] = 0.0;
|
||||||
|
}
|
||||||
|
meta.divergence = static_cast<double>(render.divergence_q) / 32767.0;
|
||||||
|
meta.snap = render.snap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
geometry::q_to_adm_xyz(state_.q(object, 0), state_.q(object, 1), state_.q(object, 2), &x,
|
geometry::q_to_adm_xyz(state_.q(object, 0), state_.q(object, 1), state_.q(object, 2), &x,
|
||||||
&y, &z);
|
&y, &z);
|
||||||
const int slot = object - 1;
|
const ObjectMetadata& meta = meta_[slot];
|
||||||
if (!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
const bool position_changed =
|
||||||
previous_[slot][2] != z) {
|
!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
||||||
events_[slot].push_back(OamdEvent{event_sample, x, y, z, ramp_samples});
|
previous_[slot][2] != z;
|
||||||
|
const bool meta_changed = !has_previous_[slot] || !same_meta(previous_meta_[slot], meta);
|
||||||
|
if (position_changed || meta_changed) {
|
||||||
|
events_[slot].push_back(OamdEvent{event_sample, x, y, z, ramp_samples, meta});
|
||||||
previous_[slot][0] = x;
|
previous_[slot][0] = x;
|
||||||
previous_[slot][1] = y;
|
previous_[slot][1] = y;
|
||||||
previous_[slot][2] = z;
|
previous_[slot][2] = z;
|
||||||
|
previous_meta_[slot] = meta;
|
||||||
has_previous_[slot] = true;
|
has_previous_[slot] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ struct OamdEvent {
|
|||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
std::int64_t ramp_samples = 0;
|
std::int64_t ramp_samples = 0;
|
||||||
|
ObjectMetadata meta;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class TrajectoryMode { Compact, Dense64 };
|
enum class TrajectoryMode { Compact, Dense64 };
|
||||||
@@ -62,6 +63,8 @@ private:
|
|||||||
std::vector<OamdEvent> events_[kObjectCount];
|
std::vector<OamdEvent> events_[kObjectCount];
|
||||||
bool has_previous_[kObjectCount] = {};
|
bool has_previous_[kObjectCount] = {};
|
||||||
double previous_[kObjectCount][3] = {};
|
double previous_[kObjectCount][3] = {};
|
||||||
|
ObjectMetadata meta_[kObjectCount];
|
||||||
|
ObjectMetadata previous_meta_[kObjectCount];
|
||||||
bool fixed_[kObjectCount] = {};
|
bool fixed_[kObjectCount] = {};
|
||||||
double fixed_xyz_[kObjectCount][3] = {};
|
double fixed_xyz_[kObjectCount][3] = {};
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-4
@@ -1845,10 +1845,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
|||||||
stream_done = true;
|
stream_done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// The speaker and binaural renderers consume the full per-object
|
// The speaker, binaural and ADM paths consume the full per-object
|
||||||
// block state (multi-block and every declared object); the ADM
|
// block state (multi-block and every declared object); the legacy
|
||||||
// export path keeps the reference's 15-track single-block view.
|
// stream/ADM single-block view only needs the slot fields.
|
||||||
const bool full_metadata_state = speaker_enabled || binaural_enabled;
|
const bool full_metadata_state =
|
||||||
|
speaker_enabled || binaural_enabled || adm_enabled;
|
||||||
const Status oamd =
|
const Status oamd =
|
||||||
full_metadata_state
|
full_metadata_state
|
||||||
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
|
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "adm/adm_metadata.h"
|
#include "adm/adm_metadata.h"
|
||||||
|
#include "adm/adm_tracks.h"
|
||||||
#include "eac3_transport/eac3_reader.h"
|
#include "eac3_transport/eac3_reader.h"
|
||||||
#include "eac3joc_core.h"
|
#include "eac3joc_core.h"
|
||||||
#include "foundation/bit_reader.h"
|
#include "foundation/bit_reader.h"
|
||||||
@@ -955,6 +956,60 @@ void test_dbmd_and_axml_trim() {
|
|||||||
CHECK(plain_axml.find("<DolbyAtmosMasterFile>") == std::string::npos);
|
CHECK(plain_axml.find("<DolbyAtmosMasterFile>") == std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_adm_object_metadata() {
|
||||||
|
std::vector<joc::adm::Track> tracks(15);
|
||||||
|
for (std::size_t i = 0; i < tracks.size(); ++i) {
|
||||||
|
tracks[i].name = "obj" + std::to_string(i);
|
||||||
|
}
|
||||||
|
joc::adm::Keyframe block;
|
||||||
|
block.duration_samples = 48000;
|
||||||
|
block.meta.gain = 0.5;
|
||||||
|
block.meta.size[0] = 0.516155;
|
||||||
|
block.meta.size[1] = 0.516155;
|
||||||
|
block.meta.size[2] = 0.516155;
|
||||||
|
block.meta.divergence = 0.25;
|
||||||
|
tracks[1].blocks.push_back(block);
|
||||||
|
const std::string axml = joc::adm::build_axml(tracks, 1.0, 48000);
|
||||||
|
CHECK(axml.find("<width>0.516155</width><height>0.516155</height><depth>0.516155</depth>") !=
|
||||||
|
std::string::npos);
|
||||||
|
CHECK(axml.find("<gain gainUnit=\"linear\">0.500000</gain>") != std::string::npos);
|
||||||
|
CHECK(axml.find("<objectDivergence positionRange=\"0.250000\"/>") != std::string::npos);
|
||||||
|
|
||||||
|
// Default metadata writes no fields.
|
||||||
|
tracks[1].blocks[0].meta = joc::adm::ObjectMetadata{};
|
||||||
|
const std::string plain = joc::adm::build_axml(tracks, 1.0, 48000);
|
||||||
|
CHECK(plain.find("<width>") == std::string::npos);
|
||||||
|
CHECK(plain.find("<gain ") == std::string::npos);
|
||||||
|
CHECK(plain.find("<objectDivergence ") == std::string::npos);
|
||||||
|
|
||||||
|
// TrajectoryBuilder carries block-0 metadata and drops divergence when the
|
||||||
|
// next payload does not send it, matching the speaker renderer.
|
||||||
|
joc::adm::TrajectoryBuilder builder;
|
||||||
|
joc::oamd::OamdUpdate update;
|
||||||
|
update.has_frame_state = true;
|
||||||
|
update.object_count = 3;
|
||||||
|
update.frame_state.object_count = 3;
|
||||||
|
update.frame_state.block_count = 1;
|
||||||
|
update.frame_state.objects.resize(3);
|
||||||
|
auto& element = update.frame_state.objects[2];
|
||||||
|
element.kind = joc::oamd::ObjectKind::kDynamic;
|
||||||
|
element.blocks.resize(1);
|
||||||
|
auto& render = element.blocks[0].render;
|
||||||
|
render.gain_q = 2048;
|
||||||
|
render.size_mode = 1;
|
||||||
|
render.size_q[0] = render.size_q[1] = render.size_q[2] = 16384;
|
||||||
|
render.divergence_q = 16384;
|
||||||
|
builder.submit_frame(0, &update, 0);
|
||||||
|
joc::oamd::OamdUpdate second = update;
|
||||||
|
second.frame_state.objects[2].blocks[0].render.divergence_q = 0;
|
||||||
|
builder.submit_frame(40, &second, 0);
|
||||||
|
std::vector<joc::adm::Track> trajectory;
|
||||||
|
CHECK(builder.build(96000, joc::adm::TrajectoryMode::Compact, &trajectory).ok());
|
||||||
|
CHECK(trajectory[1].blocks.size() >= 2);
|
||||||
|
CHECK(std::fabs(trajectory[1].blocks.front().meta.gain - 0.5) < 1e-12);
|
||||||
|
CHECK(trajectory[1].blocks.back().meta.divergence == 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
void test_int24_packing() {
|
void test_int24_packing() {
|
||||||
// Interleaved (L,R) for two frames: 0.0, +1.0, -1.0, +2.0 (clips).
|
// Interleaved (L,R) for two frames: 0.0, +1.0, -1.0, +2.0 (clips).
|
||||||
const float values[4] = {0.0f, 1.0f, -1.0f, 2.0f};
|
const float values[4] = {0.0f, 1.0f, -1.0f, 2.0f};
|
||||||
@@ -2421,6 +2476,7 @@ int main() {
|
|||||||
test_speaker_surround_fold();
|
test_speaker_surround_fold();
|
||||||
test_speaker_step_trim_events();
|
test_speaker_step_trim_events();
|
||||||
test_dbmd_and_axml_trim();
|
test_dbmd_and_axml_trim();
|
||||||
|
test_adm_object_metadata();
|
||||||
test_int24_packing();
|
test_int24_packing();
|
||||||
test_utf8_paths();
|
test_utf8_paths();
|
||||||
test_process_runner();
|
test_process_runner();
|
||||||
|
|||||||
Reference in new issue
Block a user