att_diff = 13.0 # Attenuation when start using the diffuse reverberation model [dB] att_max = 50.0 # Attenuation at the end of the simulation [dB] fs = 16000.0 # Sampling frequency [Hz] pos_src = np.random.rand(nb_src, 3) * room_sz pos_rcv = np.random.rand(nb_rcv, 3) * room_sz time_max = 100 # Stop the measurements after find an average time greter than this time [s] times = np.zeros((len(T60_vec), 1)) for i in range(len(T60_vec)): T60 = T60_vec[i] start_time = time.time() for j in range(nb_test_per_point): beta = gpuRIR.beta_SabineEstimation(room_sz, T60) Tdiff = gpuRIR.att2t_SabineEstimator(att_diff, T60) Tmax = gpuRIR.att2t_SabineEstimator(att_max, T60) nb_img = gpuRIR.t2n(Tdiff, room_sz) RIRs = gpuRIR.simulateRIR(room_sz, beta, pos_src, pos_rcv, nb_img, Tmax, fs, Tdiff=Tdiff) times[i] = (time.time() - start_time) / nb_test_per_point if times[i] > time_max: break
traj_pts = 64 # Number of trajectory points pos_traj = np.tile(np.array([0.0, 3.0, 1.0]), (traj_pts, 1)) pos_traj[:, 0] = np.linspace(0.1, 2.9, traj_pts) # Positions of the trajectory points [m] nb_rcv = 2 # Number of receivers pos_rcv = np.array([[1.4, 1, 1.5], [1.6, 1, 1.5]]) # Position of the receivers [m] orV_rcv = np.array([[-1, 0, 0], [1, 0, 0]]) mic_pattern = "card" # Receiver polar pattern T60 = 0.6 # Time for the RIR to reach 60dB of attenuation [s] att_diff = 15.0 # Attenuation when start using the diffuse reverberation model [dB] att_max = 60.0 # Attenuation at the end of the simulation [dB] beta = gpuRIR.beta_SabineEstimation(room_sz, T60) # Reflection coefficients Tdiff = gpuRIR.att2t_SabineEstimator( att_diff, T60) # Time to start the diffuse reverberation model [s] Tmax = gpuRIR.att2t_SabineEstimator(att_max, T60) # Time to stop the simulation [s] nb_img = gpuRIR.t2n(Tdiff, room_sz) # Number of image sources in each dimension RIRs = gpuRIR.simulateRIR(room_sz, beta, pos_traj, pos_rcv, nb_img, Tmax, fs, Tdiff=Tdiff, orV_rcv=orV_rcv, mic_pattern=mic_pattern) filtered_signal = gpuRIR.simulateTrajectory(source_signal, RIRs)
def simulate(self): """ Get the array recording using gpuRIR to perform the acoustic simulations. """ if self.T60 == 0: Tdiff = 0.1 Tmax = 0.1 nb_img = [1, 1, 1] else: Tdiff = gpuRIR.att2t_SabineEstimator( 12, self.T60) # Use ISM until the RIRs decay 12dB Tmax = gpuRIR.att2t_SabineEstimator( 40, self.T60) # Use diffuse model until the RIRs decay 40dB if self.T60 < 0.15: Tdiff = Tmax # Avoid issues with too short RIRs nb_img = gpuRIR.t2n(Tdiff, self.room_sz) nb_mics = len(self.mic_pos) nb_traj_pts = len(self.traj_pts) nb_gpu_calls = min( int( np.ceil(self.fs * Tdiff * nb_mics * nb_traj_pts * np.prod(nb_img) / 1e9)), nb_traj_pts) traj_pts_batch = np.ceil(nb_traj_pts / nb_gpu_calls * np.arange(0, nb_gpu_calls + 1)).astype(int) RIRs_list = [ gpuRIR.simulateRIR( self.room_sz, self.beta, self.traj_pts[traj_pts_batch[0]:traj_pts_batch[1], :], self.mic_pos, nb_img, Tmax, self.fs, Tdiff=Tdiff, orV_rcv=self.array_setup.mic_orV, mic_pattern=self.array_setup.mic_pattern) ] for i in range(1, nb_gpu_calls): RIRs_list += [ gpuRIR.simulateRIR( self.room_sz, self.beta, self.traj_pts[traj_pts_batch[i]:traj_pts_batch[i + 1], :], self.mic_pos, nb_img, Tmax, self.fs, Tdiff=Tdiff, orV_rcv=self.array_setup.mic_orV, mic_pattern=self.array_setup.mic_pattern) ] RIRs = np.concatenate(RIRs_list, axis=0) mic_signals = gpuRIR.simulateTrajectory(self.source_signal, RIRs, timestamps=self.timestamps, fs=self.fs) mic_signals = mic_signals[0:len(self.t), :] # Omnidirectional noise dp_RIRs = gpuRIR.simulateRIR(self.room_sz, self.beta, self.traj_pts, self.mic_pos, [1, 1, 1], 0.1, self.fs, orV_rcv=self.array_setup.mic_orV, mic_pattern=self.array_setup.mic_pattern) dp_signals = gpuRIR.simulateTrajectory(self.source_signal, dp_RIRs, timestamps=self.timestamps, fs=self.fs) ac_pow = np.mean([ acoustic_power(dp_signals[:, i]) for i in range(dp_signals.shape[1]) ]) noise = np.sqrt( ac_pow / 10**(self.SNR / 10)) * np.random.standard_normal( mic_signals.shape) mic_signals += noise # Apply the propagation delay to the VAD information if it exists if hasattr(self, 'source_vad'): vad = gpuRIR.simulateTrajectory(self.source_vad, dp_RIRs, timestamps=self.timestamps, fs=self.fs) self.vad = vad[0:len(self.t), :].mean( axis=1) > vad[0:len(self.t), :].max() * 1e-3 return mic_signals