From ce7c65863fbe50062575d6157d290228236f536a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:15:31 +0700 Subject: [PATCH 01/13] feat(sonku-v2): fixed-memory directional image-source early reflections A/B seam --- .../builtin_fx/sonku/SonKuEarlyReflections.h | 156 ++++++++++++++++++ engine/builtin_fx/sonku/SonKuSpatialCore.h | 16 +- 2 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 engine/builtin_fx/sonku/SonKuEarlyReflections.h diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h new file mode 100644 index 000000000..73db9ebdb --- /dev/null +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Bounded, first-order image-source room for headphone externalization trials. +// Reflection image geometry follows Allen & Berkley (JASA, 1979), not +// randomized stereo delays. The ears use lightweight ITD/ILD approximation; +// this is NOT an HRTF-convolved reflection / arbitrary geometry simulation. +// No allocation, locks, worker, I/O, FFT or second device callback. +namespace armix::sonku { +class SonKuEarlyReflections final { +public: + struct Ears {float left=0.f,right=0.f;}; + static constexpr int wallCount=4; + static constexpr int sourceCount=2; + static constexpr int ringFrames=8192; + static constexpr int geometryInterval=64; + bool prepare(double rate) noexcept { + ready_=false; + if(!std::isfinite(rate) || (std::abs(rate-44100.)>.1 && + std::abs(rate-48000.)>.1))return false; + rate_=static_cast(rate); + delaySlew_=static_cast(1.-std::exp(-1./(rate*0.024))); + gainSlew_=static_cast(1.-std::exp(-1./(rate*0.012))); + amountSlew_=static_cast(1.-std::exp(-1./(rate*0.010))); + reset(); + ready_=true; + return true; + } + void reset() noexcept { + for(auto& h:history_)h.fill(0.f); + lowpass_.fill(0.f); + for(auto& paths:tap_)for(auto& p:paths)p=Tap{}; + write_=0;untilGeometry_=0;primed_=false; + amount_=0.f; + } + // Deliberately experimental and OFF by default. Legacy 8/8 direction + // baseline stays bit-identical. A/B is set on an unpublished/offline core + // until headphone, CPU and device gates approve native publication. + bool setAmount(float value) noexcept { + if(!std::isfinite(value)||value<0.f||value>1.f)return false; + if(amountTarget_==0.f&&amount_==0.f&&value>0.f)reset(); + amountTarget_=value; + return true; + } + bool active() const noexcept {return ready_&&(amount_>0.f||amountTarget_>0.f);} + float targetAmount() const noexcept {return amountTarget_;} + Ears process(float left,float right,double azimuth,float spread) noexcept { + if(!active())return {}; + constexpr std::array dummy{}; (void)dummy; + if(untilGeometry_==0){ + updateGeometry(azimuth,spread); + untilGeometry_=geometryInterval; + } + const float x[2]{std::isfinite(left)?left:0.f, + std::isfinite(right)?right:0.f}; + for(int s=0;s(ringFrames-3)); + const int integer=static_cast(bounded); + const float fract=bounded-static_cast(integer); + const int i0=(write_-integer)&(ringFrames-1); + const int i1=(i0-1)&(ringFrames-1); + return history_[source][i0]*(1.f-fract)+history_[source][i1]*fract; + } + void updateGeometry(double azimuth,float spread) noexcept { + constexpr float pi=3.14159265358979323846f; + constexpr float sourceDistance=1.60f; // meters + constexpr float halfWidth=3.20f,halfDepth=4.00f; + constexpr float speedOfSound=343.f; + constexpr float earHalfTime=.00031f; // max +/-0.31ms + constexpr std::array walls{.74f,.74f,.67f,.67f}; + for(int source=0;source(azimuth) + +(source==0?-.5f:.5f)*spread; + const float rad=degrees*(pi/180.f); + const float sx=sourceDistance*std::sin(rad); + const float sy=sourceDistance*std::cos(rad); + const std::array,wallCount> images{{ + {{-2.f*halfWidth-sx,sy}},{{2.f*halfWidth-sx,sy}}, + {{sx,2.f*halfDepth-sy}},{{sx,-2.f*halfDepth-sy}} + }}; + for(int wall=0;wall(ringFrames-3)); + tap.targetDelayR=std::clamp(common-earDelta,1.f, + static_cast(ringFrames-3)); + tap.targetGainL=level*(1.f-.13f*directionX); + tap.targetGainR=level*(1.f+.13f*directionX); + if(!primed_){ + tap.delayL=tap.targetDelayL; + tap.delayR=tap.targetDelayR; + tap.gainL=tap.targetGainL; + tap.gainR=tap.targetGainR; + } + } + } + primed_=true; + } + static_assert((ringFrames&(ringFrames-1))==0); + std::array,sourceCount> history_{}; + std::array,sourceCount> tap_{}; + std::array lowpass_{}; + float rate_=0.f,delaySlew_=0.f,gainSlew_=0.f,amountSlew_=0.f; + float amount_=0.f,amountTarget_=0.f; + int write_=0,untilGeometry_=0; + bool ready_=false,primed_=false; +}; +} // namespace armix::sonku diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 5e4484694..a99a0c5d0 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only #pragma once #include "SonKuMeasuredHrir.h" +#include "SonKuEarlyReflections.h" #include #include #include @@ -48,6 +49,7 @@ class SonKuSpatialCore final { // without trigonometric/exponential work in the audio callback. filterSlew_=static_cast(1.-std::exp(-1./(rate*0.006))); levelSlew_=static_cast(1.-std::exp(-1./(rate*0.008))); + if(!room_.prepare(rate))return false; reset(); ready_=true; return true; @@ -62,6 +64,7 @@ class SonKuSpatialCore final { remaining_=0; degrees_=wrapDegrees(settings_.startAzimuthDegrees); haveKernel_=false; + room_.reset(); } bool setSettings(const Settings& s) noexcept { if(!valid(s))return false; @@ -75,6 +78,11 @@ class SonKuSpatialCore final { return true; } Settings settings() const noexcept {return settings_;} + // A/B-only control pending room's headphone/device qualification. + // Legacy live insert remains room-free until product evidence is accepted. + bool setEarlyReflectionsAmount(float amount) noexcept { + return room_.setAmount(amount); + } bool ready() const noexcept {return ready_;} double azimuthDegrees() const noexcept {return degrees_;} // In-place stereo; caller owns valid, non-overlapping L/R PCM pointers. @@ -121,8 +129,11 @@ class SonKuSpatialCore final { ears[0]+=v0*l0+v1*l1; ears[1]+=v0*r0+v1*r1; } - left[i]=dryLevel*x0+binauralLevel*ears[0]; - right[i]=dryLevel*x1+binauralLevel*ears[1]; + const auto reflection=room_.active() + ?room_.process(x0,x1,degrees_,settings_.stereoSpreadDegrees) + :SonKuEarlyReflections::Ears{}; + left[i]=dryLevel*x0+binauralLevel*(ears[0]+reflection.left); + right[i]=dryLevel*x1+binauralLevel*(ears[1]+reflection.right); if(++write_==taps)write_=0; if(step!=0.) { degrees_+=step; @@ -168,6 +179,7 @@ class SonKuSpatialCore final { std::array,2>,2> kernels_{}; std::array,2>,2> targets_{}; Settings settings_{}; + SonKuEarlyReflections room_{}; float smoothedMix_=1.f,smoothedTrim_=0.75f; float filterSlew_=0.f,levelSlew_=0.f; double sampleRate_=0.; From b6df9a08977aa6c31e280b45928917b363d8ec70 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:17:49 +0700 Subject: [PATCH 02/13] test(sonku-v2): A/B identical-source WAVs, PCM parity and exact-causality room gates --- .github/workflows/ui-smoke.yml | 2 + .../builtin_fx/sonku/SonKuEarlyReflections.h | 1 - tests/sonku_early_reflections_test.cpp | 48 +++++++++++++++++++ tests/sonku_offline_demo_contract.py | 10 ++++ tests/sonku_spatial_core_test.cpp | 32 +++++++++++++ tools/sonku_offline_listening.cpp | 23 +++++++-- 6 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 tests/sonku_early_reflections_test.cpp diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index f4cb2d561..c5cba742f 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -213,6 +213,8 @@ jobs: run: | g++ -std=c++20 -O2 -Wall -Wextra -pedantic tools/sonku_offline_listening.cpp -o /tmp/sonku-listening /tmp/sonku-listening sonku-listening + g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_early_reflections_test.cpp -o /tmp/sonku-room-test + /tmp/sonku-room-test python tests/sonku_offline_demo_contract.py sonku-listening - name: Publish 8D-SonKu reproducible listening WAVs and blind answer key if: ${{ always() }} diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 73db9ebdb..8bdc3172a 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -50,7 +50,6 @@ class SonKuEarlyReflections final { float targetAmount() const noexcept {return amountTarget_;} Ears process(float left,float right,double azimuth,float spread) noexcept { if(!active())return {}; - constexpr std::array dummy{}; (void)dummy; if(untilGeometry_==0){ updateGeometry(azimuth,spread); untilGeometry_=geometryInterval; diff --git a/tests/sonku_early_reflections_test.cpp b/tests/sonku_early_reflections_test.cpp new file mode 100644 index 000000000..5edd9b7f9 --- /dev/null +++ b/tests/sonku_early_reflections_test.cpp @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/sonku/SonKuEarlyReflections.h" +#include +#include +#include +#include +int main(){ + using armix::sonku::SonKuEarlyReflections; + SonKuEarlyReflections invalid; + assert(!invalid.prepare(96000.)); + assert(!invalid.prepare(std::numeric_limits::quiet_NaN())); + for(double rate:{44100.,48000.}){ + SonKuEarlyReflections a,b; + assert(a.prepare(rate)&&b.prepare(rate)); + assert(!a.active()); + assert(!a.setAmount(-.01f)); + assert(!a.setAmount(std::numeric_limits::infinity())); + assert(a.setAmount(.55f)&&b.setAmount(.55f)); + double echo=0.,earDifference=0.; + constexpr int count=4096; + for(int i=0;i180){ + echo+=std::abs(x.left)+std::abs(x.right); + earDifference+=std::abs(x.left-x.right); + } + } + assert(echo>.004 && earDifference>.001); + // Switching the optional room off must settle to bit-exact silence; + // the dry measured HRTF never borrows anything from stale room state. + assert(a.setAmount(0.f)); + for(int i=0;i<6000;++i){ + auto tail=a.process(0.f,0.f,180.,0.f); + if(i>5000)assert(tail.left==0.f&&tail.right==0.f); + } + assert(!a.active()); + } + return 0; +} diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index d8fb941d1..07ad8f4e1 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -24,6 +24,16 @@ def read(name, frames): single=read("sonku-reference-four.wav",4*120000) blind=read("sonku-blind-eight.wav",8*120000) orbit=read("sonku-orbit-cw.wav",480000) +v2four=read("sonku-v2-room-four.wav",4*120000) +v2orbit=read("sonku-v2-room-orbit-cw.wav",480000) +# Baseline V1 and candidate V2 are deliberately non-identical on same noise. +# Room must affect later samples, not fake position on the direct sound. +difference=sum(abs(int(a)-int(b)) for a,b in + zip(v2four[70000:200000],single[70000:200000])) +assert difference>1500,("V2 room candidate did not affect PCM",difference) +orbitDelta=sum(abs(int(a)-int(b)) for a,b in + zip(v2orbit[70000:200000],orbit[70000:200000])) +assert orbitDelta>1500,("V2 moving room candidate did not affect PCM",orbitDelta) # +90° (second reference segment) has a distinct binaural response. section=single[120000*2:120000*4] left=sum(abs(section[i]) for i in range(0,len(section),2)) diff --git a/tests/sonku_spatial_core_test.cpp b/tests/sonku_spatial_core_test.cpp index 57df5208c..d70ff4988 100644 --- a/tests/sonku_spatial_core_test.cpp +++ b/tests/sonku_spatial_core_test.cpp @@ -78,6 +78,38 @@ int main() { assert(std::abs(oneR[i]-chunkR[i])<1.e-6f); } assert(std::abs(whole.azimuthDegrees()-chunked.azimuthDegrees())<1.e-10); + // V2 A/B: room OFF is the verified original renderer; room ON + // produces only delayed acoustic energy, without modifying first + // arrival, direction signs or host buffer partition behavior. + constexpr int roomFrames=4096; + std::array noL{},noR{},wetL{},wetR{},partL{},partR{}; + noL[0]=wetL[0]=partL[0]=.5f; + noR[0]=wetR[0]=partR[0]=.5f; + SonKuSpatialCore noRoom,withRoom,partRoom; + assert(noRoom.prepare(rate)&&withRoom.prepare(rate)&&partRoom.prepare(rate)); + Settings roomSettings=s;roomSettings.startAzimuthDegrees=0.f; + assert(noRoom.setSettings(roomSettings)&&withRoom.setSettings(roomSettings) + &&partRoom.setSettings(roomSettings)); + assert(withRoom.setEarlyReflectionsAmount(.55f)); + assert(partRoom.setEarlyReflectionsAmount(.55f)); + noRoom.process(noL.data(),noR.data(),roomFrames); + withRoom.process(wetL.data(),wetR.data(),roomFrames); + partRoom.process(partL.data(),partR.data(),128); + partRoom.process(partL.data()+128,partR.data()+128,384); + partRoom.process(partL.data()+512,partR.data()+512,roomFrames-512); + double roomDifference=0.; + for(int i=0;i180)roomDifference+=std::abs(wetL[i]-noL[i])+ + std::abs(wetR[i]-noR[i]); + } + assert(roomDifference>.001); // A hard FRONT->REAR teleport must not replace 560 FIR coefficients // at the next 16-sample boundary. Compare the identical dry/PCM // history before and immediately after reposition. diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 807ca3141..4524af5cf 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -66,9 +66,11 @@ Settings fixed(float azimuth){ s.stereoSpreadDegrees=0.f;s.spatialMix=1.f;s.outputTrim=.72f; return s; } -std::vector staticProbes(const std::vector& azimuths) { +std::vector staticProbes(const std::vector& azimuths,float roomAmount=0.f) { SonKuSpatialCore dsp;Noise noise; if(!dsp.prepare(rate))throw std::runtime_error("No 48k HRTF"); + if(!dsp.setEarlyReflectionsAmount(roomAmount)) + throw std::runtime_error("Invalid early room amount"); std::vector result; result.reserve(static_cast(azimuths.size())* (activeFrames+silenceFrames)*4); @@ -96,9 +98,11 @@ std::vector staticProbes(const std::vector& azimuths) { } return result; } -std::vector orbit(){ +std::vector orbit(float roomAmount=0.f){ SonKuSpatialCore dsp;Noise noise; if(!dsp.prepare(rate))throw std::runtime_error("No 48k HRTF"); + if(!dsp.setEarlyReflectionsAmount(roomAmount)) + throw std::runtime_error("Invalid orbit room amount"); Settings s=fixed(0.f);s.moving=true;s.clockwise=true;s.revolutionSeconds=10.f; dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("No 360 orbit"); const int frames=rate*10; @@ -141,7 +145,14 @@ void notes(const std::filesystem::path& directory, <<"sonku-orbit-cw.wav: 10s one continuous 360deg clockwise orbit,\n" <<"starting at FRONT, acoustic RIGHT on listener's right headphone.\n\n" <<"If front/rear is ambiguous or internalized, note headphones and listener.\n" - <<"These are not room reflections, personalized HRTFs or VST3 binaries.\n"; + <<"Baseline SonKu files have no room reflections (V1).\n" + <<"V2 room candidate adds four 1st-order image-source reflections\n" + <<"per emitter (6.4x8m fixed room) with bounded ear delays and level.\n" + <<"sonku-v2-room-four.wav = A/B against sonku-reference-four.wav.\n" + <<"sonku-v2-room-orbit-cw.wav = A/B against sonku-orbit-cw.wav.\n" + <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" + <<"Do blind-level and externalization evaluation before enabling V2 live.\n" + <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; std::ofstream key(directory/"BLIND-ANSWER-KEY.txt"); if(!key)throw std::runtime_error("Cannot write blind answer key"); key<<"OPEN ONLY AFTER LISTENING. Exact 2.5-second trial windows:\n"; @@ -160,6 +171,12 @@ int main(int argc,char** argv){ staticProbes({reference.begin(),reference.end()})); writeWav(dir/"sonku-blind-eight.wav",staticProbes(blind)); writeWav(dir/"sonku-orbit-cw.wav",orbit()); + // Only the bounded early-reflection stage changes between paired + // files. Source, directions, KEMAR HRIR, loudness trim and clock are + // identical. Blind front/back listening is the decision gate. + writeWav(dir/"sonku-v2-room-four.wav", + staticProbes({reference.begin(),reference.end()},.55f)); + writeWav(dir/"sonku-v2-room-orbit-cw.wav",orbit(.55f)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + one 360 orbit\n"; From 2dfc5d4d47b3a7d6c1978c29a92276d1977a3946 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:20:43 +0700 Subject: [PATCH 03/13] docs(sonku-v2): externalization image-source model and gated A/B design --- docs/ARD_8D_SONKU_BINAURAL_ENGINE_20261112.md | 4 +++ docs/PRD_8D_SONKU_SPATIAL_AUDIO_20261112.md | 4 +++ ...KU_V2_EXTERNALIZATION_DECISION_20261113.md | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md diff --git a/docs/ARD_8D_SONKU_BINAURAL_ENGINE_20261112.md b/docs/ARD_8D_SONKU_BINAURAL_ENGINE_20261112.md index 56332e885..fc17bc3c1 100644 --- a/docs/ARD_8D_SONKU_BINAURAL_ENGINE_20261112.md +++ b/docs/ARD_8D_SONKU_BINAURAL_ENGINE_20261112.md @@ -151,3 +151,7 @@ This record supersedes the earlier **round/circular stage UI** and radial 2D mar - **No extra renderer or CSS owner**: add to existing one /preview/ editor and existing `mixer-fx-rack.css`, maintaining exactly 18 CSS owner links. No WebAudio, DSP JS clone, extra callback or CPU-intensive continuous 3D scene. - **Verification evidence**: Chromium assembled native GUI two viewport screenshots, actual FX picker insertion and ACK/readback, four acoustic directions, front/rear painter order, both monitors visible at 0° spread, real mouse drag to FRONT, rotary drag with one typed native request. Exact SHA `4652a744ab4ae01b1ceca58bb6c3d7e372eb420a`, [UI run](https://github.com/masarray/arsonmix/actions/runs/43342451656), [two screenshots](https://github.com/masarray/arsonmix/actions/runs/43342451656/artifacts/13999089726). - **Release gate**: browser FAT uses simulated JUCE events. It is not physical binaural localization or installed Windows/ASIO FAT, and the PR must be reconciled with advancing `main` before any public release. + + +## 2026-11-13 — V2 spatial externalization architecture +See docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md. Experimental room processing is opt-in and OFF in native JUCE until qualified with headphone A/B. Fixed bounded image-source early reflections retain the same single PCM authority; future ITD-aligned HRIR implementation is a separate stage. diff --git a/docs/PRD_8D_SONKU_SPATIAL_AUDIO_20261112.md b/docs/PRD_8D_SONKU_SPATIAL_AUDIO_20261112.md index aacb08d2d..c69633c38 100644 --- a/docs/PRD_8D_SONKU_SPATIAL_AUDIO_20261112.md +++ b/docs/PRD_8D_SONKU_SPATIAL_AUDIO_20261112.md @@ -100,3 +100,7 @@ Both L and R studio monitor speakers must remain separately visible and individu The editor must feel like a compact hardware-grade audio plugin, with tactile rotary controls and clear numeric readouts, not large web-style cards or anonymous browser sliders. Rotary pointer gestures must be bounded and single-commit; keyboard focus, range semantics and double-click default restoration remain accessible. Do not imitate or redistribute commercial plugin skins. Acceptance evidence on the real compiled native HTML bundle must cover correct Z-order, actual PNG load, two separately visible monitors at 0° spread, correct four-direction mapping, mouse drag to FRONT, knob edit single native queue/ACK and desktop/narrow screenshots. Do not translate GUI PASS into a claim of verified binaural headphone localization. + + +## 2026-11-13 — perceptual acceptance and UX guardrails +User reports correct 8/8 blind positions and 4/4 known, but insufficient FRONT/REAR distance and uneven perceived motion. Preserve the correct azimuth signs and build same-input, level-checked original-vs-V2 headphone WAVs first. No extra controls or labels before sound is validated. A future SPACE knob must be compact, discoverable and backed by native typed ACK/readback and compatible session migration; default must remain user-test-proven rather than arbitrary reverb. diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md new file mode 100644 index 000000000..d7b8375a6 --- /dev/null +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -0,0 +1,34 @@ +# 8D-SonKu V2 — Externalization & Natural Orbit Architecture +2026-11-13 | Experimental stage M1 | Based on PR #606 baseline + +## Confirmed user observations +- Headphone listener reports correct directions, 4/4 known and 8/8 blind. +- FRONT/REAR are too thin/near-head and motion through both median-plane axes lacks realistic depth. +- This is a perceptual report, NOT a measured distance, CPU benchmark or proof of identical HRTF fit for all listeners. + +## Technical research and prior art (no code or skin copying) +- Allen & Berkley (1979), Image Method for Efficiently Simulating Small-Room Acoustics, JASA 65(4), DOI 10.1121/1.382599 — geometrical mirror-image first-order acoustic paths and time-of-flight. +- Steam Audio core guide: https://github.com/ValveSoftware/steam-audio/blob/master/core/doc/guide.rst — direct binaural HRTF, room reflections and distance effects are separate, testable stages. +- 3D Tune-In Audio Toolkit: https://github.com/3DTune-In/3dti_AudioToolkit — ITD-independent HRIR interpolation and acoustic parallax are mature solutions, *research for later M2*, not implemented here. +- Frontal externalization BRIR study: https://pmc.ncbi.nlm.nih.gov/articles/PMC13451706/ — altered early reflections and direct/reflected ratio can improve front externalization for some listeners, not a guaranteed result on all headphones. + +## Current implementation decision: split M1 from the other acoustic stages +Keep SonKuSpatialCore and native JUCE/PCM graph as one authoritative processor; no new DSP engine, new device callback, JS audio path, thread, blocking call, file access or dynamic callback allocation. Add SonKuEarlyReflections as a fixed-memory, first-order image-source *experimental* room stage. Amount=0 by default and guarantees identical previously qualified native PCM. Amount=.55 generates *offline-only* A/B comparison WAVs using the exact original source samples and direct KEMAR HRIR. Do not publish this as a new default until blind headphone tests support it. + +### Bounded acoustic model (M1) +- Room width 6.4m, depth 8.0m, listener centered, 2 sources at 1.6m rotating on the horizontal ring. +- Four first-order wall images per source (left, right, front, rear), hence eight reflected paths. +- Delay in samples = (distance from image - direct source distance) / 343m/s × sample rate, plus a small symmetric ear baseline to create directional ITD; gains = wall reflectivity × directDistance/pathDistance × fixed safety factor. +- Mild source low-pass, ear-directional ITD/ILD approximation; NOT HRTF-convolved reflected signals or FDN reverb. +- Fixed 8192-frame power-of-two ring for each source (~64KiB total) and fractional-delay interpolation; geometry updates every 64 frames while delay and gains smoothly follow per-sample. +- Works at 44.1/48k; conservative fixed delay bounds; original direct HRTF FIR, stereo dry, spatialMix, outputTrim, ASIO and native ACK/readback remain untouched. +- One C++ unit gate, one exact-core integration parity test, two A/B WAV comparisons and a bounded CPU comparison before Windows FAT. + +## Staged next steps (NOT yet delivered) +M2: ITD/time-aligned measured HRIR preprocessing + fractional ear delay, grid-point identity and phase/ILD regression; no generic "phase aligned" switch without proving source accuracy. +M3: if needed, prepared HRTF-filtered reflections with bounded convolution and room distance parameter. +M4: only after successful listening trials, a compact SPACE control with native typed lease, accepted ACK/readback, versioned session schema and a calibrated default. No extra user-facing page. +M5: optional low-cost FDN late reverb, several HRTF profiles / calibration and head tracking after measured CPU and perceptual evidence. + +## Listening gate +Compare the legacy source-accurate 4-direction WAV and 10s orbit with two V2 files rendered from EXACT same input samples. Match perceived level, listen on headphones with OS virtualization off. Measure 8-direction mapping, front/rear distance, orbit continuity, colorations, metallic echoes and time-varying flutter. If room worsens direction or sound quality, keep amount=0. CI PCM PASS alone does not prove spatial externalization. From 2fe3df69e5fc5d7fdafca32ec6a32adb472769e8 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:23:37 +0700 Subject: [PATCH 04/13] fix(sonku-v2): finite room shutdown and exact zero bypass after slew --- engine/builtin_fx/sonku/SonKuEarlyReflections.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 8bdc3172a..240fe516c 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -63,7 +63,9 @@ class SonKuEarlyReflections final { history_[s][write_]=.70f*x[s]+.30f*lowpass_[s]; } amount_+=amountSlew_*(amountTarget_-amount_); - if(std::abs(amount_-amountTarget_)<1.e-6f)amount_=amountTarget_; + // Bound shutdown to a finite 10-12 time-constant fade, then + // restore strict bit-exact OFF/zero CPU on the next callback. + if(std::abs(amount_-amountTarget_)<1.e-5f)amount_=amountTarget_; Ears output{}; for(int s=0;s Date: Fri, 13 Nov 2026 10:26:41 +0700 Subject: [PATCH 05/13] perf(sonku-v2): same-runner V1 vs early-reflection CPU comparison at 44.1/48k --- .github/workflows/ui-smoke.yml | 4 ++ tools/sonku_rt_benchmark.cpp | 74 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tools/sonku_rt_benchmark.cpp diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index c5cba742f..03fc36a4f 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -215,6 +215,10 @@ jobs: /tmp/sonku-listening sonku-listening g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_early_reflections_test.cpp -o /tmp/sonku-room-test /tmp/sonku-room-test + - name: SonKu same-runner realtime CPU comparison (informational, not a release pass) + run: | + g++ -std=c++20 -O2 -Wall -Wextra -pedantic tools/sonku_rt_benchmark.cpp -o /tmp/sonku-rt-bench + /tmp/sonku-rt-bench python tests/sonku_offline_demo_contract.py sonku-listening - name: Publish 8D-SonKu reproducible listening WAVs and blind answer key if: ${{ always() }} diff --git a/tools/sonku_rt_benchmark.cpp b/tools/sonku_rt_benchmark.cpp new file mode 100644 index 000000000..9b3a0f9fd --- /dev/null +++ b/tools/sonku_rt_benchmark.cpp @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Scoped, runner-local reference measurement: never a hard/flaky CI threshold. +// Same 8D-SonKu core, same input blocks, same sample clock for V1 and V2. +// No wall-clock queries or I/O INSIDE the realtime processing function. +#include "../engine/builtin_fx/sonku/SonKuSpatialCore.h" +#include +#include +#include +#include +#include +#include + +namespace { +struct Result {double milliseconds=0.,checksum=0.,audios=0.;}; +template +Result measure(double rate,float amount){ + using namespace armix::sonku; + SonKuSpatialCore dsp; + if(!dsp.prepare(rate))throw std::runtime_error("unsupported sample rate"); + Settings s{};s.moving=true;s.revolutionSeconds=10.f; + s.spatialMix=1.f;s.stereoSpreadDegrees=60.f; + if(!dsp.setSettings(s)||!dsp.setEarlyReflectionsAmount(amount)) + throw std::runtime_error("invalid DSP setup"); + std::array inputL{},inputR{}; + for(std::size_t n=0;n(rate)*3; // three virtual seconds + auto start=std::chrono::steady_clock::now(); + double checksum=0.; + int done=0; + while(done(static_cast(block),frames-done); + auto l=inputL,r=inputR; + dsp.process(l.data(),r.data(),take); + for(int i=0;i( + std::chrono::steady_clock::now()-start).count(); + if(!(elapsed>0.)||!(checksum>1.))throw std::runtime_error("empty benchmark"); + return {elapsed,checksum,static_cast(frames)/rate}; +} +template +void report(double rate){ + const auto baseline=measure(rate,0.f); + const auto room=measure(rate,.55f); + std::cout<(rate); + report<512>(rate); + } + }catch(const std::exception& e){ + std::cerr<<"SONKU CPU BENCH FAIL: "< Date: Fri, 13 Nov 2026 10:39:25 +0700 Subject: [PATCH 06/13] feat(sonku-v2): render uninterrupted two-turn 20s orbit with seam and phase gates --- ...KU_V2_EXTERNALIZATION_DECISION_20261113.md | 5 ++++ tests/sonku_offline_demo_contract.py | 16 ++++++++++--- tools/sonku_offline_listening.cpp | 23 +++++++++++++------ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md index d7b8375a6..6105b9427 100644 --- a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -32,3 +32,8 @@ M5: optional low-cost FDN late reverb, several HRTF profiles / calibration and h ## Listening gate Compare the legacy source-accurate 4-direction WAV and 10s orbit with two V2 files rendered from EXACT same input samples. Match perceived level, listen on headphones with OS virtualization off. Measure 8-direction mapping, front/rear distance, orbit continuity, colorations, metallic echoes and time-varying flutter. If room worsens direction or sound quality, keep amount=0. CI PCM PASS alone does not prove spatial externalization. + +## 2026-11-13 listener feedback and two-turn orbit gate +Listener recognizes direction but describes a noncircular perceived orbit: RIGHT → FRONT is pleasing, yet FRONT/RIGHT/REAR continuity feels incomplete and FRONT subjectively nearer. The room is **rectangular 6.4 × 8 m**, so reflected image distances and directional/temporal profiles vary across axes. This is one plausible contributor, not a proven cause; non-individual HRTF and ITD-inconsistent HRIR interpolation remain other hypotheses. + +The offline evaluation now renders a **single uninterrupted 20-second, 2 × 360° clockwise trajectory** (10 seconds/turn) for both legacy direct HRTF and rectangular-room A/B. Only fade in at time 0 and fade out at 20 seconds; no fade/reset/offset at the 10-second boundary. Landmarks: FRONT 0/10/20s; RIGHT 2.5/12.5; REAR 5/15; LEFT 7.5/17.5. PCM tests verify 960,000 frames, non-silent seam, fixed rate and output sign, and C++ end-of-two-turn phase closure. Do not market a verified circular perceptual effect until headphone evaluation. diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index 07ad8f4e1..c7a5d1b1c 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -23,9 +23,9 @@ def read(name, frames): return pcm single=read("sonku-reference-four.wav",4*120000) blind=read("sonku-blind-eight.wav",8*120000) -orbit=read("sonku-orbit-cw.wav",480000) +orbit=read("sonku-orbit-cw-2x.wav",960000) v2four=read("sonku-v2-room-four.wav",4*120000) -v2orbit=read("sonku-v2-room-orbit-cw.wav",480000) +v2orbit=read("sonku-v2-room-orbit-cw-2x.wav",960000) # Baseline V1 and candidate V2 are deliberately non-identical on same noise. # Room must affect later samples, not fake position on the direct sound. difference=sum(abs(int(a)-int(b)) for a,b in @@ -41,8 +41,18 @@ def read(name, frames): assert right>left*1.2,("RIGHT HRTF channel swapped",left,right) # No false silence between orbit buffer boundaries; source is continuous. assert sum(abs(x) for x in orbit[220000:230000])>1000 +# Verify there is no mute, edit or source reset at the 10s handoff. +# Stereo interleaved: 48000 samples = 1 second, 2 PCM ints per frame. +for audio in (orbit,v2orbit): + for second in (9,10,11,19): + begin=(second*48000+4000)*2 + assert sum(abs(x) for x in audio[begin:begin+9600])>2000,( + "silent loop seam",second) +assert "20s" in (root/"LISTENING-GUIDE.txt").read_text() +assert not (root/"sonku-orbit-cw.wav").exists(),( + "stale 10s artifact must not appear alongside 2x master") assert (root/"LISTENING-GUIDE.txt").exists() key=(root/"BLIND-ANSWER-KEY.txt").read_text() assert key.count("Trial ")==8 and key.count("FRONT")==2 and key.count("REAR")==2 print("PASS 8D-SonKu actual C++ offline WAV: four directions, balanced blind", - "set, clockwise orbit, 48kHz stereo PCM, no clipping.") + "set, two continuous 360deg turns (20s), 48kHz stereo PCM, no clipping.") diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 4524af5cf..67ae2f79c 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -21,6 +21,10 @@ constexpr int framesPerBlock=128; constexpr int activeFrames=rate*2; constexpr int silenceFrames=rate/2; constexpr int rampFrames=rate/50; // 20ms, no clicks between labeled probes +constexpr int orbitSecondsPerTurn=10; +constexpr int orbitTurns=2; +constexpr int orbitFrames=rate*orbitSecondsPerTurn*orbitTurns; +static_assert(orbitFrames==960000); using armix::sonku::Settings; using armix::sonku::SonKuSpatialCore; struct Noise { @@ -105,7 +109,7 @@ std::vector orbit(float roomAmount=0.f){ throw std::runtime_error("Invalid orbit room amount"); Settings s=fixed(0.f);s.moving=true;s.clockwise=true;s.revolutionSeconds=10.f; dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("No 360 orbit"); - const int frames=rate*10; + const int frames=orbitFrames; // two complete turns on ONE continuous audio clock std::vector result; result.reserve(static_cast(frames)*4); for(int base=0;base orbit(float roomAmount=0.f){ dsp.process(l.data(),r.data(),n); for(int i=0;i.01) + throw std::runtime_error("Two turns do not close acoustic orbit"); return result; } const char* direction(int deg) { @@ -142,14 +149,16 @@ void notes(const std::filesystem::path& directory, <<"then 0.5s quiet. Order: FRONT, RIGHT, REAR, LEFT.\n" <<"sonku-blind-eight.wav: 8 x 2.5 seconds, balanced two times each.\n" <<"Write down FRONT/RIGHT/REAR/LEFT for trials 1..8 before opening KEY.\n" - <<"sonku-orbit-cw.wav: 10s one continuous 360deg clockwise orbit,\n" - <<"starting at FRONT, acoustic RIGHT on listener's right headphone.\n\n" + <<"sonku-orbit-cw-2x.wav: 20s TWO seamless continuous 360deg\n" + <<"clockwise turns, 10s each, FRONT at 0/10/20s. No pause at 10s.\n" + <<"At 2.5/12.5s RIGHT, 5/15s REAR, 7.5/17.5s LEFT.\n" + <<"Acoustic RIGHT is on listener's right headphone.\n\n" <<"If front/rear is ambiguous or internalized, note headphones and listener.\n" <<"Baseline SonKu files have no room reflections (V1).\n" <<"V2 room candidate adds four 1st-order image-source reflections\n" <<"per emitter (6.4x8m fixed room) with bounded ear delays and level.\n" <<"sonku-v2-room-four.wav = A/B against sonku-reference-four.wav.\n" - <<"sonku-v2-room-orbit-cw.wav = A/B against sonku-orbit-cw.wav.\n" + <<"sonku-v2-room-orbit-cw-2x.wav = A/B against sonku-orbit-cw-2x.wav.\n" <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" <<"Do blind-level and externalization evaluation before enabling V2 live.\n" <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; @@ -170,16 +179,16 @@ int main(int argc,char** argv){ writeWav(dir/"sonku-reference-four.wav", staticProbes({reference.begin(),reference.end()})); writeWav(dir/"sonku-blind-eight.wav",staticProbes(blind)); - writeWav(dir/"sonku-orbit-cw.wav",orbit()); + writeWav(dir/"sonku-orbit-cw-2x.wav",orbit()); // Only the bounded early-reflection stage changes between paired // files. Source, directions, KEMAR HRIR, loudness trim and clock are // identical. Blind front/back listening is the decision gate. writeWav(dir/"sonku-v2-room-four.wav", staticProbes({reference.begin(),reference.end()},.55f)); - writeWav(dir/"sonku-v2-room-orbit-cw.wav",orbit(.55f)); + writeWav(dir/"sonku-v2-room-orbit-cw-2x.wav",orbit(.55f)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " - <<"4 labeled + 8 blind directions + one 360 orbit\n"; + <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n"; }catch(const std::exception& error){ std::cerr<<"SonKu offline render FAILED: "< Date: Fri, 13 Nov 2026 10:42:47 +0700 Subject: [PATCH 07/13] feat(sonku-v2): 20s square-room diagnostic orbit and mirrored reflection tests --- ...KU_V2_EXTERNALIZATION_DECISION_20261113.md | 3 +++ .../builtin_fx/sonku/SonKuEarlyReflections.h | 23 +++++++++++++++++-- engine/builtin_fx/sonku/SonKuSpatialCore.h | 4 ++++ tests/sonku_early_reflections_test.cpp | 16 +++++++++++++ tests/sonku_offline_demo_contract.py | 6 ++++- tools/sonku_offline_listening.cpp | 15 ++++++++---- 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md index 6105b9427..45f3f7381 100644 --- a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -37,3 +37,6 @@ Compare the legacy source-accurate 4-direction WAV and 10s orbit with two V2 fil Listener recognizes direction but describes a noncircular perceived orbit: RIGHT → FRONT is pleasing, yet FRONT/RIGHT/REAR continuity feels incomplete and FRONT subjectively nearer. The room is **rectangular 6.4 × 8 m**, so reflected image distances and directional/temporal profiles vary across axes. This is one plausible contributor, not a proven cause; non-individual HRTF and ITD-inconsistent HRIR interpolation remain other hypotheses. The offline evaluation now renders a **single uninterrupted 20-second, 2 × 360° clockwise trajectory** (10 seconds/turn) for both legacy direct HRTF and rectangular-room A/B. Only fade in at time 0 and fade out at 20 seconds; no fade/reset/offset at the 10-second boundary. Landmarks: FRONT 0/10/20s; RIGHT 2.5/12.5; REAR 5/15; LEFT 7.5/17.5. PCM tests verify 960,000 frames, non-silent seam, fixed rate and output sign, and C++ end-of-two-turn phase closure. Do not market a verified circular perceptual effect until headphone evaluation. + +## 2026-11-13 — rectangular vs symmetric-room controlled comparison +The report of an elliptical/unequal-distance orbit does NOT prove a room-model bug. Alongside V1 direct HRTF and the existing rectangular 6.4×8m image-source room, a third A/B WAV uses a square 7.2×7.2m room with all wall reflectivities identical. The emitted direct HRTF, sample clock, source waveform and 2×360° motion remain identical. The square wall layout has fourfold rotational geometry and tests whether wall distance contributes to perceived asymmetry; it is NOT a circular room or a promised perceptual cure. C++ tests check left/right mirror of the reflected impulse. A/B only, original native default remains OFF. diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 240fe516c..501cccfca 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -4,6 +4,7 @@ #include #include #include +#include // Bounded, first-order image-source room for headphone externalization trials. // Reflection image geometry follows Allen & Berkley (JASA, 1979), not @@ -11,6 +12,7 @@ // this is NOT an HRTF-convolved reflection / arbitrary geometry simulation. // No allocation, locks, worker, I/O, FFT or second device callback. namespace armix::sonku { +enum class SonKuRoomShape : std::uint8_t { Rectangular=0, Square=1 }; class SonKuEarlyReflections final { public: struct Ears {float left=0.f,right=0.f;}; @@ -46,6 +48,17 @@ class SonKuEarlyReflections final { amountTarget_=value; return true; } + // Offline experiment only. Reject shape edits while effect is active. + bool setShape(SonKuRoomShape shape) noexcept { + if(shape!=SonKuRoomShape::Rectangular && shape!=SonKuRoomShape::Square) + return false; + if(active())return false; + shape_=shape; + untilGeometry_=0; + primed_=false; + return true; + } + SonKuRoomShape shape() const noexcept {return shape_;} bool active() const noexcept {return ready_&&(amount_>0.f||amountTarget_>0.f);} float targetAmount() const noexcept {return amountTarget_;} Ears process(float left,float right,double azimuth,float spread) noexcept { @@ -104,10 +117,15 @@ class SonKuEarlyReflections final { void updateGeometry(double azimuth,float spread) noexcept { constexpr float pi=3.14159265358979323846f; constexpr float sourceDistance=1.60f; // meters - constexpr float halfWidth=3.20f,halfDepth=4.00f; + // The square profile tests rotationally symmetric wall geometry; + // it is not a simulated circular room or guaranteed psychoacoustics. + const float halfWidth=(shape_==SonKuRoomShape::Square)?3.60f:3.20f; + const float halfDepth=(shape_==SonKuRoomShape::Square)?3.60f:4.00f; constexpr float speedOfSound=343.f; constexpr float earHalfTime=.00031f; // max +/-0.31ms - constexpr std::array walls{.74f,.74f,.67f,.67f}; + constexpr std::array rectangular{.74f,.74f,.67f,.67f}; + constexpr std::array square{.70f,.70f,.70f,.70f}; + const auto& walls=(shape_==SonKuRoomShape::Square)?square:rectangular; for(int source=0;source(azimuth) +(source==0?-.5f:.5f)*spread; @@ -152,6 +170,7 @@ class SonKuEarlyReflections final { float rate_=0.f,delaySlew_=0.f,gainSlew_=0.f,amountSlew_=0.f; float amount_=0.f,amountTarget_=0.f; int write_=0,untilGeometry_=0; + SonKuRoomShape shape_=SonKuRoomShape::Rectangular; bool ready_=false,primed_=false; }; } // namespace armix::sonku diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index a99a0c5d0..7ba5d1237 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -83,6 +83,10 @@ class SonKuSpatialCore final { bool setEarlyReflectionsAmount(float amount) noexcept { return room_.setAmount(amount); } + // Explicit A/B-only shape selection; never persisted or host-exposed. + bool setEarlyReflectionsShape(SonKuRoomShape shape) noexcept { + return room_.setShape(shape); + } bool ready() const noexcept {return ready_;} double azimuthDegrees() const noexcept {return degrees_;} // In-place stereo; caller owns valid, non-overlapping L/R PCM pointers. diff --git a/tests/sonku_early_reflections_test.cpp b/tests/sonku_early_reflections_test.cpp index 5edd9b7f9..e6fd7b392 100644 --- a/tests/sonku_early_reflections_test.cpp +++ b/tests/sonku_early_reflections_test.cpp @@ -13,6 +13,22 @@ int main(){ assert(!invalid.prepare(96000.)); assert(!invalid.prepare(std::numeric_limits::quiet_NaN())); for(double rate:{44100.,48000.}){ + SonKuEarlyReflections squareRight,squareLeft; + assert(squareRight.prepare(rate)&&squareLeft.prepare(rate)); + assert(squareRight.setShape(SonKuRoomShape::Square)); + assert(squareLeft.setShape(SonKuRoomShape::Square)); + assert(squareRight.setAmount(.55f)&&squareLeft.setAmount(.55f)); + double mirrorError=0.,soundEnergy=0.; + for(int i=0;i<4096;++i){ + const float v=i==0?1.f:0.f; + const auto right=squareRight.process(v,0.f,90.,0.f); + const auto left=squareLeft.process(v,0.f,-90.,0.f); + mirrorError+=std::abs(right.left-left.right)+ + std::abs(right.right-left.left); + soundEnergy+=std::abs(right.left)+std::abs(right.right); + } + assert(soundEnergy>.004); + assert(mirrorError<1.e-4); SonKuEarlyReflections a,b; assert(a.prepare(rate)&&b.prepare(rate)); assert(!a.active()); diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index c7a5d1b1c..2ce96cba0 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -26,6 +26,7 @@ def read(name, frames): orbit=read("sonku-orbit-cw-2x.wav",960000) v2four=read("sonku-v2-room-four.wav",4*120000) v2orbit=read("sonku-v2-room-orbit-cw-2x.wav",960000) +squareOrbit=read("sonku-v2-square-orbit-cw-2x.wav",960000) # Baseline V1 and candidate V2 are deliberately non-identical on same noise. # Room must affect later samples, not fake position on the direct sound. difference=sum(abs(int(a)-int(b)) for a,b in @@ -34,6 +35,9 @@ def read(name, frames): orbitDelta=sum(abs(int(a)-int(b)) for a,b in zip(v2orbit[70000:200000],orbit[70000:200000])) assert orbitDelta>1500,("V2 moving room candidate did not affect PCM",orbitDelta) +shapeDelta=sum(abs(int(a)-int(b)) for a,b in + zip(squareOrbit[70000:200000],v2orbit[70000:200000])) +assert shapeDelta>1500,("Square and rectangle rendered the same",shapeDelta) # +90° (second reference segment) has a distinct binaural response. section=single[120000*2:120000*4] left=sum(abs(section[i]) for i in range(0,len(section),2)) @@ -43,7 +47,7 @@ def read(name, frames): assert sum(abs(x) for x in orbit[220000:230000])>1000 # Verify there is no mute, edit or source reset at the 10s handoff. # Stereo interleaved: 48000 samples = 1 second, 2 PCM ints per frame. -for audio in (orbit,v2orbit): +for audio in (orbit,v2orbit,squareOrbit): for second in (9,10,11,19): begin=(second*48000+4000)*2 assert sum(abs(x) for x in audio[begin:begin+9600])>2000,( diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 67ae2f79c..18424964d 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -102,11 +102,13 @@ std::vector staticProbes(const std::vector& azimuths,float ro } return result; } -std::vector orbit(float roomAmount=0.f){ +std::vector orbit(float roomAmount=0.f, + armix::sonku::SonKuRoomShape shape=armix::sonku::SonKuRoomShape::Rectangular){ SonKuSpatialCore dsp;Noise noise; if(!dsp.prepare(rate))throw std::runtime_error("No 48k HRTF"); - if(!dsp.setEarlyReflectionsAmount(roomAmount)) - throw std::runtime_error("Invalid orbit room amount"); + if(!dsp.setEarlyReflectionsShape(shape)|| + !dsp.setEarlyReflectionsAmount(roomAmount)) + throw std::runtime_error("Invalid orbit room configuration"); Settings s=fixed(0.f);s.moving=true;s.clockwise=true;s.revolutionSeconds=10.f; dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("No 360 orbit"); const int frames=orbitFrames; // two complete turns on ONE continuous audio clock @@ -158,7 +160,10 @@ void notes(const std::filesystem::path& directory, <<"V2 room candidate adds four 1st-order image-source reflections\n" <<"per emitter (6.4x8m fixed room) with bounded ear delays and level.\n" <<"sonku-v2-room-four.wav = A/B against sonku-reference-four.wav.\n" - <<"sonku-v2-room-orbit-cw-2x.wav = A/B against sonku-orbit-cw-2x.wav.\n" + <<"sonku-v2-room-orbit-cw-2x.wav = 6.4 x 8m rectangular room.\n" + <<"sonku-v2-square-orbit-cw-2x.wav = 7.2 x 7.2m symmetric room.\n" + <<"Both candidates reuse the SAME direct HRTF/noise and 20s clock.\n" + <<"Square geometry is not a guarantee of circular perception.\n" <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" <<"Do blind-level and externalization evaluation before enabling V2 live.\n" <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; @@ -186,6 +191,8 @@ int main(int argc,char** argv){ writeWav(dir/"sonku-v2-room-four.wav", staticProbes({reference.begin(),reference.end()},.55f)); writeWav(dir/"sonku-v2-room-orbit-cw-2x.wav",orbit(.55f)); + writeWav(dir/"sonku-v2-square-orbit-cw-2x.wav", + orbit(.55f,armix::sonku::SonKuRoomShape::Square)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n"; From 409ed5d175345204048aa6a64a9ac229a475f062 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:44:32 +0700 Subject: [PATCH 08/13] feat(sonku-v2): two-turn clockwise and counterclockwise binaural A/B set --- docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md | 3 +++ tests/sonku_offline_demo_contract.py | 9 ++++++++- tools/sonku_offline_listening.cpp | 13 +++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md index 45f3f7381..b7acf194f 100644 --- a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -40,3 +40,6 @@ The offline evaluation now renders a **single uninterrupted 20-second, 2 × 360 ## 2026-11-13 — rectangular vs symmetric-room controlled comparison The report of an elliptical/unequal-distance orbit does NOT prove a room-model bug. Alongside V1 direct HRTF and the existing rectangular 6.4×8m image-source room, a third A/B WAV uses a square 7.2×7.2m room with all wall reflectivities identical. The emitted direct HRTF, sample clock, source waveform and 2×360° motion remain identical. The square wall layout has fourfold rotational geometry and tests whether wall distance contributes to perceived asymmetry; it is NOT a circular room or a promised perceptual cure. C++ tests check left/right mirror of the reflected impulse. A/B only, original native default remains OFF. + +## 2026-11-13 — independent reversed-motion listening probes +In response to asymmetrical perceived naturalness of RIGHT→FRONT vs FRONT→RIGHT, add three CCW two-turn WAVs alongside the three clockwise versions. All six are 20 seconds, use the exact same deterministic original noise, same native HRTF and DSP sample clock, and have no loop seam. Clockwise: FRONT → RIGHT → REAR → LEFT → FRONT. Counterclockwise: FRONT → LEFT → REAR → RIGHT → FRONT. This allows listening comparison of RIGHT→FRONT (CCW at 7.5–10 and 17.5–20 seconds) with FRONT→RIGHT (CW at 0–2.5 and 10–12.5 seconds), and tests whether perceptual asymmetry reverses with source rotation direction. No additional live motion modes, no UI changes, no assertion of physically circular perception. diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index 2ce96cba0..1cfba47c2 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -27,6 +27,9 @@ def read(name, frames): v2four=read("sonku-v2-room-four.wav",4*120000) v2orbit=read("sonku-v2-room-orbit-cw-2x.wav",960000) squareOrbit=read("sonku-v2-square-orbit-cw-2x.wav",960000) +reverse=read("sonku-orbit-ccw-2x.wav",960000) +reverseRoom=read("sonku-v2-room-orbit-ccw-2x.wav",960000) +reverseSquare=read("sonku-v2-square-orbit-ccw-2x.wav",960000) # Baseline V1 and candidate V2 are deliberately non-identical on same noise. # Room must affect later samples, not fake position on the direct sound. difference=sum(abs(int(a)-int(b)) for a,b in @@ -38,6 +41,10 @@ def read(name, frames): shapeDelta=sum(abs(int(a)-int(b)) for a,b in zip(squareOrbit[70000:200000],v2orbit[70000:200000])) assert shapeDelta>1500,("Square and rectangle rendered the same",shapeDelta) +# Reverse motion must change the binaural path (not merely rename a WAV). +reverseDelta=sum(abs(int(a)-int(b)) for a,b in + zip(reverse[350000:500000],orbit[350000:500000])) +assert reverseDelta>1500,("CW/CCW unexpectedly identical",reverseDelta) # +90° (second reference segment) has a distinct binaural response. section=single[120000*2:120000*4] left=sum(abs(section[i]) for i in range(0,len(section),2)) @@ -47,7 +54,7 @@ def read(name, frames): assert sum(abs(x) for x in orbit[220000:230000])>1000 # Verify there is no mute, edit or source reset at the 10s handoff. # Stereo interleaved: 48000 samples = 1 second, 2 PCM ints per frame. -for audio in (orbit,v2orbit,squareOrbit): +for audio in (orbit,v2orbit,squareOrbit,reverse,reverseRoom,reverseSquare): for second in (9,10,11,19): begin=(second*48000+4000)*2 assert sum(abs(x) for x in audio[begin:begin+9600])>2000,( diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 18424964d..1d0126c19 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -103,13 +103,14 @@ std::vector staticProbes(const std::vector& azimuths,float ro return result; } std::vector orbit(float roomAmount=0.f, - armix::sonku::SonKuRoomShape shape=armix::sonku::SonKuRoomShape::Rectangular){ + armix::sonku::SonKuRoomShape shape=armix::sonku::SonKuRoomShape::Rectangular, + bool clockwise=true){ SonKuSpatialCore dsp;Noise noise; if(!dsp.prepare(rate))throw std::runtime_error("No 48k HRTF"); if(!dsp.setEarlyReflectionsShape(shape)|| !dsp.setEarlyReflectionsAmount(roomAmount)) throw std::runtime_error("Invalid orbit room configuration"); - Settings s=fixed(0.f);s.moving=true;s.clockwise=true;s.revolutionSeconds=10.f; + Settings s=fixed(0.f);s.moving=true;s.clockwise=clockwise;s.revolutionSeconds=10.f; dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("No 360 orbit"); const int frames=orbitFrames; // two complete turns on ONE continuous audio clock std::vector result; @@ -164,6 +165,8 @@ void notes(const std::filesystem::path& directory, <<"sonku-v2-square-orbit-cw-2x.wav = 7.2 x 7.2m symmetric room.\n" <<"Both candidates reuse the SAME direct HRTF/noise and 20s clock.\n" <<"Square geometry is not a guarantee of circular perception.\n" + <<"CCW versions contain FRONT>LEFT>REAR>RIGHT>FRONT each 10s.\n" + <<"Compare direction-reversed tracks to isolate turn-order effects.\n" <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" <<"Do blind-level and externalization evaluation before enabling V2 live.\n" <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; @@ -193,6 +196,12 @@ int main(int argc,char** argv){ writeWav(dir/"sonku-v2-room-orbit-cw-2x.wav",orbit(.55f)); writeWav(dir/"sonku-v2-square-orbit-cw-2x.wav", orbit(.55f,armix::sonku::SonKuRoomShape::Square)); + writeWav(dir/"sonku-orbit-ccw-2x.wav", + orbit(0.f,armix::sonku::SonKuRoomShape::Rectangular,false)); + writeWav(dir/"sonku-v2-room-orbit-ccw-2x.wav", + orbit(.55f,armix::sonku::SonKuRoomShape::Rectangular,false)); + writeWav(dir/"sonku-v2-square-orbit-ccw-2x.wav", + orbit(.55f,armix::sonku::SonKuRoomShape::Square,false)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n"; From 3a74b0273c7a7e13d5d2614183d19995eb12ad57 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 10:47:22 +0700 Subject: [PATCH 09/13] test(sonku-v2): import room-shape enum in mirror symmetry fixture --- tests/sonku_early_reflections_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sonku_early_reflections_test.cpp b/tests/sonku_early_reflections_test.cpp index e6fd7b392..9d5787030 100644 --- a/tests/sonku_early_reflections_test.cpp +++ b/tests/sonku_early_reflections_test.cpp @@ -9,6 +9,7 @@ #include int main(){ using armix::sonku::SonKuEarlyReflections; + using armix::sonku::SonKuRoomShape; SonKuEarlyReflections invalid; assert(!invalid.prepare(96000.)); assert(!invalid.prepare(std::numeric_limits::quiet_NaN())); From 3aca1833f40a47341cbf5c999e33582b09a988b5 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 11:13:14 +0700 Subject: [PATCH 10/13] feat(sonku): bounded eight-line stereo FDN late ambience with prepared RT60 presets --- engine/builtin_fx/sonku/SonKuMusicalReverb.h | 134 +++++++++++++++++++ engine/builtin_fx/sonku/SonKuSpatialCore.h | 20 ++- 2 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 engine/builtin_fx/sonku/SonKuMusicalReverb.h diff --git a/engine/builtin_fx/sonku/SonKuMusicalReverb.h b/engine/builtin_fx/sonku/SonKuMusicalReverb.h new file mode 100644 index 000000000..f9775aad6 --- /dev/null +++ b/engine/builtin_fx/sonku/SonKuMusicalReverb.h @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Compact eight-line stereo FDN for musical late ambience. The 8x8 Hadamard +// feedback matrix is orthogonal (unit-energy): stability depends solely on +// prepared per-line RT60 gains and damping. No heap/locks/FFT/trig/I/O in process. +// A small, diffuse late field complements the already-approved square early +// reflections; no source-following stereo pan is imposed on the reverb tail. +// These listening-test presets are OFF in the shipping JUCE editor. +namespace armix::sonku { +enum class SonKuReverbPreset : std::uint8_t { StudioGlue=0, AiryChamber=1 }; + +class SonKuMusicalReverb final { +public: + struct Ears {float left=0.f,right=0.f;}; + static constexpr int lineCount=8; + static constexpr int ringFrames=4096; + bool prepare(double rate) noexcept { + ready_=false; + if(!std::isfinite(rate) || (std::abs(rate-44100.)>.1 && + std::abs(rate-48000.)>.1))return false; + sampleRate_=static_cast(rate); + slew_=static_cast(1.-std::exp(-1./(rate*.012))); + amountTarget_=0.f; + preset_=SonKuReverbPreset::StudioGlue; + configure(); + reset(); + ready_=true; + return true; + } + void reset() noexcept { + for(auto& line:memory_)line.fill(0.f); + lowpass_.fill(0.f); + write_=0;amount_=0.f; + // The target amount is a CONTROL-side setting and survives resetting + // host transport/processor so the same program can restart cleanly. + } + bool setAmount(float amount) noexcept { + if(!std::isfinite(amount) || amount<0.f || amount>1.f)return false; + if(amount_==0.f && amountTarget_==0.f && amount>0.f)reset(); + amountTarget_=amount; + return true; + } + bool setPreset(SonKuReverbPreset value) noexcept { + if(value!=SonKuReverbPreset::StudioGlue && + value!=SonKuReverbPreset::AiryChamber)return false; + // Preset updates calculate RT60 coefficients. Never use this setter + // on an active realtime callback; native host doesn't expose it yet. + if(active())return false; + preset_=value; + configure(); + return true; + } + SonKuReverbPreset preset() const noexcept {return preset_;} + bool active() const noexcept {return ready_&&(amount_>0.f||amountTarget_>0.f);} + float targetAmount() const noexcept {return amountTarget_;} + Ears process(float left,float right) noexcept { + if(!active())return {}; + const float a=std::isfinite(left)?left:0.f; + const float b=std::isfinite(right)?right:0.f; + const float mid=.5f*(a+b); + const float side=.5f*(a-b); + std::array y{},mix{}; + for(int i=0;i inMid{1,1,-1,1,1,-1,-1,1}; + constexpr std::array inSide{1,-1,1,-1,1,-1,1,-1}; + constexpr std::array outL{1,-1,1,1,-1,1,-1,1}; + constexpr std::array outR{-1,1,1,-1,1,1,-1,1}; + float wetLeft=0.f,wetRight=0.f; + for(int i=0;i lengths{ + 2111,2339,2579,2803,3079,3319,3593,3929}; + const float rt60=preset_==SonKuReverbPreset::StudioGlue?.78f:1.28f; + const float cutoff=preset_==SonKuReverbPreset::StudioGlue?5900.f:7000.f; + constexpr float pi=3.14159265358979323846f; + dampCoeff_=1.f-std::exp(-2.f*pi*cutoff/sampleRate_); + for(int i=0;i(std::lround( + lengths[i]*sampleRate_/48000.f)),1,ringFrames-2); + gain_[i]=std::exp(-6.9077553f* + static_cast(delay_[i])/(sampleRate_*rt60)); + } + } + static_assert((ringFrames&(ringFrames-1))==0); + std::array,lineCount> memory_{}; + std::array lowpass_{}; + std::array gain_{}; + std::array delay_{}; + float sampleRate_=48000.f,dampCoeff_=0.f,slew_=0.f; + float amount_=0.f,amountTarget_=0.f; + int write_=0; + SonKuReverbPreset preset_=SonKuReverbPreset::StudioGlue; + bool ready_=false; +}; +} // namespace armix::sonku diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 7ba5d1237..557c0d1ef 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -2,6 +2,7 @@ #pragma once #include "SonKuMeasuredHrir.h" #include "SonKuEarlyReflections.h" +#include "SonKuMusicalReverb.h" #include #include #include @@ -49,7 +50,7 @@ class SonKuSpatialCore final { // without trigonometric/exponential work in the audio callback. filterSlew_=static_cast(1.-std::exp(-1./(rate*0.006))); levelSlew_=static_cast(1.-std::exp(-1./(rate*0.008))); - if(!room_.prepare(rate))return false; + if(!room_.prepare(rate)||!reverb_.prepare(rate))return false; reset(); ready_=true; return true; @@ -65,6 +66,7 @@ class SonKuSpatialCore final { degrees_=wrapDegrees(settings_.startAzimuthDegrees); haveKernel_=false; room_.reset(); + reverb_.reset(); } bool setSettings(const Settings& s) noexcept { if(!valid(s))return false; @@ -87,6 +89,14 @@ class SonKuSpatialCore final { bool setEarlyReflectionsShape(SonKuRoomShape shape) noexcept { return room_.setShape(shape); } + // Experimental wet-only late room, OFF unless explicitly enabled by + // controlled offline A/B. The native parameter contract is unchanged. + bool setMusicalReverbAmount(float amount) noexcept { + return reverb_.setAmount(amount); + } + bool setMusicalReverbPreset(SonKuReverbPreset preset) noexcept { + return reverb_.setPreset(preset); + } bool ready() const noexcept {return ready_;} double azimuthDegrees() const noexcept {return degrees_;} // In-place stereo; caller owns valid, non-overlapping L/R PCM pointers. @@ -136,8 +146,11 @@ class SonKuSpatialCore final { const auto reflection=room_.active() ?room_.process(x0,x1,degrees_,settings_.stereoSpreadDegrees) :SonKuEarlyReflections::Ears{}; - left[i]=dryLevel*x0+binauralLevel*(ears[0]+reflection.left); - right[i]=dryLevel*x1+binauralLevel*(ears[1]+reflection.right); + const auto late=reverb_.active() + ?reverb_.process(x0,x1) + :SonKuMusicalReverb::Ears{}; + left[i]=dryLevel*x0+binauralLevel*(ears[0]+reflection.left+late.left); + right[i]=dryLevel*x1+binauralLevel*(ears[1]+reflection.right+late.right); if(++write_==taps)write_=0; if(step!=0.) { degrees_+=step; @@ -184,6 +197,7 @@ class SonKuSpatialCore final { std::array,2>,2> targets_{}; Settings settings_{}; SonKuEarlyReflections room_{}; + SonKuMusicalReverb reverb_{}; float smoothedMix_=1.f,smoothedTrim_=0.75f; float filterSlew_=0.f,levelSlew_=0.f; double sampleRate_=0.; From 30a75efc424f6d98efb9132b016ac9e23984a7a8 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 11:15:20 +0700 Subject: [PATCH 11/13] test(sonku): musical FDN impulse/PCM/CPU gates and 2x orbit A-B listening renders --- .github/workflows/ui-smoke.yml | 2 + ...KU_V2_EXTERNALIZATION_DECISION_20261113.md | 5 ++ tests/sonku_musical_reverb_test.cpp | 62 +++++++++++++++++++ tests/sonku_offline_demo_contract.py | 10 ++- tests/sonku_spatial_core_test.cpp | 31 ++++++++++ tools/sonku_offline_listening.cpp | 23 ++++++- tools/sonku_rt_benchmark.cpp | 9 ++- 7 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 tests/sonku_musical_reverb_test.cpp diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index 03fc36a4f..2b0cdc9e2 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -215,6 +215,8 @@ jobs: /tmp/sonku-listening sonku-listening g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_early_reflections_test.cpp -o /tmp/sonku-room-test /tmp/sonku-room-test + g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_musical_reverb_test.cpp -o /tmp/sonku-fdn-test + /tmp/sonku-fdn-test - name: SonKu same-runner realtime CPU comparison (informational, not a release pass) run: | g++ -std=c++20 -O2 -Wall -Wextra -pedantic tools/sonku_rt_benchmark.cpp -o /tmp/sonku-rt-bench diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md index b7acf194f..d746285c0 100644 --- a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -43,3 +43,8 @@ The report of an elliptical/unequal-distance orbit does NOT prove a room-model b ## 2026-11-13 — independent reversed-motion listening probes In response to asymmetrical perceived naturalness of RIGHT→FRONT vs FRONT→RIGHT, add three CCW two-turn WAVs alongside the three clockwise versions. All six are 20 seconds, use the exact same deterministic original noise, same native HRTF and DSP sample clock, and have no loop seam. Clockwise: FRONT → RIGHT → REAR → LEFT → FRONT. Counterclockwise: FRONT → LEFT → REAR → RIGHT → FRONT. This allows listening comparison of RIGHT→FRONT (CCW at 7.5–10 and 17.5–20 seconds) with FRONT→RIGHT (CW at 0–2.5 and 10–12.5 seconds), and tests whether perceptual asymmetry reverses with source rotation direction. No additional live motion modes, no UI changes, no assertion of physically circular perception. + +## 2026-11-13 — listener-approved Square Orbit checkpoint and musical late reverb M2 +The owner has listened to and approved the **square-room orbit as perceptually circular**. Its exact base code is pinned at `checkpoint/8d-sonku-square-orbit-approved-20261113` (`3a74b0273c7a7e13d5d2614183d19995eb12ad57`); this immutable evaluation milestone must not be overwritten by reverb experiments. There already are eight bounded 1st-order wall-reflection paths (four per source), but **there was no late reverb**. + +New *opt-in offline candidate*, original `SonKuMusicalReverb.h`: 8 noncommensurate delays with a normalized Hadamard orthogonal feedback matrix, per-line RT60 feedback gains prepared for 44.1/48k, damping low-pass in the loop, stereo decorrelated output, 12ms wet ramp, and at least 43ms to first late energy. Max delay ring 8×4096 floats (~128KiB) with no dynamic PCM buffer, FFT, allpass resonator cascade, or per-sample trigonometry/exp. Two listening-only presets: Studio Glue (RT60 ~0.78s; 5.9kHz damping) and Airy Chamber (RT60 ~1.28s; 7kHz). Wet amount .42 for controlled A/B is intentionally modest and **OFF in the native plugin**. Square early reflections remain exactly as approved, with no room-size or HRTF clock modification. Compare baseline square with Studio Glue and Airy Chamber 20s 2-turn WAVs, using same source, latency, level trim, azimuth and direct HRIR. C++ tests validate stable impulse energy, late onset, stereo width, RT60 decay, byte-exact disabled state and PCM partition parity. No GUI knob, session upgrade or public release until listener feedback and physical Windows audio qualification. FDN theory: Stautner/Puckette (1982), Jot/Chaigne (1991), and practical low-metallic density guidance from Valhalla DSP; original GPL-compatible implementation, no copied commercial source. diff --git a/tests/sonku_musical_reverb_test.cpp b/tests/sonku_musical_reverb_test.cpp new file mode 100644 index 000000000..3a099734a --- /dev/null +++ b/tests/sonku_musical_reverb_test.cpp @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/sonku/SonKuMusicalReverb.h" +#include +#include +#include +#include + +int main(){ + using armix::sonku::SonKuMusicalReverb; + using armix::sonku::SonKuReverbPreset; + SonKuMusicalReverb invalid; + assert(!invalid.prepare(96000.)); + assert(!invalid.prepare(std::numeric_limits::quiet_NaN())); + for(double rate:{44100.,48000.}){ + SonKuMusicalReverb fx,copy; + assert(fx.prepare(rate)&©.prepare(rate)); + assert(!fx.active()); + assert(!fx.setAmount(-.1f)); + assert(!fx.setAmount(std::numeric_limits::infinity())); + assert(!fx.setPreset(static_cast(99))); + assert(fx.setPreset(SonKuReverbPreset::StudioGlue)); + assert(copy.setPreset(SonKuReverbPreset::StudioGlue)); + assert(fx.setAmount(.40f)&©.setAmount(.40f)); + assert(!fx.setPreset(SonKuReverbPreset::AiryChamber)); + const int count=static_cast(rate*2.0); + double energy=0.,width=0.,early=0.,late=0.; + for(int i=0;i2000)energy+=magnitude; + if(i>2000&&irate*1.5)late+=magnitude; + } + assert(early==0.); // direct + early stays untouched + assert(energy>.005 && width>.002); // diffuse stereo field, not mono + assert(late(rate);++i){ + const auto output=fx.process(i==0?.4f:0.f,i==0?.4f:0.f); + airy+=std::abs(output.left)+std::abs(output.right); + } + assert(airy>.005); + } + return 0; +} diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index 1cfba47c2..42524b649 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -30,6 +30,8 @@ def read(name, frames): reverse=read("sonku-orbit-ccw-2x.wav",960000) reverseRoom=read("sonku-v2-room-orbit-ccw-2x.wav",960000) reverseSquare=read("sonku-v2-square-orbit-ccw-2x.wav",960000) +glue=read("sonku-v3-square-glue-cw-2x.wav",960000) +airy=read("sonku-v3-square-airy-cw-2x.wav",960000) # Baseline V1 and candidate V2 are deliberately non-identical on same noise. # Room must affect later samples, not fake position on the direct sound. difference=sum(abs(int(a)-int(b)) for a,b in @@ -45,6 +47,12 @@ def read(name, frames): reverseDelta=sum(abs(int(a)-int(b)) for a,b in zip(reverse[350000:500000],orbit[350000:500000])) assert reverseDelta>1500,("CW/CCW unexpectedly identical",reverseDelta) +for name,candidate in (("glue",glue),("airy",airy)): + fdnDelta=sum(abs(int(a)-int(b)) for a,b in + zip(candidate[400000:550000],squareOrbit[400000:550000])) + assert fdnDelta>1500,("FDN stage produced identical PCM",name,fdnDelta) +distinct=sum(abs(int(a)-int(b)) for a,b in zip(glue[400000:550000],airy[400000:550000])) +assert distinct>1500,("FDN Studio Glue and Airy Chamber matched exactly",distinct) # +90° (second reference segment) has a distinct binaural response. section=single[120000*2:120000*4] left=sum(abs(section[i]) for i in range(0,len(section),2)) @@ -54,7 +62,7 @@ def read(name, frames): assert sum(abs(x) for x in orbit[220000:230000])>1000 # Verify there is no mute, edit or source reset at the 10s handoff. # Stereo interleaved: 48000 samples = 1 second, 2 PCM ints per frame. -for audio in (orbit,v2orbit,squareOrbit,reverse,reverseRoom,reverseSquare): +for audio in (orbit,v2orbit,squareOrbit,reverse,reverseRoom,reverseSquare,glue,airy): for second in (9,10,11,19): begin=(second*48000+4000)*2 assert sum(abs(x) for x in audio[begin:begin+9600])>2000,( diff --git a/tests/sonku_spatial_core_test.cpp b/tests/sonku_spatial_core_test.cpp index d70ff4988..6324e8b84 100644 --- a/tests/sonku_spatial_core_test.cpp +++ b/tests/sonku_spatial_core_test.cpp @@ -110,6 +110,37 @@ int main() { std::abs(wetR[i]-noR[i]); } assert(roomDifference>.001); + // V3 late room is strictly opt-in, delayed and sample-partition + // deterministic. The approved direct-HRTF + square ER is untouched + // before the first late echo. + SonKuSpatialCore glow,glowChunks; + assert(glow.prepare(rate)&&glowChunks.prepare(rate)); + assert(glow.setEarlyReflectionsShape(SonKuRoomShape::Square)); + assert(glowChunks.setEarlyReflectionsShape(SonKuRoomShape::Square)); + assert(glow.setSettings(roomSettings)&&glowChunks.setSettings(roomSettings)); + assert(glow.setEarlyReflectionsAmount(.55f)&&glowChunks.setEarlyReflectionsAmount(.55f)); + assert(glow.setMusicalReverbAmount(.42f)&&glowChunks.setMusicalReverbAmount(.42f)); + std::array tailL{},tailR{},splitL{},splitR{}; + tailL[0]=splitL[0]=.5f;tailR[0]=splitR[0]=.5f; + glow.process(tailL.data(),tailR.data(),roomFrames); + glowChunks.process(splitL.data(),splitR.data(),128); + glowChunks.process(splitL.data()+128,splitR.data()+128,384); + glowChunks.process(splitL.data()+512,splitR.data()+512,roomFrames-512); + double diff=0.; + for(int i=0;i2200)diff+=std::abs(tailL[i]-wetL[i])+ + std::abs(tailR[i]-wetR[i]); + } + assert(diff>.001); // A hard FRONT->REAR teleport must not replace 560 FIR coefficients // at the next 16-sample boundary. Compare the identical dry/PCM // history before and immediately after reposition. diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 1d0126c19..12c511e32 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -104,12 +104,16 @@ std::vector staticProbes(const std::vector& azimuths,float ro } std::vector orbit(float roomAmount=0.f, armix::sonku::SonKuRoomShape shape=armix::sonku::SonKuRoomShape::Rectangular, - bool clockwise=true){ + bool clockwise=true,float lateAmount=0.f, + armix::sonku::SonKuReverbPreset latePreset= + armix::sonku::SonKuReverbPreset::StudioGlue){ SonKuSpatialCore dsp;Noise noise; if(!dsp.prepare(rate))throw std::runtime_error("No 48k HRTF"); if(!dsp.setEarlyReflectionsShape(shape)|| - !dsp.setEarlyReflectionsAmount(roomAmount)) - throw std::runtime_error("Invalid orbit room configuration"); + !dsp.setMusicalReverbPreset(latePreset)|| + !dsp.setEarlyReflectionsAmount(roomAmount)|| + !dsp.setMusicalReverbAmount(lateAmount)) + throw std::runtime_error("Invalid orbit acoustic configuration"); Settings s=fixed(0.f);s.moving=true;s.clockwise=clockwise;s.revolutionSeconds=10.f; dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("No 360 orbit"); const int frames=orbitFrames; // two complete turns on ONE continuous audio clock @@ -167,6 +171,13 @@ void notes(const std::filesystem::path& directory, <<"Square geometry is not a guarantee of circular perception.\n" <<"CCW versions contain FRONT>LEFT>REAR>RIGHT>FRONT each 10s.\n" <<"Compare direction-reversed tracks to isolate turn-order effects.\n" + <<"sonku-v3-square-glue-cw-2x.wav = approved square ROOM plus\n" + <<" subdued stereo 8-line FDN, Studio Glue RT60 ~0.78s.\n" + <<"sonku-v3-square-airy-cw-2x.wav = same square ROOM with\n" + <<" more spacious FDN Airy Chamber RT60 ~1.28s.\n" + <<"V2 square and V3 candidates share the exact 20s original source,\n" + <<"HRTF, four-wall ER, angle clock and output trim.\n" + <<"FDN candidate is wet-only and OFF in native plugin by default.\n" <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" <<"Do blind-level and externalization evaluation before enabling V2 live.\n" <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; @@ -202,6 +213,12 @@ int main(int argc,char** argv){ orbit(.55f,armix::sonku::SonKuRoomShape::Rectangular,false)); writeWav(dir/"sonku-v2-square-orbit-ccw-2x.wav", orbit(.55f,armix::sonku::SonKuRoomShape::Square,false)); + writeWav(dir/"sonku-v3-square-glue-cw-2x.wav", + orbit(.55f,armix::sonku::SonKuRoomShape::Square,true,.42f, + armix::sonku::SonKuReverbPreset::StudioGlue)); + writeWav(dir/"sonku-v3-square-airy-cw-2x.wav", + orbit(.55f,armix::sonku::SonKuRoomShape::Square,true,.42f, + armix::sonku::SonKuReverbPreset::AiryChamber)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n"; diff --git a/tools/sonku_rt_benchmark.cpp b/tools/sonku_rt_benchmark.cpp index 9b3a0f9fd..3336e5749 100644 --- a/tools/sonku_rt_benchmark.cpp +++ b/tools/sonku_rt_benchmark.cpp @@ -13,13 +13,14 @@ namespace { struct Result {double milliseconds=0.,checksum=0.,audios=0.;}; template -Result measure(double rate,float amount){ +Result measure(double rate,float amount,float late=0.f){ using namespace armix::sonku; SonKuSpatialCore dsp; if(!dsp.prepare(rate))throw std::runtime_error("unsupported sample rate"); Settings s{};s.moving=true;s.revolutionSeconds=10.f; s.spatialMix=1.f;s.stereoSpreadDegrees=60.f; - if(!dsp.setSettings(s)||!dsp.setEarlyReflectionsAmount(amount)) + if(!dsp.setSettings(s)||!dsp.setEarlyReflectionsAmount(amount)|| + !dsp.setMusicalReverbAmount(late)) throw std::runtime_error("invalid DSP setup"); std::array inputL{},inputR{}; for(std::size_t n=0;n void report(double rate){ const auto baseline=measure(rate,0.f); const auto room=measure(rate,.55f); + const auto musical=measure(rate,.55f,.42f); std::cout< Date: Fri, 13 Nov 2026 11:19:42 +0700 Subject: [PATCH 12/13] feat(sonku): original plucked-tone musical A/B on approved square orbit --- ...KU_V2_EXTERNALIZATION_DECISION_20261113.md | 3 + tests/sonku_offline_demo_contract.py | 10 +++ tools/sonku_offline_listening.cpp | 66 +++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md index d746285c0..d61993276 100644 --- a/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md +++ b/docs/SONKU_V2_EXTERNALIZATION_DECISION_20261113.md @@ -48,3 +48,6 @@ In response to asymmetrical perceived naturalness of RIGHT→FRONT vs FRONT→RI The owner has listened to and approved the **square-room orbit as perceptually circular**. Its exact base code is pinned at `checkpoint/8d-sonku-square-orbit-approved-20261113` (`3a74b0273c7a7e13d5d2614183d19995eb12ad57`); this immutable evaluation milestone must not be overwritten by reverb experiments. There already are eight bounded 1st-order wall-reflection paths (four per source), but **there was no late reverb**. New *opt-in offline candidate*, original `SonKuMusicalReverb.h`: 8 noncommensurate delays with a normalized Hadamard orthogonal feedback matrix, per-line RT60 feedback gains prepared for 44.1/48k, damping low-pass in the loop, stereo decorrelated output, 12ms wet ramp, and at least 43ms to first late energy. Max delay ring 8×4096 floats (~128KiB) with no dynamic PCM buffer, FFT, allpass resonator cascade, or per-sample trigonometry/exp. Two listening-only presets: Studio Glue (RT60 ~0.78s; 5.9kHz damping) and Airy Chamber (RT60 ~1.28s; 7kHz). Wet amount .42 for controlled A/B is intentionally modest and **OFF in the native plugin**. Square early reflections remain exactly as approved, with no room-size or HRTF clock modification. Compare baseline square with Studio Glue and Airy Chamber 20s 2-turn WAVs, using same source, latency, level trim, azimuth and direct HRIR. C++ tests validate stable impulse energy, late onset, stereo width, RT60 decay, byte-exact disabled state and PCM partition parity. No GUI knob, session upgrade or public release until listener feedback and physical Windows audio qualification. FDN theory: Stautner/Puckette (1982), Jot/Chaigne (1991), and practical low-metallic density guidance from Valhalla DSP; original GPL-compatible implementation, no copied commercial source. + +## 2026-11-13 — original musical-content A/B +Because broadband noise cannot reveal whether a late reverb is pleasing on music, the exact core offline renderer now also creates a deterministic 20-second synthetic plucked-tone motif, repeated identically once per 360° orbit, under the same Square ER. Three WAVs: baseline late OFF; Studio Glue RT60≈0.78s; Airy Chamber RT60≈1.28s. The melody is originally generated test material, with no copyrighted recordings. Envelope fades within each note to avoid spurious onset clicks. C++ and Python gates verify correct WAV format, PCM non-identity between presets and no clipping. This remains a **perceptual candidate**, not an assertion of musical quality. diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index 42524b649..dde0b43f6 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -32,6 +32,9 @@ def read(name, frames): reverseSquare=read("sonku-v2-square-orbit-ccw-2x.wav",960000) glue=read("sonku-v3-square-glue-cw-2x.wav",960000) airy=read("sonku-v3-square-airy-cw-2x.wav",960000) +musicBase=read("sonku-musical-square-base-2x.wav",960000) +musicGlue=read("sonku-musical-square-glue-2x.wav",960000) +musicAiry=read("sonku-musical-square-airy-2x.wav",960000) # Baseline V1 and candidate V2 are deliberately non-identical on same noise. # Room must affect later samples, not fake position on the direct sound. difference=sum(abs(int(a)-int(b)) for a,b in @@ -53,6 +56,13 @@ def read(name, frames): assert fdnDelta>1500,("FDN stage produced identical PCM",name,fdnDelta) distinct=sum(abs(int(a)-int(b)) for a,b in zip(glue[400000:550000],airy[400000:550000])) assert distinct>1500,("FDN Studio Glue and Airy Chamber matched exactly",distinct) +for name,variant in (("glue",musicGlue),("airy",musicAiry)): + delta=sum(abs(int(a)-int(b)) for a,b in + zip(variant[300000:540000],musicBase[300000:540000])) + assert delta>1000,("Musical FDN did not alter original tones",name,delta) +musicDistinct=sum(abs(int(a)-int(b)) for a,b in + zip(musicGlue[300000:540000],musicAiry[300000:540000])) +assert musicDistinct>1000,("Musical presets sound identical",musicDistinct) # +90° (second reference segment) has a distinct binaural response. section=single[120000*2:120000*4] left=sum(abs(section[i]) for i in range(0,len(section),2)) diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 12c511e32..548ceeb1b 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -138,6 +138,60 @@ std::vector orbit(float roomAmount=0.f, throw std::runtime_error("Two turns do not close acoustic orbit"); return result; } +// Original 20-second plucked-tone motif (20 half-second events, repeated on +// both revolutions). Synthesized here rather than using protected recordings. +// This deliberately exposes metallic late-tail coloration hidden by noise tests. +// It uses the EXACT same SonKuSpatialCore and accepted square early room. +std::vector musicalOrbit(float lateAmount, + armix::sonku::SonKuReverbPreset preset){ + SonKuSpatialCore dsp; + if(!dsp.prepare(rate)|| + !dsp.setEarlyReflectionsShape(armix::sonku::SonKuRoomShape::Square)|| + !dsp.setMusicalReverbPreset(preset)|| + !dsp.setEarlyReflectionsAmount(.55f)|| + !dsp.setMusicalReverbAmount(lateAmount)) + throw std::runtime_error("Invalid original musical test configuration"); + Settings s=fixed(0.f);s.moving=true;s.clockwise=true;s.revolutionSeconds=10.f; + dsp.reset();if(!dsp.setSettings(s))throw std::runtime_error("Invalid musical orbit"); + constexpr std::array notes{ + 57,64,60,69,62,65,69,60,64,67, + 71,67,65,72,69,64,60,67,64,62}; + std::array frequencies{}; + for(std::size_t i=0;i bytes; + bytes.reserve(static_cast(orbitFrames)*4); + for(int base=0;base l{},r{}; + for(int i=0;i(notes.size()); + const int position=at%noteFrames; + const float t=static_cast(position)/noteFrames; + const float attack=std::clamp(position/(rate*.009f),0.f,1.f); + const float release=std::clamp( + (noteFrames-1-position)/(rate*.030f),0.f,1.f); + const float envelope=attack*release*std::exp(-3.2f*t); + const double theta=2.*pi*frequencies[static_cast(note)]* + static_cast(position)/rate; + const float tonal=static_cast( + std::sin(theta)+.27*std::sin(2.*theta)+ + .31*std::sin(theta*1.5)); + const float sample=.115f*envelope*tonal; + l[static_cast(i)]=sample; + r[static_cast(i)]=sample; + } + dsp.process(l.data(),r.data(),n); + for(int i=0;i.01) + throw std::runtime_error("Musical double orbit did not close"); + return bytes; +} const char* direction(int deg) { switch(deg){case 0:return "FRONT";case 90:return "RIGHT";case 180:return "REAR"; case -90:return "LEFT";default:return "INVALID";} @@ -178,6 +232,12 @@ void notes(const std::filesystem::path& directory, <<"V2 square and V3 candidates share the exact 20s original source,\n" <<"HRTF, four-wall ER, angle clock and output trim.\n" <<"FDN candidate is wet-only and OFF in native plugin by default.\n" + <<"sonku-musical-square-base-2x.wav = original synthetic plucks,\n" + <<" approved square ER with NO late reverb.\n" + <<"sonku-musical-square-glue-2x.wav = identical plucks with Studio Glue.\n" + <<"sonku-musical-square-airy-2x.wav = identical plucks with Airy Chamber.\n" + <<"The plucks are ORIGINAL test tones (no copyrighted composition).\n" + <<"Use them to judge vocal-like reverb coloration/tail musicality.\n" <<"Both comparisons reuse exactly the same source noise and direct HRIR.\n" <<"Do blind-level and externalization evaluation before enabling V2 live.\n" <<"This is NOT full HRIR-convolved reflections, FDN or personalized HRTF.\n"; @@ -219,6 +279,12 @@ int main(int argc,char** argv){ writeWav(dir/"sonku-v3-square-airy-cw-2x.wav", orbit(.55f,armix::sonku::SonKuRoomShape::Square,true,.42f, armix::sonku::SonKuReverbPreset::AiryChamber)); + writeWav(dir/"sonku-musical-square-base-2x.wav", + musicalOrbit(0.f,armix::sonku::SonKuReverbPreset::StudioGlue)); + writeWav(dir/"sonku-musical-square-glue-2x.wav", + musicalOrbit(.42f,armix::sonku::SonKuReverbPreset::StudioGlue)); + writeWav(dir/"sonku-musical-square-airy-2x.wav", + musicalOrbit(.42f,armix::sonku::SonKuReverbPreset::AiryChamber)); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n"; From 63a85fbb010d6e5590ed7bfe1673eb5bed50af1f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 13 Nov 2026 12:54:00 +0700 Subject: [PATCH 13/13] test(sonku): compare late FDN against exact approved square PCM baseline --- tests/sonku_spatial_core_test.cpp | 41 ++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tests/sonku_spatial_core_test.cpp b/tests/sonku_spatial_core_test.cpp index 6324e8b84..12689ec53 100644 --- a/tests/sonku_spatial_core_test.cpp +++ b/tests/sonku_spatial_core_test.cpp @@ -4,6 +4,7 @@ #endif #include "../engine/builtin_fx/sonku/SonKuSpatialCore.h" #include +#include #include #include #include @@ -113,34 +114,46 @@ int main() { // V3 late room is strictly opt-in, delayed and sample-partition // deterministic. The approved direct-HRTF + square ER is untouched // before the first late echo. + // IMPORTANT: the accepted reference is SQUARE, not the earlier + // rectangular V2 room. A rectangle-vs-square comparison cannot + // establish that adding the FDN leaves the approved orbit intact. + // Allocate this extra test processor off-stack (each core owns + // fixed ~192 KiB acoustic rings; Windows test stacks are bounded). + auto approvedSquare=std::make_unique(); SonKuSpatialCore glow,glowChunks; - assert(glow.prepare(rate)&&glowChunks.prepare(rate)); + assert(approvedSquare->prepare(rate)&&glow.prepare(rate)&&glowChunks.prepare(rate)); + assert(approvedSquare->setEarlyReflectionsShape(SonKuRoomShape::Square)); assert(glow.setEarlyReflectionsShape(SonKuRoomShape::Square)); assert(glowChunks.setEarlyReflectionsShape(SonKuRoomShape::Square)); - assert(glow.setSettings(roomSettings)&&glowChunks.setSettings(roomSettings)); - assert(glow.setEarlyReflectionsAmount(.55f)&&glowChunks.setEarlyReflectionsAmount(.55f)); + assert(approvedSquare->setSettings(roomSettings)&& + glow.setSettings(roomSettings)&&glowChunks.setSettings(roomSettings)); + assert(approvedSquare->setEarlyReflectionsAmount(.55f)&& + glow.setEarlyReflectionsAmount(.55f)&& + glowChunks.setEarlyReflectionsAmount(.55f)); assert(glow.setMusicalReverbAmount(.42f)&&glowChunks.setMusicalReverbAmount(.42f)); - std::array tailL{},tailR{},splitL{},splitR{}; - tailL[0]=splitL[0]=.5f;tailR[0]=splitR[0]=.5f; + std::array squareL{},squareR{},tailL{},tailR{},splitL{},splitR{}; + squareL[0]=squareR[0]=tailL[0]=tailR[0]=splitL[0]=splitR[0]=.5f; + approvedSquare->process(squareL.data(),squareR.data(),roomFrames); glow.process(tailL.data(),tailR.data(),roomFrames); glowChunks.process(splitL.data(),splitR.data(),128); glowChunks.process(splitL.data()+128,splitR.data()+128,384); glowChunks.process(splitL.data()+512,splitR.data()+512,roomFrames-512); - double diff=0.; + double lateDifference=0.; for(int i=0;i43 ms at both qualified rates. + // This proves exact sample identity in the approved square + // direct+ER path before late ambience arrives. + if(i<1800){ + assert(tailL[i]==squareL[i]); + assert(tailR[i]==squareR[i]); } - if(i>2200)diff+=std::abs(tailL[i]-wetL[i])+ - std::abs(tailR[i]-wetR[i]); + if(i>2200)lateDifference+=std::abs(tailL[i]-squareL[i])+ + std::abs(tailR[i]-squareR[i]); } - assert(diff>.001); + assert(lateDifference>.001); // A hard FRONT->REAR teleport must not replace 560 FIR coefficients // at the next 16-sample boundary. Compare the identical dry/PCM // history before and immediately after reposition.