Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pyrato/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,42 @@ def air_attenuation_coefficient(

return air_abs_coeff


def critical_distance(
Comment thread
mberz marked this conversation as resolved.
volume,
reverberation_time):
r"""Calculate the critical distance of a room with
given volume and reverberation time.
Assumes the source directivity is 1 (omnidirectional source).
Comment thread
mberz marked this conversation as resolved.
See [#kra]_.

.. math::
d_c = 0.057 \sqrt{\frac{V}{T_{60}}}

Comment thread
mberz marked this conversation as resolved.
Parameters
----------
volume : double
Volume of the room in cubic meters.
reverberation_time : double
Reverberation time of the room in seconds.

Returns
-------
critical_dist : double
The resulting critical distance in meters.

References
----------
.. [#kra] H. Kuttruff, Room acoustics, 4th Ed. Taylor & Francis, 2009.

"""
if reverberation_time <= 0:
raise ValueError("Reverberation time must be greater than zero.")
Comment thread
mberz marked this conversation as resolved.
if volume <= 0:
raise ValueError("Volume must be greater than zero.")
critical_dist = 0.057 * np.sqrt(volume / reverberation_time)
Comment thread
mberz marked this conversation as resolved.
return critical_dist


def mean_free_path(
volume,
Expand Down
22 changes: 21 additions & 1 deletion tests/test_parametric.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
"""Tests for parametric related things."""

import numpy.testing as npt
import pytest
import pyrato.parametric as parametric
from pyrato.parametric import mean_free_path
import pyrato as ra
import pytest


@pytest.mark.parametrize(("volume","reverberation_time","expected_critical_distance"),
[(100, 1, 0.57),(200, 2, 0.57),(50, 0.5, 0.57),(150, 3, 0.403050865)])
def test_critical_distance_calculate(volume, reverberation_time,
expected_critical_distance):
critical_distance = parametric.critical_distance(
volume, reverberation_time)
npt.assert_allclose(critical_distance,
expected_critical_distance,
atol=1e-2)


@pytest.mark.parametrize(("volume","reverberation_time"),
[(100, 0),(0, 2),(0, 0),(-20, 3),(20, -1)])
def test_critical_distance_error(volume, reverberation_time):
with pytest.raises(ValueError, match='must be greater than zero.'):
parametric.critical_distance(volume, reverberation_time)


@pytest.mark.parametrize(
Expand Down