Chromium Code Reviews| 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 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 | 11 |
| 12 from . import audioproc_wrapper | 12 from . import audioproc_wrapper |
| 13 from . import data_access | 13 from . import data_access |
| 14 from . import eval_scores | 14 from . import eval_scores |
| 15 from . import eval_scores_factory | |
| 15 from . import evaluation | 16 from . import evaluation |
| 16 from . import noise_generation | 17 from . import noise_generation |
| 18 from . import noise_gen_factory | |
| 17 | 19 |
| 18 class ApmModuleSimulator(object): | 20 class ApmModuleSimulator(object): |
| 19 | 21 |
| 20 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES | 22 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES |
| 21 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES | 23 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES |
| 22 | 24 |
| 23 def __init__(self): | 25 def __init__(self, aechen_ir_database_path, polqa_tool_path): |
| 26 # Init. | |
| 24 self._audioproc_wrapper = audioproc_wrapper.AudioProcWrapper() | 27 self._audioproc_wrapper = audioproc_wrapper.AudioProcWrapper() |
| 25 self._evaluator = evaluation.ApmModuleEvaluator() | 28 self._evaluator = evaluation.ApmModuleEvaluator() |
| 26 | 29 |
| 30 # Instance factory objects. | |
| 31 self._noise_generator_factory = noise_gen_factory.NoiseGeneratorFactory( | |
| 32 aechen_ir_database_path=aechen_ir_database_path) | |
| 33 self._evaluation_score_factory = ( | |
| 34 eval_scores_factory.EvaluationScoreWorkerFactory( | |
| 35 polqa_tool_path=polqa_tool_path)) | |
|
AleBzk
2017/03/06 11:29:53
I added factory classes with which evaluation scor
| |
| 36 | |
| 37 # Properties for each run. | |
| 27 self._base_output_path = None | 38 self._base_output_path = None |
| 28 self._noise_generators = None | 39 self._noise_generators = None |
| 29 self._evaluation_score_workers = None | 40 self._evaluation_score_workers = None |
| 30 self._config_filepaths = None | 41 self._config_filepaths = None |
| 31 self._input_filepaths = None | 42 self._input_filepaths = None |
| 32 | 43 |
| 33 def run(self, config_filepaths, input_filepaths, noise_generator_names, | 44 def run(self, config_filepaths, input_filepaths, noise_generator_names, |
| 34 eval_score_names, output_dir): | 45 eval_score_names, output_dir): |
| 35 """ | 46 """ |
| 36 Initializes paths and required instances, then runs all the simulations. | 47 Initializes paths and required instances, then runs all the simulations. |
| 37 """ | 48 """ |
| 38 self._base_output_path = os.path.abspath(output_dir) | 49 self._base_output_path = os.path.abspath(output_dir) |
| 39 | 50 |
| 40 # Instance noise generators. | 51 # Instance noise generators. |
| 41 self._noise_generators = [ | 52 self._noise_generators = [self._noise_generator_factory.GetInstance( |
| 42 self._NOISE_GENERATOR_CLASSES[name]() for name in noise_generator_names] | 53 noise_generator_class=self._NOISE_GENERATOR_CLASSES[name]) for name in ( |
| 54 noise_generator_names)] | |
|
AleBzk
2017/03/06 11:29:53
Now getting an instance through the factory object
| |
| 43 | 55 |
| 44 # Instance evaluation score workers. | 56 # Instance evaluation score workers. |
| 45 self._evaluation_score_workers = [ | 57 self._evaluation_score_workers = [ |
| 46 self._EVAL_SCORE_WORKER_CLASSES[name]() for name in eval_score_names] | 58 self._evaluation_score_factory.GetInstance( |
| 59 evaluation_score_class=self._EVAL_SCORE_WORKER_CLASSES[name]) for ( | |
| 60 name) in eval_score_names] | |
|
AleBzk
2017/03/06 11:29:53
Now getting an instance through the factory object
| |
| 47 | 61 |
| 48 # Set APM configuration file paths. | 62 # Set APM configuration file paths. |
| 49 self._config_filepaths = self._get_paths_collection(config_filepaths) | 63 self._config_filepaths = self._get_paths_collection(config_filepaths) |
| 50 | 64 |
| 51 # Set probing signal file paths. | 65 # Set probing signal file paths. |
| 52 self._input_filepaths = self._get_paths_collection(input_filepaths) | 66 self._input_filepaths = self._get_paths_collection(input_filepaths) |
| 53 | 67 |
| 54 self._simulate_all() | 68 self._simulate_all() |
| 55 | 69 |
| 56 def _simulate_all(self): | 70 def _simulate_all(self): |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 """ | 121 """ |
| 108 Given a list of file paths, makes a collection with one pair for each item | 122 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 | 123 in the list where the key is the file name without extension and the value |
| 110 is the path. | 124 is the path. |
| 111 """ | 125 """ |
| 112 filepaths_collection = {} | 126 filepaths_collection = {} |
| 113 for filepath in filepaths: | 127 for filepath in filepaths: |
| 114 name = os.path.splitext(os.path.split(filepath)[1])[0] | 128 name = os.path.splitext(os.path.split(filepath)[1])[0] |
| 115 filepaths_collection[name] = os.path.abspath(filepath) | 129 filepaths_collection[name] = os.path.abspath(filepath) |
| 116 return filepaths_collection | 130 return filepaths_collection |
| OLD | NEW |