Route mic self-test monitoring through the (possibly AEC3-cancelled) signal

setMonitoring() connected the raw pre-AEC3 mic source straight to playback,
so the self-test howled regardless of AEC3 - it was bypassing the whole
cancellation path entirely, not failing to cancel. Mirror the processed
signal into the ScriptProcessorNode's own output and monitor that instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-09-17 18:41:31 +00:00
1 parent effabafa23
commit 7b52c0baa4
1 file changed
+15 -6
+15 -6
View File
@@ -128,6 +128,11 @@ export class MicCapture {
this.aec3.process(this.aec3Out, captureIn);
input = this.aec3Out[0];
}
// Mirrors the (possibly AEC3-cancelled) signal to the output buffer, so
// setMonitoring() below can tap what's actually being sent rather than
// the raw pre-cancellation mic feed - a self-test through the raw feed
// always howls, whether or not AEC3 is on.
event.outputBuffer.getChannelData(0).set(input);
let sumSquares = 0;
for (let i = 0; i < input.length; i++) sumSquares += input[i] * input[i];
@@ -170,21 +175,25 @@ export class MicCapture {
return this.source;
}
/** Routes the raw mic signal to `destination` too, so you can hear yourself (a mic test), until disabled again. */
/** Routes the (possibly AEC3-cancelled) mic signal to `destination` too, so
* you can hear yourself - a mic test - until disabled again. Taps the
* processor's output rather than the raw source, so the test actually
* reflects AEC3 when it's on, instead of always howling via the
* uncancelled raw feed. */
setMonitoring(enabled: boolean, destination: AudioNode): void {
if (!this.source) return;
if (!this.processor) return;
if (enabled && this.monitorTarget !== destination) {
if (this.monitorTarget) this.source.disconnect(this.monitorTarget);
this.source.connect(destination);
if (this.monitorTarget) this.processor.disconnect(this.monitorTarget);
this.processor.connect(destination);
this.monitorTarget = destination;
} else if (!enabled && this.monitorTarget) {
this.source.disconnect(this.monitorTarget);
this.processor.disconnect(this.monitorTarget);
this.monitorTarget = null;
}
}
stop(): void {
if (this.source && this.monitorTarget) this.source.disconnect(this.monitorTarget);
if (this.processor && this.monitorTarget) this.processor.disconnect(this.monitorTarget);
this.monitorTarget = null;
this.processor?.disconnect();
this.silence?.disconnect();