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.44k stars 429 forks source link

libroom.rir_builder error: "The rir array is too small for the maximum time recorded" #353

Closed mmjamm closed 2 months ago

mmjamm commented 4 months ago

Hi!

The new RIR builder in libroom C++ extension is great - my scripts run much faster! I did run into a regressions though. Sometimes I'm getting the following error: Traceback (most recent call last): File "/media/data/miheikki/git/ramen/pra_test.py", line 96, in <module> room.compute_rir() File "/home/miheikki/.local/share/virtualenvs/ramen-plSAbj_6/lib/python3.10/site-packages/pyroomacoustics/room.py", line 2327, in compute_rir libroom.rir_builder( RuntimeError: the rir array is too small for the maximum time recorded

I'm able to reproduce the bug with the following code:

import numpy as np
import pyroomacoustics as pra

room_dims = np.array([10., 10., 10.])
room = pra.ShoeBox(
        room_dims,
        fs=24000,
        materials=None,
        max_order=22,
        use_rand_ism=False
)

source = np.array([[6.35551912],[4.33308523], [3.69586303]])
room.add_source(source)

mic_array_in_room = np.array(
    [
        [1.5205189, 1.49366285, 1.73302404, 1.67847898],
        [4.68430529, 4.76250254, 4.67956424, 4.60702604],
        [2.68214263, 2.7980202,  2.55341851, 2.72701718]
    ]
)
room.add_microphone_array(mic_array_in_room)

room.compute_rir()

I'm running Python 3.10.14 My Python env:

Package         Version
--------------- -------
Cython          3.0.10
numpy           2.0.0
pip             24.0
pybind11        2.12.0
pyroomacoustics 0.7.4
scipy           1.13.1
setuptools      69.5.1
wheel           0.43.0

I'm not able to reproduce on 0.7.3 and I haven't seen the issue prior to 0.7.4.

Cheers!

fakufaku commented 4 months ago

Thanks for reporting this bug! I have found the cause to be due to rounding of the delays before computing the RIR. PR #354 fixes the bug.

fakufaku commented 4 months ago

Fixed in v0.7.5

stet-stet commented 3 months ago

Hi, I'd like to add that I encountered this on v0.7.5 today. It only occurred after simulating 10000s of files, where many of the room params and rt60 were set at random (were not logged either), so for the moment I have not been able to come up with a minimal reproduction. If I am able to reproduce this again I will report back.

fakufaku commented 3 months ago

@stet-stet thanks for letting me know. Happy to help debug this if you can find the room parameters that cause this.

stet-stet commented 3 months ago

@fakufaku I found one!

import numpy as np
from scipy.io import wavfile
import pyroomacoustics as pra

# The desired reverberation time and dimensions of the room
rt60_tgt = 0.451734045124395  # seconds
room_dim = [
            2.496315595944846,
            2.2147285947364708,
            3.749472153652182
        ]  # meters

sample_wav = "(anything should work)"
fs, audio = wavfile.read(sample_wav)

e_absorption, max_order = pra.inverse_sabine(rt60_tgt, room_dim)

room = pra.ShoeBox(
    room_dim, fs=fs, materials=pra.Material(e_absorption), max_order=max_order
)

room.add_source([
                0.24784311631630576,
                1.690743273038349,
                1.9570721698068267
            ], signal=audio, delay=0.) # this didn't need to be 0 either

mic_array = np.array([
            [
                0.46378325918698565,
            ],
            [
                1.5657207092343373,
            ],
            [
                3.015697444447528,
            ]
        ])

room.add_microphone_array(mic_array)

room.simulate()

Hope you could help debug. Thanks!

MordehayM commented 2 months ago

i have encountered the same problem after producing 8k examples (version 0.7.5)

fakufaku commented 2 months ago

@MordehayM , if you have the parameters of the room that fails handy, it would be great. I would add them as a test for the fix.

MordehayM commented 2 months ago

I am afraid I don't have them since all the parameters were randomly sampled.

MordehayM commented 2 months ago

Here, I have found:

Room dimensions: [4.57977238 5.39054892 2.82767573], RT60: 0.5824602516207891, Absorption coefficient: 0.18257819716723472, Speaker position: [1.22812426 1.2966769 1.43330033], Mic position: [1.8020194 0.76576269 0.53980759], Max order: 83

Room dimensions: [5.3997869 6.34821279 2.90299906], RT60: 0.5286659415624406, Absorption coefficient: 0.2217407971025793, Speaker position: [4.05889913 4.15230608 2.39073375], Mic position: [2.45186073 2.88844052 1.39751034], Max order: 70 54%|██████████████████████████████████▋ | 162448/300000 [15:32:34<10:44:56, 3.55it/s]Error occurred: the rir array is too small for the maximum time recorded. Retrying... Room dimensions: [5.45909408 6.34962532 2.77107005], RT60: 0.4186018470746126, Absorption coefficient: 0.27431416842419915, Speaker position: [0.54511116 2.82639397 1.04676184], Mic position: [4.15744634 2.82665472 1.01958203], Max order: 58 54%|██████████████████████████████████▊ | 163136/300000 [15:36:28<10:22:02, 3.67it/s]Error occurred: the rir array is too small for the maximum time recorded. Retrying... Room dimensions: [5.88430842 5.74587181 2.81243457], RT60: 0.48905353121657863, Absorption coefficient: 0.23546727398942446, Speaker position: [5.2673113 1.68109104 2.13159967], Mic position: [2.03474247 0.82147634 1.25415523], Max order: 66 55%|██████████████████████████████████▉ | 163795/300000 [15:40:39<12:58:03, 2.92it/s]Error occurred: the rir array is too small for the maximum time recorded. Retrying... Room dimensions: [5.8335965 4.90706049 2.5410871 ], RT60: 0.41479793499195206, Absorption coefficient: 0.25263067293986236, Speaker position: [0.58218881 3.25631355 0.91775666], Mic position: [1.06434647 3.3755251 1.84040589], Max order: 63 56%|███████████████████████████████████▉ | 168620/300000 [16:07:50<12:32:58, 2.91it/s]Error occurred: the rir array is too small for the maximum time recorded. Retrying... Room dimensions: [5.63150056 5.21368813 2.90971373], RT60: 0.4522765450131763, Absorption coefficient: 0.24979151070744487, Speaker position: [4.30157587 2.54104283 2.22109155], Mic position: [1.47065101 3.65191472 1.64230692], Max order: 61 57%|████████████████████████████████████▌ | 171638/300000 [16:26:30<15:47:14, 2.26it/s]Error occurred: the rir array is too small for the maximum time recorded. Retrying... Room dimensions: [6.24132556 4.62941236 2.52808349], RT60: 0.4397499577203515, Absorption coefficient: 0.23735500015498867, Speaker position: [3.75099353 3.82859854 1.66480812], Mic position: [0.63880713 1.93500295 1.12386568], Max order: 67

fakufaku commented 2 months ago

Thank you so much, this is very useful!

fakufaku commented 2 months ago

@MordehayM I have tested with the provided parameters, but I can't reproduce the error. What was the sampling frequency?

MordehayM commented 2 months ago

16kHz

fakufaku commented 2 months ago

@MordehayM Thanks!

The issue should be fixed by #360 in v0.7.6.

Please let me know if there are more issues.