From c5cc364794df56ff8e843181935caf64712e36f7 Mon Sep 17 00:00:00 2001 From: Christian Glombek Date: Tue, 3 Oct 2023 07:15:17 +0200 Subject: [PATCH] module-raop-sink: Fix volume calculation The volume interval that RAOP devices understand is [-30,0], where -30.0 equals min vol, and 0.0 equals max. vol. The local system volume is represented as a cubic (volumetric) value in the [0,1] interval. So cube root system volume value, scale by 30 and translate -30 to map to target output range. The special value -144 denotes volume mute. Send a corresponding RTSP message when mute is not already toggled on. --- src/modules/module-raop-sink.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/module-raop-sink.c b/src/modules/module-raop-sink.c index 63e048c9c..0046bb4c7 100644 --- a/src/modules/module-raop-sink.c +++ b/src/modules/module-raop-sink.c @@ -148,9 +148,9 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME); #define DEFAULT_CHANNELS 2 #define DEFAULT_POSITION "[ FL FR ]" -#define VOLUME_MAX 0.0 -#define VOLUME_DEF -30.0 -#define VOLUME_MIN -144.0 +#define VOLUME_MAX 0.0 +#define VOLUME_MIN -30.0 +#define VOLUME_MUTE -144.0 #define MODULE_USAGE "( raop.ip= ) " \ "( raop.port= ) " \ @@ -1723,6 +1723,10 @@ static void stream_props_changed(struct impl *impl, uint32_t id, const struct sp { bool mute; if (spa_pod_get_bool(&prop->value, &mute) == 0) { + if (!impl->mute) { + impl->volume = VOLUME_MUTE; + rtsp_send_volume(impl); + } impl->mute = mute; } spa_pod_builder_prop(&b, SPA_PROP_softMute, 0); @@ -1744,7 +1748,7 @@ static void stream_props_changed(struct impl *impl, uint32_t id, const struct sp soft_vols[i] = 1.0f; } volume /= n_vols; - volume = SPA_CLAMPF(20.0 * log10(volume), VOLUME_MIN, VOLUME_MAX); + volume = SPA_CLAMPF(cbrt(volume) * 30 - 30, VOLUME_MIN, VOLUME_MAX); impl->volume = volume; rtsp_send_volume(impl);