From 8a377d2747d11ffbab6e6dc18cc9dd50f03e2227 Mon Sep 17 00:00:00 2001 From: jenkins Date: Thu, 3 Dec 2026 12:43:52 -0600 Subject: [PATCH] bstein: flag sustained RCT audio level drops separately from tone matching --- .../av-observer/acoustic-detector.js | 39 ++++++++++++++++++- .../av-observer/acoustic-watch.js | 11 +++++- services/bstein-dev-home/av-observer/mic.html | 3 +- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/services/bstein-dev-home/av-observer/acoustic-detector.js b/services/bstein-dev-home/av-observer/acoustic-detector.js index 0b0fe704..4f137c02 100644 --- a/services/bstein-dev-home/av-observer/acoustic-detector.js +++ b/services/bstein-dev-home/av-observer/acoustic-detector.js @@ -2,6 +2,10 @@ import {ANCHOR_HZ, MARKERS_HZ, ORDER, SYMBOL_SECONDS, TRIAL_SECONDS} from './acoustic-pattern.js'; import {PilotWindow} from './pilot-window.js'; +// A review threshold for continuous test sound. It does not model intelligibility. +export const LEVEL_DROP_MS = 100; +const DROP_POWER_RATIO = 0.01; // 20 dB below the recently recognized reference. + export class AcousticDetector { constructor(rate) { this.rate = rate; @@ -18,6 +22,11 @@ export class AcousticDetector { this.faults = []; this.recent = new PilotWindow(this.windowMs); this.nextFrame = null; + this.referencePower = null; + this.quietWindows = this.dropCount = this.longestDropMs = 0; + this.firstDropMs = null; + this.haveInput = true; + this.inputMissing = false; } interrupt() { if (this.locked && this.windows < this.target) { @@ -28,6 +37,9 @@ export class AcousticDetector { this.edges = 0; this.slot = this.lastMarker = -1; this.count = this.energy = 0; + this.quietWindows = 0; + this.referencePower = null; + this.haveInput = true; this.q1.fill(0); this.q2.fill(0); } record(kind) { @@ -43,6 +55,23 @@ export class AcousticDetector { if (power[0] < min || power[marker] < min || this.energy === 0) return -1; return marker - 1; } + observeLevel(valid) { + const power = this.energy / this.size; + const quiet = this.haveInput && this.referencePower !== null && + power <= DROP_POWER_RATIO * this.referencePower; + if (valid && this.haveInput && !quiet) { + this.referencePower = this.referencePower === null ? power : + this.referencePower + 0.05 * (power - this.referencePower); + } + this.quietWindows = quiet ? this.quietWindows + 1 : 0; + const threshold = Math.ceil(LEVEL_DROP_MS / this.windowMs); + if (this.quietWindows < threshold) return; + if (this.quietWindows === threshold) { + this.dropCount++; + this.firstDropMs ??= Math.round((this.windows - this.quietWindows) * this.windowMs); + } + this.longestDropMs = Math.max(this.longestDropMs, this.quietWindows * this.windowMs); + } window(marker, endMs) { this.tick++; let valid = marker >= 0; @@ -71,6 +100,7 @@ export class AcousticDetector { this.locked = true; } this.windows++; + this.observeLevel(valid); if (!valid) { if (!this.gap) this.record('signal missing or out of sequence'); this.bad++; @@ -81,9 +111,13 @@ export class AcousticDetector { } process(samples, frame, length) { if (this.windows >= this.target) return; - if (this.nextFrame !== null && this.nextFrame !== frame) this.interrupt(); + const missing = !samples || samples.length < length; + if ((this.nextFrame !== null && this.nextFrame !== frame) || + (missing && !this.inputMissing)) this.interrupt(); + this.inputMissing = missing; this.nextFrame = frame + length; for (let i = 0; i < length && this.windows < this.target; i++) { + if (missing && i >= (samples?.length ?? 0)) this.haveInput = false; const x = samples?.[i] ?? 0; this.energy += x * x; for (let j = 0; j < this.coeff.length; j++) { @@ -93,12 +127,15 @@ export class AcousticDetector { if (++this.count === this.size) { this.window(this.detect(), (frame + i + 1) * 1000 / this.rate); this.q1.fill(0); this.q2.fill(0); this.count = this.energy = 0; + this.haveInput = true; } } } summary(nowMs) { return {locked: this.locked, complete: this.windows >= this.target, observedMs: this.windows * this.windowMs, windows: this.windows, + levelDrops: this.dropCount, longestLevelDropMs: this.longestDropMs, + firstLevelDropMs: this.firstDropMs, missingWindows: this.bad, sequenceFaults: this.sequenceFaults, missingFraction: this.windows ? this.bad / this.windows : null, gapMaxMs: this.longest * this.windowMs, trailingGapMs: this.gap * this.windowMs, diff --git a/services/bstein-dev-home/av-observer/acoustic-watch.js b/services/bstein-dev-home/av-observer/acoustic-watch.js index 1b229b77..3eac2549 100644 --- a/services/bstein-dev-home/av-observer/acoustic-watch.js +++ b/services/bstein-dev-home/av-observer/acoustic-watch.js @@ -2,6 +2,7 @@ import {TRIAL_SECONDS} from './acoustic-pattern.js'; export const phoneTest = new URLSearchParams(location.search).get('test') === 'phone'; const status = document.getElementById('path-state'); +const detail = document.getElementById('path-detail'); const clock = ms => { const s = Math.min(TRIAL_SECONDS, Math.floor(ms / 1000)); return Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0'); @@ -26,6 +27,7 @@ export async function attachDetector(run, isCurrent, finish) { run.detector = node; run.pathInterruptions = 0; status.textContent = 'Waiting for phone signal'; + detail.hidden = true; node.onprocessorerror = () => { if (isCurrent()) finish('detector failed'); }; node.port.onmessage = ({data}) => { if (!isCurrent()) return; @@ -43,11 +45,16 @@ export async function attachDetector(run, isCurrent, finish) { run.path = {...data, discontinuities:interruptions}; if (data.locked) { const gaps = data.missingWindows > 0 || data.sequenceFaults > 0; - const label = interruptions ? 'Observation interrupted' : gaps ? 'Signal breaks detected' : 'Signal tracking'; + const drop = data.levelDrops > 0; + const label = interruptions ? 'Observation interrupted' : drop ? + 'Received audio level drop · ' + Math.round(data.longestLevelDropMs) + ' ms' : 'Signal tracking'; + detail.hidden = !gaps; + detail.textContent = gaps ? 'Longest reference mismatch · ' + Math.round(data.gapMaxMs) + ' ms' : ''; status.textContent = label + ' · ' + clock(data.observedMs) + ' / 30:00'; if (data.complete) { status.textContent = interruptions ? '30 minutes · incomplete observation' : - gaps ? '30 minutes · signal breaks detected' : '30 minutes · continuous reference received'; + drop ? '30 minutes · received audio level drop · ' + Math.round(data.longestLevelDropMs) + ' ms' : + gaps ? '30 minutes · reference mismatches recorded' : '30 minutes · continuous reference received'; finish('phone test complete'); } } diff --git a/services/bstein-dev-home/av-observer/mic.html b/services/bstein-dev-home/av-observer/mic.html index 70647a03..9fbb781b 100644 --- a/services/bstein-dev-home/av-observer/mic.html +++ b/services/bstein-dev-home/av-observer/mic.html @@ -3,7 +3,8 @@ Audio Test

Audio Test

A/V Test

30-minute RCT receiver test Phone sound source

- + +