1 """Interpret sun audio headers."""
2 from warnings
import warnpy3k
3 warnpy3k("the sunaudio module has been removed in Python 3.0; "
4 "use the sunau module instead", stacklevel
=2)
10 class error(Exception):
15 """Convert a 4-char value to integer."""
16 return (ord(s
[0])<<24) |
(ord(s
[1])<<16) |
(ord(s
[2])<<8) |
ord(s
[3])
20 """Read a sound header from an open file."""
21 if fp
.read(4) != MAGIC
:
22 raise error
, 'gethdr: bad magic word'
23 hdr_size
= get_long_be(fp
.read(4))
24 data_size
= get_long_be(fp
.read(4))
25 encoding
= get_long_be(fp
.read(4))
26 sample_rate
= get_long_be(fp
.read(4))
27 channels
= get_long_be(fp
.read(4))
28 excess
= hdr_size
- 24
30 raise error
, 'gethdr: bad hdr_size'
32 info
= fp
.read(excess
)
35 return (data_size
, encoding
, sample_rate
, channels
, info
)
39 """Read and print the sound header of a named file."""
40 hdr
= gethdr(open(file, 'r'))
41 data_size
, encoding
, sample_rate
, channels
, info
= hdr
42 while info
[-1:] == '\0':
44 print 'File name: ', file
45 print 'Data size: ', data_size
46 print 'Encoding: ', encoding
47 print 'Sample rate:', sample_rate
48 print 'Channels: ', channels
49 print 'Info: ', repr(info
)