Limit volume up to 80 dB

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.

1 Like

:point_up: :nerd_face: 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 :shrimp: 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
In alsamixer, 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ā€ā€¦?

amixer

-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…)!

4 Likes

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.

1 Like

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! :nerd_face: ". 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! :nerd_face:

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? :crazy_face:

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…) :frog:

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! :sweat_smile: 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.

2 Likes

sigh. i tried my very best to indicate that you can just use your EARS to determine whether it’s loud or not :smiley_cat:

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). :stuck_out_tongue_closed_eyes:

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.

6 Likes

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.

2 Likes

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%.