Improve mapping of relative to absolute volume.
I added bounds checking to the patch and cg improved the formular. Submitted by: Andriy Gapon <avg@icyb.net.ua> PR: kern/65485 Approved by: cg Reviewed by: imp, rwatson, le
This commit is contained in:
parent
939fca9bea
commit
134896e1fc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130472
@ -330,6 +330,19 @@ sb16mix_init(struct snd_mixer *m)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rel2abs_volume(int x, int max)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = ((x * max) + 50) / 100;
|
||||
if (temp > max)
|
||||
temp = max;
|
||||
else if (temp < 0)
|
||||
temp = 0;
|
||||
return (temp);
|
||||
}
|
||||
|
||||
static int
|
||||
sb16mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
|
||||
{
|
||||
@ -340,8 +353,8 @@ sb16mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
|
||||
e = &sb16_mixtab[dev];
|
||||
max = (1 << e->bits) - 1;
|
||||
|
||||
left = (left * max) / 100;
|
||||
right = (right * max) / 100;
|
||||
left = rel2abs_volume(left, max);
|
||||
right = rel2abs_volume(right, max);
|
||||
|
||||
sb_setmixer(sb, e->reg, left << e->ofs);
|
||||
if (e->stereo)
|
||||
|
Loading…
Reference in New Issue
Block a user