summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Hafskjold Thoresen <martin@vind.ai>2025-01-04 23:22:29 +0100
committerMartin Hafskjold Thoresen <martin@vind.ai>2025-01-04 23:22:29 +0100
commite249e3003b569c7e3b270c06e02b87cad86ea2fb (patch)
tree3e63d459a4146144f49fd13b9bda46b97b5fd924
parentc5fce19c22ec32129a8b8135c35798e430c5fc53 (diff)
downloadmusicgame-e249e3003b569c7e3b270c06e02b87cad86ea2fb.tar.gz
musicgame-e249e3003b569c7e3b270c06e02b87cad86ea2fb.zip
Add some tunes
-rw-r--r--src/main.rs30
-rw-r--r--static/car.mp3bin0 -> 33024 bytes
-rw-r--r--static/cat.mp3bin0 -> 15840 bytes
-rw-r--r--static/dog.mp3bin0 -> 11702 bytes
4 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! {
diff --git a/static/car.mp3 b/static/car.mp3
new file mode 100644
index 0000000..3e98ada
--- /dev/null
+++ b/static/car.mp3
Binary files differ
diff --git a/static/cat.mp3 b/static/cat.mp3
new file mode 100644
index 0000000..0cd0088
--- /dev/null
+++ b/static/cat.mp3
Binary files differ
diff --git a/static/dog.mp3 b/static/dog.mp3
new file mode 100644
index 0000000..298bb9e
--- /dev/null
+++ b/static/dog.mp3
Binary files differ