-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
36 lines (26 loc) · 907 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
window.addEventListener('WebComponentsReady', function () {
console.log('Hello Saw!');
// Your JavaScript code should be here...
// Get handles for the knobs.
var kFreq = document.querySelector('#k-freq');
var kCutoff = document.querySelector('#k-cutoff');
var kReso = document.querySelector('#k-reso');
var kAmp = document.querySelector('#k-amp');
// Create web audio stuffs.
var context = new AudioContext();
var osc = context.createOscillator();
var lpf = context.createBiquadFilter();
var amp = context.createGain();
osc.type = 'sawtooth';
amp.gain.value = 0.25;
// Bind the knob to the oscillator frequency.
kFreq.bind(osc.frequency);
kCutoff.bind(lpf.frequency);
kReso.bind(lpf.Q);
kAmp.bind(amp.gain);
// Make connections.
osc.to(lpf).to(amp).to(context.DAC);
// TODO: Try AudioParam automation.
// Then start audio.
osc.start();
});