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.
https://pyroomacoustics.readthedocs.io
MIT License
1.33k stars 417 forks source link

`IndexError` on `room.visibility` when sources and microphones are not in sight #313

Open gdelazzari opened 1 year ago

gdelazzari commented 1 year ago

I'm trying to simulate the following room:

pyroomaudio_room

where there is a sound source at the top and a microphone array at the bottom.

However, room.simulate() fails:

Traceback (most recent call last):
  File "/home/giacomo/Projects/Tesi magistrale/Python/SoundSearch/room_audio_test.py", line 49, in <module>
    room.simulate()
  File "/home/giacomo/.local/lib/python3.10/site-packages/pyroomacoustics/room.py", line 2418, in simulate
    self.compute_rir()
  File "/home/giacomo/.local/lib/python3.10/site-packages/pyroomacoustics/room.py", line 2290, in compute_rir
    vis = self.visibility[s][m, :].astype(np.int32)
IndexError: list index out of range

It seems there is an issue with the room.visibility array in this case where the source and the microphones are not visible.

If I instead place the source and the microphones such that they are in direct sight, everything works.

Am I doing something wrong?

Thanks!

fakufaku commented 1 year ago

Hello, could you please include the code that builds the room ?

gdelazzari commented 1 year ago

Sure, sorry for not providing it before. The setup is as follows:

# Room
sigma2 = 5e-4
fs = 16000

corners = np.array([
    [ 0,  0],
    [10,  0],
    [10, 16],
    [ 0, 16],
    [ 0, 10],
    [ 8, 10],
    [ 8,  6],
    [ 0,  6],
]).T
room = pra.Room.from_corners(corners, fs=fs, max_order=1, sigma2_awgn=sigma2)

# Microphones
def mic_array_at(pos: np.ndarray) -> pra.MicrophoneArray:
    mic_locations = pra.circular_2D_array(center=pos, M=6, phi0=0, radius=37.5e-3)
    mic_locations = np.concatenate((mic_locations, np.array(pos, ndmin=2).T), axis=1)
    return pra.MicrophoneArray(mic_locations, room.fs)

mic = mic_array_at(np.array([3, 3]))
room.add_microphone_array(mic)

# Sources
rng = np.random.RandomState(23)
duration_samples = int(fs)
source_location = np.array([3, 13])
source_signal = rng.randn(duration_samples)
room.add_source(source_location, signal=source_signal)

I thought that max_order would play some important role in this case, but changing it had no effect on the issue I'm facing (I can instead see that, when the sources and microphones are in direct sight, the room.visibility matrix shape changes as a function of max_order).

Borknab commented 8 months ago

@gdelazzari Hi! I am facing a similar issue now. Did you find a way to fix it? Or an explanation on why is it failing? Thanks a lot in advance!