def get_speaker_h(self, speaker_x, speaker_y, speaker_z, receivers): room_measures = [self.width, self.length, self.height] source_position = [speaker_x, speaker_y, speaker_z] fs = 16000 n = 2048 h, _, _ = nprirgen.np_generateRir(room_measures, source_position, receivers, reverbTime=self.rt60, fs=fs, orientation=[self.array_theta, .0], nSamples=n) return h
h0 = pyrirgen.generateRir(L, s, r, soundVelocity=c, fs=fs, reverbTime=rt, nSamples=n) end = timer() t_pyrirgen = end - start # nprirgen start = timer() h1, _, refl_coeffs = nprirgen.np_generateRir(L, s, r, soundVelocity=c, fs=fs, reverbTime=rt, nSamples=n) end = timer() t_nprirgen = end - start # accuracy snr = 10 * np.log10(np.sum(np.abs(h0)**2) / np.sum(np.abs(h0 - h1)**2)) print( '[Trial #{:03}] pyrirgen: {:6.3f} sec \t nprirgen (rel): {:6.3f}\t snr={:6.3f} dB, L=[{:4.2f}, {:4.2f}, {:4.2f}], r=[{:4.2f}, {:4.2f}, {:4.2f}], s=[{:4.2f}, {:4.2f}, {:4.2f}], dis={:5.3f}, rt={:5.3f}, n={}, refl_coeffs=[{:4.2f}, {:4.2f}, {:4.2f}, {:4.2f}, {:4.2f}, {:4.2f}]' .format(i, t_pyrirgen, t_nprirgen / t_pyrirgen, snr, L[0], L[1], L[2], r[0], r[1], r[2], s[0], s[1], s[2], dist, rt, n, refl_coeffs[0], refl_coeffs[1], refl_coeffs[2], refl_coeffs[3], refl_coeffs[4], refl_coeffs[5]))
def room_gen(self, room_dims, RT60): mic_x = room_dims[0] // 2 + np.random.uniform(low=-0.15, high=0.15) mic_y = room_dims[1] // 2 + np.random.uniform(low=-0.15, high=0.15) mic_pos = [round(mic_x, 2), round(mic_y, 2), 1.5] # x,y,z in meters speakers_pos = np.zeros( (self.num_of_speakers, 3)) # (num_speakers,x,y) speakers_angles = np.zeros((self.num_of_speakers, )) angel_deg = np.linspace(0, 180, 36) # [0,30,60,90,120,150,180] for i in range(self.num_of_speakers): invalid = 0 while not invalid: angle_index = np.random.randint(low=0, high=len(angel_deg)) speakers_angles[i] = angel_deg[angle_index] angle = np.deg2rad(angel_deg[angle_index]) speaker_distance = 1.5 + \ round(np.random.uniform(low=-0.2, high=0.2), 2) x = mic_x + speaker_distance * np.cos(angle) y = mic_y + speaker_distance * np.sin(angle) speakers_pos[i, 0] = round(x, 2) speakers_pos[i, 1] = round(y, 2) speakers_pos[i, 2] = 1.5 if self.position_valid(room_dims, speakers_pos[i]): invalid = 1 else: logging.error('mic not in the room') invalid = 0 self.speakers_pos = speakers_pos self.speakers_angles = speakers_angles c = 340 # Sound velocity (m/s) r = [mic_pos] # Receiver position [x y z] (m) # Room dimensions [x y z] (m) L = [room_dims[0], room_dims[1], room_dims[2]] rt = RT60 # Reverberation time (s) n = 2048 # Number of samples mtype = 'omnidirectional' # Type of microphone order = -1 # Reflection order dim = 3 # Room dimension orientation = 0 # Microphone orientation (rad) hp_filter = True # Enable high-pass filter Systems = np.zeros((self.num_of_speakers, n)) Systems_anechoic = np.zeros((self.num_of_speakers, n)) for i in range(self.num_of_speakers): s = speakers_pos[i] h_temp, _, _ = nprirgen.np_generateRir(L, s, r, soundVelocity=c, fs=self.sr, reverbTime=rt, nSamples=n, micType=mtype, nOrder=order, nDim=dim, isHighPassFilter=hp_filter) h_temp_anechoic, _, _ = nprirgen.np_generateRir( L, s, r, soundVelocity=c, fs=self.sr, reverbTime=0, nSamples=n, micType=mtype, nOrder=order, nDim=dim, isHighPassFilter=hp_filter) Systems[i] = h_temp Systems_anechoic[i] = h_temp_anechoic return Systems, Systems_anechoic