From 37bd97c96ac79206518e95abc34933bd8b0f6369 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Thu, 30 Nov 2017 14:36:55 +0100 Subject: Change initial volume to be in % in place of absolute values Signed-off-by: Fulup Ar Foll --- alsa-binding/Alsa-AddCtl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'alsa-binding') 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 #include #include +#include #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 -- cgit 1.2.3-korg