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