mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
source: rework volume handling
- drop the 'virtual_' prefix from s->virtual_volume since we don't distuingish between reference and real volumes for sources - introduce an accuracy for source volumes: if the hardware can control the volume "close enough" don't necessarily adjust the rest in software unless it is beyond a certain threshold. This should save a little bit of CPU at the expensive of a bit of accuracy in volume handling. - other minor cleanups
This commit is contained in:
parent
2838b78e59
commit
24e582808c
5 changed files with 57 additions and 39 deletions
|
|
@ -65,6 +65,8 @@
|
|||
#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC) /* 10ms */
|
||||
#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC) /* 4ms */
|
||||
|
||||
#define VOLUME_ACCURACY (PA_VOLUME_NORM/100)
|
||||
|
||||
struct userdata {
|
||||
pa_core *core;
|
||||
pa_module *module;
|
||||
|
|
@ -987,15 +989,11 @@ static void source_get_volume_cb(pa_source *s) {
|
|||
if (pa_cvolume_equal(&u->hardware_volume, &r))
|
||||
return;
|
||||
|
||||
s->virtual_volume = u->hardware_volume = r;
|
||||
s->volume = u->hardware_volume = r;
|
||||
|
||||
if (u->mixer_path->has_dB) {
|
||||
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);
|
||||
}
|
||||
/* Hmm, so the hardware volume changed, let's reset our software volume */
|
||||
if (u->mixer_path->has_dB)
|
||||
pa_source_set_soft_volume(s, NULL);
|
||||
}
|
||||
|
||||
static void source_set_volume_cb(pa_source *s) {
|
||||
|
|
@ -1008,7 +1006,7 @@ static void source_set_volume_cb(pa_source *s) {
|
|||
pa_assert(u->mixer_handle);
|
||||
|
||||
/* Shift up by the base volume */
|
||||
pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
|
||||
pa_sw_cvolume_divide_scalar(&r, &s->volume, s->base_volume);
|
||||
|
||||
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
|
||||
return;
|
||||
|
|
@ -1019,13 +1017,26 @@ static void source_set_volume_cb(pa_source *s) {
|
|||
u->hardware_volume = r;
|
||||
|
||||
if (u->mixer_path->has_dB) {
|
||||
pa_cvolume new_soft_volume;
|
||||
pa_bool_t accurate_enough;
|
||||
|
||||
/* Match exactly what the user requested by software */
|
||||
pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
|
||||
pa_sw_cvolume_divide(&new_soft_volume, &s->volume, &u->hardware_volume);
|
||||
|
||||
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
|
||||
/* If the adjustment to do in software is only minimal we
|
||||
* can skip it. That saves us CPU at the expense of a bit of
|
||||
* accuracy */
|
||||
accurate_enough =
|
||||
(pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
|
||||
(pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
|
||||
|
||||
pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->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), &s->soft_volume));
|
||||
pa_log_debug("Calculated software volume: %s (accurate-enough=%s)", pa_cvolume_snprint(t, sizeof(t), &new_soft_volume),
|
||||
pa_yes_no(accurate_enough));
|
||||
|
||||
if (!accurate_enough)
|
||||
s->soft_volume = new_soft_volume;
|
||||
|
||||
} else {
|
||||
pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
|
||||
|
|
@ -1033,7 +1044,7 @@ static void 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->virtual_volume = r;
|
||||
s->volume = r;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1500,12 +1500,12 @@ static void source_set_volume_cb(pa_source *s) {
|
|||
if (u->profile != PROFILE_HSP)
|
||||
return;
|
||||
|
||||
gain = (pa_cvolume_max(&s->virtual_volume) * 15) / PA_VOLUME_NORM;
|
||||
gain = (pa_cvolume_max(&s->volume) * 15) / PA_VOLUME_NORM;
|
||||
|
||||
if (gain > 15)
|
||||
gain = 15;
|
||||
|
||||
pa_cvolume_set(&s->virtual_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
|
||||
pa_cvolume_set(&s->volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
|
||||
|
||||
pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetMicrophoneGain"));
|
||||
pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_UINT16, &gain, DBUS_TYPE_INVALID));
|
||||
|
|
|
|||
|
|
@ -848,11 +848,11 @@ static void source_get_volume(pa_source *s) {
|
|||
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
|
||||
|
||||
if (u->mixer_devmask & SOUND_MASK_IGAIN)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_IGAIN, &s->sample_spec, &s->virtual_volume) >= 0)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_IGAIN, &s->sample_spec, &s->volume) >= 0)
|
||||
return;
|
||||
|
||||
if (u->mixer_devmask & SOUND_MASK_RECLEV)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_RECLEV, &s->sample_spec, &s->virtual_volume) >= 0)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_READ_RECLEV, &s->sample_spec, &s->volume) >= 0)
|
||||
return;
|
||||
|
||||
pa_log_info("Device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
|
||||
|
|
@ -866,11 +866,11 @@ static void source_set_volume(pa_source *s) {
|
|||
pa_assert(u->mixer_devmask & (SOUND_MASK_IGAIN|SOUND_MASK_RECLEV));
|
||||
|
||||
if (u->mixer_devmask & SOUND_MASK_IGAIN)
|
||||
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_IGAIN, &s->sample_spec, &s->virtual_volume) >= 0)
|
||||
if (pa_oss_set_volume(u->mixer_fd, SOUND_MIXER_WRITE_IGAIN, &s->sample_spec, &s->volume) >= 0)
|
||||
return;
|
||||
|
||||
if (u->mixer_devmask & SOUND_MASK_RECLEV)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_RECLEV, &s->sample_spec, &s->virtual_volume) >= 0)
|
||||
if (pa_oss_get_volume(u->mixer_fd, SOUND_MIXER_WRITE_RECLEV, &s->sample_spec, &s->volume) >= 0)
|
||||
return;
|
||||
|
||||
pa_log_info("Device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue