Skip to content

Commit

Permalink
Fix RWebAudioInit race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien authored and LibretroAdmin committed Jul 2, 2023
1 parent 280dcb3 commit 58aafee
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions emscripten/library_rwebaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var LibraryRWebAudio = {
RA.buffers[RA.numBuffers - 1] = buf[0];
i--;
RA.bufIndex--;
} else if (!RA.startTime) {
RA.setStartTime();
}
}
},
Expand Down Expand Up @@ -74,7 +76,7 @@ var LibraryRWebAudio = {
block: function() {
do {
RA.process();
} while (RA.bufIndex === RA.numBuffers-2);
} while (RA.bufIndex === RA.numBuffers);
}
},

Expand All @@ -87,8 +89,6 @@ var LibraryRWebAudio = {

RA.numBuffers = ((latency * RA.context.sampleRate) / (1000 * RA.BUFFER_SIZE))|0;
if (RA.numBuffers < 2) RA.numBuffers = 2;

RA.numBuffers++;

for (var i = 0; i < RA.numBuffers; i++) {
RA.buffers[i] = RA.context.createBuffer(2, RA.BUFFER_SIZE, RA.context.sampleRate);
Expand All @@ -114,7 +114,7 @@ var LibraryRWebAudio = {
var count = 0;

while (samples) {
if (RA.bufIndex === RA.numBuffers-2) {
if (RA.bufIndex === RA.numBuffers) {
if (RA.nonblock) break;
else RA.block();
}
Expand Down

0 comments on commit 58aafee

Please sign in to comment.