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"""Echo path simulation factory module.
10"""
11
12import numpy as np
13
14from . import echo_path_simulation
15
16
17class EchoPathSimulatorFactory(object):
18
19  # TODO(alessiob): Replace 5 ms delay (at 48 kHz sample rate) with a more
20  # realistic impulse response.
21  _LINEAR_ECHO_IMPULSE_RESPONSE = np.array([0.0]*(5 * 48) + [0.15])
22
23  def __init__(self):
24    pass
25
26  @classmethod
27  def GetInstance(cls, echo_path_simulator_class, render_input_filepath):
28    """Creates an EchoPathSimulator instance given a class object.
29
30    Args:
31      echo_path_simulator_class: EchoPathSimulator class object (not an
32                                 instance).
33      render_input_filepath: Path to the render audio track file.
34
35    Returns:
36      An EchoPathSimulator instance.
37    """
38    assert render_input_filepath is not None or (
39        echo_path_simulator_class == echo_path_simulation.NoEchoPathSimulator)
40
41    if echo_path_simulator_class == echo_path_simulation.NoEchoPathSimulator:
42      return echo_path_simulation.NoEchoPathSimulator()
43    elif echo_path_simulator_class == (
44        echo_path_simulation.LinearEchoPathSimulator):
45      return echo_path_simulation.LinearEchoPathSimulator(
46          render_input_filepath, cls._LINEAR_ECHO_IMPULSE_RESPONSE)
47    else:
48      return echo_path_simulator_class(render_input_filepath)
49