diff options
| -rw-r--r-- | src/main.rs | 30 | ||||
| -rw-r--r-- | static/car.mp3 | bin | 0 -> 33024 bytes | |||
| -rw-r--r-- | static/cat.mp3 | bin | 0 -> 15840 bytes | |||
| -rw-r--r-- | static/dog.mp3 | bin | 0 -> 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 Binary files differnew file mode 100644 index 0000000..3e98ada --- /dev/null +++ b/static/car.mp3 diff --git a/static/cat.mp3 b/static/cat.mp3 Binary files differnew file mode 100644 index 0000000..0cd0088 --- /dev/null +++ b/static/cat.mp3 diff --git a/static/dog.mp3 b/static/dog.mp3 Binary files differnew file mode 100644 index 0000000..298bb9e --- /dev/null +++ b/static/dog.mp3 |
