rir_generator module

Module reference

rir_generator.generate(c, fs, r, s, L, beta=None, reverberation_time=None, nsample=None, mtype=<mtype.omnidirectional: b'o'>, order=-1, dim=3, orientation=None, hp_filter=True)

Generate room impulse response.

Parameters
  • c (float) – Sound velocity in m/s. Usually between 340 and 350.

  • fs (float) – Sampling frequency in Hz.

  • r (array_like) – 1D or 2D array of floats, specifying the (x, y, z) coordinates of the receiver(s) in m. Must be of shape (3,) or (x, 3) where x is the number of receivers.

  • s (array_like) – 1D array of floats specifying the (x, y, z) coordinates of the source in m.

  • L (array_like) – 1D array of floats specifying the room dimensions (x, y, z) in m.

  • beta (array_like, optional) –

    1D array of floats specifying the reflection coefficients

    [beta_x1, beta_x2, beta_y1, beta_y2, beta_z1, beta_z2]
    

    or

    [(beta_x1, beta_x2), (beta_y1, beta_y2), (beta_z1, beta_z2)]
    

    Must be of shape (6,) or (3, 2).

    You must define exactly one of beta or reverberation_time.

  • reverberation_time (float, optional) –

    Reverberation time (T_60) in seconds.

    You must define exactly one of beta or reverberation_time.

  • nsample (int, optional) – number of samples to calculate, default is T_60 * fs.

  • mtype (mtype, optional) – Microphone type, one of mtype. Defaults to mtype.omnidirectional.

  • order (int, optional) – Reflection order, default is -1, i.e. maximum order.

  • dim (int, optional) – Room dimension (2 or 3), default is 3.

  • orientation (array_like, optional) – 1D array direction in which the microphones are pointed, specified using azimuth and elevation angles (in radians), default is [0, 0].

  • hp_filter (boolean, optional) – Enable high-pass filter, the high-pass filter is enabled by default.

Returns

h – The room impulse response, shaped (nsample, len(r))

Return type

array_like

Example

>>> import rir_generator
>>> h = rir_generator.generate(
...     c=340,
...     fs=16000,
...     r=[
...       [2, 1.5, 2],
...       [2, 1.5, 3]
...     ],
...     s=[2, 3.5, 2],
...     L=[5, 4, 6],
...     reverberation_time=0.4,
...     nsample=4096,
...     mtype=rir_generator.mtype.omnidirectional,
... )
class rir_generator.mtype(value)

Bases: enum.Enum

Microphone type.

b = b'b'
bidirectional = b'b'
c = b'c'
cardioid = b'c'
h = b'h'
hypercardioid = b'h'
o = b'o'
omnidirectional = b'o'
s = b's'
subcardioid = b's'