From 12f17c6ccc13429971722299e0f3ca98bef1b688 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 30 Nov 2004 19:47:03 +0000 Subject: Fix two errors in the volume <-> %age conversion functions: - always round to nearest (one did so, but the other rounded down); - %age to volume: add the minimum value afterwards, don't subtract it from the value to be converted (else only min==0 works). CVS patchset: 7169 CVS date: 2004/11/30 19:47:03 --- src/audio_out/audio_alsa_out.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/audio_out/audio_alsa_out.c b/src/audio_out/audio_alsa_out.c index 79123ff3b..8043993f2 100644 --- a/src/audio_out/audio_alsa_out.c +++ b/src/audio_out/audio_alsa_out.c @@ -26,7 +26,7 @@ * (c) 2001 James Courtier-Dutton * * - * $Id: audio_alsa_out.c,v 1.147 2004/07/15 21:46:51 hadess Exp $ + * $Id: audio_alsa_out.c,v 1.148 2004/11/30 19:47:03 dsalt Exp $ */ #ifdef HAVE_CONFIG_H @@ -129,12 +129,7 @@ static snd_output_t *jcd_out; */ static int ao_alsa_get_percent_from_volume(long val, long min, long max) { int range = max - min; - int tmp; - if (range == 0) - return 0; - val -= min; - tmp = rint((double)val / (double)range * 100); - return tmp; + return (range == 0) ? 0 : ((val - min) * 100.0 / range + .5); } /* Stolen from alsa-lib */ @@ -267,13 +262,7 @@ static void *ao_alsa_handle_event_thread(void *data) { */ static long ao_alsa_get_volume_from_percent(int val, long min, long max) { int range = max - min; - long tmp; - - if (range == 0) - return 0; - val -= min; - tmp = (long) ((range * val) / 100); - return tmp; + return (range == 0) ? min : (val * range / 100.0 + min + .5); } /* -- cgit v1.2.3