Read the OAMD trim element into speaker rendering and ADM
The OAMD parser reads the trim element: warp mode, global trim mode, the nine per-configuration records (centre, surround and height level, the two front-back balances) and the per-object bypass flags. OamdUpdate carries it, so the file task and the streaming step see the same state; a payload without the element keeps the previous controls, and an absent element starts at warp 0 with automatic trim. Speaker rendering reads the controls from OAMD only; neither the CLI nor the frontends offer an override. Eligible layouts leave the floor Y alone at warp 0 and use clamp(2Y, 0, 1) at warp 1, the height layer is never scaled, and warp 2/3 is reported as unsupported where the speaker consumes it. Floor, height and trim evaluation keep separate coordinates: floor Y is balance(warp(Y)), while height Y and trim Y are balance(Y). An explicit configuration contributes a position-dependent scalar for each object, applied before accumulation instead of to the output channels after the mix; automatic, disabled and explicit are mutually exclusive, and a bypassed object keeps its warp but loses balance and trim. Automatic still uses the layout position compensation, disabled uses unity, and layouts without trim semantics stay disabled. LFE passes through, and ADM source positions and binaural rendering are unchanged. The controls travel in ejoc_speaker_controls, a C struct a future decoder can fill without knowing the layout; the layout table now carries the surround and height channel counts and the seven layouts that have trim semantics. The internal ABI goes to version 3 for the new process parameter. The ADM writer mirrors the element into both carriers. AXML gains DolbyAtmosMasterFile with DolbyMasterContentInfo, DolbyTrimModeSetup (one record per configuration, zero values for a disabled one) and DolbyWarpMode. dbmd segment 10 carries the nine 15-byte records (automatic flag, three float32 levels and two sign-magnitude balances), and segment 9 writes the warp code into the low three bits of at[152] while keeping the other packed fields. The task scans the first 64 audio frames for the element, as the reference does, so a duration-limited render still writes it. The bilingual mathematical notes describe the configuration index, the balance map, the three coordinates and the evaluation order; the READMEs state that the controls come from OAMD and that warp 2/3 is refused. ctest covers the element parse, configuration selection, warp 0/1 with the Q15 clamp, the height coordinate, explicit trim and balance, per-object bypass, LFE passthrough, the step's metadata updates and the exact dbmd/AXML bytes. Speaker output over the same objects16 stream is byte-identical to the reference for the seven trimmed layouts and the wider ones, and both ADM carriers of a rendered BWF are byte-identical to the reference writer. The product version goes to 1.2.0; the public ABI stays at 5.
This commit is contained in:
1 parent
20f2e77664
commit
58e3403642
21 files changed
+1597
-48
No files matched your search
@@ -0,0 +1,155 @@
|
||||
#include "speaker/speaker_trim.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "foundation/py_num.h"
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
namespace {
|
||||
|
||||
int height_class(std::uint32_t count) {
|
||||
if (count == 0u) {
|
||||
return 0;
|
||||
}
|
||||
if (count == 2u) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
int floor_class(std::uint32_t count) {
|
||||
if (count == 0u) {
|
||||
return 0;
|
||||
}
|
||||
if (count == 2u || count == 3u) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int trim_config_index(const LayoutInfo& layout) {
|
||||
return floor_class(layout.surround_channels) + 3 * height_class(layout.height_channels);
|
||||
}
|
||||
|
||||
Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout,
|
||||
ejoc_speaker_controls* out) {
|
||||
if (out == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"null speaker controls");
|
||||
}
|
||||
ejoc_speaker_controls controls{};
|
||||
controls.struct_size = sizeof(controls);
|
||||
controls.struct_version = EJOC_SPEAKER_CONTROLS_VERSION;
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_AUTOMATIC;
|
||||
if (trim != nullptr) {
|
||||
controls.warp_mode = trim->warp_mode;
|
||||
for (int slot = 0; slot < oamd::kMaxSlots; ++slot) {
|
||||
controls.trim_bypass[slot] = trim->disable_per_object[slot] ? 1u : 0u;
|
||||
}
|
||||
}
|
||||
if (controls.warp_mode > 1u) {
|
||||
return Status::fail(JOC_ERR_NOT_SUPPORTED, stage::kRender,
|
||||
"speaker: warp_mode_not_implemented: speaker rendering "
|
||||
"implements warp modes 0/1; warp mode " +
|
||||
std::to_string(controls.warp_mode) + " is reserved");
|
||||
}
|
||||
if (!layout.carries_trim) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
const std::uint32_t mode = trim != nullptr ? trim->global_trim_mode : 0u;
|
||||
if (mode == 1u) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (mode > 2u) {
|
||||
return Status::fail(JOC_ERR_NOT_SUPPORTED, stage::kRender,
|
||||
"speaker: trim_mode_not_implemented: OAMD global trim mode " +
|
||||
std::to_string(mode) + " is reserved");
|
||||
}
|
||||
if (mode == 2u) {
|
||||
const oamd::TrimConfig& record = trim->configs[trim_config_index(layout)];
|
||||
if (record.kind == oamd::TrimConfigKind::kDefault ||
|
||||
record.kind == oamd::TrimConfigKind::kAbsent) {
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (record.kind == oamd::TrimConfigKind::kDisabled) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (!std::isfinite(record.centre) || !std::isfinite(record.surround) ||
|
||||
!std::isfinite(record.height)) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"speaker: trim levels must be finite");
|
||||
}
|
||||
for (const double balance : {record.balance_listener, record.balance_overhead}) {
|
||||
if (!std::isfinite(balance) || balance < -1.0 || balance > 1.0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"speaker: balance must be finite and in [-1,1]");
|
||||
}
|
||||
}
|
||||
// Surround and height are attenuation-only; the centre level keeps its
|
||||
// sign.
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_EXPLICIT;
|
||||
controls.centre_db = record.centre;
|
||||
controls.surround_db = std::min(record.surround, 0.0);
|
||||
controls.height_db = std::min(record.height, 0.0);
|
||||
controls.listener_balance = record.balance_listener;
|
||||
controls.overhead_balance = record.balance_overhead;
|
||||
}
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
double front_back_balance(double position, double balance) {
|
||||
const long long steps =
|
||||
pynum::py_round(std::fabs(balance) * static_cast<double>(kBalanceSteps));
|
||||
if (steps == 0) {
|
||||
return position;
|
||||
}
|
||||
const double slope = static_cast<double>(steps) / 18.0;
|
||||
if (position <= kBalanceWall || position >= 1.0 - kBalanceWall) {
|
||||
return position;
|
||||
}
|
||||
if (position < 0.5) {
|
||||
return balance > 0.0 ? (1.0 + slope) * position - kBalanceWall * slope
|
||||
: (1.0 - slope) * position + kBalanceWall * slope;
|
||||
}
|
||||
return balance > 0.0
|
||||
? (1.0 - slope) * (position - 0.5) + 0.5 + 0.45 * slope
|
||||
: (1.0 + slope) * (position - 0.5) + 0.5 - 0.45 * slope;
|
||||
}
|
||||
|
||||
double apply_balance(double position, double height, double listener, double overhead) {
|
||||
if (listener == 0.0 && overhead == 0.0) {
|
||||
return position;
|
||||
}
|
||||
const double low = front_back_balance(position, listener);
|
||||
const double high = front_back_balance(position, overhead);
|
||||
return (1.0 - height) * low + height * high;
|
||||
}
|
||||
|
||||
double explicit_position_gain(const ejoc_speaker_controls& controls, double x, double y,
|
||||
double z) {
|
||||
const double surround = std::min(std::max(2.0 * y, 0.0), 1.0) * (1.0 - z);
|
||||
const double centre = 1.0 - std::min(
|
||||
std::max(10.0 * std::max(std::max(std::fabs(z) - kBalanceWall,
|
||||
y - kBalanceWall),
|
||||
std::fabs(x - 0.5) - kBalanceWall),
|
||||
0.0),
|
||||
1.0);
|
||||
const double db = surround * std::min(controls.surround_db, 0.0) +
|
||||
z * std::min(controls.height_db, 0.0) + centre * controls.centre_db;
|
||||
return std::pow(10.0, db / 20.0);
|
||||
}
|
||||
|
||||
} // namespace joc::speaker
|
||||
Reference in new issue
Block a user