annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirdesign/evaleach.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [y d2] = evaleach(d,single,name)
wolffd@0 2 % Top-down traversal of the design flowchart, at the beginning of the
wolffd@0 3 % evaluation phase.
wolffd@0 4 % Called by mirfunction, mireval, mirframe and mirsegment.
wolffd@0 5 % This is during that traversal that we check whether a chunk decomposition
wolffd@0 6 % needs to be performed or not, and carry out that chunk decomposition.
wolffd@0 7
wolffd@0 8 if nargin<3 || isempty(name)
wolffd@0 9 if not(ischar(d.method))
wolffd@0 10 name = func2str(d.method);
wolffd@0 11 end
wolffd@0 12 end
wolffd@0 13 if nargin<2
wolffd@0 14 single = 0;
wolffd@0 15 end
wolffd@0 16
wolffd@0 17 CHUNKLIM = mirchunklim;
wolffd@0 18 f = d.file;
wolffd@0 19 fr = d.frame;
wolffd@0 20 frnochunk = isfield(d.frame,'dontchunk');
wolffd@0 21 frchunkbefore = isfield(d.frame,'chunkbefore');
wolffd@0 22 sg = d.segment;
wolffd@0 23 sr = d.sampling;
wolffd@0 24 sr2 = d.resampling;
wolffd@0 25 w = d.size;
wolffd@0 26 lsz = w(2)-w(1)+1;
wolffd@0 27 len = lsz/sr;
wolffd@0 28 if ischar(sg)
wolffd@0 29 error('ERROR in MIREVAL: mirsegment of design object accepts only array of numbers as second argument.');
wolffd@0 30 end
wolffd@0 31 if not(isempty(sg))
wolffd@0 32 over = find(sg(2,:) > len);
wolffd@0 33 if not(isempty(over))
wolffd@0 34 sg = sg(:,1:over-1);
wolffd@0 35 end
wolffd@0 36 end
wolffd@0 37 a = d.argin;
wolffd@0 38 ch = d.chunk;
wolffd@0 39 chan = d.channel;
wolffd@0 40 specif = d.specif;
wolffd@0 41 if isaverage(specif)
wolffd@0 42 specif.eachchunk = 'Normal';
wolffd@0 43 end
wolffd@0 44
wolffd@0 45 if ischar(a)
wolffd@0 46 % The top-down traversal of the design flowchart now reaches the lowest
wolffd@0 47 % layer, i.e., audio file loading.
wolffd@0 48 % Now the actual evaluation will be carried out bottom-up.
wolffd@0 49
wolffd@0 50 if isempty(ch)
wolffd@0 51 % No chunk decomposition
wolffd@0 52 y = miraudio(f,'Now',[w(:)' 0 chan]);
wolffd@0 53 else
wolffd@0 54 % Chunk decomposition
wolffd@0 55 y = miraudio(f,'Now',[ch(1),ch(2) 0 chan]);
wolffd@0 56 end
wolffd@0 57 if not(isempty(d.postoption)) && d.postoption.mono
wolffd@0 58 y = miraudio(y,'Mono',1);
wolffd@0 59 end
wolffd@0 60 y = set(y,'AcrossChunks',get(d,'AcrossChunks'));
wolffd@0 61 d2 = d;
wolffd@0 62
wolffd@0 63 elseif d.chunkdecomposed && isempty(d.tmpfile)
wolffd@0 64 % Already in a chunk decomposition process
wolffd@0 65
wolffd@0 66 [y d2] = evalnow(d);
wolffd@0 67
wolffd@0 68 elseif isempty(fr) || frnochunk || not(isempty(sg)) %% WHAT ABOUT CHANNELS?
wolffd@0 69 % No frame or segment decomposition in the design to evaluate
wolffd@0 70 % (Or particular frame decomposition, where chunks are not distributed to children (frnochunk).)
wolffd@0 71
wolffd@0 72 if not(isfield(specif,'eachchunk')) ...
wolffd@0 73 || d.nochunk ...
wolffd@0 74 || (not(isempty(single)) && isnumeric(single) && single > 1 ...
wolffd@0 75 && isfield(specif,'combinechunk') ...
wolffd@0 76 && iscell(specif.combinechunk))
wolffd@0 77 chunks = [];
wolffd@0 78 elseif not(isempty(sg))
wolffd@0 79 meth = 'Segment ';
wolffd@0 80 if size(sg,1) == 1
wolffd@0 81 chunks = floor(sg(1:end-1)*sr)+1;
wolffd@0 82 chunks(2,:) = min( floor(sg(2:end)*sr)-1,lsz-1)+1;
wolffd@0 83 else
wolffd@0 84 chunks = floor(sg*sr);
wolffd@0 85 chunks(1,:) = chunks(1,:)+1;
wolffd@0 86 end
wolffd@0 87 else
wolffd@0 88 meth = 'Chunk ';
wolffd@0 89 if isempty(fr)
wolffd@0 90 if lsz > CHUNKLIM
wolffd@0 91 % The required memory exceed the max memory threshold.
wolffd@0 92 nch = ceil(lsz/CHUNKLIM);
wolffd@0 93 %%% TAKE INTO CONSIDERATION NUMBER OF CHANNELS; ETC...
wolffd@0 94 chunks = max(0,lsz-CHUNKLIM*(nch:-1:1))+w(1);
wolffd@0 95 chunks(2,:) = lsz-CHUNKLIM*(nch-1:-1:0)+w(1)-1;
wolffd@0 96 else
wolffd@0 97 chunks = [];
wolffd@0 98 end
wolffd@0 99 else
wolffd@0 100 chunks = compute_frames(fr,sr,sr2,w,lsz,CHUNKLIM,d.overlap);
wolffd@0 101 end
wolffd@0 102 end
wolffd@0 103
wolffd@0 104 if not(isempty(chunks))
wolffd@0 105 % The chunk decomposition is performed.
wolffd@0 106 nch = size(chunks,2);
wolffd@0 107 d = callbeforechunk(d,d,w,lsz); % Some optional initialisation
wolffd@0 108 tmp = [];
wolffd@0 109 if mirwaitbar
wolffd@0 110 h = waitbar(0,['Computing ' name]);
wolffd@0 111 else
wolffd@0 112 h = 0;
wolffd@0 113 end
wolffd@0 114 if not(isempty(d.tmpfile)) && d.tmpfile.fid == 0
wolffd@0 115 % When applicable, a new temporary file is created.
wolffd@0 116 d.tmpfile.fid = fopen('tmpfile.mirtoolbox','w');
wolffd@0 117 end
wolffd@0 118 tmpfile = [];
wolffd@0 119 if not(d.ascending)
wolffd@0 120 chunks = fliplr(chunks);
wolffd@0 121 end
wolffd@0 122
wolffd@0 123 afterpostoption = d.postoption; % Used only when:
wolffd@0 124 % - eachchunk is set to 'Normal',
wolffd@0 125 % - combinechunk is not set to 'Average', and
wolffd@0 126 % - no afterchunk field has been specified.
wolffd@0 127 % afterpostoption will be used for the final call
wolffd@0 128 % to the method after the chunk decomposition.
wolffd@0 129 method = d.method;
wolffd@0 130 if ischar(specif.eachchunk) && strcmpi(specif.eachchunk,'Normal')
wolffd@0 131 if not(isempty(d.postoption))
wolffd@0 132 pof = fieldnames(d.postoption);
wolffd@0 133 for o = 1:length(pof)
wolffd@0 134 if isfield(specif.option.(pof{o}),'chunkcombine')
wolffd@0 135 afterpostoption = rmfield(afterpostoption,pof{o});
wolffd@0 136 else
wolffd@0 137 d.postoption = rmfield(d.postoption,pof{o});
wolffd@0 138 end
wolffd@0 139 end
wolffd@0 140 end
wolffd@0 141 else
wolffd@0 142 method = specif.eachchunk;
wolffd@0 143 end
wolffd@0 144
wolffd@0 145 d2 = d;
wolffd@0 146 d2.method = method;
wolffd@0 147 y = {};
wolffd@0 148 for i = 1:size(chunks,2)
wolffd@0 149 disp([meth,num2str(i),'/',num2str(nch),'...'])
wolffd@0 150 d2 = set(d2,'Chunk',[chunks(1,i) chunks(2,i) (i == size(chunks,2))]);
wolffd@0 151
wolffd@0 152 if not(ischar(specif.eachchunk) && ...
wolffd@0 153 strcmpi(specif.eachchunk,'Normal'))
wolffd@0 154 if frnochunk
wolffd@0 155 d2.postoption = 0;
wolffd@0 156 else
wolffd@0 157 diffchunks = diff(chunks); % Usual chunk size
wolffd@0 158 d2.postoption = max(diffchunks) - diffchunks(i);
wolffd@0 159 % Reduction of the current chunk size to be taken into
wolffd@0 160 % consideration in mirspectrum, for instance, using
wolffd@0 161 % zeropadding
wolffd@0 162 end
wolffd@0 163 end
wolffd@0 164
wolffd@0 165 d2 = set(d2,'InterChunk',tmp);
wolffd@0 166 d2.chunkdecomposed = 1;
wolffd@0 167
wolffd@0 168 [ss d3] = evalnow(d2);
wolffd@0 169
wolffd@0 170 if iscell(ss) && not(isempty(ss))
wolffd@0 171 tmp = get(ss{1},'InterChunk');
wolffd@0 172 elseif isstruct(ss)
wolffd@0 173 tmp = [];
wolffd@0 174 else
wolffd@0 175 tmp = get(ss,'InterChunk');
wolffd@0 176 end
wolffd@0 177
wolffd@0 178 % d2 is like d3 except that its argument is now evaluated.
wolffd@0 179 d3.postoption = d.postoption; % Pas joli joli
wolffd@0 180 d3.method = method;
wolffd@0 181 d2 = d3; % This new argument is transfered to d
wolffd@0 182
wolffd@0 183 y = combinechunk_noframe(y,ss,sg,i,d2,chunks,single);
wolffd@0 184
wolffd@0 185 clear ss
wolffd@0 186 if h
wolffd@0 187 if not(d.ascending)
wolffd@0 188 close(h)
wolffd@0 189 h = waitbar((chunks(1,i)-chunks(1,end))/chunks(2,1),...
wolffd@0 190 ['Computing ' func2str(d.method) ' (backward)']);
wolffd@0 191 else
wolffd@0 192 waitbar((chunks(2,i)-chunks(1))/chunks(end),h)
wolffd@0 193 end
wolffd@0 194 end
wolffd@0 195 end
wolffd@0 196
wolffd@0 197 y = afterchunk_noframe(y,lsz,d,afterpostoption,d2);
wolffd@0 198 % Final operations to be executed after the chunk decomposition
wolffd@0 199
wolffd@0 200 if isa(d,'mirstruct') && ...
wolffd@0 201 (isempty(d.frame) || isfield(d.frame,'dontchunk'))
wolffd@0 202 y = evalbranches(d,y);
wolffd@0 203 end
wolffd@0 204 if h
wolffd@0 205 close(h)
wolffd@0 206 end
wolffd@0 207 drawnow
wolffd@0 208
wolffd@0 209 else
wolffd@0 210 % No chunk decomposition
wolffd@0 211 [y d2] = evalnow(d);
wolffd@0 212 if isa(d,'mirstruct') && isfield(d.frame,'dontchunk')
wolffd@0 213 y = evalbranches(d,y);
wolffd@0 214 end
wolffd@0 215 end
wolffd@0 216 elseif d.nochunk
wolffd@0 217 [y d2] = evalnow(d);
wolffd@0 218 else
wolffd@0 219 % Frame decomposition in the design to be evaluated.
wolffd@0 220 chunks = compute_frames(fr,sr,sr2,w,lsz,CHUNKLIM,d.overlap);
wolffd@0 221 if size(chunks,2)>1
wolffd@0 222 % The chunk decomposition is performed.
wolffd@0 223 if mirwaitbar
wolffd@0 224 h = waitbar(0,['Computing ' name]);
wolffd@0 225 else
wolffd@0 226 h = 0;
wolffd@0 227 end
wolffd@0 228 inter = [];
wolffd@0 229 d = set(d,'FrameDecomposition',1);
wolffd@0 230 d2 = d;
wolffd@0 231 nch = size(chunks,2);
wolffd@0 232 y = {};
wolffd@0 233
wolffd@0 234 if frchunkbefore
wolffd@0 235 d2after = d2;
wolffd@0 236 d2.method = d2.argin.method;
wolffd@0 237 d2.option = d2.argin.option;
wolffd@0 238 d2.postoption = d2.argin.postoption;
wolffd@0 239 d2.argin = d2.argin.argin;
wolffd@0 240 end
wolffd@0 241
wolffd@0 242 for fri = 1:nch % For each chunk...
wolffd@0 243 disp(['Chunk ',num2str(fri),'/',num2str(nch),'...'])
wolffd@0 244 d2 = set(d2,'Chunk',chunks(:,fri)');
wolffd@0 245 d2 = set(d2,'InterChunk',inter);
wolffd@0 246 %d2.postoption = [];
wolffd@0 247 [res d2] = evalnow(d2);
wolffd@0 248 if not(isempty(res))
wolffd@0 249 if iscell(res)
wolffd@0 250 inter = get(res{1},'InterChunk');
wolffd@0 251 elseif not(isstruct(res))
wolffd@0 252 inter = get(res,'InterChunk');
wolffd@0 253 res = {res};
wolffd@0 254 end
wolffd@0 255 end
wolffd@0 256
wolffd@0 257 y = combinechunk_frame(y,res,d2,fri);
wolffd@0 258 if h
wolffd@0 259 waitbar(chunks(2,fri)/chunks(end),h);
wolffd@0 260 end
wolffd@0 261 end
wolffd@0 262
wolffd@0 263 if frchunkbefore
wolffd@0 264 y = d2after.method(y,d2after.option,d2after.postoption);
wolffd@0 265 end
wolffd@0 266
wolffd@0 267 if isa(d,'mirstruct') && get(d,'Stat')
wolffd@0 268 y = mirstat(y);
wolffd@0 269 end
wolffd@0 270 if h
wolffd@0 271 close(h)
wolffd@0 272 end
wolffd@0 273 else
wolffd@0 274 % No chunk decomposition
wolffd@0 275 [y d2] = evalnow(d);
wolffd@0 276 end
wolffd@0 277 end
wolffd@0 278
wolffd@0 279
wolffd@0 280 if iscell(y)
wolffd@0 281 for i = 1:length(y)
wolffd@0 282 if not(isempty(y{i}) || isstruct(y{i}))
wolffd@0 283 if iscell(y{i})
wolffd@0 284 for j = 1:length(y{i})
wolffd@0 285 y{i}{j} = set(y{i}{j},'InterChunk',[]);
wolffd@0 286 end
wolffd@0 287 else
wolffd@0 288 y{i} = set(y{i},'InterChunk',[]);
wolffd@0 289 end
wolffd@0 290 end
wolffd@0 291 end
wolffd@0 292 end
wolffd@0 293
wolffd@0 294
wolffd@0 295 function chunks = compute_frames(fr,sr,sr2,w,lsz,CHUNKLIM,frov)
wolffd@0 296 if strcmpi(fr.length.unit,'s')
wolffd@0 297 fl = fr.length.val*sr;
wolffd@0 298 fl2 = fr.length.val*sr2;
wolffd@0 299 elseif strcmpi(fr.length.unit,'sp')
wolffd@0 300 fl = fr.length.val;
wolffd@0 301 fl2 = fl;
wolffd@0 302 end
wolffd@0 303 if strcmpi(fr.hop.unit,'/1')
wolffd@0 304 h = fr.hop.val*fl;
wolffd@0 305 h2 = fr.hop.val*fl2;
wolffd@0 306 elseif strcmpi(fr.hop.unit,'%')
wolffd@0 307 h = fr.hop.val*fl*.01;
wolffd@0 308 h2 = fr.hop.val*fl2*.01;
wolffd@0 309 elseif strcmpi(fr.hop.unit,'s')
wolffd@0 310 h = fr.hop.val*sr;
wolffd@0 311 h2 = fr.hop.val*sr2;
wolffd@0 312 elseif strcmpi(fr.hop.unit,'sp')
wolffd@0 313 h = fr.hop.val;
wolffd@0 314 h2 = fr.hop.val;
wolffd@0 315 elseif strcmpi(fr.hop.unit,'Hz')
wolffd@0 316 h = sr/fr.hop.val;
wolffd@0 317 h2 = sr2/fr.hop.val;
wolffd@0 318 end
wolffd@0 319 n = floor((lsz-fl)/h)+1; % Number of frames
wolffd@0 320 if n < 1
wolffd@0 321 %warning('WARNING IN MIRFRAME: Frame length longer than total sequence size. No frame decomposition.');
wolffd@0 322 fp = w;
wolffd@0 323 fp2 = (w-1)/sr*sr2+1;
wolffd@0 324 else
wolffd@0 325 st = floor(((1:n)-1)*h)+w(1);
wolffd@0 326 st2 = floor(((1:n)-1)*h2)+w(1);
wolffd@0 327 fp = [st; floor(st+fl-1)];
wolffd@0 328 fp(:,fp(2,:)>w(2)) = [];
wolffd@0 329 fp2 = [st2; floor(st2+fl2-1)];
wolffd@0 330 fp2(:,fp2(2,:)>(w(2)-w(1))/sr*sr2+w(2)) = [];
wolffd@0 331 end
wolffd@0 332 fpe = (fp2-1)/sr2-(fp-1)/sr; %Rounding error if resampling
wolffd@0 333 fpsz = (fp(2,1)-fp(1,1)) * n; % Total number of samples
wolffd@0 334 fpsz2 = (fp2(2,1)-fp2(1,1)) * n; % Total number of samples
wolffd@0 335 if max(fpsz,fpsz2) > CHUNKLIM
wolffd@0 336 % The required memory exceed the max memory threshold.
wolffd@0 337 nfr = size(fp,2); % Total number of frames
wolffd@0 338 frch = max(ceil(CHUNKLIM/(fp(2,1)-fp(1,1))),2); % Number of frames per chunk
wolffd@0 339 frch = max(frch,frov*2);
wolffd@0 340 [unused cut] = min(abs(fpe(1,frch:-1:1)));
wolffd@0 341 %frch = frch - cut;
wolffd@0 342 % this correspond to the frame with less rounding error
wolffd@0 343 nch = ceil((nfr-frch)/(frch-frov))+1; % Number of chunks
wolffd@0 344 chbeg = (frch-frov)*(0:nch-1)+1; % First frame in the chunk
wolffd@0 345 chend = (frch-frov)*(0:nch-1)+frch; % Last frame in the chunk
wolffd@0 346 chend = min(chend,nfr);
wolffd@0 347 if frov > 1
wolffd@0 348 chbeg = chend-frch+1;
wolffd@0 349 end
wolffd@0 350 chunks = [fp(1,chbeg) ; fp(2,chend)+1]; % After resampling, one sample may be missing, leading to a complete frame drop.
wolffd@0 351 chunks(end) = min(chunks(end),fp(end)); % Last chunk should not extend beyond audio size.
wolffd@0 352 else
wolffd@0 353 chunks = [];
wolffd@0 354 end
wolffd@0 355
wolffd@0 356
wolffd@0 357 function res = combinechunk_frame(old,new,d2,fri)
wolffd@0 358 if isempty(mirgetdata(new))
wolffd@0 359 res = old;
wolffd@0 360 return
wolffd@0 361 end
wolffd@0 362 if isstruct(old)
wolffd@0 363 f = fields(old);
wolffd@0 364 for i = 1:length(f)
wolffd@0 365 res.(f{i}) = combinechunk_frame(old.(f{i}),new.(f{i}),d2,fri);
wolffd@0 366 end
wolffd@0 367 return
wolffd@0 368 end
wolffd@0 369 if fri == 1
wolffd@0 370 res = new;
wolffd@0 371 elseif isfield(d2,'specif') && isfield(d2.specif,'combineframes')
wolffd@0 372 res = d2.specif.combineframes(old{1},new{1});
wolffd@0 373 else
wolffd@0 374 res = combineframes(old,new);
wolffd@0 375 end
wolffd@0 376
wolffd@0 377
wolffd@0 378 function res = combinechunk_noframe(old,new,sg,i,d2,chunks,single)
wolffd@0 379 if isempty(new)
wolffd@0 380 res = {};
wolffd@0 381 return
wolffd@0 382 end
wolffd@0 383 if isempty(mirgetdata(new))
wolffd@0 384 res = old;
wolffd@0 385 return
wolffd@0 386 end
wolffd@0 387 if not(iscell(new))
wolffd@0 388 new = {new};
wolffd@0 389 end
wolffd@0 390 if not(iscell(old))
wolffd@0 391 old = {old};
wolffd@0 392 end
wolffd@0 393 if not(isempty(old)) && isstruct(old{1})
wolffd@0 394 f = fields(old{1});
wolffd@0 395 for j = 1:length(f)
wolffd@0 396 index.type = '.';
wolffd@0 397 index.subs = f{j};
wolffd@0 398 res.(f{j}) = combinechunk_noframe(old{1}.(f{j}),new{1}.(f{j}),...
wolffd@0 399 sg,i,subsref(d2,index),chunks,single);
wolffd@0 400 end
wolffd@0 401 return
wolffd@0 402 end
wolffd@0 403 if ischar(single) && not(isempty(old))
wolffd@0 404 old = {old{1}};
wolffd@0 405 end
wolffd@0 406 if isempty(sg)
wolffd@0 407 if isaverage(d2.specif)
wolffd@0 408 % Measure total size for later averaging
wolffd@0 409 if iscell(new)
wolffd@0 410 new1 = new{1};
wolffd@0 411 else
wolffd@0 412 new1 = new;
wolffd@0 413 end
wolffd@0 414 dnew = get(new1,'Data');
wolffd@0 415 dnew = mircompute(@multweight,dnew,chunks(2,i)-chunks(1,i)+1);
wolffd@0 416 if iscell(new)
wolffd@0 417 new{1} = set(new1,'Data',dnew);
wolffd@0 418 else
wolffd@0 419 new = set(new1,'Data',dnew);
wolffd@0 420 end
wolffd@0 421 end
wolffd@0 422 %tmp = get(new{1},'InterChunk');
wolffd@0 423 if not(isempty(d2.tmpfile)) && d2.tmpfile.fid > 0
wolffd@0 424 % If temporary file is used, chunk results are written
wolffd@0 425 % in the file
wolffd@0 426 if i < size(chunks,2)
wolffd@0 427 ds = get(new{1},'Data');
wolffd@0 428 ps = get(new{1},'Pos');
wolffd@0 429 % ftell(d2.tmpfile.fid)
wolffd@0 430 count = fwrite(d2.tmpfile.fid,ds{1}{1},'double');
wolffd@0 431 count = fwrite(d2.tmpfile.fid,ps{1}{1},'double');
wolffd@0 432 % ftell(d2.tmpfile.fid)
wolffd@0 433 clear ds ps
wolffd@0 434 end
wolffd@0 435 res = new;
wolffd@0 436 else
wolffd@0 437 % Else, chunk results are directly combined in active
wolffd@0 438 % memory
wolffd@0 439 if i == 1
wolffd@0 440 res = new;
wolffd@0 441 else
wolffd@0 442 if isfield(d2.specif,'combinechunk')
wolffd@0 443 if not(iscell(d2.specif.combinechunk))
wolffd@0 444 method = {d2.specif.combinechunk};
wolffd@0 445 else
wolffd@0 446 method = d2.specif.combinechunk;
wolffd@0 447 end
wolffd@0 448 for z = 1:length(old)
wolffd@0 449 if isframed(old{z})
wolffd@0 450 res(z) = combineframes(old{z},new{z});
wolffd@0 451 elseif ischar(method{z})
wolffd@0 452 if strcmpi(method{z},'Concat')
wolffd@0 453 res{z} = concatchunk(old{z},new{z},d2.ascending);
wolffd@0 454 elseif strcmpi(method{z},'Average')
wolffd@0 455 res{z} = sumchunk(old{z},new{z});
wolffd@0 456 else
wolffd@0 457 error(['SYNTAX ERROR: ',...
wolffd@0 458 method{z},...
wolffd@0 459 ' is not a known keyword for combinechunk.']);
wolffd@0 460 end
wolffd@0 461 else
wolffd@0 462 res{z} = method{z}(old{z},new{z});
wolffd@0 463 end
wolffd@0 464 end
wolffd@0 465 else
wolffd@0 466 for z = 1:length(old)
wolffd@0 467 if isframed(old{z})
wolffd@0 468 res(z) = combineframes(old{z},new{z});
wolffd@0 469 else
wolffd@0 470 mirerror('MIREVAL','Chunk recombination in non-framed mode is not available for all features yet. Please turn off the chunk decomposition.');
wolffd@0 471 end
wolffd@0 472 end
wolffd@0 473 end
wolffd@0 474 end
wolffd@0 475 end
wolffd@0 476 else
wolffd@0 477 if i == 1
wolffd@0 478 res = new;
wolffd@0 479 else
wolffd@0 480 for z = 1:length(old)
wolffd@0 481 res{z} = combinesegment(old{z},new{z});
wolffd@0 482 end
wolffd@0 483 end
wolffd@0 484 end
wolffd@0 485
wolffd@0 486
wolffd@0 487 function res = afterchunk_noframe(input,lsz,d,afterpostoption,d2)
wolffd@0 488 if isstruct(input)
wolffd@0 489 %mirerror('MIREVAL','Sorry, mirstruct only accepts frame-decomposed objects as ''tmp'' fields.');
wolffd@0 490 res = input;
wolffd@0 491 %f = fields(input);
wolffd@0 492 %for i = 1:length(f)
wolffd@0 493 % index.type = '.';
wolffd@0 494 % index.subs = f{i};
wolffd@0 495 % res.(f{i}) = afterchunk_noframe(input.(f{i}),lsz,...
wolffd@0 496 % subsref(d,index),afterpostoption,subsref(d2,index));
wolffd@0 497 %end
wolffd@0 498 return
wolffd@0 499 end
wolffd@0 500 if isfield(d2.specif,'afterchunk')
wolffd@0 501 res{1} = d2.specif.afterchunk(input{1},lsz,d.postoption);
wolffd@0 502 elseif isaverage(d2.specif)
wolffd@0 503 res{1} = divideweightchunk(input{1},lsz);
wolffd@0 504 elseif not(isempty(afterpostoption)) && isempty(d2.tmpfile)
wolffd@0 505 res{1} = d.method(input{1},[],afterpostoption);
wolffd@0 506 else
wolffd@0 507 res = input;
wolffd@0 508 end
wolffd@0 509 if not(isempty(d2.tmpfile))
wolffd@0 510 adr = ftell(d2.tmpfile.fid);
wolffd@0 511 fclose(d2.tmpfile.fid);
wolffd@0 512 ytmpfile.fid = fopen('tmpfile.mirtoolbox');
wolffd@0 513 fseek(ytmpfile.fid,adr,'bof');
wolffd@0 514 ytmpfile.data = input{1};
wolffd@0 515 ytmpfile.layer = 0;
wolffd@0 516 res{1} = set(input{1},'TmpFile',ytmpfile);
wolffd@0 517 end
wolffd@0 518
wolffd@0 519
wolffd@0 520 function old = combineframes(old,new)
wolffd@0 521 if not(iscell(old))
wolffd@0 522 old = {old};
wolffd@0 523 end
wolffd@0 524 if not(iscell(new))
wolffd@0 525 new = {new};
wolffd@0 526 end
wolffd@0 527 for var = 1:length(new)
wolffd@0 528 ov = old{var};
wolffd@0 529 nv = new{var};
wolffd@0 530 if isa(ov,'mirscalar')
wolffd@0 531 ov = combinedata(ov,nv,'Data');
wolffd@0 532 ov = combinedata(ov,nv,'Mode');
wolffd@0 533 if isa(ov,'mirpitch')
wolffd@0 534 ov = combinedata(ov,nv,'Amplitude');
wolffd@0 535 end
wolffd@0 536 else
wolffd@0 537 if isa(ov,'mirtemporal')
wolffd@0 538 [ov omatch nmatch] = combinedata(ov,nv,'Time',[],[],@modiftime);
wolffd@0 539 else
wolffd@0 540 [ov omatch nmatch] = combinedata(ov,nv,'Pos',[],[]);
wolffd@0 541 if isa(ov,'mirspectrum')
wolffd@0 542 [ov omatch nmatch] = combinedata(ov,nv,'Phase',[],[]);
wolffd@0 543 end
wolffd@0 544 end
wolffd@0 545 ov = combinedata(ov,nv,'Data',omatch,nmatch);
wolffd@0 546 end
wolffd@0 547 ov = combinedata(ov,nv,'FramePos');
wolffd@0 548 ov = combinedata(ov,nv,'PeakPos');
wolffd@0 549 ov = combinedata(ov,nv,'PeakVal');
wolffd@0 550 ov = combinedata(ov,nv,'PeakMode');
wolffd@0 551 old{var} = ov;
wolffd@0 552 end
wolffd@0 553
wolffd@0 554
wolffd@0 555 function [ov omatch nmatch] = combinedata(ov,nv,key,omatch,nmatch,modifdata)
wolffd@0 556 if isstruct(ov)
wolffd@0 557 omatch = [];
wolffd@0 558 nmatch = [];
wolffd@0 559 f = fields(ov);
wolffd@0 560 for i = 1:length(f)
wolffd@0 561 ov.(f{i}) = combinedata(ov.(f{i}),nv.(f{i}),key);
wolffd@0 562 end
wolffd@0 563 return
wolffd@0 564 end
wolffd@0 565 odata = get(ov,key);
wolffd@0 566 if isempty(odata) || isempty(odata{1})
wolffd@0 567 return
wolffd@0 568 end
wolffd@0 569 odata = odata{1};
wolffd@0 570 if iscell(odata)
wolffd@0 571 if ischar(odata{1})
wolffd@0 572 return
wolffd@0 573 else
wolffd@0 574 odata = odata{1};
wolffd@0 575 end
wolffd@0 576 end
wolffd@0 577 ndata = get(nv,key);
wolffd@0 578 ndata = ndata{1};
wolffd@0 579 if iscell(ndata)
wolffd@0 580 ndata = ndata{1};
wolffd@0 581 end
wolffd@0 582 if nargin>3
wolffd@0 583 if isempty(omatch)
wolffd@0 584 ol = size(odata,1);
wolffd@0 585 nl = size(ndata,1);
wolffd@0 586 unmatch = ol-nl;
wolffd@0 587 if unmatch>0
wolffd@0 588 [unused idx] = min(odata(1:1+unmatch,1,1)-ndata(1));
wolffd@0 589 omatch = idx:idx+nl-1;
wolffd@0 590 nmatch = 1:nl;
wolffd@0 591 elseif unmatch<0
wolffd@0 592 [unused idx] = min(ndata(1:1-unmatch,1,1)-odata(1));
wolffd@0 593 nmatch = idx:idx+ol-1;
wolffd@0 594 omatch = 1:ol;
wolffd@0 595 else
wolffd@0 596 nmatch = 1:nl;
wolffd@0 597 omatch = 1:ol;
wolffd@0 598 end
wolffd@0 599 end
wolffd@0 600 odata(omatch,end+1:end+size(ndata,2),:,:) = ndata(nmatch,:,:,:); %4.D for keysom
wolffd@0 601 else
wolffd@0 602 odata(:,end+1:end+size(ndata,2),:,:) = ndata;
wolffd@0 603 end
wolffd@0 604 ov = set(ov,key,{{odata}}); %{odata} for warped chromagram for instance....
wolffd@0 605
wolffd@0 606
wolffd@0 607 function d = modiftime(d,p)
wolffd@0 608 d = d + p;
wolffd@0 609
wolffd@0 610
wolffd@0 611 function [y d] = evalnow(d)
wolffd@0 612 % Go one step further in the top-down evaluation initialisation
wolffd@0 613 argin = d.argin;
wolffd@0 614 if not(iscell(argin))
wolffd@0 615 argin = {argin};
wolffd@0 616 end
wolffd@0 617 for i = 1:length(argin)
wolffd@0 618 a = argin{i};
wolffd@0 619 if not(d.ascending)
wolffd@0 620 a.ascending = 0;
wolffd@0 621 end
wolffd@0 622 if isa(a,'mirdata')
wolffd@0 623 % Input already computed
wolffd@0 624 tmpfile = get(a,'TmpFile');
wolffd@0 625 if not(isempty(tmpfile)) && tmpfile.fid > 0
wolffd@0 626 % The input can be read from the temporary file
wolffd@0 627 ch = get(d,'Chunk');
wolffd@0 628 a = tmpfile.data;
wolffd@0 629 a = set(a,'InterChunk',get(d,'InterChunk'),'TmpFile',tmpfile);
wolffd@0 630 channels = get(a,'Channels');
wolffd@0 631 channels = length(channels{1});
wolffd@0 632 if not(channels)
wolffd@0 633 channels = 1;
wolffd@0 634 end
wolffd@0 635 size = (ch(2)-ch(1)+1);
wolffd@0 636 current = ftell(tmpfile.fid);
wolffd@0 637 fseek(tmpfile.fid,current-size*(channels+1)*8,'bof');
wolffd@0 638 %ftell(tmpfile.fid)
wolffd@0 639 [data count] = fread(tmpfile.fid,[size,channels],'double');
wolffd@0 640 %count
wolffd@0 641 data = reshape(data,[size,1,channels]);
wolffd@0 642 [pos count] = fread(tmpfile.fid,size,'double');
wolffd@0 643 %count
wolffd@0 644 % ftell(tmpfile.fid)
wolffd@0 645 fseek(tmpfile.fid,current-size*(channels+1)*8,'bof');
wolffd@0 646 a = set(a,'Data',{{data}},'Pos',{{pos}});
wolffd@0 647 if ch(3)
wolffd@0 648 fclose(tmpfile.fid);
wolffd@0 649 delete('tmpfile.mirtoolbox');
wolffd@0 650 end
wolffd@0 651 argin{i} = a;
wolffd@0 652 end
wolffd@0 653 elseif isa(a,'mirdesign')
wolffd@0 654 if isempty(a.stored)
wolffd@0 655 % The design parameters are transfered to the previous component
wolffd@0 656 % in the design process
wolffd@0 657 a.size = d.size;
wolffd@0 658 a.chunk = d.chunk;
wolffd@0 659 a.file = d.file;
wolffd@0 660 a.channel = d.channel;
wolffd@0 661 a.eval = 1;
wolffd@0 662 a.interchunk = d.interchunk;
wolffd@0 663 a.sampling = d.sampling;
wolffd@0 664 if isstruct(d.frame) && isfield(d.frame,'decomposition') ...
wolffd@0 665 && not(isempty(d.frame.decomposition))
wolffd@0 666 a.chunkdecomposed = 1;
wolffd@0 667 else
wolffd@0 668 a.chunkdecomposed = d.chunkdecomposed;
wolffd@0 669 end
wolffd@0 670 if not(isempty(d.frame)) && ...
wolffd@0 671 not(strcmp(func2str(d.method),'mirframe'))
wolffd@0 672 a.frame = d.frame;
wolffd@0 673 end
wolffd@0 674 a.ready = 1;
wolffd@0 675 a.acrosschunks = d.acrosschunks;
wolffd@0 676 a.index = d.index;
wolffd@0 677 argin{i} = a;
wolffd@0 678 else
wolffd@0 679 % Variable already calculated
wolffd@0 680 tmp = get(d,'Struct');
wolffd@0 681 if not(isempty(tmp))
wolffd@0 682 for j = 1:length(a.stored) % (if modified, modify also mirframe)
wolffd@0 683 stored = a.stored{j};
wolffd@0 684 if iscell(stored)
wolffd@0 685 if length(stored)>1
wolffd@0 686 tmp = tmp{stored{1},stored{2}};
wolffd@0 687 else
wolffd@0 688 tmp = tmp{stored{1}};
wolffd@0 689 end
wolffd@0 690 else
wolffd@0 691 tmp = getfield(tmp,stored);
wolffd@0 692 end
wolffd@0 693 end
wolffd@0 694 if iscell(tmp)
wolffd@0 695 tmp = tmp{1};
wolffd@0 696 end
wolffd@0 697 else
wolffd@0 698 mirerror('evaleach','THERE is a problem..');
wolffd@0 699 end
wolffd@0 700 argin{i} = tmp;
wolffd@0 701 end
wolffd@0 702 end
wolffd@0 703 end
wolffd@0 704 if not(iscell(d.argin))
wolffd@0 705 argin = argin{1};
wolffd@0 706 end
wolffd@0 707 d.option.struct = get(d,'Struct');
wolffd@0 708 if iscell(d.postoption)
wolffd@0 709 [y argin] = d.method(argin,d.option,d.postoption{:});
wolffd@0 710 else
wolffd@0 711 [y argin] = d.method(argin,d.option,d.postoption);
wolffd@0 712 end
wolffd@0 713 d = set(d,'Argin',argin);
wolffd@0 714 if isa(d,'mirstruct') && not(isfield(d.frame,'dontchunk')) && isempty(get(d,'Chunk'))
wolffd@0 715 y = evalbranches(d,y);
wolffd@0 716 end
wolffd@0 717
wolffd@0 718
wolffd@0 719 function z = evalbranches(d,y)
wolffd@0 720 % For complex flowcharts, now that the first temporary variable (y) has been
wolffd@0 721 % computed, the dependent features (d) should be evaluated as well.
wolffd@0 722 branch = get(d,'Data');
wolffd@0 723
wolffd@0 724 for i = 1:length(branch)
wolffd@0 725 if isa(branch{i},'mirdesign') && get(branch{i},'NoChunk') == 1
wolffd@0 726 % if the value is 2, it is OK.
wolffd@0 727 %mirerror('mireval','Flowchart badly designed: mirstruct should not be used if one or several final variables do not accept chunk decomposition.');
wolffd@0 728 end
wolffd@0 729 end
wolffd@0 730
wolffd@0 731 fields = get(d,'Fields');
wolffd@0 732 z = struct;
wolffd@0 733 tmp = get(d,'Tmp');
wolffd@0 734 for i = 1:length(branch)
wolffd@0 735 z.(fields{i}) = evalbranch(branch{i},tmp,y);
wolffd@0 736 end
wolffd@0 737 if get(d,'Stat') && isempty(get(d,'Chunk'))
wolffd@0 738 z = mirstat(z,'FileNames',0);
wolffd@0 739 end
wolffd@0 740
wolffd@0 741
wolffd@0 742 function b = evalbranch(b,d,y)
wolffd@0 743 % We need to evaluate the branch reaching the current node (b) from the parent
wolffd@0 744 % corresponding to the temporary variable (d),
wolffd@0 745
wolffd@0 746 if iscell(b)
wolffd@0 747 mirerror('MIREVAL','Sorry, forked branching of temporary variable cannnot be evaluated in current version of MIRtoolbox.');
wolffd@0 748 end
wolffd@0 749 if isstruct(b)
wolffd@0 750 % Subtrees are evaluated branch after branch.
wolffd@0 751 f = fields(b);
wolffd@0 752 for i = 1:length(f)
wolffd@0 753 b.(f{i}) = evalbranch(b.(f{i}),d,y);
wolffd@0 754 end
wolffd@0 755 return
wolffd@0 756 end
wolffd@0 757 if isequal(b,d)
wolffd@0 758 %% Does it happen ever??
wolffd@0 759 b = y;
wolffd@0 760 return
wolffd@0 761 end
wolffd@0 762 if not(isa(b,'mirdesign'))
wolffd@0 763 mirerror('MIRSTRUCT','In the mirstruct object you defined, the final output should only depend on ''tmp'' variables, and should not therefore reuse the ''Design'' keyword.');
wolffd@0 764 end
wolffd@0 765 v = get(b,'Stored');
wolffd@0 766 if length(v)>1 && ischar(v{2})
wolffd@0 767 %
wolffd@0 768 f = fields(d);
wolffd@0 769 for i = 1:length(f)
wolffd@0 770 if strcmpi(v{2},f)
wolffd@0 771 b = y; % OK, now the temporary variable has been found.
wolffd@0 772 % End of recursion.
wolffd@0 773 return
wolffd@0 774 end
wolffd@0 775 end
wolffd@0 776 end
wolffd@0 777
wolffd@0 778 argin = evalbranch(get(b,'Argin'),d,y); % Recursion one parent up
wolffd@0 779
wolffd@0 780 % The operation corresponding to the branch from the parent to the node
wolffd@0 781 % is finally evaluated.
wolffd@0 782 if iscell(b.postoption)
wolffd@0 783 b = b.method(argin,b.option,b.postoption{:});
wolffd@0 784 else
wolffd@0 785 b = b.method(argin,b.option,b.postoption);
wolffd@0 786 end
wolffd@0 787
wolffd@0 788
wolffd@0 789 function res = isaverage(specif)
wolffd@0 790 res = isfield(specif,'combinechunk') && ...
wolffd@0 791 ((ischar(specif.combinechunk) && ...
wolffd@0 792 strcmpi(specif.combinechunk,'Average')) || ...
wolffd@0 793 (iscell(specif.combinechunk) && ...
wolffd@0 794 ischar(specif.combinechunk{1}) && ...
wolffd@0 795 strcmpi(specif.combinechunk{1},'Average')));
wolffd@0 796
wolffd@0 797
wolffd@0 798 function d0 = callbeforechunk(d0,d,w,lsz)
wolffd@0 799 % If necessary, the chunk decomposition is performed a first time for
wolffd@0 800 % initialisation purposes.
wolffd@0 801 % Currently used only for miraudio(...,'Normal')
wolffd@0 802 if not(ischar(d)) && not(iscell(d))
wolffd@0 803 specif = d.specif;
wolffd@0 804 CHUNKLIM = mirchunklim;
wolffd@0 805 nch = ceil(lsz/CHUNKLIM);
wolffd@0 806 if isfield(specif,'beforechunk') ...
wolffd@0 807 && ((isfield(d.option,specif.beforechunk{2}) ...
wolffd@0 808 && d.option.(specif.beforechunk{2})) ...
wolffd@0 809 || (isfield(d.postoption,specif.beforechunk{2}) ...
wolffd@0 810 && d.postoption.(specif.beforechunk{2})) )
wolffd@0 811 if mirwaitbar
wolffd@0 812 h = waitbar(0,['Preparing ' func2str(d.method)]);
wolffd@0 813 else
wolffd@0 814 h = 0;
wolffd@0 815 end
wolffd@0 816 for i = 1:nch
wolffd@0 817 disp(['Chunk ',num2str(i),'/',num2str(nch),'...'])
wolffd@0 818 chbeg = CHUNKLIM*(i-1);
wolffd@0 819 chend = CHUNKLIM*i-1;
wolffd@0 820 d2 = set(d,'Size',d0.size,'File',d0.file,...
wolffd@0 821 'Chunk',[chbeg+w(1) min(chend,lsz-1)+w(1)]);
wolffd@0 822 d2.method = specif.beforechunk{1};
wolffd@0 823 d2.postoption = {chend-lsz};
wolffd@0 824 d2.chunkdecomposed = 1;
wolffd@0 825 [tmp d] = evalnow(d2);
wolffd@0 826 d0 = set(d0,'AcrossChunks',tmp);
wolffd@0 827 if h
wolffd@0 828 waitbar(chend/lsz,h)
wolffd@0 829 end
wolffd@0 830 end
wolffd@0 831 if h
wolffd@0 832 close(h);
wolffd@0 833 end
wolffd@0 834 drawnow
wolffd@0 835 else
wolffd@0 836 d0 = callbeforechunk(d0,d.argin,w,lsz);
wolffd@0 837 end
wolffd@0 838 end
wolffd@0 839
wolffd@0 840
wolffd@0 841 function y = concatchunk(old,new,ascending)
wolffd@0 842 do = get(old,'Data');
wolffd@0 843 dn = get(new,'Data');
wolffd@0 844 fpo = get(old,'FramePos');
wolffd@0 845 fpn = get(new,'FramePos');
wolffd@0 846 if isa(old,'mirscalar')
wolffd@0 847 y = set(old,'Data',{{[do{1}{1},dn{1}{1}]}},...
wolffd@0 848 'FramePos',{{[fpo{1}{1},fpn{1}{1}]}});
wolffd@0 849 else
wolffd@0 850 to = get(old,'Pos');
wolffd@0 851 tn = get(new,'Pos');
wolffd@0 852 if ascending
wolffd@0 853 y = set(old,'Data',{{[do{1}{1};dn{1}{1}]}},...
wolffd@0 854 'Pos',{{[to{1}{1};tn{1}{1}]}},...
wolffd@0 855 'FramePos',{{[fpo{1}{1},fpn{1}{1}]}});
wolffd@0 856 else
wolffd@0 857 y = set(old,'Data',{{[dn{1}{1};do{1}{1}]}},...
wolffd@0 858 'Pos',{{[tn{1}{1};to{1}{1}]}},...
wolffd@0 859 'FramePos',{{[fpo{1}{1},fpn{1}{1}]}});
wolffd@0 860 end
wolffd@0 861 end
wolffd@0 862
wolffd@0 863
wolffd@0 864 function y = combinesegment(old,new)
wolffd@0 865 do = get(old,'Data');
wolffd@0 866 to = get(old,'Pos');
wolffd@0 867 fpo = get(old,'FramePos');
wolffd@0 868 ppo = get(old,'PeakPos');
wolffd@0 869 pppo = get(old,'PeakPrecisePos');
wolffd@0 870 pvo = get(old,'PeakVal');
wolffd@0 871 ppvo = get(old,'PeakPreciseVal');
wolffd@0 872 pmo = get(old,'PeakMode');
wolffd@0 873 apo = get(old,'AttackPos');
wolffd@0 874 rpo = get(old,'ReleasePos');
wolffd@0 875 tpo = get(old,'TrackPos');
wolffd@0 876 tvo = get(old,'TrackVal');
wolffd@0 877
wolffd@0 878 dn = get(new,'Data');
wolffd@0 879 tn = get(new,'Pos');
wolffd@0 880 fpn = get(new,'FramePos');
wolffd@0 881 ppn = get(new,'PeakPos');
wolffd@0 882 pppn = get(new,'PeakPrecisePos');
wolffd@0 883 pvn = get(new,'PeakVal');
wolffd@0 884 ppvn = get(new,'PeakPreciseVal');
wolffd@0 885 pmn = get(new,'PeakMode');
wolffd@0 886 apn = get(new,'AttackPos');
wolffd@0 887 rpn = get(new,'ReleasePos');
wolffd@0 888 tpn = get(new,'TrackPos');
wolffd@0 889 tvn = get(new,'TrackVal');
wolffd@0 890
wolffd@0 891 if not(isempty(do))
wolffd@0 892 y = set(old,'Data',{{do{1}{:},dn{1}{:}}});
wolffd@0 893 end
wolffd@0 894
wolffd@0 895 y = set(old,'FramePos',{{fpo{1}{:},fpn{1}{:}}});
wolffd@0 896
wolffd@0 897 if not(isempty(to)) && size(do{1},2) == size(to{1},2)
wolffd@0 898 y = set(y,'Pos',{{to{1}{:},tn{1}{:}}});
wolffd@0 899 end
wolffd@0 900
wolffd@0 901 if not(isempty(ppo))
wolffd@0 902 y = set(y,'PeakPos',{{ppo{1}{:},ppn{1}{:}}},...
wolffd@0 903 'PeakVal',{{pvo{1}{:},pvn{1}{:}}},...
wolffd@0 904 'PeakMode',{{pmo{1}{:},pmn{1}{:}}});
wolffd@0 905 end
wolffd@0 906
wolffd@0 907 if not(isempty(pppn))
wolffd@0 908 y = set(y,'PeakPrecisePos',{[pppo{1},pppn{1}{1}]},...
wolffd@0 909 'PeakPreciseVal',{[ppvo{1},ppvn{1}{1}]});
wolffd@0 910 end
wolffd@0 911
wolffd@0 912 if not(isempty(apn))
wolffd@0 913 y = set(y,'AttackPos',{[apo{1},apn{1}{1}]});
wolffd@0 914 end
wolffd@0 915
wolffd@0 916 if not(isempty(rpn))
wolffd@0 917 y = set(y,'ReleasePos',{[rpo{1},rpn{1}{1}]});
wolffd@0 918 end
wolffd@0 919
wolffd@0 920 if not(isempty(tpn))
wolffd@0 921 y = set(y,'TrackPos',{[tpo{1},tpn{1}{1}]});
wolffd@0 922 end
wolffd@0 923
wolffd@0 924 if not(isempty(tvn))
wolffd@0 925 y = set(y,'TrackVal',{[tvo{1},tvn{1}{1}]});
wolffd@0 926 end
wolffd@0 927
wolffd@0 928 if isa(old,'miremotion')
wolffd@0 929 deo = get(old,'DimData');
wolffd@0 930 ceo = get(old,'ClassData');
wolffd@0 931 den = get(new,'DimData');
wolffd@0 932 cen = get(new,'ClassData');
wolffd@0 933 afo = get(old,'ActivityFactors');
wolffd@0 934 vfo = get(old,'ValenceFactors');
wolffd@0 935 tfo = get(old,'TensionFactors');
wolffd@0 936 hfo = get(old,'HappyFactors');
wolffd@0 937 sfo = get(old,'SadFactors');
wolffd@0 938 tdo = get(old,'TenderFactors');
wolffd@0 939 ago = get(old,'AngerFactors');
wolffd@0 940 ffo = get(old,'FearFactors');
wolffd@0 941 afn = get(new,'ActivityFactors');
wolffd@0 942 vfn = get(new,'ValenceFactors');
wolffd@0 943 tfn = get(new,'TensionFactors');
wolffd@0 944 hfn = get(new,'HappyFactors');
wolffd@0 945 sfn = get(new,'SadFactors');
wolffd@0 946 tdn = get(new,'TenderFactors');
wolffd@0 947 agn = get(new,'AngerFactors');
wolffd@0 948 ffn = get(new,'FearFactors');
wolffd@0 949 y = set(y,'DimData',{[deo{1},den{1}{1}]},...
wolffd@0 950 'ClassData',{[ceo{1},cen{1}{1}]},...
wolffd@0 951 'ActivityFactors',{[afo{1},afn{1}{1}]},...
wolffd@0 952 'ValenceFactors',{[vfo{1},vfn{1}{1}]},...
wolffd@0 953 'TensionFactors',{[tfo{1},tfn{1}{1}]},...
wolffd@0 954 'HappyFactors',{[hfo{1},hfn{1}{1}]},...
wolffd@0 955 'SadFactors',{[sfo{1},sfn{1}{1}]},...
wolffd@0 956 'TenderFactors',{[tdo{1},tdn{1}{1}]},...
wolffd@0 957 'AngerFactors',{[ago{1},agn{1}{1}]},...
wolffd@0 958 'FearFactors',{[ffo{1},ffn{1}{1}]}...
wolffd@0 959 );
wolffd@0 960 end
wolffd@0 961
wolffd@0 962
wolffd@0 963 function y = sumchunk(old,new,order)
wolffd@0 964 %do = mirgetdata(old);
wolffd@0 965 %dn = mirgetdata(new);
wolffd@0 966 do = get(old,'Data');
wolffd@0 967 do = do{1}{1};
wolffd@0 968 dn = get(new,'Data');
wolffd@0 969 dn = dn{1}{1};
wolffd@0 970 y = set(old,'ChunkData',do+dn);
wolffd@0 971
wolffd@0 972
wolffd@0 973 function y = divideweightchunk(orig,length)
wolffd@0 974 d = get(orig,'Data');
wolffd@0 975 if isempty(d)
wolffd@0 976 y = orig;
wolffd@0 977 else
wolffd@0 978 v = mircompute(@divideweight,d,length);
wolffd@0 979 y = set(orig,'Data',v);
wolffd@0 980 end
wolffd@0 981
wolffd@0 982 function e = multweight(d,length)
wolffd@0 983 e = d*length;
wolffd@0 984
wolffd@0 985 function e = divideweight(d,length)
wolffd@0 986 e = d/length;