From 08438903e50b41968e723c9a6c3da2d47af1257a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 28 Sep 2020 12:40:16 +0200 Subject: [PATCH] acp: reset soft volume When we have accurate enough hardware volume, set the software volume to 1.0. Also fixes the issue of going to 0 volume and then staying silent until we raise the volume above 1.0. --- spa/plugins/alsa/acp/acp.c | 20 ++++++++++++++------ spa/plugins/alsa/acp/alsa-mixer.h | 1 + spa/plugins/alsa/alsa-acp-device.c | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c index 5bcd8f80e..86c49c751 100644 --- a/spa/plugins/alsa/acp/acp.c +++ b/spa/plugins/alsa/acp/acp.c @@ -785,12 +785,19 @@ static void set_volume(pa_alsa_device *dev, const pa_cvolume *v) pa_cvolume_max(&new_soft_volume), pa_yes_no(accurate_enough)); - if (!accurate_enough && impl->events && impl->events->set_soft_volume) { - uint32_t i, n_volumes = new_soft_volume.channels; - float volumes[n_volumes]; - for (i = 0; i < n_volumes; i++) - volumes[i] = ((float)new_soft_volume.values[i]) / PA_VOLUME_NORM; - impl->events->set_soft_volume(impl->user_data, &dev->device, volumes, n_volumes); + if (accurate_enough) + pa_cvolume_reset(&new_soft_volume, new_soft_volume.channels); + + if (!pa_cvolume_equal(&dev->soft_volume, &new_soft_volume)) { + dev->soft_volume = new_soft_volume; + + if (impl->events && impl->events->set_soft_volume) { + uint32_t i, n_volumes = new_soft_volume.channels; + float volumes[n_volumes]; + for (i = 0; i < n_volumes; i++) + volumes[i] = ((float)new_soft_volume.values[i]) / PA_VOLUME_NORM; + impl->events->set_soft_volume(impl->user_data, &dev->device, volumes, n_volumes); + } } } else { @@ -1417,6 +1424,7 @@ int acp_device_set_volume(struct acp_device *dev, const float *volume, uint32_t d->set_volume(d, &v); } else { d->real_volume = v; + d->soft_volume = v; if (impl->events && impl->events->set_soft_volume) impl->events->set_soft_volume(impl->user_data, dev, volume, n_volume); } diff --git a/spa/plugins/alsa/acp/alsa-mixer.h b/spa/plugins/alsa/acp/alsa-mixer.h index 260db2c07..8dece154e 100644 --- a/spa/plugins/alsa/acp/alsa-mixer.h +++ b/spa/plugins/alsa/acp/alsa-mixer.h @@ -297,6 +297,7 @@ struct pa_alsa_device { unsigned decibel_volume:1; pa_cvolume real_volume; pa_cvolume hardware_volume; + pa_cvolume soft_volume; pa_volume_t base_volume; unsigned n_volume_steps; diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index 3c3bc1143..9bb5be287 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -746,7 +746,7 @@ static void on_set_soft_volume(void *data, struct acp_device *dev, struct spa_pod_builder b = { 0 }; struct spa_pod_frame f[1]; - spa_log_debug(this->log, "device %s soft volume %f", dev->name, volume[0]); + spa_log_info(this->log, "device %s soft volume %f", dev->name, volume[0]); spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_push_object(&b, &f[0], @@ -772,7 +772,7 @@ static void on_set_soft_mute(void *data, struct acp_device *dev, struct spa_pod_builder b = { 0 }; struct spa_pod_frame f[1]; - spa_log_debug(this->log, "device %s soft mute %d", dev->name, mute); + spa_log_info(this->log, "device %s soft mute %d", dev->name, mute); spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_push_object(&b, &f[0],