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