ita_write_sofa.m 2.15 KB
Newer Older
1
function result = ita_write_sofa(varargin)
2
3
4
5
6
%ITA_WRITE_SOFA - +++ Writes itaObject to Sofa Format +++
%  This function is currently used to save itaHRTF to SOFA format. 
%  Updated to SOFA Version 2.0 -- AES69-2020 (SOFA 2.0)
%  -- www.sofaconventions.org
%  
7
8
9
%  Syntax:
%   ita_write_sofa(hrtfObj,fileName,options)
%
10
11
12
%   options:
%       'dataType' ('') : for later usage to allow spcification of dataryoe
%       when not clear from itaClass
13
14
15
16
17
%
%  Example:
%   audioObjOut = ita_write_sofa(hrtfObj,'testHRTF.sofa')
%
%  See also:
18
%   ita_toolbox_gui, ita_read, ita_write, ita_generate, ita_write_sofa_hrtf
19
20
21
22
23
24
25
26
27
28
29
30
%
%   Reference page in Help browser 
%        <a href="matlab:doc ita_write_sofa">doc ita_write_sofa</a>

% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved. 
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder. 
% </ITA-Toolbox>


% Author: Jan Gerrit Richter -- Email: jan.richter@akustik.rwth-aachen.de
% Created:  30-Sep-2014 
31
32
% Update as container for different write function:
% Hark Braren -- hark.braren@akustik.rwth-aachen.de
33
34
35
36
37
38
39
40


if nargin == 0 % Return possible argument layout
    result{1}.extension = '*.sofa';
    result{1}.comment = 'SOFA Files (*.sofa)';
    return;
end

41
sArgs = struct('pos1_data','itaAudio','pos2_filename','char','dataType','');
42
43
[data, filename, sArgs] = ita_parse_arguments(sArgs,varargin); 

44
45
46
47
48
%% check if sofa is installed
if ~exist('SOFAstart.m','file')
    error('SOFA not installed. Run ita_sofa_install');
end

Shaimaa Doma's avatar
Shaimaa Doma committed
49
if isempty(sArgs.dataType)
50
51
52
53
54
55
56
57
58
    %when not stated explicitly -> derive from data type
    switch class(data)
        case 'itaHRTF'
            sArgs.dataType = 'HRTF';
        otherwise
            error('Unable to determine Sofa type from datatyoe. Check if write function is implemented')
    end
end
    
59

60
61

%%
62
63
switch(sArgs.dataType)
    case 'HRTF'
64
        ita_write_sofa_hrtf(data,filename);
65
66
67
68
69
70
    
%     case 'Directivity'
%         sofaObj = SOFAgetConventions('GeneralTF');   
        
%      case 'SingleRoomDRIR'
%         sofaObj = SOFAgetConventions('SingleRoomDRIR');   
71

72
73
74
75
76
77
    otherwise
        error('ITA_WRITE_SOFA: Only HRTF Type is defined');
end

result = 1;
end