From 075ef60afadc7ebc02914f62dc6ae6c597b257a6 Mon Sep 17 00:00:00 2001 From: TheM14 Date: Fri, 30 Oct 2026 04:14:06 +0800 Subject: [PATCH] Resolve the declared bed layout on the streaming path --- src/stream/stream.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/stream/stream.h | 4 ++++ 2 files changed, 45 insertions(+) diff --git a/src/stream/stream.cpp b/src/stream/stream.cpp index c1ad822..c00ba2f 100644 --- a/src/stream/stream.cpp +++ b/src/stream/stream.cpp @@ -9,6 +9,7 @@ #include "hrtf/jochrtf.h" #include "hrtf/rosella_model.h" #include "hrtf/sofa_cache.h" +#include "joc_bitstream/bed_layout_map.h" #include "joc_bitstream/joc_parser.h" #include "joc_core/objects16.h" @@ -186,12 +187,52 @@ Status Stream::create(const Config& config) { return Status::success(); } +void Stream::apply_bed_positions(const FrameMetadata& entry) { + if (bed_positions_ready_ || entry.bed_assignments.empty()) { + return; + } + const bool bed_only = entry.has_update && entry.update.content_bed && + !entry.update.content_isf && !entry.update.content_dynamic; + const ::joc::joc::BedLayout bed = ::joc::joc::resolve_bed_layout(entry.bed_assignments, bed_only); + if (!bed.present) { + return; + } + bed_positions_ready_ = true; + if (!bed.bed_only) { + return; + } + for (std::size_t slot = 0; slot < bed.channels.size() && + slot < static_cast(oamd::kObjects); + ++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 (!speaker_enabled_) { + continue; + } + std::uint16_t q15[3] = {0, 0, 0}; + if (!::joc::joc::layout_bed_anchor(speaker_.layout.out_ch_config, channel, q15) && + !::joc::joc::bed_channel_q15(channel, q15)) { + continue; + } + speaker_.bed_override[slot] = true; + for (int axis = 0; axis < oamd::kAxes; ++axis) { + speaker_.bed_positions[slot][axis] = q15[axis]; + } + } +} + Status Stream::flush_pending_frame() { if (pending_frame_.streams.empty()) { return Status::success(); } FrameMetadata entry = pending_frame_; pending_frame_ = FrameMetadata(); + if (entry.has_joc) { + apply_bed_positions(entry); + } if (entry.has_joc) { std::string error; joc::CrossLayerNotes notes; diff --git a/src/stream/stream.h b/src/stream/stream.h index 4ac439a..7d7e168 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h @@ -128,6 +128,9 @@ private: return rosella_ready_ ? (rosella_pending_.size() - rosella_read_offset_) / 2u : 0u; } void reset_state(); + // 声明的 bed 布局只在首帧解析一次:bed 声道在 OAMD 里没有位置字段,方位由布局 + // 给出;流式路径和文件任务走同一套 SpeakerStep/双耳运行时,所以这里也要下发。 + void apply_bed_positions(const FrameMetadata& entry); // Drops the bed samples that have already been rendered, keeping the rest. void compact_bed_pending(); // Closes the audio frame currently being assembled and queues it. @@ -173,6 +176,7 @@ private: bool speaker_enabled_ = false; bool binaural_enabled_ = false; bool binaural_ready_ = false; + bool bed_positions_ready_ = false; bool rosella_ready_ = false; float gain_ = 1.0f; };