diff --git a/.github/workflows/sonku-p72-native-xyz.yml b/.github/workflows/sonku-p72-native-xyz.yml new file mode 100644 index 000000000..46d3ab14e --- /dev/null +++ b/.github/workflows/sonku-p72-native-xyz.yml @@ -0,0 +1,104 @@ +name: SonKu P7.2 native XYZ ACK and v3 state — isolated +# No installer / full mixer compile. JUCE source adapter and pure C++ PCM. +# Production remains LIGHT and SONK v2; P7.2 opt-in flag OFF by default. +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + paths: + - 'engine/builtin_fx/SonKuSpatialProcessor.h' + - 'engine/builtin_fx/sonku/**' + - 'tests/sonku_p72_*' + - 'CMakeLists.txt' + - '.github/workflows/sonku-p72-native-xyz.yml' +permissions: + contents: read +concurrency: + group: sonku-p72-native-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + source: + name: Pure native 44.1/48k PCM, SPSC-safe XYZ edit and P6/P7.1 parity + runs-on: ubuntu-latest + timeout-minutes: 7 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Exact PR commit fingerprint + shell: bash + env: + EXPECTED: ${{ github.event.pull_request.head.sha }} + run: | + test "$(git rev-parse HEAD)" = "$EXPECTED" + echo "SONKU_P72_EXACT_SHA=$EXPECTED" + - name: Compile and execute original default native PCM contracts + run: | + set -euo pipefail + g++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic tests/sonku_p6_realtime_quality_test.cpp -o /tmp/sonku-p6 + /tmp/sonku-p6 + g++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -DSONKU_P7_MEASURED_ELEVATION_RESEARCH=1 -DSONKU_P71_DIRECT_XYZ_RESEARCH=1 tests/sonku_p71_xyz_direct_test.cpp -o /tmp/sonku-p71 + /tmp/sonku-p71 + - name: P7.2 live native ROOM edit + complete measured direct PCM + run: | + set -euo pipefail + g++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic \ + -DSONKU_P7_MEASURED_ELEVATION_RESEARCH=1 \ + -DSONKU_P71_DIRECT_XYZ_RESEARCH=1 \ + -DSONKU_P72_NATIVE_XYZ_RT=1 \ + tests/sonku_p72_realtime_xyz_test.cpp -o /tmp/sonku-p72 + /tmp/sonku-p72 + windows-juce: + name: Windows MSVC JUCE real native PCM→ACK→v3/legacy state + runs-on: windows-2022 + timeout-minutes: 21 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Exact immutable source SHA before compilation + shell: pwsh + env: + EXPECTED: ${{ github.event.pull_request.head.sha }} + run: | + $sha = (& git rev-parse HEAD).Trim() + if($LASTEXITCODE -ne 0 -or $sha -ne $env:EXPECTED) { throw "SONKU_P72_SHA_MISMATCH:$sha" } + Write-Host "SONKU_P72_WINDOWS_SOURCE_SHA=$sha" + - uses: actions/checkout@v4 + with: + repository: juce-framework/JUCE + ref: 8.0.15 + path: third_party/JUCE + persist-credentials: false + - name: Pinned WebView2 CMake configure SDK (no installer) + shell: pwsh + run: | + nuget install Microsoft.Web.WebView2 -Version 1.0.3485.44 -OutputDirectory .deps -NonInteractive + if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Configure research option explicitly ON; verify only required targets + shell: pwsh + run: | + cmake -S . -B build-sonku-p72 -G "Visual Studio 17 2022" -A x64 ` + -DJUCE_ROOT="${{ github.workspace }}/third_party/JUCE" ` + -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" ` + -DARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT=ON -DBUILD_TESTING=ON + if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $tests = (& ctest --test-dir build-sonku-p72 -C Release --show-only=json-v1 | Out-String | ConvertFrom-Json) + if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $found = @($tests.tests | ForEach-Object { $_.name }) + foreach($name in @('NativeSonKuP72AtomicXyzLiveEditSource', + 'NativeSonKuP72JuceV3XyzLiveAckV1V2Restore', + 'NativeSonKuSessionV1V2AndAudioAppliedAck')) { + if($name -notin $found) { throw "SONKU_P72_MISSING_CTEST:$name" } + } + - name: Build only two P72 source/JUCE targets + original light regression + shell: pwsh + run: | + cmake --build build-sonku-p72 --config Release --parallel 2 --target ARMixSonKuP72SourceTests ARMixSonKuP72NativeTests ARMixSonKuNativeStateTests + if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Run native v3 ACK and v1/v2 corruption/restore CTests + shell: pwsh + run: | + ctest --test-dir build-sonku-p72 -C Release --output-on-failure ` + -R '^NativeSonKu(P72AtomicXyzLiveEditSource|P72JuceV3XyzLiveAckV1V2Restore|SessionV1V2AndAudioAppliedAck)$' + if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + Write-Host 'SONKU_P72_JUCE_WINDOWS_3_CTESTS_PASS_NO_PHYSICAL_ASIO' diff --git a/CMakeLists.txt b/CMakeLists.txt index 97b625a8e..02dfeb8d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,12 @@ project(ARMixConsole VERSION 0.5.0 LANGUAGES C CXX) option(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT "Enable unqualified SonKu full KEMAR directional reflections on the native JUCE callback" OFF) +# Native XYZ/ACK v3: isolated research switch, OFF in every public installer. +# This implies the measured KEMAR full-elevation research tables explicitly +# and never changes the ordinary 46-byte SonKu v2 native FX ABI. +option(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + "Enable P7.2 unqualified native real-time XYZ/v3 research adapter" + OFF) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -197,7 +203,11 @@ target_compile_definitions(ARMixConsole PRIVATE JUCE_APPLICATION_VERSION_STRING="${ARMIX_APP_VERSION}" ARMIX_BUILD_SOURCE_SHA="${ARMIX_BUILD_SOURCE_SHA}" ARMIX_GFX_EMBED_PNG_SKINS=1 - $<$:ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT=1>) + $<$:ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT=1> + $<$:ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT=1> + $<$:SONKU_P7_MEASURED_ELEVATION_RESEARCH=1> + $<$:SONKU_P71_DIRECT_XYZ_RESEARCH=1> + $<$:SONKU_P72_NATIVE_XYZ_RT=1>) if(WIN32) # Windows retains its proven ASIO-first / WASAPI / static WebView2 distribution. # Never link Windows loader or sound APIs into macOS/Linux builds. @@ -285,6 +295,36 @@ if(BUILD_TESTING) endif() add_test(NAME NativeSonKuSessionV1V2AndAudioAppliedAck COMMAND ARMixSonKuNativeStateTests) + + # P7.2 native real-time 3D is never required in production: its test + # binaries, large measured elevation bank and v3 schema are built ONLY + # when explicitly opted in. Reuse the exact existing JUCE processor. + if(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) + add_executable(ARMixSonKuP72SourceTests + tests/sonku_p72_realtime_xyz_test.cpp) + target_compile_features(ARMixSonKuP72SourceTests PRIVATE cxx_std_20) + target_compile_definitions(ARMixSonKuP72SourceTests PRIVATE + SONKU_P7_MEASURED_ELEVATION_RESEARCH=1 + SONKU_P71_DIRECT_XYZ_RESEARCH=1 + SONKU_P72_NATIVE_XYZ_RT=1) + add_test(NAME NativeSonKuP72AtomicXyzLiveEditSource + COMMAND ARMixSonKuP72SourceTests) + + juce_add_console_app(ARMixSonKuP72NativeTests + PRODUCT_NAME "ArSonMix SonKu P72 Native XYZ Tests") + target_sources(ARMixSonKuP72NativeTests PRIVATE + tests/sonku_p72_native_juce_xyz_test.cpp) + target_link_libraries(ARMixSonKuP72NativeTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixSonKuP72NativeTests PRIVATE cxx_std_20) + target_compile_definitions(ARMixSonKuP72NativeTests PRIVATE + ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT=1 + SONKU_P7_MEASURED_ELEVATION_RESEARCH=1 + SONKU_P71_DIRECT_XYZ_RESEARCH=1 + SONKU_P72_NATIVE_XYZ_RT=1) + add_test(NAME NativeSonKuP72JuceV3XyzLiveAckV1V2Restore + COMMAND ARMixSonKuP72NativeTests) + endif() # Pure control-plane first-run routing selection: no JUCE, drivers, # WASAPI activation or callback dependencies. Full Windows CTest gate. add_executable(ARMixFirstRunEndpointPolicyTests diff --git a/docs/SONKU_P72_NATIVE_XYZ_ACK_V3_RESEARCH_20261114.md b/docs/SONKU_P72_NATIVE_XYZ_ACK_V3_RESEARCH_20261114.md new file mode 100644 index 000000000..0ae5752c3 --- /dev/null +++ b/docs/SONKU_P72_NATIVE_XYZ_ACK_V3_RESEARCH_20261114.md @@ -0,0 +1,58 @@ +# SonKu P7.2 — research-only realtime JUCE XYZ native ACK and v3 state + +14 November 2026 · stacked on P7.1 #681 → P7 #679 → P6 #678. +**Research native host feature, not public 3D UX / ASIO / dearVR parity.** + +## Audited architecture + +The existing SonKu `Settings` POD, per-instance native SPSC queue, JUCE +`consumeRealtimeEdits`, completion ACK, and `SonKuSpatialCore` are the +**single** audio/control source of truth; no second processor, WebAudio DSP, +worker thread, new audio callback, or hidden FX identity. + +When **both** the project option +`ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT=ON` (default OFF) and CMake's +specific source targets are built, the JUCE native processor prepares +`SixSurfaceKemarResearch`, compiles the independent MIT KEMAR 3D +measured bank, and extends the existing SonKu POD control with the +research-only `directElevationDegrees` field. This parameter is +**validated in combination with the same ROOM/distance settings**, accepted +by the native callback as one transaction, and included in completion ACK +only after audio applies it. The direct HRIR and six physical reflected +paths slew on existing geometry clocks; no callback allocation or +`prepare()`/history reset during a live edit. 3D edits are rejected if +they violate room clearance or cannot fit the delay ring, preventing +silent clamping of impossible geometry or partial UX state. + +The experimental native FX state adds a single float to the existing +SONK v2 payload, making **SONK v3 / 50 bytes**. The exact older binary +v2 / 46-byte and v1 / 30-byte states are still accepted in the +experimental JUCE adapter, defaulting direct elevation to 0°. A +normal/public SonKu binary **still writes v2 46 bytes**, and does not +silently attempt to interpret experimental v3. V3 is not automatically +published in the `.smix` GUI or FX rack; an approved user-facing state/ +UI/host protocol migration requires separate evidence and release. + +This pilot is also protected against an old-engine bug where a +`setSettings` failure could change the orbit phase before declining +a ROOM edit. A rejected P7.2 edit must preserve accepted state and +azimuth. Device `prepareToPlay(44100/48000, frames)` reuses the +approved elevation. Compiling with the switch OFF emits **none** of the +extra KEMAR 3D tables and retains original v1/v2 persistence. + +## Test and release gates + +- Linux no-JUCE source CTests: 44.1/48k, 0→+25→−25° live edit on the same + core; 64/257 chunk parity, moving azimuth continuity and anti-phase + musical PCM, finite/headroom, no invalid state or rejected-phase movement. +- Real MSVC JUCE adapter: queue returns QUEUED, processBlock applies, + completion readback is authoritative, rejected geometry never ACKs, + experimental 50-byte v3 and 46/30-byte v2/v1 restorable, corrupt/truncated + state fails without accepting partial data, driver-rate reprepare works. +- All tests target only specific native source binaries with pinned + JUCE 8.0.15 and WebView2 configure headers; no full mixer/installer, + no Vocal Harmony CI, no heavy UI snapshot jobs. +- These are host/native tests, **not a physical ASIO 64/128/256 XRUN test** + or approved GUI click/end-to-end WIRE route. Actual board/real music + listening, multiple inserts, licensing and production UI remain blocked + on Issue #683. diff --git a/engine/builtin_fx/SonKuSpatialProcessor.h b/engine/builtin_fx/SonKuSpatialProcessor.h index 26552b849..f2e083793 100644 --- a/engine/builtin_fx/SonKuSpatialProcessor.h +++ b/engine/builtin_fx/SonKuSpatialProcessor.h @@ -40,7 +40,10 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, void prepareToPlay(double rate,int) override { // P6 is opt-in at build time on an unreleased test binary only. // The render profile is immutable across native audio callbacks. -#if defined(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT) && ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + // Only an explicit native experimental build prepares six surfaces. + constexpr auto profile=armix::sonku::SonKuReflectionProfile::SixSurfaceKemarResearch; +#elif defined(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT) && ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT constexpr auto profile=armix::sonku::SonKuReflectionProfile::DirectionalKemar; #else constexpr auto profile=armix::sonku::SonKuReflectionProfile::Lightweight; @@ -92,7 +95,11 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, void getStateInformation(juce::MemoryBlock& dest) override { juce::MemoryOutputStream out(dest,false); out.writeInt(0x534F4E4B); // SONK +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + out.writeInt(3); +#else out.writeInt(2); +#endif out.writeFloat(accepted_.startAzimuthDegrees); out.writeFloat(accepted_.revolutionSeconds); out.writeFloat(accepted_.stereoSpreadDegrees); @@ -104,15 +111,30 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, out.writeFloat(accepted_.sourceDistanceMeters); out.writeFloat(accepted_.roomAmount); out.writeFloat(accepted_.ambience); +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + out.writeFloat(accepted_.directElevationDegrees); +#endif } bool restoreUnpublishedState(const void* data,int size) { - if(published_||!data||(size!=30&&size!=46)|| + if(published_||!data|| +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + (size!=30&&size!=46&&size!=50)|| +#else + (size!=30&&size!=46)|| +#endif !queue_.empty()||!complete_.empty())return false; juce::MemoryInputStream in(data,static_cast(size),false); if(in.readInt()!=0x534F4E4B)return false; const int version=in.readInt(); - if((version!=1&&version!=2)|| - (version==1&&size!=30)||(version==2&&size!=46))return false; + if((version!=1&&version!=2 +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + &&version!=3 +#endif + ) || (version==1&&size!=30)||(version==2&&size!=46) +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + ||(version==3&&size!=50) +#endif + )return false; armix::sonku::Settings next{}; next.startAzimuthDegrees=in.readFloat(); next.revolutionSeconds=in.readFloat(); @@ -123,14 +145,18 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, if(moving>1||clockwise>1)return false; next.moving=moving!=0; next.clockwise=clockwise!=0; - if(version==2) { + if(version>=2) { next.spacePreset=in.readInt(); next.sourceDistanceMeters=in.readFloat(); next.roomAmount=in.readFloat(); next.ambience=in.readFloat(); } - // Old v1 .smix restores to HRTF-only. New v2 carries the acoustic - // scene, but never allows malformed/partial state into live PCM. +#if defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) && ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT + if(version==3)next.directElevationDegrees=in.readFloat(); +#endif + // v1 OFF, v2 original scene; experimental v3 includes direct + // elevation, and is rejected by ordinary public v2 builds. + // Never accept a partial or malformed native FX state. if(!in.isExhausted())return false; if(!armix::sonku::valid(next))return false; if(ready_&&!core_.setSettings(next))return false; diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 6a90351ae..f15aab200 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -7,6 +7,11 @@ #if defined(SONKU_P71_DIRECT_XYZ_RESEARCH) && SONKU_P71_DIRECT_XYZ_RESEARCH #include "SonKuSourcePlacement3D.h" #endif +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT +#if !defined(SONKU_P71_DIRECT_XYZ_RESEARCH) || !SONKU_P71_DIRECT_XYZ_RESEARCH || !defined(SONKU_P7_MEASURED_ELEVATION_RESEARCH) || !SONKU_P7_MEASURED_ELEVATION_RESEARCH +#error SonKu P7.2 native XYZ requires explicitly compiled measured P7 and P7.1 research banks +#endif +#endif #include #include #include @@ -34,6 +39,11 @@ struct Settings { // spacePreset=0 still guarantees identical legacy HRTF-only PCM. float roomAmount = .55f; float ambience = .30f; +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + // Experimental v3 only. Bundled atomically with ROOM/distance in + // existing native SPSC edit, never a second FX graph or audio worker. + float directElevationDegrees = 0.f; +#endif }; inline bool valid(const Settings& s) noexcept { return std::isfinite(s.startAzimuthDegrees) && @@ -49,6 +59,18 @@ inline bool valid(const Settings& s) noexcept { s.sourceDistanceMeters<=10.f && std::isfinite(s.roomAmount) && s.roomAmount>=0.f && s.roomAmount<=1.f && std::isfinite(s.ambience) && s.ambience>=0.f && s.ambience<=1.f && +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + // Pure control-thread admission; validate even when ROOM is OFF so + // a later enable cannot silently admit an impossible placement. + [&]() noexcept { + xyz::Placement projected{}; + const float height=s.spacePreset<=1?3.2f: + s.spacePreset==2?4.8f:7.2f; + return xyz::project(s.sourceDistanceMeters, + s.directElevationDegrees,1.45f, + height,projected); + }() && +#endif (s.spacePreset==0 || SonKuEarlyReflections::validGeometry({ s.spacePreset==1?7.2f:s.spacePreset==2?14.4f:28.8f, s.spacePreset==1?7.2f:s.spacePreset==2?14.4f:28.8f, @@ -83,6 +105,14 @@ class SonKuSpatialCore final { // a public host. Downgrading the prepared profile clears it. if(profile!=SonKuReflectionProfile::SixSurfaceKemarResearch) researchElevationDegrees_=0.f; +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + // Preserve the accepted elevation on an ASIO/device re-prepare. + // Non-3D prepared engines cannot unknowingly carry 3D state. + if(profile==SonKuReflectionProfile::SixSurfaceKemarResearch) + researchElevationDegrees_=settings_.directElevationDegrees; + else + settings_.directElevationDegrees=0.f; +#endif // Only a *new* DSP prepare re-opens the quiescent research gate. // reset() while an existing audio graph is running must NOT do so. researchPcmStarted_=false; @@ -119,16 +149,34 @@ class SonKuSpatialCore final { } bool setSettings(const Settings& s) noexcept { if(!valid(s))return false; - // Keep phase continuous for live speed/spread adjustments; changing start - // position while static is an intentional absolute reposition. - if(!s.moving || !settings_.moving || - s.startAzimuthDegrees!=settings_.startAzimuthDegrees) - degrees_=wrapDegrees(s.startAzimuthDegrees); +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + const auto activeProfile=room_.preparedProfile(); + if(activeProfile!=SonKuReflectionProfile::SixSurfaceKemarResearch && + s.directElevationDegrees!=0.f)return false; + // Transactional XYZ admission. The old core set degrees_ BEFORE room + // validation, so an invalid edit could rotate a still-running orbit. + // Stage all 3D changes and publish the phase only on success. + const float formerElevation=researchElevationDegrees_; + researchElevationDegrees_=s.directElevationDegrees; +#endif const bool changed=s.spacePreset!=settings_.spacePreset || s.sourceDistanceMeters!=settings_.sourceDistanceMeters || s.roomAmount!=settings_.roomAmount || - s.ambience!=settings_.ambience; - if(changed && !applyAcousticSettings(s))return false; + s.ambience!=settings_.ambience +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + || s.directElevationDegrees!=formerElevation +#endif + ; + if(changed && !applyAcousticSettings(s)) { +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + researchElevationDegrees_=formerElevation; +#endif + return false; + } + // Preserve continuous motion during accepted elevation edits. + if(!s.moving || !settings_.moving || + s.startAzimuthDegrees!=settings_.startAzimuthDegrees) + degrees_=wrapDegrees(s.startAzimuthDegrees); settings_=s; // Once native ROOM has been enabled, retain the smoothed transition // when it is turned OFF. Standalone experimental V2/V3 OFF fixtures @@ -151,6 +199,13 @@ class SonKuSpatialCore final { settings_.spacePreset==2?4.8f:7.2f; if(!xyz::project(settings_.sourceDistanceMeters,degrees,1.45f,h,projected)) return false; +#if defined(SONKU_P72_NATIVE_XYZ_RT) && SONKU_P72_NATIVE_XYZ_RT + // Research setup must use the same single edit transaction as the + // later JUCE audio-applied ACK and persisted v3. No shadow state. + auto next=settings_; + next.directElevationDegrees=degrees; + return setSettings(next); +#else const float old=researchElevationDegrees_; researchElevationDegrees_=degrees; if(!applyAcousticSettings(settings_)) { @@ -160,6 +215,7 @@ class SonKuSpatialCore final { remaining_=0; haveKernel_=false; return true; +#endif } float researchDirectElevation() const noexcept {return researchElevationDegrees_;} #endif diff --git a/tests/sonku_p72_native_juce_xyz_test.cpp b/tests/sonku_p72_native_juce_xyz_test.cpp new file mode 100644 index 000000000..8e52dd8bf --- /dev/null +++ b/tests/sonku_p72_native_juce_xyz_test.cpp @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// P7.2 exact real JUCE adapter: SPSC edit -> callback -> applied ACK, +// experimental v3 50-byte state, v1/v2 restore, corruption and restart. +// The normal product/catalog/installer stay on v2 and LIGHT. +#if defined(NDEBUG) +#undef NDEBUG +#endif +#if !defined(ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT) || !ARMIX_SONKU_EXPERIMENTAL_NATIVE_XYZ_RT +#error P7.2 real JUCE test MUST enable native XYZ opt-in +#endif +#include "../engine/builtin_fx/SonKuSpatialProcessor.h" +#include +#include +#include +#include +#include +int main(){ + using armix::builtin_fx::SonKuSpatialProcessor; + using armix::sonku::SonKuReflectionProfile; + using armix::sonku::Settings; + auto live=std::make_unique(); + auto flat=std::make_unique(); + live->prepareToPlay(48000.,128); + flat->prepareToPlay(48000.,128); + assert(live->isReady()&&flat->isReady()); + assert(live->preparedReflectionProfile()==SonKuReflectionProfile::SixSurfaceKemarResearch); + auto scene=live->acceptedSettings(); + assert(scene.spacePreset==0 && scene.directElevationDegrees==0.f); + scene.spacePreset=1;scene.sourceDistanceMeters=1.6f; + scene.roomAmount=.6f;scene.ambience=.15f; + scene.stereoSpreadDegrees=60.f;scene.outputTrim=.55f; + scene.moving=false;scene.startAzimuthDegrees=45.f; + assert(armix::sonku::valid(scene)); + assert(live->queueSettings(scene,1001)&&flat->queueSettings(scene,1001)); + assert(live->acceptedSettings().spacePreset==0); + juce::AudioBuffer audio(2,128),original(2,128); + juce::MidiBuffer midi; + auto render=[&](int n){ + audio.clear();original.clear(); + for(int k=0;k<128;++k){ + const float a=.10f*std::sin((n*128+k)*.039f); + const float b=.06f*std::sin((n*128+k)*.32f); + audio.setSample(0,k,a+b);audio.setSample(1,k,a-b); + original.setSample(0,k,a+b);original.setSample(1,k,a-b); + } + live->processBlock(audio,midi); + flat->processBlock(original,midi); + for(int c=0;c<2;++c)for(int k=0;k<128;++k){ + assert(std::isfinite(audio.getSample(c,k))); + assert(std::abs(audio.getSample(c,k))<1.f); + } + }; + render(0); + SonKuSpatialProcessor::Completion ack{}; + assert(live->pollCompletion(ack)&&ack.applied&&ack.requestId==1001); + assert(flat->pollCompletion(ack)&&ack.applied); + assert(live->acceptedSettings().spacePreset==1); + for(int n=1;n<38;++n)render(n); + auto bad=scene;bad.directElevationDegrees=70.f; + assert(!live->queueSettings(bad,1002)); + assert(live->acceptedSettings().directElevationDegrees==0.f); + bad=scene;bad.directElevationDegrees=25.f;bad.sourceDistanceMeters=10.f; + assert(!live->queueSettings(bad,1002)); + assert(!live->pollCompletion(ack)); + + scene.directElevationDegrees=25.f; + assert(live->queueSettings(scene,1003)); + assert(live->acceptedSettings().directElevationDegrees==0.f); + render(38); + assert(live->pollCompletion(ack)&&ack.applied&&ack.requestId==1003); + assert(ack.settings.directElevationDegrees==25.f); + assert(live->acceptedSettings().directElevationDegrees==25.f); + double changed=0.; + for(int n=39;n<95;++n){ + render(n); + for(int k=0;k<128;++k) + changed+=std::abs(audio.getSample(0,k)-original.getSample(0,k))+ + std::abs(audio.getSample(1,k)-original.getSample(1,k)); + } + assert(changed>.01); + // State snapshot must serialize only AUDIO-ACKed geometry, not queued. + juce::MemoryBlock bytes; + live->getStateInformation(bytes); + assert(bytes.getSize()==50); + juce::MemoryInputStream check(bytes.getData(),50,false); + assert(check.readInt()==0x534F4E4B&&check.readInt()==3); + auto restore=std::make_unique(); + restore->prepareToPlay(44100.,128); + assert(restore->restoreUnpublishedState(bytes.getData(),50)); + assert(restore->acceptedSettings().directElevationDegrees==25.f); + assert(restore->acceptedSettings().spacePreset==1); + restore->prepareToPlay(48000.,256); // ASIO format reprepare, no hardware + assert(restore->isReady()&&restore->acceptedSettings().directElevationDegrees==25.f); + juce::AudioBuffer after(2,64); + after.clear();after.setSample(0,0,.1f); + restore->processBlock(after,midi); + for(int c=0;c<2;++c)for(int k=0;k<64;++k) + assert(std::isfinite(after.getSample(c,k))); + + // Copy a valid but incomplete v3 blob (49 bytes) and bad schema version. + assert(!restore->restoreUnpublishedState(bytes.getData(),49)); + juce::MemoryBlock corrupt(bytes); + auto* data=static_cast(corrupt.getData()); + for(int k=46;k<50;++k)data[k]=0xff; // NaN floats are invalid + auto fails=std::make_unique(); + fails->prepareToPlay(48000.,128); + assert(!fails->restoreUnpublishedState(corrupt.getData(),50)); + assert(fails->acceptedSettings().directElevationDegrees==0.f); + + // v2 old 46-byte scene and strict v1 30-byte ROOM OFF restore. + juce::MemoryBlock v2; + {juce::MemoryOutputStream out(v2,false); + out.writeInt(0x534F4E4B);out.writeInt(2); + out.writeFloat(35.f);out.writeFloat(3.7f);out.writeFloat(60.f); + out.writeFloat(1.f);out.writeFloat(.6f);out.writeByte(1);out.writeByte(1); + out.writeInt(1);out.writeFloat(1.6f);out.writeFloat(.58f);out.writeFloat(.2f);} + assert(v2.getSize()==46); + auto older=std::make_unique(); + older->prepareToPlay(48000.,128); + assert(older->restoreUnpublishedState(v2.getData(),46)); + assert(older->acceptedSettings().directElevationDegrees==0.f); + assert(older->acceptedSettings().spacePreset==1); + juce::MemoryBlock v1; + {juce::MemoryOutputStream out(v1,false); + out.writeInt(0x534F4E4B);out.writeInt(1); + out.writeFloat(0.f);out.writeFloat(12.f);out.writeFloat(60.f); + out.writeFloat(1.f);out.writeFloat(.75f);out.writeByte(1);out.writeByte(1);} + assert(v1.getSize()==30); + auto legacy=std::make_unique(); + legacy->prepareToPlay(48000.,128); + assert(legacy->restoreUnpublishedState(v1.getData(),30)); + assert(legacy->acceptedSettings().spacePreset==0); + assert(legacy->acceptedSettings().directElevationDegrees==0.f); + legacy->sealForRealtime(); + assert(!legacy->restoreUnpublishedState(v2.getData(),46)); + return 0; +} diff --git a/tests/sonku_p72_realtime_xyz_test.cpp b/tests/sonku_p72_realtime_xyz_test.cpp new file mode 100644 index 000000000..d8b1d5e1c --- /dev/null +++ b/tests/sonku_p72_realtime_xyz_test.cpp @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// P7.2 pure C++ realtime edit contract, same native core as JUCE callback. +// 44.1/48k PCM, measured direct XYZ, phase-preserving accepted edits. +#if defined(NDEBUG) +#undef NDEBUG +#endif +#if !defined(SONKU_P7_MEASURED_ELEVATION_RESEARCH) || !SONKU_P7_MEASURED_ELEVATION_RESEARCH || !defined(SONKU_P71_DIRECT_XYZ_RESEARCH) || !SONKU_P71_DIRECT_XYZ_RESEARCH || !defined(SONKU_P72_NATIVE_XYZ_RT) || !SONKU_P72_NATIVE_XYZ_RT +#error The P7.2 source test requires exactly the full experimental contract +#endif +#include "../engine/builtin_fx/sonku/SonKuSpatialCore.h" +#include +#include +#include +#include +#include +#include +#include +using armix::sonku::SonKuSpatialCore; +using armix::sonku::SonKuReflectionProfile; +using armix::sonku::Settings; +int main(){ + constexpr double pi=3.14159265358979323846; + constexpr int N=16384; + for(double rate:{44100.,48000.}){ + for(float spread:{0.f,60.f}){ + auto changed=std::make_unique(); + auto chunks=std::make_unique(); + auto flat=std::make_unique(); + for(auto* dsp:{changed.get(),chunks.get(),flat.get()}) + assert(dsp->prepare(rate,SonKuReflectionProfile::SixSurfaceKemarResearch)); + Settings scene{}; + scene.spacePreset=1;scene.roomAmount=.58f;scene.ambience=.2f; + scene.outputTrim=.55f;scene.stereoSpreadDegrees=spread; + scene.startAzimuthDegrees=35.f;scene.revolutionSeconds=3.7f; + scene.directElevationDegrees=0.f; + assert(armix::sonku::valid(scene)); + for(auto* dsp:{changed.get(),chunks.get(),flat.get()}) + assert(dsp->setSettings(scene)); + std::array l{},r{},cl{},cr{},fl{},fr{}; + for(int n=0;n(n/rate); + const float bass=.13f*std::sin(static_cast(2*pi*220*t)); + const float treble=.05f*std::sin(static_cast(2*pi*3200*t)); + const float voice=.03f*std::sin(static_cast(2*pi*740*t)); + l[n]=cl[n]=fl[n]=bass+treble+voice; + r[n]=cr[n]=fr[n]=bass-treble+voice*.8f; + } + // Before any realtime edit, same P7.1 0-degree native behavior. + const int boundary=4096; + changed->process(l.data(),r.data(),boundary); + chunks->process(cl.data(),cr.data(),boundary); + flat->process(fl.data(),fr.data(),boundary); + for(int i=0;iazimuthDegrees(); + auto bad=scene; + bad.directElevationDegrees=65.f; + bad.startAzimuthDegrees=179.f; + assert(!armix::sonku::valid(bad)); + assert(!changed->setSettings(bad)); + bad.directElevationDegrees=std::numeric_limits::quiet_NaN(); + assert(!armix::sonku::valid(bad) && !changed->setSettings(bad)); + bad.directElevationDegrees=45.f; + bad.sourceDistanceMeters=8.f; // impossible 3.2m room + assert(!armix::sonku::valid(bad) && !changed->setSettings(bad)); + assert(changed->settings().directElevationDegrees==0.f); + assert(changed->azimuthDegrees()==phase); // rejected edit cannot move orbit + + scene.directElevationDegrees=25.f; + assert(armix::sonku::valid(scene)); + assert(changed->setSettings(scene)&&chunks->setSettings(scene)); + assert(changed->settings().directElevationDegrees==25.f); + // Live edit must keep sample clock, ring buffers and continuous orbit. + assert(changed->azimuthDegrees()==phase); + changed->process(l.data()+boundary,r.data()+boundary,N-boundary); + for(int at=boundary;atprocess(cl.data()+at,cr.data()+at,width); + at+=width; + } + flat->process(fl.data()+boundary,fr.data()+boundary,N-boundary); + double delta=0.,energy=0.; + for(int n=0;nboundary+2048) + delta+=std::abs(l[n]-fl[n])+std::abs(r[n]-fr[n]); + energy+=l[n]*l[n]+r[n]*r[n]; + } + assert(energy>.001&&delta>.05); + assert(std::abs(changed->azimuthDegrees()-chunks->azimuthDegrees())<1.e-7); + // Accept a second elevated edit (same PCM instance, no new graph). + scene.directElevationDegrees=-25.f; + assert(changed->setSettings(scene)); + assert(changed->settings().directElevationDegrees==-25.f); + // Device restart resynthesizes approved coordinates, not stale 0 degree. + assert(changed->prepare(rate,SonKuReflectionProfile::SixSurfaceKemarResearch)); + assert(changed->settings().directElevationDegrees==-25.f); + assert(changed->researchDirectElevation()==-25.f); + // A P6 downgrade must not smuggle unsupported 3D coordinates. + assert(changed->prepare(rate,SonKuReflectionProfile::DirectionalKemar)); + assert(changed->settings().directElevationDegrees==0.f); + assert(!changed->setSettings(scene)); + } + } + std::puts("PASS SonKu P7.2 atomic realtime XYZ edit, causal KEMAR PCM, phase stability, 44.1/48k, restart/downgrade"); +}