mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-01 22:58:47 -04:00
move flat volume logic into the core. while doing so add n_volume_steps field to sinks/sources
This commit is contained in:
parent
4bfa5d7d13
commit
d5f46e824e
32 changed files with 562 additions and 361 deletions
|
|
@ -703,7 +703,7 @@ static long to_alsa_volume(struct userdata *u, pa_volume_t vol) {
|
|||
return PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max);
|
||||
}
|
||||
|
||||
static int source_get_volume_cb(pa_source *s) {
|
||||
static void source_get_volume_cb(pa_source *s) {
|
||||
struct userdata *u = s->userdata;
|
||||
int err;
|
||||
unsigned i;
|
||||
|
|
@ -766,27 +766,24 @@ static int source_get_volume_cb(pa_source *s) {
|
|||
|
||||
if (!pa_cvolume_equal(&u->hardware_volume, &r)) {
|
||||
|
||||
u->hardware_volume = s->volume = r;
|
||||
s->virtual_volume = u->hardware_volume = r;
|
||||
|
||||
if (u->hw_dB_supported) {
|
||||
pa_cvolume reset;
|
||||
|
||||
/* Hmm, so the hardware volume changed, let's reset our software volume */
|
||||
|
||||
pa_cvolume_reset(&reset, s->sample_spec.channels);
|
||||
pa_source_set_soft_volume(s, &reset);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return;
|
||||
|
||||
fail:
|
||||
pa_log_error("Unable to read volume: %s", snd_strerror(err));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int source_set_volume_cb(pa_source *s) {
|
||||
static void source_set_volume_cb(pa_source *s) {
|
||||
struct userdata *u = s->userdata;
|
||||
int err;
|
||||
unsigned i;
|
||||
|
|
@ -803,7 +800,7 @@ static int source_set_volume_cb(pa_source *s) {
|
|||
long alsa_vol;
|
||||
pa_volume_t vol;
|
||||
|
||||
vol = s->volume.values[i];
|
||||
vol = s->virtual_volume.values[i];
|
||||
|
||||
if (u->hw_dB_supported) {
|
||||
|
||||
|
|
@ -840,7 +837,7 @@ static int source_set_volume_cb(pa_source *s) {
|
|||
pa_volume_t vol;
|
||||
long alsa_vol;
|
||||
|
||||
vol = pa_cvolume_max(&s->volume);
|
||||
vol = pa_cvolume_max(&s->virtual_volume);
|
||||
|
||||
if (u->hw_dB_supported) {
|
||||
alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100);
|
||||
|
|
@ -857,7 +854,7 @@ static int source_set_volume_cb(pa_source *s) {
|
|||
VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol));
|
||||
#endif
|
||||
|
||||
pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
|
||||
pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) (alsa_vol - u->hw_dB_max) / 100.0));
|
||||
|
||||
} else {
|
||||
alsa_vol = to_alsa_volume(u, vol);
|
||||
|
|
@ -879,10 +876,9 @@ static int source_set_volume_cb(pa_source *s) {
|
|||
|
||||
/* Match exactly what the user requested by software */
|
||||
|
||||
pa_sw_cvolume_divide(&r, &s->volume, &r);
|
||||
pa_source_set_soft_volume(s, &r);
|
||||
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &r);
|
||||
|
||||
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume));
|
||||
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
|
||||
pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
|
||||
pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
|
||||
|
||||
|
|
@ -891,17 +887,15 @@ static int source_set_volume_cb(pa_source *s) {
|
|||
/* We can't match exactly what the user requested, hence let's
|
||||
* at least tell the user about it */
|
||||
|
||||
s->volume = r;
|
||||
s->virtual_volume = r;
|
||||
|
||||
return 0;
|
||||
return;
|
||||
|
||||
fail:
|
||||
pa_log_error("Unable to set volume: %s", snd_strerror(err));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int source_get_mute_cb(pa_source *s) {
|
||||
static void source_get_mute_cb(pa_source *s) {
|
||||
struct userdata *u = s->userdata;
|
||||
int err, sw;
|
||||
|
||||
|
|
@ -910,15 +904,13 @@ static int source_get_mute_cb(pa_source *s) {
|
|||
|
||||
if ((err = snd_mixer_selem_get_capture_switch(u->mixer_elem, 0, &sw)) < 0) {
|
||||
pa_log_error("Unable to get switch: %s", snd_strerror(err));
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
s->muted = !sw;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int source_set_mute_cb(pa_source *s) {
|
||||
static void source_set_mute_cb(pa_source *s) {
|
||||
struct userdata *u = s->userdata;
|
||||
int err;
|
||||
|
||||
|
|
@ -927,10 +919,8 @@ static int source_set_mute_cb(pa_source *s) {
|
|||
|
||||
if ((err = snd_mixer_selem_set_capture_switch_all(u->mixer_elem, !s->muted)) < 0) {
|
||||
pa_log_error("Unable to set switch: %s", snd_strerror(err));
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void source_update_requested_latency_cb(pa_source *s) {
|
||||
|
|
@ -1372,6 +1362,9 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
|
|||
u->source->set_volume = source_set_volume_cb;
|
||||
u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0);
|
||||
pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported");
|
||||
|
||||
if (!u->hw_dB_supported)
|
||||
u->source->n_volume_steps = u->hw_volume_max - u->hw_volume_min + 1;
|
||||
} else
|
||||
pa_log_info("Using software volume control.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue