diff options
author | Ronan Le Martret <ronan.lemartret@iot.bzh> | 2017-12-19 03:02:57 +0100 |
---|---|---|
committer | Ronan Le Martret <ronan.lemartret@iot.bzh> | 2017-12-19 03:02:57 +0100 |
commit | b5007352099457ef9d9ff5bb757af605ef927b16 (patch) | |
tree | 215149d342213edcba409b5e4060685ff683bf49 /alsa-binding/Alsa-AddCtl.c | |
parent | b471b1677decf5b3fac149b90c5266929876db8c (diff) |
Change initial volume to be in % in place of absolute values
Signed-off-by: Fulup Ar Foll <fulup@iot.bzh>
Signed-off-by: Ronan Le Martret <ronan.lemartret@iot.bzh>
Diffstat (limited to 'alsa-binding/Alsa-AddCtl.c')
-rw-r--r-- | alsa-binding/Alsa-AddCtl.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/alsa-binding/Alsa-AddCtl.c b/alsa-binding/Alsa-AddCtl.c index 82a6dac..a1da706 100644 --- a/alsa-binding/Alsa-AddCtl.c +++ b/alsa-binding/Alsa-AddCtl.c @@ -25,6 +25,7 @@ #include <alsa/sound/tlv.h> #include <systemd/sd-event.h> #include <sys/ioctl.h> +#include <math.h> #include "Alsa-ApiHat.h" @@ -299,7 +300,17 @@ UpdateDefaultVal: // Set Value to default snd_ctl_elem_value_alloca(&elemValue); for (int idx = 0; idx < snd_ctl_elem_info_get_count(elemInfo); idx++) { - snd_ctl_elem_value_set_integer(elemValue, idx, ctlValue); + + // initial default value should be a percentage for integer + if (snd_ctl_elem_info_get_type(elemInfo) == SND_CTL_ELEM_TYPE_INTEGER) { + double min = (double)snd_ctl_elem_info_get_min(elemInfo); + double max = (double)snd_ctl_elem_info_get_max(elemInfo); + double normValue = ceil((ctlValue) * (max - min) * 0.01 + min); + snd_ctl_elem_value_set_integer(elemValue, idx, (int)normValue); + + } else { + snd_ctl_elem_value_set_integer(elemValue, idx, ctlValue); + } } // write default values in newly created control |