summaryrefslogtreecommitdiffstats
path: root/alsa-binding
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-16 17:22:16 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-25 18:41:50 +0100
commit980a8f01d081080b087a832570f617187093c619 (patch)
tree169308d8b91686db6c388ae6d1da5e64b68f7fb9 /alsa-binding
parent985df9fad73cd9e9c5f18e18f3fe41e030f63b20 (diff)
Fix dbScale generation when adding custom control
Fix dbScale generation when a custom INTEGER ALSA control is added. Change-Id: I935de59d1ca30466c071972939c8ef200007ceb3 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'alsa-binding')
-rw-r--r--alsa-binding/Alsa-AddCtl.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/alsa-binding/Alsa-AddCtl.c b/alsa-binding/Alsa-AddCtl.c
index 60be790..9c48914 100644
--- a/alsa-binding/Alsa-AddCtl.c
+++ b/alsa-binding/Alsa-AddCtl.c
@@ -54,6 +54,11 @@
#define SNDRV_CTL_TLVD_DB_SCALE_MUTE 0x10000
#endif
+
+#define PRESET_MIN_DB -51.0
+#define ZERO_DB 0.0
+#define PRESET_STEP 1
+
static const unsigned int *allocate_bool_fake_tlv(void) {
static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(range, -10000, 0);
unsigned int *tlv = malloc(sizeof (range));
@@ -62,24 +67,14 @@ static const unsigned int *allocate_bool_fake_tlv(void) {
return tlv;
}
-static const unsigned int *allocate_int_dbscale_tlv(int min_dB, int max_dB) {
+static const unsigned int *allocate_int_dbscale_tlv(int min_dB, int max_dB, int resolution) {
// 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] = 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;
-}
-
-static const unsigned int *allocate_int_linear_tlv(int max, int min) {
- // SNDRV_CTL_TLVD_DECLARE_DB_LINEAR (range, min, max);
- unsigned int *tlv = malloc(4 * sizeof (unsigned int));
- tlv[0] = SNDRV_CTL_TLVT_DB_LINEAR;
- tlv[1] = (unsigned int)(2 * sizeof (unsigned int));
- tlv[2] = (unsigned int)(-min * 100);
- tlv[3] = (unsigned int)(max * 100);
+ tlv[3] = (int)((max_dB - min_dB) * 100 / resolution);
return tlv;
}
@@ -88,7 +83,7 @@ STATIC json_object * addOneSndCtl(afb_req_t request, snd_ctl_t *ctlDev, json_obj
json_object *tmpJ;
const char *ctlName;
ctlRequestT ctlRequest;
- int ctlMax=100, ctlMin=0, ctlStep, ctlCount, ctlSubDev=0, ctlSndDev=0;
+ int ctlMax=100, ctlMin=0, ctlStep=1, ctlCount=1, ctlSubDev=0, ctlSndDev=0;
snd_ctl_elem_type_t ctlType=SND_CTL_ELEM_TYPE_NONE;
snd_ctl_elem_info_t *elemInfo;
snd_ctl_elem_id_t *elemId;
@@ -107,7 +102,6 @@ STATIC json_object * addOneSndCtl(afb_req_t request, snd_ctl_t *ctlDev, json_obj
goto OnErrorExit;
}
-
// We are facing a software ctl
if (ctlNumid == CTL_AUTO) {
done = json_object_object_get_ex(ctlJ, "type", &tmpJ);
@@ -224,10 +218,12 @@ STATIC json_object * addOneSndCtl(afb_req_t request, snd_ctl_t *ctlDev, json_obj
}
}
+ // Prepare fake dbscale TLV values
+ int min = PRESET_MIN_DB, max = ZERO_DB, step = PRESET_STEP;
+
// Fulup needed to be tested with some dB expert !!!
json_object *dbscaleJ;
if (json_object_object_get_ex(ctlJ, "dbscale", &dbscaleJ)) {
- int min, max;
if (json_object_get_type(dbscaleJ) != json_type_object) {
afb_req_fail_f(request, "ctl-invalid-dbscale", "devid=%s crl=%s invalid json in integer control", snd_ctl_name(ctlDev), json_object_get_string(ctlJ));
@@ -246,16 +242,13 @@ STATIC json_object * addOneSndCtl(afb_req_t request, snd_ctl_t *ctlDev, json_obj
// default value 1dB
json_object_object_get_ex(ctlJ, "step", &tmpJ);
- int step = json_object_get_int(tmpJ);
+ step = json_object_get_int(tmpJ);
if (step <= 0) step = 1;
-
- elemTlv = allocate_int_dbscale_tlv(min, max);
-
}
- } else {
- // provide a fake linear TLV
- elemTlv = allocate_int_linear_tlv(ctlMin, ctlMax);
}
+
+ elemTlv = allocate_int_dbscale_tlv(min, max, (ctlMax - ctlMin));
+
break;
case SND_CTL_ELEM_TYPE_ENUMERATED: