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

Unified Diff: webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/input_signal_creator.py

Issue 2989823002: Input signal creation for non-existing input signal files (Closed)
Patch Set: merge Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/input_signal_creator.py
diff --git a/webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/input_signal_creator.py b/webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/input_signal_creator.py
new file mode 100644
index 0000000000000000000000000000000000000000..e2a720c796f58d21c4ec0fcb217390cbbdeac64a
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/py_quality_assessment/quality_assessment/input_signal_creator.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+"""Input signal creator module.
+"""
+
+from . import exceptions
+from . import signal_processing
+
+
+class InputSignalCreator(object):
+ """Input signal creator class.
+ """
+
+ @classmethod
+ def Create(cls, name, params):
+ """Creates a input signal.
+
+ Args:
+ name: Input signal creator name.
+ params: Tuple of parameters to pass to the specific signal creator.
+
+ Returns:
+ AudioSegment instance.
+ """
+ try:
+ if name == 'pure_tone':
+ return cls._CreatePureTone(float(params[0]), int(params[1]))
+ except (TypeError, AssertionError) as e:
+ raise exceptions.InputSignalCreatorException(
+ 'Invalid signal creator parameters: {}'.format(e))
+
+ raise exceptions.InputSignalCreatorException(
+ 'Invalid input signal creator name')
+
+ @classmethod
+ def _CreatePureTone(cls, frequency, duration):
+ """
+ Generates a pure tone at 48000 Hz.
+
+ Args:
+ frequency: Float in (0-24000] (Hz).
+ duration: Integer (milliseconds).
+
+ Returns:
+ AudioSegment instance.
+ """
+ assert 0 < frequency <= 24000
+ assert 0 < duration
+ template = signal_processing.SignalProcessingUtils.GenerateSilence(duration)
+ return signal_processing.SignalProcessingUtils.GeneratePureTone(
+ template, frequency)

Powered by Google App Engine
This is Rietveld 408576698