diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 0c1b189af..19a93f451 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -698,6 +698,16 @@ jobs: /tmp/sonku-p96-candidate > /tmp/sonku-p96-candidate.csv cat /tmp/sonku-p96-reference.csv /tmp/sonku-p96-candidate.csv python3 scripts/verify_sonku_p96_bands.py /tmp/sonku-p96-reference.csv /tmp/sonku-p96-candidate.csv + if [[ "${{ github.head_ref }}" == feat/sonku-p95-p96-p97-* ]]; then + g++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic tests/sonku_p97_stage_impact_source_test.cpp -o /tmp/sonku-p97-unit + /tmp/sonku-p97-unit + g++ $FLAGS -DSONKU_P94_FRONT_BACK_DEPTH_RESEARCH=1 -DSONKU_P95_MUSICAL_PRESENCE_RESEARCH=1 -DSONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH=1 tests/sonku_p97_full_pcm_test.cpp -o /tmp/sonku-p97-reference + /tmp/sonku-p97-reference > /tmp/sonku-p97-reference.csv + g++ $FLAGS -DSONKU_P94_FRONT_BACK_DEPTH_RESEARCH=1 -DSONKU_P95_MUSICAL_PRESENCE_RESEARCH=1 -DSONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH=1 -DSONKU_P97_STAGE_IMPACT_RESEARCH=1 tests/sonku_p97_full_pcm_test.cpp -o /tmp/sonku-p97-candidate + /tmp/sonku-p97-candidate > /tmp/sonku-p97-candidate.csv + cat /tmp/sonku-p97-reference.csv /tmp/sonku-p97-candidate.csv + python3 scripts/verify_sonku_p97_stage_impact.py /tmp/sonku-p97-reference.csv /tmp/sonku-p97-candidate.csv + fi fi fi g++ $FLAGS tests/sonku_p89_stereo_room_depth_source_test.cpp -o /tmp/sonku-p89 @@ -731,6 +741,7 @@ jobs: run: | $p95flag = if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-*') { 'ON' } else { 'OFF' } $p96flag = if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { 'ON' } else { 'OFF' } + $p97flag = if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-p97-*') { 'ON' } else { 'OFF' } cmake -S . -B build -G "Visual Studio 17 2022" -A x64 ` -DJUCE_ROOT="$env:GITHUB_WORKSPACE/third_party/JUCE" ` -DJUCE_WEBVIEW2_PACKAGE_LOCATION="$env:GITHUB_WORKSPACE/.deps" ` @@ -749,6 +760,7 @@ jobs: -DARMIX_SONKU_EXPERIMENTAL_P94_FRONT_BACK_DEPTH=ON ` -DARMIX_SONKU_EXPERIMENTAL_P95_MUSICAL_PRESENCE=$p95flag ` -DARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT=$p96flag ` + -DARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT=$p97flag ` -DBUILD_TESTING=ON if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $cache = Get-Content build/CMakeCache.txt -Raw @@ -764,6 +776,7 @@ jobs: $targets = @('ARMixSonKuP94SourceTests','ARMixSonKuP94ReferenceTests','ARMixSonKuP91P92MusicBassTests','ARMixSonKuP90NativeTests','ARMixSonKuP90SourceTests','ARMixSonKuP89NativeTests','ARMixSonKuP89SourceTests','ARMixConsole') if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-*') { $targets += 'ARMixSonKuP95MusicTests' } if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { $targets += 'ARMixSonKuP96DistanceTests' } + if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-p97-*') { $targets += 'ARMixSonKuP97StageTests' } cmake --build build --config Release --parallel 2 --target $targets if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } if (-not (Test-Path -LiteralPath 'build/ARMixConsole_artefacts/Release/AR MIX Studio.exe' -PathType Leaf)) { @@ -772,6 +785,7 @@ jobs: $tests = '^NativeSonKuP(89RoomAnchoredStereoAndP88GoldenParity|89JuceV10AppliedAckAndV9Restore|90StereoExternalizationSource|90JuceV11AppliedAckAndLegacyRestore|91P92MusicFidelityWorldBassAndRoom|94FrontBackDepthA_BSource|94LevelMatchedAB' if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-*') { $tests += '|95MusicPresenceVenue' } if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { $tests += '|96DistanceBassAndTrebleRetention' } + if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-p97-*') { $tests += '|97BassVocalExternalAirSafety' } $tests += ')$' ctest --test-dir build -C Release --output-on-failure -R $tests if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } @@ -792,6 +806,9 @@ jobs: Copy-Item docs/SONKU_P95_IMMERSIVE_MUSIC_VENUE_FAT_20261116.md dist/SONKU_P95_MUSIC_VENUE_FAT.md if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { Copy-Item docs/SONKU_P96_DISTANCE_REINFORCEMENT_FAT_20261116.md dist/SONKU_P96_DISTANCE_FAT.md + if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-p97-*') { + Copy-Item docs/SONKU_P97_STAGE_IMPACT_FAT_20261116.md dist/SONKU_P97_STAGE_FAT.md + } } } $provenance = Get-Content -LiteralPath dist/BUILD_PROVENANCE.json -Raw | ConvertFrom-Json @@ -799,7 +816,7 @@ jobs: throw 'SONKU_P90_SOURCE_COMMIT_MISMATCH' } $provenance | Add-Member -Force -NotePropertyName sonkuExperiment -NotePropertyValue @{ - mode = if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { 'P9.6_STAGE_BASS_AIR_DISTANCE_RESEARCH' } elseif ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-*') { 'P9.5_IMMERSIVE_MUSIC_VENUE_FOUNDATION' } else { 'P9.4_FRONT_REAR_DEPTH_EXPERIMENT' } + mode = if ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-p97-*') { 'P9.7_STAGE_IMPACT_EXTERNAL_PRESENCE_RESEARCH' } elseif ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-p96-*') { 'P9.6_STAGE_BASS_AIR_DISTANCE_RESEARCH' } elseif ($env:GITHUB_HEAD_REF -like 'feat/sonku-p95-*') { 'P9.5_IMMERSIVE_MUSIC_VENUE_FOUNDATION' } else { 'P9.4_FRONT_REAR_DEPTH_EXPERIMENT' } stateSchema = 11 headphoneFat = 'PENDING' publicRelease = $false diff --git a/CMakeLists.txt b/CMakeLists.txt index fce8f49c3..cc0df0b81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,13 @@ if(ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT AND NOT ARMIX_SONKU_EXPERIMENTAL_P95_MUSICAL_PRESENCE) message(FATAL_ERROR "P9.6 requires P9.5 musical presence and P9 world speaker") endif() +# P9.7 is research only and never changes the approved P9.6 checkpoint. +option(ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT + "Private P9.7 concert bass impact, center HRTF and binaural early air" OFF) +if(ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT AND + NOT ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT) + message(FATAL_ERROR "P9.7 requires the P9.6 sound-reinforced world-speaker engine") +endif() set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -339,7 +346,9 @@ target_compile_definitions(ARMixConsole PRIVATE $<$:ARMIX_SONKU_EXPERIMENTAL_P95_MUSICAL_PRESENCE=1> $<$:SONKU_P95_MUSICAL_PRESENCE_RESEARCH=1> $<$:SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH=1> - $<$:ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT=1>) + $<$:ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT=1> + $<$:SONKU_P97_STAGE_IMPACT_RESEARCH=1> + $<$:ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT=1>) if(WIN32) # Windows retains its proven ASIO-first / WASAPI / static WebView2 distribution. # Never link Windows loader or sound APIs into macOS/Linux builds. @@ -874,7 +883,8 @@ if(BUILD_TESTING) $ SONKU_P94_FRONT_BACK_DEPTH_RESEARCH=1 SONKU_P95_MUSICAL_PRESENCE_RESEARCH=1 - $<$:SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH=1>) + $<$:SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH=1> + $<$:SONKU_P97_STAGE_IMPACT_RESEARCH=1>) add_test(NAME NativeSonKuP95MusicPresenceVenue COMMAND ARMixSonKuP95MusicTests) endif() @@ -885,6 +895,13 @@ if(BUILD_TESTING) add_test(NAME NativeSonKuP96DistanceBassAndTrebleRetention COMMAND ARMixSonKuP96DistanceTests) endif() + if(ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT) + add_executable(ARMixSonKuP97StageTests + tests/sonku_p97_stage_impact_source_test.cpp) + target_compile_features(ARMixSonKuP97StageTests PRIVATE cxx_std_20) + add_test(NAME NativeSonKuP97BassVocalExternalAirSafety + COMMAND ARMixSonKuP97StageTests) + endif() juce_add_console_app(ARMixSonKuP90NativeTests PRODUCT_NAME "ArSonMix SonKu P90 JUCE v11 State Tests") target_sources(ARMixSonKuP90NativeTests PRIVATE diff --git a/docs/SONKU_P97_STAGE_IMPACT_FAT_20261116.md b/docs/SONKU_P97_STAGE_IMPACT_FAT_20261116.md new file mode 100644 index 000000000..4c4c1ffc8 --- /dev/null +++ b/docs/SONKU_P97_STAGE_IMPACT_FAT_20261116.md @@ -0,0 +1,31 @@ +# SonKu P9.7 Stage Impact and External Presence — PRIVATE FAT, 2026-11-16 + +**Selected listening checkpoint:** P9.6 PR #727 head `720cec619b41aa601414d4b5ae664cb418f04ca1`. User confirmed P9.6 is already reasonably good; preserve it immutably for A/B. P9.7 is a child branch and does not rebase P9.6, alter `main`, merge the competing P9.5 PR #724, or change old .smix bytes. + +## Research, limits, and actual algorithm + +- [Sound Externalization: A Review of Recent Research](https://pmc.ncbi.nlm.nih.gov/articles/PMC7488874/) describes the significance of direct pinna cues, realistic interaural differences in reverberation, and room/source congruence. Real externalization requires headphone listening and cannot be proven by spectral gain or generalized KEMAR only. +- [Jiang et al., effect of pinna filtering](https://doi.org/10.1016/j.apacoust.2020.107257) finds direct pinna filtering helps externalization whereas applying it to diffuse reverberation can reduce externalization. We retain the measured direct HRIR and existing non-pinna image-source ER path. +- [AES virtual bass review](https://aes.org/publications/elibrary/elibrary-page/?id=18050) documents perceived bass versus distortion risks. We DO NOT generate missing-fundamental harmonics, synthesize extra LFE, or attach a headlocked mono bass. + +One opt-in **native P9.7** component (`SonKuP97StageImpact.h`) adds three bounded paths to the existing P9 mode-9 scene only when ROOM is ON and distance is above 2m. All parameters are research constants, not hardcoded .smix fields or hidden GUI pseudo-controls: + +1. **Concert punch / room body:** prepared, low-Q ~85Hz bandpass at +0.23 relative peak to the already HRTF/P9.6-processed direct ear pressure; one-pole 62Hz sub body at +0.085. The existing P9.2 position-aware damped 3-mode low-frequency *room return* is modestly increased by at most 12%, without modifying resonator decay or creating uncontrolled feedback. +2. **Center-panned presence (not vocal separation):** low-Q ~1.9kHz bandpass of INPUT L+R MID with at most +0.19 on both virtual speaker source feeds, before existing full KEMAR HRIR convolution. The center-band is filtered twice to suppress high-frequency phase leakage, and a further modest +0.085 centered presence band is added to the *already HRIR-positioned direct ears*, never a dry mono voice. The original stereo feeds remain authoritative for decoder observation, P9.2 world bass and room reflections. No dry/headlocked vocal injection or extra FIR. This can enhance centered vocal *and centered instruments*; it is NOT an AI stem separator. +3. **Early-reflection air:** +0.24 of the high-pass complement above 4.5kHz, applied only to the existing two-ear directional early-reflection result. No inter-channel mixing, Haas timing, repeated reverb worker or extra spectral EQ on the diffuse tail. This aims to improve high-frequency spatial cues without simply making room reverb hissier. + +A small +0.038 high-frequency direct-air complement preserves the already-external KEMAR cymbal/treble energy when the center-band is boosted, avoiding the earlier P9.7 first-pass regression where 7.5kHz electrical energy fell by ~13% at 10m. An explicit no-high-loss test now rejects that outcome. P9.5's adaptive upward makeup was found to reduce its overall gain as P9.7 made bass and center louder; in the first integrated candidate 7.5kHz remained ~16% below P9.6 even after the center-band filter was narrowed. A bounded 135Hz low complement (+0.080 max) and 4.5kHz high complement (+0.35 max) are therefore applied to the **already externalized, post-P9.5 stereo ear signal** immediately before the unchanged linked 0.98 peak guard. This last-stage gain is not an extra dry/stem/reverb path, and identical bilateral coefficients preserve channel-based localization cues. A test checks spectral output *after* P9.5 normalization. Reject the design if the limiter's dynamic pumping increases on music FAT. + +All P9.7 source, direct/early/modal and post-makeup stages are explicitly disabled at 0% spatial MIX so the existing native dry/bypass is preserved bit for bit; the full-PCM hash verifier covers that case with ROOM still enabled at 10m. + +The three gains ramp together over 45ms as distance moves through 2–6m. All bands use control-side prepared coefficients, bounded stable filters, fixed memory and no callback allocations. No new EQ slots, public schema, selectable render modes, fake stereo widening or additional HRTF graph. P9.5 output makeup and 0.98 linked peak guard remain unchanged. + +## Gates before approving listening audio + +1. Independently compile 44.1/48k source tests for exact ROOM OFF, 0% spatial MIX with active ROOM, and <=2m, voice/air/bass response, finite PCM, antiphase symmetry, bounded room-modal amplification and no device-restart stale memory. +2. Compare complete P9.6 and P9.7 native PCM *hashes* at 2m and ROOM OFF, and target bands at 3.1m and 10m (front and back) for 44.1/48k, using the very same source fixture. The checkpoint must remain bit-for-bit identical in disabled scenes. This guards known-good sound rather than relying on nominal gains. +3. Compile exact Windows JUCE application, V11 state/ACK, sample-peak safety CTests, UI Chromium and source-provenance portable in a branch-qualified build. No public release/merge based on a green Linux source test alone. +4. Operator headphone A/B at matching LUFS and also matching *GAIN setting*: kick/tom attack, bass audibility and decay, center vocal location and intelligibility, edge/cymbal air, interaural position, stage distance, reverb body, 0/90/180/270° and 44.1/48k. Reject nasal vocals, metallic cymbals, mono collapse, bass masking, over-limiter pumping, apparent image moving inside the head. User preference controls promotion. +5. No marketing claim of source-separated vocals, customized individual BRIR, measured live concert loudspeaker impulse response, true-peak certification or dearVR acoustic parity. + +**Checkpoint:** P9.6 remains branch/PR #727 and this draft P9.7 is entirely removable by deleting its child branch. Feature OFF recovers P9.6 binary behavior and no new user parameter exists. diff --git a/engine/builtin_fx/sonku/SonKuP97StageImpact.h b/engine/builtin_fx/sonku/SonKuP97StageImpact.h new file mode 100644 index 000000000..5384fd3cc --- /dev/null +++ b/engine/builtin_fx/sonku/SonKuP97StageImpact.h @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include + +// PRIVATE P9.7 concert-stage enhancement. No stems, no pseudo-vocal isolation: +// "center presence" applies equally to any center-panned material. Every +// added signal stays in the SAME measured world-speaker binaural graph. +// The source MID band goes THROUGH the existing HRIR. Bass reinforces the +// already HRTF/world-positioned direct ears, and air reinforces actual +// stereo image-source early reflections (not synthetic Haas/stereo widening). +// 0 additional delay; no heap, FFT, worker, I/O, trigonometry or exp in PCM. +namespace armix::sonku::p97 { +class StageImpact final { +public: + struct Stereo {float left=0.f,right=0.f;}; + bool prepare(double sampleRate) noexcept { + if(!std::isfinite(sampleRate) || + (std::abs(sampleRate-44100.)>.1 && + std::abs(sampleRate-48000.)>.1))return false; + constexpr double pi=3.1415926535897932384626433832795; + centerCoeff_=bandpass(sampleRate,1900.,.90); + punchCoeff_=bandpass(sampleRate,85.,.85); + subAlpha_=static_cast(1.-std::exp(-2.*pi*62./sampleRate)); + airAlpha_=static_cast(1.-std::exp(-2.*pi*4500./sampleRate)); + finalLowAlpha_=static_cast(1.-std::exp(-2.*pi*135./sampleRate)); + slew_=static_cast(1.-std::exp(-1./(sampleRate*.045))); + reset(); + return true; + } + void reset() noexcept { + vocal_={};vocalSecond_={};vocalDirect_={}; + punch_={};sub_={};earlyAir_={};directAir_={}; + finishLow_={};finishWide_={};stage_=0.f; + } + bool active() const noexcept {return stage_!=0.f;} + float strength() const noexcept {return stage_;} + Stereo source(float left,float right,float meters,bool roomEnabled) noexcept { + // One slow scene-depth transition, shared across the 3 stages. + const float target=roomEnabled? + std::clamp((meters-2.f)/4.f,0.f,1.f):0.f; + stage_+=slew_*(target-stage_); + if(std::abs(stage_-target)<1.e-6f)stage_=target; + const float center=.5f*(left+right); + // Two bandpasses suppress out-of-band leakage, especially cymbals + // >6kHz that a single 1.9kHz BPF would partly phase-cancel. + const float band=vocalSecond_.run(centerCoeff_, + vocal_.run(centerCoeff_,center)); + if(stage_==0.f)return {left,right}; + // Both virtual speakers receive exactly the same center delta. + // Their established HRIRs must render it; NEVER send to dry L/R. + const float delta=.19f*stage_*band; + return {left+delta,right+delta}; + } + Stereo direct(float left,float right) noexcept { + const std::array x{left,right}; + std::array result{}; + for(int c=0;c<2;++c) { + const float punch=punch_[c].run(punchCoeff_,x[c]); + sub_[c]+=subAlpha_*(x[c]-sub_[c]); + directAir_[c]+=airAlpha_*(x[c]-directAir_[c]); + const float voice=vocalDirect_[c][1].run(centerCoeff_, + vocalDirect_[c][0].run(centerCoeff_,x[c])); + // Keep spectral pressure tied to the original KEMAR ears. + // The second gentle vocal filter is NOT a dry/mono stem. + result[c]=stage_==0.f?x[c]: + x[c]+stage_*(.23f*punch+.085f*sub_[c]+ + .085f*voice+.038f*(x[c]-directAir_[c])); + } + return {result[0],result[1]}; + } + Stereo early(float left,float right) noexcept { + const std::array x{left,right}; + std::array result{}; + for(int c=0;c<2;++c){ + earlyAir_[c]+=airAlpha_*(x[c]-earlyAir_[c]); + // Boost only the real, azimuth-dependent first images above 4.5k. + // No channel crossing or artificial stereo delay: retain ILD/ITD. + result[c]=stage_==0.f?x[c]: + x[c]+.24f*stage_*(x[c]-earlyAir_[c]); + } + return {result[0],result[1]}; + } + Stereo finish(float left,float right) noexcept { + // P9.5 upward-only RMS makeup is sensitive to increased broadband + // level: direct/stem boosts can make it reduce its earlier makeup, + // unintentionally darkening cymbals. Only AFTER its detector, but + // BEFORE the existing linked peak guard, restore modest LF/HF + // spectral energy to the already-externalized stereo EAR waveform. + // Shared coefficients; no crossfeed, HRTF replacement, or new delay. + const std::array x{left,right}; + std::array result{}; + for(int c=0;c<2;++c){ + finishLow_[c]+=finalLowAlpha_*(x[c]-finishLow_[c]); + finishWide_[c]+=airAlpha_*(x[c]-finishWide_[c]); + result[c]=stage_==0.f?x[c]: + x[c]+stage_*(.080f*finishLow_[c]+ + .35f*(x[c]-finishWide_[c])); + } + return {result[0],result[1]}; + } + Stereo modal(float left,float right) const noexcept { + if(stage_==0.f)return {left,right}; + // Small damped room mode reinforcement, no feedback alteration. + const float level=1.f+.12f*stage_; + return {left*level,right*level}; + } +private: + struct Coeff {float b0=0.f,b1=0.f,b2=0.f,a1=0.f,a2=0.f;}; + struct Filter { + float z1=0.f,z2=0.f; + float run(const Coeff& c,float in) noexcept { + const float out=c.b0*in+z1; + z1=c.b1*in-c.a1*out+z2; + z2=c.b2*in-c.a2*out; + return out; + } + }; + static Coeff bandpass(double sampleRate,double frequency,double q) noexcept { + constexpr double pi=3.1415926535897932384626433832795; + const double w=2.*pi*frequency/sampleRate; + const double alpha=std::sin(w)/(2.*q); + const double inv=1./(1.+alpha); + return {static_cast(alpha*inv),0.f, + static_cast(-alpha*inv), + static_cast(-2.*std::cos(w)*inv), + static_cast((1.-alpha)*inv)}; + } + Coeff centerCoeff_{},punchCoeff_{}; + Filter vocal_{},vocalSecond_{}; + std::array punch_{}; + std::array,2> vocalDirect_{}; + std::array sub_{},earlyAir_{},directAir_{},finishLow_{},finishWide_{}; + float subAlpha_=0.f,airAlpha_=0.f,finalLowAlpha_=0.f,slew_=0.f,stage_=0.f; +}; +} // namespace armix::sonku::p97 diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 8b54a27b0..a5b95b3f2 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -28,6 +28,9 @@ #if defined(SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH) && SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH #include "SonKuP96DistanceReinforcement.h" #endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH +#include "SonKuP97StageImpact.h" +#endif #if defined(SONKU_P94_FRONT_BACK_DEPTH_RESEARCH) && SONKU_P94_FRONT_BACK_DEPTH_RESEARCH #include "SonKuP94FrontBackDepthCue.h" #endif @@ -216,6 +219,9 @@ class SonKuSpatialCore final { #if defined(SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH) && SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH if(!p96Reinforcement_.prepare(rate))return false; #endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + if(!p97Stage_.prepare(rate))return false; +#endif #if defined(SONKU_P95_MUSICAL_PRESENCE_RESEARCH) && SONKU_P95_MUSICAL_PRESENCE_RESEARCH if(!p95Presence_.prepare(rate))return false; #endif @@ -293,6 +299,9 @@ class SonKuSpatialCore final { #if defined(SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH) && SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH p96Reinforcement_.reset(); #endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + p97Stage_.reset(); +#endif #if defined(SONKU_P95_MUSICAL_PRESENCE_RESEARCH) && SONKU_P95_MUSICAL_PRESENCE_RESEARCH p95Presence_.reset(); #endif @@ -353,6 +362,9 @@ class SonKuSpatialCore final { #if defined(SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH) && SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH p96Reinforcement_.reset(); #endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + p97Stage_.reset(); +#endif #if defined(SONKU_P95_MUSICAL_PRESENCE_RESEARCH) && SONKU_P95_MUSICAL_PRESENCE_RESEARCH p95Presence_.reset(); #endif @@ -762,8 +774,21 @@ class SonKuSpatialCore final { if(p83Mode_==p83::Mode::MusicSpatialP90)sideRescue=0.f; #endif #endif - history_[0][write_]=x0; - history_[1][write_]=x1; +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + if(p90World && settings_.spatialMix>0.f){ + // Center material is reinforced ONLY before the existing + // world-speaker HRIR; room, P92 LF, and decoder observe + // the original stereo. No center headphone dry injection. + const auto fed=p97Stage_.source(x0,x1, + settings_.sourceDistanceMeters,roomEnabled); + history_[0][write_]=fed.left; + history_[1][write_]=fed.right; + }else +#endif + { + history_[0][write_]=x0; + history_[1][write_]=x1; + } float ears[2]{0.f,0.f}; for(int tap=0;tap0.f){ + // Spectral stage changes remain tied to the HRTF and + // the existing 6-wall first-image / P92 modal fields. + // Identical stereo-ear coefficients do not pan/delay + // sources or manufacture independent mono-bass channels. + const auto punch=p97Stage_.direct(directL,directR); + directL=punch.left;directR=punch.right; + const auto air=p97Stage_.early(reflection.left,reflection.right); + reflection.left=air.left;reflection.right=air.right; + const auto modal=p97Stage_.modal(p92RoomBass.left,p92RoomBass.right); + p92RoomBass.left=modal.left;p92RoomBass.right=modal.right; + } #endif float spatialL=directL+ smoothedErPresence_*calibratedEarly*reflection.left+ @@ -1012,6 +1051,14 @@ class SonKuSpatialCore final { outL*=makeup;outR*=makeup; } } +#endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + if(p90World && settings_.spatialMix>0.f){ + // The finished ear tonal block MUST NOT touch + // 0% MIX (native dry/bypass) even while ROOM remains ON. + const auto finished=p97Stage_.finish(outL,outR); + outL=finished.left;outR=finished.right; + } #endif // Zero-lookahead *linked* sample-peak safety guard. Quiet // signals are linear; peaks are gently returned below unity @@ -1328,6 +1375,9 @@ class SonKuSpatialCore final { #if defined(SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH) && SONKU_P96_DISTANCE_REINFORCEMENT_RESEARCH p96::DistanceReinforcement p96Reinforcement_{}; #endif +#if defined(SONKU_P97_STAGE_IMPACT_RESEARCH) && SONKU_P97_STAGE_IMPACT_RESEARCH + p97::StageImpact p97Stage_{}; +#endif #if defined(SONKU_P95_MUSICAL_PRESENCE_RESEARCH) && SONKU_P95_MUSICAL_PRESENCE_RESEARCH p95::MusicalPresence p95Presence_{}; #endif diff --git a/scripts/verify_sonku_p97_stage_impact.py b/scripts/verify_sonku_p97_stage_impact.py new file mode 100644 index 000000000..455f20f31 --- /dev/null +++ b/scripts/verify_sonku_p97_stage_impact.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""P9.7 must not overwrite selected P9.6 checkpoint source sound.""" +from pathlib import Path +import sys + +def parse(path): + rows={} + for line in Path(path).read_text().splitlines(): + if not line.startswith("P97_FULL,"): continue + p=line.split(",") + assert len(p)==10, line + k=(int(p[1]),int(p[2]),int(p[3]),float(p[4]),float(p[5])) + assert k not in rows + rows[k]=(tuple(float(v) for v in p[6:9]),p[9]) + assert len(rows)==20,(path,len(rows)) + return rows + +def main(): + assert len(sys.argv)==3 + base,new=parse(sys.argv[1]),parse(sys.argv[2]) + assert base.keys()==new.keys() + for k,(old,old_hash) in base.items(): + current,current_hash=new[k] + rate,az,room,distance,mix=k + if room==0 or distance<=2. or mix==0.: + assert old_hash==current_hash, f"P96_CHECKPOINT_BIT_EXACT_FAILED {k}" + else: + ratios=[b/a for a,b in zip(old,current)] + print("P97_STAGE_REAL_PCM",k,"bass/vocal/air",*[round(v,3) for v in ratios]) + if distance>=10.: + assert ratios[0]>1.06, (k,ratios) + assert ratios[1]>1.04, (k,ratios) + # P9.7 MUST NOT sacrifice the air P9.6 already restored. + assert ratios[2]>.98, (k,ratios) + assert ratios[0]<1.7 and ratios[1]<1.7 and ratios[2]<1.20, (k,ratios) + else: + # Signature at 3.1m must remain subtle, not overwritten. + assert .92{if(!root.isConnected)document.body.append(root)}; if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",mount,{once:true});else mount(); let current=null,accepted=defaults(),draft=defaults(),pending=null,latest=null, - xyzCapable=false,p83Capable=false,p84Capable=false,p85Capable=false,p86Capable=false,p87Capable=false,p88Capable=false,p89Capable=false,p90Capable=false,p91p92Capable=false,p94Capable=false,p95Capable=false,p96Capable=false,musicSafeStereo=false,p8TransparentBass=false,p82MultibandRoom=false, + xyzCapable=false,p83Capable=false,p84Capable=false,p85Capable=false,p86Capable=false,p87Capable=false,p88Capable=false,p89Capable=false,p90Capable=false,p91p92Capable=false,p94Capable=false,p95Capable=false,p96Capable=false,p97Capable=false,musicSafeStereo=false,p8TransparentBass=false,p82MultibandRoom=false, readId="",readSentAt=0,seq=1,clock=null,frame=null,observed=0,observedAt=0, drag=null,dialDrag=null,rangeEdits=new Set(),gestureStart=new Map(), visualPhase=0,visualAt=0,liveTimer=null,lastLiveAt=0; @@ -434,7 +434,9 @@ function render(){ if(!rangeEdits.has("skHrtfAlign"))align.value=String(s.hrtfElevationTrimDegrees); $("skHrtfAlignValue").textContent=(s.hrtfElevationTrimDegrees>=0?"+":"")+s.hrtfElevationTrimDegrees.toFixed(1)+"°"; } - root.querySelector(".sk-stage-caption").textContent=p96Capable&&s.renderMode===9? + root.querySelector(".sk-stage-caption").textContent=p97Capable&&s.renderMode===9? + "IMMERSIVE STAGE · BASS IMPACT · CENTER PRESENCE · EARLY AIR": + p96Capable&&s.renderMode===9? "IMMERSIVE STAGE · REINFORCED BASS + AIR · CINEMA / VENUE": p95Capable&&s.renderMode===9? "IMMERSIVE SPATIAL · MUSIC PRESENCE · WORLD BASS · CINEMA / VENUE": @@ -487,7 +489,8 @@ function render(){ // redrawn at 60 Hz. The native audio callback remains the time authority. drawSpeakers(); $("skMode").textContent=native()?(context()? - (p96Capable&&s.renderMode===9?"NATIVE IMMERSIVE · STAGE BASS + AIR": + (p97Capable&&s.renderMode===9?"NATIVE IMMERSIVE · STAGE IMPACT + EXTERNAL AIR": + p96Capable&&s.renderMode===9?"NATIVE IMMERSIVE · STAGE BASS + AIR": p95Capable&&s.renderMode===9?"NATIVE IMMERSIVE · MUSIC PRESENCE · WORLD BASS": p94Capable&&s.renderMode===9?"NATIVE IMMERSIVE SPATIAL · WORLD BASS": p91p92Capable&&s.renderMode===9?"NATIVE P9.1+P9.2 WORLD BASS · FAT": @@ -664,6 +667,7 @@ backend()?.addEventListener?.("arMixBuiltinSonKuSnapshot",r=>{ p94Capable=p91p92Capable && r.p94FrontBackDepthCue===true; p95Capable=p91p92Capable && r.p95MusicalPresence===true; p96Capable=p95Capable && r.p96DistanceReinforcement===true; + p97Capable=p96Capable && r.p97StageImpact===true; p89Capable=(r.schemaVersion===10||p90Capable) && r.p89StereoRoomDepth===true && Number.isFinite(incoming.hrtfElevationTrimDegrees); p88Capable=(r.schemaVersion===9||p89Capable) && r.p88PerceptualAlignment===true && @@ -769,7 +773,7 @@ $("skPreset").addEventListener("change",()=>{ musicCompatibleLowFrequency:false}); if(!send(scene))render(); }); -$("skClose").addEventListener("click",()=>{root.hidden=true;current=null;xyzCapable=false;p85Capable=false;p86Capable=false;p87Capable=false;p88Capable=false;p89Capable=false;p90Capable=false;p91p92Capable=false;p94Capable=false;p95Capable=false;p96Capable=false;musicSafeStereo=false;p8TransparentBass=false;p82MultibandRoom=false; +$("skClose").addEventListener("click",()=>{root.hidden=true;current=null;xyzCapable=false;p85Capable=false;p86Capable=false;p87Capable=false;p88Capable=false;p89Capable=false;p90Capable=false;p91p92Capable=false;p94Capable=false;p95Capable=false;p96Capable=false;p97Capable=false;musicSafeStereo=false;p8TransparentBass=false;p82MultibandRoom=false; cancelLiveTimer();pending=null;latest=null;readId="";readSentAt=0;dialDrag=null; drag=null;windowGesture=null;rangeEdits.clear();gestureStart.clear();lastLiveAt=0; if(clock!==null){clearInterval(clock);clock=null;} @@ -968,7 +972,7 @@ const api={ drag=null;rangeEdits.clear();gestureStart.clear(); accepted=defaults();draft=defaults();xyzCapable=false; p83Capable=p84Capable=p85Capable=p86Capable=p87Capable=p88Capable= - p89Capable=p90Capable=p91p92Capable=p94Capable=p95Capable=p96Capable=false; + p89Capable=p90Capable=p91p92Capable=p94Capable=p95Capable=p96Capable=p97Capable=false; musicSafeStereo=p8TransparentBass=p82MultibandRoom=false; current={track,slot,instanceId:null}; const s=snapshot(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(track); diff --git a/src/Main.cpp b/src/Main.cpp index 547e55ae1..b9762c5ac 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3132,6 +3132,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr #if defined(ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT) && ARMIX_SONKU_EXPERIMENTAL_P96_DISTANCE_REINFORCEMENT reply->setProperty("p96DistanceReinforcement",true); #endif +#if defined(ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT) && ARMIX_SONKU_EXPERIMENTAL_P97_STAGE_IMPACT + reply->setProperty("p97StageImpact",true); +#endif #if defined(ARMIX_SONKU_EXPERIMENTAL_P94_FRONT_BACK_DEPTH) && ARMIX_SONKU_EXPERIMENTAL_P94_FRONT_BACK_DEPTH // Branch-only measured-engine A/B. A previous v11 binary cannot // advertise this front/rear perceptual depth research capability. diff --git a/tests/sonku_p97_full_pcm_test.cpp b/tests/sonku_p97_full_pcm_test.cpp new file mode 100644 index 000000000..2c8317c0e --- /dev/null +++ b/tests/sonku_p97_full_pcm_test.cpp @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/sonku/SonKuSpatialCore.h" +#include +#include +#include +#include +#include +#include +#include +#include +using namespace armix::sonku; + +static void measure(int rate,int angle,int room,float meters,float mix=1.f) { + auto core=std::make_unique(); + assert(core->prepare(rate,SonKuReflectionProfile::SixSurfaceKemarResearch)); + Settings s{}; + s.renderMode=9; + s.moving=false; + s.startAzimuthDegrees=static_cast(angle); + s.stereoSpreadDegrees=82.f; + s.spatialMix=mix; + s.outputTrim=1.2f; + s.spacePreset=room; + s.sourceDistanceMeters=meters; + s.roomAmount=0.f; // ROOM geometry ON; wet OFF isolates measured direct + s.ambience=0.f; + assert(valid(s) && core->setSettings(s)); + const int n=rate; + constexpr double pi=3.1415926535897932384626433832795; + std::vector l(n),r(n); + for(int i=0;i(i)/rate; + const float x=.08f*std::sin(2*pi*85*t)+ + .055f*std::sin(2*pi*1900*t)+ + .028f*std::sin(2*pi*7500*t); + l[i]=x; + r[i]=.8f*x+.008f*std::sin(2*pi*1785*t); + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(256,n-i)); + std::uint64_t hash=14695981039346656037ull; + for(int i=0;i(value); + hash*=1099511628211ull; + } + } + constexpr std::array freqs{85,1900,7500}; + std::array amps{}; + for(int b=0;b<3;++b){ + double sinSum=0.,cosSum=0.; + for(int i=n/2;i0.); + } + std::printf("P97_FULL,%d,%d,%d,%.1f,%.1f,%.9f,%.9f,%.9f,%016llx\n", + rate,angle,room,meters,mix,amps[0],amps[1],amps[2], + static_cast(hash)); +} +int main(){ + for(int rate:{44100,48000}) + for(int angle:{0,180}){ + measure(rate,angle,0,10.f); // ROOM OFF exact hash parity + measure(rate,angle,3,10.f,0.f); // 0% MIX exact dry bypass + measure(rate,angle,3,2.f); // <=2m exact hash parity + measure(rate,angle,3,3.1f); // Signature: restrained stage impact + measure(rate,angle,3,10.f); // Venue: full stage impact + } +} diff --git a/tests/sonku_p97_stage_impact_source_test.cpp b/tests/sonku_p97_stage_impact_source_test.cpp new file mode 100644 index 000000000..2346201a3 --- /dev/null +++ b/tests/sonku_p97_stage_impact_source_test.cpp @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../engine/builtin_fx/sonku/SonKuP97StageImpact.h" +#include +#include +#include +using armix::sonku::p97::StageImpact; +static double signal(int rate,double hz,int section,float meters,bool room){ + StageImpact p; + assert(p.prepare(rate)); + constexpr double pi=3.14159265358979323846; + const int n=rate; + double inputPower=0.,outputPower=0.; + for(int i=0;i(std::sin(2*pi*hz*i/rate)); + const auto src=p.source(section==0?x:0.f,section==0?x:0.f,meters,room); + const auto direct=p.direct(section==1?x:0.f,section==1?x:0.f); + const auto early=p.early(section==2?x:0.f,section==2?x:0.f); + const auto finish=p.finish(section==3?x:0.f,section==3?x:0.f); + const float y=section==0?src.left:section==1?direct.left: + section==2?early.left:finish.left; + assert(std::isfinite(y)&&std::abs(y)<1.f); + if((!room || meters<=2.f))assert(y==x); + if(i>n/2) {inputPower+=double(x)*x; outputPower+=double(y)*y;} + } + return std::sqrt(outputPower/inputPower); +} +int main(){ + StageImpact bad; + assert(!bad.prepare(96000.)); + for(int rate:{44100,48000}){ + // Exact sample preservation: disabled ROOM and <=2m at all bands. + for(int section=0;section<4;++section){ + for(double hz:{85.,1900.,7500.}){ + assert(std::abs(signal(rate,hz,section,10.f,false)-1.)<1.e-6); + assert(std::abs(signal(rate,hz,section,2.f,true)-1.)<1.e-6); + } + } + const double bass=signal(rate,85.,1,10.f,true); + const double vocal=signal(rate,1900.,0,10.f,true); + const double directVoice=signal(rate,1900.,1,10.f,true); + const double directAir=signal(rate,7500.,1,10.f,true); + const double air=signal(rate,7500.,2,10.f,true); + std::printf("P97_STAGE,%d,bass=%.6f,center=%.6f,earlyAir=%.6f\n", + rate,bass,vocal,air); + assert(bass>1.14&&bass<1.45); + assert(vocal>1.13&&vocal<1.4); + assert(directVoice>1.065&&directVoice<1.20); + assert(directAir>1.01&&directAir<1.16); + assert(air>1.07&&air<1.35); + assert(signal(rate,85.,3,10.f,true)>1.04); + assert(signal(rate,7500.,3,10.f,true)>1.16); + // Center cancellation protects pure anti-phase stereo; filters are + // linked/coefficient-identical for each independently spatialized ear. + StageImpact p; + assert(p.prepare(rate)); + for(int i=0;i