summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-12-12 08:43:41 -0500
committerDavid Thompson <dthompson2@worcester.edu>2020-04-07 16:17:02 -0400
commita91a08f3f564d18b1b0801d0388672a1e16390ae (patch)
tree31d3d9bcfe37fc120b3ac799726919ac044d151a /examples
parente20eb48dbaa3de9d12b380b5de4cdf7be5b9c8a2 (diff)
Add audio example.
* examples/audio.scm: New file. * Makefile.am (EXTRA_DIST): Add it.
Diffstat (limited to 'examples')
-rw-r--r--examples/audio.scm63
-rw-r--r--examples/audio/AUTHORS21
-rw-r--r--examples/audio/explosion.wavbin0 -> 86796 bytes
-rw-r--r--examples/audio/spooky-dungeon.oggbin0 -> 496835 bytes
-rw-r--r--examples/audio/the-forgotten-land.mp3bin0 -> 1517046 bytes
-rw-r--r--examples/audio/venus.wavbin0 -> 2265902 bytes
6 files changed, 84 insertions, 0 deletions
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
--- /dev/null
+++ b/examples/audio/explosion.wav
Binary files differ
diff --git a/examples/audio/spooky-dungeon.ogg b/examples/audio/spooky-dungeon.ogg
new file mode 100644
index 0000000..9fc6313
--- /dev/null
+++ b/examples/audio/spooky-dungeon.ogg
Binary files differ
diff --git a/examples/audio/the-forgotten-land.mp3 b/examples/audio/the-forgotten-land.mp3
new file mode 100644
index 0000000..15e5147
--- /dev/null
+++ b/examples/audio/the-forgotten-land.mp3
Binary files differ
diff --git a/examples/audio/venus.wav b/examples/audio/venus.wav
new file mode 100644
index 0000000..a050a26
--- /dev/null
+++ b/examples/audio/venus.wav
Binary files differ