comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirscalar/mirsave.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 mirsave(a)
2
3 d = get(a,'Data');
4 n = get(a,'Name');
5 t = get(a,'Title');
6 c = get(a,'Channels');
7 fp = get(a,'FramePos');
8 out = cell(1,length(d));
9
10 for k = 1:length(d)
11 dk = d{k};
12 if not(iscell(dk))
13 dk = {dk};
14 end
15 out = [];
16 for l = 1:size(dk{1},3)
17 for i = 1:length(dk)
18 di = dk{i};
19 synth = zeros(1,ceil((fp{k}{i}(end)-fp{k}{i}(1))*44100)+1);
20 for j = 1:size(di,2)
21 if iscell(di)
22 dj = di{j};
23 else
24 dj = di(j);
25 end
26 if not(isempty(dj))
27 k1 = floor((fp{k}{i}(1,j)-fp{k}{i}(1))*44100)+1;
28 k2 = floor((fp{k}{i}(2,j)-fp{k}{i}(1))*44100)+1;
29 synth(k1:k2) = synth(k1:k2) ...
30 + sum(sin(2*pi*dj*(0:k2-k1)/44100),1).*hann(k2-k1+1)';
31 end
32 end
33 out = [out synth];
34 if size(dk{1},3)>1
35 out = [out rand(1,10)];
36 end
37 end
38 end
39 fout = miraudio(out,44100);
40 mirsave(fout,[n{k},'.',t]);
41 end
42
43
44 function oldmirsave % not used anymore
45 d = get(a,'Data');
46 nf = length(d);
47 fp = get(a,'FramePos');
48 nm = get(a,'Name');
49 t = get(a,'Title');
50 for i = 1:nf
51 nmi = nm{i};
52 di = d{i}{1};
53 fpi = fp{i}{1};
54
55 %Let's remove the extension from the original files
56 if length(nmi)>3 && strcmpi(nmi(end-3:end),'.wav')
57 nmi(end-3:end) = [];
58 elseif length(nmi)>2 && strcmpi(nmi(end-2:end),'.au')
59 nmi(end-2:end) = [];
60 end
61 n = [nmi,'.',lower(t),'.txt'];
62
63 fid = fopen(n, 'wt');
64 fprintf(fid,'Frame_start Frame_end Data \n');
65
66 for j = 1:length(di)
67 fprintf(fid,'%g %g %g \n',fpi(1,j),fpi(2,j),di(j));
68 end
69 fclose(fid);
70 disp([n,' saved.']);
71 end