aboutsummaryrefslogtreecommitdiff
path: root/sound.scm
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2026-04-05 19:47:05 +0100
committerGene Pasquet <dev@etenil.net>2026-04-05 19:47:05 +0100
commit027053b11a3a5d861ed2fa2db245388bd95ac246 (patch)
tree84dfd90642bb6d8eb4e0e3fa3a9d651ba29b41e8 /sound.scm
parent927f37639a3d5a0d881a5c8709f2cf577aadb15e (diff)
Progress
Diffstat (limited to 'sound.scm')
-rw-r--r--sound.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/sound.scm b/sound.scm
new file mode 100644
index 0000000..a0bb945
--- /dev/null
+++ b/sound.scm
@@ -0,0 +1,45 @@
+(module downstroke/sound *
+ (import scheme
+ (chicken base)
+ (only srfi-1 for-each)
+ downstroke/mixer)
+
+ (define *sound-registry* '())
+ (define *music* #f)
+
+ (define (init-audio!)
+ (mix-open-audio! 44100 mix-default-format 2 512))
+
+ (define (load-sounds! sound-alist)
+ (set! *sound-registry*
+ (map (lambda (pair)
+ (cons (car pair) (mix-load-chunk (cdr pair))))
+ sound-alist)))
+
+ (define (play-sound sym)
+ (let ((entry (assq sym *sound-registry*)))
+ (when (and entry (cdr entry))
+ (mix-play-channel -1 (cdr entry) 0))))
+
+ (define (load-music! path)
+ (set! *music* (mix-load-mus path)))
+
+ (define (play-music! volume)
+ (when *music*
+ (mix-play-music *music* -1)
+ (mix-volume-music (inexact->exact (round (* volume 128))))))
+
+ (define (stop-music!) (mix-halt-music))
+
+ (define (set-music-volume! volume)
+ (mix-volume-music (inexact->exact (round (* volume 128)))))
+
+ (define (cleanup-audio!)
+ (when *music*
+ (mix-halt-music)
+ (mix-free-music! *music*)
+ (set! *music* #f))
+ (for-each (lambda (pair) (mix-free-chunk! (cdr pair)))
+ *sound-registry*)
+ (set! *sound-registry* '())
+ (mix-close-audio!)))