Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeQueue + WASM example #255

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Format sink-processor.js
  • Loading branch information
DivyamAhuja committed Sep 19, 2022
commit 9c6da20fd30b0b7b23011560a9fd87fabe02eab4
2 changes: 1 addition & 1 deletion src/_data/build_info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"3.0.2","revision":"a7e8c6d","lastUpdated":"2022-09-10","copyrightYear":2022}
{"version":"3.0.2","revision":"d762369","lastUpdated":"2022-09-11","copyrightYear":2022}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,20 @@ const RENDER_QUANTUM = 128
class SinkProcessor extends AudioWorkletProcessor {
constructor(options) {
super();
// Initialize the Queue.
// We have to set prototype of queue, because queue object is passed
// using structured cloning algorithm.
// See -
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
// Initializes a FreeQueue object with the option passed from the
// AudioWorkletNode constructor on the main thread.
this.queue = options.processorOptions.queue;
Object.setPrototypeOf(this.queue, FreeQueue.prototype);
}

process(inputs, outputs) {
const output = outputs[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means it only fills up a single channel (mono). Why can't we do the stereo?

Copy link
Contributor Author

@DivyamAhuja DivyamAhuja Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library just acts as queue to share data between 2 threads.
So, I think it's up to user how they use it.

inputs and outputs are array of arrays of arrays (3 dimensional arrays)

outputs: [
  output_0: [
    channel_0: [0, 0, 0.5, 0.6....],
    channel_1: [0, 0, 0.5, 0.6....]
  ],
  output_1: [
    channel_0: [0, 0, 0.5, 0.6....],
    channel_1: [0, 0, 0.5, 0.6....],
  ]
]

So, we are technically pushing data into 2 channels of 0th output in this case


// Pull out render quantum frame from the queue into output.
// If failed, print "failed" to console.
const didPull = this.queue.pull(output, RENDER_QUANTUM);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

return this.queue.pull(output, RENDER_QUANTUM) ? true : false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can return false here.

Then I think audio worklet will just stop 🤔

https://webaudio.github.io/web-audio-api/#callback-audioworketprocess-callback

So I think we should always return true, to keep worklet alive

didPull ? null : console.log("failed");

return true;
}

}
DivyamAhuja marked this conversation as resolved.
Show resolved Hide resolved


registerProcessor('sink-processor', SinkProcessor);