diff --git a/engine/builtin_fx/ChannelHarmonyProcessor.h b/engine/builtin_fx/ChannelHarmonyProcessor.h index b54cea5cc..641d4fcff 100644 --- a/engine/builtin_fx/ChannelHarmonyProcessor.h +++ b/engine/builtin_fx/ChannelHarmonyProcessor.h @@ -165,7 +165,7 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor, void getStateInformation(juce::MemoryBlock& out) override { juce::MemoryOutputStream stream(out,false); stream.writeInt(0x41484d31); // AHM1 - stream.writeInt(2); + stream.writeInt(3); stream.writeInt(accepted_.key); stream.writeInt(accepted_.scale); stream.writeInt(accepted_.voices); @@ -176,29 +176,32 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor, stream.writeFloat(accepted_.gainDb); stream.writeInt(accepted_.guideMode); stream.writeInt64(static_cast(accepted_.guideChannelId)); + stream.writeInt(accepted_.voiceMode); } bool restoreUnpublishedState(const void* bytes,int len) { if(published_||!bytes||len<=0||len>128)return false; juce::MemoryInputStream stream(bytes,static_cast(len),false); if(stream.readInt()!=0x41484d31)return false; const int version=stream.readInt(); - if(version!=1&&version!=2)return false; + if(version!=1&&version!=2&&version!=3)return false; armix::harmony::Settings incoming{}; incoming.key=stream.readInt();incoming.scale=stream.readInt(); incoming.voices=stream.readInt();incoming.correction=stream.readBool(); incoming.wet=stream.readFloat();incoming.space=stream.readFloat(); incoming.color=stream.readFloat();incoming.gainDb=stream.readFloat(); - if(version==2){ + if(version>=2){ incoming.guideMode=stream.readInt(); const auto guide=stream.readInt64(); if(guide<0)return false; incoming.guideChannelId=static_cast(guide); } + if(version==3)incoming.voiceMode=stream.readInt(); + // v1/v2 lacked an explicit Doubler; they stay pitched Harmony. if(stream.getPosition()!=stream.getTotalLength()|| !armix::harmony::valid(incoming))return false; if(ready_&&!dsp_.setSettings(incoming))return false; // NativeMixerSessionFxRestore restores AFTER prepareToPlay. An accepted - // v2 ChannelId must become the actual AUDIO guide source, not merely a + // v2/v3 ChannelId must become the actual AUDIO guide source, not merely a // saved GUI value. This is unpublished/control-thread only. if(ready_) { guide_.reset(); diff --git a/engine/builtin_fx/HarmonyDsp.h b/engine/builtin_fx/HarmonyDsp.h index 648b7a298..2ba3ae867 100644 --- a/engine/builtin_fx/HarmonyDsp.h +++ b/engine/builtin_fx/HarmonyDsp.h @@ -20,6 +20,7 @@ namespace armix::harmony { struct Settings { int key=0, scale=0, voices=3; // C=0..B=11; 0=major, 1=natural minor; 2..5 voices + int voiceMode=0; // 0=pitched harmony (2-5), 1=true unison doubler (one wet take) bool correction=false; // Manual is always the trusted fallback. Music follows another accepted // ChannelId only after stable chroma confidence (never a PCM route). @@ -29,6 +30,7 @@ struct Settings { }; inline bool valid(const Settings& s) noexcept { return s.key>=0&&s.key<12&&s.scale>=0&&s.scale<=1&& + s.voiceMode>=0&&s.voiceMode<=1&& s.guideMode>=0&&s.guideMode<=1&& (s.guideMode==0?s.guideChannelId==0:s.guideChannelId>0)&& s.voices>=2&&s.voices<=5&&std::isfinite(s.wet)&&s.wet>=0&&s.wet<=1&& @@ -157,6 +159,19 @@ class Engine final { prepared.settings=next; prepared.gain=std::pow(10.f,next.gainDb/20.f); constexpr float pi=3.14159265358979323846f; + if(next.voiceMode==1){ + // Real unison double, NOT 2 pitched harmony voices. One + // independently windowed take follows source F0 at unity ratio. + // A tiny prepared left-back offset plus the existing shared + // room/detune/arrival give a second-take character. + const float pan=-.40f*next.space; + const float angle=(pan+1.f)*pi*.25f; + const float amount=next.wet*(.77f+.38f*next.wet)*.74f; + prepared.mixL[0]=amount*std::cos(angle); + prepared.mixR[0]=amount*std::sin(angle); + out=prepared; + return true; + } float profileEnergy=0.f; for(const auto& singer:singers) if(singerActive(singer.role,next.voices)) @@ -192,6 +207,12 @@ class Engine final { } if(settings_.correction&&!next.settings.correction) leadTune_.release(); + if(next.settings.voiceMode!=settings_.voiceMode){ + // Re-evaluate note targets on the next accepted analysis, + // without stopping the dry singer or reinitializing the room. + tonalTransitionPending_=true; + if(next.settings.voiceMode==1)targetRatio_.fill(1.f); + } settings_=next.settings; targetWet_=next.settings.wet;targetColor_=next.settings.color; targetSpace_=next.settings.space; @@ -563,7 +584,11 @@ class Engine final { } const int activeKey=effectiveKey(),activeScale=effectiveScale(); const int degree=nearestDegree(midi,activeKey,activeScale); - int note=noteAt(degree,activeKey,activeScale); + // In DOUBLE the source's own melody is authoritative, not the key + // wheel's diatonic quantization. Harmony keeps the existing scale. + int note=settings_.voiceMode==1? + static_cast(std::lround(midi)): + noteAt(degree,activeKey,activeScale); if(!tonalTransitionPending_ && !pitchChangeHasMargin(currentNote_,note,midi)){ note=currentNote_; @@ -586,7 +611,9 @@ class Engine final { leadTune_.observe(midi,note,confidence); } if(note!=currentNote_||tonalTransitionPending_){ - voicePlanner_.plan(note,activeKey,activeScale==0?major:minor); + if(settings_.voiceMode==0) + voicePlanner_.plan(note,activeKey,activeScale==0?major:minor); + else voicePlanner_.reset(); ensemble_.beginNote(); } currentNote_=note;voiced_=true;tonalTransitionPending_=false; @@ -606,11 +633,17 @@ class Engine final { }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); - for(std::size_t v=0;v @@ -33,6 +34,10 @@ root.innerHTML=` +