mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
alsa-mixer: Implement constant volume.
This change makes it possible to configure an arbitrary constant volume for a volume element in the path configuration, which is applied when the path is selected. Note: this is only useful when the exact hardware and driver are known beforehand.
This commit is contained in:
parent
55936640a1
commit
e1c289cc6b
3 changed files with 59 additions and 12 deletions
|
|
@ -1145,6 +1145,31 @@ static int element_zero_volume(pa_alsa_element *e, snd_mixer_t *m) {
|
|||
return r;
|
||||
}
|
||||
|
||||
static int element_apply_constant_volume(pa_alsa_element *e, snd_mixer_t *m) {
|
||||
snd_mixer_elem_t *me;
|
||||
snd_mixer_selem_id_t *sid;
|
||||
int r;
|
||||
|
||||
pa_assert(m);
|
||||
pa_assert(e);
|
||||
|
||||
SELEM_INIT(sid, e->alsa_name);
|
||||
if (!(me = snd_mixer_find_selem(m, sid))) {
|
||||
pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
|
||||
r = snd_mixer_selem_set_playback_volume_all(me, e->constant_volume);
|
||||
else
|
||||
r = snd_mixer_selem_set_capture_volume_all(me, e->constant_volume);
|
||||
|
||||
if (r < 0)
|
||||
pa_log_warn("Failed to set volume to %li of %s: %s", e->constant_volume, e->alsa_name, pa_alsa_strerror(errno));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
|
||||
pa_alsa_element *e;
|
||||
int r = 0;
|
||||
|
|
@ -1185,6 +1210,10 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
|
|||
r = element_zero_volume(e, m);
|
||||
break;
|
||||
|
||||
case PA_ALSA_VOLUME_CONSTANT:
|
||||
r = element_apply_constant_volume(e, m);
|
||||
break;
|
||||
|
||||
case PA_ALSA_VOLUME_MERGE:
|
||||
case PA_ALSA_VOLUME_IGNORE:
|
||||
r = 0;
|
||||
|
|
@ -1368,6 +1397,12 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
|
|||
pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", e->min_volume, e->max_volume);
|
||||
e->volume_use = PA_ALSA_VOLUME_IGNORE;
|
||||
|
||||
} else if (e->volume_use == PA_ALSA_VOLUME_CONSTANT &&
|
||||
(e->min_volume > e->constant_volume || e->max_volume < e->constant_volume)) {
|
||||
pa_log_warn("Constant volume %li configured for element %s, but the available range is from %li to %li.",
|
||||
e->constant_volume, e->alsa_name, e->min_volume, e->max_volume);
|
||||
e->volume_use = PA_ALSA_VOLUME_IGNORE;
|
||||
|
||||
} else {
|
||||
pa_bool_t is_mono;
|
||||
pa_channel_position_t p;
|
||||
|
|
@ -1685,9 +1720,16 @@ static int element_parse_volume(
|
|||
else if (pa_streq(rvalue, "zero"))
|
||||
e->volume_use = PA_ALSA_VOLUME_ZERO;
|
||||
else {
|
||||
uint32_t constant;
|
||||
|
||||
if (pa_atou(rvalue, &constant) >= 0) {
|
||||
e->volume_use = PA_ALSA_VOLUME_CONSTANT;
|
||||
e->constant_volume = constant;
|
||||
} else {
|
||||
pa_log("[%s:%u] Volume invalid of '%s'", filename, line, section);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ typedef enum pa_alsa_volume_use {
|
|||
PA_ALSA_VOLUME_IGNORE,
|
||||
PA_ALSA_VOLUME_MERGE, /* merge this volume slider into the global volume slider */
|
||||
PA_ALSA_VOLUME_OFF, /* set this volume to minimal unconditionally */
|
||||
PA_ALSA_VOLUME_ZERO /* set this volume to 0dB unconditionally */
|
||||
PA_ALSA_VOLUME_ZERO, /* set this volume to 0dB unconditionally */
|
||||
PA_ALSA_VOLUME_CONSTANT /* set this volume to a constant value unconditionally */
|
||||
} pa_alsa_volume_use_t;
|
||||
|
||||
typedef enum pa_alsa_enumeration_use {
|
||||
|
|
@ -137,6 +138,8 @@ struct pa_alsa_element {
|
|||
pa_alsa_required_t required_any;
|
||||
pa_alsa_required_t required_absent;
|
||||
|
||||
long constant_volume;
|
||||
|
||||
pa_bool_t override_map:1;
|
||||
pa_bool_t direction_try_other:1;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,9 +79,11 @@
|
|||
; # always set it to off, always to on, or make it selectable as port.
|
||||
; # If set to 'select' you need to define an Option section for on
|
||||
; # and off
|
||||
; volume = ignore | merge | off | zero # What to do with this volume: ignore it, merge it into the device
|
||||
; volume = ignore | merge | off | zero | <volume step> # What to do with this volume: ignore it, merge it into the device
|
||||
; # volume slider, always set it to the lowest value possible, or always
|
||||
; # set it to 0 dB (for whatever that means)
|
||||
; # set it to 0 dB (for whatever that means), or always set it to
|
||||
; # <volume step> (this only makes sense in path configurations where
|
||||
; # the exact hardware and driver are known beforehand).
|
||||
; volume-limit = <volume step> # Limit the maximum volume by disabling the volume steps above <volume step>.
|
||||
; enumeration = ignore | select # What to do with this enumeration, ignore it or make it selectable
|
||||
; # via device ports. If set to 'select' you need to define an Option section
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue