Port the OAMD bed layout map and the fixed bed positions into the kernel
ci / ubuntu-latest (push) Failing after 46s
ci / macos-latest (push) Canceled after 0s
ci / windows-latest (push) Canceled after 0s
ci / release (push) Canceled after 0s

This commit is contained in:
TheM14 committed 2026-10-30 04:00:38 +08:00
1 parent 2a79db4868
commit 1227fd6bbb
16 files changed
+576 -27

No files matched your search

+1
View File
@@ -118,6 +118,7 @@ set(JOC_INTERNAL_SOURCES
src/io/process.cpp src/io/process.cpp
src/io/wav_writer.cpp src/io/wav_writer.cpp
src/io/zip_reader.cpp src/io/zip_reader.cpp
src/joc_bitstream/bed_layout_map.cpp
src/joc_bitstream/joc_parser.cpp src/joc_bitstream/joc_parser.cpp
src/joc_core/objects16.cpp src/joc_core/objects16.cpp
src/oamd/oamd_parser.cpp src/oamd/oamd_parser.cpp
+5 -3
View File
@@ -212,9 +212,11 @@ ffmpeg gets `-ac 6` only for the $N=5$ configurations; $N=7$ keeps the decoder's
a non-zero $joc\_ext\_config\_idx$ is an unmapped variant, and a declared object count above 15 is a non-zero $joc\_ext\_config\_idx$ is an unmapped variant, and a declared object count above 15 is
clamped to 15 and recorded as a diagnostic - those change the DSP input, so a mismatch is refused. clamped to 15 and recorded as a diagnostic - those change the DSP input, so a mismatch is refused.
The extra pair's **identity** never reaches the DSP (section 10.1): when the dependent-substream The extra pair's **identity** never reaches the DSP (section 10.1): when the dependent-substream
`chanmap` disagrees with $k$, or an OAMD standard bed mask does, the mismatch is recorded as a `chanmap` disagrees with $k$, the mismatch is recorded as a diagnostic and the frame still
diagnostic and the frame still renders, with the bed mapping following the channel codes the renders, with the bed mapping following the channel codes the `chanmap` declares. The bed
`chanmap` declares. When one audio frame holds several EMDF containers carrying ID11/ID14, they layout the OAMD declares may hold more channels than the core substream codes (a 9.1.6 bed
with a 5.1 core, for example): only a core channel missing from that layout counts as a
mismatch. When one audio frame holds several EMDF containers carrying ID11/ID14, they
are scored by the association rule of section 8.2 and its Table 56: a container whose OAMD and JOC are scored by the association rule of section 8.2 and its Table 56: a container whose OAMD and JOC
payloads share a group id and whose ID14 parses completely wins, then one whose ID14 merely parses; payloads share a group id and whose ID14 parses completely wins, then one whose ID14 merely parses;
only a unique best score is used and the others are recorded as a diagnostic only a unique best score is used and the others are recorded as a diagnostic
+2 -1
View File
@@ -183,7 +183,8 @@ ffmpeg 侧只在 $N=5$ 档位传 `-ac 6`;$N=7$ 档位不传 `-ac`,保留解
**跨层一致性校验**(§11.2):子流声明的全频段通道数必须等于 $N$,$joc\_ext\_config\_idx$ 非零 **跨层一致性校验**(§11.2):子流声明的全频段通道数必须等于 $N$,$joc\_ext\_config\_idx$ 非零
时报未映射变体,对象数超过 15 时截断到 15 并记入 diagnostics——这几项会改变 DSP 输入,不一致就 时报未映射变体,对象数超过 15 时截断到 15 并记入 diagnostics——这几项会改变 DSP 输入,不一致就
拒绝。额外那一对的**身份**只进元数据、不进 DSP(§10.1):依赖子流 `chanmap` 与 $k$ 不一致、或 拒绝。额外那一对的**身份**只进元数据、不进 DSP(§10.1):依赖子流 `chanmap` 与 $k$ 不一致、或
OAMD 标准 bed 掩码与 $k$ 不一致时,只记 diagnostics 并照常解码,床映射按 `chanmap` 的通道码走。 OAMD 声明的 bed 布局可以比核心子流实际编码的声道多(例如 9.1.6 bed 只编 5.1 核心),只有核心
声道在 bed 布局里找不到位置才记 diagnostics 并照常解码,床映射按 `chanmap` 的通道码走。
同一音频帧里出现多个含 ID11/ID14 的 EMDF 容器时,按规格 §8.2 + Table 56 的关联规则打分: 同一音频帧里出现多个含 ID11/ID14 的 EMDF 容器时,按规格 §8.2 + Table 56 的关联规则打分:
OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只看 ID14 能否解析;唯一最高分才用, OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只看 ID14 能否解析;唯一最高分才用,
其余记入 diagnostics(`emdf/extra_container_ignored`)。额外那一对在 10 槽 ADM 骨架上的落位 其余记入 diagnostics(`emdf/extra_container_ignored`)。额外那一对在 10 槽 ADM 骨架上的落位
+15
View File
@@ -236,6 +236,9 @@ void TrajectoryBuilder::submit_frame(std::int64_t frame_index, const oamd::OamdU
ramp_samples = static_cast<std::int64_t>(update->ramp_duration_samples); ramp_samples = static_cast<std::int64_t>(update->ramp_duration_samples);
} }
for (int object = 1; object <= kObjectCount; ++object) { for (int object = 1; object <= kObjectCount; ++object) {
if (fixed_[object - 1]) {
continue; // 固定 bed 声道:位置由布局给出,不跟 OAMD 更新
}
double x = 0.0; double x = 0.0;
double y = 0.0; double y = 0.0;
double z = 0.0; double z = 0.0;
@@ -260,6 +263,18 @@ Status TrajectoryBuilder::build(std::int64_t total_samples, TrajectoryMode mode,
for (int object = 1; object <= kObjectCount; ++object) { for (int object = 1; object <= kObjectCount; ++object) {
Track track; Track track;
track.name = "JOC_Object_" + std::to_string(object); track.name = "JOC_Object_" + std::to_string(object);
if (fixed_[object - 1]) {
Keyframe block;
block.rtime_samples = 0;
block.x = fixed_xyz_[object - 1][0];
block.y = fixed_xyz_[object - 1][1];
block.z = fixed_xyz_[object - 1][2];
block.duration_samples = total_samples;
block.interpolation_samples = 0;
track.blocks.push_back(block);
out->push_back(std::move(track));
continue;
}
const Status status = const Status status =
(mode == TrajectoryMode::Compact) (mode == TrajectoryMode::Compact)
? expand_compact(events_[object - 1], total_samples, rate_, block_, ? expand_compact(events_[object - 1], total_samples, rate_, block_,
+14
View File
@@ -38,6 +38,18 @@ public:
Status build(std::int64_t total_samples, TrajectoryMode mode, std::vector<Track>* out) const; 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]; } const std::vector<OamdEvent>& events(int object_index) const { return events_[object_index]; }
std::uint32_t rate() const { return rate_; } std::uint32_t rate() const { return rate_; }
std::int64_t object_delay_samples() const { return object_delay_; } std::int64_t object_delay_samples() const { return object_delay_; }
@@ -50,6 +62,8 @@ private:
std::vector<OamdEvent> events_[kObjectCount]; std::vector<OamdEvent> events_[kObjectCount];
bool has_previous_[kObjectCount] = {}; bool has_previous_[kObjectCount] = {};
double previous_[kObjectCount][3] = {}; 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, Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
+5
View File
@@ -72,6 +72,11 @@ public:
std::size_t staged_samples() const { return staged_; } std::size_t staged_samples() const { return staged_; }
const timeline::OamdPositionTimeline& timeline() const { return timeline_; } const timeline::OamdPositionTimeline& timeline() const { return timeline_; }
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
void set_fixed_position(int object_index, const double position[3]) {
timeline_.set_fixed_position(object_index, position);
}
// finish_output_capacity as the reference computes it (plan 21.4). // finish_output_capacity as the reference computes it (plan 21.4).
std::uint32_t finish_capacity(double tail_seconds) const; std::uint32_t finish_capacity(double tail_seconds) const;
+331
View File
@@ -0,0 +1,331 @@
#include "joc_bitstream/bed_layout_map.h"
#include <cstring>
#include "speaker/speaker_layouts.h"
namespace joc::joc {
namespace {
constexpr std::uint32_t bit(BedChannel channel) {
return 1u << static_cast<unsigned>(channel);
}
// Table 12 每个 bit 展开的声道(LSB 在前)。
struct StandardBit {
BedChannel first;
BedChannel second; // kCount 表示单声道
};
constexpr StandardBit kStandardBits[10] = {
{BedChannel::kLeft, BedChannel::kRight},
{BedChannel::kCenter, BedChannel::kCount},
{BedChannel::kLfe, BedChannel::kCount},
{BedChannel::kLeftSurround, BedChannel::kRightSurround},
{BedChannel::kLeftRearSurround, BedChannel::kRightRearSurround},
{BedChannel::kTopFrontLeft, BedChannel::kTopFrontRight},
{BedChannel::kTopSideLeft, BedChannel::kTopSideRight},
{BedChannel::kTopBackLeft, BedChannel::kTopBackRight},
{BedChannel::kLeftWide, BedChannel::kRightWide},
{BedChannel::kLfe2, BedChannel::kCount},
};
// Table 13 的 17 bit 非标准掩码(LSB 在前)。
constexpr BedChannel kNonStandardBits[17] = {
BedChannel::kLfe2, BedChannel::kRightWide, BedChannel::kLeftWide,
BedChannel::kTopBackRight, BedChannel::kTopBackLeft,
BedChannel::kTopSideRight, BedChannel::kTopSideLeft,
BedChannel::kTopFrontRight, BedChannel::kTopFrontLeft,
BedChannel::kRightRearSurround, BedChannel::kLeftRearSurround,
BedChannel::kRightSurround, BedChannel::kLeftSurround,
BedChannel::kLfe, BedChannel::kCenter, BedChannel::kRight,
BedChannel::kLeft,
};
struct ChannelSpec {
BedChannel channel;
const char* short_name;
const char* label;
double xyz[3];
};
constexpr ChannelSpec kChannels[] = {
{BedChannel::kLeft, "L", "RC_L", {-1.0, 1.0, 0.0}},
{BedChannel::kRight, "R", "RC_R", {1.0, 1.0, 0.0}},
{BedChannel::kCenter, "C", "RC_C", {0.0, 1.0, 0.0}},
{BedChannel::kLfe, "LFE", "RC_LFE", {0.0, 0.0, 0.0}},
{BedChannel::kLeftSurround, "Ls", "RC_LS", {-1.0, 0.0, 0.0}},
{BedChannel::kRightSurround, "Rs", "RC_RS", {1.0, 0.0, 0.0}},
{BedChannel::kLeftRearSurround, "Lrs", "RC_LB", {-1.0, -1.0, 0.0}},
{BedChannel::kRightRearSurround, "Rrs", "RC_RB", {1.0, -1.0, 0.0}},
{BedChannel::kTopFrontLeft, "Ltf", "RC_TFL", {-0.5, 0.5, 1.0}},
{BedChannel::kTopFrontRight, "Rtf", "RC_TFR", {0.5, 0.5, 1.0}},
{BedChannel::kTopSideLeft, "Ltm", "RC_TSL", {-1.0, 0.0, 1.0}},
{BedChannel::kTopSideRight, "Rtm", "RC_TSR", {1.0, 0.0, 1.0}},
{BedChannel::kTopBackLeft, "Ltr", "RC_TBL", {-0.5, -0.5, 1.0}},
{BedChannel::kTopBackRight, "Rtr", "RC_TBR", {0.5, -0.5, 1.0}},
{BedChannel::kLeftWide, "Lw", "RC_LW", {-1.0, 0.5, 0.0}},
{BedChannel::kRightWide, "Rw", "RC_RW", {1.0, 0.5, 0.0}},
{BedChannel::kLfe2, "LFE2", "RC_LFE2", {0.0, 0.0, 0.0}},
};
const ChannelSpec* spec_of(BedChannel channel) {
for (const ChannelSpec& spec : kChannels) {
if (spec.channel == channel) {
return &spec;
}
}
return nullptr;
}
// 标准 bed 布局名,键是声明声道的集合。
struct LayoutName {
std::uint32_t mask;
const char* name;
};
constexpr std::uint32_t mask_of() { return 0u; }
constexpr LayoutName kLayoutNames[] = {
{bit(BedChannel::kLeft) | bit(BedChannel::kRight), "2.0"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) | bit(BedChannel::kCenter), "3.0"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) | bit(BedChannel::kCenter) |
bit(BedChannel::kLfe), "3.1"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround), "4.0"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter), "5.0"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe), "5.1"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround), "7.1"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide), "9.1"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "5.1.2"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "5.1.4"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "7.1.2"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "7.1.4"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight) |
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "7.1.6"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "9.1.2"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "9.1.4"},
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight) |
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "9.1.6"},
};
const char* layout_name_for(std::uint32_t mask) {
for (const LayoutName& entry : kLayoutNames) {
if (entry.mask == mask) {
return entry.name;
}
}
return "";
}
// 每个扬声器布局的标准声道名(按该布局的标准声道顺序排列)。
struct LayoutChannels {
std::uint32_t out_ch_config;
std::uint32_t count;
const char* names[16];
};
constexpr LayoutChannels kLayoutChannels[] = {
{0, 2, {"L", "R"}},
{3, 4, {"L", "R", "C", "LFE"}},
{255, 4, {"L", "R", "Lrs", "Rrs"}},
{7, 6, {"L", "R", "C", "LFE", "Ls", "Rs"}},
{11, 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"}},
{13, 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"}},
{14, 10, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"}},
{15, 10, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltm", "Rtm"}},
{16, 12, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltf", "Rtf", "Ltr", "Rtr"}},
{19, 14, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw",
"Ltf", "Rtf", "Ltr", "Rtr"}},
{20, 16, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw",
"Ltf", "Rtf", "Ltm", "Rtm", "Ltr", "Rtr"}},
};
const ejoc::speaker_tables::LayoutGeometry* geometry_for(std::uint32_t out_ch_config) {
for (const ejoc::speaker_tables::LayoutGeometry& layout : ejoc::speaker_tables::kLayouts) {
if (layout.out_ch_config == out_ch_config) {
return &layout;
}
}
return nullptr;
}
} // namespace
BedLayout resolve_bed_layout(const std::vector<oamd::BedAssignment>& assignments,
bool bed_only) {
BedLayout layout;
layout.bed_only = bed_only;
std::uint32_t mask = 0;
for (const oamd::BedAssignment& assignment : assignments) {
if (assignment.lfe_only) {
mask |= bit(BedChannel::kLfe);
layout.complete = false;
continue;
}
if (assignment.standard) {
for (int index = 0; index < 10; ++index) {
if (((assignment.mask >> index) & 1u) == 0u) {
continue;
}
mask |= bit(kStandardBits[index].first);
if (kStandardBits[index].second != BedChannel::kCount) {
mask |= bit(kStandardBits[index].second);
}
}
continue;
}
for (int index = 0; index < 17; ++index) {
if (((assignment.mask >> index) & 1u) != 0u) {
mask |= bit(kNonStandardBits[index]);
}
}
layout.complete = false; // 非标准掩码的声道名不在本标准表里
}
if (mask == 0u) {
return layout;
}
layout.present = true;
layout.mask = mask;
layout.name = layout_name_for(mask);
for (const ChannelSpec& spec : kChannels) {
const BedChannel channel = spec.channel;
if ((mask & bit(channel)) == 0u) {
continue;
}
if (channel == BedChannel::kLfe || channel == BedChannel::kLfe2) {
continue;
}
layout.channels.push_back(channel);
}
return layout;
}
const char* bed_channel_short_name(BedChannel channel) {
const ChannelSpec* spec = spec_of(channel);
return spec != nullptr ? spec->short_name : "";
}
const char* bed_channel_label(BedChannel channel) {
const ChannelSpec* spec = spec_of(channel);
return spec != nullptr ? spec->label : "";
}
bool bed_channel_adm_position(BedChannel channel, double xyz[3]) {
const ChannelSpec* spec = spec_of(channel);
if (spec == nullptr || xyz == nullptr) {
return false;
}
std::memcpy(xyz, spec->xyz, sizeof(spec->xyz));
return true;
}
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]) {
double xyz[3] = {0.0, 0.0, 0.0};
if (!bed_channel_adm_position(channel, xyz) || q15 == nullptr) {
return false;
}
const double q1 = (xyz[0] + 1.0) * 0.5 * 32767.0;
const double q2 = (1.0 - xyz[1]) * 0.5 * 32767.0;
const double q3 = xyz[2] * 32767.0;
q15[0] = static_cast<std::uint16_t>(q1 < 0.0 ? 0.0 : (q1 > 32767.0 ? 32767.0 : q1));
q15[1] = static_cast<std::uint16_t>(q2 < 0.0 ? 0.0 : (q2 > 32767.0 ? 32767.0 : q2));
q15[2] = static_cast<std::uint16_t>(q3 < 0.0 ? 0.0 : (q3 > 32767.0 ? 32767.0 : q3));
return true;
}
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
std::uint16_t q15[3]) {
if (q15 == nullptr) {
return false;
}
const char* name = bed_channel_short_name(channel);
if (name == nullptr || name[0] == '\0' || std::strcmp(name, "LFE") == 0) {
return false;
}
const LayoutChannels* table = nullptr;
for (const LayoutChannels& entry : kLayoutChannels) {
if (entry.out_ch_config == out_ch_config) {
table = &entry;
break;
}
}
const ejoc::speaker_tables::LayoutGeometry* geometry = geometry_for(out_ch_config);
if (table == nullptr || geometry == nullptr) {
return false;
}
int standard_index = -1;
for (std::uint32_t index = 0; index < table->count; ++index) {
if (std::strcmp(table->names[index], name) == 0) {
standard_index = static_cast<int>(index);
break;
}
}
if (standard_index < 0) {
return false;
}
const std::uint8_t internal = geometry->standard_from_internal[standard_index];
const ejoc::speaker_tables::RegionGeometry& region = geometry->regions[0];
for (std::uint32_t point = 0; point < region.point_count; ++point) {
if (region.points[point].speaker_id != internal) {
continue;
}
for (int axis = 0; axis < 3; ++axis) {
q15[axis] = region.points[point].coordinate_q15[axis];
}
return true;
}
return false;
}
} // namespace joc::joc
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "oamd/oamd_parser.h"
namespace joc::joc {
// OAMD Table 12 的标准 bed 声道。LSB 顺序与声明顺序一致:L/R、C、LFE、
// Ls/Rs、Lrs/Rrs、TFL/TFR、TSL/TSR、TBL/TBR、LW/RW、LFE2。
enum class BedChannel : std::uint8_t {
kLeft = 0,
kRight,
kCenter,
kLfe,
kLeftSurround,
kRightSurround,
kLeftRearSurround,
kRightRearSurround,
kTopFrontLeft,
kTopFrontRight,
kTopSideLeft,
kTopSideRight,
kTopBackLeft,
kTopBackRight,
kLeftWide,
kRightWide,
kLfe2,
kCount,
};
// 内容声明的 bed 布局。bed 对象在 OAMD 里没有位置字段,位置由这里的布局决定。
struct BedLayout {
bool present = false; // 有 bed_assignment() 声明
bool bed_only = false; // program 只由 bed 组成(无 ISF、无动态对象)
bool complete = true; // 所有声明声道都在本标准表里
const char* name = ""; // "9.1.6" 等;未知集合为空串
std::uint32_t mask = 0; // 声明声道的位集合(1 << BedChannel)
std::vector<BedChannel> channels; // 去掉 LFE/LFE2,按 JOC 对象槽顺序
};
// 声明里是否包含某个 bed 声道。
inline bool bed_layout_has(const BedLayout& layout, BedChannel channel) {
return (layout.mask & (1u << static_cast<unsigned>(channel))) != 0u;
}
// 展开 bed_assignment() 声明;``bed_only`` 来自 program_assignment() 的
// content_description。
BedLayout resolve_bed_layout(const std::vector<oamd::BedAssignment>& assignments,
bool bed_only);
// 扬声器布局里的短名("Lw")与 Table 12 的标签("RC_LW")。
const char* bed_channel_short_name(BedChannel channel);
const char* bed_channel_label(BedChannel channel);
// 固定方位:ADM 笛卡尔坐标(x 右、y 前、z 上)与渲染器使用的 Q15 方位。
bool bed_channel_adm_position(BedChannel channel, double xyz[3]);
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]);
// 目标布局里同名扬声器的 Q15 方位:bed 声道直连到该扬声器,而不是参与声像。
// 目标布局没有这个声道时返回 false。
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
std::uint16_t q15[3]);
} // namespace joc::joc
+39 -18
View File
@@ -1,5 +1,7 @@
#include "joc_bitstream/joc_parser.h" #include "joc_bitstream/joc_parser.h"
#include "joc_bitstream/bed_layout_map.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@@ -545,6 +547,26 @@ std::string position_name(Position position) {
} }
} }
// 核心声道位置 → bed 布局声道;返回 kCount 表示本标准表没有对应身份。
BedChannel bed_channel_for_position(Position position) {
switch (position) {
case Position::kLeft: return BedChannel::kLeft;
case Position::kRight: return BedChannel::kRight;
case Position::kCenter: return BedChannel::kCenter;
case Position::kLfe: return BedChannel::kLfe;
case Position::kLfe2: return BedChannel::kLfe2;
case Position::kLeftSurround: return BedChannel::kLeftSurround;
case Position::kRightSurround: return BedChannel::kRightSurround;
case Position::kLeftRearSurround: return BedChannel::kLeftRearSurround;
case Position::kRightRearSurround: return BedChannel::kRightRearSurround;
case Position::kVerticalHeightLeft: return BedChannel::kTopFrontLeft;
case Position::kVerticalHeightRight: return BedChannel::kTopFrontRight;
case Position::kTopSurroundLeft: return BedChannel::kTopSideLeft;
case Position::kTopSurroundRight: return BedChannel::kTopSideRight;
default: return BedChannel::kCount;
}
}
std::string position_list(const std::vector<Position>& positions) { std::string position_list(const std::vector<Position>& positions) {
std::string text = "["; std::string text = "[";
for (std::size_t index = 0; index < positions.size(); ++index) { for (std::size_t index = 0; index < positions.size(); ++index) {
@@ -917,25 +939,24 @@ Status check_cross_layer(const joc_frame_params& params, const eac3::Frame* core
error); error);
} }
if (bed_assignments != nullptr) { if (bed_assignments != nullptr && !bed_assignments->empty()) {
static constexpr std::uint32_t kBedBitLeftRear = 1u << 4; // RC_LB/RC_RB // OAMD 的 bed 掩码描述的是内容的 bed 布局,可以比核心子流实际编码的声道多
static constexpr std::uint32_t kBedBitTopFront = 1u << 5; // RC_TFL/RC_TFR // (例如 9.1.6 bed 只编 5.1 核心)。只有核心声道在 bed 布局里找不到位置才是
std::vector<Position> declared_pair; // 真正的不一致;多出来的 bed 声道是布局的一部分。
for (const oamd::BedAssignment& assignment : *bed_assignments) { const BedLayout bed = resolve_bed_layout(*bed_assignments, true);
if (!assignment.standard || assignment.mask == 0u) { if (bed.present && bed.complete) {
continue; bool covered = true;
for (const Position position : core_positions) {
const BedChannel channel = bed_channel_for_position(position);
if (channel == BedChannel::kCount) {
continue;
}
if (!bed_layout_has(bed, channel)) {
covered = false;
break;
}
} }
if ((assignment.mask & kBedBitLeftRear) != 0u) { if (!covered && notes != nullptr) {
push_unique(&declared_pair, Position::kLeftRearSurround);
push_unique(&declared_pair, Position::kRightRearSurround);
}
if ((assignment.mask & kBedBitTopFront) != 0u) {
push_unique(&declared_pair, Position::kVerticalHeightLeft);
push_unique(&declared_pair, Position::kVerticalHeightRight);
}
}
if (!declared_pair.empty() && declared_pair != wanted) {
if (notes != nullptr) {
notes->bed_mask_mismatch = true; notes->bed_mask_mismatch = true;
} }
} }
+9
View File
@@ -64,6 +64,9 @@ bool variable_bits_max(bits::BitReader& reader, unsigned width, unsigned max_gro
struct ProgramInfo { struct ProgramInfo {
bool dynamic_object_only = false; bool dynamic_object_only = false;
bool lfe_present = false; bool lfe_present = false;
bool content_bed = false;
bool content_isf = false;
bool content_dynamic = false;
std::uint32_t num_bed_objects = 0; std::uint32_t num_bed_objects = 0;
std::uint32_t num_isf_objects = 0; std::uint32_t num_isf_objects = 0;
std::int32_t num_dynamic_objects = -1; std::int32_t num_dynamic_objects = -1;
@@ -88,6 +91,9 @@ Status parse_program_assignment(bits::BitReader& reader, ProgramInfo* program) {
if (reader.failed()) { if (reader.failed()) {
return syntax("program_assignment truncated"); return syntax("program_assignment truncated");
} }
program->content_bed = (mask & 0x1u) != 0u;
program->content_isf = (mask & 0x2u) != 0u;
program->content_dynamic = (mask & 0x4u) != 0u;
if ((mask & 0x1u) != 0u) { if ((mask & 0x1u) != 0u) {
reader.read(1); reader.read(1);
const std::uint32_t multi = reader.read(1); const std::uint32_t multi = reader.read(1);
@@ -520,6 +526,9 @@ Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size,
out->num_bed_objects = program.num_bed_objects; out->num_bed_objects = program.num_bed_objects;
out->num_isf_objects = program.num_isf_objects; out->num_isf_objects = program.num_isf_objects;
out->num_dynamic_objects = program.num_dynamic_objects; out->num_dynamic_objects = program.num_dynamic_objects;
out->content_bed = program.content_bed;
out->content_isf = program.content_isf;
out->content_dynamic = program.content_dynamic;
if (trace != nullptr) { if (trace != nullptr) {
trace->bed_assignments = program.bed_assignments; trace->bed_assignments = program.bed_assignments;
+4
View File
@@ -35,6 +35,10 @@ struct OamdUpdate {
std::uint32_t num_bed_objects = 0; std::uint32_t num_bed_objects = 0;
std::uint32_t num_isf_objects = 0; std::uint32_t num_isf_objects = 0;
std::int32_t num_dynamic_objects = -1; std::int32_t num_dynamic_objects = -1;
// program_assignment() 的 content_description:bed / ISF / 动态对象三类内容。
bool content_bed = false;
bool content_isf = false;
bool content_dynamic = false;
}; };
class OamdState { class OamdState {
+8
View File
@@ -37,6 +37,14 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
std::uint16_t positions[oamd::kObjects][3] = {}; std::uint16_t positions[oamd::kObjects][3] = {};
context->state.object_positions_q15(positions); context->state.object_positions_q15(positions);
for (int object = 0; object < oamd::kObjects; ++object) {
if (!context->bed_override[object]) {
continue;
}
for (int axis = 0; axis < oamd::kAxes; ++axis) {
positions[object][axis] = context->bed_positions[object][axis];
}
}
// A frame without OAMD must not touch the gains at all (no event), otherwise a // A frame without OAMD must not touch the gains at all (no event), otherwise a
// pending ramp would snap - matching the reference exactly. // pending ramp would snap - matching the reference exactly.
const std::uint32_t event_count = context->last_had_payload ? 1u : 0u; const std::uint32_t event_count = context->last_had_payload ? 1u : 0u;
+4
View File
@@ -23,6 +23,10 @@ struct SpeakerStep {
std::uint32_t last_ramp_duration = 0; std::uint32_t last_ramp_duration = 0;
std::uint32_t last_object_count = 0; std::uint32_t last_object_count = 0;
bool last_had_payload = false; bool last_had_payload = false;
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。这里存
// 对象槽 → Q15 方位;bed_override 为 false 的槽仍按 OAMD 坐标声像。
std::uint16_t bed_positions[oamd::kObjects][oamd::kAxes] = {};
bool bed_override[oamd::kObjects] = {};
}; };
Status step(SpeakerStep* context, const std::vector<float>& objects16_planar, Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
+54 -5
View File
@@ -41,6 +41,7 @@
#include "io/process.h" #include "io/process.h"
#include "io/wav_writer.h" #include "io/wav_writer.h"
#include "joc_bitstream/joc_parser.h" #include "joc_bitstream/joc_parser.h"
#include "joc_bitstream/bed_layout_map.h"
#include "joc_core/objects16.h" #include "joc_core/objects16.h"
#include "oamd/oamd_parser.h" #include "oamd/oamd_parser.h"
#include "speaker/speaker_step.h" #include "speaker/speaker_step.h"
@@ -1322,6 +1323,7 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
} }
::joc::speaker::SpeakerStep speaker; ::joc::speaker::SpeakerStep speaker;
bool bed_positions_ready = false;
const bool speaker_enabled = cfg.operation == JOC_OP_SPEAKER; const bool speaker_enabled = cfg.operation == JOC_OP_SPEAKER;
if (speaker_enabled) { if (speaker_enabled) {
if (!::joc::speaker::layout_by_name(cfg.layout.c_str(), &speaker.layout)) { if (!::joc::speaker::layout_by_name(cfg.layout.c_str(), &speaker.layout)) {
@@ -1745,6 +1747,58 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
job.outer_offset = static_cast<std::int64_t>(payload->sample_offset); job.outer_offset = static_cast<std::int64_t>(payload->sample_offset);
const Status bed_ok = ::joc::oamd::parse_id11_bed_assignments( const Status bed_ok = ::joc::oamd::parse_id11_bed_assignments(
bytes.data(), bytes.size(), &group_bed_assignments); bytes.data(), bytes.size(), &group_bed_assignments);
if (bed_ok.ok() && !bed_positions_ready &&
!group_bed_assignments.empty()) {
const ::joc::joc::BedLayout bed_layout =
::joc::joc::resolve_bed_layout(
group_bed_assignments,
job.update.content_bed && !job.update.content_isf &&
!job.update.content_dynamic);
if (bed_layout.present) {
bed_positions_ready = true;
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER,
JOC_LOG_INFO,
fmt("bed layout: %s (%u bed channels)",
bed_layout.name[0] != '\0'
? bed_layout.name : "custom",
static_cast<unsigned>(
bed_layout.channels.size())));
if (bed_layout.bed_only) {
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
for (std::size_t slot = 0;
slot < bed_layout.channels.size() &&
slot < static_cast<std::size_t>(::joc::oamd::kObjects);
++slot) {
const ::joc::joc::BedChannel channel =
bed_layout.channels[slot];
double xyz[3] = {0.0, 0.0, 0.0};
if (::joc::joc::bed_channel_adm_position(channel, xyz)) {
trajectory.set_fixed_position(
static_cast<int>(slot) + 1, xyz[0], xyz[1],
xyz[2]);
if (binaural_enabled) {
binaural.set_fixed_position(
static_cast<int>(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 < ::joc::oamd::kAxes; ++axis) {
speaker.bed_positions[slot][axis] = q15[axis];
}
}
}
}
}
if (!bed_ok.ok()) { if (!bed_ok.ok()) {
failures.record(produced, StageRank::kJoc, bed_ok.code(), failures.record(produced, StageRank::kJoc, bed_ok.code(),
bed_ok.stage(), bed_ok.message()); bed_ok.stage(), bed_ok.message());
@@ -2039,11 +2093,6 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
" audio frame(s): the chanmap declares a different extra pair than " " audio frame(s): the chanmap declares a different extra pair than "
"joc_dmx_config_idx; the bed mapping follows the chanmap"); "joc_dmx_config_idx; the bed mapping follows the chanmap");
} }
if (bed_mask_mismatch_frames != 0u) {
bus.warning(std::to_string(bed_mask_mismatch_frames) +
" audio frame(s): the OAMD bed mask declares a different extra pair than "
"joc_dmx_config_idx; the bed mask only affects metadata");
}
StageFailure recorded; StageFailure recorded;
if (failures.earliest(&recorded)) { if (failures.earliest(&recorded)) {
return finalize_with_error(recorded.code, recorded.stage_text, recorded.message); return finalize_with_error(recorded.code, recorded.stage_text, recorded.message);
+4
View File
@@ -114,6 +114,10 @@ Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
double targets[kTimelineObjects][3] = {}; double targets[kTimelineObjects][3] = {};
for (int index = 0; index < kTimelineObjects; ++index) { for (int index = 0; index < kTimelineObjects; ++index) {
if (fixed_[index]) {
std::memcpy(targets[index], fixed_xyz_[index], sizeof(targets[index]));
continue;
}
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1), geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
state_.q(index + 1, 2), &targets[index][0], &targets[index][1], state_.q(index + 1, 2), &targets[index][0], &targets[index][1],
&targets[index][2]); &targets[index][2]);
+13
View File
@@ -49,6 +49,17 @@ public:
// positions[15][3]; queries must be monotonically increasing. // positions[15][3]; queries must be monotonically increasing.
Status positions_at(std::int64_t sample, double positions[kTimelineObjects][3]); Status positions_at(std::int64_t sample, double positions[kTimelineObjects][3]);
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
void set_fixed_position(int object_index, const double position[3]) {
if (object_index < 1 || object_index > kTimelineObjects) {
return;
}
fixed_[object_index - 1] = true;
fixed_xyz_[object_index - 1][0] = position[0];
fixed_xyz_[object_index - 1][1] = position[1];
fixed_xyz_[object_index - 1][2] = position[2];
}
std::uint64_t payload_count() const { return payload_count_; } std::uint64_t payload_count() const { return payload_count_; }
std::uint64_t transition_count() const { return transition_count_; } std::uint64_t transition_count() const { return transition_count_; }
bool initialized() const { return initialized_; } bool initialized() const { return initialized_; }
@@ -62,6 +73,8 @@ private:
bool initialized_ = false; bool initialized_ = false;
double previous_targets_[kTimelineObjects][3] = {}; double previous_targets_[kTimelineObjects][3] = {};
bool has_previous_[kTimelineObjects] = {}; bool has_previous_[kTimelineObjects] = {};
bool fixed_[kTimelineObjects] = {};
double fixed_xyz_[kTimelineObjects][3] = {};
std::uint64_t payload_count_ = 0; std::uint64_t payload_count_ = 0;
std::uint64_t transition_count_ = 0; std::uint64_t transition_count_ = 0;
std::int64_t last_coded_event_sample_ = -1; std::int64_t last_coded_event_sample_ = -1;