From ed11632e5731f08d69d3b0150248165456cda20f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 12:17:33 +0700 Subject: [PATCH 001/125] feat(harmony): P0 time-sliced pitch correlation, sample-rate stable ramps and ASIO block parity --- CMakeLists.txt | 6 +- docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md | 20 ++++ engine/builtin_fx/HarmonyDsp.h | 110 +++++++++++++++----- tests/harmony_cpu_profile_test.cpp | 71 +++++++++++++ tests/harmony_dsp_test.cpp | 50 +++++++++ 5 files changed, 229 insertions(+), 28 deletions(-) create mode 100644 tests/harmony_cpu_profile_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d3637a007..cee805af8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,10 @@ if(BUILD_TESTING) add_executable(ARMixHarmonyDspTests tests/harmony_dsp_test.cpp) target_compile_features(ARMixHarmonyDspTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyMultivoicePitchAndRealtimeFinitePCM COMMAND ARMixHarmonyDspTests) + # Non-gating synthetic engine-only CPU profile (not ASIO certification). + add_executable(ARMixHarmonyCpuProfileTests tests/harmony_cpu_profile_test.cpp) + target_compile_features(ARMixHarmonyCpuProfileTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonySyntheticCallbackCpuProfile COMMAND ARMixHarmonyCpuProfileTests) add_executable(ARMixHarmonyMusicGuideTests tests/harmony_music_key_test.cpp) target_compile_features(ARMixHarmonyMusicGuideTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyCrossChannelMusicKeyAndManualFallback COMMAND ARMixHarmonyMusicGuideTests) @@ -129,7 +133,7 @@ if(BUILD_TESTING) add_test(NAME ApprovedNativeHarmonyEditorAckAndSingleGui COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_harmony_assembly_test.py") add_executable(ARMixMixerRoutingTests tests/mixer_routing_plan_test.cpp) target_compile_features(ARMixMixerRoutingTests PRIVATE cxx_std_20) - add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests) + add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests ARMixHarmonyCpuProfileTests) add_test(NAME TenStripStaticRoutingAndMaster COMMAND ARMixMixerRoutingTests) # M3D atomic native Session: the accepted Console roster cannot advance # without a successful epoch/revision-gated PCM publication. diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index 2a205e6fb..d9db4ca46 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -49,3 +49,23 @@ A 1536-sample lookback at 48 kHz is **32 ms DSP delay**, before device input + o - Rubber Band v4 technical docs expose formant options and exact latency API, but licensing, ASIO callback suitability and measured overhead must be independently assessed; do not add by assumption. **Status:** engineering candidate only; PR stays Draft pending exact-HEAD qualification and physical vocal FAT. + +## 2026-11-09 follow-up — pitch CPU and measurable callback budget (post-merge) + +- Roll the shifted window's energy from one candidate lag to the next. Keep the existing dot-product, confidence threshold, quantizer and FX/PDC/GUI contracts. Each adjacent lag changes by one outgoing + one incoming squared sample instead of recomputing 160 squares. Only floating-point rounding may differ. +- Extend deterministic C++ PCM regressions to a multi-harmonic A2 sample with 64/128/257-frame chunks. Existing E2/C6, dry-latency alignment, automation and music-guide tests remain in force. +- Add `NativeHarmonySyntheticCallbackCpuProfile` to CTest. Synthetic engine-only p50/p95/p99/max data covers 48 kHz (64/128/256 samples), 96 kHz (128 samples), with 2/5 voices. Timing is recorded only outside engine->process(), but Windows runner contention makes absolute timing unsuitable for a CI hard gate. +- No quantitative speedup claim without controlled before/after on one machine. No ASIO driver, JUCE graph, real-world multichannel CPU, formant quality or ear monitoring is measured by this synthetic profile. Physical singer FAT remains release blocking. + +## 2026-11-09 P0 bounded realtime engine milestone + +**Release scope**: Stable 48-kHz 1536-sample (32ms) DSP lookback and exact native PDC remain unchanged until recorded singing/listening establishes a safe lower-latency algorithm. No experimental formant shifter or hidden direct monitor path is enabled merely to advertise latency gains. + +- Move pitch autocorrelation off one large sample spike: snapshot a fixed decimated window every ~6.7ms, process at most 32 candidate lags per sample-scheduled slice, finish before the next analysis window. All snapshots and per-instance state are fixed-size, and graph/audio ownership is unchanged. This reduces the worst-case single-sample analysis work even at ASIO 64. +- Keep the sliding lagged energy improvement from previous #485, preserving confidence thresholds, song key readback, five-voice controls and existing tests. +- Recompute voiced gate and ratio smoothing coefficients on `prepare(rate)` only so physical time constants remain the same across 32–192kHz device reopen; 48kHz response stays calibrated to the earlier engine. +- Enforce deterministic output for identical stereo singing PCM across 64/127/256 sample callback partitioning and instrument the maximum completed pitch-lag work per sample. Retain all prior E2–C6, cross-channel Music Key and dry 192k latency tests. +- The synthetic engine-only CPU profile is diagnostic, not a hardware underrun oracle. Next **non-automatable** P0 gate: independent actual Windows ASIO interface, human singing + recorded dry/wet FFT/formant comparison, 48/96k with 64/128/256 periods and 2–5 voices for 30 minutes; callback p95/p99/max, driver XRUNs and measured loopback round trip must be documented. +- Formant-preserving pitch synchronous synthesis (TD-PSOLA / equivalent) remains a separate replaceable shifter milestone: it must be verified against consonants, onset/off pitch, male/female vowels and CPU/latency tradeoffs before becoming audible default. Never claim today's granular shifter preserves formants. + +Project status: P0 **realtime boundedness implementation** awaiting exact-HEAD Windows CTest and singer FAT; not a final professional-quality or latency qualification. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 56d245e84..83b6380e0 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -61,6 +61,7 @@ inline float smoothGrainBlend(float phase) noexcept { class Engine final { public: static constexpr int maxVoices=5; + static constexpr int maxPitchLagsPerSlice=32; // upper bound for each callback sample // Maximum 192 kHz grain is 3072 frames: 2*grain latency + 3*grain // history = 15360, so 16384 frames retain the full rate/ratio budget. // Halves the three large audio rings per instance without RT allocation. @@ -72,6 +73,7 @@ class Engine final { latency_=2*grain_; decimation_=std::max(1,static_cast(std::round(rate/12000.))); detectEvery_=std::max(128,static_cast(rate/150.)); + pitchSliceEvery_=std::max(1,detectEvery_/8); // Support bass through soprano fundamentals; keep Nyquist/finiteness guards. // Earlier 850 Hz cap failed to track high soprano notes (e.g. C6). lowLag_=std::max(8,static_cast(rate/(decimation_*1200.))); @@ -85,10 +87,16 @@ class Engine final { const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; - detectCounter_=0;noteHold_=0;currentNote_=-1;candidateNote_=-1; + detectCounter_=0;pitchSliceCounter_=0;pitchNextLag_=0; + pitchActive_=false;pitchBest_=-1.f;pitchBestLag_=0; + peakPitchLagWork_=0;noteHold_=0;currentNote_=-1;candidateNote_=-1; guideKey_=-1;guideScale_=-1; voiced_=false;voicedGain_=0.f;settings_=Settings{}; - smoothingAlpha_=static_cast(1.-std::exp(-1./(rate*0.005))); // 5 ms continuous control ramp + smoothingAlpha_=static_cast(1.-std::exp(-1./(rate*0.005))); // 5 ms control ramp + // Preserve the established 48k envelope while keeping durations + // constant at 32-192k. Exponents computed off the callback. + voicedGateAlpha_=static_cast(1.-std::pow(1.-0.002,48000./rate)); + ratioAlpha_=static_cast(1.-std::pow(1.-0.00045,48000./rate)); processed_=false;settings_=Settings{}; return setSettings(settings_); } @@ -169,6 +177,7 @@ class Engine final { int latencySamples() const noexcept{return latency_;} int observedMidiNote() const noexcept{return currentNote_;} bool voiced() const noexcept{return voiced_;} + int peakPitchLagWork() const noexcept{return peakPitchLagWork_;} void process(float* l,float* r,int frames) noexcept { if(!l||!r||frames<=0||rate_<=0.)return; processed_=true; @@ -196,10 +205,18 @@ class Engine final { downWrite_=(downWrite_+1)%decimated_.size(); ++downSeen_; } - if(++detectCounter_>=detectEvery_){detectCounter_=0;detectPitch();} + if(++detectCounter_>=detectEvery_){ + detectCounter_=0;beginPitchAnalysis(); + } + // Correlation search is spread across the existing sample + // callback: never evaluate all 175+ candidate lags at once. + // Every 64-sample ASIO period sees a bounded number of slices. + if(pitchActive_ && ++pitchSliceCounter_>=pitchSliceEvery_){ + pitchSliceCounter_=0;continuePitchAnalysis(); + } const float dryL=tap(left_,static_cast(latency_)); const float dryR=tap(right_,static_cast(latency_)); - voicedGain_+=((voiced_?1.f:0.f)-voicedGain_)*0.002f; + voicedGain_+=((voiced_?1.f:0.f)-voicedGain_)*voicedGateAlpha_; float lead=0.f; if(correctionMix_>0.00001f&&voicedGain_>0.00001f) lead=shifted(maxVoices,color_); @@ -230,7 +247,7 @@ class Engine final { } float shifted(int voice,float color) noexcept { float& currentRatio=ratio_[static_cast(voice)]; - currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*0.00045f; + currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*ratioAlpha_; const float p=phase_[static_cast(voice)]; const float pB=p<0.5f?p+0.5f:p-0.5f; const float delayA=2.f*grain_+(1.f-currentRatio)*p*grain_; @@ -248,39 +265,70 @@ class Engine final { phase_[static_cast(voice)]-=1.f; return y; } - void detectPitch() noexcept { + // Prepare one immutable, bounded pitch-analysis window every analysis hop. + // The subsequent 32-lag correlation slices cannot race PCM history writes: + // they only read the frozen fixed-size pitchWindow_. + void beginPitchAnalysis() noexcept { + pitchActive_=false; if(downSeen_(highLag_+170))return; constexpr int span=160; - // Gather a contiguous fixed-size pitch window ONCE per analysis hop. - // Previously every candidate/lag re-indexed circular history in the - // inner O(lags * span) loop: unpredictable CPU peaks on tiny ASIO buffers. - std::array samples{}; auto ix=(downWrite_+decimated_.size()-1)%decimated_.size(); for(int j=0;j(j)]=decimated_[ix]; + pitchWindow_[static_cast(j)]=decimated_[ix]; ix=ix==0?decimated_.size()-1:ix-1; } - double energy=0.; + pitchEnergy_=0.; for(int j=0;j(j)]; - energy+=x*x; + const double x=pitchWindow_[static_cast(j)]; + pitchEnergy_+=x*x; } - if(energy/static_cast(span)<1.e-6){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + if(pitchEnergy_/static_cast(span)<1.e-6){ + voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1; + return; + } + pitchCorrelations_.fill(0.f); + pitchLagEnergy_=0.; + for(int j=0;j(j+lowLag_)]; + pitchLagEnergy_+=y*y; } - float best=-1.f;int bestLag=0; - std::array correlations{}; - for(int lag=lowLag_;lag<=highLag_;++lag){ - double xy=0.,yy=0.; + pitchBest_=-1.f;pitchBestLag_=0;pitchNextLag_=lowLag_; + pitchSliceCounter_=0; + pitchActive_=true; + } + void continuePitchAnalysis() noexcept { + if(!pitchActive_)return; + constexpr int span=160; + const int endLag=std::min(highLag_,pitchNextLag_+maxPitchLagsPerSlice-1); + const int work=endLag-pitchNextLag_+1; + peakPitchLagWork_=std::max(peakPitchLagWork_,work); + for(int lag=pitchNextLag_;lag<=endLag;++lag){ + if(lag>lowLag_){ + const double leaving=pitchWindow_[static_cast(lag-1)]; + const double entering=pitchWindow_[static_cast(span+lag-1)]; + pitchLagEnergy_+=entering*entering-leaving*leaving; + } + double xy=0.; for(int j=0;j(j)]; - const double y=samples[static_cast(j+lag)]; - xy+=x*y;yy+=y*y; + const double x=pitchWindow_[static_cast(j)]; + const double y=pitchWindow_[static_cast(j+lag)]; + xy+=x*y; } - const float correlation=static_cast(xy/std::sqrt(energy*yy+1.e-14)); - correlations[static_cast(lag)]=correlation; - if(correlation>best){best=correlation;bestLag=lag;} + const float correlation=static_cast( + xy/std::sqrt(pitchEnergy_*std::max(0.,pitchLagEnergy_)+1.e-14)); + pitchCorrelations_[static_cast(lag)]=correlation; + if(correlation>pitchBest_){pitchBest_=correlation;pitchBestLag_=lag;} } + pitchNextLag_=endLag+1; + if(pitchNextLag_>highLag_){ + pitchActive_=false; + finishPitchAnalysis(); + } + } + void finishPitchAnalysis() noexcept { + const auto& correlations=pitchCorrelations_; + float best=pitchBest_; + int bestLag=pitchBestLag_; // Prefer shortest strong period rather than an octave-multiple peak. if(best>0.77f){ for(int lag=lowLag_;lag<=highLag_;++lag){ @@ -337,11 +385,19 @@ class Engine final { double rate_=0.; int grain_=0,latency_=0,decimation_=4,detectEvery_=320; int lowLag_=12,highLag_=144;std::size_t write_=0,downWrite_=0,downSeen_=0; int downCounter_=0,detectCounter_=0; + int pitchSliceEvery_=1,pitchSliceCounter_=0,pitchNextLag_=0; + int pitchBestLag_=0,peakPitchLagWork_=0; + bool pitchActive_=false; + float pitchBest_=-1.f; + double pitchEnergy_=0.,pitchLagEnergy_=0.; + // Fixed PCM snapshots; no allocation or variable work on the callback. + std::array pitchWindow_{}; + std::array pitchCorrelations_{}; int currentNote_=-1,candidateNote_=-1,noteHold_=0; int guideKey_=-1,guideScale_=-1; bool voiced_=false;float voicedGain_=0.f; bool processed_=false; - float smoothingAlpha_=1.f; + float smoothingAlpha_=1.f,voicedGateAlpha_=0.002f,ratioAlpha_=0.00045f; float wet_=0.f,targetWet_=0.f,color_=0.f,targetColor_=0.f; float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; diff --git a/tests/harmony_cpu_profile_test.cpp b/tests/harmony_cpu_profile_test.cpp new file mode 100644 index 000000000..deadc8bcd --- /dev/null +++ b/tests/harmony_cpu_profile_test.cpp @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Non-gating, reproducible synthetic ENGINE-only callback CPU profile. +// Does not measure JUCE graph scheduling, ASIO driver or singer ear latency. +#include "../engine/builtin_fx/HarmonyDsp.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +using Clock=std::chrono::steady_clock; +constexpr int warmup=256; +constexpr int measured=512; +void profile(double rate,int block,int voices){ + auto engine=std::make_unique(); + if(!engine->prepare(rate)){std::cerr<<"Harmony prepare failed\n";std::exit(2);} + armix::harmony::Settings settings; + settings.voices=voices;settings.wet=0.55f;settings.correction=true; + if(!engine->setSettings(settings)){std::cerr<<"Harmony settings rejected\n";std::exit(2);} + std::array l{},r{}; + std::array elapsed{}; + double phase=0.; + const double step=6.283185307179586*220./rate; + for(int blockIndex=0;blockIndex(0.16*std::sin(phase)+ + 0.04*std::sin(2.*phase)); + l[static_cast(i)]=x; + r[static_cast(i)]=x; + phase+=step; + if(phase>=6.283185307179586)phase-=6.283185307179586; + } + const auto started=Clock::now(); + engine->process(l.data(),r.data(),block); + const auto finished=Clock::now(); + if(blockIndex>=warmup) + elapsed[static_cast(blockIndex-warmup)]= + std::chrono::duration(finished-started).count(); + for(int i=0;i(i)])|| + !std::isfinite(r[static_cast(i)])){ + std::cerr<<"Nonfinite Harmony PCM in profile\n";std::exit(2); + } + } + const double deadlineUs=1.e6*static_cast(block)/rate; + const auto misses=std::count_if(elapsed.begin(),elapsed.end(), + [deadlineUs](double elapsedUs){return elapsedUs>deadlineUs;}); + std::sort(elapsed.begin(),elapsed.end()); + std::cout<(); + need(pitched->prepare(48000.),"harmonic tracking prepare failed"); + constexpr int samples=24000; + std::vector hl(samples),hr(samples); + for(int i=0;i(i)/48000.; + hl[i]=hr[i]=static_cast( + .17*std::sin(6.283185307179586*110.*t)+ + .04*std::sin(6.283185307179586*220.*t)+ + .02*std::sin(6.283185307179586*330.*t)); + } + for(int i=0;iprocess(hl.data()+i,hr.data()+i,std::min(block,samples-i)); + need(pitched->voiced()&&pitched->observedMidiNote()==45, + "rolling pitch energy altered singer-like A2 classification"); + } + // P0: alternate ASIO block sizes must produce identical output PCM. + // Sliced analysis operates per sample, never depends on callback framing. + std::vector referenceL,referenceR; + for(int block:{64,127,256}){ + auto bounded=std::make_unique(); + need(bounded->prepare(48000.),"P0 bounded engine prepare failed"); + Settings rich;rich.voices=5;rich.wet=.7f;rich.correction=true; + need(bounded->setSettings(rich),"P0 quality setup failed"); + constexpr int frames=48000; + std::vector left(frames),right(frames); + for(int i=0;i(.18*std::sin(phase)+.06*std::sin(2*phase)); + right[i]=static_cast(.16*std::sin(phase)+.04*std::sin(3*phase)); + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(block,frames-i)); + need(bounded->peakPitchLagWork()>0&& + bounded->peakPitchLagWork()<=Engine::maxPitchLagsPerSlice, + "P0 pitch analysis overran per-sample lag budget"); + need(bounded->voiced()&&bounded->observedMidiNote()==57, + "P0 bounded singer tone detection failed"); + if(referenceL.empty()){ + referenceL=left;referenceR=right; + }else for(int i=0;ilatencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; } From db33b3c66e6a0181a044356e1ccb06ef36f34318 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 12:54:43 +0700 Subject: [PATCH 002/125] fix(harmony): phase-resilient vocal and cross-channel Music Guide DSP with stereo PCM regressions --- docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md | 8 ++++ engine/builtin_fx/HarmonyDsp.h | 5 ++- engine/builtin_fx/HarmonyMusicKey.h | 6 ++- engine/builtin_fx/HarmonyStereoFold.h | 49 +++++++++++++++++++++ tests/harmony_dsp_test.cpp | 30 +++++++++++++ tests/harmony_music_bank_test.cpp | 4 ++ tests/harmony_music_key_test.cpp | 24 ++++++++++ 7 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 engine/builtin_fx/HarmonyStereoFold.h diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index d9db4ca46..70b5bd300 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -69,3 +69,11 @@ A 1536-sample lookback at 48 kHz is **32 ms DSP delay**, before device input + o - Formant-preserving pitch synchronous synthesis (TD-PSOLA / equivalent) remains a separate replaceable shifter milestone: it must be verified against consonants, onset/off pitch, male/female vowels and CPU/latency tradeoffs before becoming audible default. Never claim today's granular shifter preserves formants. Project status: P0 **realtime boundedness implementation** awaiting exact-HEAD Windows CTest and singer FAT; not a final professional-quality or latency qualification. + +## 2026-11-09 P1 — stereo phase-resilient Harmony analysis + +Both `HarmonyDsp` vocal analysis/grain source and the cross-ChannelId `MusicKeyDetector` used `0.5*(L+R)`. Valid `L=-R` PCM from an extreme stereo widener or polarity-inverting source disappeared completely from both. The read-only music source remained audible elsewhere but Harmony incorrectly fell back to Manual. + +`StereoPhaseSafeFold.h` now provides a **per-instance, callback-owned, constant-work** fold with precomputed 20ms polarity evidence and 15ms smoothed recovery, strict -0.78 engage / -0.55 release hysteresis, silence release, and stereo analysis-only polarity repair. Ordinary coherent stereo keeps the existing sum. Neither dry stereo, audio routing, FX rack, SPSC schema, 2–5 voices, output device, declared latency nor GUI changes. No heap, locks, timers or per-sample trigonometry. + +PCM regressions: anti-phase singer A3 and nonzero five-voice harmony at 48/96k; anti-phase music C major at 48/96k, silence/Manual fallback; real native other-ChannelId antiphase A-minor guide with read-only source samples, plus preexisting in-phase, rekey, block parity, PDC and state migration. This only prevents destructive analysis cancellation, it is *not* formant preservation or ASIO/ear latency certification. Physical singer FAT remains open. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 83b6380e0..8b5743e85 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -5,6 +5,7 @@ #include #include #include +#include "HarmonyStereoFold.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -84,6 +85,7 @@ class Engine final { // Low-pass before downsampling: raw 12 kHz decimation aliases vocal sibilants // into the periodicity detector and destabilizes the live note readback. decimationLowpass_=0.f; + if(!vocalFold_.prepare(rate))return false; const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; @@ -196,7 +198,7 @@ class Engine final { } const float inputL=std::isfinite(l[i])?l[i]:0.f; const float inputR=std::isfinite(r[i])?r[i]:0.f; - const float mono=0.5f*(inputL+inputR); + const float mono=vocalFold_.process(inputL,inputR); left_[write_]=inputL;right_[write_]=inputR;mono_[write_]=mono; decimationLowpass_+=decimationAlpha_*(mono-decimationLowpass_); if(++downCounter_>=decimation_){ @@ -402,6 +404,7 @@ class Engine final { float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; float decimationLowpass_=0.f,decimationAlpha_=0.f; + StereoPhaseSafeFold vocalFold_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyMusicKey.h b/engine/builtin_fx/HarmonyMusicKey.h index 3743cb79f..a633fa0f2 100644 --- a/engine/builtin_fx/HarmonyMusicKey.h +++ b/engine/builtin_fx/HarmonyMusicKey.h @@ -4,6 +4,7 @@ #include #include #include +#include "HarmonyStereoFold.h" // Audio-thread-only, bounded chroma guide from a DIFFERENT ChannelId's real // pre-fader PCM. Not a chord recognizer and never an audible sidechain. @@ -21,6 +22,7 @@ class MusicKeyDetector final { bool prepare(double rate) noexcept { if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; decimation_=std::max(1,static_cast(std::round(rate/6000.))); + if(!stereoFold_.prepare(rate))return false; const double fs=rate/decimation_; sampleAlpha_=static_cast(1.-std::exp(-1./(fs*.18))); lowpassAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*1500./rate)); @@ -35,6 +37,7 @@ class MusicKeyDetector final { reset();return true; } void reset() noexcept { + stereoFold_.reset(); inC_.fill(0.f);inS_.fill(0.f); oscC_.fill(1.f);oscS_.fill(0.f);hist_.fill(0.f); downCount_=0;periodCount_=0;normalizeCount_=0; @@ -47,7 +50,7 @@ class MusicKeyDetector final { for(int n=0;n rotorC_{},rotorS_{},weight_{}; std::array oscC_{},oscS_{},inC_{},inS_{}; std::array hist_{}; diff --git a/engine/builtin_fx/HarmonyStereoFold.h b/engine/builtin_fx/HarmonyStereoFold.h new file mode 100644 index 000000000..fb91db8d0 --- /dev/null +++ b/engine/builtin_fx/HarmonyStereoFold.h @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include + +// Callback-owned analysis ONLY, not an audible stereo output mixer. +// Recover music/vocal guide PCM when opposite-polarity stereo cancels L+R. +// Normal correlated stereo remains the exact legacy sum; near-opposition +// needs two-threshold hysteresis and a smoothed phase-aware sign fold. +// Constant-work, fixed-state, lock/heap-free, zero added sample latency. +namespace armix::harmony { +class StereoPhaseSafeFold final { +public: + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + evidenceAlpha_=static_cast(1.-std::exp(-1./(rate*.020))); + blendAlpha_=static_cast(1.-std::exp(-1./(rate*.015))); + reset(); + return true; + } + void reset() noexcept { + energyL_=0.f;energyR_=0.f;cross_=0.f;amount_=0.f; + antiCorrelated_=false; + } + float process(float left,float right) noexcept { + // Both callers sanitize nonfinite source PCM. Limit only correlation + // evidence amplitude, never change a valid dry stereo source. + const float l=std::clamp(left,-4.f,4.f); + const float r=std::clamp(right,-4.f,4.f); + energyL_+=evidenceAlpha_*(l*l-energyL_); + energyR_+=evidenceAlpha_*(r*r-energyR_); + cross_+=evidenceAlpha_*(l*r-cross_); + const float power=.5f*(energyL_+energyR_); + if(power<1.e-8f)antiCorrelated_=false; + else if(antiCorrelated_){ + if(cross_>-.55f*power)antiCorrelated_=false; + }else if(cross_<-.78f*power)antiCorrelated_=true; + amount_+=blendAlpha_*((antiCorrelated_?1.f:0.f)-amount_); + // amount=0 -> original 0.5*(L+R); + // amount=1 -> recovered 0.5*(L-R). + return .5f*(left+right)-amount_*right; + } + float rescueAmount() const noexcept{return amount_;} +private: + float evidenceAlpha_=0.f,blendAlpha_=0.f; + float energyL_=0.f,energyR_=0.f,cross_=0.f,amount_=0.f; + bool antiCorrelated_=false; +}; +} // namespace armix::harmony diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 28ad45893..953abbf21 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -268,6 +268,36 @@ int main(){ std::abs(right[i]-referenceR[i])<1.e-6f, "P0 pitch output depends on ASIO callback block size"); } + // P1: real opposite-phase vocal PCM must not become silent harmony. + for(double rate:{48000.,96000.}){ + auto opposite=std::make_unique(); + need(opposite->prepare(rate),"antiphase singer prepare failed"); + Settings wet;wet.voices=5;wet.wet=.85f;wet.correction=true; + need(opposite->setSettings(wet),"antiphase singer settings failed"); + const int count=static_cast(rate*.65); + std::vector left(static_cast(count)); + std::vector right(static_cast(count)); + for(int i=0;i( + .19*std::sin(6.283185307179586*220.*i/rate)+ + .05*std::sin(6.283185307179586*440.*i/rate)); + left[static_cast(i)]=x; + right[static_cast(i)]=-x; + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(257,count-i)); + need(opposite->voiced()&&opposite->observedMidiNote()==57, + "phase-opposed singer lost stable A3 pitch"); + double harmonized=0.; + for(int i=count/2;i(i)]; + const float r=right[static_cast(i)]; + need(std::isfinite(l)&&std::isfinite(r),"phase-safe PCM not finite"); + const double recovered=.5*(static_cast(l)+r); + harmonized+=recovered*recovered; + } + need(harmonized>0.005,"opposed stereo produced no harmonized audio"); + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; diff --git a/tests/harmony_music_bank_test.cpp b/tests/harmony_music_bank_test.cpp index a8ac2ebdb..a2c7e2b55 100644 --- a/tests/harmony_music_bank_test.cpp +++ b/tests/harmony_music_bank_test.cpp @@ -146,7 +146,11 @@ int main(){ std::sin(6.28318530718*261.625565*t)+ std::sin(6.28318530718*329.627557*t))); } + // Real anti-phase other-channel PCM remains unmodified by the guide. + for(int j=0;j<128;++j)r[j]=-l[j]; + const float originalL=l[17],originalR=r[17]; bank2(musicB,l,r,128); + assert(l[17]==originalL&&r[17]==originalR); } assert(live->observedMusicKey()==9&&live->observedMusicScale()==1); assert(live->effectiveKeyCode()==21); // detected A minor diff --git a/tests/harmony_music_key_test.cpp b/tests/harmony_music_key_test.cpp index 03b65317e..6196e9fb5 100644 --- a/tests/harmony_music_key_test.cpp +++ b/tests/harmony_music_key_test.cpp @@ -46,6 +46,30 @@ int main(){ need(estimate.valid()&&estimate.key==9&&estimate.scale==1, "A-minor music track did not identify natural minor"); am.reset();need(!am.estimate().valid(),"channel retarget retained stale key"); + // Extreme polarity-inverted stereo music still contains C-major PCM. + MusicKeyDetector opposed; + need(opposed.prepare(rate),"opposed music prepare failed"); + const int frames=static_cast(rate*3.5); + std::vector invL(static_cast(frames)); + std::vector invR(static_cast(frames)); + for(int i=0;i(i)/rate; + const float v=static_cast(.09*( + std::sin(6.283185307179586*261.625565*t)+ + std::sin(6.283185307179586*329.627557*t)+ + std::sin(6.283185307179586*391.995436*t))); + invL[static_cast(i)]=v; + invR[static_cast(i)]=-v; + } + for(int i=0;i Date: Mon, 9 Nov 2026 14:04:08 +0700 Subject: [PATCH 003/125] perf(harmony): P1 sample-rate-stable Color and P2 prepared note intervals with tonal parity regressions --- docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md | 10 ++++ engine/builtin_fx/HarmonyDsp.h | 27 ++++++++--- engine/builtin_fx/HarmonyPreparedTone.h | 54 +++++++++++++++++++++ tests/harmony_dsp_test.cpp | 47 ++++++++++++++++++ 4 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 engine/builtin_fx/HarmonyPreparedTone.h diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index 70b5bd300..36668b501 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -77,3 +77,13 @@ Both `HarmonyDsp` vocal analysis/grain source and the cross-ChannelId `MusicKeyD `StereoPhaseSafeFold.h` now provides a **per-instance, callback-owned, constant-work** fold with precomputed 20ms polarity evidence and 15ms smoothed recovery, strict -0.78 engage / -0.55 release hysteresis, silence release, and stereo analysis-only polarity repair. Ordinary coherent stereo keeps the existing sum. Neither dry stereo, audio routing, FX rack, SPSC schema, 2–5 voices, output device, declared latency nor GUI changes. No heap, locks, timers or per-sample trigonometry. PCM regressions: anti-phase singer A3 and nonzero five-voice harmony at 48/96k; anti-phase music C major at 48/96k, silence/Manual fallback; real native other-ChannelId antiphase A-minor guide with read-only source samples, plus preexisting in-phase, rekey, block parity, PDC and state migration. This only prevents destructive analysis cancellation, it is *not* formant preservation or ASIO/ear latency certification. Physical singer FAT remains open. + +## 2026-11-09 P0/P1/P2 tone and CPU milestone — exact speaker-independent tests + +**P0 boundedness**: Preserve exactly the native two-grain shifter's 1536 samples of 48k lookback and its 32-lag-per-slice pitch work. Do not promise latency reduction, physical ASIO stability or true formant preservation without human singing and measured loopback; this commit instead ensures that deterministic pitch ratios and timbral control stay safe across devices. + +**P1 tone parity**: Extract `RateStableColor` (257 precomputed floats/instance). The original 48k one-pole coefficient `0.07 + color*0.77` is retained within float precision; at 32, 44.1, 96, 192k convert that same attenuation to its equivalent physical time. The smoothing envelope remains separate. Lookup/interpolation occurs only once per active processing sample and is shared across all active harmonies plus lead correction. Control-thread `prepare()` alone uses `std::pow`. Tests compare 10ms decay consistency across all five device rates and seven Color settings. + +**P2 realtime hot path**: Five extra `pow(2, semitones/12)` calls per pitch detection hop were replaced with a 49-entry immutable, off-callback prepared interval ratio table and one reference ratio exponent. Precomputed semitone intervals are combined by multiplication, with output clamp retained. Exhaustive deterministic test covers 12 keys, both scales, 71 degrees, five detunes and all five voice intervals (approximately 42,600 ratios). Maximum deviation from the former formula is below `1e-6` absolute in tests. No new state packets, allocations, locks, threads, routed audio, FX slot changes or GUI code. + +**Release gate**: This is source-level algorithmic hardening; the CI synthetic CPU profile is diagnostic only. Additional real voice/female/male formant comparisons and 64/128/256 ASIO buffer loopback/driver XRUN evidence remain mandatory. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 8b5743e85..742d36f3e 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -6,6 +6,7 @@ #include #include #include "HarmonyStereoFold.h" +#include "HarmonyPreparedTone.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -85,7 +86,8 @@ class Engine final { // Low-pass before downsampling: raw 12 kHz decimation aliases vocal sibilants // into the periodicity detector and destabilizes the live note readback. decimationLowpass_=0.f; - if(!vocalFold_.prepare(rate))return false; + if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate))return false; + pitchIntervals_.prepare(); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; @@ -219,9 +221,13 @@ class Engine final { const float dryL=tap(left_,static_cast(latency_)); const float dryR=tap(right_,static_cast(latency_)); voicedGain_+=((voiced_?1.f:0.f)-voicedGain_)*voicedGateAlpha_; + // Compute the device-rate-correct filter coefficient once per + // active sample, not once for each of up to six shifters. + const float filterCoef=voicedGain_>0.00001f? + toneColor_.coefficient(color_):0.f; float lead=0.f; if(correctionMix_>0.00001f&&voicedGain_>0.00001f) - lead=shifted(maxVoices,color_); + lead=shifted(maxVoices,filterCoef); const float leadBlend=correctionMix_*voicedGain_; float outL=(dryL*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); float outR=(dryR*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); @@ -229,7 +235,7 @@ class Engine final { for(int v=0;v(v); if(std::abs(mixL_[ix])+std::abs(mixR_[ix])<1.e-5f)continue; - const float y=shifted(v,color_)*voicedGain_; + const float y=shifted(v,filterCoef)*voicedGain_; outL+=y*mixL_[ix];outR+=y*mixR_[ix]; } } @@ -247,7 +253,7 @@ class Engine final { const auto a1=(a0+capacity-1)%capacity; return a[a0]*(1.f-f)+a[a1]*f; } - float shifted(int voice,float color) noexcept { + float shifted(int voice,float filterCoef) noexcept { float& currentRatio=ratio_[static_cast(voice)]; currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*ratioAlpha_; const float p=phase_[static_cast(voice)]; @@ -259,9 +265,8 @@ class Engine final { // reduced grain-edge modulation without sin/cos in audio callback. const float w=smoothGrainBlend(p); float y=w*tap(mono_,delayA)+(1.f-w)*tap(mono_,delayB); - const float coef=0.07f+color*0.77f; float& f=filtered_[static_cast(voice)]; - f+=coef*(y-f);y=f; + f+=filterCoef*(y-f);y=f; phase_[static_cast(voice)]+=1.f/static_cast(grain_); if(phase_[static_cast(voice)]>=1.f) phase_[static_cast(voice)]-=1.f; @@ -375,14 +380,18 @@ class Engine final { currentNote_=note;voiced_=true; // Fifth harmony voice is a lower sixth in key; keep each voice // independent and normalize its level against the total count. + // One fractional-pitch exponent per analysis hop; each harmony + // interval is an integer number of semitones in the chosen scale. + // Five previous pow() calls move to the CONTROL prepared LUT. + const float baseRatio=std::pow(2.f,(note-midi)/12.f); constexpr std::array intervals{{2,4,-2,6,-4}}; for(int v=0;v(v)], activeKey,activeScale); targetRatio_[static_cast(v)]=std::clamp( - std::pow(2.f,(target-midi)/12.f),0.50f,2.0f); + baseRatio*pitchIntervals_.ratio(target-note),0.50f,2.0f); } - targetRatio_[maxVoices]=std::clamp(std::pow(2.f,(note-midi)/12.f),0.75f,1.34f); + targetRatio_[maxVoices]=std::clamp(baseRatio,0.75f,1.34f); } double rate_=0.; int grain_=0,latency_=0,decimation_=4,detectEvery_=320; int lowLag_=12,highLag_=144;std::size_t write_=0,downWrite_=0,downSeen_=0; @@ -405,6 +414,8 @@ class Engine final { std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; float decimationLowpass_=0.f,decimationAlpha_=0.f; StereoPhaseSafeFold vocalFold_{}; + RateStableColor toneColor_{}; + PreparedPitchIntervals pitchIntervals_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyPreparedTone.h b/engine/builtin_fx/HarmonyPreparedTone.h new file mode 100644 index 000000000..ee1d78cd0 --- /dev/null +++ b/engine/builtin_fx/HarmonyPreparedTone.h @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Control-thread prepared Harmony timbre filter and equal-temperament +// interval ratios. No transcendental function or allocation on AUDIO. +namespace armix::harmony { +class RateStableColor final { +public: + static constexpr std::size_t segments=256; + // 48k is the previously approved Color response; all other rates + // preserve the same one-pole physical-time attenuation. + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + for(std::size_t i=0;i<=segments;++i){ + const double color=static_cast(i)/segments; + const double previous=.07+.77*color; + coefficients_[i]=static_cast( + 1.-std::pow(1.-previous,48000./rate)); + } + return true; + } + float coefficient(float color) const noexcept { + const float position=std::clamp(color,0.f,1.f)*segments; + const auto index=static_cast(position); + const auto next=std::min(index+1,segments); + const float fraction=position-static_cast(index); + const float current=coefficients_[index]; + return current+(coefficients_[next]-current)*fraction; + } +private: + std::array coefficients_{}; +}; +class PreparedPitchIntervals final { +public: + static constexpr int maximumSemitones=24; + void prepare() noexcept { + for(int delta=-maximumSemitones;delta<=maximumSemitones;++delta) + ratios_[static_cast(delta+maximumSemitones)]= + std::pow(2.f,static_cast(delta)/12.f); + } + // Caller guarantees scale-degree intervals remain inside +/-24. + // Clamping makes an unexpected new music scale safe rather than OOB. + float ratio(int semitones) const noexcept { + const int index=std::clamp(semitones,-maximumSemitones,maximumSemitones); + return ratios_[static_cast(index+maximumSemitones)]; + } +private: + std::array ratios_{}; +}; +} // namespace armix::harmony diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 953abbf21..074761544 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -298,6 +298,53 @@ int main(){ } need(harmonized>0.005,"opposed stereo produced no harmonized audio"); } + + // P1: the approved 48 kHz Color law must be preserved. At every other + // supported sample rate, equal physical time must imply equal one-pole + // attenuation; no pow/log calls can occur inside the audio callback. + for(double rate:{32000.,44100.,48000.,96000.,192000.}){ + RateStableColor table; + need(table.prepare(rate),"color filter prepare rejected supported rate"); + for(float color:{0.f,.08f,.25f,.5f,.75f,.91f,1.f}){ + const float actual=table.coefficient(color); + const float legacy=.07f+.77f*color; + need(std::isfinite(actual)&&actual>0.f&&actual<1.f, + "rate-adjusted Color coefficient invalid"); + if(rate==48000.) + need(std::abs(actual-legacy)<1.e-6f, + "48 kHz Color legacy response changed"); + const double oldDecay=std::pow(1.-static_cast(legacy),480.); + const double newDecay=std::pow(1.-static_cast(actual), + rate*.01); + need(std::abs(oldDecay-newDecay)<2.e-4, + "Color duration changes with the hardware sample rate"); + } + } + // P2: compare every supported key/scale/degree against the old per-voice + // pow(2,(targetMidi-observedMidi)/12) reference before accepting a LUT. + PreparedPitchIntervals intervals; + intervals.prepare(); + for(int key=0;key<12;++key) + for(int scale=0;scale<2;++scale) + for(int degree=-5;degree<=65;++degree){ + const int note=noteAt(degree,key,scale); + constexpr std::array offsets{{2,4,-2,6,-4}}; + for(float detune:{-.45f,-.17f,0.f,.23f,.49f}){ + const float midi=static_cast(note)+detune; + const float base=std::pow(2.f,(note-midi)/12.f); + for(const int offset:offsets){ + const int target=noteAt(degree+offset,key,scale); + need(std::abs(target-note)<=PreparedPitchIntervals::maximumSemitones, + "harmonic interval outside precomputed LUT"); + const float old=std::clamp(std::pow(2.f,(target-midi)/12.f), + 0.5f,2.f); + const float next=std::clamp(base*intervals.ratio(target-note), + 0.5f,2.f); + need(std::abs(old-next)<1.e-6f, + "precomputed harmony interval changed output pitch ratio"); + } + } + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; From b6e796891e6602d4d7d9b15a9e1c5bf8427c2914 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 14:06:09 +0700 Subject: [PATCH 004/125] test(harmony): tighten physical-time Color check and antiphase dry PCM/PDC invariance --- tests/harmony_dsp_test.cpp | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 074761544..6628babce 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -313,11 +313,14 @@ int main(){ if(rate==48000.) need(std::abs(actual-legacy)<1.e-6f, "48 kHz Color legacy response changed"); - const double oldDecay=std::pow(1.-static_cast(legacy),480.); + // 125 microseconds is six samples at 48k. A 10ms measurement + // would hide every wrong Color coefficient: these filters all + // decay to ~zero well before 10ms. + const double oldDecay=std::pow(1.-static_cast(legacy),6.); const double newDecay=std::pow(1.-static_cast(actual), - rate*.01); - need(std::abs(oldDecay-newDecay)<2.e-4, - "Color duration changes with the hardware sample rate"); + rate*.000125); + need(std::abs(oldDecay-newDecay)<1.e-4, + "Color attenuation changes at identical physical time"); } } // P2: compare every supported key/scale/degree against the old per-voice @@ -345,6 +348,36 @@ int main(){ } } } + // P0: rescued phase-opposed ANALYSIS must never modify DRY output. + // The player, direct hardware monitor and graph still own stereo polarity. + for(double rate:{48000.,192000.}){ + auto dry=std::make_unique(); + need(dry->prepare(rate),"dry antiphase sample-rate prepare failed"); + Settings silentRack;silentRack.wet=0.f;silentRack.correction=false; + need(dry->setSettings(silentRack),"dry antiphase packet failed"); + const int latency=dry->latencySamples(); + const int count=latency*3+217; + std::vector original(static_cast(count)); + std::vector left(static_cast(count)); + std::vector right(static_cast(count)); + for(int i=0;i( + .21*std::sin(6.283185307179586*140.*i/rate)+ + .06*std::sin(6.283185307179586*280.*i/rate)); + original[static_cast(i)]=x; + left[static_cast(i)]=x; + right[static_cast(i)]=-x; + } + for(int i=0;iprocess(left.data()+i,right.data()+i,std::min(127,count-i)); + for(int i=0;i(i-latency)]; + need(std::abs(left[static_cast(i)]-expected)<1.e-6f&& + std::abs(right[static_cast(i)]+expected)<1.e-6f, + "P0 polarity rescue corrupted dry stereo or exact PDC"); + } + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; From b83597bd26e7583c8dc135a9cc6ac2f8fdbcd43e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 14:42:59 +0700 Subject: [PATCH 005/125] perf(harmony): P0 eight-lag realtime slices, complete-window evidence and hostile-PCM safety --- docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md | 8 +++ engine/builtin_fx/HarmonyDsp.h | 25 +++++-- engine/builtin_fx/HarmonyStereoFold.h | 7 +- tests/harmony_dsp_test.cpp | 73 +++++++++++++++++++++ 4 files changed, 105 insertions(+), 8 deletions(-) diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index 36668b501..2f85007b7 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -87,3 +87,11 @@ PCM regressions: anti-phase singer A3 and nonzero five-voice harmony at 48/96k; **P2 realtime hot path**: Five extra `pow(2, semitones/12)` calls per pitch detection hop were replaced with a 49-entry immutable, off-callback prepared interval ratio table and one reference ratio exponent. Precomputed semitone intervals are combined by multiplication, with output clamp retained. Exhaustive deterministic test covers 12 keys, both scales, 71 degrees, five detunes and all five voice intervals (approximately 42,600 ratios). Maximum deviation from the former formula is below `1e-6` absolute in tests. No new state packets, allocations, locks, threads, routed audio, FX slot changes or GUI code. **Release gate**: This is source-level algorithmic hardening; the CI synthetic CPU profile is diagnostic only. Additional real voice/female/male formant comparisons and 64/128/256 ASIO buffer loopback/driver XRUN evidence remain mandatory. + +## 2026-11-09 P0 bounded-pitch work and hostile PCM follow-up + +**Actual source-level issue:** 32 candidate lags × 160 dot-product taps were still evaluated in a single callback sample, causing an avoidable periodic CPU spike even when the average synthetic CPU looked acceptable. Reducing the per-sample slice width without shortening cadence would cause silent abandoned pitch windows. This checkpoint changes BOTH: `maxPitchLagsPerSlice=8` and `pitchSliceEvery_=detectEvery_/32`. Total candidate-lag dot products and 48k grain/PCM/PDC are unchanged. Every snapshot finishes with headroom before the next analysis hop on all 32–192k supported sample rates, with separate completed/abandoned window counters for test-only diagnostics. + +**P0 hostile PCM fail-closed:** Native input guards now clip finite >4.0f amplitude before the internal dry/grain histories (the engine already clamps all output to +/-4.0f); NaN and infinity still become silence. `StereoPhaseSafeFold` returns the bounded fold it actually uses for correlation, instead of computing an unbounded sum after clipping evidence. This prevents a host supplying finite near-FLT_MAX PCM from poisoning Music Guide or vocal analysis with infinity. Ordinary valid PCM [-4,+4], channel polarity, dry PDC, Music Track read-only routing and GUI are untouched. + +**Qualification:** 5 sample rates (32/44.1/48/96/192k), 3 callback partitions (64/127/256 frames), deterministic A3 voiced note, complete correlation windows/no abandoned windows and <=8 candidate lags per slice; real 2/5-voice hostile IEEE PCM and direct near-FLT_MAX stereo guide. The existing 48k blockwise PCM parity, low bass/high soprano, 48/192k stereo dry and 1536-sample PDC regression remain active. Hardware ASIO and spectral/formant gate remain unverified; no claim of a completed P0 low-latency/formant engine. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 742d36f3e..0116b81ed 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -63,7 +63,7 @@ inline float smoothGrainBlend(float phase) noexcept { class Engine final { public: static constexpr int maxVoices=5; - static constexpr int maxPitchLagsPerSlice=32; // upper bound for each callback sample + static constexpr int maxPitchLagsPerSlice=8; // fewer burst MACs per sample // Maximum 192 kHz grain is 3072 frames: 2*grain latency + 3*grain // history = 15360, so 16384 frames retain the full rate/ratio budget. // Halves the three large audio rings per instance without RT allocation. @@ -75,7 +75,10 @@ class Engine final { latency_=2*grain_; decimation_=std::max(1,static_cast(std::round(rate/12000.))); detectEvery_=std::max(128,static_cast(rate/150.)); - pitchSliceEvery_=std::max(1,detectEvery_/8); + // 32 fixed time slices per analysis hop, but only 8 lags/slice. + // Even 32k input completes every supported 65-1200 Hz candidate + // before the next frozen PCM window. Distributes RT work on ASIO 64. + pitchSliceEvery_=std::max(1,detectEvery_/32); // Support bass through soprano fundamentals; keep Nyquist/finiteness guards. // Earlier 850 Hz cap failed to track high soprano notes (e.g. C6). lowLag_=std::max(8,static_cast(rate/(decimation_*1200.))); @@ -93,7 +96,8 @@ class Engine final { write_=0;downWrite_=0;downSeen_=0;downCounter_=0; detectCounter_=0;pitchSliceCounter_=0;pitchNextLag_=0; pitchActive_=false;pitchBest_=-1.f;pitchBestLag_=0; - peakPitchLagWork_=0;noteHold_=0;currentNote_=-1;candidateNote_=-1; + peakPitchLagWork_=0;completedPitchAnalyses_=0;abandonedPitchAnalyses_=0; + noteHold_=0;currentNote_=-1;candidateNote_=-1; guideKey_=-1;guideScale_=-1; voiced_=false;voicedGain_=0.f;settings_=Settings{}; smoothingAlpha_=static_cast(1.-std::exp(-1./(rate*0.005))); // 5 ms control ramp @@ -182,6 +186,9 @@ class Engine final { int observedMidiNote() const noexcept{return currentNote_;} bool voiced() const noexcept{return voiced_;} int peakPitchLagWork() const noexcept{return peakPitchLagWork_;} + // Audio-owner telemetry; standalone CTest reads after process() returns. + int completedPitchAnalyses() const noexcept{return completedPitchAnalyses_;} + int abandonedPitchAnalyses() const noexcept{return abandonedPitchAnalyses_;} void process(float* l,float* r,int frames) noexcept { if(!l||!r||frames<=0||rate_<=0.)return; processed_=true; @@ -198,8 +205,11 @@ class Engine final { mixL_[ix]+=a*(targetMixL_[ix]-mixL_[ix]); mixR_[ix]+=a*(targetMixR_[ix]-mixR_[ix]); } - const float inputL=std::isfinite(l[i])?l[i]:0.f; - const float inputR=std::isfinite(r[i])?r[i]:0.f; + // Bound pathological IEEE PCM before adding it to grain/dry + // histories; output is already limited to +/-4 in this engine. + // Regular [-4,+4] sample parity and stereo polarity are exact. + const float inputL=std::clamp(std::isfinite(l[i])?l[i]:0.f,-4.f,4.f); + const float inputR=std::clamp(std::isfinite(r[i])?r[i]:0.f,-4.f,4.f); const float mono=vocalFold_.process(inputL,inputR); left_[write_]=inputL;right_[write_]=inputR;mono_[write_]=mono; decimationLowpass_+=decimationAlpha_*(mono-decimationLowpass_); @@ -273,9 +283,10 @@ class Engine final { return y; } // Prepare one immutable, bounded pitch-analysis window every analysis hop. - // The subsequent 32-lag correlation slices cannot race PCM history writes: + // The subsequent 8-lag correlation slices cannot race PCM history writes: // they only read the frozen fixed-size pitchWindow_. void beginPitchAnalysis() noexcept { + if(pitchActive_)++abandonedPitchAnalyses_; pitchActive_=false; if(downSeen_(highLag_+170))return; constexpr int span=160; @@ -329,6 +340,7 @@ class Engine final { pitchNextLag_=endLag+1; if(pitchNextLag_>highLag_){ pitchActive_=false; + ++completedPitchAnalyses_; finishPitchAnalysis(); } } @@ -398,6 +410,7 @@ class Engine final { int downCounter_=0,detectCounter_=0; int pitchSliceEvery_=1,pitchSliceCounter_=0,pitchNextLag_=0; int pitchBestLag_=0,peakPitchLagWork_=0; + int completedPitchAnalyses_=0,abandonedPitchAnalyses_=0; bool pitchActive_=false; float pitchBest_=-1.f; double pitchEnergy_=0.,pitchLagEnergy_=0.; diff --git a/engine/builtin_fx/HarmonyStereoFold.h b/engine/builtin_fx/HarmonyStereoFold.h index fb91db8d0..8d6f4f854 100644 --- a/engine/builtin_fx/HarmonyStereoFold.h +++ b/engine/builtin_fx/HarmonyStereoFold.h @@ -36,9 +36,12 @@ class StereoPhaseSafeFold final { if(cross_>-.55f*power)antiCorrelated_=false; }else if(cross_<-.78f*power)antiCorrelated_=true; amount_+=blendAlpha_*((antiCorrelated_?1.f:0.f)-amount_); - // amount=0 -> original 0.5*(L+R); + // amount=0 -> original 0.5*(L+R) for ordinary audio. // amount=1 -> recovered 0.5*(L-R). - return .5f*(left+right)-amount_*right; + // Use bounded evidence samples for the return as well: finite + // but huge external float PCM would otherwise overflow L+R before + // pitch/Music Guide filtering. + return .5f*(l+r)-amount_*r; } float rescueAmount() const noexcept{return amount_;} private: diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 6628babce..1980fea13 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace armix::harmony; static void need(bool value,const char* why){if(!value){std::cerr<peakPitchLagWork()>0&& bounded->peakPitchLagWork()<=Engine::maxPitchLagsPerSlice, "P0 pitch analysis overran per-sample lag budget"); + need(bounded->completedPitchAnalyses()>100&& + bounded->abandonedPitchAnalyses()==0, + "P0 slices failed to finish before the next analysis hop"); need(bounded->voiced()&&bounded->observedMidiNote()==57, "P0 bounded singer tone detection failed"); if(referenceL.empty()){ @@ -378,6 +382,75 @@ int main(){ "P0 polarity rescue corrupted dry stereo or exact PDC"); } } + + // P0: all supported device rates and irregular ASIO-shaped periods must + // complete the full frozen correlation search WITHOUT dropped windows. + // This prevents a naive 32->8-lag reduction from silently truncating E2-C6. + for(const double rate:{32000.,44100.,48000.,96000.,192000.}){ + for(int block:{64,127,256}){ + auto sliced=std::make_unique(); + need(sliced->prepare(rate),"P0 multirate slice prepare failed"); + const int samples=static_cast(rate*.30); + std::vector l(static_cast(samples)); + std::vector r(static_cast(samples)); + for(int i=0;i( + .16*std::sin(6.283185307179586*220.*i/rate)+ + .04*std::sin(6.283185307179586*440.*i/rate)); + l[static_cast(i)]=value; + r[static_cast(i)]=value; + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(block,samples-i)); + need(sliced->peakPitchLagWork()<=8&& + sliced->peakPitchLagWork()>0, + "P0 worst-case lag slice exceeded eight"); + need(sliced->completedPitchAnalyses()>=20 && + sliced->abandonedPitchAnalyses()==0, + "P0 correlation hop overwritten on supported device"); + need(sliced->voiced() && sliced->observedMidiNote()==57, + "P0 sliced note lost in a supported rate/block configuration"); + } + } + // P0 defensive PCM: no allocation/crash/NaN from extreme finite, + // infinity or NaN, including during the silence->singer transition. + for(int voiceCount:{2,5}){ + auto overflow=std::make_unique(); + need(overflow->prepare(48000.),"P0 extreme PCM prepare failed"); + Settings full;full.wet=1.f;full.voices=voiceCount;full.correction=true; + need(overflow->setSettings(full),"P0 extreme PCM settings rejected"); + constexpr int frames=8192; + std::vector l(frames),r(frames); + for(int i=0;i::max(): + j==1?-std::numeric_limits::max(): + j==2?std::numeric_limits::infinity(): + j==3?-std::numeric_limits::infinity(): + j==4?std::numeric_limits::quiet_NaN(): + j==5?4.5f:j==6?-4.5f:0.f; + l[static_cast(i)]=raw; + r[static_cast(i)]=-raw; + } + for(int i=0;iprocess(l.data()+i,r.data()+i,std::min(64,frames-i)); + for(int i=0;i(i)]) && + std::isfinite(r[static_cast(i)]) && + std::abs(l[static_cast(i)])<=4.f && + std::abs(r[static_cast(i)])<=4.f, + "P0 extreme PCM yielded invalid or out-of-bounds output"); + } + // Direct analysis-only stereo fold must never produce NaN/inf even if a + // connected host provides a finite float close to FLT_MAX. + StereoPhaseSafeFold guard; + need(guard.prepare(48000.),"P0 stereo analysis fold prepare failed"); + for(int i=0;i<4096;++i){ + const float huge=std::numeric_limits::max(); + const float y=guard.process(huge,huge); + need(std::isfinite(y)&&std::abs(y)<=4.f, + "P0 guide PCM overflowed in stereo analysis fold"); + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; From bade0686a3bc3bb2de14c4018f1a6acb4ca62f95 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 16:21:24 +0700 Subject: [PATCH 006/125] fix(harmony): auto-rebind accepted FX and replay held user edits across graph/device changes --- .../preview-v2/assets/mixer-native-harmony.js | 140 ++++++++++++++---- 1 file changed, 113 insertions(+), 27 deletions(-) diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index 9800f90d4..49c9030a0 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -106,7 +106,7 @@ const backend=()=>window.__JUCE__?.backend; const state=()=>window.__ARMIX_NATIVE_M2__?.state?.()?.current; const demos=new Map(); let current=null,settings=fresh(),pending=null,latest=null,seq=0,readbackRequest=""; -let readbackSentAt=0; +let readbackSentAt=0,verified=false,heldPatch=null; let mode="DEMO",readbackLatency=0,observedNote=-1,preset="trio"; let detectedKey=-1,detectedScale=-1,detectedConfidence=0,lastGuideRead=0; let effectiveKey=-1,effectiveScale=-1,sourceSignature="",availableSources=[]; @@ -118,15 +118,75 @@ const sliders=sliderDefs.map(([key])=>({ key,input:root.querySelector('[data-field="'+key+'"]'), output:root.querySelector('[data-out="'+key+'"]') })); -const context=()=>{ +// The native accepted graph is the only authority, including after reopen. +// Track exact insert identity through a slot move; allow a successor at the +// former slot only on the SAME stable ChannelId. Never retarget another strip. +const acceptedLocation=()=>{ const n=state(); if(!current||!native()||!n?.admitted)return null; - const channel=n.graph?.channels?.find(ch=>ch.id===current.channelId); - const insert=channel?.inserts?.[current.slot]; - if(insert?.id!==current.instanceId||insert?.catalogId!==ID)return null; - return {channelId:current.channelId,deviceEpoch:n.device.epoch, - graphRevision:n.graph.revision,slot:current.slot,instanceId:current.instanceId}; + const id=current.channelId||window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const channel=n.graph?.channels?.find(ch=>ch.id===id),inserts=channel?.inserts; + if(!Array.isArray(inserts))return null; + let slot=current.instanceId? + inserts.findIndex(x=>x?.id===current.instanceId&&x.catalogId===ID):-1; + if(slot<0&&inserts[current.slot]?.catalogId===ID&&inserts[current.slot]?.id) + slot=current.slot; + if(slot<0)return null; + const insert=inserts[slot]; + if(!insert?.id||insert.catalogId!==ID)return null; + return {channelId:id,deviceEpoch:n.device.epoch, + graphRevision:n.graph.revision,slot,instanceId:insert.id}; +}; +const context=()=>{ + const c=acceptedLocation(); + if(!c||!current||c.channelId!==current.channelId|| + c.instanceId!==current.instanceId||c.slot!==current.slot|| + c.deviceEpoch!==current.boundEpoch|| + c.graphRevision!==current.boundRevision)return null; + return c; }; +// Carry only actually edited fields; never push stale full plugin presets +// into a freshly created instance after a device/graph transition. +function holdUnfinishedEdit(){ + const desired=latest||pending?.settings; + if(!desired)return; + const diff={}; + for(const key of Object.keys(settings)) + if(desired[key]!==settings[key])diff[key]=desired[key]; + heldPatch={...diff,...(heldPatch||{})}; +} +function reconcileBinding(){ + if(!native()||!current)return false; + const c=acceptedLocation(); + if(!c){ + if(verified||pending||readbackRequest){ + holdUnfinishedEdit();verified=false;pending=null;latest=null; + readbackRequest="";effectiveKey=-1;effectiveScale=-1; + hint("HARMONY RECONNECTING · WAITING FOR ACCEPTED FX");paint(); + } + return false; + } + const changed=current.channelId!==c.channelId|| + current.instanceId!==c.instanceId||current.slot!==c.slot|| + current.boundEpoch!==c.deviceEpoch|| + current.boundRevision!==c.graphRevision; + if(changed){ + holdUnfinishedEdit(); + current.channelId=c.channelId;current.instanceId=c.instanceId; + current.slot=c.slot;current.boundEpoch=c.deviceEpoch; + current.boundRevision=c.graphRevision; + pending=null;latest=null;verified=false; + readbackRequest="";readbackSentAt=0; + effectiveKey=-1;effectiveScale=-1; + detectedKey=-1;detectedScale=-1;detectedConfidence=0; + showText(el("mxHChannel"),current.track.name+" · FX "+(c.slot+1)); + hint("HARMONY CONNECTED · READING DSP"); + refreshGuideSources();paint();snapshot(true); + }else if(!verified&&(!readbackRequest||Date.now()-readbackSentAt>2500)){ + snapshot(true); + } + return true; +} const hint=t=>showText(el("mxHStatus"),t); const valid=s=>s&&Number.isInteger(s.key)&&s.key>=0&&s.key<12&& Number.isInteger(s.scale)&&s.scale>=0&&s.scale<=1&& @@ -176,7 +236,8 @@ function syncPower(){ power.setAttribute("aria-label",power.title); } function paint(){ - const v=latest||pending?.settings||settings; + const v=latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:settings); const auto=v.guideMode===1; // Native LCD never guesses from music confidence or pending UI edits. // One atomic native readback is the actual effective DSP key+scale pair. @@ -246,7 +307,7 @@ function snapshot(force=false){ } function send(next){ const c=context(); - if(!c){hint("NATIVE INSTANCE CHANGED · REOPEN FX");return;} + if(!c||!verified){hint("HARMONY RECONNECTING · EDIT HELD");return;} if(pending){latest=next;hint("DSP APPLYING · LATEST EDIT HELD");paint();return;} const id="harm-"+String(Date.now()*1000+(seq++%1000)); pending={id,settings:next,ack:false,context:c,startedAt:Date.now()}; @@ -255,15 +316,20 @@ function send(next){ hint("DSP QUEUED · AWAITING AUDIO ACK");paint(); } function edit(patch){ - const next={...(latest||pending?.settings||settings),...patch}; + const next={...(latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:settings)),...patch}; if(!valid(next))return; preset="custom"; if(!native()){ settings=next; demos.set(current?.track?.id+":"+current?.slot,{...settings}); hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else if(mode==="NATIVE")send(next); - else hint("NATIVE HARMONY NOT ACCEPTED"); + }else if(mode==="NATIVE"){ + if(!reconcileBinding()||!verified){ + heldPatch={...(heldPatch||{}),...patch}; + hint("HARMONY RECONNECTING · EDIT SAVED"); + }else send(next); + }else hint("NATIVE HARMONY NOT ACCEPTED"); paint(); } noteButtons.forEach(b=>b.addEventListener("click",()=> @@ -296,7 +362,12 @@ el("mxHPreset").addEventListener("change",e=>{ const next={...(latest||pending?.settings||settings),...change}; if(!native()){settings=next;demos.set(current?.track?.id+":"+current?.slot,{...next}); hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else if(mode==="NATIVE")send(next); + }else if(mode==="NATIVE"){ + if(!reconcileBinding()||!verified){ + heldPatch={...(heldPatch||{}),...change}; + hint("HARMONY RECONNECTING · PRESET SAVED"); + }else send(next); + } }paint(); }); el("mxHPower").addEventListener("click",()=>{ @@ -331,20 +402,25 @@ window.ArSonMixNativeHarmony=Object.freeze({ id:ID, insert(target){return Boolean(window.__ARMIX_NATIVE_M2__?.insertPlugin?.(ID,target));}, open(track,slot){ - pending=null;latest=null;seq++;observedNote=-1;readbackLatency=0; + pending=null;latest=null;heldPatch=null;verified=false; + seq++;observedNote=-1;readbackLatency=0; readbackRequest="";readbackSentAt=0; detectedKey=-1;detectedScale=-1;detectedConfidence=0;lastGuideRead=0; effectiveKey=-1;effectiveScale=-1;sourceSignature="";availableSources=[]; const n=state(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(track); const ch=n?.graph?.channels?.find(x=>x.id===id),insert=ch?.inserts?.[slot]; - current={track,slot,channelId:null,instanceId:null}; - if(native()&&n?.admitted&&insert?.catalogId===ID&&insert.id){ - current.channelId=id;current.instanceId=insert.id;mode="NATIVE"; - settings=fresh();hint("NATIVE · READING ACCEPTED DSP");snapshot(); - }else if(!native()){ + current={track,slot,channelId:id,instanceId:null, + boundEpoch:null,boundRevision:null}; + if(native()){ + mode="NATIVE";settings=fresh(); + hint("HARMONY · LOCATING ACCEPTED DSP"); + if(n?.admitted&&insert?.catalogId===ID&&insert.id) + current.instanceId=insert.id; + reconcileBinding(); + }else{ mode="DEMO";settings={...(demos.get(track.id+":"+slot)||fresh())}; hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); - }else{mode="UNAVAILABLE";settings=fresh();hint("NATIVE HARMONY SLOT NOT ACCEPTED");} + } el("mxHChannel").textContent=track.name+" · FX "+(slot+1); root.hidden=false;refreshGuideSources();paint(); }, @@ -380,7 +456,7 @@ backend()?.addEventListener?.("arMixBuiltinHarmonySnapshot",snap=>{ if(pending.ack)hint("DSP APPLIED · WAITING READBACK"); return; } - settings={...snap.settings}; + settings={...snap.settings};verified=true; effectiveKey=snap.effectiveKey;effectiveScale=snap.effectiveScale; detectedKey=Number.isInteger(snap.guideDetectedKey)?snap.guideDetectedKey:-1; detectedScale=Number.isInteger(snap.guideDetectedScale)?snap.guideDetectedScale:-1; @@ -388,18 +464,28 @@ backend()?.addEventListener?.("arMixBuiltinHarmonySnapshot",snap=>{ observedNote=Number.isInteger(snap.observedNote)?snap.observedNote:-1; readbackLatency=Number.isInteger(snap.latencySamples)?snap.latencySamples:0; pending=null; + refreshGuideSources(); if(latest){const next=latest;latest=null;send(next);} - else hint(settings.guideMode===1?"NATIVE · LIVE MUSIC GUIDE":"NATIVE DSP ACCEPTED · "+c.instanceId); - refreshGuideSources();paint(); + else if(heldPatch){ + const patch=heldPatch;heldPatch=null; + const next={...settings,...patch}; + if(next.guideMode===1&& + !availableSources.some(ch=>ch.id===next.guideChannelId)){ + next.guideMode=0;next.guideChannelId="0"; + } + if(valid(next))send(next); + else hint("HARMONY RESTORED · INVALID EDIT DISCARDED"); + }else hint(settings.guideMode===1?"NATIVE · LIVE MUSIC GUIDE":"NATIVE DSP ACCEPTED · "+c.instanceId); + paint(); }); backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ if(root.hidden||!native()||!current?.instanceId)return; queueMicrotask(()=>{ - if(!context()){ - pending=null;latest=null;effectiveKey=-1;effectiveScale=-1; - readbackRequest=""; - hint("DEVICE / GRAPH CHANGED · REOPEN ACCEPTED FX");paint();return; + if(!reconcileBinding()){ + hint("HARMONY RECONNECTING · WAITING FOR ACCEPTED FX"); + return; } + if(!verified)return; syncPower(); const now=Date.now(); if(pending){ From 1637a8b965101c8e1ca8f13c9d6ea290a802921c Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 16:22:59 +0700 Subject: [PATCH 007/125] test(harmony): exercise live graph revision, recreated DSP, slot move and lost/recovered FX without reopen --- tests/approved_native_harmony_smoke.py | 111 ++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index 32aeb3249..2f97f8589 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -25,11 +25,11 @@ def last_action(page,kind): return actions[-1] def readback(page,state,values,key,scale,detected=(-1,-1),applied=None, - request=None): + request=None,instance=INSTANCE): action=request or last_action(page,"nativeHarmonySnapshot") packet={ "requestId":action["requestId"], - "channelId":SOURCE,"instanceId":INSTANCE,"status":"ACCEPTED", + "channelId":SOURCE,"instanceId":instance,"status":"ACCEPTED", "deviceEpoch":state["device"]["epoch"], "graphRevision":state["graph"]["revision"], "schemaVersion":2,"sampleRate":48000,"latencySamples":1536, @@ -296,6 +296,113 @@ def face_metrics(locator): readback(page,state,selected,9,1,detected=(9,1), request=old_poll) assert page.locator("#mxHKeyReadout").inner_text()=="G" + # Reproduce the field screenshot: singer DSP continues playing + # while a native device/graph revision changes under an open + # Harmony editor. It MUST auto-rebind; no user reopen/wizard. + if width==1366: + accepted={**changed,"voices":5} + def push_graph(): + state["mixerSession"]["channels"]=copy.deepcopy( + state["graph"]["channels"]) + emit(page,"arMixConsoleSnapshot",state) + def bump(): + graph=state["graph"] + graph["revision"]=str(int(graph["revision"])+1) + def await_snap(instance,slot): + page.wait_for_function("""arg=>window.__actions.some(x=> + x.action==='nativeHarmonySnapshot' && + x.graphRevision===arg.revision && + x.instanceId===arg.instance && x.slot===arg.slot)""", + {"revision":state["graph"]["revision"], + "instance":instance,"slot":slot}) + result=last_action(page,"nativeHarmonySnapshot") + assert result["instanceId"]==instance,result + assert result["slot"]==slot,result + bump();push_graph() + await_snap(INSTANCE,0) + assert "REOPEN" not in page.locator("#mxHStatus").inner_text() + readback(page,state,accepted,7,0) + page.locator('[data-voices="4"]').click() + write=last_action(page,"nativeHarmonySetSettings") + assert write["graphRevision"]==state["graph"]["revision"] + accepted={**accepted,"voices":4} + apply_edit(page,state,accepted,7,0) + + # Recreated *same-channel* FX instance; stale ACKs cannot + # commit controls or paint a previous DSP identity. + successor="harmony-native-recreated" + bump() + state["graph"]["channels"][0]["inserts"][0]["id"]=successor + push_graph() + await_snap(successor,0) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":write["requestId"],"status":"APPLIED"}) + readback(page,state,DEFAULT,0,0,instance=successor) + assert page.locator("#mxHKeyReadout").inner_text()=="C" + page.locator('[data-key="9"]').click() + new_write=last_action(page,"nativeHarmonySetSettings") + assert new_write["instanceId"]==successor + assert new_write["channelId"]==SOURCE + assert new_write["settings"]["key"]==9 + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":new_write["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":new_write["requestId"],"status":"APPLIED"}) + accepted={**DEFAULT,"key":9} + readback(page,state,accepted,9,0, + applied=new_write["requestId"],instance=successor) + assert page.locator("#mxHKeyReadout").inner_text()=="A" + + # Exact same insert identity follows an FX reorder, and + # subsequent edits use NEW accepted slot (not old index). + bump() + other={"id":"eq-accepted-other","catalogId": + "armix.builtin.channel-eq.v1","name":"EQ", + "bypassed":False} + harmony=copy.deepcopy(state["graph"]["channels"][0]["inserts"][0]) + state["graph"]["channels"][0]["inserts"]=[other,harmony] + push_graph() + await_snap(successor,1) + readback(page,state,accepted,9,0,instance=successor) + page.locator('[data-voices="5"]').click() + moving=last_action(page,"nativeHarmonySetSettings") + assert moving["slot"]==1 and moving["instanceId"]==successor + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":moving["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":moving["requestId"],"status":"APPLIED"}) + accepted={**accepted,"voices":5} + readback(page,state,accepted,9,0, + applied=moving["requestId"],instance=successor) + + # A temporarily unpublished FX must NOT accept stale + # gestures. Hold the latest edit and apply only after + # a fresh accepted instance-scoped DSP readback. + bump();state["graph"]["channels"][0]["inserts"]=[other] + push_graph() + page.wait_for_function("""()=>document.querySelector( + '#mxHStatus').textContent.includes('RECONNECTING')""") + before=len(page.evaluate("""()=>window.__actions.filter( + x=>x.action==='nativeHarmonySetSettings')""")) + page.locator('[data-voices="3"]').click() + after=len(page.evaluate("""()=>window.__actions.filter( + x=>x.action==='nativeHarmonySetSettings')""")) + assert before==after,"stale FX received an edit" + bump();state["graph"]["channels"][0]["inserts"]=[other,harmony] + push_graph();await_snap(successor,1) + readback(page,state,accepted,9,0,instance=successor) + resumed=last_action(page,"nativeHarmonySetSettings") + assert resumed["slot"]==1 and resumed["instanceId"]==successor + assert resumed["settings"]["voices"]==3,resumed + emit(page,"arMixBuiltinHarmonyQueue", + {"requestId":resumed["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":resumed["requestId"],"status":"APPLIED"}) + accepted={**accepted,"voices":3} + readback(page,state,accepted,9,0, + applied=resumed["requestId"],instance=successor) + assert page.locator('#mxHStatus').inner_text().startswith("NATIVE") + assert "FX 2" in page.locator("#mxHChannel").inner_text() assert not errors,errors rect=editor.bounding_box() assert rect and rect["width"]<=width+1,(width,rect) From 44ff9e2d118c2ab96c02b0c3d79fa9b7c6bf7ce5 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 16:23:22 +0700 Subject: [PATCH 008/125] test(harmony): use Playwright keyword-only wait_for_function arg --- tests/approved_native_harmony_smoke.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index 2f97f8589..aafc277f1 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -313,8 +313,8 @@ def await_snap(instance,slot): x.action==='nativeHarmonySnapshot' && x.graphRevision===arg.revision && x.instanceId===arg.instance && x.slot===arg.slot)""", - {"revision":state["graph"]["revision"], - "instance":instance,"slot":slot}) + arg={"revision":state["graph"]["revision"], + "instance":instance,"slot":slot}) result=last_action(page,"nativeHarmonySnapshot") assert result["instanceId"]==instance,result assert result["slot"]==slot,result From b9fd483b3666566d57d7cfd78914513f1e822f77 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 16:24:41 +0700 Subject: [PATCH 009/125] test(harmony): enforce accepted-graph auto-rebind without outdated static open-gate assertion --- tests/native_harmony_assembly_test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/native_harmony_assembly_test.py b/tests/native_harmony_assembly_test.py index e262f1103..a0776ec2a 100644 --- a/tests/native_harmony_assembly_test.py +++ b/tests/native_harmony_assembly_test.py @@ -154,7 +154,12 @@ def test_reference_inspired_wide_harmony_and_exact_shared_fx_chrome(self): def test_no_fabricated_native_pcm(self): self.assertIn("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO",self.ui) self.assertIn("if(!native())",self.ui) - self.assertIn("if(native()&&n?.admitted",self.ui) + # Accepted ChannelId/instance binding is re-established on the + # current graph, not permanently pinned to the editor's open tick. + self.assertIn("if(!current||!native()||!n?.admitted)return null;",self.ui) + self.assertIn("if(n?.admitted&&insert?.catalogId===ID&&insert.id)",self.ui) + self.assertIn("function reconcileBinding(){",self.ui) + self.assertNotIn("REOPEN ACCEPTED FX",self.ui) self.assertIn("Native Harmony host not ready · audio unchanged",self.html) with self.assertRaises(ValueError): apply_native_peq(self.html) From 770f3908e28dabb250dfb0a687e573b7869dfa51 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 16:26:34 +0700 Subject: [PATCH 010/125] fix(harmony): recover initial unadmitted FX and preserve slot label after automatic rebind --- site/preview-v2/assets/mixer-native-harmony.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index 49c9030a0..6978f826e 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -411,6 +411,7 @@ window.ArSonMixNativeHarmony=Object.freeze({ const ch=n?.graph?.channels?.find(x=>x.id===id),insert=ch?.inserts?.[slot]; current={track,slot,channelId:id,instanceId:null, boundEpoch:null,boundRevision:null}; + showText(el("mxHChannel"),track.name+" · FX "+(slot+1)); if(native()){ mode="NATIVE";settings=fresh(); hint("HARMONY · LOCATING ACCEPTED DSP"); @@ -421,7 +422,6 @@ window.ArSonMixNativeHarmony=Object.freeze({ mode="DEMO";settings={...(demos.get(track.id+":"+slot)||fresh())}; hint("BROWSER PREVIEW · VISUAL ONLY · NO AUDIO"); } - el("mxHChannel").textContent=track.name+" · FX "+(slot+1); root.hidden=false;refreshGuideSources();paint(); }, close(){root.hidden=true;} @@ -479,7 +479,7 @@ backend()?.addEventListener?.("arMixBuiltinHarmonySnapshot",snap=>{ paint(); }); backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ - if(root.hidden||!native()||!current?.instanceId)return; + if(root.hidden||!native()||!current)return; queueMicrotask(()=>{ if(!reconcileBinding()){ hint("HARMONY RECONNECTING · WAITING FOR ACCEPTED FX"); From a1a3bc57485cec59ad63a57e6eb09c5ad3ce5310 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:02:45 +0700 Subject: [PATCH 011/125] fix(startup): admit real silent ChannelId mixer with zero hardware inputs Output-only DIRECT fences and callback mask validation now permit zero capture without inventing input pins. A verified SOURCE NONE startup publishes the same authoritative native PCM graph used for FX, track and WIRE editing. Preserve output muting and driver identity, add zero-capture regression cases. --- engine/device/DirectRouteFence.h | 11 ++++++---- engine/device/JuceActivePortSnapshot.h | 5 ++--- src/LiveAudioEngine.h | 28 +++++++++++++++++++----- src/LiveDryRoutingLab.h | 13 ++++++----- src/NativeMixerSessionDocument.h | 5 +++-- tests/direct_route_fence_test.cpp | 7 +++++- tests/juce_active_port_snapshot_test.cpp | 11 +++++++--- web/approved-native-bridge.js | 6 ++--- 8 files changed, 59 insertions(+), 27 deletions(-) diff --git a/engine/device/DirectRouteFence.h b/engine/device/DirectRouteFence.h index 8647f3e6d..02fbca3a0 100644 --- a/engine/device/DirectRouteFence.h +++ b/engine/device/DirectRouteFence.h @@ -92,8 +92,10 @@ class DirectRouteFence final std::string_view inputMask, std::string_view outputMask) noexcept { - if (type.empty() || device.empty() || !validMask(inputMask) - || !validMask(outputMask)) return 0; + // Zero capture pins are permitted ONLY for the input side of an + // output-only session. The playback mask must identify real pins. + if (type.empty() || device.empty() || !validMask(inputMask,true) + || !validMask(outputMask,false)) return 0; std::uint64_t hash=14695981039346656037ull; append(hash, type); append(hash, device); @@ -102,9 +104,10 @@ class DirectRouteFence final return hash ? hash : 1; // reserve zero for never-approved } private: - static bool validMask(std::string_view mask) noexcept + static bool validMask(std::string_view mask,bool allowZero) noexcept { - if (mask.empty() || mask.front() == '0') return false; + if (mask.empty() || (mask.front() == '0' && + !(allowZero && mask.size() == 1))) return false; for (const unsigned char c : mask) if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'))) return false; diff --git a/engine/device/JuceActivePortSnapshot.h b/engine/device/JuceActivePortSnapshot.h index 359ea9d96..feb8c1745 100644 --- a/engine/device/JuceActivePortSnapshot.h +++ b/engine/device/JuceActivePortSnapshot.h @@ -26,8 +26,8 @@ struct JuceActivePortSnapshot final { std::uint64_t epoch=0; juce::String deviceName, typeName; - // Accept a frozen copy of masks so unit tests can exercise sparse - // numbering without requiring an ASIO device. This executes off RT. + // Accept a frozen copy of masks to exercise sparse numbering and real + // output-only devices with zero capture pins. No fake input is created. static bool fromMasks(std::uint64_t epoch, const juce::BigInteger& inputMask, const juce::BigInteger& outputMask, @@ -46,7 +46,6 @@ struct JuceActivePortSnapshot final { if(p>=limit || out>=limit){error=Fault::tooManyOutputs;return false;} outputIndices[out++]=p; } - if(in==0){error=Fault::emptyInput;return false;} if(out==0){error=Fault::emptyOutput;return false;} JuceActivePortSnapshot candidate; LiveInputPortRegistry::Fault inputFault{}; diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index ae280f64d..3ff55dfc6 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -210,6 +210,19 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback + " | Windows Audio fallback unavailable"; } #endif + // On first installation only, an output-only endpoint is a valid + // playback/Player host. Never replace a saved explicit ASIO route. + // Physical output is still muted and DIRECT-fenced until verified. + if(error.isNotEmpty() && !savedRoute) { + const auto outputError=deviceManager_.initialise(0,2,nullptr,true); + const auto* candidate=deviceManager_.getCurrentAudioDevice(); + if(outputError.isEmpty() && candidate && + candidate->getActiveOutputChannels().countNumberOfSetBits()>=2) { + startupFallbackReason_="AUTO_OUTPUT_ONLY_NO_CAPTURE"; + error.clear(); + } else if(outputError.isNotEmpty()) + error+=" | Output-only startup: "+outputError; + } if (error.isNotEmpty()) return error; const auto* active = deviceManager_.getCurrentAudioDevice(); if (active == nullptr) @@ -1131,6 +1144,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback formats_,device->getCurrentSampleRate(), juce::jmax(32,device->getCurrentBufferSizeSamples())); if(error.isEmpty() && dryRoutingLab_.epoch()==epoch) { + // The real SOURCE NONE graph is editable before any hardware IN + // patch; one ChannelId publisher remains the PCM authority. + if(!dryRoutingLab_.admitChannelIdFromAcceptedM4( + graphOwned_->count, + juce::jmax(32,device->getCurrentBufferSizeSamples()), + allOutputsDisarmed(),currentOriginalCh1Lease())) + return "Prepared silent mixer could not admit native ChannelId graph"; acceptedMixerBinding_=readMixerBinding(*device); acceptedWasapiBinding_=std::move(profile); } @@ -2321,7 +2341,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const auto rate=device->getCurrentSampleRate(); const auto frames=device->getCurrentBufferSizeSamples(); if(inputs!=setup.inputChannels || outputs!=setup.outputChannels || - inputs.isZero() || outputs.countNumberOfSetBits()<2 || + outputs.countNumberOfSetBits()<2 || !std::isfinite(rate) || rate<8000.0 || rate!=setup.sampleRate || frames<16 || frames>LiveDryRoutingLab::Block::hardFrameLimit || frames!=setup.bufferSize)return {}; @@ -2377,8 +2397,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const armix::device::AsioRegistrationPolicy::Identity* expectedAsio = nullptr) { auto* device=deviceManager_.getCurrentAudioDevice(); - if (device == nullptr || device->getActiveInputChannels().isZero() - || device->getActiveOutputChannels().isZero()) + if (device == nullptr || device->getActiveOutputChannels().isZero()) return false; // JUCE BigInteger has no fixed 64-bit channel limit: preserve all // channel bits when locking an explicitly approved ASIO/WASAPI route. @@ -2420,8 +2439,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback bool resumeVerifiedDirectRoute() { auto* device=deviceManager_.getCurrentAudioDevice(); - if (device == nullptr || device->getActiveInputChannels().isZero() - || device->getActiveOutputChannels().isZero()) + if (device == nullptr || device->getActiveOutputChannels().isZero()) return false; const auto backend=device->getTypeName(); const auto name=device->getName(); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 5a0a6ac62..c5730245e 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -94,7 +94,7 @@ class LiveDryRoutingLab final { device,generation,snapshot,reason))return; const int inputs=snapshot.inputs.enabledCount; const int outputs=snapshot.outputCount; - if(inputs<=0 || outputs<2) return; // stereo monitoring LAB only + if(inputs<0 || outputs<2) return; // output-only is a real SILENT native session for(int i=0;isetProperty("channels",juce::var(channels)); const FxSelections none{}; - // Same publisher/graph as a real user APPLY, but no authorization. - // Never briefly advertise a synthetic route as LIVE. + // Genuine accepted SOURCE NONE topology: editing does not require + // microphone capture. Sound remains zero and unarmed until a verified + // source and independently authorized physical output exist. return apply(juce::var(request.release()),directPermitted, independentClock,loadedFx,none,formats, - sampleRate,deviceFrames,false); + sampleRate,deviceFrames,true); } juce::String apply (const juce::var& command, bool directPermitted, @@ -220,7 +221,7 @@ class LiveDryRoutingLab final { if(topologyFault_.load(std::memory_order_acquire)) return "Device callback channel layout changed; reopen AUDIO SETUP before applying"; const int countNow=portCount_.load(std::memory_order_acquire); - if(countNow<=0 || countNow>armix::device::LiveInputPortRegistry::limit) + if(countNow<0 || countNow>armix::device::LiveInputPortRegistry::limit) return "Invalid active device input channel mask"; std::array physicalPorts{}; for(int i=0;iarmix::device::LiveInputPortRegistry::limit) + if(inputs<0||inputs>armix::device::LiveInputPortRegistry::limit) return false; std::array ports{}; for(int i=0;i256 || - live.backend.isEmpty() || live.capture.isEmpty() || + if(!outputs.valid() || callbackInputs<0 || callbackInputs>256 || + live.backend.isEmpty() || + (callbackInputs>0 && live.capture.isEmpty()) || live.playback.isEmpty() || live.inputMask.isEmpty() || live.outputMask.isEmpty() || !std::isfinite(live.rate) || live.rate<8000. || live.rate>384000. || diff --git a/tests/direct_route_fence_test.cpp b/tests/direct_route_fence_test.cpp index afb0fbeb6..f78d4b3d8 100644 --- a/tests/direct_route_fence_test.cpp +++ b/tests/direct_route_fence_test.cpp @@ -12,7 +12,12 @@ int main() check(f.fault() == F::awaitingApproval); check(!f.observeStart("ASIO", "Live USB", "3", "3")); check(!f.approve("ASIO", "", "3", "3")); - check(!f.approve("ASIO", "Live USB", "0", "3")); + // Explicit output-only setup keeps a real zero capture mask, not fake IN. + check(f.approve("ASIO", "Live USB", "0", "3")); + check(f.observeStart("ASIO", "Live USB", "0", "3")); + check(!f.observeStart("ASIO", "Live USB", "0", "0")); + f.suspend(); + check(!f.approve("ASIO", "Live USB", "0", "0")); check(!f.approve("ASIO", "Live USB", "3", "")); check(!f.approve("ASIO", "Live USB", "03", "3")); check(!f.approve("ASIO", "Live USB", "G", "3")); diff --git a/tests/juce_active_port_snapshot_test.cpp b/tests/juce_active_port_snapshot_test.cpp index b4e76b976..e1652fc39 100644 --- a/tests/juce_active_port_snapshot_test.cpp +++ b/tests/juce_active_port_snapshot_test.cpp @@ -40,9 +40,14 @@ int main(){ out.clear(); assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); - in.clear(); - assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); - assert(fault==JuceActivePortSnapshot::Fault::emptyInput); + in.clear();out.setBit(1);out.setBit(7); + assert(JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(snap.inputs.enabledCount==0); + assert(snap.matchesCallback(12,0,2)); + assert(!snap.matchesCallback(12,1,2)); + out.clear(); + assert(!JuceActivePortSnapshot::fromMasks(13,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); assert(snap.inputs.callbackIndex(9)==previous.inputs.callbackIndex(9)); assert(!JuceActivePortSnapshot::capture(nullptr,12,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::nullDevice); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index b202f8c60..41f8f3129 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1462,7 +1462,7 @@ hardware.device.epoch!=="0" && hardware.device.sampleRate>0 && hardware.device.bufferFrames>0 && Array.isArray(hardware.device.enabledInputs) && - hardware.device.enabledInputs.length>0 && + // Physical IN is optional; SOURCE NONE and FX/WIRE are native edits. Array.isArray(hardware.device.enabledOutputs) && hardware.device.enabledOutputs.length>=2 && (mixerSession()?.authority==="CHANNEL_ID" @@ -1513,7 +1513,7 @@ !deviceOpen?"NO VERIFIED AUDIO DEVICE": d.outputArmed?(next.admitted?"NATIVE PCM · HARDWARE FAT PENDING": "MAIN MONITOR ON · PCM ADMISSION NOT VERIFIED"): - !d.enabledInputs?.length?"NO CAPTURE INPUT · OPEN AUDIO I/O": + !d.enabledInputs?.length?"NO HARDWARE IN · MIXER/FX READY · USE PLAYER OR AUDIO I/O": legacy()?.routeAccepted?"NATIVE INPUT ROUTED · MONITOR OFF": deviceReady()?"SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK": "NO VERIFIED INPUT ROUTE · OPEN AUDIO I/O"; @@ -2211,7 +2211,7 @@ deviceReady()? "NATIVE G0 · verified physical IN ready · select a channel input": hardware?.device?.enabledInputs?.length===0? - "NO CAPTURE PINS · Audio I/O: enable an actual hardware input": + "NO HARDWARE IN · FX/BUS/WIRE REMAIN AVAILABLE": "NATIVE G0 NOT READY · open Audio I/O and verify device / native route"); return; } From fda9ef50e54e274fb798095bdd485c24f4f3ab3f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:06:17 +0700 Subject: [PATCH 012/125] fix(native): preserve unpatched M4 contract, safely admit silent starter, persist 0-input sessions Only a verified ten-channel SOURCE NONE starter may enter native ChannelId without physical capture. Keep M4 fail-silent until admission, retain exact device fence and enable portable .smix roundtrip with zero capture. Extend tests. --- src/LiveAudioEngine.h | 2 +- src/LiveDryRoutingLab.h | 24 ++++++++++++++++------- src/NativeMixerSessionDocument.h | 10 +++++++--- tests/juce_active_port_snapshot_test.cpp | 2 +- tests/native_mixer_session_store_test.cpp | 15 ++++++++++++++ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 3ff55dfc6..c6f267d56 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1149,7 +1149,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback if(!dryRoutingLab_.admitChannelIdFromAcceptedM4( graphOwned_->count, juce::jmax(32,device->getCurrentBufferSizeSamples()), - allOutputsDisarmed(),currentOriginalCh1Lease())) + allOutputsDisarmed(),currentOriginalCh1Lease(),true)) return "Prepared silent mixer could not admit native ChannelId graph"; acceptedMixerBinding_=readMixerBinding(*device); acceptedWasapiBinding_=std::move(profile); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index c5730245e..49c77cd75 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -174,12 +174,11 @@ class LiveDryRoutingLab final { } request->setProperty("channels",juce::var(channels)); const FxSelections none{}; - // Genuine accepted SOURCE NONE topology: editing does not require - // microphone capture. Sound remains zero and unarmed until a verified - // source and independently authorized physical output exist. + // Keep M4's historical unpatched/fail-silent behavior. Startup + // explicitly promotes this same genuine SOURCE NONE graph to PCM. return apply(juce::var(request.release()),directPermitted, independentClock,loadedFx,none,formats, - sampleRate,deviceFrames,true); + sampleRate,deviceFrames,false); } juce::String apply (const juce::var& command, bool directPermitted, @@ -1153,7 +1152,8 @@ class LiveDryRoutingLab final { // The published ChannelId snapshot retains this owner until RT retires. bool admitChannelIdFromAcceptedM4(int occupiedExternalCh1Fx, int deviceFrames,bool outputsDisarmed, - armix::mixer::DynamicChannelFxLeaseBank::ExternalLease externalCh1={}) { + armix::mixer::DynamicChannelFxLeaseBank::ExternalLease externalCh1={}, + bool admitSilentUnpatched=false) { // E5: a native BUS uses topology that M4 cannot represent. Never // demote its renderer on an unsupported legacy re-admission. if((nativeStructureLive_ || nativeControlDirty_) && @@ -1165,18 +1165,28 @@ class LiveDryRoutingLab final { channelIdPcmEpoch_.store(0,std::memory_order_release); nativeStructureLive_=false; try { + const bool silentStarter=admitSilentUnpatched && !hasExplicitRoute() && + sourceTemplate_.isObject() && !userPatched_.load(std::memory_order_acquire); if(!outputsDisarmed || occupiedExternalCh1Fx<0 || (occupiedExternalCh1Fx>0)!=externalCh1.populated() || - !hasExplicitRoute()||!ready() || + (!hasExplicitRoute()&&!silentStarter)||!ready() || topologyFault_.load(std::memory_order_acquire)) return false; const auto generation=epoch(),m4Revision=revision(); const auto* old=publisher_.controlPrepared(generation,m4Revision); if(!old || deviceFrames<=0) return false; + const auto& route=silentStarter?sourceTemplate_:acceptedRoute_; + // This admission never upgrades a draft with unverified capture. + if(silentStarter) { + const auto* rows=route.getProperty("channels",juce::var()).getArray(); + if(!rows || rows->size()!=count)return false; + for(const auto& row:*rows) + if(row.getProperty("mode",{}).toString()!="NONE")return false; + } armix::mixer::NativeDryRouteCommand decoded; juce::String problem; if(!armix::mixer::NativeDryRouteCommand::decode( - acceptedRoute_,decoded,problem))return false; + route,decoded,problem))return false; // A native IN is a callback ordinal, not the numerical physical // port label. Preserve original order including sparse ASIO pins. const int inputs=portCount_.load(std::memory_order_acquire); diff --git a/src/NativeMixerSessionDocument.h b/src/NativeMixerSessionDocument.h index ca93c1b66..d89b47a78 100644 --- a/src/NativeMixerSessionDocument.h +++ b/src/NativeMixerSessionDocument.h @@ -349,7 +349,7 @@ class Codec final { doc.savedMs=static_cast(ms); const auto binding=get(root,"binding"); if(!textField(get(binding,"backend"),doc.binding.backend,128)|| - !textField(get(binding,"capture"),doc.binding.capture,256)|| + !textField(get(binding,"capture"),doc.binding.capture,256,true)|| !textField(get(binding,"playback"),doc.binding.playback,256)|| !textField(get(binding,"inputMask"),doc.binding.inputMask,256)|| !textField(get(binding,"outputMask"),doc.binding.outputMask,256)) @@ -428,13 +428,17 @@ class Codec final { (doc.legacyIds.monitor.value&&!seek(doc.legacyIds.monitor,ChannelRole::monitor))) return false; auto req=get(root,"request"); - if(!integral(get(req,"physicalInputs"),doc.request.physicalInputs,1,256)|| + if(!integral(get(req,"physicalInputs"),doc.request.physicalInputs,0,256)|| !integral(get(req,"maxFrames"),doc.request.maxFrames,16,8192)|| !strictBool(get(req,"mainMonoAfterFx"),doc.request.mainMonoAfterFx)) return false; const auto sourcesVar=get(req,"sources"); const auto* sources=sourcesVar.getArray(); - if(!sources||sources->size()>channels->size())return false; + if(!sources||sources->size()>channels->size()|| + (doc.request.physicalInputs==0 && !sources->isEmpty()))return false; + if(doc.binding.capture.isEmpty() && + (doc.request.physicalInputs!=0 || doc.binding.inputMask!="0")) + return false; std::set seenSources; for(const auto& src:*sources) { DynamicSourcePatch p; diff --git a/tests/juce_active_port_snapshot_test.cpp b/tests/juce_active_port_snapshot_test.cpp index e1652fc39..06fd698b7 100644 --- a/tests/juce_active_port_snapshot_test.cpp +++ b/tests/juce_active_port_snapshot_test.cpp @@ -48,7 +48,7 @@ int main(){ out.clear(); assert(!JuceActivePortSnapshot::fromMasks(13,in,out,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); - assert(snap.inputs.callbackIndex(9)==previous.inputs.callbackIndex(9)); + assert(snap.inputs.callbackIndex(9)==-1); // failed 0-OUT preserves accepted zero-input snapshot assert(!JuceActivePortSnapshot::capture(nullptr,12,snap,fault)); assert(fault==JuceActivePortSnapshot::Fault::nullDevice); } diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index bd0191557..8f34bd107 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -351,6 +351,21 @@ static void warmVst3Discovery() { } int main(){ + // Zero-input is a legitimate saved SOURCE NONE workspace, never a fake mic. + { + auto silent=makeSession(); + silent.binding={"Windows Audio","","Speakers","0","3",48000.,256}; + silent.request.sources.clear();silent.request.physicalInputs=0; + MixerSessionDocument decoded; + assert(Codec::decode(Codec::encode(silent),decoded)); + assert(decoded.request.physicalInputs==0 && decoded.request.sources.empty()); + assert(decoded.roster.revision()==silent.roster.revision()); + assert(MixerDeviceBindingPolicy::apply(decoded,decoded.binding, + decoded.outputs,0,BindingMode::exact).isEmpty()); + auto malformed=juce::JSON::parse(Codec::encode(silent)); + malformed.getProperty("binding",{}).getDynamicObject()->setProperty("inputMask","3"); + assert(!Codec::decode(juce::JSON::toString(malformed,false),decoded)); + } warmVst3Discovery(); nativeDeviceRecovery(); auto d=makeSession(); From 67a04bd4f429bd9fa0a9d71df8246e7f24cfea97 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:09:29 +0700 Subject: [PATCH 013/125] fix(harmony): confirm native key edits and real vocal pitch activity in modeless GUI --- docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md | 18 +++++++++++ site/preview-v2/assets/mixer-fx-rack.css | 2 ++ .../preview-v2/assets/mixer-native-harmony.js | 31 ++++++++++++++++--- tests/approved_native_harmony_smoke.py | 23 ++++++++++++-- tests/native_harmony_assembly_test.py | 5 +++ 5 files changed, 71 insertions(+), 8 deletions(-) diff --git a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md index 2f85007b7..9ade422a9 100644 --- a/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md +++ b/docs/ARSON_HARMONY_ENGINE_AUDIT_20261108.md @@ -95,3 +95,21 @@ PCM regressions: anti-phase singer A3 and nonzero five-voice harmony at 48/96k; **P0 hostile PCM fail-closed:** Native input guards now clip finite >4.0f amplitude before the internal dry/grain histories (the engine already clamps all output to +/-4.0f); NaN and infinity still become silence. `StereoPhaseSafeFold` returns the bounded fold it actually uses for correlation, instead of computing an unbounded sum after clipping evidence. This prevents a host supplying finite near-FLT_MAX PCM from poisoning Music Guide or vocal analysis with infinity. Ordinary valid PCM [-4,+4], channel polarity, dry PDC, Music Track read-only routing and GUI are untouched. **Qualification:** 5 sample rates (32/44.1/48/96/192k), 3 callback partitions (64/127/256 frames), deterministic A3 voiced note, complete correlation windows/no abandoned windows and <=8 candidate lags per slice; real 2/5-voice hostile IEEE PCM and direct near-FLT_MAX stereo guide. The existing 48k blockwise PCM parity, low bass/high soprano, 48/192k stereo dry and 1536-sample PDC regression remain active. Hardware ASIO and spectral/formant gate remain unverified; no claim of a completed P0 low-latency/formant engine. + +## 2026-11-09 P0 Harmony native-key and singer telemetry UX + +The field failure had two independent operator problems: (1) stale modeless-editor +control lease on graph/device change was resolved by accepted-graph auto-rebind, +and (2) native pitch `observedNote` was in the authoritative C++ snapshot but +never visible to the operator in Manual Key, which only polled Music mode. +The editor now uses the EXISTING 12Hz console tick for <=2Hz readback in +both modes, showing `TRACKING A3`/ `WAITING VOICE`/ `DSP SYNCING` +from the true PCM-owner `observedNote`, never inferred from the UI key. +Key gestures outline the requested letter immediately but the accepted +key/LCD still changes ONLY after the native DSP ACK and matching readback. +The status reports `KEY C#m - AWAITING DSP ACK` while pending. One +small footer string and a one-pixel indicator; no graph routing, FX +parameter schema, audio callback work or polling timer added. Real Chromium +test additionally checks manual-mode liveness, immediate gesture indicator +and its disappearance after accepted readback. Vocal formant/spatial realism +remains unproven and separate from this GUI feedback milestone. diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index b5f8376f9..15a890976 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -710,6 +710,8 @@ .mx-harm-foot>span:first-child{ min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap } +.mx-harm-foot #mxHTracking{flex:0 0 auto;white-space:nowrap;color:#80c6c3} +.mx-harm-note.queued:not(.active){outline:2px solid #69d6b4;outline-offset:1px} @media(max-width:740px){ .mx-harm-body{grid-template-columns:126px minmax(0,1fr) 206px;min-height:224px} .mx-harm-left{padding:14px 9px 10px} diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index 6978f826e..c7d4d11f6 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -60,7 +60,7 @@ root.innerHTML=` MANUAL -
PREVIEW · NO AUDIO
+
PREVIEW · NO AUDIOVOICE WAITING
`; // Cached editor nodes and change-only text: no DOM traversal/paint churn on // native readback ticks while the user sings. @@ -247,6 +247,13 @@ function paint(){ const reliable=displayKey>=0&&displayKey<12&&displayScale>=0&&displayScale<=1; const inGraph=availableSources.some(ch=>ch.id===v.guideChannelId); const detected=auto&&detectedKey>=0&&detectedScale>=0; + // Gesture feedback is visibly immediate, but the active key still + // reflects ONLY the last native PCM ACK + authoritative readback. + const draft=latest||pending?.settings|| + (heldPatch?{...settings,...heldPatch}:null); + const queuedKey=nativeView&&draft&& + (draft.key!==settings.key||draft.scale!==settings.scale) + ?draft.key:-1; for(const b of guideButtons){ const active=Number(b.dataset.guideMode)===v.guideMode; b.classList.toggle("active",active); @@ -256,8 +263,11 @@ function paint(){ const source=el("mxHGuideSource"); const chosen=inGraph?v.guideChannelId:"0"; if(source.value!==chosen)source.value=chosen; - for(const b of noteButtons)b.classList.toggle("active", - reliable&&Number(b.dataset.key)===displayKey); + for(const b of noteButtons){ + b.classList.toggle("active", + reliable&&Number(b.dataset.key)===displayKey); + b.classList.toggle("queued",Number(b.dataset.key)===queuedKey); + } for(const b of voiceButtons){ const active=Number(b.dataset.voices)===v.voices; b.classList.toggle("active",active); @@ -292,6 +302,12 @@ function paint(){ showText(output,key==="gainDb"?v[key].toFixed(1)+" dB":Math.round(value)+"%"); } syncPower(); + const detectedNote=observedNote>=0 && observedNote<=127? + keys[observedNote%12]+String(Math.floor(observedNote/12)-1):""; + const tracking=nativeView? + !verified?"DSP SYNCING":detectedNote?"TRACKING "+detectedNote:"WAITING VOICE": + "DEMO"; + showText(el("mxHTracking"),tracking); showText(el("mxHLatency"),mode==="NATIVE"?readbackLatency+" samples":"DEMO"); } // One in-flight readback, a bounded retry on the EXISTING 12 Hz console @@ -313,7 +329,9 @@ function send(next){ pending={id,settings:next,ack:false,context:c,startedAt:Date.now()}; backend().emitEvent("arMixAction",{action:"nativeHarmonySetSettings", requestId:id,...c,settings:next}); - hint("DSP QUEUED · AWAITING AUDIO ACK");paint(); + hint(next.key!==settings.key||next.scale!==settings.scale? + "KEY "+keys[next.key]+(next.scale?"m":"")+" · AWAITING DSP ACK": + "DSP QUEUED · AWAITING AUDIO ACK");paint(); } function edit(patch){ const next={...(latest||pending?.settings|| @@ -499,7 +517,10 @@ backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ } return; } - if(settings.guideMode===1&&now-lastGuideRead>750){ + // Manual mode also needs real singer activity. The accepted native + // audio-owner observedNote already exists; use this 12Hz console tick + // at <=2Hz readback without allocating a new polling timer. + if(now-lastGuideRead>500){ lastGuideRead=now;snapshot(); } }); diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index aafc277f1..0d1efce0b 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -25,7 +25,7 @@ def last_action(page,kind): return actions[-1] def readback(page,state,values,key,scale,detected=(-1,-1),applied=None, - request=None,instance=INSTANCE): + request=None,instance=INSTANCE,observed=-1): action=request or last_action(page,"nativeHarmonySnapshot") packet={ "requestId":action["requestId"], @@ -33,7 +33,7 @@ def readback(page,state,values,key,scale,detected=(-1,-1),applied=None, "deviceEpoch":state["device"]["epoch"], "graphRevision":state["graph"]["revision"], "schemaVersion":2,"sampleRate":48000,"latencySamples":1536, - "settings":copy.deepcopy(values),"observedNote":-1, + "settings":copy.deepcopy(values),"observedNote":observed, "guideDetectedKey":detected[0],"guideDetectedScale":detected[1], "guideConfidence":0.75 if detected[0]>=0 else 0.0, "effectiveKey":key,"effectiveScale":scale, @@ -104,7 +104,8 @@ def main(): # Native LCD must not fabricate manual/detected effective key # until the exact instance-scoped DSP snapshot arrives. assert page.locator("#mxHKeyReadout").inner_text()=="—" - readback(page,state,DEFAULT,0,0) + readback(page,state,DEFAULT,0,0,observed=57) + assert page.locator("#mxHTracking").inner_text()=="TRACKING A3" assert page.locator("#mxHKeyReadout").inner_text()=="C" assert page.locator("#mxHGuideStatus").inner_text()=="MANUAL" assert page.locator("#mxHSourcePicker").is_hidden() @@ -158,9 +159,14 @@ def main(): assert manual["settings"]["guideMode"]==0 assert manual["settings"]["guideChannelId"]=="0" assert page.locator("#mxHKeyReadout").inner_text()=="Am" + assert "AWAITING DSP ACK" in page.locator("#mxHStatus").inner_text() + assert "queued" in (page.locator( + '.mx-harm-note[data-key="7"]').get_attribute("class") or "") locked={**DEFAULT,"key":7} apply_edit(page,state,locked,7,0) assert page.locator("#mxHKeyReadout").inner_text()=="G" + assert "queued" not in (page.locator( + '.mx-harm-note[data-key="7"]').get_attribute("class") or "") assert page.locator("#mxHGuideStatus").inner_text()=="MANUAL" assert page.locator("#mxHSourcePicker").is_hidden() # G is a literal circle, subtly larger than unselected notes. @@ -296,6 +302,17 @@ def face_metrics(locator): readback(page,state,selected,9,1,detected=(9,1), request=old_poll) assert page.locator("#mxHKeyReadout").inner_text()=="G" + # Manual Key also observes audio-owner tracking on existing + # console ticks. Never infer singing from a UI button state. + before=len(page.evaluate( + "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) + page.wait_for_timeout(530) + emit(page,"arMixConsoleSnapshot",state) + page.wait_for_function("""count=>window.__actions.filter( + x=>x.action==='nativeHarmonySnapshot').length>count""",arg=before) + monitor=last_action(page,"nativeHarmonySnapshot") + readback(page,state,changed,7,0,request=monitor,observed=60) + assert page.locator("#mxHTracking").inner_text()=="TRACKING C4" # Reproduce the field screenshot: singer DSP continues playing # while a native device/graph revision changes under an open # Harmony editor. It MUST auto-rebind; no user reopen/wizard. diff --git a/tests/native_harmony_assembly_test.py b/tests/native_harmony_assembly_test.py index a0776ec2a..1a00c7e2f 100644 --- a/tests/native_harmony_assembly_test.py +++ b/tests/native_harmony_assembly_test.py @@ -90,6 +90,11 @@ def test_quiet_manual_music_mode_and_selector(self): self.assertIn('edit({guideMode:0,guideChannelId:"0"})',self.ui) self.assertIn('const status=!auto?"MANUAL":!inGraph?"SAFE":detected?"AUTO":"LISTEN";',self.ui) self.assertIn("showText(el(\"mxHKeyReadout\"),",self.ui) + self.assertIn('id="mxHTracking" aria-live="off"',self.ui) + self.assertIn('showText(el("mxHTracking"),tracking)',self.ui) + self.assertIn('if(now-lastGuideRead>500)',self.ui) + self.assertIn('b.classList.toggle("queued"',self.ui) + self.assertIn('.mx-harm-note.queued:not(.active)',self.css) self.assertIn('role="status" aria-live="polite"',self.ui) self.assertIn(".mx-harm-mode button.active",self.css) self.assertIn(".mx-harm-source-picker[hidden]{display:none}",self.css) From 75e99c63a8ef46d6c361113b33f58e325848361e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:10:50 +0700 Subject: [PATCH 014/125] test(P0): prove output-only native silent mixer can add track and render true zero PCM Adapt startup banner contract to zero-capture no longer blocking FX, add JUCE-backed 0-IN 2-OUT ChannelId bootstrap/track/PCM test; retain M4 unpatched refusal. --- tests/approved_native_m2_contract.test.cjs | 3 +- tests/native_mixer_session_store_test.cpp | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 31f2539ef..6568af4c0 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1241,7 +1241,8 @@ test("P0 native FX rack and per-slot readback update mounted strip without repla test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ const bridge=read("web/approved-native-bridge.js"); assert.match(bridge,/SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK/); - assert.match(bridge,/NO CAPTURE INPUT · OPEN AUDIO I\/O/); + assert.match(bridge,/NO HARDWARE IN · MIXER\/FX READY · USE PLAYER OR AUDIO I\/O/); + assert.doesNotMatch(bridge,/hardware\.device\.enabledInputs\.length>0/); assert.match(bridge,/NO VERIFIED INPUT ROUTE · OPEN AUDIO I\/O/); assert.doesNotMatch(bridge,/NO AUDIBLE OUTPUT · PATCH INPUT \+ ARM/); assert.match(bridge,/const preparedFirstSound=session\?\.authority==="NONE"/); diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 8f34bd107..952281888 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -93,6 +93,38 @@ class FixtureDevice final : public juce::AudioIODevice { double rate=48000.; }; +static void outputOnlyNativeStartup() { + // Real output-only callback: never invent a capture pin, but a silent + // ChannelId session, its FX/WIRE bus and physical zero output are valid. + FixtureDevice playback; + playback.inputMask.clear(); + LiveDryRoutingLab mixer; + juce::AudioPluginFormatManager formats; + mixer.prepareDevice(&playback); + assert(mixer.startUnpatchedSession(true,false,0,formats,48000.,480).isEmpty()); + assert(mixer.ready() && !mixer.hasExplicitRoute()); + // Legacy startup is silent before the one deliberate native migration. + assert(!mixer.admitChannelIdFromAcceptedM4(0,480,true)); + assert(mixer.admitChannelIdFromAcceptedM4(0,480,true,{},true)); + assert(mixer.hasExplicitRoute() && !mixer.hasVerifiedNativeSources()); + const auto native=mixer.nativeBusStatus(); + assert(native.isObject()); + const auto graph=static_cast( + native.getProperty("graphRevision",{}).toString().getLargeIntValue()); + const auto roster=static_cast( + native.getProperty("rosterRevision",{}).toString().getLargeIntValue()); + const auto add=mixer.createNativeInputChannel(mixer.epoch(),graph,roster, + "No Microphone Track",ProcessingFormat::stereo,true); + assert(add.accepted && !mixer.hasVerifiedNativeSources()); + std::array left{},right{}; + left.fill(1.f);right.fill(1.f); // must be cleared, not fake audio + float* outputs[]={left.data(),right.data()}; + assert(mixer.process(nullptr,0,outputs,2,480,1.f,true, + nullptr,nullptr,false,nullptr,nullptr,true)); + for(const auto s:left)assert(s==0.f); + for(const auto s:right)assert(s==0.f); +} + static void nativeDeviceRecovery() { FixtureDevice device; auto saved=makeSession(); @@ -366,6 +398,7 @@ int main(){ malformed.getProperty("binding",{}).getDynamicObject()->setProperty("inputMask","3"); assert(!Codec::decode(juce::JSON::toString(malformed,false),decoded)); } + outputOnlyNativeStartup(); warmVst3Discovery(); nativeDeviceRecovery(); auto d=makeSession(); From 4fd5d635366c6b550f3d7d8da37be453344bbb11 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:12:44 +0700 Subject: [PATCH 015/125] docs(harmony): source-backed natural ensemble DSP architecture and release gates --- ..._NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md diff --git a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md new file mode 100644 index 000000000..012c9ea76 --- /dev/null +++ b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md @@ -0,0 +1,46 @@ +# ArSon Harmony — Natural Vocal Ensemble DSP Architecture & Evidence +2026-11-09 | source branch PR #487 | Design audit, **NOT** acoustic certification + +## Product acceptance + +A user singing one live monophonic lead must hear **one intelligible lead in front and independently perceived backing singers**, e.g. three voices behind, moderately left, near-center and moderately right. The BACKINGS must vary in timing, intonation, timbre and room position without creating robotic timbre, metallic grain edges, clicks, doubling of consonant transients, excess latency or ASIO XRUN. Key buttons should respond immediately with *pending* feedback, then turn *accepted* only on true native DSP ACK/readback. GUI should display an audio-owned tracking note, not pretend that pressing Key triggers sound or proves PCM processing. + +## Source-code diagnosis (before redesign) + +Current `engine/builtin_fx/HarmonyDsp.h` uses one phase-safe mono analysis/grain source for all harmony voices, two overlapping 16ms grains per shifter, identical initial grain phase for all voices, note-locked fixed diatonic offsets `{+2,+4,-2,+6,-4}` scale degrees, the **same one-pole Color** coefficient for all voices, equal-power stereo pan, and shared smoothing. `Space` only multiplies pan; it supplies no distance, room or early reflections. There are no differentiated vocal-formant paths, per-voice onset microtiming, natural vibrato or voice-leading across chords. The current declared DSP PDC at 48k remains **1536 samples / 32ms**. `Voice count=3` represents three wet harmony voices in addition to dry lead, not three separately modeled people. + +This is functional prototype pitch-shifting, **not** a formant-stable choir model. Improving pan or reverb alone cannot repair consonant smearing, pitch-mark phase discontinuity, or shifted formants. `Color` is *brightness*, not voice-tract formant preservation. + +## Research cross-check (public engineering references) + +- Antares Harmony Engine: independent voice timbre/vibrato/panning, humanize and choir controls; scale, chord and arranged notes; https://www.antarestech.com/products/creative-vocal-effects/harmony-engine +- Antares walkthrough: per-voice pan/throat length, vibrato onset/rate, timing and pitch variation; https://www.antarestech.com/blog/tutorial-introduction-to-harmony-engine +- Eventide H949: intelligent de-glitched splicing, micropitch and randomized delay to reduce lockstep duplication; https://www.eventideaudio.com/plug-ins/h949-harmonizer/ +- Eventide Quadravox: independent diatonic voice intervals and pitch transitions; https://cdn.eventideaudio.com/manuals/h90/1.1.2/content/algorithms/pitch.html +- PSOLA singing paper: pitch marks and 2-period Hann window, formant-aware spectral envelope processing, low-cost resynthesis but pitch-mark error is audible; https://www.mdpi.com/2076-3417/6/11/368 +- AES PSOLA + transient preservation: pitched segmentation needs robust marks and explicit consonant/transient bypass/reinjection; https://aes.org/publications/elibrary-page/?id=15624 +- Real-time phase vocoder spectral envelope: whitening/reconstruction is an alternative but incurs spectral window work and transient tradeoffs; https://www.isca-archive.org/interspeech_2017/lenarczyk17_interspeech.pdf +- Rubber Band documentation: `OptionFormantPreserved` and `OptionPitchHighConsistency` for dynamically varying vocal pitch. LiveShifter documents **>=50ms delay** depending on settings; not a free drop-in replacement for a low-latency live ASIO path; https://breakfastquay.com/rubberband/integration.html and https://breakfastquay.com/rubberband/code-doc/classRubberBand_1_1RubberBandLiveShifter.html. License GPLv2+ or commercial, review distribution terms before any integration: https://breakfastquay.com/rubberband/license.html +- Backing-vocal spatial placement / front-back depth: complementary pan and differences in timbre, early reflections, reverb/delay; natural doubles need independent microtiming; mono-check to avoid comb filtering: https://www.izotope.com/community/blog/tips-for-mixing-vocal-harmonies and https://www.izotope.com/community/blog/what-is-mix-depth-how-to-create-front-back-space and https://www.izotope.com/community/blog/10-tips-for-better-mixes-through-panning + +## Committed engineering decision, staged — no rushed wholesale DSP swap + +**P0: native GUI provenance, truth, response.** Keep one audio-owned ChannelId/InstanceId, native ACK and readback. Preserve editor across device/graph revision using safe auto-rebind. `observedNote` (quantized tracked MIDI note, *not exact raw singing F0*) now drives a small `TRACKING A3` / `WAITING VOICE` indicator on existing console ticks at <=2Hz, including Manual Key. Key gesture outlined as *queued* immediately while the actual LCD highlight is still the last accepted DSP value. No new polling timer, speculative PCM meters, Lab modes, FX permission gates or GUI shell redesign. + +**P0: make pitch/resynthesis natural, then measure.** Retain the proven prototype behind a native A/B flag during experimentation. Candidate quality path: confidence-gated fundamental detection -> robust glottal-epoch / pitch-mark tracking (using existing pitch estimator as an initial predictor; verify each mark by correlation) -> low-cost overlap-add on two-period tapered periods, scheduled at target F0. Preserve spectral envelope via pitch-synchronous segment handling; if audible vowel/formant drift persists at large shifts, benchmark pre/post spectral-envelope or LPC correction off the shared analysis window. Shared normalized/unvoiced consonant and transient path should not create three repeated sibilant attacks. When pitch confidence falls, crossfade safely to neutral or limited fallback rather than random target harmonies. Do not invent claims that TD-PSOLA alone is perfect at large intervals. Maintain the same single native PCM owner, immutable prepared controls, bounded history and predictable callback instruction budget. + +**P1: three distinct backing singers; ensemble spatializer.** Model each voice independently AFTER pitch generation: slight deterministic, slowly evolving detune rather than random-per-sample jitter; own phrase-onset delay / vibrato rate+depth/offset; mild unique spectral contour and intentional register. Keep leading dry vocal prominent. Initial *hypotheses to measure/listen*, not shipped presets: pan L=-0.35 to -0.45, inner=-0.05 to +0.05, R=+0.35 to +0.45; differences in onset 10–25ms; low-amplitude individual 3–8-cent pitch drift (slow and correlated within a phrase), modest sustain-only vibrato ~4–6 Hz, no hard random reset at graph boundaries. Per-voice room-send and early reflection mix with small filtered reflected taps ~20–50ms, not five independent convolution reverbs. Reverberant-to-direct ratio and high-frequency loss convey distance; simply cranking global width does not make a voice sound behind the lead. Pan+room must remain mono-compatible with no unexpected polarity cancellation; avoid phase-widening shortcuts. + +**P2: musical arrangement reliability.** Key+scale alone does NOT tell the current chord; fixed diatonic thirds/fifths can harmonize out of chord when music changes. Source-channel Music Guide must stay an independent read-only reference with confidence hysteresis/fallback; explore chord estimation / optional MIDI note control and smooth voice-leading only AFTER reliable native PCM keys and natural pitch shifting. No silent auto-chord hallucination. `Space` remains a single easy control that intelligently combines width/depth with carefully tuned bounds; power and Wet remain intuitive. + +**Low-latency ownership rule.** The source singer's ASIO monitor must not be slowed by experimental spatialization. Any PDC change needs native graph/host correctness and same-time dry/wet alignment verification. The present 1536-sample lookback is a measured *code delay*, not a benchmark of total ASIO round trip. Incremental tuning cannot be declared 'zero latency'. No locks/malloc/blocking on callback, no unbounded FFT work on sample path, no plugin worker feeding the realtime thread with a blocking rendezvous. + +## Measured acceptance gates before release promotion + +1. Exact Windows native compiled tests at 32/44.1/48/96/192 kHz and callback periods 64/128/256: deterministic output across buffer partitionings; bounded per-sample/per-block costs, no NaN/inf, clipping, lost ACK, stale FX lease or phase-cancelled mono. +2. Native visual/transport tests: tap Key while voice is live -> immediate pending outline/status; only accepted key after audio ACK and matching readback; live pitch tracking readback while Manual; Graph revision, device restart, FX move/recreate, stale ACK rejected; renderer never strands user on REOPEN. +3. Voice quality: licensed/consented male/female/child-free adult recordings, vowels A/E/I/O/U, breath/voiced/unvoiced consonants and held/fast syllables; measure F0 trajectory error, F1/F2/F3 shift, transient repetition, onset jitter, sibilance and phrase coherence against dry and reference algorithms. +4. Spatial A/B with mono fold-down: blind listen for **three distinguishable backup singers behind the lead**, not combed/flanged copies. Check L/C/R placements, loudness-normalized mono/stereo, low/normal/high background levels, output on mono speakers and headphones. +5. Actual ASIO physical FAT at 48/96 kHz, 64/128/256 frames: CPU time distribution p95/p99, deadline margin and XRUNs with 2/3/5 voices and multiple mixer plugins, hot graph/device rebind. These results cannot be inferred from ordinary GitHub Actions. + +**Non-claim:** The present PR does not yet implement or certify natural formants, an acoustic spatial engine, or a shorter engine PDC. Changing those requires measured code, CTest, render comparisons, audio A/B and physical ASIO proof. From 178631b5b72750ae7a01f18487385c5ce18daaaa Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:15:18 +0700 Subject: [PATCH 016/125] test(device): update DIRECT fingerprint contract for genuine output-only playback --- tests/direct_restore_recovery_contract_test.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/direct_restore_recovery_contract_test.mjs b/tests/direct_restore_recovery_contract_test.mjs index f9e1ec018..8101526d3 100644 --- a/tests/direct_restore_recovery_contract_test.mjs +++ b/tests/direct_restore_recovery_contract_test.mjs @@ -87,8 +87,10 @@ test('ASIO/WASAPI DIRECT authorizes the exact active input/output channel map',( } assert.ok(engine.includes('EXACT_ACTIVE_INPUT_AND_OUTPUT_CHANNEL_BITMASKS')); assert.ok(fence.includes('UNEXPECTED_DIRECT_BACKEND_DEVICE_OR_CHANNEL_MASK')); - assert.ok(fence.includes('!validMask(inputMask)')); - assert.ok(fence.includes('!validMask(outputMask)')); + // A real output-only playback session has the canonical zero input mask. + // The exact device fingerprint must still reject absent physical outputs. + assert.ok(fence.includes('!validMask(inputMask,true)')); + assert.ok(fence.includes('!validMask(outputMask,false)')); const callback=engine.slice(engine.indexOf('void audioDeviceIOCallbackWithContext')); assert.ok(callback.indexOf('!directFence_.permitted()')>=0); assert.ok(callback.indexOf('!directFence_.permitted()') Date: Mon, 9 Nov 2026 17:18:46 +0700 Subject: [PATCH 017/125] test(harmony): emulate continuous 12 Hz native console ticks for Manual voice liveness --- tests/approved_native_harmony_smoke.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index 0d1efce0b..0ac77f873 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -306,10 +306,20 @@ def face_metrics(locator): # console ticks. Never infer singing from a UI button state. before=len(page.evaluate( "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) - page.wait_for_timeout(530) - emit(page,"arMixConsoleSnapshot",state) - page.wait_for_function("""count=>window.__actions.filter( - x=>x.action==='nativeHarmonySnapshot').length>count""",arg=before) + # Native host produces ~12 console ticks per second, not one + # artificially selected 530ms tick after an arbitrary prior + # music readback. Exercise the real tick cadence for 2s. + # A single tick may legitimately be coalesced or queued. + after=before + for _ in range(24): + emit(page,"arMixConsoleSnapshot",state) + after=len(page.evaluate( + "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) + if after>before:break + page.wait_for_timeout(85) + assert after>before,("no Manual Key native tracking poll", + page.locator("#mxHStatus").inner_text(), + page.locator("#mxHTracking").inner_text()) monitor=last_action(page,"nativeHarmonySnapshot") readback(page,state,changed,7,0,request=monitor,observed=60) assert page.locator("#mxHTracking").inner_text()=="TRACKING C4" From cc57c1f8ec105d6db7b87d24daed25d60b5b2711 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:20:20 +0700 Subject: [PATCH 018/125] test(harmony): drain outstanding native readback before asserting Manual Key polling --- tests/approved_native_harmony_smoke.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index 0ac77f873..24c1a8976 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -304,6 +304,12 @@ def face_metrics(locator): assert page.locator("#mxHKeyReadout").inner_text()=="G" # Manual Key also observes audio-owner tracking on existing # console ticks. Never infer singing from a UI button state. + # The preceding bypass-readback tests may have left ONE + # outstanding (throttled) snapshot request. Complete it as + # native JUCE would, rather than asserting a second request + # within the in-flight 2500ms readback fence. + latest_snap=last_action(page,"nativeHarmonySnapshot") + readback(page,state,values,7,0,request=latest_snap) before=len(page.evaluate( "()=>window.__actions.filter(x=>x.action==='nativeHarmonySnapshot')")) # Native host produces ~12 console ticks per second, not one From 16a8599fdd9a2dddfa64329f6c550a00e029ca14 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:36:32 +0700 Subject: [PATCH 019/125] fix(P0): make Audio I/O output-only selection work end-to-end Allow explicit NONE capture for separate Windows audio endpoints and empty enabled capture masks for genuine ASIO devices, preserving exact verified stereo outputs, user choice, DIRECT fencing and readback. Match native bridge device Apply/ACK to accepted zero-capture graph; add regression contract. --- src/Main.cpp | 26 +++++++++++++++------- tests/approved_native_m2_contract.test.cjs | 12 ++++++++++ web/approved-native-bridge.js | 20 +++++++++++------ 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 4e6bed06c..09f77424a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1359,9 +1359,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto typeName=config.getProperty("backend",{}).toString(); const auto capture=config.getProperty("captureDevice",{}).toString(); const auto playback=config.getProperty("playbackDevice",{}).toString(); - if(typeName.isEmpty()||capture.isEmpty()||playback.isEmpty()|| + if(typeName.isEmpty()||playback.isEmpty()|| typeName.length()>160||capture.length()>250||playback.length()>250) - return send(false,"REJECTED","Choose actual capture and playback devices"); + return send(false,"REJECTED","Choose an actual playback device"); auto& manager=engine_.devices(); juce::AudioIODeviceType* selectedType=nullptr; for(auto* type:manager.getAvailableDeviceTypes()) @@ -1370,8 +1370,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Do not let JS submit arbitrary names or combine unmatched ASIO devices. const auto namesIn=selectedType->getDeviceNames(true); const auto namesOut=selectedType->getDeviceNames(false); - if(!namesIn.contains(capture)||!namesOut.contains(playback)|| - (!selectedType->hasSeparateInputsAndOutputs()&&capture!=playback)) + // A separate-input/output backend can legitimately open a render + // endpoint WITHOUT capture hardware. Empty capture is a deliberate + // operator choice, never an inferred name or a fake input port. + // ASIO/non-separate drivers retain exact duplex device identity; + // they may still expose zero enabled capture *pins*. + const bool separate=selectedType->hasSeparateInputsAndOutputs(); + const bool outputOnly=separate&&capture.isEmpty(); + if((!outputOnly&&!namesIn.contains(capture))||!namesOut.contains(playback)|| + (!separate&&capture!=playback)) return send(false,"REJECTED","Device names or duplex pairing are not reported by JUCE"); auto sample=config.getProperty("sampleRate",{}), period=config.getProperty("bufferSize",{}); if(!(sample.isInt()||sample.isDouble()||sample.isInt64())|| @@ -1449,14 +1456,18 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr }; juce::BigInteger inMask,outMask; if(!parsePins(pinInput,inCount,inMask)||!parsePins(pinOutput,outCount,outMask)|| - inMask.countNumberOfSetBits()<1||outMask.countNumberOfSetBits()<2) - return send(false,"REJECTED","Choose >=1 verified capture and >=2 playback pins"); + (outputOnly&&!inMask.isZero())||outMask.countNumberOfSetBits()<2) + return send(false,"REJECTED","Select real input pins (or none) and >=2 verified playback pins"); candidate.useDefaultInputChannels=false; candidate.useDefaultOutputChannels=false; candidate.inputChannels=inMask; candidate.outputChannels=outMask; }else { - candidate.useDefaultInputChannels=true; + // The requested 0-IN option must not reopen a microphone merely + // because JUCE defaults to enabling available capture channels. + // Output pin selection still requires actual driver readback. + candidate.useDefaultInputChannels=!outputOnly; + if(outputOnly)candidate.inputChannels.clear(); candidate.useDefaultOutputChannels=true; } auto* active=manager.getCurrentAudioDevice(); @@ -1511,7 +1522,6 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (!candidate.useDefaultOutputChannels&&actual.outputChannels!=candidate.outputChannels)|| opened->getActiveInputChannels()!=actual.inputChannels|| opened->getActiveOutputChannels()!=actual.outputChannels|| - opened->getActiveInputChannels().countNumberOfSetBits()<1|| opened->getActiveOutputChannels().countNumberOfSetBits()<2|| std::abs(opened->getCurrentSampleRate()-actual.sampleRate)>1.0|| opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 6568af4c0..6eb2bab28 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1248,6 +1248,18 @@ test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ assert.match(bridge,/const preparedFirstSound=session\?\.authority==="NONE"/); assert.match(bridge,/const deviceReady=\(\)=>/); }); +test("P0 output-only Audio I/O is a real native configuration, never blocked by missing capture",()=>{ + const cpp=read("src/Main.cpp"),bridge=read("web/approved-native-bridge.js"); + assert.match(cpp,/const bool outputOnly=separate&&capture\.isEmpty\(\)/); + assert.match(cpp,/candidate\.useDefaultInputChannels=!outputOnly/); + assert.match(cpp,/if\(outputOnly\)candidate\.inputChannels\.clear\(\)/); + assert.match(cpp,/\(outputOnly&&!inMask\.isZero\(\)\)/); + assert.doesNotMatch(cpp,/opened->getActiveInputChannels\(\)\.countNumberOfSetBits\(\)<1/); + assert.match(bridge,/No hardware input \(Player \/ FX\)/); + assert.match(bridge,/t\?\.separate\?\["",\.\.\.\(t\.inputs\|\|\[\]\)\]/); + assert.doesNotMatch(bridge,/ack\.active\.enabledInputs\.length>0/); + assert.match(bridge,/FX\/WIRE available/); +}); test("P0 FIRST SOUND G0 offers verified input and leaves automatic MAIN to native",()=>{ const vm=require("node:vm"),sent=[],listeners=new Map(),renderedChoices=[]; let win; diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 41f8f3129..e94d52274 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1675,7 +1675,8 @@ devicePanel.querySelector("[data-audio-apply]").onclick=()=>{ if(deviceBusy||!deviceChoice||!deviceInventory?.active)return; const draft=deviceChoice,active=deviceInventory.active; - if(!draft.backend||!draft.capture||!draft.playback)return; + const separate=deviceInventory.types?.find(x=>x.name===draft.backend)?.separate===true; + if(!draft.backend||!draft.playback||(!separate&&!draft.capture))return; sendDeviceApply(); }; devicePanel.querySelector("[data-audio-remap]").onclick=()=>{ @@ -1696,7 +1697,10 @@ if(!el)return; el.replaceChildren(...values.map(value=>{ const option=document.createElement("option"); - option.value=value;option.textContent=value;return option; + option.value=value; + option.textContent=name==="capture"&&value==="" + ?"No hardware input (Player / FX)":value; + return option; })); if(values.includes(current))el.value=current; el.disabled=deviceBusy; @@ -1707,7 +1711,9 @@ if(!deviceChoice){ const backendName=active.backend||types[0]?.name||""; const selected=types.find(x=>x.name===backendName); - const capture=active.captureDevice||selected?.inputs?.[0]||""; + // Preserve an already-open output-only endpoint on repeated dialog opens. + const capture=active.open?String(active.captureDevice||""): + active.captureDevice||selected?.inputs?.[0]||""; deviceChoice={backend:backendName,capture, playback:active.playbackDevice|| (selected?.separate?selected?.outputs?.[0]:capture)||"", @@ -1720,7 +1726,8 @@ if(asio4allHint)asio4allHint.hidden=!( deviceChoice.backend==="ASIO"&&/asio4all/i.test(deviceChoice.capture)); fillAudioSelect("backend",types.map(x=>x.name),deviceChoice.backend); - fillAudioSelect("capture",t?.inputs||[],deviceChoice.capture); + fillAudioSelect("capture", + t?.separate?["",...(t.inputs||[])]:t?.inputs||[],deviceChoice.capture); fillAudioSelect("playback",t?.outputs||[],deviceChoice.playback); const same=active.open&&active.backend===deviceChoice.backend&& active.captureDevice===deviceChoice.capture&& @@ -1766,7 +1773,7 @@ "ACTIVE · "+active.backend+" · "+active.rate+" Hz / "+active.buffer+" samples": "No verified audio device. Select a supported input and output."); devicePanel.querySelector("[data-audio-apply]").disabled=deviceBusy|| - !deviceChoice.backend||!deviceChoice.capture|| + !deviceChoice.backend||(!t?.separate&&!deviceChoice.capture)|| !deviceChoice.playback; const remap=devicePanel.querySelector("[data-audio-remap]"); remap.hidden=!same || offeredPinRemap!==active.deviceGeneration; @@ -1812,13 +1819,12 @@ const accepted=ack.ok===true&&["ACCEPTED_LIVE","ACCEPTED_MUTED"].includes(ack.state) && ack.active?.open===true && ack.active?.authorized===true && Array.isArray(ack.active.enabledInputs) && - ack.active.enabledInputs.length>0 && Array.isArray(ack.active.enabledOutputs) && ack.active.enabledOutputs.length>=2; const outputReady=ack.outputMuted===false; deviceResult=accepted? (outputReady?"Mixer ready · Output live": - ack.mixerBound?"Mixer ready · Verify channel IN and output":"Audio device ready · choose a channel IN"): + ack.mixerBound?"Mixer ready · FX/WIRE available":"Audio device ready · no hardware input required"): ack.state==="NEEDS_REMAP"? "NEEDS REMAP · "+ack.error: "Device rejected · "+(ack.error||"native hardware readback failed"); From b0f485b9ed66788bf36379d3eed7b061b0ff8597 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:39:24 +0700 Subject: [PATCH 020/125] test(P0): Chromium verify output-only Audio I/O, Apply/ACK and no auto-mic reopen --- tests/approved_native_cold_start_smoke.py | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index d4053e2c0..3d9764280 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -41,6 +41,44 @@ def main(): addEventListener(name,callback){window.__nativeListeners.set(name,callback);}}};""") page.goto((out/'index.html').as_uri()) page.wait_for_function('()=>window.__ARMIX_NATIVE_M2__?.enabled') + # Output-only playback is a REAL Audio I/O choice, not a hidden + # capture prerequisite. Verify native intent/ACK on the approved + # assembled Windows GUI at every supported viewport. + page.locator('.command-bar [data-native-io]').click() + io_inventory={ + 'types':[{'name':'Windows Audio','separate':True, + 'inputs':['Studio Mic'],'outputs':['Speakers']}], + 'active':{'backend':'Windows Audio','captureDevice':'Studio Mic', + 'playbackDevice':'Speakers','open':True, + 'authorized':True,'deviceGeneration':23, + 'inputNames':['Mic 1'],'outputNames':['L','R'], + 'enabledInputs':[0],'enabledOutputs':[0,1], + 'rate':48000,'buffer':480, + 'rates':[48000],'buffers':[480]}} + emit(page,'arMixAudioDeviceInventory',io_inventory) + capture_select=page.locator('.armix-audio-dialog [data-audio-field="capture"]') + capture_select.select_option(value='') + assert capture_select.input_value()=='' + assert page.locator('.armix-audio-dialog [data-audio-apply]').is_enabled() + page.locator('.armix-audio-dialog [data-audio-apply]').click() + request=page.evaluate("""()=>window.__events.filter(e=> + e.payload?.action==='audioDeviceApply').at(-1)?.payload""") + assert request and request['config']['captureDevice']=='' + assert request['config']['playbackDevice']=='Speakers' + assert request['config']['enabledInputs']==[] + assert request['config']['enabledOutputs']==[] + out_active={**io_inventory['active'],'captureDevice':'', + 'inputNames':[],'enabledInputs':[]} + emit(page,'arMixAudioDeviceApplyAck',{ + 'requestId':request['requestId'],'ok':True, + 'state':'ACCEPTED_MUTED','active':out_active, + 'outputMuted':True,'mixerBound':True}) + assert page.locator('.armix-audio-shade').is_hidden() + page.locator('.command-bar [data-native-io]').click() + io_inventory['active']=out_active + emit(page,'arMixAudioDeviceInventory',io_inventory) + assert capture_select.input_value()=='' # reopening does not auto-patch a mic + page.locator('.armix-audio-dialog [data-audio-close]').click() g0=json.loads((ROOT/'integration/console-v6/fixtures.json').read_text())['g0'] g0['mixerSession']={'authority':'NONE','deviceEpoch':g0['device']['epoch'],'channels':[]} g0['legacyM4']={'active':True,'routeAccepted':False,'routingRevision':'1'} From ce326e1797abf3f89b4b9bb4e30bdb84a8443c91 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:46:05 +0700 Subject: [PATCH 021/125] fix(recovery): preserve genuine zero-capture WASAPI mixer across verified device restore Reject missing/stereo-incomplete playback but do not require a microphone when restoring the exact saved output-only endpoint. Retain DIRECT fingerprint and fail-silent guards. Repair advanced setup guidance and add regression test. --- src/LiveAudioEngine.h | 7 +++++-- src/Main.cpp | 4 ++-- tests/direct_restore_recovery_contract_test.mjs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index c6f267d56..4bc90b441 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -2545,10 +2545,13 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const juce::AudioDeviceManager::AudioDeviceSetup& expected) { const auto* active = deviceManager_.getCurrentAudioDevice(); + // A previously verified OUTPUT-ONLY mixer must be recoverable with + // the same zero-capture identity. Only the physical stereo output is + // compulsory; resumeVerifiedDirectRoute() separately rechecks exact + // backend/device/input/output masks before PCM can be armed. if (active == nullptr || deviceManager_.getCurrentAudioDeviceType() != "Windows Audio" || - active->getActiveInputChannels().isZero() || - active->getActiveOutputChannels().isZero()) return false; + active->getActiveOutputChannels().countNumberOfSetBits()<2) return false; juce::AudioDeviceManager::AudioDeviceSetup current; deviceManager_.getAudioDeviceSetup (current); return current.inputDeviceName == expected.inputDeviceName diff --git a/src/Main.cpp b/src/Main.cpp index 09f77424a..389bd7a3e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1630,11 +1630,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr else { safe->diagnostics_.record ("DIRECT_ROUTE_REJECTED", - "No valid full-duplex device; audio remains gated"); + "No verified stereo playback device; audio remains gated"); safe->emitNotice ( safe->engine_.hasRetainedUnboundMixer() ? "Mixer and plugin state retained. Device binding changed; output stays muted until a verified full-session rebind." - : "Choose a working capture and render device. Audio remains muted.", true); + : "Choose a working stereo output in Audio I/O. Input hardware is optional.", true); safe->emitApprovedNativeSnapshot(); } }); diff --git a/tests/direct_restore_recovery_contract_test.mjs b/tests/direct_restore_recovery_contract_test.mjs index 8101526d3..f91ce6bc8 100644 --- a/tests/direct_restore_recovery_contract_test.mjs +++ b/tests/direct_restore_recovery_contract_test.mjs @@ -35,6 +35,19 @@ test('actual device recoveries occur on message thread, not inside audio callbac assert.match(gate,/generation == generation_/); assert.match(gate,/State::exhausted/); }); +test('output-only SAME-device WASAPI recovery never invents or requires microphone pins',()=>{ + const begin=engine.indexOf('bool verifyRestoredDirectDevice ('); + const end=engine.indexOf('void detach()',begin); + assert.ok(begin>0&&end>begin); + const restore=engine.slice(begin,end); + assert.ok(restore.includes('active->getActiveOutputChannels().countNumberOfSetBits()<2')); + assert.ok(!restore.includes('active->getActiveInputChannels().isZero()'), + 'zero actual capture pins must not make a valid output-only mixer unrecoverable'); + assert.ok(restore.includes('current.inputDeviceName == expected.inputDeviceName')); + assert.ok(restore.includes('current.outputDeviceName == expected.outputDeviceName')); + assert.match(engine,/resumeVerifiedDirectRoute\(\)/); + assert.match(main,/No verified stereo playback device; audio remains gated/); +}); test('restore retry is bounded and disabled on success, explicit direct and setup paths',()=>{ assert.match(main,/directRestore_\.failed \(snapshot\.generation, now\)/); assert.match(main,/directRestore_\.recovered \(snapshot\.generation\)/); From 94885d7042d219aa76b2b37ab5dc6901afbc544e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:48:02 +0700 Subject: [PATCH 022/125] fix(FX): never gate compiled-in EQ, Compressor or Harmony on external VST3 scanner Keep verified third-party catalog and Show/backup/handoff gates, but make native built-in FX available on initial SOURCE NONE workspace while background plugin scan is busy. Add guard contract regression. --- src/Main.cpp | 9 +++++++-- tests/approved_native_m2_contract.test.cjs | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 389bd7a3e..d306d13c8 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1082,9 +1082,14 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity; const bool builtInHarmony=catalogId== armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity; - const auto* plugin=(builtInEq||builtInComp||builtInHarmony)?nullptr:catalog_.find(catalogId); + // Built-in DSP is compiled into the native host. Its admit + // path must remain usable even while third-party VST3 metadata + // discovery blocks or scans in the background. External + // plugins still require a fully verified, idle catalog. + const bool externalCatalog=!builtInEq&&!builtInComp&&!builtInHarmony; + const auto* plugin=externalCatalog?catalog_.find(catalogId):nullptr; std::uint64_t ep=0,rev=0,roster=0,target=0; - if((!builtInEq&&!builtInComp&&!builtInHarmony&&!plugin)||catalog_.busy()||nativeShowBusy_|| + if((externalCatalog&&(!plugin||catalog_.busy()))||nativeShowBusy_|| studioBackupBusy_||engine_.isGraphSwitchPending()) { nativeError="NATIVE_VST3_CATALOG_OR_HOST_BUSY"; } else if(!armix::console::approvedNativeId( diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 6eb2bab28..2813fdf0d 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1248,6 +1248,17 @@ test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ assert.match(bridge,/const preparedFirstSound=session\?\.authority==="NONE"/); assert.match(bridge,/const deviceReady=\(\)=>/); }); +test("P0 built-in EQ/Compressor/Harmony load independent of slow external VST3 catalog scan",()=>{ + const cpp=read("src/Main.cpp"); + const gate=cpp.slice(cpp.indexOf('const bool builtInEq=catalogId=='), + cpp.indexOf('const auto result=builtInEq?',cpp.indexOf('const bool builtInEq=catalogId=='))); + assert.ok(gate.includes('const bool externalCatalog=!builtInEq&&!builtInComp&&!builtInHarmony')); + assert.ok(gate.includes('externalCatalog&&(!plugin||catalog_.busy())')); + assert.ok(!gate.includes('||catalog_.busy()||nativeShowBusy_'), + 'third-party metadata discovery must not disable compiled-in FX'); + assert.ok(gate.includes('nativeShowBusy_')&&gate.includes('studioBackupBusy_'), + 'native structural session/backup safety interlocks remain active'); +}); test("P0 output-only Audio I/O is a real native configuration, never blocked by missing capture",()=>{ const cpp=read("src/Main.cpp"),bridge=read("web/approved-native-bridge.js"); assert.match(cpp,/const bool outputOnly=separate&&capture\.isEmpty\(\)/); From 9b128a5da66c3c4963efb475bbe8d72b8b019d39 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:54:04 +0700 Subject: [PATCH 023/125] fix(FX picker): show genuine native EQ, Compressor and Harmony before VST3 discovery Built-in JUCE processors are already present in the executable: expose them in the approved Windows picker on first paint and after every external catalog refresh. Label their real native format, without fake vendor metadata or browser DSP. --- scripts/build_approved_native_gui.py | 4 ++-- tests/approved_native_m2_contract.test.cjs | 12 ++++++++++++ web/approved-native-bridge.js | 22 +++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py index 0c7d1bcdb..c3e8e6afa 100644 --- a/scripts/build_approved_native_gui.py +++ b/scripts/build_approved_native_gui.py @@ -228,10 +228,10 @@ def accepted_pages_html() -> str: " setNativeCatalog(rows){\n" " pluginCatalog=rows.filter(x=>x&&typeof x.id==='string'&&typeof x.name==='string').map(x=>({\n" " id:x.id,name:x.name,vendor:x.vendor||'Unknown',category:x.category||'Utility',\n" - " format:'VST3',status:'ready',latencySamples:null,\n" + " format:x.format==='Native'?'Native':'VST3',status:'ready',latencySamples:null,\n" " favorite:!!x.favorite,hidden:false}));\n" " const label=document.querySelector('.plugin-disclaimer');\n" - " if(label)label.textContent='NATIVE JUCE VST3 · only verified scanned catalog entries are insertable';\n" + " if(label)label.textContent='Native EQ/Compressor/Harmony ready · external VST3 require verified scan';\n" " renderPluginCatalog();renderFastPicker();return pluginCatalog.length;\n" " },\n" " closeNativePicker(){setFastPicker(false);},\n" diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 2813fdf0d..f3741e58f 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1248,6 +1248,18 @@ test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ assert.match(bridge,/const preparedFirstSound=session\?\.authority==="NONE"/); assert.match(bridge,/const deviceReady=\(\)=>/); }); +test("P0 native built-in FX appear before vendor scan and remain after catalog refresh",()=>{ + const bridge=read("web/approved-native-bridge.js"); + const builder=read("scripts/build_approved_native_gui.py"); + for(const id of ["armix.builtin.channel-eq.v1", + "armix.builtin.channel-compressor.v1", + "armix.builtin.arson-harmony.v1"]) + assert.ok(bridge.includes('id:"'+id+'"')); + assert.ok(bridge.includes('[...nativeBuiltins,...nativeCatalog.values()]')); + assert.ok(bridge.includes('presentFxCatalog(); // compiled native FX')); + assert.ok(builder.includes("x.format==='Native'?'Native':'VST3'")); + assert.ok(!bridge.includes('scope?.setNativeCatalog?.([])')); +}); test("P0 built-in EQ/Compressor/Harmony load independent of slow external VST3 catalog scan",()=>{ const cpp=read("src/Main.cpp"); const gate=cpp.slice(cpp.indexOf('const bool builtInEq=catalogId=='), diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index e94d52274..212cb90c7 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -983,6 +983,18 @@ return true; } let pendingFxInsert=null,fxRequestSerial=0,nativeCatalog=new Map(); + // Native JUCE processors: these are real compiled DSP, not demo effects, + // scanned VST binaries, a JS renderer or placeholder library entries. + const nativeBuiltins=Object.freeze([ + Object.freeze({id:"armix.builtin.channel-eq.v1",name:"Parametric EQ", + vendor:"ArSonMix",category:"EQ",format:"Native",source:"builtin"}), + Object.freeze({id:"armix.builtin.channel-compressor.v1",name:"Compressor", + vendor:"ArSonMix",category:"Dynamics",format:"Native",source:"builtin"}), + Object.freeze({id:"armix.builtin.arson-harmony.v1",name:"ArSon Harmony", + vendor:"ArSonMix",category:"Utility",format:"Native",source:"builtin"}) + ]); + const presentFxCatalog=()=>scope?.setNativeCatalog?.( + [...nativeBuiltins,...nativeCatalog.values()]); let nativeFxDiscoveryRequested=false,nativeFxCatalogScanning=false; // Lazy USER-triggered discovery: the first Add FX opens immediately and // starts real JUCE VST3 scanning on its dedicated non-audio worker. Never @@ -2503,7 +2515,7 @@ typeof actual?.instanceId==="string"&&actual.instanceId.length){ status("CH "+(p.channel+1)+" FX loaded · verified native VST3"); scope?.closeNativePicker?.(); - scope?.setNativeCatalog?.([...nativeCatalog.values()]); + presentFxCatalog(); controller.subscribe(); }else { const reason=ack?.error||"native FX instance missing from accepted PCM"; @@ -2518,12 +2530,12 @@ nativeCatalog=new Map(catalog.items.filter(p=> p&&typeof p.id==="string"&&p.id.length>0&& typeof p.name==="string"&&p.name.length>0).map(p=>[p.id,p])); - scope?.setNativeCatalog?.([...nativeCatalog.values()]); + presentFxCatalog(); if(nativeFxDiscoveryRequested&&!nativeFxCatalogScanning&&nativeCatalog.size===0) - status("No installed VST3 discovered · use Import VST3 in Plugin Manager"); + status("Built-in FX ready · import VST3 to add more effects"); if(hardware?.raw?.legacyM4)paintM4FxInstances(hardware.raw.legacyM4); const count=document.getElementById("pluginCount"); - if(count)count.title="Verified JUCE native VST3 catalog"; + if(count)count.title="Native built-in DSP + verified VST3 catalog"; }); backend.addEventListener("arMixScanProgress",progress=>{ const statusEl=document.getElementById("pluginScanStatus"); @@ -3154,7 +3166,7 @@ const ready=()=>{ presentNativeOnlyTools(); installFirstSoundMenu(); - scope?.setNativeCatalog?.([]); // no synthetic/demo VST3 in Windows host + presentFxCatalog(); // compiled native FX, never demo or vendor placeholders updateHardwarePanel(null); stopDemo(); status("NATIVE: subscribed · waiting for true device and accepted ChannelId graph"); From 0389e7f3e5d5bef464c7ebcf63593603b257f51e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:54:31 +0700 Subject: [PATCH 024/125] test(UI): ensure built-in native FX are already in cold-start picker before VST3 scan --- tests/approved_native_cold_start_smoke.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index 3d9764280..fa4c157d2 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -41,6 +41,13 @@ def main(): addEventListener(name,callback){window.__nativeListeners.set(name,callback);}}};""") page.goto((out/'index.html').as_uri()) page.wait_for_function('()=>window.__ARMIX_NATIVE_M2__?.enabled') + # Built-in JUCE DSP must be discoverable before ANY third-party + # VST3 catalog response. The native host never inserts demo FX. + for native_id in ('armix.builtin.channel-eq.v1', + 'armix.builtin.channel-compressor.v1', + 'armix.builtin.arson-harmony.v1'): + assert page.locator('#fastResults [data-fast-id="'+native_id+'"]').count()==1, ( + 'Compiled native FX missing from cold-start picker: '+native_id) # Output-only playback is a REAL Audio I/O choice, not a hidden # capture prerequisite. Verify native intent/ACK on the approved # assembled Windows GUI at every supported viewport. From df15d63b8b63ae8dfdd417e61b963aae0ebbbd2b Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:58:06 +0700 Subject: [PATCH 025/125] test(P0): reconcile native FX catalog contract with built-in processors available before VST3 scan --- tests/approved_native_m2_contract.test.cjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index f3741e58f..2463bda6e 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -381,7 +381,10 @@ test("P0 first Add FX discovers real local VST3 lazily without an audio-thread s assert.match(bridge,/discoverFxOnFirstPickerOpen\(\);[\s\S]*?scope\?\.openFastPicker/); assert.match(native,/action == "scanVst3"[\s\S]*?catalog_\.scanDefaults\(\)/); assert.match(catalog,/struct Scanner final : juce::Thread/); - assert.match(bridge,/scope\?\.setNativeCatalog\?\.\(\[\.\.\.nativeCatalog\.values\(\)\]\)/); + // The approved picker publishes real compiled-in FX independently of + // external scanner state; the verified VST3 library follows those entries. + assert.match(bridge,/const presentFxCatalog=\(\)=>scope\?\.setNativeCatalog\?\.\(/); + assert.ok(bridge.includes('[...nativeBuiltins,...nativeCatalog.values()]')); // Neither startup nor audio callback can trigger a surprise system scan. assert.doesNotMatch(bridge.slice(0,bridge.indexOf("function discoverFxOnFirstPickerOpen")), /action:"scanVst3"/); @@ -563,7 +566,8 @@ test("P0 WIRE-to-MAIN and channel OUT use one acknowledged native transaction",( assert.match(native,/engine_\.repatchDryRoutingLabChannel\(channel,/); assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\)/); assert.match(builder,/closeNativePicker\(\)\{setFastPicker\(false\);\}/); - assert.match(builder,/NATIVE JUCE VST3/); + assert.match(builder,/Native EQ\/Compressor\/Harmony ready/); + assert.match(builder,/external VST3 require verified scan/); assert.doesNotMatch(bridge,/AudioContext|AudioWorklet/); }); test("P0 typed mono-stereo, PAN detent, fader geometry & FX failure diagnostics",()=>{ From bdfa32ce2f06a52128331a301d55ca32fa6794b0 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 17:58:22 +0700 Subject: [PATCH 026/125] feat(harmony): P1 deterministic singer ensemble space with independent timing, intonation and early reflections --- ..._NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md | 29 ++++++ engine/builtin_fx/HarmonyDsp.h | 50 +++++++--- engine/builtin_fx/HarmonyEnsembleSpace.h | 94 +++++++++++++++++++ tests/harmony_dsp_test.cpp | 85 +++++++++++++++++ 4 files changed, 246 insertions(+), 12 deletions(-) create mode 100644 engine/builtin_fx/HarmonyEnsembleSpace.h diff --git a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md index 012c9ea76..fb0aee62a 100644 --- a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md +++ b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md @@ -44,3 +44,32 @@ This is functional prototype pitch-shifting, **not** a formant-stable choir mode 5. Actual ASIO physical FAT at 48/96 kHz, 64/128/256 frames: CPU time distribution p95/p99, deadline margin and XRUNs with 2/3/5 voices and multiple mixer plugins, hot graph/device rebind. These results cannot be inferred from ordinary GitHub Actions. **Non-claim:** The present PR does not yet implement or certify natural formants, an acoustic spatial engine, or a shorter engine PDC. Changing those requires measured code, CTest, render comparisons, audio A/B and physical ASIO proof. + +## 2026-11-09 P1 implemented — bounded singer individuation and early room + +New `engine/builtin_fx/HarmonyEnsembleSpace.h` defines five deterministic +backing singer identities, allocated as fixed-size fields and prepared on the +control thread. Each has its own arrival offset (5–17ms), phase and slight +detune (~1–3 cents) with onset-ramped, subtle 4.5–5.35Hz vibrato, and a +mild unique timbre coefficient. Up to five fixed 4096-sample reflection rings +supply one integer-delay, opposite-side quiet early reflection (12–20ms). +The same existing `Space` control now governs moderate pan width and +room amount, without adding another GUI mode or `.smix` schema field. + +No `sin`, `pow`, heap allocation, locks, worker or buffered audio queue +runs inside callback; each singer's LFO uses control-thread sine LUT. All +reflection histories advance when backing voices are inactive so stale FX +cannot reappear. No native graph, VST3, ASIO callback owner, slider/preset, +transport or routing changes. Plugin PDC remains 1536 samples @48k +(32ms). Vocal backing output is intentionally slightly later than the +lead, rather than delaying the lead itself: this is *musical onset and +depth*, NOT an additional reported whole-plugin latency. + +Acceptance includes fixed-tap reflection impulse at 32–192k, isolation +between singers, bounded detune/vibrato and mono-compatible 3-voice +stereo field at 48/96k. Existing PCM block-partitioning, host bypass, +anti-phase dry and realtime CPU diagnostic still apply. This is a P1 +ensemble-spatial realism increment, **not a formant-preserving +resynthesis fix**. The original two-grain pitch shifter can still sound +robotic on real recorded consonants and wide intervals. It requires a +separate pitch-synchronous/formant-aware algorithm and A/B acoustic gate. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 0116b81ed..ebc9a5a7e 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -7,6 +7,7 @@ #include #include "HarmonyStereoFold.h" #include "HarmonyPreparedTone.h" +#include "HarmonyEnsembleSpace.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -86,10 +87,15 @@ class Engine final { if(lowLag_>=highLag_||latency_+3*grain_>=static_cast(capacity))return false; left_.fill(0.f);right_.fill(0.f);mono_.fill(0.f);decimated_.fill(0.f); filtered_.fill(0.f);phase_.fill(0.f);ratio_.fill(1.f);targetRatio_.fill(1.f); + // Independent grain clocks avoid five identical backing-singer seams. + // Lead correction keeps its neutral original phase. + for(int v=0;v(v)]=.157f*static_cast(v); // Low-pass before downsampling: raw 12 kHz decimation aliases vocal sibilants // into the periodicity detector and destabilizes the live note readback. decimationLowpass_=0.f; - if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate))return false; + if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate)|| + !ensemble_.prepare(rate))return false; pitchIntervals_.prepare(); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); @@ -123,7 +129,9 @@ class Engine final { constexpr float pi=3.14159265358979323846f; const float amplitude=next.wet*0.65f/std::sqrt(static_cast(next.voices)); for(int v=0;v(v)/(next.voices-1)-1.f); + // Width is moderate even at the center-friendly default Space. + const float pan=.72f*next.space* + (2.f*static_cast(v)/(next.voices-1)-1.f); const float angle=(pan+1.f)*pi*0.25f; prepared.mixL[v]=amplitude*std::cos(angle); prepared.mixR[v]=amplitude*std::sin(angle); @@ -145,6 +153,7 @@ class Engine final { } settings_=next.settings; targetWet_=next.settings.wet;targetColor_=next.settings.color; + targetSpace_=next.settings.space; targetGain_=next.gain; targetCorrection_=next.settings.correction?1.f:0.f; for(int v=0;v(v)]=next.mixR[v]; } if(!processed_){ - wet_=targetWet_;color_=targetColor_;gain_=targetGain_; + wet_=targetWet_;color_=targetColor_;space_=targetSpace_; + gain_=targetGain_; correctionMix_=targetCorrection_; mixL_=targetMixL_;mixR_=targetMixR_; } @@ -198,6 +208,7 @@ class Engine final { const float a=smoothingAlpha_; wet_+=a*(targetWet_-wet_); color_+=a*(targetColor_-color_); + space_+=a*(targetSpace_-space_); gain_+=a*(targetGain_-gain_); correctionMix_+=a*(targetCorrection_-correctionMix_); for(int v=0;v0.00001f){ - for(int v=0;v(v); - if(std::abs(mixL_[ix])+std::abs(mixR_[ix])<1.e-5f)continue; - const float y=shifted(v,filterCoef)*voicedGain_; - outL+=y*mixL_[ix];outR+=y*mixR_[ix]; + // A small, non-negative opposite-side early reflection makes a + // backing voice recede without phase widening or extra reverb FX. + // All rings advance even while muted, preventing stale FX tails. + const float roomAmount=.13f*space_; + for(int v=0;v(v); + const bool audible=voicedGain_>0.00001f&& + std::abs(mixL_[ix])+std::abs(mixR_[ix])>=1.e-5f; + float voice=0.f; + if(audible){ + voice=shifted(v,ensemble_.timbreCoefficient(v,filterCoef), + ensemble_.arrivalSamples(v), + ensemble_.pitchRatio(v))*voicedGain_; } + const float reflection=ensemble_.exchangeReflection(v,voice); + outL+=voice*mixL_[ix]+reflection*mixR_[ix]*roomAmount; + outR+=voice*mixR_[ix]+reflection*mixL_[ix]*roomAmount; } l[i]=std::clamp(outL*gain_,-4.f,4.f); r[i]=std::clamp(outR*gain_,-4.f,4.f); + ensemble_.advance(voiced_); write_=(write_+1)%capacity; } } @@ -263,13 +285,15 @@ class Engine final { const auto a1=(a0+capacity-1)%capacity; return a[a0]*(1.f-f)+a[a1]*f; } - float shifted(int voice,float filterCoef) noexcept { + float shifted(int voice,float filterCoef,float arrival=0.f, + float fineRatio=1.f) noexcept { float& currentRatio=ratio_[static_cast(voice)]; currentRatio+=(targetRatio_[static_cast(voice)]-currentRatio)*ratioAlpha_; + const float effectiveRatio=std::clamp(currentRatio*fineRatio,.49f,2.01f); const float p=phase_[static_cast(voice)]; const float pB=p<0.5f?p+0.5f:p-0.5f; - const float delayA=2.f*grain_+(1.f-currentRatio)*p*grain_; - const float delayB=2.f*grain_+(1.f-currentRatio)*pB*grain_; + const float delayA=2.f*grain_+arrival+(1.f-effectiveRatio)*p*grain_; + const float delayB=2.f*grain_+arrival+(1.f-effectiveRatio)*pB*grain_; // Cubic smoothstep over the complementary two-grain windows. // Unlike the triangular seam, both endpoints have zero slope: // reduced grain-edge modulation without sin/cos in audio callback. @@ -423,12 +447,14 @@ class Engine final { bool processed_=false; float smoothingAlpha_=1.f,voicedGateAlpha_=0.002f,ratioAlpha_=0.00045f; float wet_=0.f,targetWet_=0.f,color_=0.f,targetColor_=0.f; + float space_=0.f,targetSpace_=0.f; float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; float decimationLowpass_=0.f,decimationAlpha_=0.f; StereoPhaseSafeFold vocalFold_{}; RateStableColor toneColor_{}; PreparedPitchIntervals pitchIntervals_{}; + EnsembleSpace ensemble_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyEnsembleSpace.h b/engine/builtin_fx/HarmonyEnsembleSpace.h new file mode 100644 index 000000000..6cf38eeaa --- /dev/null +++ b/engine/builtin_fx/HarmonyEnsembleSpace.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// Deterministic, bounded, single-audio-owner backing-singer individualization. +// Prepared on non-realtime thread. No random generator, heap, mutex, worker +// or transcendental functions in the PCM callback. +namespace armix::harmony { +class EnsembleSpace final { +public: + static constexpr int voices=5; + static constexpr std::size_t reflectionCapacity=4096; + static constexpr std::size_t sineCount=1024; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + constexpr float tau=6.2831853071795864769f; + constexpr std::array arrivalMs{{5.f,9.f,12.f,15.f,17.f}}; + constexpr std::array reflectionMs{{12.f,15.f,17.f,19.f,20.f}}; + constexpr std::array cents{{-2.8f,1.4f,3.2f,-1.7f,2.3f}}; + constexpr std::array vibratoHz{{4.7f,5.2f,4.9f,5.35f,4.55f}}; + constexpr std::array vibratoCents{{2.4f,3.0f,2.8f,2.6f,3.3f}}; + constexpr std::array timbre{{.93f,.86f,.96f,.89f,.83f}}; + for(std::size_t i=0;i(i)/sineCount); + for(int v=0;v(v); + offset_[ix]=static_cast(rate*arrivalMs[ix]*.001); + reflectionDelay_[ix]=static_cast(std::lround(rate*reflectionMs[ix]*.001)); + if(reflectionDelay_[ix]<2|| + reflectionDelay_[ix]>=static_cast(reflectionCapacity))return false; + ratio_[ix]=std::pow(2.f,cents[ix]/1200.f); + vibratoRatio_[ix]=vibratoCents[ix]*(.69314718056f/1200.f); + increment_[ix]=vibratoHz[ix]/static_cast(rate); + phase_[ix]=static_cast(ix)*.197f; + tone_[ix]=timbre[ix]; + reflections_[ix].fill(0.f); + } + ageStart_=static_cast(rate*.065); + ageRamp_=static_cast(1./(rate*.165)); + age_=0;cursor_=0; + return true; + } + float arrivalSamples(int v) const noexcept { + return offset_[static_cast(v)]; + } + int reflectionSamples(int v) const noexcept { + return reflectionDelay_[static_cast(v)]; + } + float timbreCoefficient(int v,float colorCoefficient) const noexcept { + return colorCoefficient*tone_[static_cast(v)]; + } + // All 5 LFOs have independent, deterministic phase and frequency. + // Sustain vibrato appears gradually; no per-block reset or random jitter. + float pitchRatio(int v) noexcept { + const auto i=static_cast(v); + const float position=phase_[i]*static_cast(sineCount); + const auto index=static_cast(position); + const auto following=(index+1)&(sineCount-1); + const float fraction=position-static_cast(index); + const float wave=sine_[index]+(sine_[following]-sine_[index])*fraction; + phase_[i]+=increment_[i]; + if(phase_[i]>=1.f)phase_[i]-=1.f; + const float mature=std::clamp((age_-ageStart_)*ageRamp_,0.f,1.f); + return ratio_[i]*(1.f+wave*vibratoRatio_[i]*mature); + } + // Exactly one filtered early reflection from each independent singer. + // Fixed integer tap delay: changing Space can never sweep a delay line + // or create a pitch chirp. 4096 samples covers 20ms even at 192k. + float exchangeReflection(int v,float sample) noexcept { + const auto i=static_cast(v); + reflections_[i][cursor_]=sample; + const auto delayed=(cursor_+reflectionCapacity- + static_cast(reflectionDelay_[i]))&(reflectionCapacity-1); + return reflections_[i][delayed]; + } + void advance(bool voiced) noexcept { + cursor_=(cursor_+1)&(reflectionCapacity-1); + if(!voiced)age_=0; + else if(age_<100000000)++age_; + } +private: + std::array sine_{}; + std::array,voices> reflections_{}; + std::array offset_{},ratio_{},vibratoRatio_{}; + std::array increment_{},phase_{},tone_{}; + std::array reflectionDelay_{}; + std::size_t cursor_=0; + int age_=0,ageStart_=0; + float ageRamp_=0.f; +}; +} // namespace armix::harmony diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 1980fea13..00d77179b 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -451,6 +451,91 @@ int main(){ need(std::isfinite(y)&&std::abs(y)<=4.f, "P0 guide PCM overflowed in stereo analysis fold"); } + + // P1 natural ensemble: each singer owns a distinct stable arrival time, + // vibrato phase/rate and early-reflection history. No heap or random PCM + // work is introduced, and reflections must not bleed between singers. + for(double rate:{32000.,48000.,96000.,192000.}){ + auto ensemble=std::make_unique(); + need(ensemble->prepare(rate),"ensemble prepare rejected supported rate"); + need(ensemble->arrivalSamples(0)>0.f&& + ensemble->arrivalSamples(2)>ensemble->arrivalSamples(1), + "independent singer onset offsets not prepared"); + need(ensemble->reflectionSamples(4)( + EnsembleSpace::reflectionCapacity), + "highest-rate reflection would read outside fixed history"); + const int delay=ensemble->reflectionSamples(0); + for(int i=0;i<=delay+5;++i){ + for(int v=0;vexchangeReflection(v,input); + const float expected=(i==delay&&v==0)?1.f:0.f; + need(std::abs(out-expected)<1.e-6f, + "ensemble reflection delay or channel isolation broken"); + } + ensemble->advance(true); + } + float minRatio=2.f,maxRatio=0.f; + const int sustain=static_cast(rate*.60); + for(int i=0;ipitchRatio(0); + const float b=ensemble->pitchRatio(1); + need(std::isfinite(a)&&std::isfinite(b)&&a>.996f&&a<1.004f&& + b>.996f&&b<1.004f, + "ensemble vibrato/detune exceeds transparent musical bounds"); + minRatio=std::min(minRatio,a);maxRatio=std::max(maxRatio,a); + ensemble->advance(true); + } + need(maxRatio-minRatio>0.0004f, + "ensemble vocalist lacks independent sustain modulation"); + ensemble->advance(false); + } + // At Space=0 mono input stays mono with no reflected crossfeed. At + // Space=1, three distinct backing singers must form true stereo PCM, + // while the singer's dry path keeps its declared delay and center. + for(double rate:{48000.,96000.}){ + constexpr int samples=48000; + std::vector zeroL(samples),zeroR(samples); + std::vector wideL(samples),wideR(samples); + auto center=std::make_unique(); + auto wide=std::make_unique(); + need(center->prepare(rate)&&wide->prepare(rate), + "ensemble space engine prepare failed"); + Settings narrow; narrow.voices=3;narrow.wet=.6f;narrow.space=0.f; + Settings spread=narrow;spread.space=1.f; + need(center->setSettings(narrow)&&wide->setSettings(spread), + "ensemble controls not accepted"); + for(int i=0;i(.16*std::sin( + 6.283185307179586*220.*i/rate)+.05*std::sin( + 6.283185307179586*440.*i/rate)); + zeroL[static_cast(i)]=zeroR[static_cast(i)]=x; + wideL[static_cast(i)]=wideR[static_cast(i)]=x; + } + for(int i=0;iprocess(zeroL.data()+i,zeroR.data()+i,len); + wide->process(wideL.data()+i,wideR.data()+i,len); + } + double centerDifference=0.,spreadDifference=0.,wideEnergy=0.,foldEnergy=0.; + for(int i=samples/2;i(i)]- + zeroR[static_cast(i)]); + spreadDifference+=std::abs(wideL[static_cast(i)]- + wideR[static_cast(i)]); + const double x=.5*(wideL[static_cast(i)]+ + wideR[static_cast(i)]); + wideEnergy+=wideL[static_cast(i)]* + wideL[static_cast(i)]+ + wideR[static_cast(i)]* + wideR[static_cast(i)]; + foldEnergy+=x*x; + } + need(centerDifference<.0001, + "Space zero leaked phase-widened stereo or unbalanced rooms"); + need(spreadDifference>0.5&&wideEnergy>1.&&foldEnergy>.1, + "ensemble room has no stereo depth or loses mono compatibility"); + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; From 6f1338efb2f20692ecbe57a499efe32a609ee5f7 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 18:04:20 +0700 Subject: [PATCH 027/125] fix(P0): restore durable .smix over pristine native SOURCE NONE starter on cold boot The always-on ChannelId graph is real PCM, but on fresh startup must not make the saved Show unrecoverable. Permit replaceActive only for unmodified silent starter on exact verified device; do not overwrite authored FX/WIRE/track edits. Prove native 0-input saved Show restoration and regression safety. --- src/LiveAudioEngine.h | 5 +++++ src/LiveDryRoutingLab.h | 12 +++++++++++ src/Main.cpp | 17 +++++++++++++--- tests/approved_native_m2_contract.test.cjs | 12 +++++++++++ tests/native_mixer_session_store_test.cpp | 23 ++++++++++++++++++++++ 5 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 4bc90b441..a7e892f31 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1592,6 +1592,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return {}; } + // Cold-start restore ONLY: the installed native SOURCE NONE starter has + // never been edited, so the durable saved Show can safely take ownership. + bool hasPristineStartupMixer() const noexcept { + return dryRoutingLab_.canReplacePristineStartupMixer(); + } std::uint64_t dryRoutingLabEpoch() const noexcept {return dryRoutingLab_.epoch();} std::uint64_t dryRoutingLabRevision() const noexcept {return dryRoutingLab_.revision();} std::uint64_t outputArmRevision() const noexcept {return dryRoutingLab_.controlRevision();} diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 49c77cd75..932554589 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -2438,6 +2438,18 @@ class LiveDryRoutingLab final { return channelIdPhysicalPcmActive() && nativeStructureLive_ ?nativeAccepted_.pcmRevision:revision(); } + // The first accepted SOURCE NONE ChannelId graph is a disposable + // bootstrap topology, not an authored Show. A persisted .smix may replace + // it once on cold start; any accepted FX, control, WIRE, BUS or source + // mutation immediately makes that replacement unsafe. + // CONTROL THREAD ONLY: hasAuthoredMixerContent traverses roster/FX. + bool canReplacePristineStartupMixer() const noexcept { + return channelIdPhysicalPcmActive() && sourceTemplate_.isObject() && + !acceptedRoute_.isObject() && !nativeStructureLive_ && + !nativeControlDirty_ && nativeAccepted_.fxOwners && + nativeAccepted_.graph.request.sources.empty() && + !hasAuthoredMixerContent(); + } bool hasVerifiedNativeSources() const noexcept { return channelIdPhysicalPcmActive() && !nativeAccepted_.graph.request.sources.empty(); } diff --git a/src/Main.cpp b/src/Main.cpp index d306d13c8..9e407759f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2217,11 +2217,22 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr !usedPrevious && !retained && doc.resumeMain.value_or(true); const auto live=engine_.status().getProperty("dryRoutingLab",{}); - if(static_cast(live.getProperty("nativeChannelIdPcmActive",false))) { + const bool nativeAlreadyActive=static_cast( + live.getProperty("nativeChannelIdPcmActive",false)); + // A fresh silent ChannelId starter is now admitted before the saved + // Show is inspected. Only THAT unmodified bootstrap may be replaced, + // and only by this automatic cold-start restore. User-authored FX, + // WIRE, BUS and fader edits must never be overwritten by late scan. + const bool replacePristineStartup=nativeAlreadyActive && + startupOnSavedDevice && !retained && !usedPrevious && + bindingMode==armix::session::MixerDeviceBindingPolicy::Mode::exact && + engine_.hasPristineStartupMixer(); + if(nativeAlreadyActive && !replacePristineStartup) { mixerSessionStatus_="LIVE_MIXER_UNCHANGED"; - return "Live native mixer already active; refusing to replace it"; + return "Live native mixer already edited; refusing to replace it"; } - error=engine_.restoreNativeMixerSession(std::move(doc),states,false,nullptr,bindingMode); + error=engine_.restoreNativeMixerSession(std::move(doc),states, + replacePristineStartup,nullptr,bindingMode); if(error.isNotEmpty()) { mixerSessionStatus_=error.contains("NEEDS_REMAP") ?"NEEDS_REMAP":"RESTORE_REJECTED"; diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 2463bda6e..57ec4c39d 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1242,6 +1242,18 @@ test("P0 native FX rack and per-slot readback update mounted strip without repla assert.equal(paints,2,"an actual VST instance identity change MUST re-project"); }); +test("P0 automatic cold-start Show replaces only pristine SOURCE NONE ChannelId",()=>{ + const main=read('src/Main.cpp'); + const engine=read('src/LiveAudioEngine.h'); + const route=read('src/LiveDryRoutingLab.h'); + assert.match(main,/startupOnSavedDevice && !retained && !usedPrevious/); + assert.match(main,/engine_\.hasPristineStartupMixer\(\)/); + assert.match(main,/restoreNativeMixerSession\(std::move\(doc\),states,\s*replacePristineStartup/); + assert.match(engine,/dryRoutingLab_\.canReplacePristineStartupMixer\(\)/); + assert.match(route,/bool canReplacePristineStartupMixer\(\) const noexcept/); + assert.match(route,/!nativeControlDirty_ && nativeAccepted_\.fxOwners/); +}); + test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ const bridge=read("web/approved-native-bridge.js"); assert.match(bridge,/SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK/); diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 952281888..3dadd54e1 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -107,6 +107,28 @@ static void outputOnlyNativeStartup() { assert(!mixer.admitChannelIdFromAcceptedM4(0,480,true)); assert(mixer.admitChannelIdFromAcceptedM4(0,480,true,{},true)); assert(mixer.hasExplicitRoute() && !mixer.hasVerifiedNativeSources()); + assert(mixer.canReplacePristineStartupMixer()); + // Startup automatically restores an existing .smix on precisely the + // same verified device. The saved Show must win over a never-edited + // SOURCE NONE starter, without a second publisher/audio callback. + { + auto saved=makeSession(); + saved.binding={"Windows Audio","","Verified WASAPI fixture","0","3",48000.,480}; + saved.request.physicalInputs=0; + saved.request.sources.clear(); + saved.request.maxFrames=480; + saved.rackBypassed.clear(); + armix::device::JuceActivePortSnapshot pins; + armix::device::JuceActivePortSnapshot::Fault fault; + assert(armix::device::JuceActivePortSnapshot::capture(&playback,mixer.epoch(),pins,fault)); + std::shared_ptr bank; + const auto prepare=NativeMixerSessionFxRestore::prepare(saved,{},formats, + 48000.,480,pins.epoch,mixer.nativeGraphRevisionForRestore(),bank); + assert(prepare.isEmpty() && bank); + assert(mixer.restoreNativeMixerSession(saved,std::move(bank),pins,true,true).isEmpty()); + assert(!mixer.canReplacePristineStartupMixer()); // saved Show is now authored + assert(mixer.hasExplicitRoute() && !mixer.hasVerifiedNativeSources()); + } const auto native=mixer.nativeBusStatus(); assert(native.isObject()); const auto graph=static_cast( @@ -116,6 +138,7 @@ static void outputOnlyNativeStartup() { const auto add=mixer.createNativeInputChannel(mixer.epoch(),graph,roster, "No Microphone Track",ProcessingFormat::stereo,true); assert(add.accepted && !mixer.hasVerifiedNativeSources()); + assert(!mixer.canReplacePristineStartupMixer()); // edited graph can never be replaced std::array left{},right{}; left.fill(1.f);right.fill(1.f); // must be cleared, not fake audio float* outputs[]={left.data(),right.data()}; From 9f1b5b5ac5ba4144a1c3ea3b0e4f7357a3571035 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 18:05:29 +0700 Subject: [PATCH 028/125] fix(recovery): permit verified previous checkpoint to replace untouched cold-start graph --- src/Main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main.cpp b/src/Main.cpp index 9e407759f..c2332c784 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2223,8 +2223,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Show is inspected. Only THAT unmodified bootstrap may be replaced, // and only by this automatic cold-start restore. User-authored FX, // WIRE, BUS and fader edits must never be overwritten by late scan. + // A verified PREVIOUS checkpoint is also eligible: the separate + // resume policy keeps MAIN muted after recovery from corrupt HEAD. const bool replacePristineStartup=nativeAlreadyActive && - startupOnSavedDevice && !retained && !usedPrevious && + startupOnSavedDevice && !retained && bindingMode==armix::session::MixerDeviceBindingPolicy::Mode::exact && engine_.hasPristineStartupMixer(); if(nativeAlreadyActive && !replacePristineStartup) { From 36a9bccb7c1c9e90c2133d5574953eaf36f7694d Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 18:05:43 +0700 Subject: [PATCH 029/125] test(recovery): verified previous .smix can replace pristine starter while MAIN remains muted --- tests/approved_native_m2_contract.test.cjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 57ec4c39d..51f903a50 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1246,7 +1246,9 @@ test("P0 automatic cold-start Show replaces only pristine SOURCE NONE ChannelId" const main=read('src/Main.cpp'); const engine=read('src/LiveAudioEngine.h'); const route=read('src/LiveDryRoutingLab.h'); - assert.match(main,/startupOnSavedDevice && !retained && !usedPrevious/); + assert.match(main,/startupOnSavedDevice && !retained &&/); + assert.doesNotMatch(main,/startupOnSavedDevice && !retained && !usedPrevious/); + assert.match(main,/!usedPrevious && !retained/); // only normal auto-resume, not recovery admission assert.match(main,/engine_\.hasPristineStartupMixer\(\)/); assert.match(main,/restoreNativeMixerSession\(std::move\(doc\),states,\s*replacePristineStartup/); assert.match(engine,/dryRoutingLab_\.canReplacePristineStartupMixer\(\)/); From f40d419b4122494c6988e4170d89b5ed3171f7a2 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 18:54:48 +0700 Subject: [PATCH 030/125] docs(harmony): PRD and ARD for backing-only perceived depth and lead preservation --- ...ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md | 66 +++++++++++++++++++ ...RD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md | 45 +++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md create mode 100644 docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md diff --git a/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md new file mode 100644 index 000000000..ec4420bf0 --- /dev/null +++ b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md @@ -0,0 +1,66 @@ +# ARD — ArSon Harmony FX Backing-Only Spatial Depth Engine (v1.0) +**Date:** 2026-11-09 · **Status:** Proposed architecture with staged implementation checks +**Scope:** Native built-in Harmony on PR #487; companion [PRD](PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md) and [Natural Ensemble](ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md). + +## Evidence-led acoustic model +Human auditory distance relies on **direct/reverberant energy ratio**, overall source level, spectral balance and interaural cues. Increasing reverberant ratio commonly signals greater distance; absolute physical distance cannot be inferred from a simple Space knob. First-arriving direct sound determines much of localization (precedence); a small number of obvious repeats can produce slap/comb effects rather than a coherent room. More high-frequency absorption is a mixing cue, but **air absorption over just a few metres does not justify extreme LPF**. For a live singer, masking and consonant smearing are unacceptable. + +- Bronkhorst & Houtgast, *Nature* 1999, distance versus DRR: https://www.nature.com/articles/17374 +- Zahorik review, distance, intensity, DRR, spectral and interaural cues: https://pmc.ncbi.nlm.nih.gov/articles/PMC4744263/ +- Litovsky et al. review of the precedence effect: https://pmc.ncbi.nlm.nih.gov/articles/PMC4310855/ +- JASA 2025 frontal distance study (DRR or spectral centroid best single cue): https://pubmed.ncbi.nlm.nih.gov/40928551/ +- Sound on Sound depth mixing (level/EQ/diffuse reverb versus clarity): https://www.soundonsound.com/techniques/creating-sense-depth-your-mix +- iZotope mix depth: https://www.izotope.com/community/blog/what-is-mix-depth-how-to-create-front-back-space +- FDN theory / realtime late room: https://artificial-audio.github.io/portfolio/fdn/ + +## Before: audited exact C++ issue +`engine/builtin_fx/HarmonyDsp.h::process` mixes lead with +`(1.f - wet_*0.65f*voicedGain_)` despite the lead being dry; at Wet=.45 / voicedGain=1 this is about -3 dB lead. This is **gain duck**, not proof of phase cancellation. Current `HarmonyEnsembleSpace.h` adds one early opposite-side tap/voice but has **no diffuse late field**. At most it generates scattered echoes and pan; it does not control DRR as an acoustic scene. + +## One-source, one-room block graph +```text +Mono mic PCM + accepted ChannelId / native graph + | + +--> phase-safe analysis / voice targets --> pitch shifters (2-5) + | | + | +--> independent singer onset / timbre / pitch modulation + | | + | +--> short direct backing L/R (Space-dependent attenuation) + | +--> per-singer fixed-tap filtered early reflections + | +--> ONE shared small stereo diffuse late field [FDN] + | (backing send ONLY; fixed delay, stable feedback) + | + +--> exact delayed native L/R lead --> optional explicitly enabled Pitch Tune + | | + +-----------------------------> sum w backing L/R + -> explicit Gain -> existing PCM bus +``` +Only existing `Settings::space`, wet, color and voices. No new scene schema, plugin routing, hidden monitor step, GUI Lab, or second ownership. `Space=0` disables audible room, not the valid PCM path. Diffuse field is never fed with lead. + +## Time/frequency strategy +- **Front:** lead unchanged by wet, stereo and sample latency untouched. Pitch Tune explicitly replaces/corrects when user enables it; never implied by Wet. +- **Direct backup:** keep existing individually phase-offset 5–17 ms arrival, deterministic cent modulation and prepared pan L/C/R. At increasing Space, reduce direct backing gain mildly (candidate 0dB to -4dB) so backing remains intelligible but moves behind. +- **Backstage spectral contour:** one sample-rate-normalized low-pass in each voice with a smooth dry/filtered crossfade, evaluated on backing only. Candidate corner around 3–6 kHz and partial dry retention; do not physically claim air propagation at 3 m. +- **Early field:** use existing per-voice 12–20 ms fixed taps, with mild high-frequency damping and side distribution; no modulation of the delay tap by Space (avoids Doppler/comb chirp). +- **Late field:** one shared bounded 4-branch stereo feedback delay network (FDN), fixed integer delay lines with different non-harmonic lengths and a normalized Hadamard feedback transform. Feedback damping and per-line gain computed in non-RT `prepare(rate)` to target about 0.45–0.7 s decay. Conservative energy normalization, filtered output, no runaway or metallic tonal build-up. First prototype is room **ambience**, not cathedral/hall reverb. +- **Control:** `space` interpolates smoothly across width, direct gain, backing brightness, early/late send and return. `wet` scales backing energy only; disabled or Wet=0 must not leak old tail. All coefficients finite and clamped. No audio-owner reallocation or blocking. + +## Proposed bounded C++ data ownership +- `HarmonyEnsembleSpace.h`: per-voice onset, identity modulation and 4096-sample early reflection rings; optional per-voice damping state. Precompute sample-rate coefficients on CONTROL `prepare(rate)`; callback only adds/multiplies. +- `HarmonyDepthRoom.h`: 4 shared, 8192-sample float delay rings (128 KiB); 4 damping states; 4 feedback gains; 1 monotonic write index. Delays up to 41 ms at 192k remain in bounds. A 4x4 orthonormal Hadamard transformation (scale 0.5) ensures controlled feedback energy. No `new`, FFT, `pow`, `sin`, `log`, device calls or synchronization in `processSample`. +- `HarmonyDsp.h`: keep lead path independent of `wet`; accumulate backing direct and early/late sends by voice, shared stereo room returns only in wet branch. Use existing 5-ms control smoothing and fixed instance state. +- Single publisher and callback: preserve bridge ACK/readback/graph lease, `ChannelHarmonyProcessor`, SPSC packets and `latencySamples()`. Declared PDC remains 1536 samples @48k until evidence warrants an independent P0 latency redesign. + +## Risks, failure behavior and test design +| Risk | Defensive behavior / evidence | +|---|---| +| Room self-oscillation / metallic flutter | Precomputed feedback magnitude <1 and damping, orthogonal matrix; impulse decay < target floor by ~2 seconds; 32/44.1/48/96/192k CTest and extended silence | +| Mono cancellation / comb | Positive-polarity forward dry, no artificial anti-phase width; L+R output energy with 2/3/5 voices >0 and lead parity; evaluate ER frequency response with real voice | +| Space automation chirping | Interpolate gains/filter coefficients, **not** delay lengths; test 0->1->0 at arbitrary 64-sample boundaries, output finite without transient spike | +| Lead duck | Unit check dry equals original delayed PCM at wet=0,45,100 and multiple Space; actual lead equation cannot reference Wet | +| Reverb masks lyrics | Limit room gain, high-pass/LP spectrally soften only wet room; compare consonant intelligibility, DRR as measured against current impl | +| Real singer still robot | Keep depth independent; this architecture doesn't solve formant/grain synthesis; P0 resynthesis follows separate proof | +| Device restart / session | `prepare(rate)` resets room/filters and restarts deterministic state, no stale room tail from previous device; maintain GUI native ACK identity | + +## No shortcut quality declaration +Do not equate "FDN compiled" with “feels like three people metres away.” First require baseline/updated dry and backing stems rendered at level parity, mono/stereo blind A/B for perceived front-back ranking, listening through nearfields/headphones/mono laptop speaker, and actual ASIO 48/96 kHz 64/128/256 buffers with full mixer FX rack and CPU p95/p99/XRUN data. The desired response is **distant but distinct, not washed out**. Exact room dimensions and HRTF positioning are not implemented and must not be shown as facts in GUI. diff --git a/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md new file mode 100644 index 000000000..3a8d97827 --- /dev/null +++ b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md @@ -0,0 +1,45 @@ +# PRD — ArSon Harmony FX: Natural Backing Vocal Depth (v1.0) +**Date:** 2026-11-09 · **Status:** Binding product target, not a claim of acoustic quality achieved +**Owner scope:** ArSonMix native built-in Harmony on draft PR #487. Preserve the approved compact Harmony editor, same .smix schema, native PCM ownership, and auto-rebinding DSP/GUI. +**Related:** [Natural Ensemble architecture](ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md) · [Harmony engine audit](ARSON_HARMONY_ENGINE_AUDIT_20261108.md) · [Depth engine ARD](ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md) + +## User outcome / job to be done +One live singer should remain **clearly in front and unmistakably themselves**. Enabling 3 harmony backing singers should sound like **three people standing farther back**—mildly left, inner-center and mildly right in a coherent shared acoustic space. Harmony must not replace, cancel, phase-comb or automatically duck the original singer. When harmony is muted/off/at Wet 0, the same dry vocal must be preserved exactly except declared latency/PDC, explicitly selected pitch correction and global Gain. + +Users currently report a robotic/noise-like stack with little natural back/front separation. This is a P0 sound-quality defect, not solved by more panning or simply adding vibrato or wet reverb. The original 2-grain pitch-shifter is **still unqualified on singer recordings**; adding depth is a separate measurable, staged milestone. + +## Native one-knob user workflow +- The single existing **Space** knob remains the primary distance/width control; no Room Lab, advanced switches, extra dialog, permission gate or mandatory mixer routing. Wet controls backing strength; Color controls timbral brightness; Gain remains explicit output gain. +- At **Space 0**: compact, center-dominant dry backing (little/no backing reflection), lead still forward. +- At **Space 0.6 (factory default)**: audible but unobtrusive backing group a few steps behind, with left/near-center/right separation. Depth comes from lower backing direct level relative to reflected/diffuse sound, smooth upper timbre, modest onset offset and coherent short room, **not arbitrary meters or fake 3D localization**. +- At **Space 1**: noticeably deeper backing; no excessively long tails, discrete echo, metallic ring, mono disappearing vocals or extra lead level loss. Space automation must not sweep variable delay taps. +- **Wet 0 or rack bypass**: backing and its room must not leak into the monitoring output. Switching the rack on/off must follow native state, no GUI-only fake effect. +- **Music / Manual Key**: existing authoritative audio-owner ACK/readback, observed note and auto-rebind remain intact. Changing Space while holding a note must not produce zipper/click. + +## Audio precedence and separation requirements +1. **Lead invariant (P0):** Without user-enabled Pitch Tune, the sample-aligned lead path is independent of Wet/Space and retains channel polarity. Only the explicitly selected output Gain can scale both. Do not reuse a wet/dry crossfade that subtracts lead energy. +2. **Backing-only depth (P1):** all direct attenuation, high-frequency shading, early reflections and late diffusion apply to backing voices only. No additional effect may enter the lead path inadvertently. +3. **Direct-to-reverberant ratio (DRR):** deeper Space decreases backing DRR relative to Space near zero. This is a measurable signal-energy relationship, NOT a fixed literal physical distance. More reflection alone is not a substitute for quieter direct backing; no exaggerated reverb masking lyrics. +4. **Realistic front/back:** differentiated backing timbre without muffling consonants into noise; controlled stereo spread, mild independent phrases and natural pitch resynthesis. Existing 5–17 ms singer onset offsets and 12–20 ms early reflections need additional diffuse room energy to avoid hearing a single metallic/slap echo. +5. **Same room:** three singers share one subtle stereo diffuse field (with per-voice source position), not three unrelated giant reverb boxes. Late field is correlated acoustically but should not collapse to identical phase L=−R. +6. **Mono/speaker sanity:** mono fold of all wet voices stays audible and finite, no polarity inversion of dry signal, no excessive comb-filtering from source duplication. Test direct monitor + host monitored route externally: two simultaneous lead paths can still cause comb filtering outside Harmony, which DSP alone cannot cure. +7. **RT budget / portable:** keep current single JUCE PCM callback, bounded fixed memory and deterministic per-sample work. No fft/heap/mutex/host calls in realtime, no forced new global audio device, no new plugin PDC unless graph PDC tests pass. + +## Objective acceptance gates (all required) +| Gate | Test and evidence | Release requirement | +|---|---|---| +| Lead preservation | Wet=0/45/100, Space=0/60/100, no Pitch Tune, native PCM difference against dry-latency baseline | Sample-exact or <=1e-6 numerical lead-path delta after removing backing; no silent wet lead duck | +| Backstage vs foreground | Record natural male/female adult singing phrases; loudness-matched blind A/B between Space 0 / 0.6 / 1 | Listener reliably ranks backing behind lead and three voices separate; report results, not invented 3m coordinates | +| DRR / spectral balance | Synthetic impulse + vowel, separate backing-only STEM before final sum, calculate direct/reflected RMS in defined windows, compare bands | DRR decreases with Space; no extreme high-frequency loss (sibilant intelligibility); log curve | +| Room behavior | 32–192 kHz transient and silence; inspect 0.3–1.5 s tails and decay | No audible flutter echo, metallic ping, runaway feedback, NaN, noise-on-silence or tail on Wet 0 | +| Mono compatibility | L+R fold-down, L-R, in-phase and anti-phase stereo; 2/3/5 voices, 64/128/256 frames | Lead unchanged, backing energy remains audible with no complete cancellation | +| Realtime | Exact Windows MSVC/CTest plus CPU profile and real ASIO 48/96k × 64/128/256 frames with FX rack open/close and device graph restart | No extra graph latency, XRUNs or callback p95/p99 regressions; report hardware measurements | +| Natural vocal quality (separate P0) | Consented vowel/consonant, breathy, low-bass, female-soprano, slides and vibrato recordings | Formant and intelligibility evidence; cannot call the ensemble natural before this gate | + +## Milestones / explicit nonclaims +**D0:** Update PRD/ARD, isolate and remove wet-dependent lead duck, add mono/dry assertions. +**D1:** Prepared-sample-rate backing spectral shading + source-specific early reflections; one small bounded *backing-only* stereo diffuse late field; Space maps direct and reflected energy, not just width. +**D2:** Calibrate room decay/DRR and blind-listening A/B; profile worst-case Windows ASIO and return the simplest model that passes. +**D3 (separate P0 quality):** formant-preserving voiced/unvoiced resynthesis and expressive musical voice leading. D1 must not be marketed as completion of D3. + +**Release rule:** CI passing proves code correctness; perceived 3-person background distance and human timbre need real recordings/listener evidence. Keep PR Draft until justified. From 8c75946d0081a81f52d8a4b75b37e30078f95686 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 18:57:47 +0700 Subject: [PATCH 031/125] feat(harmony): preserve lead and implement backing-only depth, damped shared room and native regressions --- ...ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md | 6 ++ ...RD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md | 4 ++ engine/builtin_fx/HarmonyDepthRoom.h | 71 +++++++++++++++++++ engine/builtin_fx/HarmonyDsp.h | 40 ++++++++--- engine/builtin_fx/HarmonyEnsembleSpace.h | 14 +++- tests/harmony_dsp_test.cpp | 63 ++++++++++++++++ 6 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 engine/builtin_fx/HarmonyDepthRoom.h diff --git a/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md index ec4420bf0..f8f0dc757 100644 --- a/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md +++ b/docs/ARD_ARSON_HARMONY_DEPTH_ENGINE_20261109.md @@ -64,3 +64,9 @@ Only existing `Settings::space`, wet, color and voices. No new scene schema, plu ## No shortcut quality declaration Do not equate "FDN compiled" with “feels like three people metres away.” First require baseline/updated dry and backing stems rendered at level parity, mono/stereo blind A/B for perceived front-back ranking, listening through nearfields/headphones/mono laptop speaker, and actual ASIO 48/96 kHz 64/128/256 buffers with full mixer FX rack and CPU p95/p99/XRUN data. The desired response is **distant but distinct, not washed out**. Exact room dimensions and HRTF positioning are not implemented and must not be shown as facts in GUI. + +## 2026-11-09 implementation checkpoint D0–D1 (unqualified acoustically) + +D0 implemented: `HarmonyDsp::leadPath` no longer references Wet; Pitch Tune still explicitly blends corrected lead. Direct backing attenuation is separate from dry lead. D1 implemented: `EnsembleSpace::shadeBacking` adds a rate-correct gentle LP shading to **backing only**; `BackingDepthRoom` adds a 4-branch fixed-delay, precomputed 0.55 s nominal FDN with frequency damping and non-anti-phase stereo outputs. Space smooths original pan, backing attenuation, early-field gain, late send and return. No new controls/schema or device calls; no extra plugin PDC. + +Added CTest gates for 32/44.1/48/96/192 kHz impulse/tail feedback stability, reset/silence/mono compatibility, backing HF-shading boundedness and explicit pitch-tune lead preservation. This is an acoustically *unqualified* room candidate until real listening A/B and physical ASIO load. diff --git a/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md index 3a8d97827..4b3a00397 100644 --- a/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md +++ b/docs/PRD_ARSON_HARMONY_NATURAL_DEPTH_20261109.md @@ -43,3 +43,7 @@ Users currently report a robotic/noise-like stack with little natural back/front **D3 (separate P0 quality):** formant-preserving voiced/unvoiced resynthesis and expressive musical voice leading. D1 must not be marketed as completion of D3. **Release rule:** CI passing proves code correctness; perceived 3-person background distance and human timbre need real recordings/listener evidence. Keep PR Draft until justified. + +## 2026-11-09 D0/D1 working candidate (pending CI and ear-test) + +Updated `HarmonyDsp.h` removes the silent Wet-controlled lead duck, preserves the already selected Pitch Tune semantics and builds an independent backing-only distance chain. The existing Space control now adjusts direct-versus-reflected ratio, gentle high-frequency contour and one shared late stereo ambience field in addition to moderate pan. This addresses the *architecture* behind depth—not a verified acoustic outcome. D2 listener ranking/DRR level matching and D3 formant-aware synthesis remain open; preserve Draft status. diff --git a/engine/builtin_fx/HarmonyDepthRoom.h b/engine/builtin_fx/HarmonyDepthRoom.h new file mode 100644 index 000000000..83854d3f0 --- /dev/null +++ b/engine/builtin_fx/HarmonyDepthRoom.h @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +namespace armix::harmony { +// ONE deterministic backing-only stereo ambience field, not 5 reverbs. +// A 4x4 orthonormal Hadamard feedback stage distributes early line energy. +// Loop gains and pole coefficients are prepared off the realtime callback; +// the total energy gain is strictly < 1 before frequency damping. +class BackingDepthRoom final { +public: + static constexpr std::size_t branches=4; + static constexpr std::size_t capacity=8192; + struct Output {float left=0.f,right=0.f;}; + bool prepare(double rate) noexcept { + if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; + constexpr std::array delayMs{{23.f,29.f,34.f,41.f}}; + for(std::size_t i=0;i(std::lround( + static_cast(delayMs[i])*.001*rate)); + if(delay_[i]<2||delay_[i]>=capacity)return false; + // Nominal room RT60 ~0.55 s at low frequencies, shorter at + // high frequencies through the one-pole damping filter. + feedback_[i]=static_cast(std::pow( + 10.,-3.*static_cast(delay_[i])/(rate*.55))); + if(!std::isfinite(feedback_[i])||feedback_[i]>=1.f)return false; + lines_[i].fill(0.f);damped_[i]=0.f; + } + dampingAlpha_=static_cast( + 1.-std::exp(-2.*3.141592653589793*3200./rate)); + cursor_=0; + return dampingAlpha_>0.f&&dampingAlpha_<1.f; + } + Output process(float inputL,float inputR) noexcept { + std::array d{}; + for(std::size_t i=0;i,branches> lines_{}; + std::array delay_{}; + std::array feedback_{},damped_{}; + float dampingAlpha_=0.f; + std::size_t cursor_=0; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index ebc9a5a7e..141d35168 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -8,6 +8,7 @@ #include "HarmonyStereoFold.h" #include "HarmonyPreparedTone.h" #include "HarmonyEnsembleSpace.h" +#include "HarmonyDepthRoom.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -95,7 +96,7 @@ class Engine final { // into the periodicity detector and destabilizes the live note readback. decimationLowpass_=0.f; if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate)|| - !ensemble_.prepare(rate))return false; + !ensemble_.prepare(rate)||!depthRoom_.prepare(rate))return false; pitchIntervals_.prepare(); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); @@ -199,6 +200,11 @@ class Engine final { // Audio-owner telemetry; standalone CTest reads after process() returns. int completedPitchAnalyses() const noexcept{return completedPitchAnalyses_;} int abandonedPitchAnalyses() const noexcept{return abandonedPitchAnalyses_;} + // Wet changes are NEVER a hidden sidechain duck on the real lead. Only + // explicitly enabled Pitch Tune may substitute corrected lead samples. + static float leadPath(float original,float corrected,float correctionMix) noexcept { + return original*(1.f-correctionMix)+corrected*correctionMix; + } void process(float* l,float* r,int frames) noexcept { if(!l||!r||frames<=0||rate_<=0.)return; processed_=true; @@ -250,12 +256,14 @@ class Engine final { if(correctionMix_>0.00001f&&voicedGain_>0.00001f) lead=shifted(maxVoices,filterCoef); const float leadBlend=correctionMix_*voicedGain_; - float outL=(dryL*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); - float outR=(dryR*(1.f-leadBlend)+lead*leadBlend)*(1.f-wet_*0.65f*voicedGain_); - // A small, non-negative opposite-side early reflection makes a - // backing voice recede without phase widening or extra reverb FX. - // All rings advance even while muted, preventing stale FX tails. - const float roomAmount=.13f*space_; + float outL=leadPath(dryL,lead,leadBlend); + float outR=leadPath(dryR,lead,leadBlend); + // The lead is never sent into the backing room. At larger Space, + // attenuate direct backing while raising its reflected proportion. + // This reduces backing DRR without attenuating the original lead. + const float backingDirect=1.f-.38f*space_; + const float earlyReturn=.28f*space_; + float roomSendL=0.f,roomSendR=0.f; for(int v=0;v(v); const bool audible=voicedGain_>0.00001f&& @@ -266,10 +274,23 @@ class Engine final { ensemble_.arrivalSamples(v), ensemble_.pitchRatio(v))*voicedGain_; } + voice=ensemble_.shadeBacking(v,voice,space_); const float reflection=ensemble_.exchangeReflection(v,voice); - outL+=voice*mixL_[ix]+reflection*mixR_[ix]*roomAmount; - outR+=voice*mixR_[ix]+reflection*mixL_[ix]*roomAmount; + const float directL=voice*mixL_[ix],directR=voice*mixR_[ix]; + outL+=directL*backingDirect+ + reflection*mixR_[ix]*earlyReturn; + outR+=directR*backingDirect+ + reflection*mixL_[ix]*earlyReturn; + roomSendL+=directL;roomSendR+=directR; } + // One shared backing-only diffuse field. Both its input and + // audible return ramp with Space. Wet=0 gates its old tail on + // a smooth <=5 ms envelope while the room ring still decays. + const auto room=depthRoom_.process(roomSendL*space_, + roomSendR*space_); + const float roomGate=std::min(1.f,wet_*4.f); + const float lateReturn=.85f*space_*roomGate; + outL+=room.left*lateReturn;outR+=room.right*lateReturn; l[i]=std::clamp(outL*gain_,-4.f,4.f); r[i]=std::clamp(outR*gain_,-4.f,4.f); ensemble_.advance(voiced_); @@ -455,6 +476,7 @@ class Engine final { RateStableColor toneColor_{}; PreparedPitchIntervals pitchIntervals_{}; EnsembleSpace ensemble_{}; + BackingDepthRoom depthRoom_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyEnsembleSpace.h b/engine/builtin_fx/HarmonyEnsembleSpace.h index 6cf38eeaa..0d1eb5dfd 100644 --- a/engine/builtin_fx/HarmonyEnsembleSpace.h +++ b/engine/builtin_fx/HarmonyEnsembleSpace.h @@ -38,11 +38,22 @@ class EnsembleSpace final { tone_[ix]=timbre[ix]; reflections_[ix].fill(0.f); } + // A sample-rate-stable, shallow air/room HF shading of backing + // singers only. Bypassed exactly when Space=0; lead is untouched. + shadingAlpha_=static_cast( + 1.-std::exp(-2.*3.141592653589793*4400./rate)); + distanceLowpass_.fill(0.f); ageStart_=static_cast(rate*.065); ageRamp_=static_cast(1./(rate*.165)); age_=0;cursor_=0; return true; } + float shadeBacking(int v,float sample,float space) noexcept { + const auto i=static_cast(v); + distanceLowpass_[i]+=shadingAlpha_*(sample-distanceLowpass_[i]); + const float blend=.52f*std::clamp(space,0.f,1.f); + return sample*(1.f-blend)+distanceLowpass_[i]*blend; + } float arrivalSamples(int v) const noexcept { return offset_[static_cast(v)]; } @@ -85,7 +96,8 @@ class EnsembleSpace final { std::array sine_{}; std::array,voices> reflections_{}; std::array offset_{},ratio_{},vibratoRatio_{}; - std::array increment_{},phase_{},tone_{}; + std::array increment_{},phase_{},tone_{},distanceLowpass_{}; + float shadingAlpha_=0.f; std::array reflectionDelay_{}; std::size_t cursor_=0; int age_=0,ageStart_=0; diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 00d77179b..f5df9dec2 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -536,6 +536,69 @@ int main(){ need(spreadDifference>0.5&&wideEnergy>1.&&foldEnergy>.1, "ensemble room has no stereo depth or loses mono compatibility"); } + + // P0 lead preservation: backing Wet must never change the lead amplitude. + // The *only* intentional lead replacement is Pitch Tune's explicit blend. + for(float dry:{-.9f,-.3f,0.f,.27f,.9f}){ + need(Engine::leadPath(dry,.5f,0.f)==dry, + "wet-independent original lead unexpectedly ducked"); + need(std::abs(Engine::leadPath(dry,.5f,.5f)-(.5f*dry+.25f))<1.e-6f, + "explicit Pitch Tune blend changed"); + } + + // P1 diffuse shared BACKING room: no immediate output, fixed delay at + // all accepted rates, decaying rather than metallic or unstable feedback. + for(double rate:{32000.,44100.,48000.,96000.,192000.}){ + auto room=std::make_unique(); + need(room->prepare(rate),"backing room rejected supported sample rate"); + for(std::size_t v=0;vdelaySamples(v)>0&& + room->delaySamples(v)feedbackGain(v)>0.f&&room->feedbackGain(v)<1.f, + "backing FDN missing bounded delays or stable feedback"); + const int total=static_cast(rate*1.8); + double first=0.,late=0.,last=0.,mono=0.; + for(int i=0;iprocess(i==0?1.f:0.f,i==0?1.f:0.f); + need(std::isfinite(o.left)&&std::isfinite(o.right)&& + std::abs(o.left)<2.f&&std::abs(o.right)<2.f, + "backing room blew up or returned non-finite PCM"); + const double energy=o.left*o.left+o.right*o.right; + if(i(rate*.02)) + need(energy<1.e-18,"diffuse field leaked before its first tap"); + if(i(rate*.11))first+=energy; + else if(i(rate*.35))late+=energy; + if(i>static_cast(rate*1.5))last+=energy; + mono+=(.5*(o.left+o.right))*(.5*(o.left+o.right)); + } + need(first>1.e-5&&late>1.e-9&&last1.e-5,"room anti-phase cancelled in mono"); + need(room->prepare(rate),"device restart failed to reset room"); + for(int i=0;i<512;++i){ + const auto o=room->process(0.f,0.f); + need(o.left==0.f&&o.right==0.f, + "room restart retained stale output from previous session"); + } + } + // P1 stereo depth changes must remain audible in mono, but lead should + // stay transparent regardless of Space and Wet when no Pitch Tune. + for(float depth:{0.f,.5f,1.f}){ + EnsembleSpace singer; + need(singer.prepare(48000.),"backing HF shader prepare failed"); + double inputEnergy=0.,outputEnergy=0.; + for(int i=0;i<3000;++i){ + const float pulse=(i%7)<3?1.f:-1.f; + const float shaded=singer.shadeBacking(0,pulse,depth); + inputEnergy+=pulse*pulse; + outputEnergy+=shaded*shaded; + singer.advance(true); + } + need(outputEnergy>0.&&outputEnergy<=inputEnergy*1.01, + "backing distance contour amplified or removed singer"); + if(depth==0.f)need(std::abs(outputEnergy-inputEnergy)<1.e-6, + "Space zero failed to preserve direct backing"); + } // Declared 48k wet/dry sample PDC must remain 2*16ms even after slicing. need(e->latencySamples()==1536,"P0 changed live session PDC without proof"); std::cout<<"Native Harmony DSP: deterministic PCM, 2-5 voices, octave/scale, stereo, silence and 32-192k PASS\n"; From b9b64f7083a04bb748a4d9a4d8b5fc9b9d142c63 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 19:28:25 +0700 Subject: [PATCH 032/125] Fix native zero-capture admission and reduce Audio I/O reopen stalls Show only the accepted native roster, open the requested backend directly under the existing output fence, and let the shipped UI test the verified MAIN pins without replacing the mixer. Report post-gate JUCE buffer peaks and source SHA for field diagnosis. --- CMakeLists.txt | 11 ++- integration/ApprovedNativeRuntimeSnapshot.h | 4 +- scripts/build_approved_native_gui.py | 7 ++ src/DiagnosticTone.h | 3 +- src/LiveAudioEngine.h | 84 ++++++++++++++--- src/LiveDryRoutingLab.h | 11 +++ src/Main.cpp | 95 ++++++++++++++++---- tests/approved_native_cold_start_smoke.py | 19 ++-- tests/approved_native_v8_projection_test.cpp | 18 +++- tests/mixer_io_operator_contract_test.mjs | 9 +- web/approved-native-bridge.js | 23 +++-- 11 files changed, 241 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b039ae0c..72e05dd04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,22 @@ target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h engine/bu if(MSVC) target_compile_options(ARMixConsole PRIVATE "$<$:/utf-8>") endif() +# Stamp the build source in Copy Audio Report, including Windows field trials. +execute_process(COMMAND git rev-parse --verify HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE ARMIX_BUILD_SOURCE_SHA OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE ARMIX_BUILD_SOURCE_STATUS ERROR_QUIET) +if(NOT ARMIX_BUILD_SOURCE_STATUS EQUAL 0 OR NOT ARMIX_BUILD_SOURCE_SHA MATCHES "^[0-9a-f]+$") + set(ARMIX_BUILD_SOURCE_SHA "unavailable") +endif() # One JUCE mixer/PCM host on all three desktops. Device backends are OS owned. target_compile_definitions(ARMixConsole PRIVATE JUCE_WEB_BROWSER=1 JUCE_USE_CURL=0 JUCE_PLUGINHOST_VST3=1 JUCE_APPLICATION_NAME_STRING="AR MIX Studio" - JUCE_APPLICATION_VERSION_STRING="0.5.0-p2") + JUCE_APPLICATION_VERSION_STRING="0.5.0-p2" + ARMIX_BUILD_SOURCE_SHA="${ARMIX_BUILD_SOURCE_SHA}") if(WIN32) # Windows retains its proven ASIO-first / WASAPI / static WebView2 distribution. # Never link Windows loader or sound APIs into macOS/Linux builds. diff --git a/integration/ApprovedNativeRuntimeSnapshot.h b/integration/ApprovedNativeRuntimeSnapshot.h index f5065a557..2b3207ea9 100644 --- a/integration/ApprovedNativeRuntimeSnapshot.h +++ b/integration/ApprovedNativeRuntimeSnapshot.h @@ -71,7 +71,7 @@ inline bool publishVerifiedFirstSoundState(juce::var& snapshot, static_cast(routeEpoch)>0 && static_cast(revision)>0 && juce::String(static_cast(routeEpoch))==epoch.toString() && - inputs.isArray() && !inputs.getArray()->isEmpty() && + inputs.isArray() && outputs.isArray() && outputs.getArray()->size()>=2 && nativeV8Number(device.getProperty("sampleRate",{}),rate) && nativeV8Number(device.getProperty("bufferFrames",{}),frames) && @@ -267,7 +267,7 @@ inline bool projectInstalledNativeChannelIdGraph( const auto frames=device.getProperty("bufferFrames",{}); double actualRate=0.,actualFrames=0.; if (!outputMask.isArray() || !inputMask.isArray() || - outputMask.getArray()->size()<2 || inputMask.getArray()->isEmpty() || + outputMask.getArray()->size()<2 || !nativeV8Number(rate,actualRate) || !nativeV8Number(frames,actualFrames) || actualRate<8000. || actualRate>384000. || diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py index c3e8e6afa..877c27e96 100644 --- a/scripts/build_approved_native_gui.py +++ b/scripts/build_approved_native_gui.py @@ -58,6 +58,13 @@ def accepted_pages_html() -> str: # HTML at native build time. Every anchor must occur exactly once: no silent # breakage if Pages GUI source evolves. No extra layout or simulated PCM. NATIVE_EVENT_HOOKS = ( + # Do not expose the reference mixer while the native host is still starting. + ("", "\n"), + ("Mixer · Reference Session", "Mixer · Native Session"), + ("Interactive visual reference. Changes are local to this mockup.", "Preparing native mixer…"), + ("SIMULATED METERS · NO REAL AUDIO", "NATIVE AUDIO"), # The published /preview/ HTML and its V28 checkpoint are immutable. # Change ONLY the compiled native WebView's operator fader travel law. # The DSP gain remains exact dB -> 10^(dB/20), and the mapping is diff --git a/src/DiagnosticTone.h b/src/DiagnosticTone.h index fbedcc300..b7647649d 100644 --- a/src/DiagnosticTone.h +++ b/src/DiagnosticTone.h @@ -7,7 +7,7 @@ namespace armix::diagnostics { // Diagnostic routes are temporary, never persisted as the chosen user device. -enum class Route : int { normal = 0, dryThrough = 1, outputOnlyTone = 2, captureOnly = 3 }; +enum class Route : int { normal = 0, dryThrough = 1, outputOnlyTone = 2, captureOnly = 3, mainOutputTone = 4 }; inline constexpr const char* routeName (Route route) noexcept { @@ -17,6 +17,7 @@ inline constexpr const char* routeName (Route route) noexcept case Route::dryThrough: return "DRY_THROUGH"; case Route::outputOnlyTone: return "OUTPUT_ONLY_TONE"; case Route::captureOnly: return "CAPTURE_ONLY"; + case Route::mainOutputTone: return "MAIN_OUTPUT_TONE"; } return "INVALID"; } diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index a7e892f31..9c82f5ae3 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -580,9 +580,35 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // user setup is restored on exit; temporary routes must not be persisted. juce::String setDiagnosticRoute (armix::diagnostics::Route wanted) { - if (dryRoutingLab_.hasAuthoredMixerContent()) - return "An authored mixer cannot enter endpoint isolation until a safe session rebind is available"; using Route = armix::diagnostics::Route; + const auto currentRoute=diagnosticRoute_.load(std::memory_order_acquire); + if(wanted==Route::mainOutputTone) { + if(currentRoute==wanted)return {}; + if(currentRoute!=Route::normal || independent_.active()) + return "Return to NORMAL on the DIRECT device before testing MAIN."; + if(const auto error=liveOutputArmFault(false);error.isNotEmpty())return error; + if(secondaryOutput_.armed()) + return "Stop STREAM before testing the physical MAIN output."; + const auto pair=dryRoutingLab_.acceptedMainCallbackPair(); + if(pair[0]<0 || pair[1]<0 || pair[0]==pair[1]) + return "No verified MAIN output pair."; + mainTestEpoch_.store(dryRoutingLab_.epoch(),std::memory_order_relaxed); + mainTestPair_.store(static_cast(pair[0]) | + (static_cast(pair[1])<<16),std::memory_order_relaxed); + mainTestWasArmed_=isMonitorEnabled(); + mainTestPeak_.store(0.f,std::memory_order_relaxed); + diagnosticRoute_.store(wanted,std::memory_order_release); + setMonitorEnabled(true); // the operator explicitly requested this isolated tone + return {}; + } + if(currentRoute==Route::mainOutputTone) { + // A diagnostic ARM does not authorize microphone audio on exit. + if(!mainTestWasArmed_)setOutputMuted(true); + diagnosticRoute_.store(Route::normal,std::memory_order_release); + if(wanted==Route::normal)return {}; + } + if (dryRoutingLab_.hasAuthoredMixerContent()) + return "Use MAIN OUTPUT TONE to test the output without reopening the authored mixer."; if (handoff_.busy()) return "Finish the pending FX graph transition first"; if (independent_.active()) return "Disable independent clock mode before endpoint isolation tests"; if (wanted == diagnosticRoute_.load (std::memory_order_acquire) && @@ -2246,6 +2272,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback o->setProperty ("peak", outputPeak_.load()); o->setProperty ("peakLeft", outputPeakL_.load()); o->setProperty ("peakRight", outputPeakR_.load()); + o->setProperty ("driverBufferPeakLeft",driverBufferPeakL_.load(std::memory_order_relaxed)); + o->setProperty ("driverBufferPeakRight",driverBufferPeakR_.load(std::memory_order_relaxed)); + o->setProperty ("driverBufferProvenance","JUCE_CALLBACK_OUTPUT_POST_GATE"); + o->setProperty ("mainTestLastPeak",mainTestPeak_.load(std::memory_order_relaxed)); const auto loudness = masterLoudness_.read(); const bool measuredDirect = !dual && loudness.supported; o->setProperty ("masterAnalysisProvenance", @@ -2496,6 +2526,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback LiveDryRoutingLab dryRoutingLab_; std::atomic diagnosticRoute_ {armix::diagnostics::Route::normal}; std::atomic routeReconfiguring_ {false}; + std::atomic mainTestEpoch_{0}; + std::atomic mainTestPair_{0}; + bool mainTestWasArmed_=false; // control thread only std::optional savedLiveSetup_; // Indexed atomic bypass flags: instant RT-safe toggles, no graph detachment. // Temporary publication silence never changes operator MONITOR or MAIN MUTE. @@ -2508,6 +2541,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback std::atomic captureObservationBlocks_ {0}; // per native device epoch, even UNPATCHED armix::rt::CaptureBoundaryEvidence captureBoundary_; // callback-only PCM continuity std::atomic outputPeakL_ { 0.f }, outputPeakR_ { 0.f }; + std::atomic driverBufferPeakL_{0.f},driverBufferPeakR_{0.f},mainTestPeak_{0.f}; std::atomic callbackInputs_ { 0 }, callbackOutputs_ { 0 }; std::atomic callbackCount_ { 0 }; // Audio-thread-only timestamp and cheap atomically published counters. @@ -2634,6 +2668,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback inputPeak_.store (0.f); postFxPeak_.store (0.f); outputPeak_.store (0.f); + publishDriverBufferPeaks(0.f,0.f); } void audioDeviceStopped() override @@ -2650,6 +2685,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback captureBoundary_.reset(); // no stale pin peaks after disconnect inputPeak_.store (0.f); outputPeak_.store (0.f); + publishDriverBufferPeaks(0.f,0.f); } // ONE original CH1 rack processor for M4 compatibility and the native @@ -2740,6 +2776,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return fx; } + void publishDriverBufferPeaks(float left,float right) noexcept { + driverBufferPeakL_.store(left,std::memory_order_relaxed); + driverBufferPeakR_.store(right,std::memory_order_relaxed); + } + void audioDeviceIOCallbackWithContext ( const float* const* inputs, int inputChannels, float* const* outputs, int outputChannels, int samples, const juce::AudioIODeviceCallbackContext&) override @@ -2749,7 +2790,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // while the user is changing devices. Atomic gate only: no name hash, // allocations, OS calls or device restart on the realtime callback. // An independent WASAPI bridge has its own verified endpoint guard. - const auto activeDiagnosticRoute = diagnosticRoute_.load (std::memory_order_relaxed); + const auto activeDiagnosticRoute = diagnosticRoute_.load (std::memory_order_acquire); // DRY_THROUGH still routes a live microphone to the hardware output: // it MUST use the same DIRECT authorization fence as NORMAL. Only // genuinely isolated OUTPUT_ONLY_TONE / CAPTURE_ONLY tests may bypass @@ -2761,6 +2802,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback { for (int c=0; c (samples), std::memory_order_relaxed); return; @@ -2805,6 +2847,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback outputPeak_.store(0.f, std::memory_order_relaxed); outputPeakL_.store(0.f, std::memory_order_relaxed); outputPeakR_.store(0.f, std::memory_order_relaxed); + publishDriverBufferPeaks(0.f,0.f); handoff_.endCycle(cycle); // ACK prepared FX graph even in silence return; } @@ -2915,7 +2958,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback peak=juce::jmax(peak,std::abs(out[i])); } if(c==0)movedPeakL=peak; - else movedPeakR=peak; + else if(c==1)movedPeakR=peak; } if(routedFxMove==1 && cycle.graph) { cycle.graph->orderPacked.store( @@ -2962,6 +3005,9 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback for(int channel=0;channel outputPair{{0,1}}; + if(route==armix::diagnostics::Route::mainOutputTone) { + const auto packed=mainTestPair_.load(std::memory_order_relaxed); + outputPair={{static_cast(packed&0xffffu),static_cast(packed>>16)}}; + if(!dryRoutingLab_.ready() || + mainTestEpoch_.load(std::memory_order_relaxed)!=dryRoutingLab_.epoch()) + outputPair={{-1,-1}}; + } + const auto testPair=armix::mixer::NativeOutputPairTap::select(outputs,outputChannels,outputPair); const bool captureTest = route == armix::diagnostics::Route::captureOnly; - if (toneTest && outputChannels > 0) + if (toneTest && testPair[0]) testOutputFrames_.fetch_add (static_cast (samples), std::memory_order_relaxed); if (captureTest && inputChannels > 0) testCaptureFrames_.fetch_add (static_cast (samples), std::memory_order_relaxed); @@ -3010,7 +3066,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback { auto* left = scratch_.getWritePointer (0); auto* right = scratch_.getWritePointer (1); - const bool audible = enabled && !masterMute_.load (std::memory_order_relaxed); + const bool audible = testPair[0] && enabled && !masterMute_.load (std::memory_order_relaxed); for (int i = 0; i < frames; ++i) left[i] = right[i] = diagnosticTone_.next (audible); } @@ -3044,6 +3100,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const float* left = scratch_.getReadPointer (0); const float* right = scratch_.getReadPointer (1); float* dst = outputs[c] + offset; + if(toneTest && (!testPair[0] || (c!=outputPair[0] && c!=outputPair[1]))) { + juce::FloatVectorOperations::clear(dst,frames); + continue; + } const float fromL = mono ? monoL : (c == 0 ? matrix.ll : matrix.rl); const float fromR = mono ? monoR : (c == 0 ? matrix.lr : matrix.rr); float channelPeak = 0.f; @@ -3063,8 +3123,8 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback channelPeak = juce::jmax (channelPeak, std::abs (value)); } outPeak = juce::jmax (outPeak, channelPeak); - if (c == 0) outPeakL = juce::jmax (outPeakL, channelPeak); - if (c == 1) outPeakR = juce::jmax (outPeakR, channelPeak); + if (c == outputPair[0]) outPeakL = juce::jmax (outPeakL, channelPeak); + if (c == outputPair[1]) outPeakR = juce::jmax (outPeakR, channelPeak); } } if (!independent_.active()) @@ -3077,6 +3137,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } inputPeak_.store (juce::jmin (1.f, inPeak), std::memory_order_relaxed); postFxPeak_.store (juce::jmin (1.f, postFxPeak), std::memory_order_relaxed); + publishDriverBufferPeaks(outPeakL,outPeakR); + if(route==armix::diagnostics::Route::mainOutputTone) + mainTestPeak_.store(juce::jmax(mainTestPeak_.load(std::memory_order_relaxed),outPeak), + std::memory_order_relaxed); outputPeak_.store (juce::jmin (1.f, outPeak), std::memory_order_relaxed); outputPeakL_.store (juce::jmin (1.f, outPeakL), std::memory_order_relaxed); outputPeakR_.store (juce::jmin (1.f, outPeakR), std::memory_order_relaxed); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 932554589..5a4d019c0 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -2590,6 +2590,17 @@ class LiveDryRoutingLab final { } std::uint64_t revision() const noexcept {return publisher_.lastRevision();} // control only + // Control thread only. The test uses the exact pair the current mixer + // owns, including non-contiguous physical pins mapped to compact indices. + std::array acceptedMainCallbackPair() const noexcept { + if(!ready())return {{-1,-1}}; + if(channelIdPhysicalPcmActive()) + return {{nativeAccepted_.hardware.mainL,nativeAccepted_.hardware.mainR}}; + if(const auto* graph=publisher_.controlPrepared(epoch(),revision())) + return {{graph->mainOutputLeft(),graph->mainOutputRight()}}; + return {{-1,-1}}; + } + // JUCE render callback, with a verified single-clock device. Routing // publishes at the BLOCK boundary. Missing/stale ports output SILENCE. // A failed run never falls through to an unrelated microphone/plugin path. diff --git a/src/Main.cpp b/src/Main.cpp index c2332c784..299157079 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1050,6 +1050,14 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // ENGINE callback. This code executes on the JUCE message thread, not RT. void handleApprovedNativeControl(const juce::var& request) { + if(audioDeviceApplyActive_) { + auto ack=std::make_unique(); + ack->setProperty("requestId",request.getProperty("requestId",{})); + ack->setProperty("status","REJECTED"); + ack->setProperty("errorCode","AUDIO_DEVICE_APPLY_IN_PROGRESS"); + browser_.emitEventIfBrowserIsVisible("arMixConsoleAck",juce::var(ack.release())); + return; + } const auto beforeLive=engine_.status(); const auto before=approvedNativeSnapshot(beforeLive); const auto route=beforeLive.getProperty("dryRoutingLab",{}); @@ -1324,11 +1332,55 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr serviceAutomaticMain(); } + bool audioDeviceApplyActive_=false; // JUCE message thread, including nested driver dispatch + + juce::String openSelectedAudioDevice(const juce::String& backend, + const juce::AudioDeviceManager::AudioDeviceSetup& setup) { + auto& manager=engine_.devices(); + if(manager.getCurrentAudioDeviceType()==backend) { + if(auto* device=manager.getCurrentAudioDevice();device && !device->isOpen()) + manager.closeAudioDevice(); + return manager.setAudioDeviceSetup(setup,true); + } + + // JUCE's setCurrentAudioDeviceType opens its remembered/default + // device first and sleeps on the message thread. Initialise the + // exact named backend and requested masks in one open instead. + auto xml=manager.createStateXml(); + if(!xml)xml=std::make_unique("DEVICESETUP"); + xml->setAttribute("deviceType",backend); + xml->removeAttribute("audioDeviceName"); + xml->setAttribute("audioInputDeviceName",setup.inputDeviceName); + xml->setAttribute("audioOutputDeviceName",setup.outputDeviceName); + xml->setAttribute("audioDeviceRate",setup.sampleRate); + xml->setAttribute("audioDeviceBufferSize",setup.bufferSize); + const auto setMask=[&](const char* key,bool useDefault,const juce::BigInteger& mask) { + if(useDefault)xml->removeAttribute(key); + else xml->setAttribute(key,mask.toString(2)); + }; + setMask("audioDeviceInChans",setup.useDefaultInputChannels,setup.inputChannels); + setMask("audioDeviceOutChans",setup.useDefaultOutputChannels,setup.outputChannels); + diagnostics_.record("CUSTOM_AUDIO_PHASE","CLOSE_PREVIOUS | "+manager.getCurrentAudioDeviceType()); + manager.closeAudioDevice(); + diagnostics_.record("CUSTOM_AUDIO_PHASE","OPEN_SELECTED | "+backend); + return manager.initialise(2,2,xml.get(),false); + } + void applyCustomAudioDevice(const juce::var& args) { - // Synchronous manager operations stay on JUCE's established message - // thread. A vendor driver may block; never pretend JS async fixes it. + // JUCE device lifecycle runs on the message thread, including ASIO's + // modal callbacks. Serialize transactions across nested dispatch. const auto id=args.getProperty("requestId",{}).toString().substring(0,64); + if(audioDeviceApplyActive_) { + auto ack=std::make_unique(); + ack->setProperty("requestId",id); + ack->setProperty("ok",false); + ack->setProperty("state","BUSY"); + ack->setProperty("error","Audio I/O is already applying a device change."); + browser_.emitEventIfBrowserIsVisible("arMixAudioDeviceApplyAck",juce::var(ack.release())); + return; + } + const juce::ScopedValueSetter applying(audioDeviceApplyActive_,true); const auto oldGeneration=engine_.status().getProperty("deviceGeneration",0); auto send=[&](bool ok,const juce::String& state,const juce::String& error, bool canReusePins=false) @@ -1355,7 +1407,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if(nativeShowBusy_||studioBackupBusy_||mixerSessionWorker_.busy()|| engine_.isGraphSwitchPending()|| static_cast(nativeRoute.getProperty("pending",false))|| - engine_.independentClockActive()||engine_.hasTemporaryDiagnosticDevice()|| + engine_.independentClockActive()|| + engine_.diagnosticRoute()!=armix::diagnostics::Route::normal|| engine_.secondaryArmed()) return send(false,"REJECTED", "Stop STREAM and finish Show/FX/diagnostic/clock transition first"); @@ -1494,7 +1547,6 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto start=monotonicMilliseconds(); autoMainEpoch_=0; engine_.beginManualAudioSetup(); - if(!unchangedDevice)manager.setCurrentAudioDeviceType(typeName,false); // JUCE setAudioDeviceSetup() can return success without reopening when // setup == currentSetup and currentAudioDevice != nullptr, even when // that driver object has stopped. closeAudioDevice() deletes it but @@ -1506,9 +1558,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr typeName+" | "+(previousWasOpen?"REFRESH_ASIO_PINS":"CLOSED_DEVICE_RECOVERY")); manager.closeAudioDevice(); } - auto error=manager.getCurrentAudioDeviceType()==typeName - ?manager.setAudioDeviceSetup(candidate,true) - :juce::String("Selected audio backend could not be opened"); + diagnostics_.record("CUSTOM_AUDIO_PHASE","APPLY | "+typeName); + auto error=openSelectedAudioDevice(typeName,candidate); + diagnostics_.record("CUSTOM_AUDIO_PHASE","VERIFY_READBACK | "+typeName); juce::AudioDeviceManager::AudioDeviceSetup actual; manager.getAudioDeviceSetup(actual); auto* opened=manager.getCurrentAudioDevice(); @@ -1531,6 +1583,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr std::abs(opened->getCurrentSampleRate()-actual.sampleRate)>1.0|| opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) error="Driver readback mismatch; device setting was not accepted"; + if(error.isEmpty())diagnostics_.record("CUSTOM_AUDIO_PHASE","BIND_MIXER | "+typeName); if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(true)) { if(!previousMixerBound && engine_.directRouteAuthorized() && (engine_.hasRetainedUnboundMixer() || mixerSessionRecoveryPending_)) { @@ -1564,11 +1617,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // One rollback, never blind default endpoint fallback, no auto-unmute. // A previously CLOSED device was never a verified rollback target. engine_.beginManualAudioSetup(); - if(recovery.priorKnownOpen&&manager.getCurrentAudioDeviceType()!=previousType&&previousType.isNotEmpty()) - manager.setCurrentAudioDeviceType(previousType,false); + diagnostics_.record("CUSTOM_AUDIO_PHASE","ROLLBACK | "+previousType); const auto restored=recovery.priorKnownOpen&&previousType.isNotEmpty()&& - manager.getCurrentAudioDeviceType()==previousType&& - manager.setAudioDeviceSetup(before,true).isEmpty(); + openSelectedAudioDevice(previousType,before).isEmpty()&& + manager.getCurrentAudioDeviceType()==previousType; juce::AudioDeviceManager::AudioDeviceSetup checked; manager.getAudioDeviceSetup(checked); const bool verified=restored&& @@ -1774,7 +1826,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr result.preallocateBytes (64 * 1024); result << "ARSONMIX / SMART AUDIO DIAGNOSTIC REPORT v2\n"; result << "Timestamp: " << juce::Time::getCurrentTime().toISO8601 (true) << "\n"; - result << "Build: experimental-P0 clock-instrumentation / native JUCE 8.0.15\n"; + result << "Build: " << juce::JUCEApplication::getInstance()->getApplicationVersion() + << " | Source HEAD: " << ARMIX_BUILD_SOURCE_SHA << "\n"; result << "Platform: " << juce::SystemStats::getOperatingSystemName() << "\n"; result << "CPU: " << juce::SystemStats::getCpuModel() << "\n"; result << "Logical cores: " << juce::SystemStats::getNumCpus() @@ -2388,6 +2441,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr void onAction (const juce::var& args) { const auto action = args.getProperty ("action", {}).toString(); + if(audioDeviceApplyActive_ && action!="audioDeviceApply")return; const auto value = args.getProperty ("value", {}); const int slot = static_cast (args.getProperty ("slot", -1)); // User may adjust live levels, but cannot alter the persisted VST @@ -4160,7 +4214,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr lastDirectRestoreError_.clear(); // One-sided device routes are temporary and must never leak into // normal user configuration or the persisted audio-devices.xml. - if (engine_.hasTemporaryDiagnosticDevice()) + if (engine_.hasTemporaryDiagnosticDevice() || + engine_.diagnosticRoute()==armix::diagnostics::Route::mainOutputTone) { const auto error = engine_.setDiagnosticRoute (armix::diagnostics::Route::normal); if (error.isNotEmpty()) return emitNotice (error, true); @@ -4179,9 +4234,12 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr deviceSettingsDirty_ = true; } using Route = armix::diagnostics::Route; - const auto selected = value.toString(); + auto selected = value.toString(); + if(selected=="TOGGLE_MAIN_OUTPUT_TONE") + selected=engine_.diagnosticRoute()==Route::mainOutputTone?"NORMAL":"MAIN_OUTPUT_TONE"; auto route = Route::normal; if (selected == "OUTPUT_ONLY_TONE") route = Route::outputOnlyTone; + else if (selected == "MAIN_OUTPUT_TONE") route = Route::mainOutputTone; else if (selected == "CAPTURE_ONLY") route = Route::captureOnly; else if (selected == "DRY_THROUGH") route = Route::dryThrough; else if (selected != "NORMAL") return emitNotice ("Unsupported diagnostic mode", true); @@ -4196,8 +4254,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if (route == Route::normal) deviceSettingsDirty_ = true; diagnostics_.record ("AUDIO_TEST_MODE", selected + " | " + juce::JSON::toString (engine_.status(), false)); - emitNotice ("Audio diagnostic: " + selected + - ". Use low headphone volume and MARK CRACKLE on audible faults."); + if(route==Route::mainOutputTone) + emitNotice("MAIN test tone active. Use low speaker volume. Press Test MAIN output again to stop."); + else + emitNotice ("Audio diagnostic: " + selected + + ". Use low headphone volume and MARK CRACKLE on audible faults."); } else if (action == "diagnosticMark") { @@ -4604,6 +4665,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr void changeListenerCallback (juce::ChangeBroadcaster*) override { + if(audioDeviceApplyActive_)return; // synchronous transaction owns recovery // Save device state only after a real change, not on every 3-second tick. deviceSettingsDirty_ = true; // The retention gate closes only on an actual epoch/owner change. @@ -4619,6 +4681,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr void timerCallback() override { + if(audioDeviceApplyActive_)return; // a vendor modal loop may re-enter JUCE // Always disabled unless the user explicitly starts a bounded trace. const bool timing = guiPerf_.active; const double tickStart = timing ? juce::Time::getMillisecondCounterHiRes() : 0.0; diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index fa4c157d2..f7016c754 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -1,4 +1,4 @@ -"""Real compiled DOM from G0: first drag without OUT priming, first native +"""Real compiled DOM: hide reference G0, first drag without OUT priming, first native FX picker insert on original CH with structural=false, then vendor editor. Backend isolation is emulated; actual latency/sample evidence is CTest. """ @@ -41,6 +41,7 @@ def main(): addEventListener(name,callback){window.__nativeListeners.set(name,callback);}}};""") page.goto((out/'index.html').as_uri()) page.wait_for_function('()=>window.__ARMIX_NATIVE_M2__?.enabled') + assert page.locator('.console-pane').is_hidden() # Built-in JUCE DSP must be discoverable before ANY third-party # VST3 catalog response. The native host never inserts demo FX. for native_id in ('armix.builtin.channel-eq.v1', @@ -135,6 +136,9 @@ def show_select(value): emit(page,"arMixNativeSessionAck",{"operation":"OPEN","ok":False,"error":"Invalid mixer JSON"}) assert page.get_by_text("Invalid mixer JSON",exact=True).count()>=1 assert not page.evaluate("()=>window.__events.some(e=>e.payload?.action==='monitor')") + show_click("Test MAIN output") + assert page.evaluate("()=>window.__events.at(-1).payload")=={ + "action":"diagnosticRoute","value":"TOGGLE_MAIN_OUTPUT_TONE"} show_click("Browse Shows") assert page.evaluate("()=>window.__events.at(-1).payload.action")=="routingDryShowList" emit(page,"arMixNativeShowListAck",{"ok":True,"items":[ @@ -169,12 +173,10 @@ def show_select(value): assert page.evaluate("()=>window.__events.at(-1).payload.action")=="routingDryShowList" emit(page,"arMixNativeShowListAck",{"ok":True,"items":[]}) assert not page.evaluate("()=>window.__events.some(e=>e.payload?.action==='monitor')") - if 'collapsed-send' in (page.locator('.console-body').get_attribute('class') or ''): - page.locator('.section-rail [data-section="send"]').click() - # Release before bootstrap SOURCE's later native readback arrives. - drag(page,1,2) + assert page.locator('.console-pane').is_hidden() assert not page.evaluate('()=>window.__nativeIntents.length') state=snapshot() + state['device'].update(enabledInputs=[],inputEndpoints=[]) state['graph']['edges'].pop(1) # genuinely no existing channel send state['graph']['capabilities']['supportedOps'] += ['LOAD_INSERT'] for ident, role, name in [('101','GROUP','Vocal Group'), @@ -187,6 +189,10 @@ def show_select(value): state['legacyM4']={'active':True,'routeAccepted':True,'routingRevision':'77', 'nativeBusStructural':False,'fxInstances':[[] for _ in range(14)]} emit(page,'arMixConsoleSnapshot',state) + page.locator('.console-pane').wait_for(state='visible') + if 'collapsed-send' in (page.locator('.console-body').get_attribute('class') or ''): + page.locator('.section-rail [data-section="send"]').click() + drag(page,1,2) page.wait_for_function('()=>window.__nativeIntents.length===1') route=page.evaluate('()=>window.__nativeIntents[0]') assert route['operation']=='APPLY_WIRE_TRANSACTION' @@ -294,7 +300,8 @@ def show_select(value): 'state':'ACCEPTED_LIVE','active':active,'mixerBound':True,'outputMuted':False}) assert page.locator('.armix-audio-shade').is_hidden() rebound=copy.deepcopy(state) - rebound['device'].update(epoch='93',outputArmed=True) + rebound['device'].update(epoch='93',outputArmed=True, + enabledInputs=g0['device']['enabledInputs'],inputEndpoints=g0['device']['inputEndpoints']) rebound['graph']['revision']='6' rebound['graph']['capabilities']['supportedOps'].append('CREATE_CHANNEL') rebound['mixerSession'].update(deviceEpoch='93',routeRevision='6') diff --git a/tests/approved_native_v8_projection_test.cpp b/tests/approved_native_v8_projection_test.cpp index dced419c2..576c4386a 100644 --- a/tests/approved_native_v8_projection_test.cpp +++ b/tests/approved_native_v8_projection_test.cpp @@ -637,6 +637,11 @@ static void installedCallbackAdmissionRegression(const juce::var& rawBus) { =="9007199254740993"); assert(std::abs(static_cast(session.getProperty("main",{}) .getProperty("db",0.))-(-13.5))<0.00001); + // The installed graph remains editable with playback and no capture pins. + dev.getDynamicObject()->setProperty("enabledInputs",juce::var(juce::Array{})); + assert(projectInstalledNativeChannelIdGraph(snap,live)); + publishAuthoritativeMixerSession(snap); + assert(snap.getProperty("mixerSession",{}).getProperty("authority","").toString()=="CHANNEL_ID"); // Real restart: lab routing epoch counts STOP+START, unlike M2 // deviceStartCount. This G0-to-native authority switch must advance. auto disconnected=canonicalSnapshot(); @@ -826,7 +831,18 @@ static void firstSoundRouteAdmissionRegression() { auto withoutInput=juce::JSON::parse(juce::JSON::toString(snapshot,false)); withoutInput.getProperty("device",{}).getDynamicObject() ->setProperty("enabledInputs",juce::var(juce::Array{})); - assert(!publishVerifiedFirstSoundState(withoutInput,live)); + assert(publishVerifiedFirstSoundState(withoutInput,live)); + assert(withoutInput.getProperty("legacyM4",{}) + .getProperty("channels",{}).getArray()->isEmpty()); // stale MONO mapping rejected + auto noCaptureRoute=juce::JSON::parse(juce::JSON::toString(live,false)); + auto noCaptureRows=noCaptureRoute.getProperty("dryRoutingLab",{}) + .getProperty("acceptedRoute",{}).getProperty("channels",{}); + auto* unpatched=noCaptureRows[4].getDynamicObject(); + unpatched->setProperty("mode","NONE"); + unpatched->setProperty("left",-1); + assert(publishVerifiedFirstSoundState(withoutInput,noCaptureRoute)); + assert(withoutInput.getProperty("legacyM4",{}) + .getProperty("channels",{}).getArray()->size()==10); } // Control-only fixture: validates exclusive M4 session normalization, diff --git a/tests/mixer_io_operator_contract_test.mjs b/tests/mixer_io_operator_contract_test.mjs index 11176a98e..157d8917a 100644 --- a/tests/mixer_io_operator_contract_test.mjs +++ b/tests/mixer_io_operator_contract_test.mjs @@ -202,7 +202,14 @@ test('DEVICE1 existing matrix drives real JUCE manager with gated native readbac for(const flag of ['JUCE_ASIO=1','JUCE_WASAPI=1','JUCE_DIRECTSOUND=1'])assert.ok(cm.includes(flag)); assert.match(native,/manager, 1, 64, 1, 64, false, false, false, false/); // hidden fallback only assert.match(native,/action == "audioDeviceApply"/); - assert.match(native,/setAudioDeviceSetup\(candidate,true\)/); + const open=native.slice(native.indexOf('juce::String openSelectedAudioDevice('), + native.indexOf('void applyCustomAudioDevice(')); + assert.match(native,/openSelectedAudioDevice\(typeName,candidate\)/); + assert.match(native,/openSelectedAudioDevice\(previousType,before\)/); + assert.match(open,/setAudioDeviceSetup\(setup,true\)/); + assert.match(open,/manager\.initialise\(2,2,xml\.get\(\),false\)/); + assert.match(open,/manager\.closeAudioDevice\(\);[\s\S]*manager\.initialise/); + assert.doesNotMatch(open,/manager\.setCurrentAudioDeviceType\(/); assert.match(native,/beginManualAudioSetup\(\)/); assert.match(native,/finishManualAudioSetup\(\)/); assert.match(native,/RESTORED_MUTED/); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 212cb90c7..af49d6e55 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1924,6 +1924,11 @@ // Windows RAM/process paging context from the existing 1 Hz control // timer. No sampling or file I/O happens in the ASIO callback. const healthTitle=item("span","more-tools-caption","AUDIO HEALTH"); + const tone=item("button","tool","Test MAIN output"); + tone.title="Start or stop a quiet tone on the verified MAIN pair without reopening the driver"; + tone.addEventListener("click",()=>{ + backend.emitEvent("arMixAction",{action:"diagnosticRoute",value:"TOGGLE_MAIN_OUTPUT_TONE"}); + }); const mark=item("button","tool","Mark Crackle"); mark.title="Capture 5s before an audible crackle, including Windows memory"; mark.addEventListener("click",()=>{ @@ -2080,7 +2085,7 @@ if(!save)controller?.subscribe(); }); menu.append(caption,setup,muteBtn,hardwareNote, - healthTitle,mark,report,advanced, + healthTitle,tone,mark,report,advanced, showHeading,showSave,showBrowse,showSelect,showUpdate,showRecall,showRecover,showNote); // Single discoverable AUDIO I/O button next to ordinary mixer tools. // The existing More entry remains a shortcut to THIS SAME panel. @@ -2167,7 +2172,10 @@ const session=next?.raw?.mixerSession; if(!session || session.deviceEpoch!==next.device.epoch) { flags.acceptedGraphConnected=false; - status("NATIVE SESSION UNAVAILABLE · controls unchanged"); + flags.productionCallbackLive=false; + lastPaintedSignature=""; + delete document.documentElement.dataset.armixNativeRoster; + status("NATIVE SESSION UNAVAILABLE · verify Audio I/O"); return; } // Never paint unacknowledged controls; pending slider caps are kept @@ -2178,7 +2186,8 @@ reconcileM4RackReadback(next); if(session.authority==="M4" && m4Verified()) { paintM4Fallback(next); - scope?.syncVerifiedM4Wires?.(session.channels.map(ch=>ch.source),m4TrackIds); + if(scope?.syncVerifiedM4Wires?.(session.channels.map(ch=>ch.source),m4TrackIds)) + document.documentElement.dataset.armixNativeRoster="accepted"; } // A second channel's IN can be selected while the first transaction is // in flight. Always dispatch its latest choice with a FRESH native route @@ -2213,8 +2222,10 @@ pendingFxInsert=null;pendingTrackDelete=null;startupWire=null;activeWireAttempt=null; pendingWireGains.clear();pendingNativeControl.clear();liveFaderVisualTargets.clear(); const signature="retained|"+next.identity+"|"+appearanceRevision; - if(lastPaintedSignature!==signature && projectNativeGraphWithoutFocusLoss(next)) + if(lastPaintedSignature!==signature && projectNativeGraphWithoutFocusLoss(next)){ lastPaintedSignature=signature; + document.documentElement.dataset.armixNativeRoster="accepted"; + } stopDemo(); paintNativeMeters(next); status("NEEDS REMAP · mixer retained · output muted"); @@ -2223,13 +2234,14 @@ if (!nativeAdmitted) { flags.productionCallbackLive=false;flags.acceptedGraphConnected=false; lastPaintedSignature="";lastNativeTopologySignature=""; + if(!m4Verified())delete document.documentElement.dataset.armixNativeRoster; stopDemo(); status(m4Verified()? "NATIVE M4 · real PCM faders and meters · ChannelId buses not yet admitted": deviceReady()? "NATIVE G0 · verified physical IN ready · select a channel input": hardware?.device?.enabledInputs?.length===0? - "NO HARDWARE IN · FX/BUS/WIRE REMAIN AVAILABLE": + "NATIVE MIXER UNAVAILABLE · verify playback in Audio I/O": "NATIVE G0 NOT READY · open Audio I/O and verify device / native route"); return; } @@ -2249,6 +2261,7 @@ stopDemo();status("NATIVE READBACK INVALID · existing GUI controls unchanged"); return; } + document.documentElement.dataset.armixNativeRoster="accepted"; flags.productionCallbackLive=next.productLive;flags.acceptedGraphConnected=true; syncMonitorButton(next.device); lastPaintedSignature=signature;stopDemo();paintNativeMeters(next); From c9563d14ed0ff91df81b077c8630610e986fd864 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 19:32:47 +0700 Subject: [PATCH 033/125] Allow explicit MAIN pin recovery without replacing the mixer session Keep normal device Apply anchored to saved physical MAIN pins. Accept deliberate assignment of exactly two driver-verified playback pins, and retry saved-session restore over a pristine startup graph after verified device recovery. --- src/Main.cpp | 40 ++++++++++++++-------- src/NativeMixerSessionDocument.h | 13 +++---- tests/approved_native_cold_start_smoke.py | 24 +++++++++++-- tests/approved_native_m2_contract.test.cjs | 7 ++-- tests/mixer_io_operator_contract_test.mjs | 6 ++-- tests/native_mixer_session_store_test.cpp | 12 +++++++ web/approved-native-bridge.js | 16 +++++++-- 7 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 299157079..e32644a81 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1332,6 +1332,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr serviceAutomaticMain(); } + using MixerBindingMode=armix::session::MixerDeviceBindingPolicy::Mode; bool audioDeviceApplyActive_=false; // JUCE message thread, including nested driver dispatch juce::String openSelectedAudioDevice(const juce::String& backend, @@ -1458,6 +1459,10 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const bool previousWasOpen=previousDevice!=nullptr&&previousDevice->isOpen(); const bool previousMixerBound=engine_.hasBoundMixerRoute(); const bool previousMonitor=engine_.isMonitorEnabled(); + const auto assignMain=config.getProperty("assignSelectedPlaybackPinsToMain",false); + if(!assignMain.isBool()) + return send(false,"REJECTED","Invalid MAIN playback pin selection"); + const bool explicitMain=static_cast(assignMain); const auto confirm=config.getProperty("confirmRetainedPinMapping",false); if(!confirm.isBool()) return send(false,"REJECTED","Invalid retained mixer mapping confirmation"); @@ -1465,7 +1470,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // The first Apply must open and verify the selected device. // Confirmation binds only that exact, still-open generation; // draft rate, buffer and pin changes use the normal Apply path. - if(!sameEndpoint || !previousWasOpen || rate!=before.sampleRate || + if(explicitMain || !sameEndpoint || !previousWasOpen || rate!=before.sampleRate || block!=before.bufferSize || !engine_.confirmRetainedWasapiPortMapping()) return send(false,"NEEDS_REMAP", @@ -1498,6 +1503,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto recovery=armix::device::AudioSetupRecoveryPolicy::select( sameEndpoint,previousWasOpen,typeName=="ASIO", pinInput.isArray()&&pinOutput.isArray()); + if(explicitMain && (!recovery.reuseActivePins || + pinOutput.getArray()->size()!=2)) + return send(false,"REJECTED","Select exactly two inspected playback pins for MAIN."); if(recovery.reuseActivePins) { const auto inCount=juce::jmin(64,previousDevice->getInputChannelNames().size()); const auto outCount=juce::jmin(64,previousDevice->getOutputChannelNames().size()); @@ -1584,7 +1592,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) error="Driver readback mismatch; device setting was not accepted"; if(error.isEmpty())diagnostics_.record("CUSTOM_AUDIO_PHASE","BIND_MIXER | "+typeName); - if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(true)) { + const auto bindingMode=explicitMain?MixerBindingMode::verifiedMainPinApply: + MixerBindingMode::verifiedDeviceApply; + if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(bindingMode)) { if(!previousMixerBound && engine_.directRouteAuthorized() && (engine_.hasRetainedUnboundMixer() || mixerSessionRecoveryPending_)) { const juce::String needsRemap="Device opened. Mixer retained and muted; its port mapping or FX processing format needs review"; @@ -2273,14 +2283,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const bool nativeAlreadyActive=static_cast( live.getProperty("nativeChannelIdPcmActive",false)); // A fresh silent ChannelId starter is now admitted before the saved - // Show is inspected. Only THAT unmodified bootstrap may be replaced, - // and only by this automatic cold-start restore. User-authored FX, + // Show is inspected. Only THAT unmodified bootstrap may be replaced + // by cold-start restore or by verified Apply after a failed startup. User-authored FX, // WIRE, BUS and fader edits must never be overwritten by late scan. // A verified PREVIOUS checkpoint is also eligible: the separate // resume policy keeps MAIN muted after recovery from corrupt HEAD. - const bool replacePristineStartup=nativeAlreadyActive && - startupOnSavedDevice && !retained && - bindingMode==armix::session::MixerDeviceBindingPolicy::Mode::exact && + const bool recoveringAfterDeviceApply=bindingMode!=MixerBindingMode::exact && + mixerSessionRecoveryPending_; + const bool replacePristineStartup=nativeAlreadyActive && !retained && + (startupOnSavedDevice || recoveringAfterDeviceApply) && engine_.hasPristineStartupMixer(); if(nativeAlreadyActive && !replacePristineStartup) { mixerSessionStatus_="LIVE_MIXER_UNCHANGED"; @@ -4643,16 +4654,17 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } } - bool finishAudioSetupAndRecoverMixer(bool verifiedDeviceApply=false) { + bool finishAudioSetupAndRecoverMixer(MixerBindingMode bindingMode=MixerBindingMode::exact) { const bool bound=engine_.finishManualAudioSetup(); if(!engine_.directRouteAuthorized())return false; const auto lab=engine_.status().getProperty("dryRoutingLab",{}); - if(static_cast(lab.getProperty("nativeChannelIdPcmActive",false)))return true; - if(engine_.hasRetainedNativeSession() || - armix::session::NativeMixerSessionStore(settingsDirectory()).exists()) { - using BindingMode=armix::session::MixerDeviceBindingPolicy::Mode; - const auto error=restoreSavedMixerSession(false,verifiedDeviceApply? - BindingMode::verifiedDeviceApply:BindingMode::exact); + const bool hasCheckpoint=armix::session::NativeMixerSessionStore(settingsDirectory()).exists(); + const bool recoverPristine=bindingMode!=MixerBindingMode::exact && hasCheckpoint && + mixerSessionRecoveryPending_ && engine_.hasPristineStartupMixer(); + if(static_cast(lab.getProperty("nativeChannelIdPcmActive",false)) && + !recoverPristine)return true; + if(engine_.hasRetainedNativeSession() || hasCheckpoint) { + const auto error=restoreSavedMixerSession(false,bindingMode); if(error.isNotEmpty()) { mixerSessionError_=error; emitNotice("Mixer retained; "+error,true); diff --git a/src/NativeMixerSessionDocument.h b/src/NativeMixerSessionDocument.h index d89b47a78..bdd014941 100644 --- a/src/NativeMixerSessionDocument.h +++ b/src/NativeMixerSessionDocument.h @@ -65,12 +65,13 @@ struct MixerDeviceBindingPolicy final { (!a.monitorEnabled || (a.monitorL==b.monitorL && a.monitorR==b.monitorR)); } - enum class Mode { exact, verifiedDeviceApply }; + enum class Mode { exact, verifiedDeviceApply, verifiedMainPinApply }; static VerifiedNativeOutputs proposedOutputs(const MixerSessionDocument& document, const HardwareBinding& live,int count,Mode mode=Mode::exact) { const auto& saved=document.binding; - if(mode==Mode::verifiedDeviceApply && - (saved.backend!=live.backend || saved.playback!=live.playback)) + if(mode==Mode::verifiedMainPinApply || + (mode==Mode::verifiedDeviceApply && + (saved.backend!=live.backend || saved.playback!=live.playback))) return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}: VerifiedNativeOutputs{count,-1,-1,-1,-1,false}; // A matching endpoint name does NOT prove an unchanged physical @@ -134,9 +135,9 @@ struct MixerDeviceBindingPolicy final { // ordinals; it never authorizes quietly switching MAIN to another // jack. Compare against the policy-computed remap even when a caller // supplies a valid but DIFFERENT output pair. - if(saved.backend==live.backend && saved.playback==live.playback) { - const auto mapped=proposedOutputs(document,live, - outputs.activeOutputChannels,Mode::verifiedDeviceApply); + if(mode==Mode::verifiedMainPinApply || + (saved.backend==live.backend && saved.playback==live.playback)) { + const auto mapped=proposedOutputs(document,live,outputs.activeOutputChannels,mode); if(!mapped.valid() || !sameOutputs(mapped,outputs)) return "NEEDS_REMAP: saved MAIN output pins are no longer selected; explicitly choose MAIN outputs"; } diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index f7016c754..9d0a0fec9 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -76,7 +76,8 @@ def main(): assert request['config']['enabledInputs']==[] assert request['config']['enabledOutputs']==[] out_active={**io_inventory['active'],'captureDevice':'', - 'inputNames':[],'enabledInputs':[]} + 'inputNames':[],'enabledInputs':[], + 'outputNames':['WDM L','WDM R','Realtek L','Realtek R']} emit(page,'arMixAudioDeviceApplyAck',{ 'requestId':request['requestId'],'ok':True, 'state':'ACCEPTED_MUTED','active':out_active, @@ -86,7 +87,26 @@ def main(): io_inventory['active']=out_active emit(page,'arMixAudioDeviceInventory',io_inventory) assert capture_select.input_value()=='' # reopening does not auto-patch a mic - page.locator('.armix-audio-dialog [data-audio-close]').click() + page.locator('.armix-audio-dialog details summary').click() + assign_main=page.locator('[data-audio-main-pins]') + def playback_pin(index): + return page.locator(f'[data-audio-pin="output"][data-pin-index="{index}"]') + playback_pin(0).uncheck() + assert assign_main.is_hidden() + playback_pin(1).uncheck() + playback_pin(2).check() + playback_pin(3).check() + assign_main.click() + repatch=page.evaluate("""()=>window.__events.filter(e=> + e.payload?.action==='audioDeviceApply').at(-1)?.payload""") + assert repatch['config']['assignSelectedPlaybackPinsToMain'] is True + assert repatch['config']['enabledOutputs']==[2,3] + assert repatch['config']['enabledInputs']==[] + emit(page,'arMixAudioDeviceApplyAck',{ + 'requestId':repatch['requestId'],'ok':True, + 'state':'ACCEPTED_MUTED','active':{**out_active,'enabledOutputs':[2,3]}, + 'outputMuted':True,'mixerBound':True}) + assert page.locator('.armix-audio-shade').is_hidden() g0=json.loads((ROOT/'integration/console-v6/fixtures.json').read_text())['g0'] g0['mixerSession']={'authority':'NONE','deviceEpoch':g0['device']['epoch'],'channels':[]} g0['legacyM4']={'active':True,'routeAccepted':False,'routingRevision':'1'} diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 51f903a50..8617140bc 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1246,8 +1246,9 @@ test("P0 automatic cold-start Show replaces only pristine SOURCE NONE ChannelId" const main=read('src/Main.cpp'); const engine=read('src/LiveAudioEngine.h'); const route=read('src/LiveDryRoutingLab.h'); - assert.match(main,/startupOnSavedDevice && !retained &&/); - assert.doesNotMatch(main,/startupOnSavedDevice && !retained && !usedPrevious/); + assert.match(main,/nativeAlreadyActive && !retained &&/); + assert.match(main,/\(startupOnSavedDevice \|\| recoveringAfterDeviceApply\) &&/); + assert.match(main,/recoveringAfterDeviceApply=bindingMode!=MixerBindingMode::exact &&\s*mixerSessionRecoveryPending_/); assert.match(main,/!usedPrevious && !retained/); // only normal auto-resume, not recovery admission assert.match(main,/engine_\.hasPristineStartupMixer\(\)/); assert.match(main,/restoreNativeMixerSession\(std::move\(doc\),states,\s*replacePristineStartup/); @@ -1259,7 +1260,7 @@ test("P0 automatic cold-start Show replaces only pristine SOURCE NONE ChannelId" test("P0 startup banner never demands legacy Patch CH1 / Arm wizard",()=>{ const bridge=read("web/approved-native-bridge.js"); assert.match(bridge,/SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK/); - assert.match(bridge,/NO HARDWARE IN · MIXER\/FX READY · USE PLAYER OR AUDIO I\/O/); + assert.match(bridge,/next.admitted\?"NO HARDWARE IN · MIXER\/FX READY"/); assert.doesNotMatch(bridge,/hardware\.device\.enabledInputs\.length>0/); assert.match(bridge,/NO VERIFIED INPUT ROUTE · OPEN AUDIO I\/O/); assert.doesNotMatch(bridge,/NO AUDIBLE OUTPUT · PATCH INPUT \+ ARM/); diff --git a/tests/mixer_io_operator_contract_test.mjs b/tests/mixer_io_operator_contract_test.mjs index 157d8917a..ce8dc23f8 100644 --- a/tests/mixer_io_operator_contract_test.mjs +++ b/tests/mixer_io_operator_contract_test.mjs @@ -227,10 +227,12 @@ test('DEVICE1 existing matrix drives real JUCE manager with gated native readbac test('explicit device Apply restores the authored mixer after driver readback and can roll back',()=>{ const main=read('src/Main.cpp'); const apply=main.slice(main.indexOf('void applyCustomAudioDevice('),main.indexOf('void showDeviceSetup()')); - assert.match(apply,/if\(error\.isEmpty\(\)&&!finishAudioSetupAndRecoverMixer\(true\)\)/); + assert.match(apply,/if\(error\.isEmpty\(\)&&!finishAudioSetupAndRecoverMixer\(bindingMode\)\)/); assert.match(apply,/if\(!previousMixerBound && engine_\.directRouteAuthorized\(\)/); assert.match(apply,/finishAudioSetupAndRecoverMixer\(\);/); - assert.match(main,/BindingMode::verifiedDeviceApply:BindingMode::exact/); + assert.match(apply,/explicitMain\?MixerBindingMode::verifiedMainPinApply/); + assert.match(apply,/pinOutput.getArray\(\)->size\(\)!=2/); + assert.match(main,/restoreSavedMixerSession\(false,bindingMode\)/); }); test('SETUP1 honest bus patch has real AUX/MAIN/MONITOR navigation, no fake GROUP DCA',()=>{ diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 3dadd54e1..5e9d56fb8 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -489,6 +489,18 @@ int main(){ assert(MixerDeviceBindingPolicy::apply(main34,only12,unauthorized12,2, BindingMode::verifiedDeviceApply).startsWith("NEEDS_REMAP")); assert(Codec::encode(main34)==main34Before); + // Deliberate MAIN assignment through the verified current two-pin mask + // is distinct from a normal Apply that must preserve the original pair. + auto explicitlyRepatched=main34; + const auto explicitPair=MixerDeviceBindingPolicy::proposedOutputs( + main34,only12,2,BindingMode::verifiedMainPinApply); + assert(explicitPair.valid() && explicitPair.mainL==0 && explicitPair.mainR==1); + assert(MixerDeviceBindingPolicy::apply(explicitlyRepatched,only12,explicitPair,2, + BindingMode::verifiedMainPinApply).isEmpty()); + assert(explicitlyRepatched.binding.outputMask=="3"); + assert(explicitlyRepatched.roster.revision()==main34.roster.revision()); + assert(!MixerDeviceBindingPolicy::proposedOutputs(main34,main34.binding,4, + BindingMode::verifiedMainPinApply).valid()); // If outputs 3/4 remain physically selected, ordinal 2/3 -> 0/1 // is a legal SAME-PIN remap, not an automatic route to different jacks. auto only34=main34.binding; diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index af49d6e55..1747fec56 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1525,7 +1525,8 @@ !deviceOpen?"NO VERIFIED AUDIO DEVICE": d.outputArmed?(next.admitted?"NATIVE PCM · HARDWARE FAT PENDING": "MAIN MONITOR ON · PCM ADMISSION NOT VERIFIED"): - !d.enabledInputs?.length?"NO HARDWARE IN · MIXER/FX READY · USE PLAYER OR AUDIO I/O": + !d.enabledInputs?.length?(next.admitted?"NO HARDWARE IN · MIXER/FX READY": + "MIXER SESSION UNAVAILABLE · CHECK AUDIO I/O"): legacy()?.routeAccepted?"NATIVE INPUT ROUTED · MONITOR OFF": deviceReady()?"SELECT CHANNEL IN · NATIVE MONITOR AFTER ACK": "NO VERIFIED INPUT ROUTE · OPEN AUDIO I/O"; @@ -1638,6 +1639,7 @@
+
@@ -1691,6 +1693,9 @@ if(!draft.backend||!draft.playback||(!separate&&!draft.capture))return; sendDeviceApply(); }; + devicePanel.querySelector("[data-audio-main-pins]").onclick=()=>{ + if(!deviceBusy)sendDeviceApply(false,true); + }; devicePanel.querySelector("[data-audio-remap]").onclick=()=>{ if(!deviceBusy && offeredPinRemap!==null) sendDeviceApply(true); @@ -1787,17 +1792,21 @@ devicePanel.querySelector("[data-audio-apply]").disabled=deviceBusy|| !deviceChoice.backend||(!t?.separate&&!deviceChoice.capture)|| !deviceChoice.playback; + const assignMain=devicePanel.querySelector("[data-audio-main-pins]"); + assignMain.hidden=!same || deviceChoice.outputPins?.length!==2; + assignMain.disabled=deviceBusy; const remap=devicePanel.querySelector("[data-audio-remap]"); remap.hidden=!same || offeredPinRemap!==active.deviceGeneration; remap.disabled=deviceBusy; remap.title="Reuse existing input and output pin numbers on the selected device. MONITOR stays off."; } - function sendDeviceApply(confirmRetainedPinMapping=false){ + function sendDeviceApply(confirmRetainedPinMapping=false,assignMain=false){ if(!deviceChoice||!deviceInventory?.active)return; const c=deviceChoice,a=deviceInventory.active; const same=a.open&&a.backend===c.backend&& a.captureDevice===c.capture&&a.playbackDevice===c.playback; if(confirmRetainedPinMapping && (!same || offeredPinRemap!==a.deviceGeneration))return; + if(assignMain && (!same || c.outputPins?.length!==2))return; deviceBusy=true; const requestId="approved-io-"+(++deviceRequest); devicePanel.dataset.pendingRequest=requestId; @@ -1811,7 +1820,8 @@ bufferSize:confirmRetainedPinMapping?a.buffer:same?c.buffer:0, enabledInputs:same?c.inputPins:[], enabledOutputs:same?c.outputPins:[], - ...(confirmRetainedPinMapping?{confirmRetainedPinMapping:true}:{})}}); + ...(confirmRetainedPinMapping?{confirmRetainedPinMapping:true}:{}), + ...(assignMain?{assignSelectedPlaybackPinsToMain:true}:{})}}); } if(connected){ backend.addEventListener("arMixAudioDeviceInventory",inventory=>{ From 29f29acd1495406ed3748cf0a9f0b4086ad13392 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:14:13 +0700 Subject: [PATCH 034/125] Recover ASIO4ALL mixer bindings by verified physical pin labels Reconcile changed compact ordinals without losing the VB-Cable source, resume same-driver restarts with a bounded pin correction, and keep authored FX on compatible device epochs. Adopt a single verified physical speaker pair on explicit Apply when the old pair is gone. --- src/LiveAudioEngine.h | 83 ++++++++++++++- src/LiveDryRoutingLab.h | 3 + src/Main.cpp | 98 ++++++++++++++++-- src/NativeMixerSessionDocument.h | 120 ++++++++++++++++------ tests/mixer_io_operator_contract_test.mjs | 7 +- tests/native_mixer_session_store_test.cpp | 81 ++++++++++++++- web/approved-native-bridge.js | 5 +- 7 files changed, 348 insertions(+), 49 deletions(-) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 9c82f5ae3..ba6525b18 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -396,6 +396,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // starts its new callback before the selector window is closed. void beginManualAudioSetup() noexcept { offeredWasapiBinding_.reset(); + resumeMainAfterAsioReset_.store(false,std::memory_order_release); setOutputMuted(true); secondaryOutput_.disarm(); directFence_.suspend(); @@ -403,7 +404,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // device-binding operation, not an implicit CLEAR MIXER command. // The JUCE selector may change the driver before its window closes. } - bool finishManualAudioSetup() { + bool finishManualAudioSetup(bool reuseAsioBinding=true) { if(!approveDirectRoute())return false; using Decision=armix::device::DeviceSessionDecision; switch(armix::device::decideDeviceSession( @@ -414,7 +415,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback case Decision::createFirstSilentMixer: return startUnpatchedProductionSession().isEmpty(); case Decision::retainUnboundMixer: - return rebindRetainedWasapiSession(); + return (reuseAsioBinding && reattachRetainedAsioMixer()) || rebindRetainedWasapiSession(); case Decision::rejectedDevice: return false; } @@ -444,6 +445,79 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback bool recoverSameWasapiMixer() { return hasRetainedUnboundMixer() && rebindRetainedWasapiSession(); } + // The JUCE ASIO device may restart itself after a control panel change. + // Reauthorize only the previously approved driver class and session. + bool authorizeRetainedAsioRestart() { + using Policy=armix::session::MixerDeviceBindingPolicy; + if(!hasRetainedNativeSession() || !acceptedMixerBinding_ || + !Policy::isAsio4All(*acceptedMixerBinding_) || !asioPinnedRegistration_.valid() || + !allOutputsDisarmed() || independent_.active() || !attached_ || handoff_.busy() || + fxMovePhase_.load(std::memory_order_acquire)!=0 || + routeReconfiguring_.load(std::memory_order_acquire) || + diagnosticRoute()!=armix::diagnostics::Route::normal)return false; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !device->isOpen() || device->getTypeName()!="ASIO" || + device->getName()!=acceptedMixerBinding_->playback)return false; + return approveDirectRoute(&asioPinnedRegistration_); + } + std::optional asioRestartPinCorrection() { + using Policy=armix::session::MixerDeviceBindingPolicy; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !acceptedMixerBinding_ || !directFence_.permitted())return {}; + const auto& previous=*acceptedMixerBinding_; + const auto live=readMixerBinding(*device); + if(live.backend!=previous.backend || live.capture!=previous.capture || + live.playback!=previous.playback)return {}; + juce::AudioDeviceManager::AudioDeviceSetup setup; + deviceManager_.getAudioDeviceSetup(setup); + const auto correct=[](const juce::String& oldMask,const juce::StringArray& oldNames, + const juce::StringArray& newNames,juce::BigInteger& mask, + bool& useDefault) { + if(oldNames==newNames)return false; + juce::BigInteger before; + before.parseString(oldMask,16); + const auto mapped=Policy::translateNamedPins(before,oldNames,newNames); + if(!mapped || *mapped==mask)return false; + mask=*mapped; + useDefault=false; + return true; + }; + const bool input=correct(previous.inputMask,previous.inputNames,live.inputNames, + setup.inputChannels,setup.useDefaultInputChannels); + const bool output=correct(previous.outputMask,previous.outputNames,live.outputNames, + setup.outputChannels,setup.useDefaultOutputChannels); + if(!input && !output)return {}; + setup.useDefaultInputChannels=false; + setup.useDefaultOutputChannels=false; + return setup; + } + bool reattachRetainedAsioMixer() { + using Policy=armix::session::MixerDeviceBindingPolicy; + if(!acceptedMixerBinding_ || !Policy::isAsio4All(*acceptedMixerBinding_) || + !hasRetainedNativeSession() || !allOutputsDisarmed() || + !directFence_.permitted() || handoff_.busy())return false; + const auto* previous=&*acceptedMixerBinding_; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device || !device->isOpen())return false; + const auto epoch=dryRoutingLab_.epoch(); + const auto live=readMixerBinding(*device); + armix::device::JuceActivePortSnapshot pins; + armix::device::JuceActivePortSnapshot::Fault fault{}; + if(!Policy::sameBinding(*previous,live) || previous->inputNames!=live.inputNames || + previous->outputNames.isEmpty() || previous->outputNames!=live.outputNames || + !armix::device::JuceActivePortSnapshot::capture(device,epoch,pins,fault) || + !dryRoutingLab_.matchesSessionDevice(pins) || + !dryRoutingLab_.rebindVerifiedDevice(dryRoutingLab_.retainedNativeEpoch(), + epoch,live.frames,false))return false; + acceptedMixerBinding_=live; + return true; + } + bool takeAsioResetMonitorIntent() noexcept { + return resumeMainAfterAsioReset_.exchange(false,std::memory_order_acq_rel); + } + void cancelAsioResetMonitorIntent() noexcept { + resumeMainAfterAsioReset_.store(false,std::memory_order_release); + } bool hasRetainedNativeSession() const noexcept { return dryRoutingLab_.hasRetainedNativeSession(); } @@ -2442,6 +2516,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback const auto inputMask=device->getActiveInputChannels().toString (16); const auto outputMask=device->getActiveOutputChannels().toString (16); armix::device::AsioRegistrationPolicy::Identity candidate; + if (backend != "ASIO" && expectedAsio != nullptr)return false; if (backend == "ASIO") { const auto selected = armix::device::AsioRegistryIdentityProbe::resolve ( @@ -2534,6 +2609,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback // Temporary publication silence never changes operator MONITOR or MAIN MUTE. // The DIRECT device fence and physical-output verification remain separate. std::atomic topologyPublicationMute_ { false }; + std::atomic resumeMainAfterAsioReset_{false}; std::atomic monitor_ { false }, channelMute_ { false }, masterMute_ { false }, masterMono_ { false }, dryTest_ { false }; std::atomic masterGain_ { 1.f }, channelGain_ { 1.f }, channelPan_ { 0.f }; std::atomic inputPeak_ { 0.f }, postFxPeak_ { 0.f }, outputPeak_ { 0.f }; @@ -2673,7 +2749,8 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback void audioDeviceStopped() override { - setOutputMuted(true); + if(monitor_.exchange(false,std::memory_order_acq_rel)) + resumeMainAfterAsioReset_.store(true,std::memory_order_release); secondaryOutput_.invalidateSource(); // explicit reconnect required after device stop masterLoudness_.prepare (0.0); // clear validity across device epoch dryRoutingLab_.deviceStopped(); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 5a4d019c0..21ae5578b 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -2494,6 +2494,9 @@ class LiveDryRoutingLab final { // CONTROL ONLY: hardware loss makes ready() false but does not erase // authored values, FX identity, GROUP/FX_RETURN buses or accepted WIREs. // Never downgrade this dynamic document to the fixed 10CH/4AUX schema. + std::uint64_t retainedNativeEpoch() const noexcept { + return hasRetainedNativeSession()?nativeAccepted_.deviceEpoch:0; + } bool hasRetainedNativeSession() const noexcept { return !channelIdPhysicalPcmActive() && nativeAccepted_.fxOwners && hasAuthoredMixerContent(); } diff --git a/src/Main.cpp b/src/Main.cpp index e32644a81..196cfccf6 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1275,7 +1275,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr o->setProperty("open",device!=nullptr&&device->isOpen()); o->setProperty("authorized",engine_.directRouteAuthorized()); o->setProperty("outputMuted",engine_.isOutputMuted()); - o->setProperty("deviceGeneration",engine_.status().getProperty("deviceGeneration",0)); + const auto live=engine_.status(); + o->setProperty("deviceGeneration",live.getProperty("deviceGeneration",0)); + o->setProperty("mainOutputs",live.getProperty("dryRoutingLab",{}).getProperty("mainOutputs",{})); juce::Array inputNames,outputNames,inputPins,outputPins,rates,buffers; if(device!=nullptr&&device->isOpen()) { const auto inputs=device->getInputChannelNames(); @@ -1336,9 +1338,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr bool audioDeviceApplyActive_=false; // JUCE message thread, including nested driver dispatch juce::String openSelectedAudioDevice(const juce::String& backend, - const juce::AudioDeviceManager::AudioDeviceSetup& setup) { + const juce::AudioDeviceManager::AudioDeviceSetup& setup,bool resetDefaults=false) { auto& manager=engine_.devices(); - if(manager.getCurrentAudioDeviceType()==backend) { + if(manager.getCurrentAudioDeviceType()==backend && !resetDefaults) { if(auto* device=manager.getCurrentAudioDevice();device && !device->isOpen()) manager.closeAudioDevice(); return manager.setAudioDeviceSetup(setup,true); @@ -1572,12 +1574,40 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr juce::AudioDeviceManager::AudioDeviceSetup actual; manager.getAudioDeviceSetup(actual); auto* opened=manager.getCurrentAudioDevice(); - const bool changedAsioPinLayout=error.isEmpty()&&recovery.verifyAsioPinIdentity&& + bool changedAsioPinLayout=error.isEmpty()&&recovery.verifyAsioPinIdentity&& opened!=nullptr&&opened->isOpen()&& (opened->getInputChannelNames()!=originalInputNames|| opened->getOutputChannelNames()!=originalOutputNames); + const bool refreshedAsio4All=typeName=="ASIO" && playback.startsWithIgnoreCase("ASIO4ALL") && + recovery.reuseActivePins && (changedAsioPinLayout || error.isNotEmpty()); + bool explicitPairStillIdentified=explicitMain; + if(refreshedAsio4All) { + // Never replay an index into a newly enumerated ASIO aggregate. + // Preserve verified selected names if they still exist, including + // VB-Cable capture moved past newly enabled input channels. + using BindingPolicy=armix::session::MixerDeviceBindingPolicy; + const auto freshInputNames=changedAsioPinLayout?opened->getInputChannelNames():juce::StringArray{}; + const auto freshOutputNames=changedAsioPinLayout?opened->getOutputChannelNames():juce::StringArray{}; + const auto capturePins=changedAsioPinLayout?BindingPolicy::translateNamedPins( + candidate.inputChannels,originalInputNames,freshInputNames):std::nullopt; + const auto playbackPins=changedAsioPinLayout?BindingPolicy::translateNamedPins( + candidate.outputChannels,originalOutputNames,freshOutputNames):std::nullopt; + candidate.useDefaultInputChannels=!capturePins && !candidate.inputChannels.isZero(); + candidate.useDefaultOutputChannels=!playbackPins; + if(capturePins)candidate.inputChannels=*capturePins; + if(playbackPins)candidate.outputChannels=*playbackPins; + explicitPairStillIdentified=explicitMain && playbackPins.has_value(); + diagnostics_.record("CUSTOM_AUDIO_PHASE","REFRESH_ASIO4ALL_INVENTORY"); + error=openSelectedAudioDevice(typeName,candidate,true); + manager.getAudioDeviceSetup(actual); + opened=manager.getCurrentAudioDevice(); + changedAsioPinLayout=error.isEmpty() && opened && opened->isOpen() && + ((capturePins && opened->getInputChannelNames()!=freshInputNames) || + (playbackPins && opened->getOutputChannelNames()!=freshOutputNames)); + } + asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); if(changedAsioPinLayout) - error="ASIO pin layout changed. Output remains muted; review the NEW capture and playback pins and Apply again"; + error="ASIO pin layout changed. Output remains muted; review the new playback pins."; if(error.isEmpty()&&(opened==nullptr||!opened->isOpen()|| manager.getCurrentAudioDeviceType()!=typeName|| actual.inputDeviceName!=capture||actual.outputDeviceName!=playback|| @@ -1592,12 +1622,13 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) error="Driver readback mismatch; device setting was not accepted"; if(error.isEmpty())diagnostics_.record("CUSTOM_AUDIO_PHASE","BIND_MIXER | "+typeName); - const auto bindingMode=explicitMain?MixerBindingMode::verifiedMainPinApply: + const auto bindingMode=explicitPairStillIdentified?MixerBindingMode::verifiedMainPinApply: MixerBindingMode::verifiedDeviceApply; if(error.isEmpty()&&!finishAudioSetupAndRecoverMixer(bindingMode)) { if(!previousMixerBound && engine_.directRouteAuthorized() && (engine_.hasRetainedUnboundMixer() || mixerSessionRecoveryPending_)) { - const juce::String needsRemap="Device opened. Mixer retained and muted; its port mapping or FX processing format needs review"; + const auto needsRemap=mixerSessionError_.isNotEmpty()?mixerSessionError_: + juce::String("Device opened, but the mixer could not bind to its playback pins."); diagnostics_.record("CUSTOM_AUDIO_NEEDS_REMAP",needsRemap); send(false,"NEEDS_REMAP",needsRemap,engine_.stageRetainedWasapiPortMapping()); emitApprovedNativeSnapshot(); @@ -1646,6 +1677,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (manager.getCurrentAudioDevice()->getInputChannelNames()==originalInputNames&& manager.getCurrentAudioDevice()->getOutputChannelNames()==originalOutputNames))&& finishAudioSetupAndRecoverMixer(); + asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); diagnostics_.record("CUSTOM_AUDIO_APPLY_FAIL",error+" | rollback="+ (verified?"RESTORED":"RECOVERY_REQUIRED")+" | "+ juce::String(static_cast(monotonicMilliseconds()-start))+" ms"); @@ -4623,6 +4655,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr fault=engine_.liveOutputArmFault(); if (fault.isEmpty()) { autoMainEpoch_=0; + if(!arm)engine_.cancelAsioResetMonitorIntent(); engine_.setMonitorEnabled(arm); diagnostics_.record("OUTPUT_MUTE",arm?"OFF":"ON"); } @@ -4655,7 +4688,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } bool finishAudioSetupAndRecoverMixer(MixerBindingMode bindingMode=MixerBindingMode::exact) { - const bool bound=engine_.finishManualAudioSetup(); + const bool bound=engine_.finishManualAudioSetup(bindingMode!=MixerBindingMode::verifiedMainPinApply); if(!engine_.directRouteAuthorized())return false; const auto lab=engine_.status().getProperty("dryRoutingLab",{}); const bool hasCheckpoint=armix::session::NativeMixerSessionStore(settingsDirectory()).exists(); @@ -4675,6 +4708,54 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr return bound; } + std::uint64_t asioRecoveryEpoch_=0; + void serviceAsioMixerRestart() { + const auto epoch=engine_.dryRoutingLabEpoch(); + if(epoch==asioRecoveryEpoch_ || !engine_.hasRetainedNativeSession() || + nativeShowBusy_ || studioBackupBusy_ || mixerSessionWorker_.busy() || catalog_.busy() || + engine_.isGraphSwitchPending() || + (audioSetupWindow_ && audioSetupWindow_->isVisible()))return; + auto* device=engine_.devices().getCurrentAudioDevice(); + if(!device || !device->isOpen() || device->getTypeName()!="ASIO" || + !device->getName().startsWithIgnoreCase("ASIO4ALL"))return; + asioRecoveryEpoch_=epoch; // at most one automatic bind per negotiated epoch + const juce::ScopedValueSetter applying(audioDeviceApplyActive_,true); + if(!engine_.authorizeRetainedAsioRestart())return; + if(const auto corrected=engine_.asioRestartPinCorrection()) { + // One bounded correction for JUCE's restart with the old mask. + // Keep the approved driver and preserve named physical endpoints. + const auto inputNames=device->getInputChannelNames(); + const auto outputNames=device->getOutputChannelNames(); + const auto error=openSelectedAudioDevice("ASIO",*corrected); + asioRecoveryEpoch_=engine_.dryRoutingLabEpoch(); + auto* reopened=engine_.devices().getCurrentAudioDevice(); + if(error.isNotEmpty() || !reopened || !reopened->isOpen() || + reopened->getInputChannelNames()!=inputNames || + reopened->getOutputChannelNames()!=outputNames || + reopened->getActiveInputChannels()!=corrected->inputChannels || + reopened->getActiveOutputChannels()!=corrected->outputChannels || + !engine_.authorizeRetainedAsioRestart()) { + diagnostics_.record("ASIO4ALL_PIN_CORRECTION_FAILED", + error.isNotEmpty()?error:juce::String("Readback changed during correction")); + emitApprovedNativeSnapshot(); + return; + } + } + const auto error=engine_.reattachRetainedAsioMixer()?juce::String{}: + restoreSavedMixerSession(false,MixerBindingMode::verifiedAsioRestart); + if(error.isNotEmpty()) { + diagnostics_.record("ASIO4ALL_REATTACH_FAILED",error); + emitApprovedNativeSnapshot(); + return; + } + mixerSessionStatus_="RESTORED_MUTED"; + mixerSessionError_.clear(); + if(engine_.takeAsioResetMonitorIntent())requestAutomaticMain(); + if(engine_.isMonitorEnabled())mixerSessionStatus_="RESTORED_MONITORING"; + diagnostics_.record("ASIO4ALL_REATTACHED","Verified driver and original MAIN pair"); + emitApprovedNativeSnapshot(); + } + void changeListenerCallback (juce::ChangeBroadcaster*) override { if(audioDeviceApplyActive_)return; // synchronous transaction owns recovery @@ -4780,6 +4861,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // Audio thread publishes only fault flags. A bounded message-thread // restore transaction handles device failures without hot-plug spin. serviceDirectRestore(); + serviceAsioMixerRestart(); serviceAutomaticMain(); // Autosave only while ALL outputs are muted. Vendor-state reads // happen on CONTROL; disk commits run on ONE serialized IO worker. diff --git a/src/NativeMixerSessionDocument.h b/src/NativeMixerSessionDocument.h index bdd014941..62f201b8b 100644 --- a/src/NativeMixerSessionDocument.h +++ b/src/NativeMixerSessionDocument.h @@ -65,49 +65,65 @@ struct MixerDeviceBindingPolicy final { (!a.monitorEnabled || (a.monitorL==b.monitorL && a.monitorR==b.monitorR)); } - enum class Mode { exact, verifiedDeviceApply, verifiedMainPinApply }; + enum class Mode { exact, verifiedDeviceApply, verifiedMainPinApply, verifiedAsioRestart }; + static bool isAsio4All(const HardwareBinding& binding) { + return binding.backend=="ASIO" && binding.playback.startsWithIgnoreCase("ASIO4ALL"); + } + static std::optional translateNamedPins( + const juce::BigInteger& previous,const juce::StringArray& oldNames, + const juce::StringArray& newNames) { + juce::BigInteger result; + for(int pin=previous.findNextSetBit(0);pin>=0;pin=previous.findNextSetBit(pin+1)) { + const int next=findSamePin(oldNames,newNames,pin); + if(next<0 || next>=64)return {}; + result.setBit(next); + } + return result; + } static VerifiedNativeOutputs proposedOutputs(const MixerSessionDocument& document, const HardwareBinding& live,int count,Mode mode=Mode::exact) { const auto& saved=document.binding; + const VerifiedNativeOutputs unavailable{count,-1,-1,-1,-1,false}; if(mode==Mode::verifiedMainPinApply || (mode==Mode::verifiedDeviceApply && (saved.backend!=live.backend || saved.playback!=live.playback))) - return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}: - VerifiedNativeOutputs{count,-1,-1,-1,-1,false}; - // A matching endpoint name does NOT prove an unchanged physical - // jack inventory. Reject rather than silently rebase MAIN to 1/2 - // if pin labels changed or an unknown ASIO inventory lost pins. - if(mode==Mode::verifiedDeviceApply && - ((!saved.outputNames.isEmpty() && saved.outputNames!=live.outputNames) || - (saved.outputNames.isEmpty() && live.backend=="ASIO" && - saved.outputMask!=live.outputMask))) - return {count,-1,-1,-1,-1,false}; + return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}:unavailable; + if(mode==Mode::verifiedAsioRestart && + (!isAsio4All(live) || saved.backend!=live.backend || saved.playback!=live.playback)) + return unavailable; + if(mode==Mode::verifiedAsioRestart && saved.outputNames.isEmpty())return unavailable; auto outputs=document.outputs; outputs.activeOutputChannels=count; - if(saved.outputMask!=live.outputMask) { - const auto oldPins=mask(saved.outputMask); - const auto newPins=mask(live.outputMask); - outputs.mainL=remapPin(oldPins,newPins,outputs.mainL); - outputs.mainR=remapPin(oldPins,newPins,outputs.mainR); + const auto oldPins=mask(saved.outputMask),newPins=mask(live.outputMask); + if(mode!=Mode::exact || saved.outputMask!=live.outputMask) { + const auto remap=[&](int ordinal) { + return remapPin(oldPins,newPins,saved.outputNames,live.outputNames, + ordinal,live.backend=="ASIO"); + }; + outputs.mainL=remap(outputs.mainL); + outputs.mainR=remap(outputs.mainR); if(outputs.monitorEnabled) { - outputs.monitorL=remapPin(oldPins,newPins,outputs.monitorL); - outputs.monitorR=remapPin(oldPins,newPins,outputs.monitorR); + outputs.monitorL=remap(outputs.monitorL); + outputs.monitorR=remap(outputs.monitorR); } } if(!outputs.valid()) { outputs.monitorL=outputs.monitorR=-1; outputs.monitorEnabled=false; } - // Never substitute the first available pair when the saved MAIN - // physical connectors disappear. Audio may only return after the - // operator explicitly patches MAIN to available output pins. + // An explicit Apply can adopt the sole coherent physical pair that + // ASIO4ALL now exposes. An unsolicited restart can only resume the + // original named MAIN pair, even if another pair is now available. + if(!outputs.valid() && mode==Mode::verifiedDeviceApply && + isAsio4All(live) && count==2 && isNamedSpeakerPair(newPins,live.outputNames)) + return {count,0,1,-1,-1,false}; return outputs; } static juce::String apply(MixerSessionDocument& document, const HardwareBinding& live, const VerifiedNativeOutputs& outputs, int callbackInputs,Mode mode) { - if(!outputs.valid() || callbackInputs<0 || callbackInputs>256 || + if(callbackInputs<0 || callbackInputs>256 || live.backend.isEmpty() || (callbackInputs>0 && live.capture.isEmpty()) || live.playback.isEmpty() || live.inputMask.isEmpty() || @@ -115,6 +131,8 @@ struct MixerDeviceBindingPolicy final { live.rate<8000. || live.rate>384000. || live.frames<16 || live.frames>8192) return "NEEDS_REMAP: live device verification incomplete"; + if(!outputs.valid()) + return "NEEDS_REMAP: saved MAIN pair unavailable on the active playback pins"; const auto oldPins=mask(document.binding.inputMask); const auto newPins=mask(live.inputMask); if(oldPins.countNumberOfSetBits()!=document.request.physicalInputs || @@ -135,7 +153,7 @@ struct MixerDeviceBindingPolicy final { // ordinals; it never authorizes quietly switching MAIN to another // jack. Compare against the policy-computed remap even when a caller // supplies a valid but DIFFERENT output pair. - if(mode==Mode::verifiedMainPinApply || + if(mode==Mode::verifiedMainPinApply || mode==Mode::verifiedAsioRestart || (saved.backend==live.backend && saved.playback==live.playback)) { const auto mapped=proposedOutputs(document,live,outputs.activeOutputChannels,mode); if(!mapped.valid() || !sameOutputs(mapped,outputs)) @@ -143,19 +161,27 @@ struct MixerDeviceBindingPolicy final { } auto& sources=document.request.sources; - if(saved.backend!=live.backend || saved.capture!=live.capture || - !samePinNames(saved.inputNames,live.inputNames,live.backend)) { + if(saved.backend!=live.backend || saved.capture!=live.capture) { + if(mode==Mode::verifiedAsioRestart && !sources.empty()) + return "NEEDS_REMAP: waiting for the previous ASIO capture endpoint"; // Matching pin numbers alone cannot identify another capture source. sources.clear(); - } else if(oldPins!=newPins) { + } else if(oldPins!=newPins || saved.inputNames!=live.inputNames || + (live.backend=="ASIO" && saved.inputNames.isEmpty())) { std::vector mapped; mapped.reserve(sources.size()); for(auto source:sources) { - source.inputL=remapPin(oldPins,newPins,source.inputL); - if(source.stereo)source.inputR=remapPin(oldPins,newPins,source.inputR); + const auto remap=[&](int ordinal) { + return remapPin(oldPins,newPins,saved.inputNames,live.inputNames, + ordinal,live.backend=="ASIO"); + }; + source.inputL=remap(source.inputL); + if(source.stereo)source.inputR=remap(source.inputR); if(source.inputL>=0 && (!source.stereo || source.inputR>=0)) mapped.push_back(source); } + if(mode==Mode::verifiedAsioRestart && mapped.size()!=sources.size()) + return "NEEDS_REMAP: waiting for the previous ASIO capture pins"; sources=std::move(mapped); } document.request.physicalInputs=callbackInputs; @@ -164,21 +190,47 @@ struct MixerDeviceBindingPolicy final { return {}; } private: - static bool samePinNames(const juce::StringArray& saved,const juce::StringArray& live, - const juce::String& backend) { - return saved.isEmpty()?backend!="ASIO":saved==live; - } static juce::BigInteger mask(const juce::String& text) { juce::BigInteger bits; bits.parseString(text,16); return bits; } - static int remapPin(const juce::BigInteger& saved,const juce::BigInteger& current,int ordinal) { + static bool isNamedSpeakerPair(const juce::BigInteger& pins,const juce::StringArray& names) { + const auto left=names[pins.findNextSetBit(0)].trim().toLowerCase(); + const auto right=names[pins.getHighestBit()].trim().toLowerCase(); + return left.endsWith(" 1") && right.endsWith(" 2") && + left.dropLastCharacters(2)==right.dropLastCharacters(2) && + !left.contains("vb-audio") && !left.contains("cable") && + !left.contains("virtual") && !left.contains("loopback") && + (left.contains("realtek") || left.contains("speaker") || left.contains("output with sst")); + } + static int findSamePin(const juce::StringArray& previous,const juce::StringArray& live,int pin) { + const auto name=previous[pin]; + if(name.isEmpty() || previous.indexOf(name)!=pin || + previous.indexOf(name,false,pin+1)>=0)return -1; + const auto next=live.indexOf(name); + return next>=0 && live.indexOf(name,false,next+1)<0?next:-1; + } + static int remapPin(const juce::BigInteger& saved,const juce::BigInteger& current, + const juce::StringArray& savedNames,const juce::StringArray& currentNames, + int ordinal,bool requireNames) { if(ordinal<0)return -1; int physical=saved.findNextSetBit(0); for(int i=0;i=0;++i) physical=saved.findNextSetBit(physical+1); - if(physical<0 || !current[physical])return -1; + if(physical<0)return -1; + if(savedNames!=currentNames || requireNames) { + const auto name=savedNames[physical]; + if(name.isEmpty()) { + // Old documents without a label inventory can keep the + // exact mask. They cannot identify a newly numbered pin. + if(!savedNames.isEmpty() || (requireNames && saved!=current))return -1; + } else { + physical=findSamePin(savedNames,currentNames,physical); + if(physical<0)return -1; + } + } + if(!current[physical])return -1; int index=0; for(int pin=current.findNextSetBit(0);pinsize\(\)!=2/); assert.match(main,/restoreSavedMixerSession\(false,bindingMode\)/); + assert.match(apply,/if\(refreshedAsio4All\) \{[\s\S]*?openSelectedAudioDevice\(typeName,candidate,true\)/); + assert.match(main,/epoch==asioRecoveryEpoch_/); + assert.match(main,/authorizeRetainedAsioRestart\(\)[\s\S]*?restoreSavedMixerSession\(false,MixerBindingMode::verifiedAsioRestart\)/); }); test('SETUP1 honest bus patch has real AUX/MAIN/MONITOR navigation, no fake GROUP DCA',()=>{ diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 5e9d56fb8..9d6fd7abf 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -307,6 +307,31 @@ static void nativeDeviceRecovery() { assert(current.inserts.size()==1 && current.inserts[0].catalogId==eqId); current.binding=saved.binding; + // Render actual PCM after a sparse ASIO4ALL re-enumeration. Two compact + // callbacks now address physical pins 2 and 3, with MAIN L at ordinal 1. + auto aggregate=current; + aggregate.binding={"ASIO","ASIO4ALL v2","ASIO4ALL v2","3","3",48000.,480, + {"VB-Audio Point 1","VB-Audio Point 2"},{"2nd output with SST 1","2nd output with SST 2"}}; + auto reenumerated=aggregate.binding; + reenumerated.inputMask=reenumerated.outputMask="6"; + reenumerated.inputNames.insert(0,"Other capture"); + reenumerated.outputNames={"Other playback","2nd output with SST 2","2nd output with SST 1"}; + const auto asioPair=MixerDeviceBindingPolicy::proposedOutputs( + aggregate,reenumerated,2,BindingMode::verifiedAsioRestart); + assert(MixerDeviceBindingPolicy::apply(aggregate,reenumerated,asioPair,2, + BindingMode::verifiedAsioRestart).isEmpty()); + mixer.deviceStopped(); + device.inputMask.setBit(2);device.inputMask.clearBit(0); + device.outputMask=device.inputMask; + mixer.prepareDevice(&device); + assert(restore(aggregate,currentStates,true).isEmpty()); + process(true); + assert(outL.back()==0.f && outR.back()==0.f); + process(false); + assert(outL.back()>.02f && outR.back()>outL.back()+.01f); + device.inputMask.clearBit(2);device.inputMask.setBit(0); + device.outputMask=device.inputMask; + // The field failure switched Realtek playback to HDMI while keeping the // same VB-Cable source and a live FX rack. The new epoch has working PCM, // existing WIRE IDs and a repatchable ChannelId graph after one Apply. @@ -533,7 +558,61 @@ int main(){ BindingMode::exact).isNotEmpty()); assert(MixerDeviceBindingPolicy::apply(reordered,reorderedPins,d.outputs,2, BindingMode::verifiedDeviceApply).isEmpty()); - assert(reordered.request.sources.empty()); + assert(reordered.request.sources.size()==d.request.sources.size()); + assert(reordered.request.sources.front().inputL==1); + assert(reordered.request.sources.front().inputR==-1); + + // ASIO4ALL can reorder the VB-Cable input and the Realtek pair even + // though JUCE still reports the same registered driver name. + auto asio=d; + asio.binding.backend="ASIO"; + asio.request.sources.front().stereo=true; + asio.request.sources.front().inputR=1; + asio.binding.capture=asio.binding.playback="ASIO4ALL v2"; + asio.binding.inputNames={"VB-Audio Point 1","VB-Audio Point 2"}; + asio.binding.outputNames={"2nd output with SST 1","2nd output with SST 2"}; + asio.binding.outputMask="3"; + asio.outputs={2,0,1,-1,-1,false}; + auto shifted=asio.binding; + shifted.inputNames={"New input","VB-Audio Point 1","VB-Audio Point 2"}; + shifted.inputMask="6"; + shifted.outputNames={"New output","2nd output with SST 2","2nd output with SST 1"}; + shifted.outputMask="6"; + const auto shiftedPair=MixerDeviceBindingPolicy::proposedOutputs(asio,shifted,2, + BindingMode::verifiedAsioRestart); + assert(shiftedPair.valid() && shiftedPair.mainL==1 && shiftedPair.mainR==0); + auto shiftedSession=asio; + assert(MixerDeviceBindingPolicy::apply(shiftedSession,shifted,shiftedPair,2, + BindingMode::verifiedAsioRestart).isEmpty()); + assert(shiftedSession.request.sources.front().inputL==0); + assert(shiftedSession.request.sources.front().inputR==1); + assert(shiftedSession.roster.revision()==asio.roster.revision()); + juce::BigInteger oldCapturePins; + oldCapturePins.setRange(0,2,true); + const auto translated=MixerDeviceBindingPolicy::translateNamedPins( + oldCapturePins,asio.binding.inputNames,shifted.inputNames); + assert(translated && translated->toString(16)=="6"); + auto temporarilyUnavailable=shifted; + temporarilyUnavailable.inputMask="3"; + assert(MixerDeviceBindingPolicy::apply(asio,temporarilyUnavailable,shiftedPair,2, + BindingMode::verifiedAsioRestart).contains("previous ASIO capture pins")); + assert(asio.binding.inputMask=="3" && asio.request.sources.front().inputR==1); + + auto nextSpeaker=asio.binding; + nextSpeaker.outputNames={"Realtek HD Audio output with SST 1","Realtek HD Audio output with SST 2"}; + assert(!MixerDeviceBindingPolicy::proposedOutputs(asio,nextSpeaker,2, + BindingMode::verifiedAsioRestart).valid()); + const auto newlyApproved=MixerDeviceBindingPolicy::proposedOutputs(asio,nextSpeaker,2, + BindingMode::verifiedDeviceApply); + assert(newlyApproved.valid() && newlyApproved.mainL==0 && newlyApproved.mainR==1); + auto virtualCable=nextSpeaker; + virtualCable.outputNames={"VB-Audio Point 1","VB-Audio Point 2"}; + assert(!MixerDeviceBindingPolicy::proposedOutputs(asio,virtualCable,2, + BindingMode::verifiedDeviceApply).valid()); + auto duplicatePins=shifted; + duplicatePins.outputNames.add("2nd output with SST 1"); + assert(!MixerDeviceBindingPolicy::proposedOutputs(asio,duplicatePins,2, + BindingMode::verifiedAsioRestart).valid()); auto exact=d; assert(MixerDeviceBindingPolicy::apply(exact,d.binding,d.outputs,2,BindingMode::exact) .isEmpty()); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 1747fec56..7cf291e3b 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1786,8 +1786,11 @@ }else pins.textContent="Apply this device first to inspect its real enabled pins."; } const activeText=devicePanel.querySelector("[data-audio-active]"); + const mainPins=Array.isArray(active.mainOutputs)?active.mainOutputs + .map(pin=>active.outputNames?.[pin]).filter(Boolean):[]; if(activeText && !deviceBusy)activeText.textContent=deviceResult||(active.open? - "ACTIVE · "+active.backend+" · "+active.rate+" Hz / "+active.buffer+" samples": + "ACTIVE · "+active.backend+" · "+active.rate+" Hz / "+active.buffer+" samples"+ + (mainPins.length===2?" · MAIN "+mainPins.join(" / "):""): "No verified audio device. Select a supported input and output."); devicePanel.querySelector("[data-audio-apply]").disabled=deviceBusy|| !deviceChoice.backend||(!t?.separate&&!deviceChoice.capture)|| From 6285f80b5286c70b2b1bd1c79828f9332633b08e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:16:04 +0700 Subject: [PATCH 035/125] Validate ASIO recovery in the complete Windows contract suite --- tests/independent_clock_adapter_contract_test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/independent_clock_adapter_contract_test.mjs b/tests/independent_clock_adapter_contract_test.mjs index 8d113a649..705cb1be9 100644 --- a/tests/independent_clock_adapter_contract_test.mjs +++ b/tests/independent_clock_adapter_contract_test.mjs @@ -161,7 +161,7 @@ test('P0 ASIO live direct route fence blocks hotplug substitution before DSP',() assert.match(engine,/directSuppressedFrames_\.fetch_add/); assert.match(engine,/directRouteProtection/); assert.match(host,/engine_\.beginManualAudioSetup\(\)/); - assert.match(host,/engine_\.finishManualAudioSetup\(\)/); + assert.match(host,/engine_\.finishManualAudioSetup\(bindingMode!=MixerBindingMode::verifiedMainPinApply\)/); assert.match(host,/engine_\.directRouteAuthorized\(\)/); }); From 738ab4fca1b6bfe7f359db2a8b105295b422f972 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:27:42 +0700 Subject: [PATCH 036/125] feat(harmony): causal pitch-synchronous vocal candidate with safe grain fallback and PCM parity --- CMakeLists.txt | 3 + ..._NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md | 8 ++ engine/builtin_fx/HarmonyDsp.h | 50 ++++++-- engine/builtin_fx/HarmonyPitchSynchronous.h | 121 ++++++++++++++++++ tests/harmony_pitch_synchronous_test.cpp | 81 ++++++++++++ 5 files changed, 255 insertions(+), 8 deletions(-) create mode 100644 engine/builtin_fx/HarmonyPitchSynchronous.h create mode 100644 tests/harmony_pitch_synchronous_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cee805af8..fd8bf6c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,9 @@ if(BUILD_TESTING) add_executable(ARMixFxStructuralHandoffTests tests/live_fx_structural_handoff_test.cpp) target_compile_features(ARMixFxStructuralHandoffTests PRIVATE cxx_std_20) add_test(NAME R0BStructuralFxAckAndControlThreadRetirement COMMAND ARMixFxStructuralHandoffTests) + add_executable(ARMixHarmonyPitchSyncTests tests/harmony_pitch_synchronous_test.cpp) + target_compile_features(ARMixHarmonyPitchSyncTests PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyPitchSynchronousFormantCandidateAndBlockParity COMMAND ARMixHarmonyPitchSyncTests) add_executable(ARMixHarmonyDspTests tests/harmony_dsp_test.cpp) target_compile_features(ARMixHarmonyDspTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyMultivoicePitchAndRealtimeFinitePCM COMMAND ARMixHarmonyDspTests) diff --git a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md index fb0aee62a..6f57fb189 100644 --- a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md +++ b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md @@ -73,3 +73,11 @@ ensemble-spatial realism increment, **not a formant-preserving resynthesis fix**. The original two-grain pitch shifter can still sound robotic on real recorded consonants and wide intervals. It requires a separate pitch-synchronous/formant-aware algorithm and A/B acoustic gate. + +## 2026-11-09 P0 native pitch-synchronous candidate (requires physical singer qualification) + +Audit found the audible 16ms fixed-grain playback still changes vowel phase at unrelated seam boundaries. This commit adds a **causal, bounded pitch-synchronous window candidate** to the same ChannelId `HarmonyDsp`. It uses source-F0 pitch periods and local positive source landmarks to read waveform windows at **unity PCM speed**, while note ratio controls the spacing of synthesis centers; formants are no longer intentionally frequency-scaled by speeding the source playback. The original grain shifter is retained as the fallback for missing landmarks/low correlation/unvoiced phonemes; transitions ramp over 12ms. This is an approximation, not a proven glottal-closure PSOLA or completed formant-safe voice model. + +- One 16,384-sample mono history already owned by Harmony; no new audio route, device, host, PDC, user control or UI. Per-voice candidate stores at most 8 active source windows, fixed-size. Peak searches are bounded to <1 source period and never read future input. +- New original-harmonic source CTest checks up/down ratios, a low male period, high-rate registers and **exact 64/257 callback-partition PCM parity** at 48/96/192k. Existing native lead preservation and phase-safe music tests still apply. +- **Crucial nonclaim:** harmonic synthetic tests do not establish a singer's natural vowel formants or consonant intelligibility. Positive peaks are not reliable epochs for all breathy, growled or multi-pitch vocals. Do not mark PR production-ready until real recorded-vocal spectral F1/F2/F3, fricative/phrase boundaries, loudness-matched blind A/B and worst-case ASIO xrun/latency testing. If an audible regression occurs, fall back to the previous grain implementation before release. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 141d35168..37f4b4f9f 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -9,6 +9,7 @@ #include "HarmonyPreparedTone.h" #include "HarmonyEnsembleSpace.h" #include "HarmonyDepthRoom.h" +#include "HarmonyPitchSynchronous.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -98,6 +99,10 @@ class Engine final { if(!vocalFold_.prepare(rate)||!toneColor_.prepare(rate)|| !ensemble_.prepare(rate)||!depthRoom_.prepare(rate))return false; pitchIntervals_.prepare(); + pitchSync_.reset(); + pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); + sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; + pitchSyncAlpha_=static_cast(1.-std::exp(-1./(rate*.012))); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; @@ -295,6 +300,7 @@ class Engine final { r[i]=std::clamp(outR*gain_,-4.f,4.f); ensemble_.advance(voiced_); write_=(write_+1)%capacity; + ++sampleClock_; } } private: @@ -320,11 +326,27 @@ class Engine final { // reduced grain-edge modulation without sin/cos in audio callback. const float w=smoothGrainBlend(p); float y=w*tap(mono_,delayA)+(1.f-w)*tap(mono_,delayB); - float& f=filtered_[static_cast(voice)]; - f+=filterCoef*(y-f);y=f; - phase_[static_cast(voice)]+=1.f/static_cast(grain_); - if(phase_[static_cast(voice)]>=1.f) - phase_[static_cast(voice)]-=1.f; + const auto ix=static_cast(voice); + float& f=filtered_[ix]; + f+=filterCoef*(y-f); + // Voiced, periodic sources can use causal pitch-synchronous + // overlap-add. The exact source period is measured, not inferred + // from the harmony target. Uncertain/nonperiodic sounds retain the + // previous validated granular shifter with a bounded 12ms crossfade. + const bool confident=voiced_&&sourceConfidence_>.82f&& + sourcePeriodSamples_>=8.f; + PitchSynchronousVoice::Output sync{}; + if(confident) + sync=pitchSync_.process(voice,sampleClock_,write_,mono_, + sourcePeriodSamples_,effectiveRatio, + static_cast(latency_)+arrival); + float& colorState=pitchSyncFiltered_[ix]; + colorState+=filterCoef*(sync.sample-colorState); + float& blend=pitchSyncBlend_[ix]; + blend+=pitchSyncAlpha_*((confident&&sync.ready?1.f:0.f)-blend); + y=f*(1.f-blend)+colorState*blend; + phase_[ix]+=1.f/static_cast(grain_); + if(phase_[ix]>=1.f)phase_[ix]-=1.f; return y; } // Prepare one immutable, bounded pitch-analysis window every analysis hop. @@ -346,7 +368,7 @@ class Engine final { pitchEnergy_+=x*x; } if(pitchEnergy_/static_cast(span)<1.e-6){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1; + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1; return; } pitchCorrelations_.fill(0.f); @@ -402,7 +424,7 @@ class Engine final { } } if(bestLag==0||best<=0.77f){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; } // Three-point peak interpolation reduces integer-lag tuning steps, // especially at the high end of the supported singing range. @@ -418,7 +440,7 @@ class Engine final { const float hz=static_cast(rate_)/(decimation_*lag); const float midi=69.f+12.f*std::log2(hz/440.f); if(!std::isfinite(midi)||midi<31.f||midi>96.f){ - voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; } const int activeKey=effectiveKey(),activeScale=effectiveScale(); int degree=nearestDegree(midi,activeKey,activeScale); @@ -435,6 +457,14 @@ class Engine final { // do not generate provisional harmony on a single noisy transient. if(noteHold_<2)return; currentNote_=note;voiced_=true; + const float newPeriod=static_cast(rate_/hz); + if(sourcePeriodSamples_>0.f&& + std::abs(newPeriod-sourcePeriodSamples_)>.25f*sourcePeriodSamples_){ + pitchSync_.reset();pitchSyncBlend_.fill(0.f); + pitchSyncFiltered_.fill(0.f); + } + sourcePeriodSamples_=newPeriod; + sourceConfidence_=std::clamp(best,0.f,1.f); // Fifth harmony voice is a lower sixth in key; keep each voice // independent and normalize its level against the total count. // One fractional-pitch exponent per analysis hop; each harmony @@ -468,6 +498,9 @@ class Engine final { bool processed_=false; float smoothingAlpha_=1.f,voicedGateAlpha_=0.002f,ratioAlpha_=0.00045f; float wet_=0.f,targetWet_=0.f,color_=0.f,targetColor_=0.f; + float sourcePeriodSamples_=0.f,sourceConfidence_=0.f,pitchSyncAlpha_=0.f; + std::uint64_t sampleClock_=0; + std::array pitchSyncBlend_{},pitchSyncFiltered_{}; float space_=0.f,targetSpace_=0.f; float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; @@ -477,6 +510,7 @@ class Engine final { PreparedPitchIntervals pitchIntervals_{}; EnsembleSpace ensemble_{}; BackingDepthRoom depthRoom_{}; + PitchSynchronousVoice pitchSync_{}; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h new file mode 100644 index 000000000..01c323f80 --- /dev/null +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include +#include + +namespace armix::harmony { +// Experimental causal pitch-synchronous source-window candidate. +// Vowel waveforms are read at unity sample speed; pitch changes arise by +// re-spacing aligned source windows, rather than resampling their formants. +// Positive waveform peaks are approximate epochs, NOT proven glottal closures. +// This must pass actual singer A/B before acoustic release qualification. +// All state is fixed; no allocation, locks, FFT or IO in process(). +template +class PitchSynchronousVoice final { + static_assert(Capacity >= 4096 && (Capacity & (Capacity-1)) == 0); + static_assert(Voices > 0 && Voices <= 8); +public: + struct Output { float sample=0.f; bool ready=false; }; + void reset() noexcept { states_={}; } + void resetVoice(int v) noexcept { + if(v>=0&&v(v)]={}; + } + // time/writeIndex refer to the input sample just written to the ring. + // fixedDelay retains the host's published latency; a singer-specific + // arrival delay can be added without moving the original dry PCM. + Output process(int v,std::uint64_t time,std::size_t writeIndex, + const std::array& input, + float sourcePeriod,float ratio,float fixedDelay) noexcept { + if(v<0||v>=Voices||!std::isfinite(sourcePeriod)|| + !std::isfinite(ratio)||!std::isfinite(fixedDelay)|| + sourcePeriod<8.f||sourcePeriod>3200.f|| + ratio<.49f||ratio>2.01f||fixedDelay(v)]; + const double period=static_cast(sourcePeriod); + const double spacing=period/static_cast(ratio); + const double width=std::max(period,spacing); + if(!state.initialized) { + state.initialized=true; + state.nextCenter=static_cast(time)+width; + } + // Advance at most two grains per sample, even on hostile period jumps. + // Normal supported periods place >=4 samples between target marks. + for(int scheduled=0;scheduled<2 && + static_cast(time)+.0001>=state.nextCenter-width;++scheduled) { + const double desired=state.nextCenter-static_cast(fixedDelay); + const auto peak=findPositiveEpoch(input,time,writeIndex,desired,period); + if(peak>=0) { + auto& grain=state.grains[state.nextSlot]; + grain={state.nextCenter,static_cast(peak),width,true}; + state.nextSlot=(state.nextSlot+1)%state.grains.size(); + } + state.nextCenter+=spacing; + } + if(state.nextCenter+width(time)) + state.nextCenter=static_cast(time)+width; + float sum=0.f,weight=0.f; + for(auto& grain:state.grains) { + if(!grain.active)continue; + const double offset=static_cast(time)-grain.center; + const double u=offset/grain.width; + if(u>=1.){grain.active=false;continue;} + if(u<=-1.)continue; + // Raised compact zero-slope window, avoiding per-sample trig. + const float w=static_cast((1.-u*u)*(1.-u*u)); + const float sample=readAt(input,time,writeIndex,grain.source+offset); + sum+=sample*w;weight+=w; + } + if(weight<.05f)return {}; + return {sum/weight,true}; + } +private: + struct Grain {double center=0.,source=0.,width=1.;bool active=false;}; + struct State { + std::array grains{}; + double nextCenter=0.; + std::size_t nextSlot=0; + bool initialized=false; + }; + // Bound the peak search to <1 source cycle, never scanning beyond the + // already received microphone input. Unreliable speech uses fallback. + static std::int64_t findPositiveEpoch(const std::array& input, + std::uint64_t time,std::size_t writeIndex, + double desired,double period) noexcept { + const auto half=static_cast(std::ceil(period*.46)); + const auto center=static_cast(std::llround(desired)); + const auto oldest=static_cast( + time>=Capacity-3?time-(Capacity-3):0); + const auto newest=static_cast(time>1?time-1:0); + const auto start=std::max(oldest,center-half); + const auto end=std::min(newest,center+half); + if(end( + static_cast(time)-t); + const float value=input[(writeIndex+Capacity-age)&(Capacity-1)]; + if(value>best){best=value;peak=t;} + } + return peak; + } + static float readAt(const std::array& input, + std::uint64_t time,std::size_t writeIndex,double position) noexcept { + if(time<2||position<0.||position>static_cast(time-1)|| + position( + time>=Capacity-3?time-(Capacity-3):0))return 0.f; + const double age=static_cast(time)-position; + const auto whole=static_cast(age); + const float fractional=static_cast( + age-static_cast(whole)); + const auto index=(writeIndex+Capacity-whole)&(Capacity-1); + return input[index]*(1.f-fraction)+ + input[(index+Capacity-1)&(Capacity-1)]*fractional; + } + std::array states_{}; +}; +} // namespace armix::harmony diff --git a/tests/harmony_pitch_synchronous_test.cpp b/tests/harmony_pitch_synchronous_test.cpp new file mode 100644 index 000000000..97477cda2 --- /dev/null +++ b/tests/harmony_pitch_synchronous_test.cpp @@ -0,0 +1,81 @@ +#include "../engine/builtin_fx/HarmonyPitchSynchronous.h" +#include +#include +#include +#include +#include +#include +using armix::harmony::PitchSynchronousVoice; +using Shifter=PitchSynchronousVoice<16384,6>; +static void need(bool yes,const char* reason){ + if(!yes){std::cerr< render(double rate,double f0,double ratio,int block){ + auto p=Shifter{}; + std::array ring{}; + const int n=static_cast(rate*.65); + std::vector out(static_cast(n)); + for(int pos=0;pos(t)&16383]=static_cast( + .19*std::sin(phase)+.052*std::sin(2*phase+.31)+ + .029*std::sin(3*phase+.17)); + const auto sample=p.process(0,t,static_cast(t)&16383,ring, + static_cast(rate/f0),static_cast(ratio), + static_cast(rate*.032)); + out[static_cast(t)]=sample.sample; + need(std::isfinite(sample.sample)&&std::abs(sample.sample)<2.f, + "synchronous output nonfinite/unbounded"); + } + return out; +} +static double measuredHz(const std::vector& signal,double rate,double wanted){ + const int begin=static_cast(rate*.27); + const int length=static_cast(rate*.23); + const int low=static_cast(rate/(wanted*1.05)); + const int high=static_cast(rate/(wanted*.95)); + double best=-100.;int lag=0; + for(int d=low;d<=high;++d){ + double numerator=0,energy=0; + for(int t=begin;t(t)]* + signal[static_cast(t-d)]; + energy+=signal[static_cast(t)]* + signal[static_cast(t)]; + } + if(numerator/(energy+1.e-20)>best){ + best=numerator/(energy+1.e-20);lag=d; + } + } + need(best>.6&&lag>0,"synchronous source lost periodicity"); + return rate/lag; +} +int main(){ + // Actual source-period pitch shifting, not just a sine-wave finite test. + // Three original harmonics approximate one voiced source; FFT/formant and + // actual adult singer evidence are still necessary before quality claims. + for(const auto& v:std::array,5>{{ + {{48000.,220.,1.5}},{{48000.,220.,.667}}, + {{48000.,82.40689,1.2}},{{96000.,440.,.75}}, + {{192000.,880.,1.4}} + }}){ + const auto a=render(v[0],v[1],v[2],64); + const auto b=render(v[0],v[1],v[2],257); + need(a.size()==b.size(),"different source length"); + for(std::size_t i=0;i silence{}; + need(!bad.process(0,0,0,silence,0.f,1.f,1536.f).ready, + "invalid F0 accepted"); + need(!bad.process(0,100,100,silence,3200.f,1.f,1536.f).ready, + "insufficient host latency accepted"); + std::cout<<"bounded source windows and block parity passed\n"; +} From ee9f9f105adf6a506c039995c2ad24675d3c35a0 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:28:06 +0700 Subject: [PATCH 037/125] feat(vocal-throw): integrate M1-M6 over Player main with conflict-free native/GUI merge --- .github/workflows/ui-smoke.yml | 27 ++ CMakeLists.txt | 12 + ...ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md | 45 ++ ...SON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md | 45 ++ docs/ARSON_VOCAL_THROW_NATIVE_20261108.md | 54 +++ engine/builtin_fx/BuiltInFxCatalog.h | 1 + engine/builtin_fx/VocalThrow.h | 354 ++++++++++++++++ engine/builtin_fx/VocalThrowProcessor.h | 228 ++++++++++ engine/core/DynamicNativeSessionPublisher.h | 48 ++- engine/core/NativeBeatFrameContext.h | 32 ++ engine/core/NativeMusicTempoMonitor.h | 376 ++++++++++++++++ scripts/compose_native_peq.py | 34 +- .../assets/arson-vocal-hardware-encoder.svg | 8 + .../assets/arson-vocal-hardware-push.svg | 10 + .../assets/arson-vocal-hardware-rotor.svg | 61 +++ .../assets/arson-vocal-hardware-toggle.svg | 6 + .../assets/arson-vocal-throw-performance.svg | 26 ++ .../assets/mixer-contextual-buttons.css | 28 +- site/preview-v2/assets/mixer-fx-rack.css | 232 ++++++++++ .../assets/mixer-native-compressor.js | 1 + site/preview-v2/assets/mixer-native-peq.js | 3 +- .../assets/mixer-native-vocal-throw.js | 401 ++++++++++++++++++ src/LiveAudioEngine.h | 60 +++ src/LiveDryRoutingLab.h | 27 ++ src/Main.cpp | 272 +++++++++++- src/NativeMixerSessionFxRestore.h | 15 +- tests/approved_native_vocal_throw_smoke.py | 310 ++++++++++++++ tests/builtin_vocal_throw_test.cpp | 356 ++++++++++++++++ tests/native_music_tempo_test.cpp | 291 +++++++++++++ tests/native_peq_assembly_test.py | 48 +++ web/approved-native-bridge.js | 5 +- 31 files changed, 3391 insertions(+), 25 deletions(-) create mode 100644 docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md create mode 100644 docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md create mode 100644 docs/ARSON_VOCAL_THROW_NATIVE_20261108.md create mode 100644 engine/builtin_fx/VocalThrow.h create mode 100644 engine/builtin_fx/VocalThrowProcessor.h create mode 100644 engine/core/NativeBeatFrameContext.h create mode 100644 engine/core/NativeMusicTempoMonitor.h create mode 100644 site/preview-v2/assets/arson-vocal-hardware-encoder.svg create mode 100644 site/preview-v2/assets/arson-vocal-hardware-push.svg create mode 100644 site/preview-v2/assets/arson-vocal-hardware-rotor.svg create mode 100644 site/preview-v2/assets/arson-vocal-hardware-toggle.svg create mode 100644 site/preview-v2/assets/arson-vocal-throw-performance.svg create mode 100644 site/preview-v2/assets/mixer-native-vocal-throw.js create mode 100644 tests/approved_native_vocal_throw_smoke.py create mode 100644 tests/builtin_vocal_throw_test.cpp create mode 100644 tests/native_music_tempo_test.cpp diff --git a/.github/workflows/ui-smoke.yml b/.github/workflows/ui-smoke.yml index a57b32e9e..605c61924 100644 --- a/.github/workflows/ui-smoke.yml +++ b/.github/workflows/ui-smoke.yml @@ -109,6 +109,7 @@ jobs: node --check site/preview-v2/assets/mixer-native-compressor.js node --check site/preview-v2/assets/mixer-native-harmony.js python tests/native_harmony_assembly_test.py + node --check site/preview-v2/assets/mixer-native-vocal-throw.js python tests/native_peq_assembly_test.py python tests/approved_operator_ux_smoke.py python scripts/build_ui_css.py --check @@ -128,6 +129,32 @@ jobs: - name: Block incomplete product release only when preparing product review if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft && startsWith(github.head_ref, 'integration/product-') }} run: node scripts/check_console_puzzle.mjs --release + vocal-throw-preview: + name: Vocal Throw native editor desktop/mobile Chromium FAT + needs: quick + if: ${{ github.event_name == 'pull_request' && (startsWith(github.head_ref, 'feature/arson-vocal-throw-') || startsWith(github.head_ref, 'integration/arson-vocal-throw-')) }} + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: Install Chromium for targeted Vocal Throw UI + run: | + python -m pip install playwright + python -m playwright install --with-deps chromium + - name: Check exact mixer picker, native ACK and editor in desktop/mobile + run: python tests/approved_native_vocal_throw_smoke.py + - name: Keep compact editor screenshot evidence + if: ${{ always() }} + uses: actions/upload-artifact@v4 + with: + name: ArSonMix-Vocal-Throw-Desktop-Mobile-${{ github.run_id }} + path: arsonmix-vocal-throw-*.png + if-no-files-found: ignore + retention-days: 7 + operator-ux-fat: name: Operator UX real Chromium / native-assembled GUI (5 viewports) needs: quick diff --git a/CMakeLists.txt b/CMakeLists.txt index 622f606aa..b2241cd9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -424,6 +424,18 @@ if(BUILD_TESTING) COMMAND ARMixNativeCompressorLifecycleTests) add_dependencies(ARMixMixerRoutingTests ARMixNativeCompressorLifecycleTests) + add_executable(ARMixNativeVocalThrowTests tests/builtin_vocal_throw_test.cpp + engine/builtin_fx/VocalThrow.h) + target_compile_features(ARMixNativeVocalThrowTests PRIVATE cxx_std_20) + add_test(NAME NativeVocalThrowPhraseCaptureManualAutoAndNoHeap COMMAND ARMixNativeVocalThrowTests) + add_dependencies(ARMixMixerRoutingTests ARMixNativeVocalThrowTests) + add_executable(ARMixNativeMusicTempoTests tests/native_music_tempo_test.cpp + engine/core/NativeMusicTempoMonitor.h) + target_compile_features(ARMixNativeMusicTempoTests PRIVATE cxx_std_20) + add_test(NAME NativeMusicTempoSourceOnsetsAndFallback COMMAND ARMixNativeMusicTempoTests) + add_dependencies(ARMixMixerRoutingTests ARMixNativeMusicTempoTests) + + add_executable(ARMixNativeMasterLoudnessTests tests/native_master_loudness_test.cpp engine/dsp/NativeMasterLoudness.h) target_compile_features(ARMixNativeMasterLoudnessTests PRIVATE cxx_std_20) add_test(NAME P1KMeasuredNativeBS1770StereoAnd4xTruePeak COMMAND ARMixNativeMasterLoudnessTests) diff --git a/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md b/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md new file mode 100644 index 000000000..6cb0512fb --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_BEAT_GRID_M3_20261109.md @@ -0,0 +1,45 @@ +# ArSon Vocal Throw M3 — native music beat-phase quantized echo + +**Branch:** `feature/arson-vocal-throw-phase-grid-m3-20261109`; builds on draft M2 PR #474 (which builds on M1 PR #469). Product issue #473. **Not a hardware-certified stage release.** + +## What changed + +A stable BPM alone cannot locate the *beat boundary*. M3 shares the existing native ChannelId audio renderer's monotonically increasing callback frame counter with its built-in FX processing, then quantizes **only the newly scheduled echo** when the selected MUSIC ChannelId has a credible beat-phase estimate. + +``` +ONE native ASIO/JUCE ChannelId render (epoch + graph revision) + beginAudioBlock(frames) -> monotonic native sample-frame start + NativeBeatFrameScope (thread-local, callback-only and restored on exit) + pre-FX MUSIC ChannelId -> 10ms nonmutating energy frames + each summary carries its exact observed audio end-frame (within 10ms) + SPSC -> existing control timer -> BPM, onset anchor, phase confidence + CONTROL publishes BPM + sample-frame anchor + epoch/revision to FX + -> atomic version-fenced snapshot (one read attempt per callback) + VOICE FX on SAME callback/thread + -> read versioned tempo + scoped native frame origin + -> if source/epoch/revision invalid: accepted Manual/TAP + -> if BPM stable, beat phase weak: BPM-derived interval, NO grid + -> if BPM and phase credible: snapshot anchor & interval at THROW + -> freeze voice with existing two-tail bounded PCM + -> schedule next echo at FIRST native music grid point >= + intended (phrase end + musical subdivision), with correction + bounded to ONE subdivision and zero change to dry PCM + -> already sounding echo tails retain frozen timing across BPM/graph edits +``` + +### Realtime invariant +No new audio callback, dynamic allocation, model inference, FFT, lock, waiting, JS audio, logging or file I/O from the callback. Channel PCM enters one mixer graph and is never processed twice. The timing scope is a trivially copied thread-local struct, no global audio clock thread. Tempo/phase inference (up to 121 BPM candidates) is CONTROL-only. Packed atomic scalar fields are protected by an even/odd version; the audio callback makes **one** bounded read attempt and immediately falls back on inconsistency. + +### Confidence and fallback +- BPM confidence and beat-phase confidence are independent. A musical onset beat grid is used only if a majority of percussive onset strength agrees on a single pulse lattice. +- Ambiguous rhythmic patterns remain **AUTO BPM · BPM only**, not a speculative grid. A missing source or stale graph becomes **Manual / TAP** without losing the accepted preset. +- A 10ms analysis window means onset time has approximately up to one window of inherent beat-position uncertainty, even though *subsequent scheduling* uses exact callback sample indices. This is not sample-perfect transient detection. +- Phase quantization is measured against **pre-FX** selected music PCM, not against a fully latency-compensated external performance clock. Vendor VST3 latency, off-beat percussion, compressed music, drift, sample-rate changes, ASIO callback reentrancy and sparse backing must still pass field tests. + +### Automated acceptance +- Native DSP unit test verifies an actual frozen phrase's first echo is scheduled on the music frame lattice and remains there after transport disappears, compared with Manual/TAP quarter-note fallback; repeats at 64/128-frame PCM chunks with callback heap forbidden. +- Native graph PCM test stamps the selected music ChannelId from one authoritative callback at variable 64+36 sample chunks, verifies anchored BPM/phase confidence at 72/95/120/160 BPM, one block-clock scope, frame counter continuity after a graph revision, and restoration of callback-only context. +- Desktop/mobile Chromium smoke explicitly distinguishes a native ACKed source's **BPM only** from **BEAT GRID** status. No user-facing opt-in or extra monitor/arm step. + +### Deferred release qualification +Physical ASIO 64/128 frame loops at 44.1/48/96 kHz; on-stage singer/backing leakage, syncopated 4/4 and half/double-time, large FX PDC, dropout/replug, fade/no-click audition, real CPU/xrun vs bypass, and sustained stress still require field evidence. Do not merge while the PR chain and these safety gates remain unresolved. diff --git a/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md b/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md new file mode 100644 index 000000000..088665a93 --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_MUSIC_TEMPO_M2_20261108.md @@ -0,0 +1,45 @@ +# ArSon Vocal Throw M2 — Native Music Channel Tempo Detection + +**Status:** implementation and qualification draft, stacked on Vocal Throw M1 PR #469. M1 green head `4db384851e6f6378cca4fd037b744c98bd1f0ba3`; M2 is PR #474 and tracks issue #473. + +## Signal authority + +``` +Authoritative ChannelId native PCM graph, single JUCE / ASIO callback + MUSIC ChannelId selected explicitly by singer/operator + -> PRE-FX non-mutating read-only music tap + -> 10ms stereo absolute-energy summary, bounded SPSC + -> existing 12Hz JUCE control timer: onset search + BPM confidence + -> accepted tempo precomputed into sample intervals, CONTROL only + -> per-VocalThrow atomic pending interval + -> next dry/vocal PCM callback copies interval BEFORE any THROW + -> new frozen vocal echo gets music interval, old tails keep prior schedule + VOICE ChannelId -> VocalThrow (no added dry PCM delay) -> WIRE/BUS/MAIN +``` + +**AUDIO callback contract:** no memory allocations, FFT, file I/O, logging, locks, networking, JS DSP, or new audio threads. Only the explicitly selected source channel's input stereo samples are summarized; every other channel skips the per-sample music tap. Existing JUCE callback remains the only audio authority. Core audio buffers and retained FX leases remain with the native graph. + +**CONTROL contract:** only an accepted `ChannelId` with input / GROUP / FX_RETURN role and an actually scheduled PCM lane is a permissible tempo source. The native FX editor validates both its own vocal insert instance and source identity, device epoch and graph revision. Monitor/MAIN and the vocal channel itself are not accepted. On a valid structural graph recompile, an existing source ID is rebound with a new analysis generation; if absent or stale, the music clock is disabled, and Vocal Throw falls back to its saved BPM or TAP tempo. + +## Detector + +- A 10ms energy onset, 80ms transient refractory and adaptive floor reject a simple repeated rise from a sustained note. +- Bounded pairwise onset-period candidate scoring (60–180 BPM), with penalty for octave half/double candidates, three consistent estimates and confidence threshold. +- Native readback distinguishes **AUTO BPM locked**, **Listening**, and **Manual/TAP fallback**. A silence period exceeding 3.2s resets lock. +- UI conveys confidence as measured by estimator; this number is not field-certified reliability. + +**Explicit limitations:** Music/onset BPM estimation does not provide sample-perfect beat-phase grid alignment. A recent transient anchor is retained for diagnostics only; it is not used as a globally compensated sample clock. Syncopated and heavily compressed music, live mic bleed, time-signature changes, half/double-time ambiguity and device-specific ASIO timing remain hardware field gates. Tempo selection is ephemeral song-wide, not yet persisted per Show. The fallback path always remains audible on the singer's dry stream. + +## Qualification evidence + +- Prior M1 Windows MSVC/JUCE: 63/63 CTest on exact SHA `4db384851e6f6378cca4fd037b744c98bd1f0ba3`. +- M2 Windows MSVC/JUCE: 64/64 CTest, including `NativeMusicTempoSourceOnsetsAndFallback`, on exact SHA `cce63231da52f69e6789873ecc406adba69aa1cb`. See [Actions run 42498186748](https://github.com/masarray/arsonmix/actions/runs/42498186748). +- Chromium FAT M2 native Vocal Throw picker, music source ACK, BPM readback and stale instance handling passed on same SHA. +- Later hardening: inbound tempo sampled before same-callback THROW and reset on plugin audio reprepare; corresponding regression checks for manual fallback and active tail interval stability. Qualification on the later SHA must be checked independently. +- Deterministic PCM: 72, 95, 120, 160 BPM; non-vocal source, stale revision, source change, dropout, default fallback. The CTest calls the *actual* native publisher to verify a music signal traverses the accepted graph, not only the isolated estimator. + +**Not qualified:** physical ASIO 64/128 frame load at 44.1/48/96 kHz; prolonged simultaneous singer/backing test; live beat-grid sync / stereo echo hearing test; WASAPI secondary stream callback load; long-run xrun/restart and voice-music bleed reliability. Green CI is necessary but not sufficient for release. + +## Next DSP/UX milestone + +Prove stable beat phase with a source-specific latency-compensated anchor; handle half/double-time ambiguity with confidence floor and long-window hysteresis; permit song/Show fallback preference; add footswitch mapping and live capture metrics without callback work. Until then label UI as estimated **AUTO BPM** rather than **sample-accurate beat quantization**. diff --git a/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md b/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md new file mode 100644 index 000000000..e39acc139 --- /dev/null +++ b/docs/ARSON_VOCAL_THROW_NATIVE_20261108.md @@ -0,0 +1,54 @@ +# ArSon Vocal Throw — native phrase-aware live delay + +**Status: functional prototype on a separate feature branch; not a certified live-performance release.** + +This is a first-class native ChannelId insert in ArSonMix's single JUCE PCM render graph, not a second audio callback, browser-generated sound or independent DAW. + +## Implemented + +- **Manual:** rolling ring buffer holds up to 1.5 seconds of the most recent vocal. THROW captures a word or phrase and schedules up to six decaying repeats. Two independent tail voices allow a subsequent phrase to overlap an existing echo instead of cutting it. +- **Auto:** energy envelope, minimum voice duration, silence threshold and cooldown detect the end of a sung phrase without letting the wet echo re-trigger itself. +- **Hybrid (default):** phrase-end automation and manual cue together, with manual-cue suppression of a subsequent auto event for the same phrase. +- **Tempo:** BPM entry (60-200), TAP BPM, quarter/eighth/dotted-eighth/half note subdivisions. Interval timing is in native samples at the actual device rate. +- **Mix:** direct dry input with zero added samples, stereo echo, decay, short fades, smoothed wet edits, and ducking while the singer is active. A bounded active-tap gain normalizer prevents dense repeats/overlapping phrases from amplifying the wet bus simply because taps stack; dry is never attenuated. +- **Real-time:** all rolling/frozen buffers are allocated off-callback; a fixed maximum 24-stereo-frame-per-sample capture copy budget per active tail avoids a single large callback memcpy. Contiguous copy chunks eliminate per-frame modulo, and the ring write cursor rolls over without division. A lock-free SPSC transfers host settings and manual cue to the audio callback. Callback never allocates/logs/locks. +- **Identity & persistence:** stable native catalog ID; ChannelId, device epoch, graph revision, and insert instance fencing. DSP completed ACK and later readback precede accepted display. Schema-versioned 48-byte AVTH settings blob validated during Show restore; audio capture and tails are not persisted. +- **UX:** a compact FX editor inside the exact approved /preview/ mixer; presets in header, uniform power/close, BPM/note/repeat, THROW, TAP and collapsible advanced controls. One shared FX stylesheet. + +## Architecture + +Hardware input → ChannelId mixer strip → upstream EQ/Compressor/VST3 → VocalThrowProcessor → downstream inserts → fader/pan → WIRE/BUS/MAIN → hardware output. + +Core files: engine/builtin_fx/VocalThrow.h (DSP), VocalThrowProcessor.h (JUCE), src/LiveAudioEngine.h (graph install), src/Main.cpp (validated command/readback), src/NativeMixerSessionFxRestore.h (versioned state), scripts/compose_native_peq.py (one picker), web/approved-native-bridge.js (real insert), site/preview-v2/assets/mixer-native-vocal-throw.js (controls only). + +## Tests / qualification + +The ARMixNativeVocalThrowTests CTest covers zero-added-sample dry, tempo divisions, captured stereo echoes after manual cue, auto-end detection and no self-trigger, bad parameter rejection, 8/44.1/48 kHz sample rates and a global allocator guard around realtime processing. Additional deterministic tests cover 8/48/96 kHz two-tail preservation during a second cue, a full two-tail pool reporting cue refusal rather than overwriting a running phrase, suppression of manual/auto double-cues, and peak containment of dense six-tap echoes. Python native picker/compiled-gui tests enforce no extra mixer screen and real-ACK event names. + +Before shipping: exact-SHA Windows MSVC + CTest, actual approved /preview/ Chromium screenshots, ASIO 64/128-frame stress at 44.1/48/96 kHz, live singer audition, device restart, bypass/tail behavior, and Show restore. + +## Explicit limitations + +1. **Automatic BPM analysis from the music/backing bus is not yet implemented.** Auto currently means automatic vocal phrase-end trigger, not auto-estimated music tempo. BPM is entered or TAP-derived. Full beat tracking requires an independent music-bus feed, beat confidence and phase tracking. +2. Voice end detector uses an adjustable energy-envelope heuristic, not linguistic speech recognition or a trained singing model. Breaths, falsetto and microphone bleed can cause false cues. +3. No MIDI footswitch binding, more than two simultaneous phrase layers, stretchable echo phrases, global music BPM transport integration, or direct song-snapshot binding in this milestone. When both frozen-tail slots are busy, further THROW requests are rejected (native ACK reports not applied) rather than cutting an existing musical phrase. +4. Green quick CI is not equivalent to real Windows native compilation or ASIO device certification. Zero reported PDC applies only to the FX DSP's dry path; end-to-end hardware/driver latency and callback CPU load still require ASIO measurements. +5. Existing channel routing and independent secondary audio clock remain authoritative; the FX insert makes no new claims about unresolved WIRE/SOURCE ONLY issues. + +## Field test + +Insert ID armix.builtin.vocal-throw.v1 into real ChannelId vocal strip; confirm graph ACK; sing “atau tidak” then press THROW at 72/95/120/160 BPM; try Auto with varying held notes and short breaths; toggle bypass while dry vocal remains direct; change device/quantum and reject stale instance requests. Compare physical ASIO callback xruns, stereo/feedback, click-free fades and singer subjective quality. + +## 2026-11-08 — performance and musicality hardening audit + +Audit of the first native revision identified these concrete risks: +- Triggering a second phrase reset `playing_` and overwrote the frozen buffer of the first tail; audible repeat discontinuity was possible. +- The original capture copied 24 frames via two per-frame ring modulo operations; this was an avoidable callback hot-path cost. +- Hybrid manual cues could be followed by auto-trigger of the same sung phrase, producing unintended double repeats. +- Wet level changed immediately on edits; close-spaced six-tap feedback-like echoes could produce unnecessarily high wet peaks. + +Hardening: two independent frozen voices, bounded cue admission (explicit rejection if full), bulk contiguous ring capture, write cursor without modulo, continuous smoothing of wet/duck gain, current-phrase manual suppression of auto replay, and peak-aware wet overlap normalization. Silence counters are now saturating for multi-hour sessions. + +**Realtime caveats:** No heap, locks, logging or file operations in `processStereo`, `throwNow`, or parameter application. Worst-case processing still includes two simultaneous 24-frame copy budgets, and an up-to-twelve-tap mix; on low-buffer ASIO that requires measured xrun and callback-duration evidence, not just source inspection. Extra frozen buffer memory is allocated only on channels with this effect. A full two-voice pool intentionally rejects a new cue, so polyphony and cue policies should be evaluated with vocalist/operator tests. + +**Next release gates:** exact-SHA MSVC CTest and native JUCE compile, 64/128-frame ASIO at 44.1/48/96 kHz, overnight stability and lifecycle/device-rate restart, phrase-ending listening sessions including breath/bleed/falsetto, bypass/re-enable and FX graph routing, and latency/xrun baseline comparisons versus bypass. Beat tracking from an isolated backing/music bus (confidence, phase and half/double-time hysteresis) remains a separate architecture milestone, not an already delivered feature. diff --git a/engine/builtin_fx/BuiltInFxCatalog.h b/engine/builtin_fx/BuiltInFxCatalog.h index bbc6b83d3..67db030e2 100644 --- a/engine/builtin_fx/BuiltInFxCatalog.h +++ b/engine/builtin_fx/BuiltInFxCatalog.h @@ -11,6 +11,7 @@ namespace armix::builtin_fx { inline constexpr std::string_view channelEqId = "armix.builtin.channel-eq.v1"; inline constexpr std::string_view channelCompressorId = "armix.builtin.channel-compressor.v1"; +inline constexpr std::string_view vocalThrowId = "armix.builtin.vocal-throw.v1"; enum class FilterKind : std::uint8_t { highPass, lowShelf, bell, highShelf, lowPass }; enum class Slope : std::uint8_t { db12 = 12, db24 = 24 }; diff --git a/engine/builtin_fx/VocalThrow.h b/engine/builtin_fx/VocalThrow.h new file mode 100644 index 000000000..d49993394 --- /dev/null +++ b/engine/builtin_fx/VocalThrow.h @@ -0,0 +1,354 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include +#include +#include + +// ArSon Vocal Throw. One audio-thread owner; preparation allocates on CONTROL. +// The microphone's dry PCM is never buffered or delayed. A rolling history +// freezes the last word/phrase for tempo-spaced stereo echoes. All samples and +// triggers run on the existing native ChannelId PCM callback, never WebView. +namespace armix::builtin_fx { +struct VocalThrowSettings final { + int mode=2; // 0 manual, 1 automatic, 2 hybrid + float bpm=120.f; // explicit/host or tap BPM (not claimed auto-detected) + int division=0; // 0 quarter, 1 eighth, 2 dotted eighth, 3 half + int repeats=3; + float captureMs=460.f; + float silenceMs=220.f; + float thresholdDb=-35.f; + float wet=.42f; + float decay=.55f; // successive repeat amplitude multiplier + float ducking=.7f; // suppress echo while lead vocalist is active +}; +class VocalThrow final { +public: + static constexpr int addedLatencySamples=0; + static constexpr int maxRepeats=6; + static constexpr float maxCaptureMs=1500.f; + struct PreparedEdit { + VocalThrowSettings settings{}; + double sampleRate=0.; + std::uint32_t intervalSamples=0, captureSamples=0, silenceSamples=0; + float gateLinear=0.f; + bool valid=false; + }; + static bool validSettings(const VocalThrowSettings& s) noexcept { + return s.mode>=0&&s.mode<=2&&s.division>=0&&s.division<=3&& + s.repeats>=1&&s.repeats<=maxRepeats&& + std::isfinite(s.bpm)&&s.bpm>=60.f&&s.bpm<=200.f&& + std::isfinite(s.captureMs)&&s.captureMs>=80.f&&s.captureMs<=maxCaptureMs&& + std::isfinite(s.silenceMs)&&s.silenceMs>=80.f&&s.silenceMs<=900.f&& + std::isfinite(s.thresholdDb)&&s.thresholdDb>=-65.f&&s.thresholdDb<=-15.f&& + std::isfinite(s.wet)&&s.wet>=0.f&&s.wet<=1.f&& + std::isfinite(s.decay)&&s.decay>=.15f&&s.decay<=.9f&& + std::isfinite(s.ducking)&&s.ducking>=0.f&&s.ducking<=1.f; + } + static bool prepareEdit(const VocalThrowSettings& s,double sampleRate,PreparedEdit& out) noexcept { + if(!validSettings(s)||!std::isfinite(sampleRate)|| + sampleRate<8000.||sampleRate>192000.)return false; + constexpr std::array beats{{1.,.5,.75,2.}}; + PreparedEdit next{}; + next.settings=s;next.sampleRate=sampleRate; + next.intervalSamples=std::max(1u,static_cast( + std::llround(60.*sampleRate*beats[static_cast(s.division)]/s.bpm))); + next.captureSamples=std::max(1u,static_cast( + std::llround(sampleRate*s.captureMs/1000.))); + next.silenceSamples=std::max(1u,static_cast( + std::llround(sampleRate*s.silenceMs/1000.))); + next.gateLinear=static_cast(std::pow(10.,s.thresholdDb/20.)); + next.valid=next.gateLinear>0.f; + out=next;return true; + } + // CONTROL thread only, before publishing the insert. Maximum memory is + // bounded by the selected device rate and independent of song duration. + bool prepare(double rate) { + PreparedEdit packet{}; + if(!prepareEdit(VocalThrowSettings{},rate,packet))return false; + const auto historyFrames=static_cast(std::ceil(rate*2.5))+4; + const auto freezeFrames=static_cast(std::ceil(rate*maxCaptureMs/1000.))+4; + if(historyFrames>500000||freezeFrames>300000)return false; + historyL_.assign(historyFrames,0.f); + historyR_.assign(historyFrames,0.f); + // Two independent tails: new phrases never overwrite an active echo. + for(auto& voice:voices_) { + voice.freezeL.assign(freezeFrames,0.f); + voice.freezeR.assign(freezeFrames,0.f); + } + rate_=rate;ready_=true;settings_=packet;reset(); + return true; + } + // CONTROL, before publication. No vector resizing during state restore. + bool resetUnpublished(const VocalThrowSettings& settings) noexcept { + PreparedEdit next{}; + if(!ready_||!prepareEdit(settings,rate_,next))return false; + settings_=next;reset();return true; + } + // AUDIO: trivially copied, completely validated, no heap/locks. + bool applyPrepared(const PreparedEdit& edit) noexcept { + if(!ready_||!edit.valid||edit.sampleRate!=rate_|| + !validSettings(edit.settings)||edit.intervalSamples==0|| + edit.captureSamples==0||edit.captureSamples>voices_[0].freezeL.size()|| + edit.silenceSamples==0)return false; + settings_=edit;return true; + } + // AUDIO: incoming transport interval is already computed on CONTROL. + // A zero interval explicitly falls back to accepted song/TAP BPM. Each + // frozen tail keeps its interval when a backing track changes tempo. + void setMusicIntervalSamples(std::uint32_t samples) noexcept { + musicIntervalSamples_=samples; + gridValid_=false; // BPM-only mode never claims a measured beat grid. + } + // AUDIO: the JUCE insert reads the one accepted ChannelId block clock + // and control-prepared music onset anchor. Onsets are observed in 10ms + // windows, so beat-phase is approximate (not sample-perfect detection). + // The local->graph sample mapping is taken before every FX processing + // block; it works even when the insert was added after playback began. + void setMusicBeatGrid(std::uint32_t intervalSamples, + std::uint64_t anchorFrame, + std::uint64_t blockStartFrame, + bool locked) noexcept { + musicIntervalSamples_=locked?intervalSamples:0; + gridValid_=locked&&intervalSamples>0; + gridAnchorFrame_=anchorFrame; + gridBlockStartFrame_=blockStartFrame; + gridLocalStartFrame_=clock_; + } + // AUDIO: triggers the most recent word/phrase, preferring the latest + // vocal end if the singer stopped within the last 700 ms. + bool throwNow() noexcept { + if(!ready_||recorded_==0||lastSoundEnd_==0||clock_(rate_*.7); + if(clock_-lastSoundEnd_>recent)return false; // reject stale/silent cues + const bool ended=quiet_>0; + // Auto already threw this finished phrase. A late manual click must + // not produce a second identical echo in Hybrid mode. + if(ended && lastSoundEnd_==autoTriggeredPhraseEnd_)return false; + const bool accepted=freezeAt(ended?lastSoundEnd_:clock_); + if(accepted)manualInCurrentPhrase_=true; + return accepted; + } + void processStereo(float* left,float* right,std::size_t frames) noexcept { + if(!ready_||!left||!right)return; + const bool mono=left==right; + const std::uint32_t maxQuiet=static_cast(rate_); + const std::uint32_t phraseGap=static_cast(rate_*.06); + const std::uint32_t minVoice=static_cast(rate_*.08); + for(std::size_t i=0;ienvelope_?envAttack_:envRelease_; + envelope_=coeff*envelope_+(1.f-coeff)*peak; + if(envelope_<1.0e-20f)envelope_=0.f; + const bool singing=envelope_>=settings_.gateLinear; + if(singing) { + if(quiet_>phraseGap) { + voiced_=0; + manualInCurrentPhrase_=false; // genuinely new sung phrase + autoTriggeredPhraseEnd_=0; + } + quiet_=0; + voiced_=std::min(voiced_+1,maxQuiet); + lastSoundEnd_=clock_; + if(voiced_>=minVoice)armed_=true; + } else { + if(quiet_=settings_.silenceSamples) { + if(settings_.settings.mode!=0 && !manualInCurrentPhrase_ + && clock_>=nextAutoEligible_) { + if(freezeAt(lastSoundEnd_)) { + autoTriggeredPhraseEnd_=lastSoundEnd_; + nextAutoEligible_=clock_+ + static_cast(rate_*.4); + } + } + armed_=false; + } + } + float echoL=0.f,echoR=0.f,activeTapGain=0.f; + for(auto& voice:voices_) { + if(voice.copying)copyFrozenChunk(voice); + if(!voice.playing)continue; + // Fixed six-tap limit, constant time; voice owns its capture + // and scheduling packet even when BPM changes mid-tail. + for(int tap=0;tap(tap); + const std::uint64_t start=voice.repeatStarts[slot]; + if(clock_<=start)continue; + const std::uint64_t offset=clock_-start-1; + if(offset>=voice.freezeCount)continue; + float ramp=1.f; + if(voice.edgeSamples>0) { + ramp=std::min(ramp,static_cast(offset)/ + static_cast(voice.edgeSamples)); + ramp=std::min(ramp,static_cast(voice.freezeCount-offset-1)/ + static_cast(voice.edgeSamples)); + } + const auto p=static_cast(offset); + const float gain=voice.repeatGains[slot]*std::max(0.f,ramp); + echoL+=voice.freezeL[p]*gain;echoR+=voice.freezeR[p]*gain; + activeTapGain+=gain; + } + const auto end=voice.repeatStarts[ + static_cast(voice.active.settings.repeats-1)] + +voice.freezeCount; + if(clock_>end)voice.playing=false; + } + // Slew wet level and ducking independently to avoid zipper + // noise on rapid GUI edits and the next vocal entrance. + const float duckTarget=singing?1.f-settings_.settings.ducking:1.f; + duck_=duck_*duckCoeff_+duckTarget*(1.f-duckCoeff_); + wetSmoothed_=wetSmoothed_*duckCoeff_+ + settings_.settings.wet*(1.f-duckCoeff_); + // Concert-safe overlap headroom: many closely spaced taps, + // including two phrases, must not multiply the wet peak by 6x. + // No attenuation for ordinary nonoverlapping delays. + const float echoGain=(wetSmoothed_*duck_)/ + std::max(1.f,activeTapGain*wetSmoothed_); + left[i]=dryL+echoL*echoGain; + if(!mono)right[i]=dryR+echoR*echoGain; + } + } + [[nodiscard]] bool ready() const noexcept{return ready_;} + [[nodiscard]] VocalThrowSettings settingsForTests() const noexcept{return settings_.settings;} + [[nodiscard]] bool echoActive() const noexcept{ + for(const auto& voice:voices_)if(voice.playing)return true; + return false; + } + [[nodiscard]] unsigned throwCount() const noexcept{return throwCount_;} + [[nodiscard]] double sampleRate() const noexcept{return rate_;} +private: + struct TailVoice final { + std::vector freezeL,freezeR; + std::array repeatStarts{}; + std::array repeatGains{}; + PreparedEdit active{}; + std::uint64_t copyEnd=0,freezeCount=0; + std::size_t copyIndex=0,sourceIndex=0; + std::uint32_t edgeSamples=0; + std::uint64_t gridAnchorFrame=0,gridCueFrame=0,gridCueLocal=0; + bool gridValid=false; + bool copying=false,playing=false; + }; + bool freezeAt(std::uint64_t end) noexcept { + if(end==0||end>clock_||historyL_.empty())return false; + // Bounded polyphony: do not cut or overwrite an existing phrase. + // A full pool rejects a cue (and reports this via native ACK). + TailVoice* slot=nullptr; + for(auto& voice:voices_) { + if(!voice.playing&&!voice.copying){slot=&voice;break;} + } + if(!slot)return false; + const auto available=std::min(end,recorded_); + const auto count=std::min(available,settings_.captureSamples); + if(count(rate_*.025))return false; + slot->copyEnd=end; + slot->freezeCount=count; + slot->copyIndex=0; + slot->sourceIndex=static_cast((end-count)%historyL_.size()); + slot->edgeSamples=static_cast(rate_*.004); + slot->active=settings_; + if(musicIntervalSamples_) + slot->active.intervalSamples=musicIntervalSamples_; + // Freeze the same accepted beat grid as the captured phrase. + // Later tempo changes, stale epochs or an unplugged MUSIC WIRE do + // not re-time an already accepted echo tail. + slot->gridValid=gridValid_; + slot->gridAnchorFrame=gridAnchorFrame_; + slot->gridCueFrame=gridBlockStartFrame_+ + (gridValid_?clock_-gridLocalStartFrame_:0); + slot->gridCueLocal=clock_; + slot->copying=true; + ++throwCount_; + return true; + } + void copyFrozenChunk(TailVoice& voice) noexcept { + // A fixed 24-frame budget each sample. Contiguous bulk copying + // replaces per-frame division/modulo in the former implementation. + const std::size_t left=static_cast(voice.freezeCount)-voice.copyIndex; + const std::size_t n=std::min({24,left, + historyL_.size()-voice.sourceIndex}); + std::copy_n(historyL_.data()+voice.sourceIndex,n, + voice.freezeL.data()+voice.copyIndex); + std::copy_n(historyR_.data()+voice.sourceIndex,n, + voice.freezeR.data()+voice.copyIndex); + voice.copyIndex+=n; + voice.sourceIndex+=n; + if(voice.sourceIndex==historyL_.size())voice.sourceIndex=0; + if(voice.copyIndex!=voice.freezeCount)return; + voice.copying=false; + std::uint64_t first=std::max( + clock_,voice.copyEnd+voice.active.intervalSamples); + if(voice.gridValid && voice.active.intervalSamples && + first>=voice.gridCueLocal) { + const auto interval=voice.active.intervalSamples; + const auto globalFirst=voice.gridCueFrame+ + (first-voice.gridCueLocal); + // Quantize only the echo onset, never the singer's dry PCM. + // Use unsigned arithmetic and bound grid correction to one + // subdivision, protecting against a stale/future anchor. + if(globalFirst>=voice.gridAnchorFrame) { + const auto remainder= + (globalFirst-voice.gridAnchorFrame)%interval; + if(remainder)first+=interval-remainder; + } else if(voice.gridAnchorFrame-globalFirst<=interval) { + first+=voice.gridAnchorFrame-globalFirst; + } + } + float amplitude=1.f; + for(int tap=0;tap(tap); + voice.repeatStarts[slot]=first+ + static_cast(tap)*voice.active.intervalSamples; + voice.repeatGains[slot]=amplitude; + amplitude*=voice.active.settings.decay; + } + voice.playing=true; + } + void reset() noexcept { + clock_=lastSoundEnd_=nextAutoEligible_=autoTriggeredPhraseEnd_=0; + recorded_=writeIndex_=0; + voiced_=quiet_=0; + armed_=manualInCurrentPhrase_=false; + envelope_=0.f;duck_=1.f;throwCount_=0; + wetSmoothed_=settings_.settings.wet; + if(rate_>0) { + envAttack_=static_cast(std::exp(-1./(rate_*.004))); + envRelease_=static_cast(std::exp(-1./(rate_*.018))); + duckCoeff_=static_cast(std::exp(-1./(rate_*.008))); + } + for(auto& voice:voices_) { + voice.copyEnd=voice.freezeCount=0; + voice.copyIndex=voice.sourceIndex=0; + voice.edgeSamples=0; + voice.copying=voice.playing=false; + voice.gridValid=false; + voice.gridAnchorFrame=voice.gridCueFrame=voice.gridCueLocal=0; + voice.repeatStarts.fill(0);voice.repeatGains.fill(0.f); + } + std::fill(historyL_.begin(),historyL_.end(),0.f); + std::fill(historyR_.begin(),historyR_.end(),0.f); + } + PreparedEdit settings_{}; + std::vector historyL_,historyR_; + std::array voices_{}; + std::uint64_t clock_=0,lastSoundEnd_=0,nextAutoEligible_=0,autoTriggeredPhraseEnd_=0; + std::size_t recorded_=0,writeIndex_=0; + std::uint32_t voiced_=0,quiet_=0; + float envelope_=0.f,envAttack_=0.f,envRelease_=0.f,duckCoeff_=0.f; + float duck_=1.f,wetSmoothed_=.42f; + double rate_=0.; + std::uint32_t musicIntervalSamples_=0; + std::uint64_t gridAnchorFrame_=0,gridBlockStartFrame_=0,gridLocalStartFrame_=0; + bool gridValid_=false; + unsigned throwCount_=0; + bool armed_=false,manualInCurrentPhrase_=false,ready_=false; +}; +} // namespace armix::builtin_fx diff --git a/engine/builtin_fx/VocalThrowProcessor.h b/engine/builtin_fx/VocalThrowProcessor.h new file mode 100644 index 000000000..dde1edb89 --- /dev/null +++ b/engine/builtin_fx/VocalThrowProcessor.h @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "VocalThrow.h" +#include "FxSpsc.h" +#include "../core/RealtimeNativeFxControl.h" +#include "../core/NativeBeatFrameContext.h" +#include +#include +#include + +// JUCE adapter for the existing ChannelId FX rack. All setting/throw requests +// are bound to an exact accepted graph instance by ConsoleWindow before they +// enter the control->audio SPSC. Audio never posts a WebView event. +namespace armix::builtin_fx { +class VocalThrowProcessor final : public juce::AudioProcessor, + public armix::mixer::RealtimeNativeFxControl { +public: + static constexpr const char* catalogIdentity="armix.builtin.vocal-throw.v1"; + enum class CommandKind : std::uint8_t { settings, trigger }; + struct Completion { + std::uint64_t requestId=0; + VocalThrowSettings settings{}; + CommandKind kind=CommandKind::settings; + bool applied=false; + }; + VocalThrowProcessor() + : juce::AudioProcessor(BusesProperties() + .withInput("Input",juce::AudioChannelSet::stereo(),true) + .withOutput("Output",juce::AudioChannelSet::stereo(),true)) { + setLatencySamples(VocalThrow::addedLatencySamples); + } + const juce::String getName() const override {return "ArSon Vocal Throw";} + bool acceptsMidi() const override{return false;} + bool producesMidi() const override{return false;} + bool isMidiEffect() const override{return false;} + double getTailLengthSeconds() const override{return 16.;} + int getNumPrograms() override{return 1;} + int getCurrentProgram() override{return 0;} + void setCurrentProgram(int) override{} + const juce::String getProgramName(int) override{return "Current";} + void changeProgramName(int,const juce::String&) override{} + bool hasEditor() const override{return false;} + juce::AudioProcessorEditor* createEditor() override{return nullptr;} + bool isBusesLayoutSupported(const BusesLayout& layout) const override { + return layout.getMainInputChannelSet()==juce::AudioChannelSet::stereo()&& + layout.getMainOutputChannelSet()==juce::AudioChannelSet::stereo(); + } + void prepareToPlay(double sampleRate,int) override { + // Each device epoch gets a new frame clock. A previously accepted + // auto BPM interval is invalid if the hardware sample rate changed. + lastTempoBpm_=0.f;lastTempoDivision_=-1; + musicInterval_.store(0,std::memory_order_release); + ready_=core_.prepare(sampleRate)&&core_.resetUnpublished(accepted_); + if(ready_)rate_=sampleRate; + } + void releaseResources() override{ + ready_=false;musicInterval_.store(0,std::memory_order_release); + } + void processBlock(juce::AudioBuffer& pcm,juce::MidiBuffer&) override { + juce::ScopedNoDenormals noDenormals; + if(!ready_||pcm.getNumChannels()<2||pcm.getNumSamples()<=0)return; + // consumeRealtimeEdits() snapshots the accepted tempo BEFORE any + // manual cue in the same block; bypassed inserts use the same path. + consumeRealtimeEdits(); + core_.processStereo(pcm.getWritePointer(0),pcm.getWritePointer(1), + static_cast(pcm.getNumSamples())); + observedThrows_.store(core_.throwCount(),std::memory_order_relaxed); + observedTail_.store(core_.echoActive(),std::memory_order_relaxed); + } + void processBlock(juce::AudioBuffer&,juce::MidiBuffer&) override{} + void consumeRealtimeEdits() noexcept override { + if(!ready_)return; + // One bounded attempt, never spin in ASIO. The native PCM callback + // is the ONLY owner of a valid block sample clock. A stale epoch, + // graph revision, or torn control publication falls back to TAP. + const auto block=armix::mixer::NativeBeatFrameScope::current(); + const auto v0=gridVersion_.load(std::memory_order_acquire); + bool valid=block.valid && (v0&1U)==0U; + std::uint64_t anchor=0; + std::uint32_t interval=0; + if(valid) { + const auto epoch=gridEpoch_.load(std::memory_order_relaxed); + const auto revision=gridRevision_.load(std::memory_order_relaxed); + anchor=gridAnchor_.load(std::memory_order_relaxed); + interval=musicInterval_.load(std::memory_order_relaxed); + const auto v1=gridVersion_.load(std::memory_order_acquire); + valid=v0==v1 && block.epoch==epoch && + block.revision==revision && interval>0; + } + // Low-confidence music can provide a real BPM while its beat + // position is ambiguous. Keep that useful interval, but do NOT + // claim grid quantization. If the whole transport is stale/torn, + // fall all the way back to accepted Manual/TAP. + if(valid&&anchor>0&&anchor<=block.startFrame) + core_.setMusicBeatGrid(interval,anchor,block.startFrame,true); + else + core_.setMusicIntervalSamples(valid?interval:0); + Edit e{}; + if(!done_.canPush()||!commands_.pop(e))return; + const bool applied=e.kind==CommandKind::settings? + core_.applyPrepared(e.prepared):core_.throwNow(); + (void)done_.push({e.id,e.prepared.settings,e.kind,applied}); + } + // CONTROL-thread song/auto BPM, deliberately independent of accepted + // serialized preset BPM. No queue ACK storm or GUI state overwrite. + void publishMusicBpm(float bpm) noexcept { + if(!ready_||!std::isfinite(bpm)||bpm<60.f||bpm>200.f) { + if(lastTempoBpm_!=0.f) { + lastTempoBpm_=0.f;lastTempoDivision_=-1; + musicInterval_.store(0,std::memory_order_release); + } + return; + } + // The 12Hz message timer may deliver the same accepted tempo many + // times. Never recompute power/division or publish redundant atomics. + if(lastTempoBpm_==bpm && lastTempoDivision_==accepted_.division) + return; + auto settings=accepted_;settings.bpm=bpm; + VocalThrow::PreparedEdit packet{}; + const auto valid=VocalThrow::prepareEdit(settings,rate_,packet); + lastTempoBpm_=valid?bpm:0.f; + lastTempoDivision_=valid?accepted_.division:-1; + musicInterval_.store(valid?packet.intervalSamples:0, + std::memory_order_release); + } + // CONTROL ONLY: one source-derived BPM+phase packet is fenced by the + // accepted native PCM epoch/revision. The sample-grid anchor comes from + // onset timestamped INSIDE the same audio callback (10ms granularity). + // Writer is the existing serialized JUCE timer, not a second thread. + void publishMusicGrid(float bpm,std::uint64_t anchorFrame, + std::uint64_t epoch, + std::uint64_t revision) noexcept { + gridVersion_.fetch_add(1,std::memory_order_acq_rel); // odd, unstable + publishMusicBpm(bpm); + gridAnchor_.store(bpm>=60.f&&bpm<=200.f?anchorFrame:0, + std::memory_order_relaxed); + gridEpoch_.store(epoch,std::memory_order_relaxed); + gridRevision_.store(revision,std::memory_order_relaxed); + gridVersion_.fetch_add(1,std::memory_order_release); // even, ready + } + bool queueSettings(const VocalThrowSettings& settings,std::uint64_t id) noexcept { + if(!ready_||id==0)return false; + Edit e{};e.id=id;e.kind=CommandKind::settings; + if(!VocalThrow::prepareEdit(settings,rate_,e.prepared))return false; + return commands_.push(e); + } + bool queueTrigger(std::uint64_t id) noexcept { + if(!ready_||id==0)return false; + Edit e{};e.id=id;e.kind=CommandKind::trigger; + return commands_.push(e); + } + bool pollCompletion(Completion& out) noexcept { + if(!done_.pop(out))return false; + if(out.applied&&out.kind==CommandKind::settings)accepted_=out.settings; + return true; + } + VocalThrowSettings acceptedSettings() const noexcept{return accepted_;} + double acceptedSampleRate() const noexcept{return rate_;} + unsigned observedThrowCount() const noexcept { + return observedThrows_.load(std::memory_order_relaxed); + } + bool observedTailActive() const noexcept { + return observedTail_.load(std::memory_order_relaxed); + } + bool isReady() const noexcept{return ready_;} + void sealForRealtime() noexcept override{published_=true;} + bool stateSnapshotQuiescent() const noexcept override{ + return commands_.empty()&&done_.empty(); + } + void getStateInformation(juce::MemoryBlock& out) override { + juce::MemoryOutputStream writer(out,false); + writer.writeInt(0x41565448); // AVTH + writer.writeInt(1); + writer.writeInt(accepted_.mode); + writer.writeFloat(accepted_.bpm); + writer.writeInt(accepted_.division); + writer.writeInt(accepted_.repeats); + writer.writeFloat(accepted_.captureMs); + writer.writeFloat(accepted_.silenceMs); + writer.writeFloat(accepted_.thresholdDb); + writer.writeFloat(accepted_.wet); + writer.writeFloat(accepted_.decay); + writer.writeFloat(accepted_.ducking); + } + bool restoreUnpublishedState(const void* data,int bytes) { + if(published_||!data||bytes!=48||!commands_.empty()||!done_.empty()) + return false; + juce::MemoryInputStream reader(data,static_cast(bytes),false); + if(reader.readInt()!=0x41565448||reader.readInt()!=1)return false; + VocalThrowSettings s{}; + s.mode=reader.readInt(); + s.bpm=reader.readFloat(); + s.division=reader.readInt(); + s.repeats=reader.readInt(); + s.captureMs=reader.readFloat(); + s.silenceMs=reader.readFloat(); + s.thresholdDb=reader.readFloat(); + s.wet=reader.readFloat(); + s.decay=reader.readFloat(); + s.ducking=reader.readFloat(); + if(!reader.isExhausted()||!VocalThrow::validSettings(s))return false; + if(ready_&&!core_.resetUnpublished(s))return false; + accepted_=s;return true; + } + void setStateInformation(const void* data,int bytes) override{ + (void)restoreUnpublishedState(data,bytes); + } +private: + struct Edit { + std::uint64_t id=0; + CommandKind kind=CommandKind::settings; + VocalThrow::PreparedEdit prepared{}; + }; + VocalThrow core_{}; + FxSpsc commands_{}; + FxSpsc done_{}; + VocalThrowSettings accepted_{}; + std::atomic observedThrows_{0}; + std::atomic musicInterval_{0}; + std::atomic gridVersion_{0},gridAnchor_{0}; + std::atomic gridEpoch_{0},gridRevision_{0}; + std::atomic observedTail_{false}; + double rate_=0.; + float lastTempoBpm_=0.f; // CONTROL only + int lastTempoDivision_=-1; // CONTROL only + bool ready_=false,published_=false; +}; +} // namespace armix::builtin_fx diff --git a/engine/core/DynamicNativeSessionPublisher.h b/engine/core/DynamicNativeSessionPublisher.h index f867130fa..18ef3d10c 100644 --- a/engine/core/DynamicNativeSessionPublisher.h +++ b/engine/core/DynamicNativeSessionPublisher.h @@ -2,6 +2,8 @@ #pragma once #include "DynamicPreparedMixerBlock.h" #include "DynamicConsoleRoutingView.h" +#include "NativeMusicTempoMonitor.h" +#include "NativeBeatFrameContext.h" #include "RealtimeRoutePublisher.h" #include "RealtimeRenderPermit.h" #include @@ -124,8 +126,23 @@ class DynamicNativeSessionPublisher final { const auto status=publisher_.publish(std::move(next), expectedRevision,activeDeviceEpoch); switch(status) { - case Publisher::Result::applied: + case Publisher::Result::applied: { + const auto source=musicTempo_.selectedSource(); + if(source.value) { + const auto* published=publisher_.controlPrepared( + proposedDeviceEpoch,expectedRevision+1); + const auto* channel=published? + published->routing.find(source):nullptr; + const bool retained=published&&channel&& + (channel->role==ChannelRole::input|| + channel->role==ChannelRole::group|| + channel->role==ChannelRole::fxReturn)&& + published->graph.channelScheduled(source); + musicTempo_.onGraphCommitted(proposedDeviceEpoch, + expectedRevision,expectedRevision+1,retained); + } report.revision=expectedRevision+1;return report; + } case Publisher::Result::staleDevice: report.fault=Fault::staleDevice;break; case Publisher::Result::staleRevision: @@ -187,11 +204,20 @@ class DynamicNativeSessionPublisher final { if(!exclusive) { clearOutputs();return false; } + // One sample domain for all ChannelIds and their FX racks. This + // fixed-time callback-local scope also fences bypassed/stale inserts; + // no second transport thread, allocation or callback is introduced. + const auto startFrame=musicTempo_.beginAudioBlock(deviceEpoch,frames); + NativeBeatFrameScope frameScope{deviceEpoch,snap->graphRevision,startFrame}; // Prepared FX takes precedence over the legacy external callback. // NEVER invoke both: that would double-compress or double-reverb. // Snapshot ownership pins the M4 instance throughout this callback; // only control-thread retirement releases the shared owner. const auto dispatch=[&](ChannelId id,float* l,float* r,int n) noexcept { + // Analysis source is the installed ChannelId MUSIC PCM, before + // its VST rack; never microphone/echo/main unless explicitly + // selected and role-checked on CONTROL. No analysis on AUDIO. + musicTempo_.capture(id,l,r,n,snap->deviceEpoch,snap->graphRevision); const auto& acceptedFx=snap->prepared->fx; if(acceptedFx.render) acceptedFx.render(acceptedFx.context,id,l,r,n); @@ -204,6 +230,25 @@ class DynamicNativeSessionPublisher final { return ok; } + // CONTROL ONLY: choose an actual active backing input/GROUP/FX return. + // Preserve the one authoritative PCM graph and reject stale selectors. + bool setMusicTempoSource(std::uint64_t epoch,std::uint64_t revision, + ChannelId source,double sampleRate) noexcept { + const auto* p=publisher_.controlPrepared(epoch,revision); + if(!p)return false; + if(source.value) { + const auto* ch=p->routing.find(source); + if(!ch || (ch->role!=ChannelRole::input && + ch->role!=ChannelRole::group && + ch->role!=ChannelRole::fxReturn) || + !p->graph.channelScheduled(source))return false; + } + return musicTempo_.select(source,epoch,revision,sampleRate); + } + NativeMusicTempoMonitor::State pollMusicTempo(std::uint64_t epoch, + std::uint64_t revision) noexcept { + return musicTempo_.poll(epoch,revision); + } // CONTROL ONLY; pointer is valid until the next structural commit. // The caller must COPY needed fields before yielding the writer thread. // Future WebView event serializes this only after native ACK, never draft. @@ -290,6 +335,7 @@ class DynamicNativeSessionPublisher final { } private: Publisher publisher_; + NativeMusicTempoMonitor musicTempo_{}; std::atomic_flag rendering_=ATOMIC_FLAG_INIT; }; } // namespace armix::mixer diff --git a/engine/core/NativeBeatFrameContext.h b/engine/core/NativeBeatFrameContext.h new file mode 100644 index 000000000..c77f79b08 --- /dev/null +++ b/engine/core/NativeBeatFrameContext.h @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include + +// A tiny callback-local sample-clock context, NOT a transport or second +// callback. The native ChannelId publisher owns the authoritative frame +// counter. JUCE's built-in VocalThrow reads the same context only while +// it is rendering as an insert on that callback thread. No heap or locks. +namespace armix::mixer { +struct NativeBeatFrameContext final { + std::uint64_t epoch=0,revision=0,startFrame=0; + bool valid=false; +}; +inline thread_local NativeBeatFrameContext currentNativeBeatFrame{}; + +class NativeBeatFrameScope final { +public: + explicit NativeBeatFrameScope(std::uint64_t epoch,std::uint64_t revision, + std::uint64_t startFrame) noexcept + : previous_(currentNativeBeatFrame) { + currentNativeBeatFrame={epoch,revision,startFrame,epoch!=0&&revision!=0}; + } + ~NativeBeatFrameScope() noexcept {currentNativeBeatFrame=previous_;} + NativeBeatFrameScope(const NativeBeatFrameScope&)=delete; + NativeBeatFrameScope& operator=(const NativeBeatFrameScope&)=delete; + static NativeBeatFrameContext current() noexcept { + return currentNativeBeatFrame; + } +private: + NativeBeatFrameContext previous_{}; +}; +} // namespace armix::mixer diff --git a/engine/core/NativeMusicTempoMonitor.h b/engine/core/NativeMusicTempoMonitor.h new file mode 100644 index 000000000..7023de8ed --- /dev/null +++ b/engine/core/NativeMusicTempoMonitor.h @@ -0,0 +1,376 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "../builtin_fx/FxSpsc.h" +#include "DynamicChannelRoster.h" +#include +#include +#include +#include +#include +#include + +// ArSon M2: source-specific music tempo observation inside the ONE installed +// ChannelId renderer. AUDIO only summarizes its explicitly selected music +// channel into 10ms energy frames and pushes a bounded SPSC. CONTROL owns all +// onset, pulse-correlation and tempo work. This is NOT a second audio engine. +namespace armix::mixer { +class MusicTempoEstimator final { +public: + struct Result final { + float bpm=0.f,confidence=0.f,phaseConfidence=0.f; + bool phaseLocked=false; + std::uint64_t beatAnchorTick=0,observationTick=0; + // Both are authoritative native callback sample-frame positions. + // Onset is quantized by the 10ms summary window; not sample-perfect + // transient detection or DAW-wide delay compensation. + std::uint64_t beatAnchorFrame=0,observationFrame=0; + bool locked=false; + // Last CONTROL-only scan's actual tempo-bin comparisons. Enables + // deterministic worst-case budget regression without wall-clock + // timing or instrumentation on the ASIO callback. + std::uint32_t scoringComparisons=0; + }; + void reset() noexcept { + previous_=floor_=0.f;count_=write_=0; + lastHit_=lastScan_=lastTick_=0; + stableCount_=0;candidateBpm_=0;result_={}; + } + void ingest(float energy,std::uint64_t tick, + std::uint64_t endingFrame=0) noexcept { + if(!std::isfinite(energy)||energy<0.f)energy=0.f; + if(lastTick_ && (tick<=lastTick_ || tick-lastTick_>4))reset(); + lastTick_=tick; + floor_+=.005f*(energy-floor_); + const float rise=energy-previous_; + // Attack transient only; sustained pads/bleed cannot retrigger + // every 10ms. 80ms refractory rejects the same drum's ringing. + if(tick>=lastHit_+8 && energy>.003f && + rise>std::max(.005f,floor_*.45f)) { + hits_[write_]={tick,std::min(1.f,rise),endingFrame}; + write_=(write_+1)%hits_.size(); + count_=std::min(count_+1,hits_.size()); + lastHit_=tick; + } + previous_=energy; + if(endingFrame)result_.observationFrame=endingFrame; + if(result_.locked && tick>lastHit_+320) { + result_.locked=false;result_.confidence=0.f; + result_.phaseLocked=false;result_.phaseConfidence=0.f; + candidateBpm_=stableCount_=0; + } + if(tick>=lastScan_+50) { + lastScan_=tick; + evaluate(); + } + } + Result result() const noexcept {return result_;} +private: + struct Hit { + std::uint64_t tick=0; + float strength=0.f; + std::uint64_t frame=0; + }; + std::array hits_{}; + std::size_t count_=0,write_=0; + std::uint64_t lastHit_=0,lastScan_=0,lastTick_=0; + float previous_=0.f,floor_=0.f; + int stableCount_=0,candidateBpm_=0; + Result result_{}; + + void evaluate() noexcept { + if(count_<7 || lastTick_<300 || lastTick_>lastHit_+320)return; + const auto at=[&](std::size_t i) noexcept ->const Hit& { + return hits_[(write_+hits_.size()-count_+i)%hits_.size()]; + }; + if(at(count_-1).tick-at(0).tick<300)return; + int bestBpm=0; + float bestScore=0.f; + // CONTROL-owned fixed stack scratch; no heap or unbounded history. + // Retain the incumbent candidate's score so a transient half/double + // time accent cannot steal an already convincing song clock. + std::array candidates{}; + // CONTROL ONLY, exact-score-preserving sparse candidate search. + // The former 121-BPM outer loop re-traversed the complete onset + // history for every candidate, adding unpredictable GUI timer work. + // Each onset pair can support only nearby BPM bins (<=3 periods). + // Enumerate each pair ONCE, derive the mathematically eligible BPM + // neighborhood, then use the original round/error/weight formula. + // Memory is the same 121-float fixed stack array; no heap, worker, + // allocations, callback scheduling or changed confidence threshold. + constexpr int minBpm=60,maxBpm=180; + constexpr float maxPairTicks=(6000.f/minBpm)*3.08f; + std::uint32_t compared=0; + for(std::size_t j=1;j1100)continue; + for(std::size_t i=j;i-->0;) { + const auto& earlier=at(i); + const float dt=static_cast(later.tick-earlier.tick); + if(dt>maxPairTicks)break; + const float strength=std::sqrt(earlier.strength*later.strength); + for(int cycles=1;cycles<=3;++cycles) { + const float targetBpm=6000.f*cycles/dt; + // The original tolerance is max(1.4 ticks, 2.2% of + // a multi-beat period). Within 60–180 BPM, its largest + // possible candidate separation is <10 BPM. +/-12 + // therefore cannot discard an original valid score. + const int near=static_cast(std::lround(targetBpm)); + const int lo=std::max(minBpm,near-12); + const int hi=std::min(maxBpm,near+12); + for(int bpm=lo;bpm<=hi;++bpm) { + ++compared; + const float period=6000.f/static_cast(bpm); + if(dt>period*3.08f)continue; + if(static_cast(std::lround(dt/period))!=cycles)continue; + const float tolerance=std::max(1.4f,.022f*period*cycles); + const float error=std::abs(dt-period*cycles); + if(error>=tolerance)continue; + candidates[static_cast(bpm-minBpm)]+= + strength*(1.f-error/tolerance)/ + (cycles==1?1.f:cycles==2?1.6f:2.25f); + } + } + } + } + result_.scoringComparisons=compared; + // Preserve deterministic ascending-BPM tie-breaking and the old + // half/double-time decision semantics exactly. + for(int bpm=minBpm;bpm<=maxBpm;++bpm) { + const float score=candidates[static_cast(bpm-minBpm)]; + if(score>bestScore){bestScore=score;bestBpm=bpm;} + } + if(bestBpm==0 || bestScore<2.0f)return; + if(result_.locked) { + const int previous=static_cast(std::lround(result_.bpm)); + const bool octave=std::abs(2*previous-bestBpm)<=3 || + std::abs(previous-2*bestBpm)<=3; + if(octave && previous>=60 && previous<=180 && + candidates[static_cast(previous-60)]>= + bestScore*.70f) { + // The rhythmic subdivision is ambiguous. Stay on the song + // BPM until a genuine, repeatedly stronger tempo emerges. + bestBpm=previous; + } + } + if(std::abs(bestBpm-candidateBpm_)<=2)++stableCount_; + else {candidateBpm_=bestBpm;stableCount_=1;} + // A proven lock resists transient alternate half/double-time peaks. + if(result_.locked && std::abs(bestBpm-result_.bpm)>5.f && + stableCount_<6)return; + if(stableCount_<3)return; + // Octave hysteresis can deliberately select a weaker incumbent. + // Confidence MUST describe that selected BPM, not an alternate + // double/half-time peak that we explicitly rejected. + const float acceptedScore= + candidates[static_cast(bestBpm-60)]; + // Only the same LIVE 11-second onset window contributes to the + // candidate score. The ring may still contain many old weak hat + // attacks from a previous passage. Dividing by all 128 archival + // hits permanently depresses confidence even after a convincing + // quarter-note pulse returns (observed Windows CTest regression). + // Keep numerator and denominator on the identical time horizon. + std::size_t recentCount=0; + for(std::size_t i=0;i(std::max(7,recentCount))*.9f,0.f,1.f); + if(confidence<.28f) { + // A busy but low-confidence groove is NOT a stable beat. The + // previous code kept locked=true (and old beat-phase) while + // overwriting BPM, which could shift the next singer echo on an + // untrusted grid. Fail closed to accepted Manual/TAP, then demand + // three fresh good estimates before reacquiring Auto. + result_.confidence=confidence; + result_.locked=false; + result_.phaseLocked=false; + result_.phaseConfidence=0.f; + result_.beatAnchorFrame=0; + result_.beatAnchorTick=0; + stableCount_=candidateBpm_=0; + return; + } + result_.bpm=static_cast(bestBpm); + result_.confidence=confidence; + // CONTROL: phase is a separate decision from the BPM estimate. + // Search the bounded onset set for the strongest coherent pulse + // lattice, not simply the most recent loud snare / clap. + const float period=6000.f/result_.bpm; + const float tolerance=std::max(1.6f,period*.075f); + const auto matches=[&](std::uint64_t a,std::uint64_t b) noexcept { + const float elapsed=static_cast(a>b?a-b:b-a); + const float cycles=std::round(elapsed/period); + const float difference=std::abs(elapsed-cycles*period); + return std::max(0.f,1.f-difference/tolerance); + }; + float total=0.f; + for(std::size_t i=0;i0.f)for(std::size_t candidate=0;candidate1100)continue; + float coherence=0.f; + for(std::size_t i=0;ileading+.0001f || + (std::abs(coherence-leading)<=.0001f && + center.tick>anchor)) { + leading=coherence; + anchor=center.tick; + anchorFrame=center.frame; + } + } + // Competing off-beat cohorts mean the quarter-note phase is not + // established, even when interval BPM itself is reliable. + float competing=0.f; + if(anchor)for(std::size_t candidate=0;candidate1100 || + matches(center.tick,anchor)>.15f)continue; + float coherence=0.f; + for(std::size_t i=0;i0.f? + std::clamp(leading/total,0.f,1.f):0.f; + result_.phaseLocked=anchorFrame>0 && + result_.phaseConfidence>=.52f && + competing192000.))return false; + source_.store(id.value,std::memory_order_relaxed); + epoch_.store(epoch,std::memory_order_relaxed); + revision_.store(revision,std::memory_order_relaxed); + window_.store(id.value? + static_cast(std::lround(sampleRate*.01)):0, + std::memory_order_relaxed); + config_.fetch_add(1,std::memory_order_release); + return true; + } + // CONTROL: harmless structural WIRE/FX commits should preserve a valid + // music source. If the selected channel disappears, fall back to manual + // immediately rather than capturing stale processor/graph PCM. + ChannelId selectedSource() const noexcept { + return ChannelId{source_.load(std::memory_order_relaxed)}; + } + void onGraphCommitted(std::uint64_t epoch,std::uint64_t previousRevision, + std::uint64_t revision,bool retained) noexcept { + if(!selectedSource().value)return; + if(!retained || epoch_.load(std::memory_order_relaxed)!=epoch || + revision_.load(std::memory_order_relaxed)!=previousRevision) { + (void)select(ChannelId{},epoch,revision,0); + return; + } + revision_.store(revision,std::memory_order_relaxed); + config_.fetch_add(1,std::memory_order_release); + } + // AUDIO ONLY: the accepted publisher calls this ONCE per successfully + // admitted render block before traversing its ChannelId lanes. Revisions + // do not reset this clock; a physical epoch change always does. + std::uint64_t beginAudioBlock(std::uint64_t epoch,int frames) noexcept { + if(audioEpoch_!=epoch) { + audioEpoch_=epoch; + audioFrameClock_=0; + } + const auto start=audioFrameClock_; + if(frames>0)audioFrameClock_+=static_cast(frames); + blockStartFrame_=start; + return start; + } + // AUDIO: invoked once for every scheduled source channel by the existing + // renderer's pre-FX dispatch. Only the selected ID costs per-sample work. + void capture(ChannelId id,const float* left,const float* right,int frames, + std::uint64_t epoch,std::uint64_t revision) noexcept { + const auto generation=config_.load(std::memory_order_acquire); + if(audioGeneration_!=generation) { + audioGeneration_=generation; + bucketSamples_=0;energySum_=0.f;audioTick_=0; + } + if(!id.value||id.value!=source_.load(std::memory_order_relaxed)|| + epoch!=epoch_.load(std::memory_order_relaxed)|| + revision!=revision_.load(std::memory_order_relaxed)|| + !left||!right||frames<=0)return; + const auto window=window_.load(std::memory_order_relaxed); + if(window==0)return; + for(int i=0;i(i)+1}; + if(!frames_.push(f)) + dropped_.fetch_add(1,std::memory_order_relaxed); + bucketSamples_=0;energySum_=0.f; + } + } + } + // CONTROL: limited work per timer tick, never called from ASIO callback. + State poll(std::uint64_t liveEpoch,std::uint64_t liveRevision) noexcept { + const auto generation=config_.load(std::memory_order_acquire); + if(controlGeneration_!=generation) { + controlGeneration_=generation;estimator_.reset(); + } + Frame f{}; + for(int i=0;i<512 && frames_.pop(f);++i) + if(f.generation==generation) + estimator_.ingest(f.energy,f.tick,f.frameEnd); + State out{}; + out.source.value=source_.load(std::memory_order_relaxed); + out.epoch=epoch_.load(std::memory_order_relaxed); + out.revision=revision_.load(std::memory_order_relaxed); + out.dropped=dropped_.load(std::memory_order_relaxed); + out.active=out.source.value && out.epoch==liveEpoch && + out.revision==liveRevision; + if(out.active)out.tempo=estimator_.result(); + return out; + } +private: + struct Frame { + std::uint32_t generation=0; + std::uint64_t tick=0; + float energy=0.f; + std::uint64_t frameEnd=0; + }; + armix::builtin_fx::FxSpsc frames_{}; + MusicTempoEstimator estimator_{}; // CONTROL owner only + std::atomic source_{0},epoch_{0},revision_{0}; + std::atomic config_{0},window_{0},dropped_{0}; + // The following fields are AUDIO-thread exclusive. + std::uint32_t audioGeneration_=0,bucketSamples_=0; + float energySum_=0.f; + std::uint64_t audioTick_=0; + std::uint64_t audioEpoch_=0,audioFrameClock_=0,blockStartFrame_=0; + std::uint32_t controlGeneration_=0; // CONTROL only +}; +} // namespace armix::mixer diff --git a/scripts/compose_native_peq.py b/scripts/compose_native_peq.py index a44984f58..4962371d1 100644 --- a/scripts/compose_native_peq.py +++ b/scripts/compose_native_peq.py @@ -6,6 +6,7 @@ SCRIPT='' COMP_SCRIPT='' HARMONY_SCRIPT='' +THROW_SCRIPT='' PICKER_HEAD="function renderFastPicker(){" PICKER_FN="""function insertChosenNativeEq(){ const t=tracks.concat(master).find(x=>x.id===activeFxTarget?.channelId); @@ -73,6 +74,25 @@ say('ArSon Harmony · browser preview ONLY · no DSP'); return true; } +function insertChosenNativeThrow(){ + const t=tracks.concat(master).find(x=>x.id===activeFxTarget?.channelId); + const slot=Number(activeFxTarget?.slot); + if(!t||!Number.isInteger(slot)||slot<0||slot>=8){ + say('Vocal Throw · choose an empty FX insert');return false; + } + if(window.__JUCE__?.backend?.emitEvent){ + const host=window.ArSonMixNativeVocalThrow; + if(!host?.insert){say('Native Vocal Throw host unavailable');return false;} + host.insert(activeFxTarget);return true; + } + if(t.fx[slot]!=='None'){ + say('FX slot already occupied · choose an empty insert');return false; + } + t.fx[slot]='ArSon Vocal Throw';t.slotBypass[slot]=false; + t.fxInsertIds[slot]={id:'visual-throw-'+t.id+'-'+slot,name:'ArSon Vocal Throw'}; + refreshStrip(t);setFastPicker(false); + say('Vocal Throw · browser preview ONLY · no audio DSP');return true; +} function renderFastPicker(){""" PICKER_RENDER="plugEl('fastResults').innerHTML=list.length?list.map(p=>" PICKER_RENDER_NEW="""const eqBuiltin=!q||['parametric eq','peq','channel eq','built-in fx'].some(n=>n.includes(q))? @@ -81,7 +101,9 @@ '':''; const harmonyBuiltin=!q||['arson harmony','harmony','vocal harmony','built-in fx'].some(n=>n.includes(q))? '':''; - const builtin=(eqBuiltin||compBuiltin||harmonyBuiltin?'
BUILT-IN FX
':'')+eqBuiltin+compBuiltin+harmonyBuiltin; + const throwBuiltin=!q||['vocal throw','throw','delay','echo','phrase','concert','built-in fx'].some(n=>n.includes(q))? + '':''; + const builtin=(eqBuiltin||compBuiltin||harmonyBuiltin||throwBuiltin?'
BUILT-IN FX
':'')+eqBuiltin+compBuiltin+harmonyBuiltin+throwBuiltin; plugEl('fastResults').innerHTML=builtin+'
VST3 PLUGINS
'+(list.length?list.map(p=>""" PICKER_END=""").join(''):'
No matching effects
';""" PICKER_END_NEW=""").join(''):'
No matching effects
');""" @@ -89,9 +111,10 @@ PICKER_CLICK_NEW=""" if(e.target.closest('[data-fast-native-harmony]')){insertChosenNativeHarmony();return;} if(e.target.closest('[data-fast-native-eq]')){insertChosenNativeEq();return;} if(e.target.closest('[data-fast-native-comp]')){insertChosenNativeCompressor();return;} + if(e.target.closest('[data-fast-native-throw]')){insertChosenNativeThrow();return;} const btn=e.target.closest('[data-fast-id]');if(btn)insertCatalogPlugin(btn.dataset.fastId);""" PICKER_ENTER="if(b){e.preventDefault();insertCatalogPlugin(b.dataset.fastId);}" -PICKER_ENTER_NEW="if(b){e.preventDefault();if(b.hasAttribute('data-fast-native-harmony'))insertChosenNativeHarmony();else if(b.hasAttribute('data-fast-native-eq'))insertChosenNativeEq();else if(b.hasAttribute('data-fast-native-comp'))insertChosenNativeCompressor();else insertCatalogPlugin(b.dataset.fastId);}" +PICKER_ENTER_NEW="if(b){e.preventDefault();if(b.hasAttribute('data-fast-native-harmony'))insertChosenNativeHarmony();else if(b.hasAttribute('data-fast-native-throw'))insertChosenNativeThrow();else if(b.hasAttribute('data-fast-native-eq'))insertChosenNativeEq();else if(b.hasAttribute('data-fast-native-comp'))insertChosenNativeCompressor();else insertCatalogPlugin(b.dataset.fastId);}" OPEN=" if(a==='openPlugin'){openFastPicker(t,Number(btn.dataset.slot),btn);return;}" OPEN_NEW=""" if(a==='openPlugin'){ const index=Number(btn.dataset.slot); @@ -104,6 +127,9 @@ if(t.fx[index]==='ArSon Harmony'){ window.ArSonMixNativeHarmony?.open(t,index);return; } + if(t.fx[index]==='ArSon Vocal Throw'){ + window.ArSonMixNativeVocalThrow?.open(t,index);return; + } openFastPicker(t,index,btn);return; }""" def apply_native_peq(html: str)->str: @@ -114,11 +140,11 @@ def apply_native_peq(html: str)->str: (PICKER_ENTER,PICKER_ENTER_NEW), (OPEN,OPEN_NEW)) if html.count('')!=1 or html.count('')!=1 or \ - SCRIPT in html or COMP_SCRIPT in html or 'insertChosenNativeEq' in html: + SCRIPT in html or COMP_SCRIPT in html or HARMONY_SCRIPT in html or THROW_SCRIPT in html or 'insertChosenNativeEq' in html: raise ValueError("Parametric EQ requires one pristine approved compiled GUI") for before,after in anchors: if html.count(before)!=1: raise ValueError('Ambiguous approved picker/editor anchor: '+before[:90]) html=html.replace(before,after,1) - html=html.replace('',SCRIPT+'\n'+COMP_SCRIPT+'\n'+HARMONY_SCRIPT+'\n',1) + html=html.replace('',SCRIPT+'\n'+COMP_SCRIPT+'\n'+HARMONY_SCRIPT+'\n'+THROW_SCRIPT+'\n',1) return html diff --git a/site/preview-v2/assets/arson-vocal-hardware-encoder.svg b/site/preview-v2/assets/arson-vocal-hardware-encoder.svg new file mode 100644 index 000000000..2cb7d175f --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-encoder.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-push.svg b/site/preview-v2/assets/arson-vocal-hardware-push.svg new file mode 100644 index 000000000..1b9970a96 --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-push.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-rotor.svg b/site/preview-v2/assets/arson-vocal-hardware-rotor.svg new file mode 100644 index 000000000..e8c72a55e --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-rotor.svg @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-hardware-toggle.svg b/site/preview-v2/assets/arson-vocal-hardware-toggle.svg new file mode 100644 index 000000000..d3aad9aa7 --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-hardware-toggle.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/site/preview-v2/assets/arson-vocal-throw-performance.svg b/site/preview-v2/assets/arson-vocal-throw-performance.svg new file mode 100644 index 000000000..c3622667a --- /dev/null +++ b/site/preview-v2/assets/arson-vocal-throw-performance.svg @@ -0,0 +1,26 @@ + \ No newline at end of file diff --git a/site/preview-v2/assets/mixer-contextual-buttons.css b/site/preview-v2/assets/mixer-contextual-buttons.css index d80749d4e..cb2b07a5e 100644 --- a/site/preview-v2/assets/mixer-contextual-buttons.css +++ b/site/preview-v2/assets/mixer-contextual-buttons.css @@ -197,22 +197,24 @@ } /* Single authoritative modal Close + built-in FX Power chrome. + The semantic .armix-builtin-fx-power / -close classes are mandatory on + every built-in editor, while legacy EQ/Compressor names remain compatible. All cards: same 24px hit box, same icon, same pressed-red interaction. Green ON, muted red insert bypass, amber rack bypass, grey unavailable. FX state is assigned exclusively from accepted DSP graph readback. */ -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close){display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;box-sizing:border-box!important;flex:0 0 24px!important;width:24px!important;min-width:24px!important;max-width:24px!important;height:24px!important;min-height:24px!important;max-height:24px!important;padding:0!important;margin:0!important;font-size:0!important;line-height:1!important;color:#e0edf2!important;cursor:pointer!important;border:1px solid #607d8c!important;border-radius:4px!important;background:linear-gradient(#3e5866,#293e4b)!important;box-shadow:inset 0 1px #ffffff22,0 1px 2px #06131f75!important;transform:none!important;text-shadow:none!important;transition:background-color .10s,border-color .10s,color .10s!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close) svg{display:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close)::before{content:none!important;display:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close)::after,:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):active::after{content:""!important;display:block!important;position:relative!important;flex:0 0 12px!important;inset:auto!important;width:12px!important;height:12px!important;opacity:1!important;border:0!important;border-radius:0!important;transform:none!important;box-shadow:none!important;pointer-events:none!important;background:linear-gradient(45deg,transparent 43%,currentColor 43% 57%,transparent 57%),linear-gradient(-45deg,transparent 43%,currentColor 43% 57%,transparent 57%)!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):hover:not(:disabled){color:#fff!important;border-color:#b27078!important;background:linear-gradient(#64424f,#4d343f)!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):active:not(:disabled){color:#fff!important;border-color:#ee8b93!important;background:linear-gradient(#cc4753,#982a36)!important;box-shadow:inset 0 2px 4px #4c0c1790,0 0 0 1px #ef698069!important;transition:none!important} -:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close):focus-visible{outline:2px solid #a2dce9!important;outline-offset:2px!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power){display:inline-flex!important;align-items:center!important;justify-content:center!important;box-sizing:border-box!important;flex:0 0 26px!important;width:26px!important;height:24px!important;opacity:1!important;padding:0!important;border:1px solid #4b6572!important;border-radius:4px!important;background:linear-gradient(#384b56,#243846)!important;box-shadow:inset 0 1px #ffffff20!important;font-size:18px!important;transition:none!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="on"]{color:#76f0b9!important;border-color:#428969!important;background:linear-gradient(#335c51,#204539)!important;text-shadow:0 0 5px #7df0b85c!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="off"]{color:#e99b9f!important;border-color:#83525a!important;background:linear-gradient(#533b42,#3a3039)!important;text-shadow:none!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="rack-off"]{color:#f0c483!important;border-color:#846948!important;background:linear-gradient(#544737,#41382d)!important;text-shadow:none!important;cursor:not-allowed!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power)[data-fx-state="unknown"]{color:#8498a4!important;border-color:#4b5d66!important;background:linear-gradient(#3a4751,#2b3941)!important;text-shadow:none!important;cursor:not-allowed!important} -body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power):focus-visible{outline:2px solid #9cdbe7!important;outline-offset:2px!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close){display:inline-flex!important;align-items:center!important;justify-content:center!important;position:relative!important;box-sizing:border-box!important;flex:0 0 24px!important;width:24px!important;min-width:24px!important;max-width:24px!important;height:24px!important;min-height:24px!important;max-height:24px!important;padding:0!important;margin:0!important;font-size:0!important;line-height:1!important;color:#e0edf2!important;cursor:pointer!important;border:1px solid #607d8c!important;border-radius:4px!important;background:linear-gradient(#3e5866,#293e4b)!important;box-shadow:inset 0 1px #ffffff22,0 1px 2px #06131f75!important;transform:none!important;text-shadow:none!important;transition:background-color .10s,border-color .10s,color .10s!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close) svg{display:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close)::before{content:none!important;display:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close)::after,:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):active::after{content:""!important;display:block!important;position:relative!important;flex:0 0 12px!important;inset:auto!important;width:12px!important;height:12px!important;opacity:1!important;border:0!important;border-radius:0!important;transform:none!important;box-shadow:none!important;pointer-events:none!important;background:linear-gradient(45deg,transparent 43%,currentColor 43% 57%,transparent 57%),linear-gradient(-45deg,transparent 43%,currentColor 43% 57%,transparent 57%)!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):hover:not(:disabled){color:#fff!important;border-color:#b27078!important;background:linear-gradient(#64424f,#4d343f)!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):active:not(:disabled){color:#fff!important;border-color:#ee8b93!important;background:linear-gradient(#cc4753,#982a36)!important;box-shadow:inset 0 2px 4px #4c0c1790,0 0 0 1px #ef698069!important;transition:none!important} +:is(.app,body) :is(#identityClose,#pluginClose,#fastClose,#wireConfigClose,#wireWsClose,#routeChoiceClose,.armix-floating-close,.mx-peq-close,.mx-comp-close,.mx-harm-close,.armix-builtin-fx-close):focus-visible{outline:2px solid #a2dce9!important;outline-offset:2px!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power){display:inline-flex!important;align-items:center!important;justify-content:center!important;box-sizing:border-box!important;flex:0 0 26px!important;width:26px!important;height:24px!important;opacity:1!important;padding:0!important;border:1px solid #4b6572!important;border-radius:4px!important;background:linear-gradient(#384b56,#243846)!important;box-shadow:inset 0 1px #ffffff20!important;font-size:18px!important;transition:none!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="on"]{color:#76f0b9!important;border-color:#428969!important;background:linear-gradient(#335c51,#204539)!important;text-shadow:0 0 5px #7df0b85c!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="off"]{color:#e99b9f!important;border-color:#83525a!important;background:linear-gradient(#533b42,#3a3039)!important;text-shadow:none!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="rack-off"]{color:#f0c483!important;border-color:#846948!important;background:linear-gradient(#544737,#41382d)!important;text-shadow:none!important;cursor:not-allowed!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power)[data-fx-state="unknown"]{color:#8498a4!important;border-color:#4b5d66!important;background:linear-gradient(#3a4751,#2b3941)!important;text-shadow:none!important;cursor:not-allowed!important} +body :is(.mx-peq-global,.mx-comp-power,.mx-harm-power,.armix-builtin-fx-power):focus-visible{outline:2px solid #9cdbe7!important;outline-offset:2px!important} /* ArSon Player: compact stage-first drawer inside the ONE approved mixer GUI. */ #playerToggle{min-width:86px;letter-spacing:.01em} diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index b5f8376f9..30b699c29 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -748,3 +748,235 @@ @media(prefers-reduced-motion:reduce){ .mx-harm *{transition:none!important;animation:none!important} } + +/* Vocal Throw M4 — aligned studio-hardware faceplate. + One spacing grid, one encoder body, one fixed 260deg rounded level arc. + Close/Power remain the same approved EQ/Compressor shared controls. */ +.mx-vthrow{position:fixed;z-index:15001;top:clamp(7px,7vh,66px);left:clamp(7px,9vw,175px); + width:min(778px,calc(100vw - 14px));max-height:calc(100dvh - 14px);display:flex;flex-direction:column; + box-sizing:border-box;overflow:hidden;border:1px solid #505763;border-radius:9px;color:#d5dce5; + background:linear-gradient(155deg,#323740,#242931 60%,#20252d); + box-shadow:inset 0 1px #ffffff21,inset 0 -1px #090c1199,0 18px 50px #000c; + font:400 11px/1.35 Inter,'Segoe UI',sans-serif} +.mx-vthrow[hidden]{display:none}.mx-vthrow *{box-sizing:border-box} +.mx-vthrow button{font:inherit;cursor:pointer} +.mx-vthrow :is(button,select,input):focus-visible{outline:2px solid #b6e8e3;outline-offset:3px} +.mx-vthrow .vt-face-header{height:42px;flex:0 0 42px;display:flex;align-items:center;gap:8px; + min-width:0;padding:0 10px 0 16px;cursor:move;touch-action:none;user-select:none; + background:linear-gradient(#3d444e,#292f38);border-bottom:1px solid #141922; + box-shadow:inset 0 1px #ffffff29,inset 0 -1px #ffffff09} +.mx-vthrow .brand{display:flex;align-items:baseline;gap:7px;white-space:nowrap;flex:0 0 auto} +.mx-vthrow .brand-mark{font-size:9px;font-weight:660;color:#c885e7;letter-spacing:.12em} +.mx-vthrow .brand-name{font-size:12px;font-weight:580;color:#f0eef4;letter-spacing:.055em} +.mx-vthrow .channel{min-width:0;max-width:120px;flex:1;overflow:hidden;text-overflow:ellipsis; + white-space:nowrap;font-size:9px;color:#aeb1ba} +.mx-vthrow .vt-preset{display:flex;align-items:center;gap:4px;margin-left:auto;min-width:0} +.mx-vthrow .vt-preset select{width:112px;height:25px;min-width:0;max-width:112px;padding:0 7px; + border:1px solid #525c68;border-radius:4px;background:linear-gradient(#2a3039,#1f252e); + color:#dce1e9;font:500 10px Inter,'Segoe UI',sans-serif} +.mx-vthrow option{color:#e8eaf1;background:#272b34} +.mx-vthrow .vt-hardware{min-height:0;overflow:auto;overscroll-behavior:contain;display:grid; + padding:0;scrollbar-width:thin;scrollbar-color:#565563 #22272e} +.mx-vthrow .vt-console{padding:14px 17px 13px;border-bottom:1px solid #515660; + background:linear-gradient(135deg,#31363e,#262b34 65%,#2b2f38); + box-shadow:inset 0 1px #ffffff13} +.mx-vthrow .vt-instrument{display:grid;grid-template-columns:minmax(0,1fr) 212px minmax(0,1fr); + align-items:center;column-gap:15px;min-width:0} +.mx-vthrow .vt-encoder-bank{display:grid;grid-template-columns:repeat(3,minmax(0,1fr)); + justify-items:center;align-items:center;min-width:0;gap:3px} +.mx-vthrow .vt-encoder{display:flex;flex-direction:column;align-items:center;justify-content:center; + gap:5px;min-width:0;padding:6px 0 4px} +.mx-vthrow .vt-encoder-name{height:12px;line-height:12px;color:#a5b0bc;font-size:8px; + font-weight:530;letter-spacing:.055em;white-space:nowrap} +.mx-vthrow .vt-encoder-face{position:relative;display:block;flex:0 0 auto;width:68px;height:68px; + padding:0;border:0;border-radius:50%;touch-action:none;cursor:ns-resize; + background:transparent url("arson-vocal-hardware-encoder.svg") center/77% 77% no-repeat; + filter:drop-shadow(0 4px 5px #060a10a8)} +.mx-vthrow .vt-knob-meter{position:absolute;inset:0;width:100%;height:100%;overflow:visible; + fill:none;pointer-events:none} +.mx-vthrow .vt-meter-track,.mx-vthrow .vt-meter-fill{fill:none;stroke-width:3.3; + stroke-linecap:round;stroke-linejoin:round} +.mx-vthrow .vt-meter-track{stroke:#52616c;stroke-opacity:.8} +.mx-vthrow .vt-meter-fill{stroke:#79d4c7;stroke-width:3.8; + stroke-dasharray:100 100;stroke-dashoffset:var(--arc-offset,100); + filter:drop-shadow(0 0 1.3px #6ad8c788)} +.mx-vthrow .vt-encoder-needle{position:absolute;inset:0;transform:rotate(var(--turn,-130deg)); + pointer-events:none} +.mx-vthrow .vt-encoder-needle::after{content:"";position:absolute;left:calc(50% - 1.25px); + top:23%;height:12px;width:2.5px;border-radius:3px;background:#aee9e2; + box-shadow:0 0 3px #73cfce94} +.mx-vthrow .vt-encoder-value{font:500 11px/14px Inter,'Segoe UI',sans-serif; + color:#e0dce6;font-variant-numeric:tabular-nums;white-space:nowrap} +.mx-vthrow .vt-center{min-width:0;display:flex;align-items:center; + justify-content:center;flex-direction:column;gap:0} +.mx-vthrow .vt-throw-button{position:relative;display:block;width:212px;height:212px;flex:0 0 auto; + border:0;padding:0;border-radius:50%;overflow:visible;touch-action:manipulation;cursor:pointer; + background:transparent url("arson-vocal-throw-performance.svg") center/contain no-repeat; + filter:drop-shadow(0 8px 9px #090d15af);transform:translateZ(0); + transition:filter 150ms ease,transform 100ms ease} +.mx-vthrow .vt-throw-aura{position:absolute;inset:10%;border-radius:50%;pointer-events:none; + box-shadow:inset 0 0 0 1px #b267c821,0 0 0 1px #11141b; + transition:box-shadow 150ms ease} +.mx-vthrow .vt-throw-button:hover:not(:disabled){filter:brightness(1.19) drop-shadow(0 8px 10px #080c13ca)} +.mx-vthrow .vt-throw-button:hover:not(:disabled) .vt-throw-aura{box-shadow:0 0 22px #bc36df3b,inset 0 0 0 1px #c17fdd3a} +.mx-vthrow .vt-throw-button:active:not(:disabled){transform:scale(.958) translateY(2px); + filter:brightness(1.32) drop-shadow(0 1px 2px #000b)} +.mx-vthrow .vt-throw-button[data-tail=true]:not(:disabled) .vt-throw-aura{ + box-shadow:0 0 29px #bb29e73f,inset 0 0 0 1px #e7a7f783} +.mx-vthrow .vt-throw-button:disabled{opacity:.53;filter:grayscale(.72) brightness(.8)} +.mx-vthrow .vt-throw-engraving{margin-top:-3px;color:#a995b4; + font-size:9px;letter-spacing:.24em;font-weight:560;user-select:none} +.mx-vthrow .vt-performance{display:grid;grid-template-columns:90px minmax(0,1fr) 293px; + align-items:center;column-gap:18px;margin-top:8px;min-height:104px} +.mx-vthrow .vt-wet-module{padding:3px 0} +.mx-vthrow .vt-wet-module .vt-encoder-face{width:68px;height:68px} +.mx-vthrow .vt-trigger{min-width:0;display:flex;align-items:center;justify-content:center} +.mx-vthrow .vt-mode-buttons,.mx-vthrow .vt-division-buttons{display:flex;align-items:center; + gap:2px;padding:3px;border:1px solid #171c23;border-radius:7px; + background:linear-gradient(#131820,#242a32); + box-shadow:inset 0 2px 4px #060b11b8,0 1px #56606a3d} +.mx-vthrow :is(.vt-mode-buttons,.vt-division-buttons) button{flex:1;min-width:0; + min-height:29px;padding:3px 7px;border:1px solid transparent;border-radius:4px; + background:linear-gradient(#3b424b,#2d343d);box-shadow:inset 0 1px #ffffff15; + color:#a6b0bc;font-size:10px;font-weight:580;letter-spacing:.03em} +.mx-vthrow :is(.vt-mode-buttons,.vt-division-buttons) button[aria-pressed=true]{ + color:#f5e4ff;border-color:#784f8b;background:linear-gradient(#6a4c78,#3f344a); + box-shadow:inset 0 1px #efbaff2b,0 0 7px #b66bd327} +.mx-vthrow .vt-virtual-input,.mx-vthrow .vt-screen-reader{position:absolute!important; + width:1px!important;height:1px!important;padding:0!important;border:0!important; + opacity:0!important;overflow:hidden!important;pointer-events:none!important} +.mx-vthrow .vt-clock-tap{display:grid;grid-template-columns:minmax(0,1fr) 83px; + align-items:center;gap:9px;min-width:0} +.mx-vthrow .vt-tempo{min-width:0;display:flex;flex-direction:column;align-items:center;gap:3px} +.mx-vthrow .vt-clock-screen{position:relative;width:100%;height:79px;min-width:0;display:flex;flex-direction:column; + justify-content:center;align-items:stretch;gap:1px;padding:7px 11px 5px; + border:1px solid #42616a;border-radius:6px;color:#cbf8e9; + background:radial-gradient(ellipse at 50% 15%,#173b40b5,transparent 80%), + linear-gradient(155deg,#071c22,#092831 70%,#061a20); + box-shadow:inset 0 2px 11px #000b,inset 0 0 0 1px #092a32,0 1px #53667233} +.mx-vthrow .vt-lcd-top{display:flex;align-items:center;justify-content:space-between; + font-size:9px;letter-spacing:.15em;color:#77aead} +.mx-vthrow #vtClockLabel{color:#a9dec5;font-size:9px;font-weight:550;letter-spacing:.1em} +.mx-vthrow .vt-lcd-digits{display:flex;align-items:baseline;gap:8px} +.mx-vthrow #vtDisplayBpm{padding:0;margin:0;border:0;background:none;appearance:none; + font:500 44px/1.04 'Segoe UI',Inter,sans-serif; + color:#d8fff2;letter-spacing:-.05em;font-variant-numeric:tabular-nums; + text-shadow:0 0 15px #61b7a533;cursor:text;text-align:left} +.mx-vthrow #vtDisplayBpm:hover{color:#e8fff7} +.mx-vthrow .vt-clock-screen[data-editing=true] #vtDisplayBpm{opacity:0;pointer-events:none} +.mx-vthrow .vt-lcd-digits>span{font-size:10px;color:#7fbeb2;letter-spacing:.07em} +.mx-vthrow .vt-manual-bpm{display:none;position:absolute;left:11px;right:10px; + top:25px;height:49px;align-items:center;z-index:1} +.mx-vthrow .vt-clock-screen[data-editing=true] .vt-manual-bpm{display:flex} +.mx-vthrow .vt-manual-bpm input{width:100%;max-width:148px;height:49px;margin:0; + padding:0;border:0;border-bottom:1px solid #75d5c58f;border-radius:0; + outline:0;background:#0b252d;color:#d8fff2; + font:500 44px/1.04 'Segoe UI',sans-serif;text-align:left; + letter-spacing:-.05em;font-variant-numeric:tabular-nums; + appearance:textfield} +.mx-vthrow .vt-manual-bpm input::-webkit-inner-spin-button, +.mx-vthrow .vt-manual-bpm input::-webkit-outer-spin-button{appearance:none;margin:0} +.mx-vthrow .vt-tap-button{height:81px;display:flex;flex-direction:column; + align-items:center;justify-content:center;gap:1px;color:#c8d0d9; + background:linear-gradient(#414852,#262c35);border:1px solid #4c5661;border-radius:12px; + box-shadow:inset 0 1px #ffffff21,0 3px 6px #0008} +.mx-vthrow .vt-tap-button span{font-size:15px;font-weight:640;letter-spacing:.12em} +.mx-vthrow .vt-tap-button small{font-size:9px;letter-spacing:.12em;color:#a5b0bc} +.mx-vthrow .vt-tap-button:active{background:linear-gradient(#242931,#353b45); + box-shadow:inset 0 2px 5px #000a} +.mx-vthrow .vt-transport{min-width:0;display:grid; + grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:24px; + padding:12px 18px 13px;background:linear-gradient(#232a33,#20252d); + border-top:1px solid #0f141b;border-bottom:1px solid #4b525c} +.mx-vthrow .vt-pulse,.mx-vthrow .vt-music-source{min-width:0; + display:flex;flex-direction:column;align-items:stretch;gap:6px} +.mx-vthrow .vt-small-label{font-size:9px;font-weight:550;letter-spacing:.11em; + color:#a7acb6;white-space:nowrap} +.mx-vthrow .vt-division-buttons{height:38px} +.mx-vthrow .vt-division-buttons button{height:30px;padding:3px 4px} +.mx-vthrow .vt-repeat-leds{display:flex;align-items:center;gap:5px; + white-space:nowrap;height:14px} +.mx-vthrow .vt-repeat-leds i{display:block;width:16px;height:3px; + border-radius:3px;background:#3d4550} +.mx-vthrow .vt-repeat-leds i[data-on=true]{background:#7bd4c7;box-shadow:0 0 4px #7bd4c755} +.mx-vthrow .vt-repeat-leds[data-playing=true] i[data-on=true]{background:#ade6d4} +.mx-vthrow .vt-music-source select{height:38px;width:100%;min-width:0;padding:0 9px; + border:1px solid #46515e;border-radius:5px;background:linear-gradient(#333a45,#252c36); + color:#d8e0e8;font:500 10px Inter,'Segoe UI',sans-serif} +.mx-vthrow .music-status{height:14px;overflow:hidden;text-overflow:ellipsis; + white-space:nowrap;font-size:9px;color:#9abfb9} +.mx-vthrow .vt-status-rail{height:29px;min-width:0;display:flex;align-items:center; + justify-content:space-between;gap:14px;padding:0 17px; + border-top:1px solid #090d13;background:linear-gradient(#272d36,#232831); + font-size:9px;letter-spacing:.035em;color:#929eaa} +.mx-vthrow .vt-device{flex:0 0 auto;white-space:nowrap} +.mx-vthrow .dot{display:inline-block;width:6px;height:6px;margin-right:6px; + border-radius:50%;background:#6f7781;box-shadow:0 0 0 1px #10141a} +.mx-vthrow .dot.active{background:#79cbb8;box-shadow:0 0 5px #79cbb855} +.mx-vthrow .vt-hint{min-width:0;flex:1;text-align:center;overflow:hidden; + text-overflow:ellipsis;white-space:nowrap} +.mx-vthrow #vtCount{flex:0 0 auto;white-space:nowrap} +.mx-vthrow[data-fx-state=off] :is(.vt-encoder-face,.vt-throw-button), +.mx-vthrow[data-fx-state=rack-off] :is(.vt-encoder-face,.vt-throw-button){ + opacity:.55;filter:grayscale(.55) brightness(.77)} +@media(max-width:770px){ + .mx-vthrow{top:7px;left:7px} + .mx-vthrow .vt-console{padding:10px 10px 12px} + .mx-vthrow .vt-instrument{grid-template-columns:minmax(0,1fr) 192px minmax(0,1fr);gap:8px} + .mx-vthrow .vt-throw-button{width:192px;height:192px} + .mx-vthrow .vt-encoder-face{width:54px;height:54px} + .mx-vthrow .vt-encoder-name{font-size:7.5px} + .mx-vthrow .vt-encoder-needle::after{height:9px} + .mx-vthrow .vt-performance{grid-template-columns:78px minmax(0,1fr) 285px;column-gap:8px} + .mx-vthrow .vt-wet-module .vt-encoder-face{width:54px;height:54px} + .mx-vthrow .vt-transport{gap:14px;padding:10px} +} +@media(max-width:600px){ + .mx-vthrow{width:calc(100vw - 10px);max-height:calc(100dvh - 10px);left:5px;top:5px} + .mx-vthrow .vt-face-header{height:39px;flex-basis:39px;gap:5px;padding:0 7px} + .mx-vthrow .brand{gap:5px}.mx-vthrow .brand-mark{font-size:8px} + .mx-vthrow .brand-name{font-size:10px} + .mx-vthrow .channel{max-width:42px;font-size:8px} + .mx-vthrow .vt-preset select{width:82px;max-width:82px;font-size:9px} + .mx-vthrow .vt-instrument{display:flex;flex-direction:column;gap:0} + .mx-vthrow .vt-center{order:0;margin-bottom:8px} + .mx-vthrow #vtEncodersLeft{order:1} + .mx-vthrow #vtEncodersRight{order:2} + .mx-vthrow .vt-throw-button{width:166px;height:166px} + .mx-vthrow .vt-throw-engraving{font-size:9px;margin-top:-4px} + .mx-vthrow .vt-encoder-bank{width:100%;grid-template-columns:repeat(3,minmax(0,1fr));gap:0} + .mx-vthrow .vt-encoder{gap:3px;padding:3px 0 2px} + .mx-vthrow .vt-encoder-face{width:59px;height:59px} + .mx-vthrow .vt-encoder-name{font-size:8px} + .mx-vthrow .vt-encoder-value{font-size:10px} + .mx-vthrow .vt-performance{grid-template-columns:76px minmax(0,1fr); + column-gap:12px;row-gap:8px;min-height:0;margin-top:8px} + .mx-vthrow .vt-wet-module .vt-encoder-face{width:59px;height:59px} + .mx-vthrow .vt-clock-tap{grid-column:1/-1;grid-template-columns:minmax(0,1fr) 85px; + align-items:center;gap:10px} + .mx-vthrow .vt-clock-screen{height:83px} + .mx-vthrow #vtDisplayBpm{font-size:47px} + .mx-vthrow .vt-tap-button{height:84px} + .mx-vthrow .vt-mode-buttons{width:max-content;max-width:100%} + .mx-vthrow .vt-mode-buttons button{font-size:9px;min-height:31px;padding:3px 7px} + .mx-vthrow .vt-transport{grid-template-columns:1fr;gap:9px;padding:10px} + .mx-vthrow .vt-division-buttons{height:35px} + .mx-vthrow .vt-division-buttons button{font-size:9px;height:27px} + .mx-vthrow .vt-music-source select{height:31px} + .mx-vthrow .vt-status-rail{gap:7px;padding:0 9px} +} +@media(max-width:350px){ + .mx-vthrow .channel{display:none} + .mx-vthrow .brand-name{font-size:9px} + .mx-vthrow .vt-preset select{width:72px} + .mx-vthrow .vt-mode-buttons button{padding:3px 5px} +} +@media(max-height:590px) and (min-width:601px){ + .mx-vthrow{top:4px;max-height:calc(100dvh - 8px)} + .mx-vthrow .vt-console{padding-top:6px;padding-bottom:7px} + .mx-vthrow .vt-throw-button{height:172px;width:172px} + .mx-vthrow .vt-instrument{grid-template-columns:minmax(0,1fr) 176px minmax(0,1fr)} +} +@media(prefers-reduced-motion:reduce){ + .mx-vthrow .vt-throw-button,.mx-vthrow .vt-throw-aura{transition:none} +} diff --git a/site/preview-v2/assets/mixer-native-compressor.js b/site/preview-v2/assets/mixer-native-compressor.js index 57bd82293..c9599c2ef 100644 --- a/site/preview-v2/assets/mixer-native-compressor.js +++ b/site/preview-v2/assets/mixer-native-compressor.js @@ -61,6 +61,7 @@ power.title="FX STATE UNAVAILABLE";power.dataset.fxState="unknown"; power.disabled=true;power.setAttribute("aria-pressed","false"); power.setAttribute("aria-label","Compressor state unavailable"); close.setAttribute("aria-label","Close Compressor"); +power.classList.add("armix-builtin-fx-power");close.classList.add("armix-builtin-fx-close"); header.append(brand,channel,presetSelect,stateDot,power,close); const controls=dom("div","mx-comp-controls"); const left=dom("div","mx-comp-left"); diff --git a/site/preview-v2/assets/mixer-native-peq.js b/site/preview-v2/assets/mixer-native-peq.js index e0b2e990e..270ec25b0 100644 --- a/site/preview-v2/assets/mixer-native-peq.js +++ b/site/preview-v2/assets/mixer-native-peq.js @@ -76,7 +76,8 @@ close.innerHTML=' { +"use strict"; +const ID="armix.builtin.vocal-throw.v1"; +const defaults=()=>({mode:2,bpm:120,division:0,repeats:3,captureMs:460, + silenceMs:220,thresholdDb:-35,wet:.42,decay:.55,ducking:.7}); +const presets={ + Concert:defaults(), + Fast:{...defaults(),division:1,repeats:4,captureMs:330,decay:.6}, + Ballad:{...defaults(),bpm:72,captureMs:650,wet:.48}, + Word:{...defaults(),mode:0,captureMs:280,silenceMs:180} +}; +const ranges={bpm:[60,200],repeats:[1,6],captureMs:[80,1500],silenceMs:[80,900], + thresholdDb:[-65,-15],wet:[0,1],decay:[.15,.9],ducking:[0,1]}; +const valid=s=>s&&[0,1,2].includes(s.mode)&&[0,1,2,3].includes(s.division)&& + Object.entries(ranges).every(([k,[min,max]])=> + Number.isFinite(s[k])&&s[k]>=min&&s[k]<=max); +const same=(a,b)=>Object.keys(defaults()).every(k=>a[k]===b[k]); +const clamp=(v,min,max)=>Math.max(min,Math.min(max,v)); +const backend=()=>window.__JUCE__?.backend; +const native=()=>typeof backend()?.emitEvent==="function"; +const snapshot=()=>window.__ARMIX_NATIVE_M2__?.state?.()?.current; + +const panel=document.createElement("section"); +panel.className="mx-vthrow";panel.id="mxNativeVocalThrow";panel.hidden=true; +panel.setAttribute("role","dialog");panel.setAttribute("aria-modal","false"); +panel.setAttribute("aria-label","ArSon Vocal Throw"); +// One universal 260-degree rounded level arc for EVERY hardware encoder. +// The face itself stays stationary; only the pointer and stroke advance. +const rotaryArc=''; +panel.innerHTML=[ + '
ARSONVOCAL THROW
', + '', + '', + '
', + '
', + '
', + '
', + '
MIX42%
', + '
', + '
TEMPOMAN
BPM
', + '
', + '
RHYTHM
1/4 · HYBRID
', + '
TAP
', + '
LIVE0
' +].join(""); +document.body.append(panel); +const $=id=>panel.querySelector("#"+id); +const encoderMeta={ + captureMs:["CAPTURE","ms",5,"vtEncodersLeft"], + silenceMs:["END","ms",10,"vtEncodersLeft"], + thresholdDb:["GATE","dB",1,"vtEncodersLeft"], + decay:["DECAY","%",.01,"vtEncodersRight"], + ducking:["DUCK","%",.01,"vtEncodersRight"], + repeats:["REPEATS","x",1,"vtEncodersRight"] +}; +for(const [key,[title,unit,,bank]] of Object.entries(encoderMeta)){ + const node=document.createElement("div"); + node.className="vt-encoder";node.dataset.key=key; + node.innerHTML=''+title+''+ + ''+ + ''; + node.querySelector("output").dataset.unit=unit; + $(bank).append(node); +} +let current=null,accepted=defaults(),draft=defaults(),pending=null, + readId="",readSent=0,seq=1,taps=[],windowDrag=null; +let tempoPending=null,musicSource="0",musicReadback=null; +const context=()=>{ + const state=snapshot(),id=current&&window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const fx=state?.graph?.channels?.find(ch=>ch.id===id)?.inserts?.[current?.slot]; + if(!state?.admitted||!id||fx?.catalogId!==ID||fx?.id!==current?.instanceId)return null; + return {channelId:id,slot:current.slot,instanceId:fx.id, + deviceEpoch:state.device.epoch,graphRevision:state.graph.revision}; +}; +const hint=text=>{$("vtHint").textContent=text;}; +function refreshMusicChannels(){ + const state=snapshot(),ctx=context(),selector=$("vtMusicSource"); + const selected=tempoPending?.source||musicSource; + const candidates=(state?.graph?.channels||[]).filter(ch=> + ch&&ch.id&&String(ch.id)!==String(ctx?.channelId)&& + ["INPUT","GROUP","FX_RETURN","FXRETURN"].includes( + String(ch.role||"").toUpperCase().replaceAll("-","_"))); + selector.replaceChildren(new Option("Manual / TAP","0")); + for(const ch of candidates)selector.add(new Option( + String(ch.name||ch.id).slice(0,45),String(ch.id))); + if([...selector.options].some(x=>x.value===String(selected))) + selector.value=String(selected); + else selector.value="0"; + selector.disabled=!ctx||!native()||Boolean(tempoPending); +} +function renderMusicStatus(tempo){ + if(tempo)musicReadback=tempo; + const label=$("vtMusicStatus"),clock=$("vtClockLabel"),number=$("vtDisplayBpm"); + const fallback=()=>{number.textContent=String(Math.round(accepted.bpm));clock.textContent="MAN";}; + if(tempoPending){label.textContent="CONNECT";label.title="Validating music channel";clock.textContent="CHECK";return;} + if(musicSource==="0"){label.textContent="TAP";label.title="Manual BPM / TAP";fallback();return;} + if(!musicReadback?.musicSourceActive){label.textContent="NO SIGNAL";label.title="Music source unavailable · manual BPM fallback";fallback();return;} + if(!musicReadback.musicLocked){label.textContent="LISTEN";label.title="Listening for beat · manual BPM fallback";fallback();return;} + const confidence=Math.round(Math.max(0,Math.min(1,Number(musicReadback.musicConfidence)||0))*100); + const beatGrid=musicReadback.musicGridAvailable===true; + const bpm=Math.round(Number(musicReadback.musicBpm)); + label.textContent=beatGrid?bpm+" · GRID":bpm+" · BPM"; + label.title="Auto tempo "+bpm+" BPM · "+confidence+"% confidence · "+(beatGrid?"beat grid":"BPM only"); + clock.textContent=beatGrid?"LOCK":"AUTO"; + number.textContent=String(bpm); +} +function syncPower(){ + const state=snapshot(),id=current&&window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); + const lane=state?.graph?.channels?.find(ch=>ch.id===id),fx=lane?.inserts?.[current?.slot]; + const value=!context()?"unknown":lane.fxRackBypassed?"rack-off":fx.bypassed?"off":"on"; + panel.dataset.fxState=value; + const btn=$("vtPower");btn.dataset.fxState=value; + btn.disabled=value==="unknown"||value==="rack-off"; + btn.title=value==="on"?"Active · click to bypass":value==="off"?"Bypassed · click to enable": + value==="rack-off"?"FX rack bypassed":"Native FX unavailable"; + btn.setAttribute("aria-pressed",String(value==="on")); + btn.setAttribute("aria-label",btn.title); + $("vtThrow").disabled=value!=="on"||!!pending; + $("vtStatus").textContent=value==="on"? + ($("vtThrow").dataset.tail==="true"?"TAIL":"LIVE"): + value==="off"?"BYPASS":value==="rack-off"?"RACK OFF":"OFFLINE"; +} +function paint(){ + $("vtMode").value=String(draft.mode); + if(panel.querySelector(".vt-clock-screen").dataset.editing!=="true") + $("vtBpm").value=String(draft.bpm); + $("vtDivision").value=String(draft.division);$("vtRepeats").value=String(draft.repeats); + for(const [key,[,unit]] of Object.entries(encoderMeta)){ + const node=panel.querySelector('.vt-encoder[data-key="'+key+'"]'); + const min=ranges[key][0],max=ranges[key][1]; + const pct=(draft[key]-min)/(max-min); + const turn=-130+260*pct; + node.style.setProperty("--turn",turn.toFixed(2)+"deg"); + // pathLength=100 guarantees a linearly advancing, rounded 260-degree arc. + // Never rotate the knob chassis with the pointer. + node.style.setProperty("--arc-offset",(100-pct*100).toFixed(3)); + node.querySelector(".vt-encoder-value").textContent= + (unit==="%"?Math.round(draft[key]*100):Math.round(draft[key]))+unit; + const dial=node.querySelector(".vt-encoder-face"); + dial.setAttribute("aria-valuemin",String(min)); + dial.setAttribute("aria-valuemax",String(max)); + dial.setAttribute("aria-valuenow",String(draft[key])); + dial.setAttribute("aria-valuetext",node.querySelector(".vt-encoder-value").textContent); + } + const wetPct=Math.round(draft.wet*100); + $("vtWetValue").textContent=wetPct+"%"; + $("vtWetDial").style.setProperty("--turn",(-130+260*draft.wet).toFixed(2)+"deg"); + $("vtWetDial").style.setProperty("--arc-offset",(100-draft.wet*100).toFixed(3)); + $("vtWetDial").setAttribute("aria-valuenow",String(wetPct)); + $("vtWetDial").setAttribute("aria-valuetext",wetPct+" percent"); + for(const b of panel.querySelectorAll(".vt-mode-buttons button")) + b.setAttribute("aria-pressed",String(Number(b.dataset.mode)===draft.mode)); + for(const b of panel.querySelectorAll(".vt-division-buttons button")) + b.setAttribute("aria-pressed",String(Number(b.dataset.division)===draft.division)); + $("vtPreset").value=Object.entries(presets).find(([,v])=>same(v,draft))?.[0]||"Custom"; + const rhythmic=["1/4","1/8","DOTTED 1/8","1/2"][accepted.division]; + const modes=["MANUAL","AUTO","HYBRID"]; + $("vtRhythm").textContent=rhythmic+" · "+modes[accepted.mode]; + for(const [index,led] of [...$("vtBeatRail").querySelectorAll("i")].entries()) + led.dataset.on=String(index{ + if(!current||pending)return; + bpmScreen.dataset.editing="true"; + $("vtBpm").value=String(draft.bpm); + $("vtBpm").focus();$("vtBpm").select(); +}); +$("vtBpm").addEventListener("keydown",e=>{ + if(e.key==="Escape"){ + e.preventDefault();e.stopPropagation(); + $("vtBpm").value=String(accepted.bpm); + $("vtBpm").blur(); + }else if(e.key==="Enter"){ + e.preventDefault();$("vtBpm").blur(); + } +}); +$("vtBpm").addEventListener("blur",()=>{bpmScreen.dataset.editing="false";}); +for(const [key,id] of [["mode","vtMode"],["bpm","vtBpm"], + ["division","vtDivision"],["repeats","vtRepeats"]]){ + $(id).addEventListener("change",()=>{ + draft={...draft,[key]:Number($(id).value)};paint();send("nativeThrowSet"); + }); +} +// Physical rotary control: vertical pointer drag, mouse wheel and keyboard. +// Update visual locally during movement; issue exactly ONE accepted native +// settings intent at drag release. No DOM/audio DSP loops are introduced. +function bindRotary(face,key,step){ + const [min,max]=ranges[key]; + const quantize=v=>clamp(Math.round(v/step)*step,min,max); + let gesture=null; + const update=v=>{if(pending)return;draft={...draft,[key]:quantize(v)};paint();}; + face.addEventListener("pointerdown",e=>{ + if(e.button!==0||pending)return; + gesture={id:e.pointerId,y:e.clientY,initial:draft[key],changed:false}; + face.setPointerCapture(e.pointerId);e.preventDefault(); + }); + face.addEventListener("pointermove",e=>{ + if(!gesture||gesture.id!==e.pointerId)return; + const next=quantize(gesture.initial+(gesture.y-e.clientY)*(max-min)/168); + if(next!==draft[key]){gesture.changed=true;update(next);} + e.preventDefault(); + }); + const finish=e=>{ + if(!gesture||e.pointerId!==gesture.id)return; + const changed=gesture.changed;gesture=null; + if(face.hasPointerCapture?.(e.pointerId))face.releasePointerCapture(e.pointerId); + if(changed)send("nativeThrowSet"); + }; + face.addEventListener("pointerup",finish); + face.addEventListener("pointercancel",()=>{gesture=null;paint();}); + face.addEventListener("wheel",e=>{ + if(pending)return; + e.preventDefault();update(draft[key]+(e.deltaY<0?step:-step)); + send("nativeThrowSet"); + },{passive:false}); + face.addEventListener("keydown",e=>{ + const delta={ArrowUp:1,ArrowRight:1,ArrowDown:-1,ArrowLeft:-1,PageUp:5,PageDown:-5}[e.key]; + if(delta===undefined&&e.key!=="Home"&&e.key!=="End")return; + e.preventDefault(); + update(e.key==="Home"?min:e.key==="End"?max:draft[key]+delta*step); + send("nativeThrowSet"); + }); + face.addEventListener("dblclick",()=>{ + if(pending)return; + update(defaults()[key]);send("nativeThrowSet"); + }); +} +for(const [key,[,,step]] of Object.entries(encoderMeta)) + bindRotary(panel.querySelector('.vt-encoder[data-key="'+key+'"] .vt-encoder-face'),key,step); +bindRotary($("vtWetDial"),"wet",.01); +for(const button of panel.querySelectorAll(".vt-mode-buttons button")){ + button.addEventListener("click",()=>{ + $("vtMode").value=button.dataset.mode; + $("vtMode").dispatchEvent(new Event("change",{bubbles:true})); + }); +} +for(const button of panel.querySelectorAll(".vt-division-buttons button")){ + button.addEventListener("click",()=>{ + $("vtDivision").value=button.dataset.division; + $("vtDivision").dispatchEvent(new Event("change",{bubbles:true})); + }); +} +$("vtMusicSource").addEventListener("change",()=>{ + const ctx=context(),source=String($("vtMusicSource").value); + if(!ctx||!native()||tempoPending){refreshMusicChannels();return;} + const requestId="tempo-"+Date.now()+"-"+(++seq); + tempoPending={requestId,source,created:Date.now()}; + backend().emitEvent("arMixAction",{ + action:"nativeThrowTempoSource",requestId,sourceChannelId:source,...ctx}); + renderMusicStatus();refreshMusicChannels(); +}); +$("vtPreset").addEventListener("change",()=>{ + const p=presets[$("vtPreset").value];if(!p)return; + draft={...p};paint();send("nativeThrowSet"); +}); +$("vtThrow").addEventListener("click",()=>send("nativeThrowTrigger")); +$("vtTap").addEventListener("click",()=>{ + const now=performance.now(); + if(taps.length&&now-taps[taps.length-1]>2500)taps=[]; + taps.push(now);if(taps.length>6)taps.shift(); + if(taps.length<3){hint("Tap at least three beats");return;} + const deltas=taps.slice(1).map((time,i)=>time-taps[i]).filter(v=>v>=280&&v<=1200); + if(deltas.length<2){hint("Tap a steady beat");return;} + const ordered=[...deltas].sort((a,b)=>a-b); + const median=ordered[Math.floor(ordered.length/2)]; + draft={...draft,bpm:clamp(Math.round(60000/median),60,200)}; + paint();send("nativeThrowSet"); +}); +$("vtPower").addEventListener("click",()=>{ + if(current&&context())window.__ARMIX_NATIVE_M2__?.consumeAction?.( + current.track,"slotPower",{dataset:{slot:String(current.slot)}}); +}); +$("vtClose").addEventListener("click",()=>{panel.hidden=true;pending=null;tempoPending=null;readId="";}); +window.addEventListener("keydown",e=>{ + if(e.key==="Escape"&&!panel.hidden){panel.hidden=true;pending=null;readId="";} +}); +const head=panel.querySelector("header"); +head.addEventListener("pointerdown",e=>{ + if(e.button||e.target.closest("button,select"))return; + const box=panel.getBoundingClientRect(); + windowDrag={id:e.pointerId,dx:e.clientX-box.left,dy:e.clientY-box.top}; + head.setPointerCapture(e.pointerId);e.preventDefault(); +}); +head.addEventListener("pointermove",e=>{ + if(!windowDrag||e.pointerId!==windowDrag.id)return; + panel.style.left=clamp(e.clientX-windowDrag.dx,0,Math.max(0,innerWidth-panel.offsetWidth))+"px"; + panel.style.top=clamp(e.clientY-windowDrag.dy,0,Math.max(0,innerHeight-panel.offsetHeight))+"px"; +}); +head.addEventListener("pointerup",e=>{windowDrag=null;head.releasePointerCapture?.(e.pointerId);}); +window.ArSonMixNativeVocalThrow=Object.freeze({ + id:ID, + insert(target){return Boolean(window.__ARMIX_NATIVE_M2__?.insertPlugin?.(ID,target));}, + open(track,slot){ + current={track,slot,instanceId:null};pending=null;tempoPending=null;musicSource="0";musicReadback=null;readId=""; + const state=snapshot(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(track); + const insert=state?.graph?.channels?.find(ch=>ch.id===id)?.inserts?.[slot]; + if(native()&&state?.admitted&&insert?.catalogId===ID&&insert.id){ + current.instanceId=insert.id;draft=defaults();accepted=defaults(); + hint(""); + }else if(!native()){draft=defaults();accepted=defaults(); + hint("Browser preview only · no PCM");} + else hint("Native FX instance unavailable"); + $("vtChannel").textContent=track.name||"CH"; + panel.hidden=false;paint();refreshMusicChannels();requestSnapshot(true); + }, + close(){panel.hidden=true;} +}); +backend()?.addEventListener?.("arMixBuiltinThrowTempoAck",reply=>{ + if(!tempoPending||reply?.requestId!==tempoPending.requestId)return; + if(reply.status==="APPLIED"){ + musicSource=tempoPending.source; + hint(""); + }else hint("Tempo source rejected · "+(reply.errorCode||"STALE")); + tempoPending=null;refreshMusicChannels();renderMusicStatus(); + requestSnapshot(true); +}); +backend()?.addEventListener?.("arMixBuiltinThrowQueue",reply=>{ + if(!pending||reply?.requestId!==pending.requestId)return; + if(reply.status==="REJECTED"){hint("DSP rejected · "+(reply.errorCode||"STALE")); + pending=null;requestSnapshot(true);syncPower();} +}); +backend()?.addEventListener?.("arMixBuiltinThrowAck",reply=>{ + if(!pending||reply?.requestId!==pending.requestId)return; + if(reply.status!=="APPLIED"){hint("DSP rejected · "+(reply.errorCode||"UNKNOWN")); + pending=null;requestSnapshot(true);syncPower();return;} + if(pending.command==="nativeThrowTrigger"){hint(""); + pending=null;requestSnapshot(true);syncPower();} + else{pending.ack=true;requestSnapshot(true);} +}); +backend()?.addEventListener?.("arMixBuiltinThrowSnapshot",reply=>{ + if(panel.hidden||reply?.requestId!==readId)return; + readId="";readSent=0; + const ctx=context(); + if(!ctx||reply.status!=="ACCEPTED"||reply.channelId!==ctx.channelId|| + reply.instanceId!==ctx.instanceId||reply.deviceEpoch!==ctx.deviceEpoch|| + reply.graphRevision!==ctx.graphRevision||!valid(reply.settings)|| + reply.addedLatencySamples!==0){hint("Stale FX graph · reopen editor");return;} + if(reply.musicSourceChannelId!==undefined) { + musicSource=String(reply.musicSourceChannelId||"0"); + refreshMusicChannels();renderMusicStatus(reply); + } + $("vtCount").textContent=String(reply.throwCount||0); + $("vtCount").setAttribute("aria-label",String(reply.throwCount||0)+" completed throws"); + $("vtDot").classList.toggle("active",reply.tailActive===true); + $("vtBeatRail").dataset.playing=String(reply.tailActive===true); + $("vtThrow").dataset.tail=String(reply.tailActive===true); + $("vtStatus").textContent=reply.tailActive?"TAIL":"LIVE"; + if(pending){ + if(!pending.ack||reply.appliedRequestId!==pending.requestId)return; + accepted={...reply.settings};draft={...accepted};pending=null; + hint(""); + }else{accepted={...reply.settings};draft={...accepted};} + paint(); +}); +backend()?.addEventListener?.("arMixConsoleSnapshot",()=>{ + if(panel.hidden)return; + if(native()&&!context()){ + pending=null;tempoPending=null; + hint("FX graph changed · reopen"); + } + refreshMusicChannels();syncPower(); +}); +window.setInterval(()=>{ + if(panel.hidden)return; + if(pending&&Date.now()-pending.created>3500){hint("DSP ACK timeout");pending=null;} + if(tempoPending&&Date.now()-tempoPending.created>3500){ + hint("Tempo source ACK timeout");tempoPending=null;refreshMusicChannels(); + } + if(native())requestSnapshot(); + syncPower(); +},250); +})(); diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 0d35127a4..c01398153 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -14,6 +14,7 @@ #include "../engine/builtin_fx/ChannelEqProcessor.h" #include "../engine/builtin_fx/ChannelCompressorProcessor.h" #include "../engine/builtin_fx/ChannelHarmonyProcessor.h" +#include "../engine/builtin_fx/VocalThrowProcessor.h" #include "DiagnosticTone.h" #include "../engine/device/JuceIndependentClockDevice.h" #include "../engine/device/LiveSecondaryOutputDevice.h" @@ -1912,6 +1913,65 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback } } + // ArSon Vocal Throw: single native PCM graph, same insert leases, bypass, + // ChannelId topology and dry monitoring as EQ/Compressor. + LiveDryRoutingLab::NativeBusResult installNativeBuiltInVocalThrow( + std::uint64_t ep,std::uint64_t pcmRevision, + std::uint64_t rosterRevision,armix::mixer::ChannelId id) { + LiveDryRoutingLab::NativeBusResult fail{}; + fail.error="NATIVE_THROW_HOST_UNAVAILABLE"; + auto* device=deviceManager_.getCurrentAudioDevice(); + if(independent_.active()||!attached_||!device|| + !directFence_.permitted()||secondaryOutput_.armed()|| + handoff_.busy()||fxMovePhase_.load(std::memory_order_acquire)!=0|| + routeReconfiguring_.load(std::memory_order_acquire)|| + diagnosticRoute_.load(std::memory_order_acquire)!= + armix::diagnostics::Route::normal)return fail; + if(ep!=dryRoutingLab_.epoch()){ + fail.error="NATIVE_THROW_DEVICE_CHANGED";return fail; + } + const auto rate=device->getCurrentSampleRate(); + const int frames=juce::jmax(32,device->getCurrentBufferSizeSamples()); + if(!(rate>=8000.&&rate<=192000.)|| + frames>LiveDryRoutingLab::Block::hardFrameLimit) { + fail.error="NATIVE_THROW_UNSUPPORTED_AUDIO_FORMAT";return fail; + } + try { + auto processor=std::make_unique(); + processor->prepareToPlay(rate,frames); + if(!processor->isReady()){ + fail.error="NATIVE_THROW_PREPARE_REJECTED";return fail; + } + auto lease=std::make_shared< + armix::mixer::LiveChannelFxGraph::FxInstance>( + std::move(processor), + juce::String(armix::builtin_fx::VocalThrowProcessor::catalogIdentity), + "ArSon Vocal Throw",LiveDryRoutingLab::Block::hardFrameLimit); + return dryRoutingLab_.attachNativeInsert(ep,pcmRevision, + rosterRevision,id, + armix::builtin_fx::VocalThrowProcessor::catalogIdentity, + std::move(lease),true); + } catch(...) { + fail.error="NATIVE_THROW_PREPARE_EXCEPTION";return fail; + } + } + + bool selectNativeMusicTempoSource(std::uint64_t epoch,std::uint64_t revision, + armix::mixer::ChannelId musicChannel) noexcept { + auto* device=deviceManager_.getCurrentAudioDevice(); + if(!device||independent_.active()||!attached_||!directFence_.permitted()) + return false; + return dryRoutingLab_.selectMusicTempoSource(epoch,revision, + musicChannel,device->getCurrentSampleRate()); + } + armix::mixer::NativeMusicTempoMonitor::State pollNativeMusicTempo() noexcept { + return dryRoutingLab_.pollMusicTempo(); + } + template + void forEachNativeProcessor(Callback&& visit) const { + dryRoutingLab_.forEachNativeProcessor(std::forward(visit)); + } + // User-owned VST3 on a true dynamic ChannelId. Instantiation/scan/layout // work is CONTROL only; the callback receives an immutable fx lease. LiveDryRoutingLab::NativeBusResult installNativeVst3( diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index f404be1a4..08a706816 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -5,6 +5,7 @@ #include "../engine/core/MasterOutputMonoPolicy.h" #include "../engine/core/LiveChannelFxGraph.h" #include "../engine/core/DynamicChannelFxLeaseBank.h" +#include "../engine/core/NativeMusicTempoMonitor.h" #include "../engine/device/DeviceSessionTransitionPolicy.h" #include "../engine/core/NativeFxRackTransaction.h" #include "../engine/core/UnifiedLegacyProductionAdmission.h" @@ -1389,6 +1390,32 @@ class LiveDryRoutingLab final { return nativeAccepted_.setFxBypass(nativePublisher_,epochAtEdit, pcmRevision,target,slot,token,bypass); } + // Native music onset analysis has no secondary audio callback. A source + // selector is admitted only against the ACTIVE epoch/revision graph. + bool selectMusicTempoSource(std::uint64_t ep,std::uint64_t rev, + armix::mixer::ChannelId source,double sampleRate) noexcept { + if(!channelIdPhysicalPcmActive()||ep!=epoch()|| + rev!=nativeAccepted_.pcmRevision)return false; + return nativePublisher_.setMusicTempoSource(ep,rev,source,sampleRate); + } + armix::mixer::NativeMusicTempoMonitor::State pollMusicTempo() noexcept { + const auto ep=channelIdPhysicalPcmActive()?epoch():0; + return nativePublisher_.pollMusicTempo(ep,nativeAccepted_.pcmRevision); + } + // CONTROL traversal of the *published* insert owners. No audio-thread + // graph search or raw unmanaged pointers survive this synchronous call. + template + void forEachNativeProcessor(Callback&& visit) const { + if(!channelIdPhysicalPcmActive()||!nativeAccepted_.fxOwners)return; + for(const auto& ch:nativeAccepted_.graph.roster.channels()) { + const auto count=nativeAccepted_.fxOwners->insertCount(ch.id); + for(std::size_t slot=0;slotownerForControl(ch.id,slot); + if(owner && *owner && (*owner)->processor) + visit(ch.id,(*owner)->processor.get()); + } + } + } bool nativeChannelIsOriginalCh1(armix::mixer::ChannelId target) const noexcept { return nativeAccepted_.fxOwners && nativeAccepted_.fxOwners->externalChannel()==target && diff --git a/src/Main.cpp b/src/Main.cpp index e7b88e1a8..6abffa599 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -409,6 +409,14 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } pendingNativeHarmony_; juce::String lastNativeHarmonyRequest_,lastNativeHarmonyInstance_; juce::String lastNativeHarmonyEpoch_,lastNativeHarmonyRevision_; + struct PendingNativeThrow { + armix::mixer::LiveChannelFxGraph::InstanceLease owner; + juce::String request,channelId,deviceEpoch,revision,instanceId; + juce::uint32 started=0; + } pendingNativeThrow_; + juce::String lastNativeThrowRequest_,lastNativeThrowInstance_; + juce::String lastNativeThrowEpoch_,lastNativeThrowRevision_; + armix::mixer::NativeMusicTempoMonitor::State lastMusicTempo_{}; std::unique_ptr editorWindow_; std::unique_ptr audioSetupWindow_; juce::String startupError_, lastAudioXml_; @@ -1092,9 +1100,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity; const bool builtInHarmony=catalogId== armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity; - const auto* plugin=(builtInEq||builtInComp||builtInHarmony)?nullptr:catalog_.find(catalogId); + const bool builtInThrow=catalogId== + armix::builtin_fx::VocalThrowProcessor::catalogIdentity; + const auto* plugin=(builtInEq||builtInComp||builtInHarmony||builtInThrow)?nullptr:catalog_.find(catalogId); std::uint64_t ep=0,rev=0,roster=0,target=0; - if((!builtInEq&&!builtInComp&&!builtInHarmony&&!plugin)||catalog_.busy()||nativeShowBusy_|| + if((!builtInEq&&!builtInComp&&!builtInHarmony&&!builtInThrow&&!plugin)||catalog_.busy()||nativeShowBusy_|| studioBackupBusy_||engine_.isGraphSwitchPending()) { nativeError="NATIVE_VST3_CATALOG_OR_HOST_BUSY"; } else if(!armix::console::approvedNativeId( @@ -1116,6 +1126,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr builtInHarmony? engine_.installNativeBuiltInHarmony( ep,rev,roster,armix::mixer::ChannelId{target}): + builtInThrow? + engine_.installNativeBuiltInVocalThrow( + ep,rev,roster,armix::mixer::ChannelId{target}): engine_.installNativeVst3( ep,rev,roster,armix::mixer::ChannelId{target}, plugin->path,plugin->uid,plugin->key()); @@ -2129,6 +2142,143 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr "arMixBuiltinHarmonyAck",juce::var(ack.release())); } + // CONTROL ONLY: drain at most 512 ten-ms music summary frames per 12Hz + // host tick. The actual music audio was tapped inside the existing PCM + // graph; BPM/onset analysis never touches the ASIO callback. All live + // vocal inserts consume a precomputed atomic interval, not a WebView BPM. + void serviceNativeMusicTempo() { + lastMusicTempo_=engine_.pollNativeMusicTempo(); + const bool bpmLocked=lastMusicTempo_.active&& + lastMusicTempo_.tempo.locked; + const bool phaseLocked=bpmLocked&& + lastMusicTempo_.tempo.phaseLocked&& + lastMusicTempo_.tempo.beatAnchorFrame>0; + const float bpm=bpmLocked?lastMusicTempo_.tempo.bpm:0.f; + const std::uint64_t anchor=phaseLocked? + lastMusicTempo_.tempo.beatAnchorFrame:0; + const auto epoch=lastMusicTempo_.epoch; + const auto revision=lastMusicTempo_.revision; + engine_.forEachNativeProcessor([bpm,anchor,epoch,revision]( + armix::mixer::ChannelId,juce::AudioProcessor* p) { + if(auto* vocal=dynamic_cast(p)) + vocal->publishMusicGrid(bpm,anchor,epoch,revision); + }); + } + + // Native Vocal Throw settings, manual cue and auto-trigger readback. + // Settings and triggers are not accepted until the AUDIO-owned SPSC + // completion is drained on JUCE's message thread. + void emitNativeThrowSnapshot(const juce::String& request, + const juce::String& channelId,const juce::String& epoch, + const juce::String& revision,const juce::String& instanceId, + armix::builtin_fx::VocalThrowProcessor* processor) { + auto reply=std::make_unique(); + reply->setProperty("requestId",request); + reply->setProperty("channelId",channelId); + reply->setProperty("deviceEpoch",epoch); + reply->setProperty("graphRevision",revision); + reply->setProperty("instanceId",instanceId); + reply->setProperty("schemaVersion",1); + reply->setProperty("status",processor?"ACCEPTED":"REJECTED"); + if(processor) { + auto settings=std::make_unique(); + const auto s=processor->acceptedSettings(); + settings->setProperty("mode",s.mode); + settings->setProperty("bpm",s.bpm); + settings->setProperty("division",s.division); + settings->setProperty("repeats",s.repeats); + settings->setProperty("captureMs",s.captureMs); + settings->setProperty("silenceMs",s.silenceMs); + settings->setProperty("thresholdDb",s.thresholdDb); + settings->setProperty("wet",s.wet); + settings->setProperty("decay",s.decay); + settings->setProperty("ducking",s.ducking); + reply->setProperty("settings",juce::var(settings.release())); + reply->setProperty("sampleRate",processor->acceptedSampleRate()); + // MUSIC tempo belongs to Vocal Throw, not to the unrelated EQ. + // Fence every displayed source/beat to THIS accepted graph. + // A retired device may leave a last control-timer snapshot; it + // must never appear as a locked beat on a newly opened device. + const bool currentMusicGraph=lastMusicTempo_.active&& + epoch==juce::String(std::to_string(lastMusicTempo_.epoch))&& + revision==juce::String(std::to_string(lastMusicTempo_.revision)); + reply->setProperty("musicSourceChannelId", + currentMusicGraph? + juce::String(std::to_string(lastMusicTempo_.source.value)): + juce::String("0")); + reply->setProperty("musicSourceActive",currentMusicGraph); + reply->setProperty("musicLocked",currentMusicGraph&& + lastMusicTempo_.tempo.locked); + reply->setProperty("musicBpm", + currentMusicGraph&&lastMusicTempo_.tempo.locked? + lastMusicTempo_.tempo.bpm:0.f); + reply->setProperty("musicConfidence", + currentMusicGraph?lastMusicTempo_.tempo.confidence:0.f); + reply->setProperty("musicGridAvailable",currentMusicGraph&& + lastMusicTempo_.tempo.locked&& + lastMusicTempo_.tempo.phaseLocked); + reply->setProperty("musicPhaseConfidence", + currentMusicGraph?lastMusicTempo_.tempo.phaseConfidence:0.f); + reply->setProperty("musicBeatAnchorFrame",juce::String( + std::to_string(currentMusicGraph? + lastMusicTempo_.tempo.beatAnchorFrame:0))); + reply->setProperty("musicDroppedFrames",currentMusicGraph? + static_cast(lastMusicTempo_.dropped):0); + + reply->setProperty("throwCount",static_cast(processor->observedThrowCount())); + reply->setProperty("tailActive",processor->observedTailActive()); + reply->setProperty("addedLatencySamples",processor->getLatencySamples()); + if(instanceId==lastNativeThrowInstance_&& + epoch==lastNativeThrowEpoch_&&revision==lastNativeThrowRevision_) + reply->setProperty("appliedRequestId",lastNativeThrowRequest_); + } else reply->setProperty("error","NATIVE_THROW_INSTANCE_OR_REVISION_UNAVAILABLE"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowSnapshot",juce::var(reply.release())); + } + + void servicePendingNativeThrow() { + if(!pendingNativeThrow_.owner)return; + auto* processor=dynamic_cast( + pendingNativeThrow_.owner->processor.get()); + if(!processor){pendingNativeThrow_={};return;} + armix::builtin_fx::VocalThrowProcessor::Completion completion{}; + if(!processor->pollCompletion(completion)&& + juce::Time::getMillisecondCounter()-pendingNativeThrow_.started<3000u) + return; + const auto request=pendingNativeThrow_.request; + bool applied=completion.applied&&completion.requestId!=0&& + request=="throw-"+juce::String(std::to_string(completion.requestId)); + const auto snap=approvedNativeSnapshot(); + const auto device=snap.getProperty("device",{}); + const auto graph=snap.getProperty("graph",{}); + applied=applied&&pendingNativeThrow_.deviceEpoch== + device.getProperty("epoch","").toString()&& + pendingNativeThrow_.revision== + graph.getProperty("revision","").toString(); + if(applied) { + lastNativeThrowRequest_=request; + lastNativeThrowInstance_=pendingNativeThrow_.instanceId; + lastNativeThrowEpoch_=pendingNativeThrow_.deviceEpoch; + lastNativeThrowRevision_=pendingNativeThrow_.revision; + } + auto ack=std::make_unique(); + ack->setProperty("requestId",request); + ack->setProperty("channelId",pendingNativeThrow_.channelId); + ack->setProperty("deviceEpoch",pendingNativeThrow_.deviceEpoch); + ack->setProperty("graphRevision",pendingNativeThrow_.revision); + ack->setProperty("instanceId",pendingNativeThrow_.instanceId); + ack->setProperty("status",applied?"APPLIED":"REJECTED"); + ack->setProperty("command",completion.kind== + armix::builtin_fx::VocalThrowProcessor::CommandKind::trigger? + "TRIGGER":"SETTINGS"); + ack->setProperty("errorCode",applied?"NONE": + completion.kind==armix::builtin_fx::VocalThrowProcessor::CommandKind::trigger? + "NO_CAPTURE_OR_STALE_GRAPH":"DSP_EDIT_NOT_APPLIED_OR_STALE"); + pendingNativeThrow_={}; + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowAck",juce::var(ack.release())); + } + // Never confuse durable logical ChannelId state with a physical device // authorization. This message-thread report is status only, not PCM. void emitMixerSessionAck(const juce::String& operation, @@ -2149,7 +2299,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr for(auto& insert:doc.inserts) { if(insert.catalogId==armix::builtin_fx::ChannelEqProcessor::catalogIdentity || insert.catalogId==armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity || - insert.catalogId==armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity) { + insert.catalogId==armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity || + insert.catalogId==armix::builtin_fx::VocalThrowProcessor::catalogIdentity) { if(insert.path.isNotEmpty() || insert.uid!=0) return "Saved built-in FX identity was modified"; continue; @@ -2592,7 +2743,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr action == "routingNativeFxRackBypass" || action == "routingNativeFxInsertBypass" || action == "routingFxRackBypass" || - action == "nativeEqSetBand" || action == "nativeCompSet")) + action == "nativeEqSetBand" || action == "nativeCompSet" || + action == "nativeThrowSet" || action == "nativeThrowTrigger" || + action == "nativeThrowTempoSource")) { const auto reason=juce::String( "Studio backup in progress. Finish backup before editing saved FX or VST library."); @@ -2929,6 +3082,115 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr return; } + // ArSon Vocal Throw: all UI commands reference one exact installed + // ChannelId + device epoch + graph revision + insert instance. + if(action=="nativeThrowSnapshot"||action=="nativeThrowSet"|| + action=="nativeThrowTrigger"||action=="nativeThrowTempoSource") { + const auto rawChannel=args.getProperty("channelId",{}); + const auto rawEpoch=args.getProperty("deviceEpoch",{}); + const auto rawRevision=args.getProperty("graphRevision",{}); + const auto rawInstance=args.getProperty("instanceId",{}); + const auto request=args.getProperty("requestId",{}).toString(); + const int throwSlot=static_cast(args.getProperty("slot",-1)); + std::uint64_t ch=0,ep=0,rev=0; + const bool valid=armix::console::approvedNativeId(rawChannel,ch)&& + armix::console::approvedNativeId(rawEpoch,ep)&& + armix::console::approvedNativeId(rawRevision,rev)&& + rawInstance.isString()&&rawInstance.toString().isNotEmpty()&& + throwSlot>=0&&throwSlot(throwSlot), + rawInstance.toString()): + armix::mixer::LiveChannelFxGraph::InstanceLease{}; + auto* processor=owner?dynamic_cast( + owner->processor.get()):nullptr; + if(action=="nativeThrowSnapshot") { + emitNativeThrowSnapshot(request,rawChannel.toString(), + rawEpoch.toString(),rawRevision.toString(), + rawInstance.toString(),processor); + return; + } + if(action=="nativeThrowTempoSource") { + // A single shared song clock is selected by stable ChannelId; + // the source cannot be this vocal channel, MAIN or MONITOR. + const auto rawSource=args.getProperty("sourceChannelId",{}); + const auto sourceText=rawSource.toString(); + std::uint64_t source=0; + const bool parsed=sourceText=="0" || + armix::console::approvedNativeId(rawSource,source); + const bool chosen=processor && parsed && (!source||source!=ch) && + !nativeShowBusy_&&!studioBackupBusy_ && + engine_.selectNativeMusicTempoSource( + ep,rev,armix::mixer::ChannelId{source}); + if(chosen)serviceNativeMusicTempo(); + auto reply=std::make_unique(); + reply->setProperty("requestId",request); + reply->setProperty("status",chosen?"APPLIED":"REJECTED"); + reply->setProperty("sourceChannelId",sourceText); + reply->setProperty("errorCode",chosen?"NONE": + "INVALID_OR_STALE_MUSIC_CHANNEL"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowTempoAck",juce::var(reply.release())); + return; + } + const auto wire=request.startsWith("throw-")? + request.substring(6).toStdString():std::string(); + std::uint64_t numeric=0; + if(!wire.empty()&&wire.size()<=19&& + wire.find_first_not_of("0123456789")==std::string::npos) { + try{numeric=std::stoull(wire);}catch(...){numeric=0;} + } + const bool isSettings=action=="nativeThrowSet"; + const auto values=args.getProperty("settings",{}); + armix::builtin_fx::VocalThrowSettings settings{}; + auto read=[&values](const char* key,float& out) { + const auto value=values.getProperty(key,{}); + if(!value.isInt()&&!value.isDouble())return false; + const auto v=static_cast(value); + if(!std::isfinite(v))return false; + out=static_cast(v); + return std::isfinite(out); + }; + auto integer=[&read](const char* key,int& out) { + float candidate=0.f; + if(!read(key,candidate)||candidate!=std::floor(candidate)|| + candidate<0.f||candidate>1000.f)return false; + out=static_cast(candidate);return true; + }; + const bool settingsValid=!isSettings || (values.isObject()&& + integer("mode",settings.mode)&&read("bpm",settings.bpm)&& + integer("division",settings.division)&&integer("repeats",settings.repeats)&& + read("captureMs",settings.captureMs)&&read("silenceMs",settings.silenceMs)&& + read("thresholdDb",settings.thresholdDb)&&read("wet",settings.wet)&& + read("decay",settings.decay)&&read("ducking",settings.ducking)&& + armix::builtin_fx::VocalThrow::validSettings(settings)); + bool queued=false; + if(processor&&numeric>0&&settingsValid&&!pendingNativeThrow_.owner&& + !nativeShowBusy_&&!studioBackupBusy_&&!engine_.independentClockActive()) { + queued=isSettings?processor->queueSettings(settings,numeric): + processor->queueTrigger(numeric); + if(queued) { + pendingNativeThrow_.owner=owner; + pendingNativeThrow_.request=request; + pendingNativeThrow_.channelId=rawChannel.toString(); + pendingNativeThrow_.deviceEpoch=rawEpoch.toString(); + pendingNativeThrow_.revision=rawRevision.toString(); + pendingNativeThrow_.instanceId=rawInstance.toString(); + pendingNativeThrow_.started=juce::Time::getMillisecondCounter(); + } + } + auto ack=std::make_unique(); + ack->setProperty("requestId",request); + ack->setProperty("status",queued?"QUEUED":"REJECTED"); + ack->setProperty("errorCode",queued?"NONE": + pendingNativeThrow_.owner?"THROW_CONTROL_BUSY": + "INVALID_OR_STALE_NATIVE_THROW"); + if(browser_.loaded)browser_.emitEventIfBrowserIsVisible( + "arMixBuiltinThrowQueue",juce::var(ack.release())); + return; + } + // Route the approved channel FX picker to the SAME prepared M4 // graph as physical IN/OUT. ID resolves exclusively in the JUCE // catalog; browser paths/names are never trusted as plugin identity. @@ -4822,9 +5084,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr guiPerf_.prevTickMs = tickStart; } ++timerTicks_; + serviceNativeMusicTempo(); servicePendingNativeEq(); servicePendingNativeComp(); servicePendingNativeHarmony(); + servicePendingNativeThrow(); // A hidden JUCE/WebView2 peer may defer first navigation. Expose the // compositor behind the opaque startup splash after the first tick; // the user sees the completed mixer only after the ready handshake. diff --git a/src/NativeMixerSessionFxRestore.h b/src/NativeMixerSessionFxRestore.h index 6fccac16f..c86211b53 100644 --- a/src/NativeMixerSessionFxRestore.h +++ b/src/NativeMixerSessionFxRestore.h @@ -6,6 +6,7 @@ #include "../engine/builtin_fx/ChannelEqProcessor.h" #include "../engine/builtin_fx/ChannelCompressorProcessor.h" #include "../engine/builtin_fx/ChannelHarmonyProcessor.h" +#include "../engine/builtin_fx/VocalThrowProcessor.h" #include #include #include @@ -95,6 +96,16 @@ class NativeMixerSessionFxRestore final { state.bytes.getData(),static_cast(state.bytes.getSize()))) return "Saved native Harmony state rejected; graph unchanged"; processor=std::move(harmony); + } else if(insert.catalogId== + armix::builtin_fx::VocalThrowProcessor::catalogIdentity) { + auto throwFx=std::make_unique(); + throwFx->prepareToPlay(sampleRate,frames); + if(!throwFx->isReady()|| + !throwFx->restoreUnpublishedState( + state.bytes.getData(), + static_cast(state.bytes.getSize()))) + return "Saved native Vocal Throw state rejected; graph unchanged"; + processor=std::move(throwFx); } else { if(!format|| !format->fileMightContainThisPluginType(insert.path)) @@ -116,7 +127,9 @@ class NativeMixerSessionFxRestore final { insert.catalogId!= armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity && insert.catalogId!= - armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity) + armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity && + insert.catalogId!= + armix::builtin_fx::VocalThrowProcessor::catalogIdentity) processor->setStateInformation(state.bytes.getData(), static_cast(state.bytes.getSize())); const int latency=processor->getLatencySamples(); diff --git a/tests/approved_native_vocal_throw_smoke.py b/tests/approved_native_vocal_throw_smoke.py new file mode 100644 index 000000000..4d35568f4 --- /dev/null +++ b/tests/approved_native_vocal_throw_smoke.py @@ -0,0 +1,310 @@ +"""Real approved /preview/ bundle: ArSon Vocal Throw picker, insert, native ACK. +The JUCE event transport is emulated, NOT the native DSP nor singing quality. +DSP is independently tested in standalone CTest on Windows.""" +import copy +import importlib.util +from pathlib import Path +import tempfile +from playwright.sync_api import sync_playwright +from approved_native_wire_gain_smoke import snapshot, emit, ack, SOURCE, RECEIVER + +ROOT=Path(__file__).resolve().parents[1] +ID="armix.builtin.vocal-throw.v1" +INSTANCE="vocal-throw-test-instance" +DEFAULTS={"mode":2,"bpm":120,"division":0,"repeats":3, + "captureMs":460,"silenceMs":220,"thresholdDb":-35, + "wet":.42,"decay":.55,"ducking":.7} + +def last(page,action): + records=page.evaluate("name=>window.__actions.filter(x=>x.action===name)",action) + assert records, "No "+action+" event" + return records[-1] + +def reply_snapshot(page,state,settings,applied=None,count=0,tail=False,music=None): + act=last(page,"nativeThrowSnapshot") + data={"requestId":act["requestId"],"channelId":SOURCE,"slot":0, + "instanceId":INSTANCE,"status":"ACCEPTED","schemaVersion":1, + "deviceEpoch":state["device"]["epoch"], + "graphRevision":state["graph"]["revision"],"sampleRate":48000, + "addedLatencySamples":0,"throwCount":count,"tailActive":tail, + "musicSourceChannelId":music["source"] if music else "0", + "musicSourceActive":bool(music), + "musicLocked":bool(music), + "musicBpm":music["bpm"] if music else 0, + "musicConfidence":music["confidence"] if music else 0, + "musicGridAvailable":music.get("grid",False) if music else False, + "musicPhaseConfidence":music["confidence"] if music and music.get("grid",False) else 0, + "settings":copy.deepcopy(settings)} + if applied:data["appliedRequestId"]=applied + emit(page,"arMixBuiltinThrowSnapshot",data) + +def main(): + spec=importlib.util.spec_from_file_location( + "bundle",ROOT/"scripts/build_approved_native_gui.py") + bundle=importlib.util.module_from_spec(spec);spec.loader.exec_module(bundle) + source_svg=(ROOT/"site/preview-v2/assets/arson-vocal-throw-performance.svg").read_text() + assert "data:image/webp;base64," in source_svg, "original user Illustrator icon must be embedded" + assert 'clip-path="url(#aiLens)"' in source_svg + assert 'M128 29 L120 43' not in source_svg, "no 4-way navigation markers on THROW" + with tempfile.TemporaryDirectory(prefix="armix-throw-") as directory,sync_playwright() as pw: + out=Path(directory);bundle.stage(out) + browser=pw.chromium.launch(headless=True) + for width,height in [(1366,768),(390,844)]: + page=browser.new_page(viewport={"width":width,"height":height}) + errors=[] + page.on("pageerror",lambda e:errors.append(str(e))) + page.add_init_script("""window.__nativeListeners=new Map(); + window.__nativeIntents=[];window.__actions=[]; + window.__JUCE__={backend:{ + emitEvent(name,payload){ + if(name==='arMixConsoleIntent')window.__nativeIntents.push(payload); + if(name==='arMixAction')window.__actions.push(payload);}, + addEventListener(name,callback){ + const old=window.__nativeListeners.get(name); + window.__nativeListeners.set(name,old? + payload=>{old(payload);callback(payload);}:callback);}}};""") + page.goto((out/"index.html").as_uri()) + page.wait_for_function("()=>window.__ARMIX_NATIVE_M2__?.enabled && window.ArSonMixNativeVocalThrow") + state=snapshot() + state["graph"]["capabilities"]["supportedOps"]+=["LOAD_INSERT","REMOVE_INSERT","MOVE_INSERT"] + emit(page,"arMixConsoleSnapshot",state) + if width<=500:page.locator("#bankSelect").select_option("0") + strip=page.locator('#tracks .strip[data-id="1"]') + strip.locator('.fx-pick.empty').first.click() + picker=page.locator("#fastResults [data-fast-native-throw]") + picker.wait_for(state="visible") + assert picker.count()==1,"exactly one Vocal Throw built-in picker option" + picker.click() + intents=page.evaluate("""()=>window.__nativeIntents.filter( + x=>x.operation==='LOAD_INSERT')""") + assert len(intents)==1,intents + assert intents[0]["payload"]["catalogId"]==ID + assert page.locator("#mxNativeVocalThrow").is_hidden(),"no editor before accepted insert" + state["graph"].update(revision="3",rosterRevision="3") + state["graph"]["channels"][0]["fxRackBypassed"]=False + state["graph"]["channels"][0]["inserts"].append({ + "id":INSTANCE,"catalogId":ID,"name":"ArSon Vocal Throw","bypassed":False}) + state["mixerSession"].update(routeRevision="3",rosterRevision="3", + channels=copy.deepcopy(state["graph"]["channels"])) + ack(page,state,intents[0]);emit(page,"arMixConsoleSnapshot",state) + row=strip.locator('.fxslot-row[data-insert-id="'+INSTANCE+'"]') + row.wait_for(state="visible") + page.keyboard.press("Escape") + row.locator('[data-action="openPlugin"]').click() + editor=page.locator("#mxNativeVocalThrow") + editor.wait_for(state="visible") + assert editor.locator("#vtPreset").count()==1 + assert editor.locator("#vtClose.mx-comp-close.armix-floating-close").count()==1 + assert editor.locator("#vtPower.mx-comp-power.armix-builtin-fx-power").count()==1 + assert editor.locator("#vtClose.armix-builtin-fx-close").count()==1 + assert page.locator("#mxNativePeq .armix-builtin-fx-power").count()==1 + assert page.locator("#mxNativePeq .armix-builtin-fx-close").count()==1 + assert page.locator("#mxNativeComp .armix-builtin-fx-power").count()==1 + assert page.locator("#mxNativeComp .armix-builtin-fx-close").count()==1 + assert editor.locator("#vtPower").get_attribute("data-fx-state")=="on" + assert editor.locator("#vtPower").get_attribute("aria-pressed")=="true" + # EQ and Compressor have ONE CSS owner for 24px Close and 26px + # Power hit boxes, the same as Vocal Throw (no local overrides). + close_box=editor.locator("#vtClose").bounding_box() + power_box=editor.locator("#vtPower").bounding_box() + assert close_box and power_box + assert abs(close_box["width"]-24)<.1 and abs(close_box["height"]-24)<.1 + assert abs(power_box["width"]-26)<.1 and abs(power_box["height"]-24)<.1 + assert power_box["x"]+power_box["width"]<=close_box["x"]+1 + assert editor.locator("#vtMode").input_value()=="2" + initial=last(page,"nativeThrowSnapshot") + page.wait_for_timeout(300) + assert last(page,"nativeThrowSnapshot")["requestId"]==initial["requestId"],\ + "snapshot polling overwrote outstanding request too early" + reply_snapshot(page,state,DEFAULTS) + assert editor.locator("#vtStatus").inner_text()=="LIVE" + assert editor.locator("#vtCount").inner_text()=="0" + box=editor.bounding_box() + assert box and box["width"]<=778 and box["width"]<=width and \ + box["x"]>=0 and box["x"]+box["width"]<=width+1,(width,box) + assert editor.evaluate("(el)=>el.scrollWidth<=el.clientWidth+1"),\ + "premium FX editor overflows horizontal viewport" + assert editor.locator("#vtDisplayBpm").inner_text()=="120" + assert editor.locator("#vtClockLabel").inner_text()=="MAN" + # BPM is one integrated LCD number, not a detached duplicate. + # Click the LCD to enter editing; Escape restores the accepted + # native setting without issuing a new DSP command. + assert editor.locator("#vtBpm").is_hidden() + editor.locator("#vtDisplayBpm").click() + assert editor.locator("#vtBpm").is_visible() + assert editor.locator("#vtBpm").input_value()=="120" + editor.locator("#vtBpm").fill("133") + editor.locator("#vtBpm").press("Escape") + assert editor.locator("#vtBpm").is_hidden() + assert editor.locator("#vtDisplayBpm").inner_text()=="120" + assert editor.locator("#vtBeatRail i[data-on='true']").count()==3 + assert editor.locator(".vt-encoder-bank .vt-encoder-face").count()==6 + assert editor.locator("#vtWetDial[role='slider']").count()==1 + assert editor.locator(".vt-throw-button").count()==1 + trigger=editor.locator("#vtThrow") + assert trigger.get_attribute("aria-label")=="Throw captured vocal phrase" + assert trigger.inner_text().strip()=="","Singer cue has no noisy visible words" + tb=trigger.bounding_box() + assert tb and tb["width"]>=160 and tb["height"]>=160 + assert editor.locator(".vt-throw-engraving").inner_text()=="THROW" + assert editor.locator("#vtTap").is_visible() + assert editor.locator("#vtMusicStatus").inner_text()=="TAP" + assert "FIRE PHRASE" not in editor.inner_text() + assert "SMART PHRASE / LIVE ENGINE" not in editor.inner_text() + assert "ZERO DRY LATENCY" not in editor.inner_text() + assert editor.locator(".vt-mode-buttons button").count()==3 + assert editor.locator(".vt-division-buttons button").count()==4 + # No browser form hiding of basic parameters: real accessible + # hardware rotary controls are displayed at desktop AND mobile. + assert editor.locator("#vtWetDial").is_visible() + assert editor.locator('.vt-encoder[data-key="captureMs"] button').is_visible() + # Every control, including MIX, has the exact SAME stationary + # knob body, pointer and rounded level arc geometry. + assert editor.locator(".vt-encoder-face").count()==7 + assert editor.locator(".vt-meter-fill").count()==7 + assert editor.locator(".vt-knob-meter").count()==7 + for dial in editor.locator(".vt-encoder-face").all(): + bg=dial.evaluate("(el)=>getComputedStyle(el).backgroundImage") + assert "arson-vocal-hardware-encoder.svg" in bg,bg + assert dial.locator(".vt-meter-fill").get_attribute("pathLength")=="100" + # Inspect the actual rendered SVG control backgrounds. WebView + # file:// disables fetch() for SVG files, not CSS backgrounds. + for selector,name in [("#vtWetDial","encoder"), + ('.vt-encoder-face',"encoder"), + ("#vtThrow","performance")]: + bg=editor.locator(selector).first.evaluate( + "(el)=>getComputedStyle(el).backgroundImage") + assert ("arson-vocal-throw-performance.svg" if name=="performance" + else "arson-vocal-hardware-"+name+".svg") in bg,(selector,bg) + # Bounded physical layout QA, not just a screenshot. The large + # singer switch must be centered, the two encoder banks in + # alignment, and tempo LCD and TAP must be physically adjacent. + throw=editor.locator("#vtThrow").bounding_box() + left=editor.locator("#vtEncodersLeft").bounding_box() + right=editor.locator("#vtEncodersRight").bounding_box() + lcd=editor.locator(".vt-clock-screen").bounding_box() + tap=editor.locator("#vtTap").bounding_box() + assert all([throw,left,right,lcd,tap]) + assert abs((throw["x"]+throw["width"]/2)-(box["x"]+box["width"]/2))<4, \ + ("THROW is off center",width,throw,box) + if width>600: + assert abs(left["y"]-right["y"])<3, ("uneven encoder rows",left,right) + assert left["x"]+left["width"]<=throw["x"]+1 and \ + throw["x"]+throw["width"]<=right["x"]+1, \ + ("encoders invade singer button",left,throw,right) + else: + assert throw["y"]+throw["height"]=145 and lcd["height"]>=70 + rail=editor.locator(".vt-status-rail").bounding_box() + assert rail and rail["y"]+rail["height"]<=box["y"]+box["height"]+2, \ + ("footer clipped beneath mobile controls",width,rail,box) + # No control may draw past the horizontal plugin bounds. + for control in ["#vtThrow","#vtTap","#vtWetDial", + "#vtClockLabel","#vtDisplayBpm"]: + rect=editor.locator(control).bounding_box() + assert rect and rect["x"]>=box["x"]-1 and \ + rect["x"]+rect["width"]<=box["x"]+box["width"]+1,(control,rect,box) + page.screenshot(path="arsonmix-vocal-throw-"+str(width)+".png") + editor.screenshot(path="arsonmix-vocal-throw-editor-"+str(width)+".png") + if width==1366: + editor.locator('.vt-mode-buttons button[data-mode="0"]').click() + edit=last(page,"nativeThrowSet") + assert edit["settings"]["mode"]==0 and edit["instanceId"]==INSTANCE + assert edit["channelId"]==SOURCE + emit(page,"arMixBuiltinThrowQueue",{"requestId":edit["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":edit["requestId"],"status":"APPLIED"}) + reply_snapshot(page,state,{**DEFAULTS,"mode":0},applied=edit["requestId"]) + assert editor.locator("#vtMode").input_value()=="0" + assert editor.locator('.vt-mode-buttons button[data-mode="0"]').get_attribute("aria-pressed")=="true" + # Rotary wheel edits actually send settings through the native + # request/ACK/readback contract, not a CSS-only animation. + dial=editor.locator("#vtWetDial") + before=dial.evaluate("""el=>({ + offset:parseFloat(getComputedStyle(el.querySelector('.vt-meter-fill')).strokeDashoffset), + transform:getComputedStyle(el.querySelector('.vt-encoder-needle')).transform, + bg:getComputedStyle(el).backgroundImage + })""") + dial.hover() + page.mouse.wheel(0,-120) + after=dial.evaluate("""el=>({ + offset:parseFloat(getComputedStyle(el.querySelector('.vt-meter-fill')).strokeDashoffset), + transform:getComputedStyle(el.querySelector('.vt-encoder-needle')).transform, + bg:getComputedStyle(el).backgroundImage + })""") + assert float(after["offset"]).42 and rotary["settings"]["wet"]<=.44 + emit(page,"arMixBuiltinThrowQueue",{"requestId":rotary["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":rotary["requestId"],"status":"APPLIED"}) + updated={**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} + reply_snapshot(page,state,updated,applied=rotary["requestId"]) + assert "%" in editor.locator("#vtWetValue").inner_text() + editor.locator("#vtThrow").click() + assert editor.locator("#vtThrow").is_disabled(), "no repeated stage cue until native ACK" + cue=last(page,"nativeThrowTrigger") + assert cue["instanceId"]==INSTANCE and cue["channelId"]==SOURCE + assert cue["slot"]==0 + emit(page,"arMixBuiltinThrowQueue",{"requestId":cue["requestId"],"status":"QUEUED"}) + emit(page,"arMixBuiltinThrowAck",{"requestId":cue["requestId"],"status":"APPLIED"}) + reply_snapshot(page,state,{**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]},count=1,tail=True) + assert editor.locator("#vtCount").inner_text()=="1" + assert editor.locator("#vtStatus").inner_text()=="TAIL" + assert editor.locator("#vtThrow").get_attribute("data-tail")=="true" + assert not editor.locator("#vtThrow").is_disabled() + # Real native tempo-source command (not a browser-only BPM guess). + source_menu=editor.locator("#vtMusicSource") + assert source_menu.locator('option[value="'+RECEIVER+'"]').count()==1 + source_menu.select_option(RECEIVER) + request=last(page,"nativeThrowTempoSource") + assert request["sourceChannelId"]==RECEIVER and request["channelId"]==SOURCE + assert editor.locator("#vtMusicStatus").inner_text()=="CONNECT" + emit(page,"arMixBuiltinThrowTempoAck",{ + "requestId":request["requestId"],"status":"APPLIED", + "sourceChannelId":RECEIVER}) + reply_snapshot(page,state, + {**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} if width==1366 else DEFAULTS, + count=1 if width==1366 else 0,tail=width==1366, + music={"source":RECEIVER,"bpm":120,"confidence":.85}) + assert editor.locator("#vtMusicStatus").inner_text()=="120 · BPM" + assert editor.locator("#vtClockLabel").inner_text()=="AUTO" + # Snapshot transport is request/response, not unsolicited push. + # Wait for a fresh native read request before testing a second + # DSP status update; a replay of the prior request is ignored. + previous=last(page,"nativeThrowSnapshot")["requestId"] + page.wait_for_function( + """old=>window.__actions.filter(x=>x.action==='nativeThrowSnapshot').at(-1)?.requestId!==old""", + arg=previous,timeout=4000) + # Confidence-approved grid is a separate native fact; the GUI + # must never fabricate it from BPM alone. + reply_snapshot(page,state, + {**DEFAULTS,"mode":0,"wet":rotary["settings"]["wet"]} if width==1366 else DEFAULTS, + count=1 if width==1366 else 0,tail=width==1366, + music={"source":RECEIVER,"bpm":120,"confidence":.85,"grid":True}) + assert editor.locator("#vtMusicStatus").inner_text()=="120 · GRID" + assert editor.locator("#vtClockLabel").inner_text()=="LOCK" + if width==1366: + # The next changed graph invalidates the old editor instance. + state["graph"]["channels"][0]["inserts"][0]["id"]="replaced-instance" + state["graph"].update(revision="4",rosterRevision="4") + state["mixerSession"].update(routeRevision="4",rosterRevision="4", + channels=copy.deepcopy(state["graph"]["channels"])) + emit(page,"arMixConsoleSnapshot",state) + page.wait_for_function("""()=>document.querySelector('#vtThrow')?.disabled""",timeout=2000) + editor.locator("#vtClose").click() + assert editor.is_hidden(),"standard close must dismiss editor" + assert not errors,(width,errors) + page.close() + browser.close() + print("PASS: ArSon Vocal Throw native picker/ACK/manual cue/compact editor in 2 viewports") + +if __name__=="__main__": + main() diff --git a/tests/builtin_vocal_throw_test.cpp b/tests/builtin_vocal_throw_test.cpp new file mode 100644 index 000000000..30f125715 --- /dev/null +++ b/tests/builtin_vocal_throw_test.cpp @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/builtin_fx/VocalThrow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#define check(x) do {if(!(x)){std::fprintf(stderr,"FAIL:%s:%d %s\n",__FILE__,__LINE__,#x);std::abort();}}while(false) +// Catch allocations from inside the audio callback, not from preparation. +static std::atomic noHeap{false}; +void* operator new(std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void* operator new[](std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept{std::free(p);} +void operator delete[](void* p) noexcept{std::free(p);} +void operator delete(void* p,std::size_t) noexcept{std::free(p);} +void operator delete[](void* p,std::size_t) noexcept{std::free(p);} + +using armix::builtin_fx::VocalThrow; +using armix::builtin_fx::VocalThrowSettings; +static void run(VocalThrow& fx,float l,float r,int frames,float& maxL,float& maxR) { + std::array left{},right{}; + for(int begin=0;begin(n)); + noHeap.store(false,std::memory_order_release); + for(int i=0;i::quiet_NaN(); + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.mode=3; + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.repeats=7; + check(!VocalThrow::prepareEdit(settings,48000,packet)); + settings=VocalThrowSettings{};settings.captureMs=1550; + check(!VocalThrow::prepareEdit(settings,48000,packet)); +} +static void manualAndDry(double rate) { + VocalThrow fx;check(fx.prepare(rate)); + auto s=fx.settingsForTests();s.mode=0;s.captureMs=300;s.silenceMs=150; + check(fx.resetUnpublished(s)); + float peakL=0,peakR=0; + // No trigger: the leading vocalist is bit-exact dry, even in an insert. + std::array left{},right{}; + left.fill(.35f);right.fill(-.20f); + noHeap.store(true); + fx.processStereo(left.data(),right.data(),left.size()); + noHeap.store(false); + for(std::size_t n=0;n(rate*.35),peakL,peakR); + run(fx,0,0,static_cast(rate*.06),peakL,peakR); + check(fx.throwCount()==0); + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired&&fx.throwCount()==1); + peakL=peakR=0; + run(fx,0,0,static_cast(rate*.10),peakL,peakR); + check(peakL==0&&peakR==0); // beat-scheduled, no immediate echo smear + run(fx,0,0,static_cast(rate*.75),peakL,peakR); + check(peakL>.01f&&peakR>.005f); + // Recorded stereo is preserved (same gain on both channels). + check(peakL>peakR*1.4f); + noHeap.store(true); + const bool staleCue=fx.throwNow(); + noHeap.store(false); + check(!staleCue); // 700ms after last vocal: never report an empty throw +} +static void automaticAndHybrid(double rate) { + VocalThrow fx;check(fx.prepare(rate)); + auto s=fx.settingsForTests(); + s.mode=1;s.captureMs=220;s.silenceMs=120;s.thresholdDb=-30; + check(fx.resetUnpublished(s)); + float l=0,r=0; + run(fx,.5f,.35f,static_cast(rate*.3),l,r); + run(fx,0,0,static_cast(rate*.23),l,r); + check(fx.throwCount()==1); + run(fx,0,0,static_cast(rate*1.0),l,r); + check(fx.throwCount()==1); // no retrigger on the echoed tail + run(fx,.5f,.35f,static_cast(rate*.28),l,r); + run(fx,0,0,static_cast(rate*.23),l,r); + check(fx.throwCount()==2); + +} +static void hybridEditAndNoHeap() { + VocalThrow fx;check(fx.prepare(48000)); + VocalThrowSettings s{};s.mode=2;s.bpm=95;s.division=1;s.repeats=6; + VocalThrow::PreparedEdit edit{};check(VocalThrow::prepareEdit(s,48000,edit)); + check(!fx.applyPrepared(VocalThrow::PreparedEdit{})); + auto stale=edit;stale.sampleRate=44100;check(!fx.applyPrepared(stale)); + noHeap.store(true);const bool ok=fx.applyPrepared(edit);noHeap.store(false); + check(ok); + float l=0,r=0; + run(fx,.4f,.2f,10000,l,r); + noHeap.store(true);const bool fired=fx.throwNow();noHeap.store(false); + check(fired); + run(fx,0,0,200000,l,r); + check(std::isfinite(l)&&std::isfinite(r)); +} +// Two separate frozen phrases must coexist. A new cue must not chop the +// already sounding repeat. All fixtures run as bounded PCM chunks without +// any callback allocations, including at the highest allowed device rate. +static void twoTailsStayLive(double rate) { + VocalThrow reference,overlap; + check(reference.prepare(rate)&&overlap.prepare(rate)); + auto s=reference.settingsForTests(); + s.mode=0;s.bpm=200;s.division=1;s.repeats=3; + s.captureMs=300;s.silenceMs=120; + check(reference.resetUnpublished(s)&&overlap.resetUnpublished(s)); + float l=0.f,r=0.f; + auto both=[&](float input,int frames) { + run(reference,input,input*.5f,frames,l,r); + run(overlap,input,input*.5f,frames,l,r); + }; + both(.5f,static_cast(rate*.20)); + both(0.f,static_cast(rate*.10)); + noHeap.store(true); + const bool firstA=reference.throwNow(),firstB=overlap.throwNow(); + noHeap.store(false); + check(firstA&&firstB); + both(.4f,static_cast(rate*.12)); + both(0.f,static_cast(rate*.03)); + noHeap.store(true); + const bool second=overlap.throwNow(); + const bool saturated=overlap.throwNow(); + noHeap.store(false); + check(second&&!saturated); + check(overlap.throwCount()==2); + // From 0.45 to 0.485 s the second voice is preparing, and its first + // scheduled echo is still in the future. Output must be IDENTICAL to + // the reference's first tail, not abruptly muted by the second cue. + std::array refL{},refR{},mixL{},mixR{}; + float maxReference=0.f,maxOverlap=0.f; + const int compareFrames=static_cast(rate*.035); + for(int done=0;done(std::min(128,compareFrames-done)); + refL.fill(0.f);refR.fill(0.f);mixL.fill(0.f);mixR.fill(0.f); + noHeap.store(true); + reference.processStereo(refL.data(),refR.data(),count); + overlap.processStereo(mixL.data(),mixR.data(),count); + noHeap.store(false); + for(std::size_t i=0;i.001f&&maxOverlap>.001f); + run(overlap,0.f,0.f,static_cast(rate*.8),l,r); + check(overlap.throwCount()==2); +} +static void autoThenManualMustNotDoubleEcho() { + VocalThrow fx;check(fx.prepare(48000)); + auto s=fx.settingsForTests(); + s.mode=2;s.silenceMs=120;s.captureMs=250; + check(fx.resetUnpublished(s)); + float l=0.f,r=0.f; + run(fx,.5f,.25f,14400,l,r); + run(fx,0.f,0.f,12000,l,r); + check(fx.throwCount()==1); + noHeap.store(true); + const bool duplicated=fx.throwNow(); + noHeap.store(false); + check(!duplicated&&fx.throwCount()==1); + // A fresh phrase re-arms the manual path: previous auto trigger must + // not poison legitimate new cues when the singer starts again. + run(fx,.5f,.25f,12000,l,r); + noHeap.store(true); + const bool newPhrase=fx.throwNow(); + noHeap.store(false); + check(newPhrase&&fx.throwCount()==2); +} +static void denseRepeatsStayBounded() { + VocalThrow fx;check(fx.prepare(48000)); + auto settings=fx.settingsForTests(); + settings.mode=0;settings.bpm=200;settings.division=1; + settings.repeats=6;settings.decay=.9f; + settings.captureMs=1200.f;settings.wet=1.f;settings.ducking=0.f; + check(fx.resetUnpublished(settings)); + float maxL=0.f,maxR=0.f; + run(fx,.75f,.6f,48000,maxL,maxR); + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired); + maxL=maxR=0.f; + run(fx,0.f,0.f,static_cast(48000*2.5),maxL,maxR); + check(maxL>.20f&&maxR>.10f); + // An exposed six-tap feedback-like burst must not produce >0dBFS + // solely because echo taps overlap (dry path is unchanged). + check(maxL<=.751f&&maxR<=.601f); +} +static void manualOverrideSuppressesAuto() { + VocalThrow fx;check(fx.prepare(48000)); + auto s=fx.settingsForTests(); + s.mode=2;s.silenceMs=160;s.captureMs=250; + check(fx.resetUnpublished(s)); + float l=0.f,r=0.f; + run(fx,.5f,.25f,12000,l,r); // phrase 1 + run(fx,0.f,0.f,2400,l,r); // manual cue before auto silence timeout + noHeap.store(true); + const bool fired=fx.throwNow(); + noHeap.store(false); + check(fired&&fx.throwCount()==1); + run(fx,0.f,0.f,12000,l,r); + check(fx.throwCount()==1); // same phrase must not double-fire + run(fx,.5f,.25f,12000,l,r); // genuinely new phrase + // The 18ms release envelope must fall below the voice gate BEFORE + // the 160ms silence threshold begins. 208ms total is insufficient + // with a sustained 0.5 peak and threshold -35dB. + run(fx,0.f,0.f,9000,l,r); + check(fx.throwCount()==1); // no premature false-positive throw + run(fx,0.f,0.f,5000,l,r); + check(fx.throwCount()==2); // new phrase, after full release + gate +} +// Accepted music BPM affects only new frozen tails, never retimes a tail +// already singing. An unlocked source must use persisted Manual/TAP BPM. +static void musicTempoChangesOnlyFutureTail() { + VocalThrow music,manual; + check(music.prepare(48000)&&manual.prepare(48000)); + auto s=music.settingsForTests(); + s.mode=0;s.bpm=120.f;s.division=0;s.repeats=1; + s.captureMs=120.f;s.wet=1.f;s.ducking=0.f; + check(music.resetUnpublished(s)&&manual.resetUnpublished(s)); + float a=0.f,b=0.f; + run(music,.6f,.4f,12000,a,b); + run(manual,.6f,.4f,12000,a,b); + run(music,0.f,0.f,2880,a,b); + run(manual,0.f,0.f,2880,a,b); + noHeap.store(true); + music.setMusicIntervalSamples(16000); // quarter-note at 180 BPM + const bool firedMusic=music.throwNow(); + const bool firedManual=manual.throwNow(); + // The selected backing bus can disappear immediately after the cue. + // Its already frozen tail must retain the accepted .25s repeat interval. + music.setMusicIntervalSamples(0); + noHeap.store(false); + check(firedMusic&&firedManual); + a=b=0.f; + run(music,0.f,0.f,12960,a,b); // 270 ms after cue + check(a==0.f&&b==0.f); + a=b=0.f; + run(music,0.f,0.f,8160,a,b); // repeat around 290-410 ms + check(a>.01f&&b>.01f); + a=b=0.f; + run(manual,0.f,0.f,17760,a,b); // manual .5s must still be silent + check(a==0.f&&b==0.f); + a=b=0.f; + run(manual,0.f,0.f,7680,a,b); + check(a>.01f&&b>.01f); +} +// M3 beat-phase regression. Vocal PCM remains zero-latency dry, while the +// first frozen echo is snapped to the accepted source beat lattice. Changing +// transport AFTER the cue never changes the frozen tail's scheduled onset. +static void nativeMusicBeatGridQuantization(int quantum) { + VocalThrow gridded,unquantized; + check(gridded.prepare(48000)&&unquantized.prepare(48000)); + auto settings=gridded.settingsForTests(); + settings.mode=0;settings.captureMs=120.f; + settings.repeats=1;settings.bpm=120.f; + settings.division=0;settings.wet=1.f;settings.ducking=0.f; + check(gridded.resetUnpublished(settings)); + check(unquantized.resetUnpublished(settings)); + float l=0.f,r=0.f; + run(gridded,.65f,.35f,12000,l,r); + run(unquantized,.65f,.35f,12000,l,r); + run(gridded,0.f,0.f,3000,l,r); + run(unquantized,0.f,0.f,3000,l,r); + // Both processors have local sample 15000. Music tempo is 180 BPM + // (16000 sample quarter) with an observed beat at graph frame 100. + gridded.setMusicBeatGrid(16000,100,15000,true); + noHeap.store(true,std::memory_order_release); + const auto snapped=gridded.throwNow(); + const auto plain=unquantized.throwNow(); + // Simulate late rejection of source / changed BPM immediately following + // the cue. The old grid snapshot must remain in this tail. + gridded.setMusicBeatGrid(10000,15000,15000,false); + noHeap.store(false,std::memory_order_release); + check(snapped&&plain); + const auto onset=[&](VocalThrow& fx) { + std::array ll{},rr{}; + for(int start=0;start<50000;start+=quantum) { + const int n=std::min(quantum,50000-start); + ll.fill(0.f);rr.fill(0.f); + noHeap.store(true,std::memory_order_release); + fx.processStereo(ll.data(),rr.data(),static_cast(n)); + noHeap.store(false,std::memory_order_release); + for(int k=0;k.0002f)return start+k; + } + } + return -1; + }; + // First native music grid point >= intended onset: frame 32100. + // Cue at graph frame 15000 => first wet sample around offset 17100. + const int quantized=onset(gridded); + const int fallback=onset(unquantized); + check(quantized>=17100&&quantized<17120); + check(fallback>=23980&&fallback<25000); // manual 120 BPM / quarter + check(quantized+5000 +#include +#include +#include +#include +#include +#include +#define check(x) do {if(!(x)){std::fprintf(stderr,"FAIL:%s:%d %s\n",__FILE__,__LINE__,#x);std::abort();}}while(false) +static std::atomic noHeap{false}; +void* operator new(std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void* operator new[](std::size_t n) { + if(noHeap.load(std::memory_order_relaxed))std::abort(); + if(void* p=std::malloc(n?n:1))return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept {std::free(p);} +void operator delete[](void* p) noexcept {std::free(p);} +void operator delete(void* p,std::size_t) noexcept {std::free(p);} +void operator delete[](void* p,std::size_t) noexcept {std::free(p);} +using armix::mixer::ChannelId; +using armix::mixer::NativeMusicTempoMonitor; +static void renderWindow(NativeMusicTempoMonitor& tap,int index,int period, + float beat=.7f,bool weakOffbeats=false, + std::uint64_t epoch=7,std::uint64_t revision=13) { + std::array l{},r{}; + const int pos=index%period; + const float level=pos==0?beat: + weakOffbeats&&pos==period/2?.07f:0.f; + l.fill(level);r.fill(level); + // A 10ms bucket is split across 64+36 ASIO callback frames at 10kHz. + noHeap.store(true,std::memory_order_release); + (void)tap.beginAudioBlock(epoch,64); + tap.capture(ChannelId{301},l.data(),r.data(),64,epoch,revision); + (void)tap.beginAudioBlock(epoch,36); + tap.capture(ChannelId{301},l.data()+64,r.data()+64,36,epoch,revision); + noHeap.store(false,std::memory_order_release); + if(index%8==0)(void)tap.poll(epoch,revision); // host timer, not RT +} +static void lockTempo(int bpm,bool hats=false) { + NativeMusicTempoMonitor tap; + check(!tap.select(ChannelId{301},7,13,0)); + check(tap.select(ChannelId{301},7,13,10000)); + auto state=tap.poll(7,13); + check(state.active&&state.source.value==301&&!state.tempo.locked); + const int period=static_cast(std::lround(6000.0/bpm)); + for(int n=0;n<1100;++n)renderWindow(tap,n,period,.75f,hats); + state=tap.poll(7,13); + check(state.tempo.locked); + check(std::abs(state.tempo.bpm-bpm)<=3.1f); + check(state.tempo.confidence>=.28f); + // Sparse pair scoring uses only qualifying BPM neighborhoods instead + // of 121 complete rescans. This is a deterministic, hardware-neutral + // CONTROL timer budget, NOT a wall-clock benchmark. + check(state.tempo.scoringComparisons>0); + check(state.tempo.scoringComparisons<120000); + check(state.tempo.phaseLocked && state.tempo.phaseConfidence>=.50f); + check(state.tempo.beatAnchorTick>0); + check(state.tempo.beatAnchorFrame>0); + check(state.tempo.observationFrame>state.tempo.beatAnchorFrame); + check(state.dropped==0); + // One second of no music must NOT produce spurious half/double BPM. + for(int n=1100;n<1200;++n)renderWindow(tap,n,6000); + state=tap.poll(7,13); + check(state.tempo.locked); + // The user must see manual/TAP fallback after >3.2s of silence. + for(int n=1200;n<1580;++n)renderWindow(tap,n,6000); + state=tap.poll(7,13); + check(!state.tempo.locked); +} +// A full backing groove can carry snare/hi-hat accents on the eighth-note +// offbeat. Its BPM may be correct while a quarter-note phase is ambiguous. +static void harmonicAndPhaseAmbiguity() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + const auto groove=[&](int index,float offbeat) { + std::array left{},right{}; + const int p=index%50; // quarter note at 120 BPM + const float value=p==0?.78f:p==25?offbeat:0.f; + left.fill(value);right.fill(value); + noHeap.store(true,std::memory_order_release); + (void)tap.beginAudioBlock(7,64); + tap.capture(ChannelId{301},left.data(),right.data(),64,7,13); + (void)tap.beginAudioBlock(7,36); + tap.capture(ChannelId{301},left.data()+64,right.data()+64,36,7,13); + noHeap.store(false,std::memory_order_release); + if(index%8==0)(void)tap.poll(7,13); + }; + for(int i=0;i<1150;++i)groove(i,.035f); + auto baseline=tap.poll(7,13); + check(baseline.tempo.locked && std::abs(baseline.tempo.bpm-120.f)<=3.f); + check(baseline.tempo.phaseLocked); + // For 11s, the equal-strength offbeat pulse could be mistaken for a + // new beat lattice; do not switch to 60 BPM, or claim a phase lock. + for(int i=1150;i<2450;++i)groove(i,.78f); + auto ambiguous=tap.poll(7,13); + check(ambiguous.tempo.locked); + check(ambiguous.tempo.scoringComparisons>0); + check(ambiguous.tempo.scoringComparisons<120000); + check(std::abs(ambiguous.tempo.bpm-120.f)<=3.f); + check(!ambiguous.tempo.phaseLocked); + // The music clears; the true quarter-note lattice should recover. + for(int i=2450;i<3650;++i)groove(i,.035f); + auto recovered=tap.poll(7,13); + check(recovered.tempo.locked); + check(recovered.tempo.scoringComparisons>0); + check(recovered.tempo.scoringComparisons<120000); + check(std::abs(recovered.tempo.bpm-120.f)<=3.f); + check(recovered.tempo.phaseLocked); + check(recovered.dropped==0); +} +// A formerly locked backing can switch to densely accented but weak +// percussion. This is enough rhythmic activity to score a candidate, yet +// NOT enough evidence to keep the old beat grid or invent a new one. +static void weakBusyGrooveMustReleaseBeatGrid() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + for(int n=0;n<1100;++n)renderWindow(tap,n,50,.78f); + auto locked=tap.poll(7,13); + check(locked.tempo.locked&&locked.tempo.phaseLocked); + for(int n=1100;n<2350;++n)renderWindow(tap,n,8,.10f); + const auto ambiguous=tap.poll(7,13); + check(ambiguous.active); + check(!ambiguous.tempo.locked && !ambiguous.tempo.phaseLocked); + check(ambiguous.tempo.confidence<.28f); + check(ambiguous.dropped==0); + // Once clear music returns the phase can be acquired again. + for(int n=2350;n<3550;++n)renderWindow(tap,n,50,.78f); + const auto recovered=tap.poll(7,13); + check(recovered.tempo.locked && + std::abs(recovered.tempo.bpm-120.f)<=3.f); + check(recovered.tempo.phaseLocked); +} +static void steadyPadIsNotAClock() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + std::array pcm{};pcm.fill(.22f); + for(int index=0;index<1200;++index) { + noHeap.store(true); + (void)tap.beginAudioBlock(7,100); + tap.capture(ChannelId{301},pcm.data(),pcm.data(),100,7,13); + noHeap.store(false); + if(index%8==0)(void)tap.poll(7,13); + } + const auto state=tap.poll(7,13); + check(!state.tempo.locked); + // A sustained pad is not evidence of rhythm. It cannot trigger a + // high-cost candidate scan simply because PCM keeps arriving. + check(state.tempo.scoringComparisons==0); +} +static void failClosed() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,48000)); + std::array pcm{};pcm.fill(.8f); + noHeap.store(true); + for(int i=0;i<240;++i) { + // Wrong channel and wrong graph revision must not populate the FIFO. + tap.capture(ChannelId{302},pcm.data(),pcm.data(),128,7,13); + tap.capture(ChannelId{301},pcm.data(),pcm.data(),128,7,14); + } + noHeap.store(false); + auto stale=tap.poll(7,14); + check(!stale.active&&!stale.tempo.locked); + auto active=tap.poll(7,13); + check(active.active&&!active.tempo.locked); + check(tap.select(ChannelId{},7,13,0)); + check(!tap.poll(7,13).active); +} +static void actualGraphSourcePcm() { + using namespace armix::mixer; + DynamicChannelRoster roster; + ChannelEdit source,main; + source.kind=ChannelEdit::Kind::add;source.position=0; + source.role=ChannelRole::input;source.text="BACKING"; + main.kind=ChannelEdit::Kind::add;main.position=1; + main.role=ChannelRole::main;main.text="MAIN"; + main.format=ProcessingFormat::stereo; + const std::array adds{source,main}; + const auto created=roster.edit(0,adds); + check(created.ok()&&created.createdIds.size()==2); + const auto music=created.createdIds[0],master=created.createdIds[1]; + ChannelEdit output; + output.kind=ChannelEdit::Kind::setPrimaryOutput; + output.id=music;output.target=master; + const std::array links{output}; + check(roster.edit(1,links).ok()); + DynamicGraphRequest request; + request.physicalInputs=1;request.maxFrames=128; + request.sources={{music,0,-1,false}}; + DynamicNativeSessionPublisher graph; + constexpr std::uint64_t epoch=7; + const auto applied=graph.commit(roster,request,0,epoch,epoch,true); + check(applied.ok()&&applied.revision==1); + check(!graph.setMusicTempoSource(epoch,1,master,10000)); // MAIN forbidden + check(!graph.setMusicTempoSource(epoch-1,1,music,10000)); + check(graph.setMusicTempoSource(epoch,1,music,10000)); + std::array input{},outL{},outR{}; + const float* physical[]{input.data()}; + int expectedTick=0; + const auto dryFx=[&](ChannelId,float*,float*,int n) noexcept { + const auto current=NativeBeatFrameScope::current(); + check(current.valid && current.epoch==epoch && + current.revision==1 && n==100); + check(current.startFrame==static_cast(expectedTick)*100); + }; + for(int tick=0;tick<1000;++tick) { + input.fill((tick%50)==0?.65f:0.f); // 120 BPM from real graph + noHeap.store(true,std::memory_order_release); + expectedTick=tick; + const bool rendered=graph.render(epoch,physical,1, + outL.data(),outR.data(),100,false,dryFx); + noHeap.store(false,std::memory_order_release); + check(rendered); + if(tick%8==0)(void)graph.pollMusicTempo(epoch,1); + } + auto state=graph.pollMusicTempo(epoch,1); + check(state.active&&state.source==music); + check(state.tempo.locked&&std::abs(state.tempo.bpm-120.f)<=3.f); + check(state.tempo.phaseLocked&&state.tempo.phaseConfidence>=.50f); + check(state.tempo.beatAnchorFrame>0 && + state.tempo.beatAnchorFrame<=100000); + check(state.tempo.observationFrame>=state.tempo.beatAnchorFrame); + check(!NativeBeatFrameScope::current().valid); // callback scope restored + // The *same* music ChannelId survives a graph revision with no second + // callback or preserved stale PCM pointers. + const auto newer=graph.commit(roster,request,1,epoch,epoch,true); + check(newer.ok()&&newer.revision==2); + state=graph.pollMusicTempo(epoch,2); + check(state.active&&state.source==music); + check(!graph.pollMusicTempo(epoch,1).active); + const auto newGraphFx=[&](ChannelId,float*,float*,int n) noexcept { + const auto block=NativeBeatFrameScope::current(); + check(block.valid && block.epoch==epoch && + block.revision==2 && block.startFrame==100000 && n==100); + }; + noHeap.store(true,std::memory_order_release); + const bool next=graph.render(epoch,physical,1, + outL.data(),outR.data(),100,false,newGraphFx); + noHeap.store(false,std::memory_order_release); + check(next); + check(!NativeBeatFrameScope::current().valid); + graph.unpublish(); + graph.pollRetirement(); +} +static void callbackClockEpochAndNestedScope() { + using armix::mixer::NativeBeatFrameScope; + NativeMusicTempoMonitor tap; + check(!NativeBeatFrameScope::current().valid); + noHeap.store(true,std::memory_order_release); + check(tap.beginAudioBlock(82,64)==0); + check(tap.beginAudioBlock(82,128)==64); + { + NativeBeatFrameScope outer{82,7,192}; + const auto a=NativeBeatFrameScope::current(); + check(a.valid&&a.epoch==82&&a.revision==7&&a.startFrame==192); + { + NativeBeatFrameScope nested{82,8,320}; + const auto b=NativeBeatFrameScope::current(); + check(b.valid&&b.revision==8&&b.startFrame==320); + } + const auto restored=NativeBeatFrameScope::current(); + check(restored.valid&&restored.revision==7&&restored.startFrame==192); + } + check(!NativeBeatFrameScope::current().valid); + check(tap.beginAudioBlock(82,256)==192); + // Physical device restart must establish a NEW sample origin. This + // prevents a beat from the old ASIO epoch appearing on the new device. + check(tap.beginAudioBlock(83,64)==0); + check(tap.beginAudioBlock(83,128)==64); + noHeap.store(false,std::memory_order_release); +} +int main() { + lockTempo(72); + lockTempo(95); + lockTempo(120); + lockTempo(160); + lockTempo(120,true); + harmonicAndPhaseAmbiguity(); + weakBusyGrooveMustReleaseBeatGrid(); + steadyPadIsNotAClock(); + failClosed(); + callbackClockEpochAndNestedScope(); + actualGraphSourcePcm(); + std::puts("PASS: native music-channel BPM 72/95/120/160, silence holdover, stale graph, no RT heap"); +} diff --git a/tests/native_peq_assembly_test.py b/tests/native_peq_assembly_test.py index 890d798f1..069bd4889 100644 --- a/tests/native_peq_assembly_test.py +++ b/tests/native_peq_assembly_test.py @@ -24,6 +24,9 @@ def test_one_authoritative_mixer(self): self.assertEqual(self.assembled.count('src="assets/mixer-native-peq.js?v=eq-graph1"'),1) self.assertEqual(self.assembled.count('src="assets/mixer-native-compressor.js?v=comp-1"'),1) self.assertEqual(self.assembled.count("function insertChosenNativeCompressor(){"),1) + self.assertEqual(self.assembled.count("function insertChosenNativeThrow(){"),1) + self.assertEqual(self.assembled.count('src="assets/mixer-native-vocal-throw.js?v=throw-1"'),1) + self.assertEqual(self.assembled.count('data-fast-native-throw="1"'),1) def test_native_rack_uses_regular_insert_slot(self): self.assertIn("host.insert(activeFxTarget)",self.assembled) @@ -35,6 +38,7 @@ def test_native_rack_uses_regular_insert_slot(self): self.assertEqual(self.assembled.count('data-fast-native-eq="1"'),1) self.assertEqual(self.assembled.count('data-fast-native-comp="1"'),1) self.assertIn("if(t.fx[index]==='Compressor')",self.assembled) + self.assertIn("if(t.fx[index]==='ArSon Vocal Throw')",self.assembled) def test_single_style_owner(self): # The approved CSS compiler requires exactly 18 component-owner links. @@ -54,6 +58,50 @@ def test_single_style_owner(self): self.assertIn('addedLatencySamples!==0',compressor) self.assertNotIn("new AudioContext",compressor) self.assertIn(".mx-comp[hidden]{display:none}",css) + throw=(ROOT/"site/preview-v2/assets/mixer-native-vocal-throw.js").read_text("utf-8") + self.assertIn("arMixBuiltinThrowAck",throw) + self.assertIn("arMixBuiltinThrowSnapshot",throw) + self.assertIn("nativeThrowTrigger",throw) + self.assertIn('id="vtPreset"',throw) + self.assertIn("armix-floating-close",throw) + self.assertNotIn("new AudioContext",throw) + + def test_native_tempo_readback_belongs_to_vocal_throw_not_eq(self): + # The real C++ dispatcher must populate the exact VocalThrow + # snapshot, not an unrelated EQ response. Browser-only mocks cannot + # catch a payload sent on the wrong native event. + main=(ROOT/"src/Main.cpp").read_text("utf-8") + def body(start,finish): + self.assertEqual(main.count(start),1) + return main.split(start,1)[1].split(finish,1)[0] + eq=body("void emitNativeEqSnapshot(", + "void servicePendingNativeEq()") + vocal=body("void emitNativeThrowSnapshot(", + "void servicePendingNativeThrow()") + fields=("musicSourceChannelId","musicSourceActive", + "musicLocked","musicBpm","musicConfidence", + "musicGridAvailable","musicPhaseConfidence", + "musicBeatAnchorFrame","musicDroppedFrames") + for field in fields: + self.assertIn('reply->setProperty("'+field+'"',vocal, + "missing accepted Vocal Throw BPM field: "+field) + self.assertNotIn('reply->setProperty("'+field+'"',eq, + "cross-FX snapshot pollution: "+field) + # After device restart or graph change the last control snapshot + # is stale. No stale source/phase can be advertised as locked. + self.assertIn("const bool currentMusicGraph=lastMusicTempo_.active",vocal) + self.assertIn("lastMusicTempo_.epoch",vocal) + self.assertIn("lastMusicTempo_.revision",vocal) + self.assertIn("currentMusicGraph&&",vocal) + self.assertIn("musicBpm",vocal) + self.assertIn('juce::String("0")',vocal) + self.assertIn('"arMixBuiltinThrowSnapshot"',vocal) + self.assertNotIn('"arMixBuiltinThrowSnapshot"',eq) + throw_js=(ROOT/"site/preview-v2/assets/mixer-native-vocal-throw.js").read_text("utf-8") + for field in ("musicLocked","musicBpm","musicGridAvailable", + "musicSourceChannelId"): + self.assertIn(field,throw_js) + self.assertNotIn("new AudioContext",throw_js) def test_fail_closed_on_repeat(self): with self.assertRaises(ValueError): diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index b202f8c60..2cf1b3c23 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -2739,6 +2739,8 @@ window.ArSonMixNativeCompressor?.open(t,slot); } else if(insert.catalogId==='armix.builtin.arson-harmony.v1') { window.ArSonMixNativeHarmony?.open(t,slot); + } else if(insert.catalogId==='armix.builtin.vocal-throw.v1') { + window.ArSonMixNativeVocalThrow?.open(t,slot); } else backend.emitEvent("arMixAction",{action:"routingFxEditor",channelId:id,slot, instanceId:insert.id,deviceEpoch:current.device.epoch,revision:current.graph.revision}); } else {discoverFxOnFirstPickerOpen();scope?.openFastPicker?.(t,slot,btn);} @@ -2936,7 +2938,8 @@ const plugin=nativeCatalog.get(id) || (id==='armix.builtin.channel-eq.v1'?{id,name:'Parametric EQ'}: id==='armix.builtin.channel-compressor.v1'?{id,name:'Compressor'}: - id==='armix.builtin.arson-harmony.v1'?{id,name:'ArSon Harmony'}:null); + id==='armix.builtin.arson-harmony.v1'?{id,name:'ArSon Harmony'}: + id==='armix.builtin.vocal-throw.v1'?{id,name:'ArSon Vocal Throw'}:null); const track=scope?.tracks?.find(x=>x.id===target?.channelId)|| (scope?.master?.id===target?.channelId?scope.master:null); const channel=m4Index(track),slot=Number(target?.slot); From 55168b2777c2a6dcfe24f2432bb4f02e89b63199 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:31:56 +0700 Subject: [PATCH 038/125] ci(harmony): targeted no-JUCE C++ DSP regression on draft PR changes --- .github/workflows/harmony-fast-dsp.yml | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/harmony-fast-dsp.yml diff --git a/.github/workflows/harmony-fast-dsp.yml b/.github/workflows/harmony-fast-dsp.yml new file mode 100644 index 000000000..3e793091e --- /dev/null +++ b/.github/workflows/harmony-fast-dsp.yml @@ -0,0 +1,31 @@ +name: Harmony native DSP fast verification +on: + pull_request: + types: [opened, reopened, synchronize] + paths: + - 'engine/builtin_fx/Harmony*.h' + - 'tests/harmony*.cpp' + - 'CMakeLists.txt' + - '.github/workflows/harmony-fast-dsp.yml' +permissions: + contents: read +concurrency: + group: harmony-fast-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + harmony-cpp: + name: Native DSP compile and PCM regression (Linux, no JUCE) + runs-on: ubuntu-latest + timeout-minutes: 7 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Build and run synchronous vocal fixture + run: | + g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_pitch_synchronous_test.cpp -o /tmp/arson-harmony-psola + /tmp/arson-harmony-psola + - name: Compile and run complete engine dry, pitch, stereo and graph-independent PCM fixtures + run: | + g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_dsp_test.cpp -o /tmp/arson-harmony-engine + /tmp/arson-harmony-engine From 1aaae66a85c20efca77f2ffa55564b37a7192ca0 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:32:58 +0700 Subject: [PATCH 039/125] fix(vocal-throw): revoke stale auto BPM lock when ASIO music PCM callback stalls --- engine/core/NativeMusicTempoMonitor.h | 28 ++++++++++++++++++++++-- tests/native_music_tempo_test.cpp | 31 +++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/engine/core/NativeMusicTempoMonitor.h b/engine/core/NativeMusicTempoMonitor.h index 7023de8ed..05f29fbe9 100644 --- a/engine/core/NativeMusicTempoMonitor.h +++ b/engine/core/NativeMusicTempoMonitor.h @@ -8,6 +8,7 @@ #include #include #include +#include // ArSon M2: source-specific music tempo observation inside the ONE installed // ChannelId renderer. AUDIO only summarizes its explicitly selected music @@ -336,15 +337,37 @@ class NativeMusicTempoMonitor final { } } // CONTROL: limited work per timer tick, never called from ASIO callback. - State poll(std::uint64_t liveEpoch,std::uint64_t liveRevision) noexcept { + State poll(std::uint64_t liveEpoch,std::uint64_t liveRevision, + std::uint64_t nowMs=0) noexcept { + // CONTROL only. The former tick-only timeout could hold the last + // beat/grid indefinitely when an ASIO callback stopped completely: + // no new 10ms frames meant the estimator clock could not expire. + // Monotonic wall time is never read from the realtime callback. + if(nowMs==0) + nowMs=static_cast( + std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count()); const auto generation=config_.load(std::memory_order_acquire); if(controlGeneration_!=generation) { controlGeneration_=generation;estimator_.reset(); + lastReceivedControlMs_=0; } Frame f{}; + bool sawCurrentFrame=false; for(int i=0;i<512 && frames_.pop(f);++i) - if(f.generation==generation) + if(f.generation==generation) { estimator_.ingest(f.energy,f.tick,f.frameEnd); + sawCurrentFrame=true; + } + if(sawCurrentFrame)lastReceivedControlMs_=nowMs; + else if(lastReceivedControlMs_ && nowMs>=lastReceivedControlMs_ && + nowMs-lastReceivedControlMs_>3500) { + // Keep the selected ChannelId, but never publish an obsolete + // BPM/phase lock after the audio stream freezes or is suspended. + // On resumed PCM the same source reacquires from fresh onsets. + estimator_.reset(); + lastReceivedControlMs_=0; + } State out{}; out.source.value=source_.load(std::memory_order_relaxed); out.epoch=epoch_.load(std::memory_order_relaxed); @@ -372,5 +395,6 @@ class NativeMusicTempoMonitor final { std::uint64_t audioTick_=0; std::uint64_t audioEpoch_=0,audioFrameClock_=0,blockStartFrame_=0; std::uint32_t controlGeneration_=0; // CONTROL only + std::uint64_t lastReceivedControlMs_=0; // CONTROL-only callback stall watchdog }; } // namespace armix::mixer diff --git a/tests/native_music_tempo_test.cpp b/tests/native_music_tempo_test.cpp index 08ed0d85b..2659db43b 100644 --- a/tests/native_music_tempo_test.cpp +++ b/tests/native_music_tempo_test.cpp @@ -28,7 +28,8 @@ using armix::mixer::ChannelId; using armix::mixer::NativeMusicTempoMonitor; static void renderWindow(NativeMusicTempoMonitor& tap,int index,int period, float beat=.7f,bool weakOffbeats=false, - std::uint64_t epoch=7,std::uint64_t revision=13) { + std::uint64_t epoch=7,std::uint64_t revision=13, + std::uint64_t controlNowMs=0) { std::array l{},r{}; const int pos=index%period; const float level=pos==0?beat: @@ -41,7 +42,7 @@ static void renderWindow(NativeMusicTempoMonitor& tap,int index,int period, (void)tap.beginAudioBlock(epoch,36); tap.capture(ChannelId{301},l.data()+64,r.data()+64,36,epoch,revision); noHeap.store(false,std::memory_order_release); - if(index%8==0)(void)tap.poll(epoch,revision); // host timer, not RT + if(index%8==0)(void)tap.poll(epoch,revision,controlNowMs); // host timer, not RT } static void lockTempo(int bpm,bool hats=false) { NativeMusicTempoMonitor tap; @@ -137,6 +138,31 @@ static void weakBusyGrooveMustReleaseBeatGrid() { std::abs(recovered.tempo.bpm-120.f)<=3.f); check(recovered.tempo.phaseLocked); } +// If the audio callback stops entirely (ASIO suspension/reconfiguration), + // tick-based expiry alone cannot advance: fail closed on CONTROL time. +static void stoppedAudioCallbackMustRevokeOldBeat() { + NativeMusicTempoMonitor tap; + check(tap.select(ChannelId{301},7,13,10000)); + for(int n=0;n<1100;++n) + renderWindow(tap,n,50,.75f,false,7,13,1000+static_cast(n)*10); + auto locked=tap.poll(7,13,12000); + check(locked.active && locked.tempo.locked && locked.tempo.phaseLocked); + // A short interruption must not cause a needless BPM reset. + const auto hold=tap.poll(7,13,14450); + check(hold.active && hold.tempo.locked); + // No render/capture calls at all for >3.5s: stale beat cannot survive. + const auto stale=tap.poll(7,13,15501); + check(stale.active && stale.source.value==301); + check(!stale.tempo.locked && !stale.tempo.phaseLocked); + check(stale.tempo.beatAnchorFrame==0 && stale.tempo.bpm==0.f); + // Resume the very same source; require fresh musical evidence. + for(int n=1100;n<2300;++n) + renderWindow(tap,n,50,.75f,false,7,13, + 15510+static_cast(n-1100)*10); + const auto recovered=tap.poll(7,13,27600); + check(recovered.active && recovered.tempo.locked); + check(recovered.tempo.phaseLocked && std::abs(recovered.tempo.bpm-120.f)<=3.f); +} static void steadyPadIsNotAClock() { NativeMusicTempoMonitor tap; check(tap.select(ChannelId{301},7,13,10000)); @@ -283,6 +309,7 @@ int main() { lockTempo(120,true); harmonicAndPhaseAmbiguity(); weakBusyGrooveMustReleaseBeatGrid(); + stoppedAudioCallbackMustRevokeOldBeat(); steadyPadIsNotAClock(); failClosed(); callbackClockEpochAndNestedScope(); From 0e9609e92cb0e1431ded113de31ff9e576da9843 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:32:59 +0700 Subject: [PATCH 040/125] fix(harmony): correct fractional window interpolation in native C++ compile --- engine/builtin_fx/HarmonyPitchSynchronous.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h index 01c323f80..9395ea1ca 100644 --- a/engine/builtin_fx/HarmonyPitchSynchronous.h +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -113,7 +113,7 @@ class PitchSynchronousVoice final { const float fractional=static_cast( age-static_cast(whole)); const auto index=(writeIndex+Capacity-whole)&(Capacity-1); - return input[index]*(1.f-fraction)+ + return input[index]*(1.f-fractional)+ input[(index+Capacity-1)&(Capacity-1)]*fractional; } std::array states_{}; From 94f768d2df9c56431d78d2044d5bc9229e2877ab Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Mon, 9 Nov 2026 20:41:18 +0700 Subject: [PATCH 041/125] feat(harmony): native WAV A/B renderer for lead, legacy, synchronous backing and Space listening QA --- .github/workflows/harmony-fast-dsp.yml | 4 + CMakeLists.txt | 3 + ..._NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md | 12 ++ engine/builtin_fx/HarmonyDsp.h | 10 +- tools/harmony_offline_ab.cpp | 183 ++++++++++++++++++ 5 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 tools/harmony_offline_ab.cpp diff --git a/.github/workflows/harmony-fast-dsp.yml b/.github/workflows/harmony-fast-dsp.yml index 3e793091e..282f7f97d 100644 --- a/.github/workflows/harmony-fast-dsp.yml +++ b/.github/workflows/harmony-fast-dsp.yml @@ -29,3 +29,7 @@ jobs: run: | g++ -std=c++20 -O2 -Wall -Wextra tests/harmony_dsp_test.cpp -o /tmp/arson-harmony-engine /tmp/arson-harmony-engine + - name: Compile and exercise native offline listening A/B renderer + run: | + g++ -std=c++20 -O2 -Wall -Wextra tools/harmony_offline_ab.cpp -o /tmp/arson-harmony-ab + /tmp/arson-harmony-ab --self-test diff --git a/CMakeLists.txt b/CMakeLists.txt index fd8bf6c58..85caeeafd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,9 @@ if(BUILD_TESTING) add_executable(ARMixFxStructuralHandoffTests tests/live_fx_structural_handoff_test.cpp) target_compile_features(ARMixFxStructuralHandoffTests PRIVATE cxx_std_20) add_test(NAME R0BStructuralFxAckAndControlThreadRetirement COMMAND ARMixFxStructuralHandoffTests) + add_executable(ARMixHarmonyOfflineAb tools/harmony_offline_ab.cpp) + target_compile_features(ARMixHarmonyOfflineAb PRIVATE cxx_std_20) + add_test(NAME NativeHarmonyOfflineDryAndABRenderHarness COMMAND ARMixHarmonyOfflineAb --self-test) add_executable(ARMixHarmonyPitchSyncTests tests/harmony_pitch_synchronous_test.cpp) target_compile_features(ARMixHarmonyPitchSyncTests PRIVATE cxx_std_20) add_test(NAME NativeHarmonyPitchSynchronousFormantCandidateAndBlockParity COMMAND ARMixHarmonyPitchSyncTests) diff --git a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md index 6f57fb189..aa64cb791 100644 --- a/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md +++ b/docs/ARSON_HARMONY_NATURAL_ENSEMBLE_ARCHITECTURE_20261109.md @@ -81,3 +81,15 @@ Audit found the audible 16ms fixed-grain playback still changes vowel phase at u - One 16,384-sample mono history already owned by Harmony; no new audio route, device, host, PDC, user control or UI. Per-voice candidate stores at most 8 active source windows, fixed-size. Peak searches are bounded to <1 source period and never read future input. - New original-harmonic source CTest checks up/down ratios, a low male period, high-rate registers and **exact 64/257 callback-partition PCM parity** at 48/96/192k. Existing native lead preservation and phase-safe music tests still apply. - **Crucial nonclaim:** harmonic synthetic tests do not establish a singer's natural vowel formants or consonant intelligibility. Positive peaks are not reliable epochs for all breathy, growled or multi-pitch vocals. Do not mark PR production-ready until real recorded-vocal spectral F1/F2/F3, fricative/phrase boundaries, loudness-matched blind A/B and worst-case ASIO xrun/latency testing. If an audible regression occurs, fall back to the previous grain implementation before release. + +## 2026-11-09 Native vocal A/B workstation milestone + +The same `HarmonyDsp::Engine` now exposes an **offline reference-only** switch to re-render the previous grain synthesis against the pitch-synchronous candidate; normal live devices always default to the candidate and no new GUI mode/schema/control packet is added. The separate `ARMixHarmonyOfflineAb` C++ CLI takes a licensed/consented **adult** voice excerpt in mono/stereo 16/24-bit PCM or 32-bit float RIFF WAV, 32–192 kHz, <=60 seconds: + +```sh +ARMixHarmonyOfflineAb dry-vocal.wav output-directory +``` + +Outputs `01_lead_reference.wav`, `02_legacy_grain_mix.wav`, `03_new_space_060.wav`, `04_new_backing_only.wav`, `05_new_mono_fold.wav`, `06_new_space_000.wav`, `07_new_space_100.wav`, and `metrics.json`. All cases are reset from identical input and Manual C major / three voices / Wet 45%, Pitch Tune OFF, Gain 0dB. Wet0 lead is compared sample-exact across candidates; backing stem is mathematical difference from that lead and rejects hard-clipped output. The tool runs offline only; no filesystem IO in the audio callback. Compile/run `--self-test` as a quick synthetic source integrity check. + +**Unmet acoustic gates:** actual consented singer recordings and blind A/B, F1/F2/F3/vowel envelope preservation, noisy consonants, source expression, physical Windows ASIO loopback and CPU/xrun timings. Do NOT use the synthetic self-test or unnormalized WAV comparison to claim a professional natural-sounding result. diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 37f4b4f9f..d56d93af8 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -102,6 +102,7 @@ class Engine final { pitchSync_.reset(); pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; + pitchSyncReferenceEnabled_=true; pitchSyncAlpha_=static_cast(1.-std::exp(-1./(rate*.012))); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); @@ -199,6 +200,12 @@ class Engine final { } const Settings& settings() const noexcept{return settings_;} int latencySamples() const noexcept{return latency_;} + // Offline A/B harness only: retain the exact legacy granular reference + // without introducing a user-facing mode or changing serialized FX state. + // Production instances always default to the pitch-synchronous candidate. + void setPitchSynchronousCandidateForOfflineReference(bool enabled) noexcept { + pitchSyncReferenceEnabled_=enabled; + } int observedMidiNote() const noexcept{return currentNote_;} bool voiced() const noexcept{return voiced_;} int peakPitchLagWork() const noexcept{return peakPitchLagWork_;} @@ -333,7 +340,7 @@ class Engine final { // overlap-add. The exact source period is measured, not inferred // from the harmony target. Uncertain/nonperiodic sounds retain the // previous validated granular shifter with a bounded 12ms crossfade. - const bool confident=voiced_&&sourceConfidence_>.82f&& + const bool confident=pitchSyncReferenceEnabled_&&voiced_&&sourceConfidence_>.82f&& sourcePeriodSamples_>=8.f; PitchSynchronousVoice::Output sync{}; if(confident) @@ -500,6 +507,7 @@ class Engine final { float wet_=0.f,targetWet_=0.f,color_=0.f,targetColor_=0.f; float sourcePeriodSamples_=0.f,sourceConfidence_=0.f,pitchSyncAlpha_=0.f; std::uint64_t sampleClock_=0; + bool pitchSyncReferenceEnabled_=true; std::array pitchSyncBlend_{},pitchSyncFiltered_{}; float space_=0.f,targetSpace_=0.f; float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; diff --git a/tools/harmony_offline_ab.cpp b/tools/harmony_offline_ab.cpp new file mode 100644 index 000000000..211e8f4d8 --- /dev/null +++ b/tools/harmony_offline_ab.cpp @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Offline native Harmony A/B: genuine adult vocal WAVs, no live callback IO. +// Synthesized self-test is only a build and integrity gate, not an ear-test. +#include "../engine/builtin_fx/HarmonyDsp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using armix::harmony::Engine; +using armix::harmony::Settings; +namespace fs=std::filesystem; +struct Wave {unsigned rate=0;std::vector left,right;}; +static std::uint16_t u16(const unsigned char* p){return std::uint16_t(p[0])|(std::uint16_t(p[1])<<8);} +static std::uint32_t u32(const unsigned char* p){return std::uint32_t(p[0])|(std::uint32_t(p[1])<<8)|(std::uint32_t(p[2])<<16)|(std::uint32_t(p[3])<<24);} +static void put16(std::ostream& out,std::uint16_t v){out.put(char(v&255));out.put(char((v>>8)&255));} +static void put32(std::ostream& out,std::uint32_t v){for(int k=0;k<4;++k)out.put(char((v>>(8*k))&255));} +static Wave readWave(const fs::path& file){ + if(!fs::exists(file)||fs::file_size(file)>220000000)throw std::runtime_error("WAV missing/too large"); + std::ifstream stream(file,std::ios::binary); + if(!stream)throw std::runtime_error("WAV open failed"); + const std::vector bytes((std::istreambuf_iterator(stream)),{}); + if(bytes.size()<44||std::memcmp(bytes.data(),"RIFF",4)!=0|| + std::memcmp(bytes.data()+8,"WAVE",4)!=0) + throw std::runtime_error("expected RIFF/WAVE"); + std::uint16_t fmt=0,ch=0,bits=0,align=0;std::uint32_t hz=0; + std::size_t offset=12,dataStart=0,dataBytes=0; + while(offset+8<=bytes.size()){ + const auto size=static_cast(u32(bytes.data()+offset+4)); + const auto start=offset+8; + if(size>bytes.size()-start)throw std::runtime_error("truncated WAV chunk"); + if(std::memcmp(bytes.data()+offset,"fmt ",4)==0){ + if(size<16)throw std::runtime_error("WAV fmt too short"); + const auto* p=bytes.data()+start; + fmt=u16(p);ch=u16(p+2);hz=u32(p+4);align=u16(p+12);bits=u16(p+14); + }else if(std::memcmp(bytes.data()+offset,"data",4)==0){ + dataStart=start;dataBytes=size; + } + offset=start+size+(size&1); + } + if(hz<32000||hz>192000||(ch!=1&&ch!=2)|| + !((fmt==1&&(bits==16||bits==24))||(fmt==3&&bits==32))|| + align!=ch*(bits/8)||!dataBytes||dataBytes%align) + throw std::runtime_error("use 32-192kHz mono/stereo PCM16/24 or IEEE float32 WAV"); + const auto frames=dataBytes/align; + if(frames>static_cast(hz)*60)throw std::runtime_error("use <=60s original adult-vocal excerpt"); + Wave out;out.rate=hz;out.left.resize(frames);out.right.resize(frames); + const auto* data=bytes.data()+dataStart; + for(std::size_t i=0;ifloat{ + const auto* p=data+i*align+static_cast(c)*(bits/8); + if(fmt==3){ + const auto raw=u32(p);float x=0;std::memcpy(&x,&raw,sizeof(x)); + return std::isfinite(x)?std::clamp(x,-4.f,4.f):0.f; + } + if(bits==16)return static_cast(std::int16_t(u16(p)))/32768.f; + std::int32_t value=std::int32_t(p[0])|(std::int32_t(p[1])<<8)| + (std::int32_t(p[2])<<16); + if(value&0x800000)value|=~0xffffff; + return static_cast(value)/8388608.f; + }; + out.left[i]=sample(0); + out.right[i]=sample(ch==2?1:0); + } + return out; +} +static void writeWave(const fs::path& path,const Wave& wave){ + if(wave.left.size()!=wave.right.size()||wave.left.size()>0x1fffffff) + throw std::runtime_error("WAV output too large"); + std::ofstream out(path,std::ios::binary|std::ios::trunc); + if(!out)throw std::runtime_error("WAV output open failed"); + const std::uint32_t n=static_cast(wave.left.size()*8); + out.write("RIFF",4);put32(out,n+36);out.write("WAVEfmt ",8); + put32(out,16);put16(out,3);put16(out,2);put32(out,wave.rate); + put32(out,wave.rate*8);put16(out,8);put16(out,32); + out.write("data",4);put32(out,n); + for(std::size_t i=0;i(); + if(!e->prepare(input.rate)||!e->setSettings(settings)) + throw std::runtime_error("native Harmony configuration invalid"); + e->setPitchSynchronousCandidateForOfflineReference(synchronous); + Wave out=input; + for(std::size_t pos=0;pos(block)) + e->process(out.left.data()+pos,out.right.data()+pos, + static_cast(std::min(static_cast(block),out.left.size()-pos))); + return out; +} +static double rms(const Wave& x){ + if(x.left.empty())return 0.;double acc=0.; + for(std::size_t i=0;i=3.999f||std::abs(modern.right[i])>=3.999f) + throw std::runtime_error("mixed output clipped: lower recording level for valid stem subtraction"); + const Wave backing=subtract(modern,dry); + writeWave(folder/"01_lead_reference.wav",dry); + writeWave(folder/"02_legacy_grain_mix.wav",old); + writeWave(folder/"03_new_space_060.wav",modern); + writeWave(folder/"04_new_backing_only.wav",backing); + writeWave(folder/"05_new_mono_fold.wav",fold(modern)); + settings.space=0.f;writeWave(folder/"06_new_space_000.wav",process(input,settings,true)); + settings.space=1.f;writeWave(folder/"07_new_space_100.wav",process(input,settings,true)); + generateReport(folder,input,dry,old,modern,backing); +} +int main(int argc,char** argv){ + try{ + if(argc==2&&std::string(argv[1])=="--self-test"){ + Wave v;v.rate=48000;v.left.resize(18000);v.right.resize(18000); + for(int i=0;i<18000;++i){ + const double ph=6.283185307179586*220.*i/48000.; + v.left[i]=v.right[i]=static_cast( + .13*std::sin(ph)+.06*std::sin(2*ph)+.03*std::sin(3*ph)); + } + Settings s;s.wet=.45f; + auto before=process(v,s,false); + auto after=process(v,s,true); + if(!(rms(before)>0.01&&rms(after)>0.01))return 2; + s.wet=0.f; + if(!same(process(v,s,false),process(v,s,true)))return 3; + std::cout<<"Offline native A/B test passed (synthetic only)\n"; + return 0; + } + if(argc!=3){std::cerr<<"usage: harmony_offline_ab input.wav output_directory\n";return 1;} + renderAb(readWave(argv[1]),argv[2]); + std::cout<<"WAV A/B written. No human-singing/formant qualification implied.\n"; + return 0; + }catch(const std::exception& e){std::cerr<<"Harmony A/B: "< Date: Mon, 9 Nov 2026 20:49:57 +0700 Subject: [PATCH 042/125] feat(desktop): custom JUCE SVG caption, ArSonMiX brand and event-driven wire geometry --- .../assets/mixer-chrome-material.css | 18 +++ site/preview-v2/index.html | 41 +++++- src/ArSonWindowChrome.h | 126 ++++++++++++++++++ src/Main.cpp | 13 +- ...ve_caption_wire_geometry_contract.test.cjs | 30 +++++ web/approved-native-bridge.js | 3 + 6 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 src/ArSonWindowChrome.h create mode 100644 tests/native_caption_wire_geometry_contract.test.cjs diff --git a/site/preview-v2/assets/mixer-chrome-material.css b/site/preview-v2/assets/mixer-chrome-material.css index 4e6cddea4..9b054a2aa 100644 --- a/site/preview-v2/assets/mixer-chrome-material.css +++ b/site/preview-v2/assets/mixer-chrome-material.css @@ -1489,3 +1489,21 @@ html :where(.app, .app *),html :where(.app, .app *)::before,html :where(.app, .a .routing-wire-overlay path{filter:none!important;pointer-events:none} + +/* Desktop JUCE titlebar: one real OS window caption, no doubled WebView header. + The public interactive browser reference keeps its own top identity bar. */ +html.armix-native-desktop .app > .window-title{display:none!important} +.window-title .logo{display:inline-flex!important;align-items:center;gap:0;letter-spacing:.015em} +.window-title .logo .armix-brand-ar{color:#48d5f3} +.window-title .logo .armix-brand-son{color:#eff8fa} +.window-title .logo .armix-brand-mix{color:#ffad59} +/* Compact consistent operator toolbar spacing, preserving existing BTN-180 skin. */ +.app .command-bar{ + min-height:34px!important;align-items:center!important;column-gap:5px!important; + padding-left:9px!important;padding-right:9px!important; +} +.app .command-bar>.sep{margin-left:2px!important;margin-right:2px!important} +.app .command-bar .toolbar-label{font-size:9px!important;letter-spacing:.06em} +@media(max-width:1220px){ + .app .command-bar{column-gap:3px!important;padding-left:5px!important;padding-right:5px!important} +} diff --git a/site/preview-v2/index.html b/site/preview-v2/index.html index c2fa7648b..724f78ea2 100644 --- a/site/preview-v2/index.html +++ b/site/preview-v2/index.html @@ -30,7 +30,7 @@
-
Mixer · Reference SessionOPERATOR-FIRST · SINGLE LIVE CONSOLE REFERENCE
+
Mixer · Reference SessionOPERATOR-FIRST · SINGLE LIVE CONSOLE REFERENCE