summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-02 01:35:53 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-06 16:49:46 +0000
commitee41b0386fae5d4d753313d6e4cae1f07ba18138 (patch)
treefb349c82c50b1b6f72864452fc3cf7c1cabf8466
parent3ee6068012b9afc958598385fe17587ef8fdcefc (diff)
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 <jonathan.aillet@iot.bzh>
-rw-r--r--alsa-binding/Alsa-AddCtl.c16
1 files changed, 8 insertions, 8 deletions
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;