1992-04-22 10:47:50 -03:00
|
|
|
# Play CD audio on speaker or headphones.
|
|
|
|
|
1992-06-03 13:49:29 -03:00
|
|
|
callbacktypes = ['audio','pnum','index','ptime','atime','catalog','ident','control']
|
|
|
|
|
1992-04-13 15:38:20 -03:00
|
|
|
def playaudio(port, type, audio):
|
|
|
|
port.writesamps(audio)
|
|
|
|
|
1992-06-03 13:49:29 -03:00
|
|
|
def prtrack(cdinfo, type, pnum):
|
|
|
|
if cdinfo.track[pnum] <> '':
|
|
|
|
print 'playing "' + cdinfo.track[pnum] + '"'
|
|
|
|
else:
|
|
|
|
print callbacktypes[type]+': '+`pnum`
|
|
|
|
|
1992-04-22 10:39:48 -03:00
|
|
|
def callback(arg, type, data):
|
1992-06-03 13:49:29 -03:00
|
|
|
print callbacktypes[type]+': '+`data`
|
|
|
|
|
|
|
|
def tcallback(arg, type, data):
|
|
|
|
print callbacktypes[type]+': '+triple(data)
|
1992-04-22 10:39:48 -03:00
|
|
|
|
|
|
|
def triple((a, b, c)):
|
|
|
|
return zfill(a) + ':' + zfill(b) + ':' + zfill(c)
|
|
|
|
|
|
|
|
def zfill(n):
|
|
|
|
s = `n`
|
|
|
|
return '0' * (2 - len(s)) + s
|
|
|
|
|
|
|
|
def prtrackinfo(info):
|
|
|
|
for i in range(len(info)):
|
|
|
|
start, total = info[i]
|
|
|
|
print 'Track', zfill(i+1), triple(start), triple(total)
|
|
|
|
|
|
|
|
statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']
|
|
|
|
|
|
|
|
def prstatus(status):
|
|
|
|
state, track, curtime, abstime, totaltime, first, last, \
|
|
|
|
scsi_audio, cur_block, dummy = status
|
|
|
|
print 'Status:',
|
|
|
|
if 0 <= state < len(statedict):
|
|
|
|
print statedict[state]
|
|
|
|
else:
|
|
|
|
print state
|
|
|
|
print 'Track: ', track
|
|
|
|
print 'Time: ', triple(curtime)
|
|
|
|
print 'Abs: ', triple(abstime)
|
|
|
|
print 'Total: ', triple(totaltime)
|
|
|
|
print 'First: ', first
|
|
|
|
print 'Last: ', last
|
|
|
|
print 'SCSI: ', scsi_audio
|
|
|
|
print 'Block: ', cur_block
|
|
|
|
print 'Future:', dummy
|
1992-04-15 14:49:14 -03:00
|
|
|
|
1992-04-13 15:38:20 -03:00
|
|
|
def main():
|
1995-04-06 11:46:31 -03:00
|
|
|
import sys, readcd, al, AL, cd, cdplayer
|
1992-06-03 13:49:29 -03:00
|
|
|
verbose = 0
|
1994-10-07 07:25:49 -03:00
|
|
|
r = readcd.Readcd()
|
1992-04-22 10:39:48 -03:00
|
|
|
prstatus(r.getstatus())
|
|
|
|
prtrackinfo(r.gettrackinfo())
|
1994-10-07 07:25:49 -03:00
|
|
|
cdinfo = cdplayer.Cdplayer(r.gettrackinfo())
|
1992-06-03 13:49:29 -03:00
|
|
|
if cdinfo.title <> '':
|
|
|
|
print 'Title: "' + cdinfo.title + '"'
|
|
|
|
if cdinfo.artist <> '':
|
|
|
|
print 'Artist: ' + cdinfo.artist
|
1992-04-22 10:39:48 -03:00
|
|
|
for arg in sys.argv[1:]:
|
1992-06-03 13:49:29 -03:00
|
|
|
if arg == '-v':
|
|
|
|
verbose = 1
|
|
|
|
continue
|
1992-04-22 10:39:48 -03:00
|
|
|
x = eval(arg)
|
|
|
|
try:
|
|
|
|
l = len(x)
|
|
|
|
r.appendstretch(x[0], x[1])
|
|
|
|
except TypeError:
|
|
|
|
r.appendtrack(x)
|
1992-04-13 15:38:20 -03:00
|
|
|
try:
|
1992-04-22 10:39:48 -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
|
|
|
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)
|
|
|
|
|
1992-04-22 10:39:48 -03:00
|
|
|
for i in range(8):
|
|
|
|
r.setcallback(i, callback, None)
|
1992-06-03 13:49:29 -03:00
|
|
|
if verbose:
|
1995-04-06 11:46:31 -03:00
|
|
|
r.setcallback(cd.ptime, tcallback, None)
|
|
|
|
r.setcallback(cd.atime, tcallback, None)
|
1992-06-03 13:49:29 -03:00
|
|
|
else:
|
1995-04-06 11:46:31 -03:00
|
|
|
r.removecallback(cd.ptime)
|
|
|
|
r.removecallback(cd.atime)
|
|
|
|
r.setcallback(cd.pnum, prtrack, cdinfo)
|
|
|
|
r.setcallback(cd.audio, playaudio, port)
|
1992-04-13 15:38:20 -03:00
|
|
|
|
1992-04-22 10:39:48 -03:00
|
|
|
data = r.play()
|
1992-04-13 15:38:20 -03:00
|
|
|
except KeyboardInterrupt:
|
1992-06-03 13:49:29 -03:00
|
|
|
status = r.getstatus()
|
|
|
|
print 'Interrupted at '+triple(status[2])+' into track '+ \
|
|
|
|
`status[1]`+' (absolute time '+triple(status[3])+')'
|
1992-04-13 15:38:20 -03:00
|
|
|
al.setparams(AL.DEFAULT_DEVICE, oldparams)
|
|
|
|
|
|
|
|
main()
|