Sync the kernel copy with the OAMD frame-level core
The kernel copy follows the new kernel. The renderer has a frame-level state machine (normal, hold, hard cut and passthrough, the 8-plane passthrough, the LFE clipgain ramp and interpolation when no previous state exists), the OAMD parser carries the complete frame state (several blocks, more than 16 objects) and the speaker renderer applies the metadata (gain and inactive flags, zone/elevation, size, snap, divergence, ISF and bed distribution). oamd_math and oamd_params are new modules, the ISF tables are compiled in now that the upstream data/ directory is gone, and the binaural timeline accepts a complete frame state. joc_core.h moves to ABI 6 (frame parameters and EMDF payload info at v2, JOC_FRAME_STATUS_*, raw 5-bit offset_ts) and eac3joc_core.h to EJOC ABI 4 (EJOC_FRAME_STATUS_*, ejoc_frame_input v1, ejoc_renderer_render_frame, EJOC_CORE_OUT_CHANNELS and EJOC_LFE_SLOT; the old ejoc_renderer_process stays). joc_stream.h and joc_version.h are unchanged. joc_kernel.vcxproj lists the two new translation units and the four new headers. The component's layout table gains the kernel's 6.0 layout (L R Ls Rs Lrs Rrs) after 9.1.6, and layout_table_test expects twelve layouts, so the list the preferences page shows and the list the renderer accepts are the same again. README, THIRD_PARTY_NOTICES and the CI comment pin the copy to commit 3f0d5e87fe41b90d9350528d2dca2ca82a637a3f; tag v1.2.0 points at the older a276028 and is not the sync baseline. Builds Release-Static|x64 and |Win32 with no errors. The offline test tools build and pass on both architectures: layout_table_test reports 12 layouts, and channel_swap_test, log_rotation_test and long_path_test pass. scan_crosscheck agrees with the core on the upstream test material, and the render harness delivers 7.1.4 speaker output and binaural output on both architectures, with the speaker-path WAV byte-identical between them. The core is still vendored under kernel/; building it from the upstream checkout at build time is a separate change.
This commit is contained in:
1 parent
5b41868e94
commit
defe9538fe
39 files changed
+6714
-616
No files matched your search
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "speaker/speaker_layouts.h"
|
||||
@@ -100,6 +101,9 @@ constexpr LayoutName kLayoutNames[] = {
|
||||
{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::kLeftRearSurround) | bit(BedChannel::kRightRearSurround), "6.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
@@ -328,4 +332,301 @@ bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// ETSI TS 103 420 Table B.10: the fixed ADM position of every Table 12 bed
|
||||
// channel. bed_output_description() matches these points against the target
|
||||
// layout; the kChannels table above keeps the ADM/binaural path's coordinates.
|
||||
struct TableB10Position {
|
||||
BedChannel channel;
|
||||
double xyz[3];
|
||||
};
|
||||
|
||||
constexpr TableB10Position kTableB10[oamd::kBedLabelCount] = {
|
||||
{BedChannel::kLeft, {-1.0, 1.0, 0.0}},
|
||||
{BedChannel::kRight, {1.0, 1.0, 0.0}},
|
||||
{BedChannel::kCenter, {0.0, 1.0, 0.0}},
|
||||
{BedChannel::kLfe, {-1.0, 1.0, -1.0}},
|
||||
{BedChannel::kLeftSurround, {-1.0, 0.0, 0.0}},
|
||||
{BedChannel::kRightSurround, {1.0, 0.0, 0.0}},
|
||||
{BedChannel::kLeftRearSurround, {-1.0, -1.0, 0.0}},
|
||||
{BedChannel::kRightRearSurround, {1.0, -1.0, 0.0}},
|
||||
{BedChannel::kTopFrontLeft, {-1.0, 1.0, 1.0}},
|
||||
{BedChannel::kTopFrontRight, {1.0, 1.0, 1.0}},
|
||||
{BedChannel::kTopSideLeft, {-1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopSideRight, {1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopBackLeft, {-1.0, -1.0, 1.0}},
|
||||
{BedChannel::kTopBackRight, {1.0, -1.0, 1.0}},
|
||||
{BedChannel::kLeftWide, {-1.0, 21.0 / 31.0, 0.0}},
|
||||
{BedChannel::kRightWide, {1.0, 21.0 / 31.0, 0.0}},
|
||||
{BedChannel::kLfe2, {1.0, 1.0, -1.0}},
|
||||
};
|
||||
|
||||
// bed_layout.BED_REFERENCE_POSITIONS_Q15; index 3 is the non-spatial sentinel.
|
||||
constexpr std::int32_t kReferencePositions[kBedReferencePositionCount][3] = {
|
||||
{0, 0, 0}, {32767, 0, 0}, {16384, 0, 0}, {-1, -1, -1},
|
||||
{0, 16384, 0}, {32767, 16384, 0}, {0, 32767, 0}, {32767, 32767, 0},
|
||||
{16384, 32767, 0}, {5285, 0, 0}, {27483, 0, 0}, {0, 5285, 0},
|
||||
{32767, 5285, 0}, {7928, 0, 32767}, {24840, 0, 32767}, {7928, 7928, 32767},
|
||||
{24840, 7928, 32767}, {7928, 16384, 32767}, {24840, 16384, 32767},
|
||||
{7928, 24840, 32767}, {24840, 24840, 32767}, {7928, 32767, 32767},
|
||||
{24840, 32767, 32767}, {11099, 0, 0}, {21669, 0, 0}, {0, 11099, 0},
|
||||
{32767, 11099, 0}, {0, 21669, 0}, {32767, 21669, 0}, {0, 27483, 0},
|
||||
{32767, 27483, 0}, {5285, 32767, 0}, {27483, 32767, 0}, {11099, 32767, 0},
|
||||
{21669, 32767, 0}, {16384, 0, 32767}, {16384, 16384, 32767},
|
||||
{16384, 32767, 32767},
|
||||
};
|
||||
|
||||
// 自动 trim 的每个布局基准衰减,单位 dB。
|
||||
struct AttenuationEntry {
|
||||
const char* compact_name;
|
||||
double db;
|
||||
};
|
||||
|
||||
constexpr AttenuationEntry kAttenuation[] = {
|
||||
{"20", -4.5}, {"31", -4.5}, {"40", -3.0}, {"51", -3.0},
|
||||
{"60", -1.5}, {"71", -1.5}, {"512", -2.25}, {"514", -1.5},
|
||||
{"712", -0.75}, {"714", 0.0}, {"914", 0.0}, {"916", 0.0},
|
||||
};
|
||||
|
||||
constexpr int kMaxChannels = static_cast<int>(ejoc::speaker_tables::kMaxChannels);
|
||||
|
||||
void set_sentinel(std::int32_t coordinate[3]) {
|
||||
coordinate[0] = -1;
|
||||
coordinate[1] = -1;
|
||||
coordinate[2] = -1;
|
||||
}
|
||||
|
||||
bool is_sentinel(const std::int32_t coordinate[3]) {
|
||||
return coordinate[0] == -1 && coordinate[1] == -1 && coordinate[2] == -1;
|
||||
}
|
||||
|
||||
bool is_lfe_label(BedChannel channel) {
|
||||
return channel == BedChannel::kLfe || channel == BedChannel::kLfe2;
|
||||
}
|
||||
|
||||
const TableB10Position* table_b10(BedChannel channel) {
|
||||
for (const TableB10Position& entry : kTableB10) {
|
||||
if (entry.channel == channel) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ADM 笛卡尔坐标 -> 渲染器方位 (u 右, v 后, w 上)。
|
||||
void render_coordinates(const double xyz[3], double out[3]) {
|
||||
out[0] = (xyz[0] + 1.0) * 0.5;
|
||||
out[1] = (1.0 - xyz[1]) * 0.5;
|
||||
out[2] = xyz[2];
|
||||
}
|
||||
|
||||
// 渲染器方位的欧氏距离,比较的是归一化到 0..1 的坐标。
|
||||
double render_distance(const double left[3], const double right[3]) {
|
||||
const double du = left[0] - right[0];
|
||||
const double dv = left[1] - right[1];
|
||||
const double dw = left[2] - right[2];
|
||||
return std::sqrt(du * du + dv * dv + dw * dw);
|
||||
}
|
||||
|
||||
// Reference-position matching: the non-spatial sentinel resolves to index 3.
|
||||
int nearest_reference(const std::int32_t coordinate[3]) {
|
||||
if (is_sentinel(coordinate)) {
|
||||
return 3;
|
||||
}
|
||||
const double position[3] = {
|
||||
static_cast<double>(coordinate[0]) / 32768.0,
|
||||
static_cast<double>(coordinate[1]) / 32768.0,
|
||||
static_cast<double>(coordinate[2]) / 32768.0,
|
||||
};
|
||||
int best = 3;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (int index = 0; index < kBedReferencePositionCount; ++index) {
|
||||
const std::int32_t* candidate = kReferencePositions[index];
|
||||
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(candidate[0]) / 32768.0,
|
||||
static_cast<double>(candidate[1]) / 32768.0,
|
||||
static_cast<double>(candidate[2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(position, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = index;
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// 目标布局里离 desired 最近、且在 0.05 容差内的输出声道;没有返回 -1。
|
||||
int nearest_channel(const double desired[3], const std::int32_t positions[][3],
|
||||
std::uint32_t channel_count) {
|
||||
int best = -1;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (std::uint32_t index = 0; index < channel_count; ++index) {
|
||||
if (is_sentinel(positions[index])) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(positions[index][0]) / 32768.0,
|
||||
static_cast<double>(positions[index][1]) / 32768.0,
|
||||
static_cast<double>(positions[index][2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(desired, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = static_cast<int>(index);
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
if (have_best && best_distance <= 0.05) {
|
||||
return best;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 输出声道 index -> 该声道的 Q15 方位;LFE 与非空间声道给 sentinel。
|
||||
void channel_positions(const speaker::LayoutInfo& layout,
|
||||
std::int32_t positions[][3]) {
|
||||
for (int index = 0; index < kMaxChannels; ++index) {
|
||||
set_sentinel(positions[index]);
|
||||
}
|
||||
const auto* geometry = ejoc::speaker_tables::find_layout(layout.speaker_bitfield);
|
||||
if (geometry != nullptr) {
|
||||
bool known[kMaxChannels] = {};
|
||||
std::int32_t found[kMaxChannels][3];
|
||||
for (int index = 0; index < kMaxChannels; ++index) {
|
||||
set_sentinel(found[index]);
|
||||
}
|
||||
for (const auto& region : geometry->regions) {
|
||||
for (std::size_t point = 0; point < region.point_count; ++point) {
|
||||
const auto speaker = static_cast<int>(region.points[point].speaker_id);
|
||||
if (speaker < 0 || speaker >= kMaxChannels || known[speaker]) {
|
||||
continue;
|
||||
}
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
found[speaker][axis] =
|
||||
static_cast<std::int32_t>(region.points[point].coordinate_q15[axis]);
|
||||
}
|
||||
known[speaker] = true;
|
||||
}
|
||||
}
|
||||
const std::uint32_t count =
|
||||
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
|
||||
? layout.channel_count
|
||||
: static_cast<std::uint32_t>(kMaxChannels);
|
||||
for (std::uint32_t index = 0; index < count; ++index) {
|
||||
const char* name = layout.channel_names != nullptr ? layout.channel_names[index]
|
||||
: nullptr;
|
||||
if (name != nullptr && std::strcmp(name, "LFE") == 0) {
|
||||
continue;
|
||||
}
|
||||
if (known[index]) {
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
positions[index][axis] = found[index][axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int channel_index(const speaker::LayoutInfo& layout, const char* name) {
|
||||
if (name == nullptr || layout.channel_names == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
for (std::uint32_t index = 0; index < layout.channel_count; ++index) {
|
||||
if (std::strcmp(layout.channel_names[index], name) == 0) {
|
||||
return static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
double attenuation_db(const speaker::LayoutInfo& layout) {
|
||||
for (const AttenuationEntry& entry : kAttenuation) {
|
||||
if (std::strcmp(entry.compact_name, layout.compact_name) == 0) {
|
||||
return entry.db;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::int32_t (*bed_reference_positions_q15())[3] {
|
||||
return kReferencePositions;
|
||||
}
|
||||
|
||||
BedOutputDescription bed_output_description(const speaker::LayoutInfo& layout) {
|
||||
BedOutputDescription description;
|
||||
std::int32_t positions[kMaxChannels][3];
|
||||
channel_positions(layout, positions);
|
||||
const std::uint32_t output_count =
|
||||
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
|
||||
? layout.channel_count
|
||||
: static_cast<std::uint32_t>(kMaxChannels);
|
||||
description.output_labels.reserve(output_count);
|
||||
for (std::uint32_t index = 0; index < output_count; ++index) {
|
||||
description.output_labels.push_back(nearest_reference(positions[index]));
|
||||
}
|
||||
for (int label = 0; label < oamd::kBedLabelCount; ++label) {
|
||||
const BedChannel channel = static_cast<BedChannel>(label);
|
||||
const char* name = channel == BedChannel::kLfe2 ? nullptr
|
||||
: bed_channel_short_name(channel);
|
||||
int slot = -1;
|
||||
if (name != nullptr && name[0] != '\0') {
|
||||
slot = channel_index(layout, name);
|
||||
}
|
||||
if (slot < 0 && channel == BedChannel::kLfe2) {
|
||||
slot = channel_index(layout, "LFE");
|
||||
}
|
||||
const TableB10Position* position = table_b10(channel);
|
||||
double desired[3] = {0.0, 0.0, 0.0};
|
||||
if (position != nullptr) {
|
||||
render_coordinates(position->xyz, desired);
|
||||
}
|
||||
if (slot < 0 && position != nullptr) {
|
||||
slot = nearest_channel(desired, positions, output_count);
|
||||
}
|
||||
if (slot < 0) {
|
||||
description.label_to_slot[label] = is_lfe_label(channel) ? -1 : -2;
|
||||
} else {
|
||||
description.label_to_slot[label] = slot;
|
||||
}
|
||||
if (is_lfe_label(channel)) {
|
||||
description.direct_output_labels[label] = 3;
|
||||
} else {
|
||||
int best = 3;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (int index = 0; index < kBedReferencePositionCount; ++index) {
|
||||
const std::int32_t* candidate = kReferencePositions[index];
|
||||
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(candidate[0]) / 32768.0,
|
||||
static_cast<double>(candidate[1]) / 32768.0,
|
||||
static_cast<double>(candidate[2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(desired, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = index;
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
description.direct_output_labels[label] = best;
|
||||
}
|
||||
}
|
||||
description.automatic_attenuation_db = attenuation_db(layout);
|
||||
return description;
|
||||
}
|
||||
|
||||
} // namespace joc::joc
|
||||
Reference in new issue
Block a user