annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirenvelope/mirplay.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function mirplay(e,varargin)
Daniel@0 2
Daniel@0 3 % mirplay method for mirenvelope objects. Help displayed in ../mirplay.m
Daniel@0 4
Daniel@0 5 ch.key = 'Channel';
Daniel@0 6 ch.type = 'Integer';
Daniel@0 7 ch.default = 0;
Daniel@0 8 option.ch = ch;
Daniel@0 9
Daniel@0 10 sg.key = 'Segment';
Daniel@0 11 sg.type = 'Integer';
Daniel@0 12 sg.default = 0;
Daniel@0 13 option.sg = sg;
Daniel@0 14
Daniel@0 15 se.key = 'Sequence';
Daniel@0 16 se.type = 'Integer';
Daniel@0 17 se.default = 0;
Daniel@0 18 option.se = se;
Daniel@0 19
Daniel@0 20 inc.key = 'Increasing';
Daniel@0 21 inc.type = 'MIRtb';
Daniel@0 22 option.inc = inc;
Daniel@0 23
Daniel@0 24 dec.key = 'Decreasing';
Daniel@0 25 dec.type = 'MIRtb';
Daniel@0 26 option.dec = dec;
Daniel@0 27
Daniel@0 28 every.key = 'Every';
Daniel@0 29 every.type = 'Integer';
Daniel@0 30 option.every = every;
Daniel@0 31
Daniel@0 32 burst.key = 'Burst';
Daniel@0 33 burst.type = 'Boolean';
Daniel@0 34 burst.default = 1;
Daniel@0 35 option.burst = burst;
Daniel@0 36
Daniel@0 37 specif.option = option;
Daniel@0 38
Daniel@0 39 specif.eachchunk = 'Normal';
Daniel@0 40
Daniel@0 41 varargout = mirfunction(@mirplay,e,varargin,nargout,specif,@init,@main);
Daniel@0 42 if nargout == 0
Daniel@0 43 varargout = {};
Daniel@0 44 end
Daniel@0 45
Daniel@0 46
Daniel@0 47 function [x type] = init(x,option)
Daniel@0 48 type = '';
Daniel@0 49
Daniel@0 50
Daniel@0 51 function noargout = main(a,option,postoption)
Daniel@0 52 if iscell(a)
Daniel@0 53 a = a{1};
Daniel@0 54 end
Daniel@0 55 d = get(a,'Data');
Daniel@0 56 f = get(a,'Sampling');
Daniel@0 57 n = get(a,'Name');
Daniel@0 58 c = get(a,'Channels');
Daniel@0 59 fp = get(a,'FramePos');
Daniel@0 60 if not(option.se)
Daniel@0 61 if length(d)>1
Daniel@0 62 if isfield(option,'inc')
Daniel@0 63 [unused order] = sort(mirgetdata(option.inc));
Daniel@0 64 elseif isfield(option,'dec')
Daniel@0 65 [unused order] = sort(mirgetdata(option.dec),'descend');
Daniel@0 66 else
Daniel@0 67 order = 1:length(d);
Daniel@0 68 end
Daniel@0 69 if isfield(option,'every')
Daniel@0 70 order = order(1:option.every:end);
Daniel@0 71 end
Daniel@0 72 else
Daniel@0 73 order = 1;
Daniel@0 74 end
Daniel@0 75 else
Daniel@0 76 order = option.se;
Daniel@0 77 end
Daniel@0 78 if not(isempty(order))
Daniel@0 79 for k = order(:)'
Daniel@0 80 display(['Playing envelope of file: ' n{k}])
Daniel@0 81 dk = d{k};
Daniel@0 82 if not(iscell(dk))
Daniel@0 83 dk = {dk};
Daniel@0 84 end
Daniel@0 85 if option.ch
Daniel@0 86 if isempty(c{k})
Daniel@0 87 chk = option.ch;
Daniel@0 88 else
Daniel@0 89 [unused unused chk] = intersect(option.ch,c{k});
Daniel@0 90 end
Daniel@0 91 else
Daniel@0 92 chk = 1:size(dk{1},3);
Daniel@0 93 end
Daniel@0 94 if isempty(chk)
Daniel@0 95 display('No channel to play.');
Daniel@0 96 end
Daniel@0 97 for l = chk
Daniel@0 98 if chk(end)>1
Daniel@0 99 display([' Playing channel #' num2str(l)]);
Daniel@0 100 end
Daniel@0 101 if option.sg
Daniel@0 102 sgk = option.sg(find(option.sg<=length(dk)));
Daniel@0 103 else
Daniel@0 104 sgk = 1:length(dk);
Daniel@0 105 end
Daniel@0 106 for i = sgk
Daniel@0 107 if sgk(end)>1
Daniel@0 108 display([' Playing segment #' num2str(i)])
Daniel@0 109 end
Daniel@0 110 di = dk{i};
Daniel@0 111 for j = 1:size(di,2)
Daniel@0 112 djl = resample(di(:,j,l),11025,round(f{k}));
Daniel@0 113 djl = djl/max(djl);
Daniel@0 114 djl = rand(length(djl),1).*djl;
Daniel@0 115 sound(djl,11025);
Daniel@0 116 idealtime = length(djl)/11025;
Daniel@0 117 practime = toc;
Daniel@0 118 if practime < idealtime
Daniel@0 119 pause(idealtime-practime)
Daniel@0 120 end
Daniel@0 121 end
Daniel@0 122 if option.burst && sgk(end)>1
Daniel@0 123 sound(rand(1,10))
Daniel@0 124 end
Daniel@0 125 end
Daniel@0 126 end
Daniel@0 127 end
Daniel@0 128 end
Daniel@0 129 noargout = {};