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

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

Issue 2715943002: APM Quality Assessment, simulation controller and libraries (Closed)
Patch Set: Initial unit test files. Created 3 years, 9 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
(Empty)
1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
2 #
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
5 # tree. An additional intellectual property rights grant can be found
6 # in the file PATENTS. All contributing project authors may
7 # be found in the AUTHORS file in the root of the source tree.
8
9 import logging
10 import os
11
12 from . import data_access
13 from . import eval_scores
14 from . import noise_generation
15
16 class ApmModuleSimulator(object):
17
18 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES
19 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES
20
21 def __init__(self):
22 # TODO(alessio): instance when implementation is ready.
aleloi2 2017/03/02 01:14:03 Sorry, I don't understand this comment. Does it me
AleBzk 2017/03/02 09:58:38 Acknowledged.
AleBzk 2017/03/02 09:58:38 Sorry for not being clear here. This CL still miss
23 self._audioproc_wrapper = None
24 self._evaluator = None
25
26 self._base_output_path = None
27 self._noise_generators = None
28 self._evaluation_score_workers = None
29 self._config_filepaths = None
30 self._input_filepaths = None
31
32 def run(self, config_filepaths, input_filepaths, noise_generator_names,
33 eval_score_names, output_dir):
34 """
35 Initializes paths and required instances before running all the simulations.
aleloi2 2017/03/02 01:14:03 Perhaps add 'Then runs the simulations.'
AleBzk 2017/03/02 09:58:38 Done.
36 """
37 self._base_output_path = os.path.abspath(output_dir)
38
39 # Instance noise generators.
40 self._noise_generators = [
41 self._NOISE_GENERATOR_CLASSES[name]() for name in noise_generator_names]
aleloi2 2017/03/02 01:14:03 A key error happens if a user passes a wrong name,
AleBzk 2017/03/02 09:58:38 Yes and no :) The client code should handle the e
AleBzk 2017/03/02 09:58:38 Acknowledged.
42
43 # Instance evaluation score workers.
44 self._evaluation_score_workers = [
45 self._EVAL_SCORE_WORKER_CLASSES[name]() for name in eval_score_names]
46
47 # Set APM configuration file paths.
48 self._config_filepaths = self._get_paths_collection(config_filepaths)
49
50 # Set probing signal file paths.
51 self._input_filepaths = self._get_paths_collection(input_filepaths)
52
53 self._simulate_all()
54
55 def _simulate_all(self):
56 """
57 Iterates over the combinations of APM configurations, probing signals, and
58 noise generators.
59 """
60 # Try different APM config files.
61 for config_name in self._config_filepaths:
62 config_filepath = self._config_filepaths[config_name]
63
64 # Try different probing signal files.
65 for input_name in self._input_filepaths:
66 input_filepath = self._input_filepaths[input_name]
67
68 # Try different noise generators.
69 for noise_generator in self._noise_generators:
70 logging.info('config: <%s>, input: <%s>, noise: <%s>',
71 config_name, input_name, noise_generator.NAME)
72
aleloi2 2017/03/02 01:14:03 I think we can consider using itertools.product he
AleBzk 2017/03/02 09:58:38 True. I usually go for that option, I hate 45 degr
AleBzk 2017/03/02 09:58:38 Acknowledged.
73 # Output path for the input-noise pairs. It is used to cache the noisy
74 # copies of the probing signals (shared across some simulations).
75 input_noise_cache_path = os.path.join(
76 self._base_output_path,
77 '_cache',
78 'input_{}-noise_{}'.format(input_name, noise_generator.NAME))
79 data_access.make_directory(input_noise_cache_path)
80 logging.debug('input-noise cache path: <%s>', input_noise_cache_path)
81
82 # Full output path.
83 output_path = os.path.join(
84 self._base_output_path,
85 'cfg-{}'.format(config_name),
86 'input-{}'.format(input_name),
87 'noise-{}'.format(noise_generator.NAME))
88 data_access.make_directory(output_path)
89 logging.debug('output path: <%s>', output_path)
90
91 self._simulate(noise_generator, input_filepath,
92 input_noise_cache_path, output_path, config_filepath)
93
94 def _simulate(self, noise_generator, input_filepath, input_noise_cache_path,
95 output_path, config_filepath):
96 """
97 Simulates a given combination of APM configurations, probing signals, and
98 noise generators. It iterates over the noise generator internal
99 configurations.
100 """
101 # TODO(alessio): implement.
102 pass
103
104 @classmethod
105 def _get_paths_collection(cls, filepaths):
106 """
107 Given a list of file paths, makes a collection with one pair for each item
108 in the list where the key is the file name without extension and the value
109 is the path.
110 """
111 filepaths_collection = {}
112 for filepath in filepaths:
113 name = os.path.splitext(os.path.split(filepath)[1])[0]
114 filepaths_collection[name] = os.path.abspath(filepath)
115 return filepaths_collection
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698