From b582f2cafee7d538d7927b901c2dea595c458171 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 02:44:17 +0700 Subject: [PATCH 01/25] fix(harmonice): recover stereo lead tuning and stable backing registers --- engine/builtin_fx/HarmonyDsp.h | 140 +++++++++++------ engine/builtin_fx/HarmonyEnsembleSpace.h | 11 +- engine/builtin_fx/HarmonyLeadTune.h | 51 +++++++ engine/builtin_fx/HarmonyPitchSynchronous.h | 59 ++++++- engine/builtin_fx/HarmonyVoicePlanner.h | 63 ++++++++ site/preview-v2/assets/mixer-fx-rack.css | 32 +++- .../preview-v2/assets/mixer-native-harmony.js | 27 +++- tests/approved_native_harmony_smoke.py | 40 +++++ tests/harmony_cpu_profile_test.cpp | 3 +- tests/harmony_dsp_test.cpp | 144 +++++++++++++++++- tests/native_harmony_assembly_test.py | 5 +- tools/harmony_offline_ab.cpp | 23 ++- 12 files changed, 523 insertions(+), 75 deletions(-) create mode 100644 engine/builtin_fx/HarmonyLeadTune.h create mode 100644 engine/builtin_fx/HarmonyVoicePlanner.h diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index e1d60272c..41db290c3 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -12,6 +12,8 @@ #include "HarmonyRoomFocus.h" #include "HarmonyStageSpatial.h" #include "HarmonyPitchSynchronous.h" +#include "HarmonyLeadTune.h" +#include "HarmonyVoicePlanner.h" // Deterministic, allocation-free vocal harmony DSP. No JUCE or GUI dependency. // Grain shifting is a functioning prototype, not formant-accurate synthesis. @@ -68,6 +70,7 @@ inline float smoothGrainBlend(float phase) noexcept { class Engine final { public: static constexpr int maxVoices=5; + static_assert(singers.size()==maxVoices); 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. @@ -92,7 +95,6 @@ class Engine final { 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 @@ -103,6 +105,10 @@ class Engine final { !stage_.prepare(rate)||!roomFocus_.prepare(rate))return false; pitchIntervals_.prepare(); pitchSync_.reset(); + leadShifter_.reset(); + leadTune_.prepare(detectEvery_/rate); + leadRatio_=1.f;leadBlend_=0.f;leadPeriod_=0.f; + leadRendering_=false;voicePlanner_.reset(); pitchSyncBlend_.fill(0.f);pitchSyncFiltered_.fill(0.f); sourcePeriodSamples_=0.f;sourceConfidence_=0.f;sampleClock_=0; pitchSyncReferenceEnabled_=true; @@ -150,15 +156,20 @@ class Engine final { prepared.settings=next; prepared.gain=std::pow(10.f,next.gainDb/20.f); constexpr float pi=3.14159265358979323846f; + float profileEnergy=0.f; + for(const auto& singer:singers) + if(singerActive(singer.role,next.voices)) + profileEnergy+=singer.presence*singer.presence; const float amplitude=normalizedBackingWetAmplitude( - next.wet,next.voices,enhancedPresence); - for(int v=0;v(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); + next.wet,next.voices,enhancedPresence)* + std::sqrt(static_cast(next.voices)/profileEnergy); + for(std::size_t v=0;v(v); mixL_[ix]+=a*(targetMixL_[ix]-mixL_[ix]); @@ -298,15 +311,11 @@ class Engine final { 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. + // active sample, not once for each backing shifter. 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,filterCoef); - const float leadBlend=correctionMix_*voicedGain_; - float outL=leadPath(dryL,lead,leadBlend); - float outR=leadPath(dryR,lead,leadBlend); + float outL=dryL,outR=dryR; + renderLead(outL,outR); // Direct sound and reflections from backing singers only. // Preserve the exact previous spatial gains in offline reference. const auto stageGain=BackingStageSpatial::gains(space_); @@ -360,13 +369,31 @@ 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_); + ensemble_.advance(voiced_&&sourceConfidence_>.87f&¬eHold_>=2); stage_.advance(); write_=(write_+1)%capacity; ++sampleClock_; } } private: + void renderLead(float& left,float& right) noexcept { + const float target=leadTune_.ratio(); + const bool tuning=targetCorrection_>0.f&&std::abs(target-1.f)>.00015f; + if(!tuning&&leadBlend_<.00001f){ + if(leadRendering_)leadShifter_.reset(); + leadRendering_=false;leadBlend_=0.f;leadRatio_=1.f; + return; + } + leadRendering_=true; + leadRatio_+=ratioAlpha_*(target-leadRatio_); + const auto tuned=leadShifter_.processStereo(0,sampleClock_,write_,mono_, + left_,right_,leadPeriod_,leadRatio_,static_cast(latency_)); + leadBlend_+=smoothingAlpha_*((tuning&&tuned.ready?1.f:0.f)-leadBlend_); + if(tuned.ready){ + left=leadPath(left,tuned.left,leadBlend_); + right=leadPath(right,tuned.right,leadBlend_); + } + } float tap(const std::array& a,float delay) const noexcept { const float d=std::clamp(delay,1.f,static_cast(capacity-3)); const int whole=static_cast(d); @@ -398,7 +425,7 @@ class Engine final { // previous validated granular shifter with a bounded 12ms crossfade. const bool confident=pitchSyncReferenceEnabled_&&voiced_&&sourceConfidence_>.82f&& sourcePeriodSamples_>=8.f; - PitchSynchronousVoice::Output sync{}; + PitchSynchronousVoice::Output sync{}; if(confident) sync=pitchSync_.process(voice,sampleClock_,write_,mono_, sourcePeriodSamples_,effectiveRatio, @@ -431,7 +458,7 @@ class Engine final { pitchEnergy_+=x*x; } if(pitchEnergy_/static_cast(span)<1.e-6){ - sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1; + releasePitch(); return; } pitchCorrelations_.fill(0.f); @@ -474,6 +501,11 @@ class Engine final { finishPitchAnalysis(); } } + void releasePitch() noexcept { + sourceConfidence_=0.f;voiced_=false;noteHold_=0; + candidateNote_=-1;currentNote_=-1; + leadTune_.release();voicePlanner_.reset(); + } void finishPitchAnalysis() noexcept { const auto& correlations=pitchCorrelations_; float best=pitchBest_; @@ -481,13 +513,17 @@ class Engine final { // Prefer shortest strong period rather than an octave-multiple peak. if(best>0.77f){ for(int lag=lowLag_;lag<=highLag_;++lag){ - if(correlations[static_cast(lag)]>=std::max(0.77f,best-0.035f)){ + const float peak=correlations[static_cast(lag)]; + if(peak>=std::max(0.77f,best-0.035f)&& + (lag==lowLag_||peak>=correlations[static_cast(lag-1)])&& + (lag==highLag_||peak>=correlations[static_cast(lag+1)])){ bestLag=lag;break; } } } if(bestLag==0||best<=0.77f){ - sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + releasePitch(); + return; } // Three-point peak interpolation reduces integer-lag tuning steps, // especially at the high end of the supported singing range. @@ -503,15 +539,15 @@ 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){ - sourceConfidence_=0.f;voiced_=false;noteHold_=0;candidateNote_=-1;currentNote_=-1;return; + releasePitch(); + return; } const int activeKey=effectiveKey(),activeScale=effectiveScale(); - int degree=nearestDegree(midi,activeKey,activeScale); + const int degree=nearestDegree(midi,activeKey,activeScale); int note=noteAt(degree,activeKey,activeScale); if(!tonalTransitionPending_ && !pitchChangeHasMargin(currentNote_,note,midi)){ note=currentNote_; - degree=nearestDegree(static_cast(note),activeKey,activeScale); } if(note!=candidateNote_){candidateNote_=note;noteHold_=1;} // Saturate the hold counter: a multi-hour sustained note must not @@ -519,30 +555,37 @@ class Engine final { else if(noteHold_<3)++noteHold_; // Two consistent windows for both phrase onset and melodic transitions; // do not generate provisional harmony on a single noisy transient. - if(noteHold_<2)return; - currentNote_=note;voiced_=true;tonalTransitionPending_=false; + const float confidence=std::clamp( + correlations[static_cast(bestLag)],0.f,1.f); + if(noteHold_<2){ + leadTune_.release(); + return; + } const float newPeriod=static_cast(rate_/hz); + if(settings_.correction){ + leadPeriod_=newPeriod; + leadTune_.observe(midi,note,confidence); + } + if(note!=currentNote_||tonalTransitionPending_){ + voicePlanner_.plan(note,activeKey,activeScale==0?major:minor); + ensemble_.beginNote(); + } + 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); } 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 - // 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( - baseRatio*pitchIntervals_.ratio(target-note),0.50f,2.0f); + sourceConfidence_=confidence; + // 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); + for(std::size_t v=0;v pitchSyncBlend_{},pitchSyncFiltered_{}; + std::array pitchSyncBlend_{},pitchSyncFiltered_{}; float space_=0.f,targetSpace_=0.f; - float gain_=1.f,targetGain_=1.f,correctionMix_=0.f,targetCorrection_=0.f; + float gain_=1.f,targetGain_=1.f,targetCorrection_=0.f; std::array mixL_{},mixR_{},targetMixL_{},targetMixR_{}; float decimationLowpass_=0.f,decimationAlpha_=0.f; StereoPhaseSafeFold vocalFold_{}; @@ -580,10 +623,15 @@ class Engine final { BackingDepthRoom depthRoom_{}; BackingStageSpatial stage_{}; BackingRoomFocus roomFocus_{}; - PitchSynchronousVoice pitchSync_{}; + PitchSynchronousVoice pitchSync_{}; + PitchSynchronousVoice leadShifter_{}; + LeadTune leadTune_{}; + VoicePlanner voicePlanner_{}; + bool leadRendering_=false; + float leadRatio_=1.f,leadBlend_=0.f,leadPeriod_=0.f; Settings settings_{}; std::array left_{},right_{},mono_{}; std::array decimated_{}; - std::array filtered_{},phase_{},ratio_{},targetRatio_{}; + std::array filtered_{},phase_{},ratio_{},targetRatio_{}; }; } // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyEnsembleSpace.h b/engine/builtin_fx/HarmonyEnsembleSpace.h index ad91b2cb8..81449589a 100644 --- a/engine/builtin_fx/HarmonyEnsembleSpace.h +++ b/engine/builtin_fx/HarmonyEnsembleSpace.h @@ -49,7 +49,8 @@ class EnsembleSpace final { distanceLowpass_.fill(0.f); ageStart_=static_cast(rate*.065); ageRamp_=static_cast(1./(rate*.165)); - age_=0;cursor_=0; + expressionAlpha_=static_cast(1.-std::exp(-1./(rate*.018))); + expression_=0.f;age_=0;cursor_=0; return true; } float shadeBacking(int v,float sample,float space) noexcept { @@ -78,8 +79,7 @@ class EnsembleSpace final { 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); + return ratio_[i]*(1.f+wave*vibratoRatio_[i]*expression_); } // Exactly one filtered early reflection from each independent singer. // Fixed integer tap delay: changing Space can never sweep a delay line @@ -102,10 +102,13 @@ class EnsembleSpace final { int secondReflectionSamples(int singer) const noexcept { return secondDelay_[static_cast(singer)]; } + void beginNote() noexcept { age_=0; } void advance(bool voiced) noexcept { cursor_=(cursor_+1)&(reflectionCapacity-1); if(!voiced)age_=0; else if(age_<100000000)++age_; + const float mature=std::clamp((age_-ageStart_)*ageRamp_,0.f,1.f); + expression_+=expressionAlpha_*(mature-expression_); } private: std::array sine_{}; @@ -116,6 +119,6 @@ class EnsembleSpace final { std::array reflectionDelay_{},secondDelay_{}; std::size_t cursor_=0; int age_=0,ageStart_=0; - float ageRamp_=0.f; + float ageRamp_=0.f,expressionAlpha_=0.f,expression_=0.f; }; } // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyLeadTune.h b/engine/builtin_fx/HarmonyLeadTune.h new file mode 100644 index 000000000..4de5359cf --- /dev/null +++ b/engine/builtin_fx/HarmonyLeadTune.h @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include + +namespace armix::harmony { +// Hop-rate lead policy. The slow note center drives correction while the +// instantaneous period still drives synthesis, retaining pitch modulation. +class LeadTune final { +public: + void prepare(double hopSeconds) noexcept { + centerAlpha_=static_cast(1.-std::exp(-hopSeconds/.16)); + stableHops_=static_cast(std::ceil(.080/hopSeconds)); + release(); + } + + void release() noexcept { + note_=-1; + age_=0; + ratio_=1.f; + } + + void observe(float midi,int note,float confidence) noexcept { + if(confidence<.87f||std::abs(midi-note)>.65f){ + release(); + return; + } + // Keep the same intent through normal vibrato around the note. A + // large excursion, or a different nearby scale note, reacquires. + if(note_!=note||std::abs(midi-center_)>.75f){ + note_=note; + center_=midi; + age_=0; + ratio_=1.f; + return; + } + center_+=centerAlpha_*(midi-center_); + if(age_(note_)-center_; + const float correction=std::copysign( + std::min(.34f,.8f*std::max(0.f,std::abs(error)-.09f)),error); + ratio_=std::exp2(correction/12.f); + } + + float ratio() const noexcept {return ratio_;} +private: + int note_=-1,age_=0,stableHops_=1; + float center_=0.f,centerAlpha_=1.f,ratio_=1.f; +}; +} // namespace armix::harmony diff --git a/engine/builtin_fx/HarmonyPitchSynchronous.h b/engine/builtin_fx/HarmonyPitchSynchronous.h index 9395ea1ca..339126876 100644 --- a/engine/builtin_fx/HarmonyPitchSynchronous.h +++ b/engine/builtin_fx/HarmonyPitchSynchronous.h @@ -19,6 +19,7 @@ class PitchSynchronousVoice final { static_assert(Voices > 0 && Voices <= 8); public: struct Output { float sample=0.f; bool ready=false; }; + struct StereoOutput { float left=0.f,right=0.f; bool ready=false; }; void reset() noexcept { states_={}; } void resetVoice(int v) noexcept { if(v>=0&&v(v)]={}; @@ -29,6 +30,28 @@ class PitchSynchronousVoice final { Output process(int v,std::uint64_t time,std::size_t writeIndex, const std::array& input, float sourcePeriod,float ratio,float fixedDelay) noexcept { + const auto out=render(v,time,writeIndex,input,input,input, + sourcePeriod,ratio,fixedDelay); + return {out.left,out.ready}; + } + + // The detector selects one set of epochs. Both stereo channels use the + // same windows, timing and normalization, with no lead COLOR filtering. + StereoOutput processStereo(int v,std::uint64_t time,std::size_t writeIndex, + const std::array& epochs, + const std::array& left, + const std::array& right, + float sourcePeriod,float ratio,float fixedDelay) noexcept { + return render(v,time,writeIndex,epochs,left,right, + sourcePeriod,ratio,fixedDelay); + } +private: + template + StereoOutput render(int v,std::uint64_t time,std::size_t writeIndex, + const std::array& epochs, + const std::array& left, + const std::array& right, + 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|| @@ -41,23 +64,32 @@ class PitchSynchronousVoice final { if(!state.initialized) { state.initialized=true; state.nextCenter=static_cast(time)+width; + if constexpr(Stereo) { + const auto peak=findPositiveEpoch(epochs,time,writeIndex, + state.nextCenter-fixedDelay,period); + if(peak>=0) + state.nextCenter=refineEpoch(epochs,time,writeIndex,peak)+fixedDelay; + } } // 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); + const auto peak=findPositiveEpoch(epochs,time,writeIndex,desired,period); if(peak>=0) { auto& grain=state.grains[state.nextSlot]; - grain={state.nextCenter,static_cast(peak),width,true}; + double epoch=static_cast(peak); + if constexpr(Stereo) + epoch=refineEpoch(epochs,time,writeIndex,peak); + grain={state.nextCenter,epoch,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; + float sumL=0.f,sumR=0.f,weight=0.f; for(auto& grain:state.grains) { if(!grain.active)continue; const double offset=static_cast(time)-grain.center; @@ -66,13 +98,14 @@ class PitchSynchronousVoice final { 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; + sumL+=readAt(left,time,writeIndex,grain.source+offset)*w; + if constexpr(Stereo) + sumR+=readAt(right,time,writeIndex,grain.source+offset)*w; + weight+=w; } if(weight<.05f)return {}; - return {sum/weight,true}; + return {sumL/weight,sumR/weight,true}; } -private: struct Grain {double center=0.,source=0.,width=1.;bool active=false;}; struct State { std::array grains{}; @@ -103,6 +136,18 @@ class PitchSynchronousVoice final { } return peak; } + static double refineEpoch(const std::array& input, + std::uint64_t time,std::size_t writeIndex,std::int64_t peak) 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 curvature=a-2.f*b+c; + if(b=-1.e-6f)return static_cast(peak); + return static_cast(peak)+ + std::clamp(.5f*(a-c)/curvature,-.5f,.5f); + } 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)|| diff --git a/engine/builtin_fx/HarmonyVoicePlanner.h b/engine/builtin_fx/HarmonyVoicePlanner.h new file mode 100644 index 000000000..cc06fb270 --- /dev/null +++ b/engine/builtin_fx/HarmonyVoicePlanner.h @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +namespace armix::harmony { +// Stable DSP slots for the five singers. Activation order (LOW, MID, HIGH, +// lower support, upper support) is separate from their musical/pan order. +enum class Singer { low, mid, high, lowerSupport, upperSupport }; +struct SingerProfile { + Singer role; + int minInterval,maxInterval,preferred; + 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} +}}; +inline constexpr bool singerActive(Singer role,int voices) noexcept { + return role==Singer::low||role==Singer::high|| + (role==Singer::mid&&voices>=3)|| + (role==Singer::lowerSupport&&voices>=4)|| + (role==Singer::upperSupport&&voices>=5); +} + +// Diatonic live fallback. At most four candidates per singer. Disjoint +// interval bands prevent crossing or duplicating the lead or another role. +// Prefer consonant anchors, then retain common tones/limit movement when +// the scale allows it. Music Key supplies a scale, never a chord. +class VoicePlanner final { +public: + void reset() noexcept { targets_.fill(-1); } + + void plan(int melody,int key,const std::array& scale) noexcept { + for(std::size_t i=0;i targets_{{-1,-1,-1,-1,-1}}; +}; +} // namespace armix::harmony diff --git a/site/preview-v2/assets/mixer-fx-rack.css b/site/preview-v2/assets/mixer-fx-rack.css index 35f92efef..a95ae18b5 100644 --- a/site/preview-v2/assets/mixer-fx-rack.css +++ b/site/preview-v2/assets/mixer-fx-rack.css @@ -505,11 +505,35 @@ } .mx-harm-voices button:hover:not(.active){background:linear-gradient(#406c74,#30555e)} .mx-harm-voices button:active:not(:disabled){box-shadow:inset 0 3px 6px #09252fb8,0 1px 0 #132d38} -.mx-harm-correction{ - display:flex;align-items:center;gap:8px;color:#b8d9df;font-size:9px; - letter-spacing:.45px;white-space:nowrap;cursor:pointer;margin-top:auto +.mx-harm button.mx-harm-correction{ + appearance:none;display:flex;align-items:center;align-self:flex-start;gap:7px; + min-height:24px;padding:0;border:0;background:none;border-radius:4px; + color:#b8d9df;font-size:9px;line-height:1;letter-spacing:.45px; + white-space:nowrap;margin-top:auto +} +.mx-harm-switch-track{ + display:block;position:relative;flex:0 0 32px;width:32px;height:16px; + border:1px solid #64828b;border-radius:9px;background:#142c36; + box-shadow:inset 0 1px 3px #081b23; + transition:background .14s ease,border-color .14s ease +} +.mx-harm-switch-track::before{ + content:"";position:absolute;left:2px;top:2px;width:10px;height:10px; + border-radius:50%;background:#b6ced1;box-shadow:0 1px 2px #0a242f9c; + transition:transform .14s ease,background .14s ease +} +.mx-harm-correction[aria-checked="true"] .mx-harm-switch-track{ + background:#39786c;border-color:#77bdac +} +.mx-harm-correction[aria-checked="true"] .mx-harm-switch-track::before{ + transform:translateX(16px);background:#e2f6ec +} +.mx-harm-correction[aria-busy="true"] .mx-harm-switch-track{border-style:dashed} +.mx-harm button.mx-harm-correction:disabled{cursor:wait} +.mx-harm-correction:disabled .mx-harm-switch-track::before{visibility:hidden} +@media(prefers-reduced-motion:reduce){ + .mx-harm-switch-track,.mx-harm-switch-track::before{transition:none} } -.mx-harm-correction input{accent-color:#57bba4;width:14px;height:14px;margin:0} .mx-harm-control-deck{ display:flex;align-items:center;justify-content:center;min-width:0; border-right:1px solid #a7b9bf; diff --git a/site/preview-v2/assets/mixer-native-harmony.js b/site/preview-v2/assets/mixer-native-harmony.js index afa106d74..c603c6cbe 100644 --- a/site/preview-v2/assets/mixer-native-harmony.js +++ b/site/preview-v2/assets/mixer-native-harmony.js @@ -33,7 +33,10 @@ root.innerHTML=` - +
@@ -95,11 +98,11 @@ const fresh=()=>({key:0,scale:0,voices:3,correction:false, guideMode:0,guideChannelId:"0", color:0.5,space:0.6,wet:0.45,gainDb:0}); const presets={ - duo:{voices:2,color:.45,space:.35,wet:.31,correction:false,gainDb:0}, - trio:{voices:3,color:.50,space:.56,wet:.40,correction:false,gainDb:0}, - quartet:{voices:4,color:.66,space:.95,wet:.52,correction:true,gainDb:-2}, - quintet:{voices:5,color:.61,space:.88,wet:.45,correction:true,gainDb:-3}, - choir:{voices:4,color:.24,space:.30,wet:.58,correction:true,gainDb:-3} + duo:{voices:2,color:.45,space:.35,wet:.31,gainDb:0}, + trio:{voices:3,color:.50,space:.56,wet:.40,gainDb:0}, + quartet:{voices:4,color:.66,space:.95,wet:.52,gainDb:-2}, + quintet:{voices:5,color:.61,space:.88,wet:.45,gainDb:-3}, + choir:{voices:4,color:.24,space:.30,wet:.58,gainDb:-3} }; const native=()=>Boolean(window.__JUCE__?.backend?.emitEvent); const backend=()=>window.__JUCE__?.backend; @@ -276,7 +279,12 @@ function paint(){ } for(const b of scaleButtons)b.classList.toggle("active", reliable&&Number(b.dataset.scale)===displayScale); - el("mxHCorrection").checked=v.correction; + const correction=el("mxHCorrection"); + const syncing=nativeView&&!verified; + const correctionPending=nativeView&&v.correction!==settings.correction; + correction.disabled=syncing; + correction.setAttribute("aria-busy",String(syncing||correctionPending)); + correction.setAttribute("aria-checked",String(!syncing&&settings.correction)); showText(el("mxHKeyReadout"),reliable?keys[displayKey]+(displayScale?"m":""):"—"); showText(el("mxHNote"),reliable?(displayScale?"MINOR":"MAJOR"):"KEY"); el("mxHKeyReadout").setAttribute("aria-label", @@ -370,7 +378,10 @@ el("mxHGuideSource").addEventListener("change",e=>{ const source=e.target.value; edit({guideMode:source==="0"?0:1,guideChannelId:source}); }); -el("mxHCorrection").addEventListener("change",e=>edit({correction:e.target.checked})); +el("mxHCorrection").addEventListener("click",()=>{ + const desired=latest||pending?.settings||settings; + edit({correction:!desired.correction}); +}); sliders.forEach(({input})=>input.addEventListener("input",()=>{ const k=input.dataset.field,x=Number(input.value); edit({[k]:k==="gainDb"?x:x/100}); diff --git a/tests/approved_native_harmony_smoke.py b/tests/approved_native_harmony_smoke.py index f09dc1530..0b0fa26b9 100644 --- a/tests/approved_native_harmony_smoke.py +++ b/tests/approved_native_harmony_smoke.py @@ -104,7 +104,47 @@ 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()=="—" + switch=page.get_by_role("switch",name="PITCH TUNE") + assert switch.is_disabled() and switch.get_attribute("aria-busy")=="true" readback(page,state,DEFAULT,0,0,observed=57) + assert switch.get_attribute("aria-checked")=="false" + track=switch.locator(".mx-harm-switch-track").bounding_box() + label=switch.get_by_text("PITCH TUNE").bounding_box() + assert track and label and (track["width"],track["height"])==(32,16) + assert abs(track["y"]+track["height"]/2-label["y"]-label["height"]/2)<1 + if width==1366: + editor.screenshot(path="arsonmix-native-harmony-editor-pitch-tune-off.png") + switch.focus() + switch.press("Space") + pitch_edit=last_action(page,"nativeHarmonySetSettings") + assert pitch_edit["settings"]["correction"] is True + assert switch.get_attribute("aria-checked")=="false" + assert switch.get_attribute("aria-busy")=="true" + emit(page,"arMixBuiltinHarmonyAck", + {"requestId":pitch_edit["requestId"],"status":"APPLIED"}) + assert switch.get_attribute("aria-checked")=="false" + readback(page,state,{**DEFAULT,"correction":True},0,0, + applied=pitch_edit["requestId"],observed=57) + assert switch.get_attribute("aria-checked")=="true" + assert switch.get_attribute("aria-busy")=="false" + switch.evaluate("el=>el.blur()") + if width==1366: + page.wait_for_timeout(160) + editor.screenshot(path="arsonmix-native-harmony-editor-pitch-tune-on.png") + page.locator("#mxHPreset").select_option("quartet") + preset_settings=last_action(page,"nativeHarmonySetSettings")["settings"] + assert preset_settings["voices"]==4 and preset_settings["correction"] is True + apply_edit(page,state,preset_settings,0,0) + switch.click() + assert last_action(page,"nativeHarmonySetSettings")["settings"]["correction"] is False + assert switch.get_attribute("aria-checked")=="true" + apply_edit(page,state,{**preset_settings,"correction":False},0,0) + assert switch.get_attribute("aria-checked")=="false" + page.locator("#mxHClose").click() + row.locator('[data-action="openPlugin"]').click() + assert switch.is_disabled() + readback(page,state,DEFAULT,0,0,observed=57) + assert switch.get_attribute("aria-checked")=="false" assert page.locator("#mxHTracking").inner_text()=="TRACKING A3" assert page.locator("#mxHKeyReadout").inner_text()=="C" assert page.locator("#mxHGuideStatus").inner_text()=="MANUAL" diff --git a/tests/harmony_cpu_profile_test.cpp b/tests/harmony_cpu_profile_test.cpp index 5c5f0168a..3c700510b 100644 --- a/tests/harmony_cpu_profile_test.cpp +++ b/tests/harmony_cpu_profile_test.cpp @@ -31,7 +31,8 @@ void profile(double rate,int block,int voices,bool musicGuide=false){ std::array l{},r{},musicL{},musicR{}; std::array elapsed{}; double phase=0.; - const double step=6.283185307179586*220./rate; + // 35 cents sharp so the enabled lead shifter actually runs. + const double step=6.283185307179586*220.*std::exp2(35./1200.)/rate; for(int blockIndex=0;blockIndex using namespace armix::harmony; static void need(bool value,const char* why){if(!value){std::cerr< left,right;}; +static LeadFixture leadFixture(int rate,double noteHz,float cents,float vibrato){ + LeadFixture out{std::vector(2*rate),std::vector(2*rate)}; + constexpr double tau=6.283185307179586; + double phase=0.; + for(int i=0;i<2*rate;++i){ + const double modulation=vibrato*std::sin(tau*5.*i/rate); + phase+=tau*noteHz*std::exp2((cents+modulation)/1200.)/rate; + out.left[i]=static_cast(.17*std::sin(phase)+.045*std::sin(2*phase)); + out.right[i]=static_cast(.11*std::sin(phase+.38)+.04*std::sin(2*phase+1.2)); + } + return out; +} +static LeadFixture tune(LeadFixture signal,int rate,bool correction, + int block=127,float color=.5f,int releaseAt=-1){ + auto engine=std::make_unique(); + need(engine->prepare(rate)&&engine->latencySamples()==2*std::lround(.016*rate), + "Pitch Tune changed PDC"); + Settings s;s.wet=0.f;s.correction=correction;s.color=color; + need(engine->setSettings(s),"lead-only settings rejected"); + const int size=static_cast(signal.left.size()); + for(int i=0;isetSettings(s),"Pitch Tune release rejected"); + } + const int end=iprocess(signal.left.data()+i,signal.right.data()+i,n); + i+=n; + } + return signal; +} +static std::vector centsByCycle(const LeadFixture& signal,int rate,double target){ + std::vector cents; + const auto& x=signal.left; + double previous=-1.; + for(int i=rate;i(x.size())-1;++i){ + if(x[i]>=0.f||x[i+1]<0.f)continue; + const double crossing=i-x[i]/(x[i+1]-x[i]); + if(previous>=0.)cents.push_back(1200.*std::log2(rate/(crossing-previous)/target)); + previous=crossing; + } + std::sort(cents.begin(),cents.end()); + need(cents.size()>50,"lead fixture lacks steady pitch"); + return cents; +} +static double stereoResidual(const LeadFixture& signal,int rate){ + double side=0.,mid=0.; + for(std::size_t i=static_cast(rate);i=5.&¢er<=27.,"lead correction failed to reduce pitch error gently"); + const auto sharpDry=tune(sharp,rate,false); + need(std::abs(stereoResidual(corrected,rate)/stereoResidual(sharpDry,rate)-1.)<.10, + "correction collapsed or inflated the stereo lead"); + const auto warm=tune(sharp,rate,true,64,0.f); + need(warm.left==corrected.left&&warm.right==corrected.right, + "lead correction changed with block size or backing COLOR"); + } + const auto vibrato=leadFixture(rate,220.,0.f,55.f); + const auto tuned=tune(vibrato,rate,true); + const auto cycles=centsByCycle(tuned,rate,220.); + const auto original=centsByCycle(tune(vibrato,rate,false),rate,220.); + const auto span=[](const auto& values){ + return values[9*values.size()/10]-values[values.size()/10]; + }; + need(span(cycles)>.85*span(original)&&span(cycles)<1.15*span(original), + "wide vibrato changed excessively"); + auto mono=leadFixture(rate,220.,-35.f,0.f); + mono.right=mono.left; + const auto on=tune(mono,rate,true); + need(on.left==on.right,"mono lead acquired a stereo discrepancy"); + const auto dry=tune(mono,rate,false); + const auto disabled=tune(mono,rate,true,127,.5f,rate); + need(std::equal(disabled.left.begin()+rate+rate/10,disabled.left.end(), + dry.left.begin()+rate+rate/10), + "disable did not return to sample-exact delayed lead"); + for(int i=rate;i=melody+role.minInterval&¬e<=melody+role.maxInterval, + "diatonic singer crossed its register band"); + need(std::find(scale.begin(),scale.end(),(note-key)%12)!=scale.end(), + "diatonic singer left the selected key"); + } + } + } + } + VoicePlanner planner; + planner.plan(69,0,major); + const int high=planner.target(2); + planner.plan(67,0,major); + need(planner.target(2)==high,"HIGH missed a stable common tone"); + planner.reset(); + planner.plan(67,0,major); + need(planner.target(2)!=high,"reset retained previous phrase voicing"); +} int main(){ + testLeadTune(); + testVoicePlanner(); // Each Engine owns fixed ring buffers. Allocate offline fixtures on heap: // many simultaneous stack-local instances exceed the Windows CTest stack. static_assert(sizeof(Engine)>64*1024,"verify test heap-fixture rationale"); @@ -594,12 +723,21 @@ int main(){ need(Engine::prepareSettings(settings,modern)&& Engine::prepareSettings(settings,legacy,false), "prepared Harmony wet staging rejected"); - for(int voice=0;voiceprior*1.73f,"prepared Harmony pan lost presence or normalization"); + energy+=level*level; + if(singerActive(singers[voice].role,voices)){ + ++count; + need(level>prior*1.73f&&levelmodern.mixR[0]&&modern.mixR[2]>modern.mixL[2], + "LOW/HIGH changed sides when voice count changed"); } // 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/native_harmony_assembly_test.py b/tests/native_harmony_assembly_test.py index 84d68a3f7..6c2d9a15d 100644 --- a/tests/native_harmony_assembly_test.py +++ b/tests/native_harmony_assembly_test.py @@ -160,7 +160,10 @@ def test_reference_inspired_wide_harmony_and_exact_shared_fx_chrome(self): self.assertIn("Number.isInteger(s.voices)&&s.voices>=2&&s.voices<=5",self.ui) engine=(ROOT/"engine/builtin_fx/HarmonyDsp.h").read_text("utf-8") self.assertIn("static constexpr int maxVoices=5",engine) - self.assertIn("std::array filtered_",engine) + self.assertIn("leadShifter_.processStereo(",engine) + self.assertIn('role="switch"',self.ui) + self.assertIn('String(!syncing&&settings.correction)',self.ui) + self.assertNotIn("correction:true",self.ui) self.assertIn(".mx-harm-scale button.active{",self.css) self.assertIn("flex:1 1 0;min-width:0;height:27px",self.css) self.assertIn("var(--dial-sweep,0deg)",self.css) diff --git a/tools/harmony_offline_ab.cpp b/tools/harmony_offline_ab.cpp index de612a792..1f987fd0b 100644 --- a/tools/harmony_offline_ab.cpp +++ b/tools/harmony_offline_ab.cpp @@ -207,7 +207,28 @@ int main(int argc,char** argv){ 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;} + if(argc==6&&std::string(argv[1])=="--lead-tune"){ + const auto input=readWave(argv[2]); + const fs::path folder=argv[3]; + fs::create_directories(folder); + Settings s; + s.wet=0.f;s.key=std::stoi(argv[4]);s.scale=std::stoi(argv[5]); + const auto dry=process(input,s,true); + s.correction=true; + const auto tuned=process(input,s,true); + writeWave(folder/"lead-dry.wav",dry); + writeWave(folder/"lead-pitch-tune.wav",tuned); + s.correction=false;s.wet=.45f; + const auto mix=process(input,s,true); + writeWave(folder/"lead-and-backing.wav",mix); + writeWave(folder/"backing-only.wav",subtract(mix,dry)); + return 0; + } + if(argc!=3){ + std::cerr<<"usage: harmony_offline_ab input.wav output_directory\n" + <<" harmony_offline_ab --lead-tune input.wav output_directory key scale\n"; + return 1; + } renderAb(readWave(argv[1]),argv[2]); std::cout<<"WAV A/B written. No human-singing/formant qualification implied.\n"; return 0; From a1ef2265624b8cfc6248064a2ee45b6313b8e92e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 03:48:05 +0700 Subject: [PATCH 02/25] fix(harmony): stabilize quiet/high backing and expose Duo * fix(harmony): keep stable signed epochs for quiet/high backing vowels * fix(harmony): bridge brief pitch-confidence gaps and prevent PSOLA dropout noise * test(harmony): cover soft soprano signed epochs and 64/257 block parity * fix(harmonice-ui): expose supported two-harmony-voice Duo selector * test(gui): exercise Natural Duo preset and direct two-voice native readback * test(harmony): assert VOICES 2 and Duo preset parity in approved editor * style(harmonice): fit four voice buttons on compact editor widths --- engine/builtin_fx/HarmonyDsp.h | 38 ++++++++++++-- engine/builtin_fx/HarmonyPitchSynchronous.h | 51 +++++++++++++------ site/preview-v2/assets/mixer-fx-rack.css | 9 ++-- .../preview-v2/assets/mixer-native-harmony.js | 2 +- tests/approved_native_harmony_smoke.py | 12 ++++- tests/harmony_pitch_synchronous_test.cpp | 25 +++++++-- tests/native_harmony_assembly_test.py | 3 ++ 7 files changed, 109 insertions(+), 31 deletions(-) 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 + +