Skip to content

Commit

Permalink
alsamixer: fix calculation in set_normalized_volume (overflow)
Browse files Browse the repository at this point in the history
Lowering volume below 0 causes overflow spike to 100% volume (volume goes
below 0 and back to 100 repeatedly). 0 overflows past infinity when holding
down z,x,c.

> value = lrint_dir(6000.0 * log10(volume), dir) + max;
   (where volume = 0 , and dir = -1 . min = -9999999 , and max = -6)
> log10(0) is negative infinity = error

Fixes: #266
Reported-by: genr8eofl <genBTC@gmx.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
perexg committed May 23, 2024
1 parent cc0bcef commit 84d0a91
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions alsamixer/volume_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static int set_normalized_volume(snd_mixer_elem_t *elem,
min_norm = pow(10, (min - max) / 6000.0);
volume = volume * (1 - min_norm) + min_norm;
}
if (volume <= 0)
volume = 1e-36;
value = lrint_dir(6000.0 * log10(volume), dir) + max;
return set_dB[ctl_dir](elem, channel, value, dir);
}
Expand Down

0 comments on commit 84d0a91

Please sign in to comment.