The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Demo / sgi / al / playaiff.py
blob22120dc66ca47b91a56f51800f04a816f33c15cf
1 import aiff
2 import al
3 import sys
4 import time
6 def main():
7 v = 1
8 c = al.newconfig()
9 nchannels = c.getchannels()
10 nsampframes = 0 # ???
11 sampwidth = c.getwidth()
12 samprate = 0.0 # unknown
13 filename = sys.argv[1]
14 f = open(filename, 'r')
15 type, totalsize = aiff.read_chunk_header(f)
16 if type <> 'FORM':
17 raise aiff.Error, 'FORM chunk expected at start of file'
18 aiff.read_form_chunk(f)
19 while 1:
20 try:
21 type, size = aiff.read_chunk_header(f)
22 except EOFError:
23 break
24 if v: print 'header:', `type`, size
25 if type == 'COMM':
26 nchannels, nsampframes, sampwidth, samprate = \
27 aiff.read_comm_chunk(f)
28 if v: print nchannels, nsampframes, sampwidth, samprate
29 elif type == 'SSND':
30 offset, blocksize = aiff.read_ssnd_chunk(f)
31 if v: print offset, blocksize
32 data = f.read(size-8)
33 if size%2: void = f.read(1)
34 p = makeport(nchannels, sampwidth, samprate)
35 play(p, data, offset, blocksize)
36 elif type in aiff.skiplist:
37 aiff.skip_chunk(f, size)
38 else:
39 raise aiff.Error, 'bad chunk type ' + type
41 def makeport(nchannels, sampwidth, samprate):
42 c = al.newconfig()
43 c.setchannels(nchannels)
44 c.setwidth(sampwidth/8)
45 # can't set the rate...
46 p = al.openport('', 'w', c)
47 return p
49 def play(p, data, offset, blocksize):
50 data = data[offset:]
51 p.writesamps(data)
52 while p.getfilled() > 0: time.sleep(0.01)
54 main()