wolffd@0: function varargout = mirplay(a,varargin) wolffd@0: % mirplay(a) plays audio signal, envelope, or pitches. wolffd@0: % If a is an envelope, what is actually played is a white noise of wolffd@0: % same envelope. wolffd@0: % If a is a mirpitch object, pitches are played using sinusoids. wolffd@0: % Optional arguments: wolffd@0: % mirplay(...,'Channel',i) plays the channel(s) of rank(s) indicated by wolffd@0: % the array i. wolffd@0: % mirplay(...,'Segment',k) plays the segment(s) of rank(s) indicated by wolffd@0: % the array k. wolffd@0: % mirplay(...,'Sequence',l) plays the sequence(s) of rank(s) indicated wolffd@0: % by the array l. wolffd@0: % mirplay(...,'Increasing',d) plays the sequences in increasing order wolffd@0: % of d, which could be either an array or a mirscalar data. wolffd@0: % mirplay(...,'Decreasing',d) plays the sequences in decreasing order wolffd@0: % of d, which could be either an array or a mirscalar data. wolffd@0: % mirplay(...,'Every',s) plays every s sequence, where s is a number wolffd@0: % indicating the step between sequences. wolffd@0: % mirplay(...,'Burst',0) toggles off the burst sound between wolffd@0: % segments. wolffd@0: % Example: mirplay(mirenvelope('Folder'),... wolffd@0: % 'increasing', mirrms('Folder'),... wolffd@0: % 'every',5) wolffd@0: wolffd@0: if ischar(a) wolffd@0: varargout = mirplay(miraudio(a),varargin{:}); wolffd@0: elseif isscalar(a) wolffd@0: ch.key = 'Channel'; wolffd@0: ch.type = 'Integer'; wolffd@0: ch.default = 0; wolffd@0: option.ch = ch; wolffd@0: wolffd@0: sg.key = 'Segment'; wolffd@0: sg.type = 'Integer'; wolffd@0: sg.default = 0; wolffd@0: option.sg = sg; wolffd@0: wolffd@0: se.key = 'Sequence'; wolffd@0: se.type = 'Integer'; wolffd@0: se.default = 0; wolffd@0: option.se = se; wolffd@0: wolffd@0: inc.key = 'Increasing'; wolffd@0: inc.type = 'MIRtb'; wolffd@0: option.inc = inc; wolffd@0: wolffd@0: dec.key = 'Decreasing'; wolffd@0: dec.type = 'MIRtb'; wolffd@0: option.dec = dec; wolffd@0: wolffd@0: every.key = 'Every'; wolffd@0: every.type = 'Integer'; wolffd@0: option.every = every; wolffd@0: wolffd@0: burst.key = 'Burst'; wolffd@0: burst.type = 'Boolean'; wolffd@0: burst.default = 1; wolffd@0: option.burst = burst; wolffd@0: wolffd@0: specif.option = option; wolffd@0: wolffd@0: specif.eachchunk = 'Normal'; wolffd@0: wolffd@0: varargout = mirfunction(@mirplay,a,varargin,nargout,specif,@init,@main); wolffd@0: if nargout == 0 wolffd@0: varargout = {}; wolffd@0: end wolffd@0: else wolffd@0: mirerror('mirplay','You cannot play this type of object.') wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function [x type] = init(x,option) wolffd@0: type = ''; wolffd@0: wolffd@0: wolffd@0: function noargout = main(a,option,postoption) wolffd@0: if iscell(a) wolffd@0: a = a{1}; wolffd@0: end wolffd@0: d = get(a,'Data'); wolffd@0: if isa(a,'mirpitch') wolffd@0: amp = get(a,'Amplitude'); wolffd@0: end wolffd@0: f = get(a,'Sampling'); wolffd@0: n = get(a,'Name'); wolffd@0: c = get(a,'Channels'); wolffd@0: fp = get(a,'FramePos'); wolffd@0: if not(option.se) wolffd@0: if length(d)>1 wolffd@0: if isfield(option,'inc') wolffd@0: [unused order] = sort(mirgetdata(option.inc)); wolffd@0: elseif isfield(option,'dec') wolffd@0: [unused order] = sort(mirgetdata(option.dec),'descend'); wolffd@0: else wolffd@0: order = 1:length(d); wolffd@0: end wolffd@0: if isfield(option,'every') wolffd@0: order = order(1:option.every:end); wolffd@0: end wolffd@0: else wolffd@0: order = 1; wolffd@0: end wolffd@0: else wolffd@0: order = option.se; wolffd@0: end wolffd@0: if not(isempty(order)) wolffd@0: for k = order(:)' wolffd@0: display(['Playing analysis of file: ' n{k}]) wolffd@0: dk = d{k}; wolffd@0: if not(iscell(dk)) wolffd@0: dk = {dk}; wolffd@0: end wolffd@0: if option.ch wolffd@0: if isempty(c{k}) wolffd@0: chk = option.ch; wolffd@0: else wolffd@0: [unused unused chk] = intersect(option.ch,c{k}); wolffd@0: end wolffd@0: else wolffd@0: chk = 1:size(dk{1},3); wolffd@0: end wolffd@0: if isempty(chk) wolffd@0: display('No channel to play.'); wolffd@0: end wolffd@0: for l = chk wolffd@0: if chk(end)>1 wolffd@0: display([' Playing channel #' num2str(l)]); wolffd@0: end wolffd@0: if option.sg wolffd@0: sgk = option.sg(find(option.sg<=length(dk))); wolffd@0: else wolffd@0: sgk = 1:length(dk); wolffd@0: end wolffd@0: for i = sgk wolffd@0: if sgk(end)>1 wolffd@0: display([' Playing segment #' num2str(i)]) wolffd@0: end wolffd@0: di = dk{i}; wolffd@0: if isa(a,'mirpitch') wolffd@0: ampi = amp{k}{i}; wolffd@0: end wolffd@0: synth = zeros(1,ceil((fp{k}{i}(end)-fp{k}{i}(1))*44100)+1); wolffd@0: for j = 1:size(di,2) wolffd@0: if iscell(di) wolffd@0: dj = di{j}; wolffd@0: else wolffd@0: dj = di(:,j); wolffd@0: end wolffd@0: dj(isnan(dj)) = 0; wolffd@0: if isa(a,'mirpitch') wolffd@0: ampj = zeros(size(dj)); wolffd@0: if iscell(ampi) wolffd@0: ampj(1:size(ampi{j})) = ampi{j}; wolffd@0: else wolffd@0: ampj(1:size(ampi(:,j))) = ampi(:,j); wolffd@0: end wolffd@0: end wolffd@0: if not(isempty(dj)) wolffd@0: k1 = floor((fp{k}{i}(1,j)-fp{k}{i}(1))*44100)+1; wolffd@0: k2 = floor((fp{k}{i}(2,j)-fp{k}{i}(1))*44100)+1; wolffd@0: if isa(a,'mirpitch') wolffd@0: ampj = repmat(ampj,1,k2-k1+1); wolffd@0: else wolffd@0: ampj = ones(size(dj),k2-k1+1); wolffd@0: end wolffd@0: synth(k1:k2) = synth(k1:k2) ... wolffd@0: + sum(ampj.*sin(2*pi*dj*(0:k2-k1)/44100),1) ... wolffd@0: .*hann(k2-k1+1)'; wolffd@0: %plot((ampj.*sin(2*pi*dj*(0:k2-k1)/44100))') wolffd@0: %drawnow wolffd@0: end wolffd@0: end wolffd@0: soundsc(synth,44100); wolffd@0: if option.burst && sgk(end)>1 wolffd@0: sound(rand(1,10)) wolffd@0: end wolffd@0: %pause(0.5) wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: noargout = {};