Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8d7c925 authored by vivek mehta's avatar vivek mehta Committed by Eric Laurent
Browse files

hal: add support to override volume gain to step mapping table

- if customer mapping is added in platform info file, use that
- in absence of customer table use default mapping

BUG 28897755
Change-Id: I4bf8bcf1913f16ad6298ff1f3fa5dd649c889b2a
parent 1d2e4743
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -369,6 +369,27 @@ bool audio_hw_send_gain_dep_calibration(int level) {
    return ret_val;
}

__attribute__ ((visibility ("default")))
int audio_hw_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
                                    int table_size) {
     int ret_val = 0;
     ALOGV("%s: enter ... ", __func__);

     pthread_mutex_lock(&adev_init_lock);
     if (adev == NULL) {
         ALOGW("%s: adev is NULL .... ", __func__);
         goto done;
     }

     pthread_mutex_lock(&adev->lock);
     ret_val = platform_get_gain_level_mapping(mapping_tbl, table_size);
     pthread_mutex_unlock(&adev->lock);
done:
     pthread_mutex_unlock(&adev_init_lock);
     ALOGV("%s: exit ... ", __func__);
     return ret_val;
}

static bool is_supported_format(audio_format_t format)
{
    switch (format) {
+10 −0
Original line number Diff line number Diff line
@@ -1102,3 +1102,13 @@ bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev __unus
    return false;
}

bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry __unused)
{
    return false;
}

int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl __unused,
                                    int table_size __unused)
{
    return 0;
}
+50 −0
Original line number Diff line number Diff line
@@ -2733,3 +2733,53 @@ int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
    }
    return 0;
}

static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
static int num_gain_tbl_entry = 0;

bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {

    ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
    if (num_gain_tbl_entry == -1) {
        ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
               __func__);
        return false;
    }

    if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
        ALOGE("%s: max entry reached max[%d] current index[%d]  .. rejecting", __func__,
               MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
        num_gain_tbl_entry  = -1; // indicates error and no more info will be cached
        return false;
    }

    if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
        ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
        num_gain_tbl_entry  = -1; // indicates error and no more info will be cached
        return false;
    }

    tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
    ++num_gain_tbl_entry;

    return true;
}

int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
                                    int table_size) {
    int itt = 0;
    ALOGV("platform_get_gain_level_mapping called ");

    if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
        ALOGD("%s: empty or currupted gain_mapping_table", __func__);
        return 0;
    }

    for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
        mapping_tbl[itt] = tbl_mapping[itt];
        ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
               mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
    }

    return num_gain_tbl_entry;
}
+20 −0
Original line number Diff line number Diff line
@@ -17,6 +17,15 @@
#ifndef AUDIO_PLATFORM_API_H
#define AUDIO_PLATFORM_API_H

#include "voice.h"
#define MAX_VOLUME_CAL_STEPS 15

struct amp_db_and_gain_table {
    float amp;
    float db;
    uint32_t level;
};

void *platform_init(struct audio_device *adev);
void platform_deinit(void *platform);
const char *platform_get_snd_device_name(snd_device_t snd_device);
@@ -57,6 +66,17 @@ void platform_add_operator_specific_device(snd_device_t snd_device,
                                           const char *operator,
                                           const char *mixer_path,
                                           unsigned int acdb_id);
/* return true if adding entry success
   return false if adding entry fails */

bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry);

/* return 0 if no custome mapping table found or when error detected
            use default mapping in this case
   return > 0 indicates number of entries in mapping table */

int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
                                    int table_size);

/* returns the latency for a usecase in Us */
int64_t platform_render_latency(audio_usecase_t usecase);
+39 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <audio_hw.h>
#include "platform_api.h"
#include <platform.h>
#include <math.h>

typedef enum {
    ROOT,
@@ -32,6 +33,7 @@ typedef enum {
    BACKEND_NAME,
    CONFIG_PARAMS,
    OPERATOR_SPECIFIC,
    GAIN_LEVEL_MAPPING,
} section_t;

typedef void (* section_process_fn)(const XML_Char **attr);
@@ -42,6 +44,7 @@ static void process_backend_name(const XML_Char **attr);
static void process_config_params(const XML_Char **attr);
static void process_root(const XML_Char **attr);
static void process_operator_specific(const XML_Char **attr);
static void process_gain_db_to_level_map(const XML_Char **attr);

static section_process_fn section_table[] = {
    [ROOT] = process_root,
@@ -50,6 +53,7 @@ static section_process_fn section_table[] = {
    [BACKEND_NAME] = process_backend_name,
    [CONFIG_PARAMS] = process_config_params,
    [OPERATOR_SPECIFIC] = process_operator_specific,
    [GAIN_LEVEL_MAPPING] = process_gain_db_to_level_map,
};

static section_t section;
@@ -191,6 +195,29 @@ done:
    return;
}

static void process_gain_db_to_level_map(const XML_Char **attr)
{
    struct amp_db_and_gain_table tbl_entry;

    if ((strcmp(attr[0], "db") != 0) ||
        (strcmp(attr[2], "level") != 0)) {
        ALOGE("%s: invalid attribute passed  %s %sexpected amp db level",
               __func__, attr[0], attr[2]);
        goto done;
    }

    tbl_entry.db = atof(attr[1]);
    tbl_entry.amp = exp(tbl_entry.db * 0.115129f);
    tbl_entry.level = atoi(attr[3]);

    ALOGV("%s: amp [%f]  db [%f] level [%d]", __func__,
           tbl_entry.amp, tbl_entry.db, tbl_entry.level);
    platform_add_gain_level_mapping(&tbl_entry);

done:
    return;
}

static void process_acdb_id(const XML_Char **attr)
{
    int index;
@@ -297,6 +324,8 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name,
        section = CONFIG_PARAMS;
    } else if (strcmp(tag_name, "operator_specific") == 0) {
        section = OPERATOR_SPECIFIC;
    } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
        section = GAIN_LEVEL_MAPPING;
    } else if (strcmp(tag_name, "device") == 0) {
        if ((section != ACDB) && (section != BACKEND_NAME) && (section != OPERATOR_SPECIFIC)) {
            ALOGE("device tag only supported for acdb/backend names");
@@ -322,6 +351,14 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name,

        section_process_fn fn = section_table[section];
        fn(attr);
    } else if (strcmp(tag_name, "gain_level_map") == 0) {
        if (section != GAIN_LEVEL_MAPPING) {
            ALOGE("usecase tag only supported with GAIN_LEVEL_MAPPING section");
            return;
        }

        section_process_fn fn = section_table[GAIN_LEVEL_MAPPING];
        fn(attr);
    }

    return;
@@ -339,6 +376,8 @@ static void end_tag(void *userdata __unused, const XML_Char *tag_name)
        section = ROOT;
    } else if (strcmp(tag_name, "operator_specific") == 0) {
        section = ROOT;
    } else if (strcmp(tag_name, "gain_db_to_level_mapping") == 0) {
        section = ROOT;
    }
}

Loading