From 43803d9080d3fcdeaeca5c721e9327ea27f7b0e2 Mon Sep 17 00:00:00 2001 From: Alexey Korepanov Date: Thu, 12 Oct 2023 14:06:46 +0400 Subject: [PATCH] fix ring buffer indexes --- .../design-pattern/lib/wasm-audio-helper.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/audio-worklet/design-pattern/lib/wasm-audio-helper.js b/src/audio-worklet/design-pattern/lib/wasm-audio-helper.js index 7b2826225..1ea76b5fd 100644 --- a/src/audio-worklet/design-pattern/lib/wasm-audio-helper.js +++ b/src/audio-worklet/design-pattern/lib/wasm-audio-helper.js @@ -222,10 +222,7 @@ class RingBuffer { } } - this._writeIndex += sourceLength; - if (this._writeIndex >= this._length) { - this._writeIndex = 0; - } + this._writeIndex = (this._writeIndex + sourceLength) % this._length; // For excessive frames, the buffer will be overwritten. this._framesAvailable += sourceLength; @@ -258,10 +255,7 @@ class RingBuffer { } } - this._readIndex += destinationLength; - if (this._readIndex >= this._length) { - this._readIndex = 0; - } + this._readIndex = (this._readIndex + destinationLength) % this._length; this._framesAvailable -= destinationLength; if (this._framesAvailable < 0) {