summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-09-11 21:39:43 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-09-11 21:39:43 -0400
commite248d78e875fa41db317b50817e30ec3ca778f78 (patch)
tree7446edd6fd073c1e5f2b3c8e0c51404629848c3e /2d
parenta73088300c2902e4d9b6c6adf5289fb117012582 (diff)
Add audio module.
This is just a think layer over some basic SDL mixer functions so that users don't need to deal with SDL directly.
Diffstat (limited to '2d')
-rw-r--r--2d/audio.scm80
1 files changed, 80 insertions, 0 deletions
diff --git a/2d/audio.scm b/2d/audio.scm
new file mode 100644
index 0000000..d67eebe
--- /dev/null
+++ b/2d/audio.scm
@@ -0,0 +1,80 @@
+;;; guile-2d
+;;; Copyright (C) 2013 David Thompson <dthompson2@worcester.edu>
+;;;
+;;; Guile-2d is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU Lesser General Public License as
+;;; published by the Free Software Foundation, either version 3 of the
+;;; License, or (at your option) any later version.
+;;;
+;;; Guile-2d is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; Lesser General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Lesser General Public
+;;; License along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; Wrappers over SDL mixer.
+;;
+;;; Code:
+
+(define-module (2d audio)
+ #:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-2)
+ #:use-module ((sdl mixer) #:prefix SDL:))
+
+;; Wrapper over SDL audio objects.
+(define-record-type <sample>
+ (make-sample audio)
+ sample?
+ (audio sample-audio))
+
+(define (load-sample filename)
+ "Load audio sample from FILENAME. Return #f on failure."
+ (let ((audio (SDL:load-wave filename)))
+ (if audio
+ (make-sample audio)
+ #f)))
+
+(define (sample-play sample)
+ "Play SAMPLE."
+ (SDL:play-channel (sample-audio sample)))
+
+(export make-sample
+ load-sample
+ sample?
+ sample-audio
+ sample-play)
+
+;; Wrapper over SDL music objects.
+(define-record-type <music>
+ (make-music audio)
+ music?
+ (audio music-audio))
+
+(define (load-music filename)
+ "Load music from FILENAME. Return #f on failure."
+ (let ((audio (SDL:load-music filename)))
+ (if audio
+ (make-music audio)
+ #f)))
+
+(define (music-play music)
+ "Play MUSIC."
+ (SDL:play-music (music-audio music)))
+
+(export make-music
+ load-music
+ music?
+ music-audio
+ music-play)
+
+(re-export (SDL:pause-music . music-pause)
+ (SDL:resume-music . music-resume)
+ (SDL:rewind-music . music-rewind)
+ (SDL:halt-music . music-stop)
+ (SDL:paused-music? . music-paused?)
+ (SDL:playing-music? . music-playing?))