Skip to content
Merged
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
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,18 @@ if(BUILD_TESTING)
target_link_libraries(ARMixHarmonyChannelPcmTests PRIVATE juce::juce_audio_processors juce::juce_recommended_config_flags)
target_compile_features(ARMixHarmonyChannelPcmTests PRIVATE cxx_std_20)
add_test(NAME NativeHarmonyMusicFromOtherChannelIdAndStateMigration COMMAND ARMixHarmonyChannelPcmTests)
# Explicit FX lease + ChannelId PCM regression: continuous Harmony DSP on
# disabled insert/rack, exact dry PDC and state-identical wet reactivation.
juce_add_console_app(ARMixHarmonyBypassPcmTests PRODUCT_NAME "ArSonMix Harmony Clickless Bypass PCM")
target_sources(ARMixHarmonyBypassPcmTests PRIVATE tests/harmony_bypass_reliability_test.cpp)
target_link_libraries(ARMixHarmonyBypassPcmTests PRIVATE
juce::juce_audio_processors juce::juce_recommended_config_flags)
target_compile_features(ARMixHarmonyBypassPcmTests PRIVATE cxx_std_20)
add_test(NAME NativeHarmonyWarmBypassRackSlotAndLatencyParity COMMAND ARMixHarmonyBypassPcmTests)
add_test(NAME ApprovedNativeHarmonyEditorAckAndSingleGui COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_harmony_assembly_test.py")
add_executable(ARMixMixerRoutingTests tests/mixer_routing_plan_test.cpp)
target_compile_features(ARMixMixerRoutingTests PRIVATE cxx_std_20)
add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests ARMixHarmonyCpuProfileTests)
add_dependencies(ARMixMixerRoutingTests ARMixHarmonyDspTests ARMixHarmonyMusicGuideTests ARMixHarmonyChannelPcmTests ARMixHarmonyBypassPcmTests ARMixHarmonyCpuProfileTests)
add_test(NAME TenStripStaticRoutingAndMaster COMMAND ARMixMixerRoutingTests)
# M3D atomic native Session: the accepted Console roster cannot advance
# without a successful epoch/revision-gated PCM publication.
Expand Down
1 change: 1 addition & 0 deletions engine/builtin_fx/ChannelHarmonyProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor,
}
double acceptedSampleRate() const noexcept {return sampleRate_;}
bool isReady() const noexcept{return ready_;}
bool requiresContinuousBypassProcessing() const noexcept override {return true;}
void sealForRealtime() noexcept override {published_=true;}
bool stateSnapshotQuiescent() const noexcept override {
return queued_.empty()&&completion_.empty()&&!pendingId_;
Expand Down
20 changes: 13 additions & 7 deletions engine/builtin_fx/HarmonyDsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Engine final {
pitchActive_=false;pitchBest_=-1.f;pitchBestLag_=0;
peakPitchLagWork_=0;completedPitchAnalyses_=0;abandonedPitchAnalyses_=0;
noteHold_=0;currentNote_=-1;candidateNote_=-1;
guideKey_=-1;guideScale_=-1;
guideKey_=-1;guideScale_=-1;tonalTransitionPending_=false;
voiced_=false;voicedGain_=0.f;settings_=Settings{};
smoothingAlpha_=static_cast<float>(1.-std::exp(-1./(rate*0.005))); // 5 ms control ramp
// Preserve the established 48k envelope while keeping durations
Expand Down Expand Up @@ -164,12 +164,14 @@ class Engine final {
}
bool applyPreparedSettings(const PreparedSettings& next) noexcept {
// Caller publishes only prepareSettings()-validated packets.
// A scale/key change must not inherit the previous tonal quantizer
// candidate or remain held on a now-out-of-scale note.
// Discard only the TONAL candidate on a key/source edit. The singer's
// current voiced envelope, source period and active grains continue.
// Next completed pitch windows retune to the new scale, bypassing
// old-key note hysteresis exactly until a new note is confirmed.
if(next.settings.key!=settings_.key||next.settings.scale!=settings_.scale||
next.settings.guideMode!=settings_.guideMode||
next.settings.guideChannelId!=settings_.guideChannelId){
candidateNote_=-1;currentNote_=-1;noteHold_=0;voiced_=false;
candidateNote_=-1;noteHold_=0;tonalTransitionPending_=true;
}
if(next.settings.guideMode!=settings_.guideMode||
next.settings.guideChannelId!=settings_.guideChannelId){
Expand Down Expand Up @@ -207,7 +209,9 @@ class Engine final {
const int previousKey=effectiveKey(),previousScale=effectiveScale();
guideKey_=key;guideScale_=scale;
if(previousKey!=effectiveKey()||previousScale!=effectiveScale()){
currentNote_=-1;candidateNote_=-1;noteHold_=0;voiced_=false;
// A guide-key revision is not vocal silence. Preserve the
// continuous sound and retune at the next stable pitch evidence.
candidateNote_=-1;noteHold_=0;tonalTransitionPending_=true;
}
}
int effectiveKey() const noexcept {
Expand Down Expand Up @@ -504,7 +508,8 @@ class Engine final {
const int activeKey=effectiveKey(),activeScale=effectiveScale();
int degree=nearestDegree(midi,activeKey,activeScale);
int note=noteAt(degree,activeKey,activeScale);
if(!pitchChangeHasMargin(currentNote_,note,midi)){
if(!tonalTransitionPending_ &&
!pitchChangeHasMargin(currentNote_,note,midi)){
note=currentNote_;
degree=nearestDegree(static_cast<float>(note),activeKey,activeScale);
}
Expand All @@ -515,7 +520,7 @@ class Engine final {
// 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;
currentNote_=note;voiced_=true;tonalTransitionPending_=false;
const float newPeriod=static_cast<float>(rate_/hz);
if(sourcePeriodSamples_>0.f&&
std::abs(newPeriod-sourcePeriodSamples_)>.25f*sourcePeriodSamples_){
Expand Down Expand Up @@ -553,6 +558,7 @@ class Engine final {
std::array<float,231> pitchCorrelations_{};
int currentNote_=-1,candidateNote_=-1,noteHold_=0;
int guideKey_=-1,guideScale_=-1;
bool tonalTransitionPending_=false; // retune note, never mute voiced singer
bool voiced_=false;float voicedGain_=0.f;
bool processed_=false;
float smoothingAlpha_=1.f,voicedGateAlpha_=0.002f,ratioAlpha_=0.00045f;
Expand Down
19 changes: 16 additions & 3 deletions engine/core/LiveChannelFxGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LiveChannelFxGraph final {
struct FxInstance final : juce::AudioProcessorListener {
std::unique_ptr<Processor> processor;
RealtimeNativeFxControl* nativeControl=nullptr; // bound once OFF realtime
bool continuousBypassProcessing=false; // prepared once; no dynamic cast in RT
juce::MidiBuffer midi;
const juce::String catalogId;
const juce::String name;
Expand Down Expand Up @@ -61,7 +62,11 @@ class LiveChannelFxGraph final {
bypassFade.prepare(false,processor?processor->getSampleRate():48000.0,0);
if(processor){
nativeControl=dynamic_cast<RealtimeNativeFxControl*>(processor.get());
if(nativeControl)nativeControl->sealForRealtime();
if(nativeControl){
continuousBypassProcessing=
nativeControl->requiresContinuousBypassProcessing();
nativeControl->sealForRealtime();
}
processor->addListener(this);
}
}
Expand Down Expand Up @@ -140,11 +145,16 @@ class LiveChannelFxGraph final {
dryLeft[static_cast<std::size_t>(i)]=l;
dryRight[static_cast<std::size_t>(i)]=r;
}
if(bypassFade.fullyBypassed()||latencyChanged.load(std::memory_order_acquire)) {
const bool fullyBypassed=bypassFade.fullyBypassed();
if((fullyBypassed&&!continuousBypassProcessing)||
latencyChanged.load(std::memory_order_acquire)) {
juce::FloatVectorOperations::copy(left,dryLeft.data(),samples);
juce::FloatVectorOperations::copy(right,dryRight.data(),samples);
processing.clear(std::memory_order_release);return;
}
// Harmony alone remains timeline-warm while fully bypassed.
// The host consumes real PCM, but publishes the exact PDC dry path:
// no stale pitch history or room tail can leak on reactivation.
const bool fading=bypassFade.transitioning();
try {
float* planar[]{left,right};
Expand All @@ -157,7 +167,10 @@ class LiveChannelFxGraph final {
juce::FloatVectorOperations::clear(left,samples);
juce::FloatVectorOperations::clear(right,samples);
}
if(fading)for(int i=0;i<samples;++i) {
if(fullyBypassed){
juce::FloatVectorOperations::copy(left,dryLeft.data(),samples);
juce::FloatVectorOperations::copy(right,dryRight.data(),samples);
} else if(fading)for(int i=0;i<samples;++i) {
const auto mix=bypassFade.next();
left[i]=left[i]*mix.wet+dryLeft[static_cast<std::size_t>(i)]*mix.dry;
right[i]=right[i]*mix.wet+dryRight[static_cast<std::size_t>(i)]*mix.dry;
Expand Down
5 changes: 5 additions & 0 deletions engine/core/RealtimeNativeFxControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace armix::mixer {
struct RealtimeNativeFxControl {
virtual ~RealtimeNativeFxControl() = default;
virtual void consumeRealtimeEdits() noexcept = 0;
// CONTROL-queried once when the native FX lease is prepared. Temporal DSP
// that cannot resume from stale input (Harmony pitch/history/room) must
// continue processing the actual PCM while its output is bypassed.
// Ordinary EQ/compressor/vendor FX retain the CPU-saving bypass fast path.
virtual bool requiresContinuousBypassProcessing() const noexcept {return false;}
// AUDIO callback only. A native performer cue can be dangerous when
// the rack is OFF: while fully bypassed its capture clock stops.
// Default no-op preserves Compressor/EQ/Harmony and vendor FX behavior.
Expand Down
154 changes: 154 additions & 0 deletions tests/harmony_bypass_reliability_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Real JUCE FX instance and native ChannelId PCM lease, not just envelope math.
// The enabled reference must equal the twice-bypassed Harmony AFTER re-entry.
// Old code failed because a fully bypassed Harmony stopped reading live PCM.
#include "../engine/core/DynamicChannelFxLeaseBank.h"
#include "../engine/builtin_fx/ChannelHarmonyProcessor.h"
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include <cassert>
#include <array>
#include <algorithm>
#include <cmath>
#include <memory>
#include <iostream>

using namespace armix::mixer;
using armix::builtin_fx::ChannelHarmonyProcessor;

static float singer(int n) noexcept {
const double t=static_cast<double>(n)/48000.;
return static_cast<float>(.16*std::sin(6.283185307179586*220.*t)+
.045*std::sin(6.283185307179586*440.*t));
}
static LiveChannelFxGraph::InstanceLease makeHarmony() {
auto p=std::make_unique<ChannelHarmonyProcessor>();
p->prepareToPlay(48000.,64);
assert(p->isReady() && p->getLatencySamples()==1536);
armix::harmony::Settings rich;
rich.voices=5;rich.wet=1.f;rich.space=1.f;
assert(p->queueAccepted(rich,9001));
return std::make_shared<LiveChannelFxGraph::FxInstance>(
std::move(p),ChannelHarmonyProcessor::catalogIdentity,
"ArSon Harmony",64);
}
int main() {
constexpr ChannelId vocal{7301};
auto uninterrupted=makeHarmony(), switching=makeHarmony(),legacy=makeHarmony();
assert(switching->continuousBypassProcessing);
// Isolated offline reference of PRE-FIX host behavior; production never
// disables the warm-processing contract. This must diverge on reentry.
legacy->continuousBypassProcessing=false;
assert(uninterrupted->latencySamples==1536);
assert(switching->latencySamples==uninterrupted->latencySamples);
DynamicChannelFxLeaseBank::Assignment referenceRow,switchingRow,legacyRow;
referenceRow.id=vocal;referenceRow.format=ProcessingFormat::stereo;
referenceRow.inserts.push_back(uninterrupted);
switchingRow.id=vocal;switchingRow.format=ProcessingFormat::stereo;
switchingRow.inserts.push_back(switching);
legacyRow.id=vocal;legacyRow.format=ProcessingFormat::stereo;
legacyRow.inserts.push_back(legacy);
DynamicChannelFxLeaseBank alwaysOn,switched,oldBehavior;
const std::array<DynamicChannelFxLeaseBank::Assignment,1> referenceRows{referenceRow};
const std::array<DynamicChannelFxLeaseBank::Assignment,1> switchingRows{switchingRow};
const std::array<DynamicChannelFxLeaseBank::Assignment,1> legacyRows{legacyRow};
assert(DynamicChannelFxLeaseBank::prepare(1,1,legacyRows,oldBehavior)==
DynamicChannelFxLeaseBank::Fault::none);
assert(DynamicChannelFxLeaseBank::prepare(1,1,referenceRows,alwaysOn)==
DynamicChannelFxLeaseBank::Fault::none);
assert(DynamicChannelFxLeaseBank::prepare(1,1,switchingRows,switched)==
DynamicChannelFxLeaseBank::Fault::none);
bool priorSlot=false,priorRack=false;
float maxWetDifference=0.f,maxDryDifference=0.f;
float maxOldBypassDifference=0.f,maxClickSlopeExcess=0.f;
int samplesCheckedWet=0,samplesCheckedDry=0;
float previousWetL=0.f,previousWetR=0.f;
float previousProbeL=0.f,previousProbeR=0.f,previousDry=0.f;
// Fixed 64-frame hardware-shaped partitions, with slot and rack OFF.
// The last pair is a quick reverse-toggle (no graph or callback restart).
for(int block=0;block<1300;++block) {
const bool slotOff=(block>=320&&block<580)||
(block>=700&&block<780)||
(block==1110||block==1112);
const bool rackOff=(block>=850&&block<1000)||
(block==1111||block==1113);
if(slotOff!=priorSlot) {
assert(switched.setInsertBypass(1,1,vocal,0,switching->instanceId,slotOff));
assert(oldBehavior.setInsertBypass(1,1,vocal,0,legacy->instanceId,slotOff));
priorSlot=slotOff;
}
if(rackOff!=priorRack) {
assert(switched.setRackBypass(1,1,vocal,rackOff));
assert(oldBehavior.setRackBypass(1,1,vocal,rackOff));
priorRack=rackOff;
}
std::array<float,64> baseL{},baseR{},probeL{},probeR{},oldL{},oldR{};
for(int i=0;i<64;++i) {
const int n=block*64+i;
baseL[i]=probeL[i]=oldL[i]=singer(n);
baseR[i]=probeR[i]=oldR[i]=singer(n);
}
alwaysOn(vocal,baseL.data(),baseR.data(),64);
switched(vocal,probeL.data(),probeR.data(),64);
oldBehavior(vocal,oldL.data(),oldR.data(),64);
const bool quietBypass=slotOff||rackOff;
const bool steadyWet=!quietBypass &&
(block>=590&&block<700 || block>=790&&block<850 ||
block>=1010&&block<1110 || block>=1125);
const bool steadyDry=quietBypass&&
(block>=330&&block<580 || block>=710&&block<780 ||
block>=860&&block<1000);
for(int i=0;i<64;++i) {
const int n=block*64+i;
const float delayed=n>=1536?singer(n-1536):0.f;
if(n>=1537){
// Actual post-bypass sample slope may only exceed either
// continuous wet or exact aligned dry slope by the 8ms ramp
// contribution. No block-edge impulse is allowed.
const float wetSlope=std::max(std::abs(baseL[i]-previousWetL),
std::abs(baseR[i]-previousWetR));
const float drySlope=std::abs(delayed-previousDry);
const float actualSlope=std::max(std::abs(probeL[i]-previousProbeL),
std::abs(probeR[i]-previousProbeR));
const float excess=actualSlope-std::max(wetSlope,drySlope);
maxClickSlopeExcess=std::max(maxClickSlopeExcess,excess);
assert(excess<.035f);
}
previousWetL=baseL[i];previousWetR=baseR[i];
previousProbeL=probeL[i];previousProbeR=probeR[i];
previousDry=delayed;
assert(std::isfinite(probeL[i])&&std::isfinite(probeR[i]));
assert(std::abs(probeL[i])<=4.f&&std::abs(probeR[i])<=4.f);
if(steadyWet) {
const float d=std::max(std::abs(probeL[i]-baseL[i]),
std::abs(probeR[i]-baseR[i]));
maxWetDifference=std::max(maxWetDifference,d);
assert(d<.00002f); // same exact history as never-bypassed DSP
++samplesCheckedWet;
if(block>=590&&block<615 || block>=790&&block<815)
maxOldBypassDifference=std::max(maxOldBypassDifference,
std::max(std::abs(oldL[i]-baseL[i]),
std::abs(oldR[i]-baseR[i])));
}
if(steadyDry) {
const int n=block*64+i-1536;
const float expect=n>=0?singer(n):0.f;
const float d=std::max(std::abs(probeL[i]-expect),
std::abs(probeR[i]-expect));
maxDryDifference=std::max(maxDryDifference,d);
assert(d<.00002f); // never switch PDC when OFF
++samplesCheckedDry;
}
}
}
assert(samplesCheckedWet>10000&&samplesCheckedDry>10000);
assert(maxOldBypassDifference>.003f); // old skipped DSP history visibly diverges
assert(!switched.rackBypassed(vocal));
std::cout<<"Harmony native ChannelId warm bypass, dry PDC and state parity PASS; "
<<"wet_samples="<<samplesCheckedWet<<" dry_samples="<<samplesCheckedDry
<<" max_wet_difference="<<maxWetDifference
<<" max_dry_difference="<<maxDryDifference
<<" max_old_bypass_difference="<<maxOldBypassDifference
<<" max_click_slope_excess="<<maxClickSlopeExcess<<"\\n";
}
Loading
Loading