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