From ee41b0386fae5d4d753313d6e4cae1f07ba18138 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Sat, 2 Jun 2018 01:35:53 +0200 Subject: Update dB basic TLV Handle volume in dB instead of absolute value. Allows a more natural augmentation/diminution of volume. Bug-AGL: SPEC-1405 Change-Id: If186c826e7008283f7c05599efa6158ac613a380 Signed-off-by: Jonathan Aillet --- alsa-binding/Alsa-AddCtl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'alsa-binding') diff --git a/alsa-binding/Alsa-AddCtl.c b/alsa-binding/Alsa-AddCtl.c index a1da706..02bc268 100644 --- a/alsa-binding/Alsa-AddCtl.c +++ b/alsa-binding/Alsa-AddCtl.c @@ -62,14 +62,14 @@ static const unsigned int *allocate_bool_fake_tlv(void) { return tlv; } -static const unsigned int *allocate_int_dbscale_tlv(int min, int step, int mute) { +static const unsigned int *allocate_int_dbscale_tlv(int min_dB, int max_dB) { // SNDRV_CTL_TLVD_DECLARE_DB_SCALE(range, min, step, mute); size_t tlvSize = sizeof (4 * sizeof (unsigned int)); unsigned int *tlv = malloc(tlvSize); - tlv[0] = SNDRV_CTL_TLVT_DB_LINEAR; - tlv[1] = (int) tlvSize; - tlv[2] = min * 100; - tlv[3] = ((step * 100) & SNDRV_CTL_TLVD_DB_SCALE_MASK) | ((mute * 100) ? SNDRV_CTL_TLVD_DB_SCALE_MUTE : 0); + tlv[0] = SND_CTL_TLVT_DB_SCALE; + tlv[1] = 2 * sizeof(int); + tlv[2] = (int)(min_dB * 100); + tlv[3] = (int)((max_dB - min_dB) * 100 / max_dB); return tlv; } @@ -249,7 +249,7 @@ STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_objec int step = json_object_get_int(tmpJ); if (step <= 0) step = 1; - elemTlv = allocate_int_dbscale_tlv(min, max, step); + elemTlv = allocate_int_dbscale_tlv(min, max); } } else { @@ -268,7 +268,7 @@ STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_objec goto OnErrorExit; } - int length = json_object_array_length(enumsJ); + size_t length = json_object_array_length(enumsJ); const char **enumlabels = malloc(length * sizeof (char*)); for (int jdx = 0; jdx < length; jdx++) { @@ -276,7 +276,7 @@ STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_objec enumlabels[jdx] = json_object_get_string(tmpJ); } - err = snd_ctl_add_enumerated_elem_set(ctlDev, elemInfo, 1, ctlCount, length, enumlabels); + err = snd_ctl_add_enumerated_elem_set(ctlDev, elemInfo, 1, ctlCount, (int) length, enumlabels); if (err) { afb_req_fail_f(request, "ctl-invalid-bool", "devid=%s crl=%s invalid enumerated control", snd_ctl_name(ctlDev), json_object_get_string(ctlJ)); goto OnErrorExit; -- cgit 1.2.3-korg