diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 41db290c3..648b7a298 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -111,6 +111,7 @@ class Engine final { leadRendering_=false;voicePlanner_.reset(); pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; + uncertainPitchHops_=0;weakSyncHops_=0;pitchSyncStable_=false; pitchSyncReferenceEnabled_=true; stageDepthReferenceEnabled_=true; roomFocusReferenceEnabled_=true; @@ -369,7 +370,9 @@ class Engine final { outL+=room.left*roomReturn;outR+=room.right*roomReturn; l[i]=std::clamp(outL*gain_,-4.f,4.f); r[i]=std::clamp(outR*gain_,-4.f,4.f); - ensemble_.advance(voiced_&&sourceConfidence_>.87f&¬eHold_>=2); + // Expression follows stable notes; confidence hysteresis is + // handled by the tracker, not by vibrato resetting on one hop. + ensemble_.advance(voiced_&¬eHold_>=2); stage_.advance(); write_=(write_+1)%capacity; ++sampleClock_; @@ -423,7 +426,8 @@ 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=pitchSyncReferenceEnabled_&&voiced_&&sourceConfidence_>.82f&& + // Avoid 150Hz switching between two synthesis algorithms. + const bool confident=pitchSyncReferenceEnabled_&&voiced_&&pitchSyncStable_&& sourcePeriodSamples_>=8.f; PitchSynchronousVoice::Output sync{}; if(confident) @@ -431,10 +435,13 @@ class Engine final { sourcePeriodSamples_,effectiveRatio, static_cast(latency_)+arrival); float& colorState=pitchSyncFiltered_[ix]; - colorState+=filterCoef*(sync.sample-colorState); + // Invalid PSOLA epochs must never inject zero into the high-voice + // output while a crossfade is still active. + if(sync.ready)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; + const float validSync=sync.ready?colorState:f; + y=f*(1.f-blend)+validSync*blend; phase_[ix]+=1.f/static_cast(grain_); if(phase_[ix]>=1.f)phase_[ix]-=1.f; return y; @@ -504,8 +511,19 @@ class Engine final { void releasePitch() noexcept { sourceConfidence_=0.f;voiced_=false;noteHold_=0; candidateNote_=-1;currentNote_=-1; + uncertainPitchHops_=0;weakSyncHops_=0;pitchSyncStable_=false; 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. + void uncertainPitchEvidence() noexcept { + if(voiced_&¬eHold_>=2&&uncertainPitchHops_<2){ + ++uncertainPitchHops_; + return; + } + releasePitch(); + } void finishPitchAnalysis() noexcept { const auto& correlations=pitchCorrelations_; float best=pitchBest_; @@ -522,9 +540,10 @@ class Engine final { } } if(bestLag==0||best<=0.77f){ - releasePitch(); + uncertainPitchEvidence(); return; } + uncertainPitchHops_=0; // Three-point peak interpolation reduces integer-lag tuning steps, // especially at the high end of the supported singing range. float lag=static_cast(bestLag); @@ -578,6 +597,13 @@ class Engine final { } sourcePeriodSamples_=newPeriod; sourceConfidence_=confidence; + // Hysteresis prevents marginal correlation confidence causing + // rapid PSOLA/granular alternation. Silence disables it immediately. + if(confidence>=.86f){ + pitchSyncStable_=true;weakSyncHops_=0; + }else if(confidence<.79f){ + if(++weakSyncHops_>=3)pitchSyncStable_=false; + }else weakSyncHops_=0; // Integer intervals come from the prepared LUT. The single // fractional ratio tracks the current microphone pitch. const float baseRatio=std::exp2((note-midi)/12.f); @@ -607,6 +633,8 @@ 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; + int uncertainPitchHops_=0,weakSyncHops_=0; + bool pitchSyncStable_=false; std::uint64_t sampleClock_=0; bool pitchSyncReferenceEnabled_=true,stageDepthReferenceEnabled_=true; bool roomFocusReferenceEnabled_=true; diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h index 339126876..11b123c8d 100644 --- a/engine/builtin_fx/HarmonyPitchSynchronous.h +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -65,10 +65,11 @@ class PitchSynchronousVoice final { state.initialized=true; state.nextCenter=static_cast(time)+width; if constexpr(Stereo) { - const auto peak=findPositiveEpoch(epochs,time,writeIndex, - state.nextCenter-fixedDelay,period); + const auto peak=findStableEpoch(epochs,time,writeIndex, + state.nextCenter-fixedDelay,period,state.epochPolarity); if(peak>=0) - state.nextCenter=refineEpoch(epochs,time,writeIndex,peak)+fixedDelay; + state.nextCenter=refineEpoch(epochs,time,writeIndex,peak, + state.epochPolarity)+fixedDelay; } } // Advance at most two grains per sample, even on hostile period jumps. @@ -76,12 +77,13 @@ class PitchSynchronousVoice final { 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(epochs,time,writeIndex,desired,period); + const auto peak=findStableEpoch(epochs,time,writeIndex,desired,period, + 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); + epoch=refineEpoch(epochs,time,writeIndex,peak,state.epochPolarity); grain={state.nextCenter,epoch,width,true}; state.nextSlot=(state.nextSlot+1)%state.grains.size(); } @@ -111,13 +113,19 @@ class PitchSynchronousVoice final { std::array grains{}; double nextCenter=0.; std::size_t nextSlot=0; + int epochPolarity=0; // stable sign throughout the voiced resynthesis run 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, + // A fixed +3mV positive-peak threshold rejects quiet voiced periods and + // asymmetric vowels, leaving holes in the high backing shifter. Select + // the strongest signed source landmark once per voice and keep its sign + // throughout the phrase, so polarity never flips between adjacent grains. + // The caller's independent high-confidence pitch detector remains the + // voiced/noise gate; this floor only excludes numerical silence. + // The same <1-period scan and history bounds apply at every sample rate. + static std::int64_t findStableEpoch(const std::array& input, std::uint64_t time,std::size_t writeIndex, - double desired,double period) noexcept { + double desired,double period,int& polarity) noexcept { const auto half=static_cast(std::ceil(period*.46)); const auto center=static_cast(std::llround(desired)); const auto oldest=static_cast( @@ -126,23 +134,34 @@ class PitchSynchronousVoice final { 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;} + if(value>maxPositive){maxPositive=value;positive=t;} + if(-value>maxNegative){maxNegative=-value;negative=t;} } - return peak; + constexpr float silenceFloor=1.e-5f; + if(polarity==0) { + if(std::max(maxPositive,maxNegative)=maxNegative?1:-1; + } + return polarity>0? + (maxPositive>=silenceFloor?positive:-1): + (maxNegative>=silenceFloor?negative:-1); } static double refineEpoch(const std::array& input, - std::uint64_t time,std::size_t writeIndex,std::int64_t peak) noexcept { + std::uint64_t time,std::size_t writeIndex,std::int64_t peak, + int polarity) noexcept { const auto age=time-static_cast(peak); if(age<2||age>=Capacity-3||peak==0)return static_cast(peak); const auto i=(writeIndex+Capacity-age)&(Capacity-1); - const float a=input[(i+Capacity-1)&(Capacity-1)],b=input[i]; - const float c=input[(i+1)&(Capacity-1)]; + const float sign=polarity<0?-1.f:1.f; + const float a=sign*input[(i+Capacity-1)&(Capacity-1)]; + const float b=sign*input[i]; + const float c=sign*input[(i+1)&(Capacity-1)]; const float curvature=a-2.f*b+c; if(b=-1.e-6f)return static_cast(peak); return static_cast(peak)+ diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index a95ae18b5..6e30248f0 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -484,10 +484,10 @@ .mx-harm-signature strong{font-size:17px;font-weight:500;letter-spacing:-.35px;color:#d1ebec} .mx-harm-signature small{font-size:8px;letter-spacing:1.1px;color:#86a8b2} .mx-harm-label{font-size:9px;letter-spacing:.9px;color:#a3c0c8;font-weight:500} -.mx-harm-voices{display:flex;gap:4px;width:100%} +.mx-harm-voices{display:flex;gap:3px;width:100%} .mx-harm-voices button{ appearance:none;display:flex;align-items:center;justify-content:center; - gap:3px;flex:1;min-width:0;height:30px;padding:0 3px;border-radius:5px; + gap:2px;flex:1;min-width:0;height:30px;padding:0 2px;border-radius:5px; border:1px solid #557784;line-height:1; background:linear-gradient(180deg,#365b67,#294953); color:#cfe5e7;font-size:11px;font-weight:500; @@ -495,7 +495,7 @@ 0 1px 0 #132d38,0 2px 4px #0618223f; transition:background .13s ease,box-shadow .13s ease,color .13s ease } -.mx-harm-voice-glyph{display:block;flex:0 0 13px;width:13px;height:13px} +.mx-harm-voice-glyph{display:block;flex:0 0 11px;width:11px;height:11px} .mx-harm-voices button span{display:block;font-variant-numeric:tabular-nums} .mx-harm-voices button.active{ background:linear-gradient(180deg,#438d7d,#326c63); @@ -767,7 +767,8 @@ .mx-harm-signature{min-height:71px} .mx-harm-voices{gap:2px} .mx-harm-voices button{height:28px;padding:0 2px;gap:2px} - .mx-harm-voice-glyph{width:11px;height:11px;flex-basis:11px} + /* Four counts remain legible in the narrow 112px left rail. */ + .mx-harm-voice-glyph{display:none} .mx-harm-source{flex-wrap:wrap;gap:5px;padding:5px 8px} .mx-harm-source-picker{flex:1} .mx-harm-guide-status{font-size:8px} diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index c603c6cbe..a985603d6 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -31,7 +31,7 @@ root.innerHTML=` HARMONICEVOCAL ENGINE VOICES