DavidDiazGuerra / gpuRIR

Python library for Room Impulse Response (RIR) simulation with GPU acceleration
GNU Affero General Public License v3.0
488 stars 94 forks source link

all-zero values exist in generated RIRs #45

Closed BingYang-20 closed 1 year ago

BingYang-20 commented 1 year ago

Hello! I'm trying to simulate RIRs with gpuRIR toolbox. But there are some generated RIR examples that are with all-zero values. Could you please give me some suggestions about how to deal with this case?

One example is as follows:

import numpy as np 
import gpuRIR

fs = 16000
T60 = 0.32
room_sz = np.array([14.97, 29.60,  5.74])
traj_pts = np.array([[14.65, 28.10,  3.54]])
mic_pos = np.array([[3.71, 7.30, 1.58], [3.81, 7.21, 1.58]])
abs_weights = [0.57, 0.24,  0.66, 0.48, 0.43, 0.58]
beta = gpuRIR.beta_SabineEstimation(room_sz, T60, abs_weights)
mic_orV = np.array([[-1.,  0.,  0.], [ 1.,  0.,  0.]])
mic_pattern = 'omni'
Tdiff = gpuRIR.att2t_SabineEstimator(12, T60) 
Tmax = gpuRIR.att2t_SabineEstimator(60, T60)  
nb_img = gpuRIR.t2n( Tdiff, room_sz )
RIRs = gpuRIR.simulateRIR(room_sz, beta, traj_pts, mic_pos,
    nb_img, Tmax, fs, Tdiff=Tdiff, orV_rcv=mic_orV, mic_pattern=mic_pattern)
DavidDiazGuerra commented 1 year ago

Hi BingYang,

That's probably because you're simulating a huge room with a too short reverberation time. In those scenarios, the diffuse reverberation model that gpuRIR uses to speed up the simulations and the Sabine equation used to calculate Tdiff and Tmax don't work really well. Actually, in your example, the sources are about 23 meters away from the microphones which means that the direct path will take about 67 ms to reach the microphones, but you're using Tdiff = 0.64 ms, so you're losing it.

For that kind of room, I would always compute the whole RIRs using the ISM without any kind of diffuse reverberation model (Tdiff=Tmax) and I would probably try to find a better way to estimate Tmax and even beta. In your example, if you use Tdiff=Tmax you should get the proper RIR that a room with that size and reflection coefficients (beta) would have, but it probably won't really match your desired T60.

Best regards, David

BingYang-20 commented 1 year ago

Thanks for your patient reply! I understand the cause of the issue now. Would increasing the values of both Tdiff and Tmax ( Tdiff is smaller Tmax to guarantee both directional early reflections and diffused late reverberation) be helpful to get a proper RIR with the required room size, reflection coefficients and T60 in this example?

DavidDiazGuerra commented 1 year ago

I would keep Tdiff equal to Tmax so the whole RIR is computed with the image source method (ISM). The ISM can simulate both the early reflections and the late reverberation. The diffuse model used when Tdiff < Tmax is an approximation that can speed up the simulations, but it's only valid when the late reverberation can be modeled as a random noise with exponential decay, and that's not the case for such big rooms except when they have really high values of T60.

The ISM will simulate a proper RIR for the room size and reflection coefficients that you choose. The problem is how to choose the correct reflection coefficients (beta) so the RIR has the desired T60. The function gpuRIR.beta_SabineEstimation performs a simple estimation using the Sabine equation that works okay for RIRs with a nice exponential decay, but your room is not like that so probably the estimate won't be really good. I'm afraid I don't know any method that could help you to estimate the reflection coefficients in that kind of room. Actually, I'm not even sure how to measure the T60 in that room, since the RIR is so sparse that measuring the energy decay can be a bit tricky.

BingYang-20 commented 1 year ago

Do you have any suggestions on how to set room size and T60 under the condition gpuRIR works well (namely generated RIRs are with a nice exponential decay and gpuRIR.beta_SabineEstimation can give a good estimation of beta). For example, what is the recommended room size, and what is the recommended T60 setting for relatively larger room size (like larger than [10m, 8m, 6m]) and relatively smaller room size (like smaller than [10m, 8m, 6m])?

DavidDiazGuerra commented 1 year ago

I'm afraid I don't have much experience working with that kind of rooms. The main issue with big room sizes is that the reflections from the walls take too long to reach the microphones so the RIRs are quite sparse (actually, being physically in the room it would probably sound more like echos rather than like a reverberation) while the nice exponential decay usually happens when a lot of reflections are arriving at almost the same time, so the RIR looks like some kind of continuous noise. After some time, the RIR should become less and less sparse since the number of reflections arriving at the microphone increase with time, but if the walls are not very reflective their reflections might be completely attenuated before that happens.

BingYang-20 commented 1 year ago

I got it. Thank you very much!