diff --git a/docs/SONKU_M4_NATIVE_SPACE_RELEASE_CANDIDATE_20261113.md b/docs/SONKU_M4_NATIVE_SPACE_RELEASE_CANDIDATE_20261113.md new file mode 100644 index 000000000..30812dd94 --- /dev/null +++ b/docs/SONKU_M4_NATIVE_SPACE_RELEASE_CANDIDATE_20261113.md @@ -0,0 +1,71 @@ +# SonKu M4 — Native SPACE / musical ambience release candidate +2026-11-13 | Draft stacked on #643 → #629 → #606 | NOT public release + +## Why this is a vertical product slice +Operator opens **8D-SonKu** from the real FX rack and selects OFF / SQUARE / +CHAMBER / LARGE. Two small sliders control source distance and musical +AMBIENCE. A single `nativeSonKuSet` message flows through the existing +device-epoch, graph-revision, exact ChannelId, instance lease, native queue, +JUCE processing callback and completion. The GUI only displays APPLIED after +matching callback ACK and accepted DSP readback. No WebAudio, browser PCM, +fake owner or duplicated audio callback. + +Room map: +- OFF: original direct KEMAR HRIR; no ER or late FDN work, v1-compatible. +- SQUARE: 7.2 × 7.2 m, max radius 3.1 m, short Studio Glue decay ~0.78 s. +- CHAMBER: 14.4 × 14.4 m, max radius 6.7 m, Airy decay ~1.28 s. +- LARGE: 28.8 × 28.8 m, max radius 10 m, restrained decay ~2.05 s. +RoomAmount is fixed to the previously tested 0.55 when user first enables +a scene. For each scene, the direct path uses 1.6 / sourceDistance pressure, +the eight first-order wall paths use 1.6 / reflectedPath pressure, and the +diffuse tail is wet-only. The exact approved HRIR azimuth and orbit geometry +are unchanged. + +## Realtime invariants +- All 8× per-line FDN feedback gains and damping coefficients for these + presets are computed on `prepare()` and selected without exp(), new/delete, + locks, device restart, or blocking calls in the callback. +- Coefficients and wet levels slew on the sample clock; existing ER fractional + delays and gains slew too, with geometry recalculated only every 64 samples. +- Reenable after disabled room uses a validity horizon on the existing fixed + 8192-sample ER rings; reenable on FDN uses a horizon on the existing 4096- + frame rings. No ~64/128 KiB buffer clears in a live edit. +- FX graph owns bypass/retire/reorder/routing; SonKu never installs its own + audio device or hidden monitoring gate. +- Multiple instances have independent fixed memory; no static mutable DSP. + +## Persistence and backward compatibility +`SonKuSpatialProcessor` serializes SONK version 2, exactly 46 bytes with +old 30-byte v1 restore supported. New state carries `spacePreset`, +`sourceDistanceMeters`, `roomAmount`, `ambience`. Legacy v1 restores as +room OFF; malformed v2 is rejected atomically; the last accepted edit is +only persisted after audio-applied completion. Accepted snapshot schema=2 +returns exactly the stored state. Existing GUI transport v1 fields may omit +new controls and default OFF. + +## What still blocks public release +1. CI: source contract, native no-JUCE PCM, Chromium actual WebView2-assembled + controls, exact-SHA Windows MSVC/CTest, multi-instance restore and restart. +2. Confirm no clicks/glitches on OFF→LARGE→SQUARE, rapid slider changes, rack + bypass, graph remove, save/open .smix, device swap, and stereo-only policy. +3. Human headphone A/B: compare approved Square reference, Studio Glue, Airy + and M4 scene presets with music + voice (front/rear distance, flutter, + metallic coloration, decay masking); adjust only after evidence. +4. Reconcile parent #606 (latest main) → #629 → #643 → this M4 without + dropping independent WIRE, GUI, updater and FX progress. Do not promote + public release based on Linux offline/Chromium mocks alone. + +## Explicit physical limits +2D first-order 4-wall image model; no height/floor/ceiling, personalized +HRTF, frequency-calibrated air absorption, true measured BRIR, later +higher-order bounces or physically fitted RT60. LARGE is a musical scene +preset, not a certified geometry-based hall reverb. Accurate propagation +delay of the direct path is not modeled, for low latency. + +## References (concepts only) +- Allen–Berkley image-source method: JASA 65(4), 1979, DOI 10.1121/1.382599 +- Valve Steam Audio core guide: direct distance and room reflections are + separate stages; no vendor code copied. + https://github.com/ValveSoftware/steam-audio/blob/master/core/doc/guide.rst +- JUCE AudioProcessor: processBlock realtime cautions and bypass semantics. + https://docs.juce.com/master/classjuce_1_1AudioProcessor.html diff --git a/engine/builtin_fx/SonKuSpatialProcessor.h b/engine/builtin_fx/SonKuSpatialProcessor.h index d0f9ed31b..2412d6c87 100644 --- a/engine/builtin_fx/SonKuSpatialProcessor.h +++ b/engine/builtin_fx/SonKuSpatialProcessor.h @@ -23,7 +23,9 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, bool acceptsMidi() const override {return false;} bool producesMidi() const override {return false;} bool isMidiEffect() const override {return false;} - double getTailLengthSeconds() const override {return 0.;} + // Conservative bounded tail for the longest enabled room program. OFF + // still performs no FDN work; this reports potential host tail ownership. + double getTailLengthSeconds() const override {return 2.6;} int getNumPrograms() override {return 1;} int getCurrentProgram() override {return 0;} void setCurrentProgram(int) override {} @@ -80,7 +82,7 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, void getStateInformation(juce::MemoryBlock& dest) override { juce::MemoryOutputStream out(dest,false); out.writeInt(0x534F4E4B); // SONK - out.writeInt(1); + out.writeInt(2); out.writeFloat(accepted_.startAzimuthDegrees); out.writeFloat(accepted_.revolutionSeconds); out.writeFloat(accepted_.stereoSpreadDegrees); @@ -88,11 +90,19 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, out.writeFloat(accepted_.outputTrim); out.writeByte(accepted_.moving?1:0); out.writeByte(accepted_.clockwise?1:0); + out.writeInt(accepted_.spacePreset); + out.writeFloat(accepted_.sourceDistanceMeters); + out.writeFloat(accepted_.roomAmount); + out.writeFloat(accepted_.ambience); } bool restoreUnpublishedState(const void* data,int size) { - if(published_||!data||size!=30||!queue_.empty()||!complete_.empty())return false; + if(published_||!data||(size!=30&&size!=46)|| + !queue_.empty()||!complete_.empty())return false; juce::MemoryInputStream in(data,static_cast(size),false); - if(in.readInt()!=0x534F4E4B||in.readInt()!=1)return false; + if(in.readInt()!=0x534F4E4B)return false; + const int version=in.readInt(); + if((version!=1&&version!=2)|| + (version==1&&size!=30)||(version==2&&size!=46))return false; armix::sonku::Settings next{}; next.startAzimuthDegrees=in.readFloat(); next.revolutionSeconds=in.readFloat(); @@ -100,9 +110,18 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, next.spatialMix=in.readFloat(); next.outputTrim=in.readFloat(); const int moving=in.readByte(),clockwise=in.readByte(); - if(moving>1||clockwise>1||!in.isExhausted())return false; + if(moving>1||clockwise>1)return false; next.moving=moving!=0; next.clockwise=clockwise!=0; + if(version==2) { + next.spacePreset=in.readInt(); + next.sourceDistanceMeters=in.readFloat(); + next.roomAmount=in.readFloat(); + next.ambience=in.readFloat(); + } + // Old v1 .smix restores to HRTF-only. New v2 carries the acoustic + // scene, but never allows malformed/partial state into live PCM. + if(!in.isExhausted())return false; if(!armix::sonku::valid(next))return false; if(ready_&&!core_.setSettings(next))return false; accepted_=next; diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 25c40be4f..92aeebf05 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -42,7 +42,7 @@ class SonKuEarlyReflections final { 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; + write_=0;untilGeometry_=0;primed_=false;validFrames_=0; amount_=0.f; } // Deliberately experimental and OFF by default. Legacy 8/8 direction @@ -90,6 +90,26 @@ class SonKuEarlyReflections final { primed_=false; return true; } + // Caller validates geometry on CONTROL side before queuing the POD edit. + // Audio-side update only changes targets for existing 64-frame image + // geometry updates; old path taps smoothly move, never clear big rings. + bool setRealtimeRoom(const SonKuRoomGeometry& g,float amount, + bool enabled) noexcept { + if(!std::isfinite(amount)||amount<0.f||amount>1.f)return false; + if(enabled && !validGeometry(g))return false; + if(!active() && enabled && amount>0.f){ + validFrames_=0; lowpass_.fill(0.f); + } + if(enabled){ + geometry_=g;custom_=true;shape_=SonKuRoomShape::Square; + }else{ + custom_=false;shape_=SonKuRoomShape::Square; + } + realtimeMode_=true; + amountTarget_=enabled?amount:0.f; + untilGeometry_=0; + return true; + } float relativeDistanceGain() const noexcept { return custom_?1.6f/geometry_.distanceMeters:1.f; } @@ -127,6 +147,7 @@ class SonKuEarlyReflections final { } } write_=(write_+1)&(ringFrames-1); + if(realtimeMode_&&validFrames_(ringFrames-3)); const int integer=static_cast(bounded); + // Avoid re-reading a stale tail after the user disabled and later + // re-enabled the ROOM. Entire 64 KiB ring never needs RT clearing. + if(realtimeMode_&&validFrames_<=integer+1)return 0.f; const float fract=bounded-static_cast(integer); const int i0=(write_-integer)&(ringFrames-1); const int i1=(i0-1)&(ringFrames-1); @@ -210,7 +234,8 @@ class SonKuEarlyReflections final { 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; + int write_=0,untilGeometry_=0,validFrames_=0; + bool realtimeMode_=false; SonKuRoomShape shape_=SonKuRoomShape::Rectangular; SonKuRoomGeometry geometry_{}; bool custom_=false,ready_=false,primed_=false; diff --git a/engine/builtin_fx/sonku/SonKuMusicalReverb.h b/engine/builtin_fx/sonku/SonKuMusicalReverb.h index f9775aad6..ab76c230e 100644 --- a/engine/builtin_fx/sonku/SonKuMusicalReverb.h +++ b/engine/builtin_fx/sonku/SonKuMusicalReverb.h @@ -12,7 +12,7 @@ // 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 }; +enum class SonKuReverbPreset : std::uint8_t { StudioGlue=0, AiryChamber=1, LargeRoom=2 }; class SonKuMusicalReverb final { public: @@ -28,6 +28,12 @@ class SonKuMusicalReverb final { amountTarget_=0.f; preset_=SonKuReverbPreset::StudioGlue; configure(); + // All room-aware coefficients prepared once OFF the PCM callback. + prepared_[0]=makeCoefficients(.78f,5900.f); + prepared_[1]=makeCoefficients(1.28f,7000.f); + prepared_[2]=makeCoefficients(2.05f,6000.f); + targetGain_=gain_;targetDamp_=dampCoeff_; + realtimeMode_=false; reset(); ready_=true; return true; @@ -35,7 +41,7 @@ class SonKuMusicalReverb final { void reset() noexcept { for(auto& line:memory_)line.fill(0.f); lowpass_.fill(0.f); - write_=0;amount_=0.f; + write_=0;amount_=0.f;validFrames_=0; // The target amount is a CONTROL-side setting and survives resetting // host transport/processor so the same program can restart cleanly. } @@ -55,6 +61,24 @@ class SonKuMusicalReverb final { configure(); return true; } + // Realtime-safe preset/wet update: only POD/table copies, no exponentials, + // heap, locks or clearing 128 KiB of delay memory in the audio callback. + // A validity horizon ensures no stale tail from a previous OFF period. + bool setRealtimeProgram(SonKuReverbPreset preset,float amount) noexcept { + if((preset!=SonKuReverbPreset::StudioGlue && + preset!=SonKuReverbPreset::AiryChamber && + preset!=SonKuReverbPreset::LargeRoom)|| + !std::isfinite(amount)||amount<0.f||amount>1.f)return false; + if(!active() && amount>0.f){validFrames_=0;lowpass_.fill(0.f);} + const auto& coefficients=prepared_[static_cast(preset)]; + targetGain_=coefficients.gains; + targetDamp_=coefficients.damping; + if(!realtimeMode_){gain_=targetGain_;dampCoeff_=targetDamp_;} + realtimeMode_=true; + preset_=preset; + amountTarget_=amount; + 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_;} @@ -65,10 +89,13 @@ class SonKuMusicalReverb final { const float mid=.5f*(a+b); const float side=.5f*(a-b); std::array y{},mix{}; + if(realtimeMode_)dampCoeff_+=slew_*(targetDamp_-dampCoeff_); for(int i=0;i gains{}; + float damping=0.f; + }; + Coefficients makeCoefficients(float rt60,float cutoff) const noexcept { + Coefficients prepared{}; + constexpr float pi=3.14159265358979323846f; + prepared.damping=1.f-std::exp(-2.f*pi*cutoff/sampleRate_); + for(int i=0;i(delay_[i])/(sampleRate_*rt60)); + return prepared; + } void configure() noexcept { // Incommensurate lengths at 48k, scaled once at prepare/control side. // First late energy arrives ~44 ms: behind earliest image reflections. @@ -123,11 +164,13 @@ class SonKuMusicalReverb final { static_assert((ringFrames&(ringFrames-1))==0); std::array,lineCount> memory_{}; std::array lowpass_{}; - std::array gain_{}; + std::array gain_{},targetGain_{}; + std::array prepared_{}; std::array delay_{}; - float sampleRate_=48000.f,dampCoeff_=0.f,slew_=0.f; + float sampleRate_=48000.f,dampCoeff_=0.f,targetDamp_=0.f,slew_=0.f; float amount_=0.f,amountTarget_=0.f; - int write_=0; + int write_=0,validFrames_=0; + bool realtimeMode_=false; SonKuReverbPreset preset_=SonKuReverbPreset::StudioGlue; bool ready_=false; }; diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 6f0073ac0..27d3226d8 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -21,6 +21,15 @@ struct Settings { float outputTrim = 0.75f; // avoid summing two uncorrelated emitters at unity bool moving = true; bool clockwise = true; + // Version-2 persisted, native-ACKed acoustic scene. Zero is legacy + // HRTF-only. All other scenes are optional and OFF unless selected. + int spacePreset = 0; // 0=OFF, 1=Square 7.2, 2=Chamber 14.4, 3=Large 28.8 + float sourceDistanceMeters = 1.6f; + // Stored while OFF so the first selected scene is immediately audible + // and turning ROOM off/on remembers the previous wet preference. + // spacePreset=0 still guarantees identical legacy HRTF-only PCM. + float roomAmount = .55f; + float ambience = .30f; }; inline bool valid(const Settings& s) noexcept { return std::isfinite(s.startAzimuthDegrees) && @@ -30,7 +39,16 @@ inline bool valid(const Settings& s) noexcept { std::isfinite(s.stereoSpreadDegrees) && s.stereoSpreadDegrees>=0.f && s.stereoSpreadDegrees<=180.f && std::isfinite(s.spatialMix) && s.spatialMix>=0.f && s.spatialMix<=1.f && - std::isfinite(s.outputTrim) && s.outputTrim>=0.f && s.outputTrim<=1.f; + std::isfinite(s.outputTrim) && s.outputTrim>=0.f && s.outputTrim<=1.f && + s.spacePreset>=0 && s.spacePreset<=3 && + std::isfinite(s.sourceDistanceMeters) && s.sourceDistanceMeters>=1.6f && + s.sourceDistanceMeters<=10.f && + std::isfinite(s.roomAmount) && s.roomAmount>=0.f && s.roomAmount<=1.f && + std::isfinite(s.ambience) && s.ambience>=0.f && s.ambience<=1.f && + (s.spacePreset==0 || SonKuEarlyReflections::validGeometry({ + s.spacePreset==1?7.2f:s.spacePreset==2?14.4f:28.8f, + s.spacePreset==1?7.2f:s.spacePreset==2?14.4f:28.8f, + s.sourceDistanceMeters})); } inline double wrapDegrees(double degrees) noexcept { degrees=std::fmod(degrees,360.0); @@ -53,7 +71,10 @@ class SonKuSpatialCore final { if(!room_.prepare(rate)||!reverb_.prepare(rate))return false; reset(); ready_=true; - return true; + // Re-publish a saved active scene after device restart, but do NOT + // select the new realtime FDN program for the legacy/offline default: + // original Studio Glue / Airy Chamber listening renders remain exact. + return settings_.spacePreset==0 || applyAcousticSettings(settings_); } void reset() noexcept { for(auto& channel:history_)channel.fill(0.f); @@ -75,6 +96,11 @@ class SonKuSpatialCore final { if(!s.moving || !settings_.moving || s.startAzimuthDegrees!=settings_.startAzimuthDegrees) degrees_=wrapDegrees(s.startAzimuthDegrees); + const bool changed=s.spacePreset!=settings_.spacePreset || + s.sourceDistanceMeters!=settings_.sourceDistanceMeters || + s.roomAmount!=settings_.roomAmount || + s.ambience!=settings_.ambience; + if(changed && !applyAcousticSettings(s))return false; settings_=s; remaining_=0; return true; @@ -178,6 +204,18 @@ class SonKuSpatialCore final { } } private: + bool applyAcousticSettings(const Settings& s) noexcept { + const float width=s.spacePreset==1?7.2f: + s.spacePreset==2?14.4f:28.8f; + const SonKuRoomGeometry geometry{ + width,width,s.spacePreset? s.sourceDistanceMeters:1.6f}; + const auto preset=s.spacePreset==3?SonKuReverbPreset::LargeRoom: + s.spacePreset==2?SonKuReverbPreset::AiryChamber: + SonKuReverbPreset::StudioGlue; + return room_.setRealtimeRoom(geometry,s.roomAmount,s.spacePreset!=0) && + reverb_.setRealtimeProgram(preset, + s.spacePreset!=0?s.ambience:0.f); + } // Positive azimuth is right. MIT KEMAR supplied azimuth 0..180 with // symmetric opposite-ear swapping for left hemisphere, not yaw-panning. void interpolate(std::size_t source,double azimuth) noexcept { diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index 999f30358..58dff3d82 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -1346,3 +1346,31 @@ .mx-sonku .sk-rotary{padding:3px 0!important} .mx-sonku .sk-guide{font-size:9px} } + +/* SonKu M4 native SPACE controls — same existing FX-rack CSS owner. + Small instrument-row treatment, not another card or a 19th CSS bundle. */ +.mx-sonku .sk-space-panel{display:grid;gap:7px;padding:9px 8px 8px; + border-top:1px solid #446171;border-bottom:1px solid #203a4a; + background:rgba(5,20,30,.27);border-radius:6px} +.mx-sonku .sk-space-head{display:flex;align-items:center;justify-content:space-between; + font-size:9px;letter-spacing:.85px;color:#afcfdd;font-weight:550} +.mx-sonku .sk-space-head output{color:#8ed3e0;font-size:9px;letter-spacing:.2px; + font-variant-numeric:tabular-nums} +.mx-sonku .sk-space-options{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:4px} +.mx-sonku .sk-space-options button{min-width:0;min-height:26px;padding:4px 2px; + border:1px solid #45616c;border-radius:4px;background:#1d3543; + font-size:8px;letter-spacing:.2px;font-weight:500;color:#bad2dc} +.mx-sonku .sk-space-options button[aria-pressed="true"]{color:#e8fbff; + border-color:#6fc6d7;background:#24556a;box-shadow:inset 0 1px #ffffff19} +.mx-sonku .sk-space-options button:focus-visible{outline:2px solid #9bdae8;outline-offset:1px} +.mx-sonku .sk-controls .sk-space-slider{display:grid!important; + grid-template-columns:1fr auto;gap:3px!important;align-items:center; + font-size:9px;letter-spacing:.4px;color:#a6c5d1;margin:0} +.mx-sonku .sk-controls .sk-space-slider output{font-size:9px; + color:#daf2f7;font-variant-numeric:tabular-nums} +.mx-sonku .sk-controls .sk-space-slider input{grid-column:1/-1; + width:100%;height:13px;margin:0!important;accent-color:#67c4d7} +.mx-sonku .sk-space-slider input:disabled{opacity:.32;cursor:not-allowed} +.mx-sonku .sk-space-hint{font-size:8px;line-height:1.35;color:#87aebb} +@media(max-width:550px){.mx-sonku .sk-space-panel{gap:6px;padding:8px} + .mx-sonku .sk-space-options button{min-height:29px;font-size:9px}} diff --git a/site/preview-v2/assets/mixer-native-sonku.js b/site/preview-v2/assets/mixer-native-sonku.js index e5f4508a8..dd4ea9291 100644 --- a/site/preview-v2/assets/mixer-native-sonku.js +++ b/site/preview-v2/assets/mixer-native-sonku.js @@ -4,14 +4,22 @@ "use strict"; const ID="armix.builtin.8d-sonku.v1"; const defaults=()=>({startAzimuthDegrees:0,revolutionSeconds:12, - stereoSpreadDegrees:60,spatialMix:1,outputTrim:.75,moving:true,clockwise:true}); + stereoSpreadDegrees:60,spatialMix:1,outputTrim:.75,moving:true,clockwise:true, + spacePreset:0,sourceDistanceMeters:1.6,roomAmount:.55,ambience:.30}); +const normalizeSettings=s=>({...defaults(),...s}); +const roomMaxDistance=[10,3.1,6.7,10]; const valid=s=>s && Number.isFinite(s.startAzimuthDegrees) && Math.abs(s.startAzimuthDegrees)<=360 && Number.isFinite(s.revolutionSeconds)&&s.revolutionSeconds>=.5&&s.revolutionSeconds<=120 && Number.isFinite(s.stereoSpreadDegrees)&&s.stereoSpreadDegrees>=0&&s.stereoSpreadDegrees<=180 && Number.isFinite(s.spatialMix)&&s.spatialMix>=0&&s.spatialMix<=1 && Number.isFinite(s.outputTrim)&&s.outputTrim>=0&&s.outputTrim<=1 && - typeof s.moving==="boolean"&&typeof s.clockwise==="boolean"; + typeof s.moving==="boolean"&&typeof s.clockwise==="boolean" && + Number.isInteger(s.spacePreset) && s.spacePreset>=0 && s.spacePreset<=3 && + Number.isFinite(s.sourceDistanceMeters) && s.sourceDistanceMeters>=1.6 && + s.sourceDistanceMeters<=roomMaxDistance[s.spacePreset]+.0001 && + Number.isFinite(s.roomAmount) && s.roomAmount>=0 && s.roomAmount<=1 && + Number.isFinite(s.ambience) && s.ambience>=0 && s.ambience<=1; const backend=()=>window.__JUCE__?.backend; const native=()=>typeof backend()?.emitEvent==="function"; const snapshot=()=>window.__ARMIX_NATIVE_M2__?.fxEditorState?.()|| @@ -104,7 +112,19 @@ root.innerHTML=[ '', '', '', - '
Drag the two monitors on the orbit · knobs: vertical drag, double-click to reset
', + '
', + '
SPACEDIRECT ONLY
', + '
', + '', + '', + '', + '
', + '', + '', + '
Reflections + musical room tail · OFF keeps original HRTF
', + '
Drag monitors to position · rotary knobs: vertical drag, double-click to reset
', '', '
VISUAL PREVIEWNo browser audio
' ].join(""); @@ -142,6 +162,21 @@ function render(){ dial.style.setProperty("--sk-sweep",(p*270).toFixed(2)+"deg"); dial.style.setProperty("--sk-needle",(-135+p*270).toFixed(2)+"deg"); } + // ROOM is one typed native scene, never a browser audio simulator. + root.querySelectorAll("[data-sk-room]").forEach(el=>{ + el.setAttribute("aria-pressed", + String(Number(el.dataset.skRoom)===s.spacePreset)); + }); + const sizeLabels=["DIRECT ONLY","7.2 × 7.2 m","14.4 × 14.4 m","28.8 × 28.8 m"]; + $("skSpaceText").textContent=sizeLabels[s.spacePreset]; + const distance=$("skDistance"),max=roomMaxDistance[s.spacePreset]; + distance.max=String(max); + distance.disabled=s.spacePreset===0; + distance.value=String(Math.min(max,s.sourceDistanceMeters)); + $("skDistanceValue").textContent=s.sourceDistanceMeters.toFixed(1)+" m"; + $("skAmbience").value=String(Math.round(s.ambience*100)); + $("skAmbience").disabled=s.spacePreset===0; + $("skAmbienceValue").textContent=Math.round(s.ambience*100)+"%"; const liveMotion=s.moving&¤t&&!pending?observed: s.startAzimuthDegrees; const phase=native()&&s.moving&¤t&&!pending&&observedAt? @@ -208,16 +243,17 @@ backend()?.addEventListener?.("arMixBuiltinSonKuSnapshot",r=>{ if(r?.requestId!==readId||!current)return; const c=context();if(!c||r.status!=="ACCEPTED"|| r.channelId!==c.channelId||r.instanceId!==c.instanceId)return; - if(!valid(r.settings))return; + const incoming=normalizeSettings(r.settings); + if(!valid(incoming))return; readId="";readSentAt=0; if(pending) { if(!pending.ack || r.appliedRequestId!==pending.requestId){ if(pending.ack)requestSnapshot(); return; } - accepted={...r.settings};pending=null;hint("DSP APPLIED · ACCEPTED");flushLatest(); + accepted={...incoming};pending=null;hint("DSP APPLIED · ACCEPTED");flushLatest(); }else if(!drag&&!dialDrag){ - accepted={...r.settings};draft={...r.settings}; + accepted={...incoming};draft={...incoming}; } if(Number.isFinite(r.observedAzimuthDegrees)){ observed=r.observedAzimuthDegrees;observedAt=performance.now(); @@ -229,6 +265,27 @@ $("skClose").addEventListener("click",()=>{root.hidden=true;current=null; if(clock!==null){clearInterval(clock);clock=null;}}); $("skMotion").addEventListener("click",()=>send({...draft,moving:!draft.moving})); $("skDirection").addEventListener("click",()=>send({...draft,clockwise:!draft.clockwise})); +root.querySelectorAll("[data-sk-room]").forEach(btn=>btn.addEventListener("click",()=>{ + const preset=Number(btn.dataset.skRoom),max=roomMaxDistance[preset]; + send({...draft,spacePreset:preset, + sourceDistanceMeters:preset===0?draft.sourceDistanceMeters: + Math.min(draft.sourceDistanceMeters,max)}); +})); +for(const [id,key,convert] of [ + ["skDistance","sourceDistanceMeters",v=>v], + ["skAmbience","ambience",v=>v/100]]) { + const slider=$(id); + slider.addEventListener("input",()=>{ + if(slider.disabled)return; + const value=Number(slider.value); + if(!Number.isFinite(value))return; + draft={...draft,[key]:convert(value)};render(); + }); + slider.addEventListener("change",()=>{ + if(slider.disabled)return; + send({...draft,[key]:convert(Number(slider.value))}); + }); +} for(const [id,key,convert] of [ ["skSpeed","revolutionSeconds",v=>v], ["skSpread","stereoSpreadDegrees",v=>v], diff --git a/src/Main.cpp b/src/Main.cpp index 593a5dc3b..c5503e135 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2965,7 +2965,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr reply->setProperty("deviceEpoch",epoch); reply->setProperty("graphRevision",revision); reply->setProperty("instanceId",instanceId); - reply->setProperty("schemaVersion",1); + reply->setProperty("schemaVersion",2); reply->setProperty("status",processor?"ACCEPTED":"REJECTED"); if(processor) { const auto s=processor->acceptedSettings(); @@ -2977,6 +2977,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr values->setProperty("outputTrim",s.outputTrim); values->setProperty("moving",s.moving); values->setProperty("clockwise",s.clockwise); + values->setProperty("spacePreset",s.spacePreset); + values->setProperty("sourceDistanceMeters",s.sourceDistanceMeters); + values->setProperty("roomAmount",s.roomAmount); + values->setProperty("ambience",s.ambience); reply->setProperty("settings",juce::var(values.release())); reply->setProperty("observedAzimuthDegrees", processor->observedAzimuthDegrees()); @@ -4605,9 +4609,25 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr moving.isBool()&&clockwise.isBool(); if(parameters){settings.moving=static_cast(moving); settings.clockwise=static_cast(clockwise);} + // Optional v2 fields preserve legacy v1 clients and old sessions. + // Typed native intent remains bounded and validated before SPSC. + const auto preset=values.getProperty("spacePreset",{}); + bool acousticParameters=true; + if(!preset.isVoid()){ + if(!preset.isInt())acousticParameters=false; + else settings.spacePreset=static_cast(preset); + } + const auto optionalNumber=[&](const char* key,float& target) { + if(values.getProperty(key,{}).isVoid())return true; + return number(key,target); + }; + acousticParameters=acousticParameters && + optionalNumber("sourceDistanceMeters",settings.sourceDistanceMeters) && + optionalNumber("roomAmount",settings.roomAmount) && + optionalNumber("ambience",settings.ambience); const auto numeric=fxRequest.sequence("sonku-"); bool queued=false; - if(p&&numeric&¶meters&&armix::sonku::valid(settings) && + if(p&&numeric&¶meters&&acousticParameters&&armix::sonku::valid(settings) && !pendingNativeSonKu_.owner&&!nativeShowBusy_&&!studioBackupBusy_&& !engine_.independentClockActive()) { queued=p->queueSettings(settings,numeric); diff --git a/tests/approved_native_sonku_smoke.py b/tests/approved_native_sonku_smoke.py index c70c0592e..3e9c19519 100644 --- a/tests/approved_native_sonku_smoke.py +++ b/tests/approved_native_sonku_smoke.py @@ -21,6 +21,10 @@ "outputTrim":0.75, "moving":True, "clockwise":True, + "spacePreset":0, + "sourceDistanceMeters":1.6, + "roomAmount":0.55, + "ambience":0.30, } def last_action(page,name): @@ -32,7 +36,7 @@ def last_action(page,name): def accepted_snapshot(page,state,settings,applied=None): read=last_action(page,"nativeSonKuSnapshot") payload={ - "requestId":read["requestId"],"status":"ACCEPTED","schemaVersion":1, + "requestId":read["requestId"],"status":"ACCEPTED","schemaVersion":2, "channelId":SOURCE,"slot":0,"instanceId":INSTANCE, "deviceEpoch":state["device"]["epoch"], "graphRevision":state["graph"]["revision"], @@ -229,6 +233,58 @@ def screen(x,y): "stereoSpreadDegrees":0.0,"startAzimuthDegrees":0.0, "revolutionSeconds":dialAction["settings"]["revolutionSeconds"]}, applied=dialAction["requestId"]) + # M4: native SPACE must be an actual typed ACK/readback edit. + # No browser-only audio, no visual success before PCM applied. + assert editor.locator(".sk-space-options button").count()==4 + assert editor.locator("#skDistance").is_disabled() + assert editor.locator("#skAmbience").is_disabled() + editor.locator('[data-sk-room="2"]').click() + scene=last_action(page,"nativeSonKuSet") + assert scene["settings"]["spacePreset"]==2,scene + assert scene["settings"]["sourceDistanceMeters"]==1.6,scene + assert scene["settings"]["roomAmount"]==0.55,scene + assert scene["settings"]["ambience"]==0.30,scene + assert "ACCEPTED" not in editor.locator("#skHint").inner_text() + emit(page,"arMixBuiltinSonKuAck",{ + "requestId":scene["requestId"],"status":"APPLIED"}) + sceneState={**SETTINGS,"moving":False,"startAzimuthDegrees":0.0, + "stereoSpreadDegrees":0.0, + "revolutionSeconds":dialAction["settings"]["revolutionSeconds"], + "spacePreset":2} + accepted_snapshot(page,state,sceneState,applied=scene["requestId"]) + assert editor.locator('[data-sk-room="2"]').get_attribute("aria-pressed")=="true" + assert editor.locator("#skDistance").is_enabled() + assert editor.locator("#skAmbience").is_enabled() + # Programmatic range edit emits real DOM input+change events, just as + # an operator gesture does; assertions inspect outgoing native packets. + editor.locator("#skDistance").evaluate("""n=>{ + n.value='5.0';n.dispatchEvent(new Event('input',{bubbles:true})); + n.dispatchEvent(new Event('change',{bubbles:true}));}""") + distance=last_action(page,"nativeSonKuSet") + assert distance["settings"]["spacePreset"]==2,distance + assert abs(distance["settings"]["sourceDistanceMeters"]-5.0)<.01,distance + emit(page,"arMixBuiltinSonKuAck",{ + "requestId":distance["requestId"],"status":"APPLIED"}) + sceneState={**sceneState,"sourceDistanceMeters":5.0} + accepted_snapshot(page,state,sceneState,applied=distance["requestId"]) + editor.locator('[data-sk-room="1"]').click() + clamped=last_action(page,"nativeSonKuSet") + assert clamped["settings"]["spacePreset"]==1,clamped + assert clamped["settings"]["sourceDistanceMeters"]<=3.1,clamped + emit(page,"arMixBuiltinSonKuAck",{ + "requestId":clamped["requestId"],"status":"APPLIED"}) + sceneState={**sceneState,"spacePreset":1, + "sourceDistanceMeters":clamped["settings"]["sourceDistanceMeters"]} + accepted_snapshot(page,state,sceneState,applied=clamped["requestId"]) + editor.locator('[data-sk-room="0"]').click() + off=last_action(page,"nativeSonKuSet") + assert off["settings"]["spacePreset"]==0,off + emit(page,"arMixBuiltinSonKuAck",{ + "requestId":off["requestId"],"status":"APPLIED"}) + accepted_snapshot(page,state,{**sceneState,"spacePreset":0}, + applied=off["requestId"]) + assert editor.locator("#skDistance").is_disabled() + assert editor.locator("#skAmbience").is_disabled() bounds=editor.bounding_box() assert bounds and bounds["width"]>260 and bounds["width"]setProperty("'+field+'"',snapshot) + if field=="spacePreset": + self.assertIn('values.getProperty("spacePreset"',main) + else: + self.assertIn('optionalNumber("'+field+'"',main) + self.assertIn(field,js) + self.assertIn(field,core) + self.assertIn('reply->setProperty("schemaVersion",2)',snapshot) + self.assertIn("queueSettings(settings,numeric)",main) + self.assertIn("complete_.push(",processor) + self.assertIn("out.writeInt(2)",processor) + self.assertIn("version==1&&size!=30",processor) + self.assertIn("version==2&&size!=46",processor) + self.assertNotIn("new AudioContext",js) + self.assertIn("[data-sk-room]",js) + self.assertIn('arMixBuiltinSonKuAck',js) + def test_native_tempo_readback_belongs_to_vocal_throw_not_eq(self): # The real C++ dispatcher must populate the exact VocalThrow # snapshot, not an unrelated EQ response. Browser-only mocks cannot diff --git a/tests/sonku_musical_reverb_test.cpp b/tests/sonku_musical_reverb_test.cpp index 3a099734a..d958ec743 100644 --- a/tests/sonku_musical_reverb_test.cpp +++ b/tests/sonku_musical_reverb_test.cpp @@ -57,6 +57,30 @@ int main(){ airy+=std::abs(output.left)+std::abs(output.right); } assert(airy>.005); + // Native M4 can change room decay in the callback with prepared + // coefficients and no tail-ring clear, even while active. + SonKuMusicalReverb live; + assert(live.prepare(rate)); + assert(live.setRealtimeProgram(SonKuReverbPreset::StudioGlue,.38f)); + assert(!live.setRealtimeProgram(SonKuReverbPreset::LargeRoom,1.1f)); + for(int i=0;i(rate);++i) { + const auto out=live.process(i==0?.4f:0.f,i==0?.4f:0.f); + assert(std::isfinite(out.left)&&std::isfinite(out.right)); + } + assert(live.setRealtimeProgram(SonKuReverbPreset::LargeRoom,.38f)); + for(int i=0;i<8192;++i) { + const auto out=live.process(0.f,0.f); + assert(std::isfinite(out.left)&&std::isfinite(out.right)); + } + assert(live.setRealtimeProgram(SonKuReverbPreset::LargeRoom,0.f)); + for(int i=0;i<11000;++i)live.process(0.f,0.f); + assert(!live.active()); + // Reactivation may not expose delay contents from the last run. + assert(live.setRealtimeProgram(SonKuReverbPreset::AiryChamber,.38f)); + for(int i=0;i<1800;++i){ + const auto out=live.process(0.f,0.f); + assert(out.left==0.f&&out.right==0.f); + } } return 0; } diff --git a/tests/sonku_offline_demo_contract.py b/tests/sonku_offline_demo_contract.py index 7a9bb4842..7faa70b27 100644 --- a/tests/sonku_offline_demo_contract.py +++ b/tests/sonku_offline_demo_contract.py @@ -51,6 +51,24 @@ def energy(a): return sum(abs(int(x)) for x in a[300000:440000]) assert .081000,"M4 square ambience is silent" +assert music_delta(m4Chamber,m4Square)>1000,"Chamber settings ignored" +assert music_delta(m4Large,m4Chamber)>1000,"Large room reverb ignored" +assert music_delta(m4Chamber,m4ChamberFar)>1000,"Chamber distance ignored" +assert music_delta(m4Large,m4LargeFar)>1000,"Large room distance ignored" +def musical_energy(a): + return sum(abs(int(x)) for x in a[280000:450000]) +assert musical_energy(m4ChamberFar).01); assert(std::abs(farEnergy/nearEnergy-.2)<1.e-5); } + // M4: real native scene settings must affect the exact PCM core, not + // just a visual mock. Old 1.6m/Square HRTF remains the same baseline. + { + auto reference=std::make_unique(); + auto scene=std::make_unique(); + auto partition=std::make_unique(); + assert(reference->prepare(rate)&&scene->prepare(rate)&& + partition->prepare(rate)); + Settings live=s;live.moving=false;live.startAzimuthDegrees=0.f; + live.spacePreset=2;live.sourceDistanceMeters=5.f; + live.roomAmount=.55f;live.ambience=.32f; + assert(valid(live)); + Settings bad=live;bad.spacePreset=1; + assert(!valid(bad)); // 5m cannot fit inside 7.2m square + bad=live;bad.ambience=std::numeric_limits::quiet_NaN(); + assert(!valid(bad)); + bad=live;bad.spacePreset=4;assert(!valid(bad)); + assert(reference->setSettings(s)); + assert(scene->setSettings(live)&&partition->setSettings(live)); + constexpr int n=4096; + std::array refL{},refR{},a{},b{},chunkL{},chunkR{}; + for(int i=0;i(i)*.07f); + refL[i]=refR[i]=a[i]=b[i]=chunkL[i]=chunkR[i]=sample; + } + reference->process(refL.data(),refR.data(),n); + scene->process(a.data(),b.data(),n); + for(int i=0;iprocess(chunkL.data()+i,chunkR.data()+i,128); + double delta=0.; + for(int i=0;i.1); // actual accepted-space DSP, not GUI-only + // Changing room size in-flight is permitted: all geometry and + // FDN coefficients are already bounded, no memory allocation. + live.spacePreset=3;live.sourceDistanceMeters=8.f; + assert(valid(live)&&scene->setSettings(live)); + std::array transitionL{},transitionR{}; + transitionL.fill(.13f);transitionR.fill(.13f); + scene->process(transitionL.data(),transitionR.data(),128); + for(int i=0;i<128;++i) + assert(std::isfinite(transitionL[i])&& + std::isfinite(transitionR[i])&& + std::abs(transitionL[i])<1.f&& + std::abs(transitionR[i])<1.f); + // Turning SPACE off removes all room+FDN work after smoothing. + live.spacePreset=0;assert(scene->setSettings(live)); + for(int i=0;i<90;++i){ + transitionL.fill(0.f);transitionR.fill(0.f); + scene->process(transitionL.data(),transitionR.data(),128); + } + } // 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 08b579f96..ae2697103 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -146,15 +146,18 @@ std::vector orbit(float roomAmount=0.f, // 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){ + armix::sonku::SonKuReverbPreset preset, + std::optional nativeScene=std::nullopt){ SonKuSpatialCore dsp; if(!dsp.prepare(rate)|| - !dsp.setEarlyReflectionsShape(armix::sonku::SonKuRoomShape::Square)|| - !dsp.setMusicalReverbPreset(preset)|| - !dsp.setEarlyReflectionsAmount(.55f)|| - !dsp.setMusicalReverbAmount(lateAmount)) + (!nativeScene && + (!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; + Settings s=nativeScene.value_or(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, @@ -255,6 +258,14 @@ void notes(const std::filesystem::path& directory, <<"distance, and separately judge actual level reduction as a cue.\n" <<"V4 room tests disable FDN deliberately: the existing 0.78/1.28s\n" <<"tail is not calibrated for large halls (no pretend big-hall RT60).\n" + <<"M4 musical candidate WAVs use the EXACT native SonKu settings v2:\n" + <<"sonku-m4-musical-square-near-2x.wav = 7.2m, 1.6m, 0.30 ambience.\n" + <<"sonku-m4-musical-chamber-near-2x.wav = 14.4m, 1.6m.\n" + <<"sonku-m4-musical-chamber-far-2x.wav = 14.4m, 5m.\n" + <<"sonku-m4-musical-large-near-2x.wav = 28.8m, 1.6m.\n" + <<"sonku-m4-musical-large-far-2x.wav = 28.8m, 8m.\n" + <<"Same original plucked motif + KEMAR HRTF, same 20s clock;\n" + <<"decay programs = 0.78 / 1.28 / 2.05 s. NOT volume-normalized.\n" <<"Not simulated: air absorption, floor/ceiling, personalized HRTF,\n" <<"direct path time-of-flight, or higher-order wall reflections.\n" <<"Offline candidates only, NO native GUI/session/product release.\n"; @@ -323,6 +334,21 @@ int main(int argc,char** argv){ orbit(.55f,SonKuRoomShape::Square,true,0.f, SonKuReverbPreset::StudioGlue, SonKuRoomGeometry{28.8f,28.8f,8.f})); + // Native scene v2 listening evidence. These use the exact core API + // that receives ACKed FX editor settings (no separate reverb engine). + auto emitScene=[&](const char* file,int preset,float distance){ + Settings settings=fixed(0.f); + settings.spacePreset=preset; + settings.sourceDistanceMeters=distance; + settings.roomAmount=.55f; + settings.ambience=.30f; + writeWav(dir/file,musicalOrbit(0.f,SonKuReverbPreset::StudioGlue,settings)); + }; + emitScene("sonku-m4-musical-square-near-2x.wav",1,1.6f); + emitScene("sonku-m4-musical-chamber-near-2x.wav",2,1.6f); + emitScene("sonku-m4-musical-chamber-far-2x.wav",2,5.f); + emitScene("sonku-m4-musical-large-near-2x.wav",3,1.6f); + emitScene("sonku-m4-musical-large-far-2x.wav",3,8.f); notes(dir,blind); std::cout<<"SonKu listening package PASS: measured native HRTF, " <<"4 labeled + 8 blind directions + two uninterrupted 360 turns\n";