Commit f6bcadcf authored by Marco Berzborn's avatar Marco Berzborn

very basic version of writing itaAudio objects to sofa files

parent 25fd5413
......@@ -82,6 +82,16 @@ switch(sArgs.dataType)
% sofaObj = SOFAgetConventions('SingleRoomDRIR');
% sofaObj = createSofaDRIR(sofaObj,data,userDataFields);
% sofaObj = ita_sofa_setCoordinates(sofaObj,data,'channelCoordinateType','ReceiverPosition');
case 'GeneralFIR'
sofaObj = SOFAgetConventions('GeneralFIR');
sofaObj = createSofaFIR(sofaObj,data,userDataFields); % userdatafields are generated from sofaObj.userdata
sofaObj = ita_sofa_setCoordinates(sofaObj, data,'channelCoordinateType','ReceiverPosition');
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
otherwise
error('ITA_WRITE_SOFA: Only HRTF Type is defined');
end
......@@ -98,6 +108,35 @@ result = 1;
end
function sofaObj = createSofaFIR(sofaObj, data, userDataFields)
if ~isa(data, 'itaAudio')
ita_verbose_info('I only export itaAudio objects', 0);
return;
end
sofaObj.Data.IR = zeros(1, data.nChannels, data.nSamples);
sofaObj.Data.IR(1,: ,:) = data.timeData.';
sofaObj.Data.Delay = zeros(1, data.nChannels);
sofaObj.Data.SamplingRate = data.samplingRate;
userData = data.userData;
for index = 1:length(userDataFields)
if isfield(userData,userDataFields{index})
sofaObj.(userDataFields{index}) = userData.(userDataFields{index});
end
end
if ~isempty(data.objectCoordinates.cart)
sofaObj.ReceiverPosition = data.objectCoordinates.cart;
end
end
function sofaObj = createSofaHRTF(sofaObj,data,userDataFields)
if ~isa(data,'itaHRTF')
......
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