Configuration

There are basically two ways for controlling and configuring the Binaural simulator. In both cases you will need audio files to create your acoustic scenes with it. You could of course use your own audio files, but you can also use files from the large Database. In that case you only have to specify the path of the desired files in the database and the Binaural simulator will download them during processing. For further information on that have a look at the Work with the database.

Configuration using a Matlab script

The Binaural simulator uses the object-oriented programming architecture of Matlab. In order to initialise the simulation tool, an Object of the SimulatorConvexRoom()-class has to be instantiated by:

>> sim = simulator.SimulatorConvexRoom();

Note that the constructor returns a handle, which is the pendant to a reference of an object in other programming language. Assigning sim to a another variable does not copy the object. The simulation framework is depending on a simulation kernel written in C++/MEX. It is not recommended to instantiate more than one object of the SimulatorConvexRoom()-class by calling the constructor multiple times, since all objects would access the same simulation kernel. To see all configurable parameters of the simulator call the object’s name in Matlab:

>> sim

sim =

  SimulatorConvexRoom with properties:

                BlockSize: 4096
               SampleRate: 44100
          NumberOfThreads: 1
                 Renderer: @ssr_binaural
              HRIRDataset: [1x1 simulator.DirectionalIR]
             MaximumDelay: 0.0500
                 PreDelay: 0
       LengthOfSimulation: 5
                  Sources: {[1x1 simulator.source.Point]  [1x1 simulator.source.Point]}
                    Sinks: [1x1 simulator.AudioSink]
                    Walls: []
    ReverberationRoomType: 'shoebox'
    ReverberationMaxOrder: 0

For a more detailed description of each parameter refer to the documentation in the source code. In order to change various processing parameters of the simulator the build-in set/get functionality of Matlab should be used, e.g.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
% some processing parameters
set(sim, ...
  'BlockSize', 4096, ...
  'SampleRate', 44100, ...
  'MaximumDelay', 0.05, ...
  'PreDelay', 0.0, ...
  'LengthOfSimulation', 5.0, ...
  'Renderer', @ssr_binaural, ...
  'HRIRDataset', simulator.DirectionalIR( ...
    'impulse_responses/qu_kemar_anechoic/QU_KEMAR_anechoic_3m.sofa') ...
  );

Line 3 and 4 set the sample rate of the simulator to 44.1 kHz and defines a block size of 4096 samples. To define the acoustic scene, add the sound sources and the listener.

1
2
3
4
5
% acoustic scene
set(sim, ...
  'Sources', {simulator.source.Point(), simulator.source.Point()}, ...
  'Sinks', simulator.AudioSink(2) ...
  );

Sound sources are stored in a cell array. Line 3 defines two point sources, that are created by calling the constructor of the simulator.source.Point-class. For the binaural simulation the parameter Sinks must contain only one object of the simulator.AudioSink-class describing the listener (Line 4). The argument 2 in the constructor’s call defines the number of input channel of the sink, which is 2 for binaural signals. Since sources and sinks are also handles, they can be accessed using the same set/get procedure as for the simulator object, e.g.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
% set parameters of audio sources
set(sim.Sources{1}, ...
  'AudioBuffer', simulator.buffer.FIFO(1), ...
  'Position', [1; 2; 1.75], ...
  'Name', 'Cello', ...
  'Volume', 0.4 ...
  );

set(sim.Sources{2}, ...
  'AudioBuffer', simulator.buffer.FIFO(1), ...
  'Position', [1; -2; 1.75], ...
  'Name', 'Castanets' ...
  );

% set parameters of head
set(sim.Sinks, ...
  'Position' , [0; 0; 1.75], ...
  'UnitX', [1; 0; 0], ...
  'UnitZ', [0; 0; 1], ...
  'Name', 'Head' ...
  );

Name defines an unique identifier for the scene object, which should not be re-used for any other scene object. Position defines the position of the scene object in 3D Cartesian coordinates (measured in meter). In order to emit sound from sound sources, audio buffers have to be respectively defined containing the sources’ audio signals. A single-channel FIFO-Buffer can be defined by simulator.buffer.FIFO(1). For more details about possible buffer types please refer to the documentation in the source code of the buffers. To load sound files into the buffers execute

1
2
3
4
5
6
% set audio input of buffers
set(sim.Sources{1}.AudioBuffer, ...
  'File', 'stimuli/anechoic/instruments/anechoic_cello.wav');

set(sim.Sources{2}.AudioBuffer, ...
  'File', 'stimuli/anechoic/instruments/anechoic_castanets.wav');

Configuration using XML Scene Description

In following the configuration as defined above using a Matlab script is done calling the constructor of the simulator object with an extra argument defining the file name of a XML scene description file.

>> sim = simulator.SimulatorConvexRoom('test_binaural.xml');

The content of test_binaural.xml is shown below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<scene
  BlockSize="4096"
  SampleRate="44100"
  MaximumDelay="0.05"
  PreDelay="0.0"
  LengthOfSimulation="5.0"
  NumberOfThreads="1"
  Renderer="ssr_binaural"
  HRIRs="impulse_responses/qu_kemar_anechoic/QU_KEMAR_anechoic_3m.sofa">
  <source Position="1 2 1.75"
          Type="point"
          Name="Cello"
          Volume="0.4">
    <buffer ChannelMapping="1"
            Type="fifo"
            File="stimuli/anechoic/instruments/anechoic_cello.wav"/>
  </source>
  <source Position="1 -2 1.75"
          Type="point"
          Name="Castanets">
    <buffer ChannelMapping="1"
            Type="fifo"
            File="stimuli/anechoic/instruments/anechoic_castanets.wav"/>
  </source>
  <sink Position="0 0 1.75"
        UnitX="1 0 0"
        UnitZ="0 0 1"
        Name="Head"/>
</scene>