コード例 #1
0
ファイル: rec_play.py プロジェクト: asottile/ancient-pythons
def playit (buf) :
	p = al.openport('hello', 'w')
	print 'playing...'
	p.writesamps(buf)
	while p.getfilled() > 0:
		time.millisleep(10)
	print 'done.'
	p.closeport()
コード例 #2
0
ファイル: rec_play.py プロジェクト: 8Banana/py1.0
def playit(buf):
    p = al.openport('hello', 'w')
    print 'playing...'
    p.writesamps(buf)
    while p.getfilled() > 0:
        time.millisleep(10)
    print 'done.'
    p.closeport()
コード例 #3
0
def tryrecv(s):
    cnt = 0
    while 1:
        if s.avail():
            return s.recvfrom(MSGSIZE)
        time.millisleep(100)
        cnt = cnt + 100
        if cnt > MSGTIMEOUT:
            raise recv_timeout
コード例 #4
0
def main():
	s = socket(AF_INET, SOCK_DGRAM)
	s.bind('', PORT)

	foreground()
	wid = winopen('tv')
	RGBmode()
	gconfig()
	qdevice(ESCKEY)

	oldw, oldh = getsize()
	ortho2(0, oldw, 0, oldh)
	testimage()

	t1 = millitimer()

	while 1:
		if qtest():
			dev, val = qread()
			if dev == ESCKEY:
				winclose(wid)
				return
			elif dev == REDRAW:
				oldw, oldh = reshape()
		elif s.avail():
			data = s.recv(17000)
			header = string.strip(data[:HS])
			w, h, pf, x1, y1, x2, y2 = eval(header)
			if (w, h) <> (oldw, oldh):
				x, y = getorigin()
				x, y = x-1, y+21 # TWM correction
				winposition(x, x+w-1, y+oldh-h, y+oldh-1)
				oldw, oldh = reshape()
			data2 = data[HS:]
			dx = (x2-x1+1)/pf
			dy = (y2-y1+1)/pf
			data3 = unpackrect(dx, dy, 1, data2)
			rectzoom(pf, pf)
			lrectwrite(x1, y1, x1+dx-1, y1+dy-1, data3)
			t1 = millitimer()
		else:
			t2 = millitimer()
			if t2-t1 >= 5000:
				testimage()
				t1 = t2
			else:
				millisleep(10)

	winclose(wid)
	return data
コード例 #5
0
ファイル: playold.py プロジェクト: 8Banana/py1.0
def main():
    if len(sys.argv) < 2:
        f = sys.stdin
        filename = sys.argv[0]
    else:
        if len(sys.argv) <> 2:
            sys.stderr.write('usage: ' + \
               sys.argv[0] + ' filename\n')
            sys.exit(2)
        filename = sys.argv[1]
        f = open(filename, 'r')
    #
    magic = f.read(4)
    extra = ''
    if magic == '0008':
        rate = 8000
    elif magic == '0016':
        rate = 16000
    elif magic == '0032':
        rate = 32000
    else:
        sys.stderr.write('no magic header; assuming 8k samples/sec.\n')
        rate = 8000
        extra = magic
    #
    pv = [AL.OUTPUT_RATE, rate]
    al.setparams(AL.DEFAULT_DEVICE, pv)
    c = al.newconfig()
    c.setchannels(AL.MONO)
    c.setwidth(AL.SAMPLE_8)
    port = al.openport(filename, 'w', c)
    if extra:
        port.writesamps(extra)
    while 1:
        buf = f.read(BUFSIZE)
        if not buf: break
        port.writesamps(buf)
    while port.getfilled() > 0:
        time.millisleep(100)
コード例 #6
0
ファイル: playold.py プロジェクト: asottile/ancient-pythons
def main():
	if len(sys.argv) < 2:
		f = sys.stdin
		filename = sys.argv[0]
	else:
		if len(sys.argv) <> 2:
			sys.stderr.write('usage: ' + \
					 sys.argv[0] + ' filename\n')
			sys.exit(2)
		filename = sys.argv[1]
		f = open(filename, 'r')
	#
	magic = f.read(4)
	extra = ''
	if magic == '0008':
		rate = 8000
	elif magic == '0016':
		rate = 16000
	elif magic == '0032':
		rate = 32000
	else:
		sys.stderr.write('no magic header; assuming 8k samples/sec.\n')
		rate = 8000
		extra = magic
	#
	pv = [AL.OUTPUT_RATE, rate]
	al.setparams(AL.DEFAULT_DEVICE, pv)
	c = al.newconfig()
	c.setchannels(AL.MONO)
	c.setwidth(AL.SAMPLE_8)
	port = al.openport(filename, 'w', c)
	if extra:
		port.writesamps(extra)
	while 1:
		buf = f.read(BUFSIZE)
		if not buf: break
		port.writesamps(buf)
	while port.getfilled() > 0:
		time.millisleep(100)
コード例 #7
0
def delayfunc(msecs):
    #
    # Check for immediate stdwin event
    #
    event = stdwinq.pollevent()
    if event:
        mainloop.dispatch(event)
        return
    #
    # Use millisleep for very short delays or if there are no windows
    #
    if msecs < 100 or mainloop.countwindows() == 0:
        if msecs > 0:
            time.millisleep(msecs)
        return
    #
    # Post a timer event on an arbitrary window and wait for it
    #
    window = mainloop.anywindow()
    window.settimer(msecs / 100)
    event = stdwinq.getevent()
    window.settimer(0)
    if event[0] <> WE_TIMER:
        mainloop.dispatch(event)
コード例 #8
0
def delayfunc(msecs):
	#
	# Check for immediate stdwin event
	#
	event = stdwinq.pollevent()
	if event:
		mainloop.dispatch(event)
		return
	#
	# Use millisleep for very short delays or if there are no windows
	#
	if msecs < 100 or mainloop.countwindows() == 0:
		if msecs > 0:
			time.millisleep(msecs)
		return
	#
	# Post a timer event on an arbitrary window and wait for it
	#
	window = mainloop.anywindow()
	window.settimer(msecs/100)
	event = stdwinq.getevent()
	window.settimer(0)
	if event[0] <> WE_TIMER:
		mainloop.dispatch(event)
コード例 #9
0
ファイル: playaiff.py プロジェクト: 8Banana/py1.0
def play(p, data, offset, blocksize):
    data = data[offset:]
    p.writesamps(data)
    while p.getfilled() > 0:
        time.millisleep(10)
コード例 #10
0
ファイル: alwatch.py プロジェクト: 8Banana/py1.0
import time
import al, AL
import string

dev = AL.DEFAULT_DEVICE

source_name = ['line', 'microphone', 'digital']

params = al.queryparams(dev)
for i in range(1, len(params), 2):
	params[i] = -1
while 1:
	time.millisleep(100)
	old = params[:]
	al.getparams(dev, params)
	if params <> old:
		for i in range(0, len(params), 2):
			if params[i+1] <> old[i+1]:
				name = al.getname(dev, params[i])
				if params[i] == AL.INPUT_SOURCE:
					if 0 <= old[i+1] < len(source_name):
						oldval = source_name[old[i+1]]
					else:
						oldval = ''
					newval = source_name[params[i+1]]
				else:
					oldval = `old[i+1]`
					newval = `params[i+1]`
				print string.ljust(name, 25),
				print '(' + string.rjust(oldval, 10) + ')',
				print '-->',
コード例 #11
0
ファイル: video.py プロジェクト: nagayev/old-python
        writemask(0x7ff - ((1 << ybits) - 1))
        lrectwrite(0, 0, cw - 1, ch - 1, chromdata)
        writemask((1 << ybits) - 1)
        pixmode(PM_SIZE, 8)
    if pf:
        rectzoom(pf * mf, pf * mf)
    elif mf <> 1:
        rectzoom(mf, mf)
    lrectwrite(0, 0, w - 1, h - 1, data)
    # This is ugly here, but the only way to get the two
    # channels started in sync
    #if af <> None:
    #	playsound(af,spkr)
    ct = time.millitimer() - epoch.epoch
    if epoch.correcttiming and tijd > 0 and ct < tijd:
        time.millisleep(tijd - ct)
    #swapbuffers()
    return tijd


def initcmap(ybits, ibits, qbits, chrompack):
    if ybits + ibits + qbits > 11:
        raise 'Sorry, 11 bits max'
    maxy = pow(2, ybits)
    maxi = pow(2, ibits)
    maxq = pow(2, qbits)
    for i in range(2048, 4096 - 256):
        mapcolor(i, 0, 255, 0)
    for y in range(maxy):
        yv = float(y) / float(maxy - 1)
        for i in range(maxi):