On Github kindohm / audiolibjs-intro
Created by Mike Hodnick [github.com/kindohm]
*hint: because it is freaking awesome
JavaScript -> Audio API -> Browser
JavaScript -> audiolib.js -> Audio API -> Browser
* Not the same as the HTML5 <audio> object.
var osc, device, channels = 1; var audioCallback = function(buffer, channelCount) { osc.append(buffer, channelCount); }; device = audioLib.AudioDevice(audioCallback, channels); osc = audioLib.Oscillator(device.sampleRate, 400);
for (index = 0; index < buffer.length; index += 2){ osc1.generate(); osc2.generate(); leftSample = osc1.getMix(); rightSample = osc2.getMix(); buffer[index] = leftSample; buffer[index + 1] = rightSample; }
for (index = 0; index < buffer.length; index += channels) { lfo.generate(); osc.fm = lfo.getMix(); osc.generate(); sample = osc.getMix(); // fill buffer... }
for (i = 0; i < oscillators.length; i++) { oscillators[i].generate(); sample += oscillators[i].getMix() * level; }
Only so much headroom is available.
User-controlled mixing versus computed.
var sample = 0; generator.generate(); sample = generator.getMix(); effect.pushSample(sample); sample += effect.getMix();