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