Commit 2c627862 authored by rbo's avatar rbo
Browse files

ita_write_sofa additional object data

additional object data can be added & receiverView and receiverUp removed
parent 983c3d54
...@@ -8,6 +8,7 @@ function result = ita_write_sofa(varargin) ...@@ -8,6 +8,7 @@ function result = ita_write_sofa(varargin)
% Options (default): % Options (default):
% 'dataType' (HRTF) : sets the data type. currently only HRTF % 'dataType' (HRTF) : sets the data type. currently only HRTF
% supported % supported
% userData : a struct with userDataFields
% %
% Example: % Example:
...@@ -35,7 +36,7 @@ if nargin == 0 % Return possible argument layout ...@@ -35,7 +36,7 @@ if nargin == 0 % Return possible argument layout
return; return;
end end
sArgs = struct('pos1_data','itaAudio','pos2_filename','char','dataType','HRTF'); sArgs = struct('pos1_data','itaAudio','pos2_filename','char','dataType','HRTF','userdata',[]);
[data, filename, sArgs] = ita_parse_arguments(sArgs,varargin); [data, filename, sArgs] = ita_parse_arguments(sArgs,varargin);
...@@ -55,9 +56,14 @@ switch(sArgs.dataType) ...@@ -55,9 +56,14 @@ switch(sArgs.dataType)
case 'HRTF' case 'HRTF'
sofaObj = SOFAgetConventions('SimpleFreeFieldHRIR'); sofaObj = SOFAgetConventions('SimpleFreeFieldHRIR');
sofaObj = createSofaHRTF(sofaObj,data,userDataFields); sofaObj = createSofaHRTF(sofaObj,data,userDataFields); % userdatafields are generated from sofaObj.userdata
sofaObj = ita_sofa_setCoordinates(sofaObj,data,'channelCoordinateType','SourcePosition'); sofaObj = ita_sofa_setCoordinates(sofaObj,data,'channelCoordinateType','SourcePosition');
if ~isempty(sArgs.userdata) % user data are replaced by the struct
fNames = fieldnames(sArgs.userdata);
for idxFN = 1:numel(fNames)
sofaObj.(fNames{idxFN}) = sArgs.userdata.(fNames{idxFN});
end
end
% case 'Directivity' % case 'Directivity'
% sofaObj = SOFAgetConventions('GeneralTF'); % sofaObj = SOFAgetConventions('GeneralTF');
...@@ -72,11 +78,10 @@ switch(sArgs.dataType) ...@@ -72,11 +78,10 @@ switch(sArgs.dataType)
error('ITA_WRITE_SOFA: Only HRTF Type is defined'); error('ITA_WRITE_SOFA: Only HRTF Type is defined');
end end
sofaObj.GLOBAL_ApplicationName = 'itaToolbox'; sofaObj.GLOBAL_ApplicationName = 'ITA-Toolbox';
sofaObj.GLOBAL_AuthorContact = sprintf('%s (%s)',AuthorStr,EmailStr); sofaObj.GLOBAL_AuthorContact = sprintf('%s (%s)',AuthorStr,EmailStr);
sofaObj.GLOBAL_Comment = data.comment; sofaObj.GLOBAL_Comment = data.comment;
sofaObj.GLOBAL_DateCreated = date; sofaObj.GLOBAL_DataType = 'Directivity';
sofaObj.GLOBAL_DataType = 'Directivity';
SOFAupdateDimensions(sofaObj); SOFAupdateDimensions(sofaObj);
SOFAsave(filename,sofaObj); SOFAsave(filename,sofaObj);
...@@ -107,15 +112,17 @@ function sofaObj = createSofaHRTF(sofaObj,data,userDataFields) ...@@ -107,15 +112,17 @@ function sofaObj = createSofaHRTF(sofaObj,data,userDataFields)
end end
end end
% two channels are needed
if ~isempty(data.objectCoordinates.cart) if ~isempty(data.objectCoordinates.cart)
sofaObj.ReceiverPosition = data.objectCoordinates.cart; sofaObj.ReceiverPosition = data.objectCoordinates.cart;
end end
if ~isempty(data.objectUpVector.cart) % if ~isempty(data.objectUpVector.cart) % is not working with one or
sofaObj.ReceiverUp = data.objectUpVector.cart; % two channels
end % sofaObj.ReceiverUp = data.objectUpVector.cart;
if ~isempty(data.objectViewVector.cart) % end
sofaObj.ReceiverView = data.objectViewVector.cart; % if ~isempty(data.objectViewVector.cart)
end % sofaObj.ReceiverView = data.objectViewVector.cart;
% end
end 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