78 lines
2.7 KiB
C++
78 lines
2.7 KiB
C++
// Port of src/oamd_tracks.py.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "adm/adm_metadata.h"
|
|
#include "foundation/metadata_timing.h"
|
|
#include "foundation/status.h"
|
|
#include "oamd/oamd_parser.h"
|
|
|
|
namespace joc::adm {
|
|
|
|
struct OamdEvent {
|
|
std::int64_t sample = 0;
|
|
double x = 0.0;
|
|
double y = 0.0;
|
|
double z = 0.0;
|
|
std::int64_t ramp_samples = 0;
|
|
};
|
|
|
|
enum class TrajectoryMode { Compact, Dense64 };
|
|
|
|
// Feeds the same per-frame OAMD state machine the reference's build_adm_tracks
|
|
// runs, and records one event per object whenever its coordinates change.
|
|
class TrajectoryBuilder {
|
|
public:
|
|
TrajectoryBuilder(std::uint32_t rate = 48000,
|
|
std::int64_t update_block_samples = timing::kMetadataBlockSamples,
|
|
std::int64_t object_delay_samples = 1473)
|
|
: rate_(rate),
|
|
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);
|
|
|
|
Status build(std::int64_t total_samples, TrajectoryMode mode, std::vector<Track>* out) const;
|
|
|
|
// bed 声道是固定通道:OAMD 不给位置,整片静止在声明的 bed 方位。
|
|
void set_fixed_position(int object_index, double x, double y, double z) {
|
|
if (object_index < 1 || object_index > kObjectCount) {
|
|
return;
|
|
}
|
|
const int slot = object_index - 1;
|
|
fixed_[slot] = true;
|
|
fixed_xyz_[slot][0] = x;
|
|
fixed_xyz_[slot][1] = y;
|
|
fixed_xyz_[slot][2] = z;
|
|
}
|
|
|
|
const std::vector<OamdEvent>& events(int object_index) const { return events_[object_index]; }
|
|
std::uint32_t rate() const { return rate_; }
|
|
std::int64_t object_delay_samples() const { return object_delay_; }
|
|
|
|
private:
|
|
std::uint32_t rate_;
|
|
std::int64_t block_;
|
|
std::int64_t object_delay_;
|
|
oamd::OamdState state_;
|
|
std::vector<OamdEvent> events_[kObjectCount];
|
|
bool has_previous_[kObjectCount] = {};
|
|
double previous_[kObjectCount][3] = {};
|
|
bool fixed_[kObjectCount] = {};
|
|
double fixed_xyz_[kObjectCount][3] = {};
|
|
};
|
|
|
|
Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
|
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_block_samples, std::int64_t object_delay_samples,
|
|
int object_index, std::vector<Keyframe>* out);
|
|
|
|
} // namespace joc::adm
|