blob: e7496d19251b4688bd493de05d02220ebe7353be [file] [log] [blame]
Guido van Rossumb9506291992-04-13 18:38:20 +00001# Receive UDP packets from sendcd.py and play them on the speaker or
2# audio jack.
3
4import al, AL
5from socket import *
Sjoerd Mullenderf1bb3341995-04-06 14:46:31 +00006from cd import DATASIZE
Guido van Rossumb9506291992-04-13 18:38:20 +00007
Guido van Rossumf2759a51992-04-14 11:04:57 +00008PORT = 50505 # Must match the port in sendcd.py
Guido van Rossumb9506291992-04-13 18:38:20 +00009
10def main():
11 s = socket(AF_INET, SOCK_DGRAM)
12 s.bind('', PORT)
13
Guido van Rossumf2759a51992-04-14 11:04:57 +000014 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)
Guido van Rossumb9506291992-04-13 18:38:20 +000024
Guido van Rossumf2759a51992-04-14 11:04:57 +000025 while 1:
Sjoerd Mullenderf1bb3341995-04-06 14:46:31 +000026 data = s.recv(DATASIZE)
Guido van Rossumf2759a51992-04-14 11:04:57 +000027 if not data:
28 print 'EOF'
29 break
30 port.writesamps(data)
31 except KeyboardInterrupt:
32 pass
33
34 al.setparams(AL.DEFAULT_DEVICE, oldparams)
35
36main()