Add live voice playback diagnostics and sample accounting
This commit is contained in:
@@ -95,6 +95,16 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor {
|
||||
|
||||
clear() {
|
||||
this.reportFinal(); // final cumulative report for the interrupted ref
|
||||
// Attribute queued output and the deferred tail to their real references.
|
||||
const discarded = new Map();
|
||||
for (const span of this.refQueue) {
|
||||
discarded.set(span.ref, (discarded.get(span.ref) ?? 0) + span.out);
|
||||
}
|
||||
const tail = Math.max(0, Math.round(this.admittedSrc / this.ratio) - this.emittedOut);
|
||||
if (tail > 0) discarded.set(this.pendingRef, (discarded.get(this.pendingRef) ?? 0) + tail);
|
||||
for (const [audioRef, discardedSamples] of discarded) {
|
||||
this.port.postMessage({ type: 'discarded', audioRef, discardedSamples, contextRate: sampleRate });
|
||||
}
|
||||
this.r = this.w = this.count = 0;
|
||||
this.queuedSource = 0;
|
||||
this.refQueue.length = 0;
|
||||
@@ -310,7 +320,7 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor {
|
||||
// Multiply integer counts first to avoid rounding an exact whole millisecond down.
|
||||
const playedMs = Math.floor((playedOut * 1000) / sampleRate);
|
||||
if (playedMs <= 0) return;
|
||||
this.port.postMessage({ type: 'progress', audioRef: ref, playedMs });
|
||||
this.port.postMessage({ type: 'progress', audioRef: ref, playedMs, consumedSamples: playedOut, contextRate: sampleRate });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user