Room Impulse Response Generator¶
rir_generator module¶
Module reference¶
- rir_generator.generate(c, fs, r, s, L, beta=None, reverberation_time=None, nsample=None, mtype=mtype.omnidirectional, 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)
wherex
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
orreverberation_time
.reverberation_time (float, optional) –
Reverberation time (T_60) in seconds.
You must define exactly one of
beta
orreverberation_time
.nsample (int, optional) – number of samples to calculate, default is
T_60 * fs
.mtype (mtype, optional) – Microphone type, one of
mtype
. Defaults tomtype.omnidirectional
.order (int, optional) – Reflection order, default is
-1
, i.e. maximum order.dim (int, optional) – Room dimension (
2
or3
), default is3
.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, ... )
References¶
- AB76
J. B. Alien and D. A. Berkley. Image method for efficiently simulating small‐room acoustics. The Journal of the Acoustical Society of America, 60(S1):S9–S9, 1976. doi:10.1121/1.2003643.
- Hab20
Emanuël Habets. Ehabets/rir-generator: rir generator. October 2020. URL: https://github.com/ehabets/RIR-Generator, doi:10.5281/zenodo.4096349.
- Pet86
Patrick M. Peterson. Simulating the response of multiple microphones to a single acoustic source in a reverberant room. The Journal of the Acoustical Society of America, 80(5):1527–1529, 1986. doi:10.1121/1.394357.
Python- and C-based room impulse response generator, for use in convolutional reverb.
Official Python port of https://github.com/ehabets/RIR-Generator.
Example¶
import numpy as np
import scipy.signal as ss
import soundfile as sf
import rir_generator as rir
signal, fs = sf.read("bark.wav", always_2d=True)
h = rir.generate(
c=340, # Sound velocity (m/s)
fs=fs, # Sample frequency (samples/s)
r=[ # Receiver position(s) [x y z] (m)
[2, 1.5, 1],
[2, 1.5, 2],
[2, 1.5, 3]
],
s=[2, 3.5, 2], # Source position [x y z] (m)
L=[5, 4, 6], # Room dimensions [x y z] (m)
reverberation_time=0.4, # Reverberation time (s)
nsample=4096, # Number of output samples
)
print(h.shape) # (4096, 3)
print(signal.shape) # (11462, 2)
# Convolve 2-channel signal with 3 impulse responses
signal = ss.convolve(h[:, None, :], signal[:, :, None])
print(signal.shape) # (15557, 2, 3)