Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ui-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
needs: quick
# Run dedicated Vocal Throw visual validation in the reconciled native
# engine branch too; generic /preview/ smoke does not call this fixture.
if: ${{ github.event_name == 'pull_request' && (startsWith(github.head_ref, 'feature/arson-vocal-throw-') || startsWith(github.head_ref, 'integration/arson-vocal-throw-') || github.head_ref == 'integration/asio4all-harmony-d4-compat-20261109') }}
if: ${{ github.event_name == 'pull_request' && (startsWith(github.head_ref, 'feature/arson-vocal-throw-') || startsWith(github.head_ref, 'integration/arson-vocal-throw-') || github.head_ref == 'fix/p0-reconcile-native-asio-harmony-20261110' || github.head_ref == 'integration/asio4all-harmony-d4-compat-20261109') }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
Expand Down
22 changes: 19 additions & 3 deletions engine/builtin_fx/ChannelHarmonyProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,24 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor,
return b.getMainInputChannelSet()==juce::AudioChannelSet::stereo() &&
b.getMainOutputChannelSet()==juce::AudioChannelSet::stereo();
}
void prepareToPlay(double rate,int) override {
void prepareToPlay(double rate,int maximumExpectedSamplesPerBlock) override {
ready_=dsp_.prepare(rate)&&guide_.prepare(rate)&&dsp_.setSettings(accepted_);
guideSource_.store(accepted_.guideMode==1?accepted_.guideChannelId:0,
std::memory_order_release);
guideAge_=0;guideObservedKey_.store(-1,std::memory_order_relaxed);
guideObservedScale_.store(-1,std::memory_order_relaxed);
guideConfidence_.store(0.f,std::memory_order_relaxed);
publishEffectiveKey();
if(ready_) {sampleRate_=rate;setLatencySamples(dsp_.latencySamples());}
if(ready_) {
// FxInstance samples the AudioProcessor rate once, when its fixed
// 8 ms bypass envelope is prepared. Native built-ins are prepared
// directly; without JUCE rate metadata it otherwise sees zero
// and fades in only 64 samples at real 48/96 kHz device rates.
setRateAndBufferSizeDetails(rate,
std::max(1,maximumExpectedSamplesPerBlock));
sampleRate_=rate;
setLatencySamples(dsp_.latencySamples());
}
}
void releaseResources() override {ready_=false;}
void processBlock(juce::AudioBuffer<float>& samples,juce::MidiBuffer&) override {
Expand All @@ -50,9 +59,16 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor,
consumeRealtimeEdits();
// Missing/deleted/disconnected source must not leave a stale accepted
// tonal estimate running indefinitely. Manual Key is the fallback.
const int guideTimeout=static_cast<int>(sampleRate_*2.);
const bool guideWasFresh=guideAge_<=guideTimeout;
guideAge_=std::min(guideAge_+samples.getNumSamples(),
static_cast<int>(sampleRate_*3.));
if(guideAge_>static_cast<int>(sampleRate_*2.)){
if(guideWasFresh&&guideAge_>guideTimeout){
// The guide source went missing. A detector that still retains
// old chroma would publish the old key on the FIRST resumed
// source block, before gathering fresh evidence. Invalidate once
// at the missing-source boundary, not at every audio callback.
guide_.reset();
dsp_.setGuideKey(-1,-1);
guideObservedKey_.store(-1,std::memory_order_relaxed);
guideObservedScale_.store(-1,std::memory_order_relaxed);
Expand Down
133 changes: 106 additions & 27 deletions engine/builtin_fx/VocalThrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,38 @@ class VocalThrow final {
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.
// AUDIO ONLY. A click DURING a syllable is a musical intent, not an
// immediate splice. The singer finishes naturally; we freeze at the
// verified end boundary. A second click cancels the queued intent.
// An already completed phrase (last 700ms) is fired immediately.
bool throwNow() noexcept {
if(!ready_||recorded_==0||lastSoundEnd_==0||clock_<lastSoundEnd_)return false;
if(!ready_)return false;
if(cueArmed_) {
cueArmed_=cueSawVoice_=false; // deliberate performer cancellation
return true;
}
const auto recent=static_cast<std::uint64_t>(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;
const auto gap=static_cast<std::uint32_t>(rate_*.06);
const bool finished=lastSoundEnd_>0&&quiet_>=gap&&
clock_>=lastSoundEnd_&&clock_-lastSoundEnd_<=recent;
if(finished) {
// AUTO/HYBRID has already consumed this phrase.
if(lastSoundEnd_==autoTriggeredPhraseEnd_)return false;
const bool fired=freezeAt(lastSoundEnd_);
if(fired) {
manualInCurrentPhrase_=true;
armed_=false;
}
return fired;
}
// Even before the first microphone frame, arm ONE future phrase.
// Never retain the cue past four seconds or a device/bypass reset.
cueArmed_=true;
cueSawVoice_=armed_ && lastSoundEnd_>0;
cueDeadline_=clock_+static_cast<std::uint64_t>(rate_*4.);
return true;
}
[[nodiscard]] bool cueArmed() const noexcept{return cueArmed_;}
void processStereo(float* left,float* right,std::size_t frames) noexcept {
if(!ready_||!left||!right)return;
const bool mono=left==right;
Expand All @@ -147,21 +165,38 @@ class VocalThrow final {
const float coeff=peak>envelope_?envAttack_:envRelease_;
envelope_=coeff*envelope_+(1.f-coeff)*peak;
if(envelope_<1.0e-20f)envelope_=0.f;
const bool singing=envelope_>=settings_.gateLinear;
// Update ambient floor only when the vocal envelope is quiet.
// Gate hysteresis avoids chattering at syllable tails; never
// change the lead vocal dry PCM or demand calibration from user.
const float gate=std::max(settings_.gateLinear,noiseFloor_*3.0f);
const bool singing=envelope_>=gate*(quiet_==0?.75f:1.f);
if(singing) {
if(quiet_>phraseGap) {
voiced_=0;
manualInCurrentPhrase_=false; // genuinely new sung phrase
autoTriggeredPhraseEnd_=0;
if(quiet_>phraseGap || lastWordStart_==0) {
lastWordStart_=clock_;
if(quiet_>phraseGap) {
voiced_=0;
manualInCurrentPhrase_=false;
autoTriggeredPhraseEnd_=0;
}
}
quiet_=0;
voiced_=std::min(voiced_+1,maxQuiet);
lastSoundEnd_=clock_;
if(voiced_>=minVoice)armed_=true;
if(voiced_>=minVoice) {
armed_=true;
if(cueArmed_)cueSawVoice_=true;
}
} else {
if(quiet_<maxQuiet)++quiet_; // never wrap during multi-hour sessions
noiseFloor_=noiseFloor_*.9998f+peak*.0002f;
if(armed_ && quiet_>=settings_.silenceSamples) {
if(settings_.settings.mode!=0 && !manualInCurrentPhrase_
// Manual queued cue gets priority over AUTO/HYBRID.
// Freeze the completed phrase, not the middle of a word.
if(cueArmed_ && cueSawVoice_) {
if(freezeAt(lastSoundEnd_))
manualInCurrentPhrase_=true;
cueArmed_=cueSawVoice_=false;
} else if(settings_.settings.mode!=0 && !manualInCurrentPhrase_
&& clock_>=nextAutoEligible_) {
if(freezeAt(lastSoundEnd_)) {
autoTriggeredPhraseEnd_=lastSoundEnd_;
Expand All @@ -172,6 +207,8 @@ class VocalThrow final {
armed_=false;
}
}
if(cueArmed_ && clock_>=cueDeadline_)
cueArmed_=cueSawVoice_=false; // bounded stale-cue expiry
float echoL=0.f,echoR=0.f,activeTapGain=0.f;
for(auto& voice:voices_) {
if(voice.copying)copyFrozenChunk(voice);
Expand All @@ -193,7 +230,31 @@ class VocalThrow final {
}
const auto p=static_cast<std::size_t>(offset);
const float gain=voice.repeatGains[slot]*std::max(0.f,ramp);
echoL+=voice.freezeL[p]*gain;echoR+=voice.freezeR[p]*gain;
// Ping-pong is wet-only. A true stereo source is folded
// to a stable wet mid, then positioned alternately L/R;
// the dry original is preserved sample-for-sample.
const float mid=.5f*(voice.freezeL[p]+voice.freezeR[p]);
auto& lowpass=voice.tapTone[slot];
const float alpha=.58f/(1.f+.22f*static_cast<float>(tap));
lowpass+=alpha*(mid-lowpass);
const float tone=(.75f-.07f*static_cast<float>(tap))*mid+
(.25f+.07f*static_cast<float>(tap))*lowpass;
// Tiny asymmetric early reflection = spatial depth;
// bounded reads only from the already frozen phrase,
// never a second realtime delay allocation or HRTF.
const auto reflectionOffset=voice.reflectionSamples;
const float reflection=p>=reflectionOffset?
.5f*(voice.freezeL[p-reflectionOffset]+
voice.freezeR[p-reflectionOffset]):0.f;
const float direct=tone*gain;
const float room=reflection*gain*.115f;
if((tap&1)==0) {
echoL+=direct*.93f;
echoR+=direct*.23f+room;
} else {
echoR+=direct*.93f;
echoL+=direct*.23f+room;
}
activeTapGain+=gain;
}
const auto end=voice.repeatStarts[
Expand Down Expand Up @@ -224,9 +285,10 @@ class VocalThrow final {
void invalidateCaptureHistory() noexcept {
recorded_=0;
lastSoundEnd_=nextAutoEligible_=autoTriggeredPhraseEnd_=0;
lastWordStart_=cueDeadline_=0;
voiced_=quiet_=0;
armed_=manualInCurrentPhrase_=false;
envelope_=0.f;
armed_=manualInCurrentPhrase_=cueArmed_=cueSawVoice_=false;
noiseFloor_=0.f;envelope_=0.f;
for(auto& voice:voices_) {
voice.copying=false;voice.playing=false;
voice.freezeCount=0;voice.copyIndex=0;
Expand All @@ -245,10 +307,11 @@ class VocalThrow final {
std::vector<float> freezeL,freezeR;
std::array<std::uint64_t,maxRepeats> repeatStarts{};
std::array<float,maxRepeats> repeatGains{};
std::array<float,maxRepeats> tapTone{}; // voice-owned HF damping
PreparedEdit active{};
std::uint64_t copyEnd=0,freezeCount=0;
std::size_t copyIndex=0,sourceIndex=0;
std::uint32_t edgeSamples=0;
std::uint32_t edgeSamples=0,reflectionSamples=0;
std::uint64_t gridAnchorFrame=0,gridCueFrame=0,gridCueLocal=0;
bool gridValid=false;
bool copying=false,playing=false;
Expand All @@ -263,13 +326,20 @@ class VocalThrow final {
}
if(!slot)return false;
const auto available=std::min<std::uint64_t>(end,recorded_);
const auto count=std::min<std::uint64_t>(available,settings_.captureSamples);
auto count=std::min<std::uint64_t>(available,settings_.captureSamples);
// Prefer the actual last voiced onset (including 28ms consonant
// preroll) over an arbitrary fixed-size slice of the previous word.
const auto pre=static_cast<std::uint64_t>(rate_*.028);
const auto onset=lastWordStart_>pre?lastWordStart_-pre:0;
if(onset>0&&onset<end)count=std::min(count,end-onset);
if(count<static_cast<std::uint64_t>(rate_*.025))return false;
slot->copyEnd=end;
slot->freezeCount=count;
slot->copyIndex=0;
slot->sourceIndex=static_cast<std::size_t>((end-count)%historyL_.size());
slot->edgeSamples=static_cast<std::uint32_t>(rate_*.004);
slot->reflectionSamples=static_cast<std::uint32_t>(rate_*.011);
slot->tapTone.fill(0.f);
slot->active=settings_;
if(musicIntervalSamples_)
slot->active.intervalSamples=musicIntervalSamples_;
Expand Down Expand Up @@ -313,7 +383,11 @@ class VocalThrow final {
if(globalFirst>=voice.gridAnchorFrame) {
const auto remainder=
(globalFirst-voice.gridAnchorFrame)%interval;
if(remainder)first+=interval-remainder;
// Never wait nearly another beat just to satisfy a stale
// onset lattice. Small phase correction is musical; a full
// extra delay is not. Upper bound = one quarter subdivision.
if(remainder && interval-remainder<=interval/4)
first+=interval-remainder;
} else if(voice.gridAnchorFrame-globalFirst<=interval) {
first+=voice.gridAnchorFrame-globalFirst;
}
Expand All @@ -330,10 +404,11 @@ class VocalThrow final {
}
void reset() noexcept {
clock_=lastSoundEnd_=nextAutoEligible_=autoTriggeredPhraseEnd_=0;
lastWordStart_=cueDeadline_=0;
recorded_=writeIndex_=0;
voiced_=quiet_=0;
armed_=manualInCurrentPhrase_=false;
envelope_=0.f;duck_=1.f;throwCount_=0;
armed_=manualInCurrentPhrase_=cueArmed_=cueSawVoice_=false;
noiseFloor_=0.f;envelope_=0.f;duck_=1.f;throwCount_=0;
wetSmoothed_=settings_.settings.wet;
if(rate_>0) {
envAttack_=static_cast<float>(std::exp(-1./(rate_*.004)));
Expand All @@ -343,7 +418,8 @@ class VocalThrow final {
for(auto& voice:voices_) {
voice.copyEnd=voice.freezeCount=0;
voice.copyIndex=voice.sourceIndex=0;
voice.edgeSamples=0;
voice.edgeSamples=voice.reflectionSamples=0;
voice.tapTone.fill(0.f);
voice.copying=voice.playing=false;
voice.gridValid=false;
voice.gridAnchorFrame=voice.gridCueFrame=voice.gridCueLocal=0;
Expand All @@ -356,15 +432,18 @@ class VocalThrow final {
std::vector<float> historyL_,historyR_;
std::array<TailVoice,2> voices_{};
std::uint64_t clock_=0,lastSoundEnd_=0,nextAutoEligible_=0,autoTriggeredPhraseEnd_=0;
std::uint64_t lastWordStart_=0,cueDeadline_=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 noiseFloor_=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;
bool cueArmed_=false,cueSawVoice_=false;
};
} // namespace armix::builtin_fx
7 changes: 6 additions & 1 deletion engine/builtin_fx/VocalThrowProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class VocalThrowProcessor final : public juce::AudioProcessor,
static_cast<std::size_t>(pcm.getNumSamples()));
observedThrows_.store(core_.throwCount(),std::memory_order_relaxed);
observedTail_.store(core_.echoActive(),std::memory_order_relaxed);
observedCueArmed_.store(core_.cueArmed(),std::memory_order_relaxed);
}
void processBlock(juce::AudioBuffer<double>&,juce::MidiBuffer&) override{}
void onRealtimeBypass(bool requested,bool fully) noexcept override {
Expand All @@ -87,6 +88,7 @@ class VocalThrowProcessor final : public juce::AudioProcessor,
if(clear&&ready_) {
core_.invalidateCaptureHistory();
observedTail_.store(false,std::memory_order_relaxed);
observedCueArmed_.store(false,std::memory_order_relaxed);
}
if(requested&&fully)captureInvalidated_=true;
if(!requested)captureInvalidated_=false;
Expand Down Expand Up @@ -206,6 +208,9 @@ class VocalThrowProcessor final : public juce::AudioProcessor,
bool observedTailActive() const noexcept {
return observedTail_.load(std::memory_order_relaxed);
}
bool observedCueArmed() const noexcept {
return observedCueArmed_.load(std::memory_order_relaxed);
}
bool isReady() const noexcept{return ready_;}
void sealForRealtime() noexcept override{published_=true;}
bool stateSnapshotQuiescent() const noexcept override{
Expand Down Expand Up @@ -266,7 +271,7 @@ class VocalThrowProcessor final : public juce::AudioProcessor,
std::array<std::atomic<std::uint64_t>,32> cancelledIds_{};
std::uint32_t cancelWrite_=0; // CONTROL only
bool bypassed_=false,captureInvalidated_=false; // AUDIO only
std::atomic<bool> observedTail_{false};
std::atomic<bool> observedTail_{false},observedCueArmed_{false};
double rate_=0.;
float lastTempoBpm_=0.f; // CONTROL only
int lastTempoDivision_=-1; // CONTROL only
Expand Down
Loading
Loading