Geekcamp 2015
- Chinmay Pendharkar
bgsound
<object> , <embed>
<audio>
— W3C WebAudio Draft Spec
// Create Context and Nodex
var audioCtx = new AudioContext();
var oscillator = audioCtx.createOscillator();
var filter = context.createBiquadFilter();
// Set parameter values
oscillator.detune.value = -400;
filter.type = filter.LOWPASS;
filter.frequency.value = 5000;
// Connect nodes
oscillator.connect(filter);
filter.connect(audioCtx.destination);
var sp = context.createScriptProcessor();
sp.onprocess = function (processEvent){
/* fill your own buffer */
var out = autoTune(processEvent.inputBuffers);
processEvent.outputBuffers = out;
}
sp.connect(context.destination);
var context = new window.AudioContext();
var buffer = context.createBufferSource();
buffer.connect(context.destination);
filter.frequency.value = 400; // Set Frequency to 400Hz.
filter.Q // Filter Q-value
filter.gain // Filter gain
oscillator.frequency // Oscillator frequency.
oscillator.detune // Detune an oscillator
gain.gain // Set gain value (loudness)
delay.delayTime // Set the delay
buffer.playbackRate // Speed of playbackRate
panner.pan // Left/Right Panning
....
playRate.setValueAtTime(2, 5);
frequency.linearRampToValueAtTime(400, 2);
delayTime.exponentialRampToValueAtTime(3.1, 10);
pan.setTargetAtTime(-1, 7.2);
gain.setValueCurveAtTime([0, 1, 0.7, 0.7, 0.5, 0.2, 0], 0, 0.5)
var osc = context.createOscillator();
var gain = context.createGain();
// Connect oscillator to gain
osc.connect(gain.gain);
// Connect buffer to gain and gain to output
buffer.connect(gain);
gain.connect(context.destination);
var carrier = context.createOscillator();
var message = context.createOscillator();
// Connect oscillator to frequency
message.connect(carrier.frequency);
// Connect carrier to gain and gain to output
carrier.connect(context.destination);
// MIDI Input
navigator.requestMIDIAccess(function(midi){
for (let input of midi.inputs.values()) {
input.onmidimessage = function(event){
console.log("New MIDI Data:", event.data); // UInt8Array
}
}
});
// MIDI Output
midi.output[0].send( [ 0x90, 0x45, 0x7f ] );