From d3c98184091bd3a9677a864fd075f16bc9299bd5 Mon Sep 17 00:00:00 2001 From: TheM14 Date: Fri, 30 Oct 2026 05:23:35 +0800 Subject: [PATCH] Sync the kernel copy with the HRTF bed position fixes --- kernel/src/binaural/binaural_runtime.cpp | 2 +- kernel/src/hrtf/rosella_renderer.cpp | 6 +++++- kernel/src/hrtf/rosella_renderer.h | 3 +++ kernel/src/stream/stream.cpp | 9 +++++++-- kernel/src/task/task.cpp | 4 ++++ kernel/src/timeline/position_timeline.h | 17 +++++++++++++++++ src/joc_decode.cpp | 7 ++++--- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/kernel/src/binaural/binaural_runtime.cpp b/kernel/src/binaural/binaural_runtime.cpp index deb3ac1..a25ace0 100644 --- a/kernel/src/binaural/binaural_runtime.cpp +++ b/kernel/src/binaural/binaural_runtime.cpp @@ -205,7 +205,7 @@ Status SofaBinauralRuntime::reset() { if (ejoc_sofa_binaural_reset(handle_) != 0) { return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender, "sofa reset failed"); } - timeline_ = timeline::OamdPositionTimeline(); + timeline_.reset(); output_.clear(); staged_ = 0; input_samples_ = 0; diff --git a/kernel/src/hrtf/rosella_renderer.cpp b/kernel/src/hrtf/rosella_renderer.cpp index 8a08839..87e73d1 100644 --- a/kernel/src/hrtf/rosella_renderer.cpp +++ b/kernel/src/hrtf/rosella_renderer.cpp @@ -1329,7 +1329,7 @@ Status RosellaRuntime::reset() { impl_->raw_output_samples = 0u; impl_->metadata_block_updates = 0u; impl_->finished = false; - impl_->timeline = timeline::OamdPositionTimeline(timeline::kTimelineObjects); + impl_->timeline.reset(); return Status::success(); } @@ -1355,4 +1355,8 @@ std::uint64_t RosellaRuntime::metadata_block_updates() const { } const timeline::OamdPositionTimeline& RosellaRuntime::timeline() const { return impl_->timeline; } +void RosellaRuntime::set_fixed_position(int object_index, const double position[3]) { + impl_->timeline.set_fixed_position(object_index, position); +} + } // namespace joc::hrtf diff --git a/kernel/src/hrtf/rosella_renderer.h b/kernel/src/hrtf/rosella_renderer.h index 7922df7..c822e3a 100644 --- a/kernel/src/hrtf/rosella_renderer.h +++ b/kernel/src/hrtf/rosella_renderer.h @@ -56,6 +56,9 @@ public: std::uint64_t metadata_block_updates() const; const timeline::OamdPositionTimeline& timeline() const; + // bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。 + void set_fixed_position(int object_index, const double position[3]); + private: struct Impl; std::unique_ptr impl_; diff --git a/kernel/src/stream/stream.cpp b/kernel/src/stream/stream.cpp index c00ba2f..f2a468a 100644 --- a/kernel/src/stream/stream.cpp +++ b/kernel/src/stream/stream.cpp @@ -206,8 +206,13 @@ void Stream::apply_bed_positions(const FrameMetadata& entry) { ++slot) { const ::joc::joc::BedChannel channel = bed.channels[slot]; double xyz[3] = {0.0, 0.0, 0.0}; - if (binaural_ready_ && ::joc::joc::bed_channel_adm_position(channel, xyz)) { - binaural_.set_fixed_position(static_cast(slot) + 1, xyz); + if (::joc::joc::bed_channel_adm_position(channel, xyz)) { + if (binaural_ready_) { + binaural_.set_fixed_position(static_cast(slot) + 1, xyz); + } + if (rosella_ready_) { + rosella_.set_fixed_position(static_cast(slot) + 1, xyz); + } } if (!speaker_enabled_) { continue; diff --git a/kernel/src/task/task.cpp b/kernel/src/task/task.cpp index 247eafb..6ec5210 100644 --- a/kernel/src/task/task.cpp +++ b/kernel/src/task/task.cpp @@ -1780,6 +1780,10 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu binaural.set_fixed_position( static_cast(slot) + 1, xyz); } + if (rosella_enabled) { + rosella.set_fixed_position( + static_cast(slot) + 1, xyz); + } } if (!speaker_enabled) { continue; diff --git a/kernel/src/timeline/position_timeline.h b/kernel/src/timeline/position_timeline.h index cf87d39..55e7763 100644 --- a/kernel/src/timeline/position_timeline.h +++ b/kernel/src/timeline/position_timeline.h @@ -60,6 +60,23 @@ public: fixed_xyz_[object_index - 1][2] = position[2]; } + // Drops the OAMD state and every transition but keeps the fixed bed positions: + // they describe the content, not the playback position. + void reset() { + state_.reset(); + for (int index = 0; index < kTimelineObjects; ++index) { + tracks_[index] = ObjectPositionTrack(); + has_previous_[index] = false; + for (int axis = 0; axis < 3; ++axis) { + previous_targets_[index][axis] = 0.0; + } + } + initialized_ = false; + payload_count_ = 0; + transition_count_ = 0; + last_coded_event_sample_ = -1; + } + std::uint64_t payload_count() const { return payload_count_; } std::uint64_t transition_count() const { return transition_count_; } bool initialized() const { return initialized_; } diff --git a/src/joc_decode.cpp b/src/joc_decode.cpp index 787ee9d..b555398 100644 --- a/src/joc_decode.cpp +++ b/src/joc_decode.cpp @@ -1108,9 +1108,10 @@ bool Engine::seek(double seconds, double total_seconds, std::string* error) { impl.delivered = 0; } - // joc_stream_reset keeps the renderer and its HRTF field: it drops the whole - // timeline, gain ramps, room tail and filter-bank history, which is exactly - // what a restart at another position needs. + // joc_stream_reset keeps the renderer and its HRTF field: it drops the timeline + // state, gain ramps, room tail and filter-bank history, which is exactly what a + // restart at another position needs. The fixed bed positions survive: they + // describe the content, not the playback position. const joc_error reset = impl.api.reset(impl.stream); if (reset != JOC_OK) { if (error != nullptr) {