-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsigna.m
63 lines (55 loc) · 1.49 KB
/
signa.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function signa(wav,fn,s)
%
% signa(waveform, filename [,scale]);
%
% writes the waveform out as short integers with the low
% bit masked off.
%
% Inputs:
% waveform -- vector, may be complex
% filename -- string, if wavefrom is complex '.r' and '.i' are appended,
% and two files are written.
% scale -- optional scale. If unspecified, the waveform is scaled to
% full scale integer 32766. If specified, the output is
% waveform*scale*32766
%
%
% Written by John Pauly, Dec. 5, 1994
% (c) Leland Stanford Jr. University
%
wmax = hex2dec('7ffe');
% if no scale is specified, use as much dynamic range as possible
if nargin == 2,
s = 1/max(max(abs(real(wav)),abs(imag(wav))));
end;
% scale up to fit in a short integer
wav = wav*s*wmax;
% mask off low bit, since it would be an EOS otherwise
wav = 2*round(wav/2);
% if the imaginary component is zero, supress it
if sum(abs(imag(wav))) == 0,
wav = real(wav);
end;
if isreal(wav),
fip = fopen(fn,'wb','b');
if fip == -1,
disp(sprintf('Error opening %s for write',fn));
return;
end;
fwrite(fip,wav,'short');
else
fip = fopen([fn,'.r'],'wb','b');
if fip == -1,
disp(sprintf('Error opening %s for write',[fn,'.r']));
return;
end;
fwrite(fip,real(wav),'short');
fclose(fip);
fip = fopen([fn,'.i'],'wb','b');
if fip == -1,
disp(sprintf('Error opening %s for write',[fn,'.i']));
return;
end;
fwrite(fip,imag(wav),'short');
fclose(fip);
end;