summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-08-13 13:54:17 +0200
committerLennart Poettering <lennart@poettering.net>2008-08-13 13:54:17 +0200
commit29daef7a265db1977db4eb2eb68dd85c943fceef (patch)
treee106b737a56813883e037c86e70fc49aa192a30f
parent8ab85fdf9e8d5465ae29434f6618b63c3511b767 (diff)
downloadpulseaudio-29daef7a265db1977db4eb2eb68dd85c943fceef.tar.gz
add new function pa_alsa_volume_divide()
-rw-r--r--src/modules/alsa-util.c24
-rw-r--r--src/modules/alsa-util.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c
index 2dcf6d9c3..be3cdf446 100644
--- a/src/modules/alsa-util.c
+++ b/src/modules/alsa-util.c
@@ -1117,3 +1117,27 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) {
return item;
}
+
+pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t) {
+ unsigned i;
+
+ pa_assert(r);
+ pa_assert(t);
+ pa_assert(r->channels == t->channels);
+
+ for (i = 0; i < r->channels; i++) {
+ double a, b, c;
+
+ a = pa_sw_volume_to_linear(r->values[i]); /* the hw volume */
+ b = pa_sw_volume_to_linear(t->values[i]); /* the intended volume */
+
+ if (a <= 0)
+ c = 0;
+ else
+ c = b / a;
+
+ r->values[i] = pa_sw_volume_from_linear(c);
+ }
+
+ return r;
+}
diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h
index 4de8bcd24..1b73200be 100644
--- a/src/modules/alsa-util.h
+++ b/src/modules/alsa-util.h
@@ -26,6 +26,7 @@
#include <asoundlib.h>
#include <pulse/sample.h>
+#include <pulse/volume.h>
#include <pulse/mainloop-api.h>
#include <pulse/channelmap.h>
#include <pulse/proplist.h>
@@ -94,4 +95,6 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents);
pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll);
+pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t);
+
#endif