compas_acoustics.simulation_methods
¶
Interchangeable ways to compute a scene's impulse responses (contract: base).
Binaural and Ambisonics need pyFDN (Python >= 3.11), so they are imported on first use.
Classes¶
SimulationMethod
¶
Bases: ABC
A way to compute impulse responses. See the module docstring for the output contract.
Methods:¶
compute
abstractmethod
¶
compute(context: SimulationContext) -> dict
One response per source-receiver pair, keyed '<receiver guid>_<source guid>'.
SimulationContext
dataclass
¶
SimulationContext(scene: object, geometry: object, sources: list, receivers: list, sampling_rate: int, outside: list = list())
What every method sees, built once per Scene.simulate.
Mono
¶
Mono(image_source_order: int = 3, ray_tracing: bool = True, air_absorption: bool = True, n_rays: Optional[int] = None, energy_thres: float = 1e-07, duration: Optional[float] = None, receiver_radius: float = 0.5, seed: Union[bool, int] = True, normalize: bool = True, air: Optional[AirConditions] = None)
Bases: SimulationMethod
Image sources up to image_source_order (pyroomacoustics: Scheibler et al. 2018, Sec. 3) and, if
ray_tracing, pyroomacoustics' stochastic ray tracer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_source_order
|
int
|
Last image source order. With |
3
|
ray_tracing
|
bool
|
Materials without scattering coefficients scatter 0.05 in every band. Without it, the settings |
True
|
air_absorption
|
bool
|
|
True
|
n_rays
|
int
|
Per source; default |
None
|
energy_thres
|
float
|
The product of its reflections in its least absorbed band at which a ray stops; the logged energy is that over the squared distance (Schroeder 2011, Eq. 5.54), so the tail has decayed much further. |
1e-7
|
duration
|
float
|
Of the ray-traced responses, in seconds. Default: |
None
|
receiver_radius
|
float
|
In metres. |
0.5
|
seed
|
bool or int
|
True seeds with 42, an int with that value, False or None leaves the run unseeded
( |
True
|
normalize
|
bool
|
Whether the responses are peak-normalized views. |
True
|
air
|
AirConditions
|
Its speed of sound and, with |
None
|
Examples:
>>> import compas_acoustics as ca
>>> scene = ca.Scene("office")
>>> wall = ca.AcousticMaterial("wall", 0.2, 0.1)
>>> scene.add_acoustic_objects(ca.AcousticObjectsLibrary.shoebox_room(6, 5, 3, materials=wall))
>>> scene.add_source(ca.Source("talker", 1.5, 1.5, 1.6))
>>> scene.add_receiver(ca.Receiver("listener", 4.0, 3.0, 1.2))
>>> responses = scene.simulate(ca.Mono(image_source_order=2, ray_tracing=False))
>>> ir = next(iter(responses.values()))
>>> ir.sampling_rate, ir.n_channels, ir.generation["method"]
(48000, 1, 'mono')
Ray tracing, on by default, adds the late reflections; the seed makes a run repeatable.
>>> responses = scene.simulate(ca.Mono(n_rays=2000, duration=0.5))
>>> ir = next(iter(responses.values()))
>>> ir.ir.shape, ir.generation["seed"]
((24000,), 42)
Binaural
¶
Binaural(reference=None, hrtf=None, *, tail=None, image_source_order=3, n_slopes=1, decay_db=30.0, duration=None, n_rays=None, directional_absorption=True, late_envelope=None, diffraction=False, air_absorption=None, seed=True, normalize=True, air=None, scattering=False)
Bases: _HybridMethod
Binaural room impulse responses: image sources, optional edge diffraction, a directional FDN.
The early field is the image sources up to image_source_order and, with diffraction, the diffracted
paths. The images of the last order drive a feedback delay network of 96 delay lines, one per direction (the
count Kirsch et al. 2023, Secs. 1.2 and 3.3, use offline), whose decay follows a target (Wendt et al. 2014,
Sec. 1.2). Every early path and delay line is filtered with the HRIR measured nearest its direction. Needs
Python >= 3.11 and a closed room. Responses are ears left then right, stored under 'binaural';
generation["hrtf"] names the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
(str, dict, Mono or None)
|
A package-scale mono response per pair for the decay target and the late envelope: a method's name on
the IR graph ( |
None
|
hrtf
|
str or path
|
|
None
|
Examples:
>>> import compas_acoustics as ca
>>> scene = ca.Scene("office")
>>> wall = ca.AcousticMaterial("wall", 0.2, 0.1)
>>> scene.add_acoustic_objects(ca.AcousticObjectsLibrary.shoebox_room(6, 5, 3, materials=wall))
>>> scene.add_source(ca.Source("talker", 1.5, 1.5, 1.6))
>>> scene.add_receiver(ca.Receiver("listener", 4.0, 3.0, 1.2))
>>> ir = next(iter(scene.simulate(ca.Binaural(tail="eyring")).values()))
>>> ir.n_channels, ir.generation["hrtf"]
(2, 'KU100_HRIR_L2702.sofa')
With a ray-traced reference the decay is fitted to a response you already have.
>>> reference = scene.simulate(ca.Mono(ray_tracing=True))
>>> responses = scene.simulate(ca.Binaural(reference="mono"))
Ambisonics
¶
Ambisonics(reference=None, sh_order=1, normalization='SN3D', *, tail=None, image_source_order=3, n_slopes=1, decay_db=30.0, duration=None, n_rays=None, directional_absorption=True, late_envelope=None, diffraction=False, air_absorption=None, seed=True, normalize=True, air=None, scattering=False)
Bases: _HybridMethod
Ambisonic room impulse responses: image sources, optional edge diffraction, a directional FDN.
As Binaural, with every early path encoded at its direction and every delay line projected from
its direction at sh_order. Responses are ACN in normalization, stored under 'ambisonics'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
(str, dict, Mono or None)
|
As |
None
|
sh_order
|
int
|
The network has 96 delay lines, the count Kirsch et al. (2023, Secs. 1.2 and 3.3) use offline, up to third
order, which the 96-point grid supports; above that the smallest equal-area grid supporting the order. The
input gain |
1
|
normalization
|
('SN3D', 'N3D')
|
ACN channel order, W = 1 for a unit plane wave. |
"SN3D"
|
Examples:
>>> import compas_acoustics as ca
>>> scene = ca.Scene("office")
>>> wall = ca.AcousticMaterial("wall", 0.2, 0.1)
>>> scene.add_acoustic_objects(ca.AcousticObjectsLibrary.shoebox_room(6, 5, 3, materials=wall))
>>> scene.add_source(ca.Source("talker", 1.5, 1.5, 1.6))
>>> scene.add_receiver(ca.Receiver("listener", 4.0, 3.0, 1.2))
>>> ir = next(iter(scene.simulate(ca.Ambisonics(tail="eyring", sh_order=2)).values()))
>>> ir.n_channels, ir.ambisonic_order
(9, 2)
Attributes¶
Functions:¶
image_source_search_seconds
¶
The package's order-of-magnitude estimate of the image source search time in seconds, for warnings.
It grows by a factor n_faces / 2.2 per order; its constants were fitted to timed searches, and the times
depend on the machine.