• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3#
4# Use of this source code is governed by a BSD-style license
5# that can be found in the LICENSE file in the root of the source
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS.  All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
9
10"""Generate .json files with which the APM module can be tested using the
11   apm_quality_assessment.py script and audioproc_f as APM simulator.
12"""
13
14import logging
15import os
16
17import quality_assessment.data_access as data_access
18
19OUTPUT_PATH = os.path.abspath('apm_configs')
20
21
22def _GenerateDefaultOverridden(config_override):
23  """Generates one or more APM overriden configurations.
24
25  For each item in config_override, it overrides the default configuration and
26  writes a new APM configuration file.
27
28  The default settings are loaded via "-all_default".
29  Check "src/modules/audio_processing/test/audioproc_float.cc" and search
30  for "if (FLAG_all_default) {".
31
32  For instance, in 55eb6d621489730084927868fed195d3645a9ec9 the default is this:
33  settings.use_aec = rtc::Optional<bool>(true);
34  settings.use_aecm = rtc::Optional<bool>(false);
35  settings.use_agc = rtc::Optional<bool>(true);
36  settings.use_bf = rtc::Optional<bool>(false);
37  settings.use_ed = rtc::Optional<bool>(false);
38  settings.use_hpf = rtc::Optional<bool>(true);
39  settings.use_le = rtc::Optional<bool>(true);
40  settings.use_ns = rtc::Optional<bool>(true);
41  settings.use_ts = rtc::Optional<bool>(true);
42  settings.use_vad = rtc::Optional<bool>(true);
43
44  Args:
45    config_override: dict of APM configuration file names as keys; the values
46                     are dict instances encoding the audioproc_f flags.
47  """
48  for config_filename in config_override:
49    config = config_override[config_filename]
50    config['-all_default'] = None
51
52    config_filepath = os.path.join(OUTPUT_PATH, 'default-{}.json'.format(
53        config_filename))
54    logging.debug('config file <%s> | %s', config_filepath, config)
55
56    data_access.AudioProcConfigFile.Save(config_filepath, config)
57    logging.info('config file created: <%s>', config_filepath)
58
59
60def _GenerateAllDefaultButOne():
61  """Disables the flags enabled by default one-by-one.
62  """
63  config_sets = {
64      'no_AEC': {'-aec': 0,},
65      'no_AGC': {'-agc': 0,},
66      'no_HP_filter': {'-hpf': 0,},
67      'no_level_estimator': {'-le': 0,},
68      'no_noise_suppressor': {'-ns': 0,},
69      'no_transient_suppressor': {'-ts': 0,},
70      'no_vad': {'-vad': 0,},
71  }
72  _GenerateDefaultOverridden(config_sets)
73
74
75def _GenerateAllDefaultPlusOne():
76  """Enables the flags disabled by default one-by-one.
77  """
78  config_sets = {
79      'with_AECM': {'-aec': 0, '-aecm': 1,},  # AEC and AECM are exclusive.
80      'with_AGC_limiter': {'-agc_limiter': 1,},
81      'with_AEC_delay_agnostic': {'-delay_agnostic': 1,},
82      'with_drift_compensation': {'-drift_compensation': 1,},
83      'with_residual_echo_detector': {'-ed': 1,},
84      'with_AEC_extended_filter': {'-extended_filter': 1,},
85      'with_LC': {'-lc': 1,},
86      'with_refined_adaptive_filter': {'-refined_adaptive_filter': 1,},
87  }
88  _GenerateDefaultOverridden(config_sets)
89
90
91def main():
92  logging.basicConfig(level=logging.INFO)
93  _GenerateAllDefaultPlusOne()
94  _GenerateAllDefaultButOne()
95
96
97if __name__ == '__main__':
98  main()
99