From a91a08f3f564d18b1b0801d0388672a1e16390ae Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 12 Dec 2019 08:43:41 -0500 Subject: Add audio example. * examples/audio.scm: New file. * Makefile.am (EXTRA_DIST): Add it. --- examples/audio.scm | 63 ++++++++++++++++++++++++++++++++++ examples/audio/AUTHORS | 21 ++++++++++++ examples/audio/explosion.wav | Bin 0 -> 86796 bytes examples/audio/spooky-dungeon.ogg | Bin 0 -> 496835 bytes examples/audio/the-forgotten-land.mp3 | Bin 0 -> 1517046 bytes examples/audio/venus.wav | Bin 0 -> 2265902 bytes 6 files changed, 84 insertions(+) create mode 100644 examples/audio.scm create mode 100644 examples/audio/AUTHORS create mode 100644 examples/audio/explosion.wav create mode 100644 examples/audio/spooky-dungeon.ogg create mode 100644 examples/audio/the-forgotten-land.mp3 create mode 100644 examples/audio/venus.wav (limited to 'examples') diff --git a/examples/audio.scm b/examples/audio.scm new file mode 100644 index 0000000..b3e1de4 --- /dev/null +++ b/examples/audio.scm @@ -0,0 +1,63 @@ +(use-modules (chickadee) + (chickadee audio) + (chickadee math vector) + (chickadee render font) + (ice-9 match)) + +(define effect #f) +(define music #f) +(define music-source #f) +(define playlist + #("audio/the-forgotten-land.mp3" + "audio/venus.wav" + "audio/spooky-dungeon.ogg")) +(define playlist-index -1) +(define status-message "") +(define status-position (vec2 200.0 240.0)) +(define instructions + "VAMP (Very Advanced Music Player) + +CONTROLS: + +SPACE - play/pause +N - next music file +P - previous music file +L - play an explosion sound just because +Q - quit") +(define instructions-position (vec2 200.0 400.0)) + +(define (playlist-move n) + (source-stop music-source) + (set! playlist-index (modulo (+ playlist-index n) (vector-length playlist))) + (let ((file-name (vector-ref playlist playlist-index))) + (set! music (load-audio file-name #:mode 'stream)) + (set-source-audio! music-source music) + (source-play music-source) + (set! status-message (string-append "NOW PLAYING: " (basename file-name))))) + +(define (load) + (set! effect (load-audio "audio/explosion.wav")) + (set! music-source (make-source)) + (playlist-move 1)) + +(define (update dt) + (when (source-stopped? music-source) + (playlist-move 1))) + +(define (draw alpha) + (when (>= playlist-index 0) + (draw-text status-message status-position)) + (draw-text instructions instructions-position)) + +(define (key-press key scancode modifiers repeat?) + (match key + ('q (abort-game)) + ('space (source-toggle music-source)) + ('l (audio-play effect)) + ('n + (playlist-move 1)) + ('p + (playlist-move -1)) + (_ #t))) + +(run-game #:load load #:update update #:key-press key-press #:draw draw) diff --git a/examples/audio/AUTHORS b/examples/audio/AUTHORS new file mode 100644 index 0000000..1baaa5a --- /dev/null +++ b/examples/audio/AUTHORS @@ -0,0 +1,21 @@ +-*- org -*- + +* explosion.wav + By: TinyWorlds + License: CC0 + URL: https://opengameart.org/content/explosion-0 + +* the-forgotten-land.mp3 + By: SketchyLogic + License: CC-BY 3.0 + URL: https://opengameart.org/content/war-of-the-arcane-18-rpg-tracks + +* spooky-dungeon.ogg + By: Memoraphile @ You're Perfect Studio + License: CC0 + URL: https://opengameart.org/content/spooky-dungeon + +* venus.wav + By: SketchyLogic + License: CC0 + URL: https://opengameart.org/content/nes-shooter-music-5-tracks-3-jingles diff --git a/examples/audio/explosion.wav b/examples/audio/explosion.wav new file mode 100644 index 0000000..c789505 Binary files /dev/null and b/examples/audio/explosion.wav differ diff --git a/examples/audio/spooky-dungeon.ogg b/examples/audio/spooky-dungeon.ogg new file mode 100644 index 0000000..9fc6313 Binary files /dev/null and b/examples/audio/spooky-dungeon.ogg differ diff --git a/examples/audio/the-forgotten-land.mp3 b/examples/audio/the-forgotten-land.mp3 new file mode 100644 index 0000000..15e5147 Binary files /dev/null and b/examples/audio/the-forgotten-land.mp3 differ diff --git a/examples/audio/venus.wav b/examples/audio/venus.wav new file mode 100644 index 0000000..a050a26 Binary files /dev/null and b/examples/audio/venus.wav differ -- cgit v1.2.3