diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 648b7a298..ba6722942 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -110,13 +110,17 @@ class Engine final { leadRatio_=1.f;leadBlend_=0.f;leadPeriod_=0.f; leadRendering_=false;voicePlanner_.reset(); pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); + pitchSyncValid_.fill(0.f); sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; uncertainPitchHops_=0;weakSyncHops_=0;pitchSyncStable_=false; pitchSyncReferenceEnabled_=true; stageDepthReferenceEnabled_=true; roomFocusReferenceEnabled_=true; presenceReferenceEnabled_=true; - pitchSyncAlpha_=static_cast(1.-std::exp(-1./(rate*.012))); + // Both renderer choice and missing-epoch recovery are time-domain + // crossfades. Never hard-switch their independent source phases. + pitchSyncAlpha_=static_cast(1.-std::exp(-1./(rate*.030))); + pitchSyncValidAlpha_=static_cast(1.-std::exp(-1./(rate*.005))); const float cutoff=1800.f; decimationAlpha_=static_cast(1.-std::exp(-2.*3.141592653589793*cutoff/rate)); write_=0;downWrite_=0;downSeen_=0;downCounter_=0; @@ -129,7 +133,9 @@ class Engine final { 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)); + // Sustain a noisy, vibrato-heavy sung vowel without 2ms square-like + // envelope edges; real silence is still detected immediately. + voicedGateAlpha_=static_cast(1.-std::exp(-1./(rate*.008))); ratioAlpha_=static_cast(1.-std::pow(1.-0.00045,48000./rate)); processed_=false;settings_=Settings{}; return setSettings(settings_); @@ -167,7 +173,12 @@ class Engine final { for(std::size_t v=0;v(grain_); if(phase_[ix]>=1.f)phase_[ix]-=1.f; return y; @@ -512,13 +532,15 @@ class Engine final { sourceConfidence_=0.f;voiced_=false;noteHold_=0; candidateNote_=-1;currentNote_=-1; uncertainPitchHops_=0;weakSyncHops_=0;pitchSyncStable_=false; + sourcePeriodSamples_=0.f; leadTune_.release();voicePlanner_.reset(); } - // Keep the last known voiced note through at most two energetic but - // ambiguous analysis windows (~13ms at 48k); actual silence immediately - // releases. This prevents periodic gating on high vowels/consonants. + // Keep the last known voiced note through at most five energetic but + // ambiguous analysis windows (~33ms at 48k); true silence immediately + // releases. Avoid ~150Hz note-gating during loud vowels and long vibrato. + // Six inconclusive windows still release, never an indefinite noise hold. void uncertainPitchEvidence() noexcept { - if(voiced_&¬eHold_>=2&&uncertainPitchHops_<2){ + if(voiced_&¬eHold_>=2&&uncertainPitchHops_<5){ ++uncertainPitchHops_; return; } @@ -592,10 +614,23 @@ class Engine final { currentNote_=note;voiced_=true;tonalTransitionPending_=false; if(sourcePeriodSamples_>0.f&& std::abs(newPeriod-sourcePeriodSamples_)>.25f*sourcePeriodSamples_){ - pitchSync_.reset();pitchSyncBlend_.fill(0.f); - pitchSyncFiltered_.fill(0.f); + // A confirmed octave-size transition is a new periodicity. + // Re-seed grains but let the 5/30ms fallback crossfades mask + // this discontinuity instead of resetting output gains to zero. + pitchSync_.reset(); + pitchSyncStable_=false;weakSyncHops_=0; + sourcePeriodSamples_=newPeriod; + }else if(sourcePeriodSamples_<=0.f){ + sourcePeriodSamples_=newPeriod; + }else{ + // Six-millisecond F0 windows fluctuate on long singer vibrato. + // Slew the source period at note-rate, not as discrete PSOLA + // grain-window jumps. A 5% bounded hop still tracks a real + // melodic transition promptly; target intervals remain separate. + const float bounded=std::clamp(newPeriod, + sourcePeriodSamples_*.95f,sourcePeriodSamples_*1.05f); + sourcePeriodSamples_+=.30f*(bounded-sourcePeriodSamples_); } - sourcePeriodSamples_=newPeriod; sourceConfidence_=confidence; // Hysteresis prevents marginal correlation confidence causing // rapid PSOLA/granular alternation. Silence disables it immediately. @@ -633,13 +668,14 @@ class Engine final { 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; + float pitchSyncValidAlpha_=0.f; int uncertainPitchHops_=0,weakSyncHops_=0; bool pitchSyncStable_=false; std::uint64_t sampleClock_=0; bool pitchSyncReferenceEnabled_=true,stageDepthReferenceEnabled_=true; bool roomFocusReferenceEnabled_=true; bool presenceReferenceEnabled_=true; - std::array pitchSyncBlend_{},pitchSyncFiltered_{}; + std::array pitchSyncBlend_{},pitchSyncFiltered_{},pitchSyncValid_{}; float space_=0.f,targetSpace_=0.f; float gain_=1.f,targetGain_=1.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h index 11b123c8d..011198ef6 100644 --- a/engine/builtin_fx/HarmonyPitchSynchronous.h +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -64,13 +64,14 @@ class PitchSynchronousVoice final { if(!state.initialized) { state.initialized=true; state.nextCenter=static_cast(time)+width; - if constexpr(Stereo) { - const auto peak=findStableEpoch(epochs,time,writeIndex, - state.nextCenter-fixedDelay,period,state.epochPolarity); - if(peak>=0) - state.nextCenter=refineEpoch(epochs,time,writeIndex,peak, - state.epochPolarity)+fixedDelay; - } + // Align mono backing *and* stereo lead to fractional epochs. + // Integer-peak rounding previously induced a 1-sample phase + // staircase on high soprano periods, heard as brittle buzz. + const auto peak=findStableEpoch(epochs,time,writeIndex, + state.nextCenter-fixedDelay,period,state.epochPolarity); + if(peak>=0) + state.nextCenter=refineEpoch(epochs,time,writeIndex,peak, + state.epochPolarity)+fixedDelay; } // Advance at most two grains per sample, even on hostile period jumps. // Normal supported periods place >=4 samples between target marks. @@ -81,9 +82,8 @@ class PitchSynchronousVoice final { state.epochPolarity); if(peak>=0) { auto& grain=state.grains[state.nextSlot]; - double epoch=static_cast(peak); - if constexpr(Stereo) - epoch=refineEpoch(epochs,time,writeIndex,peak,state.epochPolarity); + const double epoch=refineEpoch( + epochs,time,writeIndex,peak,state.epochPolarity); grain={state.nextCenter,epoch,width,true}; state.nextSlot=(state.nextSlot+1)%state.grains.size(); } diff --git a/engine/builtin_fx/HarmonyStageSpatial.h b/engine/builtin_fx/HarmonyStageSpatial.h index d032d40ab..018600088 100644 --- a/engine/builtin_fx/HarmonyStageSpatial.h +++ b/engine/builtin_fx/HarmonyStageSpatial.h @@ -18,6 +18,15 @@ class BackingStageSpatial final { const float s=std::clamp(space,0.f,1.f); return {1.f-.62f*s,.49f*s,1.08f*s}; } + // Hard-side backing singers lose direct presence against a dense lead + // when the global Space direct/reverb ratio recedes. Restore HIGH + // intelligibility only in its directional direct field; the shared + // diffuse room and lead signal remain unchanged. No extra compressor, + // reverb instance, latency or dynamic loudness pump. + static float directionalPresence(int singer,float space) noexcept { + const float s=std::clamp(space,0.f,1.f); + return 1.f+s*(singer==2?.32f:singer==4?.10f:0.f); + } bool prepare(double rate) noexcept { if(!std::isfinite(rate)||rate<32000.||rate>192000.)return false; const auto delay=static_cast(std::lround(rate*.00022)); diff --git a/engine/builtin_fx/HarmonyVoicePlanner.h b/engine/builtin_fx/HarmonyVoicePlanner.h index cc06fb270..afa56dde0 100644 --- a/engine/builtin_fx/HarmonyVoicePlanner.h +++ b/engine/builtin_fx/HarmonyVoicePlanner.h @@ -15,11 +15,13 @@ struct SingerProfile { float pan,presence; }; inline constexpr std::array singers{{ - {Singer::low, -5,-3,-4,-.68f,1.16f}, - {Singer::mid, 3, 5, 4, .00f,1.00f}, - {Singer::high, 6, 9, 7, .68f,1.12f}, - {Singer::lowerSupport, -9,-6,-7,-.34f,1.00f}, - {Singer::upperSupport, 10,12,12, .34f,1.00f} + // Harder lateral anchors but still center-safe at Space=0. The HIGH + // singer gets more relative presence; normalization remains 1/sqrt(N). + {Singer::low, -5,-3,-4,-.94f,1.20f}, + {Singer::mid, 3, 5, 4, .00f,.94f}, + {Singer::high, 6, 9, 7, .95f,1.37f}, + {Singer::lowerSupport, -9,-6,-7,-.66f,1.03f}, + {Singer::upperSupport, 10,12,12, .67f,1.18f} }}; inline constexpr bool singerActive(Singer role,int voices) noexcept { return role==Singer::low||role==Singer::high|| diff --git a/tests/harmony_dsp_test.cpp b/tests/harmony_dsp_test.cpp index 633b74ab3..a867540e4 100644 --- a/tests/harmony_dsp_test.cpp +++ b/tests/harmony_dsp_test.cpp @@ -137,7 +137,81 @@ static void testVoicePlanner(){ planner.plan(67,0,major); need(planner.target(2)!=high,"reset retained previous phrase voicing"); } +// Stress the USER failure shape: a long 5Hz/70-cent vibrato under +// chorus-level gain with short noisy consonants. Dry/Wet are checked using +// the actual native Engine; fixture is NOT an ASIO or human-likeness claim. +static void testLoudVibratoContinuity(){ + constexpr int rate=48000,frames=rate*2; + std::vector inL(frames),inR(frames); + constexpr double tau=6.283185307179586; + double phase=0.; + for(int i=0;i(i)/rate; + const double vibrato=70.*std::sin(tau*5.1*t); + phase+=tau*220.*std::exp2(vibrato/1200.)/rate; + const double chorus=std::clamp((t-.4)*15.,0.,1.)* + (1.-std::clamp((t-1.25)*15.,0.,1.)); + const double level=.12+.16*chorus; + // Busy phrase: a 14ms noisy consonant every 210ms after warm-up. + const double noise=(i>rate/3 && i%(rate*21/100)((i*977+17)%137-68)/68.:0.; + inL[i]=static_cast( + level*(std::sin(phase)+.26*std::sin(2.*phase+.2)+ + .16*std::sin(3.*phase))+noise); + inR[i]=static_cast( + level*(.85*std::sin(phase+.12)+.31*std::sin(3.*phase+.4))+ + noise*.85); + } + auto process=[&](int block,int voices,bool wet){ + auto dsp=std::make_unique(); + need(dsp->prepare(rate)&&dsp->latencySamples()==1536, + "vibrato engine PDC changed"); + Settings settings;settings.voices=voices;settings.wet=wet?.75f:0.f; + settings.space=.82f; + need(dsp->setSettings(settings),"vibrato DSP settings rejected"); + auto l=inL,r=inR; + int audibleTicks=0,checkedTicks=0; + for(int pos=0;posprocess(l.data()+pos,r.data()+pos,count); + if(pos>rate/3&&posvoiced())++audibleTicks; + } + } + need(audibleTicks>checkedTicks*.96, + "loud-vibrato tracking repeatedly lost voiced continuity"); + return std::pair{std::move(l),std::move(r)}; + }; + const auto five64=process(64,5,true); + const auto five257=process(257,5,true); + need(five64==five257, + "heavy five-voice vibrato output depends on ASIO callback partition"); + const auto dry=process(257,5,false); + double harmonyE=0.,outE=0.,monoE=0.; + float largestStep=0.f; + for(int i=rate/2;i(i)]; + const float r=five64.second[static_cast(i)]; + const float dl=dry.first[static_cast(i)]; + const float dr=dry.second[static_cast(i)]; + need(std::isfinite(l)&&std::isfinite(r)&& + std::abs(l)<3.9f&&std::abs(r)<3.9f, + "loud vibrato harmonic mixed PCM nonfinite or clipped"); + harmonyE+=(l-dl)*(l-dl)+(r-dr)*(r-dr); + outE+=l*l+r*r; + monoE+=(l+r)*(l+r)*.25; + largestStep=std::max(largestStep,std::abs(l- + five64.first[static_cast(i-1)])); + } + need(harmonyE>1.&&outE>4.&&monoE>1., + "high-demand ensemble lost harmony or mono energy"); + need(largestStep<.65f, + "long-vibrato ensemble produced an unbounded sample discontinuity"); +} + int main(){ + testLoudVibratoContinuity(); testLeadTune(); testVoicePlanner(); // Each Engine owns fixed ring buffers. Allocate offline fixtures on heap: @@ -738,6 +812,21 @@ int main(){ "ensemble gain changes with voice count"); need(modern.mixL[0]>modern.mixR[0]&&modern.mixR[2]>modern.mixL[2], "LOW/HIGH changed sides when voice count changed"); + // 60% SPACE must now create an audible hard-sided LOW/HIGH pair + // without making the center MID dominate the music mix. + need(modern.mixL[0]>modern.mixR[0]*3.f&& + modern.mixR[2]>modern.mixL[2]*3.f, + "perceptual HARD stereo spread not applied to LOW/HIGH"); + const float low=std::hypot(modern.mixL[0],modern.mixR[0]); + const float high=std::hypot(modern.mixL[2],modern.mixR[2]); + need(high>low*1.11f,"HIGH voice still masked behind LOW"); + Settings centered=settings;centered.space=0.f; + Engine::PreparedSettings mono{}; + need(Engine::prepareSettings(centered,mono), + "Space0 layout invalid"); + need(std::abs(mono.mixL[0]-mono.mixR[0])<1.e-6f&& + std::abs(mono.mixL[2]-mono.mixR[2])<1.e-6f, + "hard pan leaks when Space=0"); } // P0 lead preservation: backing Wet must never change the lead amplitude. // The *only* intentional lead replacement is Pitch Tune's explicit blend. diff --git a/tests/harmony_stage_spatial_test.cpp b/tests/harmony_stage_spatial_test.cpp index a1935f73e..26e5b722a 100644 --- a/tests/harmony_stage_spatial_test.cpp +++ b/tests/harmony_stage_spatial_test.cpp @@ -119,6 +119,13 @@ static void focusTest(double rate){ f.returnGain(0.f,0.f,1.f)==1.f,"room restart stale sample"); } int main(){ + // Space=0 is unchanged; at wide Space, HIGH retains a small direct + // spectral/level anchor rather than drowning in the shared late room. + need(BackingStageSpatial::directionalPresence(2,0.f)==1.f&& + BackingStageSpatial::directionalPresence(0,1.f)==1.f&& + BackingStageSpatial::directionalPresence(2,1.f)>1.3f&& + BackingStageSpatial::directionalPresence(4,1.f)>1.09f, + "HIGH/support direct focus incorrect or LOW unexpectedly boosted"); for(double rate:{32000.,44100.,48000.,96000.,192000.}){ focusTest(rate); double previous=-1.;