1992-04-13 15:38:20 -03:00
|
|
|
# Read CD audio data from the SCSI bus and play it back over the
|
|
|
|
# built-in speaker or audio jack.
|
|
|
|
|
1992-04-15 14:49:14 -03:00
|
|
|
import sys
|
1992-04-13 15:38:20 -03:00
|
|
|
import al
|
|
|
|
import AL
|
|
|
|
import cd
|
|
|
|
import CD
|
|
|
|
|
|
|
|
def playaudio(port, type, audio):
|
|
|
|
## print 'playaudio'
|
|
|
|
port.writesamps(audio)
|
|
|
|
|
|
|
|
callbacks = ['audio', 'pnum', 'index', 'ptime', 'atime', 'catalog', 'ident', 'control']
|
|
|
|
|
|
|
|
def callback(port, type, data):
|
|
|
|
print 'type', callbacks[type], 'data', `data`
|
|
|
|
|
1992-04-15 14:49:14 -03:00
|
|
|
Error = 'playcd.error'
|
|
|
|
|
1992-04-13 15:38:20 -03:00
|
|
|
def main():
|
|
|
|
player = cd.open()
|
|
|
|
parser = cd.createparser()
|
|
|
|
|
1992-04-15 14:49:14 -03:00
|
|
|
state, track, (min, sec, frame), (abs_min, abs_sec, abs_frame), \
|
|
|
|
(total_min, total_sec, total_frame), \
|
|
|
|
first, last, scsi_audio, \
|
|
|
|
cur_block, (dum1, dum2, dum3) = player.getstatus()
|
|
|
|
print state, track, (min, sec, frame), \
|
|
|
|
(abs_min, abs_sec, abs_frame), \
|
|
|
|
(total_min, total_sec, total_frame), \
|
|
|
|
first, last, scsi_audio, \
|
|
|
|
cur_block, (dum1, dum2, dum3)
|
1992-04-13 15:38:20 -03:00
|
|
|
|
|
|
|
if state <> CD.READY:
|
|
|
|
player.close()
|
1992-04-15 14:49:14 -03:00
|
|
|
raise Error, 'CD not ready'
|
1992-04-13 15:38:20 -03:00
|
|
|
if not scsi_audio:
|
|
|
|
player.close()
|
1992-04-15 14:49:14 -03:00
|
|
|
raise Error, 'not an audio-capable CD-ROM player'
|
1992-04-13 15:38:20 -03:00
|
|
|
|
|
|
|
for i in range(first, last+1):
|
|
|
|
trackinfo = player.gettrackinfo(i)
|
1992-04-15 14:49:14 -03:00
|
|
|
print 'Track', i, trackinfo
|
|
|
|
|
|
|
|
if sys.argv[1:]:
|
|
|
|
print 'Start at track', sys.argv[1]
|
|
|
|
player.seektrack(eval(sys.argv[1]))
|
1992-04-13 15:38:20 -03:00
|
|
|
|
|
|
|
size = player.bestreadsize()
|
|
|
|
|
1992-04-14 08:07:19 -03:00
|
|
|
oldparams = [AL.OUTPUT_RATE, 0]
|
|
|
|
params = oldparams[:]
|
|
|
|
al.getparams(AL.DEFAULT_DEVICE, oldparams)
|
|
|
|
params[1] = AL.RATE_44100
|
1992-04-13 15:38:20 -03:00
|
|
|
try:
|
|
|
|
al.setparams(AL.DEFAULT_DEVICE, params)
|
|
|
|
config = al.newconfig()
|
|
|
|
config.setwidth(AL.SAMPLE_16)
|
|
|
|
config.setchannels(AL.STEREO)
|
|
|
|
port = al.openport('CD Player', 'w', config)
|
|
|
|
|
|
|
|
parser.setcallback(CD.AUDIO, playaudio, port)
|
|
|
|
for i in range(1, 8):
|
|
|
|
parser.setcallback(i, callback, port)
|
|
|
|
parser.removecallback(CD.ATIME)
|
|
|
|
parser.removecallback(CD.PTIME)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
frames = player.readda(size)
|
|
|
|
if frames == '':
|
|
|
|
break
|
|
|
|
parser.parseframe(frames)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
|
|
|
al.setparams(AL.DEFAULT_DEVICE, oldparams)
|
|
|
|
player.close()
|
|
|
|
parser.deleteparser()
|
|
|
|
|
|
|
|
main()
|