summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 92bda43..3c98db2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -402,6 +402,36 @@ async fn route_index(State(st): State<Server>) -> Response {
(game_list)
button hx-post="/game" { "Create game" }
+
+ button #soundtest { "Sound test" }
+
+ script { (PreEscaped(r#"
+
+async function soundtest() {
+ const context = new AudioContext();
+
+ function loadSample(url) {
+ return fetch(url)
+ .then(response => response.arrayBuffer())
+ .then(buffer => context.decodeAudioData(buffer));
+ }
+
+ function playSample(sample, sampleNote, noteToPlay) {
+ const source = context.createBufferSource();
+ source.buffer = sample;
+ source.playbackRate.value = 2 ** ((noteToPlay - sampleNote) / 12);
+ source.connect(context.destination);
+ source.start(0);
+ }
+
+ const sample = await loadSample('/static/cat.mp3');
+ const audio = new Audio("/static/dog.mp3");
+ [0, 2, 4, 5, 7, 9, 11, 12].forEach((p, i) => setTimeout(() =>
+ playSample(sample, 60, 60 + p), 500 * i)
+ );
+}
+document.getElementById("soundtest").onclick = soundtest;
+"#)) }
};
html_response(html! {