Is there a way to limit volume up to 80 dB?
Well you canāt really limit sound in decibels, that depends on every device and piece of software in the chain.
But you can limit audio to whatever %, with the same methods as any other Linux distro.
actually, decibels dont mean volume or loudness, LUFS does. but anyway, -80 dB? with a MINUS, right? as in, BELOW full scale, also known as dBFS?
but why, there is a way! but i wouldnt recommend it⦠anyway, this works only for pulseaudio and alsa afaik? (bruh)
where @DEFAULT_SINK@ or @DEFAULT_AUDIO_SINK@ is your current output device, i.e. headphones or speakers,
and @DEFAULT_SOURCE@ or @DEFAULT_AUDIO_SOURCE@ is your current input device, i.e. microphone or loopback.
a bit of a disclaimer: i dont have alsa or pulseaudio installed, this is all off the top of my head (and my memory isnt greatā¦)
for example, ā100%ā is 0dB (LOUD WARNING):
pactl set-sink-volume @DEFAULT_SINK@ 0dB
or
pacmd set-sink-volume @DEFAULT_SINK@ 0dB
amixer -c @DEFAULT_SINK@ set Master 0dB
or
amixer set Master 0dB
(idk, their documentation on what syntax should be is not great, ahhā¦)
(btw dont be confused with -1dB (gain), -1dB (pactl/pacmd) and 1dB- (amixer) lol, one is a volume setting and two others are volume decrease commands! ikr? its a MESS!)
(btw no.2: apparently alsa and pulseaudio calculate gain (peak) levels⦠differently?)
raising and lowering volume levels incrementally:
pactl set-sink-volume @DEFAULT_SINK@ +3dB
pactl set-sink-volume @DEFAULT_SINK@ -3dB
amixer set Master +3dB
amixer set Master -3dB
(iirc ~3dB is like⦠5% plus/minus? correct me if im wrong!)
(or -c @DEFAULT_SINK@ idk?)
and hereās the fun part for actually limiting the maximum āvolumeā: you dont! iirc, pulseaudio doesnt have an upper limit by default, it is a job for the mixers to do, like pulsemixer. BUT! alsa actually does have an upper (dB? dBFS? most likely the latter, again, their docs are SHITE!!!) gain limit and it is capped at 100% by default⦠yeah, im pretty sure that is a hardcode, cos you cant reach levels higher than 0dB - GOOD. let it be that way. so, good news for lovers of legacy software - get your old ass ALSA today!
this is why people (who are still using alsa and/or pulseaudio) use graphical (software) mixers (e.g. pkgs.pavucontrol, pkgs.pulsemixer, pkgs.ncpamixer) or make tons of shell scripts with calculators like bc or something, which are bound to XF86AudioLowerVolume and XF86AudioRaiseVolume media keys⦠imo, it do be kinda jank tho. theyāre both legacy audio systems, so it doesnt matter that much, when modern systems route to pipewire ANYWAY, right? alsa and pulseaudio dont exist and they cant hurt youā¦
but what about the current 21st century? oh, hereās how itās done nowadays with pipewire and wireplumber:
wpctl set-volume -l 1 @DEFAULT_SINK@ 5%+
wpctl set-volume -l 1 @DEFAULT_SINK@ 5%-
(specify -l or --limit flag to set a certain gain / peak limit, where -l 1 is max of 100%, which you can bind to your media keys!)
yep. pipewire also cant limit gains / peaks in dB(FS). well, you really shouldnt do this via SOFTWARE in the first place! get a HARDWARE mixer and twist all your knobs however you want.
instead, many desktop environments and window managers limit the volume as a percentage:
for example, hyprland limits it by default:
bindl = , XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+
bindel = , XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindl = , XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindl = , XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
(where 1 is 100%. if there wasnt an -l then thatād be an L to your ears⦠no? ok, ill stopā¦)
(bindl on the first one so that one doesnt accidentally hold the key too much)
and this is how it is done in niri:
XF86AudioRaiseVolume repeat=false allow-when-locked=true { spawn-sh "wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1+ -l 1.0"; }
XF86AudioLowerVolume allow-when-locked=true { spawn-sh "wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1-"; }
XF86AudioMute repeat=false allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"; }
XF86AudioMicMute repeat=false allow-when-locked=true { spawn-sh "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"; }
notice theyāre all the same and also use wpctl. that;s simply because the --limit is exclusive to pipewire with wireplumber (afaik)!
those media keys, the name of which you can get via pkgs.wev or pkgs.xev, work session-wide, in all applications, it is the āsystem volumeā. there are graphical mixers you could also use, such as pkgs.pulsemeeter, pkgs.sonusmix, pkgs.wiremix and the like.
yeah. pipewire doesnt have this ādBā feature and for a good reason - 0dB doesnt necessarily mean 100% of VOLUME - its LOUDNESS is and will always be unique and always different! besides, everything distorts after 100%, which is, again, more often than not IS NOT actually 0dB! just like waffle8946 said - itās inaccurate. shrimple
as that. your 80dB is not the same as my 80dB, both in contexts of dBFS and SPL (dont worry about it), which alsamixer claims to be linear (?). its crazy hard to replicate anything that is non-linear in software! just like screen brightness isnt lightness and vice versa! yeah? it differs hardware to hardware and room to room. which is why i mentioned that roughly 3dB is equivalent to 5% - its awkward. moral of it all is: dont bother - its just too much to consider!
but hey, worry not, because pipewire is in active development, maybe one day weāll get RMS limi-⦠ah, yes, hardware mixers! quite a useful piece of techware! comes with knobs that you can physically touch and change them peaks⦠in decibels! perhaps even relative to full scale! or even LUFS!
edit: coming back to this with some new information for future readers (this is about the legacy alsa volume levels):
Volume Mapping
Inalsamixer, the volume is mapped to a value that is more natural for a human ear. The mapping is designed so that the position in the interval is proportional to the volume as a human ear would perceive it, i.e. the position is the cubic root of the linear sample multiplication factor. For controls with a small range (24 dB or less), the mapping is linear in the dB values so that each step has the same size visually.Only for controls without dB information, a linear mapping of the hardware volume register values is used (this is the same algorithm as used in the old
alsamixer).
ālinearāā¦?
-R Use the raw value for evaluating the percentage representation. This is the default mode. -M Use the mapped volume for evaluating the percentage representation like alsamixer, to be more natural for human ear.
P.S. as always, do fact check me. ugh, in general, it is rather an obscure way to control volume (erm, actually, PCM amplitude levels, cos volume isnt the right word, it is a convention, a norm, that people often simplify TO just a āvolumeā⦠and so did iā¦)!
Is OP perhaps referring to a db(A) SPL dosimetry limit rather than a volume gain perhaps? The 80 dB is concordant with the typical limit used, see below.
Mode 1 WHO standard level for adults: this will apply 1.6 Pa2h per 7 days as the reference exposure (derived from 80 dBA for 40 hours a week)
Safe Listening - Devices and Systems - A WHO-ITU Standard
Such functionality is available on iPhones and some brands of headphones based on my personal experience.
The reference above in Appendix 1 gives a method for the estimation of the dose received accounting for different elements of the processing chain.
It is not an easy task and I am not aware of an open source implementation existing.
You get the point. I want to limit volume up to 80 dB because it is the safe limit for ears and is available on modern devices on iPhone, as you listed. I suppose that itās easy to do on an iPhone because they all use the same hardware, and they are calibrated from the box. Then, it means finding out my speakersā maximum volume and tinkering with PipeWire to do it or just getting a hardware mixer, right?
Do the speakers no have a hardware volume control?
You could set that so the speakers do 80dB and you donāt have to configure any limits in software.
Because otherwise you would have to turn up your speakers to full volume and have the risk that if something were to fail on the software side being blasted at full volume.
EDIT: I kind of assumed desktop speakers but if we are talking about a laptop this may not apply.
oh dearie me. that is suuuch an unnecessary and obscure way to limit the vol-, NOPE, not volume, LOUDNESSā¦! OP should have been a bit more clear on this⦠well, this is the first time im seeing anyone wish to try this at homeā¦
for example, in music industry, people use LUFS or dB(FS). thatās it. NOT sound pressure levels! SPL dB is very, VERY unpopular. maybe a few nerdy scientists use it, AT BEST, just for the fancy statistics, "oh my, your venue is so incredibly loud!
". ahemā¦
ah yes, iphones and macbooks do come with an SPL dB hardware meter (androids dont afaik), but, uh, you see⦠well⦠ugh, what am i getting into⦠theyāre just TERRIBLE! itās not (never was) an accurate way of measuring ACOUSTIC PRESSURE LEVELS! you have many variables:
- calibration (none of the iphones/macbooks are, because they dont have a calibration feature lmao)
- directivity and linearity (itās⦠a mobile phone/laptop micā¦)
- wind protection (ditto)
- noise floor (noisy inductors!)
- SPL limit (ah yes, poor microphones (aka iphone/macbook) cant capture high SPLs, which is quite important if you want to know if somethingās louder than 80 SPL dB)
- A, B, C, L/Z weights, (so, non-RMS) (sigh. a decibel is a unit of comparison and an iphone is just a toy. get an actual SPL dB (sound level) meter. these are not a toy and they DO have all the acoustic pressure weighing schemes that you NEED in order to actually COMPARE and MEASURE the SPL!)
and in the end, what is it going to tell you? people perceive loudness differently. our hearing is unique. AND the audio hardware is ALSO unique! the environments in which sounds are played are unique! this is why this is utterly useless to someone who ISNT a scientist or a sound engineer.
but okay, perhaps you have a pet that is sensitive to high pressure levels or you yourself have a hearing condition. well, im am not an expert, and this is a nixOS forum (or is it?), not a place where you get medical advice (or do you?), but sure, letās see:
quite a dated paper, but nothingās changed. if anything, the situation is even worse. both androids and iphones are shit. thereās like chaos out there, have you seen..? i also found other .gov documents on this topic, but theyāre even more dated (2013-2015). what do you know! nobody uses SPL dB meters on their phones! itās a stupid idea!
so,
yes and no (for reasons above). but yes, please do get a hardware mixer, it is quite a useful piece of knobware, indeed!
tl;dr instead of a SPL dB meter, get a software LUFS meter (plugin) or a hardware LUFS meter (if you have a sound system at home), and, actually (i forgot about this one),
this:
is probably what youāre also looking for. it has a limiter, filters and other bits and bobs. the problem is that youāre probably gonna do it by āfeelā anyway (even though LUFS is accurate enough), but i guess at this point it this is just an auxiliary little software for fine-tuning your output. and just an FYI: software LUFS is the same as hardware LUFS, unlike SPL dB, which you are trying to measure, jeez! ![]()
fun fact: a physics professor made this!
so, finally, do you mind if i ask you: why do you need⦠to limit the loudness in SPL dB? like, the actual acoustic pressure? inside your room? ![]()
P.S. remember: if you play with the audio loudness in any way, you will degrade its quality, haha! dont use a āloudness normaliserā on the master output, haha! in a best case scenario, the mastering engineers ALREADY did the job for you, haha! (but nobody listenedā¦) ![]()
EDIT: right, my bad: ROUGHLY, about each and every 10dB (NOT gain this time! i already explained the full scale in my first reply) is a doubling of the perceived loudness, cos DECIBELS are logarithmic, not linear, just like pH and richter (earthquake) magnitude scales and the like. so, 20dB is 4 times louder, 30dB is 8 times louder, 80dB is 256 times louder (!), etc., but i didnt really consider the ENERGY intensity aspect which affects hearing over long(-term) periods of time (loudness recruitment and softness imperception) while answering this, SORRY!
again, ive just never seen anyone wanting to measure their room⦠UGH! seriously, forget about SPL dB, i dont recommend this! youāre not actually going to try it, right..?
EDIT2: oh, right, you also have the āstable volumeā feature on youtube and other āaudio normaliserā applications and stuff like that - those DO NOT do LOUDNESS normalisation, MOST LIKELY. they do PEAK (gain) normalisation (dBFS) - two different things! those will NOT help you achieve comfortable LOUDNESS levels in your room. once again, for the 9000th time, get an actual mixer that YOU (yourself) will be able to control to your comfortable LUFSsās, alright..?
EDIT3: oh, interesting:
so, APPARENTLY, and i did not know this, admittedly, youtubeās preferred normalised LOUDNESS level is -14 LUFS. that IS interesting, isnt it? today iāve learntā¦
i know im repeating myself, but just to be crystal clear: no one ever measures their bedrooms for sound pressure levels up to (rather uncomfortable) 80 SPL dB⦠LOL
I have no comment on anything besides this, but ā¦
⦠you are aware that high absolute sound volume can cause permanent hearing damage, yes? I understood @aljustiet to be asking, in casual terms, how to put a hard upper limit on absolute volume in order to protect their hearing. Your explanation of how dB SPL is not the best way to measure absolute volume is interesting, but does not really address the point of the question.
sigh. i tried my very best to indicate that you can just use your EARS to determine whether itās loud or not ![]()
i think itās stupid, is what im saying, to measure loudness in SPL.
and with that, i must leave. im realising that i have no interest in this anymore (sorry). ![]()
This will also be my last post to this thread, however, no, it is not safe to ājust use your earsā to determine whether something is too loud. The human brain is good at noticing a sudden change in the volume level, but really really bad at noticing a steady level of noise that is too high, particularly if it ramps up slowly. Just the opposite: youāll get used to it and think itās fine, and maybe even decide that the music needs to be turned up some more.
This is actually an interesting question that I realize Iām somewhat curious about too. The term youāre looking for is probably āloudness normalisationā, and Iām seeing some documentation on achieving that using EasyEffects. Thereās a preset made by someone that might be of interest to you (see: Digitalone1/EasyEffects-Presets). I donāt think itās exactly what youāre looking for (it seems to raise volume if too low and lowers volume if too high), but itās a good start to figuring out how to tweak EasyEffects.
NixOS doesnāt have a module to get EasyEffects going, but home-manager does (if you use it). You can also just write the user service yourself and test it out. The program is packaged as pkgs.easyeffects.
Thereās a volume control program called pwvucontrol that shows how much dB is reduced next to the volume slider. If I know the max SPL volume of the speakers/headphones, I think itās possible to approximately calculate the sound level currently. E.g., Bose QC Ultra 1 has a max volume of 100.3 dB, and minus -20 dB would be -46%.
