Daniel@0: function varargout = mirplay(a,varargin) Daniel@0: Daniel@0: % mirplay method for miraudio objects. Help displayed in ../mirplay.m Daniel@0: Daniel@0: ch.key = 'Channel'; Daniel@0: ch.type = 'Integer'; Daniel@0: ch.default = 0; Daniel@0: option.ch = ch; Daniel@0: Daniel@0: sg.key = 'Segment'; Daniel@0: sg.type = 'Integer'; Daniel@0: sg.default = 0; Daniel@0: option.sg = sg; Daniel@0: Daniel@0: se.key = 'Sequence'; Daniel@0: se.type = 'Integer'; Daniel@0: se.default = 0; Daniel@0: option.se = se; Daniel@0: Daniel@0: inc.key = 'Increasing'; Daniel@0: inc.type = 'MIRtb'; Daniel@0: option.inc = inc; Daniel@0: Daniel@0: dec.key = 'Decreasing'; Daniel@0: dec.type = 'MIRtb'; Daniel@0: option.dec = dec; Daniel@0: Daniel@0: every.key = 'Every'; Daniel@0: every.type = 'Integer'; Daniel@0: option.every = every; Daniel@0: Daniel@0: burst.key = 'Burst'; Daniel@0: burst.type = 'Boolean'; Daniel@0: burst.default = 1; Daniel@0: option.burst = burst; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: specif.eachchunk = 'Normal'; Daniel@0: Daniel@0: varargout = mirfunction(@mirplay,a,varargin,nargout,specif,@init,@main); Daniel@0: if nargout == 0 Daniel@0: varargout = {}; Daniel@0: end Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: type = ''; Daniel@0: Daniel@0: Daniel@0: function noargout = main(a,option,postoption) Daniel@0: if iscell(a) Daniel@0: a = a{1}; Daniel@0: end Daniel@0: d = get(a,'Data'); Daniel@0: f = get(a,'Sampling'); Daniel@0: n = get(a,'Name'); Daniel@0: c = get(a,'Channels'); Daniel@0: fp = get(a,'FramePos'); Daniel@0: if not(option.se) Daniel@0: if length(d)>1 Daniel@0: if isfield(option,'inc') Daniel@0: [unused order] = sort(mirgetdata(option.inc)); Daniel@0: elseif isfield(option,'dec') Daniel@0: [unused order] = sort(mirgetdata(option.dec),'descend'); Daniel@0: else Daniel@0: order = 1:length(d); Daniel@0: end Daniel@0: if isfield(option,'every') Daniel@0: order = order(1:option.every:end); Daniel@0: end Daniel@0: else Daniel@0: order = 1; Daniel@0: end Daniel@0: else Daniel@0: order = option.se; Daniel@0: end Daniel@0: if not(isempty(order)) Daniel@0: for k = order(:)' Daniel@0: display(['Playing file: ' n{k}]) Daniel@0: dk = d{k}; Daniel@0: if not(iscell(dk)) Daniel@0: dk = {dk}; Daniel@0: end Daniel@0: if option.ch Daniel@0: if isempty(c{k}) Daniel@0: chk = option.ch; Daniel@0: else Daniel@0: [unused unused chk] = intersect(option.ch,c{k}); Daniel@0: end Daniel@0: else Daniel@0: chk = 1:size(dk{1},3); Daniel@0: end Daniel@0: if isempty(chk) Daniel@0: display('No channel to play.'); Daniel@0: end Daniel@0: for l = chk Daniel@0: if chk(end)>1 Daniel@0: display([' Playing channel #' num2str(l)]); Daniel@0: end Daniel@0: if option.sg Daniel@0: sgk = option.sg(find(option.sg<=length(dk))); Daniel@0: else Daniel@0: sgk = 1:length(dk); Daniel@0: end Daniel@0: for i = sgk Daniel@0: if sgk(end)>1 Daniel@0: display([' Playing segment #' num2str(i)]) Daniel@0: end Daniel@0: di = dk{i}; Daniel@0: for j = 1:size(di,2) Daniel@0: tic Daniel@0: sound(di(:,j,l),f{k}); Daniel@0: idealtime = size(di,1)/f{k}; Daniel@0: practime = toc; Daniel@0: if practime < idealtime Daniel@0: pause(idealtime-practime) Daniel@0: end Daniel@0: end Daniel@0: if option.burst && sgk(end)>1 Daniel@0: sound(rand(1,10)) Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: noargout = {};