Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
787984afe5 |
No files matched your search
@@ -10,7 +10,7 @@
|
||||
|
||||
#define JOC_VERSION_MAJOR 1
|
||||
#define JOC_VERSION_MINOR 3
|
||||
#define JOC_VERSION_PATCH 1
|
||||
#define JOC_VERSION_STRING "1.3.1"
|
||||
#define JOC_VERSION_PATCH 2
|
||||
#define JOC_VERSION_STRING "1.3.2"
|
||||
|
||||
#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) +
|
||||
"</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=\"" +
|
||||
pynum::format_fixed(static_cast<double>(block.interpolation_samples) / scale,
|
||||
5) +
|
||||
|
||||
@@ -14,6 +14,15 @@ namespace joc::adm {
|
||||
inline constexpr int kObjectCount = 15;
|
||||
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 {
|
||||
std::int64_t rtime_samples = 0;
|
||||
double x = 0.0;
|
||||
@@ -21,6 +30,7 @@ struct Keyframe {
|
||||
double z = 0.0;
|
||||
std::int64_t duration_samples = 0;
|
||||
std::int64_t interpolation_samples = 0;
|
||||
ObjectMetadata meta;
|
||||
};
|
||||
|
||||
struct Track {
|
||||
|
||||
+61
-13
@@ -16,15 +16,22 @@ struct Point {
|
||||
double y = 0.0;
|
||||
double z = 0.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).
|
||||
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) {
|
||||
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) {
|
||||
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.duration_samples = duration;
|
||||
keyframe.interpolation_samples = std::min(point.interpolation_samples, duration);
|
||||
keyframe.meta = point.meta;
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
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[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
}
|
||||
|
||||
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;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
append_point(&points, sample, position[0], position[1], position[2],
|
||||
update_block_samples);
|
||||
update_block_samples, event.meta);
|
||||
future -= update_block_samples;
|
||||
}
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
}
|
||||
|
||||
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]) {
|
||||
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 y = 0.0;
|
||||
double z = 0.0;
|
||||
geometry::q_to_adm_xyz(state_.q(object, 0), state_.q(object, 1), state_.q(object, 2), &x,
|
||||
&y, &z);
|
||||
const int slot = object - 1;
|
||||
if (!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
||||
previous_[slot][2] != z) {
|
||||
events_[slot].push_back(OamdEvent{event_sample, x, y, z, ramp_samples});
|
||||
const ObjectMetadata& meta = meta_[slot];
|
||||
const bool position_changed =
|
||||
!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
||||
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][1] = y;
|
||||
previous_[slot][2] = z;
|
||||
previous_meta_[slot] = meta;
|
||||
has_previous_[slot] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ struct OamdEvent {
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
std::int64_t ramp_samples = 0;
|
||||
ObjectMetadata meta;
|
||||
};
|
||||
|
||||
enum class TrajectoryMode { Compact, Dense64 };
|
||||
@@ -62,6 +63,8 @@ private:
|
||||
std::vector<OamdEvent> events_[kObjectCount];
|
||||
bool has_previous_[kObjectCount] = {};
|
||||
double previous_[kObjectCount][3] = {};
|
||||
ObjectMetadata meta_[kObjectCount];
|
||||
ObjectMetadata previous_meta_[kObjectCount];
|
||||
bool fixed_[kObjectCount] = {};
|
||||
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;
|
||||
break;
|
||||
}
|
||||
// The speaker and binaural renderers consume the full per-object
|
||||
// block state (multi-block and every declared object); the ADM
|
||||
// export path keeps the reference's 15-track single-block view.
|
||||
const bool full_metadata_state = speaker_enabled || binaural_enabled;
|
||||
// The speaker, binaural and ADM paths consume the full per-object
|
||||
// block state (multi-block and every declared object); the legacy
|
||||
// stream/ADM single-block view only needs the slot fields.
|
||||
const bool full_metadata_state =
|
||||
speaker_enabled || binaural_enabled || adm_enabled;
|
||||
const Status oamd =
|
||||
full_metadata_state
|
||||
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "adm/adm_tracks.h"
|
||||
#include "eac3_transport/eac3_reader.h"
|
||||
#include "eac3joc_core.h"
|
||||
#include "foundation/bit_reader.h"
|
||||
@@ -955,6 +956,60 @@ void test_dbmd_and_axml_trim() {
|
||||
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() {
|
||||
// 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};
|
||||
@@ -2421,6 +2476,7 @@ int main() {
|
||||
test_speaker_surround_fold();
|
||||
test_speaker_step_trim_events();
|
||||
test_dbmd_and_axml_trim();
|
||||
test_adm_object_metadata();
|
||||
test_int24_packing();
|
||||
test_utf8_paths();
|
||||
test_process_runner();
|
||||
|
||||
Reference in new issue
Block a user