Make SOFA room processing optional and self-contained
SOFA and explicit .jochrtf inputs now render direct sound by default. --sofa-room enables the project image-source/FDN room, with the compact preset for Near/Mid and the original large room for Far. - preserve native HRIR timing and apply Data.Delay once - remove external reference configuration, radial head synthesis and the artificial centre response - ship both generated float64 room assets and their generator - retain .jochrtf as an explicit lightweight input and offline export - keep personalized headphone processing unchanged and update bilingual documentation Checked: independent direct/reflection convolution, FDN FIR/recursive agreement, fractional delay and metadata timing, chunk invariance, 8 bit-exact personalized regressions, CLI smoke tests, and full-song D1/D2 renders of two tracks.
This commit is contained in:
1 parent
26e84569c2
commit
3ea285e407
19 files changed
+861
-1134
No files matched your search
@@ -1,137 +0,0 @@
|
||||
"""Configured reference environment, geometry and scalar level calibration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
|
||||
from rosella_bank import RosellaBank
|
||||
from rosella_direct import _profile_geometry, direct_and_room_send
|
||||
from rosella_model import load_personalized_headphone
|
||||
from rosella_room import RosellaRoomFir
|
||||
|
||||
|
||||
DEFAULT_REFERENCE_CONFIG = Path(__file__).resolve().parents[1]/"local"/"binaural_reference.json"
|
||||
REFERENCE_MODES = {"near": 1, "mid": 3, "far": 2}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ReferencePosition:
|
||||
direction: np.ndarray
|
||||
distance_m: float
|
||||
ear_distance_m: float
|
||||
centre_weight: float
|
||||
direct_gain: float
|
||||
room_send: float
|
||||
|
||||
|
||||
class ReferenceEnvironment:
|
||||
def __init__(self, config=None, *, mode=None):
|
||||
self.config_path = Path(config or os.environ.get("BINAURAL_REFERENCE_CONFIG") or
|
||||
DEFAULT_REFERENCE_CONFIG).expanduser().resolve()
|
||||
with self.config_path.open(encoding="utf-8") as stream:
|
||||
spec = json.load(stream)
|
||||
self.configuration_sha256 = hashlib.sha256(
|
||||
json.dumps(spec, sort_keys=True, separators=(",", ":")).encode("utf-8")).hexdigest()
|
||||
if spec.get("schema") != "binaural-reference-v1":
|
||||
raise ValueError("unsupported reference configuration")
|
||||
path = Path(spec["model_path"]).expanduser()
|
||||
if not path.is_absolute():
|
||||
path = self.config_path.parent/path
|
||||
self.model_sha256 = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
if self.model_sha256.lower() != str(spec["model_sha256"]).lower():
|
||||
raise ValueError("reference data hash mismatch")
|
||||
self.model = load_personalized_headphone(path)
|
||||
self.calibration_profile_index = int(spec["profile_index"])
|
||||
self.profile_id = str(spec["profile_id"])
|
||||
if self.calibration_profile_index not in (2, 3) or self.model.sample_rate != 48000:
|
||||
raise ValueError("unsupported reference profile")
|
||||
self.mode = ({v: k for k, v in REFERENCE_MODES.items()}[self.calibration_profile_index]
|
||||
if mode is None else str(mode).lower())
|
||||
if self.mode not in REFERENCE_MODES:
|
||||
raise ValueError("reference mode must be near, mid, or far")
|
||||
self.profile_index = REFERENCE_MODES[self.mode]
|
||||
if int(self.model.header_integer_fields[0]) != 0:
|
||||
raise ValueError("reference-v1 requires a Cartesian mapping")
|
||||
self.profile = self.model.profiles[self.profile_index]
|
||||
self.compiled_receivers = spec.get("compiled_receiver_positions_m")
|
||||
self.room_slots = int(spec.get("room_impulse_slots", 4096))
|
||||
self.calibration_directions = int(spec.get("level_calibration_directions", 128))
|
||||
if not 128 <= self.room_slots <= 16384 or not 16 <= self.calibration_directions <= 2048:
|
||||
raise ValueError("reference configuration exceeds supported bounds")
|
||||
self.h0, self.coupling = map(float, self.model.header_float_scalars[:2])
|
||||
if self.h0 <= 0 or self.coupling <= 0:
|
||||
raise ValueError("invalid reference energy coupling")
|
||||
self.minimum_distance_m = float(self.profile.minimum_normalized_radius)*float(self.profile.distance_scale_m)
|
||||
self.reference_distance_m = self.map_position((0., 1., 0.)).distance_m
|
||||
|
||||
def map_position(self, position, *, profile_index=None):
|
||||
position = np.asarray(position, dtype=np.float64)
|
||||
if position.shape != (3,) or not np.isfinite(position).all():
|
||||
raise ValueError("reference position must contain three finite values")
|
||||
extension = max(1., float(np.max(np.abs(position))))
|
||||
if extension > 50.1+1e-9:
|
||||
raise ValueError("position exceeds the finite metadata domain")
|
||||
index = self.profile_index if profile_index is None else int(profile_index)
|
||||
profile, direction, radius, _, _ = _profile_geometry(self.model, position/extension, index)
|
||||
distance = float(profile.distance_scale_m)*radius*extension
|
||||
minimum = float(profile.minimum_normalized_radius)*float(profile.distance_scale_m)
|
||||
regularized = max(distance, minimum)
|
||||
alpha = distance/regularized
|
||||
effective = self.h0*distance
|
||||
if index == REFERENCE_MODES["near"]:
|
||||
a, send = 1., 0.
|
||||
else:
|
||||
a = 1/math.sqrt(1+self.coupling*effective*effective)
|
||||
send = effective*a
|
||||
return ReferencePosition(np.asarray(direction), distance, regularized, alpha, a, send)
|
||||
|
||||
def create_room(self):
|
||||
return RosellaRoomFir(self.model, impulse_slots=self.room_slots)
|
||||
|
||||
@staticmethod
|
||||
def create_bank(source_channels):
|
||||
return RosellaBank(1, source_channels=source_channels, output_channels=2)
|
||||
|
||||
def calibrate(self, field, spectrum_at):
|
||||
from public_filterbank import hybrid_gain_synthesis_dictionary
|
||||
from rosella_direct import _FIELD_CACHE
|
||||
# Discard stale cache entries when object ids are reused.
|
||||
_FIELD_CACHE.pop(id(self.model), None)
|
||||
count = self.calibration_directions
|
||||
i = np.arange(count, dtype=np.float64)
|
||||
z = 1-2*(i+.5)/count
|
||||
phi = i*np.pi*(3-math.sqrt(5))
|
||||
unit = np.column_stack((np.sqrt(1-z*z)*np.cos(phi), np.sqrt(1-z*z)*np.sin(phi), z))
|
||||
dictionary = hybrid_gain_synthesis_dictionary(field.fft_size)
|
||||
band = (field.frequencies >= 100) & (field.frequencies <= 16000)
|
||||
weights = 1/field.frequencies[band]
|
||||
reference_energy = 0.
|
||||
new_energy = 0.
|
||||
for direction in unit:
|
||||
adm = (-direction[1], direction[0], direction[2])
|
||||
state = self.map_position(adm, profile_index=self.calibration_profile_index)
|
||||
parameters = direct_and_room_send(self.model, adm, self.calibration_profile_index)
|
||||
vector = np.empty((2, 154), dtype=np.float64)
|
||||
vector[:, 0::2], vector[:, 1::2] = parameters.gains.real, parameters.gains.imag
|
||||
reference = np.fft.rfft(vector @ dictionary.T, field.fft_size)
|
||||
target = spectrum_at(state)*state.direct_gain
|
||||
reference_energy += float(np.sum(np.abs(reference[:, band])**2*weights))
|
||||
new_energy += float(np.sum(np.abs(target[:, band])**2*weights))
|
||||
if min(reference_energy, new_energy) <= 1e-24 or not math.isfinite(new_energy):
|
||||
raise ValueError("reference level calibration has no finite signal energy")
|
||||
return math.sqrt(reference_energy/new_energy)
|
||||
|
||||
def info(self):
|
||||
return dict(profile_id=self.profile_id, model_sha256=self.model_sha256,
|
||||
configuration_sha256=self.configuration_sha256,
|
||||
mode=self.mode, selected_profile_index=self.profile_index,
|
||||
calibration_profile_index=self.calibration_profile_index,
|
||||
distance_semantics="reference-reproduction-metres", reference_distance_m=self.reference_distance_m,
|
||||
regularized_distance_m=self.minimum_distance_m,
|
||||
filterbank=1, room_impulse_slots=self.room_slots,
|
||||
calibration_directions=self.calibration_directions)
|
||||
+17
-10
@@ -116,22 +116,25 @@ class SofaBinauralRenderer:
|
||||
tail_seconds: float = 5.0,
|
||||
output_gain: float = 1.0,
|
||||
chunk_frames: int = 64,
|
||||
bed_channels=None, reference_config=None,
|
||||
interpolation: str = "lf_logmag_phase") -> "SofaBinauralRenderer":
|
||||
from sofa_reference_backend import ReferenceSofaBackend
|
||||
bed_channels=None,
|
||||
interpolation: str = "lf_logmag_phase",
|
||||
reference_distance_m: float | None = None,
|
||||
sofa_room: bool = False,
|
||||
room_preset: str | None = None) -> "SofaBinauralRenderer":
|
||||
from sofa_direct_backend import DirectSofaBackend
|
||||
if cache_policy not in (None, "none", "memory") or cache_dir is not None:
|
||||
raise ValueError("SOFA renders full HRIRs; use compile_hrtf.py to export a .jochrtf")
|
||||
if projection_ridge != DEFAULT_PROJECTION_RIDGE or sh_ridge != DEFAULT_SH_RIDGE:
|
||||
raise ValueError("full HRIR rendering does not use projection/SH ridge parameters")
|
||||
source = resolve_sofa_hrtf(sofa)
|
||||
backend = ReferenceSofaBackend(
|
||||
backend = DirectSofaBackend(
|
||||
source,
|
||||
source_count=SOURCE_CHANNELS,
|
||||
output_gain=output_gain,
|
||||
reference_config=reference_config,
|
||||
mode=mode,
|
||||
shell_radius_m=shell_radius_m,
|
||||
method=interpolation)
|
||||
method=interpolation,
|
||||
reference_distance_m=reference_distance_m, sofa_room=sofa_room, room_preset=room_preset)
|
||||
return cls(
|
||||
backend,
|
||||
mode=mode,
|
||||
@@ -148,13 +151,17 @@ class SofaBinauralRenderer:
|
||||
tail_seconds: float = 5.0,
|
||||
output_gain: float = 1.0,
|
||||
chunk_frames: int = 64,
|
||||
bed_channels=None, reference_config=None) -> "SofaBinauralRenderer":
|
||||
from sofa_reference_backend import ReferenceSofaBackend
|
||||
bed_channels=None,
|
||||
reference_distance_m: float | None = None,
|
||||
sofa_room: bool = False,
|
||||
room_preset: str | None = None) -> "SofaBinauralRenderer":
|
||||
from sofa_direct_backend import DirectSofaBackend
|
||||
source = resolve_compiled_hrtf_cache(cache)
|
||||
backend = ReferenceSofaBackend(
|
||||
backend = DirectSofaBackend(
|
||||
source,
|
||||
source_count=SOURCE_CHANNELS,
|
||||
compiled=True, reference_config=reference_config, output_gain=output_gain, mode=mode)
|
||||
compiled=True, output_gain=output_gain, mode=mode,
|
||||
reference_distance_m=reference_distance_m, sofa_room=sofa_room, room_preset=room_preset)
|
||||
return cls(
|
||||
backend,
|
||||
mode=mode,
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
"""Generate a float64 FIR realization of the existing project room FDN."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from dataclasses import asdict, replace
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
|
||||
from public_room import LateFdnConfig, SharedUnitaryFdn, ShoeboxRoomConfig
|
||||
|
||||
|
||||
SCHEMA = "sofa-project-room-v1"
|
||||
DEFAULT_PATH = Path(__file__).resolve().parents[1] / "data" / "sofa-room.npz"
|
||||
ROOM_PATHS = {"legacy": DEFAULT_PATH, "compact": DEFAULT_PATH.with_name("sofa-room-compact.npz")}
|
||||
|
||||
|
||||
def preset_config(preset):
|
||||
early, late = ShoeboxRoomConfig(), LateFdnConfig()
|
||||
provenance = {"preset": preset, "size_time_scale": 1.}
|
||||
if preset == "compact":
|
||||
dimensions = np.array([8.5, 11.3, 5.2])
|
||||
original = np.array(early.dimensions_m)
|
||||
|
||||
def volume_over_area(d):
|
||||
return float(np.prod(d) / (2 * (d[0] * d[1] + d[0] * d[2] + d[1] * d[2])))
|
||||
|
||||
scale = volume_over_area(dimensions) / volume_over_area(original)
|
||||
early = replace(early, dimensions_m=tuple(dimensions), listener_position_m=tuple(dimensions / 2))
|
||||
late = replace(late, rt60_seconds=late.rt60_seconds * scale,
|
||||
delay_seconds=tuple(v * scale for v in late.delay_seconds),
|
||||
allpass_seconds=tuple(v * scale for v in late.allpass_seconds))
|
||||
provenance.update(size_time_scale=scale,
|
||||
geometry_reference="Zahorik 2009, Table 1 model 9, L=11.3 W=8.5 H=5.2 m",
|
||||
geometry_reference_url="https://pmc.ncbi.nlm.nih.gov/articles/PMC2730711/",
|
||||
scaling="V/S ratio; same effective average wall absorption; original FDN algorithm",
|
||||
reproduction_scope="geometry only; not a reproduction of the paper's BRIR model")
|
||||
elif preset != "legacy":
|
||||
raise ValueError("room preset must be compact or legacy")
|
||||
return early, late, provenance
|
||||
|
||||
|
||||
def generate(path=None, *, preset="legacy"):
|
||||
started = time.perf_counter()
|
||||
early, config, provenance = preset_config(preset)
|
||||
fdn = SharedUnitaryFdn(config)
|
||||
length = int(np.ceil(2 * config.rt60_seconds * config.sample_rate_hz))
|
||||
probe_length = int(np.ceil(config.rt60_seconds * config.sample_rate_hz))
|
||||
impulse = np.zeros(length + probe_length)
|
||||
impulse[0] = 1.
|
||||
response = fdn.process(impulse)
|
||||
kernel = np.ascontiguousarray(response[:length].T, dtype="<f8")
|
||||
discarded = float(np.sum(response[length:] ** 2) / np.sum(kernel ** 2))
|
||||
if discarded > 1e-12:
|
||||
raise ValueError(f"FDN FIR tail exceeds the -120 dB energy budget: {discarded}")
|
||||
metadata = dict(schema=SCHEMA, sample_rate_hz=config.sample_rate_hz,
|
||||
fdn_config=asdict(config), early_config=asdict(early), **provenance,
|
||||
algorithm=fdn.info(), impulse_samples=length,
|
||||
discarded_probe_samples=probe_length, discarded_energy_ratio=discarded,
|
||||
kernel_sha256=hashlib.sha256(kernel.tobytes()).hexdigest(),
|
||||
source_algorithm_sha256=hashlib.sha256(
|
||||
Path(__file__).with_name("public_room.py").read_bytes()).hexdigest(),
|
||||
generation_seconds=time.perf_counter() - started)
|
||||
path = Path(ROOM_PATHS[preset] if path is None else path).expanduser().resolve()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
np.savez_compressed(path, schema=np.array(SCHEMA), sample_rate_hz=np.int64(48000),
|
||||
late_fir=kernel, metadata_json=np.array(json.dumps(metadata, sort_keys=True)))
|
||||
print(json.dumps(dict(path=str(path), taps=length, bytes=path.stat().st_size,
|
||||
preset=preset, dimensions_m=early.dimensions_m, rt60_parameter_s=config.rt60_seconds,
|
||||
discarded_energy_ratio=discarded,
|
||||
generation_seconds=metadata["generation_seconds"]), indent=2))
|
||||
return metadata
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("output", nargs="?", type=Path)
|
||||
parser.add_argument("--preset", choices=("all", "legacy", "compact"), default="all")
|
||||
args = parser.parse_args()
|
||||
if args.preset == "all":
|
||||
if args.output is not None:
|
||||
parser.error("a custom output requires --preset legacy or compact")
|
||||
for name in ROOM_PATHS:
|
||||
generate(preset=name)
|
||||
else:
|
||||
generate(args.output, preset=args.preset)
|
||||
@@ -0,0 +1,121 @@
|
||||
"""Stateful direct and reflected paths for compact HRTF fields."""
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
import numpy as np
|
||||
from public_filterbank import HYBRID_BANDS
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HybridPath:
|
||||
label: str
|
||||
delay_slots: np.ndarray # whole-QMF delay per ear, [2]
|
||||
transfer: np.ndarray # [ear,77], includes gain and residual delay
|
||||
|
||||
def __post_init__(self):
|
||||
slots = np.asarray(self.delay_slots)
|
||||
if slots.shape == ():
|
||||
slots = np.repeat(slots, 2)
|
||||
if slots.shape != (2,) or slots.dtype.kind not in "iu":
|
||||
raise ValueError("hybrid path delay_slots must contain two integers")
|
||||
slots = np.asarray(slots, dtype=np.int64)
|
||||
transfer = np.asarray(self.transfer, dtype=np.complex128)
|
||||
if transfer.shape != (2, HYBRID_BANDS) or not np.isfinite(transfer).all():
|
||||
raise ValueError("hybrid path transfer must have finite shape [2,77]")
|
||||
if np.any(slots < 0):
|
||||
raise ValueError("hybrid path delay_slots must be non-negative")
|
||||
slots.setflags(write=False)
|
||||
transfer.setflags(write=False)
|
||||
object.__setattr__(self, "delay_slots", slots)
|
||||
object.__setattr__(self, "transfer", transfer)
|
||||
|
||||
|
||||
class HybridObjectPathRenderer:
|
||||
"""Per-object hybrid histories and path transitions."""
|
||||
|
||||
def __init__(self, source_count: int, *, history_slots: int = 256,
|
||||
transition_slots: int = 8):
|
||||
self.source_count = int(source_count)
|
||||
self.history_slots = int(history_slots)
|
||||
self.transition_slots = int(transition_slots)
|
||||
if min(self.source_count, self.history_slots) <= 0 or self.transition_slots < 0:
|
||||
raise ValueError("invalid hybrid path renderer dimensions")
|
||||
self.history = np.zeros(
|
||||
(self.source_count, self.history_slots, HYBRID_BANDS), dtype=np.complex128)
|
||||
self.position = 0
|
||||
self.current: list[tuple[HybridPath, ...]] = [tuple() for _ in range(self.source_count)]
|
||||
self.target: list[tuple[HybridPath, ...] | None] = [None] * self.source_count
|
||||
self.fade_position = np.zeros(self.source_count, dtype=np.int32)
|
||||
self.fade_total = np.zeros(self.source_count, dtype=np.int32)
|
||||
self.processed_slots = 0
|
||||
|
||||
def reset(self) -> None:
|
||||
self.history.fill(0.0)
|
||||
self.position = 0
|
||||
self.target = [None] * self.source_count
|
||||
self.fade_position.fill(0)
|
||||
self.fade_total.fill(0)
|
||||
self.processed_slots = 0
|
||||
|
||||
def set_paths(self, source: int, paths, *, fade_slots: int | None = None) -> None:
|
||||
source = int(source)
|
||||
if not 0 <= source < self.source_count:
|
||||
raise IndexError(source)
|
||||
values = tuple(paths)
|
||||
for path in values:
|
||||
if np.any(path.delay_slots >= self.history_slots):
|
||||
raise ValueError(
|
||||
f"path {path.label!r} needs {path.delay_slots.tolist()} slots, "
|
||||
f"history capacity is {self.history_slots}")
|
||||
fade = self.transition_slots if fade_slots is None else int(fade_slots)
|
||||
if fade < 0:
|
||||
raise ValueError("path fade must be non-negative")
|
||||
if self.target[source] is not None:
|
||||
self.current[source] = self.target[source]
|
||||
self.target[source] = None
|
||||
if not self.processed_slots or fade == 0:
|
||||
self.current[source] = values
|
||||
self.target[source] = None
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = 0
|
||||
else:
|
||||
self.target[source] = values
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = fade
|
||||
|
||||
def _render_paths(self, source: int, paths: tuple[HybridPath, ...]) -> np.ndarray:
|
||||
result = np.zeros((2, HYBRID_BANDS), dtype=np.complex128)
|
||||
for path in paths:
|
||||
indices = (self.position - path.delay_slots) % self.history_slots
|
||||
delayed = self.history[source, indices, :]
|
||||
result += delayed * path.transfer
|
||||
return result
|
||||
|
||||
def process(self, hybrid) -> np.ndarray:
|
||||
values = np.asarray(hybrid, dtype=np.complex128)
|
||||
if values.ndim != 3 or values.shape[1:] != (self.source_count, HYBRID_BANDS):
|
||||
raise ValueError(
|
||||
f"hybrid input must have shape [slots,{self.source_count},77]")
|
||||
if not np.isfinite(values).all():
|
||||
raise ValueError("hybrid input contains non-finite values")
|
||||
output = np.zeros((len(values), 2, HYBRID_BANDS), dtype=np.complex128)
|
||||
for slot in range(len(values)):
|
||||
self.history[:, self.position, :] = values[slot]
|
||||
for source in range(self.source_count - 1, -1, -1):
|
||||
current = self._render_paths(source, self.current[source])
|
||||
target_paths = self.target[source]
|
||||
if target_paths is None:
|
||||
output[slot] += current
|
||||
continue
|
||||
target = self._render_paths(source, target_paths)
|
||||
self.fade_position[source] += 1
|
||||
amount = min(
|
||||
1.0, self.fade_position[source] / float(self.fade_total[source]))
|
||||
output[slot] += current * (1.0 - amount) + target * amount
|
||||
if self.fade_position[source] >= self.fade_total[source]:
|
||||
self.current[source] = target_paths
|
||||
self.target[source] = None
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = 0
|
||||
self.position = (self.position + 1) % self.history_slots
|
||||
self.processed_slots += 1
|
||||
return output
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Listener-centred point-source coordinates for direct HRTF rendering."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import math
|
||||
import numpy as np
|
||||
from reference_distance import ReferenceDistanceProfileV1
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PointSourcePosition:
|
||||
direction: np.ndarray
|
||||
distance_m: float
|
||||
normalized_radius: float
|
||||
|
||||
|
||||
class PointSourceReference:
|
||||
def __init__(self, reference_distance_m=None, *, mode=None):
|
||||
self.mode = ReferenceDistanceProfileV1.validate_profile("mid" if mode is None else mode)
|
||||
self.reference_distance_m = float(ReferenceDistanceProfileV1.DISTANCE_M[self.mode]
|
||||
if reference_distance_m is None else reference_distance_m)
|
||||
if not math.isfinite(self.reference_distance_m) or self.reference_distance_m <= 0:
|
||||
raise ValueError("source reference distance must be finite and positive")
|
||||
|
||||
def map_position(self, position, *, previous_direction=None):
|
||||
values = np.asarray(position, dtype=np.float64)
|
||||
if values.shape != (3,) or not np.isfinite(values).all():
|
||||
raise ValueError("source position must contain three finite values")
|
||||
if np.max(np.abs(values)) > 50.1 + 1e-8:
|
||||
raise ValueError("source position exceeds the finite metadata domain")
|
||||
radius = float(np.linalg.norm(values))
|
||||
direction = values[[1, 0, 2]] * [1., -1., 1.]
|
||||
if radius > 1e-12:
|
||||
direction /= radius
|
||||
elif previous_direction is None:
|
||||
direction = np.array([1., 0., 0.])
|
||||
else:
|
||||
direction = np.asarray(previous_direction, dtype=np.float64).copy()
|
||||
return PointSourcePosition(direction, radius * self.reference_distance_m, radius)
|
||||
|
||||
def info(self):
|
||||
return dict(reference_variant="direct-point-source-v1",
|
||||
reference_distance_m=self.reference_distance_m,
|
||||
mode=self.mode, profile_distances_m=dict(ReferenceDistanceProfileV1.DISTANCE_M),
|
||||
distance_semantics="nominal-object-coordinate-scale",
|
||||
distance_attenuation="none; preserve authored programme gain",
|
||||
radial_adaptation="none; retain selected SOFA measurement shell",
|
||||
coincident_source_direction="previous direction, otherwise front",
|
||||
additional_absolute_propagation_delay=False)
|
||||
@@ -1,552 +0,0 @@
|
||||
"""Stateful public SOFA binaural renderer.
|
||||
|
||||
The runtime topology mirrors the existing multi-object binaural path:
|
||||
64-QMF -> 77 hybrid -> per-object directional transfer -> stereo synthesis.
|
||||
The HRTF parameter source is a SOFA-derived fifth-order field. Early
|
||||
reflections and the late room use project-owned behavior.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from public_filterbank import (
|
||||
ANALYSIS_SYNTHESIS_LATENCY_SAMPLES,
|
||||
HYBRID_BANDS,
|
||||
QMF_HOP,
|
||||
PublicAnalysis77,
|
||||
PublicSynthesis77,
|
||||
table_info as filterbank_table_info,
|
||||
)
|
||||
from public_room import (
|
||||
LateFdnConfig,
|
||||
SharedUnitaryFdn,
|
||||
ShoeboxRoomConfig,
|
||||
first_order_image_sources,
|
||||
)
|
||||
from reference_distance import DistanceState, ReferenceDistanceProfileV1
|
||||
from sofa_canonical import CanonicalHrtf
|
||||
from sofa_hrtf_field import (
|
||||
DEFAULT_ORDER,
|
||||
DEFAULT_PROJECTION_RIDGE,
|
||||
DEFAULT_SH_RIDGE,
|
||||
SofaHrtfField,
|
||||
compile_sofa_hrtf,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class HybridPath:
|
||||
label: str
|
||||
delay_slots: np.ndarray # whole-QMF delay per ear, [2]
|
||||
transfer: np.ndarray # [ear,77], includes residual delay and HRTF delay
|
||||
|
||||
def __post_init__(self):
|
||||
slots = np.asarray(self.delay_slots)
|
||||
if slots.shape == ():
|
||||
slots = np.repeat(slots, 2)
|
||||
if slots.shape != (2,) or slots.dtype.kind not in "iu":
|
||||
raise ValueError("hybrid path delay_slots must contain two integers")
|
||||
slots = np.asarray(slots, dtype=np.int64)
|
||||
transfer = np.asarray(self.transfer, dtype=np.complex128)
|
||||
if transfer.shape != (2, HYBRID_BANDS) or not np.isfinite(transfer).all():
|
||||
raise ValueError("hybrid path transfer must have finite shape [2,77]")
|
||||
if np.any(slots < 0):
|
||||
raise ValueError("hybrid path delay_slots must be non-negative")
|
||||
slots.setflags(write=False)
|
||||
transfer.setflags(write=False)
|
||||
object.__setattr__(self, "delay_slots", slots)
|
||||
object.__setattr__(self, "transfer", transfer)
|
||||
|
||||
|
||||
class HybridObjectPathRenderer:
|
||||
"""Per-object hybrid histories for direct and image-source paths."""
|
||||
|
||||
def __init__(self, source_count: int, *, history_slots: int = 256,
|
||||
transition_slots: int = 8):
|
||||
self.source_count = int(source_count)
|
||||
self.history_slots = int(history_slots)
|
||||
self.transition_slots = int(transition_slots)
|
||||
if min(self.source_count, self.history_slots) <= 0 or self.transition_slots < 0:
|
||||
raise ValueError("invalid hybrid path renderer dimensions")
|
||||
self.history = np.zeros(
|
||||
(self.source_count, self.history_slots, HYBRID_BANDS), dtype=np.complex128)
|
||||
self.position = 0
|
||||
self.current: list[tuple[HybridPath, ...]] = [tuple() for _ in range(self.source_count)]
|
||||
self.target: list[tuple[HybridPath, ...] | None] = [None] * self.source_count
|
||||
self.fade_position = np.zeros(self.source_count, dtype=np.int32)
|
||||
self.fade_total = np.zeros(self.source_count, dtype=np.int32)
|
||||
self.processed_slots = 0
|
||||
|
||||
def reset(self) -> None:
|
||||
self.history.fill(0.0)
|
||||
self.position = 0
|
||||
self.target = [None] * self.source_count
|
||||
self.fade_position.fill(0)
|
||||
self.fade_total.fill(0)
|
||||
self.processed_slots = 0
|
||||
|
||||
def set_paths(self, source: int, paths, *, fade_slots: int | None = None) -> None:
|
||||
source = int(source)
|
||||
if not 0 <= source < self.source_count:
|
||||
raise IndexError(source)
|
||||
values = tuple(paths)
|
||||
for path in values:
|
||||
if np.any(path.delay_slots >= self.history_slots):
|
||||
raise ValueError(
|
||||
f"path {path.label!r} needs {path.delay_slots.tolist()} slots, "
|
||||
f"history capacity is {self.history_slots}")
|
||||
fade = self.transition_slots if fade_slots is None else int(fade_slots)
|
||||
if fade < 0:
|
||||
raise ValueError("path fade must be non-negative")
|
||||
if self.target[source] is not None:
|
||||
# Normal 512-sample updates complete an 8-slot transition exactly.
|
||||
# If a caller updates faster, use the previous target as the new
|
||||
# stable side rather than resetting signal history.
|
||||
self.current[source] = self.target[source]
|
||||
self.target[source] = None
|
||||
if not self.processed_slots or fade == 0:
|
||||
self.current[source] = values
|
||||
self.target[source] = None
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = 0
|
||||
else:
|
||||
self.target[source] = values
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = fade
|
||||
|
||||
def _render_paths(self, source: int, paths: tuple[HybridPath, ...]) -> np.ndarray:
|
||||
result = np.zeros((2, HYBRID_BANDS), dtype=np.complex128)
|
||||
for path in paths:
|
||||
indices = (self.position - path.delay_slots) % self.history_slots
|
||||
delayed = self.history[source, indices, :]
|
||||
result += delayed * path.transfer
|
||||
return result
|
||||
|
||||
def process(self, hybrid) -> np.ndarray:
|
||||
values = np.asarray(hybrid, dtype=np.complex128)
|
||||
if values.ndim != 3 or values.shape[1:] != (self.source_count, HYBRID_BANDS):
|
||||
raise ValueError(
|
||||
f"hybrid input must have shape [slots,{self.source_count},77]")
|
||||
if not np.isfinite(values).all():
|
||||
raise ValueError("hybrid input contains non-finite values")
|
||||
output = np.zeros((len(values), 2, HYBRID_BANDS), dtype=np.complex128)
|
||||
for slot in range(len(values)):
|
||||
self.history[:, self.position, :] = values[slot]
|
||||
for source in range(self.source_count - 1, -1, -1):
|
||||
current = self._render_paths(source, self.current[source])
|
||||
target_paths = self.target[source]
|
||||
if target_paths is None:
|
||||
output[slot] += current
|
||||
continue
|
||||
target = self._render_paths(source, target_paths)
|
||||
self.fade_position[source] += 1
|
||||
amount = min(
|
||||
1.0, self.fade_position[source] / float(self.fade_total[source]))
|
||||
output[slot] += current * (1.0 - amount) + target * amount
|
||||
if self.fade_position[source] >= self.fade_total[source]:
|
||||
self.current[source] = target_paths
|
||||
self.target[source] = None
|
||||
self.fade_position[source] = 0
|
||||
self.fade_total[source] = 0
|
||||
self.position = (self.position + 1) % self.history_slots
|
||||
self.processed_slots += 1
|
||||
return output
|
||||
|
||||
|
||||
class _StereoDelay:
|
||||
def __init__(self, delay_samples: int):
|
||||
self.delay_samples = int(delay_samples)
|
||||
if self.delay_samples < 0:
|
||||
raise ValueError("delay must be non-negative")
|
||||
self.state = np.zeros((self.delay_samples, 2), dtype=np.float64)
|
||||
|
||||
def reset(self) -> None:
|
||||
self.state.fill(0.0)
|
||||
|
||||
def process(self, values) -> np.ndarray:
|
||||
source = np.asarray(values, dtype=np.float64)
|
||||
if source.ndim != 2 or source.shape[1] != 2:
|
||||
raise ValueError("stereo delay input must have shape [samples,2]")
|
||||
if self.delay_samples == 0:
|
||||
return source.copy()
|
||||
joined = np.concatenate((self.state, source), axis=0)
|
||||
output = joined[:len(source)].copy()
|
||||
self.state = joined[len(source):len(source) + self.delay_samples].copy()
|
||||
return output
|
||||
|
||||
|
||||
class SofaBinauralBackend:
|
||||
"""SOFA-derived public 77-band/SH renderer with public room processing."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
field: SofaHrtfField,
|
||||
*,
|
||||
source_count: int = 16,
|
||||
sample_rate_hz: float = 48000.0,
|
||||
default_profile: str = "mid",
|
||||
enable_early_reflections: bool = True,
|
||||
enable_late_room: bool = True,
|
||||
room_config: ShoeboxRoomConfig = ShoeboxRoomConfig(),
|
||||
fdn_config: LateFdnConfig | None = None,
|
||||
transition_slots: int = 8,
|
||||
history_slots: int = 256,
|
||||
output_gain: float = 1.0):
|
||||
self.source_count = int(source_count)
|
||||
self.sample_rate_hz = float(sample_rate_hz)
|
||||
self.default_profile = ReferenceDistanceProfileV1.validate_profile(default_profile)
|
||||
self.enable_early_reflections = bool(enable_early_reflections)
|
||||
self.enable_late_room = bool(enable_late_room)
|
||||
self.room_config = room_config
|
||||
self.room_config.validate()
|
||||
self.output_gain = float(output_gain)
|
||||
if (self.source_count <= 0 or not math.isfinite(self.sample_rate_hz)
|
||||
or self.sample_rate_hz <= 0.0):
|
||||
raise ValueError("source_count and sample rate must be positive")
|
||||
if not math.isfinite(self.output_gain):
|
||||
raise ValueError("output gain must be finite")
|
||||
if abs(self.sample_rate_hz - 48000.0) > 1.0e-9:
|
||||
raise ValueError("the public binaural runtime requires 48 kHz")
|
||||
|
||||
if not isinstance(field, SofaHrtfField):
|
||||
raise TypeError(
|
||||
"field must be SofaHrtfField; use from_sofa() or "
|
||||
"from_compiled_cache() for file inputs")
|
||||
self.field = field
|
||||
self.hrtf_input_kind = "field"
|
||||
self.hrtf_input_path: str | None = None
|
||||
self.cache_policy: str | None = None
|
||||
if abs(self.field.sample_rate_hz - self.sample_rate_hz) > 1.0e-9:
|
||||
raise ValueError("HRTF field sample rate does not match the renderer")
|
||||
|
||||
self.early_history_slots = int(history_slots)
|
||||
if self.early_history_slots <= 0:
|
||||
raise ValueError("history_slots must be positive")
|
||||
maximum_hrtf_delay = float(np.max(self.field.delay_bounds[:, 1], initial=0.0))
|
||||
self.maximum_hrtf_delay_samples = maximum_hrtf_delay
|
||||
self.hrtf_history_slots = int(math.ceil(maximum_hrtf_delay / QMF_HOP))
|
||||
self.analysis = PublicAnalysis77(self.source_count)
|
||||
self.paths = HybridObjectPathRenderer(
|
||||
self.source_count,
|
||||
history_slots=self.early_history_slots + self.hrtf_history_slots,
|
||||
transition_slots=transition_slots)
|
||||
self.synthesis = PublicSynthesis77(2)
|
||||
actual_fdn_config = fdn_config or LateFdnConfig(sample_rate_hz=self.sample_rate_hz)
|
||||
if abs(actual_fdn_config.sample_rate_hz - self.sample_rate_hz) > 1.0e-9:
|
||||
raise ValueError("FDN sample rate does not match the renderer")
|
||||
self.fdn = SharedUnitaryFdn(actual_fdn_config)
|
||||
self.late_delay = _StereoDelay(ANALYSIS_SYNTHESIS_LATENCY_SAMPLES)
|
||||
|
||||
self.positions = np.zeros((self.source_count, 3), dtype=np.float64)
|
||||
self.positions[:, 1] = 1.0
|
||||
self.profiles = [self.default_profile] * self.source_count
|
||||
self.user_gain = np.ones(self.source_count, dtype=np.float64)
|
||||
self.special_lfe = np.zeros(self.source_count, dtype=bool)
|
||||
self.distance_state: list[DistanceState | None] = [None] * self.source_count
|
||||
self.late_current = np.zeros(self.source_count, dtype=np.float64)
|
||||
self.late_start = np.zeros(self.source_count, dtype=np.float64)
|
||||
self.late_target = np.zeros(self.source_count, dtype=np.float64)
|
||||
self.late_fade_position = np.zeros(self.source_count, dtype=np.int64)
|
||||
self.late_fade_total = np.zeros(self.source_count, dtype=np.int64)
|
||||
self.maximum_early_delay_samples = 0.0
|
||||
self.latency_to_discard = ANALYSIS_SYNTHESIS_LATENCY_SAMPLES
|
||||
self.processed_input_samples = 0
|
||||
self.output_samples = 0
|
||||
self.parameter_updates = 0
|
||||
self.finished = False
|
||||
for source in range(self.source_count):
|
||||
self.set_source(
|
||||
source, self.positions[source], profile=self.default_profile,
|
||||
fade=False)
|
||||
|
||||
@classmethod
|
||||
def from_sofa(
|
||||
cls, sofa: str | Path | CanonicalHrtf, *,
|
||||
cache_policy: str = "memory",
|
||||
cache_dir: str | Path | None = None,
|
||||
shell_radius_m: float = 1.0,
|
||||
order: int = DEFAULT_ORDER,
|
||||
projection_ridge: float = DEFAULT_PROJECTION_RIDGE,
|
||||
sh_ridge: float = DEFAULT_SH_RIDGE,
|
||||
**renderer_options) -> "SofaBinauralBackend":
|
||||
"""Compile a SOFA source once and construct the runtime renderer."""
|
||||
field = compile_sofa_hrtf(
|
||||
sofa,
|
||||
target_sample_rate_hz=float(
|
||||
renderer_options.get("sample_rate_hz", 48000.0)),
|
||||
shell_radius_m=shell_radius_m,
|
||||
order=order,
|
||||
projection_ridge=projection_ridge,
|
||||
sh_ridge=sh_ridge,
|
||||
cache_policy=cache_policy,
|
||||
cache_dir=cache_dir)
|
||||
result = cls(field, **renderer_options)
|
||||
result.hrtf_input_kind = "sofa"
|
||||
result.hrtf_input_path = (
|
||||
str(Path(sofa).expanduser().resolve())
|
||||
if not isinstance(sofa, CanonicalHrtf) else sofa.source_path)
|
||||
result.cache_policy = str(cache_policy).lower()
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def from_compiled_cache(
|
||||
cls, cache: str | Path, **renderer_options
|
||||
) -> "SofaBinauralBackend":
|
||||
"""Load an explicitly selected validated JOC compiled HRTF cache."""
|
||||
path = Path(cache).expanduser().resolve()
|
||||
field = SofaHrtfField.load(path)
|
||||
result = cls(field, **renderer_options)
|
||||
result.hrtf_input_kind = "compiled_cache"
|
||||
result.hrtf_input_path = str(path)
|
||||
result.cache_policy = None
|
||||
return result
|
||||
|
||||
def _make_path(self, label: str, direction_adm, path_distance_m: float,
|
||||
extra_delay_samples: float, amplitude: float) -> HybridPath:
|
||||
del path_distance_m
|
||||
evaluation = self.field.evaluate_adm(direction_adm)
|
||||
extra_delay = float(extra_delay_samples)
|
||||
if not math.isfinite(extra_delay) or extra_delay < 0.0:
|
||||
raise ValueError("path delay must be finite and non-negative")
|
||||
early_delay_slots = int(math.floor(extra_delay / QMF_HOP))
|
||||
if early_delay_slots >= self.early_history_slots:
|
||||
raise ValueError(
|
||||
f"path {label!r} needs {early_delay_slots} early-delay slots, "
|
||||
f"early history capacity is {self.early_history_slots}")
|
||||
total_delay = np.asarray(evaluation.delay_samples, dtype=np.float64) + extra_delay
|
||||
delay_slots = np.floor(total_delay / QMF_HOP).astype(np.int64)
|
||||
residual = total_delay - delay_slots * QMF_HOP
|
||||
propagation_phase = np.exp(
|
||||
-2j * np.pi * self.field.band_center_frequencies_hz[None, :]
|
||||
* residual[:, None]
|
||||
/ self.sample_rate_hz)
|
||||
transfer = np.asarray(
|
||||
evaluation.aligned_gains * propagation_phase * float(amplitude),
|
||||
dtype=np.complex128)
|
||||
return HybridPath(label, delay_slots, transfer)
|
||||
|
||||
def _ordinary_paths(self, state: DistanceState, gain: float) -> tuple[HybridPath, ...]:
|
||||
# Object PCM is programme-normalized. Physical distance controls room
|
||||
# geometry, while the project profile supplies the direct presentation
|
||||
# coefficient instead of applying a second free-field 1/r attenuation.
|
||||
direct_amplitude = gain * ReferenceDistanceProfileV1.direct_level_gain(state)
|
||||
room_gain = ReferenceDistanceProfileV1.room_calibration_gain(state)
|
||||
paths = [self._make_path(
|
||||
"direct", state.direction_adm, state.physical_distance_m, 0.0,
|
||||
direct_amplitude)]
|
||||
if self.enable_early_reflections:
|
||||
reflections = first_order_image_sources(
|
||||
state.direction_adm, state.physical_distance_m,
|
||||
self.sample_rate_hz, self.room_config)
|
||||
for reflection in reflections:
|
||||
amplitude = (
|
||||
gain * room_gain * reflection.reflection_gain
|
||||
* ReferenceDistanceProfileV1.inverse_distance_gain(
|
||||
self.field.measurement_radius_m,
|
||||
reflection.path_distance_m))
|
||||
paths.append(self._make_path(
|
||||
f"early:{reflection.wall}", reflection.direction_adm,
|
||||
reflection.path_distance_m, reflection.extra_delay_samples,
|
||||
amplitude))
|
||||
self.maximum_early_delay_samples = max(
|
||||
self.maximum_early_delay_samples,
|
||||
reflection.extra_delay_samples)
|
||||
return tuple(paths)
|
||||
|
||||
def _lfe_paths(self, gain: float) -> tuple[HybridPath, ...]:
|
||||
frequency = self.field.band_center_frequencies_hz
|
||||
lowpass = np.ones(HYBRID_BANDS, dtype=np.float64)
|
||||
lowpass[frequency >= 180.0] = 0.0
|
||||
transition = (frequency > 120.0) & (frequency < 180.0)
|
||||
amount = (frequency[transition] - 120.0) / 60.0
|
||||
lowpass[transition] = np.cos(0.5 * np.pi * amount) ** 2
|
||||
transfer = np.repeat(
|
||||
(gain * lowpass / math.sqrt(2.0))[None, :], 2, axis=0
|
||||
).astype(np.complex128)
|
||||
return (HybridPath(
|
||||
"public_lfe_lowpass", np.zeros(2, dtype=np.int64), transfer),)
|
||||
|
||||
def _set_late_target(self, source: int, value: float, fade: bool) -> None:
|
||||
value = float(value)
|
||||
fade_samples = (self.paths.transition_slots * QMF_HOP
|
||||
if fade and self.processed_input_samples else 0)
|
||||
if fade_samples == 0:
|
||||
self.late_current[source] = value
|
||||
self.late_start[source] = value
|
||||
self.late_target[source] = value
|
||||
self.late_fade_position[source] = 0
|
||||
self.late_fade_total[source] = 0
|
||||
else:
|
||||
self.late_start[source] = self.late_current[source]
|
||||
self.late_target[source] = value
|
||||
self.late_fade_position[source] = 0
|
||||
self.late_fade_total[source] = fade_samples
|
||||
|
||||
def set_source(self, source: int, position_adm, *, profile: str | None = None,
|
||||
gain: float = 1.0, enabled: bool = True,
|
||||
special_lfe: bool = False, fade: bool = True) -> None:
|
||||
if self.finished:
|
||||
raise RuntimeError("SOFA renderer is finished")
|
||||
source = int(source)
|
||||
if not 0 <= source < self.source_count:
|
||||
raise IndexError(source)
|
||||
gain = float(gain)
|
||||
if not math.isfinite(gain):
|
||||
raise ValueError("source gain must be finite")
|
||||
effective_gain = gain if enabled else 0.0
|
||||
name = self.default_profile if profile is None else profile
|
||||
state = ReferenceDistanceProfileV1.map_adm_position(position_adm, name)
|
||||
path_set = (self._lfe_paths(effective_gain) if special_lfe
|
||||
else self._ordinary_paths(state, effective_gain))
|
||||
self.paths.set_paths(
|
||||
source, path_set,
|
||||
fade_slots=(self.paths.transition_slots if fade else 0))
|
||||
late_send = (0.0 if special_lfe or not self.enable_late_room or not enabled
|
||||
else effective_gain
|
||||
* ReferenceDistanceProfileV1.room_calibration_gain(state)
|
||||
* ReferenceDistanceProfileV1.late_send(state))
|
||||
self._set_late_target(source, late_send, fade)
|
||||
self.positions[source] = np.asarray(position_adm, dtype=np.float64)
|
||||
self.profiles[source] = state.profile
|
||||
self.user_gain[source] = gain
|
||||
self.special_lfe[source] = bool(special_lfe)
|
||||
self.distance_state[source] = state
|
||||
self.parameter_updates += 1
|
||||
|
||||
def _late_send_envelope(self, sample_count: int) -> np.ndarray:
|
||||
envelope = np.empty((sample_count, self.source_count), dtype=np.float64)
|
||||
for source in range(self.source_count):
|
||||
total = int(self.late_fade_total[source])
|
||||
if total == 0:
|
||||
envelope[:, source] = self.late_current[source]
|
||||
continue
|
||||
start_position = int(self.late_fade_position[source])
|
||||
position = start_position + np.arange(1, sample_count + 1)
|
||||
amount = np.clip(position / float(total), 0.0, 1.0)
|
||||
envelope[:, source] = (
|
||||
self.late_start[source] * (1.0 - amount)
|
||||
+ self.late_target[source] * amount)
|
||||
new_position = start_position + sample_count
|
||||
if new_position >= total:
|
||||
self.late_current[source] = self.late_target[source]
|
||||
self.late_start[source] = self.late_target[source]
|
||||
self.late_fade_position[source] = 0
|
||||
self.late_fade_total[source] = 0
|
||||
else:
|
||||
self.late_current[source] = float(envelope[-1, source])
|
||||
self.late_fade_position[source] = new_position
|
||||
return envelope
|
||||
|
||||
def _process(self, sources) -> np.ndarray:
|
||||
values = np.asarray(sources, dtype=np.float64)
|
||||
if values.ndim != 2 or values.shape[1] != self.source_count:
|
||||
raise ValueError(f"sources must have shape [samples,{self.source_count}]")
|
||||
if len(values) % QMF_HOP:
|
||||
raise ValueError("SOFA backend input must be divisible by 64 samples")
|
||||
if not np.isfinite(values).all():
|
||||
raise ValueError("SOFA backend input contains non-finite values")
|
||||
hybrid = self.analysis.process(values)
|
||||
direct_and_early = self.paths.process(hybrid)
|
||||
direct_pcm = self.synthesis.process(direct_and_early)
|
||||
if self.enable_late_room:
|
||||
sends = self._late_send_envelope(len(values))
|
||||
mono = np.sum(values * sends, axis=1, dtype=np.float64)
|
||||
late_pcm = self.late_delay.process(self.fdn.process(mono))
|
||||
else:
|
||||
# Still advance any pending send fade deterministically.
|
||||
self._late_send_envelope(len(values))
|
||||
late_pcm = np.zeros_like(direct_pcm)
|
||||
mixed = np.asarray((direct_pcm + late_pcm) * self.output_gain, dtype=np.float64)
|
||||
skip = min(self.latency_to_discard, len(mixed))
|
||||
self.latency_to_discard -= skip
|
||||
self.processed_input_samples += len(values)
|
||||
output = mixed[skip:]
|
||||
self.output_samples += len(output)
|
||||
return output
|
||||
|
||||
def process(self, sources) -> np.ndarray:
|
||||
if self.finished:
|
||||
raise RuntimeError("SOFA renderer is finished")
|
||||
return self._process(sources)
|
||||
|
||||
def finish(self, *, tail_seconds: float | None = None) -> np.ndarray:
|
||||
if self.finished:
|
||||
return np.zeros((0, 2), dtype=np.float64)
|
||||
if tail_seconds is not None and (
|
||||
not math.isfinite(float(tail_seconds)) or float(tail_seconds) < 0.0):
|
||||
raise ValueError("tail_seconds must be finite and non-negative")
|
||||
requested = (self.fdn.tail_samples if tail_seconds is None
|
||||
else int(math.ceil(float(tail_seconds) * self.sample_rate_hz)))
|
||||
drain = max(
|
||||
requested if self.enable_late_room else 0,
|
||||
int(math.ceil(
|
||||
self.maximum_hrtf_delay_samples
|
||||
+ self.maximum_early_delay_samples)) + 2048,
|
||||
) + ANALYSIS_SYNTHESIS_LATENCY_SAMPLES
|
||||
drain = int(math.ceil(drain / QMF_HOP) * QMF_HOP)
|
||||
output = self._process(np.zeros((drain, self.source_count), dtype=np.float64))
|
||||
self.finished = True
|
||||
return output
|
||||
|
||||
def finish_output_capacity(self, tail_seconds: float | None = None) -> int:
|
||||
"""Return a conservative bound for one future :meth:`finish` output."""
|
||||
if tail_seconds is not None and (
|
||||
not math.isfinite(float(tail_seconds)) or float(tail_seconds) < 0.0):
|
||||
raise ValueError("tail_seconds must be finite and non-negative")
|
||||
requested = (self.fdn.tail_samples if tail_seconds is None
|
||||
else int(math.ceil(float(tail_seconds) * self.sample_rate_hz)))
|
||||
hrtf_bound = self.hrtf_history_slots * QMF_HOP
|
||||
early_bound = hrtf_bound + 2048
|
||||
if self.enable_early_reflections:
|
||||
early_bound += self.early_history_slots * QMF_HOP
|
||||
drain = max(requested if self.enable_late_room else 0, early_bound)
|
||||
drain += ANALYSIS_SYNTHESIS_LATENCY_SAMPLES
|
||||
return int(math.ceil(drain / QMF_HOP) * QMF_HOP)
|
||||
|
||||
def reset(self) -> None:
|
||||
self.analysis.reset()
|
||||
self.paths.reset()
|
||||
self.synthesis.reset()
|
||||
self.fdn.reset()
|
||||
self.late_delay.reset()
|
||||
self.latency_to_discard = ANALYSIS_SYNTHESIS_LATENCY_SAMPLES
|
||||
self.processed_input_samples = 0
|
||||
self.output_samples = 0
|
||||
self.finished = False
|
||||
for source in range(self.source_count):
|
||||
self.set_source(
|
||||
source, self.positions[source], profile=self.profiles[source],
|
||||
gain=float(self.user_gain[source]),
|
||||
special_lfe=bool(self.special_lfe[source]), fade=False)
|
||||
|
||||
def info(self) -> dict:
|
||||
return {
|
||||
"name": "SofaBinauralBackend",
|
||||
"source_count": self.source_count,
|
||||
"sample_rate_hz": self.sample_rate_hz,
|
||||
"precision": "float64/complex128",
|
||||
"signal_path": (
|
||||
"public 64-QMF -> public 77-hybrid -> SOFA order-5 real-SH "
|
||||
"direct/early -> public synthesis + shared unitary FDN"),
|
||||
"hrtf_input_kind": self.hrtf_input_kind,
|
||||
"hrtf_input_path": self.hrtf_input_path,
|
||||
"cache_policy": self.cache_policy,
|
||||
"latency_compensated_samples": ANALYSIS_SYNTHESIS_LATENCY_SAMPLES,
|
||||
"enable_early_reflections": self.enable_early_reflections,
|
||||
"enable_late_room": self.enable_late_room,
|
||||
"early_history_slots": self.early_history_slots,
|
||||
"hrtf_history_slots": self.hrtf_history_slots,
|
||||
"maximum_hrtf_delay_samples": self.maximum_hrtf_delay_samples,
|
||||
"maximum_early_delay_samples": self.maximum_early_delay_samples,
|
||||
"parameter_updates": self.parameter_updates,
|
||||
"processed_input_samples_including_flush": self.processed_input_samples,
|
||||
"output_samples_before_trim": self.output_samples,
|
||||
"distance": ReferenceDistanceProfileV1.info(),
|
||||
"filterbank": filterbank_table_info(),
|
||||
"field": self.field.info(),
|
||||
"late_room": self.fdn.info(),
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
"""Direct rendering of full SOFA HRIRs and explicitly selected compact fields."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import deque
|
||||
import math
|
||||
from pathlib import Path
|
||||
import warnings
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
|
||||
from partitioned_convolution import MultiSourcePartitionedConvolver
|
||||
from point_source import PointSourceReference
|
||||
from sofa_hrir import FullHrirField
|
||||
|
||||
|
||||
class _CompiledField:
|
||||
def __init__(self, path):
|
||||
from sofa_hrtf_field import SofaHrtfField
|
||||
self.field = SofaHrtfField.load(path)
|
||||
self.fft_size = 2048
|
||||
self.measurement_radius_m = self.field.measurement_radius_m
|
||||
i = np.arange(128)
|
||||
z = 1 - 2 * (i + .5) / 128
|
||||
phi = i * np.pi * (3 - math.sqrt(5))
|
||||
directions = np.column_stack((np.sqrt(1 - z * z) * np.cos(phi),
|
||||
np.sqrt(1 - z * z) * np.sin(phi), z))
|
||||
self.recording_origin_samples = int(round(float(np.median([
|
||||
self.field.evaluate_sofa(q).delay_samples.mean() for q in directions]))))
|
||||
|
||||
def info(self):
|
||||
return dict(source_sha256=self.field.source_sha256, method="compiled-band-field",
|
||||
measurement_radius_m=self.measurement_radius_m,
|
||||
cache_key=self.field.cache_key, format_version=self.field.format_version,
|
||||
recording_origin_samples=self.recording_origin_samples,
|
||||
radial_adaptation="none")
|
||||
|
||||
|
||||
class DirectSofaBackend:
|
||||
fixed_reference = True
|
||||
default_profile = "mid"
|
||||
dsp_backend = "python-full-hrir"
|
||||
block_samples = 128
|
||||
|
||||
def __init__(self, source, *, compiled=False, source_count=16, output_gain=1.,
|
||||
method="lf_logmag_phase", shell_radius_m=None, mode=None,
|
||||
reference_distance_m=None, sofa_room=False, room_preset=None):
|
||||
if source_count <= 0 or not math.isfinite(output_gain):
|
||||
raise ValueError("invalid source count or output gain")
|
||||
self.source_count, self.output_gain = int(source_count), float(output_gain)
|
||||
self.reference = PointSourceReference(reference_distance_m, mode=mode)
|
||||
self.default_profile = self.reference.mode
|
||||
self.compiled = bool(compiled)
|
||||
self.field = (_CompiledField(source) if compiled else
|
||||
FullHrirField(source, method=method, shell_radius_m=shell_radius_m))
|
||||
self.hrtf_input_kind = "compiled_cache" if compiled else "sofa"
|
||||
self.response_kind = "hrir" if compiled else getattr(self.field, "response_kind", "hrir")
|
||||
if self.response_kind == "brir":
|
||||
message = "输入为包含房间响应的BRIR,将直接渲染文件响应。"
|
||||
if sofa_room:
|
||||
message += "已忽略--sofa-room。"
|
||||
warnings.warn(message, UserWarning)
|
||||
sofa_room = False
|
||||
self.hrtf_input_path = str(Path(source).expanduser().resolve())
|
||||
self._last = [None] * self.source_count
|
||||
self.distance_states = [None] * self.source_count
|
||||
self.processed_input_samples = self.output_samples = self.parameter_updates = 0
|
||||
self.finished = False
|
||||
self._filter_updates = deque()
|
||||
self.origin = self.field.recording_origin_samples
|
||||
if compiled:
|
||||
from hybrid_paths import HybridObjectPathRenderer
|
||||
from rosella_bank import RosellaBank
|
||||
self.dsp_backend = "python-compiled-hrtf"
|
||||
self.bank = RosellaBank(1, source_channels=self.source_count, output_channels=2)
|
||||
maximum = int(math.ceil(float(np.max(self.field.field.delay_bounds)) / 64))
|
||||
self.paths = HybridObjectPathRenderer(self.source_count, history_slots=maximum + 8,
|
||||
transition_slots=2)
|
||||
self.latency_samples = self.bank.latency_samples
|
||||
from rosella_direct import special_lfe_direct
|
||||
self.lfe_transfer = special_lfe_direct().gains
|
||||
else:
|
||||
self.latency_samples = self.field.common_latency_samples
|
||||
self.convolver = MultiSourcePartitionedConvolver(
|
||||
self.source_count, block_size=128, max_filter_taps=self.field.fft_size)
|
||||
self.lfe_filter = np.zeros((2, self.field.fft_size), dtype=np.float64)
|
||||
start = self.latency_samples + max(self.origin, 0) - 64
|
||||
if start < 0 or start + 129 > self.field.fft_size:
|
||||
raise ValueError("LFE latency exceeds filter budget")
|
||||
self.lfe_filter[:, start:start + 129] = signal.firwin(129, 150., fs=48000) / math.sqrt(2)
|
||||
self._latency_remaining = self.latency_samples
|
||||
self.room = None
|
||||
self.filter_taps = self.field.fft_size
|
||||
if sofa_room:
|
||||
from sofa_room import SofaRoom
|
||||
self.room = SofaRoom(self.source_count, self.reference,
|
||||
implementation_latency=self.latency_samples, recording_origin=self.origin,
|
||||
preset=room_preset)
|
||||
if self.compiled:
|
||||
maximum += int(math.ceil(self.room.early_delay_bound_samples / 64))
|
||||
self.paths = HybridObjectPathRenderer(self.source_count, history_slots=maximum + 8,
|
||||
transition_slots=2)
|
||||
else:
|
||||
self.filter_taps = self.room.filter_budget(self.field)
|
||||
self.convolver = MultiSourcePartitionedConvolver(
|
||||
self.source_count, block_size=128, max_filter_taps=self.filter_taps)
|
||||
|
||||
def set_source(self, source, position_adm, *, profile=None, gain=1., enabled=True,
|
||||
special_lfe=False, fade=True):
|
||||
if self.finished:
|
||||
raise RuntimeError("renderer is finished")
|
||||
source = int(source)
|
||||
if not 0 <= source < self.source_count or not math.isfinite(gain):
|
||||
raise ValueError("invalid source or gain")
|
||||
if profile not in (None, self.default_profile):
|
||||
raise ValueError("source profile must match the selected reference mode")
|
||||
position = np.asarray(position_adm, dtype=np.float64)
|
||||
if position.shape != (3,) or not np.isfinite(position).all():
|
||||
raise ValueError("source position must be finite")
|
||||
gain = float(gain) if enabled else 0.
|
||||
key = (tuple(position), gain, bool(special_lfe))
|
||||
if key == self._last[source]:
|
||||
return
|
||||
first = self.processed_input_samples == 0
|
||||
if special_lfe:
|
||||
if self.room is not None:
|
||||
self.room.set_source(source, None, gain, first=first, special_lfe=True)
|
||||
if self.compiled:
|
||||
from hybrid_paths import HybridPath
|
||||
f = self.field.field.band_center_frequencies_hz
|
||||
transfer = self.lfe_transfer * gain * np.exp(-2j * np.pi * (self.origin % 64) * f / 48000)
|
||||
path = HybridPath("lfe", np.full(2, self.origin // 64, dtype=np.int64), transfer)
|
||||
self.paths.set_paths(source, (path,), fade_slots=0 if first else 2)
|
||||
else:
|
||||
self._set_filter(source, self.lfe_filter * gain, first=first, fade=fade)
|
||||
else:
|
||||
previous = self.distance_states[source]
|
||||
state = self.reference.map_position(
|
||||
position, previous_direction=None if previous is None else previous.direction)
|
||||
if self.compiled:
|
||||
from hybrid_paths import HybridPath
|
||||
evaluation = self.field.field.evaluate_sofa(state.direction)
|
||||
slots = np.floor(evaluation.delay_samples / 64).astype(np.int64)
|
||||
residual = evaluation.delay_samples - slots * 64
|
||||
f = self.field.field.band_center_frequencies_hz
|
||||
transfer = evaluation.aligned_gains * np.exp(-2j * np.pi * residual[:, None] * f / 48000)
|
||||
direct_gain = 1. if self.room is None else self.room.direct_gain(state)
|
||||
paths = [HybridPath("direct", slots, transfer * gain * direct_gain)]
|
||||
if self.room is not None:
|
||||
for reflection in self.room.paths(state):
|
||||
q = reflection.direction_adm[[1, 0, 2]] * [1, -1, 1]
|
||||
e = self.field.field.evaluate_sofa(q)
|
||||
total = e.delay_samples + reflection.extra_delay_samples
|
||||
early_slots = np.floor(total / 64).astype(np.int64)
|
||||
residual = total - early_slots * 64
|
||||
h = e.aligned_gains * np.exp(-2j * np.pi * residual[:, None] * f / 48000)
|
||||
h *= gain * self.room.early_gain(reflection, self.field.measurement_radius_m)
|
||||
paths.append(HybridPath("early:" + reflection.wall, early_slots, h))
|
||||
self.paths.set_paths(source, paths, fade_slots=0 if first or not fade else 2)
|
||||
else:
|
||||
if self.room is None:
|
||||
spectrum = self.field.spectrum(state.direction)
|
||||
hrir = np.roll(np.fft.irfft(spectrum, self.field.fft_size),
|
||||
self.field.common_latency_samples, axis=-1)
|
||||
else:
|
||||
hrir = self.room.full_hrir(self.field, state)
|
||||
self._set_filter(source, hrir * gain, first=first, fade=fade)
|
||||
self.distance_states[source] = state
|
||||
if self.room is not None:
|
||||
self.room.set_source(source, state, gain, first=first)
|
||||
self._last[source] = key
|
||||
self.parameter_updates += 1
|
||||
|
||||
def _set_filter(self, source, hrir, *, first, fade):
|
||||
if first:
|
||||
self.convolver.set_filter(source, hrir, fade_blocks=0)
|
||||
else:
|
||||
# Keep parameter changes on the source timeline after removing the common FIR shift.
|
||||
due = self.processed_input_samples + self.field.common_latency_samples
|
||||
update = (due, source, hrir, int(bool(fade)))
|
||||
for index in range(len(self._filter_updates) - 1, -1, -1):
|
||||
item = self._filter_updates[index]
|
||||
if item[0] != due:
|
||||
break
|
||||
if item[1] == source:
|
||||
self._filter_updates[index] = update
|
||||
return
|
||||
self._filter_updates.append(update)
|
||||
|
||||
def process(self, source):
|
||||
if self.finished:
|
||||
raise RuntimeError("renderer is finished")
|
||||
values = np.asarray(source, dtype=np.float64)
|
||||
if (values.ndim != 2 or values.shape[1] != self.source_count or len(values) % 128
|
||||
or not np.isfinite(values).all()):
|
||||
raise ValueError("input must contain finite complete 128-sample source blocks")
|
||||
outputs = []
|
||||
for start in range(0, len(values), 128):
|
||||
block = values[start:start + 128]
|
||||
if self.compiled:
|
||||
hops = block.reshape(2, 64, self.source_count).transpose(0, 2, 1)
|
||||
hybrid = self.bank.hybrid_analysis.process_chunk(self.bank.qmf_analysis.process_chunk(hops))
|
||||
direct = self.paths.process(hybrid)
|
||||
time = self.bank.qmf_synthesis.process_chunk(self.bank.hybrid_synthesis.process_chunk(direct))
|
||||
output = time.transpose(0, 2, 1).reshape(-1, 2)
|
||||
else:
|
||||
while self._filter_updates and self._filter_updates[0][0] <= self.processed_input_samples:
|
||||
_, source, hrir, fade_blocks = self._filter_updates.popleft()
|
||||
self.convolver.set_filter(source, hrir, fade_blocks=fade_blocks)
|
||||
output = self.convolver.process(block)
|
||||
self.processed_input_samples += 128
|
||||
if self.room is not None:
|
||||
output = self.room.process(block, output)
|
||||
if len(output) == 0:
|
||||
continue
|
||||
skip = min(len(output), self._latency_remaining)
|
||||
self._latency_remaining -= skip
|
||||
outputs.append(output[skip:] * self.output_gain)
|
||||
result = np.concatenate(outputs) if outputs else np.empty((0, 2))
|
||||
self.output_samples += len(result)
|
||||
return result
|
||||
|
||||
def finish_output_capacity(self, tail_seconds):
|
||||
tail = float(tail_seconds)
|
||||
if not math.isfinite(tail) or tail < 0:
|
||||
raise ValueError("tail must be finite and nonnegative")
|
||||
return int(math.ceil((tail * 48000 + self.latency_samples + self.filter_taps) / 128) * 128)
|
||||
|
||||
def finish(self, *, tail_seconds=5.):
|
||||
if self.finished:
|
||||
return np.empty((0, 2))
|
||||
count = self.finish_output_capacity(tail_seconds)
|
||||
expected = max(0, self.processed_input_samples + count - self.latency_samples - self.output_samples)
|
||||
if self.room is not None:
|
||||
pending = len(self.room.pending_direct) * 128
|
||||
count = int(math.ceil((count + pending) / self.room.batch_samples) * self.room.batch_samples) - pending
|
||||
output = self.process(np.zeros((count, self.source_count)))
|
||||
self.output_samples -= max(0, len(output) - expected)
|
||||
self.finished = True
|
||||
return output[:expected]
|
||||
|
||||
def info(self):
|
||||
return dict(hrtf_input_kind=self.hrtf_input_kind, hrtf_input_path=self.hrtf_input_path,
|
||||
cache_policy=None, field=self.field.info(), reference=self.reference.info(),
|
||||
level_calibration=1., latency_compensated_samples=self.latency_samples,
|
||||
processing_batch_samples=128 if self.room is None else self.room.batch_samples,
|
||||
recording_origin_compensated_samples=0,
|
||||
recording_origin_preserved_samples=self.origin,
|
||||
parameter_alignment_delay_samples=0 if self.compiled else self.field.common_latency_samples,
|
||||
current_reference_distances_m=[s.distance_m for s in self.distance_states if s is not None],
|
||||
parameter_updates=self.parameter_updates,
|
||||
direct_representation="77-band" if self.compiled else "full-HRIR",
|
||||
radial_model="none", room_processing=self.room is not None,
|
||||
room={"enabled": False} if self.room is None else self.room.info(),
|
||||
response_kind=self.response_kind, precision="float64/complex128")
|
||||
+5
-64
@@ -5,12 +5,14 @@ from collections import OrderedDict
|
||||
import math
|
||||
import numpy as np
|
||||
from scipy.interpolate import PchipInterpolator
|
||||
from scipy.spatial import ConvexHull, SphericalVoronoi, cKDTree
|
||||
from scipy.spatial import ConvexHull, cKDTree
|
||||
|
||||
from sofa_canonical import CanonicalHrtf, load_simple_free_field_hrir
|
||||
|
||||
|
||||
class FullHrirField:
|
||||
response_kind = "hrir"
|
||||
|
||||
def __init__(self, source, *, method="lf_logmag_phase", shell_radius_m=None,
|
||||
fft_size=None):
|
||||
if method not in ("lf_logmag_phase", "lf_mca_zero"):
|
||||
@@ -41,13 +43,6 @@ class FullHrirField:
|
||||
if not np.allclose(receiver, receiver[0], atol=1e-9, rtol=0):
|
||||
raise ValueError("moving receiver geometry is unsupported")
|
||||
self.receivers = receiver[0].copy()
|
||||
if np.linalg.norm(self.receivers.mean(axis=0)) > 1e-6:
|
||||
raise ValueError("radial model requires ears centred on the listener")
|
||||
self.head_radius_m = float(np.linalg.norm(self.receivers[0]))
|
||||
if not (0.04 < self.head_radius_m < .15) or not np.isclose(
|
||||
np.linalg.norm(self.receivers[1]), self.head_radius_m, atol=1e-6):
|
||||
raise ValueError("unsupported receiver geometry for the radial model")
|
||||
self.ear_directions = self.receivers/self.head_radius_m
|
||||
unit = c.unit_directions[selected]
|
||||
_, first, inverse = np.unique(np.round(unit, 10), axis=0, return_index=True, return_inverse=True)
|
||||
for group in np.flatnonzero(np.bincount(inverse) > 1):
|
||||
@@ -83,10 +78,6 @@ class FullHrirField:
|
||||
self.common_latency_samples = self.fft_size//2
|
||||
physical = raw*np.exp(-1j*self.omega*c.delay_samples[selected, :, None])
|
||||
self.floor = max(float(np.max(np.abs(physical)))*1e-6, 1e-15)
|
||||
areas = SphericalVoronoi(self.directions).calculate_areas()
|
||||
areas /= areas.sum()
|
||||
energy = np.einsum("m,mef->f", areas, np.abs(physical)**2)/2
|
||||
self.centre_spectrum = np.sqrt(energy)*np.exp(-1j*self.omega*self.recording_origin_samples)
|
||||
self.aligned = physical*np.exp(1j*self.omega*self.delays[..., None])
|
||||
self.log_magnitude = None
|
||||
self.auditory = None
|
||||
@@ -166,55 +157,5 @@ class FullHrirField:
|
||||
interpolation_storage_bytes=sum(x.nbytes for x in arrays if x is not None),
|
||||
max_triangle_edge_degrees=self.max_triangle_edge_degrees,
|
||||
phase_fit_rms_rad_p95=float(np.percentile(self.phase_fit_rms_rad, 95)),
|
||||
ear_model="complex-rigid-sphere-distance-ratio",
|
||||
radial_model_validation="analytic-identity-and-series-checks; approximate-human-head")
|
||||
|
||||
|
||||
def sphere_transfer(frequencies, radius, head_radius, cosines, *, sound_speed=343.3,
|
||||
tolerance=1e-10):
|
||||
"""Point-source pressure / free-field centre pressure, FFT sign convention.
|
||||
|
||||
Evaluate the rigid-sphere series using adjacent Hankel ratios, avoiding
|
||||
overflow of high-order Neumann functions at low frequency.
|
||||
"""
|
||||
f = np.asarray(frequencies, dtype=np.float64)
|
||||
r, a = float(radius), float(head_radius)
|
||||
mu = np.asarray(cosines, dtype=np.float64)
|
||||
if f.ndim != 1 or not np.isfinite(f).all() or np.any(f < 0) or not np.isfinite(mu).all():
|
||||
raise ValueError("invalid sphere frequency or incidence")
|
||||
if not (math.isfinite(r) and math.isfinite(a) and r > a > 0):
|
||||
raise ValueError("sphere source must be outside the head")
|
||||
x = 2*np.pi*f*a/sound_speed
|
||||
z = x*(r/a)
|
||||
order = max(int(math.ceil(float(x.max(initial=0))))+32,
|
||||
int(math.ceil(math.log(tolerance)/math.log(a/r)))+16)
|
||||
if order > 4096:
|
||||
raise ValueError("source too close to the sphere surface")
|
||||
mu = np.clip(mu, -1., 1.)
|
||||
p_before, p = np.ones_like(mu), mu.copy()
|
||||
result = np.ones(mu.shape+(len(f),), dtype=np.complex128)/(1+1j*x)
|
||||
ratio_a = x/(1+1j*x)
|
||||
ratio_r = z/(1+1j*z)
|
||||
product = np.ones_like(x, dtype=np.complex128)
|
||||
for n in range(1, order+1):
|
||||
quotient = np.divide(ratio_a, ratio_r, out=np.full_like(ratio_a, a/r), where=z != 0)
|
||||
product *= quotient
|
||||
result += (2*n+1)*p[..., None]*product/(n+1-x*ratio_a)
|
||||
p_before, p = p, ((2*n+1)*mu*p-n*p_before)/(n+1)
|
||||
ratio_a = x/((2*n+1)-x*ratio_a)
|
||||
ratio_r = z/((2*n+1)-z*ratio_r)
|
||||
result *= np.exp(1j*x)
|
||||
if not np.isfinite(result).all():
|
||||
raise ValueError("sphere series failed to converge")
|
||||
return result
|
||||
|
||||
|
||||
def radial_ratio(field, direction, radius):
|
||||
if abs(float(radius)-field.measurement_radius_m) < 1e-10:
|
||||
return np.ones((2, len(field.frequencies)), dtype=np.complex128)
|
||||
mu = field.ear_directions @ np.asarray(direction, dtype=np.float64)
|
||||
source = sphere_transfer(field.frequencies, field.measurement_radius_m, field.head_radius_m, mu)
|
||||
target = sphere_transfer(field.frequencies, radius, field.head_radius_m, mu)
|
||||
if np.min(np.abs(source)) < 1e-10:
|
||||
raise ValueError("singular radial reference response")
|
||||
return target/source
|
||||
ear_model="measured-SOFA-receivers",
|
||||
receiver_positions_m=self.receivers.tolist())
|
||||
@@ -1,270 +0,0 @@
|
||||
"""Direct HRIR rendering with a configured reference environment."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
import math
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
|
||||
from binaural_reference import ReferenceEnvironment
|
||||
from partitioned_convolution import MultiSourcePartitionedConvolver
|
||||
from sofa_hrir import FullHrirField, radial_ratio
|
||||
from sofa_hrtf_field import SofaHrtfField
|
||||
from sofa_binaural_backend import HybridPath, HybridObjectPathRenderer, _StereoDelay
|
||||
|
||||
|
||||
class _CompiledField:
|
||||
def __init__(self, path, receivers):
|
||||
if receivers is None:
|
||||
raise ValueError("compiled input requires configured receiver positions")
|
||||
self.field = SofaHrtfField.load(path)
|
||||
self.fft_size = 2048
|
||||
self.frequencies = np.fft.rfftfreq(self.fft_size, 1/48000)
|
||||
self.measurement_radius_m = self.field.measurement_radius_m
|
||||
receivers = np.asarray(receivers, dtype=np.float64)
|
||||
if receivers.shape != (2, 3) or not np.isfinite(receivers).all():
|
||||
raise ValueError("invalid compiled receiver positions")
|
||||
self.head_radius_m = float(np.linalg.norm(receivers[0]))
|
||||
if not .04 < self.head_radius_m < .15 or not np.allclose(receivers[0], -receivers[1], atol=1e-6):
|
||||
raise ValueError("unsupported compiled receiver geometry")
|
||||
self.ear_directions = receivers/self.head_radius_m
|
||||
self.band_geometry = SimpleNamespace(frequencies=self.field.band_center_frequencies_hz,
|
||||
measurement_radius_m=self.measurement_radius_m, head_radius_m=self.head_radius_m,
|
||||
ear_directions=self.ear_directions)
|
||||
i = np.arange(128)
|
||||
z = 1-2*(i+.5)/128
|
||||
phi = i*np.pi*(3-math.sqrt(5))
|
||||
directions = np.column_stack((np.sqrt(1-z*z)*np.cos(phi), np.sqrt(1-z*z)*np.sin(phi), z))
|
||||
evaluations = [self.field.evaluate_sofa(q) for q in directions]
|
||||
self.recording_origin_samples = int(round(float(np.median([e.delay_samples.mean() for e in evaluations]))))
|
||||
self.centre_band = np.sqrt(np.mean([np.abs(e.transfer_gains)**2 for e in evaluations], axis=(0, 1)))
|
||||
from public_filterbank import hybrid_gain_synthesis_dictionary
|
||||
self.dictionary = hybrid_gain_synthesis_dictionary(self.fft_size)
|
||||
|
||||
def bands(self, state):
|
||||
e = self.field.evaluate_sofa(state.direction)
|
||||
ratio = radial_ratio(self.band_geometry, state.direction, state.ear_distance_m)
|
||||
return e, ratio
|
||||
|
||||
def spectrum_at(self, state):
|
||||
e, ratio = self.bands(state)
|
||||
f = self.field.band_center_frequencies_hz
|
||||
centre = self.centre_band*np.exp(-2j*np.pi*f*self.recording_origin_samples/48000)
|
||||
gains = state.centre_weight*e.transfer_gains*ratio+(1-state.centre_weight)*centre
|
||||
values = np.empty((2, 154))
|
||||
values[:, 0::2], values[:, 1::2] = gains.real, gains.imag
|
||||
return np.fft.rfft(values @ self.dictionary.T, self.fft_size)
|
||||
|
||||
def info(self):
|
||||
return dict(source_sha256=self.field.source_sha256, method="compiled-band-field",
|
||||
measurement_radius_m=self.measurement_radius_m,
|
||||
receiver_geometry_source="reference-configuration",
|
||||
cache_key=self.field.cache_key, format_version=self.field.format_version,
|
||||
recording_origin_samples=self.recording_origin_samples,
|
||||
radial_model_validation="analytic-identity-and-series-checks; approximate-human-head")
|
||||
|
||||
|
||||
class ReferenceSofaBackend:
|
||||
fixed_reference = True
|
||||
default_profile = "mid"
|
||||
dsp_backend = "python-full-hrir"
|
||||
block_samples = 128
|
||||
environment_batch_samples = 1536
|
||||
|
||||
def __init__(self, source, *, reference_config=None, compiled=False, source_count=16,
|
||||
output_gain=1., method="lf_logmag_phase", shell_radius_m=None, mode=None):
|
||||
if source_count <= 0 or not math.isfinite(output_gain):
|
||||
raise ValueError("invalid source count or output gain")
|
||||
self.source_count, self.output_gain = int(source_count), float(output_gain)
|
||||
self.environment = ReferenceEnvironment(reference_config, mode=mode)
|
||||
self.default_profile = self.environment.mode
|
||||
self.compiled = bool(compiled)
|
||||
self.field = (_CompiledField(source, self.environment.compiled_receivers) if compiled else
|
||||
FullHrirField(source, method=method, shell_radius_m=shell_radius_m))
|
||||
self.hrtf_input_kind = "compiled_cache" if compiled else "sofa"
|
||||
self.hrtf_input_path = str(Path(source).expanduser().resolve())
|
||||
self.cache_policy = None
|
||||
if self.environment.minimum_distance_m <= self.field.head_radius_m:
|
||||
raise ValueError("reference near-centre regularization lies inside the head")
|
||||
self._spectra = OrderedDict()
|
||||
self.level_calibration = self.environment.calibrate(self.field, self.spectrum_at)
|
||||
self.bank = self.environment.create_bank(self.source_count)
|
||||
self.room = self.environment.create_room()
|
||||
self._last = [None]*self.source_count
|
||||
self.distance_states = [None]*self.source_count
|
||||
self._sends = np.zeros(self.source_count, dtype=np.float64)
|
||||
self._send_targets = self._sends.copy()
|
||||
self.processed_input_samples = self.output_samples = self.parameter_updates = 0
|
||||
self.finished = False
|
||||
self._pending_room = []
|
||||
self._pending_direct = []
|
||||
self.origin = self.field.recording_origin_samples
|
||||
if self.origin < 0:
|
||||
raise ValueError("negative recording origin requires an explicit time-base adapter")
|
||||
self.implementation_latency = (self.bank.latency_samples if compiled else self.field.common_latency_samples)
|
||||
self.latency_samples = max(self.implementation_latency, self.bank.latency_samples)+max(self.origin, 0)
|
||||
self._latency_remaining = self.latency_samples
|
||||
self.room_delay = _StereoDelay(self.latency_samples-self.bank.latency_samples)
|
||||
if compiled:
|
||||
self.dsp_backend = "python-compiled-hrtf"
|
||||
maximum = int(math.ceil(float(np.max(self.field.field.delay_bounds))/64))
|
||||
self.paths = HybridObjectPathRenderer(self.source_count, history_slots=maximum+8, transition_slots=2)
|
||||
self.direct_delay = _StereoDelay(max(0, self.latency_samples-self.bank.latency_samples-self.origin))
|
||||
self.lfe_transfer = self._compiled_lfe()
|
||||
self.direct_bank = self.environment.create_bank(self.source_count)
|
||||
else:
|
||||
self.convolver = MultiSourcePartitionedConvolver(self.source_count, block_size=self.block_samples,
|
||||
max_filter_taps=self.field.fft_size)
|
||||
self.direct_delay = _StereoDelay(max(0, self.latency_samples-self.implementation_latency-max(self.origin, 0)))
|
||||
lowpass = signal.firwin(129, 150., fs=48000)
|
||||
h = np.zeros((2, self.field.fft_size), dtype=np.float64)
|
||||
start = self.latency_samples-64
|
||||
if start < 0 or start+len(lowpass) > self.field.fft_size:
|
||||
raise ValueError("LFE latency exceeds filter budget")
|
||||
h[:, start:start+len(lowpass)] = lowpass/math.sqrt(2)
|
||||
self.lfe_filter = h
|
||||
|
||||
def spectrum_at(self, state):
|
||||
if self.compiled:
|
||||
return self.field.spectrum_at(state)
|
||||
key = (tuple(state.direction), state.ear_distance_m, state.centre_weight)
|
||||
if key in self._spectra:
|
||||
self._spectra.move_to_end(key)
|
||||
return self._spectra[key].copy()
|
||||
value = self.field.spectrum(state.direction)*radial_ratio(self.field, state.direction, state.ear_distance_m)
|
||||
value = value*state.centre_weight+(1-state.centre_weight)*self.field.centre_spectrum
|
||||
self._spectra[key] = value.copy()
|
||||
if len(self._spectra) > 128:
|
||||
self._spectra.popitem(last=False)
|
||||
return value
|
||||
|
||||
def _compiled_lfe(self):
|
||||
from rosella_direct import special_lfe_direct
|
||||
return special_lfe_direct().gains
|
||||
|
||||
def set_source(self, source, position_adm, *, profile=None, gain=1., enabled=True,
|
||||
special_lfe=False, fade=True):
|
||||
if self.finished:
|
||||
raise RuntimeError("renderer is finished")
|
||||
source = int(source)
|
||||
if not 0 <= source < self.source_count or not math.isfinite(gain):
|
||||
raise ValueError("invalid source or gain")
|
||||
if profile not in (None, self.default_profile):
|
||||
raise ValueError("source profile must match the selected reference mode")
|
||||
position = np.asarray(position_adm, dtype=np.float64)
|
||||
if position.shape != (3,) or not np.isfinite(position).all():
|
||||
raise ValueError("source position must be finite")
|
||||
gain = float(gain) if enabled else 0.
|
||||
key = (tuple(position), gain, bool(special_lfe))
|
||||
if key == self._last[source]:
|
||||
return
|
||||
self._last[source] = key
|
||||
first = self.processed_input_samples == 0
|
||||
if special_lfe:
|
||||
self._send_targets[source] = 0.
|
||||
if self.compiled:
|
||||
f = self.field.field.band_center_frequencies_hz
|
||||
transfer = self.lfe_transfer*gain*np.exp(-2j*np.pi*(self.origin % 64)*f/48000)
|
||||
path = HybridPath("lfe", np.full(2, self.origin//64, dtype=np.int64), transfer)
|
||||
self.paths.set_paths(source, (path,), fade_slots=0 if first else 2)
|
||||
else:
|
||||
self.convolver.set_filter(source, self.lfe_filter*gain, fade_blocks=0 if first else 1)
|
||||
else:
|
||||
state = self.environment.map_position(position)
|
||||
self.distance_states[source] = state
|
||||
self._send_targets[source] = state.room_send*gain
|
||||
if self.compiled:
|
||||
evaluation, ratio = self.field.bands(state)
|
||||
slots = np.floor(evaluation.delay_samples/64).astype(np.int64)
|
||||
residual = evaluation.delay_samples-slots*64
|
||||
f = self.field.field.band_center_frequencies_hz
|
||||
transfer = evaluation.aligned_gains*np.exp(-2j*np.pi*residual[:, None]*f/48000)*ratio
|
||||
transfer *= state.centre_weight*state.direct_gain*self.level_calibration*gain
|
||||
paths = [HybridPath("direct", slots, transfer)]
|
||||
if state.centre_weight < 1:
|
||||
delay = max(0, self.origin)
|
||||
centre = self.field.centre_band*np.exp(-2j*np.pi*(delay % 64)*f/48000)
|
||||
centre = np.tile(centre, (2, 1))*(1-state.centre_weight)*state.direct_gain*self.level_calibration*gain
|
||||
paths.append(HybridPath("centre", np.full(2, delay//64, dtype=np.int64), centre))
|
||||
self.paths.set_paths(source, paths, fade_slots=0 if first or not fade else 2)
|
||||
else:
|
||||
spectrum = self.spectrum_at(state)*state.direct_gain*self.level_calibration*gain
|
||||
hrir = np.roll(np.fft.irfft(spectrum, self.field.fft_size), self.field.common_latency_samples, axis=-1)
|
||||
self.convolver.set_filter(source, hrir, fade_blocks=0 if first or not fade else 1)
|
||||
if first:
|
||||
self._sends[source] = self._send_targets[source]
|
||||
self.parameter_updates += 1
|
||||
|
||||
def process(self, source):
|
||||
if self.finished:
|
||||
raise RuntimeError("renderer is finished")
|
||||
values = np.asarray(source, dtype=np.float64)
|
||||
if values.ndim != 2 or values.shape[1] != self.source_count or len(values) % self.block_samples or not np.isfinite(values).all():
|
||||
raise ValueError("input must contain finite complete 128-sample source blocks")
|
||||
outputs = []
|
||||
for start in range(0, len(values), self.block_samples):
|
||||
block = values[start:start+self.block_samples]
|
||||
hops = block.reshape(2, 64, self.source_count).transpose(0, 2, 1)
|
||||
hybrid = self.bank.hybrid_analysis.process_chunk(self.bank.qmf_analysis.process_chunk(hops))
|
||||
amount = np.array([.5, 1.])[:, None]
|
||||
sends = self._sends+(self._send_targets-self._sends)*amount
|
||||
room_input = np.einsum("tsf,ts->tf", hybrid, sends)
|
||||
if self.compiled:
|
||||
self._pending_direct.append(self.paths.process(hybrid))
|
||||
else:
|
||||
self._pending_direct.append(self.convolver.process(block))
|
||||
self._pending_room.append(room_input)
|
||||
self._sends[:] = self._send_targets
|
||||
self.processed_input_samples += self.block_samples
|
||||
if len(self._pending_room)*self.block_samples < self.environment_batch_samples:
|
||||
continue
|
||||
room = self.room.process_chunk(np.concatenate(self._pending_room))
|
||||
time = self.bank.qmf_synthesis.process_chunk(self.bank.hybrid_synthesis.process_chunk(room))
|
||||
wet = time.transpose(0, 2, 1).reshape(-1, 2)
|
||||
direct = np.concatenate(self._pending_direct)
|
||||
if self.compiled:
|
||||
direct = self.direct_bank.qmf_synthesis.process_chunk(
|
||||
self.direct_bank.hybrid_synthesis.process_chunk(direct))
|
||||
direct = direct.transpose(0, 2, 1).reshape(-1, 2)
|
||||
output = self.direct_delay.process(direct)+self.room_delay.process(wet)
|
||||
self._pending_direct.clear()
|
||||
self._pending_room.clear()
|
||||
skip = min(len(output), self._latency_remaining)
|
||||
self._latency_remaining -= skip
|
||||
outputs.append(output[skip:]*self.output_gain)
|
||||
output = np.concatenate(outputs) if outputs else np.empty((0, 2))
|
||||
self.output_samples += len(output)
|
||||
return output
|
||||
|
||||
def finish_output_capacity(self, tail_seconds):
|
||||
tail = float(tail_seconds)
|
||||
if not math.isfinite(tail) or tail < 0:
|
||||
raise ValueError("tail must be finite and nonnegative")
|
||||
return int(math.ceil((tail*48000+self.latency_samples+self.field.fft_size)/128)*128)
|
||||
|
||||
def finish(self, *, tail_seconds=5.):
|
||||
if self.finished:
|
||||
return np.empty((0, 2))
|
||||
count = self.finish_output_capacity(tail_seconds)
|
||||
pending = len(self._pending_room)*self.block_samples
|
||||
padded = int(math.ceil((count+pending)/self.environment_batch_samples)*self.environment_batch_samples)-pending
|
||||
expected = max(0, self.processed_input_samples+count-self.latency_samples-self.output_samples)
|
||||
output = self.process(np.zeros((padded, self.source_count)))
|
||||
self.output_samples -= max(0, len(output)-expected)
|
||||
output = output[:expected]
|
||||
self.finished = True
|
||||
return output
|
||||
|
||||
def info(self):
|
||||
distances = [s.distance_m for s in self.distance_states if s is not None]
|
||||
return dict(hrtf_input_kind=self.hrtf_input_kind, hrtf_input_path=self.hrtf_input_path,
|
||||
cache_policy=None, field=self.field.info(), reference=self.environment.info(),
|
||||
level_calibration=self.level_calibration,
|
||||
latency_compensated_samples=self.latency_samples,
|
||||
processing_batch_samples=self.environment_batch_samples,
|
||||
recording_origin_compensated_samples=self.origin,
|
||||
current_reference_distances_m=distances,
|
||||
parameter_updates=self.parameter_updates, direct_representation=("77-band" if self.compiled else "full-HRIR"),
|
||||
radial_model="approximate-rigid-sphere-ratio", precision="float64/complex128")
|
||||
@@ -0,0 +1,123 @@
|
||||
"""Full-resolution coupling to the existing project-owned early/late room."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from scipy import fft
|
||||
|
||||
from generate_sofa_room import SCHEMA, ROOM_PATHS
|
||||
from partitioned_convolution import UniformPartitionedConvolver
|
||||
from public_room import ShoeboxRoomConfig, first_order_image_sources
|
||||
from reference_distance import DistanceState, ReferenceDistanceProfileV1
|
||||
|
||||
|
||||
class SofaRoom:
|
||||
batch_samples = 1536
|
||||
|
||||
def __init__(self, source_count, reference, *, implementation_latency, recording_origin,
|
||||
path=None, preset=None):
|
||||
self.reference = reference
|
||||
self.preset = ("legacy" if reference.mode == "far" else "compact") if preset is None else str(preset)
|
||||
if self.preset not in ROOM_PATHS:
|
||||
raise ValueError("room preset must be compact or legacy")
|
||||
self.path = Path(ROOM_PATHS[self.preset] if path is None else path)
|
||||
with np.load(self.path, allow_pickle=False) as data:
|
||||
if str(data["schema"]) != SCHEMA or int(data["sample_rate_hz"]) != 48000:
|
||||
raise ValueError("unsupported SOFA room asset schema or sample rate")
|
||||
kernel = np.asarray(data["late_fir"], dtype="<f8")
|
||||
self.metadata = json.loads(str(data["metadata_json"]))
|
||||
if (kernel.ndim != 2 or kernel.shape[0] != 2 or kernel.shape[1] < 1
|
||||
or not np.isfinite(kernel).all()
|
||||
or hashlib.sha256(kernel.tobytes()).hexdigest() != self.metadata["kernel_sha256"]):
|
||||
raise ValueError("invalid SOFA room FIR or checksum")
|
||||
self.config = ShoeboxRoomConfig(**self.metadata["early_config"])
|
||||
self.config.validate()
|
||||
self.alignment_samples = int(implementation_latency) + max(0, int(recording_origin))
|
||||
kernel = np.pad(kernel, ((0, 0), (self.alignment_samples, 0)))
|
||||
self.convolver = UniformPartitionedConvolver(kernel, block_size=self.batch_samples)
|
||||
self.current = np.zeros(int(source_count))
|
||||
self.target = self.current.copy()
|
||||
self.pending_mono, self.pending_direct = [], []
|
||||
self.maximum_early_delay_samples = 0.
|
||||
|
||||
def distance_state(self, state):
|
||||
return DistanceState(
|
||||
self.reference.mode, state.normalized_radius, self.reference.reference_distance_m,
|
||||
max(ReferenceDistanceProfileV1.MINIMUM_DISTANCE_M, state.distance_m),
|
||||
state.direction[[1, 0, 2]] * [-1, 1, 1])
|
||||
|
||||
def paths(self, state):
|
||||
distance = self.distance_state(state)
|
||||
try:
|
||||
paths = first_order_image_sources(distance.direction_adm, distance.physical_distance_m,
|
||||
48000, self.config)
|
||||
except ValueError as error:
|
||||
raise ValueError("--sofa-room预设房间无法表示当前声源位置;关闭该开关可保留直接声") from error
|
||||
self.maximum_early_delay_samples = max(
|
||||
self.maximum_early_delay_samples, max(p.extra_delay_samples for p in paths))
|
||||
return paths
|
||||
|
||||
def direct_gain(self, state):
|
||||
return ReferenceDistanceProfileV1.direct_level_gain(self.distance_state(state))
|
||||
|
||||
def early_gain(self, path, measurement_radius_m):
|
||||
return (ReferenceDistanceProfileV1.PUBLIC_ROOM_CALIBRATION_GAIN * path.reflection_gain
|
||||
* measurement_radius_m / path.path_distance_m)
|
||||
|
||||
def set_source(self, source, state, gain, *, first=False, special_lfe=False):
|
||||
value = 0. if special_lfe else (float(gain) * ReferenceDistanceProfileV1.PUBLIC_ROOM_CALIBRATION_GAIN
|
||||
* ReferenceDistanceProfileV1.late_send(self.distance_state(state)))
|
||||
self.target[source] = value
|
||||
if first:
|
||||
self.current[source] = value
|
||||
|
||||
def filter_budget(self, field):
|
||||
needed = field.fft_size + int(math.ceil(self.early_delay_bound_samples)) + 64
|
||||
return 1 << (needed - 1).bit_length()
|
||||
|
||||
@property
|
||||
def early_delay_bound_samples(self):
|
||||
dimensions = np.asarray(self.config.dimensions_m)
|
||||
listener = np.asarray(self.config.listener_position_m)
|
||||
return 2 * float(np.max(np.maximum(listener, dimensions - listener))) * 48000 / self.config.speed_of_sound_m_s
|
||||
|
||||
def full_hrir(self, field, state):
|
||||
length = self.filter_budget(field)
|
||||
omega = 2 * math.pi * fft.rfftfreq(length)
|
||||
direct = np.roll(np.fft.irfft(field.spectrum(state.direction), field.fft_size),
|
||||
field.common_latency_samples, axis=-1)
|
||||
spectrum = fft.rfft(direct, length) * self.direct_gain(state)
|
||||
for path in self.paths(state):
|
||||
q = path.direction_adm[[1, 0, 2]] * [1, -1, 1]
|
||||
hrir = np.roll(np.fft.irfft(field.spectrum(q), field.fft_size),
|
||||
field.common_latency_samples, axis=-1)
|
||||
spectrum += (fft.rfft(hrir, length) * np.exp(-1j * omega * path.extra_delay_samples)
|
||||
* self.early_gain(path, field.measurement_radius_m))
|
||||
return fft.irfft(spectrum, length, axis=-1)
|
||||
|
||||
def process(self, source_block, direct_block):
|
||||
amount = np.arange(1, 129, dtype=np.float64)[:, None] / 128
|
||||
sends = self.current + (self.target - self.current) * amount
|
||||
self.pending_mono.append(np.einsum("ts,ts->t", source_block, sends))
|
||||
self.pending_direct.append(direct_block)
|
||||
self.current[:] = self.target
|
||||
if len(self.pending_mono) * 128 < self.batch_samples:
|
||||
return np.empty((0, 2))
|
||||
result = np.concatenate(self.pending_direct) + self.convolver.process_block(np.concatenate(self.pending_mono))
|
||||
self.pending_mono.clear()
|
||||
self.pending_direct.clear()
|
||||
return result
|
||||
|
||||
def info(self):
|
||||
return dict(enabled=True, schema=SCHEMA, preset=self.preset, asset=str(self.path.resolve()),
|
||||
late_fir=self.metadata, early_config=asdict(self.config),
|
||||
maximum_early_delay_samples=self.maximum_early_delay_samples,
|
||||
late_alignment_samples=self.alignment_samples,
|
||||
distance_coupling=ReferenceDistanceProfileV1.info(),
|
||||
high_precision_adaptation="full-HRIR early paths with fractional delay; PCM float64 late FIR",
|
||||
normalization="original project room coupling; not a measured BRIR")
|
||||
Reference in new issue
Block a user