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.47k stars 433 forks source link

[next_gen_simultator] error when multi-microphone array and this type of room #98

Closed Chutlhu closed 5 years ago

Chutlhu commented 5 years ago

Dear developer, I am running the following script:

import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt

from stl import mesh
from mpl_toolkits import mplot3d

path_to_musis_stl_file = './data/raw/MUSIS_3D_no_mics_simple.stl'
haru_fs = 16e3
haru_bar = [-6.5, 8.5, 2+0.1]
src_pos  = [-6, 4, 3]

def pyroom_walls_from_stl(path_to_stl_file):
    # with numpy-stl
    the_mesh = mesh.Mesh.from_file(path_to_stl_file)
    ntriang, nvec, npts = the_mesh.vectors.shape
    size_reduc_factor = 500.  # to get a realistic room size (not 3km)

    material = pra.Material.make_freq_flat(0.2)

    # create one wall per triangle
    walls = []
    for w in range(ntriang):
            walls.append(
                pra.wall_factory(
                    the_mesh.vectors[w].T / size_reduc_factor,
                    material.absorption["coeffs"],
                    material.scattering["coeffs"],
                )
            )

    return walls

def get_haru_mics(baricenter):
    haru_bar = np.array(baricenter)
    haru = pra.circular_2D_array(
        center=haru_bar[:2], M=8, phi0=-45/180*np.pi, radius=0.095)[:, :-1]
    haru = np.concatenate((haru, np.ones([1, 7])*haru_bar[2]), axis=0)
    haru = haru[:, ::-1]
    return haru

## Laod room into pyroomacoustic
walls = pyroom_walls_from_stl(path_to_musis_stl_file)
room = pra.Room(
    walls,
    fs=16000,
    max_order=3,
)

room.add_source(src_pos)
room.add_microphone_array(
    pra.MicrophoneArray(get_haru_mics(haru_bar), haru_fs)
)

# compute the rir
room.image_source_model()
# room.ray_tracing()
# room.compute_rir()
# room.plot_rir()

# show the room
room.plot(img_order=1)
plt.show()

to load and compute the RIR of the following model of a 3D non-convex room (there is no ceiling.): MUSIS_3D_no_mics_simple.stl.zip With the following (cool) results (room.plot(img_order=1)): requirements.txt

musis_pyroom_im

However, I am encountering the following problems:

  1. room.compute_rir() return an error of sound sources outside the room:

    ../pyroomacoustics/pyroomacoustics/room.py", line 1136, in compute_rir
    n_bins = np.nonzero(self.rt_histograms[m][s][0].sum(axis=0))[0][-1] + 1
    AttributeError: 'Room' object has no attribute 'rt_histograms'

    UPDATE This error happens when multiple microphone are used.

  2. the image source wrt to the floor is inside the room (it seems that the image method is running on the convex hall. Thus, if theri is a discontinuty, like the 'plinth' I am using, the floor is considered at the level of the plinth. EDIT this is actually right, my mistake. It is the right image source with respect to the plinth

fakufaku commented 5 years ago

I am planning to automate all this later, but for now it is important to call the three following methods one after the other to get the computation of RIR right:

room.image_source_model()
room.ray_tracing()
room.compute_rir()

Let me know if that solves the issue.

Chutlhu commented 5 years ago

Thank you, unfortunately it does not solve the issues when multiple-microphone array is used. You can try this also in one of the example you provide as room_from_stl.py. Just doing the following change:

    room.add_microphone_array(
        pra.MicrophoneArray(
            np.array([[-6.5, 8.5, 2+0.1], [-6.5, 8.1, 2+0.1]]).T, room.fs)
    )

I have this error:

Traceback (most recent call last):
  File "src/room_from_stl.py", line 59, in <module>
    room.compute_rir()
  File "/home/ddicarlo/Documents/Code/InProgress/2019@dataset_aegean/pyroomacoustics/pyroomacoustics/room.py", line 1136, in compute_rir
    n_bins = np.nonzero(self.rt_histograms[m][s][0].sum(axis=0))[0][-1] + 1
IndexError: index -1 is out of bounds for axis 0 with size 0

For now I can do a for-loop for every mic position of the mic array

fakufaku commented 5 years ago

Indeed. Thanks for pointing this out. I'm investigating the problem.

fakufaku commented 5 years ago

@Chutlhu I fixed the problem in 99a739514 . I also fixed the decay of the RIR which was not correctly set with respect to distance.