gibberish-dsp
Version:
Gibberish is designed to be an optimized API for audio synthesis using per-sample techniques.
94 lines (68 loc) • 2.75 kB
JavaScript
/* Intro tutorial
This tutorial provides some quick examples of creating synths,
routing them through effects, sequencing them, and adding
modulations.
The code display on the right side of the screen shows the
callback generated by Gibberish; calling this function once will output
a single sample (potentially stereo) of data. Whenever you execute
code in the editor on the left, the callback will be update to show
the results.
---=== GETTING STARTED ===---
To execute code in the left-hand editor:
a. execute selected block: hit Ctrl+Enter
b. execute one line: place cursor on line and hit Ctrl+Enter
c. execute block: place cursor in block and hit Alt+Enter
"blocks" are delimited by empty lines. Most examples are formatted so that
they can be executed as a single block; just place your cursor inside
of them and hit Alt+Enter.
To clear audio graph and stop sound: Ctrl+. (Ctrl+Period)
Here's a quick tutorial to get started. Click on the demos menu to see other
tutorials and examples.*/
// note that all synthesis objects have been exported to the global
// namespace (window) for this playground. In normal usage you would
// preface their names with the Gibberish object.
// create a one oscillator synth with an attack/decay envelope
synth = Synth()
// connect our Synth to the master output of Gibberish
synth.connect( Gibberish.out )
// play a note at a provided frequency
synth.note( 220 )
// change the attack time (measured in samples)
synth.attack = 44100
synth.note( 220 )
// this can be shortened to:
synthB = Synth({ attack:44100 }).connect()
synthB.note( 330 )
// clear all DSP
Gibberish.clear()
// kick drum
kick = Kick().connect()
// sequence kick every half second at 110 Hz
seq = Sequencer({ target:kick, key:'note', values:[120], timings:[22050] }).start()
// add another frequency to the sequence
seq.values = [120,240]
// faster!
seq.timings = [11025]
// clear
Gibberish.clear()
// Synth2 comes with an osc, filter, and attack/decay envelope
synth = Synth({ filterType:2, attack:44, decay: 5512 }).connect()
// make a reverb effect using the Freeverb algorithm
verb = Freeverb({ input:synth, roomSize:.975, damping:.5 }).connect()
// our synth is now connected directly to the main output bus
// as well as to our reverb, which is turn also connected to the
// output bus
seq = Sequencer({
target:synth,
key:'note',
values:[55,110,165,220],
timings:[5512]
})
seq.start()
// modulate our synth's cutoff frequency, which is in the range
// of 0..1
synth.cutoff = Add( .75, Sine({ frequency:.1, gain:.375 }) )
// be careful when adjusting the Q... setting it to too high
// a value can cause the synth's filter to blow up (and possibly
// your eardrums as well).
synth.Q = .75