Skip to content
Merged
93 changes: 93 additions & 0 deletions integration/FirstSoundSignalEvidence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include <juce_core/juce_core.h>
#include <cmath>
#include <memory>

// JUCE MESSAGE-thread evidence projection. Raw values come ONLY from the
// installed LiveAudioEngine callback atomics; this does not produce PCM,
// read the audio device, invent a signal, or claim audible speaker output.
namespace armix::console {
inline bool evidenceFlag(const juce::var& o, const char* name, bool expected) {
const auto v=o.getProperty(name,{});
return v.isBool() && static_cast<bool>(v)==expected;
}
inline bool evidenceInteger(const juce::var& v, double& n) {
if(!(v.isInt()||v.isInt64()||v.isDouble()))return false;
n=static_cast<double>(v);
return std::isfinite(n) && n>=0.0 && n<=9007199254740991.0
&& std::floor(n)==n;
}
inline bool evidencePeak(const juce::var& v, double& peak) {
if(!(v.isInt()||v.isInt64()||v.isDouble()))return false;
peak=static_cast<double>(v);
return std::isfinite(peak) && peak>=0.0 && peak<=16.0;
}
inline juce::var projectFirstSoundSignalEvidence(
const juce::var& live, bool verifiedDirectOpen,
bool primaryOutputArmed, int activeInputCount, int activeOutputCount)
{
auto t=std::make_unique<juce::DynamicObject>();
// Empty/never-called capture must be UNKNOWN, not a synthetic zero
// that misleadingly suggests a working microphone or driver.
t->setProperty("captureObserved",false);
t->setProperty("rawCapturePresent",false);
t->setProperty("rawCapturePeak",juce::var());
t->setProperty("captureCallbackPeaks",juce::var(juce::Array<juce::var>{}));
t->setProperty("mainPcmObserved",false);
t->setProperty("mainPcmPresent",false);
t->setProperty("mainPcmPeak",juce::var());
t->setProperty("monitorPcmPresent",false);
if(!live.isObject() || !verifiedDirectOpen ||
activeInputCount<=0 || activeInputCount>64 ||
activeOutputCount<2 || activeOutputCount>64)
return juce::var(t.release());
const auto route=live.getProperty("dryRoutingLab",{});
if(!route.isObject() ||
!evidenceFlag(live,"connected",true) ||
!evidenceFlag(live,"directRouteAuthorized",true) ||
!evidenceFlag(live,"adaptiveClockActive",false) ||
!evidenceFlag(route,"active",true) ||
!evidenceFlag(route,"ready",true) ||
!evidenceFlag(route,"topologyFault",false))
return juce::var(t.release());
double observations=0.,inCount=0.,outCount=0.,inputPeak=0.;
if(!evidenceInteger(live.getProperty("captureObservationBlocks",{}),observations) ||
observations<1. ||
!evidenceInteger(live.getProperty("callbackInputChannels",{}),inCount) ||
!evidenceInteger(live.getProperty("callbackOutputChannels",{}),outCount) ||
inCount!=activeInputCount || outCount!=activeOutputCount ||
!evidencePeak(live.getProperty("inputPeak",{}),inputPeak))
return juce::var(t.release());
const auto peaks=live.getProperty("captureCallbackPeaks",{});
const auto* list=peaks.getArray();
if(!list || list->size()!=activeInputCount)
return juce::var(t.release());
juce::Array<juce::var> verifiedPeaks;
for(const auto& value:*list) {
double peak=0.;
if(!evidencePeak(value,peak))
return juce::var(t.release());
verifiedPeaks.add(peak);
}
t->setProperty("captureObserved",true);
t->setProperty("rawCapturePeak",inputPeak);
t->setProperty("rawCapturePresent",inputPeak>0.0005);
t->setProperty("captureCallbackPeaks",juce::var(verifiedPeaks));
// MAIN telemetry is measured *post* fader/FX/output gate, but remains
// PCM evidence only: it can never certify actual DAC/earphone playback.
if(primaryOutputArmed &&
evidenceFlag(route,"hasAcceptedRoute",true) &&
evidenceFlag(live,"monitor",true)) {
double left=0.,right=0.;
if(evidencePeak(live.getProperty("peakLeft",{}),left) &&
evidencePeak(live.getProperty("peakRight",{}),right)) {
const auto peak=juce::jmax(left,right);
t->setProperty("mainPcmObserved",true);
t->setProperty("mainPcmPeak",peak);
t->setProperty("mainPcmPresent",peak>0.0005);
}
}
return juce::var(t.release());
}
} // namespace armix::console
16 changes: 10 additions & 6 deletions src/ApprovedConsoleNativeTransportV6.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include <juce_gui_extra/juce_gui_extra.h>
#include "../integration/FirstSoundSignalEvidence.h"
#include <cmath>
#include <cstdint>
#include <limits>
Expand Down Expand Up @@ -107,12 +108,15 @@ inline juce::var snapshot (const juce::var& live,
graph->setProperty ("capabilities", juce::var (caps.release()));
root->setProperty ("graph", juce::var (graph.release()));

auto telemetry = std::make_unique<juce::DynamicObject>();
telemetry->setProperty ("rawCapturePresent", false);
telemetry->setProperty ("rawCapturePeak", 0.0);
telemetry->setProperty ("mainPcmPresent", false);
telemetry->setProperty ("monitorPcmPresent", false);
root->setProperty ("telemetry", juce::var (telemetry.release()));
// The original G0 snapshot published fixed FALSE/0 for raw capture,
// hiding actual driver PCM even while a verified unpatched callback ran.
// Read the existing engine atomics via the same JUCE message-thread
// snapshot. Keep UNKNOWN when callbacks/ports are stale or unavailable.
root->setProperty ("telemetry",armix::console::projectFirstSoundSignalEvidence (
live, active != nullptr && active->isOpen() && direct,
primaryOutputArmed,
active != nullptr ? active->getActiveInputChannels().countNumberOfSetBits() : 0,
active != nullptr ? active->getActiveOutputChannels().countNumberOfSetBits() : 0));
return juce::var (root.release());
}

Expand Down
58 changes: 57 additions & 1 deletion tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,61 @@ test("native G0 preserves verified first-sound M4 route without claiming Channel
assert.match(read("src/ApprovedConsoleNativeTransportV6.h"),
/"outputArmed", primaryOutputArmed/);
});
test("First Sound evidence maps sparse physical pins to actual callback ordinals and diagnoses silence",()=>{
const g0=clone(fixtures.g0);
g0.legacyM4={active:true,routeAccepted:true,routingRevision:"9"};
g0.device.enabledInputs=[0,2];
g0.device.inputEndpoints.push({
id:"in:2",port:2,callback:1,label:"Mic 3",active:true
});
g0.device.outputArmed=true;
g0.telemetry={
captureObserved:true,rawCapturePresent:true,rawCapturePeak:0.38,
captureCallbackPeaks:[0,0.38],mainPcmObserved:true,
mainPcmPresent:true,mainPcmPeak:0.17,monitorPcmPresent:false
};
const snapshot=protocol.normalizeSnapshot(g0);
assert.ok(snapshot);assert.equal(snapshot.admitted,false);
const first=protocol.diagnoseFirstSound(snapshot,0);
assert.equal(first.selectedPin,0);
assert.equal(first.rawPeak,0);
assert.match(first.nextAction,/Selected input is silent/);
const second=protocol.diagnoseFirstSound(snapshot,2);
assert.equal(second.selectedPin,2);
assert.equal(second.rawPeak,0.38);
assert.equal(second.mainPeak,0.17);
assert.match(second.nextAction,/physically/);
assert.match(second.readout,/IN 3/);
const all=protocol.diagnoseFirstSound(snapshot,"");
assert.equal(all.rawPeak,0.38);
// A mistaken output claim never becomes a loudspeaker certification.
g0.device.outputArmed=false;
const muted=protocol.diagnoseFirstSound(protocol.normalizeSnapshot(g0),2);
assert.match(muted.nextAction,/ARM output/);
g0.device.outputArmed=true;
g0.legacyM4.routeAccepted=false;
const unpatched=protocol.diagnoseFirstSound(protocol.normalizeSnapshot(g0),2);
assert.match(unpatched.nextAction,/PATCH CH1/);
g0.legacyM4.routeAccepted=true;
g0.telemetry.mainPcmPeak=0;g0.telemetry.mainPcmPresent=false;
assert.match(protocol.diagnoseFirstSound(protocol.normalizeSnapshot(g0),2).nextAction,/MAIN PCM silent/);
g0.telemetry.captureObserved=false;
const unknown=protocol.diagnoseFirstSound(protocol.normalizeSnapshot(g0),2);
assert.equal(unknown.rawPeak,null);
assert.match(unknown.nextAction,/No current-epoch capture callback/);
});
test("native signal evidence is produced from measured engine fields, never JS simulated PCM",()=>{
const header=read("integration/FirstSoundSignalEvidence.h");
const transport=read("src/ApprovedConsoleNativeTransportV6.h");
const bridge=read("web/approved-native-bridge.js");
assert.match(header,/captureObservationBlocks/);
assert.match(header,/callbackInputChannels/);
assert.match(header,/captureCallbackPeaks/);
assert.match(header,/directRouteAuthorized/);
assert.match(transport,/projectFirstSoundSignalEvidence/);
assert.doesNotMatch(transport,/setProperty \("rawCapturePeak", 0\.0\)/);
assert.match(bridge,/protocol\.diagnoseFirstSound/);
});
test("strict producer rejects JS Number identities, invalid hardware pins and fake LIVE",()=>{
const cases=[
s=>{s.device.epoch=69;},
Expand Down Expand Up @@ -391,7 +446,8 @@ test("native Windows operator can explicitly patch first physical input, arm and
assert.match(js,/if\(ack\.ok===true\)/);
assert.match(js,/NATIVE PATCH REJECTED:/);
assert.match(js,/NO VERIFIED AUDIO DEVICE/);
assert.match(js,/REAL NATIVE PCM · FAT PENDING/);
assert.match(js,/NATIVE PCM · HARDWARE FAT PENDING/);
assert.match(js,/MAIN ARMED · PCM NOT YET ADMITTED/);
assert.match(main,/action=="routingSourceSwitch"/);
assert.match(main,/engine_\.liveOutputArmFault\(\)/);
assert.match(main,/safe->emitApprovedNativeSnapshot\(\)/);
Expand Down
61 changes: 61 additions & 0 deletions tests/approved_native_v8_projection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../integration/ApprovedNativeV8Projection.h"
#include "../integration/ApprovedNativeControlIntent.h"
#include "../integration/ApprovedNativeRuntimeSnapshot.h"
#include "../integration/FirstSoundSignalEvidence.h"
#if defined(NDEBUG)
#undef NDEBUG
#endif
Expand Down Expand Up @@ -397,6 +398,65 @@ static void firstSoundRouteAdmissionRegression() {
assert(!publishVerifiedFirstSoundState(withoutInput,live));
}

static void firstSoundMeasuredSignalEvidenceRegression() {
auto live=parse(R"JSON({
"connected":true,"directRouteAuthorized":true,
"adaptiveClockActive":false,"monitor":true,
"captureObservationBlocks":19,
"callbackInputChannels":2,"callbackOutputChannels":2,
"inputPeak":0.35,"captureCallbackPeaks":[0.0,0.35],
"peakLeft":0.08,"peakRight":0.12,
"dryRoutingLab":{"active":true,"ready":true,"topologyFault":false,
"hasAcceptedRoute":true}
})JSON");
const auto signal=[&](const juce::var& l,bool direct,bool arm,int ins=2,int outs=2) {
return projectFirstSoundSignalEvidence(l,direct,arm,ins,outs);
};
const auto accepted=signal(live,true,true);
assert(static_cast<bool>(accepted.getProperty("captureObserved",false)));
assert(static_cast<bool>(accepted.getProperty("rawCapturePresent",false)));
assert(static_cast<bool>(accepted.getProperty("mainPcmObserved",false)));
assert(static_cast<bool>(accepted.getProperty("mainPcmPresent",false)));
assert(std::abs(static_cast<double>(accepted.getProperty("rawCapturePeak",0.))-0.35)<1e-7);
assert(std::abs(static_cast<double>(accepted.getProperty("mainPcmPeak",0.))-0.12)<1e-7);
assert(accepted.getProperty("captureCallbackPeaks",{}).getArray()->size()==2);
// An active unpatched graph still observes real input while correctly
// hiding routed MAIN PCM. No physical output is ever auto-authorized.
live.getProperty("dryRoutingLab",{}).getDynamicObject()
->setProperty("hasAcceptedRoute",false);
auto unpatched=signal(live,true,true);
assert(static_cast<bool>(unpatched.getProperty("captureObserved",false)));
assert(!static_cast<bool>(unpatched.getProperty("mainPcmObserved",true)));
live.getProperty("dryRoutingLab",{}).getDynamicObject()
->setProperty("hasAcceptedRoute",true);
auto disarmed=signal(live,true,false);
assert(static_cast<bool>(disarmed.getProperty("captureObserved",false)));
assert(!static_cast<bool>(disarmed.getProperty("mainPcmObserved",true)));
live.getDynamicObject()->setProperty("inputPeak",0.);
live.getDynamicObject()->setProperty("captureCallbackPeaks",parse(
R"JSON({"peaks":[0,0]})JSON").getProperty("peaks",{}));
auto silence=signal(live,true,true);
assert(static_cast<bool>(silence.getProperty("captureObserved",false)));
assert(!static_cast<bool>(silence.getProperty("rawCapturePresent",true)));
assert(!silence.getProperty("rawCapturePeak",{}).isVoid());
live.getDynamicObject()->setProperty("inputPeak",0.35);
// Driver callback never occurred (or is stale): evidence UNKNOWN rather
// than a fabricated 0 dBFS or reported hardware source.
live.getDynamicObject()->setProperty("captureObservationBlocks",0);
auto none=signal(live,true,true);
assert(!static_cast<bool>(none.getProperty("captureObserved",true)));
assert(none.getProperty("rawCapturePeak",{}).isVoid());
live.getDynamicObject()->setProperty("captureObservationBlocks",19);
assert(!static_cast<bool>(signal(live,false,true).getProperty("captureObserved",true)));
assert(!static_cast<bool>(signal(live,true,true,1,2)
.getProperty("captureObserved",true)));
live.getDynamicObject()->setProperty("directRouteAuthorized",false);
assert(!static_cast<bool>(signal(live,true,true).getProperty("captureObserved",true)));
live.getDynamicObject()->setProperty("directRouteAuthorized",true);
live.getDynamicObject()->setProperty("captureCallbackPeaks",juce::var());
assert(!static_cast<bool>(signal(live,true,true).getProperty("captureObserved",true)));
}

int main() {
auto snap=canonicalSnapshot();
auto bus=realBusReadbackFixture();
Expand Down Expand Up @@ -430,6 +490,7 @@ int main() {
controlIntentTranslationCases(snap,bus);
installedCallbackAdmissionRegression(bus);
firstSoundRouteAdmissionRegression();
firstSoundMeasuredSignalEvidenceRegression();

auto missingMain=realBusReadbackFixture();
missingMain.getProperty("channels",{})[1].getDynamicObject()
Expand Down
20 changes: 12 additions & 8 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@
d.outputArmed?"Output armed":"Output muted";
const warning=document.querySelector?.(".status-bar .warning");
if(warning)warning.textContent=!deviceOpen?"NO VERIFIED AUDIO DEVICE":
next.admitted&&d.outputArmed?"REAL NATIVE PCM · FAT PENDING":
d.outputArmed?(next.admitted?"NATIVE PCM · HARDWARE FAT PENDING":
"MAIN ARMED · PCM NOT YET ADMITTED"):
Comment on lines +173 to +174

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 Update the contract assertion for the changed status text

Changing this status text leaves tests/approved_native_m2_contract.test.cjs:449 asserting /REAL NATIVE PCM · FAT PENDING/, which no longer appears in the bridge. Running node --test tests/approved_native_m2_contract.test.cjs fails on that assertion. Both .github/workflows/ui-smoke.yml and .github/workflows/p1-windows.yml run this contract suite, so the change breaks qualification even when the native implementation is otherwise correct. Update the assertion to match the intended new wording.

Useful? React with 👍 / 👎.

legacy()?.routeAccepted?"INPUT PATCHED · OUTPUT MUTED":
"NO AUDIBLE OUTPUT · PATCH INPUT + ARM";
if(!inputSelect)return;
const pins=deviceOpen?d.inputEndpoints.filter(p=>
Expand All @@ -197,12 +199,14 @@
if(armBtn)armBtn.disabled=!deviceReady() ||
legacy()?.routeAccepted!==true || d.outputArmed;
if(muteBtn)muteBtn.disabled=!deviceOpen || !d.outputArmed;
if(hardwareNote)hardwareNote.textContent=!deviceOpen?
"Open Audio Setup: select a real input and output.":
!deviceReady()?"Verify ASIO/WASAPI input/output masks.":
!legacy()?.routeAccepted?"Select input, PATCH CH1, then ARM output.":
!d.outputArmed?"Input patch accepted. Reduce speaker volume before ARM.":
"User-armed output · check physical sound and native meter.";
if(hardwareNote) {
const evidence=protocol.diagnoseFirstSound?.(next,inputSelect.value);
// Human-readable PCM stages from the ORIGINAL native callback only.
// These values are NOT evidence that the DAC or speaker is audible.
hardwareNote.textContent=evidence?
evidence.readout+" · "+evidence.nextAction:
"No verified hardware PCM readback available.";
}
}
function installFirstSoundMenu() {
const menu=document.querySelector?.("#moreTools .more-tools-panel");
Expand Down Expand Up @@ -271,7 +275,7 @@
flags.productionCallbackLive=false;flags.acceptedGraphConnected=false;
lastPaintedSignature="";
stopDemo();
status("NATIVE G0 · perangkat aktual terbaca; ChannelId PCM/WIRE belum diterima. Edit audio diblokir.");
status("NATIVE G0 · PATCH CH1/ARM tersedia pada device terverifikasi; kontrol ChannelId/WIRE menunggu PCM native.");
return;
}
// Control readback may change at the SAME structural graph revision.
Expand Down
39 changes: 38 additions & 1 deletion web/approved-native-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,43 @@
return false;
});
}
// Read-only operator diagnosis from verified Windows callback evidence.
// UI-only: this routine cannot patch, ARM, create PCM or certify speakers.
function diagnoseFirstSound(snapshot, selectedPhysicalPort=null) {
const d=snapshot?.device, t=snapshot?.telemetry, m4=snapshot?.raw?.legacyM4;
const opened=Boolean(d && d.sampleRate>0 && Array.isArray(d.enabledOutputs) &&
d.enabledOutputs.length>=2 && Array.isArray(d.enabledInputs) && d.enabledInputs.length>0);
const measured=x=>typeof x==="number"&&Number.isFinite(x)&&x>=0&&x<=16?x:null;
const dbfs=x=>x===null?"N/A":x===0?"−∞ dBFS":
(20*Math.log10(x)).toFixed(1)+" dBFS";
const endpoints=Array.isArray(d?.inputEndpoints)?d.inputEndpoints:[];
const physical=selectedPhysicalPort===null||selectedPhysicalPort===""?
null:Number(selectedPhysicalPort);
const pin=Number.isInteger(physical)?endpoints.find(p=>
p.port===physical && p.active===true && d.enabledInputs.includes(p.port)):null;
const observed=t?.captureObserved===true;
const portPeak=pin && Array.isArray(t?.captureCallbackPeaks)?
measured(t.captureCallbackPeaks[pin.callback]):null;
const raw=observed?(pin?portPeak:measured(t?.rawCapturePeak)):null;
const mainObserved=t?.mainPcmObserved===true;
const main=mainObserved?measured(t?.mainPcmPeak):null;
let nextAction;
if(!opened)nextAction="Choose verified input and output devices in Audio Setup.";
else if(m4?.active!==true)nextAction="Native mixer not ready; check verified DIRECT device.";
else if(!observed)nextAction="No current-epoch capture callback evidence; verify driver and inputs.";
else if(pin && raw===0)nextAction="Selected input is silent; check physical source and input gain.";
else if(raw===null)nextAction="Capture peak unavailable; do not assume an active source.";
else if(m4.routeAccepted!==true)nextAction="PATCH CH1 to the selected hardware input.";
else if(d.outputArmed!==true)nextAction="Patch accepted; lower volume then ARM output.";
else if(!mainObserved)nextAction="No MAIN PCM measurement; check routing and output state.";
else if(main===0)nextAction="MAIN PCM silent; check CH1 fader/MUTE and MASTER MUTE.";
else nextAction="MAIN PCM measured; verify headphone/speaker sound physically.";
const label=pin?"IN "+(pin.port+1):"ALL INPUTS";
return Object.freeze({captureObserved:observed,mainPcmObserved:mainObserved,
rawPeak:raw,mainPeak:main,rawDbfs:dbfs(raw),mainDbfs:dbfs(main),
selectedPin:pin?.port??null,nextAction,
readout:label+" "+dbfs(raw)+" · MAIN PCM "+dbfs(main)});
}
function createController({emit, onStatus=()=>{}, onAccepted=()=>{}}) {
if (typeof emit !== "function") throw Error("Native emitter required");
let current = null, pending = null, lastRequest = 0, lastError = "NATIVE_NOT_SUBSCRIBED";
Expand Down Expand Up @@ -298,5 +335,5 @@
}
return Object.freeze({subscribe,onSnapshot,onAck,intent,state,expire});
}
return Object.freeze({decimal,cmp,normalizeSnapshot,readbackProvesIntent,createController});
return Object.freeze({decimal,cmp,normalizeSnapshot,readbackProvesIntent,diagnoseFirstSound,createController});
});
Loading