LCAV / pyroomacoustics

Pyroomacoustics is a package for audio signal processing for indoor applications. It was developed as a fast prototyping platform for beamforming algorithms in indoor scenarios.

Home Page:https://pyroomacoustics.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues with room simulation when adding multiple sources to a single room object

alexandergwm opened this issue · comments

commented

Hello,

I am working on a project where I need to simulate one room by adding sources to a single ShoeBox room object and clearing the sources after each iteration. That is, I want to keep the characteristics of the room the same but just change the position and content of the source. However, I am encountering errors during the simulation process, specifically when calling the compute_rir() function.

Here's the code snippet for my current implementation:

`room = pra.ShoeBox(room_dim, fs=16000, materials=pra.Material(e_absorption), max_order=max_order)
room.add_microphone_array(mic_locs)

for i in range(4620):
# Add source to the room
room.add_source(sources_pos[i, :], signal=data_train[i, :].numpy(), delay=0.2)

# Compute RIR and simulate
room.simulate()

# Save the simulation result
room.mic_array.to_wav('/root/autodl-tmp/base_env/audio_signal_processing/audio_data/TIMIT/Simulated_train_data/room_rir{}.wav'.format(i), norm=True, bitdepth=np.float32)

# Measure RT60
rt60 = room.measure_rt60()
print('The desired RT60 was {}'.format(rt60_tgt))
print('The measured RT60 is {}'.format(rt60[1, 0]))
print('The {}th room is simulated'.format(i))

# Remove the source before the next iteration
room.sources.clear()`

I just received the error without any description and it just referer there is something wrong in 'compute_rir()'
Thanks for your help.

Hi @alexandergwm , the simulator has some internal state that needs to be manually reset after changing the sources.
The easiest is to just re-create the object. I don't think this has a lot of overhead.
If you insist on reusing the same object, you can reset the state as follows:

room.simulator_state["ism_done"] = False
room.simulator_state["rt_done"] = False  # only needed if you use ray tracing