bstein: flag sustained RCT audio level drops separately from tone matching

This commit is contained in:
jenkins 2026-12-03 12:43:52 -06:00
parent 8113ebda75
commit 8a377d2747
3 changed files with 49 additions and 4 deletions

View File

@ -2,6 +2,10 @@
import {ANCHOR_HZ, MARKERS_HZ, ORDER, SYMBOL_SECONDS, TRIAL_SECONDS} from './acoustic-pattern.js'; import {ANCHOR_HZ, MARKERS_HZ, ORDER, SYMBOL_SECONDS, TRIAL_SECONDS} from './acoustic-pattern.js';
import {PilotWindow} from './pilot-window.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 { export class AcousticDetector {
constructor(rate) { constructor(rate) {
this.rate = rate; this.rate = rate;
@ -18,6 +22,11 @@ export class AcousticDetector {
this.faults = []; this.faults = [];
this.recent = new PilotWindow(this.windowMs); this.recent = new PilotWindow(this.windowMs);
this.nextFrame = null; this.nextFrame = null;
this.referencePower = null;
this.quietWindows = this.dropCount = this.longestDropMs = 0;
this.firstDropMs = null;
this.haveInput = true;
this.inputMissing = false;
} }
interrupt() { interrupt() {
if (this.locked && this.windows < this.target) { if (this.locked && this.windows < this.target) {
@ -28,6 +37,9 @@ export class AcousticDetector {
this.edges = 0; this.edges = 0;
this.slot = this.lastMarker = -1; this.slot = this.lastMarker = -1;
this.count = this.energy = 0; this.count = this.energy = 0;
this.quietWindows = 0;
this.referencePower = null;
this.haveInput = true;
this.q1.fill(0); this.q2.fill(0); this.q1.fill(0); this.q2.fill(0);
} }
record(kind) { record(kind) {
@ -43,6 +55,23 @@ export class AcousticDetector {
if (power[0] < min || power[marker] < min || this.energy === 0) return -1; if (power[0] < min || power[marker] < min || this.energy === 0) return -1;
return marker - 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) { window(marker, endMs) {
this.tick++; this.tick++;
let valid = marker >= 0; let valid = marker >= 0;
@ -71,6 +100,7 @@ export class AcousticDetector {
this.locked = true; this.locked = true;
} }
this.windows++; this.windows++;
this.observeLevel(valid);
if (!valid) { if (!valid) {
if (!this.gap) this.record('signal missing or out of sequence'); if (!this.gap) this.record('signal missing or out of sequence');
this.bad++; this.bad++;
@ -81,9 +111,13 @@ export class AcousticDetector {
} }
process(samples, frame, length) { process(samples, frame, length) {
if (this.windows >= this.target) return; 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; this.nextFrame = frame + length;
for (let i = 0; i < length && this.windows < this.target; i++) { 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; const x = samples?.[i] ?? 0;
this.energy += x * x; this.energy += x * x;
for (let j = 0; j < this.coeff.length; j++) { for (let j = 0; j < this.coeff.length; j++) {
@ -93,12 +127,15 @@ export class AcousticDetector {
if (++this.count === this.size) { if (++this.count === this.size) {
this.window(this.detect(), (frame + i + 1) * 1000 / this.rate); this.window(this.detect(), (frame + i + 1) * 1000 / this.rate);
this.q1.fill(0); this.q2.fill(0); this.count = this.energy = 0; this.q1.fill(0); this.q2.fill(0); this.count = this.energy = 0;
this.haveInput = true;
} }
} }
} }
summary(nowMs) { summary(nowMs) {
return {locked: this.locked, complete: this.windows >= this.target, return {locked: this.locked, complete: this.windows >= this.target,
observedMs: this.windows * this.windowMs, windows: this.windows, observedMs: this.windows * this.windowMs, windows: this.windows,
levelDrops: this.dropCount, longestLevelDropMs: this.longestDropMs,
firstLevelDropMs: this.firstDropMs,
missingWindows: this.bad, sequenceFaults: this.sequenceFaults, missingWindows: this.bad, sequenceFaults: this.sequenceFaults,
missingFraction: this.windows ? this.bad / this.windows : null, missingFraction: this.windows ? this.bad / this.windows : null,
gapMaxMs: this.longest * this.windowMs, trailingGapMs: this.gap * this.windowMs, gapMaxMs: this.longest * this.windowMs, trailingGapMs: this.gap * this.windowMs,

View File

@ -2,6 +2,7 @@ import {TRIAL_SECONDS} from './acoustic-pattern.js';
export const phoneTest = new URLSearchParams(location.search).get('test') === 'phone'; export const phoneTest = new URLSearchParams(location.search).get('test') === 'phone';
const status = document.getElementById('path-state'); const status = document.getElementById('path-state');
const detail = document.getElementById('path-detail');
const clock = ms => { const clock = ms => {
const s = Math.min(TRIAL_SECONDS, Math.floor(ms / 1000)); const s = Math.min(TRIAL_SECONDS, Math.floor(ms / 1000));
return Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0'); 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.detector = node;
run.pathInterruptions = 0; run.pathInterruptions = 0;
status.textContent = 'Waiting for phone signal'; status.textContent = 'Waiting for phone signal';
detail.hidden = true;
node.onprocessorerror = () => { if (isCurrent()) finish('detector failed'); }; node.onprocessorerror = () => { if (isCurrent()) finish('detector failed'); };
node.port.onmessage = ({data}) => { node.port.onmessage = ({data}) => {
if (!isCurrent()) return; if (!isCurrent()) return;
@ -43,11 +45,16 @@ export async function attachDetector(run, isCurrent, finish) {
run.path = {...data, discontinuities:interruptions}; run.path = {...data, discontinuities:interruptions};
if (data.locked) { if (data.locked) {
const gaps = data.missingWindows > 0 || data.sequenceFaults > 0; 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'; status.textContent = label + ' · ' + clock(data.observedMs) + ' / 30:00';
if (data.complete) { if (data.complete) {
status.textContent = interruptions ? '30 minutes · incomplete observation' : 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'); finish('phone test complete');
} }
} }

View File

@ -3,7 +3,8 @@
<title>Audio Test</title><link rel="stylesheet" href="style.css"> <title>Audio Test</title><link rel="stylesheet" href="style.css">
<main><h1>Audio Test</h1><a href="./">A/V Test</a> <main><h1>Audio Test</h1><a href="./">A/V Test</a>
<p><a id="path-link" href="mic.html?test=phone">30-minute RCT receiver test</a> <a href="phone.html">Phone sound source</a></p> <p><a id="path-link" href="mic.html?test=phone">30-minute RCT receiver test</a> <a href="phone.html">Phone sound source</a></p>
<p id="path-state" role="status" hidden></p> <p id="path-state" role="status" title="Level drops require at least 100 ms at least 20 dB below the recognized phone reference." hidden></p>
<p id="path-detail" hidden></p>
<div><button id="devices">Choose devices…</button> <div><button id="devices">Choose devices…</button>
<label>Microphone <select id="input"></select></label> <label>Microphone <select id="input"></select></label>
<label>Output <select id="output"></select></label></div> <label>Output <select id="output"></select></label></div>