diff options
author | David Thompson <dthompson2@worcester.edu> | 2018-01-09 08:42:46 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2018-01-09 08:42:46 -0500 |
commit | 2ff6e24c2ea70512782dea8a779d2257a663219a (patch) | |
tree | 64b518d07c85deebd84e43e0053cc09f4c4e0cce | |
parent | 14f984b34d065d7c8bb27f5fe9a46cab4d66b563 (diff) |
audio: Use values between 0 and 1 for volume.
Hide the weird SDL usage of 0 to 128.
* chickadee/audio.scm (set-sample-volume!, music-volume,
set-music-volume!): Translate to/from SDL's volume range.
-rw-r--r-- | chickadee/audio.scm | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/chickadee/audio.scm b/chickadee/audio.scm index d92ae94..c92eb44 100644 --- a/chickadee/audio.scm +++ b/chickadee/audio.scm @@ -77,9 +77,10 @@ (error "cannot load audio sample:" file)))) (define (set-sample-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))) + "Set the volume that all samples are played at to VOLUME, a floating +point value between 0 and 1." + (ignore-value + (sdl2:set-channel-volume! #f (inexact->exact (round (* volume 128.0)))))) (define (play-sample sample) "Play SAMPLE." @@ -105,14 +106,16 @@ value between 0 and 128." (make-music (sdl2:load-music file))) (define (music-volume) - "Return the volume level for music, an integer value between 0 and -128." - (sdl2:music-volume)) + "Return the volume level for music, a floating point value between +0 and 1." + (/ (sdl2:music-volume) 128.0)) (define (set-music-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))) + "Set the volume that music is played at to VOLUME, a floating point +value between 0 and 1." + (ignore-value + (sdl2:set-music-volume! + (inexact->exact (round (* volume 128.0)))))) (define* (play-music music #:key loop?) "Play MUSIC. If LOOP?, play it over and over and over and over |