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

[RFC] (ao_pipewire:) logarithmic volume control #15836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WhitePeter
Copy link

This is a proof of concept to get logarithmic volume control with
ao_pipewire, because a logarithmic function best describes human
loudness perception. Anything in the analog world, e.g. HiFi amps, uses
logarithmic potentiometers in their volume control circuitry for this
reason.

There is an important difference though. The 0dB, aka 100% full blast,
mark is shifted by 100, so as to not mess up the volume control code,
thus 100, in this context, means 0dB and is actually the same as before
in that respect. The only noticeable differences are:
1) volume in-/decrements are now in decibels and
2) 0 is actually 2 in the mixer controls, e.g. pulsemixer

As for 1), a good minimum in-/decrement is +/-3 as that is considered
just significant enough to make a difference. As a side note, the cutoff
frequency of a low-pass filter, for instance, is defined as the
frequency at which the response has dropped by -3dB for this reason.

As for 2), a linear value of zero is impossible on a logarithmic scale
as that would equate to -infinity decibels. But, for all intents and
purposes, -100dB is virtually silent.

The reason for this being an RFC is that the proper way, as may have
become clear by, would be to represent 0dB as such in all the user
facing interfaces. But this author has no idea how one would go about
that. Maybe the above is sufficient, as in: it's not technically correct
but good enough for our purposes.

Also the scale to the other end, the positive values, is way too liberal
with possible values of +100dB, as that would be far above and beyond
any reasonable "overdrive" amplification. But this author has volume-max
set to 100 anyway, since over-amplification is basically just asking for
clipping. A somewhat reasonable maximum could be 112, aka +12dB, which
should be plenty over-amplified already, but if you must...

As a longer term goal this author would like to see all ao_* modules
using a logarithmic volume scale, as it is "the only correct way"(tm).
;-)

@WhitePeter WhitePeter marked this pull request as ready for review February 8, 2025 14:30
@WhitePeter WhitePeter force-pushed the pipewire-logarithmic-vol branch from 35e6671 to d19b03e Compare February 8, 2025 15:46
Copy link

github-actions bot commented Feb 8, 2025

Download the artifacts for this pull request:

Windows
macOS

@WhitePeter WhitePeter force-pushed the pipewire-logarithmic-vol branch from d19b03e to b3e2299 Compare February 8, 2025 17:27
@WhitePeter
Copy link
Author

WhitePeter commented Feb 9, 2025

I just pushed this to master in my own fork. So anybody wanting to try this feel free to pull from there. Might need to rebase against upstream, since I am not doing this on any kind of schedule.

@WhitePeter WhitePeter force-pushed the pipewire-logarithmic-vol branch from b3e2299 to e69f2f7 Compare February 9, 2025 20:39
This is a proof of concept to get logarithmic volume control with
ao_pipewire, because a logarithmic function best describes human
loudness perception. Anything in the analog world, e.g. HiFi amps, uses
logarithmic potentiometers in their volume control circuitry for this
reason.

There is an important difference though. The 0dB, aka 100% full blast,
mark is shifted by 100, so as to not mess up the volume control code,
thus 100, in this context, means 0dB and is actually the same as before
in that respect. The only noticeable differences are:
    1) volume in-/decrements are now in decibels and
    2) 0 is actually 2 in the mixer controls, e.g. pulsemixer

As for 1), a good minimum in-/decrement is +/-3 as that is considered
just significant enough to make a difference. As a side note, the cutoff
frequency of a low-pass filter, for instance, is defined as the
frequency at which the response has dropped by -3dB for this reason.

As for 2), a linear value of zero is impossible on a logarithmic scale
as that would equate to -infinity decibels. But, for all intents and
purposes, -100dB is virtually silent.

The reason for this being an RFC is that the proper way, as may have
become clear by, would be to represent 0dB as such in all the user
facing interfaces. But this author has no idea how one would go about
that. Maybe the above is sufficient, as in: it's not technically correct
but good enough for our purposes.

Also the scale to the other end, the positive values, is way too liberal
with possible values of +100dB, as that would be far above and beyond
any reasonable "overdrive" amplification. But this author has volume-max
set to 100 anyway, since over-amplification is basically just asking for
clipping. A somewhat reasonable maximum could be 112, aka +12dB, which
should be plenty over-amplified already, but if you must...

As a longer term goal this author would like to see all ao_* modules
using a logarithmic volume scale, as it is "the only correct way"(tm).
;-)

See also: mpv-player#1345, mpv-player#3545
@WhitePeter WhitePeter force-pushed the pipewire-logarithmic-vol branch from e69f2f7 to 2a7b02a Compare February 12, 2025 17:53
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.

1 participant