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

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

Issue 3010413002: Total Harmonic Distorsion plus noise (THD+n) score in APM-QA. (Closed)
Patch Set: merge Created 3 years, 2 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 """
11 11
12 import logging 12 import logging
13 import os 13 import os
14 14
15 from . import data_access 15 from . import data_access
16 from . import echo_path_simulation 16 from . import echo_path_simulation
17 from . import echo_path_simulation_factory 17 from . import echo_path_simulation_factory
18 from . import eval_scores 18 from . import eval_scores
19 from . import eval_scores_factory 19 from . import eval_scores_factory
20 from . import exceptions
20 from . import input_mixer 21 from . import input_mixer
21 from . import test_data_generation 22 from . import test_data_generation
22 from . import test_data_generation_factory 23 from . import test_data_generation_factory
23 24
24 25
25 class ApmModuleSimulator(object): 26 class ApmModuleSimulator(object):
26 """Audio processing module (APM) simulator class. 27 """Audio processing module (APM) simulator class.
27 """ 28 """
28 29
29 _TEST_DATA_GENERATOR_CLASSES = ( 30 _TEST_DATA_GENERATOR_CLASSES = (
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 output_path: base output path for the test data generator. 242 output_path: base output path for the test data generator.
242 config_filepath: APM configuration file to test. 243 config_filepath: APM configuration file to test.
243 echo_path_simulator: EchoPathSimulator instance. 244 echo_path_simulator: EchoPathSimulator instance.
244 """ 245 """
245 # Generate pairs of noisy input and reference signal files. 246 # Generate pairs of noisy input and reference signal files.
246 test_data_generators.Generate( 247 test_data_generators.Generate(
247 input_signal_filepath=clean_capture_input_filepath, 248 input_signal_filepath=clean_capture_input_filepath,
248 test_data_cache_path=test_data_cache_path, 249 test_data_cache_path=test_data_cache_path,
249 base_output_path=output_path) 250 base_output_path=output_path)
250 251
252 # Extract metadata linked to the clean input file (if any).
253 apm_input_metadata = None
254 try:
255 apm_input_metadata = data_access.Metadata.LoadFileMetadata(
256 clean_capture_input_filepath)
257 except IOError as e:
258 apm_input_metadata = {}
259 apm_input_metadata['test_data_gen_name'] = test_data_generators.NAME
260 apm_input_metadata['test_data_gen_config'] = None
261
251 # For each test data pair, simulate a call and evaluate. 262 # For each test data pair, simulate a call and evaluate.
252 for config_name in test_data_generators.config_names: 263 for config_name in test_data_generators.config_names:
253 logging.info(' - test data generator config: <%s>', config_name) 264 logging.info(' - test data generator config: <%s>', config_name)
265 apm_input_metadata['test_data_gen_config'] = config_name
254 266
255 # Paths to the test data generator output. 267 # Paths to the test data generator output.
256 # Note that the reference signal does not depend on the render input 268 # Note that the reference signal does not depend on the render input
257 # which is optional. 269 # which is optional.
258 noisy_capture_input_filepath = ( 270 noisy_capture_input_filepath = (
259 test_data_generators.noisy_signal_filepaths[config_name]) 271 test_data_generators.noisy_signal_filepaths[config_name])
260 reference_signal_filepath = ( 272 reference_signal_filepath = (
261 test_data_generators.reference_signal_filepaths[config_name]) 273 test_data_generators.reference_signal_filepaths[config_name])
262 274
263 # Output path for the evaluation (e.g., APM output file). 275 # Output path for the evaluation (e.g., APM output file).
264 evaluation_output_path = test_data_generators.apm_output_paths[ 276 evaluation_output_path = test_data_generators.apm_output_paths[
265 config_name] 277 config_name]
266 278
267 # Paths to the APM input signals. 279 # Paths to the APM input signals.
268 echo_path_filepath = echo_path_simulator.Simulate( 280 echo_path_filepath = echo_path_simulator.Simulate(
269 echo_test_data_cache_path) 281 echo_test_data_cache_path)
270 apm_input_filepath = input_mixer.ApmInputMixer.Mix( 282 apm_input_filepath = input_mixer.ApmInputMixer.Mix(
271 echo_test_data_cache_path, noisy_capture_input_filepath, 283 echo_test_data_cache_path, noisy_capture_input_filepath,
272 echo_path_filepath) 284 echo_path_filepath)
273 285
274 # Simulate a call using APM. 286 # Simulate a call using APM.
275 self._audioproc_wrapper.Run( 287 self._audioproc_wrapper.Run(
276 config_filepath=config_filepath, 288 config_filepath=config_filepath,
277 capture_input_filepath=apm_input_filepath, 289 capture_input_filepath=apm_input_filepath,
278 render_input_filepath=render_input_filepath, 290 render_input_filepath=render_input_filepath,
279 output_path=evaluation_output_path) 291 output_path=evaluation_output_path)
280 292
281 # Evaluate. 293 try:
282 self._evaluator.Run( 294 # Evaluate.
283 evaluation_score_workers=self._evaluation_score_workers, 295 self._evaluator.Run(
284 apm_output_filepath=self._audioproc_wrapper.output_filepath, 296 evaluation_score_workers=self._evaluation_score_workers,
285 reference_input_filepath=reference_signal_filepath, 297 apm_input_metadata=apm_input_metadata,
286 output_path=evaluation_output_path) 298 apm_output_filepath=self._audioproc_wrapper.output_filepath,
299 reference_input_filepath=reference_signal_filepath,
300 output_path=evaluation_output_path)
287 301
288 # Save simulation metadata. 302 # Save simulation metadata.
289 data_access.Metadata.SaveAudioTestDataPaths( 303 data_access.Metadata.SaveAudioTestDataPaths(
290 output_path=evaluation_output_path, 304 output_path=evaluation_output_path,
291 clean_capture_input_filepath=clean_capture_input_filepath, 305 clean_capture_input_filepath=clean_capture_input_filepath,
292 echo_free_capture_filepath=noisy_capture_input_filepath, 306 echo_free_capture_filepath=noisy_capture_input_filepath,
293 echo_filepath=echo_path_filepath, 307 echo_filepath=echo_path_filepath,
294 render_filepath=render_input_filepath, 308 render_filepath=render_input_filepath,
295 capture_filepath=apm_input_filepath, 309 capture_filepath=apm_input_filepath,
296 apm_output_filepath=self._audioproc_wrapper.output_filepath, 310 apm_output_filepath=self._audioproc_wrapper.output_filepath,
297 apm_reference_filepath=reference_signal_filepath) 311 apm_reference_filepath=reference_signal_filepath)
312 except exceptions.EvaluationScoreException as e:
313 logging.warning('the evaluation failed: %s', e.message)
314 continue
298 315
299 def _SetTestInputSignalFilePaths(self, capture_input_filepaths, 316 def _SetTestInputSignalFilePaths(self, capture_input_filepaths,
300 render_input_filepaths): 317 render_input_filepaths):
301 """Sets input and render input file paths collections. 318 """Sets input and render input file paths collections.
302 319
303 Pairs the input and render input files by storing the file paths into two 320 Pairs the input and render input files by storing the file paths into two
304 collections. The key is the file name of the input file. 321 collections. The key is the file name of the input file.
305 322
306 Args: 323 Args:
307 capture_input_filepaths: list of file paths. 324 capture_input_filepaths: list of file paths.
(...skipping 26 matching lines...) Expand all
334 """ 351 """
335 filepaths_collection = {} 352 filepaths_collection = {}
336 for filepath in filepaths: 353 for filepath in filepaths:
337 name = cls._ExtractFileName(filepath) 354 name = cls._ExtractFileName(filepath)
338 filepaths_collection[name] = os.path.abspath(filepath) 355 filepaths_collection[name] = os.path.abspath(filepath)
339 return filepaths_collection 356 return filepaths_collection
340 357
341 @classmethod 358 @classmethod
342 def _ExtractFileName(cls, filepath): 359 def _ExtractFileName(cls, filepath):
343 return os.path.splitext(os.path.split(filepath)[-1])[0] 360 return os.path.splitext(os.path.split(filepath)[-1])[0]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698