-
Notifications
You must be signed in to change notification settings - Fork 24
/
simple-demo.html
71 lines (43 loc) · 1.3 KB
/
simple-demo.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
69
70
71
<!DOCTYPE html>
<html>
<head>
<script src="tune.js"></script>
</head>
<body style="font-family:helvetica;">
<h1 style="font-weight:100">Tune.js Simple Demo</h1>
<h2 style="font-weight:100">Turn up your sound</h2>
</body>
<script>
/* TUNE SETUP */
// Create a new Tune object
var tune = new Tune();
// Load a 12 tone just intonation scale
tune.loadScale('slendro');
/* WEB AUDIO SETUP */
var actx = new (AudioContext || wedkitAudioContext)();
var osc = actx.createOscillator()
var vol = actx.createGain()
var echo = actx.createDelay()
echo.delayTime.value = 0.3
vol.gain.value = 0.5
osc.type = "sawtooth"
osc.connect(vol).connect(echo).connect(actx.destination)
echo.connect(vol)
osc.start()
/* PLAYING NOTES */
changeNote = function() {
var step = random(tune.scale.length)
var octave = random(-3,2)
var newFreq = tune.note( step, octave )
osc.frequency.setValueAtTime( newFreq, actx.currentTime)
}
setInterval(changeNote, 50)
var random = function(limit,limit2) {
if (limit2) {
return Math.floor(Math.random() * (limit2-limit)) + limit
} else {
return Math.floor(Math.random() * limit)
}
}
</script>
</html>