Files
JustOneCacophony/src/oamd/oamd_parser.h
T
TheM14 1227fd6bbb
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
Port the OAMD bed layout map and the fixed bed positions into the kernel
2026-10-30 04:00:38 +08:00

113 lines
3.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Port of src/oamd_bits.py.
#pragma once
#include <cstddef>
#include <cstdint>
#include <vector>
#include "foundation/status.h"
#include "joc_core.h"
namespace joc::oamd {
inline constexpr int kMaxSlots = 16;
inline constexpr int kObjects = 15;
inline constexpr int kAxes = 3;
inline constexpr int kNQ12 = 62;
inline constexpr int kNQ3 = 15;
inline constexpr int kQ15Scale = 32768;
// (the reference's None), i.e. hold the previous position.
struct SlotUpdate {
std::int16_t q1 = -1;
std::int16_t q2 = -1;
std::int16_t q3 = -1;
};
struct OamdUpdate {
SlotUpdate slots[kMaxSlots];
std::uint32_t block_offset_samples = 0;
std::uint32_t ramp_duration_samples = 0;
std::uint32_t object_count = 0;
bool dynamic_object_only = false;
bool lfe_present = false;
std::uint32_t num_bed_objects = 0;
std::uint32_t num_isf_objects = 0;
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 {
public:
OamdState() { reset(); }
void reset() {
for (int slot = 0; slot < kMaxSlots; ++slot) {
for (int axis = 0; axis < kAxes; ++axis) {
q_[slot][axis] = 0;
}
}
q_[0][0] = 16384;
q_[0][1] = 16384;
}
void apply(const OamdUpdate& update) {
for (int slot = 0; slot < kMaxSlots; ++slot) {
const SlotUpdate& value = update.slots[slot];
if (value.q1 >= 0) { q_[slot][0] = value.q1; }
if (value.q2 >= 0) { q_[slot][1] = value.q2; }
if (value.q3 >= 0) { q_[slot][2] = value.q3; }
}
}
std::int16_t q(int slot, int axis) const { return q_[slot][axis]; }
// Objects 1..15 as q15 triples, the layout the speaker renderer consumes.
void object_positions_q15(std::uint16_t out[kObjects][kAxes]) const {
for (int object = 0; object < kObjects; ++object) {
for (int axis = 0; axis < kAxes; ++axis) {
out[object][axis] = static_cast<std::uint16_t>(q_[object + 1][axis]);
}
}
}
private:
std::int16_t q_[kMaxSlots][kAxes] = {};
};
// q_of(k, n) = min(32767, floor(32768 k / n + 0.5)), the reference's quantiser.
int q_of(int k, int n);
Status parse_id11(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
struct BedAssignment {
bool lfe_only = false;
bool standard = false;
std::uint32_t mask = 0;
};
struct ParseTrace {
std::vector<BedAssignment> bed_assignments;
std::uint32_t element_count = 0;
std::uint32_t object_element_count = 0;
std::uint32_t sample_offset_code = 0;
std::uint32_t sample_offset = 0;
std::uint32_t block_count = 0;
std::uint32_t parsed_end_bit = 0;
bool reserved_data_not_present = false;
};
Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out,
ParseTrace* trace);
// Parses only the OAMD header and program_assignment(), which is all the
// cross-layer bed-mask check (spec section 11.2 item 2) needs.
Status parse_id11_bed_assignments(const std::uint8_t* payload, std::size_t payload_size,
std::vector<BedAssignment>* out);
} // namespace joc::oamd