diff --git a/.github/workflows/harmony-fast-dsp.yml b/.github/workflows/harmony-fast-dsp.yml index a0c4e1168..05575575a 100644 --- a/.github/workflows/harmony-fast-dsp.yml +++ b/.github/workflows/harmony-fast-dsp.yml @@ -1,21 +1,73 @@ -name: Harmony native DSP fast verification +name: Vocal Harmony plugin DSP (scoped) +# Only code/tests of the built-in Vocal Harmony FX may start this workflow. +# In particular, shared CMakeLists.txt, Player, mixer, generic GUI and CI +# maintenance must never trigger an unrelated Vocal Harmony failure. on: pull_request: types: [opened, reopened, synchronize] paths: - 'engine/builtin_fx/Harmony*.h' + - 'engine/builtin_fx/ChannelHarmonyProcessor.h' - 'tests/harmony*.cpp' - 'tools/harmony_offline_ab.cpp' - - 'CMakeLists.txt' - - '.github/workflows/harmony-fast-dsp.yml' + - 'site/preview-v2/assets/mixer-native-harmony.js' + - 'tests/native_harmony_assembly_test.py' + - 'tests/approved_native_harmony_smoke.py' permissions: contents: read concurrency: group: harmony-fast-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: + scope: + name: Check Vocal Harmony files changed in this PR update + runs-on: ubuntu-latest + timeout-minutes: 3 + outputs: + dsp: ${{ steps.scope.outputs.dsp }} + ui: ${{ steps.scope.outputs.ui }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 2 + - name: Classify only actual Vocal Harmony source changes + id: scope + shell: bash + env: + PR_ACTION: ${{ github.event.action }} + PR_BEFORE: ${{ github.event.before }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + run: | + # GitHub 'paths' looks at the entire PR diff. If a mixed PR + # changes unrelated files later, do not re-run the plugin DSP. + # Prefer the exact synchronize-before SHA to handle multi-commit + # pushes; on missing/unfetchable evidence, fail OPEN for safety. + BASE="$PR_BASE" + if [[ "$PR_ACTION" == "synchronize" && "$PR_BEFORE" =~ ^[a-fA-F0-9]{40}$ && ! "$PR_BEFORE" =~ ^0+$ ]]; then + BASE="$PR_BEFORE" + fi + if [[ ! "$BASE" =~ ^[a-fA-F0-9]{40}$ ]]; then + printf 'dsp=true\nui=true\n' >> "$GITHUB_OUTPUT" + exit 0 + fi + if ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then + if ! git fetch --no-tags --depth=1 origin "$BASE"; then + printf 'dsp=true\nui=true\n' >> "$GITHUB_OUTPUT" + exit 0 + fi + fi + if ! git diff --name-only --no-renames "$BASE" HEAD > "$RUNNER_TEMP/vocal-harmony-diff.txt"; then + printf 'dsp=true\nui=true\n' >> "$GITHUB_OUTPUT" + exit 0 + fi + node scripts/vocal_harmony_ci_scope.mjs < "$RUNNER_TEMP/vocal-harmony-diff.txt" >> "$GITHUB_OUTPUT" + echo "VOCAL_HARMONY_CHANGED_FILES:" + cat "$RUNNER_TEMP/vocal-harmony-diff.txt" harmony-cpp: name: Native DSP compile and PCM regression (Linux, no JUCE) + needs: scope + if: ${{ needs.scope.outputs.dsp == 'true' }} runs-on: ubuntu-latest timeout-minutes: 7 steps: @@ -38,3 +90,17 @@ jobs: run: | g++ -std=c++20 -O2 -Wall -Wextra tools/harmony_offline_ab.cpp -o /tmp/arson-harmony-ab /tmp/arson-harmony-ab --self-test + harmony-ui: + name: Vocal Harmony editor syntax and approved UI contract (no Chromium) + needs: scope + if: ${{ needs.scope.outputs.ui == 'true' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Plugin editor JS and native bridge/ACK contract + run: | + node --check site/preview-v2/assets/mixer-native-harmony.js + python tests/native_harmony_assembly_test.py diff --git a/.github/workflows/sonku-native-windows.yml b/.github/workflows/sonku-native-windows.yml new file mode 100644 index 000000000..1e312f039 --- /dev/null +++ b/.github/workflows/sonku-native-windows.yml @@ -0,0 +1,127 @@ +name: SonKu native JUCE Windows (focused experimental quality) +# Verify the REAL JUCE adapter in a single targeted opt-in build. +# No full mixer executable, installer, Chromium, hardware ASIO or Vocal Harmony. +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + paths: + - 'engine/builtin_fx/sonku/**' + - 'engine/builtin_fx/SonKuSpatialProcessor.h' + - 'tests/sonku_native_state_test.cpp' + - 'tests/sonku_p6_realtime_quality_test.cpp' + - '.github/workflows/sonku-native-windows.yml' +permissions: + contents: read +concurrency: + group: sonku-native-windows-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + scope: + name: Classify exact new source changes, avoid unrelated Windows repeats + runs-on: ubuntu-latest + timeout-minutes: 3 + outputs: + compile: ${{ steps.delta.outputs.compile }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 2 + - name: Compare exact PR synchronization range, fail open if unknown + id: delta + shell: bash + env: + ACTION: ${{ github.event.action }} + BEFORE: ${{ github.event.before }} + run: | + set -euo pipefail + # On initial or uncertain pushes always compile; never guess. + if [[ "$ACTION" != synchronize || ! "$BEFORE" =~ ^[0-9a-f]{40}$ || "$BEFORE" =~ ^0+$ ]]; then + echo "compile=true" >> "$GITHUB_OUTPUT" + echo "SONKU_WINDOWS_COMPILE_REASON=initial_or_unverifiable_delta" + exit 0 + fi + if ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then + if ! git fetch --no-tags --depth=1 origin "$BEFORE"; then + echo "compile=true" >> "$GITHUB_OUTPUT" + echo "SONKU_WINDOWS_COMPILE_REASON=missing_predecessor" + exit 0 + fi + fi + if ! git diff --name-only --no-renames "$BEFORE" HEAD > "$RUNNER_TEMP/sonku-delta.txt"; then + echo "compile=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + cat "$RUNNER_TEMP/sonku-delta.txt" + # P7-only MIT measured data and six-plane lab files are compiled + # OUT of the real JUCE P6 build. They have their own Linux CI. + if grep -Eq '^((CMakeLists.txt)|(engine/builtin_fx/SonKuSpatialProcessor.h)|(engine/builtin_fx/sonku/(SonKuEarlyReflections|SonKuSpatialCore|SonKuStereoIntegrity|SonKuMeasuredHrir|SonKuMusicalReverb).h)|(tests/sonku_(native_state|p6_realtime_quality)_test.cpp)|(\.github/workflows/sonku-native-windows.yml))$' "$RUNNER_TEMP/sonku-delta.txt"; then + echo "compile=true" >> "$GITHUB_OUTPUT" + echo "SONKU_WINDOWS_COMPILE_REASON=real_native_adapter_change" + elif grep -Eq '^engine/builtin_fx/sonku/' "$RUNNER_TEMP/sonku-delta.txt" && + grep '^engine/builtin_fx/sonku/' "$RUNNER_TEMP/sonku-delta.txt" | + grep -Ev '^engine/builtin_fx/sonku/(SonKuMeasuredHrir3D|SonKuVerticalImageSource).h$' >/dev/null; then + echo "compile=true" >> "$GITHUB_OUTPUT" + echo "SONKU_WINDOWS_COMPILE_REASON=unknown_sonku_native_header" + else + echo "compile=false" >> "$GITHUB_OUTPUT" + echo "SONKU_WINDOWS_COMPILE_REASON=research_or_docs_only" + fi + native-juce: + needs: scope + if: ${{ needs.scope.outputs.compile == 'true' }} + name: Windows MSVC SonKu native adapter + core (opt-in ON) + runs-on: windows-2022 + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Verify immutable PR head + 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_SHA_MISMATCH expected=$env:EXPECTED actual=$sha" + } + Write-Host "SONKU_QUALIFICATION_SOURCE_SHA=$sha" + - uses: actions/checkout@v4 + with: + repository: juce-framework/JUCE + ref: 8.0.15 + path: third_party/JUCE + persist-credentials: false + - name: Provide pinned WebView2 CMake 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 only CTest catalog with experimental P6 ON + shell: pwsh + run: | + cmake -S . -B build-sonku-p6 -G "Visual Studio 17 2022" -A x64 ` + -DJUCE_ROOT="${{ github.workspace }}/third_party/JUCE" ` + -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" ` + -DARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT=ON -DBUILD_TESTING=ON + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $result = (& ctest --test-dir build-sonku-p6 -C Release --show-only=json-v1 | Out-String | ConvertFrom-Json) + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $found = @($result.tests | ForEach-Object { $_.name }) + foreach($name in @('NativeSonKuSessionV1V2AndAudioAppliedAck', + 'NativeSonKuP6PreparedRoomDirectionalAndChunkParity')) { + if($name -notin $found) { throw "SONKU_CTEST_TARGET_NOT_REGISTERED:$name" } + } + - name: Build ONLY two SonKu source targets (no installer/full app) + shell: pwsh + run: | + cmake --build build-sonku-p6 --config Release --parallel 2 --target ARMixSonKuNativeStateTests ARMixSonKuP6PreparedTests + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Execute native JUCE acceptance, PCM and state CTests + shell: pwsh + run: | + ctest --test-dir build-sonku-p6 -C Release --output-on-failure ` + -R '^NativeSonKu(SessionV1V2AndAudioAppliedAck|P6PreparedRoomDirectionalAndChunkParity)$' + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + Write-Host 'SONKU_P6_WINDOWS_JUCE_NATIVE_ON=PASS (no physical ASIO)' diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index 2d3bffee8..34012a304 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -320,6 +320,14 @@ jobs: run: | g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_p5_room_reactivation_test.cpp -o /tmp/sonku-p5-room /tmp/sonku-p5-room + - name: P6 native JUCE-path quality prepare, active room PCM and chunk parity + run: | + g++ -std=c++20 -O2 -Wall -Wextra -pedantic tests/sonku_p6_realtime_quality_test.cpp -o /tmp/sonku-p6-native + /tmp/sonku-p6-native + - name: P6 actual realtime ROOM FRONT/REAR listening WAV and objective audit + run: | + /tmp/sonku-integrity-audio sonku-integrity-evidence --p6-realtime-only + python tests/sonku_p6_realtime_audio_audit.py sonku-integrity-evidence - name: P2 original voice-like headphone A/B and numeric PCM comparison run: | /tmp/sonku-integrity-audio sonku-integrity-evidence --directional-er-only diff --git a/CMakeLists.txt b/CMakeLists.txt index e2f1cb58d..97b625a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.22) project(ARMixConsole VERSION 0.5.0 LANGUAGES C CXX) +# Experimental P6 native profile: OFF by default in production/installer. +option(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT + "Enable unqualified SonKu full KEMAR directional reflections on the native JUCE callback" + OFF) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -192,7 +196,8 @@ target_compile_definitions(ARMixConsole PRIVATE JUCE_APPLICATION_NAME_STRING="AR MIX Studio" JUCE_APPLICATION_VERSION_STRING="${ARMIX_APP_VERSION}" ARMIX_BUILD_SOURCE_SHA="${ARMIX_BUILD_SOURCE_SHA}" - ARMIX_GFX_EMBED_PNG_SKINS=1) + ARMIX_GFX_EMBED_PNG_SKINS=1 + $<$:ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_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. @@ -261,12 +266,23 @@ if(BUILD_TESTING) add_executable(ARMixSonKuCoreTests tests/sonku_spatial_core_test.cpp) target_compile_features(ARMixSonKuCoreTests PRIVATE cxx_std_20) add_test(NAME NativeSonKuMeasuredBinauralDirectionalAndChunkParity COMMAND ARMixSonKuCoreTests) + # P6 same core/PCM profile: no JUCE or SDK required for source regression. + add_executable(ARMixSonKuP6PreparedTests tests/sonku_p6_realtime_quality_test.cpp) + target_compile_features(ARMixSonKuP6PreparedTests PRIVATE cxx_std_20) + add_test(NAME NativeSonKuP6PreparedRoomDirectionalAndChunkParity + COMMAND ARMixSonKuP6PreparedTests) # Real JUCE processor: audio-applied ACK, v1/v2 state, corruption fences. juce_add_console_app(ARMixSonKuNativeStateTests PRODUCT_NAME "ArSonMix SonKu Native State Tests") target_sources(ARMixSonKuNativeStateTests PRIVATE tests/sonku_native_state_test.cpp) target_link_libraries(ARMixSonKuNativeStateTests PRIVATE juce::juce_audio_processors juce::juce_recommended_config_flags) target_compile_features(ARMixSonKuNativeStateTests PRIVATE cxx_std_20) + # Compile and test the same opt-in native profile in the actual JUCE + # adapter when a deliberately qualified experimental build requests it. + if(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT) + target_compile_definitions(ARMixSonKuNativeStateTests PRIVATE + ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT=1) + endif() add_test(NAME NativeSonKuSessionV1V2AndAudioAppliedAck COMMAND ARMixSonKuNativeStateTests) # Pure control-plane first-run routing selection: no JUCE, drivers, diff --git a/docs/SONKU_P6_PREPARED_REALTIME_DIRECTIONAL_20261114.md b/docs/SONKU_P6_PREPARED_REALTIME_DIRECTIONAL_20261114.md new file mode 100644 index 000000000..7e2aafe67 --- /dev/null +++ b/docs/SONKU_P6_PREPARED_REALTIME_DIRECTIONAL_20261114.md @@ -0,0 +1,86 @@ +# SonKu P6 — prepared realtime directional KEMAR (experimental integration) + +2026-11-14 · stacked on PR #674 / P0–P5 · **not production-qualified** + +## What was integrated + +The P2 directional image-source measured-KEMAR HRIR renderer, P3 exact +zero-spread source fusion and P4 contiguous 140-tap read are now selectable +as **one immutable prepared native render profile**. `SonKuSpatialCore::prepare` +accepts `SonKuReflectionProfile::DirectionalKemar`. The selected profile +reaches the original `SonKuEarlyReflections` that already handles actual +native `spacePreset` ROOM scenes and is called from one JUCE PCM processor. + +`SonKuSpatialProcessor::prepareToPlay` uses this profile only when the +**explicit experimental** CMake option is enabled: + +``` +-DARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT=ON +``` + +Default = **OFF**. Do not add this to published installers or release workflows +until qualification. No WebAudio worker, duplicate DSP graph, new FX ID, +.session/`.smix` schema, GUI, bridge, control ACK or WIRE modifications. + +The profile is admitted *before* the native room is activated. All experimental +offline setters are rejected on that profile so the renderer cannot be silently +downgraded/mutated after prepare. Device restart re-prepares the profile +and restores the accepted native acoustic scene. ROOM ON/OFF and scene distance +edits continue to use the existing smoothed 64-sample image geometry and +10–24ms level/delay transitions; P5 epoch guard prevents old ring audio. +The realtime callback does not allocate, lock, query clock, clear large rings, +load datasets, spawn threads or select a new renderer. + +## Evidence + +- Native C++ P6 test covers invalid profile fail closed, default unchanged, + explicit JUCE-path profile selection, active ROOM + moving orbit, + 44.1/48k mixed-polarity music, fixed versus arbitrary PCM chunks, + strict no-reflection early prefix, measurable distinction from lightweight + room, restart with an accepted active scene, and immutable profile rejection. +- All previous P0–P5 fixture/PCM/380-frequency and A/B guards remain. +- The SAME native core, native ROOM scene and exact input are benchmarked as + `SONKU_P6_RT` at 48k/128, spread 0° and 60°, reporting p99 against the + theoretical block budget; shared Linux runner numbers are informational only. + +## Release veto (open) + +This is **engine integration**, not proof of a better audible space. +Directional reflections still use horizontal-only MIT KEMAR, four walls, and +may be expensive for many concurrent inserts. Do not auto-promote this +CMake switch, PR, public binary, or claim dearVR parity before: +1. On the actual Windows JUCE/ASIO mixer, measure p95/p99, XRUN and channel count + at 44.1/48k with 64/128/256 frames, 1 and several SonKu instances, WIRE + VST3. +2. Same-gain, blind headphone A/B on real stereo material, solo voice, anti-phase, + FRONT/REAR, movement, ROOM on/off and 0°/60° spread. +3. Confirm tonal coloration, perceived outside-head position, distance ordering, + no click on edit/restart, no audible late-reverb artifact. +4. Reconcile any main-branch changes and run native JUCE Windows compilation + before a tester build. Keep original P0–P5 PR draft. + +Do not use an unstable per-callback CPU clock to dynamically switch HRTF modes; +a global mixer graph budget belongs to the host admission policy, not a guessed +one-size threshold in the audio thread. + +## P6 native ROOM headphone artifact + +The scoped SonKu fast CI also renders **eight lossless original 48k/16-bit +stereo WAVs**: LIGHT versus DIRECTIONAL prepared mode on FRONT/REAR and +stereo spreads 0°/60°. Both use the exact same real native SQUARE +ROOM controls, output trim, direct HRIR, synthesized phase-conflicted +L/R instruments and 3-second frame clock (no external licensed music). +`tests/sonku_p6_realtime_audio_audit.py` enforces consistent metadata, +the exact no-reflection early prefix, finite / unclipped and non-silent +PCM, and a genuine measured wet-output difference after reflections. +Metrics are uploaded with the WAVs and listening guide. A difference +from lightweight reflections is expected; it is **not** evidence the +candidate sounds better, externalizes more or matches dearVR. + +## Native build reproducibility + +`ARMixSonKuP6PreparedTests` is now a focused portable CTest target. +The existing real JUCE `ARMixSonKuNativeStateTests` asserts the prepared +profile in **both** option-OFF (Lightweight) and explicit option-ON +(DirectionalKemar) Windows builds, alongside native ACK/state restoration. +Use the exact PR SHA to compile the test once on Windows; Linux native +GitHub Actions proves portable-core behavior but not a Windows JUCE binary. diff --git a/engine/builtin_fx/SonKuSpatialProcessor.h b/engine/builtin_fx/SonKuSpatialProcessor.h index 2412d6c87..26552b849 100644 --- a/engine/builtin_fx/SonKuSpatialProcessor.h +++ b/engine/builtin_fx/SonKuSpatialProcessor.h @@ -38,7 +38,14 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, && layout.getMainOutputChannelSet()==juce::AudioChannelSet::stereo(); } void prepareToPlay(double rate,int) override { - ready_=core_.prepare(rate); + // 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 + constexpr auto profile=armix::sonku::SonKuReflectionProfile::DirectionalKemar; +#else + constexpr auto profile=armix::sonku::SonKuReflectionProfile::Lightweight; +#endif + ready_=core_.prepare(rate,profile); observedAzimuthDegrees_.store(accepted_.startAzimuthDegrees,std::memory_order_relaxed); if(ready_)ready_=core_.setSettings(accepted_); } @@ -71,6 +78,9 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor, } armix::sonku::Settings acceptedSettings() const noexcept {return accepted_;} bool isReady() const noexcept {return ready_;} + armix::sonku::SonKuReflectionProfile preparedReflectionProfile() const noexcept { + return core_.preparedReflectionProfile(); + } float observedAzimuthDegrees() const noexcept { return observedAzimuthDegrees_.load(std::memory_order_relaxed); } diff --git a/engine/builtin_fx/sonku/SonKuEarlyReflections.h b/engine/builtin_fx/sonku/SonKuEarlyReflections.h index 477af9b54..38550bc7c 100644 --- a/engine/builtin_fx/sonku/SonKuEarlyReflections.h +++ b/engine/builtin_fx/sonku/SonKuEarlyReflections.h @@ -20,6 +20,11 @@ enum class SonKuRoomShape : std::uint8_t { Rectangular=0, Square=1 }; struct SonKuRoomGeometry { float widthMeters=7.2f,depthMeters=7.2f,distanceMeters=1.6f; }; +// One render profile is admitted at prepare time, never switched inside PCM. +// The measured horizontal KEMAR path remains experimental until ASIO/AB FAT. +enum class SonKuReflectionProfile : std::uint8_t { + Lightweight=0, DirectionalKemar=1 +}; class SonKuEarlyReflections final { public: struct Ears {float left=0.f,right=0.f;}; @@ -27,8 +32,11 @@ class SonKuEarlyReflections final { static constexpr int sourceCount=2; static constexpr int ringFrames=8192; static constexpr int geometryInterval=64; - bool prepare(double rate) noexcept { + bool prepare(double rate, SonKuReflectionProfile profile= + SonKuReflectionProfile::Lightweight) noexcept { ready_=false; + if(profile!=SonKuReflectionProfile::Lightweight && + profile!=SonKuReflectionProfile::DirectionalKemar)return false; if(!std::isfinite(rate) || (std::abs(rate-44100.)>.1 && std::abs(rate-48000.)>.1))return false; rate_=static_cast(rate); @@ -36,7 +44,16 @@ class SonKuEarlyReflections final { gainSlew_=static_cast(1.-std::exp(-1./(rate*0.012))); amountSlew_=static_cast(1.-std::exp(-1./(rate*0.010))); kernelSlew_=static_cast(1.-std::exp(-1./(rate*0.008))); - hrirBank_=(rate==44100.)?hrir::normal44100:hrir::normal48000; + // Match the sample-rate tolerance admitted by both native cores; an + // ASIO rate close to 44100 must never index the 48k measured HRIR. + hrirBank_=(std::abs(rate-44100.)<=.1)?hrir::normal44100:hrir::normal48000; + profile_=profile; + // P6: select the exact P2+P3+P4 kernels before publishing this + // instance. No runtime transition, heap, mode queue or graph fork. + directionalHrir_=profile==SonKuReflectionProfile::DirectionalKemar; + fastZeroSpread_=directionalHrir_; + fastContiguousHrir_=directionalHrir_; + realtimeMode_=false; reset(); ready_=true; return true; @@ -49,10 +66,11 @@ class SonKuEarlyReflections final { amount_=0.f; fuseEligible_=true; } + SonKuReflectionProfile preparedProfile() const noexcept{return profile_;} // OFFLINE A/B ONLY: existing approved room mode remains bit-exact by // default. Reject mode changes while active; no public state/GUI switch. bool setDirectionalHrir(bool enabled) noexcept { - if(active())return false; + if(profile_!=SonKuReflectionProfile::Lightweight || active())return false; directionalHrir_=enabled; if(!enabled){fastZeroSpread_=false;fastContiguousHrir_=false;} fuseEligible_=true; @@ -64,7 +82,8 @@ class SonKuEarlyReflections final { // while both emitters share the same direction (spread == 0). // This changes no public settings or live graph authority. bool setDirectionalZeroSpreadFusion(bool enabled) noexcept { - if(active() || (enabled && !directionalHrir_))return false; + if(profile_!=SonKuReflectionProfile::Lightweight || + active() || (enabled && !directionalHrir_))return false; fastZeroSpread_=enabled; fuseEligible_=true; return true; @@ -74,7 +93,8 @@ class SonKuEarlyReflections final { // when the delayed 140-tap HRIR FIR window is wholly in one ring span. // No duplicated ring storage and no HRIR coefficient truncation. bool setDirectionalContiguousHrir(bool enabled) noexcept { - if(active() || (enabled && !directionalHrir_))return false; + if(profile_!=SonKuReflectionProfile::Lightweight || + active() || (enabled && !directionalHrir_))return false; fastContiguousHrir_=enabled; return true; } @@ -376,5 +396,6 @@ class SonKuEarlyReflections final { bool directionalHrir_=false; bool fastZeroSpread_=false,fuseEligible_=true; bool fastContiguousHrir_=false; + SonKuReflectionProfile profile_=SonKuReflectionProfile::Lightweight; }; } // namespace armix::sonku diff --git a/engine/builtin_fx/sonku/SonKuSpatialCore.h b/engine/builtin_fx/sonku/SonKuSpatialCore.h index 2f9cb8df0..8280b7a02 100644 --- a/engine/builtin_fx/sonku/SonKuSpatialCore.h +++ b/engine/builtin_fx/sonku/SonKuSpatialCore.h @@ -59,12 +59,13 @@ class SonKuSpatialCore final { public: static constexpr int taps=hrir::taps; static constexpr int updateInterval=16; - bool prepare(double rate) noexcept { + bool prepare(double rate, SonKuReflectionProfile profile= + SonKuReflectionProfile::Lightweight) noexcept { ready_=false; if(!std::isfinite(rate) || (std::abs(rate-44100.)>.1 && std::abs(rate-48000.)>.1))return false; sampleRate_=rate; - bank_=(std::abs(rate-44100.)<.1)?hrir::normal44100:hrir::normal48000; + bank_=(std::abs(rate-44100.)<=.1)?hrir::normal44100:hrir::normal48000; // Prepared control-side: continuous coefficient and gain smoothing // without trigonometric/exponential work in the audio callback. filterSlew_=static_cast(1.-std::exp(-1./(rate*0.006))); @@ -74,7 +75,7 @@ class SonKuSpatialCore final { distanceSlew_=static_cast(1.-std::exp(-1./(rate*0.030))); bassSlew_=static_cast(1.-std::exp(-2.*3.14159265358979323846*180./rate)); limiterRelease_=static_cast(1./(rate*0.080)); - if(!room_.prepare(rate)||!reverb_.prepare(rate)|| + if(!room_.prepare(rate,profile)||!reverb_.prepare(rate)|| !integrity_.prepare(rate))return false; reset(); ready_=true; @@ -159,6 +160,9 @@ class SonKuSpatialCore final { return reverb_.setPreset(preset); } bool ready() const noexcept {return ready_;} + SonKuReflectionProfile preparedReflectionProfile() const noexcept { + return room_.preparedProfile(); + } 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. diff --git a/scripts/vocal_harmony_ci_scope.mjs b/scripts/vocal_harmony_ci_scope.mjs new file mode 100644 index 000000000..98da1cab7 --- /dev/null +++ b/scripts/vocal_harmony_ci_scope.mjs @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Path classification for the Vocal Harmony plugin's dedicated CI. +// The broader JUCE mixer/ArSon Player/GUI workflows must never be treated +// as changes to this plugin merely because they share CMakeLists.txt. +import {readFileSync} from 'node:fs'; +import {pathToFileURL} from 'node:url'; + +const dspPaths = [ + /^engine\/builtin_fx\/Harmony[^/]*\.h$/, + /^engine\/builtin_fx\/ChannelHarmonyProcessor\.h$/, + /^tests\/harmony[^/]*\.(?:cpp|py)$/, + /^tools\/harmony_offline_ab\.cpp$/ +]; +const uiPaths = [ + /^site\/preview-v2\/assets\/mixer-native-harmony\.js$/, + /^tests\/(?:native_harmony_assembly_test|approved_native_harmony_smoke)\.py$/ +]; + +export function classifyVocalHarmonyChanges(files) { + const changed = Array.isArray(files) ? files : []; + const dsp = changed.some(file => typeof file === 'string' && + dspPaths.some(pattern => pattern.test(file))); + const uiOnly = changed.some(file => typeof file === 'string' && + uiPaths.some(pattern => pattern.test(file))); + return {dsp, ui: dsp || uiOnly}; +} + +// stdin: git diff --name-only --no-renames BASE HEAD +// stdout: GitHub Actions $GITHUB_OUTPUT-compatible names; no network/API. +if (process.argv[1] && + import.meta.url === pathToFileURL(process.argv[1]).href) { + const files = readFileSync(0, 'utf8').split(/\r?\n/).filter(Boolean); + const result = classifyVocalHarmonyChanges(files); + process.stdout.write('dsp=' + result.dsp + '\nui=' + result.ui + '\n'); +} diff --git a/tests/sonku_native_state_test.cpp b/tests/sonku_native_state_test.cpp index ad2927dff..3df820ede 100644 --- a/tests/sonku_native_state_test.cpp +++ b/tests/sonku_native_state_test.cpp @@ -13,6 +13,13 @@ int main(){ SonKuSpatialProcessor live; live.prepareToPlay(48000.,128); assert(live.isReady()); +#if defined(ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT) && ARMIX_SONKU_EXPERIMENTAL_DIRECTIONAL_RT + assert(live.preparedReflectionProfile()== + armix::sonku::SonKuReflectionProfile::DirectionalKemar); +#else + assert(live.preparedReflectionProfile()== + armix::sonku::SonKuReflectionProfile::Lightweight); +#endif auto scene=live.acceptedSettings(); assert(scene.spacePreset==0); // legacy samples always load with ROOM OFF scene.spacePreset=2;scene.sourceDistanceMeters=5.f; @@ -38,6 +45,7 @@ int main(){ assert(bytes.getSize()==46); SonKuSpatialProcessor restored; restored.prepareToPlay(48000.,128); + assert(restored.preparedReflectionProfile()==live.preparedReflectionProfile()); assert(restored.restoreUnpublishedState(bytes.getData(), static_cast(bytes.getSize()))); const auto got=restored.acceptedSettings(); diff --git a/tests/sonku_p6_realtime_audio_audit.py b/tests/sonku_p6_realtime_audio_audit.py new file mode 100644 index 000000000..ba0b1d742 --- /dev/null +++ b/tests/sonku_p6_realtime_audio_audit.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +"""P6 actual native SQUARE ROOM fixture: no phase/time/source confounds.""" +import json +import math +import pathlib +import struct +import sys +import wave + +def read_wav(path): + with wave.open(str(path), "rb") as audio: + if (audio.getnchannels(), audio.getsampwidth(), audio.getframerate(), + audio.getnframes()) != (2, 2, 48000, 144000): + raise AssertionError(f"unexpected WAV layout: {path}") + raw = audio.readframes(audio.getnframes()) + sample = struct.unpack("<" + "h" * (len(raw)//2), raw) + return sample + +def main(directory): + directory = pathlib.Path(directory) + result = {"method": "same-source actual native ROOM LIGHT vs prepared P6", + "qualification": "machine PCM only; not ASIO / dearVR listening", + "pairs": {}} + for side in ("front", "rear"): + for spread in (0, 60): + name = f"{side}-spread{spread}" + light = read_wav(directory/f"sonku-p6-light-{name}.wav") + full = read_wav(directory/f"sonku-p6-directional-{name}.wav") + assert len(light) == len(full) + # Physically causal reflections cannot affect the immediate + # native direct HRTF; the same stereo musical source is used. + assert light[:96*2] == full[:96*2], name + delta = [(a-b)/32768.0 for a,b in zip(light[2500*2:],full[2500*2:])] + rms_delta = math.sqrt(sum(x*x for x in delta)/len(delta)) + max_peak = max(max(abs(x) for x in light), + max(abs(x) for x in full))/32768.0 + full_rms = math.sqrt(sum((x/32768.0)**2 for x in full)/len(full)) + if not (math.isfinite(rms_delta) and rms_delta>1e-6 + and 1e-4 +#include +#include +#include +#include +#include +#include + +int main(){ + using namespace armix::sonku; + constexpr double pi=3.14159265358979323846; + constexpr int frames=12288; + for(const double rate:{44100.,48000.}){ + auto reject=std::make_unique(); + assert(!reject->prepare(rate,static_cast(255))); + auto light=std::make_unique(); + auto full=std::make_unique(); + auto split=std::make_unique(); + assert(light->prepare(rate)); + assert(full->prepare(rate,SonKuReflectionProfile::DirectionalKemar)); + assert(split->prepare(rate,SonKuReflectionProfile::DirectionalKemar)); + assert(light->preparedReflectionProfile()==SonKuReflectionProfile::Lightweight); + assert(full->preparedReflectionProfile()==SonKuReflectionProfile::DirectionalKemar); + // Prepared production-profile kernels are immutable; offline-only + // mutators must not silently disable the real-time renderer. + assert(!full->setDirectionalEarlyReflectionsHrir(false)); + assert(!full->setDirectionalZeroSpreadFusion(false)); + assert(!full->setDirectionalContiguousHrir(false)); + Settings scene{}; + scene.startAzimuthDegrees=40.f;scene.revolutionSeconds=3.f; + scene.moving=true;scene.stereoSpreadDegrees=60.f; + scene.spacePreset=1;scene.sourceDistanceMeters=1.6f; + scene.spatialMix=1.f;scene.outputTrim=.6f; + scene.roomAmount=.70f;scene.ambience=.22f; + assert(light->setSettings(scene)); + assert(full->setSettings(scene)); + assert(split->setSettings(scene)); + std::array l{},r{},sl{},sr{},ll{},lr{}; + for(int n=0;n(n/rate); + const float bass=.12f*std::sin(static_cast(2.*pi*220.*t)); + const float treb=.06f*std::sin(static_cast(2.*pi*3200.*t)); + const float side=.035f*std::sin(static_cast(2.*pi*470.*t)); + l[n]=sl[n]=ll[n]=bass+treb+side; + r[n]=sr[n]=lr[n]=bass-treb-side; + } + full->process(l.data(),r.data(),frames); + light->process(ll.data(),lr.data(),frames); + for(int at=0;atprocess(sl.data()+at,sr.data()+at,n); + at+=n; + } + double difference=0.,energy=0.; + for(int n=0;n2500)difference+=std::abs(l[n]-ll[n])+std::abs(r[n]-lr[n]); + energy+=l[n]*l[n]+r[n]*r[n]; + } + assert(energy>0.01 && difference>1.e-4); + assert(std::abs(full->azimuthDegrees()-split->azimuthDegrees())<1.e-7); + // On device restart the accepted scene must republish with the + // explicitly requested profile, not retain an old hidden mode. + assert(full->prepare(rate,SonKuReflectionProfile::DirectionalKemar)); + assert(full->preparedReflectionProfile()==SonKuReflectionProfile::DirectionalKemar); + assert(full->settings().spacePreset==1); + assert(full->prepare(rate)); + assert(full->preparedReflectionProfile()==SonKuReflectionProfile::Lightweight); + assert(full->settings().spacePreset==1); + } + // Both native KEMAR consumers must choose the identical measured bank + // for a driver-reported rate within the accepted 0.1-Hz tolerance. + for(const auto [nominal,near]:{ + std::pair{44100.,44100.05}, + std::pair{48000.,47999.95}}){ + auto exact=std::make_unique(); + auto candidate=std::make_unique(); + assert(exact->prepare(nominal,SonKuReflectionProfile::DirectionalKemar)); + assert(candidate->prepare(near,SonKuReflectionProfile::DirectionalKemar)); + const SonKuRoomGeometry g{7.2f,7.2f,1.6f}; + assert(exact->setRealtimeRoom(g,.55f,true)); + assert(candidate->setRealtimeRoom(g,.55f,true)); + double error=0.,signal=0.; + for(int i=0;i<4000;++i){ + const float v=i==0?.35f:0.f; + const auto a=exact->process(v,v,45.,60.f); + const auto b=candidate->process(v,v,45.,60.f); + error+=std::abs(a.left-b.left)+std::abs(a.right-b.right); + signal+=std::abs(a.left)+std::abs(a.right); + } + assert(signal>1.e-4 && error<.005); + } + std::puts("PASS P6 native ROOM profile, 44.1/48k and tolerance, restart, full-KEMAR music and chunk parity"); +} diff --git a/tools/sonku_offline_listening.cpp b/tools/sonku_offline_listening.cpp index 83ffe4bef..b490d9228 100644 --- a/tools/sonku_offline_listening.cpp +++ b/tools/sonku_offline_listening.cpp @@ -402,6 +402,72 @@ std::vector directionalRoomAudio(int azimuth,bool measured, } return pcm; } +// P6: the ACTUAL native ROOM scene, prepared before the PCM callback. +// Same source and saved user scene, light vs opt-in P2/P3/P4 full KEMAR. +// Unlike P2 offline setAmount fixtures this exercises native setRealtimeRoom. +std::vector realtimeRoomAudio(int azimuth,float spread, + bool directional){ + SonKuSpatialCore dsp; + const auto profile=directional + ?armix::sonku::SonKuReflectionProfile::DirectionalKemar + :armix::sonku::SonKuReflectionProfile::Lightweight; + if(!dsp.prepare(rate,profile)) + throw std::runtime_error("P6 native profile prepare failed"); + Settings scene=fixed(static_cast(azimuth)); + scene.spacePreset=1;scene.sourceDistanceMeters=1.6f; + scene.roomAmount=.65f;scene.ambience=.20f; + scene.stereoSpreadDegrees=spread;scene.outputTrim=.60f; + if(!dsp.setSettings(scene)) + throw std::runtime_error("P6 native ROOM scene rejected"); + constexpr int total=rate*3; + constexpr float pi=3.14159265358979323846f; + std::vector pcm; + pcm.reserve(static_cast(total)*4); + for(int at=0;at l{},r{}; + for(int i=0;i(f)/rate; + const float env=std::clamp(std::min(f,total-1-f)/ + static_cast(rate/50),0.f,1.f); + const float bass=.095f*std::sin(2.f*pi*220.f*t); + const float leftTreble=.032f*std::sin(2.f*pi*3200.f*t); + const float rightTreble=-.032f*std::sin(2.f*pi*3200.f*t); + const float harmonic=.04f*std::sin(2.f*pi*660.f*t); + l[i]=env*(bass+harmonic+leftTreble+ + .018f*std::sin(2.f*pi*4700.f*t)); + r[i]=env*(bass+harmonic+rightTreble+ + .021f*std::sin(2.f*pi*940.f*t)); + } + dsp.process(l.data(),r.data(),n); + for(int i=0;i(spread),false)); + writeWav(dir/("sonku-p6-directional-"+label+".wav"), + realtimeRoomAudio(azimuth,static_cast(spread),true)); + } + } + std::ofstream guide(dir/"P6-REALTIME-ROOM-HEADPHONE-AB.txt"); + if(!guide)throw std::runtime_error("P6 guide output failed"); + guide<<"Eight original 3s stereo 48k/16bit WAVs; FOUR matched A/B pairs.\n" + <<"Compare sonku-p6-light-* versus sonku-p6-directional-*.\n" + <<"FRONT/REAR each with stereo spread 0 and 60 degrees.\n" + <<"Actual native ROOM SQUARE, 1.6m, reflections 0.65, ambience 0.20.\n" + <<"Exact same synthetic phase-conflicted bass/treble stereo source.\n" + <<"No mastering or per-file normalization, listen with headphones.\n" + <<"Disable headphone spatial enhancements; keep a SAFE level.\n" + <<"These are numerical/native scene demonstrations, NOT measured\n" + <<"dearVR externalization or human listener preference scores.\n"; +} void writeP4ContiguousAudio(const std::filesystem::path& dir){ for(int azimuth:{0,180}){ const std::string side=azimuth==0?"front":"rear"; @@ -490,7 +556,8 @@ int main(int argc,char** argv){ (std::string(argv[2])=="--music-integrity-only" || std::string(argv[2])=="--directional-er-only" || std::string(argv[2])=="--p3-fusion-only" || - std::string(argv[2])=="--p4-contiguous-only"))) + std::string(argv[2])=="--p4-contiguous-only" || + std::string(argv[2])=="--p6-realtime-only"))) throw std::runtime_error("Usage: sonku-offline-demo OUTPUT_DIRECTORY [--music-integrity-only]"); const std::filesystem::path dir(argv[1]); std::filesystem::create_directories(dir); @@ -501,6 +568,13 @@ int main(int argc,char** argv){ std::cout<<"P2 directional room 4 WAV rendered\n"; #else throw std::runtime_error("P2 directional room only exists in candidate"); +#endif + } else if(std::string(argv[2])=="--p6-realtime-only"){ +#if !defined(SONKU_AB_BASELINE) + writeP6RealtimeAudio(dir); + std::cout<<"P6 native ROOM eight A/B WAV rendered\n"; +#else + throw std::runtime_error("P6 native scene unavailable in alpha.23"); #endif } else if(std::string(argv[2])=="--p4-contiguous-only"){ #if !defined(SONKU_AB_BASELINE) diff --git a/tools/sonku_rt_benchmark.cpp b/tools/sonku_rt_benchmark.cpp index 29dd236cd..980483829 100644 --- a/tools/sonku_rt_benchmark.cpp +++ b/tools/sonku_rt_benchmark.cpp @@ -21,10 +21,16 @@ template Result measure(double rate,float amount,float late=0.f, const armix::sonku::SonKuRoomGeometry* geometry=nullptr, bool directional=false,float spread=60.f, - bool fused=false,bool contiguous=false){ + bool fused=false,bool contiguous=false, + bool realtimeNative=false,bool nativeDirectional=false){ using namespace armix::sonku; SonKuSpatialCore dsp; - if(!dsp.prepare(rate))throw std::runtime_error("unsupported sample rate"); + if(nativeDirectional && !realtimeNative) + throw std::runtime_error("directional realtime profile requires native scene"); + if(!dsp.prepare(rate,nativeDirectional + ?SonKuReflectionProfile::DirectionalKemar + :SonKuReflectionProfile::Lightweight)) + throw std::runtime_error("unsupported sample rate/profile"); if(directional && !dsp.setDirectionalEarlyReflectionsHrir(true)) throw std::runtime_error("directional room not prepared"); if(fused && !dsp.setDirectionalZeroSpreadFusion(true)) @@ -33,7 +39,10 @@ Result measure(double rate,float amount,float late=0.f, throw std::runtime_error("P4 contiguous HRIR not prepared"); Settings s{};s.moving=true;s.revolutionSeconds=10.f; s.spatialMix=1.f;s.stereoSpreadDegrees=spread; - if(!dsp.setSettings(s)|| + if(realtimeNative){ + s.spacePreset=1;s.roomAmount=amount;s.ambience=late; + if(!dsp.setSettings(s))throw std::runtime_error("invalid realtime scene"); + }else if(!dsp.setSettings(s)|| (geometry && !dsp.setAcousticRoomGeometry(*geometry))|| !dsp.setEarlyReflectionsAmount(amount)|| !dsp.setMusicalReverbAmount(late)) @@ -160,6 +169,24 @@ int main(){ <<" note=runner_local_not_ASIO\n"; } } + // P6 measures the TRUE native ROOM scene, not the offline setAmount + // shortcut. Same graph, input, gain, 3-second frame clock, 128 block. + // The numbers are indicative; CI never uses them as ASIO certification. + for(float spread:{0.f,60.f}){ + const auto light=measure<128>(48000.,.55f,0.f,nullptr, + false,spread,false,false,true,false); + const auto full=measure<128>(48000.,.55f,0.f,nullptr, + false,spread,false,false,true,true); + std::cout<