learnvst
learnvst

Reputation: 16195

Audio effects with NaCl extension

I have just started investigating NaCl in the hopes of making an audio browser extension. There is a sine wave demo in the documentation, so it seems that making a synthesizer would be trivial.

I am interested to know if it is possible to capture the browser audio stream before it is output so that real-time effects can be applied. Is this possible?

Upvotes: 2

Views: 481

Answers (1)

Cutch
Cutch

Reputation: 3575

Not only is it possible. I've done it. You create a ScriptProcessorNode whose onaudioprocess callback takes the inputbuffer and passes it to a waiting NaCl module via postMessage. Once the NaCl module is finished processing it sends it back to JavaScript via postMessage. The ScriptProcessorNode must output something so you introduce a 1 frame delay and the ScriptProcessorNode copies the most recent processed output received from NaCl.

The Flow looks like this:

ScriptProcessorNode -> postMessage input buffer to NaCl

ScriptProcessorNode -> copy most recent buffer received from NaCl into output buffer.

NaCl -> Receives audio sample buffer, processes it and posts it back.

Let me know if you want me to post the code on GitHub or have anymore questions.

HTH, John

Upvotes: 4

Related Questions