Commit bf58ee1c authored by Hark Braren's avatar Hark Braren
Browse files

Added check if one or 2 ears when reading sofa file

parent 3fe15210
......@@ -37,7 +37,7 @@ handleSofa = SOFAload(filename);
%% check HRTF
isHrtf = ismember(handleSofa.GLOBAL_SOFAConventions,{'SimpleFreeFieldHRIR','SimpleFreeFieldHRTF','SimpleFreeFieldTF'});
if ~isHrtf
error("Datatype not typically used for HRTFs");
error("%s: Datatype not typically used for HRTFs",handleSofa.GLOBAL_SOFAConventions);
end
%% get positional data
......@@ -86,8 +86,8 @@ samplingrate = handleSofa.Data.SamplingRate;
if size(data,2) ~= 2
error('unknown data structure')
end
leftEarData = itaAudio(squeeze(data(:,1,:)).',samplingrate,'time');
rightEarData = itaAudio(squeeze(data(:,2,:)).',samplingrate,'time');
leftEarData = itaAudio(squeeze(data(:,1,:))',samplingrate,'time');
rightEarData = itaAudio(squeeze(data(:,2,:))',samplingrate,'time');
audioData = [leftEarData, rightEarData];
end
......@@ -102,7 +102,7 @@ if ~ismember(handleSofa.N_Units,{'hertz','hz','Hertz','Hz'})
end
frequencies = handleSofa.N;
data = handleSofa.data.Real+1j*handleSofa.Data.Imag;
data = handleSofa.Data.Real+1j*handleSofa.Data.Imag;
if std(diff(frequencies)) > 0.01*mean(diff(frequencies))
ita_verbose_info('Please check frequency Vector. It seems there are some values missing - returnin itaResult',0);
......@@ -114,13 +114,21 @@ else
ita_verbose_info('Automatically converting from equidistantly sampled frequency domain data, handle with care',1)
end
if size(data,2) ~= 2
error('unknown data structure')
end
samplingrate = 2*max(fVec);
dataL = itaAudio(squeeze(data(:,1,:)).',samplingrate,'freq');
dataR = itaAudio(squeeze(data(:,2,:)).',samplingrate,'freq');
% check number of ears
switch size(data,2)
case 1
ita_verbose_info('ita_read_sofa_hrtf: Only data of one ear present, using it for both ears',0)
dataL = itaAudio(squeeze(data(:,1,:)).',samplingrate,'freq');
dataR = dataL;
case 2
dataL = itaAudio(squeeze(data(:,1,:)).',samplingrate,'freq');
dataR = itaAudio(squeeze(data(:,2,:)).',samplingrate,'freq');
otherwise
error('Number of ears not matching')
end
audioData = [dataL, dataR];
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment