Skip to content

Commit

Permalink
Update audioWorklet.js
Browse files Browse the repository at this point in the history
Accumulate 1 second of data before starting playback
  • Loading branch information
guest271314 authored Sep 21, 2023
1 parent 8f38623 commit 268c210
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions audioWorklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class AudioDataWorkletStream extends AudioWorkletProcessor {
Object.assign(this, options.processorOptions, {
uint8: new Uint8Array(70982024),
});
this.started = false;
this.port.onmessage = this.appendBuffers.bind(this);
}
async appendBuffers({ data: { readable } }) {
Expand All @@ -19,10 +18,10 @@ class AudioDataWorkletStream extends AudioWorkletProcessor {
}
for (let i = !index ? 44 : 0; i < value.length; i++) {
this.uint8[index++] = value[i];
}
if (!this.started) {
this.started = true;
this.port.postMessage({ start: true });
// accumulate 1 second of data to avoid glitches at beginning of playback
if (index === 44100) {
this.port.postMessage({ start: true });
}
}
return stream(await reader.read());
};
Expand Down

0 comments on commit 268c210

Please sign in to comment.