itaHpTF_MS.m 6.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
classdef itaHpTF_MS < itaHpTF
    %ITAHPTF_Meas - Calculation of the HpTF from measured TF and Mic.
    %Reference Measurements
    %
    %
    % Derived from itaHpTF. See itaHpTF_Meas for measurement
    % Without any argument ita_itaHpTF_setup is called. Otherwise use and
    % itaMSTF as input (To Do)

    %
    % itaHpTF_Meas Properties:
    %         TF            (measured transfer function)
    %         fLower        (lower frequency for extrapolation)
    %         fUpper        (upper frequency for regularization)
    %         method        (mSTD, max, mean: see Masiero, Bruno; Fels, Janina: "Perceptually Robust Headphone Equalization for Binaural Reproduction"
    %                                             Audio Engineering Society Convention 130, May 2011)
    %         normalized    (Normalization of HpTF)
    % itaHpTF_Meas Methods:
    %         run           Will be called immediatly after the GUI. Can
    %                       also be used with the subjects' name: this.run('Hans'). This method will return an itaHpTF_Audio to the workspace. 
    
    % <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>
    
    properties(Access = private)
        mMSTF        = itaMSTF;
    end
    
    properties(Dependent = true, Hidden = false)

        MSTF        = [];
    end
    
    properties (Dependent = true, SetAccess = private)
    end
    
    methods
        function this = itaHpTF_MS(varargin)
            
            this = this@itaHpTF();
            
            this.MSTF.inputChannels = [1 2];
            this.MSTF.outputChannels = [1 2];
            if nargin == 1
                % init
rbo's avatar
isa fix    
rbo committed
48
                if isa(varargin{1},'itaHpTF')
49
                    this.init = varargin;
rbo's avatar
isa fix    
rbo committed
50
51
                elseif isa(varargin{1},'itaMSTF') % calibration input
                    this.MSTF = varargin{1};
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
                end
                this.dimensions = 2*this.repeat;
                this.fftDegree = this.MSTF.fftDegree;
                
            else
                this_tmp = ita_itaHpTF_setup(this);
                if ~isempty(this_tmp)
                    this = this_tmp;
                    this.dimensions = 2*this.repeat;
                    this.fftDegree = this.MSTF.fftDegree;
                    HpTF = this.run; %#ok<NASGU>
                end
            end
            this.signalType = 'energy';
        end
        
        
        function HpTF = run(this,varargin) % run measurement
            if nargin == 2
                if ischar(varargin{1}), this.nameSubj = varargin{1}; end 
            end
            
            chIn    = this.MSTF.inputChannels; % TO DO setzt sich zurck
            chOut   = this.MSTF.outputChannels;
            MS      = this.MSTF;
            
            for idxM=1:this.repeat
                strL = [this.nameHP ', '  this.nameSubj ', run ',num2str(idxM) ' L'];
                strR = [this.nameHP ', '  this.nameSubj ', run ',num2str(idxM) ' R'];
                
                % Measure Left side
                MS.inputChannels = chIn(1);
                MS.outputChannels = chOut(1);
                resultL = MS.run;
                resultL.channelNames{1} = strL;
                
                % Measure Right side
                MS.inputChannels = chIn(2);
                MS.outputChannels = chOut(2);
                resultR = MS.run;
                resultR.channelNames{1} = strR;
                
                % Store data
                result2ch = ita_merge(resultL,resultR);
%                 if ~isempty(this.savePath)
%                     ita_write(result2ch,[this.savePath,'\HP_' this.nameHP '_Subj_' ...
%                         this.nameSubj '_run_',num2str(idxM) '.ita']);
%                 end
                
                this.freqData(:,[2*idxM-1,2*idxM]) = result2ch.freqData(:,[1 2]);
                this.channelNames{2*idxM-1} = strL;
                this.channelNames{2*idxM}   = strR;
                
                % Display on command window and continue
                if idxM~=this.repeat
                    commandwindow
                    disp(['Measurement ',num2str(idxM),'/',num2str(this.repeat),' finished.'])
                    disp('Put headphones off and on again. Press any key to continue.')
                    pause
                    pause(2)
                else
                    commandwindow
                    fprintf('\nMEASUREMENT DONE!\n')
                end
            end
            MS.outputChannels = chOut;
            MS.inputChannels = chIn;
            
            HpTF = itaHpTF_Audio(this);
            assignin('base', ['HpTF_' this.nameSubj], HpTF)
        end
        
        function display(this)
            this.displayLineStart
            this.disp
        end
        
        function disp(this)
            disp@itaHpTF(this)
        end
        
        %% ................................................................
        % GET
        %..................................................................

        
        function MSTF = get.MSTF(this)
            MSTF = this.mMSTF; end
        
        %% ................................................................
        % SET
        %..................................................................
        function this = set.MSTF(this,MSTF)
            this.mMSTF = MSTF; end
        
    end
    
    methods(Hidden = true)
    end
    
    methods(Hidden = true)
        function sObj = saveobj(this)
            % To Do!
            %             % Called whenever an object is saved
            %             % have to get save objects for both base classes
            
            sObj = saveobj@itaHpTF(this);
            
            % Copy all properties that were defined to be saved
            propertylist = itaHpTF_MS.propertiesSaved;
            for idx = 1:numel(propertylist)
                sObj.(propertylist{idx}) = this.(propertylist{idx});
            end
        end
    end
    
    methods(Static)
        function this = loadobj(sObj)
            this = itaHpTF_MS(sObj);
        end
        
        function result = propertiesSaved
            result = {'MSTF'};
        end
        
        function result = propertiesLoad
            result = {'mMSTF'};
        end
    end
end