export class BoundedAudioQueue {
    capacity;
    maxAgeMs;
    frames = [];
    processedFrames = 0;
    droppedOverflow = 0;
    droppedStale = 0;
    constructor(capacity = 24, maxAgeMs = 1500) {
        this.capacity = capacity;
        this.maxAgeMs = maxAgeMs;
    }
    push(frame, now) { this.dropStale(now); if (this.frames.length >= this.capacity) {
        this.frames.shift();
        this.droppedOverflow++;
    } this.frames.push(frame); }
    take(now) { this.dropStale(now); const frame = this.frames.shift(); if (frame)
        this.processedFrames++; return frame; }
    metrics() { return { processedFrames: this.processedFrames, droppedOverflow: this.droppedOverflow, droppedStale: this.droppedStale }; }
    dropStale(now) { while (this.frames.length && now - this.frames[0].createdAt > this.maxAgeMs) {
        this.frames.shift();
        this.droppedStale++;
    } }
}
