Add audio example.
authorDavid Thompson <dthompson2@worcester.edu>
Thu, 12 Dec 2019 13:43:41 +0000 (08:43 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Tue, 7 Apr 2020 20:17:02 +0000 (16:17 -0400)
* examples/audio.scm: New file.
* Makefile.am (EXTRA_DIST): Add it.

Makefile.am
examples/audio.scm [new file with mode: 0644]
examples/audio/AUTHORS [new file with mode: 0644]
examples/audio/explosion.wav [new file with mode: 0644]
examples/audio/spooky-dungeon.ogg [new file with mode: 0644]
examples/audio/the-forgotten-land.mp3 [new file with mode: 0644]
examples/audio/venus.wav [new file with mode: 0644]

index 23d7e5a..ce67cd0 100644 (file)
@@ -86,6 +86,7 @@ SOURCES =                                     \
 
 EXTRA_DIST +=                                  \
   COPYING                                      \
+  examples/audio.scm                           \
   examples/sprite.scm                          \
   examples/lines.scm                           \
   examples/text.scm                            \
diff --git a/examples/audio.scm b/examples/audio.scm
new file mode 100644 (file)
index 0000000..b3e1de4
--- /dev/null
@@ -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 (file)
index 0000000..1baaa5a
--- /dev/null
@@ -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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..a050a26
Binary files /dev/null and b/examples/audio/venus.wav differ