Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Demo / sgi / cd / recvcd.py
blobe7496d19251b4688bd493de05d02220ebe7353be
1 # Receive UDP packets from sendcd.py and play them on the speaker or
2 # audio jack.
4 import al, AL
5 from socket import *
6 from cd import DATASIZE
8 PORT = 50505 # Must match the port in sendcd.py
10 def main():
11 s = socket(AF_INET, SOCK_DGRAM)
12 s.bind('', PORT)
14 oldparams = [AL.OUTPUT_RATE, 0]
15 params = oldparams[:]
16 al.getparams(AL.DEFAULT_DEVICE, oldparams)
17 params[1] = AL.RATE_44100
18 try:
19 al.setparams(AL.DEFAULT_DEVICE, params)
20 config = al.newconfig()
21 config.setwidth(AL.SAMPLE_16)
22 config.setchannels(AL.STEREO)
23 port = al.openport('CD Player', 'w', config)
25 while 1:
26 data = s.recv(DATASIZE)
27 if not data:
28 print 'EOF'
29 break
30 port.writesamps(data)
31 except KeyboardInterrupt:
32 pass
34 al.setparams(AL.DEFAULT_DEVICE, oldparams)
36 main()