comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@miraudio/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,f,multichan)
2
3 ext = 0; % Specified new extension
4 if nargin < 2
5 f = '.mir';
6 elseif length(f)>3 && strcmpi(f(end-3:end),'.wav')
7 ext = '.wav';
8 if length(f)==4
9 f = '.mir';
10 end
11 elseif length(f)>2 && strcmpi(f(end-2:end),'.au')
12 ext = '.au';
13 if length(f)==3
14 f = '.mir';
15 end
16 end
17
18 if nargin < 3
19 multichan = '';
20 end
21
22 d = get(a,'Data');
23 nf = length(d);
24 fs = get(a,'Sampling');
25 nb = get(a,'NBits');
26 nm = get(a,'Name');
27 ch = get(a,'Channels');
28 maxd = 0;
29 for i = 1:nf
30 for j = 1:length(d{i})
31 maxd = max(max(max(max(abs(d{i}{j}),[],1),[],2),[],3),maxd);
32 end
33 end
34 for i = 1:nf
35 nbi = nb{i};
36 di = d{i};
37 fsi = fs{i};
38 nmi = nm{i};
39 chi = ch{i};
40 out = [];
41 for j = 1:length(di)
42 di{j} = di{j}./repmat(maxd,size(di{j}))*.9999;
43 out = [out;reshape(di{j},[],size(di{j},3),1)];
44 if length(di)>1
45 out = [out;rand(100,size(di{j},3))]*.9;
46 end
47 end
48
49 %Let's remove the extension from the original files
50 if length(nmi)>3 && strcmpi(nmi(end-3:end),'.wav')
51 nmi(end-3:end) = [];
52 elseif length(nmi)>2 && strcmpi(nmi(end-2:end),'.au')
53 nmi(end-2:end) = [];
54 end
55
56 nchan = size(out,2);
57 if isempty(multichan) || nchan < 2
58 if nf>1 || strcmp(f(1),'.')
59 %Let's add the new suffix
60 n = [nmi f];
61 else
62 n = f;
63 end
64 if not(ischar(ext)) || strcmp(ext,'.wav')
65 if length(n)<4 || not(strcmpi(n(end-3:end),'.wav'))
66 n = [n '.wav'];
67 end
68 wavwrite(out,fsi,nbi,n)
69 elseif strcmp(ext,'.au')
70 if length(n)<3 || not(strcmpi(n(end-2:end),'.au'))
71 n = [n '.au'];
72 end
73 auwrite(out,fsi,nbi,'linear',n)
74 end
75 disp([n,' saved.']);
76 else
77 for j = 1:nchan
78 nb = num2str(chi(j));
79 if nf>1 || strcmp(f(1),'.')
80 %Let's add the new suffix
81 n = [nmi nb f];
82 else
83 n = [f nb];
84 end
85 if not(ischar(ext)) || strcmp(ext,'.wav')
86 if length(n)<4 || not(strcmpi(n(end-3:end),'.wav'))
87 n = [n '.wav'];
88 end
89 wavwrite(out(:,j),fsi,nbi,n)
90 elseif strcmp(ext,'.au')
91 if length(n)<3 || not(strcmpi(n(end-2:end),'.au'))
92 n = [n '.au'];
93 end
94 auwrite(out(:,j),fsi,nbi,'linear',n)
95 end
96 disp([n,' saved.']);
97 end
98 end
99 end