-
Notifications
You must be signed in to change notification settings - Fork 4
/
SIN_runTest.m
285 lines (231 loc) · 11.2 KB
/
SIN_runTest.m
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
48
49
50
51
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
function results = SIN_runTest(opts, playlist)
%% DESCRIPTION:
%
% Master control function to run various tests associated with SIN. The
% basic idea is to pass the function a unique test identifier (CWB is
% thinking a string) that can be used to execute a specific set of
% instructions. The upshot of this approach is that the same test can be
% executed with ease from the commandline or via a GUI.
%
% INPUT:
%
% opts: SIN test options structure returned from SIN_TestSetup.m
%
% playlist: *USE ONLY FOR DEBUGGING AND PROTOTYPING PURPOSES!*
% Once you are finished debugging, update SIN_stiminfo to
% return the playlist you want to use for this specific test.
%
% cell array, each element is the path to a wav file that
% will be used in testing. In the context of SIN, this
% information can generally be grabbed from SIN_stiminfo.m in
% a fairly straightforward way.
%
% Note: if playlist is empty, a playlist is generated using
% SIN_getPlaylist. This
% OUTPUT:
%
% results: results structure. May be single element or multi-element
% depending on how the test is configured/run.
%
% Development:
%
% Christopher W. Bishop
% University of Washington
% 5/14
%% GET TESTID
% Base running decisions on the testID of the first options structure.
% Necessary for ANL and other multipart tests. Could be dangerous,
% though, in other circumstances.
testID = {opts(1).specific.testID};
%% INITIALIZE RETURN VARIABLES
% Loop through all tests (eventually)
for t=1:length(testID)
% Display the test ID so the user knows which test and file name is
% running
display(['Running ' testID]);
display(['Data saved to: ' opts(1).specific.saveData2mat]);
% Clear the previous results from the work space. These can be very
% large and make tests run very sluggishly. Better to remove them prior
% to run time.
display('Clearing previous test results to improve performance');
evalin('base', 'clear results');
% Switch
% Each TEST ID has a unique set of instructions.
switch testID{t}
case {'ANL', 'ANL (MCL-Too Loud)', 'ANL (MCL-Too Quiet)', 'ANL (MCL-Estimate)', 'ANL (BNL-Too Loud)', 'ANL (BNL-Too Quiet)', 'ANL (BNL-Estimate)'}
for i=1:length(opts)
%% GET PLAYLIST
% Must get the playlist for each test in case individual
% tests require a different test list
% Append the data at run time.
% Only append the "list" (if you can call it that) for
% the first section of the test.
if i == 1
opts(i).specific.genPlaylist.Append2UsedList = true;
[playlist, lists] = SIN_getPlaylist(opts(i));
opts(i).specific.genPlaylist.Append2UsedList = false;
else
% Once we've loaded in the audio track ONCE, use the
% raw data as the playlist rather than the file name.
% This will save in file read/write times substantially
% since this is a large file.
%
% Christi asked CWB to speed up ANL, this is part of
% that solution.
playlist = results(1).RunTime.sandbox.stim;
end %
% Copy over relevant sections from previous tests.
if i > 1
% Buffer Position
opts(i).player.startplaybackat = ...
results(i-1).RunTime.sandbox.buffer_pos./results(i-1).RunTime.sandbox.playback_fs;
% mod_mixer
% Only want to copy over non-zero values.
mixer_mask = results(i-1).RunTime.player.mod_mixer ~= 0;
opts(i).player.mod_mixer(mixer_mask) = ...
results(i-1).RunTime.player.mod_mixer(mixer_mask);
% Calibration information
end % if i > 1
% Launch ANL (at least part of it)
% We'll need to run this essentially 4 or 5 times and save
% the values in different files.
results(i) = opts(i).player.player_handle(playlist, opts(i));
% Check for errors after every step of test.
results(i) = errorCheck(results(i), playlist);
% Stimulus cleanup
% We need to remove a few things from the data structure
% to decrease file size.
% 1. Remove sandbox.stim from RunTime. This is now
% redundant with sandbox.stim from first test
% segment.
%
% 2. Remove playback_list from RunTime. This is now
% 100% redundant with stim in UserOpts.
%
% 3. Remove data2play_mixed. This is huge.
%
% 4.
if i > 1
results(i).RunTime.sandbox.playback_list = {};
results(i).RunTime.sandbox.stim = {};
end % if i > 1
end % for i=1:length(opts)
case {'HINT (Practice)', 'HINT (First Correct)', 'HINT (Perceptual Test, SPSHN)', 'HINT (SNR-50, SPSHN)', 'HINT (SNR-80, SPSHN)', 'HINT (SNR-50, ISTS)', 'HINT (SNR-80, ISTS)', 'HINT (Traditional, diotic)'};
% Run HINT for SIN
for i=1:numel(opts)
%% GET PLAYLIST
% Must get the playlist for each test in case individual
% tests require a different test list
% Conditional statement here handles used list tracking for
% this specific set of tests. We only want to add when we
% make it to the second test.
if i == 1
opts(i).specific.genPlaylist.Append2UsedList = true;
else
opts(i).specific.genPlaylist.Append2UsedList = false;
end %
[playlist, ~] = SIN_getPlaylist(opts(i));
% Every other test should inherit the mod_mixer from the
% test before it
if mod(i, 2) == 0
opts(i).player.mod_mixer = results(i-1).RunTime.player.mod_mixer;
end % if mod(i, 2) == 0
% Run the stage
results(i) = opts(i).player.player_handle(playlist, opts(i));
% Check for errors after every stage of test.
results(i) = errorCheck(results(i), playlist);
end % end
otherwise
% If we don't have any special instructions, run
% portaudio_adaptiveplay.
% Launch whatever the specified player is
% Need the loop in case we encounter multi-stage tests that
% do not have any special instructions.
for i=1:numel(opts)
% Create playlist. Do this for each stage of the test
% separately.
if i == 1
opts(i).specific.genPlaylist.Append2UsedList = true;
else
opts(i).specific.genPlaylist.Append2UsedList = false;
end %
[playlist, ~] = SIN_getPlaylist(opts(i));
% Run the stage
results(i) = opts(i).player.player_handle(playlist, opts(i));
% Check for errors after every stage of test.
results(i) = errorCheck(results(i), playlist);
end % for i=1:numel(opts)
end % switch/otherwise
% % Run Analysis on the fly for spot checking??
% % We'll generally want to do this, CWB thinks.
% if results(1).RunTime.analysis.run
% results = results(1).RunTime.analysis.fhand(results, results(1).RunTime.analysis.params);
% end % if results(1).analysis.run
%% Tell the user we're saving the data.
% Estimate the size of the results structure
var_info = whos('results');
mbytes = var_info.bytes/(1000^2);
display(['Saving results to file: ' opts(1).specific.saveData2mat]);
display(['Results are ' num2str(mbytes) ' MB in size']);
% Let the user know this could take a while if it's over a GB.
if mbytes > 1000
display('This might take a while. Please be patient');
end
% Save to results file
% Results should have whatever data are explicitly stored in the
% analysis phase as well.
SIN_saveResults(results);
% Assign results to the top-level workspace
assignin('base', 'results', results);
% Close remaining GUIs and make sure all errors are cleared
SIN_ClearErrors;
end % for t=1:length(testID)
% Save allresults structure instead??
function results = errorCheck(results, playlist)
%% DESCRIPTION:
%
% Function to check for and recover from errors following a test. If
% error has occurred, prompt user for input on whether to continue
% testing or to repeat the last test.
%
% INPUT:
%
% results: results structure from previous test
%
% playlist: playlist used for test
%
% OUTPUT:
%
% results: results structure after appropriate action taken (if any).
%
% Christopher W Bishop
% University of Washington
% 9/14
% Error checking
% - If the player encounters an error for any reason, then we need to
% give the user options on how to proceed.
if isfield(results.RunTime.player, 'state') && isequal(results.RunTime.player.state, 'error')
% First, run error clearing routine
% But don't close runSIN. Leave that open so the user can still run
% tests.
SIN_ClearErrors('closerunSIN', false);
% We can just continue with testing
resp = [];
while isempty(resp) || isempty(strfind('cr', lower(resp)))
resp = lower(input('Error encountered. Would you like to continue testing or repeat the last test/test segment? (C for continue, R for repeat)', 's'));
end % while isempty
% If user wants to continue anyway, then just return control to the
% calling function. Otherwise, repeat the test.
if resp == 'c'
return
elseif resp == 'r'
% Repeat the test
% Set analyes to false, since we'll run it again when we return
% results to SIN_runTest
opts = results.UserOptions;
opts.analysis.run = false;
results = SIN_runTest(opts, playlist);
end % resp == c
elseif ~isfield(results.RunTime.player, 'state')
warning('Player state unknown. Assuming no errors occurred');
end % if isequal ... error ...