# Usage¶

As explained in the Working with the database tutorial the database is located at https://dev.qu.tu-berlin.de/projects/twoears-database, but you don’t have to download any files yourself as this is automatically performed by the Binaural simulator or by explicitly calling xml.dbGetFile(), for example:

filename = xml.dbGetFile('stimuli/anechoic/instruments/anechoic_cello.wav');


All the data that is automatically downloaded is cached inside a temporary folder. You can get the position of this folder by executing xml.dbTmp and change it with xml.dbTmp('/path/to/tmp'). If you would like to clear the temporary folder you can execute xml.dbClearTmp. Before downloading a file from the remote database xml.dbGetFile first looks if you have a file on your computer in the exact relative position as specified, in this case ./stimuli/anechoic/instruments/anechoic_cello.wav, then it will look if you have a local copy of the database on your PC. The position of that database can be specified or seen by the xm.dbPath function. After that it looks inside the temporary cache for the file and only then downloads it.

Let us now assume that you want to have an HRTF in addition to our WAV-file and you want to convolve the HRTF with sig from above:

hrtffile = xml.dbGetFile('impulse_responses/qu_kemar_anechoic/QU_KEMAR_anechoic_3m.sofa');
% display some information about the impulse response
SOFAinfo(hrtf);
% plot a figure with the measurement setup
SOFAplotGeometry(hrtf);
% have a look at the size of the data
size(hrtf.Data.IR)
% get information about the measurement setup
hrtf.ListenerPosition       % position of dummy head
hrtf.SourcePosition         % position of loudspeaker
% head orientation of the dummy head + coordinate system and units
hrtf.ListenerView
hrtf.ListenerView_Type
hrtf.ListenerView_Units
% calculate the source position from a listener point of view
apparentSourceVector = SOFAcalculateAPV(hrtf);
% listen to the HRTF with azimuth of -90°
apparentSourceVector(91, 1)
SOFAplotGeometry(hrtf, 91);
soundOutput = [conv(squeeze(hrtf.Data.IR(91, 1, :)), sig) ...
conv(squeeze(hrtf.Data.IR(91, 2, :)), sig)];
sound(soundOutput, hrtf.Data.SamplingRate);


You could do the same by not using the SOFA API directly, but by using only functions from the Binaural simulator:

% Load HRTF data set
hrtf = simulator.DirectionalIR( ...
xml.dbGetFile('impulse_responses/qu_kemar_anechoic/QU_KEMAR_anechoic_3m.sofa'));
% Get a the HRTF for an azimuth of 80° (this is to the left of you)
impulseResponse = hrtf.getImpulseResponses(80);
figure;
plot(impulseResponse.left(1:400), '-b');
hold on;
plot(impulseResponse.right(1:400), '-r');
% Listen to the output signal
outputSignal = [conv(impulseResponse.left, sig) ...
conv(impulseResponse.right, sig)];
sound(outputSignal, hrtf.SampleRate);


In the daily use of the Two!Ears Auditory Model you might even never directly use the xml.dbGetFile() function as you specify files to use most likely inside a scene description file, see Configuration using XML Scene Description. For example, in order to use the same HRTF from above you have to add the following address to your scene configuration:

<scene HRIRs="impulse_responses/qu_kemar_anechoic/QU_KEMAR_anechoic_3m.sofa">


The Binaural simulator will then automatically call the xml.dbGetFile() function in order to get the desired HRTF.