Last active
December 18, 2015 11:49
-
-
Save NHQ/5778704 to your computer and use it in GitHub Desktop.
web audio script processing basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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