[polypaudio-commits] r796 - in /trunk/src/modules: module-alsa-sink.c module-alsa-source.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Apr 25 00:54:50 PDT 2006


Author: ossman
Date: Tue Apr 25 09:54:49 2006
New Revision: 796

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=796&root=polypaudio&view=rev
Log:
Fall back to software volume if hardware mixer cannot control all channels.

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=796&root=polypaudio&r1=795&r2=796&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-sink.c (original)
+++ trunk/src/modules/module-alsa-sink.c Tue Apr 25 09:54:49 2006
@@ -201,25 +201,18 @@
     struct userdata *u = s->userdata;
     long vol;
     int err;
+    int i;
 
     assert(u && u->mixer_elem);
 
-    if (snd_mixer_selem_has_playback_volume_joined(u->mixer_elem)) {
-        err = snd_mixer_selem_get_playback_volume(u->mixer_elem, 0, &vol);
+    for (i = 0;i < s->hw_volume.channels;i++) {
+        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)
             goto fail;
-        pa_cvolume_set(&s->hw_volume, s->hw_volume.channels,
-            (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min));
-    } else {
-        int i;
-
-        for (i = 0;i < s->hw_volume.channels;i++) {
-            err = snd_mixer_selem_get_playback_volume(u->mixer_elem, i, &vol);
-            if (err < 0)
-                goto fail;
-            s->hw_volume.values[i] =
-                (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
-        }
+        s->hw_volume.values[i] =
+            (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
     }
 
     return 0;
@@ -234,37 +227,25 @@
 static int sink_set_hw_volume_cb(pa_sink *s) {
     struct userdata *u = s->userdata;
     int err;
+    int i;
     pa_volume_t vol;
 
     assert(u && u->mixer_elem);
 
-    if (snd_mixer_selem_has_playback_volume_joined(u->mixer_elem)) {
-        vol = pa_cvolume_avg(&s->hw_volume);
+    for (i = 0;i < s->hw_volume.channels;i++) {
+        assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, i));
+
+        vol = s->hw_volume.values[i];
 
         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_all(u->mixer_elem, vol);
+
+        err = snd_mixer_selem_set_playback_volume(u->mixer_elem, i, vol);
         if (err < 0)
             goto fail;
-    } else {
-        int i;
-
-        for (i = 0;i < s->hw_volume.channels;i++) {
-            vol = s->hw_volume.values[i];
-
-            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)
-                goto fail;
-        }
     }
 
     return 0;
@@ -383,10 +364,19 @@
     if (u->mixer_handle) {
         assert(u->mixer_elem);
         if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) {
-            u->sink->get_hw_volume = sink_get_hw_volume_cb;
-            u->sink->set_hw_volume = sink_set_hw_volume_cb;
-            snd_mixer_selem_get_playback_volume_range(
-                u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max);
+            int i;
+
+            for (i = 0;i < ss.channels;i++) {
+                if (!snd_mixer_selem_has_playback_channel(u->mixer_elem, i))
+                    break;
+            }
+
+            if (i == ss.channels) {
+                u->sink->get_hw_volume = sink_get_hw_volume_cb;
+                u->sink->set_hw_volume = sink_set_hw_volume_cb;
+                snd_mixer_selem_get_playback_volume_range(
+                    u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max);
+            }
         }
         if (snd_mixer_selem_has_playback_switch(u->mixer_elem)) {
             u->sink->get_hw_mute = sink_get_hw_mute_cb;

Modified: trunk/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-alsa-source.c?rev=796&root=polypaudio&r1=795&r2=796&view=diff
==============================================================================
--- trunk/src/modules/module-alsa-source.c (original)
+++ trunk/src/modules/module-alsa-source.c Tue Apr 25 09:54:49 2006
@@ -190,25 +190,18 @@
     struct userdata *u = s->userdata;
     long vol;
     int err;
+    int i;
 
     assert(u && u->mixer_elem);
 
-    if (snd_mixer_selem_has_capture_volume_joined(u->mixer_elem)) {
-        err = snd_mixer_selem_get_capture_volume(u->mixer_elem, 0, &vol);
+    for (i = 0;i < s->hw_volume.channels;i++) {
+        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)
             goto fail;
-        pa_cvolume_set(&s->hw_volume, s->hw_volume.channels,
-            (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min));
-    } else {
-        int i;
-
-        for (i = 0;i < s->hw_volume.channels;i++) {
-            err = snd_mixer_selem_get_capture_volume(u->mixer_elem, i, &vol);
-            if (err < 0)
-                goto fail;
-            s->hw_volume.values[i] =
-                (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
-        }
+        s->hw_volume.values[i] =
+            (vol - u->hw_volume_min) * PA_VOLUME_NORM / (u->hw_volume_max - u->hw_volume_min);
     }
 
     return 0;
@@ -224,35 +217,23 @@
     struct userdata *u = s->userdata;
     int err;
     pa_volume_t vol;
+    int i;
 
     assert(u && u->mixer_elem);
 
-    if (snd_mixer_selem_has_capture_volume_joined(u->mixer_elem)) {
-        vol = pa_cvolume_avg(&s->hw_volume);
+    for (i = 0;i < s->hw_volume.channels;i++) {
+        assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, i));
+
+        vol = s->hw_volume.values[i];
 
         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_all(u->mixer_elem, vol);
+        err = snd_mixer_selem_set_capture_volume(u->mixer_elem, i, vol);
         if (err < 0)
             goto fail;
-    } else {
-        int i;
-
-        for (i = 0;i < s->hw_volume.channels;i++) {
-            vol = s->hw_volume.values[i];
-
-            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)
-                goto fail;
-        }
     }
 
     return 0;
@@ -372,10 +353,19 @@
     if (u->mixer_handle) {
         assert(u->mixer_elem);
         if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) {
-            u->source->get_hw_volume = source_get_hw_volume_cb;
-            u->source->set_hw_volume = source_set_hw_volume_cb;
-            snd_mixer_selem_get_capture_volume_range(
-                u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max);
+            int i;
+
+            for (i = 0;i < ss.channels;i++) {
+                if (!snd_mixer_selem_has_capture_channel(u->mixer_elem, i))
+                    break;
+            }
+
+            if (i == ss.channels) {
+                u->source->get_hw_volume = source_get_hw_volume_cb;
+                u->source->set_hw_volume = source_set_hw_volume_cb;
+                snd_mixer_selem_get_capture_volume_range(
+                    u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max);
+            }
         }
         if (snd_mixer_selem_has_capture_switch(u->mixer_elem)) {
             u->source->get_hw_mute = source_get_hw_mute_cb;




More information about the pulseaudio-commits mailing list