From 29daef7a265db1977db4eb2eb68dd85c943fceef Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:54:17 +0200 Subject: add new function pa_alsa_volume_divide() --- src/modules/alsa-util.c | 24 ++++++++++++++++++++++++ src/modules/alsa-util.h | 3 +++ 2 files changed, 27 insertions(+) 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 #include +#include #include #include #include @@ -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 -- cgit v1.2.1