annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirenvelope/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(e,f)
wolffd@0 2
wolffd@0 3 ext = 0; % Specified new extension
wolffd@0 4 if nargin == 1
wolffd@0 5 f = '.envelope.mir';
wolffd@0 6 elseif length(f)>3 && strcmpi(f(end-3:end),'.wav')
wolffd@0 7 ext = '.wav';
wolffd@0 8 if length(f)==4
wolffd@0 9 f = '.mir';
wolffd@0 10 end
wolffd@0 11 elseif length(f)>2 && strcmpi(f(end-2:end),'.au')
wolffd@0 12 ext = '.au';
wolffd@0 13 if length(f)==3
wolffd@0 14 f = '.mir';
wolffd@0 15 end
wolffd@0 16 end
wolffd@0 17
wolffd@0 18 d = get(e,'Data');
wolffd@0 19 nf = length(d);
wolffd@0 20 fs = get(e,'Sampling');
wolffd@0 21 nm = get(e,'Name');
wolffd@0 22 for i = 1:nf
wolffd@0 23 di = d{i}{1};
wolffd@0 24 fsi = fs{i};
wolffd@0 25 nmi = nm{i};
wolffd@0 26 di = resample(di,11025,round(fs{i}));
wolffd@0 27 di = rand(size(di)).*di;
wolffd@0 28 di = di/max(max(max(abs(di))))*.9999;
wolffd@0 29 di = reshape(di,[],1);
wolffd@0 30
wolffd@0 31 %Let's remove the extension from the original files
wolffd@0 32 if length(nmi)>3 && strcmpi(nmi(end-3:end),'.wav')
wolffd@0 33 nmi(end-3:end) = [];
wolffd@0 34 elseif length(nmi)>2 && strcmpi(nmi(end-2:end),'.au')
wolffd@0 35 nmi(end-2:end) = [];
wolffd@0 36 end
wolffd@0 37
wolffd@0 38 if nf>1 || strcmp(f(1),'.')
wolffd@0 39 %Let's add the new suffix
wolffd@0 40 n = [nmi f];
wolffd@0 41 else
wolffd@0 42 n = f;
wolffd@0 43 end
wolffd@0 44
wolffd@0 45 if not(ischar(ext)) || strcmp(ext,'.wav')
wolffd@0 46 if length(n)<4 || not(strcmpi(n(end-3:end),'.wav'))
wolffd@0 47 n = [n '.wav'];
wolffd@0 48 end
wolffd@0 49 wavwrite(di,11025,32,n)
wolffd@0 50 elseif strcmp(ext,'.au')
wolffd@0 51 if length(n)<3 || not(strcmpi(n(end-2:end),'.au'))
wolffd@0 52 n = [n '.au'];
wolffd@0 53 end
wolffd@0 54 auwrite(di,11025,32,'linear',n)
wolffd@0 55 end
wolffd@0 56 disp([n,' saved.']);
wolffd@0 57 end