audioconvert: add option to disable volume updates

Add channelmix.lock-volumes. When set to true it will disable volume
updates until set back to false.

See #3361
This commit is contained in:
Wim Taymans 2023-07-25 12:32:58 +02:00
parent cd3375f39e
commit ad1a36a718

View file

@ -89,6 +89,7 @@ struct props {
unsigned int resample_quality; unsigned int resample_quality;
double rate; double rate;
char wav_path[512]; char wav_path[512];
unsigned int lock_volumes:1;
}; };
static void props_reset(struct props *props) static void props_reset(struct props *props)
@ -109,6 +110,7 @@ static void props_reset(struct props *props)
props->resample_quality = RESAMPLE_DEFAULT_QUALITY; props->resample_quality = RESAMPLE_DEFAULT_QUALITY;
props->rate = 1.0; props->rate = 1.0;
spa_zero(props->wav_path); spa_zero(props->wav_path);
props->lock_volumes = false;
} }
struct buffer { struct buffer {
@ -695,6 +697,14 @@ static int impl_node_enum_params(void *object, int seq,
SPA_PROP_INFO_type, SPA_POD_String(p->wav_path), SPA_PROP_INFO_type, SPA_POD_String(p->wav_path),
SPA_PROP_INFO_params, SPA_POD_Bool(true)); SPA_PROP_INFO_params, SPA_POD_Bool(true));
break; break;
case 27:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_PropInfo, id,
SPA_PROP_INFO_name, SPA_POD_String("channelmix.lock-volumes"),
SPA_PROP_INFO_description, SPA_POD_String("Disable volume updates"),
SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(p->lock_volumes),
SPA_PROP_INFO_params, SPA_POD_Bool(true));
break;
default: default:
return 0; return 0;
} }
@ -773,6 +783,8 @@ static int impl_node_enum_params(void *object, int seq,
spa_pod_builder_string(&b, dither_method_info[this->dir[1].conv.method].label); spa_pod_builder_string(&b, dither_method_info[this->dir[1].conv.method].label);
spa_pod_builder_string(&b, "debug.wav-path"); spa_pod_builder_string(&b, "debug.wav-path");
spa_pod_builder_string(&b, p->wav_path); spa_pod_builder_string(&b, p->wav_path);
spa_pod_builder_string(&b, "channelmix.lock-volumes");
spa_pod_builder_bool(&b, p->lock_volumes);
spa_pod_builder_pop(&b, &f[1]); spa_pod_builder_pop(&b, &f[1]);
param = spa_pod_builder_pop(&b, &f[0]); param = spa_pod_builder_pop(&b, &f[0]);
break; break;
@ -854,6 +866,8 @@ static int audioconvert_set_param(struct impl *this, const char *k, const char *
spa_scnprintf(this->props.wav_path, spa_scnprintf(this->props.wav_path,
sizeof(this->props.wav_path), "%s", s ? s : ""); sizeof(this->props.wav_path), "%s", s ? s : "");
} }
else if (spa_streq(k, "channelmix.lock-volumes"))
this->props.lock_volumes = spa_atob(s);
else else
return 0; return 0;
return 1; return 1;
@ -1049,13 +1063,15 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
case SPA_PROP_volume: case SPA_PROP_volume:
p->prev_volume = p->volume; p->prev_volume = p->volume;
if (spa_pod_get_float(&prop->value, &p->volume) == 0) { if (!p->lock_volumes &&
spa_pod_get_float(&prop->value, &p->volume) == 0) {
spa_log_debug(this->log, "%p new volume %f", this, p->volume); spa_log_debug(this->log, "%p new volume %f", this, p->volume);
changed++; changed++;
} }
break; break;
case SPA_PROP_mute: case SPA_PROP_mute:
if (spa_pod_get_bool(&prop->value, &p->channel.mute) == 0) { if (!p->lock_volumes &&
spa_pod_get_bool(&prop->value, &p->channel.mute) == 0) {
have_channel_volume = true; have_channel_volume = true;
changed++; changed++;
} }
@ -1124,7 +1140,8 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
} }
break; break;
case SPA_PROP_channelVolumes: case SPA_PROP_channelVolumes:
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, if (!p->lock_volumes &&
(n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
have_channel_volume = true; have_channel_volume = true;
p->channel.n_volumes = n; p->channel.n_volumes = n;
@ -1139,13 +1156,15 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
} }
break; break;
case SPA_PROP_softMute: case SPA_PROP_softMute:
if (spa_pod_get_bool(&prop->value, &p->soft.mute) == 0) { if (!p->lock_volumes &&
spa_pod_get_bool(&prop->value, &p->soft.mute) == 0) {
have_soft_volume = true; have_soft_volume = true;
changed++; changed++;
} }
break; break;
case SPA_PROP_softVolumes: case SPA_PROP_softVolumes:
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, if (!p->lock_volumes &&
(n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) { p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
have_soft_volume = true; have_soft_volume = true;
p->soft.n_volumes = n; p->soft.n_volumes = n;
@ -1187,7 +1206,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
set_volume(this); set_volume(this);
} }
if (vol_ramp_params_changed) { if (!p->lock_volumes && vol_ramp_params_changed) {
void *sequence = NULL; void *sequence = NULL;
if (p->volume == p->prev_volume) if (p->volume == p->prev_volume)
spa_log_error(this->log, "no change in volume, cannot ramp volume"); spa_log_error(this->log, "no change in volume, cannot ramp volume");