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