Compute the room impulse response between every source and microphone.
(self)
| 2267 | self.simulator_state["rt_done"] = True |
| 2268 | |
| 2269 | def compute_rir(self): |
| 2270 | """ |
| 2271 | Compute the room impulse response between every source and microphone. |
| 2272 | """ |
| 2273 | |
| 2274 | if self.simulator_state["ism_needed"] and not self.simulator_state["ism_done"]: |
| 2275 | self.image_source_model() |
| 2276 | |
| 2277 | if self.simulator_state["rt_needed"] and not self.simulator_state["rt_done"]: |
| 2278 | self.ray_tracing() |
| 2279 | |
| 2280 | # If the RIR highpass filter is enabled, compute the coefficients. |
| 2281 | rir_hpf_sos = None |
| 2282 | if constants.get("rir_hpf_enable"): |
| 2283 | rir_hpf_sos = design_highpass_filter_sos( |
| 2284 | self.fs, constants.get("rir_hpf_fc"), **constants.get("rir_hpf_kwargs") |
| 2285 | ) |
| 2286 | |
| 2287 | self.rir = [] |
| 2288 | |
| 2289 | volume_room = self.get_volume() |
| 2290 | |
| 2291 | # Loop over ever microphone present in the room and then for each |
| 2292 | # microphone and source pair present in the room |
| 2293 | for m, mic in enumerate(self.mic_array.R.T): |
| 2294 | self.rir.append([]) |
| 2295 | for s, src in enumerate(self.sources): |
| 2296 | """ |
| 2297 | Compute the room impulse response between the source |
| 2298 | and the microphone whose position is given as an |
| 2299 | argument. |
| 2300 | """ |
| 2301 | # fractional delay length |
| 2302 | fdl = constants.get("frac_delay_length") |
| 2303 | |
| 2304 | rir_parts = [] |
| 2305 | |
| 2306 | if self.simulator_state["ism_needed"]: |
| 2307 | ir_ism = compute_ism_rir( |
| 2308 | src, |
| 2309 | mic, |
| 2310 | self.mic_array.directivity[m], |
| 2311 | src.directions[m, :, :], |
| 2312 | self.visibility[s][m, :], |
| 2313 | fdl, |
| 2314 | self.c, |
| 2315 | self.fs, |
| 2316 | self.octave_bands, |
| 2317 | min_phase=self.min_phase, |
| 2318 | air_abs_coeffs=self.air_absorption, |
| 2319 | ) |
| 2320 | rir_parts.append(ir_ism) |
| 2321 | |
| 2322 | if self.simulator_state["rt_needed"]: |
| 2323 | t0 = np.linalg.norm(src.position - mic) / self.c |
| 2324 | ir_rt = compute_rt_rir( |
| 2325 | t0.item(), |
| 2326 | self.rt_histograms[m][s], |