summaryrefslogtreecommitdiff
path: root/platform/javascript/js
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-09-14 03:38:52 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-09-15 11:58:52 +0200
commitba08f39e47f12c6910388f41367305c93eaa06e4 (patch)
tree713e185f33e9cb1c6c04b9c1e1bccb3a7e016d2d /platform/javascript/js
parentf2c44949c07e5ec2aadf519fca98e5bb1517f74c (diff)
[HTML5] Fix bug in AudioWorklet when reading output buffer.
Would attempt an out of bounds read, causing an exception.
Diffstat (limited to 'platform/javascript/js')
-rw-r--r--platform/javascript/js/libs/audio.worklet.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/platform/javascript/js/libs/audio.worklet.js b/platform/javascript/js/libs/audio.worklet.js
index 866f845139..df475ba52d 100644
--- a/platform/javascript/js/libs/audio.worklet.js
+++ b/platform/javascript/js/libs/audio.worklet.js
@@ -66,17 +66,17 @@ class RingBuffer {
const mw = this.buffer.length - this.wpos;
if (mw >= to_write) {
this.buffer.set(p_buffer, this.wpos);
+ this.wpos += to_write;
+ if (mw === to_write) {
+ this.wpos = 0;
+ }
} else {
- const high = p_buffer.subarray(0, to_write - mw);
- const low = p_buffer.subarray(to_write - mw);
+ const high = p_buffer.subarray(0, mw);
+ const low = p_buffer.subarray(mw);
this.buffer.set(high, this.wpos);
this.buffer.set(low);
+ this.wpos = low.length;
}
- let diff = to_write;
- if (this.wpos + diff >= this.buffer.length) {
- diff -= this.buffer.length;
- }
- this.wpos += diff;
Atomics.add(this.avail, 0, to_write);
Atomics.notify(this.avail, 0);
}