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