diff --git a/.github/workflows/imersip-fast.yml b/.github/workflows/imersip-fast.yml new file mode 100644 index 000000000..9a4f56d01 --- /dev/null +++ b/.github/workflows/imersip-fast.yml @@ -0,0 +1,68 @@ +name: ImerSip P8.7 musical front-speaker plus P8.6 focused room +on: + pull_request: + paths: + - 'engine/builtin_fx/ImerSip*.h' + - 'engine/builtin_fx/sonku/SonKuP84FusedMusicHrir.h' + - 'engine/builtin_fx/sonku/SonKuP87MusicalAirBody.h' + - 'engine/builtin_fx/sonku/SonKuSpatialCore.h' + - 'tests/imersip_music_phase_guard_test.cpp' + - 'tests/imersip_fx_picker_contract_test.py' + - 'tests/imersip_native_picker_chromium_smoke.py' + - 'src/NativeBuiltInFx.h' + - 'scripts/compose_native_peq.py' + - 'scripts/build_approved_native_gui.py' + - 'web/approved-native-bridge.js' + - 'CMakeLists.txt' + - '.github/workflows/imersip-fast.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + source-pcm: + runs-on: ubuntu-latest + timeout-minutes: 8 + steps: + - uses: actions/checkout@v4 + - name: Compile real SonKu P8.2 plus ImerSip phase-safe enhancer + shell: bash + run: | + g++ -std=c++20 -O2 -Wall -Wextra -Werror \ + -DSONKU_P7_MEASURED_ELEVATION_RESEARCH=1 \ + -DSONKU_P71_DIRECT_XYZ_RESEARCH=1 \ + -DSONKU_P72_NATIVE_XYZ_RT=1 \ + -DSONKU_P75_MUSIC_SAFE_RESEARCH=1 \ + -DSONKU_P80_TRANSPARENT_BASS_RESEARCH=1 \ + -DSONKU_P82_MULTIBAND_ROOM_RESEARCH=1 \ + tests/imersip_music_phase_guard_test.cpp -o imersip_music_test + - name: P8.2 unmodified path plus P8.4 fused HRIR DC/bass, vocal MID, stereo phase and chunks + run: ./imersip_music_test + - name: Build-to-FX-Picker registration and JUCE host contract + run: python -m unittest discover -s tests -p imersip_fx_picker_contract_test.py -v + + picker-visual: + name: ImerSip in actual compiled native FX Picker (Chromium) + needs: source-pcm + runs-on: ubuntu-latest + timeout-minutes: 12 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install isolated browser driver + run: | + python -m pip install playwright + python -m playwright install --with-deps chromium + - name: Visual native GUI catalog, search, JUCE intent and no fake PCM + run: python tests/imersip_native_picker_chromium_smoke.py + - name: Upload actual ImerSip picker screenshot + if: always() + uses: actions/upload-artifact@v4 + with: + name: ImerSip-Native-FX-Picker-Evidence-${{ github.run_id }} + path: imersip-visible-native-picker.png + if-no-files-found: ignore + retention-days: 14 diff --git a/.github/workflows/sonku-p82-acoustic-windows-field.yml b/.github/workflows/sonku-p82-acoustic-windows-field.yml index 15ff4e144..21dde832b 100644 --- a/.github/workflows/sonku-p82-acoustic-windows-field.yml +++ b/.github/workflows/sonku-p82-acoustic-windows-field.yml @@ -16,12 +16,18 @@ on: - 'tests/sonku_p75_*' - 'tests/sonku_p80_*' - 'tests/sonku_p82_*' + - 'engine/builtin_fx/ImerSip*.h' + - 'tests/imersip_native_state_test.cpp' workflow_dispatch: permissions: contents: read concurrency: group: sonku-p82-physical-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + # An immutable Windows candidate must finish once started; rapid source + # or documentation updates used to cancel a ten-minute successful build + # before artifact upload. Pending newer commits are serialized, not allowed + # to abort the running exact-SHA qualification. + cancel-in-progress: false jobs: preflight: name: Isolated fast PCM and GUI preflight @@ -39,6 +45,11 @@ jobs: node tests/sonku_p73_gui_contract_test.js grep -q "'FIELD_PREVIEW_FULL_CTEST_NOT_RUN'" scripts/m3e_fat_evidence_gate.mjs python -m unittest discover -s tests -p native_peq_assembly_test.py + # Fail fast on the exact v5 ImerSip GUI, picker and provenance. + python -m unittest discover -s tests -p imersip_fx_picker_contract_test.py -v + # Fail BEFORE expensive Windows compile if a copied PowerShell + # artifact metadata block has duplicate keys (PSParserError). + python -c 'import re; from pathlib import Path; s=Path(".github/workflows/sonku-p82-acoustic-windows-field.yml").read_text(); b=s.split("NotePropertyName imersipResearch -NotePropertyValue @{",1)[1].split("} -Force",1)[0]; keys=re.findall(r"(?m)^\s+([A-Za-z_]\w*)\s*=",b); assert len(keys)==len(set(keys)), "IMERSIP_DUPLICATE_POWERSHELL_PROVENANCE_KEY"; print("IMERSIP_METADATA_UNIQUE_KEYS_OK",len(keys))' - name: 44.1 and 48 kHz prepared PCM source regression run: | set -euo pipefail @@ -131,7 +142,8 @@ jobs: 'NativeSonKuSessionV1V2AndAudioAppliedAck', 'NativeSonKuP75MusicStereoPhaseNoNullAndChunkParity', 'NativeSonKuP80TransparentBassStereoPhaseAndRoomDiagnostic', - 'NativeSonKuP82SixWallThreeBandRoomTimingDecayAndParity') + 'NativeSonKuP82SixWallThreeBandRoomTimingDecayAndParity', + 'ImerSipNativeJuceP82AcceptedStateAckAndRestore') $available = @($tests.tests | ForEach-Object { $_.name }) foreach ($test in $required) { if ($test -notin $available) { throw "SONKU_P82_MISSING_CTEST:$test" } @@ -140,7 +152,7 @@ jobs: shell: pwsh run: | cmake --build build --config Release --parallel 2 --target ` - ARMixConsole ARMixSonKuP72SourceTests ARMixSonKuP72NativeTests ARMixSonKuNativeStateTests ARMixSonKuP75MusicIntegrityTests ARMixSonKuP80TonalEvidenceTests ARMixSonKuP82RoomTests + ARMixConsole ARMixSonKuP72SourceTests ARMixSonKuP72NativeTests ARMixSonKuNativeStateTests ARMixSonKuP75MusicIntegrityTests ARMixSonKuP80TonalEvidenceTests ARMixSonKuP82RoomTests ARMixImerSipNativeTests if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $exe = 'build/ARMixConsole_artefacts/Release/AR MIX Studio.exe' if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) { throw "SONKU_P75_NO_GUI_EXE" } @@ -149,7 +161,7 @@ jobs: shell: pwsh run: | ctest --test-dir build -C Release --output-on-failure ` - -R '^NativeSonKu(P72AtomicXyzLiveEditSource|P72JuceV3XyzLiveAckV1V2Restore|SessionV1V2AndAudioAppliedAck|P75MusicStereoPhaseNoNullAndChunkParity|P80TransparentBassStereoPhaseAndRoomDiagnostic|P82SixWallThreeBandRoomTimingDecayAndParity)$' + -R '^NativeSonKu(P72AtomicXyzLiveEditSource|P72JuceV3XyzLiveAckV1V2Restore|SessionV1V2AndAudioAppliedAck|P75MusicStereoPhaseNoNullAndChunkParity|P80TransparentBassStereoPhaseAndRoomDiagnostic|P82SixWallThreeBandRoomTimingDecayAndParity)$|^ImerSipNativeJuceP82AcceptedStateAckAndRestore$' if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - name: Package real native portable mixer, never an installer shell: pwsh @@ -189,6 +201,42 @@ jobs: mitKemarNoticeSha256 = (Get-FileHash -LiteralPath docs/THIRD_PARTY_8D_SONKU_HRTF.md -Algorithm SHA256).Hash.ToLowerInvariant() fieldFatGuideSha256 = (Get-FileHash -LiteralPath docs/SONKU_P82_ACOUSTIC_ROOM_FIELD_FAT_20261114.md -Algorithm SHA256).Hash.ToLowerInvariant() } -Force + $p | Add-Member -NotePropertyName imersipResearch -NotePropertyValue @{ + catalogId = 'armix.builtin.imersip.v1' + p82CoreEnabled = $true + phaseSafeSidelobe = $true + coherentBassShelf = $true + monoCenterPreserved = $true + p82NativeAdapterTest = 'REQUIRED' + physicalHeadphoneQualified = $false + fullAudioEditorAvailable = $true + fullAudioEditorType = 'JUCE_NATIVE_FX_EDITOR_SPSC_AUDIO_APPLIED' + detailControl = $true + detailHighShelfHz = 5600 + imrsSchemaVersion = 5 + imrsStateBytes = 52 + # This is a CURRENT v5 physical headset research candidate. + # Old v2/36-byte/175°/1.6m metadata falsely described the + # latest executable and forced the wrong provenance gate. + backwardCompatibleImrsVersions = @(1,2,3,4) + directMidMeasuredHrtf = $true + originalStereoSideProtected = $true + defaultVirtualSpeakerSpreadDegrees = 96 + speakerSpreadRangeDegrees = @(32,126) + sourceDistanceMeters = 5.08 + sourceDistanceRangeMeters = @(1.6,7.4) + sourceHeightPhysicalMeters = 1.45 + earHrtfAlignRangeDegrees = @(-30,20) + independentEarlyAndLate = $true + realtimeKnobsDuringDrag = $true + coherentSpaceLinkedBass = $true + p84FusedMeasuredDirection = $true + binauralEarlyMidAndSide = $true + actualDualMeasuredKemarSpeakers = $true + p82StandardCenterMusicDefaultUnchanged = $true + + publicRelease = $false + } -Force $p | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath $path -Encoding utf8 - name: Independent GUI PE, approved resources, provenance and ZIP verification shell: pwsh @@ -196,6 +244,25 @@ jobs: & ./scripts/verify_native_windows_artifact.ps1 -OutputDir dist if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $p = Get-Content -LiteralPath dist/BUILD_PROVENANCE.json -Raw | ConvertFrom-Json + if (-not $p.imersipResearch.fullAudioEditorAvailable -or + -not $p.imersipResearch.detailControl -or + $p.imersipResearch.imrsSchemaVersion -ne 5 -or + $p.imersipResearch.imrsStateBytes -ne 52 -or + -not $p.imersipResearch.directMidMeasuredHrtf -or + -not $p.imersipResearch.originalStereoSideProtected -or + $p.imersipResearch.defaultVirtualSpeakerSpreadDegrees -ne 96 -or + [math]::Abs([double]$p.imersipResearch.sourceDistanceMeters - 5.08) -gt 0.01 -or + $p.imersipResearch.sourceDistanceRangeMeters.Count -ne 2 -or + $p.imersipResearch.earHrtfAlignRangeDegrees.Count -ne 2 -or + -not $p.imersipResearch.independentEarlyAndLate -or + -not $p.imersipResearch.realtimeKnobsDuringDrag -or + -not $p.imersipResearch.coherentSpaceLinkedBass -or + -not $p.imersipResearch.p84FusedMeasuredDirection -or + -not $p.imersipResearch.binauralEarlyMidAndSide -or + -not $p.imersipResearch.actualDualMeasuredKemarSpeakers -or + -not $p.imersipResearch.p82StandardCenterMusicDefaultUnchanged) { + throw 'IMERSIP_V5_CURRENT_GUI_DEPTH_HEIGHT_AND_PCM_CONTRACT_MISSING' + } if (-not $p.sonkuExperiment.enabled -or -not $p.sonkuExperiment.musicSafeStereo -or -not $p.sonkuExperiment.p8TransparentBass -or @@ -228,7 +295,7 @@ jobs: - uses: actions/upload-artifact@v4 name: Upload isolated SonKu Windows x64 field candidate with: - name: ArSonMix-SonKu-P82-Multiband-Room-Windows-x64-${{ github.run_id }} + name: ArSonMix-ImerSip-P87-StereoFirst-v5-Windows-x64-${{ github.run_id }} path: dist/ if-no-files-found: error retention-days: 21 diff --git a/CMakeLists.txt b/CMakeLists.txt index ba32b706b..0a917a7ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,7 +177,7 @@ juce_add_binary_data(ARMixAssets SOURCES "${ARMIX_BRAND_DIR}/arsonmix-256.png") target_include_directories(ARMixConsole PRIVATE "${ARMIX_APPROVED_GUI_DIR}") -target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h engine/builtin_fx/HarmonyDsp.h engine/builtin_fx/HarmonyMusicKey.h engine/builtin_fx/ChannelHarmonyProcessor.h engine/builtin_fx/SonKuSpatialProcessor.h engine/builtin_fx/sonku/SonKuSpatialCore.h engine/builtin_fx/sonku/SonKuMeasuredHrir.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/AuxBusPlan.h engine/core/PreparedMixerBlock.h engine/core/MasterOutputMonoPolicy.h engine/core/LiveChannelFxGraph.h engine/core/PreparedNativeMixerSession.h engine/core/NativeDryRouteCommand.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/NativeFxParameterHotkey.h src/FactoryFxRegistry.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/NativeShowSchema.h src/NativeDryShowRecall.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/LiveSecondaryOutputDevice.h engine/core/LiveOutputRouteGate.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) +target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h engine/builtin_fx/HarmonyDsp.h engine/builtin_fx/HarmonyMusicKey.h engine/builtin_fx/ChannelHarmonyProcessor.h engine/builtin_fx/SonKuSpatialProcessor.h engine/builtin_fx/ImerSipProcessor.h engine/builtin_fx/ImerSipDsp.h engine/builtin_fx/ImerSipPhaseSafe.h engine/builtin_fx/sonku/SonKuSpatialCore.h engine/builtin_fx/sonku/SonKuMeasuredHrir.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/AuxBusPlan.h engine/core/PreparedMixerBlock.h engine/core/MasterOutputMonoPolicy.h engine/core/LiveChannelFxGraph.h engine/core/PreparedNativeMixerSession.h engine/core/NativeDryRouteCommand.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/NativeFxParameterHotkey.h src/FactoryFxRegistry.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/NativeShowSchema.h src/NativeDryShowRecall.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/LiveSecondaryOutputDevice.h engine/core/LiveOutputRouteGate.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) # Explicit UTF-8 source decoding: native channel icons are Unicode, and # MSVC's machine-specific ANSI source charset corrupts emoji literals. # Limit the flag to C++ (not Windows .rc/resource compilation). @@ -403,6 +403,40 @@ if(BUILD_TESTING) SONKU_P82_MULTIBAND_ROOM_RESEARCH=1) add_test(NAME NativeSonKuP82SixWallThreeBandRoomTimingDecayAndParity COMMAND ARMixSonKuP82RoomTests) + # ImerSip uses the exact P8.2 native PCM, then positive + # coherent LF shelf and mono-invariant SIDE HF enhancement. + # Expensive JUCE/Windows installer is NOT a source-test dependency. + add_executable(ARMixImerSipMusicTests + tests/imersip_music_phase_guard_test.cpp) + target_compile_features(ARMixImerSipMusicTests PRIVATE cxx_std_20) + target_compile_definitions(ARMixImerSipMusicTests PRIVATE + SONKU_P7_MEASURED_ELEVATION_RESEARCH=1 + SONKU_P71_DIRECT_XYZ_RESEARCH=1 + SONKU_P72_NATIVE_XYZ_RT=1 + SONKU_P75_MUSIC_SAFE_RESEARCH=1 + SONKU_P80_TRANSPARENT_BASS_RESEARCH=1 + SONKU_P82_MULTIBAND_ROOM_RESEARCH=1) + add_test(NAME ImerSipP82NoAddedPhaseCancellationBassAndChunkParity + COMMAND ARMixImerSipMusicTests) + # Compile the actual JUCE plugin adapter with the SAME P8.2 + # research macro contract, not just the header-only PCM simulation. + juce_add_console_app(ARMixImerSipNativeTests + PRODUCT_NAME "ImerSip Native JUCE State and PCM") + target_sources(ARMixImerSipNativeTests PRIVATE + tests/imersip_native_state_test.cpp + engine/builtin_fx/ImerSipProcessor.h) + target_link_libraries(ARMixImerSipNativeTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixImerSipNativeTests PRIVATE cxx_std_20) + target_compile_definitions(ARMixImerSipNativeTests PRIVATE + SONKU_P7_MEASURED_ELEVATION_RESEARCH=1 + SONKU_P71_DIRECT_XYZ_RESEARCH=1 + SONKU_P72_NATIVE_XYZ_RT=1 + SONKU_P75_MUSIC_SAFE_RESEARCH=1 + SONKU_P80_TRANSPARENT_BASS_RESEARCH=1 + SONKU_P82_MULTIBAND_ROOM_RESEARCH=1) + add_test(NAME ImerSipNativeJuceP82AcceptedStateAckAndRestore + COMMAND ARMixImerSipNativeTests) endif() endif() endif() diff --git a/docs/IMERSIP_CLOSE_ORCHESTRA_STAGE_FAT_20261115.md b/docs/IMERSIP_CLOSE_ORCHESTRA_STAGE_FAT_20261115.md new file mode 100644 index 000000000..f80d89995 --- /dev/null +++ b/docs/IMERSIP_CLOSE_ORCHESTRA_STAGE_FAT_20261115.md @@ -0,0 +1,21 @@ +# ImerSip Close Orchestra Stage — FAT candidate, 15 Nov 2026 + +## Target from the owner's physical listening +Source instruments near, life-size orchestra directly in front, wide external separation, detailed voice, and living bass supported by the room rather than a thick late-reverb wash. SonKu P8.4 is the owner-preferred audible A/B reference; preserve its P8.2 transparent bass and bounded P8.4 HRIR fusion. No orbit. + +## Native implementation +- All venues: **1.6m fixed source** in the genuine P8.2 six-wall acoustic geometry. Concert/Cinema use large venue dimensions; Live Room uses 14.4m. A 1.6m source distance does not imply a 1.6m room. +- Concert EARLY amount = 0.075 + 0.180×Venue Space; LATE amount = 0.025 + 0.100×Venue Space, zero wet at Immersion=0. Cinema/Live similarly bias EARLY above LATE. Larger early/direct cue can add external room impression while preserving articulate foreground instruments. Exact values are LISTENING CANDIDATES, not measured source-room impulse responses. +- Original LEFT/RIGHT source music remains direct, original MID vocal remains dry before optional air detail and coherent low-shelf; source SIDE preserved; the measured P8.4-12% HP750 fused direction contributes only a controlled SIDE return. Standard SonKu unaffected. +- BASS IMPACT adds a small positive *coherent* LP120 shelf with equal L/R coefficient and an extra (1+0.45×Space) multiplier. This mimics near-hall LF pressure while avoiding delayed bass recombination and low-frequency phase cancellations; it is NOT genuine measured room-mode modelling or a substitute for headphones-specific correction. +- Native JUCE editor displays SOURCE 1.6m CLOSE/DIRECT, same 6 controls and native ACK. No duplicate DSP engine or M4 routing; changes don't touch production main. + +## Red Windows issue audited +Old run https://github.com/masarray/arsonmix/actions/runs/43659352042: GUI EXE, packaging, all seven JUCE/PCM tests actually PASS. It failed **after** packaging from duplicated `physicalHeadphoneQualified` in PowerShell hashtable, confirmed in the original job log. Commit `91fdc75` removed duplicate and added fast preflight gate. Do not call the CI green until full exact-SHA run including ZIP verification succeeds. + +## Gates +1. 44.1/48k actual P8.2 native PCM test checks 1.6m invariant across 3 venues x spaces 0/.45/1, early > late, bass monotone & original bass preserved, original MID, 175/180 wide stereo, anti-phase content, P8.4 fusion/DC, native 64/128/8192 chunk parity. +2. Native Windows 7 CTests including real JUCE ImerSip editor, state v1/v2 restoration, SPSC accepted ACK; packaging manifest uniqueness and PE/ZIP hash checks. No public release unless green. +3. Physical A/B against owner-approved SonKu P8.4, same level with dearVR / SonKu inserts disabled when listening to ImerSip. Evaluate vocal 1–4k clarity, violin and percussion location, bass kick/body, frontal outside-head vs in-head, early vs late balance, ASIO buffer 64/128/256 and actual XRUN. Never assert better sound from source CI alone. + +Sources: 2026 frontal externalization work https://pmc.ncbi.nlm.nih.gov/articles/PMC13451706/ ; auditory localization review https://doi.org/10.3389/fpsyg.2024.1408073 . The optimal ratio is listener/content-dependent. diff --git a/docs/IMERSIP_OWNER_APPROVED_AUDIO_UI_LIFECYCLE_20261115.md b/docs/IMERSIP_OWNER_APPROVED_AUDIO_UI_LIFECYCLE_20261115.md new file mode 100644 index 000000000..9a348f918 --- /dev/null +++ b/docs/IMERSIP_OWNER_APPROVED_AUDIO_UI_LIFECYCLE_20261115.md @@ -0,0 +1,11 @@ +# ImerSip approved audio checkpoint — editor lifecycle + host power +Baseline: 30f3e333368cc3ca97b568c91f05a63f07e80980 on immutable branch checkpoint/imersip-180deg-approved-audio-20261115. +Owner likes current 180° sound. Do not change HRIR, music MID/SIDE, P8.7, concert room, bass, audio callback, preset, or .smix state. +Fix: titlebar X hides editor; exact ChannelId/lane + slot + instanceId + epoch + revision re-show retains SAME JUCE window and its graph lease, with active-owner check. New target uses original guarded lease+new editor; no new audio authority. +Host native Power uses exact rack bypass per-insert state and fade (not new DSP flag) via bound Main.cpp control callback. Disabled when unbound, per-slot atomic state readback, live refresh. Closing window clears transient Original A/B. +Layout 980x560: enlarged top-view, readable aligned 4x2 knob grid, labeled spatial/tone sections, separated venue/actions/power/status. No forced bold cards. +Gates: native JUCE compiled editor/processor test checks power authority binding, clean viewport, same-processor open-close state, PCM accepted settings; Windows JUCE app and portable on same commit required. Manual Windows rack click -> X -> reopen -> repeated reopen -> power OFF/ON while meters continue -> save/open verification still required before owner acceptance. + +## Final native slot-power semantics and lifecycle regression +- INSERT ON / INSERT OFF is the bypass state of **this exact insert**, not the channel-wide rack master gate. Original A/B is temporary audition, not power. The editor caption uses this unambiguous vocabulary; all power changes still call Main.cpp native token/lease-guarded bypass callbacks, not a second local DSP authority. +- JUCE native test now exercises visibility false→true on the same editor pointer with bypass retained, with a distinct master-rack state not altered by insert toggling. A fresh editor is intentionally power-disabled until the host binds the exact verified rack slot. This is a control/UI-only regression: source-exact approved 180° DSP and .smix format untouched. diff --git a/docs/IMERSIP_OWNER_P82_171DEG_AUDIO_AB_REFERENCE_20261115.md b/docs/IMERSIP_OWNER_P82_171DEG_AUDIO_AB_REFERENCE_20261115.md new file mode 100644 index 000000000..19d68acfa --- /dev/null +++ b/docs/IMERSIP_OWNER_P82_171DEG_AUDIO_AB_REFERENCE_20261115.md @@ -0,0 +1,27 @@ +# ImerSip subjective A/B reference — owner screenshot 15 Nov 2026 + +This document locks the **actual reported owner-preferred sound**, not a synthetic guessed benchmark. +Screenshot: ArSonMix `v0.5.0-dev+g29ac1dde`, 8D-SonKu editor on CH 2. No PCM/audio WAV is embedded in the screenshot and we cannot objectively claim the screenshot proves phase, frequency response, loudness or speaker externalization. + +## User's starting-point reference: SonKu P8.2 +- Existing FX rack: `dearVR PRO 2`, `ImerSip`, `8D-SonKu` on CH 2. Verify bypass state of other spatial processors when doing controlled A/B. The screenshot is **not proof** all three are simultaneously audio-active. +- 8D-SonKu editor: STATIC, clockwise label displayed but motion OFF; SIDE WIDTH **171°**; SPATIAL MIX **100%**; OUTPUT **+2.5 dB**. +- ROOM preset **SQUARE**, dimensions **7.2 × 7.2 m**, distance **1.6 m**, elevation **0°**; REFLECTIONS **100%**; REVERB **47%**. +- Owner says this is reasonably good musical starting point, but needs still greater outside-the-head speaker externalization and clearer detail; audible phase cancellation remains problematic. No subjective acceptance for first ImerSip version, which was hollow/mid-muffled/near-mono. + +## Actual upgrade strategy, not visual equivalence +1. KEEP original stereo music/direct center vocals as authoritative, not reconstitute them from averaged two displaced binaural HRIRs. The first ImerSip released in research was overly wet/centered at 60° and failed owner's music listening. In current code: `original MID=(L+R)/2` has no KEMAR center-HRTF or wet reflections (except bounded optional DETAIL at user demand); raw `SIDE=(L-R)/2` always survives. +2. For optional external space, ImerSip may compute a genuine **pair** of P8.2 measured KEMAR filters at ±(80°..180°)/2. IMPORTANT: enabling this per-ImerSip research mode must not change the normal 8D-SonKu build/sound. Only the binaural SIDE differential is mixed into ImerSip at low level. User's width 171° corresponds to ImerSip WIDTH=91%. The current 95% default =175°—a deliberately close stage starting point. +3. LOW BASS: preserve source channel-coherent 25–220 Hz (no Haas or extra room-modulated low bass), and provide a bounded positive LF shelf through BASS IMPACT. Never claim perceptual unchanged bass without A/B. +4. MID/VOCAL: preserve exact source MID at DETAIL=0, BASS=0 and unity output, with spatial width and room at maximum. All virtual ambience must stay as differential SIDE; reject large new mono nulls. +5. DETAIL: optional controlled high shelf (above ~5.6 kHz), not default midrange exciter. Subjective brightness preference is not assumed. +6. Use JUCE built-in native editor, no fake JS DSP or competing WebAudio callback. Control gesture → SPSC → audio applied ACK; Save/Open supports v1→v2 migration. + +## A/B field protocol on user's real Windows headphones +- First bypass dearVR PRO2 and ImerSip; listen to **only 8D-SonKu P8.2** with EXACT numbers above. Fix device, rate (44.1 or 48k), buffer, gain, channel and songs. +- Then bypass 8D-SonKu and any other spatial processor, enable **only ImerSip** on the same channel/route. Start Concert, immersion 58%, width 91–95%, space 45%, bass 75%, detail 0%, output matched by ear or a loudness analyzer. Avoid stacked processors; do not A/B a +2.5 dB track with a unity source and mistake louder for better. +- Alternate processing blind where possible on the same music fragments: (A) centered vocals/piano/snare, (B) anti-phase/independent stereo instrumentation, (C) bass kick 25–220Hz, (D) front lateral/back perceived localization, (E) sibilance/upper HF fatigue, (F) real sampled room-tail reverb and transients. +- Acceptance: stage outside head convincingly, MID vocal uncolored; no mono-like collapse or hollow 1–4k presence; bass full; original left/right percussion localization intact; no audible pitch/combing, overbright harshness or clipped output; CPU stable at 44.1/48k. +- Tests and acceptance criteria differ: native PCM mathematical invariants/CTests can detect certain errors; cannot certify physical headset HRTF transfer or externalization for the listener. Real perfectly anti-phase source is mathematically silent upon mono sum regardless of a transparent processor. + +**Do not merge into public main or replace P8.2 reference** until the Windows JUCE full candidate passes and owner physically accepts the listening comparison. diff --git a/docs/IMERSIP_P0_180_DEG_FULL_HRIR_STEREO_MUSIC_20261115.md b/docs/IMERSIP_P0_180_DEG_FULL_HRIR_STEREO_MUSIC_20261115.md new file mode 100644 index 000000000..699bd903f --- /dev/null +++ b/docs/IMERSIP_P0_180_DEG_FULL_HRIR_STEREO_MUSIC_20261115.md @@ -0,0 +1,19 @@ +# ImerSip 180 degree full measured stereo / not near-mono — 2026-11-15 + +## Owner FAT rejection +User screenshot shows FRONT STAGE / 126° with all knobs at 100%, Speaker Distance 1.6m, Ear Align +8.5°, Stereo 1.33x. User perceives the music as nearly mono and says knob extremes are ineffective. Audio result is rejected regardless of the prior green PCM delta tests. Latest SonKu P8.7/P8.9 screenshots are extreme experiment references, not validated sound presets. + +## Source-level root cause +ImerSip previously fused physical L/R kernels toward a centered KEMAR HRIR at only **30%** directional strength before exposing direct ears; later ImerSip retained just 45% of the measured-side component at STEREO KEEP 100%. Effective source directional contrast could therefore be ~13.5% of the physical measured HRIR difference despite a max 126° stage. This compounds music stereo masking. A single "STEREO 1.33x" RMS metric cannot prove interaural separation or realistic speaker position. + +## Repair +- Stage Width maps user 0..100% to 30..180 degrees; full = KEMAR +/-90 degrees, a LATERAL placement that can maximize separation but is *not* proof of frontal externalization. The visual top view, numeric readout, and actual source geometry use the same angle. Default user stage = 130.5° (67%). +- ImerSip-only KEMAR target HRIR correction keeps FULL measured difference for independently different L/R stereo sources while centering only the *common* mono HRIR component. Original SonKu path remains unchanged byte-for-byte; old P8.4 filter study remains available for unit provenance but is **not** attenuating the current ImerSip differential anymore. +- Original source L/R SIDE is kept on the direct music bed, with the existing LF guard, bounded measured SIDE addition, early/late P8.6 room and P8.7 air/body; no stereo widening using artificial Haas, positive/negative phase copies or another audio graph. +- Dedicated tests at 44.1/48k verify actual full +/-90 measured source output vs 30°, mono-correlated front and stereo preservation, 64/128 chunk parity, each useful knob endpoint real PCM delta, bass 40..220Hz, peak, saved sessions v1..v5, native mixer FX picker. +- Do not promote as equivalent to dearVR or subjectively immersive before real same-headphone owner audition and exact commit Windows JUCE ZIP provenance. Keep PR draft, do not change main. + +Reference PR: https://github.com/masarray/arsonmix/pull/706 + +## Measured 180° HRTF and control strength calibration +The exact MIT-KEMAR measured +/-90-degree SIDE impulse energy was only 1.1548x the +/-15-degree impulse energy at 44.1 kHz. This is a physical HRIR measurement, not permission to invent different acoustic filters or assert an impossible >1.25x raw energy. Direct source still reaches true 180° angular directions. ImerSip's measured direct-side admission therefore now uses a bounded width-linked .20..60 coefficient, NOT the former flat 45% at every angle, so the full Stage Width endpoint produces a more meaningful actual PCM effect. Existing >=86% original music SIDE integrity regression is UNCHANGED. No source SIDE M/S widener is added. diff --git a/docs/IMERSIP_P0_STEREO_KEEP_EXTERNALIZATION_FIX_20261115.md b/docs/IMERSIP_P0_STEREO_KEEP_EXTERNALIZATION_FIX_20261115.md new file mode 100644 index 000000000..411fe34af --- /dev/null +++ b/docs/IMERSIP_P0_STEREO_KEEP_EXTERNALIZATION_FIX_20261115.md @@ -0,0 +1,15 @@ +# ImerSip — Stereo Keep must not disable externalization (15 Nov 2026) + +Owner explicitly reports P8.7 requires extreme WIDTH, SPATIAL MIX, ROOM and REVERB just to START sounding spatial, and rejects near-mono ImerSip render despite max knob settings. The two user-provided screenshots are *research extremes*, not quality presets. + +## Root problem in current ImerSip v5 +While fixing previous near-mono music regression, the direct HRIR SIDE contribution was reduced to 10% at `STEREO KEEP=100%`, effectively suppressing the binaural cue even when `IMMERSION=100%`. That is not a valid independence of fidelity and externalization. + +## Independent stereo fidelity / true direction +Measured two-ear KEMAR direct response from the existing P8.2/8.4 core is retained. The original dry stereo SIDE is NEVER canceled under KEEP mode. Instead, a separate four-pole 480Hz high-passed measured stereo HRTF SIDE is added at a bounded gain of 45% * immersion. Setting KEEP to zero restores the former full direct-HRTF transfer candidate; intermediate settings crossfade two different physical strategies. Original MID stays separately HRIR externalized. Bounded early/late P8.6 room and P8.7 music air remain, no fake delay/extra convolution/reverb, no changes to SonKu ordinary renderer. + +## Qualification +Real PCM 44.1/48k assertions must establish stereo integrity on independent, anti-phase and hard-pan fixture signals, 0 ROOM width sensitivity with KEEP 100%, mono front stability, 64/128 chunk parity, original P8.2 unaffected, bass, peak, dry bypass and true Windows JUCE IMRS v1-v5 ACK/restore. A real 100% control must not have the previous ~10% HRIR SIDE restriction. No claim of audible dearVR equivalence without same-headphone owner audition. No release, branch remains PR draft until full Windows and user listening. + +## Default tuning correction +Prior v5 used 76% immersion, 68% width, 70% early, 34% late and 60% depth. It left default musical scene too restrained relative to the user's P8.7 reference. New opt-in default (not a hidden migration of saved sessions): 88% immersion, 82% width (=109.1° frontal angle), 78% early, 25% late, 78% depth (=6.12m), 100% stereo keep, bass 50%, air 40%, 0dB trim, 0° KEMAR ear correction. Old IMRS records remain restored exactly; UI double-click default matches C++ initializer. No blanket 100% reverb and no hidden output boost. diff --git a/docs/IMERSIP_P82_PHASE_SAFE_IMPLEMENTATION_20261115.md b/docs/IMERSIP_P82_PHASE_SAFE_IMPLEMENTATION_20261115.md new file mode 100644 index 000000000..ccc966ee1 --- /dev/null +++ b/docs/IMERSIP_P82_PHASE_SAFE_IMPLEMENTATION_20261115.md @@ -0,0 +1,35 @@ +# ImerSip v2 — wide musical concert sound with a protected vocal center + +Status: **field research, physical headphone A/B pending**. Replaces acoustically rejected ImerSip v1. The user liked some SonKu P8.2 configurations with virtually wide speakers near 180°, but rejected the ImerSip v1 field ZIP as nasal/muffled and stereo-to-mono, without any editor. Do not use the earlier green DSP tests as a certificate of listening quality. + +## Evidence and diagnosis +- v1 hard-coded `stereoSpreadDegrees=60`, put the **entire stereo mix including vocals** through the P8.2 center HRTF and six-wall reverberation, then applied a small high-SIDE shelf. P8.2's protected anti-phase SIDE could survive mathematically while the direct music MID already sounded colored and the scene was focused in the head. +- v1 tests compared the output MID to the **same colorized P8.2 core**, instead of the music's original MID. Those tests were incomplete for vocal coloration. +- `ImerSipProcessor::hasEditor()` had returned false, and `createEditor()` returned nullptr. This was a shipped UX omission. +- P8.2's existing **music-safe** renderer uses a single centered HRTF even with the WIDTH dial near 180°. ImerSip now opts into **two actually separate measured KEMAR HRIR directions** for a stereo SIDE reference, and keeps the unfiltered music MID. A numeric 175° stage or nonindividualized BRIR still does not prove externalization without headphone listening. + +## v2 architecture +- One existing native JUCE stereo FX insert, unchanged `armix.builtin.imersip.v1` identity and versioned IMRS 36-byte v2 state with backward-compatible 32-byte v1 restoration (Detail=OFF on migration). +- Capture ORIGINAL source MID=(L+R)/2 and SIDE=(L-R)/2, process the original stereo samples in one P8.2 core with **ImerSip-only two independent measured KEMAR virtual speakers** at +/-stage angle, retain **only the differential SIDE component** from that genuine binaural processing, and mix a bounded amount into ORIGINAL SIDE. This costs four instead of two FIR tap multiplies in ImerSip and must be qualified for ASIO CPU. **Original MID is never re-rendered through center HRTF or early/late room**. The DSP then applies an optional coherent positive LF shelf and positive highpassed SIDE shelf, a small positive >5 kHz Detail shelf (identical L/R coefficients), and a single output trim. +- With BASS=0, DETAIL=0 and gain=unity the final MID must match the original source MID within float arithmetic tolerances at 44.1 and 48k, for mono vocal, hard panned, arbitrary stereo, and anti-phase source. The original SIDE is always present at unity before optional enhancement. +- One fixed-front source; stage WIDTH maps 80–180°, default 175°; room amount and wet-side return are bounded to prevent the foggy/full-band effect of v1. No moving/revolving source, Haas delay, polarity-flip widening, stereo-to-mono preprocessing, compressor or global makeup gain. The P8.2 core has a prepare-only opt-in research flag that defaults OFF; the SonKu P8.2 default audio algorithm and public behavior remain unchanged. +- A truly anti-phase **original** stereo recording mathematically cancels in mono. ImerSip cannot preserve both original L and R and eliminate that fact; the enforceable promise is avoiding **additional** destructive center cancellation. +- Real externalization depends on direct HRTF/BRIR, individualized spectral details, motion and reflections and is not guaranteed by dry MID protection or measured source angle alone. This is a bounded, favorable audio A/B candidate; treat next personalized speaker externalization as a separate listening-driven improvement, not a validated feature. + +## UX/controls +`ImerSipProcessor::hasEditor()==true` and `createEditor()` now return an 840x474 native JUCE panel hosted in the existing mixer FX editor window (no separate WebAudio/ASIO authority). Compact premium dark styling, visual listener + L/R stage; Concert Hall / Cinema / Live Room; Immersion / Stage Width / Venue Space / Bass Impact / DETAIL (>5 kHz only) / Output gain, with numeric readouts. Detail is a bounded +0..1.3 dB stereo-coherent high shelf; no 1–4 kHz vocal EQ boost. + +Changes enqueue using the existing SPSC real-time mailbox; only audio callback applies them, with completion readback to the editor. During drag the editor batches to one final action instead of pushing every frame. Store/restore remains with the native mixer Save/Open IMRS state. The host no longer needs JS specialty per-plugin commands for ImerSip, unlike SonKu's existing custom browser editor. + +## Qualification gates +1. Source C++ PCM at 44.1/48 kHz verifies **original** MID parity, L/R SIDE preservation, mono vocal, anti-phase, **measured stereo HRIR against original centered KEMAR**, high-spread geometry, genuine P8.2 room residual, bass 40/70/110/160/220 Hz and chunk invariance. +2. True Windows JUCE build and native CTest must instantiate **a working editor** and the actual two-speaker native side reference, plus descriptor/picker, audio-applied ACK, save/restore and PCM. Build provenance explicitly marks UI and dry-vocal protection. +3. On the owner's actual music/headphones: level-matched A/B original bypass vs P8.2 GOLDEN vs ImerSip v2; check vocals, midrange color, bass, high-frequency harshness, width, front/external distance, localization and CPU, including ROOM OFF/ON. If perceived stage is still in-head, stop and investigate independent left/right BRIR externalization before claiming acoustic success. +4. Do not merge/release as public or replace the latest main GUI; research branch is stacked on #695 and #706 and can be ported when approved. + +### Science/research basis +- Sound Externalization: A Review of Recent Research, https://pmc.ncbi.nlm.nih.gov/articles/PMC7488874/ : interaural coherence and room interaction, strong caveat about nonindividualized HRTF and frontal localization. +- The role of reverberation-related binaural cues in the externalization of speech, https://pubmed.ncbi.nlm.nih.gov/26328729/ : frontal sound requires plausible binaural reflection cues. +- Auditory localization: a comprehensive practical review, https://pmc.ncbi.nlm.nih.gov/articles/PMC11267622/ : HRTF, relative motion, reverberation and tradeoffs. + +**Do not claim dearVR equivalence, full phase cancellation elimination, physical spatial externalization proof or fully qualified monitoring without actual user's listening acceptance.** diff --git a/docs/IMERSIP_P84_FUSED_HRIR_EXTRACTION_20261115.md b/docs/IMERSIP_P84_FUSED_HRIR_EXTRACTION_20261115.md new file mode 100644 index 000000000..525f37b2a --- /dev/null +++ b/docs/IMERSIP_P84_FUSED_HRIR_EXTRACTION_20261115.md @@ -0,0 +1,25 @@ +# ImerSip experimental fused HRIR extraction (2026-11-15) + +## Why +The user listened to the SonKu P8.4 screen / executable `v0.5.0-dev+g641b4eae` and reports it sounds BETTER than P8.2. Listening preference supersedes PR #704's older text saying P8.4 is unapproved; formal hardware FAT measurements and externalization proof still remain outstanding. + +P8.4 reference screenshot: render mode `SPATIAL · P8.4 MUSIC FIRST`; virtual speaker angle **180°**, head-yaw slider **180°**, spatial mix **100%**, output **+2.5 dB**, LARGE 28.8 × 28.8 m, distance **6.1 m**, reflections **100%**, reverb **47%**. Clockwise button appears highlighted; screenshot cannot establish whether transport/audio motion is occurring. These are user-shared visual control settings, not measured PCM. + +## Isolation: do NOT merge rejected P8.3 +Original tested fusion kernel: PR #704 commit `641b4eaec653b2ecacc997200356a53aa98c4339`, `engine/builtin_fx/sonku/SonKuP84FusedMusicHrir.h`, copied unchanged into the P8.2-based ImerSip PR #706. This extracts **just** high-pass coefficient-space directional-contrast fusion; NO P8.3 physical/LF480/dual-callback code, no PR #704 parent branch history. + +For each measured L/R speaker source, ear and FIR tap: + +`H_ImerSip = H_center + 0.12 × HP750(H_measured_direction - H_center)`. + +The bounded 140-tap kernel calculation occurs during the existing 16-frame direct-kernel target update. It operates in the existing single SonKuSpatialCore and existing four direct FIRs. It is enabled **only if the ImerSip research adapter explicitly calls** `enableImerSipMeasuredStereoSide(true)`; the ordinary SonKu P8.2 center path remains untouched. Crucially, ImerSip then discards the spatialized MID and preserves the ORIGINAL source MID for direct vocals. It retains the original LF, phase-aligned SIDE, room differential and optional gentle detail. No audio callback allocations, second engine, power normalization or source motion. + +Note: this is **not an exact copy of the full SonKu P8.4 monitor**: ImerSip still has a different dry-MID level, controlled room-return balance and fixed-front scene. It is a deliberate, bounded transfer of the successful idea, not a fabricated claim of P8.4 sound equivalence or superior externalization. + +## Validation +- Source `tests/imersip_music_phase_guard_test.cpp`: actual P8.2 source and transplanted P8.4 kernel, 44.1/48k, kernel differential and nearly unity summed LF/DC, exact ordinary SonKu OFF-mode parity, actual KEMAR L/R impulse difference, preserved raw vocal MID/stereo SIDE, bass guard, detail HF/1–3 kHz, 64/128/8192 chunk parity and sample-peak headroom. +- Windows `ARMixImerSipNativeTests`: actual JUCE editor instantiation, FX catalog, audio-applied SPSC settings, IMRS v1→v2 session migration and accepted state tests. Full Windows portable artifact is only valid after this gate and provenance checks pass. +- These are *necessary engineering gates*, not audible speaker externalization proof or calibrated 4× true-peak/BS.1770-5/ASIO XRUN evidence. + +## Physical audition against the owner's proven sound +A: only SonKu P8.4 with the screenshot settings. B: only new ImerSip; start Concert Hall, Stage Width 95% (175°), Immersion 58%, Space 45%, Bass 75%, Detail 40%, Output volume matched. Bypass dearVR and the other spatial plugin in each case; stacking them will invalidate sound and phase observations. Loudness-match the A/B (P8.4 screenshot shows +2.5 dB), then evaluate actual vocals 1–4 kHz, 25–220 Hz bass pressure, frontal stage, stereo percussion separation, image externalization and natural late room. Revert/veto this extracted fusion if B sounds smaller, muffled, overbright, center-collapsed, or less musical than A. No modification to SonKu golden or public main is authorized by synthetic PASS alone. diff --git a/docs/IMERSIP_P86_DIRECT_SPEAKER_TRANSFER_20261115.md b/docs/IMERSIP_P86_DIRECT_SPEAKER_TRANSFER_20261115.md new file mode 100644 index 000000000..71280a9e4 --- /dev/null +++ b/docs/IMERSIP_P86_DIRECT_SPEAKER_TRANSFER_20261115.md @@ -0,0 +1,22 @@ +# ImerSip P8.6 FRONT-SPEAKER DIRECT TRANSFER — research candidate (2026-11-15) + +## Owner FAT regression and root cause + +Actual owner screenshot at 100% IMMERSION, 180-degree STAGE, 100% VENUE SPACE, 100% BASS/DETAIL: still virtually no spatial externalization. Previous ImerSip rendered a measured P8.4-fused direct HRTF in SonKuSpatialCore but explicitly THREW IT AWAY on output. Then reinserted full original headphone stereo and merely added SIDE widening and six-wall room. Simply reducing floor/ceiling energy with P8.6 does not externalize a headphone-dry source. + +## Isolated corrective candidate (never affects ordinary SonKu, no extra DSP graph) + +- Same P8.2 single SonKuSpatialCore and real 140-tap measured MIT KEMAR pair. The opt-in ImerSip RoomReturns now includes **the actual DIRECT EAR pair** before generic scene attenuation, alongside existing six-wall early and 3-band late returns. Only the ImerSip caller requests these; normal SonKu output and public session contract are unchanged. +- Full immersion routes the measured front loudspeaker direct difference through a **four-stage 700 Hz high-pass** and adds that directional transfer above the stable original stereo foundation. This is an LF-integrity correction after strict PCM tests caught bass regression in the first 260 Hz crossover. It keeps 40–220 Hz almost unchanged (subject to full-room returns) without an extra FIR or latency lookahead; 0% is exact dry and mid positions are smoothly slewed. The high-pass filter is a candidate, not a calibrated BRIR or a proof of audible externalization. +- ImerSip-only P8.4 high-pass directional fusion uses its supported upper bound 30% (formerly 12%) to produce substantial interaural transfer. Ordinary SonKu/P8.4 experiment is unchanged. +- P8.6 horizontal six-wall focus (four walls 100%, floor 24%, ceiling 15%) stays active. Early directional room is emphasized and late diffuse FDN restrained to avoid 'sound from ceiling/floor/room everywhere'. +- Actual front speaker geometry maps WIDTH to 40–100 degrees total (+/-20..50), **not** unrealistic +/-90-degree side-of-head loudspeakers. The JUCE stage diagram and numeric label now show the same geometry as the DSP. +- The ImerSip-only final linked peak guard protects the actual binaural direct output at high mastered levels, instead of clamping the DIRECT substitution back to dry; it is a sample-peak limiter, not a true-peak/oversampled limiter. NO allocation/FFT/mutex/thread on the PCM callback. + +## Verification and field acceptance + +- Native 44.1/48 kHz two-ear direct-signal test with ROOM OFF, exact original SonKu OFF parity, mono voice, anti-phase/stereo, bass/no null, dry bypass, chunk parity, venue/wall energy, and actual non-negligible direct-vs-dry PCM transfer. +- Full real Windows JUCE CTtest + native executable ZIP must pass **on the same commit** before user download is promoted. +- These tests prove DSP routing and bounds, NOT psychoacoustic quality. Headphone localization depends on listener-specific HRTF/headphone response, and static scene without head-tracking is inherently limited. Run loudness-matched A/B against preferred SonKu P8.4 and P8.6; user physical listening is the release gate. + +References: SonKu P8.6 PR #711; ImerSip PR #706. Public research: https://pmc.ncbi.nlm.nih.gov/articles/PMC13451706/ and https://journals.sagepub.com/doi/10.1177/2331216520948390. diff --git a/docs/IMERSIP_P86_HORIZONTAL_FOCUS_EXTRACTION_20261115.md b/docs/IMERSIP_P86_HORIZONTAL_FOCUS_EXTRACTION_20261115.md new file mode 100644 index 000000000..34c20b2d6 --- /dev/null +++ b/docs/IMERSIP_P86_HORIZONTAL_FOCUS_EXTRACTION_20261115.md @@ -0,0 +1,53 @@ +# ImerSip: P8.6 horizontal-first room extraction — research gate (15 Nov 2026) + +## Why +Owner's physical ImerSip test still unacceptable; audit of GitHub +run 43671493675 revealed **real Windows SegFault** +in ImerSipNativeJuceP82AcceptedStateAckAndRestore. Exact test source had +FOUR large SonKu/ImerSip processors constructed on the same Windows +~1MiB stack; running them in Linux earlier did not prove Win64 safety. +Commit `7d789aa9` now heap-owns all four JUCE test processors; the +Windows CTest and exact portable ZIP must be revalidated before use. + +Owner also requested inspecting P8.6, PR #711 commit +`884e1440f2e415f8731113e912d636081db8a9d0`. +P8.6 is a **private**, unapproved, isolated P8.5 stack that targets +floor/ceiling diffuseness without abandoning a directional speaker. +Do not merge P8.6 or its P8.5/P8.3 ancestry onto this ImerSip P8.2 fork. + +## Exact conceptual extraction (no new DSP engine) +In the same existing SonKuEarlyReflections six-wall renderer, ImerSip +passes a new optional `imersipHorizontalFocus=true` only when the +ImerSip measured two-speaker feature is active. +It keeps the real six paths, FIR, geometry, materials and delays: +- left, right, front, rear: **1.00x** original pressure; +- floor: **0.24x** original pressure; +- ceiling: **0.15x** original pressure. + +These exact coefficients come from P8.6 and affect **only the reflected +path after convolution**. The dry KEMAR binaural HRIR, fused P8.4 +HP750 contrast, direct stereo original MID/SIDE, coherent LF120 shelf, +1.6m source and native SPSC/GUI contract stay unchanged. It is a static +front-orchestra stage, NOT rotating or head-tracked audio. + +The optional flag defaults to FALSE, preserving normal 8D-SonKu P8.2 +output. The research lever changes no preset/session state and creates +no branch-dependent copies of room arrays, delay rings or FIRs. P8.6's +ER presence 0.76 and FDN presence 0.38 are NOT blindly imported because +ImerSip already has separate bounded, measured EARLY/LATE mixing laws, +and the owner's immediate regression was that previous wet returns were +INAUDIBLE. Relative audible comparisons must be measured first. + +## Engineering gates +- Original SonKu normal-path bit-exact OFF flag, original bass, + anti-phase SIDE, 44.1/48k 64/128/8192 chunk parity. +- Source test evaluates per-path weights 1/1/1/1/.24/.15, live six-wall + room PCM with and without ImerSip focus at both rates, nonzero room + energy and actual output difference, not just source-code inspection. +- Real JUCE state/ACK/audio callback CTest after heap stack fix, + Windows EXE+ZIP manifest SHA and provenance. +- Real owner headphone A/B vs approved P8.4 and P8.5/P8.6; focus can + make sound drier or more head-locked. No claim of premium immersive + acceptance based on CI alone. + +Reference: https://github.com/masarray/arsonmix/pull/711 diff --git a/docs/IMERSIP_P87_FRONT_SPEAKER_MUSIC_20261115.md b/docs/IMERSIP_P87_FRONT_SPEAKER_MUSIC_20261115.md new file mode 100644 index 000000000..48bb7a6d8 --- /dev/null +++ b/docs/IMERSIP_P87_FRONT_SPEAKER_MUSIC_20261115.md @@ -0,0 +1,16 @@ +# ImerSip: SonKu P8.7 musical transfer with stronger front speakers + +15 Nov 2026, private headphone research. Owner rejected prior ImerSip acoustic externalization. +Source: SonKu P8.7 draft PR #712 and ImerSip draft PR #706; do not merge experimental ancestry. + +## Transfer +- Source-exact SonKuP87MusicalAirBody.h provides shared two-ear 3.9kHz +1.9dB direct shelf and 42% of true stereo FDN lowpass 175Hz wet body. +- The existing ImerSip 4-pole direct HRTF-difference crossover is moved from 700 to 480Hz to increase 1-4kHz speaker transfer; strict original bass bounds are unchanged. +- P8.6 four horizontal reflection paths remain, floor 24%, ceiling 15%. Late diffuse high frequencies are not boosted. +- Deliberately DO NOT stack P8.7's +9% original music bass on existing ImerSip bassImpact boost. Source output must pass 40-220 Hz guard. +- No new .smix version, no second JUCE engine, callbacks, devices, threads, FFT, FIR, synthetic bass, or P8.3 ancestry. + +## Acceptance +- 44.1/48k PCM real source test probes P8.7 air/body spectra, exact test-only source A/B and real rendered changes, bass/mono/SIDE/anti-phase/chunk parity, 0% dry and peak safety. +- Native JUCE audio applied ACK / save/restore, actual Windows x64 ZIP provenance from the same commit are required before user FAT. +- Neither an RMS delta nor CI green constitutes perceptual externalization proof; only level-matched same-headphone audition can confirm outside-head quality. diff --git a/docs/IMERSIP_P88_CONCERT_LATERAL_ENERGY_20261115.md b/docs/IMERSIP_P88_CONCERT_LATERAL_ENERGY_20261115.md new file mode 100644 index 000000000..bbd52ebf7 --- /dev/null +++ b/docs/IMERSIP_P88_CONCERT_LATERAL_ENERGY_20261115.md @@ -0,0 +1,17 @@ +# ImerSip — Concert Stage Lateral Early Energy (2026-11-15) + +## Owner objective and prior state +User says current SonKu P8.7-adapted ImerSip is not yet luxurious, celebratory and genuinely immersive. At commit 67b1f7f, the measured direct KEMAR front speaker path, 3.9k P8.7 musical air and real FDN LP175 musical body work at 44.1/48k. These features cannot on their own guarantee headphone externalization (headphone-specific HRTFs, no head-tracking). + +## Research reasoning +2026 frontal externalization study reports level and early-reflection adjustment improve frontal virtual source externalization (https://pmc.ncbi.nlm.nih.gov/articles/PMC13451706/). True source width correlates more to appropriately directional EARLY lateral energy; envelopment correlates more with late diffuse energy (see https://doi.org/10.3390/app12062823 and https://doi.org/10.1038/s44384-025-00027-4). Unbounded late reverberation risks making speakers indistinct and appearing above/around the head; simply adding wet tails is wrong. + +## Scoped implementation +- One JUCE/native P8.2/P8.4 core, existing P8.6 six-wall horizontal focus and P8.7 air/body. NO stereo Haas, fake reverb, additional BRIR, worker, 2nd source, FFT, allocations or new public render-mode. +- ImerSipConcertStage.h makes only a 250–3800Hz TWO-pole-HP + TWO-pole-LP bounded lateral band from already spatialized directional early reflections. Maximum additional 4x of this *small MEASURED reflected early-side band* scales with current validated IMMERSION * VENUE SPACE * STAGE WIDTH. No extra signal at 0% mix, 0% venue space or 0% stage width. Gains slew 25ms. +- The initial 70% one-pole version passed but contributed just 0.0041 / 0.0044 source-relative RMS at full venue in 44.1 / 48k tests: plausibly inaudible. This revision calibrates the tiny ACTUAL directional ER band to a maximum 4x and uses two-pole HP/LP to reject excessive subbass/upper-diffuse gain; full/max and default PCM delta now have explicit minimum acceptance gates. This is not multiplying the whole mix by four. +- The additional signal is exactly L=-R, preserving existing dry MID, vocal mono fold-down and the original concert bass. It does not enhance late HF/diffuse FDN reverb, and the existing optional-enhancement headroom gate and global linked limiter remain authoritative. +- Explicit test-only A/B constructor lets tests measure the new stage versus same P8.7 core with no new lateral contribution, with exact 64/128/8192 audio chunk parity. No .smix v2 state layout change. UI knobs remain familiar and source-authoritative. + +## Qualification before owner FAT +44.1/48k: true binaural direct HRIR, P8.7-enabled output, independent 250-3800Hz lateral test, exact dual-ear mid cancellation, source-stage A/B PCM evidence, 0% space/width boundary, old mono vocals, anti-phase, real six-wall ER, bass 40–220Hz, high-peaks and chunk parity. Full Windows JUCE + PE/provenance and approved portable ZIP on SAME SHA needed before sharing a new test binary. Never claim more immersive just from PCM difference; level-matched physical headphones decide. diff --git a/docs/IMERSIP_REAL_ACOUSTIC_WET_NULL_TEST_20261115.md b/docs/IMERSIP_REAL_ACOUSTIC_WET_NULL_TEST_20261115.md new file mode 100644 index 000000000..98a554a4c --- /dev/null +++ b/docs/IMERSIP_REAL_ACOUSTIC_WET_NULL_TEST_20261115.md @@ -0,0 +1,37 @@ +# ImerSip: true acoustic wet and live PCM-evidence gate (15 Nov 2026) + +User's real headphone verdict: effect remained virtually unchanged even as the +ImerSip implementation grew. The previous ImerSip calculated actual SonKu +P8.4 directional HRIR and P8.2 room but multiplied its already downmixed +wet SIDE by a second gain ~0.05 at default. The existing tests only proved +a near-zero numerical difference, not useful acoustics. Neither equal-looking +VU meters nor a successful SPSC ACK proves an effect is audible. + +## Architectural repair +One existing native SonKuSpatialCore, same P8.2 six-wall image reflections +and same 3-band 8-line FDN. Its process method optionally copies already +computed EARLY and LATE stereo returns into a fixed 8192-sample array owned +by ImerSip; ordinary SonKu uses nullptr. No second DSP, no second reverb, +no additional 140-tap FIR, no callback allocation/mutex/FFT. + +The ImerSip mixer now has independently slewed actual early/late returns, +P8.4 directional SIDE, and source direct L/R. The acoustic return is +highpassed at 220Hz (early) and 160Hz (late) so low-end pressure is provided +by existing coherent LF shelf, not phase-sensitive delayed bass. Only 32% +of early MID and 12% of late MID is blended; direct vocal is still +predominant. Source stays 1.6m; room remains large; no rotating sound, +new mute, global AGC or fake browser audio. + +Add the real callback PCM delta energy ratio (and processed frame count) to +JUCE editor; distinguish NO PCM CALLBACK, SILENT INPUT, and nonzero +LIVE PCM DELTA -xx dB. This tests actual callback, not just slider/ACK. +New tests exercise 44.1/48k real PCM mono, independent and anti-correlated +stereo and require full room DIFFERENCE to original input above -24dB +RMS (source independent, tonal boosts OFF). This does not prove perceived +3D sound quality or externalization. Need loudness-matched owner audition +against verified SonKu P8.4 baseline and true peak/CPU FAT before release. + +Do not merge into main or claim sound success while owner reports it is bad. + +## Default preset audibility fix +Prior default Immersion 58% / Venue Space 45% left an already-weak room below the dedicated -32dB musical delta gate even though MAX settings passed. The new default is 82% / 65%, with unchanged 1.6m source and original direct stereo MID. The default null test uses the actual C++ Settings initializer, *not* duplicated numbers, so old near-bypass defaults cannot return unnoticed. Existing saved .smix is intentionally not silently overwritten; controls still need actual PCM delta readback. No claim of superior acoustic quality until owner FAT. diff --git a/docs/IMERSIP_SOURCE_MID_FIDELITY_GATE_20261116.md b/docs/IMERSIP_SOURCE_MID_FIDELITY_GATE_20261116.md new file mode 100644 index 000000000..7b13259dc --- /dev/null +++ b/docs/IMERSIP_SOURCE_MID_FIDELITY_GATE_20261116.md @@ -0,0 +1,19 @@ +# ImerSip v5 — source-MID music-fidelity gate (2026-11-16) + +## Evidence and scope + +The owner rejected a muffled, mid-forward, weak-bass, near-mono headphone presentation. Spectral tests of the BASS and AIR knobs alone cannot detect coloring caused by the measured direct HRTF path. Under `STEREO KEEP=100%`, `ImerSipDsp::process` previously added the full high-passed `deltaMid` between measured KEMAR stereo direct and original dry headphones. Its four 480 Hz high-pass stages still admitted upper vocal MID energy. + +## Bounded audio correction + +ImerSip alone now applies an additional three-pole 3200 Hz complementary high-pass to only the measured direct **MID difference**. The existing original dry MID remains primary at 500-2600 Hz. Measured direct **SIDE** is not attenuated by this change; high-frequency pinna-direction cues, source L/R bass, existing actual six-wall early returns and single 3-band FDN remain present. No new graph, second reverb, delayed bass crossfeed, heap allocation, modelled 'subwoofer', or device callback was introduced. Both smoothing coefficients and filter states are prepared/reset at supported 44.1/48 kHz rates. + +This is an engineering candidate, **not** a headphone-validated improvement. Naturalness, vocal clarity, physical bass and externalization need a loudness-matched owner A/B. Higher binaural delta does not establish quality. + +## Objective gate + +New `verifyDrySourceVocalMidFidelity` checks the ORIGINAL source MID level for mono fixtures at 500, 1100, 1900, and 2600 Hz, at narrow and maximum stereo width, room and tonal controls OFF, 44.1/48 kHz, both 128 and 64 frame chunks. Target 0.89–1.12 relative MID RMS (level, **not** a promise of spectral transparency). Existing real HRTF, full-width SIDE, mono/anti-phase, room wet-delta, bass, AIR, peak, chunk parity, native state ACK and Windows JUCE gates remain mandatory. + +## Hold and comparison + +Do not retarget/merge PR #706 to production `main` or mix P9.1/P9.2 experimental world-bass code until physical headphone listening and exact Windows binary verification. Use equal-playback-loudness comparison: bypass all other spatial FX, compare original music and user-preferred SonKu P8.4 at identical volume, then ImerSip. Inspect vocal 1–4 kHz, low-frequency impact, treble detail, front-stage separation, and room decay as separate dimensions. The default preset values and saved IMRS v1–v5 state are unchanged by this tonal transfer fix. diff --git a/docs/IMERSIP_STEREO_FIRST_REAL_CONTROLS_FIELD_FAT_20261115.md b/docs/IMERSIP_STEREO_FIRST_REAL_CONTROLS_FIELD_FAT_20261115.md new file mode 100644 index 000000000..8929379b9 --- /dev/null +++ b/docs/IMERSIP_STEREO_FIRST_REAL_CONTROLS_FIELD_FAT_20261115.md @@ -0,0 +1,25 @@ +# ImerSip P0 — stereo-first MUSIC STAGE + physically effective controls +2026-11-15. Research only. Source-of-truth user FAT: prior P8.7 and P8.9 screenshot combinations at ~7m room source, -19.4° KEMAR ear alignment, and 100% reflections/reverb still had poor sound externalization relative to dearVR; ImerSip previous "all knobs max" sounded near-mono and worse than original stereo. Never call that a passed listening experience. + +## Correct engineering goal +Stereo musical fidelity FIRST, externalized direct speaker orientation and physically measured room distance SECOND. No false assertion that P8.7 is dearVR quality. Official Sennheiser dearVR PRO2 info explains independent source distance, early reflections, late room and adjustable CLARITY as separate functions (https://help.sennheiser.com/hc/en-us/articles/27424692616594-How-to-produce-natural-immersive-music-with-the-CLARITY-modul-of-dearVR-PRO2). The comparator is *human listening at equal loudness*, not large PCM delta. + +## Specific root defects repaired +- Former stage WIDTH default 95% = 97/100°, leaving just 3° to max. New 32–126° front arc, default ~96°, with marked knob/source auditory difference. +- Former fixed virtual SOURCE distance 1.6 m regardless of user "externalize" intent. New 1.6–7.4m control maps to SonKu sourceDistanceMeters and actual wall path-time/level in SAME P8.2 early/FDN core, default ~5.08m. +- Old P8.7 height correction could be achieved only by moving physical XYZ source down toward the floor. ImerSip-only true KEMAR 3D direct HRIR trim -30..+20° is independent of physical room XYZ; default 0°, no hidden override of user's anatomy. At -19.5° tests compare actual ear PCM, not GUI animation. Ordinary SonKu rendering is unchanged. +- EARLY SPACE can now be exactly zero while LATE TAIL independently remains available. No hidden 20% early baseline. Max gains enlarged with core and optional output protection. +- Stereo KEEP retains original M/S music separation; more HRTF SIDE transfer is optional, not forced on all stereo content. Contrast with previous near-mono FAT. +- Tonal knobs with deliberately useful end stops: strong but bounded coherent original LF and ~2dB HF DETAIL above 5.6kHz. No synthetic bass oscillator, second FDN, FIR, FFT, graph reroute or new native engine. +- The former GUI deferred slider changes until mouse-up. New JUCE sliders queue the most recent edit through SPSC at up to 25Hz, completion ACK remains native audio-applied. Two horizontal source controls added to compact stage view, alongside eight correctly labelled rotary controls, A/B original, music-default, stereo meter. +- IMRS v5 (52-byte) carries distance and ear align; v1-v4 accepted sessions restore with independently initialized safe defaults. No overwrite of saved .smix, no auto mute. +- Windows portable package metadata now reports the ACTUAL 52-byte schema, 32–126° angle, 1.6–7.4 m distance and -30..+20° HRTF trim. Earlier stale v2 provenance had incorrectly marked a newly built binary as old 175°/1.6m renderer. + +## Required gates +Native PCM 44.1/48k true stereo hard-pan/anti-phase/source MID, real speaker depth and angle sensitivity, 3D KEMAR elevation transfer, six-wall room path/FDN tails, exact bypass, output peak guard, chunk parity, SonKu P8.2 normal-path unchanged. Native JUCE real FX Picker, on-control PCM edit/ACK/readback, v1-v5 state restore, true Windows PE & exact same-commit portable artifact mandatory BEFORE a user FAT ZIP is promoted. + +## Listening acceptance, not an algorithmic claim +A/B the ORIGINAL at the SAME monitoring loudness. Start with ~75% IMMERSION, 90–100° stage, 4.5–5.5m depth, EAR ALIGN 0° (audition gradual -10, -15, -19.5° separately), STEREO KEEP 100% and EARLY~50–70, LATE~20–35, OUTPUT 0 dB. Compare mono vocal focus, preservation of independent musical left/right, all transients, kick, ease of positioning speaker outside head. Do not maximize OUTPUT along with reverberation or mistake limiting for externalization. If the listener still hears it above/inside the head, the candidate is not acceptable merely because its numerical DSP tests passed. Generic non-individual KEMAR cannot guarantee another listener's exact pinna/head response. + +## Isolation +Keep PR #706 draft until user approves headphones. Do not merge SonKu P8.3 experimental ancestry or change ASIO/WASAPI routing, device-recovery work (#713), GUI styling on other branches, or public release. diff --git a/engine/builtin_fx/ImerSipConcertStage.h b/engine/builtin_fx/ImerSipConcertStage.h new file mode 100644 index 000000000..ebed90e57 --- /dev/null +++ b/engine/builtin_fx/ImerSipConcertStage.h @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include + +// ImerSip-specific concert width from *already rendered* P8.6 directional +// early wall reflections. No synthetic delay, decorrelator, new reverb, +// extra HRTF, new audio bus, FFT, phase inversion, or worker. The existing +// stereo direct front speakers and original bass are the authorities. +// +// Two-pole 250 Hz highpass + two-pole 3800 Hz lowpass isolate the +// true early-lateral musical presence band. Sub-bass and the P8.7 +// measured-direct air band are strongly suppressed. +// The enhancement is MID-orthogonal: additional left == -additional right. +// Therefore mono fold-down, center vocal pressure and original dry remain +// exactly unchanged by THIS stage. This is a private audition candidate. +namespace armix::imersip { +class ConcertStage final { +public: + struct Ears {float left=0.f,right=0.f;}; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate) || + (std::abs(rate-44100.)>.1 && std::abs(rate-48000.)>.1)) + return false; + constexpr double twoPi=6.2831853071795864769; + lowerAlpha_=static_cast(1.-std::exp(-twoPi*250./rate)); + upperAlpha_=static_cast(1.-std::exp(-twoPi*3800./rate)); + slew_=static_cast(1.-std::exp(-1./(rate*.025))); + reset(); + return true; + } + void setScene(float immersion,float room,float width) noexcept { + // Called only with validated ImerSip settings on the native + // control path or SPSC audio edit. Affine, bounded, no exp/pow. + // Real P8.6 ER energy was only ~0.004 RMS of source even with the + // first 70% lift. A calibrated 6x lateral *reflected* component, + // NOT 4x master/dry gain, gives a measurable musical room presence + // without reviving the ceiling/floor or late FDN wash. + target_=6.0f*immersion*room*width; + } + void reset() noexcept { + low250First_=low250Second_=0.f; + low3800First_=low3800Second_=0.f; + gain_=target_; + } + Ears process(float measuredEarlyL,float measuredEarlyR) noexcept { + const float side=.5f*(measuredEarlyL-measuredEarlyR); + low250First_+=lowerAlpha_*(side-low250First_); + const float hp1=side-low250First_; + low250Second_+=lowerAlpha_*(hp1-low250Second_); + const float hp2=hp1-low250Second_; + low3800First_+=upperAlpha_*(hp2-low3800First_); + low3800Second_+=upperAlpha_*(low3800First_-low3800Second_); + gain_+=slew_*(target_-gain_); + const float lateral=gain_*low3800Second_; + return {lateral,-lateral}; + } + float targetGain() const noexcept{return target_;} +private: + float lowerAlpha_=0.f,upperAlpha_=0.f,slew_=0.f; + float low250First_=0.f,low250Second_=0.f; + float low3800First_=0.f,low3800Second_=0.f; + float gain_=0.f,target_=0.f; +}; +} // namespace armix::imersip diff --git a/engine/builtin_fx/ImerSipDsp.h b/engine/builtin_fx/ImerSipDsp.h new file mode 100644 index 000000000..a8f5bb744 --- /dev/null +++ b/engine/builtin_fx/ImerSipDsp.h @@ -0,0 +1,367 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "ImerSipPhaseSafe.h" +#include "ImerSipConcertStage.h" +#include "sonku/SonKuSpatialCore.h" +#include "sonku/SonKuP87MusicalAirBody.h" +#include +#include +#include + +// Single measured P8.2/P8.4 core + P8.6 front-focused walls, genuine P8.7 +// direct air/FDN body + bandlimited concert-stage lateral early reflection. +// No dry SIDE widening, fake echoes, second callback, runtime heap or FFT. +namespace armix::imersip { + +inline armix::sonku::Settings sceneFor(const Settings& in) noexcept { + armix::sonku::Settings s{}; + s.moving=false; // Never auto-orbit music + s.startAzimuthDegrees=0.f; // Front stationary anchor + // Owner-requested 180-degree endpoint reaches measured +/-90 KEMAR + // directions. 180 is a LATERAL speaker extreme (not a guarantee of + // frontal externalization). UI uses this identical 30..180 mapping. + s.stereoSpreadDegrees=30.f+150.f*in.width; + s.spatialMix=.75f*in.immersion; // SonKu internal HRIR, direct explicitly exported + s.outputTrim=1.f; // Final trim belongs to ImerSip + s.spacePreset=in.immersion==0.f?0:(in.venue==2?2:3); + // The original always-fixed 1.6m was the missing externalization + // dimension. Depth now drives actual measured six-wall path geometry + // (and the physical source radius) from 1.6m to 7.4m, always at + // listener ear height. No false room rotation or new audio graph. + s.sourceDistanceMeters=1.6f+5.8f*in.depth; + // Detail-first front-row hall: prioritize six-wall EARLY reflections + // (external cues) above diffuse LATE decay (mid masking). + // The original P8.2 room model remains the only acoustic engine. + // ZERO early control is real zero, not the old hidden 20% baseline. + // Headroom is normalized by the measured early-reflection PCM and + // independent FDN/phase protection, not by a second room simulator. + s.roomAmount=in.immersion==0.f?0.f: + (in.venue==1?.77f:in.venue==2?.72f:.88f)*in.space; + // Independent physical late FDN level: old SPACE knob silently boosted + // early + late together and made fully-maxed sessions sound washed out. + s.ambience=in.immersion==0.f?0.f: + (in.venue==1?.52f:in.venue==2?.48f:.56f)*in.lateRoom; + return s; +} + +class ImerSipDsp final { +public: + // Source-test A/B disables P8.7 while preserving exact shared geometry. + explicit ImerSipDsp(bool musicalAirBody=true, + bool concertStage=true) noexcept + : p87Enabled_(musicalAirBody),concertStageEnabled_(concertStage) {} + bool prepare(double rate) noexcept { + ready_=false; +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH \ + && defined(SONKU_P80_TRANSPARENT_BASS_RESEARCH) && SONKU_P80_TRANSPARENT_BASS_RESEARCH \ + && defined(SONKU_P75_MUSIC_SAFE_RESEARCH) && SONKU_P75_MUSIC_SAFE_RESEARCH \ + && defined(SONKU_P7_MEASURED_ELEVATION_RESEARCH) && SONKU_P7_MEASURED_ELEVATION_RESEARCH + ready_=core_.prepare(rate, + armix::sonku::SonKuReflectionProfile::SixSurfaceKemarResearch); + if(ready_)ready_=core_.setSettings(sceneFor(settings_)); + // An actual pair of measured virtual loudspeakers at +/- width/2. + // P8.2's default center-MID path is untouched for ordinary SonKu. + // We take only L-R binaural difference; direct music MID remains dry. + if(ready_)ready_=core_.enableImerSipMeasuredStereoSide(true); + if(ready_)ready_=core_.setImerSipDirectHrtfElevationTrim( + settings_.earAlignDegrees); + if(ready_)ready_=enhancer_.prepare(rate); + if(ready_)ready_=enhancer_.setSettings(settings_); + if(ready_)ready_=p87Body_.prepare(rate); + if(ready_)ready_=concertStage_.prepare(rate); + if(ready_) { + stageSlew_=static_cast(1.-std::exp(-1./(rate*.018))); + trimSlew_=static_cast(1.-std::exp(-1./(rate*.024))); + constexpr double pi=3.14159265358979323846; + earlyHp_=static_cast(1.-std::exp(-2.*pi*220./rate)); + lateHp_=static_cast(1.-std::exp(-2.*pi*160./rate)); + // Four-pole 480Hz difference HP expands speaker midrange + // relative to 700Hz while retaining the old strict LF tests. + directHp_=static_cast(1.-std::exp(-2.*pi*480./rate)); + // The original music MID is the timbral reference. An + // additional three-pole 3.2 kHz HP admits high-pinna HRTF + // differences but suppresses the 1-3 kHz center-vocal + // coloration that a 480 Hz crossover alone admitted. + // Prepared once; only affine one-pole updates on PCM. + directMidHp_=static_cast(1.-std::exp(-2.*pi*3200./rate)); + limiterRelease_=static_cast(1./(rate*.080)); + compareSlew_=static_cast(1.-std::exp(-1./(rate*.020))); + for(auto& ear:directDifferenceLow_)ear.fill(0.f); + directMeasuredSideLow_.fill(0.f); + directMidLow_.fill(0.f); + earlyLow_.fill(0.f);lateLow_.fill(0.f); + finalLimiter_=1.f; + updateTargets(settings_); + directGain_=directTarget_; + stereoKeep_=stereoKeepTarget_; + compareDryGain_=compareDryTarget_; + earlyGain_=earlyTarget_; + lateGain_=lateTarget_; + outputGain_=settings_.outputTrim; + core_.reset(); + enhancer_.reset(); + p87Body_.reset(); + concertStage_.reset(); + } +#endif + return ready_; + } + bool setSettings(const Settings& next) noexcept { + if(!valid(next))return false; + if(ready_ && !core_.setSettings(sceneFor(next)))return false; + if(ready_ && !core_.setImerSipDirectHrtfElevationTrim( + next.earAlignDegrees))return false; + if(!enhancer_.setSettings(next))return false; + settings_=next; + updateTargets(next); + return true; + } + Settings settings() const noexcept {return settings_;} + // Transient monitor audition only: does not alter accepted settings, + // .smix or the source/DSP graph. Called once before each audio block. + void setCompareDry(bool dry) noexcept {compareDryTarget_=dry?1.f:0.f;} + bool ready() const noexcept {return ready_;} + bool measuredStereoStageEnabled() const noexcept { + return ready_ && core_.imersipMeasuredStereoSideEnabled(); + } + + void process(float* left,float* right,int frames) noexcept { + if(!ready_||!left||!right||frames<=0)return; + int at=0; + double sourceEnergy=0.,outputEnergy=0.,deltaEnergy=0.; + double originalSideEnergy=0.,processedSideEnergy=0.; + while(at0.f) + p87Body_.enhanceDirect(hrL,hrR); + float deltaL=hrL-dryL; + float deltaR=hrR-dryR; + for(int pole=0;pole<4;++pole) { + auto& lowL=directDifferenceLow_[0][pole]; + auto& lowR=directDifferenceLow_[1][pole]; + lowL+=directHp_*(deltaL-lowL); + lowR+=directHp_*(deltaR-lowR); + deltaL-=lowL; + deltaR-=lowR; + } + // Preserve original stereo SIDE as the authoritative direct + // source while rendering a separate, band-limited binaural + // speaker contrast. Keep mode must not turn off the HRTF. + float deltaMid=.5f*(deltaL+deltaR); + const float deltaSide=.5f*(deltaL-deltaR); + // MID and SIDE need different psychoacoustic admission. + // Preserve original vocal body and instrument timbre + // while retaining the upper pinna/front HRTF MID cue. + // This does NOT attenuate measured directional SIDE. + for(auto& low:directMidLow_) { + low+=directMidHp_*(deltaMid-low); + deltaMid-=low; + } + // Previous Stereo Keep=100% multiplied measured HRTF SIDE + // by only 0.10: music was protected by effectively + // disabling directional externalization. Treat fidelity + // and binaural speaker contrast as INDEPENDENT axes. + // In Keep mode the music's original stereo SIDE remains + // exactly present; a band-limited measured KEMAR SIDE is + // added at bounded 45% strength, NOT a subtractive dry + // replacement. No fake Haas delay or decorrelated signal. + float measuredSide=.5f*(hrL-hrR); + for(int pole=0;pole<4;++pole) { + auto& low=directMeasuredSideLow_[pole]; + low+=directHp_*(measuredSide-low); + measuredSide-=low; + } + const float keep=std::clamp(stereoKeep_,0.f,1.f); + // Make STAGE WIDTH a true directional source control: + // the measured +/-90 degree interaural SIDE has a larger + // admitted contribution than the narrower +/-15 degree + // pair, without artificially widening original music SIDE. + // Mono remains center-projected and strictly mono. Keep + // original stereo bed full-level at every knob position. + const float measuredSpeakerGain=.20f+.40f*settings_.width; + const float directionalSide=directGain_*( + (1.f-keep)*deltaSide+ + keep*measuredSpeakerGain*measuredSide); + const float baseL=dryL+directGain_*deltaMid+ + directionalSide; + const float baseR=dryR+directGain_*deltaMid- + directionalSide; + earlyLow_[0]+=earlyHp_*(wet.earlyL-earlyLow_[0]); + earlyLow_[1]+=earlyHp_*(wet.earlyR-earlyLow_[1]); + lateLow_[0]+=lateHp_*(wet.lateL-lateLow_[0]); + lateLow_[1]+=lateHp_*(wet.lateR-lateLow_[1]); + const float erL=wet.earlyL-earlyLow_[0]; + const float erR=wet.earlyR-earlyLow_[1]; + const float revL=wet.lateL-lateLow_[0]; + const float revR=wet.lateR-lateLow_[1]; + // Real eight-line FDN LP175 body. Existing bassImpact shelf + // already supplies original music LF: do NOT add P8.7 +9%. + const auto body=(p87Enabled_ && settings_.immersion>0.f) + ?p87Body_.diffuseLowBody(wet.lateL,wet.lateR) + :armix::sonku::p87::MusicalAirBody::Ears{}; + const float erMid=.5f*(erL+erR),erSide=.5f*(erL-erR); + // Source-accurate four horizontal walls are already in ER. + // Selectively increase 250-3800 Hz LATERAL *early* energy + // for musical source width; do not widen original dry or + // boost the late diffuse soundfield (envelopment != width). + const auto lateral=concertStage_.process(wet.earlyL,wet.earlyR); + const float revMid=.5f*(revL+revR); + const float revSide=.5f*(revL-revR); + // P8.6 horizontal early reflections support the DIRECT + // speakers; diffuse late tail is deliberately restrained. + // Measured six-wall early MID is a distance cue for a + // centered source, not a replacement direct vocal EQ. + // With source MID protected, the old .40 early MID left + // mono material near-dry even in full Concert space. + // Admit modestly more TRUE early reflection pressure; + // leave diffuse late MID at .10 to avoid a boxy wash. + constexpr float earlyCenterPresence=.62f; + float addL=earlyGain_*(erSide+earlyCenterPresence*erMid)+ + lateGain_*(revSide+.10f*revMid+body.left)+ + (concertStageEnabled_?lateral.left:0.f); + float addR=earlyGain_*(-erSide+earlyCenterPresence*erMid)+ + lateGain_*(-revSide+.10f*revMid+body.right)+ + (concertStageEnabled_?lateral.right:0.f); + // Preserve the *direct binaural substitution* at high input + // level: only the ADDITIONAL room returns are headroom-gated. + const float headroom=std::max(0.f,.98f- + std::max(std::abs(baseL),std::abs(baseR))); + const float peakExtra=std::max(std::abs(addL),std::abs(addR)); + if(peakExtra>headroom && peakExtra>0.f) { + const float scale=headroom/peakExtra; + addL*=scale;addR*=scale; + } + float l=baseL+addL,r=baseR+addR; + enhancer_.process(l,r,sourceStereoGate_[i],dryL,dryR); + // A/B compares actual untouched ORIGINAL L/R vs DSP using + // the SAME output trim (not an automatic loudness match). + // Compare gain slews 20ms and never changes .smix. + const float dryWithTrimL=dryL*outputGain_; + const float dryWithTrimR=dryR*outputGain_; + l=l*outputGain_*(1.f-compareDryGain_)+ + dryWithTrimL*compareDryGain_; + r=r*outputGain_*(1.f-compareDryGain_)+ + dryWithTrimR*compareDryGain_; + // Linked zero-lookahead sample-peak protection. A 100% + // binaural direct stage must not silently revert to dry when + // the music approaches 0dBFS. No gain changes under unity. + const float peak=std::max(std::abs(l),std::abs(r)); + const float immediate=peak>.98f?.98f/peak:1.f; + finalLimiter_=std::min(immediate, + std::min(1.f,finalLimiter_+limiterRelease_)); + l*=finalLimiter_;r*=finalLimiter_; + left[at+i]=l;right[at+i]=r; + // Lock-free BLOCK diagnostic of actual rendered PCM, NOT + // an optimistic GUI knob or a parameter ACK by itself. + const double inL=dryL,inR=dryR; + const double dl=l-inL,dr=r-inR; + sourceEnergy+=inL*inL+inR*inR; + outputEnergy+=l*l+r*r; + deltaEnergy+=dl*dl+dr*dr; + // Per-block stereo preservation, normalized for final gain. + // Never call a large PCM delta an improvement in fidelity. + originalSideEnergy+=static_cast(side_[i])*side_[i]; + const float norm=std::max(1.e-6f,outputGain_*finalLimiter_); + const double normalizedSide=.5*(l-r)/norm; + processedSideEnergy+=normalizedSide*normalizedSide; + } + at+=count; + } + lastInputEnergy_=static_cast(sourceEnergy/(2.*frames)); + lastOutputEnergy_=static_cast(outputEnergy/(2.*frames)); + lastDifferenceEnergy_=static_cast(deltaEnergy/(sourceEnergy+1.e-14)); + lastStereoRetention_=originalSideEnergy>1.e-10? + static_cast(std::sqrt(processedSideEnergy/originalSideEnergy)): + -1.f; // centered MONO input has no original stereo to retain + } + float lastInputEnergy() const noexcept {return lastInputEnergy_;} + float lastOutputEnergy() const noexcept {return lastOutputEnergy_;} + float lastDifferenceEnergy() const noexcept {return lastDifferenceEnergy_;} + float lastStereoRetention() const noexcept {return lastStereoRetention_;} +private: + void updateTargets(const Settings& s) noexcept { + // Immersion is now chiefly DIRECT virtual speaker transfer, not + // a reverb-gain shortcut. Nonlinear fade reaches 100% true binaural + // at the end stop while retaining smooth 0% exact-dry admission. + directTarget_=s.immersion*(2.f-s.immersion); + // Both levers are independently audible. Depth modifies real + // source-wall delays; it also increases ratio of anchored ER to + // unchanged original stereo direct as the stage moves farther. + // These levels are small measured reflections, NOT dry gain. + // A small LIVE ROOM must not recycle hall-scale lateral ER gain. + // At full 180° two real KEMAR SIDE cues already provide separation; + // excessively strong signed reflection SIDE in venue=2 physically + // opposed dry music SIDE on independent-stereo test material. + // Calibrate a per-venue ER envelope (still 0..100% user-tweakable), + // never turn off actual direct speaker HRIR or alter ordinary SonKu. + const float lateralRoomScale=s.venue==2?.25f: + s.venue==1?.82f:1.f; + earlyTarget_=s.immersion*(2.60f*s.space)* + (1.f+.55f*s.depth)*lateralRoomScale; + lateTarget_=s.immersion*(1.0f*s.lateRoom); + // KEEP is now source-stereo preservation, NOT an inverse spatial + // strength dial. 100% keeps original SIDE + bounded measured HRIR + // directional contribution. 0% retains the older full transfer. + stereoKeepTarget_=s.stereoLock; + // Same physical ER energy budget for concert-stage SIDE as for + // early room. Two independent 6x and 4x stacks are not allowed. + concertStage_.setScene(s.immersion,s.space*lateralRoomScale,s.width); + } + static constexpr int scratchFrames=8192; + armix::sonku::SonKuSpatialCore core_{}; + PhaseSafeEnhancer enhancer_{}; + armix::sonku::p87::MusicalAirBody p87Body_{}; + ConcertStage concertStage_{}; + const bool p87Enabled_=true,concertStageEnabled_=true; + std::array + roomReturns_{}; + std::array sourceStereoGate_{},mid_{},side_{}; + std::array earlyLow_{},lateLow_{}; + std::array,2> directDifferenceLow_{}; + std::array directMeasuredSideLow_{}; + std::array directMidLow_{}; + Settings settings_{}; + float stageSlew_=0.f,trimSlew_=0.f; + float earlyHp_=0.f,lateHp_=0.f,directHp_=0.f,directMidHp_=0.f; + float directGain_=0.f,directTarget_=0.f; + float stereoKeep_=1.f,stereoKeepTarget_=1.f; + float compareDryGain_=0.f,compareDryTarget_=0.f,compareSlew_=0.f; + float finalLimiter_=1.f,limiterRelease_=0.f; + float earlyGain_=0.f,earlyTarget_=0.f; + float lateGain_=0.f,lateTarget_=0.f; + float outputGain_=1.f; + float lastInputEnergy_=0.f,lastOutputEnergy_=0.f,lastDifferenceEnergy_=0.f; + float lastStereoRetention_=-1.f; + bool ready_=false; +}; +} // namespace armix::imersip diff --git a/engine/builtin_fx/ImerSipEditor.h b/engine/builtin_fx/ImerSipEditor.h new file mode 100644 index 000000000..32d81c552 --- /dev/null +++ b/engine/builtin_fx/ImerSipEditor.h @@ -0,0 +1,579 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +// Included from ImerSipProcessor.h after ImerSipProcessor is fully defined. +// The standard JUCE plugin editor is hosted by the EXISTING FxEditorWindow. +// UI gesture -> bounded SPSC -> native audio callback -> completion/readback. +// The editor cannot directly mutate audio-thread DSP state. +#include +#include +#include +#include +#include + +namespace armix::builtin_fx { +class ImerSipLook final : public juce::LookAndFeel_V4 { +public: + void drawRotarySlider(juce::Graphics& g,int x,int y,int w,int h, + float pos,float start,float end,juce::Slider&) override { + const float cx=x+w*.5f,cy=y+h*.5f; + const float radius=std::min(w,h)*.37f; + const auto ink=juce::Colour(0xff58cfaa); + juce::Path track,active; + track.addCentredArc(cx,cy,radius,radius,0.f,start,end,true); + active.addCentredArc(cx,cy,radius,radius,0.f,start, + start+pos*(end-start),true); + g.setColour(juce::Colour(0xffa2b9bd)); + g.strokePath(track,juce::PathStrokeType(3.f)); + g.setColour(ink); + g.strokePath(active,juce::PathStrokeType(3.f)); + juce::ColourGradient silver(juce::Colour(0xfffaffff),cx,cy-radius, + juce::Colour(0xffb4c7cc),cx,cy+radius,false); + g.setGradientFill(silver); + g.fillEllipse(cx-radius*.74f,cy-radius*.74f, + radius*1.48f,radius*1.48f); + g.setColour(juce::Colour(0xff789aa2)); + g.drawEllipse(cx-radius*.74f,cy-radius*.74f, + radius*1.48f,radius*1.48f,1.f); + const float a=start+pos*(end-start); + const juce::Point center(cx,cy); + const auto tip=center+juce::Point(std::sin(a)*radius*.58f, + -std::cos(a)*radius*.58f); + const auto base=center+juce::Point(std::sin(a)*radius*.18f, + -std::cos(a)*radius*.18f); + g.setColour(juce::Colour(0xff244e59)); + g.drawLine(base.x,base.y,tip.x,tip.y,2.6f); + } + void drawButtonBackground(juce::Graphics& g,juce::Button& b, + const juce::Colour&,bool hover,bool pressed) override { + const auto bounds=b.getLocalBounds().toFloat().reduced(.5f); + const bool on=b.getToggleState(); + const bool head=b.getComponentID()=="imersip.power"|| + b.getComponentID()=="imersip.close"; + g.setColour(head?(on?juce::Colour(0xff2f7469): + hover?juce::Colour(0xff365f69):juce::Colour(0xff294b55)): + on?juce::Colour(0xff529d8c): + hover?juce::Colour(0xffe4f1f0):juce::Colour(0xffedf4f4)); + g.fillRoundedRectangle(bounds,5.f); + g.setColour(head?juce::Colour(0xff80cabb): + on?juce::Colour(0xff2d8776): + pressed?juce::Colour(0xff7ca3a8):juce::Colour(0xffadc3c7)); + g.drawRoundedRectangle(bounds,5.f,1.f); + } +}; + +class ImerSipEditor final : public juce::AudioProcessorEditor, + private juce::Timer { +public: + static constexpr int editorWidth=980,editorHeight=560; + static armix::imersip::Settings factoryPreset(int id) noexcept { + armix::imersip::Settings s{}; + switch(id) { + case 3: // Warm Hi-Fi: dry bass, controlled wet room + s.immersion=.88f;s.width=.74f;s.space=.62f; + s.lateRoom=.15f;s.bassImpact=.90f;s.detail=.42f; + s.depth=.70f;break; + case 4: // Grand Concert: real wide speakers, controlled hall + s.immersion=.96f;s.width=.92f;s.space=.90f; + s.lateRoom=.31f;s.bassImpact=.73f;s.detail=.65f; + s.depth=.88f;break; + case 5: // Open & Sparkling + s.immersion=.96f;s.width=1.f;s.space=.76f; + s.lateRoom=.18f;s.bassImpact=.72f;s.detail=.91f; + s.depth=.80f;break; + case 6: // Studio Reference, low room for clean A/B + s.immersion=.68f;s.width=.70f;s.space=.28f; + s.lateRoom=.05f;s.bassImpact=.40f;s.detail=.38f; + s.depth=.55f;break; + default:break; + } + return s; + } + void bindHostPower(std::function request, + std::function readback) { + hostBypassRequest_=std::move(request); + hostBypassReadback_=std::move(readback); + power_.setEnabled(static_cast(hostBypassRequest_) && + static_cast(hostBypassReadback_)); + refreshHostPower(); + } + void resetTransientComparison() noexcept { + originalAb_.setToggleState(false,juce::dontSendNotification); + fx_.setCompareDry(false); + } + explicit ImerSipEditor(ImerSipProcessor& processor) + :juce::AudioProcessorEditor(processor),fx_(processor) { + setLookAndFeel(&look_); + preset_.setComponentID("imersip.preset"); + preset_.addItem("Custom",1); + preset_.addItem("Music Default",2); + preset_.addItem("Warm Hi-Fi",3); + preset_.addItem("Grand Concert",4); + preset_.addItem("Open & Sparkling",5); + preset_.addItem("Studio Reference",6); + preset_.setColour(juce::ComboBox::backgroundColourId, + juce::Colour(0xff31535f)); + preset_.setColour(juce::ComboBox::textColourId, + juce::Colour(0xfff0f9f7)); + preset_.setColour(juce::ComboBox::outlineColourId, + juce::Colour(0xff649e9a)); + preset_.setColour(juce::ComboBox::arrowColourId, + juce::Colour(0xffa7f1d7)); + preset_.onChange=[this] { + const auto id=preset_.getSelectedId(); + if(id<2||id>6)return; + resetTransientComparison(); + sync(factoryPreset(id)); + submit(); // one existing native ACK, not a second renderer + }; + addAndMakeVisible(preset_); + close_.setComponentID("imersip.close"); + close_.setButtonText("X"); + close_.setColour(juce::TextButton::textColourOffId,juce::Colours::white); + close_.onClick=[this] { + resetTransientComparison(); + if(auto* w=findParentComponentOfClass()) + w->closeButtonPressed(); + else setVisible(false); + }; + addAndMakeVisible(close_); + for(int i=0;i<3;++i) { + auto& button=venues_[static_cast(i)]; + button.setButtonText(i==0?"CONCERT HALL":i==1?"CINEMA":"LIVE ROOM"); + button.setClickingTogglesState(false); + button.setColour(juce::TextButton::textColourOffId, + juce::Colour(0xff244b58)); + button.setColour(juce::TextButton::textColourOnId, + juce::Colours::white); + button.onClick=[this,i]{venue_=i;refreshVenues();submit();}; + addAndMakeVisible(button); + } + // The previous 6-knob editor hid stereo fidelity and linked early + // and late energy; maxing all knobs could make music nearly mono. + const char* names[]{"IMMERSION","STAGE WIDTH","EARLY SPACE","LATE TAIL", + "STEREO KEEP","BASS IMPACT","AIR DETAIL","OUTPUT"}; + const char* ids[]{"imersip.immersion","imersip.width","imersip.early", + "imersip.late","imersip.stereo","imersip.bass", + "imersip.air","imersip.output"}; + for(int i=0;i<8;++i) { + auto& slider=knobs_[static_cast(i)]; + slider.setComponentID(ids[i]); + slider.setSliderStyle(juce::Slider::RotaryHorizontalVerticalDrag); + slider.setTextBoxStyle(juce::Slider::NoTextBox,false,0,0); + slider.setRange(i==7?-12.:0.,i==7?3.5:100.,i==7?.1:1.); + slider.setRotaryParameters(juce::degreesToRadians(225.f), + juce::degreesToRadians(495.f),true); + slider.setDoubleClickReturnValue(true, + i==0?88.:i==1?67.:i==2?78.:i==3?25.: + i==4?100.:i==5?70.:i==6?60.:0.); + slider.onValueChange=[this,i]{ + refreshReadout(i); + preset_.setSelectedId(1,juce::dontSendNotification); + // Previously ALL DSP changes were postponed to mouse-up. + // During continuous rotary drag, feed the latest value to + // the 25Hz control→PCM SPSC queue, without flooding it. + if(knobs_[static_cast(i)].isMouseButtonDown()) { + deferred_=readControls();hasDeferred_=true; + } else submit(); + repaint(stage_); + }; + slider.onDragEnd=[this]{submit();}; + addAndMakeVisible(slider); + auto& cap=captions_[static_cast(i)]; + cap.setText(names[i],juce::dontSendNotification); + cap.setJustificationType(juce::Justification::centred); + cap.setFont(juce::FontOptions(9.f,juce::Font::plain)); + cap.setColour(juce::Label::textColourId,juce::Colour(0xff54747d)); + addAndMakeVisible(cap); + auto& value=values_[static_cast(i)]; + value.setJustificationType(juce::Justification::centred); + value.setFont(juce::FontOptions(12.f,juce::Font::plain)); + value.setColour(juce::Label::textColourId,juce::Colour(0xff183947)); + addAndMakeVisible(value); + } + // Depth is a REAL source-to-ear/wall distance: the old ImerSip + // renderer was hard-coded at 1.6m with no externalization dial. + depth_.setComponentID("imersip.depth"); + depth_.setSliderStyle(juce::Slider::LinearHorizontal); + depth_.setTextBoxStyle(juce::Slider::NoTextBox,false,0,0); + depth_.setRange(0.,100.,1.); + depth_.setDoubleClickReturnValue(true,78.); + depth_.onValueChange=[this]{ + preset_.setSelectedId(1,juce::dontSendNotification); + if(depth_.isMouseButtonDown()) { + deferred_=readControls();hasDeferred_=true; + } else submit(); + repaint(stage_); + }; + depth_.onDragEnd=[this]{submit();}; + addAndMakeVisible(depth_); + // Separate measured KEMAR DIRECT elevation; physical sources and + // six room-wall directions remain at ear height (no fake floor XYZ). + earAlign_.setComponentID("imersip.ear-align"); + earAlign_.setSliderStyle(juce::Slider::LinearHorizontal); + earAlign_.setTextBoxStyle(juce::Slider::NoTextBox,false,0,0); + earAlign_.setRange(-30.,20.,.5); + earAlign_.setDoubleClickReturnValue(true,0.); + earAlign_.onValueChange=[this]{ + preset_.setSelectedId(1,juce::dontSendNotification); + if(earAlign_.isMouseButtonDown()){ + deferred_=readControls();hasDeferred_=true; + }else submit(); + repaint(stage_); + }; + earAlign_.onDragEnd=[this]{submit();}; + addAndMakeVisible(earAlign_); + originalAb_.setButtonText("ORIGINAL / A-B"); + originalAb_.setClickingTogglesState(true); + originalAb_.setColour(juce::TextButton::textColourOffId, + juce::Colour(0xff244c57)); + originalAb_.setColour(juce::TextButton::textColourOnId, + juce::Colours::white); + originalAb_.onClick=[this] { + fx_.setCompareDry(originalAb_.getToggleState()); + status_=originalAb_.getToggleState() + ?"ORIGINAL SOURCE / A-B ON (NOT SAVED)" + :"PROCESSED OUTPUT / A-B OFF"; + repaint(); + }; + addAndMakeVisible(originalAb_); + musicalReset_.setButtonText("MUSIC DEFAULT"); + musicalReset_.setColour(juce::TextButton::textColourOffId, + juce::Colour(0xff244c57)); + musicalReset_.onClick=[this] { + resetTransientComparison(); + sync(factoryPreset(2)); + submit(); + }; + addAndMakeVisible(musicalReset_); + power_.setComponentID("imersip.power"); + power_.setButtonText("INSERT POWER"); + power_.setEnabled(false); // fail closed when not native-bound + power_.setColour(juce::TextButton::textColourOffId, + juce::Colours::white); + power_.setColour(juce::TextButton::textColourOnId, + juce::Colours::white); + power_.onClick=[this] { + if(!hostBypassRequest_||!hostBypassReadback_)return; + const bool wantBypassed=!hostBypassReadback_(); + if(hostBypassRequest_(wantBypassed)) { + status_=wantBypassed?"FX BYPASSED · NATIVE":"FX ENABLED · NATIVE"; + refreshHostPower(); + } else status_="POWER REJECTED · REFRESH FX RACK"; + repaint(); + }; + addAndMakeVisible(power_); + sync(fx_.acceptedSettings()); + status_="READY · NATIVE AUDIO CONTROLS"; + setSize(editorWidth,editorHeight); + startTimerHz(25); + } + + ~ImerSipEditor() override { + stopTimer(); + // Closing the popup must NEVER leave the signal monitor bypassed. + resetTransientComparison(); + setLookAndFeel(nullptr); + } + void paint(juce::Graphics& g) override { + g.fillAll(juce::Colour(0xff0e1c26)); + g.setColour(juce::Colour(0xff1e3c48)); + g.fillRect(0,0,getWidth(),72); + g.setColour(juce::Colour(0xff69d4ad)); + g.fillRect(0,71,getWidth(),1); + g.setColour(juce::Colour(0xffebf7fb)); + g.setFont(juce::FontOptions(17.f,juce::Font::plain)); + g.drawText("◇ ImerSip",22,17,158,30,juce::Justification::centredLeft); + g.setColour(juce::Colour(0xff91adbb)); + g.setFont(juce::FontOptions(11.f,juce::Font::plain)); + g.drawText("BINAURAL SPATIAL ENGINE · NATIVE FX", + 180,23,283,24,juce::Justification::centredLeft); + const auto stageBox=stage_.toFloat(); + const auto controls=juce::Rectangle(377.f,82.f,585.f,438.f); + g.setColour(juce::Colour(0xff122632)); + g.fillRoundedRectangle(stageBox,7.f); + g.setColour(juce::Colour(0xffd9e6e8)); + g.fillRoundedRectangle(controls,7.f); + g.setColour(juce::Colour(0xff2c4c5b)); + g.drawRoundedRectangle(stageBox,7.f,1.f); + g.setColour(juce::Colour(0xffafc4c7)); + g.drawRoundedRectangle(controls,7.f,1.f); + paintStage(g); + g.setColour(juce::Colour(0xff35616c)); + g.setFont(juce::FontOptions(10.5f,juce::Font::plain)); + g.drawText("VENUE",395,97,110,17,juce::Justification::centredLeft); + g.drawText("SPACE / DIRECTION",395,207,210,16, + juce::Justification::centredLeft); + g.drawText("FIDELITY / TONE",395,353,210,16, + juce::Justification::centredLeft); + g.setColour(juce::Colour(0xffafc5c8)); + g.drawLine(395.f,344.f,944.f,344.f,1.f); + g.setColour(juce::Colour(0xff5b7a83)); + g.setFont(juce::FontOptions(10.f,juce::Font::plain)); + // This toggles the individual native insert's bypassRequested; + // channel FX rack master power remains a separate host authority. + g.drawText("SLOT BYPASS · NATIVE FX / ORIGINAL A-B · TEMPORARY", + 395,499,542,15,juce::Justification::centred); + g.setColour(juce::Colour(0xff244452)); + g.fillRect(0,527,editorWidth,1); + g.setColour(juce::Colour(0xff84bbc7)); + g.drawText(status_,22,534,444,18,juce::Justification::centredLeft); + g.setColour(juce::Colour(0xff90d6e5)); + g.drawText(liveReadout_,470,534,290,18,juce::Justification::centredRight); + g.setColour(juce::Colour(0xff7da6b2)); + g.drawText("44.1 / 48 kHz · HEADPHONES",777,534,185,18, + juce::Justification::centredRight); + } + void resized() override { + stage_={18,82,346,438}; + for(int i=0;i<3;++i) + venues_[static_cast(i)].setBounds(394+i*185,120,172,36); + originalAb_.setBounds(395,169,168,29); + musicalReset_.setBounds(580,169,168,29); + preset_.setBounds(470,18,226,34); + power_.setBounds(717,18,170,34); + close_.setBounds(906,18,49,34); + depth_.setBounds(60,408,258,24); + earAlign_.setBounds(60,466,258,24); + const int xs[]{404,543,682,821,404,543,682,821}; + const int ys[]{224,224,224,224,370,370,370,370}; + for(int i=0;i<8;++i) { + const int x=xs[i],y=ys[i]; + knobs_[static_cast(i)].setBounds(x+17,y,91,81); + captions_[static_cast(i)].setBounds(x,y+84,127,17); + values_[static_cast(i)].setBounds(x,y+103,127,18); + } + } +private: + void paintStage(juce::Graphics& g) { + const float cx=191.f,cy=271.f,r=104.f; + g.setColour(juce::Colour(0xff80aebf)); + g.setFont(juce::FontOptions(11.f,juce::Font::plain)); + const float width=static_cast(knobs_[1].getValue())*.01f; + const int totalAngle=30+static_cast(std::round(width*150)); + const juce::String geometry=totalAngle>=150? + "LATERAL STAGE / ":"FRONT STAGE / "; + g.drawText(geometry+juce::String(totalAngle)+"°", + 71,113,238,19,juce::Justification::centred); + g.setColour(juce::Colour(0xff79bdc9)); + const float depth=static_cast(depth_.getValue())*.01f; + const float metres=1.6f+5.8f*depth; + g.drawText("SPEAKER DISTANCE "+juce::String(metres,1)+" m", + 54,381,274,18,juce::Justification::centred); + g.drawText("EAR ALIGN · KEMAR HRTF "+ + juce::String(earAlign_.getValue(),1)+"°", + 54,439,274,18,juce::Justification::centred); + g.setColour(juce::Colour(0xff234452)); + g.drawEllipse(cx-r,cy-r,r*2,r*2,1.f); + g.drawLine(cx-r,cy,cx+r,cy,1.f); + g.drawLine(cx,cy-r,cx,cy+r,1.f); + g.setColour(juce::Colour(0xff487486)); + g.fillEllipse(cx-19,cy-19,38,38); + g.setColour(juce::Colour(0xff101f2b)); + g.fillEllipse(cx-14,cy-14,28,28); + g.setColour(juce::Colour(0xffcceaf0)); + g.setFont(juce::FontOptions(12.f,juce::Font::plain)); + g.drawText("YOU",cx-22,cy+22,44,17,juce::Justification::centred); + const float angle=juce::degreesToRadians(15.f+75.f*width); + // Simple top-view cue: drawn radial distance tracks real DSP + // source position rather than remaining decorative on all edits. + const float positionRadius=(.60f+.38f*depth)*r; + const float sx=std::sin(angle)*positionRadius; + const float sy=std::cos(angle)*positionRadius; + const auto left=juce::Point(cx-sx,cy-sy); + const auto right=juce::Point(cx+sx,cy-sy); + g.setColour(juce::Colour(0xff4d91a9)); + g.drawLine(cx,cy,left.x,left.y,1.4f); + g.drawLine(cx,cy,right.x,right.y,1.4f); + for(int i=0;i<2;++i) { + const auto source=i==0?left:right; + g.setColour(juce::Colour(0xff081c27)); + g.fillRoundedRectangle(source.x-17,source.y-28,34,55,6); + g.setColour(juce::Colour(0xff7ed2e6)); + g.drawRoundedRectangle(source.x-17,source.y-28,34,55,6,1.3f); + g.fillEllipse(source.x-5,source.y-16,10,10); + g.drawEllipse(source.x-9,source.y,18,18,1.5f); + g.setFont(juce::FontOptions(12.f,juce::Font::plain)); + g.drawText(i==0?"L":"R", + static_cast(source.x-12), + static_cast(source.y+29),24,17, + juce::Justification::centred); + } + // This is a TOP VIEW. HRTF ear-height adjustment changes spectral + // pinna cues but must not move drawn source XYZ or reflections. + } + void refreshHostPower() { + if(!hostBypassReadback_)return; + const bool bypassed=hostBypassReadback_(); + const int state=bypassed?1:0; + if(state==lastHostPowerState_)return; + lastHostPowerState_=state; + power_.setButtonText(bypassed?"INSERT OFF":"INSERT ON"); + power_.setToggleState(!bypassed,juce::dontSendNotification); + power_.setTooltip(bypassed? + "Enable this ImerSip insert without changing FX rack master power": + "Bypass only this ImerSip insert with native rack fade"); + } + void refreshVenues() { + for(int i=0;i<3;++i)venues_[static_cast(i)] + .setToggleState(i==venue_,juce::dontSendNotification); + } + void refreshReadout(int i) { + const float v=static_cast( + knobs_[static_cast(i)].getValue()); + juce::String out; + if(i==1)out=juce::String(30+static_cast(std::round(1.5*v)))+"°"; + else if(i==7)out=(v>0.f?"+":"")+juce::String(v,1)+" dB"; + else out=juce::String(static_cast(std::round(v)))+"%"; + values_[static_cast(i)].setText(out, + juce::dontSendNotification); + } + armix::imersip::Settings readControls() const { + auto next=fx_.acceptedSettings(); + next.venue=venue_; + next.immersion=static_cast(knobs_[0].getValue()*.01); + next.width=static_cast(knobs_[1].getValue()*.01); + next.space=static_cast(knobs_[2].getValue()*.01); + next.lateRoom=static_cast(knobs_[3].getValue()*.01); + next.stereoLock=static_cast(knobs_[4].getValue()*.01); + next.bassImpact=static_cast(knobs_[5].getValue()*.01); + next.detail=static_cast(knobs_[6].getValue()*.01); + next.outputTrim=static_cast( + std::pow(10.,knobs_[7].getValue()/20.)); + next.depth=static_cast(depth_.getValue()*.01); + next.earAlignDegrees=static_cast(earAlign_.getValue()); + return next; + } + static bool matchesFactory(const armix::imersip::Settings& a, + const armix::imersip::Settings& b) noexcept { + // 'near' is a legacy Win32 SDK macro. Using it as a lambda name + // preprocesses into an invalid declaration under MSVC (C2513). + const auto equalControlValue=[](float x,float y) noexcept { + return std::abs(x-y)<.001f; + }; + return a.venue==b.venue&& + equalControlValue(a.immersion,b.immersion)&& + equalControlValue(a.space,b.space)&& + equalControlValue(a.width,b.width)&& + equalControlValue(a.bassImpact,b.bassImpact)&& + equalControlValue(a.detail,b.detail)&& + equalControlValue(a.outputTrim,b.outputTrim)&& + equalControlValue(a.stereoLock,b.stereoLock)&& + equalControlValue(a.lateRoom,b.lateRoom)&& + equalControlValue(a.depth,b.depth)&& + equalControlValue(a.earAlignDegrees,b.earAlignDegrees); + } + void sync(const armix::imersip::Settings& s) { + venue_=s.venue; + refreshVenues(); + depth_.setValue(s.depth*100.f,juce::dontSendNotification); + earAlign_.setValue(s.earAlignDegrees,juce::dontSendNotification); + const float vals[]{s.immersion*100.f,s.width*100.f, + s.space*100.f,s.lateRoom*100.f, + s.stereoLock*100.f,s.bassImpact*100.f, + s.detail*100.f, + static_cast(20.*std::log10(s.outputTrim))}; + for(int i=0;i<8;++i) { + knobs_[static_cast(i)].setValue(vals[i], + juce::dontSendNotification); + refreshReadout(i); + } + int id=1; + for(int i=2;i<=6;++i) + if(matchesFactory(s,factoryPreset(i))) {id=i;break;} + preset_.setSelectedId(id,juce::dontSendNotification); + repaint(stage_); + } + void submit() { + const auto wanted=readControls(); + if(!armix::imersip::valid(wanted)) { + status_="INVALID CONTROL VALUE · NO CHANGE";repaint();return; + } + if(pending_!=0) { + // If audio has ALREADY applied the previous gesture, consume + // its latched ACK now. Waiting for the 25 Hz paint timer made + // a rapid second drag appear inert, even though the DSP had + // finished the first edit. This runs on JUCE CONTROL only. + ImerSipProcessor::Completion ack{}; + while(fx_.pollCompletion(ack)) {} + if(fx_.lastCompletedRequestId()==pending_) { + const bool ok=fx_.lastCompletionApplied(); + pending_=0; + if(!ok)status_="DSP REJECTED · PREVIOUS EDIT"; + } + } + if(pending_!=0) { + deferred_=wanted;hasDeferred_=true; + status_="APPLYING · LATEST EDIT QUEUED";repaint();return; + } + const auto number=fx_.nextEditorRequestId(); + if(!fx_.queueSettings(wanted,number)) { + deferred_=wanted;hasDeferred_=true; + status_="BUSY · AUDIO NOT YET APPLIED";repaint();return; + } + pending_=number; + status_="APPLYING ON NATIVE AUDIO CALLBACK…";repaint(); + } + void timerCallback() override { + const auto frames=fx_.processedFrames(); + if(frames==lastObservedFrames_) { + liveReadout_="NO PCM CALLBACK / BYPASSED"; + } else if(fx_.liveInputEnergy()<1.e-10f) { + liveReadout_="SILENT INSERT INPUT"; + } else { + // PCM difference alone was incorrectly certified as spatial + // "quality". Show actual output SIDE energy relative to + // original stereo, normalized to final output trim. + const float input=std::max(fx_.liveInputEnergy(),1.e-12f); + const float output=std::max(fx_.liveOutputEnergy(),1.e-12f); + const float db=10.f*std::log10(output/input); + const float stereo=fx_.liveStereoRetention(); + liveReadout_=stereo<0.f? + "MONO INPUT · LEVEL "+juce::String(db,1)+"dB": + "STEREO "+juce::String(stereo,2)+"x · LEVEL "+ + juce::String(db,1)+"dB"; + } + lastObservedFrames_=frames; + refreshHostPower(); + repaint(juce::Rectangle(470,532,294,23)); + // The host may save/serialize this FX while its editor is open. + // Save also drains audio completions to capture accepted state. + // Read the latched CONTROL-side record, not only a FIFO pop. + ImerSipProcessor::Completion completion{}; + while(fx_.pollCompletion(completion)){} + if(pending_!=0 && fx_.lastCompletedRequestId()==pending_) { + const bool applied=fx_.lastCompletionApplied(); + pending_=0; + status_=applied?"AUDIO APPLIED · VERIFIED": + "DSP REJECTED · SETTINGS UNCHANGED"; + if(!applied)sync(fx_.acceptedSettings()); + repaint(); + } + if(pending_==0&&hasDeferred_) { + hasDeferred_=false; + submit(); // most recent dial gesture, not every mouse move + } + } + ImerSipProcessor& fx_; + ImerSipLook look_{}; + std::array venues_{}; + juce::TextButton originalAb_{},musicalReset_{},power_{},close_{}; + juce::ComboBox preset_{}; + std::function hostBypassRequest_; + std::function hostBypassReadback_; + int lastHostPowerState_=-1; + juce::Slider depth_{},earAlign_{}; + std::array knobs_{}; + std::array captions_{},values_{}; + juce::Rectangle stage_{}; + armix::imersip::Settings deferred_{}; + juce::String status_; + juce::String liveReadout_="PCM DELTA —"; + std::uint64_t lastObservedFrames_=0,pending_=0; + int venue_=0; + bool hasDeferred_=false; +}; + +inline juce::AudioProcessorEditor* ImerSipProcessor::createEditor() { + return new ImerSipEditor(*this); +} +} // namespace armix::builtin_fx diff --git a/engine/builtin_fx/ImerSipPhaseSafe.h b/engine/builtin_fx/ImerSipPhaseSafe.h new file mode 100644 index 000000000..6668f88f3 --- /dev/null +++ b/engine/builtin_fx/ImerSipPhaseSafe.h @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include + +// ImerSip after P8.2: coherent LF source shelf + matched binaural AIR shelf. +// Unlike independent Haas delays, neither stage inserts an out-of-polarity +// crossfeed. Both L/R bass filters share IDENTICAL coefficients. +// The SIDE delta is added to L and SUBTRACTED from R: mono fold-down equals +// the same coherent bass shelf applied to P8.2 MID, sample for sample. +// Native PCM only; all exponentials run in prepare(); PCM settings are affine only. +namespace armix::imersip { + +struct Settings { + int venue=0; // 0 Concert Hall, 1 Cinema, 2 Live Room + float immersion=.88f; // clearly spatial music default; 100% still stronger + float space=.78f; // prominent directional ER without full reverb + float width=.67f; // ~130.5 degree stage, 180 available at max + float bassImpact=.70f; // source-anchored original music warmth + float detail=.60f; // source-anchored treble sparkle + float outputTrim=1.f; // P8.2 full-output linear trim + float stereoLock=1.f; // 100% retains >=90% original direct SIDE + float lateRoom=.25f; // lighter tail preserves front speaker focus + float depth=.78f; // 6.1m actual source/wall geometry + float earAlignDegrees=0.f; // separate spectral KEMAR HRTF -30..+20° +}; +inline bool valid(const Settings& s) noexcept { + return s.venue>=0 && s.venue<=2 && + std::isfinite(s.immersion)&&s.immersion>=0.f&&s.immersion<=1.f && + std::isfinite(s.space)&&s.space>=0.f&&s.space<=1.f && + std::isfinite(s.width)&&s.width>=0.f&&s.width<=1.f && + std::isfinite(s.bassImpact)&&s.bassImpact>=0.f&&s.bassImpact<=1.f && + std::isfinite(s.detail)&&s.detail>=0.f&&s.detail<=1.f && + std::isfinite(s.outputTrim)&&s.outputTrim>=.25f&&s.outputTrim<=1.5f && + std::isfinite(s.stereoLock)&&s.stereoLock>=0.f&&s.stereoLock<=1.f && + std::isfinite(s.lateRoom)&&s.lateRoom>=0.f&&s.lateRoom<=1.f && + std::isfinite(s.depth)&&s.depth>=0.f&&s.depth<=1.f && + std::isfinite(s.earAlignDegrees) && + s.earAlignDegrees>=-30.f && s.earAlignDegrees<=20.f; +} + +// This filter is NOT a second reverb, compressor, M/S limiter or tone +// replacement. It never attenuates the P8.2 output as a safety workaround. +// Near 0 dBFS only the ADDITIONAL enhancement is suppressed: P8.2 remains. +class PhaseSafeEnhancer final { + // Stable RBJ second-order high shelf, designed once per device rate. + // +3.0dB above ~7kHz, near-unity below 3kHz: no broad 1-4k shout. + // Identical coefficients for both ears preserve binaural differences. + // No coefficients calculated on PCM edit/callback. + struct AirShelf { + bool prepare(double rate) noexcept { + constexpr double pi=3.14159265358979323846; + constexpr double db=3.0,frequency=7200.,slope=1.0; + const double A=std::pow(10.,db/40.); + const double w=2.*pi*frequency/rate; + const double cw=std::cos(w); + const double alpha=std::sin(w)*.5* + std::sqrt((A+1./A)*(1./slope-1.)+2.); + const double beta=2.*std::sqrt(A)*alpha; + const double a0=(A+1.)-(A-1.)*cw+beta; + if(!std::isfinite(a0)||a0<=0.)return false; + b0=static_cast( + A*((A+1.)+(A-1.)*cw+beta)/a0); + b1=static_cast( + -2.*A*((A-1.)+(A+1.)*cw)/a0); + b2=static_cast( + A*((A+1.)+(A-1.)*cw-beta)/a0); + a1=static_cast( + 2.*((A-1.)-(A+1.)*cw)/a0); + a2=static_cast( + ((A+1.)-(A-1.)*cw-beta)/a0); + reset();return true; + } + void reset() noexcept {z1={};z2={};} + float process(float x,int ear) noexcept { + const auto i=static_cast(ear); + const float y=b0*x+z1[i]; + z1[i]=b1*x-a1*y+z2[i]; + z2[i]=b2*x-a2*y; + return y; + } + float b0=1.f,b1=0.f,b2=0.f,a1=0.f,a2=0.f; + std::array z1{},z2{}; + }; +public: + bool prepare(double rate) noexcept { + ready_=false; + if(!std::isfinite(rate) || + (std::abs(rate-44100.)>.1 && std::abs(rate-48000.)>.1))return false; + constexpr double pi=3.1415926535897932384626433832795; + bassAlpha_=static_cast(1.-std::exp(-2.*pi*155./rate)); + sideAlpha_=static_cast(1.-std::exp(-2.*pi*680./rate)); + if(!airShelf_.prepare(rate))return false; + gainSlew_=static_cast(1.-std::exp(-1./(rate*.025))); + gateSlew_=static_cast(1.-std::exp(-1./(rate*.035))); + energySlew_=static_cast(1.-std::exp(-1./(rate*.075))); + reset(); + ready_=true; + return true; + } + bool setSettings(const Settings& s) noexcept { + if(!valid(s))return false; + settings_=s; + // Restore ORIGINAL source warmth and sparkle, not more KEMAR + // coloured wet MID. Maximum coherent dry LF shelf is intentionally + // below +2.8 dB at DC (1 + 0.255 * 1.45), with a broad 155 Hz + // transition; this is NOT added to any room feedback path. + // Coefficients are identical for L/R and designed in prepare(). + constexpr float cinemaMax=.255f; + constexpr float liveMax=.235f; + constexpr float concertMax=.255f; + const float maxDelta=s.venue==1?cinemaMax: + s.venue==2?liveMax:concertMax; + // VENUE SPACE links a restrained (+0..45% of the ORIGINAL + // positive delta) coherent 120Hz shelf to perceived room weight. + // This is NOT a measured room mode or a delayed bass reflection. + // Same filter coefficients per ear preserve the original LF phase. + bassTarget_=maxDelta*s.bassImpact*s.immersion* + (1.f+.45f*s.space); + // Music SIDE retains original stereo, with bounded positive tilt. + sideTarget_=.25f*s.width*s.immersion; + // Output-phase-aligned +3.0dB RBJ air shelf at 100% setting. + // Near-flat <3k, musical clarity at >7k, and a genuine audible + // difference at both default and end stop. One native DSP. + detailTarget_=s.detail*s.immersion; + return true; + } + void reset() noexcept { + bassL_=bassR_=sideLow_=midEnergy_=sideEnergy_=gate_=0.f; + airShelf_.reset(); + bassGain_=bassTarget_; + sideGain_=sideTarget_; + detailGain_=detailTarget_; + } + bool ready() const noexcept {return ready_;} + Settings settings() const noexcept {return settings_;} + + // Record per-sample ORIGINAL stereo balance before P8.2 mutates PCM. + // Caller keeps the returned gate in a fixed prepared scratch array. + float captureGate(float originalL,float originalR) noexcept { + // The SonKu core already rejects non-finite input samples. This + // original-source detector runs BEFORE that sanitization: never + // allow NaN, Inf or giant gain spikes into squared envelope state. + const float safeL=std::isfinite(originalL)? + std::clamp(originalL,-4.f,4.f):0.f; + const float safeR=std::isfinite(originalR)? + std::clamp(originalR,-4.f,4.f):0.f; + const float m=.5f*(safeL+safeR); + const float s=.5f*(safeL-safeR); + midEnergy_+=energySlew_*(m*m-midEnergy_); + sideEnergy_+=energySlew_*(s*s-sideEnergy_); + const float stereoRatio=sideEnergy_/ + (sideEnergy_+midEnergy_+1.e-12f); + const float gateTarget=std::clamp((stereoRatio-.015f)*3.f,0.f,1.f); + gate_+=gateSlew_*(gateTarget-gate_); + return gate_; + } + void process(float& l,float& r,float inputStereoGate, + float originalL,float originalR) noexcept { + if(!ready_)return; + // Apply tonal shelves to the ORIGINAL independent music L/R, + // not the already-filtered measured HRTF/FDN output. This restores + // familiar LF pressure and HF extension without multiplying the + // mid-coloured reflected field or changing stereo arrival cues. + bassL_+=bassAlpha_*(originalL-bassL_); + bassR_+=bassAlpha_*(originalR-bassR_); + bassGain_+=gainSlew_*(bassTarget_-bassGain_); + sideGain_+=gainSlew_*(sideTarget_-sideGain_); + detailGain_+=gainSlew_*(detailTarget_-detailGain_); + const float shelfL=airShelf_.process(l,0); + const float shelfR=airShelf_.process(r,1); + const float bassDeltaL=bassGain_*bassL_; + const float bassDeltaR=bassGain_*bassR_; + // One-pole complementary HP has Re(H)>=0. Summing a POSITIVE + // gain * highpassed SIDE cannot make a spectral SIDE notch. + // It also leaves mono MID exactly unchanged. + const float side=.5f*(l-r); + sideLow_+=sideAlpha_*(side-sideLow_); + const float delta=sideGain_*inputStereoGate*(side-sideLow_); + // Source LF + phase-aligned minimum-phase processed HF. Apply + // identical air-shelf biquad to L/R; preserve original KEMAR cues. + float addL=bassDeltaL+delta+detailGain_*(shelfL-l); + float addR=bassDeltaR-delta+detailGain_*(shelfR-r); + + // Peak safety does not pull down the trusted P8.2 signal. + // Unlike global AGC/limiter, it only scales optional additions. + // Sample-peak safety != oversampled true peak; qualify separately. + const float basePeak=std::max(std::abs(l),std::abs(r)); + const float available=std::max(0.f,.98f-basePeak); + const float extra=std::max(std::abs(addL),std::abs(addR)); + if(extra>available && extra>0.f) { + const float scale=available/extra; + addL*=scale; + addR*=scale; + } + l+=addL; + r+=addR; + } +private: + Settings settings_{}; + float bassAlpha_=0.f,sideAlpha_=0.f; + AirShelf airShelf_{}; + float gainSlew_=0.f,gateSlew_=0.f,energySlew_=0.f; + float bassTarget_=0.f,sideTarget_=0.f,detailTarget_=0.f; + float bassGain_=0.f,sideGain_=0.f,detailGain_=0.f; + float bassL_=0.f,bassR_=0.f,sideLow_=0.f; + float midEnergy_=0.f,sideEnergy_=0.f,gate_=0.f; + bool ready_=false; +}; +} // namespace armix::imersip diff --git a/engine/builtin_fx/ImerSipProcessor.h b/engine/builtin_fx/ImerSipProcessor.h new file mode 100644 index 000000000..769dc5946 --- /dev/null +++ b/engine/builtin_fx/ImerSipProcessor.h @@ -0,0 +1,214 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "ImerSipDsp.h" +#include "FxSpsc.h" +#include "../core/RealtimeNativeFxControl.h" +#include +#include +#include + +// Native mixer INSERT, not an independent player or ASIO callback. +// Control -> audio via SPSC, applied ACK only after callback completion; +// published .smix snapshots use the last accepted control-side state. +namespace armix::builtin_fx { +class ImerSipProcessor final : public juce::AudioProcessor, + public armix::mixer::RealtimeNativeFxControl { +public: + static constexpr const char* catalogIdentity= + "armix.builtin.imersip.v1"; + struct Completion { + std::uint64_t requestId=0; + armix::imersip::Settings settings{}; + bool applied=false; + }; + ImerSipProcessor():juce::AudioProcessor(BusesProperties() + .withInput("Input",juce::AudioChannelSet::stereo(),true) + .withOutput("Output",juce::AudioChannelSet::stereo(),true)) {} + + const juce::String getName() const override {return "ImerSip";} + bool acceptsMidi() const override {return false;} + bool producesMidi() const override {return false;} + bool isMidiEffect() const override {return false;} + double getTailLengthSeconds() const override {return 2.6;} + int getNumPrograms() override {return 1;} + int getCurrentProgram() override {return 0;} + void setCurrentProgram(int) override {} + const juce::String getProgramName(int) override {return "Concert Hall";} + void changeProgramName(int,const juce::String&) override {} + bool hasEditor() const override {return true;} + juce::AudioProcessorEditor* createEditor() override; + bool isBusesLayoutSupported(const BusesLayout& layout) const override { + return layout.getMainInputChannelSet()==juce::AudioChannelSet::stereo() + && layout.getMainOutputChannelSet()==juce::AudioChannelSet::stereo(); + } + + void prepareToPlay(double rate,int) override { + ready_=dsp_.prepare(rate); + // A/B compare is a transient monitor action, not session state. + compareDry_.store(false,std::memory_order_relaxed); + } + void releaseResources() override {ready_=false;} + bool isReady() const noexcept {return ready_;} + // Authoritative native DSP capability, never inferred from a browser dial. + bool measuredStereoStageEnabled() const noexcept { + return ready_ && dsp_.measuredStereoStageEnabled(); + } + // Measured LIVE PCM, not just parameter ACK. Unchanged counts imply + // the INSERT is bypassed/not being called by the actual audio graph. + std::uint64_t processedFrames() const noexcept { + return processedFrames_.load(std::memory_order_relaxed); + } + float liveInputEnergy() const noexcept { + return liveInputEnergy_.load(std::memory_order_relaxed); + } + float liveOutputEnergy() const noexcept { + return liveOutputEnergy_.load(std::memory_order_relaxed); + } + float liveDifferenceEnergy() const noexcept { + return liveDifferenceEnergy_.load(std::memory_order_relaxed); + } + float liveStereoRetention() const noexcept { + return liveStereoRetention_.load(std::memory_order_relaxed); + } + // UI thread only writes the atomic; PCM callback owns its sample ramp. + // Save/restore NEVER serializes this transient monitor comparison. + void setCompareDry(bool compare) noexcept { + compareDry_.store(compare,std::memory_order_release); + } + bool comparingOriginal() const noexcept { + return compareDry_.load(std::memory_order_acquire); + } + void processBlock(juce::AudioBuffer& pcm,juce::MidiBuffer&) override { + juce::ScopedNoDenormals guard; + if(!ready_ || pcm.getNumChannels()<2 || pcm.getNumSamples()<=0)return; + consumeRealtimeEdits(); + dsp_.setCompareDry(compareDry_.load(std::memory_order_acquire)); + dsp_.process(pcm.getWritePointer(0),pcm.getWritePointer(1), + pcm.getNumSamples()); + liveInputEnergy_.store(dsp_.lastInputEnergy(),std::memory_order_relaxed); + liveOutputEnergy_.store(dsp_.lastOutputEnergy(),std::memory_order_relaxed); + liveDifferenceEnergy_.store(dsp_.lastDifferenceEnergy(), + std::memory_order_relaxed); + liveStereoRetention_.store(dsp_.lastStereoRetention(), + std::memory_order_relaxed); + processedFrames_.fetch_add(static_cast( + pcm.getNumSamples()),std::memory_order_relaxed); + } + void processBlock(juce::AudioBuffer&,juce::MidiBuffer&) override {} + + void consumeRealtimeEdits() noexcept override { + Edit next; + if(!ready_ || !complete_.canPush() || !queue_.pop(next))return; + const bool ok=dsp_.setSettings(next.settings); + complete_.push({next.requestId,next.settings,ok}); + } + // Unique across closing/reopening a JUCE editor on this FX instance. + // CONTROL-only; never called by the realtime PCM callback. + std::uint64_t nextEditorRequestId() noexcept { + if(++lastIssuedRequest_==0)++lastIssuedRequest_; + return lastIssuedRequest_; + } + bool queueSettings(const armix::imersip::Settings& s, + std::uint64_t requestId) noexcept { + if(!ready_ || !requestId || !armix::imersip::valid(s) || + !queue_.push(Edit{requestId,s}))return false; + if(requestId>lastIssuedRequest_)lastIssuedRequest_=requestId; + return true; + } + bool pollCompletion(Completion& result) noexcept { + if(!complete_.pop(result))return false; + lastCompletedRequest_=result.requestId; + lastCompletedApplied_=result.applied; + if(result.applied)accepted_=result.settings; + return true; + } + // Both session Save and the floating editor run on CONTROL. Save may + // consume the very ACK that the editor is awaiting; expose a latched + // completion record so it never gets stuck on "APPLYING" after Save. + std::uint64_t lastCompletedRequestId() const noexcept { + return lastCompletedRequest_; + } + bool lastCompletionApplied() const noexcept {return lastCompletedApplied_;} + armix::imersip::Settings acceptedSettings() const noexcept { + return accepted_; + } + void sealForRealtime() noexcept override {published_=true;} + bool stateSnapshotQuiescent() const noexcept override { + return queue_.empty() && complete_.empty(); + } + + void getStateInformation(juce::MemoryBlock& dest) override { + // Native mixer save runs on CONTROL. A popup closed immediately + // after audio ACK must not serialize the previous settings simply + // because its editor timer no longer polls the completion FIFO. + Completion drained{}; + while(pollCompletion(drained)){} + juce::MemoryOutputStream out(dest,false); + out.writeInt(0x494D5253); // IMRS; isolated from SonKu/old research state + out.writeInt(5); // IMRS v5: measured HRTF ear-alignment and depth + out.writeInt(accepted_.venue); + out.writeFloat(accepted_.immersion); + out.writeFloat(accepted_.space); + out.writeFloat(accepted_.width); + out.writeFloat(accepted_.bassImpact); + out.writeFloat(accepted_.outputTrim); + out.writeFloat(accepted_.detail); + out.writeFloat(accepted_.stereoLock); + out.writeFloat(accepted_.lateRoom); + out.writeFloat(accepted_.depth); + out.writeFloat(accepted_.earAlignDegrees); + } + bool restoreUnpublishedState(const void* data,int size) { + if(published_ || !data || + (size!=32 && size!=36 && size!=44 && size!=48 && size!=52) || + !queue_.empty() || !complete_.empty())return false; + juce::MemoryInputStream in(data,static_cast(size),false); + if(in.readInt()!=0x494D5253)return false; + const int version=in.readInt(); + if(version!=(size==32?1:size==36?2:size==44?3:size==48?4:5)) + return false; + armix::imersip::Settings next{}; + next.venue=in.readInt(); + next.immersion=in.readFloat(); + next.space=in.readFloat(); + next.width=in.readFloat(); + next.bassImpact=in.readFloat(); + next.outputTrim=in.readFloat(); + // Exactly preserved v1 record; Detail defaults OFF on migration + // rather than silently altering old tonal preferences. + next.detail=version>=2?in.readFloat():0.f; + next.stereoLock=version>=3?in.readFloat():1.f; + next.lateRoom=version>=3?in.readFloat():.45f; + next.depth=version>=4?in.readFloat():.60f; + next.earAlignDegrees=version>=5?in.readFloat():0.f; + if(!in.isExhausted() || !armix::imersip::valid(next))return false; + if(ready_ && !dsp_.setSettings(next))return false; + accepted_=next; + return true; + } + void setStateInformation(const void* data,int size) override { + (void)restoreUnpublishedState(data,size); + } + +private: + struct Edit { + std::uint64_t requestId=0; + armix::imersip::Settings settings{}; + }; + armix::imersip::ImerSipDsp dsp_{}; + FxSpsc queue_{}; + FxSpsc complete_{}; + armix::imersip::Settings accepted_{}; + bool ready_=false; + bool published_=false; + std::uint64_t lastCompletedRequest_=0,lastIssuedRequest_=0; + bool lastCompletedApplied_=false; + std::atomic processedFrames_{0}; + std::atomic liveInputEnergy_{0.f},liveOutputEnergy_{0.f},liveDifferenceEnergy_{0.f}; + std::atomic liveStereoRetention_{-1.f}; + std::atomic compareDry_{false}; +}; +} // namespace armix::builtin_fx + +// JUCE editor implementation shares this exact processor, never a second DSP. +#include "ImerSipEditor.h" diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 745c0910b..69ad844f7 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -229,7 +229,15 @@ class SonKuEarlyReflections final { return wallCount; // original shipping source optimizes to 4 #endif } - Ears process(float left,float right,double azimuth,float spread) noexcept { + // Exact bounded vertical-image weighting isolated from SonKu P8.6. + // This is a research-only ImerSip opt-in; NO P8.5/P8.3 render mode + // or state dependency is carried into the P8.2 music-safe core. + static constexpr float horizontalFocusWeight(int wall,bool focused) noexcept { + return !focused || wall=wallCount) { + // Preserve original delays, KEMAR ITD/ILD and + // material filters, reducing ONLY vertical energy. + const float w=horizontalFocusWeight(wall,true); + output.left+=w*(p.gainL*l); + output.right+=w*(p.gainR*r); + }else{ + // Exact original SonKu P8.2 4/6-wall arithmetic. + output.left+=p.gainL*l; + output.right+=p.gainR*r; + } }else{ - output.left+=p.gainL*delayed(s,p.delayL); - output.right+=p.gainR*delayed(s,p.delayR); + if(imersipHorizontalFocus && wall>=wallCount) { + const float w=horizontalFocusWeight(wall,true); + output.left+=w*(p.gainL*delayed(s,p.delayL)); + output.right+=w*(p.gainR*delayed(s,p.delayR)); + }else{ + output.left+=p.gainL*delayed(s,p.delayL); + output.right+=p.gainR*delayed(s,p.delayR); + } } } } diff --git a/engine/builtin_fx/sonku/SonKuP84FusedMusicHrir.h b/engine/builtin_fx/sonku/SonKuP84FusedMusicHrir.h new file mode 100644 index 000000000..3e8322ede --- /dev/null +++ b/engine/builtin_fx/sonku/SonKuP84FusedMusicHrir.h @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include + +// SonKu P8.4 single-graph research kernel compositor. +// Fuse center music-safe HRIR + bounded HIGH-PASS direction differences +// BEFORE the existing 2x2 FIR loop: one PCM publisher, no second core. +// A first-order high-pass is calculated by convolving a difference FIR +// with a one-pole low-pass. Kernel support remains bounded at N taps; +// the truncated LP tail must be included in independent impulse tests. +// Preparation: control only. merge(): target-update every 16 frames; +// no allocation, mutex, sleep, IO, FFT or extra audio callback. +namespace armix::sonku::p84 { +class FusedMusicHrir final { +public: + bool prepare(double rate,float strength=.12f,float cutoffHz=750.f) noexcept { + if(!std::isfinite(rate)||rate<44000.||rate>48100.|| + !std::isfinite(strength)||strength<0.f||strength>.30f|| + !std::isfinite(cutoffHz)||cutoffHz<400.f||cutoffHz>2400.f) + return false; + strength_=strength; + alpha_=static_cast(1.-std::exp( + -2.*3.14159265358979323846*cutoffHz/rate)); + return true; + } + template + void merge(const std::array,2>& musicCenter, + std::array,2>& leftSpeaker, + std::array,2>& rightSpeaker) const noexcept { + for(int ear=0;ear<2;++ear){ + float leftLow=0.f,rightLow=0.f; + for(std::size_t tap=0;tap +#include + +// P8.7 private music-first psychoacoustic audition. One shared real-time +// callback, no extra FIR, FFT, dry bypass, invented room modes or clipping. +// Air is a modest common minimum-phase lead shelf of the measured DIRECT +// HRTF; identical topology for both ears preserves interaural gain/time +// cues better than independent peak/notch boosting. NEVER invert KEMAR notches. +// Low warmth comes exclusively from actual already-rendered 8-line FDN wet +// and the original per-channel music LF, not an oscillator or uncorrelated bass. +// OFF unless explicitly selected by renderMode==6 and ROOM enabled. +namespace armix::sonku::p87 { +class MusicalAirBody final { +public: + struct Ears {float left=0.f,right=0.f;}; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate) || (std::abs(rate-44100.)>.1 && + std::abs(rate-48000.)>.1))return false; + constexpr double twoPi=6.28318530717958647692; + // High shelf +1.9 dB asymptote above the ~4 kHz transition, no sharp Q peak. + // Adapted from one-pole highpass complement; stable zero/pole within circle. + airAlpha_=static_cast(1.-std::exp(-twoPi*3900./rate)); + airGain_=static_cast(std::pow(10.,1.9/20.)-1.); + // A damped, broadband low-mid tail under 180 Hz — no single resonant + // frequency, no feedback gain changes, no low-Q ringing or peak generation. + roomAlpha_=static_cast(1.-std::exp(-twoPi*175./rate)); + reset();return true; + } + void reset() noexcept {airLow_={};roomLow_={};} + void enhanceDirect(float& l,float& r) noexcept { + // Stereo equal coefficients keep both measured HRTF channels independent. + const std::array x{l,r}; + airLow_[0]+=airAlpha_*(x[0]-airLow_[0]); + airLow_[1]+=airAlpha_*(x[1]-airLow_[1]); + l=x[0]+airGain_*(x[0]-airLow_[0]); + r=x[1]+airGain_*(x[1]-airLow_[1]); + } + Ears diffuseLowBody(float l,float r) noexcept { + roomLow_[0]+=roomAlpha_*(l-roomLow_[0]); + roomLow_[1]+=roomAlpha_*(r-roomLow_[1]); + // Add ONLY 42% of the diffuse LF signal. Existing FDN RT60 remains intact + // and four horizontal early reflection image paths are untouched. + return {0.42f*roomLow_[0],0.42f*roomLow_[1]}; + } + static constexpr float musicBassRoomGain=1.09f; // room ON, LF only + float preparedAirBoost()const noexcept{return airGain_;} +private: + std::array airLow_{},roomLow_{}; + float airAlpha_=0.f,roomAlpha_=0.f,airGain_=0.f; +}; +} // namespace armix::sonku::p87 diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index be007328b..69b0f5fc7 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -4,6 +4,11 @@ #include "SonKuEarlyReflections.h" #include "SonKuMusicalReverb.h" #include "SonKuStereoIntegrity.h" +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH +// Kernel transferred verbatim from the P8.4 source-research branch. +// Only ImerSip uses this independent 12% directional-contrast fusion. +#include "SonKuP84FusedMusicHrir.h" +#endif #if defined(SONKU_P80_TRANSPARENT_BASS_RESEARCH) && SONKU_P80_TRANSPARENT_BASS_RESEARCH #include "SonKuHrtfTonalCalibration.h" #endif @@ -87,6 +92,14 @@ class SonKuSpatialCore final { public: static constexpr int taps=hrir::taps; static constexpr int updateInterval=16; + // Optional ImerSip sink: SAME real P8.2 room and FIR, no second processor. + // Preserve the existing four wet fields for source compatibility. + // The extra pair is the REAL measured P8.4-fused DIRECT HRTF before + // SonKu scene/wet/downmix. Only explicit ImerSip consumers request it. + struct RoomReturns { + float earlyL=0.f,earlyR=0.f,lateL=0.f,lateR=0.f; + float directL=0.f,directR=0.f; + }; bool prepare(double rate, SonKuReflectionProfile profile= SonKuReflectionProfile::Lightweight) noexcept { ready_=false; @@ -94,6 +107,10 @@ class SonKuSpatialCore final { std::abs(rate-48000.)>.1))return false; sampleRate_=rate; bank_=(std::abs(rate-44100.)<=.1)?hrir::normal44100:hrir::normal48000; +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + if(profile==SonKuReflectionProfile::SixSurfaceKemarResearch && + !imersipMusicFusion_.prepare(rate,.30f,750.f))return false; +#endif #if defined(SONKU_P80_TRANSPARENT_BASS_RESEARCH) && SONKU_P80_TRANSPARENT_BASS_RESEARCH if(profile==SonKuReflectionProfile::SixSurfaceKemarResearch && !tonalCalibration_.prepare(rate,bank_))return false; @@ -275,6 +292,29 @@ class SonKuSpatialCore final { bool setMusicalReverbPreset(SonKuReverbPreset preset) noexcept { return reverb_.setPreset(preset); } + // ImerSip-only admission: full two-speaker measured KEMAR SIDE and + // mono-safe center HRIR MID. Default OFF; original SonKu PCM unchanged. + // The previous P8.4 30% directional fusion, then 45% SIDE blending, + // effectively reduced a stereo KEMAR speaker cue to about 13.5%. + bool enableImerSipMeasuredStereoSide(bool enable) noexcept { +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + if(!ready_ || room_.preparedProfile()!= + SonKuReflectionProfile::SixSurfaceKemarResearch)return false; +#if defined(SONKU_P71_DIRECT_XYZ_RESEARCH) && SONKU_P71_DIRECT_XYZ_RESEARCH + if(researchPcmStarted_)return false; // prepare-only, never live toggle +#endif + imersipStereoSideResearch_=enable; + haveKernel_=false; + remaining_=0; + return true; +#else + (void)enable; + return false; +#endif + } + bool imersipMeasuredStereoSideEnabled() const noexcept { + return imersipStereoSideResearch_; + } bool ready() const noexcept {return ready_;} SonKuReflectionProfile preparedReflectionProfile() const noexcept { return room_.preparedProfile(); @@ -282,7 +322,26 @@ class SonKuSpatialCore final { double azimuthDegrees() const noexcept {return degrees_;} // In-place stereo; caller owns valid, non-overlapping L/R PCM pointers. // No vector, heap, blocking calls, I/O or filter bank allocation. - void process(float* left,float* right,int samples) noexcept { + // ImerSip-only measured KEMAR elevation alignment of the DIRECT + // HRTF. This is deliberately independent of SonKu physical source XYZ + // and its six-wall reflection geometry; ordinary SonKu never enables + // the private two-speaker path. The same already measured 3D KEMAR + // table is used: NO synthetic elevation EQ or second convolution. + bool setImerSipDirectHrtfElevationTrim(float degrees) noexcept { +#if defined(SONKU_P71_DIRECT_XYZ_RESEARCH) && SONKU_P71_DIRECT_XYZ_RESEARCH \ + && defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + if(!ready_ || !imersipStereoSideResearch_ || + !std::isfinite(degrees) || degrees < -30.f || degrees > 20.f) + return false; + imersipHrtfHeightTrimDegrees_=degrees; + remaining_=0; // target HRIR refresh; per-tap slew already provided + return true; +#else + (void)degrees;return false; +#endif + } + void process(float* left,float* right,int samples, + RoomReturns* optionalWet=nullptr) noexcept { if(!ready_ || !left || !right || samples<=0)return; #if defined(SONKU_P71_DIRECT_XYZ_RESEARCH) && SONKU_P71_DIRECT_XYZ_RESEARCH researchPcmStarted_=true; @@ -380,8 +439,8 @@ class SonKuSpatialCore final { auto& r1=kernels_[1][1][tap]; l0+=filterSlew_*(targets_[0][0][tap]-l0); r0+=filterSlew_*(targets_[0][1][tap]-r0); - if(musicSafe) { - // Both musical input channels share exactly one centered + if(musicSafe&&!imersipStereoSideResearch_) { + // Default SonKu music-safe: both inputs share one centered // measured HRIR. No dual-HRTF center interference; the // unprocessed SIDE is returned in its own stereo axis. // Only two FIR multiply-accumulates per tap, not four. @@ -403,12 +462,22 @@ class SonKuSpatialCore final { ?room_.process(transparentBass?x0:(musicSafe?inputMid:x0), transparentBass?x1:(musicSafe?inputMid:x1), degrees_,transparentBass?settings_.stereoSpreadDegrees: - (musicSafe?0.f:settings_.stereoSpreadDegrees)) + (musicSafe?0.f:settings_.stereoSpreadDegrees), + // P8.6 horizontal-only reflection weights, applied + // solely to an EXPLICIT ImerSip two-speaker candidate. + // Normal SonKu P8.2 and all public modes pass FALSE. + imersipStereoSideResearch_) :SonKuEarlyReflections::Ears{}; const auto late=reverb_.active() ?reverb_.process(transparentBass?x0:(musicSafe?inputMid:x0), transparentBass?x1:(musicSafe?inputMid:x1)) :SonKuMusicalReverb::Ears{}; + // Exact P8.2 measured ER and existing 3-band FDN, BEFORE + // the generic SonKu scene downscales its complete wet signal. + // Normal SonKu caller passes nullptr: ordinary PCM is unchanged. + if(optionalWet)optionalWet[i]={reflection.left,reflection.right, + late.left,late.right, + .5f*ears[0],.5f*ears[1]}; if(!transparentBass && !nativeSpace && settings_.outputTrim<=1.f && smoothedTrim_<=1.f) { // Preserve byte-for-byte original HRTF/old .smix output for @@ -548,11 +617,15 @@ class SonKuSpatialCore final { void interpolate(EarKernel& destination,double azimuth) noexcept { #if defined(SONKU_P71_DIRECT_XYZ_RESEARCH) && SONKU_P71_DIRECT_XYZ_RESEARCH if(room_.preparedProfile()==SonKuReflectionProfile::SixSurfaceKemarResearch && - researchElevationDegrees_!=0.f){ - // Both stereo emitters AND the coherent MID correction use the - // very same truly measured direct elevation, no third FIR. + (researchElevationDegrees_!=0.f || + (imersipStereoSideResearch_ && imersipHrtfHeightTrimDegrees_!=0.f))){ + // When ImerSip is enabled, direct-only spectral calibration + // does NOT lower the actual speaker or reflected-wall paths. + // Normal SonKu's physical XYZ/elevation remains untouched. hrir3d::interpolate(static_cast(azimuth), - researchElevationDegrees_, + imersipStereoSideResearch_ + ?imersipHrtfHeightTrimDegrees_ + :researchElevationDegrees_, std::abs(sampleRate_-44100.)<=.1,destination); return; } @@ -577,7 +650,8 @@ class SonKuSpatialCore final { } void updateKernels() noexcept { #if defined(SONKU_P75_MUSIC_SAFE_RESEARCH) && SONKU_P75_MUSIC_SAFE_RESEARCH - if(room_.preparedProfile()==SonKuReflectionProfile::SixSurfaceKemarResearch) { + if(room_.preparedProfile()==SonKuReflectionProfile::SixSurfaceKemarResearch && + !imersipStereoSideResearch_) { // Control evidence no longer gates musical MID coefficients: // the first sample already has a single centered KEMAR HRIR. // Never add two offset HRTFs for correlated source material. @@ -593,6 +667,29 @@ class SonKuSpatialCore final { degrees_-static_cast(settings_.stereoSpreadDegrees)*0.5); interpolate(targets_[1], degrees_+static_cast(settings_.stereoSpreadDegrees)*0.5); +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + if(imersipStereoSideResearch_) { + // Full measured physical left/right speaker differential, + // NOT the former twice-attenuated (30% x 45%) approximation. + // Keep a coherent MONO source at the exact measured center by + // projecting only the common FIR mode to H_center: + // H_left' = H_left + [H_center - (H_left+H_right)/2] + // H_right' = H_right + [H_center - (H_left+H_right)/2]. + // Difference H_left'-H_right' stays FULL measured strength, + // and L==R gives exactly one centered HRIR, no twin-HRTF + // combing or phantom stereo. Only enabled for ImerSip. + // Coefficient interpolation/slew remains in existing one graph. + interpolate(centerTarget_,degrees_); + for(int ear=0;ear<2;++ear) { + for(int k=0;k1.e-5f && settings_.stereoSpreadDegrees>0.f) { + // Only existing SonKu center correction needs this interpolation. + // ImerSip takes the true TWO measured speakers' SIDE difference; + // its ORIGINAL dry MID is restored outside this core. + if(!imersipStereoSideResearch_ && + coherent>1.e-5f && settings_.stereoSpreadDegrees>0.f) { interpolate(centerTarget_,degrees_); for(int ear=0;ear<2;++ear) { for(int k=0;k( + editor)==nullptr, true); +#else setResizable (true, true); +#endif centreWithSize (juce::jmax (380, editor->getWidth()), juce::jmax (300, editor->getHeight())); setVisible (true); } - void closeButtonPressed() override { setVisible (false); } + void closeButtonPressed() override { +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + // Do not leave temporary ORIGINAL A/B active after hiding editor. + if(auto* editor=dynamic_cast( + getContentComponent())) + editor->resetTransientComparison(); +#endif + setVisible(false); // retained editor + DSP; same-instance click re-shows + } }; class AudioSetupWindow final : public juce::DocumentWindow @@ -536,7 +551,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Destruction order: editorWindow_ releases its JUCE GUI BEFORE the // retained vendor processor lease. No vendor destructor runs on RT. armix::mixer::LiveChannelFxGraph::InstanceLease routedEditorOwner_; - std::uint64_t routedEditorEpoch_=0; + std::uint64_t routedEditorEpoch_=0,routedEditorRevision_=0; + juce::String routedEditorChannelKey_,routedEditorInstanceId_; + int routedEditorLane_=-1,routedEditorSlot_=-1; struct PendingNativeEq { armix::mixer::LiveChannelFxGraph::InstanceLease owner; juce::String request,channelId,deviceEpoch,revision,instanceId; @@ -981,6 +998,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr editorWindow_.reset(); routedEditorOwner_.reset(); routedEditorEpoch_=0; + routedEditorRevision_=0; + routedEditorChannelKey_.clear(); + routedEditorInstanceId_.clear(); + routedEditorLane_=-1; + routedEditorSlot_=-1; } void emitChain() @@ -6270,40 +6292,105 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr static_cast(args.getProperty("deviceEpoch",juce::var(0)))); const auto revision=static_cast( static_cast(args.getProperty("revision",juce::var(0)))); + const auto nativeId=args.getProperty("channelId",{}); + const auto channelKey=nativeId.isVoid()? + juce::String("m4:")+juce::String(lane): + juce::String("id:")+nativeId.toString(); + // ChannelId tokens are decimal STRINGS. juce::var's int64 + // conversion is not a trusted decode for that transport. + // Use the exact validated native numbers for editor and power. + std::uint64_t nativeChannel=0,nativeEpoch=0,nativeRevision=0; + const bool nativeValid=!nativeId.isVoid() && + armix::console::approvedNativeId(nativeId,nativeChannel)&& + armix::console::approvedNativeId( + args.getProperty("deviceEpoch",{}),nativeEpoch)&& + armix::console::approvedNativeId( + args.getProperty("revision",{}),nativeRevision); + const auto leaseEpoch=nativeId.isVoid()?epoch:nativeEpoch; + const auto leaseRevision=nativeId.isVoid()?revision:nativeRevision; bool opened=false; juce::String error="FX editor unavailable: device, revision or instance changed"; if(!nativeShowBusy_&&!studioBackupBusy_&&!engine_.isGraphSwitchPending()) { - armix::mixer::LiveChannelFxGraph::InstanceLease owner; - std::uint64_t retainedEpoch=epoch; - const auto nativeId=args.getProperty("channelId",{}); - if(!nativeId.isVoid()) { - std::uint64_t id=0,ep=0,rev=0; - if(armix::console::approvedNativeId(nativeId,id)&& - armix::console::approvedNativeId(args.getProperty("deviceEpoch",{}),ep)&& - armix::console::approvedNativeId(args.getProperty("revision",{}),rev)&& - slot>=0&&slot(slot),token); - retainedEpoch=ep; - } - } else owner=engine_.leaseRoutedFxForEditor(lane,slot,epoch,revision,token); - if(owner && owner->processor) { - try { - closePluginEditor(); - if(auto* editor=owner->processor->createEditorIfNeeded()) { - routedEditorOwner_=owner; - routedEditorEpoch_=retainedEpoch; - editorWindow_=std::make_unique( - owner->processor->getName(),editor); - opened=true; - error.clear(); - } else error="This VST3 has no native editor"; - } catch(const std::exception& ex) { - closePluginEditor(); - error="Vendor editor failed: "+juce::String(ex.what()); - } catch(...) { - closePluginEditor(); - error="Vendor editor failed (plugin exception)"; + // Titlebar X only hides; same native identity must REOPEN + // without attempting a second editor or FX lease. + const bool sameEditor=(nativeId.isVoid()||nativeValid) && + editorWindow_ && routedEditorOwner_ && + routedEditorEpoch_==leaseEpoch && + routedEditorRevision_==leaseRevision && + routedEditorChannelKey_==channelKey && + routedEditorInstanceId_==token && + routedEditorLane_==lane && routedEditorSlot_==slot && + engine_.retainsRoutedFxEditor(leaseEpoch,routedEditorOwner_); + if(sameEditor) { + editorWindow_->setVisible(true); + editorWindow_->toFront(true); + opened=true;error.clear(); + } else { + armix::mixer::LiveChannelFxGraph::InstanceLease owner; + const auto retainedEpoch=leaseEpoch; + const auto retainedRevision=leaseRevision; + if(!nativeId.isVoid()) { + if(nativeValid && slot>=0 && + slot(slot),token); + } else + owner=engine_.leaseRoutedFxForEditor( + lane,slot,epoch,revision,token); + if(owner && owner->processor) { + try { + closePluginEditor(); // editor destroyed before old lease + if(auto* editor=owner->processor->createEditorIfNeeded()) { +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + if(auto* imer=dynamic_cast< + armix::builtin_fx::ImerSipEditor*>(editor)) { + // Same native rack slot-bypass authority; + // no independent DSP power flag. + auto held=owner; + imer->bindHostPower( + [this,held,nativeId,nativeChannel, + retainedEpoch,retainedRevision, + lane,slot,token](bool bypass) { + if(!engine_.retainsRoutedFxEditor( + retainedEpoch,held))return false; + const bool applied=!nativeId.isVoid()? + engine_.bypassNativeVst3( + retainedEpoch,retainedRevision, + armix::mixer::ChannelId{nativeChannel}, + static_cast(slot), + token,bypass): + engine_.setDryRoutingLabFxBypass( + lane,slot,retainedEpoch, + retainedRevision,token,bypass); + if(applied)emitApprovedNativeSnapshot(); + return applied; + }, + [held] { + return held->bypassRequested.load( + std::memory_order_acquire); + }); + } +#endif + routedEditorOwner_=owner; + routedEditorEpoch_=retainedEpoch; + routedEditorRevision_=retainedRevision; + routedEditorChannelKey_=channelKey; + routedEditorInstanceId_=token; + routedEditorLane_=lane; + routedEditorSlot_=slot; + editorWindow_=std::make_unique( + owner->processor->getName(),editor); + opened=true;error.clear(); + } else error="This FX has no native editor"; + } catch(const std::exception& ex) { + closePluginEditor(); + error="Vendor editor failed: "+juce::String(ex.what()); + } catch(...) { + closePluginEditor(); + error="Vendor editor failed (plugin exception)"; + } } } } diff --git a/src/NativeBuiltInFx.h b/src/NativeBuiltInFx.h index 1e98f0a51..b8607245a 100644 --- a/src/NativeBuiltInFx.h +++ b/src/NativeBuiltInFx.h @@ -7,6 +7,9 @@ #include "../engine/builtin_fx/VocalThrowProcessor.h" #include "../engine/builtin_fx/GuitarRigEditor.h" #include "../engine/builtin_fx/SonKuSpatialProcessor.h" +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH +#include "../engine/builtin_fx/ImerSipProcessor.h" +#endif #include "../engine/core/PreparedMixerBlock.h" #include #include @@ -83,6 +86,19 @@ inline constexpr std::array nativeBuiltInFx{ "NATIVE_SONKU_UNSUPPORTED_AUDIO_FORMAT","NATIVE_SONKU_PREPARE_REJECTED", "NATIVE_SONKU_PREPARE_EXCEPTION","Saved 8D-SonKu state rejected; graph unchanged", prepareNativeBuiltInFx}, +#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && SONKU_P82_MULTIBAND_ROOM_RESEARCH + // The SAME CMake compile definition controls both the P8.2 DSP and this + // native insert registration. Without this invariant a full Windows EXE + // builds and DSP tests pass but ImerSip is absent from the FX Picker. + // Audio path is real SonKu P8.2 plus coherent mono-safe enhancement. + NativeBuiltInFx{ImerSipProcessor::catalogIdentity, + "ImerSip","Spatial",true,44100.,48000., + "NATIVE_IMERSIP_HOST_UNAVAILABLE","NATIVE_IMERSIP_DEVICE_CHANGED", + "NATIVE_IMERSIP_UNSUPPORTED_AUDIO_FORMAT","NATIVE_IMERSIP_PREPARE_REJECTED", + "NATIVE_IMERSIP_PREPARE_EXCEPTION", + "Saved ImerSip state rejected; graph unchanged", + prepareNativeBuiltInFx}, +#endif NativeBuiltInFx{GuitarRigProcessor::catalogIdentity,"Guitar FX Rig","Guitar",true,32000.,192000., "NATIVE_GFX_HOST_UNAVAILABLE","NATIVE_GFX_DEVICE_CHANGED", "NATIVE_GFX_UNSUPPORTED_AUDIO_FORMAT","NATIVE_GFX_PREPARE_REJECTED", diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 8e09afd3d..53f20b7bb 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1891,7 +1891,17 @@ test("native vendor editor retention follows current PCM ownership, not inactive const main=read('src/Main.cpp'),lab=read('src/LiveDryRoutingLab.h'); assert.match(main,/engine_\.retainsRoutedFxEditor\(routedEditorEpoch_,routedEditorOwner_\)/); assert.match(main,/routedEditorEpoch_=retainedEpoch/); - assert.match(main,/retainedEpoch=ep/); + // Current host validates decimal-string native ChannelId epoch + revision, + // then uses those exact validated counters for both reopen and bypass. + assert.match(main,/const auto leaseEpoch=nativeId\.isVoid\(\)\?epoch:nativeEpoch/); + assert.match(main,/const auto leaseRevision=nativeId\.isVoid\(\)\?revision:nativeRevision/); + assert.match(main,/const auto retainedEpoch=leaseEpoch/); + assert.match(main,/routedEditorRevision_=retainedRevision/); + assert.match(main,/const bool sameEditor=/); + assert.match(main,/editorWindow_->setVisible\(true\)/); + assert.match(main,/engine_\.bypassNativeVst3\(/); + assert.match(main,/imer->bindHostPower\(/); + assert.match(main,/emitApprovedNativeSnapshot\(\)/); assert.match(lab,/nativeAccepted_\.fxOwners->retainsEditor\(owner\)/); const editor=main.slice(main.indexOf('if(owner && owner->processor)'),main.indexOf('if(owner && owner->processor)')+700); assert.ok(editor.indexOf('closePluginEditor();') Main -> bridge -> GUI +contract and prevents the wrong-ifdef error reported on g80c0af68. +""" +from pathlib import Path +import re +import unittest + +ROOT=Path(__file__).resolve().parents[1] + +def read(path): + return (ROOT/path).read_text(encoding="utf-8") + +class ImerSipPickerContract(unittest.TestCase): + def test_same_build_define_controls_pcm_and_native_catalog(self): + cmake=read("CMakeLists.txt") + registry=read("src/NativeBuiltInFx.h") + self.assertRegex(cmake,re.compile( + r"target_compile_definitions\(ARMixConsole PRIVATE.*?" + r"\$<\$:" + r"SONKU_P82_MULTIBAND_ROOM_RESEARCH=1>", + re.S)) + self.assertEqual(registry.count( + "#if defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) && " + "SONKU_P82_MULTIBAND_ROOM_RESEARCH"),2) + self.assertNotIn( + "#if defined(ARMIX_SONKU_EXPERIMENTAL_P82_ROOM)", + registry) + self.assertIn("ImerSipProcessor::catalogIdentity",registry) + self.assertRegex(registry,re.compile( + r'ImerSipProcessor::catalogIdentity,\s*' + r'"ImerSip","Spatial",true,44100\.,48000\.')) + self.assertIn("prepareNativeBuiltInFx",registry) + + def test_host_emits_exact_native_catalog_no_duplicated_ui_authority(self): + main=read("src/Main.cpp") + bridge=read("web/approved-native-bridge.js") + composer=read("scripts/compose_native_peq.py") + stage=read("scripts/build_approved_native_gui.py") + self.assertIn('entry->setProperty("id",fx.id)',main) + self.assertIn('entry->setProperty("showInPicker",fx.showInPicker)',main) + self.assertIn('setProperty("builtIns",juce::var(builtIns))',main) + self.assertIn('emitEventIfBrowserIsVisible("arMixCatalog",catalog)',main) + self.assertIn("nativeBuiltins=catalog.builtIns.filter(",bridge) + self.assertIn("nativeBuiltins.filter(fx=>fx.showInPicker!==false)",bridge) + self.assertIn("scope?.setNativeCatalog?.(",bridge) + self.assertIn("setNativeCatalog(rows){",stage) + self.assertIn("renderPluginCatalog();renderFastPicker();",stage) + self.assertIn("p.format==='Native'",composer) + self.assertIn("!specializedIds.has(p.id)",composer) + self.assertIn("nativeExtra+eqBuiltin+compBuiltin",composer) + self.assertIn('data-fast-id=',composer) + # Exact host-owned graph: never fake a visual-only accepted FX in JUCE. + self.assertIn( + "window.__ARMIX_NATIVE_M2__?.insertPlugin?.(id,activeFxTarget)",stage) + self.assertIn("engine_.installNativeBuiltInFx(",main) + self.assertIn("armix::builtin_fx::findNativeBuiltInFx(catalogId)",main) + self.assertIn("const plugin=nativeCatalog.get(id) || nativeBuiltins.find",bridge) + + def test_native_editor_avoids_win32_preprocessor_macro_collisions(self): + # MSVC's Windows SDK defines 'near' (and historically 'far') + # as preprocessor macros. A named lambda 'near' compiled in + # Linux tests but made the real full Windows GUI fail with C2513. + # Catch this in the fast preflight before obtaining JUCE/WebView2. + editor=read("engine/builtin_fx/ImerSipEditor.h") + self.assertRegex(editor,r"\bequalControlValue\s*=") + self.assertNotRegex(editor,re.compile( + r"\b(?:const\s+)?(?:auto|bool|float|double|int)\s+" + r"(?:near|far|small|interface)\s*(?:[=;(,])")) + + def test_native_windows_artifact_requires_compiled_picker_registry(self): + cmake=read("CMakeLists.txt") + cpp=read("tests/imersip_native_state_test.cpp") + windows=read(".github/workflows/sonku-p82-acoustic-windows-field.yml") + self.assertIn("ARMixImerSipNativeTests",cmake) + self.assertIn("SONKU_P82_MULTIBAND_ROOM_RESEARCH=1)",cmake) + self.assertIn("findNativeBuiltInFx(",cpp) + self.assertIn("assert(descriptor->showInPicker)",cpp) + self.assertIn("descriptor->prepare(48000.,128,nullptr,0)",cpp) + self.assertIn("ARMixConsole ARMixSonKuP72SourceTests",windows) + self.assertIn("ARMixImerSipNativeTests",windows) + self.assertIn("ImerSipNativeJuceP82AcceptedStateAckAndRestore",windows) + self.assertIn("ArSonMix-ImerSip-P87-StereoFirst-v5-Windows-x64-",windows) + self.assertIn("imrsSchemaVersion = 5",windows) + self.assertIn("imrsStateBytes = 52",windows) + self.assertIn("sourceDistanceRangeMeters = @(1.6,7.4)",windows) + self.assertIn("earHrtfAlignRangeDegrees = @(-30,20)",windows) + self.assertIn("binauralEarlyMidAndSide = $true",windows) + +if __name__=="__main__": + unittest.main() diff --git a/tests/imersip_music_phase_guard_test.cpp b/tests/imersip_music_phase_guard_test.cpp new file mode 100644 index 000000000..1cffa77a6 --- /dev/null +++ b/tests/imersip_music_phase_guard_test.cpp @@ -0,0 +1,1123 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/ImerSipDsp.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) || !SONKU_P82_MULTIBAND_ROOM_RESEARCH +#error ImerSip requires actual SonKu P8.2 six-wall/three-band room +#endif +#if !defined(SONKU_P80_TRANSPARENT_BASS_RESEARCH) || !SONKU_P80_TRANSPARENT_BASS_RESEARCH +#error ImerSip must use transparent P8.2 bass foundation +#endif +#if !defined(SONKU_P75_MUSIC_SAFE_RESEARCH) || !SONKU_P75_MUSIC_SAFE_RESEARCH +#error ImerSip must use P8.2 preserved music SIDE +#endif +namespace { +constexpr double pi=3.1415926535897932384626433832795; +constexpr int n=16384; +using armix::imersip::ImerSipDsp; +using armix::imersip::Settings; +struct Stereo { + std::vector l,r; + explicit Stereo(int count=n):l(count),r(count){} +}; +double rms(const Stereo& a,int start,bool side) { + double e=0.; + for(int i=start;i(a.l.size());++i) { + const double v=.5*(static_cast(a.l[i])+ + (side?-1.:1.)*a.r[i]); + e+=v*v; + } + return std::sqrt(e/static_cast(a.l.size()-start)); +} +void makeSignal(Stereo& a,double rate,int fixture,float hz=120.f) { + for(int i=0;i(a.l.size());++i) { + const double t=static_cast(i)/rate; + const float v=.16f*static_cast(std::sin(2.*pi*hz*t))+ + .045f*static_cast(std::sin(2.*pi*1270.*t)); + const float d=.08f*static_cast(std::sin(2.*pi*733.*t)); + if(fixture==0){a.l[i]=v;a.r[i]=v;} // mono voice + if(fixture==1){a.l[i]=v;a.r[i]=-v;} // full anti-phase + if(fixture==2){a.l[i]=v;a.r[i]=0.f;} // left hard pan + if(fixture==3){a.l[i]=0.f;a.r[i]=v;} // right hard pan + if(fixture==4){a.l[i]=v;a.r[i]=.5f*v+d;} // independent stereo + if(fixture==5){a.l[i]=v;a.r[i]=-.48f*v+d;} // weak negative correlation + } +} +Stereo render(double rate,const Settings& s,const Stereo& input,int chunk=128, + bool p87=true,bool concertStage=true) { + Stereo result=input; + auto dsp=std::make_unique(p87,concertStage); + assert(dsp->setSettings(s) && dsp->prepare(rate)); + assert(dsp->measuredStereoStageEnabled()); + for(int at=0;at(result.l.size());at+=chunk) + dsp->process(result.l.data()+at,result.r.data()+at, + std::min(chunk,static_cast(result.l.size())-at)); + return result; +} +void assertChunkParity(const Stereo& a,const Stereo& b) { + assert(a.l.size()==b.l.size()); + for(int i=0;i(a.l.size());++i) { + assert(std::isfinite(a.l[i])&&std::isfinite(a.r[i])); + assert(std::abs(a.l[i]-b.l[i])<2.e-6f); + assert(std::abs(a.r[i]-b.r[i])<2.e-6f); + } +} +void verifySceneGeometry() { + Settings s{}; + assert(std::abs(armix::imersip::sceneFor(s).stereoSpreadDegrees-130.5f)<.02f); + s.width=1.f; + assert(std::abs(armix::imersip::sceneFor(s).stereoSpreadDegrees-180.f)<.01f); + s.width=0.f; + assert(std::abs(armix::imersip::sceneFor(s).stereoSpreadDegrees-30.f)<.01f); + for(int venue=0;venue<3;++venue) { + s.venue=venue; + auto scene=armix::imersip::sceneFor(s); + assert(!scene.moving && scene.startAzimuthDegrees==0.f); + assert(scene.spacePreset>=2); + assert(scene.spatialMix>0.f && scene.outputTrim==1.f); + assert(std::abs(scene.sourceDistanceMeters-(1.6f+5.8f*s.depth))<1.e-4f); + assert(scene.roomAmount>scene.ambience); + // P0 had a near-bypassed real room (~0.05 * core return). + // Increased actual room-gain is intentional; its *processed PCM* + // must now pass the robust dry/wet null-test below. + assert(scene.roomAmount<=.90f && scene.ambience<=.58f); + } +} +void verifyNearOrchestraRoomContract() { + for(int venue=0;venue<3;++venue)for(float amount:{0.f,.45f,1.f}) { + Settings s{};s.venue=venue;s.space=amount;s.immersion=1.f; + const auto room=armix::imersip::sceneFor(s); + assert(std::abs(room.sourceDistanceMeters-(1.6f+5.8f*s.depth))<1.e-4f); + // Early and late are INDEPENDENT. At Early=0 no phantom + // floor/wall returns may survive, even if FDN late is active. + if(amount==0.f)assert(room.roomAmount==0.f); + else assert(room.roomAmount>room.ambience); + assert(room.spacePreset>=2); + s.immersion=0.f; + const auto dry=armix::imersip::sceneFor(s); + assert(std::abs(dry.sourceDistanceMeters-room.sourceDistanceMeters)<1.e-4f); + assert(dry.spacePreset==0&&dry.roomAmount==0.f&&dry.ambience==0.f); + } +} +void verifyDryAndBounds(double rate) { + Settings bad{};bad.venue=3;assert(!armix::imersip::valid(bad)); + bad={};bad.width=2.f;assert(!armix::imersip::valid(bad)); + bad={};bad.immersion=std::numeric_limits::quiet_NaN(); + assert(!armix::imersip::valid(bad)); + Settings s{};s.immersion=0.f;s.outputTrim=1.f; + assert(armix::imersip::sceneFor(s).spacePreset==0); + Stereo source(4096);makeSignal(source,rate,4); + const auto dry=render(rate,s,source); + for(int i=0;i<4096;++i) { + assert(std::abs(dry.l[i]-source.l[i])<1.e-5f); + assert(std::abs(dry.r[i]-source.r[i])<1.e-5f); + } + auto badRate=std::make_unique(); + assert(!badRate->prepare(96000.)); +} +void verifyFrontSpeakerVocalDoesNotNull(double rate) { + // This is the regression v1 missed: an algebraic phase safety test + // against an already-boxy P8.2 output falsely certified a bad vocal. + // In v2 the reference is the ACTUAL DRY source, not that HRTF output. + for(int venue=0;venue<3;++venue)for(int fixture=0;fixture<6;++fixture) { + Stereo source;makeSignal(source,rate,fixture,450.f); + Settings s{};s.venue=venue;s.width=.95f; + s.space=1.f;s.immersion=1.f;s.bassImpact=0.f;s.detail=0.f;s.outputTrim=1.f; + auto wet=render(rate,s,source,128); + assertChunkParity(wet,render(rate,s,source,64)); + assertChunkParity(wet,render(rate,s,source,8192)); + double midDiff=0.,midInput=0.; + for(int i=4096;i1.e-8)assert(midDiff/midInput<1.0); + if(fixture==0) { + const double ref=rms(source,4096,false),now=rms(wet,4096,false); + assert(now>ref*.70 && nowref*.86); // owner rejects near-mono/washed stereo + assert(now.035); + } +} +void verifyRealP86DirectSpeakerReachesOutput(double rate) { + // The old plugin only exposed P8.2 room returns and discarded its HRTF + // direct sound. Require a real dual-speaker DIRECT signal even with ROOM + // completely OFF and prove the full ImerSip render is not near-dry. + using Core=armix::sonku::SonKuSpatialCore; + auto core=std::make_unique(); + using Profile=armix::sonku::SonKuReflectionProfile; + assert(core->prepare(rate,Profile::SixSurfaceKemarResearch)); + armix::sonku::Settings scene{}; + scene.moving=false;scene.stereoSpreadDegrees=100.f; + scene.spatialMix=1.f;scene.outputTrim=1.f;scene.spacePreset=0; + assert(core->setSettings(scene)); + assert(core->enableImerSipMeasuredStereoSide(true)); + Stereo impulse(1024);impulse.l[0]=.16f; + std::vector direct(1024); + core->process(impulse.l.data(),impulse.r.data(),1024,direct.data()); + double sentToOtherEar=0.,sentToNearEar=0.,wetWithRoomOff=0.; + for(const auto& x:direct) { + sentToNearEar+=std::abs(x.directL); + sentToOtherEar+=std::abs(x.directR); + wetWithRoomOff+=std::abs(x.earlyL)+std::abs(x.earlyR)+ + std::abs(x.lateL)+std::abs(x.lateR); + } + assert(sentToNearEar>.001 && sentToOtherEar>.001); + assert(wetWithRoomOff==0.); + // ImerSip 100% with REAL P8.6 horizontal focus must render a + // binaural DIRECT field, not just add reverb to original headphone L/R. + Stereo source(16384);makeSignal(source,rate,4,370.f); + Settings s{};s.immersion=1.f;s.width=1.f; + s.space=0.f;s.detail=0.f;s.bassImpact=0.f; + const auto renderFull=render(rate,s,source); + double directDifference=0.,dryEnergy=0.; + for(int i=4096;i<16384;++i) { + const double dl=renderFull.l[i]-source.l[i]; + const double dr=renderFull.r[i]-source.r[i]; + directDifference+=dl*dl+dr*dr; + dryEnergy+=static_cast(source.l[i])*source.l[i]+ + static_cast(source.r[i])*source.r[i]; + } + const double relative=std::sqrt(directDifference/(dryEnergy+1.e-14)); + std::fprintf(stderr,"IMERSIP_P86_DIRECT rate=%.0f transfer=%.5f\n",rate,relative); + // This fixture is dominated by 370-1270 Hz vocal/body: forcing a + // >15% difference here rewarded the very mid-coloration the owner + // rejected. It must remain measurably binaural, NOT become dry. + assert(relative>.05); + // Require a STRONG direct measured speaker effect in the upper pinna + // band independently of room, bass and optional AIR boosts. The new + // MID-fidelity guard below covers the vocal band separately. + Stereo treble(32768); + for(int i=0;i<32768;++i) { + const double time=static_cast(i)/rate; + treble.l[i]=static_cast( + .10*std::sin(2.*pi*8200.*time)+ + .04*std::sin(2.*pi*11800.*time)); + treble.r[i]=static_cast( + .07*std::sin(2.*pi*8200.*time+.9)+ + .035*std::sin(2.*pi*11800.*time+.3)); + } + const auto renderedTreble=render(rate,s,treble,128); + double highbandDelta=0.,highbandInput=0.; + for(int i=8192;i<32768;++i) { + const double dl=renderedTreble.l[i]-treble.l[i]; + const double dr=renderedTreble.r[i]-treble.r[i]; + highbandDelta+=dl*dl+dr*dr; + highbandInput+=static_cast(treble.l[i])*treble.l[i]+ + static_cast(treble.r[i])*treble.r[i]; + } + const double highbandRelative=std::sqrt( + highbandDelta/(highbandInput+1.e-14)); + std::fprintf(stderr, + "IMERSIP_HRTF_PINNA_DIRECT rate=%.0f delta=%.5f\n", + rate,highbandRelative); + assert(highbandRelative>.14); +} + +void verifyP87MusicalAirBodyRealIntegration(double rate) { + using armix::sonku::p87::MusicalAirBody; + MusicalAirBody helper; + constexpr int n=16384; + double priorAir8=0.; + for(float hz:{85.f,1000.f,8000.f,12000.f}) { + assert(helper.prepare(rate)); + double src=0.,air=0.,body=0.; + for(int i=0;i8192) {src+=x*x;air+=l*l;body+=(x+b.left)*(x+b.left);} + } + const double ar=std::sqrt(air/src),br=std::sqrt(body/src); + if(hz==85.f)assert(br>1.30&&br<1.46); + if(hz==8000.f) {assert(ar>1.13&&ar<1.28);priorAir8=ar;} + // Matches P8.7 source's transfer property: smooth increasing + // shelf, NOT an invented 12kHz absolute floor. + if(hz==12000.f)assert(ar>priorAir8&&ar<1.29); + if(hz==8000.f)assert(br<1.05); + std::fprintf(stderr, + "IMERSIP_P87_FILTER rate=%.0f hz=%.0f air=%.5f body=%.5f\\n", + rate,static_cast(hz),ar,br); + } + // The real callback must differ from the matched P8.7-disabled A/B. + Settings s{};s.immersion=1.f;s.space=1.f; + s.width=1.f;s.detail=0.f;s.bassImpact=0.f; + Stereo music(32768); + for(int i=0;i<32768;++i){ + const float t=static_cast(i/rate); + const float x=.080f*std::sin(2.*pi*8100.*t)+ + .035f*std::sin(2.*pi*83.*t); + const float y=.020f*std::sin(2.*pi*4700.*t); + music.l[i]=x+y;music.r[i]=x-y; + } + const auto old=render(rate,s,music,128,false); + const auto improved=render(rate,s,music,128,true); + const auto chunks=render(rate,s,music,64,true); + assertChunkParity(improved,chunks); + double delta=0.,e=0.; + for(int i=4096;i<32768;++i) { + const double dl=improved.l[i]-old.l[i]; + const double dr=improved.r[i]-old.r[i]; + delta+=dl*dl+dr*dr; + e+=music.l[i]*music.l[i]+music.r[i]*music.r[i]; + } + const double rel=std::sqrt(delta/(e+1.e-14)); + std::fprintf(stderr,"IMERSIP_P87_LIVE_PCM rate=%.0f relDelta=%.5f\n",rate,rel); + assert(rel>.006 && rel<.30); + s.immersion=0.f; + const auto dry=render(rate,s,music,128,true); + for(int i=0;i<32768;++i) { + assert(std::abs(dry.l[i]-music.l[i])<1.e-5f); + assert(std::abs(dry.r[i]-music.r[i])<1.e-5f); + } +} + +void verifyConcertStageLateralReflection(double rate) { + using armix::imersip::ConcertStage; + auto band=std::make_unique(); + assert(band->prepare(rate)); + band->setScene(1.f,1.f,1.f); + assert(std::abs(band->targetGain()-6.f)<1.e-5f); + // Mono early room adds NO synthetic SIDE; source MID is untouched. + for(int i=0;i<512;++i) { + const auto s=band->process(.1f,.1f); + assert(s.left==0.f&&s.right==0.f); + } + // Stronger 250-3800 Hz true lateral early band than subbass/air: + // 1 kHz contributes lively concert-stage width but not low punch or + // additional 8-12 kHz diffuse brightness on top of P8.7 direct air. + auto amplitude=[rate](float hz) { + armix::imersip::ConcertStage filter; + assert(filter.prepare(rate)); + filter.setScene(1.f,1.f,1.f); + filter.reset(); + constexpr int frames=16384; + double input=0.,extra=0.; + for(int i=0;i4096){input+=x*x;extra+=ears.left*ears.left;} + } + return std::sqrt(extra/(input+1.e-14)); + }; + const double sub=amplitude(75.f); + const double presence=amplitude(1000.f); + const double air=amplitude(10000.f); + std::fprintf(stderr, + "IMERSIP_CONCERT_BAND rate=%.0f sub=%.5f width1k=%.5f air=%.5f\n", + rate,sub,presence,air); + assert(presence>4.6 && presence<5.8); + // Two poles attenuate both bass and upper reverb much more than the + // previous broad one-pole passband: NO fake LF or doubled 10kHz wash. + assert(sub.012 && change<.12); + // At familiar default 82% IMMERSION and 65% VENUE SPACE the actual + // audio must still have a non-negligible lateral contribution. + const Settings defaults{}; + const auto defaultDry=render(rate,defaults,music,128,true,false); + const auto defaultStage=render(rate,defaults,music,128,true,true); + double d=0.,q=0.; + for(int i=4096;i<32768;++i) { + const double dl=defaultStage.l[i]-defaultDry.l[i]; + const double dr=defaultStage.r[i]-defaultDry.r[i]; + d+=dl*dl+dr*dr; + q+=music.l[i]*music.l[i]+music.r[i]*music.r[i]; + } + const double defaultDelta=std::sqrt(d/(q+1.e-14)); + std::fprintf(stderr, + "IMERSIP_CONCERT_DEFAULT rate=%.0f delta=%.7f\n",rate,defaultDelta); + assert(defaultDelta>.004 && defaultDelta<.09); + + // Turning off the VENUE SPACE knob must remove this stage, while + // leaving the P8.7 direct binaural effect and native stage intact. + s.space=0.f; + const auto roomZero=render(rate,s,music,128,true,true); + assertChunkParity(roomZero,render(rate,s,music,128,true,false)); + // Width=0 also gates only this early-lateral enhancement, not the + // original measured front-speaker engine. + s.space=1.f;s.width=0.f; + const auto narrow=render(rate,s,music,128,true,true); + assertChunkParity(narrow,render(rate,s,music,128,true,false)); +} + +void verifyStereoIntegrityOwnerRejection(double rate) { + // The old test only required 45% original SIDE and thus CERTIFIED + // near-mono. Test BOTH full immersive and defaults against actual source. + for(int venue=0;venue<3;++venue) + for(int fixture:{1,2,3,4,5}) { + Stereo source(32768);makeSignal(source,rate,fixture,441.f); + Settings s{};s.venue=venue;s.width=1.f;s.immersion=1.f; + s.space=1.f;s.lateRoom=1.f;s.stereoLock=1.f; + s.bassImpact=0.f;s.detail=0.f;s.outputTrim=1.f; + const auto out=render(rate,s,source,128); + const double before=rms(source,4096,true); + const double after=rms(out,4096,true); + const double retained=after/(before+1.e-12); + std::fprintf(stderr, + "IMERSIP_STEREO_LOCK rate=%.0f venue=%d fixture=%d ratio=%.5f\n", + rate,venue,fixture,retained); + if(retained<=.86) { + // Diagnose whether the real mono-like failure is directly + // measured HRTF or an opposing EARLY/LATE room SIDE field. + auto roomOff=s;roomOff.space=0.f;roomOff.lateRoom=0.f; + const auto directOnly=render(rate,roomOff,source,128); + auto earlyOff=s;earlyOff.space=0.f; + const auto lateOnly=render(rate,earlyOff,source,128); + auto lateOff=s;lateOff.lateRoom=0.f; + const auto earlyOnly=render(rate,lateOff,source,128); + std::fprintf(stderr, + "IMERSIP_SIDE_COMPONENTS venue=%d fixture=%d original=%.5f direct=%.5f early=%.5f late=%.5f both=%.5f\n", + venue,fixture,before, + rms(directOnly,4096,true)/(before+1.e-12), + rms(earlyOnly,4096,true)/(before+1.e-12), + rms(lateOnly,4096,true)/(before+1.e-12),retained); + } + assert(retained>.86 && retained<1.75); + // Dedicated control must have real audio influence. At minimum + // lock the original SIDE; without lock, deliberately more HRTF SIDE. + s.stereoLock=0.f; + const auto free=render(rate,s,source,128); + double difference=0.,original=0.; + for(int i=4096;i<32768;++i) { + const double dl=free.l[i]-out.l[i]; + const double dr=free.r[i]-out.r[i]; + difference+=dl*dl+dr*dr; + original+=source.l[i]*source.l[i]+source.r[i]*source.r[i]; + } + assert(std::sqrt(difference/(original+1.e-14))>.01); + } + // Separate LATE TAIL must affect the actual PCM without mutating + // early lateral band or source SIDE. Same full source and other knobs. + Settings s{};s.immersion=1.f;s.space=.8f;s.lateRoom=0.f; + Stereo music(32768);makeSignal(music,rate,4); + const auto noLate=render(rate,s,music); + s.lateRoom=1.f; + const auto yesLate=render(rate,s,music); + double diff=0.; + for(int i=4096;i<32768;++i) + diff+=std::abs(yesLate.l[i]-noLate.l[i])+ + std::abs(yesLate.r[i]-noLate.r[i]); + assert(diff>.001); +} +void verifyCompareNeverChangesSettings(double rate) { + Settings s{};s.immersion=1.f;s.stereoLock=1.f; + auto fx=std::make_unique(); + assert(fx->setSettings(s)&&fx->prepare(rate)); + assert(fx->settings().stereoLock==1.f); + constexpr int frames=32768; + Stereo music(frames);makeSignal(music,rate,4,300.f); + Stereo wet=music,dry=music; + // First fresh DSP starts processed; second instance in compare mode + // must converge toward ORIGINAL with fixed trim at least after 200ms. + auto compare=std::make_unique(); + assert(compare->setSettings(s)&&compare->prepare(rate)); + compare->setCompareDry(true); + for(int at=0;atprocess(wet.l.data()+at,wet.r.data()+at,128); + compare->process(dry.l.data()+at,dry.r.data()+at,128); + } + for(int i=24000;isettings().immersion==1.f); + assert(compare->settings().stereoLock==1.f); + assert(fx->lastStereoRetention()>0.f); +} + +void verifyP87NotTheQualityReferenceAndRealDepth(double rate) { + // Owner FAT: SonKu P8.7 default is NOT a perceptual reference. + // The previous ImerSip 1.6m constant / 97-to-100deg WIDTH dial + // had no useful front-depth control. Require *real* geometry and PCM. + Settings s{};s.immersion=1.f;s.width=.65f; + s.space=.80f;s.lateRoom=.15f; + s.bassImpact=0.f;s.detail=0.f;s.outputTrim=1.f; + s.stereoLock=1.f; + assert(std::abs(armix::imersip::sceneFor(s).sourceDistanceMeters- + (1.6f+5.8f*s.depth))<1.e-4f); + Stereo stereo(32768);makeSignal(stereo,rate,4,370.f); + auto compare=[&](const Stereo& a,const Stereo& b) { + double delta=0.,source=0.; + for(int i=4096;i<32768;++i){ + const double dl=a.l[i]-b.l[i],dr=a.r[i]-b.r[i]; + delta+=dl*dl+dr*dr; + source+=stereo.l[i]*stereo.l[i]+stereo.r[i]*stereo.r[i]; + } + return std::sqrt(delta/(source+1.e-14)); + }; + s.depth=0.f;const auto near=render(rate,s,stereo,128); + s.depth=1.f;const auto far=render(rate,s,stereo,128); + const double depthDelta=compare(near,far); + std::fprintf(stderr, + "IMERSIP_REAL_DEPTH rate=%.0f near=1.6m far=7.4m delta=%.5f\n", + rate,depthDelta); + assert(depthDelta>.009); // rejects old completely inert control + s.depth=.6f;s.width=0.f; + const auto narrow=render(rate,s,stereo,128); + s.width=1.f; + const auto wide=render(rate,s,stereo,128); + const double spreadDelta=compare(narrow,wide); + std::fprintf(stderr, + "IMERSIP_WIDTH_FULL_RANGE rate=%.0f from=30 to=180 delta=%.5f\n", + rate,spreadDelta); + assert(spreadDelta>.025); + // The FULL STOP must also matter from a usable musical default. + s.width=Settings{}.width; + const auto defWidth=render(rate,s,stereo,128); + const double maxVsDefault=compare(defWidth,wide); + std::fprintf(stderr, + "IMERSIP_WIDTH_DEFAULT_TO_MAX rate=%.0f delta=%.5f\n", + rate,maxVsDefault); + assert(maxVsDefault>.010); + Settings bad{};bad.depth=1.01f;assert(!armix::imersip::valid(bad)); + bad.depth=std::numeric_limits::quiet_NaN(); + assert(!armix::imersip::valid(bad)); +} + +void verifyDirectOnlyHrtfHeightCalibration(double rate) { + // Real measured KEMAR 3D elevation from SonKu P7, isolated as a + // P8.8-style DIRECT-only ear alignment. SOURCE XYZ must remain LEVEL. + Stereo music(32768);makeSignal(music,rate,4,790.f); + Settings s{};s.immersion=1.f;s.space=.70f;s.lateRoom=.2f; + s.width=.68f;s.stereoLock=1.f;s.bassImpact=0.f;s.detail=0.f; + s.depth=.65f;s.earAlignDegrees=0.f; + const auto baseline=render(rate,s,music,128); + s.earAlignDegrees=-19.5f; + const auto aligned=render(rate,s,music,128); + assertChunkParity(aligned,render(rate,s,music,64)); + double delta=0.,energy=0.; + for(int i=4096;i<32768;++i) { + const double dl=aligned.l[i]-baseline.l[i]; + const double dr=aligned.r[i]-baseline.r[i]; + delta+=dl*dl+dr*dr; + energy+=music.l[i]*music.l[i]+music.r[i]*music.r[i]; + } + const double changed=std::sqrt(delta/(energy+1.e-14)); + std::fprintf(stderr, + "IMERSIP_REAL_KEMAR_HEIGHT rate=%.0f trim=-19.5 delta=%.5f\n", + rate,changed); + assert(changed>.01); + assert(armix::imersip::sceneFor(s).directElevationDegrees==0.f); + assert(std::abs(armix::imersip::sceneFor(s).sourceDistanceMeters- + (1.6f+5.8f*s.depth))<1.e-4f); + assert(rms(aligned,4096,true)>rms(music,4096,true)*.78); + s.earAlignDegrees=-30.f;assert(armix::imersip::valid(s)); + s.earAlignDegrees=20.f;assert(armix::imersip::valid(s)); + s.earAlignDegrees=20.1f;assert(!armix::imersip::valid(s)); + s.earAlignDegrees=-30.1f;assert(!armix::imersip::valid(s)); +} + +void verifyStereoKeepDoesNotDisableMeasuredHrtf(double rate) { + Stereo source(32768); + makeSignal(source,rate,4,731.f); + Settings s{}; + s.immersion=1.f;s.width=1.f;s.space=0.f;s.lateRoom=0.f; + s.bassImpact=0.f;s.detail=0.f;s.outputTrim=1.f; + s.stereoLock=1.f; + const auto kept=render(rate,s,source,128); + const auto kept64=render(rate,s,source,64); + assertChunkParity(kept,kept64); + // At zero room, increasing width must still change the measured + // direct HRTF in both ears: Stereo Keep is no longer a "spatial OFF". + s.width=0.f; + const auto narrow=render(rate,s,source,128); + s.width=1.f; + double sourceEnergy=0.,directional=0.,sideBefore=0.,sideAfter=0.; + for(int i=4096;i<32768;++i) { + const double dl=kept.l[i]-narrow.l[i],dr=kept.r[i]-narrow.r[i]; + directional+=dl*dl+dr*dr; + sourceEnergy+=source.l[i]*source.l[i]+source.r[i]*source.r[i]; + const double a=.5*(source.l[i]-source.r[i]); + const double b=.5*(kept.l[i]-kept.r[i]); + sideBefore+=a*a;sideAfter+=b*b; + } + const double widthDelta=std::sqrt(directional/(sourceEnergy+1.e-14)); + const double sideRatio=std::sqrt(sideAfter/(sideBefore+1.e-14)); + std::fprintf(stderr, + "IMERSIP_HRTF_KEEP_WIDTH rate=%.0f widthDelta=%.5f side=%.5f\\n", + rate,widthDelta,sideRatio); + assert(widthDelta>.080); // full native 180-degree knob is meaningful + assert(sideRatio>.86 && sideRatio<1.8); + + // Genuine mono voice must stay mono when ROOM is OFF and two virtual + // speakers share the same centered source. No fake stereo excitation. + Stereo mono(32768); + for(int i=0;i<32768;++i){ + const float v=.11f*std::sin(2.*pi*790.*i/rate); + mono.l[i]=mono.r[i]=v; + } + const auto monoOut=render(rate,s,mono,128); + double extraSide=0.,sourceMono=0.; + for(int i=4096;i<32768;++i){ + extraSide+=std::pow(.5*(monoOut.l[i]-monoOut.r[i]),2); + sourceMono+=mono.l[i]*mono.l[i]; + } + assert(std::sqrt(extraSide/(sourceMono+1.e-14))<.12); +} + +void verifyMeasuredFullSpeakerSeparation180(double rate) { + using Core=armix::sonku::SonKuSpatialCore; + using Profile=armix::sonku::SonKuReflectionProfile; + auto measure=[rate](float angle,bool mono) { + auto fx=std::make_unique(); + assert(fx->prepare(rate,Profile::SixSurfaceKemarResearch)); + armix::sonku::Settings s{}; + s.moving=false;s.spacePreset=0;s.spatialMix=1.f; + s.stereoSpreadDegrees=angle; + assert(fx->setSettings(s)); + assert(fx->enableImerSipMeasuredStereoSide(true)); + Stereo input(1024);input.l[0]=.16f; + if(mono)input.r[0]=.16f; + std::vector ears(1024); + fx->process(input.l.data(),input.r.data(),1024,ears.data()); + double side=0.,mid=0.; + for(const auto& x:ears) { + const double d=.5*(x.directL-x.directR); + const double m=.5*(x.directL+x.directR); + side+=d*d;mid+=m*m; + } + return std::array{side,mid}; + }; + const auto narrow=measure(30.f,false); + const auto lateral=measure(180.f,false); + const auto mono=measure(180.f,true); + const double ratio=std::sqrt(lateral[0]/(narrow[0]+1.e-14)); + const double monoSide=std::sqrt(mono[0]/(mono[1]+1.e-14)); + std::fprintf(stderr, + "IMERSIP_PHYSICAL_180 rate=%.0f lateralVs30=%.4f monoLeak=%.5f\n", + rate,ratio,monoSide); + // Genuine +/-90 degree *measured* ear separation, not GUI relabel. + // True MIT-KEMAR measured ear-side impulse energy is about 1.155x + // at +/-90 vs +/-15; arbitrarily demanding 1.25 would falsify HRTF. + // Stronger audible endpoint must be asserted on the actual PCM below. + assert(ratio>1.10); + // Center-correlated music must not acquire false L-R cancellation. + assert(monoSide<.10); +} +void verifyEachKnobAffectsActualPcm(double rate) { + Stereo music(16384);makeSignal(music,rate,4,2500.f); + // Include additional treble content for real 5.6k AIR stage. + for(int i=0;i<16384;++i) { + const float air=.030f*std::sin(2.*pi*8200.*i/rate); + music.l[i]+=air; + music.r[i]+=.45f*air; + } + Settings s{};s.outputTrim=1.f; + const auto delta=[&](const Settings& a,const Settings& b) { + const auto x=render(rate,a,music),y=render(rate,b,music); + double changed=0.,source=0.; + for(int i=4096;i<16384;++i) { + const double l=x.l[i]-y.l[i],r=x.r[i]-y.r[i]; + changed+=l*l+r*r; + source+=music.l[i]*music.l[i]+music.r[i]*music.r[i]; + } + return std::sqrt(changed/(source+1.e-14)); + }; + for(int knob=0;knob<9;++knob) { + auto a=s,b=s; + switch(knob) { + case 0:a.immersion=0.f;b.immersion=1.f;break; + case 1:a.width=0.f;b.width=1.f;break; + case 2:a.space=0.f;b.space=1.f;break; + case 3:a.lateRoom=0.f;b.lateRoom=1.f;break; + case 4:a.stereoLock=0.f;b.stereoLock=1.f;break; + case 5:a.bassImpact=0.f;b.bassImpact=1.f;break; + case 6:a.detail=0.f;b.detail=1.f;break; + case 7:a.depth=0.f;b.depth=1.f;break; + case 8:a.earAlignDegrees=-20.f;b.earAlignDegrees=20.f;break; + } + const double effect=delta(a,b); + std::fprintf(stderr, + "IMERSIP_KNOB_ENDPOINT rate=%.0f knob=%d relDelta=%.6f\n", + rate,knob,effect); + assert(effect>.003); + } +} + +void verifyOriginalMusicHiFiContour(double rate) { + // Tonal enhancement is source-derived and testable independently of + // spaciousness. Compare same physical KEMAR/room path with only BASS + // or AIR knob changing; a wide L/R musical source must stay independent. + auto measure=[rate](float hz,int axis,float amount) { + constexpr int count=32768; + Stereo src(count); + for(int i=0;i{amp,rms(rendered,8192,true)}; + }; + for(int axis=0;axis<2;++axis) { + const float boostHz=axis==0?80.f:11000.f; + const float guardHz=axis==0?2000.f:1500.f; + const auto off=measure(boostHz,axis,0.f); + const auto max=measure(boostHz,axis,1.f); + const auto midOff=measure(guardHz,axis,0.f); + const auto midMax=measure(guardHz,axis,1.f); + const double gain=max.first/(off.first+1.e-14); + const double midGain=midMax.first/(midOff.first+1.e-14); + const double sideGain=max.second/(off.second+1.e-14); + std::fprintf(stderr, + "IMERSIP_SOURCE_HIFI rate=%.0f axis=%s wanted=%.4f mid=%.4f side=%.4f\n", + rate,axis==0?"BASS":"AIR",gain,midGain,sideGain); + assert(gain>1.10 && gain<1.48); + assert(midGain>.995 && midGain<1.095); + assert(sideGain>.995 && sideGain<1.48); + } +} + +void verifyDefaultMusicLevelEvidence(double rate) { + Stereo source(32768); + for(int i=0;i<32768;++i) { + const double t=static_cast(i)/rate; + const float bass=.10f*std::sin(2.*pi*83.*t); + const float body=.07f*std::sin(2.*pi*252.*t); + const float voice=.055f*std::sin(2.*pi*1700.*t); + const float air=.025f*std::sin(2.*pi*9300.*t); + source.l[i]=bass+body+voice+air; + source.r[i]=.93f*bass+.76f*body+.45f*voice-.13f*air; + } + auto measure=[](const Stereo& a) { + double sum=0.; + for(int i=8192;i(a.l.size());++i) + sum+=a.l[i]*a.l[i]+a.r[i]*a.r[i]; + return std::sqrt(sum/(2.*(a.l.size()-8192))); + }; + const Settings defaults{}; + auto strongest=defaults; + strongest.immersion=strongest.space=strongest.width=1.f; + strongest.bassImpact=strongest.detail=strongest.lateRoom=1.f; + // Output gain is held constant; do not fake quality with +3.5dB trim. + strongest.outputTrim=1.f; + const double dry=measure(source); + const double levelDefault=measure(render(rate,defaults,source,128))/dry; + const double levelMax=measure(render(rate,strongest,source,128))/dry; + std::fprintf(stderr, + "IMERSIP_MUSIC_LEVEL rate=%.0f default=%.5f max=%.5f\\n", + rate,levelDefault,levelMax); + assert(std::isfinite(levelDefault)&&std::isfinite(levelMax)); + assert(levelDefault>.70 && levelMax>.70); // deny near-silent render +} +void verifyBassFoundation(double rate) { + for(int venue=0;venue<3;++venue)for(float hz:{40.f,70.f,110.f,160.f,220.f}) { + Stereo source; + for(int i=0;i(std::sin(2*pi*hz*i/rate)); + source.l[i]=source.r[i]=x; + } + Settings s{};s.venue=venue;s.immersion=1.f;s.bassImpact=1.f; + auto processed=render(rate,s,source); + const auto before=rms(source,4096,false); + const auto after=rms(processed,4096,false); + // Coherent LF boost must not attenuate the original music bass. + std::fprintf(stderr,"IMERSIP_BASS_GUARD rate=%.0f venue=%d hz=%.0f ratio=%.5f\n", + rate,venue,hz,after/before); + assert(after>before*.995); + // Up to ~2.0dB optional LF is deliberate, but never a doubling. + assert(after(); + auto focused=std::make_unique(); + assert(normal->prepare(rate,Profile::SixSurfaceKemarResearch)); + assert(focused->prepare(rate,Profile::SixSurfaceKemarResearch)); + armix::sonku::SonKuRoomGeometry g{}; + g.widthMeters=14.4f;g.depthMeters=14.4f;g.distanceMeters=1.6f; + g.heightMeters=4.8f;g.sourceHeightMeters=1.45f; + g.listenerHeightMeters=1.45f; + assert(normal->setRealtimeRoom(g,.75f,true)); + assert(focused->setRealtimeRoom(g,.75f,true)); + double delta=0.,normalEnergy=0.,focusEnergy=0.; + for(int i=0;i<16384;++i) { + const double time=static_cast(i)/rate; + const float direct=.13f*static_cast( + std::sin(2.*pi*317.*time)); + const float side=.04f*static_cast( + std::sin(2.*pi*1237.*time)); + const float l=direct+side,r=direct-side; + const auto a=normal->process(l,r,0.,175.f,false); + const auto b=focused->process(l,r,0.,175.f,true); + assert(std::isfinite(a.left)&&std::isfinite(a.right)); + assert(std::isfinite(b.left)&&std::isfinite(b.right)); + delta+=std::abs(static_cast(a.left)-b.left)+ + std::abs(static_cast(a.right)-b.right); + normalEnergy+=static_cast(a.left)*a.left+ + static_cast(a.right)*a.right; + focusEnergy+=static_cast(b.left)*b.left+ + static_cast(b.right)*b.right; + } + // Four lateral measured paths remain active; floor and ceiling + // physically differ. Phase-interference means the TOTAL wet energy + // need not be monotonic, so do not make a false total-level claim. + assert(delta>1.e-4); + assert(normalEnergy>1.e-8 && focusEnergy>1.e-8); + std::fprintf(stderr, + "IMERSIP_P86_HORIZONTAL rate=%.0f wetDifference=%.6f focusRatio=%.5f\n", + rate,delta,focusEnergy/normalEnergy); +} +void verifyP84FusedKernelProvenanceAndLowFrequency(double rate) { + // The standalone kernel source is transferred from P8.4; no P8.3 + // physical-renderer LF480, extra worker, 2nd runtime core or macro. + using armix::sonku::p84::FusedMusicHrir; + FusedMusicHrir merger; + assert(merger.prepare(rate,.12f,750.f)); + assert(!merger.prepare(rate,.31f,750.f)); + assert(merger.prepare(rate,.12f,750.f)); + constexpr int taps=140; + using Kernel=std::array,2>; + Kernel center{},left{},right{}; + center[0][0]=1.f;center[1][0]=1.f; + left[0][0]=1.70f;left[1][0]=.45f; + right[0][0]=.45f;right[1][0]=1.70f; + merger.merge(center,left,right); + // Direction is real: L and R FIRs remain differentiated. + assert(left[0][0]>right[0][0]); + assert(left[1][0](); + auto disabled=std::make_unique(); + using Profile=armix::sonku::SonKuReflectionProfile; + assert(legacy->prepare(rate,Profile::SixSurfaceKemarResearch)); + assert(disabled->prepare(rate,Profile::SixSurfaceKemarResearch)); + Settings s{};s.width=.91f;s.space=.47f;s.immersion=1.f; + const auto original=armix::imersip::sceneFor(s); + assert(legacy->setSettings(original)); + assert(disabled->setSettings(original)); + assert(disabled->enableImerSipMeasuredStereoSide(false)); + legacy->reset();disabled->reset(); + Stereo a=input,b=input; + for(int at=0;atprocess(a.l.data()+at,a.r.data()+at,128); + disabled->process(b.l.data()+at,b.r.data()+at,128); + } + for(int i=0;i( + std::sin(2.*pi*hz*i/rate)); + input.l[i]=v;input.r[i]=v; + } + Settings s{};s.venue=venue;s.immersion=1.f; + s.bassImpact=1.f;s.detail=0.f;s.width=.95f; + s.space=0.f;const auto low=render(rate,s,input); + s.space=1.f;const auto rich=render(rate,s,input); + const auto original=rms(input,4096,false); + assert(rms(low,4096,false)>=original*.995); + assert(rms(rich,4096,false)>=rms(low,4096,false)*.995); + // Calibrated ~2dB end-stop is intentional; strict upper bound + // still rejects runaway LF / clipping or accidental second bass. + assert(rms(rich,4096,false)(); + auto dual=std::make_unique(); + using Profile=armix::sonku::SonKuReflectionProfile; + assert(dryP82->prepare(rate,Profile::SixSurfaceKemarResearch)); + assert(dual->prepare(rate,Profile::SixSurfaceKemarResearch)); + armix::sonku::Settings s{}; + s.moving=false;s.startAzimuthDegrees=0.f; + s.stereoSpreadDegrees=175.f;s.spatialMix=.65f;s.outputTrim=1.f; + assert(dryP82->setSettings(s) && dual->setSettings(s)); + assert(!dryP82->imersipMeasuredStereoSideEnabled()); + assert(dual->enableImerSipMeasuredStereoSide(true)); + assert(dual->imersipMeasuredStereoSideEnabled()); + dryP82->reset();dual->reset(); + Stereo oldRender=input,newRender=input; + for(int at=0;atprocess(oldRender.l.data()+at,oldRender.r.data()+at,128); + dual->process(newRender.l.data()+at,newRender.r.data()+at,128); + } + double sideDifference=0.; + for(int i=4096;i1.); +} +void verifyActualP82RoomChangesSideOnly(double rate) { + // Independent side material + different six-wall programs must produce + // audible stereo room differences; not a fake width-only bypass. + Stereo source;makeSignal(source,rate,4); + Settings s{};s.immersion=1.f;s.width=1.f;s.bassImpact=0.f; + s.venue=0;s.space=0.f;const auto first=render(rate,s,source); + s.space=1.f;const auto second=render(rate,s,source); + double residual=0.; + for(int i=4000;i1.e-5); + // True room returns necessarily add small delayed MID energy: + // the previous exact MID invariant made center source sound near-dry. + assert(std::isfinite(rms(second,4096,false))); +} +void verifyDrySourceVocalMidFidelity(double rate) { + // Previous tests only required the center music to remain above 70% + // of the original, allowing a large audible radio/nasal coloration. + // Test original dry MID at untrimmed unity with room, bass and AIR + // turned OFF, so the actual dual-HRTF direct transfer is isolated. + // Keep FULL WIDTH and both lateral / narrow measured speaker geometry. + for(float width:{0.f,1.f})for(float hz:{500.f,1100.f,1900.f,2600.f}) { + Stereo source(32768); + for(int i=0;i<32768;++i) { + const float v=.12f*static_cast( + std::sin(2.*pi*hz*i/rate)); + source.l[i]=source.r[i]=v; + } + Settings s{}; + s.immersion=1.f;s.width=width;s.stereoLock=1.f; + s.space=0.f;s.lateRoom=0.f; + s.bassImpact=0.f;s.detail=0.f;s.outputTrim=1.f; + const auto wet=render(rate,s,source,128); + assertChunkParity(wet,render(rate,s,source,64)); + double dryMid=0.,wetMid=0.; + for(int i=8192;i<32768;++i) { + const double a=.5*(source.l[i]+source.r[i]); + const double b=.5*(wet.l[i]+wet.r[i]); + dryMid+=a*a;wetMid+=b*b; + } + const double ratio=std::sqrt(wetMid/(dryMid+1.e-16)); + std::fprintf(stderr, + "IMERSIP_ORIGINAL_MID rate=%.0f width=%.0f hz=%.0f ratio=%.5f\n", + rate,width,hz,ratio); + // 1-3 kHz should remain within a bounded ~+/-1dB level window; + // source color is assessed separately from room externalization. + assert(ratio>.89 && ratio<1.12); + } +} + +void verifyDetailIsNotMidBoost(double rate) { + // Detail is a positive >5k high shelf, never a 1-4k shout EQ. + // Compare the EXACT same core/venue with detail OFF and ON. + Settings s{};s.venue=0;s.bassImpact=0.f;s.width=.95f; + s.immersion=1.f;s.space=.45f; + for(float hz:{90.f,500.f,1500.f,3000.f,7000.f,11000.f}) { + Stereo input; + for(int i=0;i(std::sin(2*pi*hz*i/rate)); + input.l[i]=x;input.r[i]=x; + } + s.detail=0.f;const auto before=render(rate,s,input); + s.detail=1.f;const auto after=render(rate,s,input); + const double a=rms(before,4096,false),b=rms(after,4096,false); + assert(a>1.e-4); + const double ratio=b/a; + if(hz<=3000.f)assert(ratio>=.999&&ratio<1.055); + else assert(ratio>1.02&&ratio<1.39); + } +} +void verifyAudibleWetIsNotNearBypassed(double rate) { + for(int fixture:{0,4,5}) { + Stereo input(32768);makeSignal(input,rate,fixture,311.f); + Settings s{};s.immersion=0.f;s.width=1.f; + s.detail=0.f;s.bassImpact=0.f;s.outputTrim=1.f; + const auto dry=render(rate,s,input); + s.immersion=1.f;s.space=1.f; + const auto wet=render(rate,s,input); + double power=0.,delta=0.; + for(int i=4096;i<32768;++i) { + const double a=input.l[i],b=input.r[i]; + const double dl=wet.l[i]-dry.l[i],dr=wet.r[i]-dry.r[i]; + power+=a*a+b*b;delta+=dl*dl+dr*dr; + } + const double ratio=std::sqrt(delta/(power+1.e-16)); + // Energy-based minimum -24dB PCM delta. This is NOT listener + // acceptability, but rejects the previously practically-bypassed + // room even when a trivial >1e-5 float test passed. + std::fprintf(stderr,"IMERSIP_FULL_ROOM_DELTA rate=%.0f fixture=%d ratio=%.6f dB=%.2f\n", + rate,fixture,ratio,20.*std::log10(ratio+1.e-12)); + if(!(ratio>.063)) { + std::fprintf(stderr, + "IMERSIP_NEAR_BYPASS: rate=%.0f fixture=%d deltaRms=%.8f\n", + rate,fixture,ratio); + assert(false); + } + for(int i=0;i<32768;++i) { + assert(std::abs(dry.l[i]-input.l[i])<1.e-5f); + assert(std::abs(dry.r[i]-input.r[i])<1.e-5f); + } + } +} +void verifyDefaultRoomActuallyChangesPCM(double rate) { + for(int fixture:{0,4}) { + Stereo input(32768);makeSignal(input,rate,fixture,311.f); + Settings settings{};settings.immersion=0.f; + settings.detail=0.f;settings.bassImpact=0.f; + const auto dry=render(rate,settings,input); + const Settings preset{}; + settings.immersion=preset.immersion; + settings.space=preset.space; + const auto wet=render(rate,settings,input); + double signal=0.,changed=0.; + for(int i=4096;i<32768;++i) { + signal+=static_cast(input.l[i])*input.l[i] + +static_cast(input.r[i])*input.r[i]; + changed+=static_cast(wet.l[i]-dry.l[i])* + (wet.l[i]-dry.l[i]) + +static_cast(wet.r[i]-dry.r[i])* + (wet.r[i]-dry.r[i]); + } + const double ratio=std::sqrt(changed/(signal+1.e-14)); + std::fprintf(stderr,"IMERSIP_DEFAULT_ROOM_DELTA rate=%.0f fixture=%d ratio=%.6f\n", + rate,fixture,ratio); + // This tests REAL ROOM/HRIR: both tonal knobs are OFF. Old + // visually-changing near-bypass code is rejected by this gate. + assert(ratio>.025); + } +} +void verifyPeakSafety(double rate) { + Stereo source; + for(int i=0;i( + std::sin(2*pi*997.*i/rate)); + source.l[i]=x;source.r[i]=0.f; + } + Settings s{};s.immersion=1.f;s.space=1.f; + s.width=1.f;s.bassImpact=1.f; + auto result=render(rate,s,source); + for(int i=0;iwindow.__ARMIX_NATIVE_M2__?.enabled") + state=snapshot() + state["graph"]["capabilities"]["supportedOps"].append("LOAD_INSERT") + emit(page,"arMixConsoleSnapshot",state) + # Catalog must be emitted by the NATIVE host; never show an effect + # that the actual executable has not compiled. + page.evaluate("""()=>{ + const s=window.__ARMIX_NATIVE_SCOPE__; + s.openFastPicker(s.tracks.find(t=>t.id===1),0,null); +}""") + selector=f'#fastResults button[data-fast-id="{ID}"]' + assert page.locator(selector).count()==0, "ImerSip falsely advertised before native catalog" + emit(page,"arMixCatalog",{ + "items":[],"scanning":False, + "builtIns":[{"id":ID,"name":"ImerSip","category":"Spatial", + "showInPicker":True}]}) + page.wait_for_function( + """id=>document.querySelectorAll('#fastResults button[data-fast-id="'+id+'"]').length===1""", + arg=ID) + assert page.locator(selector).count()==1, "ImerSip missing or duplicated" + assert page.locator(selector).inner_text().startswith("ImerSip") + page.locator("#fastSearch").fill("imersip") + assert page.locator(selector).count()==1, "native catalog search lost ImerSip" + assert page.locator("#fastResults [data-fast-native-sonku]").count()==0 + # Screenshot must show the actual native GUI picker item, BEFORE click. + page.screenshot(path="imersip-visible-native-picker.png") + page.locator(selector).click() + page.wait_for_function("()=>window.__nativeIntents.length===1") + intent=page.evaluate("()=>window.__nativeIntents[0]") + assert intent["operation"]=="LOAD_INSERT", intent + assert intent["payload"]["catalogId"]==ID, intent + assert intent["payload"]["slot"]==0, intent + # No premature GUI ACTIVE state without native callback/readback. + row=page.locator('#tracks .strip[data-id="1"] .fxslot-row[data-slot="0"]') + assert "ImerSip" not in row.inner_text(), "UI claimed unaccepted audio insert" + assert not errors,errors + browser.close() + print("PASS: compiled native Pages mixer picker filters ImerSip, submits LOAD_INSERT, never fakes an accepted audio instance") + +if __name__=="__main__": + main() diff --git a/tests/imersip_native_state_test.cpp b/tests/imersip_native_state_test.cpp new file mode 100644 index 000000000..ebe49c534 --- /dev/null +++ b/tests/imersip_native_state_test.cpp @@ -0,0 +1,394 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/ImerSipProcessor.h" +#include "../src/NativeBuiltInFx.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(SONKU_P82_MULTIBAND_ROOM_RESEARCH) || !SONKU_P82_MULTIBAND_ROOM_RESEARCH +#error ImerSip native JUCE tests must use actual P8.2 six-wall room +#endif +using armix::builtin_fx::ImerSipProcessor; +using armix::imersip::Settings; + +int main() { + juce::ScopedJuceInitialiser_GUI gui; + // CRITICAL: the P8.2 PCM research flag must register ImerSip in the + // exact native catalog emitted by ConsoleWindow::emitCatalog(). + // Without this gate Windows tests once passed but the FX Picker omitted + // the effect because CMake did not define the *old* macro. + const auto* descriptor=armix::builtin_fx::findNativeBuiltInFx( + ImerSipProcessor::catalogIdentity); + assert(descriptor!=nullptr); + assert(descriptor->showInPicker); + assert(std::strcmp(descriptor->name,"ImerSip")==0); + assert(std::strcmp(descriptor->category,"Spatial")==0); + assert(descriptor->minimumLiveRate==44100.); + assert(descriptor->maximumLiveRate==48000.); + auto catalogInstance=descriptor->prepare(48000.,128,nullptr,0); + assert(catalogInstance); + assert(dynamic_cast(catalogInstance.get())!=nullptr); + catalogInstance.reset(); + + // This processor owns large, fixed DSP ring buffers. Keeping several + // instances on the Windows test thread's ~1MB stack caused SegFault. + auto fx=std::make_unique(); + assert(fx->getName()=="ImerSip"); + // A verified native insert without a real editor is not a usable product. + assert(fx->hasEditor()); + { + std::unique_ptr ui(fx->createEditor()); + assert(ui && + ui->getWidth()==armix::builtin_fx::ImerSipEditor::editorWidth && + ui->getHeight()==armix::builtin_fx::ImerSipEditor::editorHeight); + assert(ui->findChildWithID("imersip.power")); + assert(ui->findChildWithID("imersip.preset")); + assert(ui->findChildWithID("imersip.close")); + // No fake browser PCM or secondary processing engine. + } + assert(fx->isBusesLayoutSupported(fx->getBusesLayout())); + fx->prepareToPlay(48000.,128); + assert(fx->isReady()); + assert(fx->measuredStereoStageEnabled()); // real two KEMAR sources + auto settings=fx->acceptedSettings(); + // Read the real initializer, never pin an obsolete preset value. + // That mistake previously turned a good Windows build RED solely + // because the MUSIC default Bass Impact changed from 75% to 55%. + const Settings initialPreset{}; + assert(settings.bassImpact==initialPreset.bassImpact); + assert(settings.immersion==initialPreset.immersion); + assert(settings.space==initialPreset.space); + assert(settings.width==initialPreset.width); + assert(settings.depth==initialPreset.depth); + assert(settings.stereoLock==initialPreset.stereoLock); + juce::MemoryBlock before; + fx->getStateInformation(before); + assert(before.getSize()==52); + assert(!fx->restoreUnpublishedState(before.getData(),51)); + std::array corrupted{}; + std::memcpy(corrupted.data(),before.getData(),52); + corrupted[0]=0; + assert(!fx->restoreUnpublishedState(corrupted.data(),52)); + assert(!fx->queueSettings(settings,0)); + settings.venue=1;settings.immersion=.81f; + settings.width=.9f;settings.bassImpact=.95f;settings.detail=.65f; + settings.stereoLock=.92f;settings.lateRoom=.31f; + settings.depth=.77f;settings.earAlignDegrees=-19.5f; + assert(fx->queueSettings(settings,52)); + assert(!fx->stateSnapshotQuiescent()); + juce::AudioBuffer pcm(2,128); + juce::MidiBuffer midi; + for(int i=0;i<128;++i) { + const float s=.2f*std::sin( + 6.28318530718f*static_cast(i)/128.f); + pcm.setSample(0,i,s); + pcm.setSample(1,i,-s); + } + fx->processBlock(pcm,midi); + ImerSipProcessor::Completion ack{}; + assert(fx->pollCompletion(ack)); + assert(ack.requestId==52&&ack.applied); + assert(ack.settings.venue==1); + assert(fx->stateSnapshotQuiescent()); + assert(fx->acceptedSettings().width==.9f); + // Reproduce Save immediately after an audio block: Save may consume + // ACK before the editor's timer polls it. A latched record must retain + // the applied identity and monotonic sequence across editor reopen. + settings.detail=.72f; + assert(fx->queueSettings(settings,53)); + fx->processBlock(pcm,midi); + juce::MemoryBlock savedDuringEdit; + fx->getStateInformation(savedDuringEdit); + assert(savedDuringEdit.getSize()==52); + assert(fx->lastCompletedRequestId()==53); + assert(fx->lastCompletionApplied()); + assert(fx->acceptedSettings().detail==.72f); + assert(fx->nextEditorRequestId()>53); + for(int i=0;i<128;++i) { + assert(std::isfinite(pcm.getSample(0,i))); + assert(std::isfinite(pcm.getSample(1,i))); + } + juce::MemoryBlock snapshot; + fx->getStateInformation(snapshot); + assert(snapshot.getSize()==52); + // This processor owns large, fixed DSP ring buffers. Keeping several + // instances on the Windows test thread's ~1MB stack caused SegFault. + auto restored=std::make_unique(); + restored->prepareToPlay(48000.,128); + assert(restored->isReady()); + assert(restored->restoreUnpublishedState(snapshot.getData(), + static_cast(snapshot.getSize()))); + auto selected=restored->acceptedSettings(); + assert(selected.venue==1&&selected.width==.9f); + assert(selected.bassImpact==.95f&&selected.immersion==.81f); + assert(selected.detail==.72f); + assert(selected.stereoLock==.92f&&selected.lateRoom==.31f); + assert(selected.depth==.77f); + assert(selected.earAlignDegrees==-19.5f); + restored->sealForRealtime(); + assert(!restored->restoreUnpublishedState(snapshot.getData(),52)); + // Old 32-byte IMRS v1 sessions must load WITHOUT unexpected Detail boost. + juce::MemoryBlock legacy; + { + // JUCE MemoryOutputStream commits its destination MemoryBlock when + // destroyed. Inspecting it while the stream is still alive used to + // falsely reject a valid 32-byte legacy session fixture. + juce::MemoryOutputStream v1(legacy,false); + v1.writeInt(0x494D5253); + v1.writeInt(1); + v1.writeInt(selected.venue); + v1.writeFloat(selected.immersion); + v1.writeFloat(selected.space); + v1.writeFloat(selected.width); + v1.writeFloat(selected.bassImpact); + v1.writeFloat(selected.outputTrim); + } + assert(legacy.getSize()==32); + // This processor owns large, fixed DSP ring buffers. Keeping several + // instances on the Windows test thread's ~1MB stack caused SegFault. + auto oldSession=std::make_unique(); + oldSession->prepareToPlay(48000.,128); + assert(oldSession->isReady()); + assert(oldSession->restoreUnpublishedState(legacy.getData(),32)); + assert(oldSession->acceptedSettings().detail==0.f); + assert(oldSession->acceptedSettings().stereoLock==1.f); + assert(oldSession->acceptedSettings().lateRoom==.45f); + assert(oldSession->acceptedSettings().depth==.60f); + assert(oldSession->acceptedSettings().earAlignDegrees==0.f); + // Legacy v2 (36-byte) must preserve DETAIL while migrating new + // controls to music-safe defaults, not silently adopt full wet. + juce::MemoryBlock v2; + { + juce::MemoryOutputStream writer(v2,false); + writer.writeInt(0x494D5253);writer.writeInt(2); + writer.writeInt(selected.venue); + writer.writeFloat(selected.immersion); + writer.writeFloat(selected.space); + writer.writeFloat(selected.width); + writer.writeFloat(selected.bassImpact); + writer.writeFloat(selected.outputTrim); + writer.writeFloat(selected.detail); + } + assert(v2.getSize()==36); + auto v2Session=std::make_unique(); + v2Session->prepareToPlay(48000.,128); + assert(v2Session->restoreUnpublishedState(v2.getData(),36)); + assert(v2Session->acceptedSettings().detail==selected.detail); + assert(v2Session->acceptedSettings().stereoLock==1.f); + assert(v2Session->acceptedSettings().lateRoom==.45f); + assert(v2Session->acceptedSettings().depth==.60f); + assert(v2Session->acceptedSettings().earAlignDegrees==0.f); + // A/B is a transient monitor control, not an accepted session edit. + juce::MemoryBlock initialCompareState; + v2Session->getStateInformation(initialCompareState); + v2Session->setCompareDry(true); + assert(v2Session->comparingOriginal()); + juce::MemoryBlock whileComparing; + v2Session->getStateInformation(whileComparing); + assert(whileComparing==initialCompareState); + v2Session->setCompareDry(false); + assert(!v2Session->comparingOriginal()); + // Existing IMRS v3 state (44 bytes) must ALSO recover on v4, + // retaining stereo safety and late tail with new calibrated depth. + juce::MemoryBlock v3; + { + juce::MemoryOutputStream w(v3,false); + w.writeInt(0x494D5253);w.writeInt(3); + w.writeInt(selected.venue);w.writeFloat(selected.immersion); + w.writeFloat(selected.space);w.writeFloat(selected.width); + w.writeFloat(selected.bassImpact);w.writeFloat(selected.outputTrim); + w.writeFloat(selected.detail);w.writeFloat(selected.stereoLock); + w.writeFloat(selected.lateRoom); + } + assert(v3.getSize()==44); + auto v3Session=std::make_unique(); + v3Session->prepareToPlay(48000.,128); + assert(v3Session->restoreUnpublishedState(v3.getData(),44)); + assert(v3Session->acceptedSettings().stereoLock==selected.stereoLock); + assert(v3Session->acceptedSettings().lateRoom==selected.lateRoom); + assert(v3Session->acceptedSettings().depth==.60f); + assert(v3Session->acceptedSettings().earAlignDegrees==0.f); + // IMRS v4 from earlier headset sessions keeps its physical depth, + // but cannot have a hidden HRTF alignment never stored by that ABI. + juce::MemoryBlock v4; + { + juce::MemoryOutputStream w(v4,false); + w.writeInt(0x494D5253);w.writeInt(4); + w.writeInt(selected.venue);w.writeFloat(selected.immersion); + w.writeFloat(selected.space);w.writeFloat(selected.width); + w.writeFloat(selected.bassImpact);w.writeFloat(selected.outputTrim); + w.writeFloat(selected.detail);w.writeFloat(selected.stereoLock); + w.writeFloat(selected.lateRoom);w.writeFloat(selected.depth); + } + assert(v4.getSize()==48); + auto v4Session=std::make_unique(); + v4Session->prepareToPlay(48000.,128); + assert(v4Session->restoreUnpublishedState(v4.getData(),48)); + assert(v4Session->acceptedSettings().depth==selected.depth); + assert(v4Session->acceptedSettings().earAlignDegrees==0.f); + // REAL JUCE processor PCM callback, not merely the standalone DSP + // helper: prove the native FX insert produces a measurable wet room + // output even for a CENTERED MONO orchestra instrument. + // This processor owns large, fixed DSP ring buffers. Keeping several + // instances on the Windows test thread's ~1MB stack caused SegFault. + auto audible=std::make_unique(); + audible->prepareToPlay(48000.,128); + assert(audible->isReady()); + // Native JUCE editor sensitivity, not just a C++ setter. + // The live DEEP STAGE slider MUST reach native PCM queue/accepted ACK. + { + std::unique_ptr live(audible->createEditor()); + assert(live); + auto* depth=dynamic_cast( + live->findChildWithID("imersip.depth")); + auto* stereo=dynamic_cast( + live->findChildWithID("imersip.stereo")); + auto* align=dynamic_cast( + live->findChildWithID("imersip.ear-align")); + auto* power=dynamic_cast( + live->findChildWithID("imersip.power")); + auto* imer=dynamic_cast(live.get()); + assert(depth&&stereo&&align&&power&&imer); + assert(!power->isEnabled()); // host-controlled, no local fake power + assert(live->getWidth()==armix::builtin_fx::ImerSipEditor::editorWidth); + assert(live->getHeight()==armix::builtin_fx::ImerSipEditor::editorHeight); + assert(!depth->getBounds().intersects(align->getBounds())); + assert(!power->getBounds().intersects(stereo->getBounds())); + auto* preset=dynamic_cast( + live->findChildWithID("imersip.preset")); + auto* close=dynamic_cast( + live->findChildWithID("imersip.close")); + assert(preset&&close); + assert(preset->getSelectedId()==2); + assert(!preset->getBounds().intersects(power->getBounds())); + assert(!preset->getBounds().intersects(close->getBounds())); + assert(!power->getBounds().intersects(close->getBounds())); + // Factory preset is an actual AUDIO edit, not cosmetic JSON state. + preset->setSelectedId(3,juce::sendNotificationSync); // Warm Hi-Fi + juce::AudioBuffer presetPulse(2,128);presetPulse.clear(); + audible->processBlock(presetPulse,midi); + ImerSipProcessor::Completion recalled{}; + assert(audible->pollCompletion(recalled)&&recalled.applied); + assert(std::abs(recalled.settings.bassImpact-.90f)<1.e-5f); + assert(std::abs(recalled.settings.lateRoom-.15f)<1.e-5f); + preset->setSelectedId(2,juce::sendNotificationSync); // Music Default + presetPulse.clear(); + audible->processBlock(presetPulse,midi); + assert(audible->pollCompletion(recalled)&&recalled.applied); + assert(std::abs(recalled.settings.bassImpact-Settings{}.bassImpact)<1.e-5f); + assert(std::abs(recalled.settings.detail-Settings{}.detail)<1.e-5f); + bool bypassed=false; + imer->bindHostPower([&](bool next){bypassed=next;return true;}, + [&]{return bypassed;}); + assert(power->isEnabled()&&power->getButtonText()=="INSERT ON"); + power->onClick(); + assert(bypassed&&power->getButtonText()=="INSERT OFF"); + // Hiding is not destruction: it must keep same JUCE editor and + // accepted DSP instance, while the native SLOT bypass remains OFF. + const auto* sameEditor=live.get(); + live->setVisible(false); + assert(live.get()==sameEditor); + live->setVisible(true); + assert(live.get()==sameEditor && bypassed); + // A real rack master switch is independent of insert power. + bool rackMasterBypassed=true; + assert(rackMasterBypassed && bypassed); + power->onClick(); + assert(!bypassed&&power->getButtonText()=="INSERT ON"); + assert(rackMasterBypassed); + // Match built-in FX CLOSE behaviour: hide editor but not DSP/lease. + close->onClick(); + assert(!live->isVisible()&&!bypassed); + live->setVisible(true); + assert(live.get()==sameEditor); + assert(std::abs(depth->getValue()-100.*Settings{}.depth)<.01); + depth->setValue(87.,juce::sendNotificationSync); + juce::AudioBuffer pulse(2,128);pulse.clear(); + audible->processBlock(pulse,midi); + ImerSipProcessor::Completion moved{}; + assert(audible->pollCompletion(moved)); + assert(moved.applied); + assert(std::abs(moved.settings.depth-.87f)<1.e-5f); + align->setValue(-19.5,juce::sendNotificationSync); + pulse.clear(); + audible->processBlock(pulse,midi); + ImerSipProcessor::Completion aligned{}; + assert(audible->pollCompletion(aligned)&&aligned.applied); + assert(aligned.settings.earAlignDegrees==-19.5f); + } + // Reopening must not reset this insert's accepted native settings. + { + std::unique_ptr again(audible->createEditor()); + assert(again && again->findChildWithID("imersip.power")); + // A fresh UI for the SAME retained DSP does not fabricate native + // power authority: host must explicitly bind the current slot. + auto* reopenedPower=dynamic_cast( + again->findChildWithID("imersip.power")); + assert(reopenedPower && !reopenedPower->isEnabled()); + auto* restoredDepth=dynamic_cast( + again->findChildWithID("imersip.depth")); + assert(restoredDepth&&std::abs(restoredDepth->getValue()-87.)<.01); + } + auto full=audible->acceptedSettings(); + full.venue=0;full.immersion=1.f;full.space=1.f; + full.width=1.f;full.bassImpact=0.f;full.detail=0.f; + full.outputTrim=1.f; + assert(audible->queueSettings(full,6001)); + juce::AudioBuffer inOut(2,128); + double originalEnergy=0.,processedDeltaEnergy=0.; + constexpr double pi=3.14159265358979323846; + for(int block=0;block<256;++block) { + for(int i=0;i<128;++i) { + const int frame=block*128+i; + const double time=frame/48000.; + const float v=static_cast( + .16*std::sin(2.*pi*311.*time)+ + .045*std::sin(2.*pi*1270.*time)); + inOut.setSample(0,i,v); + inOut.setSample(1,i,v); + } + audible->processBlock(inOut,midi); + if(block>=32)for(int i=0;i<128;++i) { + const int frame=block*128+i; + const double time=frame/48000.; + const double direct=.16*std::sin(2.*pi*311.*time)+ + .045*std::sin(2.*pi*1270.*time); + const double dl=inOut.getSample(0,i)-direct; + const double dr=inOut.getSample(1,i)-direct; + originalEnergy+=2.*direct*direct; + processedDeltaEnergy+=dl*dl+dr*dr; + } + } + ImerSipProcessor::Completion audibleAck{}; + assert(audible->pollCompletion(audibleAck)); + assert(audibleAck.requestId==6001&&audibleAck.applied); + // The editor exercises four genuine 128-frame audio callbacks before + // the 256 x 128-frame musical PCM loop: two preset ACKs, depth ACK, + // and ear-alignment ACK. Count ALL real callbacks, never relax the + // inserted-FX audio-processing evidence to make CI green. + constexpr std::uint64_t editorAckFrames=4u*128u; + constexpr std::uint64_t musicalFrames=256u*128u; + assert(audible->processedFrames()==editorAckFrames+musicalFrames); + assert(audible->liveInputEnergy()>1.e-5f); + assert(audible->liveDifferenceEnergy()>1.e-4f); + const double actualDelta=std::sqrt( + processedDeltaEnergy/(originalEnergy+1.e-16)); + std::fprintf(stderr, + "IMERSIP_REAL_JUCE_WET_DELTA_48K=%.6f dB=%.2f\n", + actualDelta,20.*std::log10(actualDelta+1.e-12)); + assert(actualDelta>.050); + assert(actualDelta<.75); + audible->releaseResources(); + + fx->releaseResources(); + assert(!fx->isReady()); + return 0; +}