spa: improve volume handling

Make a new softVolume property that contains only the soft volume
to apply.

In the case of HW/SW volume, we pass the real volume in the
channelVolume and the leftover volume in softVolume. We don't
use the monitorVolume for this anymore because it is a completely
separate volume handled by the merger node.

This way, channelVolume always represents the effective volume
set on routes, channelmix and merger and only the softVolume (when
available) is applied as software volume by channelmix.

This makes things map a bit better to what is actually happening with
the real volume and leftover software volumes after applying the
hardware volumes in the device.

With this change, the volume on the monitor is not affected by the
sink volume anymore and we can use the monitorVolume for this later.

This also means that the monitor volume in pavucontrol of the sinks
does not change when the sink volume changes. PulseAudio is inconsistent
here: If the volume is HW, the monitor volume is not affected, if the
volume is SW, it is. In PipeWire there is an option in merger to
let the volume affect the monitor with monitor.channel-volumes = true.
This commit is contained in:
Wim Taymans 2021-04-29 12:27:55 +02:00
parent 48a6cc2575
commit 5bf2144438
7 changed files with 129 additions and 56 deletions

View file

@ -405,11 +405,14 @@ static struct spa_pod *build_route(struct spa_pod_builder *b, uint32_t id,
if (dev != NULL) {
uint32_t channels = dev->format.channels;
float volumes[channels];
float soft_volumes[channels];
bool mute;
acp_device_get_mute(dev, &mute);
spa_zero(volumes);
spa_zero(soft_volumes);
acp_device_get_volume(dev, volumes, channels);
acp_device_get_soft_volume(dev, soft_volumes, channels);
spa_pod_builder_prop(b, SPA_PARAM_ROUTE_device, 0);
spa_pod_builder_int(b, dev->index);
@ -437,6 +440,10 @@ static struct spa_pod *build_route(struct spa_pod_builder *b, uint32_t id,
spa_pod_builder_array(b, sizeof(uint32_t), SPA_TYPE_Id,
channels, dev->format.map);
spa_pod_builder_prop(b, SPA_PROP_softVolumes, 0);
spa_pod_builder_array(b, sizeof(float), SPA_TYPE_Float,
channels, soft_volumes);
spa_pod_builder_pop(b, &f[1]);
}
spa_pod_builder_prop(b, SPA_PARAM_ROUTE_devices, 0);
@ -791,16 +798,16 @@ static void on_volume_changed(void *data, struct acp_device *dev)
struct spa_pod_frame f[1];
uint32_t n_volume = dev->format.channels;
float volume[n_volume];
float mon_volume[n_volume];
float soft_volume[n_volume];
spa_log_info(this->log, "device %s volume changed", dev->name);
this->info.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS;
this->params[IDX_Route].user++;
spa_zero(volume);
spa_zero(mon_volume);
acp_device_get_soft_volume(dev, volume, n_volume);
acp_device_get_volume(dev, mon_volume, n_volume);
spa_zero(soft_volume);
acp_device_get_volume(dev, volume, n_volume);
acp_device_get_soft_volume(dev, soft_volume, n_volume);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
spa_pod_builder_push_object(&b, &f[0],
@ -812,11 +819,11 @@ static void on_volume_changed(void *data, struct acp_device *dev)
SPA_TYPE_OBJECT_Props, SPA_EVENT_DEVICE_Props,
SPA_PROP_channelVolumes, SPA_POD_Array(sizeof(float),
SPA_TYPE_Float, n_volume, volume),
SPA_PROP_monitorVolumes, SPA_POD_Array(sizeof(float),
SPA_TYPE_Float, n_volume, mon_volume),
SPA_PROP_channelMap, SPA_POD_Array(sizeof(uint32_t),
SPA_TYPE_Id, dev->format.channels,
dev->format.map));
dev->format.map),
SPA_PROP_softVolumes, SPA_POD_Array(sizeof(float),
SPA_TYPE_Float, n_volume, soft_volume));
event = spa_pod_builder_pop(&b, &f[0]);
spa_device_emit_event(&this->hooks, event);