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
2 changes: 1 addition & 1 deletion .github/workflows/p1-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
-DBUILD_TESTING=ON
-DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps"
- name: Build executable and native RT tests
run: cmake --build build --config Release --target ARMixConsole ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixWorkspaceTests ARMixVaultTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2
run: cmake --build build --config Release --target ARMixConsole ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixPreparedBusGraphTests ARMixWorkspaceTests ARMixVaultTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2
- name: Test realtime control primitives
run: ctest --test-dir build -C Release --output-on-failure
- name: Package verified JUCE GUI for hardware FAT
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ juce_add_gui_app(ARMixConsole
juce_add_binary_data(ARMixAssets SOURCES
web/index.html web/styles.css web/app.js web/bridge.js web/monitor.js)

target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h)
target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/PreparedBusGraph.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h)
target_compile_definitions(ARMixConsole PRIVATE
JUCE_WEB_BROWSER=1
JUCE_USE_WIN_WEBVIEW2=1
Expand Down Expand Up @@ -53,6 +53,9 @@ if(BUILD_TESTING)
add_executable(ARMixChannelRoutingContractTests tests/channel_routing_contract_test.cpp)
target_compile_features(ARMixChannelRoutingContractTests PRIVATE cxx_std_20)
add_test(NAME MonoStereoSparsePhysicalPortRouting COMMAND ARMixChannelRoutingContractTests)
add_executable(ARMixPreparedBusGraphTests tests/prepared_bus_graph_test.cpp)
target_compile_features(ARMixPreparedBusGraphTests PRIVATE cxx_std_20)
add_test(NAME P1CTenChannelTwoAuxAudioRenderAndCycleRejection COMMAND ARMixPreparedBusGraphTests)
add_executable(ARMixOrbitPhaseTests tests/orbit_phase_test.cpp)
target_compile_features(ARMixOrbitPhaseTests PRIVATE cxx_std_20)
add_test(NAME VstAzimuthOrbitRamp COMMAND ARMixOrbitPhaseTests)
Expand Down
123 changes: 123 additions & 0 deletions engine/core/PreparedBusGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include "ChannelRoutingContract.h"
#include <array>
#include <algorithm>
#include <cmath>
#include <span>
namespace armix::mixer {
// P1C: offline-compiled, no-alloc two-AUX processing graph.
// The physical-port mask and VST lifecycles remain separate native gates.
constexpr int auxBuses=2, routingNodes=stripCount+auxBuses, maxRouteFrames=1024;
enum class RouteKind { none, mono, stereo, strip, aux };
struct RouteNode {
RouteKind kind=RouteKind::none;
int a=-1,b=-1,sendTo=-1;
float sendLevel=0.f,level=1.f;
bool main=true,mute=false;
};
struct RouteSetup {
ChannelRoutingConfig channels{};
std::array<RouteNode,routingNodes> nodes{};
};
enum class RouteError { none,invalidSource,invalidSend,invalidGain,cycle,badDevice };
struct RouteFault {RouteError code=RouteError::none;int node=-1;};
struct PreparedRoutes {
ChannelRoutingPlan device{};
std::array<RouteNode,routingNodes> nodes{};
std::array<int,routingNodes> order{};
static bool compile(const RouteSetup& src,std::span<const int> active,
PreparedRoutes& dst,RouteFault& fault) noexcept {
fault={};
RouteSetup cfg=src;
for(int i=0;i<stripCount;++i){
auto& c=cfg.channels.stripsAndMaster.strips[i];
const auto& s=src.nodes[i];
c.source=s.kind==RouteKind::mono?SourceMode::mono:
s.kind==RouteKind::stereo?SourceMode::stereo:SourceMode::disconnected;
c.inputA=c.source==SourceMode::disconnected?-1:s.a;
c.inputB=c.source==SourceMode::stereo?s.b:-1;
}
ChannelRoutingPlan device;LayoutError deviceError;
if(!ChannelRoutingPlan::compile(cfg.channels,active,device,deviceError)){
fault={RouteError::badDevice,deviceError.strip};return false;
}
std::array<std::array<bool,routingNodes>,routingNodes> edges{};
std::array<int,routingNodes> incoming{};
for(int n=0;n<routingNodes;++n){
const auto& s=src.nodes[n];
if(!std::isfinite(s.level)||s.level<0.f||s.level>4.f){
fault={RouteError::invalidGain,n};return false;
}
int from=-1;
if(s.kind==RouteKind::strip){if(s.a<0||s.a>=stripCount){fault={RouteError::invalidSource,n};return false;}from=s.a;}
else if(s.kind==RouteKind::aux){if(s.a<0||s.a>=auxBuses){fault={RouteError::invalidSource,n};return false;}from=stripCount+s.a;}
else if(s.kind==RouteKind::mono||s.kind==RouteKind::stereo){
if(n>=stripCount){fault={RouteError::invalidSource,n};return false;}
}else if(s.kind!=RouteKind::none){fault={RouteError::invalidSource,n};return false;}
if(from>=0&&!edges[from][n]){edges[from][n]=true;incoming[n]++;}
if(s.sendTo!=-1){
if(n>=stripCount||s.sendTo<0||s.sendTo>=auxBuses||!std::isfinite(s.sendLevel)||s.sendLevel<0.f||s.sendLevel>4.f){
fault={RouteError::invalidSend,n};return false;
}
int to=stripCount+s.sendTo;
if(!edges[n][to]){edges[n][to]=true;incoming[to]++;}
}
}
PreparedRoutes p;p.device=device;p.nodes=src.nodes;
std::array<bool,routingNodes> done{};
for(int k=0;k<routingNodes;++k){
int next=-1;
for(int i=0;i<routingNodes;++i)if(!done[i]&&incoming[i]==0){next=i;break;}
if(next<0){fault={RouteError::cycle,-1};return false;}
p.order[k]=next;done[next]=true;
for(int i=0;i<routingNodes;++i)if(edges[next][i])incoming[i]--;
}
dst=p;return true;
}
};
class PreparedRouteRuntime {
using Samples=std::array<float,maxRouteFrames>;
std::array<Samples,routingNodes> left_{},right_{},addLeft_{},addRight_{};
Samples masterL_{},masterR_{};
public:
template<class Insert>
bool process(const PreparedRoutes& p,const float* const* inputs,int inputCount,
float* outL,float* outR,int frames,Insert&& insert) noexcept {
if(!outL||!outR||frames<=0||frames>maxRouteFrames)return false;
for(int n=0;n<routingNodes;++n){
std::fill_n(left_[n].data(),frames,0.f);std::fill_n(right_[n].data(),frames,0.f);
std::fill_n(addLeft_[n].data(),frames,0.f);std::fill_n(addRight_[n].data(),frames,0.f);
}
std::fill_n(masterL_.data(),frames,0.f);std::fill_n(masterR_.data(),frames,0.f);
for(int k=0;k<routingNodes;++k){
int n=p.order[k];const auto& x=p.nodes[n];
float* l=left_[n].data();float* r=right_[n].data();
if(x.kind==RouteKind::mono||x.kind==RouteKind::stereo)
p.device.extract(n,inputs,inputCount,l,r,frames);
else if(x.kind==RouteKind::strip||x.kind==RouteKind::aux){
int from=x.kind==RouteKind::strip?x.a:stripCount+x.a;
std::copy_n(left_[from].data(),frames,l);std::copy_n(right_[from].data(),frames,r);
}
for(int i=0;i<frames;++i){l[i]+=addLeft_[n][i];r[i]+=addRight_[n][i];}
insert(n,l,r,frames);
if(x.mute)continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear muted node buffers before downstream routes read them

When a muted node is the source of a RouteKind::strip or RouteKind::aux route, continue skips its direct MAIN/send contributions but leaves its processed audio in left_/right_. The downstream node then copies those buffers and makes the muted signal audible again. A compiled graph with muted mono node 0 feeding node 1 produces nonzero MAIN output. Clear the muted node's output buffers before continuing so all downstream routes observe silence.

Useful? React with 👍 / 👎.

for(int i=0;i<frames;++i){l[i]*=x.level;r[i]*=x.level;}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the compiled channel fader and pan coefficients

When callers set fader or pan through RouteSetup.channels.stripsAndMaster, compilation retains those settings and computes device.base.strips[n].leftGain/rightGain, but processing never applies them: extraction supplies raw samples and this loop applies only RouteNode.level. For example, a mono input of 1 with channel fader 0.25 and pan -1 renders (1, 1) instead of (0.25, 0). This also bypasses the existing default equal-power mono pan law. Apply the compiled channel coefficients at the appropriate post-insert routing stage rather than silently ignoring the accepted channel controls.

Useful? React with 👍 / 👎.

if(x.sendTo>=0){
int target=stripCount+x.sendTo;
for(int i=0;i<frames;++i){
addLeft_[target][i]+=l[i]*x.sendLevel;
addRight_[target][i]+=r[i]*x.sendLevel;
}
}
if(x.main)for(int i=0;i<frames;++i){masterL_[i]+=l[i];masterR_[i]+=r[i];}
}
p.device.base.finishMaster(masterL_.data(),masterR_.data(),frames);
std::copy_n(masterL_.data(),frames,outL);std::copy_n(masterR_.data(),frames,outR);
return true;
}
bool process(const PreparedRoutes& p,const float* const* in,int cnt,float* l,float* r,int n) noexcept {
return process(p,in,cnt,l,r,n,[](int,float*,float*,int) noexcept {});
}
};
}
47 changes: 47 additions & 0 deletions tests/prepared_bus_graph_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: AGPL-3.0-only
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include "../engine/core/PreparedBusGraph.h"
#include <array>
#include <cassert>
#include <cmath>
using namespace armix::mixer;
static bool eq(float a,float b){return std::abs(a-b)<1.e-4f;}
int main(){
RouteSetup setup;
constexpr std::array ports{5,2,7};
setup.nodes[0]={RouteKind::mono,2,-1,0,.25f,1.f,true,false};
setup.nodes[1]={RouteKind::stereo,5,7};
setup.nodes[2]={RouteKind::strip,0};setup.nodes[2].main=false;
PreparedRoutes plan;RouteFault fault;
assert(PreparedRoutes::compile(setup,ports,plan,fault));
std::array<float,4> h5{2,2,2,2},h2{1,1,1,1},h7{3,3,3,3},l{},r{};
const float* physical[]{h5.data(),h2.data(),h7.data()};
PreparedRouteRuntime engine;
assert(engine.process(plan,physical,3,l.data(),r.data(),4));
assert(eq(l[0],3.25f)&&eq(r[0],4.25f));
assert(engine.process(plan,physical,3,l.data(),r.data(),4,
[](int bus,float* a,float* b,int n) noexcept {
if(bus==stripCount)for(int i=0;i<n;++i){a[i]*=2;b[i]*=2;}
}));
assert(eq(l[0],3.5f)&&eq(r[0],4.5f));
auto saved=plan;
setup.nodes[0].kind=RouteKind::aux;setup.nodes[0].a=0;
assert(!PreparedRoutes::compile(setup,ports,plan,fault));
assert(fault.code==RouteError::cycle);
assert(plan.nodes[0].kind==saved.nodes[0].kind);
setup.nodes[0].kind=RouteKind::mono;setup.nodes[0].a=2;
setup.nodes[1].a=6;
assert(!PreparedRoutes::compile(setup,ports,plan,fault));
assert(fault.code==RouteError::badDevice);
setup.nodes[1].a=5;
setup.nodes[0].sendTo=2;
assert(!PreparedRoutes::compile(setup,ports,plan,fault));
assert(fault.code==RouteError::invalidSend);
setup.nodes[0].sendTo=0;
assert(PreparedRoutes::compile(setup,ports,plan,fault));
assert(!engine.process(plan,physical,3,l.data(),r.data(),maxRouteFrames+1));
assert(engine.process(plan,physical,3,l.data(),r.data(),4));
assert(eq(l[0],3.25f));
}
Loading