Commit 98e2adf9 authored by Hark Braren's avatar Hark Braren
Browse files

add userData to allow modification of general sofa parameters in exported file

parent f1349797
......@@ -4,6 +4,13 @@ function varargout = ita_write_sofa_hrtf(varargin)
%
% Syntax:
% ita_write_sofa_hrtf(hrtfObj, fileName)
%
% Options:
% userData ([]): struct with user specific SOFA entries see
% <userDataFields> below
% e.g. userData = struct('GLOBAL_AuthorContact','Max Mustermann: mmu@xyz.de',...
% 'GLOBAL_Comment','Example Comment')
% See also:
% ita_read_sofa_hrtf, ita_write, itaHRTF
......@@ -20,6 +27,20 @@ function varargout = ita_write_sofa_hrtf(varargin)
% Author: Hark Braren -- Email: hark.braren@akustik.rwth-aachen.de
% Created: 12-Apr-2021
userDataFields = {'GLOBAL_AuthorContact',... %Who created it, automatically takes info from toolbox preferences
'GLOBAL_Comment',...
'GLOBAL_History',...
'GLOBAL_License',... % e.g. CC 4.0 BY - http://creativecommons.org/licenses/by/4.0/
'GLOBAL_ListenerShortName',... % e.g. KEMAR
'GLOBAL_Organization',... % (IHTA)
'GLOBAL_References',... % corresonding paper
'GLOBAL_DateCreated',...
'GLOBAL_DateModified',...
'GLOBAL_Title',...
'GLOBAL_DatabaseName',... %
'GLOBAL_Origin',...
'GLOBAL_RoomType',... %(freefield)
};
%% Initialization and Input Parsing
if nargin == 0 % Return possible argument layout
......@@ -28,8 +49,8 @@ if nargin == 0 % Return possible argument layout
return;
end
sArgs = struct('pos1_data','itaHRTF','pos2_filename','char');
[data, fileName] = ita_parse_arguments(sArgs,varargin);
sArgs = struct('pos1_data','itaHRTF','pos2_filename','char','userData',[]);
[data, fileName, sArgs] = ita_parse_arguments(sArgs,varargin);
%% check if sofa is installed
if ~exist('SOFAstart.m','file')
......@@ -73,35 +94,58 @@ end
%% General Info
Obj.GLOBAL_ApplicationName = 'ITA-Toolbox';
Obj.GLOBAL_Organization = 'Intitute for Hearing Technology and Acoustic, RWTH Aachen University';
Obj.GLOBAL_ApplicationVersion = num2str(ita_toolbox_version_number);
Obj.GLOBAL_DateCreated = date;
%The following will be overwritten with userdata is supplied
Obj.GLOBAL_DateCreated = date;
Obj.GLOBAL_AuthorContact = [ita_preferences('AuthorStr') ': ' ita_preferences('EmailStr')];
%% HRTF Info
%head position and orientation
%head position
Obj.ListenerPosition_Type = 'cartesian';
Obj.ListenerPosition_Units = 'metre';
Obj.ListenerPosition = [0 0 0];
% ear position for each measurement [0 +w 0; 0 -w 0] in hrtf.objectCoordinates
Obj.ReceiverPosition_Type = 'cartesian';
Obj.ReceiverPosition_Units = 'metre';
Obj.ReceiverPosition = repmat(data.objectCoordinates.cart,1,1,data.nDirections);
if ~isempty(data.objectCoordinates.cart)
Obj.ReceiverPosition = repmat(data.objectCoordinates.cart,1,1,data.nDirections);
else
Obj.ReceiverPosition = repmat([0 0.09 0; 0 -0.09 0],1,1,data.nDirections); %default per SOFA def
end
%head orientation
Obj.ListenerView_Type = 'cartesian';
Obj.ListenerView_Units = 'metre';
Obj.ListenerView = data.objectViewVector.cart;
Obj.ListenerUp = data.objectUpVector.cart;
if ~isempty(data.objectViewVector.cart)
Obj.ListenerView = data.objectViewVector.cart;
end
if ~isempty(data.objectUpVector.cart)
Obj.ListenerUp = data.objectUpVector.cart;
end
%Loudspeaker positions in head-related coordinates
Obj.SourcePosition_Type = 'spherical';
Obj.SourcePosition_Units = 'degree,degree,metre';
Obj.SourcePosition = sofaSphericalCoordiantas(data.dirCoord);
Obj.SourcePosition = sofaSphericalCoordiantes(data.dirCoord);
%% add Userdata
for iField = 1:numel(userDataFields)
if ismember(userDataFields{iField},fieldnames(sArgs.userData))
Obj.(userDataFields{iField}) = sArgs.userData.(userDataFields{iField});
end
end
%% update and write obj
Obj=SOFAupdateDimensions(Obj);
SOFAsave(fileName,Obj);
end
function sofaCoord = sofaSphericalCoordiantas(coords)
function sofaCoord = sofaSphericalCoordiantes(coords)
%transform from zenith to elevation angle
r = coords.r;
......
Markdown is supported
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