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 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 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/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/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 @@ -47,6 +47,9 @@ target_link_libraries(ARMixConsole PRIVATE

include(CTest)
if(BUILD_TESTING)
add_executable(ARMixMixerRoutingTests tests/mixer_routing_plan_test.cpp)
target_compile_features(ARMixMixerRoutingTests PRIVATE cxx_std_20)
add_test(NAME TenStripStaticRoutingAndMaster COMMAND ARMixMixerRoutingTests)
add_executable(ARMixOrbitPhaseTests tests/orbit_phase_test.cpp)
target_compile_features(ARMixOrbitPhaseTests PRIVATE cxx_std_20)
add_test(NAME VstAzimuthOrbitRamp COMMAND ARMixOrbitPhaseTests)
Expand Down
32 changes: 32 additions & 0 deletions docs/P1A_REAL_MIXER_ROUTING_CORE_20261028.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ArSonMix P1A — verified foundation for real 10-channel routing + MASTER (2026-10-28)

Baseline: `main@de683b001a5a1e5e050bc20ddb52d32b22fa58d1`. Scope: **pure DSP core plus deterministic C++ tests, no live activation**. Superseded/stale UI-DSP PRs must not be bulk merged. Owner's global priority remains stable ultra-low-latency Windows audio and the approved v0.8 GUI; this is not a release or a hardware certification.

## Why this milestone exists

The current JUCE native callback (`src/LiveAudioEngine.h`) processes one stereo input source through one VST3 chain to the master; `src/Main.cpp` currently consumes channel fader/pan/mute only for Channel 1. Its ten other GUI channel/MASTER insert surfaces cannot be called native live FX until a real input/bus topology exists. Issue #15 **0-FX hardware crackle** remains a release gate, and the Smart Audio Engine ARD explicitly prohibits activating P2.6 live multi-channel DSP until that hardware gate passes.

## Implemented: device-independent, offline-prepared routing contract

`engine/core/MixerRoutingPlan.h`:

- Exactly 10 source strips + one MASTER. Every source starts **disconnected** (never invented or assigned to an arbitrary device pin). Physical input indexes are explicit; mono/stereo slots do not infer a nonexistent stereo device.
- The control thread validates *all* channel mappings, valid numeric parameters, stereo channel separation, source mode and physically negotiated input count. It compiles a temporary plan and atomically **as a unit at the API boundary** replaces the output Plan only on complete success. The caller must still publish the Plan across threads safely; **this implementation does not yet provide a graph swap or cross-thread publication**.
- Precomputed equal-power mono pan and stereo-balance coefficients; logical SOLO/MUTE arbitration; fader level, MASTER gain/PAN/mute/mono. No per-sample trig, heap, logging, scans or device operations.
- `extract(strip,...)` reads true physical channel input into preallocated stereo scratch, preserving stereo. `accumulate(strip,...)` sums post-FX stereo scratch into the MASTER mix. `finishMaster(...)` applies MASTER controls after the future master FX chain.
- Unassigned or unavailable physical input returns silence and `false` from `extract`; it never masquerades as a live VST3 or fabricates VU levels.

## Engineering invariants / tests

`tests/mixer_routing_plan_test.cpp` covers 10 independent mono sources, separate left/right physical inputs, stereo identity, mono centered -3 dB law, panic/mute/solo correctness, M/S output summing, invalid physical input and duplicate L/R index, non-finite pan, gain bounds, unknown source modes, recompile rollback and null/insufficient input availability. Existing Windows CTest builds `ARMixMixerRoutingTests` as part of the established workflow (no extra workflow or redundant matrix).

## Next integration gates (deliberately not marked complete)

1. Issue #15 must be physically gated for **0 FX** (OUTPUT_ONLY_TONE, CAPTURE_ONLY, DRY_THROUGH; negotiated driver rate/period and capture/renderer evidence). A CTest pass is not a substitute.
2. Create `SourceRegistry` populated from *actual* ASIO/WASAPI/virtual input endpoints, mapping by explicit per-channel source ID, not hard-coded GUI label or default fake input. Preserve robust DirectFence/independent clocks.
3. Allocate fixed scratch/master buffers ahead of callback; each source: `extract → channel VST chain → fader/pan/mute/solo accumulate`, then `MASTER FX → finishMaster → actual output`. Avoid feedback paths for FX Return. Handle mono/stereo VST bus layout and channel-local plugin/editor/Orbit identity.
4. Publish immutable source/routing snapshots at audio block boundary using the existing `LiveGraphHandoff` epoch/quiescent retirement pattern. No graph destruction, initialization, allocations, locks or device restarts on callback. Support transaction rollback, ACK and source availability status.
5. Verify per-source meters against true post-FX levels; add callback budget profiling, cross-channel isolation, device hotplug, recall, latency/PDC and minimum-buffer soak tests. No guaranteed click-free VST order change until measured on the real device.
6. Only then enable `ADD FX` for CH2–10 and MASTER in native GUI. An unrouted channel must show a truthful disabled/unassigned status until activation.

No installer/runtime changes are included in this milestone. Public/private binary feature parity and the portable VST Vault rules remain unchanged.
168 changes: 168 additions & 0 deletions engine/core/MixerRoutingPlan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>

// Phase P1: prepared, device-independent 10-strip + MASTER routing primitive.
// NO connection to the live audio callback yet. All topology changes must be
// compiled on the control thread and published using a quiescent/epoch handoff.
// Only read/accumulate/master belong in the realtime callback.
namespace armix::mixer {

constexpr int stripCount = 10;

enum class SourceMode { disconnected, mono, stereo };

struct StripConfig final {
SourceMode source = SourceMode::disconnected;
int inputA = -1, inputB = -1; // physical input indices, never GUI labels
float faderLinear = 1.0f; // UI dB conversion happens on control thread
float pan = 0.0f; // -1 = left, 0 = center, +1 = right
bool mute = false, solo = false;
};
struct MasterConfig final {
float gainLinear = 1.0f;
float pan = 0.0f;
bool mute = false, mono = false;
};
struct Configuration final {
std::array<StripConfig,stripCount> strips {};
MasterConfig master {};
};
enum class Fault { none, invalidInputCount, inputOutOfRange, duplicateStereoInput,
invalidSourceMode, invalidGain, invalidPan };
struct Error final {
Fault code = Fault::none;
int strip = -1; // -1 denotes master/device rather than a source strip
};

struct CompiledStrip final {
int inputA = -1, inputB = -1;
SourceMode mode = SourceMode::disconnected;
bool active = false; // muted, disconnected and solo-excluded are never routed
float leftGain = 0.f, rightGain = 0.f;
};

struct Plan final {
std::array<CompiledStrip,stripCount> strips {};
int physicalInputs = 0;
float masterGain = 1.f, masterLeftBalance = 1.f, masterRightBalance = 1.f;
bool masterMono = false;
int activeStrips = 0;

// Control thread ONLY. Rejection leaves previous plan untouched.
// Unassigned strips are legal and always silent, never fake VST buses.
static bool compile(const Configuration& cfg, int inputCount, Plan& destination,
Error& error) noexcept {
error = {};
if (inputCount < 0 || inputCount > 256) {
error = {Fault::invalidInputCount,-1};
return false;
}
if (!validGain(cfg.master.gainLinear)) {
error = {Fault::invalidGain,-1}; return false;
}
if (!validPan(cfg.master.pan)) {
error = {Fault::invalidPan,-1}; return false;
}
bool anySolo = false;
for (int i=0;i<stripCount;++i) {
const auto& c=cfg.strips[i];
if (c.source!=SourceMode::disconnected &&
c.source!=SourceMode::mono && c.source!=SourceMode::stereo) {
error={Fault::invalidSourceMode,i};return false;
}
if (!validGain(c.faderLinear)) { error={Fault::invalidGain,i};return false; }
if (!validPan(c.pan)) { error={Fault::invalidPan,i};return false; }
if (c.source == SourceMode::disconnected) continue;
if (c.inputA<0 || c.inputA>=inputCount ||
(c.source==SourceMode::stereo && (c.inputB<0 || c.inputB>=inputCount))) {
error={Fault::inputOutOfRange,i};return false;
}
if (c.source==SourceMode::stereo && c.inputA==c.inputB) {
error={Fault::duplicateStereoInput,i};return false;
}
if (c.solo && !c.mute) anySolo = true;
}
Plan candidate;
candidate.physicalInputs = inputCount;
candidate.masterGain = cfg.master.mute?0.f:cfg.master.gainLinear;
candidate.masterMono = cfg.master.mono;
candidate.masterLeftBalance = cfg.master.pan>0.f?1.f-cfg.master.pan:1.f;
candidate.masterRightBalance = cfg.master.pan<0.f?1.f+cfg.master.pan:1.f;
for (int i=0;i<stripCount;++i) {
const auto& c=cfg.strips[i];
if (c.source==SourceMode::disconnected) continue;
auto& p=candidate.strips[i];
p.mode=c.source;
p.inputA=c.inputA;
p.inputB=c.source==SourceMode::stereo?c.inputB:c.inputA;
p.active=!c.mute && (!anySolo || c.solo) && c.faderLinear>0.f;
if (!p.active) continue;
++candidate.activeStrips;
if (c.source==SourceMode::mono) {
// Equal-power mono panning, computed exactly once per topology edit.
p.leftGain=c.faderLinear*std::sqrt(0.5f*(1.f-c.pan));
p.rightGain=c.faderLinear*std::sqrt(0.5f*(1.f+c.pan));
} else {
// Stereo BALANCE, not an accidental crossfeed or stereo collapse.
p.leftGain=c.faderLinear*(c.pan>0.f?1.f-c.pan:1.f);
p.rightGain=c.faderLinear*(c.pan<0.f?1.f+c.pan:1.f);
}
}
destination=candidate;
return true;
}

// RT: read one physical input source into preallocated stereo FX scratch.
// Stereo processors can consume both channels before accumulate().
bool extract(int strip,const float* const* inputs,int availableInputs,
float* left,float* right,int frames) const noexcept {
if (!left || !right || frames<=0 || strip<0 || strip>=stripCount) return false;
const auto& route=strips[strip];
const bool valid=route.active && inputs &&
route.inputA>=0 && route.inputA<availableInputs &&
route.inputB>=0 && route.inputB<availableInputs &&
inputs[route.inputA] && inputs[route.inputB];
if (!valid) {
std::fill_n(left,frames,0.f);std::fill_n(right,frames,0.f);
return false;
}
std::copy_n(inputs[route.inputA],frames,left);
std::copy_n(inputs[route.inputB],frames,right);
return true;
}

// RT: mix one channel's POST-FX scratch onto the master accumulator.
void accumulate(int strip,const float* left,const float* right,
float* masterL,float* masterR,int frames) const noexcept {
if (strip<0 || strip>=stripCount || frames<=0 ||
!left || !right || !masterL || !masterR) return;
const auto& p=strips[strip];
if (!p.active) return;
for(int i=0;i<frames;++i) {
masterL[i]+=left[i]*p.leftGain;
masterR[i]+=right[i]*p.rightGain;
}
}
static void clearMaster(float* left,float* right,int frames) noexcept {
if(frames<=0||!left||!right)return;
std::fill_n(left,frames,0.f);std::fill_n(right,frames,0.f);
}
// RT: apply master controls AFTER the planned MASTER insert chain.
void finishMaster(float* left,float* right,int frames) const noexcept {
if(frames<=0||!left||!right)return;
for(int i=0;i<frames;++i) {
const float l=left[i]*masterLeftBalance;
const float r=right[i]*masterRightBalance;
if(masterMono) left[i]=right[i]=0.5f*(l+r)*masterGain;
else {left[i]=l*masterGain;right[i]=r*masterGain;}
}
}
private:
static bool validGain(float v) noexcept { return std::isfinite(v)&&v>=0.f&&v<=4.f; }
static bool validPan(float v) noexcept { return std::isfinite(v)&&v>=-1.f&&v<=1.f; }
};
} // namespace armix::mixer
Loading
Loading