home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Demo / sgi / cd / recvcd.py < prev    next >
Text File  |  1992-04-14  |  775b  |  37 lines

  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 *
  6. from CD import CDDA_DATASIZE
  7.  
  8. PORT = 50505                # Must match the port in sendcd.py
  9.  
  10. def main():
  11.     s = socket(AF_INET, SOCK_DGRAM)
  12.     s.bind('', PORT)
  13.  
  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)
  24.  
  25.         while 1:
  26.             data = s.recv(CDDA_DATASIZE)
  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()
  37.