OLD | NEW |
1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license | 3 # Use of this source code is governed by a BSD-style license |
4 # that can be found in the LICENSE file in the root of the source | 4 # that can be found in the LICENSE file in the root of the source |
5 # tree. An additional intellectual property rights grant can be found | 5 # tree. An additional intellectual property rights grant can be found |
6 # in the file PATENTS. All contributing project authors may | 6 # in the file PATENTS. All contributing project authors may |
7 # be found in the AUTHORS file in the root of the source tree. | 7 # be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
| 9 """APM module simulator. |
| 10 """ |
| 11 |
9 import logging | 12 import logging |
10 import os | 13 import os |
11 | 14 |
12 from . import audioproc_wrapper | 15 from . import audioproc_wrapper |
13 from . import data_access | 16 from . import data_access |
14 from . import eval_scores | 17 from . import eval_scores |
| 18 from . import eval_scores_factory |
15 from . import evaluation | 19 from . import evaluation |
16 from . import noise_generation | 20 from . import noise_generation |
| 21 from . import noise_generation_factory |
| 22 |
17 | 23 |
18 class ApmModuleSimulator(object): | 24 class ApmModuleSimulator(object): |
| 25 """APM module simulator class. |
| 26 """ |
19 | 27 |
20 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES | 28 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES |
21 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES | 29 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES |
22 | 30 |
23 def __init__(self): | 31 def __init__(self, aechen_ir_database_path, polqa_tool_path): |
| 32 # Init. |
24 self._audioproc_wrapper = audioproc_wrapper.AudioProcWrapper() | 33 self._audioproc_wrapper = audioproc_wrapper.AudioProcWrapper() |
25 self._evaluator = evaluation.ApmModuleEvaluator() | 34 self._evaluator = evaluation.ApmModuleEvaluator() |
26 | 35 |
| 36 # Instance factory objects. |
| 37 self._noise_generator_factory = ( |
| 38 noise_generation_factory.NoiseGeneratorFactory( |
| 39 aechen_ir_database_path=aechen_ir_database_path)) |
| 40 self._evaluation_score_factory = ( |
| 41 eval_scores_factory.EvaluationScoreWorkerFactory( |
| 42 polqa_tool_path=polqa_tool_path)) |
| 43 |
| 44 # Properties for each run. |
27 self._base_output_path = None | 45 self._base_output_path = None |
28 self._noise_generators = None | 46 self._noise_generators = None |
29 self._evaluation_score_workers = None | 47 self._evaluation_score_workers = None |
30 self._config_filepaths = None | 48 self._config_filepaths = None |
31 self._input_filepaths = None | 49 self._input_filepaths = None |
32 | 50 |
33 def run(self, config_filepaths, input_filepaths, noise_generator_names, | 51 def run(self, config_filepaths, input_filepaths, noise_generator_names, |
34 eval_score_names, output_dir): | 52 eval_score_names, output_dir): |
35 """ | 53 """ |
36 Initializes paths and required instances, then runs all the simulations. | 54 Initializes paths and required instances, then runs all the simulations. |
37 """ | 55 """ |
38 self._base_output_path = os.path.abspath(output_dir) | 56 self._base_output_path = os.path.abspath(output_dir) |
39 | 57 |
40 # Instance noise generators. | 58 # Instance noise generators. |
41 self._noise_generators = [ | 59 self._noise_generators = [self._noise_generator_factory.GetInstance( |
42 self._NOISE_GENERATOR_CLASSES[name]() for name in noise_generator_names] | 60 noise_generator_class=self._NOISE_GENERATOR_CLASSES[name]) for name in ( |
| 61 noise_generator_names)] |
43 | 62 |
44 # Instance evaluation score workers. | 63 # Instance evaluation score workers. |
45 self._evaluation_score_workers = [ | 64 self._evaluation_score_workers = [ |
46 self._EVAL_SCORE_WORKER_CLASSES[name]() for name in eval_score_names] | 65 self._evaluation_score_factory.GetInstance( |
| 66 evaluation_score_class=self._EVAL_SCORE_WORKER_CLASSES[name]) for ( |
| 67 name) in eval_score_names] |
47 | 68 |
48 # Set APM configuration file paths. | 69 # Set APM configuration file paths. |
49 self._config_filepaths = self._get_paths_collection(config_filepaths) | 70 self._config_filepaths = self._get_paths_collection(config_filepaths) |
50 | 71 |
51 # Set probing signal file paths. | 72 # Set probing signal file paths. |
52 self._input_filepaths = self._get_paths_collection(input_filepaths) | 73 self._input_filepaths = self._get_paths_collection(input_filepaths) |
53 | 74 |
54 self._simulate_all() | 75 self._simulate_all() |
55 | 76 |
56 def _simulate_all(self): | 77 def _simulate_all(self): |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 """ | 128 """ |
108 Given a list of file paths, makes a collection with one pair for each item | 129 Given a list of file paths, makes a collection with one pair for each item |
109 in the list where the key is the file name without extension and the value | 130 in the list where the key is the file name without extension and the value |
110 is the path. | 131 is the path. |
111 """ | 132 """ |
112 filepaths_collection = {} | 133 filepaths_collection = {} |
113 for filepath in filepaths: | 134 for filepath in filepaths: |
114 name = os.path.splitext(os.path.split(filepath)[1])[0] | 135 name = os.path.splitext(os.path.split(filepath)[1])[0] |
115 filepaths_collection[name] = os.path.abspath(filepath) | 136 filepaths_collection[name] = os.path.abspath(filepath) |
116 return filepaths_collection | 137 return filepaths_collection |
OLD | NEW |