Audio, the synthesis (in whichever way) of sound.
12 notes is a full octave.
-3 -1 1 4 6 9 11
-4 -2 0 2 3 5 7 8 10 12
.___________________________________________________________________________.
: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | :
: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | :
: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | :
<-: |_| | |_| |_| | |_| |_| |_| | |_| |_| | |_| |_| |_| | |_| |_| :->
: | | | | | | | | | | | | | | | | | | :
: A | B | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C | D | E :
:___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___:
^ ^ ^ ^ ^
220 Hz 440 Hz 523.25 Hz 880 Hz 1174.65 Hz
(-1 Octave) (middle A) (+1 Octave)
In order to change the tune with the web audio api do:
const osc = ctx.createOscillator() osc.type = 'sawtooth' osc.frequency.value = 440 osc.detune.value = 3 * 100
Filters can modify values. Using .connect() they are analogous to through
streams for audio.
const f = audioContext.createBiquadFilter() f.type = 'highpass' f.frequency.value = 10000 f.connect(ctx.destination)
lowpass only values lower highpass only values higher bandpass only values in range lowshelf highshelf peaking notch allpass
Envelopes wrap sounds and smear them over time.
Attack envelopes ramp up the value.
const attack = audioContext.createGain() attack.gain.value = 0 attack.gain.setTargetAtTime(1, startTime, 0.1)
release envelopes decrease the value.
const release = audioContext.createGain() release.gain.setTargetAtTime(0, endTime, 0.2)
Keep in mind when adding a release envelope, the sound needs to keep playing until the release finishes otherwise it will just stop.
// provide enough time for the exponential falloff oscillator.stop(endTime + 2)