The kernel copy follows the new kernel: the SOFA reader, its compile cache and the field fit are gone, the compiled-field renderer is jochrtf_renderer.cpp with jochrtf_runtime.*, and joc_kernel.vcxproj lists the new translation units. With the Rosella model as the only user-facing input, the preferences page loses its SOFA radio and the settings drop HrtfSource, hrtf_source, hrtf_cache_policy, hrtf_cache_dir and hrtf_radius_m. Decoding always sets personalized_headphone_path, the default lookup is HRTF\binaural.personalized_headphone, and the page hint names that file alone. The compiled .jochrtf stays internal: the page names a model file, never a cache. Builds Release-Static|x64 (foo_input_joc.dll and joc_kernel.lib).
102 lines
3.5 KiB
C++
102 lines
3.5 KiB
C++
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "eac3joc_core.h"
|
|
#include "foundation/status.h"
|
|
#include "hrtf/jochrtf.h"
|
|
#include "oamd/oamd_parser.h"
|
|
#include "timeline/position_timeline.h"
|
|
|
|
namespace joc::binaural {
|
|
|
|
// ADM direction of the LFE source, as the reference passes it.
|
|
inline constexpr double kLfePosition[3] = {0.0, 1.0, 0.0};
|
|
inline constexpr int kSourceCount = 16;
|
|
inline constexpr std::uint32_t kBlockSamples = 512;
|
|
|
|
// Room constants the reference's native bridge passes for the default shoebox.
|
|
struct RoomConstants {
|
|
double dims[3] = {18.0, 18.0, 14.0};
|
|
double listener[3] = {9.0, 9.0, 7.0};
|
|
double walls[6] = {0.62, 0.60, 0.58, 0.61, 0.52, 0.56};
|
|
double speed_of_sound = 343.3;
|
|
std::uint32_t fdn_delays[4] = {1427u, 1783u, 1973u, 2099u};
|
|
double fdn_feedback[4] = {0.7853685923259284, 0.7394299865898056, 0.7160221718631921,
|
|
0.7009092068085467};
|
|
double damping = 0.32;
|
|
double fdn_output_gain = 0.22;
|
|
std::uint32_t allpass_delays[2] = {113u, 331u};
|
|
double allpass_gains[2] = {0.63, 0.51};
|
|
std::uint32_t enable_early_reflections = 1;
|
|
std::uint32_t enable_late_room = 1;
|
|
};
|
|
|
|
enum class Profile : std::uint32_t { Near = 0, Mid = 1, Far = 2 };
|
|
|
|
bool profile_from_name(const char* name, Profile* out);
|
|
|
|
class JochrtfRuntime {
|
|
public:
|
|
JochrtfRuntime() = default;
|
|
~JochrtfRuntime();
|
|
|
|
JochrtfRuntime(const JochrtfRuntime&) = delete;
|
|
JochrtfRuntime& operator=(const JochrtfRuntime&) = delete;
|
|
|
|
Status open(const hrtf::Field& field, const hrtf::Kernels& kernels, Profile profile,
|
|
const RoomConstants& room = RoomConstants{});
|
|
|
|
Status submit_frame(const float* objects16_planar, const oamd::OamdUpdate* update,
|
|
std::int64_t frame_index, std::int64_t outer_sample_offset,
|
|
std::int64_t object_delay_samples);
|
|
|
|
// Resets the kernel, the timeline and the counters (plan 31.2).
|
|
Status reset();
|
|
|
|
// Drains the room tail. `flush_samples` is the drain length; the reference
|
|
Status finish(std::uint32_t flush_samples, std::vector<double>* out);
|
|
|
|
// Program output (input minus the 961-sample kernel latency), interleaved.
|
|
const std::vector<double>& output() const { return output_; }
|
|
|
|
void take_output(std::vector<double>* out) {
|
|
out->swap(output_);
|
|
output_.clear();
|
|
}
|
|
|
|
std::uint64_t input_samples() const { return input_samples_; }
|
|
std::uint64_t blocks_processed() const { return blocks_processed_; }
|
|
std::size_t staged_samples() const { return staged_; }
|
|
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).
|
|
std::uint32_t finish_capacity(double tail_seconds) const;
|
|
|
|
private:
|
|
Status process_block();
|
|
|
|
ejoc_jochrtf_handle handle_ = nullptr;
|
|
Profile profile_ = Profile::Mid;
|
|
timeline::OamdPositionTimeline timeline_;
|
|
std::vector<double> staging_;
|
|
std::size_t staged_ = 0;
|
|
std::vector<double> block_output_;
|
|
std::vector<double> output_;
|
|
std::uint64_t input_samples_ = 0;
|
|
std::uint64_t processed_samples_ = 0;
|
|
std::uint64_t blocks_processed_ = 0;
|
|
std::int64_t maximum_hrtf_delay_ = 0;
|
|
std::uint32_t hrtf_history_slots_ = 1;
|
|
std::uint32_t tail_samples_ = 61200;
|
|
};
|
|
|
|
} // namespace joc::binaural
|