Sync the kernel copy with the OAMD ramp timing port
This commit is contained in:
1 parent
ff83912f46
commit
7cebf3e22e
7 files changed
+68
-46
No files matched your search
@@ -230,6 +230,7 @@
|
||||
<ClInclude Include="src\foundation\fft.h" />
|
||||
<ClInclude Include="src\foundation\fs_utf8.h" />
|
||||
<ClInclude Include="src\foundation\geometry.h" />
|
||||
<ClInclude Include="src\foundation\metadata_timing.h" />
|
||||
<ClInclude Include="src\foundation\mini_json.h" />
|
||||
<ClInclude Include="src\foundation\py_num.h" />
|
||||
<ClInclude Include="src\foundation\sha256.h" />
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "foundation/geometry.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
|
||||
namespace joc::adm {
|
||||
|
||||
@@ -66,7 +67,7 @@ Status non_monotonic(const char* name, const char* message, int object_index, st
|
||||
} // namespace
|
||||
|
||||
Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out) {
|
||||
out->clear();
|
||||
const double scale = static_cast<double>(rate);
|
||||
@@ -88,18 +89,17 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
|
||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||
const OamdEvent& event = events[index];
|
||||
const std::int64_t event_start = event.sample + object_delay_samples;
|
||||
const std::int64_t event_start = timing::align_metadata_sample(
|
||||
event.sample + object_delay_samples, update_block_samples);
|
||||
if (event_start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
const std::int64_t effective_ramp =
|
||||
std::max<std::int64_t>(0, event.ramp_samples - update_quantum_samples);
|
||||
const std::int64_t block_start =
|
||||
event_start + (effective_ramp != 0 ? update_quantum_samples : 0);
|
||||
const std::int64_t ramp = std::max<std::int64_t>(0, event.ramp_samples);
|
||||
const std::int64_t block_start = event_start;
|
||||
if (block_start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
const std::int64_t ramp_end = block_start + effective_ramp;
|
||||
const std::int64_t ramp_end = block_start + ramp;
|
||||
|
||||
if (block_start < points.back().sample) {
|
||||
return non_monotonic("non_monotonic_compact_position_updates",
|
||||
@@ -107,11 +107,8 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
block_start, points.back().sample);
|
||||
}
|
||||
if (index + 1 < events.size()) {
|
||||
const std::int64_t next_event_start = events[index + 1].sample + object_delay_samples;
|
||||
const std::int64_t next_effective =
|
||||
std::max<std::int64_t>(0, events[index + 1].ramp_samples - update_quantum_samples);
|
||||
const std::int64_t next_block_start =
|
||||
next_event_start + (next_effective != 0 ? update_quantum_samples : 0);
|
||||
const std::int64_t next_block_start = timing::align_metadata_sample(
|
||||
events[index + 1].sample + object_delay_samples, update_block_samples);
|
||||
if (next_block_start < ramp_end) {
|
||||
return non_monotonic("overlapping_compact_position_ramps",
|
||||
"a new position update arrived before the previous compact "
|
||||
@@ -121,11 +118,10 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
}
|
||||
|
||||
double target[3] = {event.x, event.y, event.z};
|
||||
std::int64_t interpolation = effective_ramp;
|
||||
std::int64_t interpolation = ramp;
|
||||
const std::int64_t available = total_samples - block_start;
|
||||
if (effective_ramp > available) {
|
||||
const double amount =
|
||||
static_cast<double>(available) / static_cast<double>(effective_ramp);
|
||||
if (ramp > available) {
|
||||
const double amount = static_cast<double>(available) / static_cast<double>(ramp);
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
@@ -147,7 +143,7 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
}
|
||||
|
||||
Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out) {
|
||||
out->clear();
|
||||
(void)rate;
|
||||
@@ -164,7 +160,8 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
|
||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||
const OamdEvent& event = events[index];
|
||||
const std::int64_t start = event.sample + object_delay_samples;
|
||||
const std::int64_t start =
|
||||
timing::align_metadata_sample(event.sample + object_delay_samples, update_block_samples);
|
||||
if (start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
@@ -176,20 +173,19 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
if (start > points.back().sample) {
|
||||
append_point(&points, start, current[0], current[1], current[2], 0);
|
||||
}
|
||||
const std::int64_t effective_ramp =
|
||||
std::max<std::int64_t>(0, event.ramp_samples - update_quantum_samples);
|
||||
if (effective_ramp == 0) {
|
||||
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);
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
current[2] = event.z;
|
||||
continue;
|
||||
}
|
||||
const std::int64_t steps =
|
||||
(effective_ramp + update_quantum_samples - 1) / update_quantum_samples;
|
||||
const std::int64_t end = start + steps * update_quantum_samples;
|
||||
const std::int64_t steps = (ramp + update_block_samples - 1) / update_block_samples;
|
||||
const std::int64_t end = start + steps * update_block_samples;
|
||||
if (index + 1 < events.size()) {
|
||||
const std::int64_t next_start = events[index + 1].sample + object_delay_samples;
|
||||
const std::int64_t next_start = timing::align_metadata_sample(
|
||||
events[index + 1].sample + object_delay_samples, update_block_samples);
|
||||
if (next_start < end) {
|
||||
return non_monotonic("overlapping_position_ramps",
|
||||
"a new position update arrived before the previous ramp "
|
||||
@@ -197,12 +193,12 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
object_index, start, end);
|
||||
}
|
||||
}
|
||||
std::int64_t future = effective_ramp;
|
||||
std::int64_t future = ramp;
|
||||
std::int64_t elapsed = 0;
|
||||
double position[3] = {current[0], current[1], current[2]};
|
||||
while (future > 0) {
|
||||
const double amount =
|
||||
std::min(static_cast<double>(update_quantum_samples) / static_cast<double>(future),
|
||||
std::min(static_cast<double>(update_block_samples) / static_cast<double>(future),
|
||||
1.0);
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
@@ -212,14 +208,14 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
position[0] = x;
|
||||
position[1] = y;
|
||||
position[2] = z;
|
||||
elapsed += update_quantum_samples;
|
||||
elapsed += update_block_samples;
|
||||
const std::int64_t sample = start + elapsed;
|
||||
if (sample >= total_samples) {
|
||||
break;
|
||||
}
|
||||
append_point(&points, sample, position[0], position[1], position[2],
|
||||
update_quantum_samples);
|
||||
future -= update_quantum_samples;
|
||||
update_block_samples);
|
||||
future -= update_block_samples;
|
||||
}
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
@@ -266,9 +262,9 @@ Status TrajectoryBuilder::build(std::int64_t total_samples, TrajectoryMode mode,
|
||||
track.name = "JOC_Object_" + std::to_string(object);
|
||||
const Status status =
|
||||
(mode == TrajectoryMode::Compact)
|
||||
? expand_compact(events_[object - 1], total_samples, rate_, quantum_,
|
||||
? expand_compact(events_[object - 1], total_samples, rate_, block_,
|
||||
object_delay_, object, &track.blocks)
|
||||
: expand_dense64(events_[object - 1], total_samples, rate_, quantum_,
|
||||
: expand_dense64(events_[object - 1], total_samples, rate_, block_,
|
||||
object_delay_, object, &track.blocks);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
@@ -26,10 +27,11 @@ enum class TrajectoryMode { Compact, Dense64 };
|
||||
// runs, and records one event per object whenever its coordinates change.
|
||||
class TrajectoryBuilder {
|
||||
public:
|
||||
TrajectoryBuilder(std::uint32_t rate = 48000, std::int64_t update_quantum_samples = 64,
|
||||
TrajectoryBuilder(std::uint32_t rate = 48000,
|
||||
std::int64_t update_block_samples = timing::kMetadataBlockSamples,
|
||||
std::int64_t object_delay_samples = 1473)
|
||||
: rate_(rate),
|
||||
quantum_(update_quantum_samples),
|
||||
block_(update_block_samples),
|
||||
object_delay_(object_delay_samples) {}
|
||||
|
||||
void submit_frame(std::int64_t frame_index, const oamd::OamdUpdate* update, std::int64_t outer_offset);
|
||||
@@ -42,7 +44,7 @@ public:
|
||||
|
||||
private:
|
||||
std::uint32_t rate_;
|
||||
std::int64_t quantum_;
|
||||
std::int64_t block_;
|
||||
std::int64_t object_delay_;
|
||||
oamd::OamdState state_;
|
||||
std::vector<OamdEvent> events_[kObjectCount];
|
||||
@@ -51,11 +53,11 @@ private:
|
||||
};
|
||||
|
||||
Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out);
|
||||
|
||||
Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out);
|
||||
|
||||
} // namespace joc::adm
|
||||
@@ -0,0 +1,25 @@
|
||||
// Port of src/oamd_tracks.py align_metadata_sample: an OAMD position update is
|
||||
// scheduled on the renderer's processing-block grid, the same 32-sample grid the
|
||||
// speaker control blocks use. It lives in foundation because both the ADM track
|
||||
// builder and the object position timeline need it, and the timeline must not
|
||||
// depend on output.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace joc::timing {
|
||||
|
||||
inline constexpr std::int64_t kMetadataBlockSamples = 32;
|
||||
|
||||
// Nearest block boundary, ties towards the earlier block; the negative branch
|
||||
// floors like the reference's Python `//`.
|
||||
inline std::int64_t align_metadata_sample(std::int64_t sample,
|
||||
std::int64_t block_samples = kMetadataBlockSamples) {
|
||||
const std::int64_t numerator = sample + block_samples / 2 - 1;
|
||||
const std::int64_t quotient =
|
||||
numerator >= 0 ? numerator / block_samples
|
||||
: -((-numerator + block_samples - 1) / block_samples);
|
||||
return block_samples * quotient;
|
||||
}
|
||||
|
||||
} // namespace joc::timing
|
||||
@@ -1423,7 +1423,8 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
}
|
||||
|
||||
::joc::io::AdmBwfWriter adm_writer;
|
||||
::joc::adm::TrajectoryBuilder trajectory(48000, 64, cfg.object_delay_samples);
|
||||
::joc::adm::TrajectoryBuilder trajectory(48000, ::joc::timing::kMetadataBlockSamples,
|
||||
cfg.object_delay_samples);
|
||||
const bool adm_enabled = cfg.operation == JOC_OP_ADM_BWF;
|
||||
if (adm_enabled) {
|
||||
const Status status = adm_writer.open(cfg.output_path);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "timeline/position_timeline.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "foundation/geometry.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
|
||||
namespace joc::timeline {
|
||||
|
||||
@@ -145,14 +147,10 @@ Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
const std::int64_t ramp_duration = static_cast<std::int64_t>(update.ramp_duration_samples);
|
||||
const std::int64_t effective_ramp =
|
||||
ramp_duration - kOamdUpdateQuantumSamples > 0 ? ramp_duration - kOamdUpdateQuantumSamples
|
||||
: 0;
|
||||
std::int64_t transition_start = coded_event + object_delay_samples;
|
||||
if (effective_ramp != 0) {
|
||||
transition_start += kOamdUpdateQuantumSamples;
|
||||
}
|
||||
std::max<std::int64_t>(0, static_cast<std::int64_t>(update.ramp_duration_samples));
|
||||
const std::int64_t transition_start =
|
||||
timing::align_metadata_sample(coded_event + object_delay_samples);
|
||||
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||
const bool changed = !has_previous_[index] ||
|
||||
std::memcmp(previous_targets_[index], targets[index],
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
namespace joc::timeline {
|
||||
|
||||
inline constexpr std::int64_t kOamdUpdateQuantumSamples = 64;
|
||||
inline constexpr int kTimelineObjects = 15;
|
||||
|
||||
struct PositionTransition {
|
||||
|
||||
Reference in new issue
Block a user