RIR Generator

Abstract

The image method, proposed by Allen and Berkley in 1979 [1], is probably one of the most commonly used methods in the acoustic signal processing community to create synthetic room impulse responses. A mex-function, which can be used in MATLAB, was developed to generate multi-channel room impulse responses using the image method. This function enables the user to control the reflection order, room dimension and microphone directivity. This package includes a tutorial, MATLAB examples, and the source code.

  1. J.B. Allen and D.A. Berkley, "Image method for efficiently simulating small-room acoustics," Journal Acoustic Society of America, 65(4), April 1979, p 943.

Example

c = 340;                     % Sound velocity (m/s)
fs = 16000;                  % Sample frequency (samples/s)
r = [ 2 1.5 2 ];             % Receiver position [ x y z ] (m)
s = [ 2 3.5 2 ];             % Source position [ x y z ] (m)
L = [ 5 4 6 ];               % Room dimensions [ x y z ] (m)
beta = 0 . 4;                % Reverberationtime (s)
nsample = 4096;              % Number of samples
mtype = ’ hypercardioid ’;   % Type of microphone
order = −1;                  % −1 equals maximum reflection order!
dim = 3;                     % Room dimension
orientation = [pi/2 0];      % Microphone orientation [azimuth elevation] in radians
hp_filter = 1;               % Enable high-pass filter

h = rir_generator(c, fs, r, s, L, beta, nsample, mtype, order, dim, orientation, hp_filter);
example_4

History

1.0.20030606 Initial version
1.1.20040803 + Microphone directivity + Improved phase accuracy
1.2.20040312 + Reflection order
1.3.20050930 + Reverberation Time
1.4.20051114 + Supports multi-channels
1.5.20051116 + High-pass filter [1]
+ Microphone directivity control
1.6.20060327 + Minor improvements
1.7.20060531 + Minor improvements
1.8.20080713 + Minor improvements
1.9.20090822 + 3D microphone directivity control
2.0.20100920 + Calculation of the source-image position changed in the code and tutorial. This ensures a proper response to reflections in case a directional microphone is used.
2.1.20120318 + Avoid the use of unallocated memory.
2.1.20140721 + Fixed computation of alpha.
2.1.20141124 + The window and sinc are now both centered around t=0.

Downloads

How to build the MEX-function

You will need to build the MEX-function using MATLAB. MATLAB supports the use of a variety of compilers for building MEX-files. MathWorks also maintains a list of supported and compatible compilers. Once you have verified that you are using a supported C++ compiler, you are ready to configure your system to build the rir_generator using the following steps:

Start MATLAB Run the following command from the MATLAB command prompt and select a C++ compiler: mex -setup Now build the MEX-function using: mex rir_generator.cpp Please do not hesitate to contact me if you experience any problems while building the MEX-function.