Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b950629

Browse files
committed
Initial revision
1 parent 9a1425d commit b950629

6 files changed

Lines changed: 377 additions & 0 deletions

File tree

Demo/sgi/cd/README

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
These are some programs to work with the SCSI CD-ROM player's audio
2+
interface (see cdaudio(3) in IRIX 4.0[.2?] or higher). At the moment
3+
the Python code is not very clean, sorry about that...
4+
5+
cdwin.py A trivial window interface to play a CD over the CD
6+
player's audio jack. More functionality is left as an
7+
excersice to the reader. Uses module stdwin.
8+
9+
listcd.py List the table-of-contents of a CD (data CDs will
10+
appear as a single track).
11+
12+
playcd.py Read audio data from the CD and play it over the
13+
Indigo's built-in speker or audio jack. Uses module al.
14+
15+
sendcd.py Read audio data from the CD and send it as UDP packets
16+
over the network (to readcd.py).
17+
18+
readcd.py Receive UDP packets containing CD audio data (from
19+
sendcd.py) and play them over the Indigo's built-in
20+
speaker or audio jack. Uses module al. (Doesn't
21+
actually use module cd.)
22+
23+
Note that to read *data* CD-ROMs you must open /dev/rdsk/dks0d4s7...

Demo/sgi/cd/cdwin.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import cd
2+
import stdwin
3+
from stdwinevents import *
4+
import mainloop
5+
6+
def main():
7+
player = cd.open()
8+
stdwin.setdefscrollbars(0, 0)
9+
win = stdwin.open('CD')
10+
win.player = player
11+
win.dispatch = cddispatch
12+
mainloop.register(win)
13+
win.settimer(10)
14+
mainloop.mainloop()
15+
16+
def cddispatch(type, win, detail):
17+
if type == WE_NULL:
18+
pass
19+
elif type == WE_CLOSE:
20+
mainloop.unregister(win)
21+
win.close()
22+
elif type == WE_DRAW:
23+
draw(win)
24+
elif type == WE_TIMER:
25+
update(win)
26+
elif type == WE_MOUSE_UP:
27+
left, top, right, bottom, v1, v2 = getgeo(win)
28+
h, v = detail[0]
29+
if left < h < right:
30+
if top < v < v1:
31+
but1(win)
32+
elif v1 < v < v2:
33+
but2(win)
34+
elif v2 < v < bottom:
35+
but3(win)
36+
else:
37+
stdwin.fleep()
38+
39+
def but1(win):
40+
update(win)
41+
42+
def but2(win):
43+
win.player.togglepause()
44+
update(win)
45+
46+
def but3(win):
47+
win.player.stop()
48+
update(win)
49+
50+
def update(win):
51+
d = win.begindrawing()
52+
drawstatus(win, d)
53+
d.enddrawing()
54+
win.settimer(10)
55+
56+
statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']
57+
58+
def draw(win):
59+
left, top, right, bottom, v1, v2 = getgeo(win)
60+
d = win.begindrawing()
61+
drawstatus(win, d)
62+
box(d, left, v1, right, v2, 'Play/Pause')
63+
box(d, left, v2, right, bottom, 'Stop')
64+
d.enddrawing()
65+
66+
def drawstatus(win, d):
67+
left, top, right, bottom, v1, v2 = getgeo(win)
68+
status = win.player.getstatus()
69+
state = status[0]
70+
if 0 <= state < len(statedict):
71+
message = statedict[state]
72+
else:
73+
message = `status`
74+
message = message + ' track ' + `status[1]` + ' of ' + `status[12]`
75+
d.erase((left, top), (right, v1))
76+
box(d, left, top, right, v1, message)
77+
78+
def box(d, left, top, right, bottom, label):
79+
R = (left+1, top+1), (right-1, bottom-1)
80+
width = d.textwidth(label)
81+
height = d.lineheight()
82+
h = (left + right - width) / 2
83+
v = (top + bottom - height) / 2
84+
d.box(R)
85+
d.cliprect(R)
86+
d.text((h, v), label)
87+
d.noclip()
88+
89+
def getgeo(win):
90+
(left, top), (right, bottom) = (0, 0), win.getwinsize()
91+
v1 = top + (bottom - top) / 3
92+
v2 = top + (bottom - top) * 2 / 3
93+
return left, top, right, bottom, v1, v2

Demo/sgi/cd/listcd.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# List track info from CD player.
2+
3+
import cd
4+
5+
def main():
6+
c = cd.open()
7+
info = []
8+
while 1:
9+
try:
10+
info.append(c.gettrackinfo(len(info) + 1))
11+
except RuntimeError:
12+
break
13+
for i in range(len(info)):
14+
start_min, start_sec, start_frame, \
15+
total_min, total_sec, total_frame = info[i]
16+
print 'Track', z(i+1),
17+
print z(start_min) + ':' + z(start_sec) + ':' + z(start_frame),
18+
print z(total_min) + ':' + z(total_sec) + ':' + z(total_frame)
19+
20+
def z(n):
21+
s = `n`
22+
return '0' * (2 - len(s)) + s

Demo/sgi/cd/playcd.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Read CD audio data from the SCSI bus and play it back over the
2+
# built-in speaker or audio jack.
3+
4+
import al
5+
import AL
6+
import cd
7+
import CD
8+
9+
def playaudio(port, type, audio):
10+
## print 'playaudio'
11+
port.writesamps(audio)
12+
13+
callbacks = ['audio', 'pnum', 'index', 'ptime', 'atime', 'catalog', 'ident', 'control']
14+
15+
def callback(port, type, data):
16+
print 'type', callbacks[type], 'data', `data`
17+
18+
def main():
19+
player = cd.open()
20+
parser = cd.createparser()
21+
22+
state, track, min, sec, frame, abs_min, abs_sec, abs_frame, \
23+
total_min, total_sec, total_frame, first, last, scsi_audio, \
24+
cur_block, dum1, dum2, dum3 = player.getstatus()
25+
print `state, track, min, sec, frame, abs_min, abs_sec, abs_frame, \
26+
total_min, total_sec, total_frame, first, last, scsi_audio, \
27+
cur_block, dum1, dum2, dum3`
28+
29+
if state <> CD.READY:
30+
player.close()
31+
raise 'playcd.Error', 'CD not ready'
32+
if not scsi_audio:
33+
player.close()
34+
raise 'playcd.Error', 'not an audio-capable CD-ROM player'
35+
36+
for i in range(first, last+1):
37+
trackinfo = player.gettrackinfo(i)
38+
print `trackinfo`
39+
40+
size = player.bestreadsize()
41+
42+
try:
43+
oldparams = [AL.OUTPUT_RATE, 0]
44+
params = oldparams[:]
45+
al.getparams(AL.DEFAULT_DEVICE, oldparams)
46+
params[1] = AL.RATE_44100
47+
al.setparams(AL.DEFAULT_DEVICE, params)
48+
config = al.newconfig()
49+
config.setwidth(AL.SAMPLE_16)
50+
config.setchannels(AL.STEREO)
51+
port = al.openport('CD Player', 'w', config)
52+
53+
parser.setcallback(CD.AUDIO, playaudio, port)
54+
for i in range(1, 8):
55+
parser.setcallback(i, callback, port)
56+
parser.removecallback(CD.ATIME)
57+
parser.removecallback(CD.PTIME)
58+
59+
while 1:
60+
frames = player.readda(size)
61+
if frames == '':
62+
break
63+
parser.parseframe(frames)
64+
except KeyboardInterrupt:
65+
pass
66+
67+
al.setparams(AL.DEFAULT_DEVICE, oldparams)
68+
player.close()
69+
parser.deleteparser()
70+
71+
main()

Demo/sgi/cd/recvcd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
7+
PORT = 50505 # Must match the port in sendcd.py
8+
9+
def main():
10+
s = socket(AF_INET, SOCK_DGRAM)
11+
s.bind('', PORT)
12+
13+
c = al.newconfig()
14+
c.setchannels(2)
15+
c.setwidth(2)
16+
p = al.openport('Audio from CD', 'w', c)
17+
al.setparams(AL.DEFAULT_DEVICE, [AL.OUTPUT_RATE, AL.RATE_44100])
18+
19+
N = 2352
20+
while 1:
21+
data = s.recv(N)
22+
if not data:
23+
print 'EOF'
24+
break
25+
p.writesamps(data)

Demo/sgi/cd/sendcd.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Read CD audio data from the SCSI CD player and send it as UDP
2+
# packets to "readcd.py" on another host.
3+
# Option:
4+
# "-l" lists track info and quits.
5+
# "-s" displays status and quits.
6+
7+
import cd
8+
import sys
9+
from socket import *
10+
import getopt
11+
12+
HOST = 'voorn.cwi.nl' # The host where readcd.py is run
13+
PORT = 50505 # Must match the port in readcd.py
14+
15+
def main():
16+
try:
17+
optlist, args = getopt.getopt(sys.argv[1:], 'ls')
18+
except getopt.error, msg:
19+
sys.stderr.write(msg + '\n')
20+
sys.exit(2)
21+
22+
player = cd.open()
23+
prstatus(player)
24+
size = player.bestreadsize()
25+
26+
if optlist:
27+
for opt, arg in optlist:
28+
if opt == '-l':
29+
prtrackinfo(player)
30+
elif opt == '-s':
31+
prstatus(player)
32+
return
33+
34+
sys.stdout.write('waiting for socket... ')
35+
sys.stdout.flush()
36+
port = socket(AF_INET, SOCK_DGRAM)
37+
port.connect(HOST, PORT)
38+
print 'socket connected'
39+
40+
parser = cd.createparser()
41+
parser.setcallback(0, audiocallback, port)
42+
parser.setcallback(1, pnumcallback, player)
43+
parser.setcallback(2, indexcallback, None)
44+
## 3 = ptime: too many calls
45+
## 4 = atime: too many calls
46+
parser.setcallback(5, catalogcallback, None)
47+
parser.setcallback(6, identcallback, None)
48+
parser.setcallback(7, controlcallback, None)
49+
50+
if len(args) >= 2:
51+
if len(args) >= 3:
52+
[min, sec, frame] = args[:3]
53+
else:
54+
[min, sec] = args
55+
frame = 0
56+
min, sec, frame = eval(min), eval(sec), eval(frame)
57+
print 'Seek to', triple(min, sec, frame)
58+
dummy = player.seek(min, sec, frame)
59+
elif len(args) == 1:
60+
track = eval(args[0])
61+
print 'Seek to track', track
62+
dummy = player.seektrack(track)
63+
else:
64+
min, sec, frame = player.getstatus()[5:8]
65+
print 'Try to seek back to', triple(min, sec, frame)
66+
try:
67+
player.seek(min, sec, frame)
68+
except RuntimeError:
69+
print 'Seek failed'
70+
71+
try:
72+
while 1:
73+
frames = player.readda(size)
74+
if frames == '':
75+
print 'END OF CD'
76+
break
77+
parser.parseframe(frames)
78+
except KeyboardInterrupt:
79+
print '[Interrupted]'
80+
pass
81+
82+
def prtrackinfo(player):
83+
info = []
84+
while 1:
85+
try:
86+
info.append(player.gettrackinfo(len(info) + 1))
87+
except RuntimeError:
88+
break
89+
for i in range(len(info)):
90+
start_min, start_sec, start_frame, \
91+
total_min, total_sec, total_frame = info[i]
92+
print 'Track', zfill(i+1), \
93+
triple(start_min, start_sec, start_frame), \
94+
triple(total_min, total_sec, total_frame)
95+
96+
def audiocallback(port, type, data):
97+
## sys.stdout.write('#')
98+
## sys.stdout.flush()
99+
port.send(data)
100+
101+
def pnumcallback(player, type, data):
102+
print 'pnum =', `data`
103+
prstatus(player)
104+
105+
def indexcallback(arg, type, data):
106+
print 'index =', `data`
107+
108+
def catalogcallback(arg, type, data):
109+
print 'catalog =', `data`
110+
111+
def identcallback(arg, type, data):
112+
print 'ident =', `data`
113+
114+
def controlcallback(arg, type, data):
115+
print 'control =', `data`
116+
117+
statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']
118+
119+
def prstatus(player):
120+
state, track, min, sec, frame, abs_min, abs_sec, abs_frame, \
121+
total_min, total_sec, total_frame, first, last, scsi_audio, \
122+
cur_block, dum1, dum2, dum3 = player.getstatus()
123+
print 'Status:',
124+
if 0 <= state < len(statedict):
125+
print statedict[state]
126+
else:
127+
print state
128+
print 'Track: ', track
129+
print 'Time: ', triple(min, sec, frame)
130+
print 'Abs: ', triple(abs_min, abs_sec, abs_frame)
131+
print 'Total: ', triple(total_min, total_sec, total_frame)
132+
print 'First: ', first
133+
print 'Last: ', last
134+
print 'SCSI: ', scsi_audio
135+
print 'Block: ', cur_block
136+
print 'Future:', (dum1, dum2, dum3)
137+
138+
def triple(a, b, c):
139+
return zfill(a) + ':' + zfill(b) + ':' + zfill(c)
140+
141+
def zfill(n):
142+
s = `n`
143+
return '0' * (2 - len(s)) + s

0 commit comments

Comments
 (0)