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

Side by Side Diff: modules/audio_processing/test/py_quality_assessment/quality_assessment/simulation_unittest.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 """Unit tests for the simulation module. 9 """Unit tests for the simulation module.
10 """ 10 """
11 11
12 import logging
12 import os 13 import os
13 import shutil 14 import shutil
14 import sys 15 import sys
15 import tempfile 16 import tempfile
16 import unittest 17 import unittest
17 18
18 SRC = os.path.abspath(os.path.join( 19 SRC = os.path.abspath(os.path.join(
19 os.path.dirname((__file__)), os.pardir, os.pardir, os.pardir, os.pardir)) 20 os.path.dirname((__file__)), os.pardir, os.pardir, os.pardir, os.pardir))
20 sys.path.append(os.path.join(SRC, 'third_party', 'pymock')) 21 sys.path.append(os.path.join(SRC, 'third_party', 'pymock'))
21 22
22 import mock 23 import mock
23 import pydub 24 import pydub
24 25
25 from . import audioproc_wrapper 26 from . import audioproc_wrapper
26 from . import evaluation 27 from . import evaluation
27 from . import signal_processing 28 from . import signal_processing
28 from . import simulation 29 from . import simulation
29 30
30 31
31 class TestApmModuleSimulator(unittest.TestCase): 32 class TestApmModuleSimulator(unittest.TestCase):
32 """Unit tests for the ApmModuleSimulator class. 33 """Unit tests for the ApmModuleSimulator class.
33 """ 34 """
34 35
35 def setUp(self): 36 def setUp(self):
36 """Create temporary folder and fake audio track.""" 37 """Create temporary folders and fake audio track."""
37 self._output_path = tempfile.mkdtemp() 38 self._output_path = tempfile.mkdtemp()
39 self._tmp_path = tempfile.mkdtemp()
38 40
39 silence = pydub.AudioSegment.silent(duration=1000, frame_rate=48000) 41 silence = pydub.AudioSegment.silent(duration=1000, frame_rate=48000)
40 fake_signal = signal_processing.SignalProcessingUtils.GenerateWhiteNoise( 42 fake_signal = signal_processing.SignalProcessingUtils.GenerateWhiteNoise(
41 silence) 43 silence)
42 self._fake_audio_track_path = os.path.join(self._output_path, 'fake.wav') 44 self._fake_audio_track_path = os.path.join(self._output_path, 'fake.wav')
43 signal_processing.SignalProcessingUtils.SaveWav( 45 signal_processing.SignalProcessingUtils.SaveWav(
44 self._fake_audio_track_path, fake_signal) 46 self._fake_audio_track_path, fake_signal)
45 47
46 def tearDown(self): 48 def tearDown(self):
47 """Recursively delete temporary folders.""" 49 """Recursively delete temporary folders."""
48 shutil.rmtree(self._output_path) 50 shutil.rmtree(self._output_path)
51 shutil.rmtree(self._tmp_path)
49 52
50 def testSimulation(self): 53 def testSimulation(self):
51 # Instance dependencies to inject and mock. 54 # Instance dependencies to inject and mock.
52 ap_wrapper = audioproc_wrapper.AudioProcWrapper() 55 ap_wrapper = audioproc_wrapper.AudioProcWrapper()
53 evaluator = evaluation.ApmModuleEvaluator() 56 evaluator = evaluation.ApmModuleEvaluator()
54 ap_wrapper.Run = mock.MagicMock(name='Run') 57 ap_wrapper.Run = mock.MagicMock(name='Run')
55 evaluator.Run = mock.MagicMock(name='Run') 58 evaluator.Run = mock.MagicMock(name='Run')
56 59
57 # Instance simulator. 60 # Instance simulator.
58 simulator = simulation.ApmModuleSimulator( 61 simulator = simulation.ApmModuleSimulator(
(...skipping 21 matching lines...) Expand all
80 # TODO(alessiob): Once the TestDataGenerator classes can be configured by 83 # TODO(alessiob): Once the TestDataGenerator classes can be configured by
81 # the client code (e.g., number of SNR pairs for the white noise teste data 84 # the client code (e.g., number of SNR pairs for the white noise teste data
82 # gnerator), the exact number of calls to ap_wrapper.Run and evaluator.Run 85 # gnerator), the exact number of calls to ap_wrapper.Run and evaluator.Run
83 # is known; use that with assertEqual. 86 # is known; use that with assertEqual.
84 min_number_of_simulations = len(config_files) * len(input_files) * len( 87 min_number_of_simulations = len(config_files) * len(input_files) * len(
85 test_data_generators) 88 test_data_generators)
86 self.assertGreaterEqual(len(ap_wrapper.Run.call_args_list), 89 self.assertGreaterEqual(len(ap_wrapper.Run.call_args_list),
87 min_number_of_simulations) 90 min_number_of_simulations)
88 self.assertGreaterEqual(len(evaluator.Run.call_args_list), 91 self.assertGreaterEqual(len(evaluator.Run.call_args_list),
89 min_number_of_simulations) 92 min_number_of_simulations)
93
94 def testPureToneGenerationWithTotalHarmonicDistorsion(self):
95 logging.warning = mock.MagicMock(name='warning')
96
97 # Instance simulator.
98 simulator = simulation.ApmModuleSimulator(
99 aechen_ir_database_path='',
100 polqa_tool_bin_path=os.path.join(
101 os.path.dirname(__file__), 'fake_polqa'),
102 ap_wrapper=audioproc_wrapper.AudioProcWrapper(),
103 evaluator=evaluation.ApmModuleEvaluator())
104
105 # What to simulate.
106 config_files = ['apm_configs/default.json']
107 input_files = [os.path.join(self._tmp_path, 'pure_tone-440_1000.wav')]
108 eval_scores = ['thd']
109
110 # Should work.
111 simulator.Run(
112 config_filepaths=config_files,
113 capture_input_filepaths=input_files,
114 test_data_generator_names=['identity'],
115 eval_score_names=eval_scores,
116 output_dir=self._output_path)
117 self.assertFalse(logging.warning.called)
118
119 # Warning expected.
120 simulator.Run(
121 config_filepaths=config_files,
122 capture_input_filepaths=input_files,
123 test_data_generator_names=['white_noise'], # Not allowed with THD.
124 eval_score_names=eval_scores,
125 output_dir=self._output_path)
126 logging.warning.assert_called_with('the evaluation failed: %s', (
127 'The THD score cannot be used with any test data generator other than '
128 '"identity"'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698