summaryrefslogtreecommitdiff
path: root/sly/audio.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-12-22 14:35:44 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-12-22 16:28:18 -0500
commit8b9b5d371d1dc1c780e227ce9a555cf6c88a85c8 (patch)
treef1b6524f92aaa329667f08f4a010a7b5e6925ae8 /sly/audio.scm
parent60d601cbb5eb142d01f880b5902329ada93fc91a (diff)
Upgrade to SDL2!
This commit is massive and crazy and I'm not going to do the usual GNU ChangeLog thing because it's just too much. Let's just be happy that the port is completed!
Diffstat (limited to 'sly/audio.scm')
-rw-r--r--sly/audio.scm55
1 files changed, 27 insertions, 28 deletions
diff --git a/sly/audio.scm b/sly/audio.scm
index 715df11..4f24e43 100644
--- a/sly/audio.scm
+++ b/sly/audio.scm
@@ -24,12 +24,11 @@
(define-module (sly audio)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-2)
- #:use-module ((sdl mixer) #:prefix SDL:)
+ #:use-module ((sdl2 mixer) #:prefix sdl2:)
#:export (enable-audio
load-sample
sample?
sample-audio
- sample-volume
set-sample-volume
play-sample
load-music
@@ -46,7 +45,11 @@
music-playing?))
(define (enable-audio)
- (SDL:open-audio))
+ ;; The SDL mixer will throw an exception if it cannot initialize a
+ ;; particular audio format. We don't want this to be fatal, so we
+ ;; ignore it.
+ (false-if-exception (sdl2:mixer-init))
+ (sdl2:open-audio))
;; Used to wrap SDL audio functions whose return values should be
;; ignored.
@@ -64,20 +67,17 @@
(define (load-sample filename)
"Load audio sample from FILENAME or return #f if the file cannot be
loaded"
- (let ((audio (SDL:load-wave filename)))
+ (let ((audio (sdl2:load-chunk filename)))
(if audio (make-sample audio) #f)))
-(define (sample-volume)
- "Return the volume that all samples are played at."
- (SDL:volume))
-
(define (set-sample-volume volume)
- "Set the volume that all samples are played at to VOLUME."
- (ignore-value (SDL:volume volume)))
+ "Set the volume that all samples are played at to VOLUME, an integer
+value between 0 and 128."
+ (ignore-value (sdl2:set-channel-volume! #f volume)))
(define (play-sample sample)
"Play the given audio SAMPLE."
- (ignore-value (SDL:play-channel (sample-audio sample))))
+ (ignore-value (sdl2:play-chunk! (sample-audio sample))))
;; Wrapper over SDL music objects.
(define-record-type <music>
@@ -85,44 +85,43 @@ loaded"
music?
(audio music-audio))
-(define (load-music filename)
- "Load music from FILENAME or return #f if the file cannot be
-loaded."
- (let ((audio (SDL:load-music filename)))
- (if audio (make-music audio) #f)))
+(define (load-music file)
+ "Load music from FILE."
+ (make-music (sdl2:load-music file)))
(define (music-volume)
"Return the volume that music is played at."
- (SDL:music-volume))
+ (sdl2:music-volume))
(define (set-music-volume volume)
- "Set the volume that music is played at to VOLUME."
- (ignore-value (SDL:volume volume)))
+ "Set the volume that music is played at to VOLUME, an integer value
+between 0 and 128."
+ (ignore-value (sdl2:set-music-volume! volume)))
(define (play-music music)
"Play the given MUSIC."
- (ignore-value (SDL:play-music (music-audio music))))
+ (sdl2:play-music! (music-audio music)))
(define (pause-music)
"Pause the current music track."
- (ignore-value (SDL:pause-music)))
+ (sdl2:pause-music!))
(define (resume-music)
"Resume the current music track."
- (ignore-value (SDL:resume-music)))
+ (sdl2:resume-music!))
(define (rewind-music)
"Restart the current music track."
- (ignore-value (SDL:rewind-music)))
+ (sdl2:rewind-music!))
(define (stop-music)
"Stop playing the current music track."
- (ignore-value (SDL:halt-music)))
+ (sdl2:stop-music!))
(define (music-playing?)
- "Return #t if music is currently playing, otherwise return #f."
- (SDL:playing-music?))
+ "Return #t if music is currently playing."
+ (sdl2:music-playing?))
(define (music-paused?)
- "Return #t if music is currently paused, otherwise return #f."
- (SDL:paused-music?))
+ "Return #t if music is currently paused."
+ (sdl2:music-paused?))