Skip to content

Commit

Permalink
ao_pipewire: reactivate cubic volume control
Browse files Browse the repository at this point in the history
Commit c7b17be by @wtay disabled cubic volume control. This reintroduces
it. There must have been a misunderstanding. *Because* pipewire uses
linear scale volume and we *want* cubic volume control this translates
between the two.

Otherwise we would just adjust volume on a linear scale which is the
worst way to do it, because loudness is measured on a logarithmic scale.
In lieu of that a cubic curve is a good enough approximation until such
time as actual logarithmic volume control becomes a possibility/reality.
This makes volume control in ao_pipewire the same as in ao_pulse.

This author does know that @wtay is the author of PipeWire but believes
that he misunderstood the intent in a drive-by included in a collection
of fixes.

Fixes: #11065
Probably fixes: #12223
  • Loading branch information
WhitePeter committed Feb 12, 2025
1 parent f7a681b commit d7e8a55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions audio/out/ao_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ static uint64_t pw_stream_get_nsec(struct pw_stream *stream)
}
#endif

// cubic volume scale for a more natural feel of volume change
#define VOL_MP2PW_LIN(v) pow(v/100., 3)
// transform PW linear values to cubic scale, pow(x, 1/n) is the nth root of x
#define VOL_PW2MP_CUB(v) lrint(100 * pow(v, 1/3.))

enum init_state {
INIT_STATE_NONE,
INIT_STATE_SUCCESS,
Expand Down Expand Up @@ -273,12 +278,12 @@ static void on_state_changed(void *userdata, enum pw_stream_state old, enum pw_s

static float spa_volume_to_mp_volume(float vol)
{
return vol * 100;
return VOL_PW2MP_CUB(vol);
}

static float mp_volume_to_spa_volume(float vol)
{
return vol / 100;
return VOL_MP2PW_LIN(vol);
}

static float volume_avg(float* vols, uint32_t n)
Expand Down

0 comments on commit d7e8a55

Please sign in to comment.