% This script combines the nine SOFA files for the different listening positions
% to a single SOFA file, containing all listening positions.
%
% NOTE: you first have to install the SOFA API
% (https://github.com/sofacoustics/API_MO/releases/latest) and execute "SOFAstart"
% before running this script.

% === Megred version ===
clear all
sofa11 = SOFAload('1_KEMAR_Calypso_Surround_X-1.0m_Y+0.5m.sofa');
sofa12 = SOFAload('2_KEMAR_Calypso_Surround_X-0.5m_Y+0.5m.sofa');
sofa1 = SOFAmerge(sofa11, sofa12);
sofa11 = SOFAload('3_KEMAR_Calypso_Surround_X+0.0m_Y+0.5m.sofa');
sofa12 = SOFAload('4_KEMAR_Calypso_Surround_X-1.0m_Y+0.0m.sofa');
sofa2 = SOFAmerge(sofa11, sofa12);
sofa11 = SOFAload('5_KEMAR_Calypso_Surround_X-0.5m_Y+0.0m.sofa');
sofa12 = SOFAload('6_KEMAR_Calypso_Surround_X+0.0m_Y+0.0m.sofa');
sofa3 = SOFAmerge(sofa11, sofa12);
sofa11 = SOFAload('7_KEMAR_Calypso_Surround_X-1.0m_Y-0.5m.sofa');
sofa12 = SOFAload('8_KEMAR_Calypso_Surround_X-0.5m_Y-0.5m.sofa');
sofa4 = SOFAmerge(sofa11, sofa12);
sofa1 = SOFAmerge(sofa1, sofa2);
sofa2 = SOFAmerge(sofa3, sofa4);
sofa11 = SOFAmerge(sofa1, sofa2);
clear sofa1 sofa2
sofa12 = SOFAload('9_KEMAR_Calypso_Surround_X+0.0m_Y-0.5m.sofa');
sofa = SOFAmerge(sofa11, sofa12);
clear sofa11 sofa12
sofa.GLOBAL_Title = 'QU KEMAR Binaural Room Impulse Responses, Calypso 5.0 Setup, Genelec 8030A';
SOFAsave('KEMAR_Calypso_Surround.sofa',sofa);
clear all
