On Github philippstucki / jsdayit-2014
The Modular Synth And Sound Processor at Your Fingertips
Advise on youtube: start presentation with question or shocking news. No questions, only answers. shocking news:interface AudioContext { readonly attribute AudioDestinationNode destination; // (...) OscillatorNode createOscillator(); GainNode createGain(); DelayNode createDelay(optional double maxDelayTime = 1.0); BiquadFilterNode createBiquadFilter(); ConvolverNode createConvolver(); // (...) };
interface AudioNode { void connect( ... ); void disconnect( ... ); readonly attribute AudioContext context; // (...) };
- Explain routing graph - Show Example
interface OscillatorNode : AudioNode { // (...) readonly attribute AudioParam frequency; void start(double when); void stop(double when); // (...) };
interface AudioParam { attribute float value; void setValueAtTime(float value, double startTime); void linearRampToValueAtTime(float value, double endTime); // (...) void cancelScheduledValues(double startTime); };
- direct value change - set value at given time, remains constant - set value using continous function - cancel schedule values
interface GainNode : AudioNode { readonly attribute AudioParam gain; };
- interesting property: negative gain
enum BiquadFilterType { "lowpass", "highpass", "bandpass", "lowshelf", (...) }; interface BiquadFilterNode : AudioNode { attribute BiquadFilterType type; readonly attribute AudioParam frequency; readonly attribute AudioParam Q; readonly attribute AudioParam gain; // (...) };
- shortly explain filter types - note how all of the parameters are AudioParams
- Used in many APIs: WebGL, Web Audio API, Canvas, etc.
Generic chunk of data, provides no direct access
Interfaces providing context on a ArrayBuffer:
Typed arrays are implementations of ArrayBufferView
> a = new Float32Array(4); [0, 0, 0, 0] > a[0] = Math.PI; > a; [3.1415927410125732, 0, 0, 0] > a.length; 4 > a.buffer; ArrayBuffer {} > a.buffer.byteLength; 16
interface AudioContext { // (...) void decodeAudioData(ArrayBuffer audioData, DecodeSuccessCallback successCallback, optional DecodeErrorCallback errorCallback); // (...) }
function loadBuffer(url, cb) { var r = new XMLHttpRequest(); r.open('GET', url, true); r.responseType = 'arraybuffer'; r.onload = function() { ctx.decodeAudioData(r.response, function(buffer) { cb.call(this, buffer); }); }; r.send(); }
interface AudioBuffer { Float32Array getChannelData(unsigned long channel); // (...) };
- in memory audio asset - raw and uncompressed - range is [-1;1]
Interface AudioBufferSourceNode : AudioNode { attribute AudioBuffer? buffer; readonly attribute AudioParam playbackRate; attribute boolean loop; attribute double loopStart; attribute double loopEnd; void start(...); void stop(...); };
- stop can only be called once - throw-away objects - buffer remains, is only assigned
- mathematical operation on two functions - produces a third function - think: blending
interface ConvolverNode : AudioNode { attribute AudioBuffer? buffer; // (...) };
interface AudioContext { // (...) ScriptProcessorNode createScriptProcessor(...); // (...) }
interface ScriptProcessorNode : AudioNode { attribute EventHandler onaudioprocess; // (...) };
interface AudioProcessingEvent : Event { readonly attribute double playbackTime; readonly attribute AudioBuffer inputBuffer; readonly attribute AudioBuffer outputBuffer; };
interface AudioBuffer { // (...) Float32Array getChannelData(unsigned long channel); };
enum OscillatorType { "sine", "square", "sawtooth", "triangle", "custom" }; interface OscillatorNode : AudioNode { void setPeriodicWave(PeriodicWave periodicWave); // (...) };
interface PeriodicWave { };
interface AudioContext { PeriodicWave createPeriodicWave(Float32Array real, Float32Array imag); // (...) }The real parameter represents an array of cosine terms (...) The imag parameter represents an array of sine terms (...)
interface DelayNode : AudioNode { readonly attribute AudioParam delayTime; };