Skip to content
Closed
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
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
15 changes: 15 additions & 0 deletions tests/harmony_bypass_reliability_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ static LiveChannelFxGraph::InstanceLease makeHarmony(
p->prepareToPlay(rate,quantum);
const int declaredLatency=2*static_cast<int>(std::round(rate*.016));
assert(p->isReady() && p->getLatencySamples()==declaredLatency);
// Prepared built-in host metadata drives the live FxInstance envelope.
// A zero JUCE rate shortened 8 ms to just 64 frames at 48/96 kHz.
assert(std::abs(p->getSampleRate()-rate)<1.e-6);
armix::harmony::Settings rich;
rich.voices=5;rich.wet=wet;rich.space=space;
assert(p->queueAccepted(rich,9001));
Expand Down Expand Up @@ -252,6 +255,18 @@ int main() {
verifiedWet+=wetCount;verifiedDry+=dryCount;
assert(!cycle.rackBypassed(vocal));
assert(!b->bypassRequested.load(std::memory_order_acquire));
// Test the actual FX lease envelope, not an isolated Fade helper.
// Every WET/Space and callback-size variant must retain 8 ms at the
// device rate rather than falling back to 64 samples.
b->bypassFade.request(true);
int fadeFrames=0;
while(b->bypassFade.transitioning()&&fadeFrames<4096){
b->bypassFade.next();
++fadeFrames;
}
assert(fadeFrames<4096);
const int expectedFade=static_cast<int>(std::round(cfg.rate*.008));
assert(std::abs(fadeFrames-expectedFade)<=1);
}
std::cout<<"Harmony multi-rate wet/space bypass matrix PASS; "
<<"scenarios="<<cases.size()
Expand Down
43 changes: 42 additions & 1 deletion tests/harmony_music_bank_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,51 @@ int main(){
// ages out safely without touching physical routing/output authority.
for(int i=0;i<950;++i) {
float l[128]{},r[128]{};
bank(vocal,l,r,128);
for(int j=0;j<128;++j) {
const double t=static_cast<double>(i*128+j)/48000.;
l[j]=r[j]=static_cast<float>(.20*std::sin(
6.28318530718*220.*t));
}
bank(vocal,l,r,128); // singer remains live during guide loss
for(int j=0;j<128;++j)
assert(std::isfinite(l[j])&&std::isfinite(r[j]));
}
assert(live->observedNote()>=0); // no lead/pitch-analysis interruption
assert(live->observedMusicKey()==-1);
assert(live->effectiveKeyCode()==14); // music absent: manual D minor
// Regression: resuming a missing music ChannelId must NOT reuse its
// previously acquired key after two seconds of missing PCM. The old
// detector retained a valid C-major estimate and immediately published
// it on the first resumed source block, before any new tonal evidence.
{
float resumedL[128]{},resumedR[128]{};
for(int j=0;j<128;++j){
const double t=static_cast<double>(j)/48000.;
resumedL[j]=resumedR[j]=static_cast<float>(.09*(
std::sin(6.28318530718*220.*t)+
std::sin(6.28318530718*261.625565*t)+
std::sin(6.28318530718*329.627557*t)));
}
const float originalL=resumedL[17],originalR=resumedR[17];
bank(music,resumedL,resumedR,128);
assert(resumedL[17]==originalL&&resumedR[17]==originalR);
assert(live->observedMusicKey()==-1);
assert(live->effectiveKeyCode()==14); // no stale C major flash
}
// Fresh A-minor guide must eventually retune after reacquisition.
for(int block=0;block<1450;++block){
float l[128]{},r[128]{};
for(int j=0;j<128;++j){
const double t=static_cast<double>(block*128+j)/48000.;
l[j]=r[j]=static_cast<float>(.09*(
std::sin(6.28318530718*220.*t)+
std::sin(6.28318530718*261.625565*t)+
std::sin(6.28318530718*329.627557*t)));
}
bank(music,l,r,128);
}
assert(live->observedMusicKey()==9&&live->observedMusicScale()==1);
assert(live->effectiveKeyCode()==21);
juce::MemoryBlock saved;
live->getStateInformation(saved);
// Realtime processor owns fixed DSP and reflection rings; production
Expand Down
Loading