Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIXES: alsamixer lowering volume control widget past 0 causes hostile volume spike to 100 #266

Closed
wants to merge 1 commit into from

Conversation

genbtc
Copy link

@genbtc genbtc commented Apr 19, 2024

bug: lowering volume below 0 causes volume to overflow and spike to 100% volume hurting my ears.

to reproduce: when holding down z,x,c to lower the volume, the volume spikes to 100% and then down to 0% over and over

background:
when volume is already 0 and direction is -1 (lowering volume) - but lower than 0 is impossible
the function set_normalized_volume @ volume-mapping.c is eventually still called anyway
value = lrint_dir(6000.0 * log10(volume), dir) + max;
and volume is 0, so
log10(0) resolves to negative infinity, so
value overflows past infinity. 9223372036854775802
alsamixer-alsa-utils-volumemap-bug3_2024-04-18_13-27-23

my fix:
this function change_volume_relative function will now skip execution of the set_normalized_playback_volume function when volume is 0 and the dir is -1
TLDR: (stop trying to set a lower volume than 0)

bug: lowering volume below 0 causes overflow spike to 100% volume hurting my ears.
   (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

Signed-off-by: genr8eofl <genBTC@gmx.com>
@perexg
Copy link
Member

perexg commented Apr 22, 2024

I think that this change is better (fixes the function where the problem occurs and tries to set the minimal dB value again instead skipping the command):

diff --git a/alsamixer/volume_mapping.c b/alsamixer/volume_mapping.c
index 29ab061..f34801c 100644
--- a/alsamixer/volume_mapping.c
+++ b/alsamixer/volume_mapping.c
@@ -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);
 }

@perexg perexg closed this in 84d0a91 May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants