comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirplay.m @ 0:e9a9cd732c1e tip

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