Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
sunaudio Namespace Reference

Data Structures

class  error
 

Functions

def get_long_be
 
def gethdr
 
def printhdr
 

Variables

string MAGIC = '.snd'
 

Detailed Description

Interpret sun audio headers.

Function Documentation

def sunaudio.get_long_be (   s)
Convert a 4-char value to integer.

Definition at line 9 of file sunaudio.py.

9 
10 def get_long_be(s):
11  """Convert a 4-char value to integer."""
12  return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
13 
def sunaudio.gethdr (   fp)
Read a sound header from an open file.

Definition at line 14 of file sunaudio.py.

References get_long_be().

14 
15 def gethdr(fp):
16  """Read a sound header from an open file."""
17  if fp.read(4) != MAGIC:
18  raise error, 'gethdr: bad magic word'
19  hdr_size = get_long_be(fp.read(4))
20  data_size = get_long_be(fp.read(4))
21  encoding = get_long_be(fp.read(4))
22  sample_rate = get_long_be(fp.read(4))
23  channels = get_long_be(fp.read(4))
24  excess = hdr_size - 24
25  if excess < 0:
26  raise error, 'gethdr: bad hdr_size'
27  if excess > 0:
28  info = fp.read(excess)
29  else:
30  info = ''
31  return (data_size, encoding, sample_rate, channels, info)
32 
def sunaudio.printhdr (   file)
Read and print the sound header of a named file.

Definition at line 33 of file sunaudio.py.

References gethdr(), and aifc.open().

33 
34 def printhdr(file):
35  """Read and print the sound header of a named file."""
36  hdr = gethdr(open(file, 'r'))
37  data_size, encoding, sample_rate, channels, info = hdr
38  while info[-1:] == '\0':
39  info = info[:-1]
40  print 'File name: ', file
41  print 'Data size: ', data_size
42  print 'Encoding: ', encoding
43  print 'Sample rate:', sample_rate
44  print 'Channels: ', channels
45  print 'Info: ', `info`

Variable Documentation

string MAGIC = '.snd'

Definition at line 3 of file sunaudio.py.