-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
68 lines (59 loc) · 1.97 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>minima</title>
<meta charset="utf-8" />
<link
href="https://fonts.googleapis.com/css?family=Cinzel|Quattrocento+Sans"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation-flex.min.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="main"></div>
<script type="text/javascript" src="main.js"></script>
<script>
'use strict';
var app = Elm.Main.init({
node: document.getElementById('main')
});
var context = new (window.AudioContext || window.webkitAudioContext)();
var waveform = 'sine',
filterType = 'lowpass',
cutoff = 3000,
gain = 0.2;
var filter = context.createBiquadFilter();
filter.type = filterType;
filter.frequency.value = cutoff;
filter.connect(context.destination);
function playNote(frequency, duration) {
// intstantiate and initialize nodes
var osc = context.createOscillator();
var amp = context.createGain();
osc.type = waveform;
osc.frequency.value = frequency;
amp.gain.value = gain;
// routing
osc.connect(amp);
amp.connect(filter);
// set timing and amp envelope
var now = context.currentTime;
amp.gain.cancelScheduledValues(now);
amp.gain.linearRampToValueAtTime(gain + 0.05, now + 0.03); // attack
amp.gain.setTargetAtTime(gain, now + 0.03, 0.01); // decay
amp.gain.setValueAtTime(gain, now + 0.03); // set mark for release
amp.gain.exponentialRampToValueAtTime(0.0001, now + duration); // release
osc.start();
osc.stop(now + duration);
}
app.ports.play.subscribe(function(args) {
playNote(args.frequency, args.duration);
});
</script>
</body>
</html>