export class FixedDurationPcmRingBuffer {
    constructor(params) {
        this.chunks = [];
        this.totalBytes = 0;
        const bytesPerSecond = params.sampleRate * params.channels * (params.bitsPerSample / 8);
        this.maxBytes = Math.max(1, Math.round((bytesPerSecond * params.durationMs) / 1000));
    }
    append(chunk) {
        if (chunk.length === 0) {
            return;
        }
        this.chunks.push(chunk);
        this.totalBytes += chunk.length;
        while (this.totalBytes > this.maxBytes && this.chunks.length > 0) {
            const removed = this.chunks.shift();
            if (!removed) {
                break;
            }
            this.totalBytes -= removed.length;
        }
    }
    drain() {
        const combined = Buffer.concat(this.chunks);
        this.clear();
        return combined;
    }
    get byteLength() {
        return this.totalBytes;
    }
    clear() {
        this.chunks = [];
        this.totalBytes = 0;
    }
}
//# sourceMappingURL=fixed-duration-pcm-ring-buffer.js.map