Skip to content

Commit

Permalink
Merge pull request #346 from grazder/ringbuffer-fix
Browse files Browse the repository at this point in the history
fixed ring buffer indexes updates in design patterns
  • Loading branch information
hoch authored Oct 13, 2023
2 parents bfbdd6e + 43803d9 commit 6b3e732
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/audio-worklet/design-pattern/lib/wasm-audio-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6b3e732

Please sign in to comment.