Guido van Rossum | b950629 | 1992-04-13 18:38:20 +0000 | [diff] [blame] | 1 | # Receive UDP packets from sendcd.py and play them on the speaker or |
| 2 | # audio jack. |
| 3 | |
| 4 | import al, AL |
| 5 | from socket import * |
Sjoerd Mullender | f1bb334 | 1995-04-06 14:46:31 +0000 | [diff] [blame] | 6 | from cd import DATASIZE |
Guido van Rossum | b950629 | 1992-04-13 18:38:20 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | f2759a5 | 1992-04-14 11:04:57 +0000 | [diff] [blame] | 8 | PORT = 50505 # Must match the port in sendcd.py |
Guido van Rossum | b950629 | 1992-04-13 18:38:20 +0000 | [diff] [blame] | 9 | |
| 10 | def main(): |
| 11 | s = socket(AF_INET, SOCK_DGRAM) |
| 12 | s.bind('', PORT) |
| 13 | |
Guido van Rossum | f2759a5 | 1992-04-14 11:04:57 +0000 | [diff] [blame] | 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) |
Guido van Rossum | b950629 | 1992-04-13 18:38:20 +0000 | [diff] [blame] | 24 | |
Guido van Rossum | f2759a5 | 1992-04-14 11:04:57 +0000 | [diff] [blame] | 25 | while 1: |
Sjoerd Mullender | f1bb334 | 1995-04-06 14:46:31 +0000 | [diff] [blame] | 26 | data = s.recv(DATASIZE) |
Guido van Rossum | f2759a5 | 1992-04-14 11:04:57 +0000 | [diff] [blame] | 27 | 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 | |
| 36 | main() |