-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpad.js
More file actions
57 lines (47 loc) · 1.39 KB
/
Copy pathpad.js
File metadata and controls
57 lines (47 loc) · 1.39 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function addPadNote(v, t, f) {
var fader = ac.createGain();
fader.connect(reverb);
var lnf = Math.log(f);
var peakScale = (0.0529162 * lnf - 0.785209) * lnf + 3.57215
var decayScale = 0.15;
var attack = 0.017;
var peakTime = t + attack;
var sawPeak = 0.44 * peakScale;
var squarePeak = 0.5 * sawPeak;
var filter = ac.createBiquadFilter();
filter.connect(fader);
filter.frequency.value = 402;
filter.detune.setValueAtTime(756, t);
filter.detune.setTargetAtTime(0, peakTime, 2 * decayScale);
var sawGain = ac.createGain();
sawGain.connect(filter);
sawGain.gain.setValueAtTime(0, t);
sawGain.gain.linearRampToValueAtTime(sawPeak, peakTime);
var saw1 = ac.createOscillator();
saw1.type = "sawtooth";
saw1.frequency.value = 1.0035 * f;
saw1.connect(sawGain);
saw1.start(t);
var saw2 = ac.createOscillator();
saw2.type = "sawtooth";
saw2.frequency.value = 0.9965 * f;
saw2.connect(sawGain);
saw2.start(t);
var squareGain = ac.createGain();
sawGain.connect(filter);
sawGain.gain.setValueAtTime(0, t);
sawGain.gain.linearRampToValueAtTime(squarePeak, peakTime);
var square = ac.createOscillator();
square.type = "square";
square.frequency.value = f;
square.connect(squareGain);
square.start(t);
var note = {
fader: fader,
oscillators: [saw1, saw2, square],
start: t,
expiration: Infinity,
frequency: f
}
return note;
}