tests/test_extraction.py954 B
import numpy as np
from localizer.config import ExtractionConfig
from localizer.extraction import extract_hrir
from fixtures import synth_brir, SAMPLE_RATE
def test_extracts_target_length():
cfg = ExtractionConfig()
brir = synth_brir(30.0)
hrir = extract_hrir(brir, cfg)
expected = int(round(cfg.hrir_duration * SAMPLE_RATE))
assert hrir.num_samples == expected # 6 ms window
def test_removes_leading_silence():
brir = synth_brir(0.0, leading_silence=200)
hrir = extract_hrir(brir)
# After trimming, energy should be concentrated near the start, not delayed by 200.
env = np.abs(hrir.left) + np.abs(hrir.right)
onset = int(np.argmax(env))
assert onset < 64
def test_preserves_lateral_energy_asymmetry():
# Source on the left: left channel should carry more energy than the right.
brir = synth_brir(60.0)
hrir = extract_hrir(brir)
assert np.sum(hrir.left ** 2) > np.sum(hrir.right ** 2)
