Two changes that belong to the same reproduction model: a bed channel has one position, defined by its label, and a SOFA set keeps the impulse responses it was measured with. CBA bed channels: the position comes from the channel's label in ETSI TS 103 420 Table B.10, not from the layout the decoder is asked to render to. The per-layout anchor table displaced bed channels onto the nearest target speaker, which silently moved content whenever the target layout changed. - Drop the anchor table and the geometry lookup; bed_channel_q15 is the only source of bed positions, so stream and task no longer need a layout to ask for one - Keep the 17-bit non-standard bed mask in channel order, as Table 13 / TS 103 190-2 Table 65 transmit it - Exclude LFE channels from the object list while keeping them in the coverage mask - Cover the Table B.10 coordinates, the q15 encoding, the 10-bit and 17-bit masks and the LFE split in tests SOFA rendering: compiling a SOFA set into a fifth-order directional field threw away the measured impulse response - the SH projection, the 64-QMF/77-hybrid round trip and the synthetic room replaced it. The full IRs are now kept and rendered as such, with the reproduction defined by a configuration that names a personalized model rather than by the renderer itself. - Add SphericalMesh: incremental convex hull over the measurement directions, barycentric weights inside the containing triangle and spherical Voronoi areas for the centre spectrum - Add FullHrirField: rfft of the selected shell, 200-1500 Hz phase fit for the delay, delay-aligned spectra, log-magnitude/phase or MCA interpolation, rigid-sphere radial ratio, recording origin and the common FFT/2 latency - Add Uniform/MultiSourcePartitionedConvolver: block 128, numpy FFT conventions, zero-fade filter rebuild from the blocks in flight - Move the Rosella reference arithmetic (profile geometry, direction basis, direct gains and room send, table-A room) out of the renderer into rosella_reference so both renderers share it - Add ReferenceEnvironment and SofaReferenceRuntime: JSON configuration with model hash and distance-profile mapping, level calibration over equal-area directions, the reference room, 1536-sample batching and a single latency removal - Keep .jochrtf an explicit input and the SOFA compile step behind --hrtf-cache-policy/--hrtf-cache-dir; add --reference-config and --sofa-interpolation, and make --hrtf-radius-m optional for a single shell - Cover the mesh weights and Voronoi areas, the sphere series and the partitioned convolver with reference values in tests - Document both rules in the READMEs and the binaural notes Rosella renders stay byte-identical (d5877e89...) and so do renders of the legacy compiled path (6f0a75d2...). Direct SOFA renders match the Python reference to 1e-4 in level; the residual comes from the barycentric solve (analytic inverse here, LAPACK there) on near-degenerate triangles.
108 lines
4.5 KiB
C++
108 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include <complex>
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "foundation/status.h"
|
|
#include "hrtf/rosella_model.h"
|
|
|
|
// One of the room's transforms is a radix-2 FFT plan, so the type is named here and
|
|
// kept out of the interface.
|
|
namespace joc::dsp {
|
|
class FftPlan;
|
|
} // namespace joc::dsp
|
|
|
|
// The reference arithmetic of the Rosella ".personalized_headphone" renderer
|
|
// (rosella_model.py, rosella_direct.py and rosella_room.py): the direction basis and
|
|
// the padded lane grid, the per-source direct gains and room send, and the recursive
|
|
// table-A room model. rosella_renderer.cpp drives these through RosellaRuntime; a
|
|
// renderer built on another field format can call them directly and get the same
|
|
// samples, so the operation order and the literals in the definitions are part of
|
|
// the interface.
|
|
namespace joc::hrtf {
|
|
|
|
// rosella_direct._profile_geometry: a virtual position resolved on one distance
|
|
// profile's grid, as the direction of the direct path plus the radius factors the
|
|
// gain weights are scaled by.
|
|
struct ProfileGeometry {
|
|
double direction[3] = {1.0, 0.0, 0.0};
|
|
double radius = 0.0;
|
|
double clamped = 0.0;
|
|
double alpha = 0.0;
|
|
};
|
|
|
|
// Quantises `position` onto the profile's metadata grid, maps it through the
|
|
// profile's axis scales and clamps it to the profile bounds; `out` takes the result.
|
|
Status profile_geometry(const RosellaModel& model, const double position[3], int profile_index,
|
|
ProfileGeometry* out);
|
|
|
|
// rosella_model.direction_basis: the observed 36-term basis of one unit vector.
|
|
void direction_basis(double x, double y, double z, double out[36]);
|
|
|
|
// rosella_direct._logical_field: the padded lane grid as [77][36][2] float64.
|
|
std::vector<double> rosella_logical_field(const std::vector<float>& padded);
|
|
|
|
// One source's direct-path gains and room send, plus the radii and the interaural
|
|
// delay the caller reports. `delayed_ear` is -1 when neither ear is delayed,
|
|
// otherwise it is the ear (0 = left, 1 = right) whose phase carries
|
|
// `delay_samples`.
|
|
struct DirectResult {
|
|
std::complex<double> gains[2][77] = {};
|
|
double room_send = 0.0;
|
|
double physical_radius_m = 0.0;
|
|
double normalized_radius = 0.0;
|
|
double clamped_radius = 0.0;
|
|
double delay_samples = 0.0;
|
|
int delayed_ear = -1;
|
|
};
|
|
|
|
// rosella_direct.special_lfe_direct: the response a special (LFE) source is
|
|
// rendered with, built once.
|
|
const DirectResult& special_lfe_direct();
|
|
|
|
// rosella_direct.direct_and_room_send: the direct gains and the room send of the
|
|
// position `position` on profile `profile_index`, read through the logical field
|
|
// grids of `field_left`/`field_right`.
|
|
Status direct_and_room_send(const RosellaModel& model, const std::vector<double>& field_left,
|
|
const std::vector<double>& field_right, const double position[3],
|
|
int profile_index, DirectResult* out);
|
|
|
|
// rosella_room.RosellaRoomFir: the recursive table-A room model, its room FIR and the
|
|
// overlap-add convolution that applies the FIR in the hybrid band domain. State is
|
|
// per instance and not thread-safe.
|
|
class RosellaRoomFir {
|
|
public:
|
|
RosellaRoomFir();
|
|
~RosellaRoomFir();
|
|
RosellaRoomFir(const RosellaRoomFir&) = delete;
|
|
RosellaRoomFir& operator=(const RosellaRoomFir&) = delete;
|
|
|
|
// Builds the room impulse response from `model` over `impulse_slots` slots. The
|
|
// room can only be processed once this succeeds; the alternate table-A mode is
|
|
// rejected here, as the reference rejects it.
|
|
Status configure(const RosellaModel& model, int impulse_slots);
|
|
// `values` is [slots][2][77], `output` is [slots][2][77] and stays zero outside
|
|
// the room bands.
|
|
Status process_chunk(const std::vector<std::complex<double>>& values, std::size_t slots,
|
|
std::vector<std::complex<double>>* output);
|
|
void reset();
|
|
bool valid() const;
|
|
|
|
private:
|
|
int length_ = 0;
|
|
bool valid_ = false;
|
|
std::vector<std::complex<double>> kernel_;
|
|
std::vector<std::complex<double>> tail_;
|
|
std::vector<std::complex<double>> kernel_fft_;
|
|
std::size_t fft_cache_size_ = 0u;
|
|
std::vector<std::complex<double>> line_; // scratch, exactly fft_size entries
|
|
std::vector<std::complex<double>> input_fft_; // scratch, [fft_size][64], fully written
|
|
std::vector<std::complex<double>> block_; // scratch, [needed][2][64], fully written
|
|
std::unique_ptr<dsp::FftPlan> forward_plan_;
|
|
std::unique_ptr<dsp::FftPlan> inverse_plan_;
|
|
};
|
|
|
|
} // namespace joc::hrtf
|