Simulation and Control Parameters¶
Global Configuration¶
A few global configuration parameters are available though the following API.
import pyroomacoustics as pra
# Get the value of the speed of sound used.
c = pra.constants.get("c")
# Set the cut-off frequency of the high-pass filter for RIR to 15 Hz.
pra.constants.set("rir_hpf_fc", 15.0)
Speed of Sound c¶
The speed of sound is set by default to 343 m/s in pyroomacoustics, which corresponds to a temperature of 20 degrees Celsius and dry air. The value of this default is stored in the global configuration.
The value of the speed of sound can be changed in two ways.
Adjust the
temperatureandhumidityparameters ofRoom,ShoeBox, orAnechoicRoom.Change the global setting
cby callingpra.constants.set("c", my_speech_of_sound)at the top of your code.
Fractional Delays¶
The fractional delays are used to approximate the continuous delays of the reflections in a signal sampled at a given frequency.
frac_delay_length(default 81) Length of the fractional delay filters used for RIR generation.sinc_lut_granularity(default 20) A look-up table (LUT) is used to approximate the sinc function when computing the fractional delay filters. This global setting controls the interval between points in the LUT. The interval is1.0 / sinc_lut_granularity. The size of the LUT is then given by(frac_delay_length + 2) * sinc_lut_granularity.
High-pass Filter¶
Room impulse response (RIR) generated by the image source model (ISM) can suffer from a large positive offset that is not present in natural RIR due to the artificial delays all being positive. This artifact has also been noted in the original ISM paper and solved by applying a high pass filter (HPF).
To make the software easier to use in general, an HPF is applied by default on the generated RIR. The HPF can be controlled via the following global settings.
rir_hpf_enable:True(default) activates the HPF.Falsedisable it.rir_hpf_fc: Cut-off frequency of the HPF (default is 10.0 Hz).rir_hpf_kwargs: Keyword arguments for the HPF design function. The arguments aren,rp,rs, andtype(i.e.,ftype) of scipy.signal.iirfilter.
Octave Bands¶
Octave bands are used in the multi-band frequency.
The octave bands are controlled by the object
OctaveBandsFactory.
The following global settings control the Octave bands during the simulation.
octave_bands_base_freq(default 125.0 Hz) The center frequency of the first octave band (default: 125 Hz)octave_bands_n_fft(default 512) The number of points to use for constructing the filters. The filters are constructed in the frequency domain by using an FFT of this size.octave_bands_keep_dc: (default False) When,True, the first filter is a shelf filter that includes the DC component. WhenFalse, it is a regular octave band filter.
Resampling Backend¶
resample_backend The resampling backend used in
resample(). It can be set to “soxr”,
“samplerate”, or “scipy”.
Number of Threads¶
num_threads Number of threads available to use. This is only used for
building the fractional delays in the simulation at the moment. Various
packages (numpy, scipy, etc.) may have their own limits on this.
The number of threads can be set by one of the following.
Setting the
PRA_NUM_THREADSenvironment variable.Calling
pra.constants.set("num_threads", new_num_threads).Seting
OMP_NUM_THREADSorMKL_NUM_THREADS.
Miscellaneous¶
room_isinside_max_iter(default 20) The methodis_inside()uses a randomized method to determine if a point is inside a room. It may fail, and will be restarted a maximum ofroom_isinside_max_itertimes.ffdist(default 10.0 m) Distance to the far field. This is only used by some of the beamforming algorithms.fc_hp(default 300.0 Hz) Cut-off frequency of thehighpass()function.
- class pyroomacoustics.parameters.Constants¶
Bases:
objectA class to provide easy access package wide to user settable constants.
- get(name)¶
- set(name, val)¶
- class pyroomacoustics.parameters.Material(energy_absorption, scattering=None)¶
Bases:
objectA class that describes the energy absorption and scattering properties of walls.
- energy_absorption¶
A dictionary containing keys
description,coeffs, andcenter_freqs.- Type:
dict
- scattering¶
A dictionary containing keys
description,coeffs, andcenter_freqs.- Type:
dict
- Parameters:
energy_absorption (float, str, or dict) –
- float: The material created will be equally absorbing at all frequencies
(i.e. flat).
str: The absorption values will be obtained from the database.
- dict: A dictionary containing keys
description,coeffs, and center_freqs.
- dict: A dictionary containing keys
scattering (float, str, or dict) –
- float: The material created will be equally scattering at all frequencies
(i.e. flat).
str: The scattering values will be obtained from the database.
- dict: A dictionary containing keys
description,coeffs, and center_freqs.
- dict: A dictionary containing keys
- property absorption_coeffs¶
shorthand to the energy absorption coefficients
- classmethod all_flat(materials)¶
Checks if all materials in a list are frequency flat
- Parameters:
materials (list or dict of Material objects) – The list of materials to check
- Return type:
Trueif all materials have a single parameter, elseFalse
- is_freq_flat()¶
Returns
Trueif the material has flat characteristics over frequency,Falseotherwise.
- resample(octave_bands)¶
resample at given octave bands
- property scattering_coeffs¶
shorthand to the scattering coefficients
- class pyroomacoustics.parameters.Physics(temperature=None, humidity=None)¶
Bases:
objectA Physics object allows to compute the room physical properties depending on temperature and humidity.
- Parameters:
temperature (float, optional) – The room temperature
humidity (float in range (0, 100), optional) – The room relative humidity in %. Default is 0.
- classmethod from_speed(c)¶
Choose a temperature and humidity matching a desired speed of sound
- get_air_absorption()¶
- Returns:
(air_absorption, center_freqs)whereair_absorptionis a listcorresponding to the center frequencies in
center_freqs
- get_sound_speed()¶
- Return type:
the speed of sound
- pyroomacoustics.parameters.calculate_speed_of_sound(t, h, p)¶
Compute the speed of sound as a function of temperature, humidity and pressure
- Parameters:
t (float) – temperature [Celsius]
h (float) – relative humidity [%]
p (float) – atmospheric pressure [kpa]
- Return type:
Speed of sound in [m/s]
- pyroomacoustics.parameters.get_num_threads()¶
Returns the number of threads available for pyroomacoustics
The number of threads can be set by 1. Setting the
PRA_NUM_THREADSenvironment variable. 2. Callingpra.constants.set("num_threads", new_num_threads). 3. SetingOMP_NUM_THREADSorMKL_NUM_THREADS.
- pyroomacoustics.parameters.make_materials(*args, **kwargs)¶
Helper method to conveniently create multiple materials.
Each positional and keyword argument should be a valid input for the Material class. Then, for each of the argument, a Material will be created by calling the constructor.
If at least one positional argument is provided, a list of Material objects constructed using the provided positional arguments is returned.
If at least one keyword argument is provided, a dict with keys corresponding to the keywords and containing Material objects constructed with the keyword values is returned.
If only positional arguments are provided, only the list is returned. If only keyword arguments are provided, only the dict is returned. If both are provided, both are returned. If no argument is provided, an empty list is returned.
1# energy absorption parameters 2floor_eabs = { 3 "description": "Example floor material", 4 "coeffs": [0.1, 0.2, 0.1, 0.1, 0.1, 0.05], 5 "center_freqs": [125, 250, 500, 1000, 2000, 4000], 6} 7 8# scattering parameters 9audience_scat = { 10 "description": "Theatre Audience", 11 "coeffs": [0.3, 0.5, 0.6, 0.6, 0.7, 0.7, 0.7] 12 "center_freqs": [125, 250, 500, 1000, 2000, 4000], 13} 14 15# create a list of materials 16my_mat_list = pra.make_materials((floor_eabs, audience_scat)) 17 18# create a dict of materials 19my_mat_dict = pra.make_materials(floor=(floor_abs, audience_scat))