diff options
author | Hsin-Yu Chao <hychao@chromium.org> | 2018-08-14 17:15:03 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-31 05:23:08 -0700 |
commit | 205aff6cd98f5a33caf24cd450f2d4ecf1b950e5 (patch) | |
tree | 02b2ea6ce643a1c9868a71c5ad74c338e63443a2 | |
parent | b6d7df60b4a4973922689fbd4d109d586151f93c (diff) | |
download | adhd-205aff6cd98f5a33caf24cd450f2d4ecf1b950e5.tar.gz |
CRAS: config - Add apm_config
apm_config includes parameters not for AEC but useful
for tuning APM performance in CRAS.
BUG=chromium:874787
TEST=apply all config files and test on nocturne
CQ-DEPEND=CL:1174085
Change-Id: I7d3e42fdde41ef721303ac063236c79eb7b23156
Reviewed-on: https://chromium-review.googlesource.com/1180785
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
-rw-r--r-- | cras/src/Makefile.am | 3 | ||||
-rw-r--r-- | cras/src/server/config/apm_config.c | 94 | ||||
-rw-r--r-- | cras/src/server/config/apm_config.h | 45 | ||||
-rw-r--r-- | cras/src/server/cras_apm_list.c | 16 | ||||
-rw-r--r-- | cras/src/tests/apm_list_unittest.cc | 10 |
5 files changed, 165 insertions, 3 deletions
diff --git a/cras/src/Makefile.am b/cras/src/Makefile.am index b762e6f7..c4026258 100644 --- a/cras/src/Makefile.am +++ b/cras/src/Makefile.am @@ -32,7 +32,8 @@ endif if HAVE_WEBRTC_APM CRAS_WEBRTC_APM_SOURCES = \ server/cras_apm_list.c \ - server/config/aec_config.c + server/config/aec_config.c \ + server/config/apm_config.c else CRAS_WEBRTC_APM_SOURCES = endif diff --git a/cras/src/server/config/apm_config.c b/cras/src/server/config/apm_config.c new file mode 100644 index 00000000..ae5df699 --- /dev/null +++ b/cras/src/server/config/apm_config.c @@ -0,0 +1,94 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <syslog.h> + +#include "apm_config.h" +#include "iniparser_wrapper.h" + +static const unsigned int MAX_INI_NAME_LEN = 63; + +#define APM_CONFIG_NAME "apm.ini" + +#define APM_GET_INT(ini, key) \ + iniparser_getint( \ + ini, key, \ + key ## _VALUE) +#define APM_GET_FLOAT(ini, key) \ + iniparser_getdouble( \ + ini, key, \ + key ## _VALUE) + +struct apm_config *apm_config_get(const char *device_config_dir) +{ + struct apm_config *config; + char ini_name[MAX_INI_NAME_LEN + 1]; + dictionary *ini; + + snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", + device_config_dir, APM_CONFIG_NAME); + ini_name[MAX_INI_NAME_LEN] = '\0'; + + ini = iniparser_load_wrapper(ini_name); + if (ini == NULL) { + syslog(LOG_DEBUG, "No ini file %s", ini_name); + return NULL; + } + + config = (struct apm_config *)calloc(1, sizeof(*config)); + config->residual_echo_detector_enabled = + APM_GET_INT(ini, APM_RESIDUAL_ECHO_DETECTOR_ENABLED); + config->high_pass_filter_enabled = + APM_GET_INT(ini, APM_HIGH_PASS_FILTER_ENABLED); + config->pre_amplifier_enabled = + APM_GET_INT(ini, APM_PRE_AMPLIFIER_ENABLED); + config->pre_amplifier_fixed_gain_factor = + APM_GET_FLOAT(ini, APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR); + config->gain_controller2_enabled = + APM_GET_INT(ini, APM_GAIN_CONTROLLER2_ENABLED); + config->gain_controller2_fixed_gain_db = + APM_GET_FLOAT(ini, APM_GAIN_CONTROLLER2_FIXED_GAIN_DB); + config->gain_controller2_adaptive_digital_mode = + APM_GET_INT(ini, APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE); + config->gain_control_compression_gain_db = + APM_GET_INT(ini, APM_GAIN_CONTROL_COMPRESSION_GAIN_DB); + config->agc_mode = (enum gain_control_mode) + APM_GET_INT(ini, APM_GAIN_CONTROL_MODE); + config->gain_control_enabled = + APM_GET_INT(ini, APM_GAIN_CONTROL_ENABLED); + config->ns_level = (enum noise_suppression_level) + APM_GET_INT(ini, APM_NOISE_SUPPRESSION_LEVEL); + config->noise_suppression_enabled = + APM_GET_INT(ini, APM_NOISE_SUPPRESSION_ENABLED); + + return config; +} + +void apm_config_dump(struct apm_config *config) +{ + syslog(LOG_ERR, "---- apm config dump ----"); + syslog(LOG_ERR, "residual_echo_detector_enabled %u", + config->residual_echo_detector_enabled); + syslog(LOG_ERR, "high_pass_filter_enabled %u", + config->high_pass_filter_enabled); + syslog(LOG_ERR, "pre_amplifier_enabled %u", + config->pre_amplifier_enabled); + syslog(LOG_ERR, "pre_amplifier_fixed_gain_factor %f", + config->pre_amplifier_fixed_gain_factor); + syslog(LOG_ERR, "gain_controller2_enabled %u", + config->gain_controller2_enabled); + syslog(LOG_ERR, "gain_controller2_fixed_gain_db %f", + config->gain_controller2_fixed_gain_db); + syslog(LOG_ERR, "gain_controller2_adaptive_digital_mode %d", + config->gain_controller2_adaptive_digital_mode); + syslog(LOG_ERR, "gain_control_compression_gain_db %u", + config->gain_control_compression_gain_db); + syslog(LOG_ERR, "gain_control_mode %u", config->agc_mode); + syslog(LOG_ERR, "gain_control_enabled %u", + config->gain_control_enabled); + syslog(LOG_ERR, "noise_suppression_level %u", config->ns_level); + syslog(LOG_ERR, "noise_suppression_enabled %u", + config->noise_suppression_enabled); +} diff --git a/cras/src/server/config/apm_config.h b/cras/src/server/config/apm_config.h new file mode 100644 index 00000000..b0e39bef --- /dev/null +++ b/cras/src/server/config/apm_config.h @@ -0,0 +1,45 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef APM_CONFIG_H_ +#define APM_CONFIG_H_ + +#include <webrtc-apm/webrtc_apm.h> +#include <webrtc-apm/webrtc_apm.h> + +#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED "apm:residual_echo_detector_enabled" +#define APM_RESIDUAL_ECHO_DETECTOR_ENABLED_VALUE 1 +#define APM_HIGH_PASS_FILTER_ENABLED "apm:high_pass_filter_enabled" +#define APM_HIGH_PASS_FILTER_ENABLED_VALUE 0 +#define APM_PRE_AMPLIFIER_ENABLED "apm:pre_amplifier_enabled" +#define APM_PRE_AMPLIFIER_ENABLED_VALUE 0 +#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR "apm:pre_amplifier_fixed_gain_factor" +#define APM_PRE_AMPLIFIER_FIXED_GAIN_FACTOR_VALUE 1.f +#define APM_GAIN_CONTROLLER2_ENABLED "apm:gain_controller2_enabled" +#define APM_GAIN_CONTROLLER2_ENABLED_VALUE 0 +#define APM_GAIN_CONTROLLER2_FIXED_GAIN_DB "apm:gain_controller2_fixed_gain_db" +#define APM_GAIN_CONTROLLER2_FIXED_GAIN_DB_VALUE 0.f +#define APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE "apm:gain_controller2_adaptive_digital_mode" +#define APM_GAIN_CONTROLLER2_ADAPTIVE_DIGITAL_MODE_VALUE 1 +#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB "apm:gain_control_compression_gain_db" +#define APM_GAIN_CONTROL_COMPRESSION_GAIN_DB_VALUE 9 +/* 0: adaptive analog, 1: adaptive digital, 2: fixed digital */ +#define APM_GAIN_CONTROL_MODE "apm:gain_control_mode" +#define APM_GAIN_CONTROL_MODE_VALUE 0 +#define APM_GAIN_CONTROL_ENABLED "apm:gain_control_enabled" +#define APM_GAIN_CONTROL_ENABLED_VALUE 0 +/* 0: low, 1: moderate, 2: high, 3: very high*/ +#define APM_NOISE_SUPPRESSION_LEVEL "apm:noise_suppression_level" +#define APM_NOISE_SUPPRESSION_LEVEL_VALUE 0 +#define APM_NOISE_SUPPRESSION_ENABLED "apm:noise_suppression_enabled" +#define APM_NOISE_SUPPRESSION_ENABLED_VALUE 0 + +/* Gets apm config from given config directory. */ +struct apm_config *apm_config_get(const char *device_config_dir); + +/* Prints config content to syslog. */ +void apm_config_dump(struct apm_config *config); + +#endif /* APM_CONFIG_H_ */ diff --git a/cras/src/server/cras_apm_list.c b/cras/src/server/cras_apm_list.c index d85c6bcf..6d592c3e 100644 --- a/cras/src/server/cras_apm_list.c +++ b/cras/src/server/cras_apm_list.c @@ -9,6 +9,7 @@ #include <webrtc-apm/webrtc_apm.h> #include "aec_config.h" +#include "apm_config.h" #include "byte_buffer.h" #include "cras_apm_list.h" #include "cras_audio_area.h" @@ -109,6 +110,7 @@ struct cras_apm_reverse_module { static struct cras_apm_reverse_module *rmodule = NULL; static struct cras_apm_list *apm_list = NULL; static struct aec_config *aec_config = NULL; +static struct apm_config *apm_config = NULL; static const char *aec_config_dir = NULL; /* Update the global process reverse flag. Should be called when apms are added @@ -263,7 +265,8 @@ struct cras_apm *cras_apm_list_add(struct cras_apm_list *list, apm->apm_ptr = webrtc_apm_create( apm->fmt.num_channels, apm->fmt.frame_rate, - aec_config); + aec_config, + apm_config); if (apm->apm_ptr == NULL) { syslog(LOG_ERR, "Fail to create webrtc apm for ch %zu" " rate %zu effect %lu", @@ -447,6 +450,9 @@ int cras_apm_list_init(const char *device_config_dir) if (aec_config) free(aec_config); aec_config = aec_config_get(device_config_dir); + if (apm_config) + free(apm_config); + apm_config = apm_config_get(device_config_dir); update_first_output_dev_to_process(); cras_iodev_list_set_device_enabled_callback( @@ -469,6 +475,14 @@ void cras_apm_list_reload_aec_config() /* Dump the config content at reload only, for debug. */ if (aec_config) aec_config_dump(aec_config); + + if (apm_config) + free(apm_config); + apm_config = apm_config_get(aec_config_dir); + + /* Dump the config content at reload only, for debug. */ + if (apm_config) + apm_config_dump(apm_config); } int cras_apm_list_deinit() diff --git a/cras/src/tests/apm_list_unittest.cc b/cras/src/tests/apm_list_unittest.cc index 698bb741..89bde4b0 100644 --- a/cras/src/tests/apm_list_unittest.cc +++ b/cras/src/tests/apm_list_unittest.cc @@ -219,9 +219,17 @@ struct aec_config *aec_config_get(const char *device_config_dir) void aec_config_dump(struct aec_config *config) { } +struct apm_config *apm_config_get(const char *device_config_dir) +{ + return NULL; +} +void apm_config_dump(struct apm_config *config) +{ +} webrtc_apm webrtc_apm_create(unsigned int num_channels, unsigned int frame_rate, - struct aec_config *aec_config) + struct aec_config *aec_config, + struct apm_config *apm_config) { return reinterpret_cast<webrtc_apm>(0x11); } |