(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!)))