aboutsummaryrefslogtreecommitdiffstats
path: root/HAL-afb/HAL-interface/hal-volmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'HAL-afb/HAL-interface/hal-volmap.c')
-rw-r--r--HAL-afb/HAL-interface/hal-volmap.c97
1 files changed, 74 insertions, 23 deletions
diff --git a/HAL-afb/HAL-interface/hal-volmap.c b/HAL-afb/HAL-interface/hal-volmap.c
index de99974..2b619fd 100644
--- a/HAL-afb/HAL-interface/hal-volmap.c
+++ b/HAL-afb/HAL-interface/hal-volmap.c
@@ -24,26 +24,30 @@
typedef enum {
- DB_NORMALIZE_LINEAR,
- DB_NORMALIZE_MATH,
+ NORMALIZE_NONE=0,
+ NORMALIZE_DB_LINEAR,
+ NORMALIZE_DB_MATH,
+ NORMALIZE_LINEAR,
} enumRandeModeDB_T;
+
// Return Value express from 0-100%
STATIC int dbNormalizeVal (enumRandeModeDB_T normaliseMode, const alsaHalDBscaleT *dbscale, int value) {
double normalized, min_norm;
-
+
// To get real DB from TLV DB values should be divided by 100
switch (normaliseMode) {
- case DB_NORMALIZE_LINEAR:
- normalized = ((double)(value-dbscale->min)/(double)(dbscale->max-dbscale->min))*100;
+ case NORMALIZE_DB_LINEAR:
+ normalized = ((double)(value-dbscale->min)/(double)(dbscale->max-dbscale->min));
break;
- case DB_NORMALIZE_MATH:
+ case NORMALIZE_DB_MATH:
normalized = exp10((double)(value - dbscale->max) / 6000.0);
if (dbscale->min != SND_CTL_TLV_DB_GAIN_MUTE) {
- min_norm = exp10((double)(dbscale->min - dbscale->max) / 6000.0);
+ min_norm = exp10((double)(dbscale->min - dbscale->max) / 20);
normalized = (normalized - min_norm) / (1 - min_norm);
}
+
break;
default:
@@ -54,35 +58,82 @@ STATIC int dbNormalizeVal (enumRandeModeDB_T normaliseMode, const alsaHalDBscale
}
// HAL normalise volume values to 0-100%
-PUBLIC struct json_object *GetNormaliseVolume(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) {
- int useNormalizeDB;
+PUBLIC struct json_object *SetGetNormaliseVolumes(ActionSetGetT action, const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) {
+ enumRandeModeDB_T useNormalizeDB;
+ int length;
+
+ // If Integer look for DBscale
+ if (halCtls->type == SND_CTL_ELEM_TYPE_INTEGER) {
- // If not valid db_scale let's use raw_scale
- if (!halCtls->dbscale || (halCtls->dbscale->min >= halCtls->dbscale->max)) {
+ // If not valid db_scale let's use raw_scale
+ if (!halCtls->dbscale || (halCtls->dbscale->min >= halCtls->dbscale->max)) {
// dbscale is invalid let's try raw range
if (halCtls->minval >= halCtls->maxval) goto ExitOnError;
// Use Raw Scale Model
- useNormalizeDB= 0;
+ useNormalizeDB= NORMALIZE_LINEAR;
- } else { // db_scale looks OK let's use it
- if ((halCtls->dbscale->max - halCtls->dbscale->min) <= MAX_LINEAR_DB_SCALE * 100) useNormalizeDB= DB_NORMALIZE_LINEAR;
- else useNormalizeDB = DB_NORMALIZE_MATH;
-
- }
+ } else { // db_scale looks OK let's use it
+ if ((halCtls->dbscale->max - halCtls->dbscale->min) <= MAX_LINEAR_DB_SCALE * 100) useNormalizeDB= NORMALIZE_DB_LINEAR;
+ else useNormalizeDB = NORMALIZE_LINEAR; // Fulup not sure how to handle this useNormalizeDB=NORMALIZE_DB_MATH;
+ }
+ } else useNormalizeDB= NORMALIZE_NONE;
+
// loop on values to normalise
- int length = json_object_array_length(valuesJ);
+ enum json_type jtype=json_object_get_type(valuesJ);
+ if (jtype == json_type_array) length = json_object_array_length(valuesJ);
+ else length = 1;
+
json_object *normalisedJ= json_object_new_array();
- for (int idx=0; idx <length; idx++) {
- json_object *valueJ = json_object_array_get_idx (valuesJ, idx);
- int value = json_object_get_int(valueJ);
+ for (int idx=0; idx < length; idx++) {
+ int value;
+
+ if (jtype == json_type_array) {
+ json_object *valueJ = json_object_array_get_idx (valuesJ, idx);
+ value = json_object_get_int(valueJ);
+ } else {
+ value = json_object_get_int(valuesJ);
+ }
// If Integer scale to 0/100
if (halCtls->type == SND_CTL_ELEM_TYPE_INTEGER) {
- if (useNormalizeDB) value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value);
- else value = 100* (value - halCtls->minval) / (halCtls->maxval - halCtls->minval);
+
+ switch (action) {
+
+ case ACTION_GET:
+ switch (useNormalizeDB) {
+ case NORMALIZE_LINEAR:
+ value = 100* (value - halCtls->minval) / (halCtls->maxval - halCtls->minval);
+ break;
+ case NORMALIZE_DB_MATH: //ToBeDone
+ value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value);
+ break;
+ case NORMALIZE_NONE:
+ default:
+ value = value;
+ }
+ break;
+
+ case ACTION_SET:
+ switch (useNormalizeDB) {
+ case NORMALIZE_LINEAR:
+ value = (value * (halCtls->maxval - halCtls->minval))/100;
+ break;
+ case NORMALIZE_DB_MATH: //ToBeDone
+ value = dbNormalizeVal (useNormalizeDB, halCtls->dbscale, value);
+ break;
+ case NORMALIZE_NONE:
+ default:
+ value = value;
+ }
+ break;
+
+ default:
+ AFB_NOTICE ("SetGetNormaliseVolumes: invalid action value=%d", (int)action);
+ goto ExitOnError;
+ }
}
json_object_array_add(normalisedJ, json_object_new_int(value));