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
9 changes: 8 additions & 1 deletion engine/builtin_fx/ChannelHarmonyProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,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){
// Disconnected ChannelId must reacquire from fresh music, rather
// than instantly reinstating the pre-dropout detector estimate
// when source PCM resumes. Reset exactly once at the timeout;
// repeated missing-source callbacks do no detector housekeeping.
guide_.reset();
dsp_.setGuideKey(-1,-1);
guideObservedKey_.store(-1,std::memory_order_relaxed);
guideObservedScale_.store(-1,std::memory_order_relaxed);
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