aboutsummaryrefslogtreecommitdiff
path: root/src/sounds.ts
diff options
context:
space:
mode:
authorJoris2022-06-11 16:42:33 +0200
committerJoris2022-06-11 16:42:33 +0200
commit03197b1ab992540b951fcbc6f841cfcd42a757f3 (patch)
tree2eb5277462b8dfef41e901a945f251725fb7ad8f /src/sounds.ts
parent70c672535f36edaeaf1d63d4637830b564271c34 (diff)
Add kick sequencer
Diffstat (limited to 'src/sounds.ts')
-rw-r--r--src/sounds.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/sounds.ts b/src/sounds.ts
new file mode 100644
index 0000000..9ce8d2e
--- /dev/null
+++ b/src/sounds.ts
@@ -0,0 +1,29 @@
+export interface Sounds {
+ kick: AudioBuffer
+}
+
+const audioContext = new AudioContext()
+let lazy: undefined | Sounds = undefined
+
+export async function load(): Promise<Sounds> {
+ if (lazy !== undefined) {
+ return lazy
+ } else {
+
+ const kick = await fetch('/sounds/kick.opus')
+ .then(res => res.arrayBuffer())
+ .then(ArrayBuffer => audioContext.decodeAudioData(ArrayBuffer))
+
+ lazy = {
+ kick
+ }
+ return lazy
+ }
+}
+
+export function playKick(sounds: Sounds) {
+ const source = audioContext.createBufferSource()
+ source.buffer = sounds.kick
+ source.connect(audioContext.destination)
+ source.start()
+}