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

itaHRTF: shortcut during contruction from already sorted itaAudio objects

parent 151f6aaf
......@@ -158,7 +158,7 @@ classdef itaHRTF < itaAudio
end
% sofa input
if ~isempty(find(strcmpi(varargin,'SOFA')==1, 1))
this = ita_read_sofa_hrtf(arargin{find(strcmpi(varargin,'SOFA')==1)+1});
this = ita_read_sofa_hrtf(varargin{find(strcmpi(varargin,'SOFA')==1)+1});
end
elseif nargin == 1
......@@ -329,49 +329,70 @@ classdef itaHRTF < itaAudio
coord = HRTFc.channelCoordinates;
% find the corresponding left and right channel
pairs = zeros(coord.nPoints/2,2);
if coord.nPoints>10000 % takes a while
ita_verbose_info([num2str(coord.nPoints) ' Points have to be sorted ...please wait...'], 0);
%% shortcut when pairs match
if mod(coord.nPoints,2)~=0
error('expecting even number of channels');
end
counter = 1;
thetaPhi = round([coord.theta_deg coord.phi_deg]*10)/10; %round to 0.1 deg
deletedChannel = 0;
for iCoord = 1:coord.nPoints
coordCurrent = thetaPhi(iCoord,:);
% if isempty(find(pairs(:) == iCoord, 1)) % only if the corresponding channel is not found
if ~any(pairs(:) == iCoord) % only if the corresponding channel is not found
% find corresponding channel
% coordComp = thetaPhi([1:iCoord-1 iCoord+1:coord.nPoints],:);
% diffCoord = bsxfun(@minus,coordCurrent,coordComp)== 0;
% idxCoord = find(diffCoord(:,1)==1 & diffCoord(:,2) ==1);
diffCoord = bsxfun(@minus,coordCurrent,thetaPhi)== 0;
idxCoord = find(diffCoord(:,1)==1 & diffCoord(:,2) ==1);
idxCoord = idxCoord(idxCoord~=iCoord);
if length(idxCoord) > 1
% deletedChannel = deletedChannel + length(idxCoord) -1;
idxCoord = idxCoord(1);
pairs = zeros(coord.nPoints/2,2);
% if first half == seconf half
if all(all([coord.n(1:coord.nPoints/2).theta_deg,...
coord.n(1:coord.nPoints/2).phi_deg]*10/10 ==...
[coord.n(coord.nPoints/2+1:coord.nPoints).theta_deg,...
coord.n(coord.nPoints/2+1:coord.nPoints).phi_deg]*10/10))
pairs = [(1:coord.nPoints/2)',(coord.nPoints/2+1:coord.nPoints)'];
%if already interleaved [l r l r]
elseif all(all([coord.n(1:2:coord.nPoints).theta_deg,...
coord.n(1:2:coord.nPoints).phi_deg]*10/10 ==...
[coord.n(2:2:coord.nPoints).theta_deg,...
coord.n(2:2:coord.nPoints).phi_deg]*10/10))
pairs = [(1:2:coord.nPoints)',(2:2:coord.nPoints)'];
%long way of finding matching pairs
else
% find the corresponding left and right channel
if coord.nPoints>10000 % takes a while
ita_verbose_info([num2str(coord.nPoints) ' Points have to be sorted ...please wait...'], 0);
end
counter = 1;
thetaPhi = round([coord.theta_deg coord.phi_deg]*10)/10; %round to 0.1 deg
deletedChannel = 0;
for iCoord = 1:coord.nPoints
coordCurrent = thetaPhi(iCoord,:);
% if isempty(find(pairs(:) == iCoord, 1)) % only if the corresponding channel is not found
if ~any(pairs(:) == iCoord) % only if the corresponding channel is not found
% find corresponding channel
% coordComp = thetaPhi([1:iCoord-1 iCoord+1:coord.nPoints],:);
% diffCoord = bsxfun(@minus,coordCurrent,coordComp)== 0;
% idxCoord = find(diffCoord(:,1)==1 & diffCoord(:,2) ==1);
diffCoord = bsxfun(@minus,coordCurrent,thetaPhi)== 0;
idxCoord = find(diffCoord(:,1)==1 & diffCoord(:,2) ==1);
idxCoord = idxCoord(idxCoord~=iCoord);
if length(idxCoord) > 1
% deletedChannel = deletedChannel + length(idxCoord) -1;
idxCoord = idxCoord(1);
end
% store the corresponding channel
pairs(counter,1) = iCoord;
% if idxCoord <iCoord
% pairs(counter,2) = idxCoord;
% else
% pairs(counter,2) = idxCoord+1;
% end
pairs(counter,2) = idxCoord;
counter = counter+1;
end
% store the corresponding channel
pairs(counter,1) = iCoord;
% if idxCoord <iCoord
% pairs(counter,2) = idxCoord;
% else
% pairs(counter,2) = idxCoord+1;
% end
pairs(counter,2) = idxCoord;
counter = counter+1;
end
% break if all corresponding channels are found
if all(pairs(:))
break;
end
end
% break if all corresponding channels are found
if all(pairs(:))
break;
end
end %loop sort pairs
end %if shortcut
% ........................................................
% split data in right and left channel
......
......@@ -42,13 +42,13 @@ end
%% get positional data
% head position coordinates and orientation
recieverCoordinates = ita_sofa_getCoordinates(handleSofa,'coordinateType','ReceiverPosition');
listenerView = ita_sofa_getCoordinates(handleSofa,'coordinateType','ListenerView');
recieverCoordinates = ita_sofa_getCoordinates(handleSofa,'channelCoordinateType','ReceiverPosition');
listenerView = ita_sofa_getCoordinates(handleSofa,'channelCoordinateType','ListenerView');
listenerUp = listenerView;
listenerUp.(listenerUp.coordSystem) = handleSofa.ListenerUp;
%source coordinates
sourceCoordinates = ita_sofa_getCoordinates(handleSofa,'coordinateType','SourcePosition');
sourceCoordinates = ita_sofa_getCoordinates(handleSofa,'channelCoordinateType','SourcePosition');
%% get datatype info
switch handleSofa.GLOBAL_DataType
......
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