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?

but why, there is a way! but only for pulseaudio and alsa afaik? (bruh)

where @DEFAULT_SINK@ is your current output device, i.e. headphones or speakers,
and @DEFAULT_SOURCE@ is your current input device, i.e. microphone or loopback.

“100%”:

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 is not great…)
(btw dont be confused with -1dB (gain), -1dB (pactl/pacmd) and 1dB- (amixer) lol, one is a volume setting and another is volume decrease!)
(btw no.2: apparently alsa and pulseaudio calculate gain levels… differently?)

incremental:

pactl set-sink-volume @DEFAULT_SINK@ +3dB
pactl set-sink-volume @DEFAULT_SINK@ -3dB
amixer set Master +3dB
amixer set Master -3dB

(or -c @DEFAULT_SINK@ idk?)

and here’s the fun part for actually limiting the maximum volume: you dont! pulseaudio doesnt have a limit (again, afaik). i think pulsemixer does. alsa, however, does, and it is by default capped at 100%.

this is why people (who are still using alsa and/or pulse) use graphical (software) mixers (e.g. pavucontrol, pulsemixer, 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. they dont exist and they cant hurt you.

but here comes pipewire with wireplumber:

wpctl set-volume -l 1.5 @DEFAULT_SINK@ 5%+
wpctl set-volume -l 1.5 @DEFAULT_SINK@ 5%-

(specify -l 1.5 or --limit 1.5 flag to set a 150% limit for a key bind)

yes. there is no way for pipewire (AFAIK!) to set a volume to a specific gain in decibels… you really shouldnt do this via SOFTWARE in the first place! get a HARDWARE mixer and twist all your knobs however you want.

this is how, for example, hyprland (window manager) did it:

bindel = , XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+
bindel = , XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindel = , XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindel = , XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle

(where 1 is 100%)
(btw usually window managers dont even come with key bindings, but desktop environments do)

they’ve bound those media keys (the name of which you can get via pkgs.wev or pkgs.xev) and set a limit, session-wide. of course, you can also use wiremix or sonusmix or something like that.

yeah. pipewire doesnt have this “dB” feature and for a good reason - 0dB doesnt necessarily mean 100% - both as perceivable volume/loudness and as software volume/loudness. besides, everything distorts after 100%. just like waffle8946 said - it’s inaccurate. shrimple :shrimp: as that. your -80dB is not the same as my -80dB.

but hey, worry not, because pipewire is in active development, maybe one day we’ll get gain limi-… ah, yes, hardware mixers! quite a useful piece of techware! comes with knobs that you can physically touch and change the gain… in decibels! or even LUFS!

edit: coming back to this with some new information for future readers:

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

…

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.
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 volume… this is the first time in my lyfe ive seen anyone actually use or even want to have this “feature”. i respect that.

in music industry, people use LUFS or dB. that’s it. 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: ".

but anyway, sure, well, let’s see what we’ve got…

ah yes, iphones and macbooks do come with an SPL dB hardware meter (androids dont), but, uh, you see… well… ugh, what am i getting into… they’re just BAD (who would’ve thunk it)! 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 weight comparison (sigh. a decibel is a unit of comparison and an iphone is just a toy. a pretty expensive toy, too. you know what’s more expensive than an iphone? an actual SPL dB meter. they are more expensive, because they’re not a toy and they have all the dB weighing schemes that you NEED in order to actually measure the SPL!)

and in the end, what is it going to tell you? people perceive loudness differently. our hearing is 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!

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 things. the problem is that you’re probably gonna do it by “feel” anyway, but i guess at this point it this is just an auxiliary little software for fine-tuning your output.

fun fact: a physics professor made this!

EDIT: oh nvm, it DOES have LUFS, i didnt know that! lol. well, here you go! i think this is the one! (software LUFS is the same as hardware LUFS, fyi)

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:

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