From 2ff6e24c2ea70512782dea8a779d2257a663219a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 9 Jan 2018 08:42:46 -0500 Subject: 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. --- chickadee/audio.scm | 21 ++++++++++++--------- 1 file 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 -- cgit v1.2.3