wolffd@0
|
1 function varargout = mirplay(a,varargin)
|
wolffd@0
|
2 % mirplay(a) plays audio signal, envelope, or pitches.
|
wolffd@0
|
3 % If a is an envelope, what is actually played is a white noise of
|
wolffd@0
|
4 % same envelope.
|
wolffd@0
|
5 % If a is a mirpitch object, pitches are played using sinusoids.
|
wolffd@0
|
6 % Optional arguments:
|
wolffd@0
|
7 % mirplay(...,'Channel',i) plays the channel(s) of rank(s) indicated by
|
wolffd@0
|
8 % the array i.
|
wolffd@0
|
9 % mirplay(...,'Segment',k) plays the segment(s) of rank(s) indicated by
|
wolffd@0
|
10 % the array k.
|
wolffd@0
|
11 % mirplay(...,'Sequence',l) plays the sequence(s) of rank(s) indicated
|
wolffd@0
|
12 % by the array l.
|
wolffd@0
|
13 % mirplay(...,'Increasing',d) plays the sequences in increasing order
|
wolffd@0
|
14 % of d, which could be either an array or a mirscalar data.
|
wolffd@0
|
15 % mirplay(...,'Decreasing',d) plays the sequences in decreasing order
|
wolffd@0
|
16 % of d, which could be either an array or a mirscalar data.
|
wolffd@0
|
17 % mirplay(...,'Every',s) plays every s sequence, where s is a number
|
wolffd@0
|
18 % indicating the step between sequences.
|
wolffd@0
|
19 % mirplay(...,'Burst',0) toggles off the burst sound between
|
wolffd@0
|
20 % segments.
|
wolffd@0
|
21 % Example: mirplay(mirenvelope('Folder'),...
|
wolffd@0
|
22 % 'increasing', mirrms('Folder'),...
|
wolffd@0
|
23 % 'every',5)
|
wolffd@0
|
24
|
wolffd@0
|
25 if ischar(a)
|
wolffd@0
|
26 varargout = mirplay(miraudio(a),varargin{:});
|
wolffd@0
|
27 elseif isscalar(a)
|
wolffd@0
|
28 ch.key = 'Channel';
|
wolffd@0
|
29 ch.type = 'Integer';
|
wolffd@0
|
30 ch.default = 0;
|
wolffd@0
|
31 option.ch = ch;
|
wolffd@0
|
32
|
wolffd@0
|
33 sg.key = 'Segment';
|
wolffd@0
|
34 sg.type = 'Integer';
|
wolffd@0
|
35 sg.default = 0;
|
wolffd@0
|
36 option.sg = sg;
|
wolffd@0
|
37
|
wolffd@0
|
38 se.key = 'Sequence';
|
wolffd@0
|
39 se.type = 'Integer';
|
wolffd@0
|
40 se.default = 0;
|
wolffd@0
|
41 option.se = se;
|
wolffd@0
|
42
|
wolffd@0
|
43 inc.key = 'Increasing';
|
wolffd@0
|
44 inc.type = 'MIRtb';
|
wolffd@0
|
45 option.inc = inc;
|
wolffd@0
|
46
|
wolffd@0
|
47 dec.key = 'Decreasing';
|
wolffd@0
|
48 dec.type = 'MIRtb';
|
wolffd@0
|
49 option.dec = dec;
|
wolffd@0
|
50
|
wolffd@0
|
51 every.key = 'Every';
|
wolffd@0
|
52 every.type = 'Integer';
|
wolffd@0
|
53 option.every = every;
|
wolffd@0
|
54
|
wolffd@0
|
55 burst.key = 'Burst';
|
wolffd@0
|
56 burst.type = 'Boolean';
|
wolffd@0
|
57 burst.default = 1;
|
wolffd@0
|
58 option.burst = burst;
|
wolffd@0
|
59
|
wolffd@0
|
60 specif.option = option;
|
wolffd@0
|
61
|
wolffd@0
|
62 specif.eachchunk = 'Normal';
|
wolffd@0
|
63
|
wolffd@0
|
64 varargout = mirfunction(@mirplay,a,varargin,nargout,specif,@init,@main);
|
wolffd@0
|
65 if nargout == 0
|
wolffd@0
|
66 varargout = {};
|
wolffd@0
|
67 end
|
wolffd@0
|
68 else
|
wolffd@0
|
69 mirerror('mirplay','You cannot play this type of object.')
|
wolffd@0
|
70 end
|
wolffd@0
|
71
|
wolffd@0
|
72
|
wolffd@0
|
73 function [x type] = init(x,option)
|
wolffd@0
|
74 type = '';
|
wolffd@0
|
75
|
wolffd@0
|
76
|
wolffd@0
|
77 function noargout = main(a,option,postoption)
|
wolffd@0
|
78 if iscell(a)
|
wolffd@0
|
79 a = a{1};
|
wolffd@0
|
80 end
|
wolffd@0
|
81 d = get(a,'Data');
|
wolffd@0
|
82 if isa(a,'mirpitch')
|
wolffd@0
|
83 amp = get(a,'Amplitude');
|
wolffd@0
|
84 end
|
wolffd@0
|
85 f = get(a,'Sampling');
|
wolffd@0
|
86 n = get(a,'Name');
|
wolffd@0
|
87 c = get(a,'Channels');
|
wolffd@0
|
88 fp = get(a,'FramePos');
|
wolffd@0
|
89 if not(option.se)
|
wolffd@0
|
90 if length(d)>1
|
wolffd@0
|
91 if isfield(option,'inc')
|
wolffd@0
|
92 [unused order] = sort(mirgetdata(option.inc));
|
wolffd@0
|
93 elseif isfield(option,'dec')
|
wolffd@0
|
94 [unused order] = sort(mirgetdata(option.dec),'descend');
|
wolffd@0
|
95 else
|
wolffd@0
|
96 order = 1:length(d);
|
wolffd@0
|
97 end
|
wolffd@0
|
98 if isfield(option,'every')
|
wolffd@0
|
99 order = order(1:option.every:end);
|
wolffd@0
|
100 end
|
wolffd@0
|
101 else
|
wolffd@0
|
102 order = 1;
|
wolffd@0
|
103 end
|
wolffd@0
|
104 else
|
wolffd@0
|
105 order = option.se;
|
wolffd@0
|
106 end
|
wolffd@0
|
107 if not(isempty(order))
|
wolffd@0
|
108 for k = order(:)'
|
wolffd@0
|
109 display(['Playing analysis of file: ' n{k}])
|
wolffd@0
|
110 dk = d{k};
|
wolffd@0
|
111 if not(iscell(dk))
|
wolffd@0
|
112 dk = {dk};
|
wolffd@0
|
113 end
|
wolffd@0
|
114 if option.ch
|
wolffd@0
|
115 if isempty(c{k})
|
wolffd@0
|
116 chk = option.ch;
|
wolffd@0
|
117 else
|
wolffd@0
|
118 [unused unused chk] = intersect(option.ch,c{k});
|
wolffd@0
|
119 end
|
wolffd@0
|
120 else
|
wolffd@0
|
121 chk = 1:size(dk{1},3);
|
wolffd@0
|
122 end
|
wolffd@0
|
123 if isempty(chk)
|
wolffd@0
|
124 display('No channel to play.');
|
wolffd@0
|
125 end
|
wolffd@0
|
126 for l = chk
|
wolffd@0
|
127 if chk(end)>1
|
wolffd@0
|
128 display([' Playing channel #' num2str(l)]);
|
wolffd@0
|
129 end
|
wolffd@0
|
130 if option.sg
|
wolffd@0
|
131 sgk = option.sg(find(option.sg<=length(dk)));
|
wolffd@0
|
132 else
|
wolffd@0
|
133 sgk = 1:length(dk);
|
wolffd@0
|
134 end
|
wolffd@0
|
135 for i = sgk
|
wolffd@0
|
136 if sgk(end)>1
|
wolffd@0
|
137 display([' Playing segment #' num2str(i)])
|
wolffd@0
|
138 end
|
wolffd@0
|
139 di = dk{i};
|
wolffd@0
|
140 if isa(a,'mirpitch')
|
wolffd@0
|
141 ampi = amp{k}{i};
|
wolffd@0
|
142 end
|
wolffd@0
|
143 synth = zeros(1,ceil((fp{k}{i}(end)-fp{k}{i}(1))*44100)+1);
|
wolffd@0
|
144 for j = 1:size(di,2)
|
wolffd@0
|
145 if iscell(di)
|
wolffd@0
|
146 dj = di{j};
|
wolffd@0
|
147 else
|
wolffd@0
|
148 dj = di(:,j);
|
wolffd@0
|
149 end
|
wolffd@0
|
150 dj(isnan(dj)) = 0;
|
wolffd@0
|
151 if isa(a,'mirpitch')
|
wolffd@0
|
152 ampj = zeros(size(dj));
|
wolffd@0
|
153 if iscell(ampi)
|
wolffd@0
|
154 ampj(1:size(ampi{j})) = ampi{j};
|
wolffd@0
|
155 else
|
wolffd@0
|
156 ampj(1:size(ampi(:,j))) = ampi(:,j);
|
wolffd@0
|
157 end
|
wolffd@0
|
158 end
|
wolffd@0
|
159 if not(isempty(dj))
|
wolffd@0
|
160 k1 = floor((fp{k}{i}(1,j)-fp{k}{i}(1))*44100)+1;
|
wolffd@0
|
161 k2 = floor((fp{k}{i}(2,j)-fp{k}{i}(1))*44100)+1;
|
wolffd@0
|
162 if isa(a,'mirpitch')
|
wolffd@0
|
163 ampj = repmat(ampj,1,k2-k1+1);
|
wolffd@0
|
164 else
|
wolffd@0
|
165 ampj = ones(size(dj),k2-k1+1);
|
wolffd@0
|
166 end
|
wolffd@0
|
167 synth(k1:k2) = synth(k1:k2) ...
|
wolffd@0
|
168 + sum(ampj.*sin(2*pi*dj*(0:k2-k1)/44100),1) ...
|
wolffd@0
|
169 .*hann(k2-k1+1)';
|
wolffd@0
|
170 %plot((ampj.*sin(2*pi*dj*(0:k2-k1)/44100))')
|
wolffd@0
|
171 %drawnow
|
wolffd@0
|
172 end
|
wolffd@0
|
173 end
|
wolffd@0
|
174 soundsc(synth,44100);
|
wolffd@0
|
175 if option.burst && sgk(end)>1
|
wolffd@0
|
176 sound(rand(1,10))
|
wolffd@0
|
177 end
|
wolffd@0
|
178 %pause(0.5)
|
wolffd@0
|
179 end
|
wolffd@0
|
180 end
|
wolffd@0
|
181 end
|
wolffd@0
|
182 end
|
wolffd@0
|
183 noargout = {}; |