summaryrefslogtreecommitdiffstats
path: root/alsa-binding/Alsa-AddCtl.c
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-14 16:02:58 +0200
commit76c6f19a3815553036ff06a51e977a59ccbbf062 (patch)
treef01bb83fe25d6e5be6c9a1dfd70f1bd238c89713 /alsa-binding/Alsa-AddCtl.c
parentd8064270ced05c7a28463120f21b7b2a29497772 (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>
Diffstat (limited to 'alsa-binding/Alsa-AddCtl.c')
-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;