diff --git a/kernel/include/eac3joc_core.h b/kernel/include/eac3joc_core.h
index 811274e..44c6d9b 100644
--- a/kernel/include/eac3joc_core.h
+++ b/kernel/include/eac3joc_core.h
@@ -23,7 +23,7 @@ extern "C" {
#endif
enum {
- EJOC_ABI_VERSION = 2,
+ EJOC_ABI_VERSION = 3,
EJOC_FRAME_SAMPLES = 1536,
EJOC_TIMESLOTS = 24,
EJOC_SUBBANDS = 64,
@@ -35,6 +35,7 @@ enum {
EJOC_MAX_PARAMETER_BANDS = 23,
EJOC_SPEAKER_BLOCK_SAMPLES = 32,
EJOC_SPEAKER_COORDINATES = 3,
+ EJOC_SPEAKER_CONTROLS_VERSION = 1,
EJOC_BINAURAL_BLOCK_SAMPLES = 512,
EJOC_BINAURAL_INPUT_CHANNELS = 16,
EJOC_BINAURAL_OUTPUT_CHANNELS = 2,
@@ -123,6 +124,44 @@ metadata_offsets must be nondecreasing and <= sample_count. sample_count must
be a multiple of EJOC_SPEAKER_BLOCK_SAMPLES. State and unfinished ramps are
preserved across calls.
*/
+
+/*
+Per-object speaker controls taken from OAMD metadata: warp mode, trim mode,
+the three trim levels and the two front-back balances. trim_bypass is indexed
+by object slot (1..15); slot 0 carries the LFE and is unused.
+
+warp_mode 0 leaves the floor Y coordinate unchanged; mode 1 maps it through
+clamp(2Y, 0, 1). warp modes 2 and 3 have no speaker implementation and are
+rejected by the caller that builds this structure.
+
+trim_mode selects where the gain comes from: automatic applies the layout
+position compensation, disabled applies no trim, and explicit applies the
+position-dependent trim from centre_db / surround_db / height_db. A bypassed
+object keeps its warp but loses the balance and the trim gain.
+
+Controls may change between calls; each call's metadata events use the
+controls passed with that call. A null pointer means warp 0, no trim and no
+balance.
+*/
+typedef enum ejoc_speaker_trim_mode {
+ EJOC_SPEAKER_TRIM_AUTOMATIC = 0,
+ EJOC_SPEAKER_TRIM_DISABLED = 1,
+ EJOC_SPEAKER_TRIM_EXPLICIT = 2
+} ejoc_speaker_trim_mode;
+
+typedef struct ejoc_speaker_controls {
+ uint32_t struct_size;
+ uint32_t struct_version;
+ uint32_t warp_mode;
+ uint32_t trim_mode; /* ejoc_speaker_trim_mode */
+ double centre_db;
+ double surround_db; /* positive values are treated as zero */
+ double height_db; /* positive values are treated as zero */
+ double listener_balance; /* [-1, 1] */
+ double overhead_balance; /* [-1, 1] */
+ uint8_t trim_bypass[EJOC_MAX_OBJECTS + 1]; /* per object slot, slot 0 unused */
+} ejoc_speaker_controls;
+
EJOC_API uint32_t EJOC_CALL ejoc_speaker_layout_channel_count(uint32_t speaker_bitfield);
EJOC_API ejoc_speaker_renderer_handle EJOC_CALL ejoc_speaker_renderer_create(uint32_t speaker_bitfield);
EJOC_API void EJOC_CALL ejoc_speaker_renderer_destroy(ejoc_speaker_renderer_handle handle);
@@ -139,6 +178,7 @@ EJOC_API int EJOC_CALL ejoc_speaker_renderer_process(
const uint8_t* region_indices,
const uint8_t* height_enabled,
const double* object_gains,
+ const ejoc_speaker_controls* controls,
double* output_interleaved);
EJOC_API ejoc_binaural_renderer_handle EJOC_CALL ejoc_binaural_renderer_create(void);
diff --git a/kernel/include/joc_version.h b/kernel/include/joc_version.h
index 5f32fae..dc1143c 100644
--- a/kernel/include/joc_version.h
+++ b/kernel/include/joc_version.h
@@ -9,8 +9,8 @@
#define JOC_VERSION_H
#define JOC_VERSION_MAJOR 1
-#define JOC_VERSION_MINOR 1
+#define JOC_VERSION_MINOR 2
#define JOC_VERSION_PATCH 0
-#define JOC_VERSION_STRING "1.1.0"
+#define JOC_VERSION_STRING "1.2.0"
#endif /* JOC_VERSION_H */
diff --git a/kernel/joc_kernel.vcxproj b/kernel/joc_kernel.vcxproj
index 96443f5..976786d 100644
--- a/kernel/joc_kernel.vcxproj
+++ b/kernel/joc_kernel.vcxproj
@@ -180,6 +180,7 @@
+
@@ -260,6 +261,7 @@
+
diff --git a/kernel/src/adm/adm_metadata.cpp b/kernel/src/adm/adm_metadata.cpp
index 4240162..fb724a9 100644
--- a/kernel/src/adm/adm_metadata.cpp
+++ b/kernel/src/adm/adm_metadata.cpp
@@ -54,6 +54,67 @@ std::uint8_t checksum(const std::string& segment) {
return static_cast((~sum + 1) & 0xFF);
}
+// OAMD trim element warp mode as the dbmd, DAMF and AXML warp field carry it:
+// 0 normal, 1 warping, 2 downmix_pl2x, 3 downmix_loro.
+std::uint32_t trim_warp_mode(const oamd::OamdTrim* trim) {
+ if (trim == nullptr) {
+ return 0;
+ }
+ return std::min(trim->warp_mode, 3u);
+}
+
+// Trim records carry the balance as a sign bit plus a 7-bit magnitude on a
+// 1/127 grid.
+std::uint8_t balance_byte(double value) {
+ const long long magnitude =
+ std::min(pynum::py_round(std::fabs(value) * 127.0), 127);
+ return static_cast(static_cast(magnitude) |
+ (value < 0.0 ? 0x80u : 0x00u));
+}
+
+void append_trim_records(const oamd::OamdTrim& trim, std::string* out) {
+ out->append("");
+ for (int index = 0; index < oamd::kTrimConfigs; ++index) {
+ const oamd::TrimConfig& record = trim.configs[index];
+ if (record.kind == oamd::TrimConfigKind::kAbsent) {
+ continue;
+ }
+ out->append("");
+ out->append(std::to_string(index));
+ out->append("");
+ if (record.kind == oamd::TrimConfigKind::kDefault) {
+ out->append("");
+ continue;
+ }
+ const bool explicit_record = record.kind == oamd::TrimConfigKind::kExplicit;
+ const double centre = explicit_record ? record.centre : 0.0;
+ const double surround = explicit_record ? record.surround : 0.0;
+ const double height = explicit_record ? record.height : 0.0;
+ const double overhead = explicit_record ? record.balance_overhead : 0.0;
+ const double listener = explicit_record ? record.balance_listener : 0.0;
+ out->append("" + pynum::format_fixed(centre, 6) + "");
+ out->append("" + pynum::format_fixed(surround, 6) + "");
+ out->append("" + pynum::format_fixed(height, 6) + "");
+ out->append("" + pynum::format_fixed(overhead, 6) +
+ "");
+ out->append("" + pynum::format_fixed(listener, 6) +
+ "");
+ out->append("");
+ }
+ out->append("");
+}
+
+void append_atmos_master_block(const oamd::OamdTrim& trim, std::string* out) {
+ const std::string warp = std::to_string(trim_warp_mode(&trim));
+ out->append("");
+ out->append(warp);
+ out->append("");
+ append_trim_records(trim, out);
+ out->append("");
+ out->append(warp);
+ out->append("");
+}
+
} // namespace
std::string ts(double seconds) {
@@ -102,7 +163,8 @@ std::string build_chna() {
return out;
}
-Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out) {
+Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out,
+ const oamd::OamdTrim* trim) {
if (out == nullptr) {
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOutput, "null output");
}
@@ -136,6 +198,10 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
segment9[106] = 0x01;
segment9[111] = 0x22;
segment9[112] = static_cast(0xFF);
+ // at[152]: the low three bits are the warp code, the other bits belong to
+ // the template's packed fields.
+ segment9[152] = static_cast(
+ (static_cast(segment9[152]) & 0xF8u) | trim_warp_mode(trim));
out->push_back(9);
put_u16(out, 248);
out->append(segment9);
@@ -152,12 +218,35 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
segment10[i] = static_cast(0x84);
}
// Nine 15-byte configuration trims start at byte 7; the first byte of each
- // carries the auto-trim flag in bit 0 (1 = automatic, 0 = manual). The
- // default is automatic, so a freshly rendered master opens with automatic
- // trims in the renderer.
- for (std::size_t layout = 0; layout < 9; ++layout) {
- const std::size_t flag = 7u + 15u * layout;
- segment10[flag] = static_cast(static_cast(segment10[flag]) | 0x01u);
+ // carries the auto-trim flag in bit 0 (1 = automatic, 0 = manual). A
+ // configuration without an explicit record stays automatic, so a freshly
+ // rendered master opens with automatic trims in the renderer.
+ for (std::size_t layout = 0; layout < static_cast(oamd::kTrimConfigs);
+ ++layout) {
+ const std::size_t base = 7u + 15u * layout;
+ const oamd::TrimConfig* record =
+ trim != nullptr ? &trim->configs[layout] : nullptr;
+ const bool manual = record != nullptr &&
+ (record->kind == oamd::TrimConfigKind::kExplicit ||
+ record->kind == oamd::TrimConfigKind::kDisabled);
+ if (!manual) {
+ segment10[base] =
+ static_cast(static_cast(segment10[base]) | 0x01u);
+ continue;
+ }
+ segment10[base] = static_cast(static_cast(segment10[base]) & 0xFEu);
+ const bool explicit_record = record->kind == oamd::TrimConfigKind::kExplicit;
+ const double levels[3] = {explicit_record ? record->centre : 0.0,
+ explicit_record ? record->surround : 0.0,
+ explicit_record ? record->height : 0.0};
+ for (std::size_t index = 0; index < 3; ++index) {
+ const float stored = static_cast(levels[index]);
+ std::memcpy(&segment10[base + 1u + 4u * index], &stored, sizeof(stored));
+ }
+ const double overhead = explicit_record ? record->balance_overhead : 0.0;
+ const double listener = explicit_record ? record->balance_listener : 0.0;
+ segment10[base + 13u] = static_cast(balance_byte(overhead));
+ segment10[base + 14u] = static_cast(balance_byte(listener));
}
const std::size_t object_modes = 4u + 2u + 1u + 9u * 15u + object_count;
for (std::uint32_t i = 10; i < std::min(object_count, 10u + kObjectCount); ++i) {
@@ -176,7 +265,8 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
return Status::success();
}
-std::string build_axml(const std::vector