Skip to content

Commit

Permalink
oto: bug fix: too many receiving data before consuming it
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Jul 28, 2024
1 parent e30088e commit ac2412e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions driver_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class OtoWorkletProcessor extends AudioWorkletProcessor {
this.bufferSize_ = %[1]d;
this.channelCount_ = %[2]d;
this.buf_ = new Float32Array();
this.waitRecv_ = false;
// Receive data from the main thread.
this.port.onmessage = (event) => {
Expand All @@ -75,22 +76,28 @@ class OtoWorkletProcessor extends AudioWorkletProcessor {
newBuf.set(this.buf_);
newBuf.set(buf, this.buf_.length);
this.buf_ = newBuf;
this.waitRecv_ = false;
}
}
process(inputs, outputs, parameters) {
const output = outputs[0];
// If the buffer is too short, request more data and return silence.
if (this.buf_.length < output[0].length*this.channelCount_) {
this.port.postMessage(null);
if (!this.waitRecv_) {
this.waitRecv_ = true;
this.port.postMessage(null);
}
for (let i = 0; i < output.length; i++) {
output[i].fill(0);
}
return true;
}
// If the buffer is short, request more data.
if (this.buf_.length < this.bufferSize_*this.channelCount_) {
if (this.buf_.length < this.bufferSize_*this.channelCount_ && !this.waitRecv_) {
this.waitRecv_ = true;
this.port.postMessage(null);
}
Expand Down

0 comments on commit ac2412e

Please sign in to comment.