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"""TestDataGenerator factory class.
10"""
11
12import logging
13
14from . import exceptions
15from . import test_data_generation
16
17
18class TestDataGeneratorFactory(object):
19  """Factory class used to create test data generators.
20
21  Usage: Create a factory passing parameters to the ctor with which the
22  generators will be produced.
23  """
24
25  def __init__(self, aechen_ir_database_path, noise_tracks_path,
26               copy_with_identity):
27    """Ctor.
28
29    Args:
30      aechen_ir_database_path: Path to the Aechen Impulse Response database.
31      noise_tracks_path: Path to the noise tracks to add.
32      copy_with_identity: Flag indicating whether the identity generator has to
33                          make copies of the clean speech input files.
34    """
35    self._output_directory_prefix = None
36    self._aechen_ir_database_path = aechen_ir_database_path
37    self._noise_tracks_path = noise_tracks_path
38    self._copy_with_identity = copy_with_identity
39
40  def SetOutputDirectoryPrefix(self, prefix):
41    self._output_directory_prefix = prefix
42
43  def GetInstance(self, test_data_generators_class):
44    """Creates an TestDataGenerator instance given a class object.
45
46    Args:
47      test_data_generators_class: TestDataGenerator class object (not an
48                                  instance).
49
50    Returns:
51      TestDataGenerator instance.
52    """
53    if self._output_directory_prefix is None:
54      raise exceptions.InitializationException(
55          'The output directory prefix for test data generators is not set')
56    logging.debug('factory producing %s', test_data_generators_class)
57
58    if test_data_generators_class == (
59        test_data_generation.IdentityTestDataGenerator):
60      return test_data_generation.IdentityTestDataGenerator(
61          self._output_directory_prefix, self._copy_with_identity)
62    elif test_data_generators_class == (
63        test_data_generation.ReverberationTestDataGenerator):
64      return test_data_generation.ReverberationTestDataGenerator(
65          self._output_directory_prefix, self._aechen_ir_database_path)
66    elif test_data_generators_class == (
67        test_data_generation.AdditiveNoiseTestDataGenerator):
68      return test_data_generation.AdditiveNoiseTestDataGenerator(
69          self._output_directory_prefix, self._noise_tracks_path)
70    else:
71      return test_data_generators_class(self._output_directory_prefix)
72