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

@ -86,6 +86,9 @@ enum spa_prop {
SPA_PROP_monitorVolumes, /**< a volume array, one volume per
* channel (Array of Float) */
SPA_PROP_latencyOffsetNsec, /**< delay adjustment */
SPA_PROP_softMute, /**< mute (Bool) */
SPA_PROP_softVolumes, /**< a volume array, one volume per
* channel (Array of Float) */
SPA_PROP_START_Video = 0x20000, /**< video related properties */
SPA_PROP_brightness,

View file

@ -68,8 +68,8 @@ static const struct spa_type_info spa_type_param[] = {
#include <spa/param/video/type-info.h>
#include <spa/param/bluetooth/type-info.h>
static const struct spa_type_info spa_type_prop_channel_volume[] = {
{ SPA_PROP_START, SPA_TYPE_Float, SPA_TYPE_INFO_BASE "channelVolumes", NULL, },
static const struct spa_type_info spa_type_prop_float_array[] = {
{ SPA_PROP_START, SPA_TYPE_Float, SPA_TYPE_INFO_BASE "floatArray", NULL, },
{ 0, 0, NULL, NULL },
};
@ -78,11 +78,6 @@ static const struct spa_type_info spa_type_prop_channel_map[] = {
{ 0, 0, NULL, NULL },
};
static const struct spa_type_info spa_type_prop_monitor_volume[] = {
{ SPA_PROP_START, SPA_TYPE_Float, SPA_TYPE_INFO_BASE "monitorVolumes", NULL, },
{ 0, 0, NULL, NULL },
};
static const struct spa_type_info spa_type_props[] = {
{ SPA_PROP_START, SPA_TYPE_Id, SPA_TYPE_INFO_PROPS_BASE, spa_type_param, },
{ SPA_PROP_unknown, SPA_TYPE_None, SPA_TYPE_INFO_PROPS_BASE "unknown", NULL },
@ -108,13 +103,15 @@ static const struct spa_type_info spa_type_props[] = {
{ SPA_PROP_patternType, SPA_TYPE_Id, SPA_TYPE_INFO_PROPS_BASE "patternType", NULL },
{ SPA_PROP_ditherType, SPA_TYPE_Id, SPA_TYPE_INFO_PROPS_BASE "ditherType", NULL },
{ SPA_PROP_truncate, SPA_TYPE_Bool, SPA_TYPE_INFO_PROPS_BASE "truncate", NULL },
{ SPA_PROP_channelVolumes, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "channelVolumes", spa_type_prop_channel_volume },
{ SPA_PROP_channelVolumes, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "channelVolumes", spa_type_prop_float_array },
{ SPA_PROP_volumeBase, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "volumeBase", NULL },
{ SPA_PROP_volumeStep, SPA_TYPE_Float, SPA_TYPE_INFO_PROPS_BASE "volumeStep", NULL },
{ SPA_PROP_channelMap, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "channelMap", spa_type_prop_channel_map },
{ SPA_PROP_monitorMute, SPA_TYPE_Bool, SPA_TYPE_INFO_PROPS_BASE "monitorMute", NULL },
{ SPA_PROP_monitorVolumes, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "monitorVolumes", spa_type_prop_monitor_volume },
{ SPA_PROP_monitorVolumes, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "monitorVolumes", spa_type_prop_float_array },
{ SPA_PROP_latencyOffsetNsec, SPA_TYPE_Long, SPA_TYPE_INFO_PROPS_BASE "latencyOffsetNsec", NULL },
{ SPA_PROP_softMute, SPA_TYPE_Bool, SPA_TYPE_INFO_PROPS_BASE "softMute", NULL },
{ SPA_PROP_softVolumes, SPA_TYPE_Array, SPA_TYPE_INFO_PROPS_BASE "softVolumes", spa_type_prop_float_array },
{ SPA_PROP_brightness, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "brightness", NULL },
{ SPA_PROP_contrast, SPA_TYPE_Int, SPA_TYPE_INFO_PROPS_BASE "contrast", NULL },