mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-09 02:45:42 +01:00
amixer: improve the raw percentual volume rounding
In commit "ae9ddeb63443cc2c46e0f0b915466cca0f800372" the rint() was changed to ceil(). Revert it back. The rint() rounding is more precise for most cases. Also, handle the special case where the percentual value is greather then zero. Set the min + 1 value in this case. At last, fix the return value in convert_prange() when range is zero. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
4aadfe334f
commit
361734165e
1 changed files with 10 additions and 4 deletions
|
@ -192,16 +192,22 @@ static int convert_prange(long val, long min, long max)
|
|||
int tmp;
|
||||
|
||||
if (range == 0)
|
||||
return 0;
|
||||
return min;
|
||||
val -= min;
|
||||
tmp = rint((double)val/(double)range * 100);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/* Function to convert from percentage to volume. val = percentage */
|
||||
/* Function to convert from percentage to volume. perc = percentage */
|
||||
static long convert_prange1(long perc, long min, long max)
|
||||
{
|
||||
long tmp;
|
||||
|
||||
#define convert_prange1(val, min, max) \
|
||||
ceil((val) * ((max) - (min)) * 0.01 + (min))
|
||||
tmp = rint(perc * (max - min) * 0.01);
|
||||
if (tmp == 0 && perc > 0)
|
||||
tmp++;
|
||||
return tmp + min;
|
||||
}
|
||||
|
||||
struct volume_ops {
|
||||
int (*get_range)(snd_mixer_elem_t *elem, long *min, long *max);
|
||||
|
|
Loading…
Reference in a new issue