summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Salt <linux@youmustbejoking.demon.co.uk>2004-11-30 19:47:03 +0000
committerDarren Salt <linux@youmustbejoking.demon.co.uk>2004-11-30 19:47:03 +0000
commit12f17c6ccc13429971722299e0f3ca98bef1b688 (patch)
treec3740f2a698b31a19c36a29af43708637774f991
parent61e98c3849f2bf78e6a7bd927233062fcbd3cf90 (diff)
downloadxine-lib-12f17c6ccc13429971722299e0f3ca98bef1b688.tar.gz
xine-lib-12f17c6ccc13429971722299e0f3ca98bef1b688.tar.bz2
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
-rw-r--r--src/audio_out/audio_alsa_out.c17
1 files 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 <James@superbug.demon.co.uk>
*
*
- * $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);
}
/*