Skip to content

Instantly share code, notes, and snippets.

@NHQ
Last active December 18, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NHQ/5778704 to your computer and use it in GitHub Desktop.
Save NHQ/5778704 to your computer and use it in GitHub Desktop.
web audio script processing basics
var master = new webkitAudioContext();
var sineWave = master.createOscillator(); // a default sinewave generator
// this is your js PCM processor node
var scriptNode = master.createScriptProcessor(2048, 1, 1); // chunk size, channels in, channels out
// define this function
scriptNode.onaudioprocess = function(e){
// FYI var chans = e.inputBuffer.numberOfChannels
var output = e.outputBuffer.getChannelData(0); // returns Float32Array(2048)
var input = e.inputBuffer.getChannelData(0); // same as above
output.set(input) // this would pass the input to the output w/o modification
}
sineWave.connect(scriptNode) // connect generator to script node
scriptNode.connect(master.destination); // connect to master out
sineWave.start(0) // start sending the signal to the scriptNode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment