[pulseaudio-commits] r1189 - in /trunk/src/modules: module-alsa-sink.c module-alsa-source.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Aug 7 09:50:17 PDT 2006
Author: lennart
Date: Mon Aug 7 18:50:15 2006
New Revision: 1189
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1189&root=pulseaudio&view=rev
Log:
try to reduce volume updates in the ALSA sinks/sources: only touch the shadowed hw volme if necessary
Modified:
trunk/src/modules/module-alsa-sink.c
trunk/src/modules/module-alsa-source.c
Modified: trunk/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-sink.c?rev=1189&root=pulseaudio&r1=1188&r2=1189&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-sink.c (original)
+++ trunk/src/modules/module-alsa-sink.c Mon Aug 7 18:50:15 2006
@@ -212,20 +212,25 @@
static int sink_get_hw_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
- long vol;
int err;
int i;
- assert(u && u->mixer_elem);
-
- for (i = 0;i < s->hw_volume.channels;i++) {
+ assert(u);
+ assert(u->mixer_elem);
+
+ for (i = 0; i < s->hw_volume.channels; i++) {
+ long set_vol, vol;
+
assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, i));
- err = snd_mixer_selem_get_playback_volume(u->mixer_elem, i, &vol);
- if (err < 0)
+ if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, i, &vol)) < 0)
goto fail;
- s->hw_volume.values[i] =
- (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
+
+ set_vol = (long) roundf(((float) s->hw_volume.values[i] * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+
+ /* Try to avoid superfluous volume changes */
+ if (set_vol != vol)
+ s->hw_volume.values[i] = (pa_volume_t) roundf(((float) (vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
}
return 0;
@@ -243,9 +248,12 @@
int i;
pa_volume_t vol;
- assert(u && u->mixer_elem);
-
- for (i = 0;i < s->hw_volume.channels;i++) {
+ assert(u);
+ assert(u->mixer_elem);
+
+ for (i = 0; i < s->hw_volume.channels; i++) {
+ long alsa_vol;
+
assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, i));
vol = s->hw_volume.values[i];
@@ -253,11 +261,9 @@
if (vol > PA_VOLUME_NORM)
vol = PA_VOLUME_NORM;
- vol = (vol * (u->hw_volume_max - u->hw_volume_min)) /
- PA_VOLUME_NORM + u->hw_volume_min;
-
- err = snd_mixer_selem_set_playback_volume(u->mixer_elem, i, vol);
- if (err < 0)
+ alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+
+ if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, i, alsa_vol)) < 0)
goto fail;
}
Modified: trunk/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-source.c?rev=1189&root=pulseaudio&r1=1188&r2=1189&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-source.c (original)
+++ trunk/src/modules/module-alsa-source.c Mon Aug 7 18:50:15 2006
@@ -213,13 +213,18 @@
assert(u && u->mixer_elem);
for (i = 0;i < s->hw_volume.channels;i++) {
+ long set_vol;
+
assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, i));
-
- err = snd_mixer_selem_get_capture_volume(u->mixer_elem, i, &vol);
- if (err < 0)
+
+ if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, i, &vol)) < 0)
goto fail;
- s->hw_volume.values[i] =
- (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
+
+ set_vol = (long) roundf(((float) s->hw_volume.values[i] * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+
+ /* Try to avoid superfluous volume changes */
+ if (set_vol != vol)
+ s->hw_volume.values[i] = (pa_volume_t) roundf(((float) (vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min));
}
return 0;
@@ -247,10 +252,9 @@
if (vol > PA_VOLUME_NORM)
vol = PA_VOLUME_NORM;
- vol = vol * (u->hw_volume_max - u->hw_volume_min) /
- PA_VOLUME_NORM + u->hw_volume_min;
- err = snd_mixer_selem_set_capture_volume(u->mixer_elem, i, vol);
- if (err < 0)
+ vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min;
+
+ if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, i, vol)) < 0)
goto fail;
}
More information about the pulseaudio-commits
mailing list