-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
102 lines (91 loc) · 2.5 KB
/
index.html
File metadata and controls
102 lines (91 loc) · 2.5 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Rain Soundscape Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.jsdelivr.net/gh/innovation-adelphiu/info-button@main/info-button.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lil-gui@0.21"></script>
<style>
body
{
font-family: sans-serif;
margin: 30px;
background-color: #001122;
color: #cceeff;
text-align: center;
}
.lil-gui
{
--width: 300px;
--widget-height: 32px;
--font-size: 14px;
--input-font-size: 14px;
left: 10px !important;
right: auto !important;
}
</style>
</head>
<body>
<br><br><br><br><br><br><br><br><br><br><br><br>
<h1>Rain Soundscape Generator</h1>
<p>Use the panel above to control volumes and playback.</p>
<script>
const tracks = [];
function createTrack(fileName, startValue)
{
const audio = new Audio(fileName);
audio.loop = true;
audio.volume = startValue;
const track = { audio: audio, baseVolume: startValue };
tracks.push(track);
return track;
}
const rainTrack = createTrack("audio/rain.mp3", 0.60); // Rain/Wind
const thunderTrack = createTrack("audio/thunder.mp3", 1.00); // Thunder
function playAll()
{
for (let i = 0; i < tracks.length; i++)
tracks[i].audio.play();
}
function stopAll()
{
for (let i = 0; i < tracks.length; i++)
tracks[i].audio.pause();
}
// lil-gui setup
const GUI = lil.GUI;
const gui = new GUI();
gui.title("Audio Controls");
gui.close();
const audioParams =
{
masterVolume: 1.00,
rainVolume: 0.60,
thunderVolume: 1.00,
playSound: () => playAll(),
stopSound: () => stopAll()
};
function syncParamsToAudio()
{
rainTrack.baseVolume = audioParams.rainVolume;
thunderTrack.baseVolume = audioParams.thunderVolume;
for (let i = 0; i < tracks.length; i++)
tracks[i].audio.volume = tracks[i].baseVolume * audioParams.masterVolume;
}
// sliders
gui.add(audioParams, "masterVolume", 0, 1, 0.01)
.name("Master Volume")
.onChange(syncParamsToAudio);
gui.add(audioParams, "rainVolume", 0, 1, 0.01)
.name("Rain/Wind Volume")
.onChange(syncParamsToAudio);
gui.add(audioParams, "thunderVolume", 0, 1, 0.01)
.name("Thunder Volume")
.onChange(syncParamsToAudio);
// buttons
gui.add(audioParams, "playSound").name("Play Audio");
gui.add(audioParams, "stopSound").name("Stop Audio");
</script>
</body>
</html>