-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (85 loc) · 3.06 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fire!</title>
<script>const TWO_PI = 6.28318530717958647693;</script>
<script type="text/javascript">
const map = (value, in_min, in_max, out_min, out_max) => (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
</script>
<script>
// audio manager
var AudioContext =
window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext;
const audioCtx = new AudioContext();
const numChannels = 2;
const sampleRate = audioCtx.sampleRate;
const bufferSize = Math.round(sampleRate/6);
console.log(`bufferSize = ${bufferSize}`);
const bufferTime = bufferSize / sampleRate;
// console.log(`bufferTime = ${bufferTime}`);
</script>
<script src="js/glide.js"></script>
<script src="js/biquad.js"></script>
<script src="js/crackling.js"></script>
<script src="js/roaring.js"></script>
<script src="js/hissing.js"></script>
<script src="js/sinewave.js"></script>
<script>
let crackle = new Crackling();
let roar = new Roaring();
let hiss = new Hissing();
let sinewave = new SineWave();
// periodically update the buffers in the sound sources
// this is not a perfect solution because the timing is not accurate thus leaing
let interval = bufferTime * 1000; // ms
let expected = performance.now() + interval;
setTimeout(step, interval);
function step() {
let dt = performance.now() - expected; // the drift (positive for overshooting)
if (dt > interval) {
// something really bad happened. Maybe the browser (tab) was inactive?
// possibly special handling to avoid futile "catch up" run
console.log("step timing error");
}
// do what is to be done
let cracklingSource = audioCtx.createBufferSource();
cracklingSource.connect(audioCtx.destination);
let roaringSource = audioCtx.createBufferSource();
roaringSource.connect(audioCtx.destination);
let hissingSource = audioCtx.createBufferSource();
hissingSource.connect(audioCtx.destination);
hissingSource.buffer = hiss.generate();
roaringSource.buffer = roar.generate();
cracklingSource.buffer = crackle.generate();
// sineSource.buffer = sinewave.generate();
hissingSource.start();
roaringSource.start();
cracklingSource.start();
/*
let sineSource = audioCtx.createBufferSource();
sineSource.connect(audioCtx.destination);
sineSource.buffer = sinewave.generate();
sineSource.start();
*/
// setup the next loop
expected += interval;
setTimeout(step, Math.max(0, interval - dt)); // take into account drift
}
function setSize(value)
{
crackle.setSize(value);
roar.setSize(value);
hiss.setSize(value);
sinewave.setFreq(value);
}
</script>
</head>
<body>
<h1>Fire!</h1>
<input type="range" min="0" max="1" step="0.001" value="1" oninput="setSize(this.value)" value="0.5">
</body></html>