Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/simulation.py

Issue 2793903006: Style fix and docstring for the APM QA Python tool (Closed)
Patch Set: _ prefix for internal use functions Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. 9 """APM module simulator.
10 """ 10 """
(...skipping 30 matching lines...) Expand all
41 eval_scores_factory.EvaluationScoreWorkerFactory( 41 eval_scores_factory.EvaluationScoreWorkerFactory(
42 polqa_tool_path=polqa_tool_path)) 42 polqa_tool_path=polqa_tool_path))
43 43
44 # Properties for each run. 44 # Properties for each run.
45 self._base_output_path = None 45 self._base_output_path = None
46 self._noise_generators = None 46 self._noise_generators = None
47 self._evaluation_score_workers = None 47 self._evaluation_score_workers = None
48 self._config_filepaths = None 48 self._config_filepaths = None
49 self._input_filepaths = None 49 self._input_filepaths = None
50 50
51 def run(self, config_filepaths, input_filepaths, noise_generator_names, 51 def Run(self, config_filepaths, input_filepaths, noise_generator_names,
52 eval_score_names, output_dir): 52 eval_score_names, output_dir):
53 """ 53 """Runs the APM simulation.
54
54 Initializes paths and required instances, then runs all the simulations. 55 Initializes paths and required instances, then runs all the simulations.
56
57 Args:
58 config_filepaths: set of APM configuration files to test.
59 input_filepaths: set of input audio track files to test.
60 noise_generator_names: set of noise generator names to test.
61 eval_score_names: set of evaluation score names to test.
62 output_dir: base path to the output directory for wav files and outcomes.
55 """ 63 """
56 self._base_output_path = os.path.abspath(output_dir) 64 self._base_output_path = os.path.abspath(output_dir)
57 65
58 # Instance noise generators. 66 # Instance noise generators.
59 self._noise_generators = [self._noise_generator_factory.GetInstance( 67 self._noise_generators = [self._noise_generator_factory.GetInstance(
60 noise_generator_class=self._NOISE_GENERATOR_CLASSES[name]) for name in ( 68 noise_generator_class=self._NOISE_GENERATOR_CLASSES[name]) for name in (
61 noise_generator_names)] 69 noise_generator_names)]
62 70
63 # Instance evaluation score workers. 71 # Instance evaluation score workers.
64 self._evaluation_score_workers = [ 72 self._evaluation_score_workers = [
65 self._evaluation_score_factory.GetInstance( 73 self._evaluation_score_factory.GetInstance(
66 evaluation_score_class=self._EVAL_SCORE_WORKER_CLASSES[name]) for ( 74 evaluation_score_class=self._EVAL_SCORE_WORKER_CLASSES[name]) for (
67 name) in eval_score_names] 75 name) in eval_score_names]
68 76
69 # Set APM configuration file paths. 77 # Set APM configuration file paths.
70 self._config_filepaths = self._get_paths_collection(config_filepaths) 78 self._config_filepaths = self._CreatePathsCollection(config_filepaths)
71 79
72 # Set probing signal file paths. 80 # Set probing signal file paths.
73 self._input_filepaths = self._get_paths_collection(input_filepaths) 81 self._input_filepaths = self._CreatePathsCollection(input_filepaths)
74 82
75 self._simulate_all() 83 self._SimulateAll()
76 84
77 def _simulate_all(self): 85 def _SimulateAll(self):
78 """ 86 """Runs all the simulations.
87
79 Iterates over the combinations of APM configurations, probing signals, and 88 Iterates over the combinations of APM configurations, probing signals, and
80 noise generators. 89 noise generators.
81 """ 90 """
82 # Try different APM config files. 91 # Try different APM config files.
83 for config_name in self._config_filepaths: 92 for config_name in self._config_filepaths:
84 config_filepath = self._config_filepaths[config_name] 93 config_filepath = self._config_filepaths[config_name]
85 94
86 # Try different probing signal files. 95 # Try different probing signal files.
87 for input_name in self._input_filepaths: 96 for input_name in self._input_filepaths:
88 input_filepath = self._input_filepaths[input_name] 97 input_filepath = self._input_filepaths[input_name]
89 98
90 # Try different noise generators. 99 # Try different noise generators.
91 for noise_generator in self._noise_generators: 100 for noise_generator in self._noise_generators:
92 logging.info('config: <%s>, input: <%s>, noise: <%s>', 101 logging.info('config: <%s>, input: <%s>, noise: <%s>',
93 config_name, input_name, noise_generator.NAME) 102 config_name, input_name, noise_generator.NAME)
94 103
95 # Output path for the input-noise pairs. It is used to cache the noisy 104 # Output path for the input-noise pairs. It is used to cache the noisy
96 # copies of the probing signals (shared across some simulations). 105 # copies of the probing signals (shared across some simulations).
97 input_noise_cache_path = os.path.join( 106 input_noise_cache_path = os.path.join(
98 self._base_output_path, 107 self._base_output_path,
99 '_cache', 108 '_cache',
100 'input_{}-noise_{}'.format(input_name, noise_generator.NAME)) 109 'input_{}-noise_{}'.format(input_name, noise_generator.NAME))
101 data_access.make_directory(input_noise_cache_path) 110 data_access.MakeDirectory(input_noise_cache_path)
102 logging.debug('input-noise cache path: <%s>', input_noise_cache_path) 111 logging.debug('input-noise cache path: <%s>', input_noise_cache_path)
103 112
104 # Full output path. 113 # Full output path.
105 output_path = os.path.join( 114 output_path = os.path.join(
106 self._base_output_path, 115 self._base_output_path,
107 'cfg-{}'.format(config_name), 116 'cfg-{}'.format(config_name),
108 'input-{}'.format(input_name), 117 'input-{}'.format(input_name),
109 'noise-{}'.format(noise_generator.NAME)) 118 'noise-{}'.format(noise_generator.NAME))
110 data_access.make_directory(output_path) 119 data_access.MakeDirectory(output_path)
111 logging.debug('output path: <%s>', output_path) 120 logging.debug('output path: <%s>', output_path)
112 121
113 self._simulate(noise_generator, input_filepath, 122 self._Simulate(noise_generator, input_filepath,
114 input_noise_cache_path, output_path, config_filepath) 123 input_noise_cache_path, output_path, config_filepath)
115 124
116 def _simulate(self, noise_generator, input_filepath, input_noise_cache_path, 125 def _Simulate(self, noise_generator, input_filepath, input_noise_cache_path,
117 output_path, config_filepath): 126 output_path, config_filepath):
118 """ 127 """Runs a single set of simulation.
119 Simulates a given combination of APM configurations, probing signals, and 128
120 noise generators. It iterates over the noise generator internal 129 Simulates a given combination of APM configuration, probing signal, and
130 noise generator. It iterates over the noise generator internal
121 configurations. 131 configurations.
132
133 Args:
134 noise_generator: NoiseGenerator instance.
135 input_filepath: input audio track file to test.
136 input_noise_cache_path: path for the noisy audio track files.
137 output_path: base output path for the noise generator.
138 config_filepath: APM configuration file to test.
122 """ 139 """
123 # Generate pairs of noisy input and reference signal files. 140 # Generate pairs of noisy input and reference signal files.
124 noise_generator.generate( 141 noise_generator.Generate(
125 input_signal_filepath=input_filepath, 142 input_signal_filepath=input_filepath,
126 input_noise_cache_path=input_noise_cache_path, 143 input_noise_cache_path=input_noise_cache_path,
127 base_output_path=output_path) 144 base_output_path=output_path)
128 145
129 # For each input-reference pair, simulate a call and evaluate. 146 # For each input-reference pair, simulate a call and evaluate.
130 for noise_generator_config_name in noise_generator.config_names: 147 for noise_generator_config_name in noise_generator.config_names:
131 logging.info(' - noise config: <%s>', noise_generator_config_name) 148 logging.info(' - noise config: <%s>', noise_generator_config_name)
132 149
133 # APM input and output signal paths. 150 # APM input and output signal paths.
134 noisy_signal_filepath = noise_generator.noisy_signal_filepaths[ 151 noisy_signal_filepath = noise_generator.noisy_signal_filepaths[
135 noise_generator_config_name] 152 noise_generator_config_name]
136 evaluation_output_path = noise_generator.output_paths[ 153 evaluation_output_path = noise_generator.apm_output_paths[
137 noise_generator_config_name] 154 noise_generator_config_name]
138 155
139 # Simulate a call using the audio processing module. 156 # Simulate a call using the audio processing module.
140 self._audioproc_wrapper.run( 157 self._audioproc_wrapper.Run(
141 config_filepath=config_filepath, 158 config_filepath=config_filepath,
142 input_filepath=noisy_signal_filepath, 159 input_filepath=noisy_signal_filepath,
143 output_path=evaluation_output_path) 160 output_path=evaluation_output_path)
144 161
145 # Reference signal path for the evaluation step. 162 # Reference signal path for the evaluation step.
146 reference_signal_filepath = noise_generator.reference_signal_filepaths[ 163 reference_signal_filepath = noise_generator.reference_signal_filepaths[
147 noise_generator_config_name] 164 noise_generator_config_name]
148 165
149 # Evaluate. 166 # Evaluate.
150 self._evaluator.run( 167 self._evaluator.Run(
151 evaluation_score_workers=self._evaluation_score_workers, 168 evaluation_score_workers=self._evaluation_score_workers,
152 apm_output_filepath=self._audioproc_wrapper.output_filepath, 169 apm_output_filepath=self._audioproc_wrapper.output_filepath,
153 reference_input_filepath=reference_signal_filepath, 170 reference_input_filepath=reference_signal_filepath,
154 output_path=evaluation_output_path) 171 output_path=evaluation_output_path)
155 172
156 @classmethod 173 @classmethod
157 def _get_paths_collection(cls, filepaths): 174 def _CreatePathsCollection(cls, filepaths):
158 """ 175 """Creates a collection of file paths.
159 Given a list of file paths, makes a collection with one pair for each item 176
160 in the list where the key is the file name without extension and the value 177 Given a list of file paths, makes a collection with one item for each file
161 is the path. 178 path. The value is absolute path, the key is the file name without
179 extenstion.
180
181 Args:
182 filepaths: list of file paths.
183
184 Returns:
185 A dict.
162 """ 186 """
163 filepaths_collection = {} 187 filepaths_collection = {}
164 for filepath in filepaths: 188 for filepath in filepaths:
165 name = os.path.splitext(os.path.split(filepath)[1])[0] 189 name = os.path.splitext(os.path.split(filepath)[1])[0]
166 filepaths_collection[name] = os.path.abspath(filepath) 190 filepaths_collection[name] = os.path.abspath(filepath)
167 return filepaths_collection 191 return filepaths_collection
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/signal_processing_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698