コード例 #1
0
def ioloop1(s, otheraddr):
	#
	# Watch out! data is in bytes, but the port counts in samples,
	# which are two bytes each (for 16-bit samples).
	# Luckily, we use mono, else it would be worse (2 samples/frame...)
	#
	SAMPSPERBUF = 500
	BYTESPERSAMP = 2 # AL.SAMPLE_16
	BUFSIZE = BYTESPERSAMP*SAMPSPERBUF
	QSIZE = 4*SAMPSPERBUF
	#
	config = al.newconfig()
	config.setqueuesize(QSIZE)
	config.setwidth(AL.SAMPLE_16)
	config.setchannels(AL.MONO)
	#
	pid = posix.fork()
	if pid:
		# Parent -- speaker/headphones handler
		log('parent started')
		spkr = al.openport('spkr', 'w', config)
		while 1:
			data = s.recv(BUFSIZE)
			if len(data) == 0:
				# EOF packet
				log('parent got empty packet; killing child')
				posix.kill(pid, 15)
				return
			# Discard whole packet if we are too much behind
			if spkr.getfillable() > len(data) / BYTESPERSAMP:
				if len(debug) >= 2:
					log('parent Q full; dropping packet')
				spkr.writesamps(data)
	else:
		# Child -- microphone handler
		log('child started')
		try:
		    try:
			    mike = al.openport('mike', 'r', config)
			    # Sleep a while to let the other side get started
			    time.sleep(1)
			    # Drain the queue before starting to read
			    data = mike.readsamps(mike.getfilled())
			    # Loop, sending packets from the mike to the net
			    while 1:
				    data = mike.readsamps(SAMPSPERBUF)
				    s.sendto(data, otheraddr)
		    except KeyboardInterrupt:
			    log('child got interrupt; exiting')
			    posix._exit(0)
		    except error:
			    log('child got error; exiting')
			    posix._exit(1)
		finally:
			log('child got unexpected error; leaving w/ traceback')
コード例 #2
0
ファイル: intercom.py プロジェクト: 8Banana/py1.0
def ioloop1(s, otheraddr):
    #
    # Watch out! data is in bytes, but the port counts in samples,
    # which are two bytes each (for 16-bit samples).
    # Luckily, we use mono, else it would be worse (2 samples/frame...)
    #
    SAMPSPERBUF = 500
    BYTESPERSAMP = 2  # AL.SAMPLE_16
    BUFSIZE = BYTESPERSAMP * SAMPSPERBUF
    QSIZE = 4 * SAMPSPERBUF
    #
    config = al.newconfig()
    config.setqueuesize(QSIZE)
    config.setwidth(AL.SAMPLE_16)
    config.setchannels(AL.MONO)
    #
    pid = posix.fork()
    if pid:
        # Parent -- speaker/headphones handler
        log('parent started')
        spkr = al.openport('spkr', 'w', config)
        while 1:
            data = s.recv(BUFSIZE)
            if len(data) == 0:
                # EOF packet
                log('parent got empty packet; killing child')
                posix.kill(pid, 15)
                return
            # Discard whole packet if we are too much behind
            if spkr.getfillable() > len(data) / BYTESPERSAMP:
                if len(debug) >= 2:
                    log('parent Q full; dropping packet')
                spkr.writesamps(data)
    else:
        # Child -- microphone handler
        log('child started')
        try:
            try:
                mike = al.openport('mike', 'r', config)
                # Sleep a while to let the other side get started
                time.sleep(1)
                # Drain the queue before starting to read
                data = mike.readsamps(mike.getfilled())
                # Loop, sending packets from the mike to the net
                while 1:
                    data = mike.readsamps(SAMPSPERBUF)
                    s.sendto(data, otheraddr)
            except KeyboardInterrupt:
                log('child got interrupt; exiting')
                posix._exit(0)
            except error:
                log('child got error; exiting')
                posix._exit(1)
        finally:
            log('child got unexpected error; leaving w/ traceback')
コード例 #3
0
	def __init__(self):
		parsetree = flp.parse_form('cmpaf_form','form')
		flp.create_full_form(self, parsetree)
		c = al.newconfig()
		c.setchannels(AL.MONO)
		c.setqueuesize(1800)
		self.iport = al.openport('cmpaf','r', c)
		self.oport = al.openport('cmpaf','w', c)
		self.do_adpcm = self.do_ulaw = self.do_diff = 0
		self.acstate = None
		self.form.show_form(FL.PLACE_SIZE, 1, 'compare audio formats')
コード例 #4
0
ファイル: Vb.py プロジェクト: asottile/ancient-pythons
	def open_audio(self):
		if self.aformat == A_OFF:
			return
		import aifc
		import al
		import AL
		import thread
		self.close_audio()
		params = [AL.INPUT_RATE, 0]
		al.getparams(AL.DEFAULT_DEVICE, params)
		rate = params[1]
		self.aout = aifc.open(self.afile, 'w')
		if self.aformat in (A_16_STEREO, A_8_STEREO):
			nch = AL.STEREO
		else:
			nch = AL.MONO
		if self.aformat in (A_16_STEREO, A_16_MONO):
			width = AL.SAMPLE_16
		else:
			width = AL.SAMPLE_8
		self.aout.setnchannels(nch)
		self.aout.setsampwidth(width)
		self.aout.setframerate(rate)
		c = al.newconfig()
		c.setqueuesize(8000)
		c.setchannels(nch)
		c.setwidth(width)
		self.aport = al.openport('Vb audio record', 'r', c)
		self.audio_stop = 0
		self.audio_ok = 0
		self.audio_busy = 1
		thread.start_new_thread(self.record_audio, ())
コード例 #5
0
ファイル: recvcd.py プロジェクト: 8Banana/py1.0
def main():
    s = socket(AF_INET, SOCK_DGRAM)
    s.bind('', PORT)

    oldparams = [AL.OUTPUT_RATE, 0]
    params = oldparams[:]
    al.getparams(AL.DEFAULT_DEVICE, oldparams)
    params[1] = AL.RATE_44100
    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)

        while 1:
            data = s.recv(CDDA_DATASIZE)
            if not data:
                print 'EOF'
                break
            port.writesamps(data)
    except KeyboardInterrupt:
        pass

    al.setparams(AL.DEFAULT_DEVICE, oldparams)
コード例 #6
0
ファイル: dald.py プロジェクト: 8Banana/py1.0
	def handle_11(self): # openport
		name, mode, config_flat = self.unpacker.unpack_openport()
		self.turn_around()
##		print 'openport:', name, mode, config_flat
		queuesize, width, channels, sampfmt, floatmax = config_flat
		try:
			c = al.newconfig()
			c.setqueuesize(queuesize)
			c.setwidth(width)
			c.setchannels(channels)
			c.setsampfmt(sampfmt)
			c.setfloatmax(floatmax)
			p = al.openport(name, mode, c)
		except RuntimeError:
			self.packer.pack_int(-1) # Should get error code?
			return
		for i in range(len(self.all_ports)):
			if self.all_ports[i] is None:
				self.all_ports[i] = p
				break
		else:
			i = len(self.all_ports)
			self.all_ports.append(p)
##		print 'openport ->', i
		self.packer.pack_int(i)
コード例 #7
0
ファイル: Vb.py プロジェクト: carol8421/gosh
	def open_audio(self):
		if self.aformat == A_OFF:
			return
		import aifc
		import al
		import AL
		import thread
		self.close_audio()
		params = [AL.INPUT_RATE, 0]
		al.getparams(AL.DEFAULT_DEVICE, params)
		rate = params[1]
		self.aout = aifc.open(self.afile, 'w')
		if self.aformat in (A_16_STEREO, A_8_STEREO):
			nch = AL.STEREO
		else:
			nch = AL.MONO
		if self.aformat in (A_16_STEREO, A_16_MONO):
			width = AL.SAMPLE_16
		else:
			width = AL.SAMPLE_8
		self.aout.setnchannels(nch)
		self.aout.setsampwidth(width)
		self.aout.setframerate(rate)
		c = al.newconfig()
		c.setqueuesize(8000)
		c.setchannels(nch)
		c.setwidth(width)
		self.aport = al.openport('Vb audio record', 'r', c)
		self.audio_stop = 0
		self.audio_ok = 0
		self.audio_busy = 1
		thread.start_new_thread(self.record_audio, ())
コード例 #8
0
ファイル: playaiff.py プロジェクト: 8Banana/py1.0
def makeport(nchannels, sampwidth, samprate):
    c = al.newconfig()
    c.setchannels(nchannels)
    c.setwidth(sampwidth / 8)
    # can't set the rate...
    p = al.openport('', 'w', c)
    return p
コード例 #9
0
def makeport(nchannels, sampwidth, samprate):
	c = al.newconfig()
	c.setchannels(nchannels)
	c.setwidth(sampwidth/8)
	# can't set the rate...
	p = al.openport('', 'w', c)
	return p
コード例 #10
0
def main():
	c = al.newconfig()
	c.setchannels(AL.MONO)
	c.setqueuesize(QSIZE)
	p = al.openport('', 'w', c)
	while 1:
		data = sys.stdin.read(BUFSIZE)
		p.writesamps(data)
コード例 #11
0
def playit(buf):
    p = al.openport('hello', 'w')
    print 'playing...'
    p.writesamps(buf)
    while p.getfilled() > 0:
        time.sleep(0.01)
    print 'done.'
    p.closeport()
コード例 #12
0
def main():
    c = al.newconfig()
    c.setchannels(AL.MONO)
    c.setqueuesize(QSIZE)
    p = al.openport('', 'r', c)
    while 1:
        data = p.readsamps(BUFSIZE)
        sys.stdout.write(data)
コード例 #13
0
def playit (buf) :
	p = al.openport('hello', 'w')
	print 'playing...'
	p.writesamps(buf)
	while p.getfilled() > 0:
		time.sleep(0.01)
	print 'done.'
	p.closeport()
コード例 #14
0
def recordit () :
	p = al.openport('hello', 'r')
	print 'recording...'
	buf = p.readsamps(500000)
	print 'done.'
	p.closeport()
	
	return buf
コード例 #15
0
def recordit():
    p = al.openport('hello', 'r')
    print 'recording...'
    buf = p.readsamps(500000)
    print 'done.'
    p.closeport()

    return buf
コード例 #16
0
 def writeframes(self, data):
     if not self.__format or not self.__params[1]:
         raise Error, 'params not specified'
     if not self.__port:
         self.__port = al.openport('Python', 'w', self.__config)
         self.__oldparams = self.__params[:]
         al.getparams(al.DEFAULT_DEVICE, self.__oldparams)
         al.setparams(al.DEFAULT_DEVICE, self.__params)
     self.__port.writesamps(data)
コード例 #17
0
 def writeframes(self, data):
     if not (self.inited_outrate and self.inited_nchannels):
         raise error, 'params not specified'
     if not self.port:
         import al, AL
         self.port = al.openport('Python', 'w', self.config)
         self.oldparams = self.params[:]
         al.getparams(AL.DEFAULT_DEVICE, self.oldparams)
         al.setparams(AL.DEFAULT_DEVICE, self.params)
     if self.converter:
         data = self.converter(data)
     self.port.writesamps(data)
コード例 #18
0
ファイル: audiodev.py プロジェクト: webiumsk/WOT-0.9.15-CT
 def writeframes(self, data):
     if not (self.inited_outrate and self.inited_nchannels):
         raise error, 'params not specified'
     if not self.port:
         import al, AL
         self.port = al.openport('Python', 'w', self.config)
         self.oldparams = self.params[:]
         al.getparams(AL.DEFAULT_DEVICE, self.oldparams)
         al.setparams(AL.DEFAULT_DEVICE, self.params)
     if self.converter:
         data = self.converter(data)
     self.port.writesamps(data)
コード例 #19
0
ファイル: playcd.py プロジェクト: asottile/ancient-pythons
def main():
	import sys, readcd, al, AL, CD, cdplayer
	verbose = 0
	r = readcd.Readcd()
	prstatus(r.getstatus())
	prtrackinfo(r.gettrackinfo())
	cdinfo = cdplayer.Cdplayer(r.gettrackinfo())
	if cdinfo.title <> '':
		print 'Title: "' + cdinfo.title + '"'
	if cdinfo.artist <> '':
		print 'Artist: ' + cdinfo.artist
	for arg in sys.argv[1:]:
		if arg == '-v':
			verbose = 1
			continue
		x = eval(arg)
		try:
			l = len(x)
			r.appendstretch(x[0], x[1])
		except TypeError:
			r.appendtrack(x)
	try:
		oldparams = [AL.OUTPUT_RATE, 0]
		params = oldparams[:]
		al.getparams(AL.DEFAULT_DEVICE, oldparams)
		params[1] = AL.RATE_44100
		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)

		for i in range(8):
			r.setcallback(i, callback, None)
		if verbose:
			r.setcallback(CD.PTIME, tcallback, None)
			r.setcallback(CD.ATIME, tcallback, None)
		else:
			r.removecallback(CD.PTIME)
			r.removecallback(CD.ATIME)
		r.setcallback(CD.PNUM, prtrack, cdinfo)
		r.setcallback(CD.AUDIO, playaudio, port)

		data = r.play()
	except KeyboardInterrupt:
		status = r.getstatus()
		print 'Interrupted at '+triple(status[2])+' into track '+ \
			  `status[1]`+' (absolute time '+triple(status[3])+')'
	al.setparams(AL.DEFAULT_DEVICE, oldparams)
コード例 #20
0
def main():
    import sys, readcd, al, AL, CD, cdplayer
    verbose = 0
    r = readcd.Readcd().init()
    prstatus(r.getstatus())
    prtrackinfo(r.gettrackinfo())
    cdinfo = cdplayer.Cdplayer().init(r.gettrackinfo())
    if cdinfo.title <> '':
        print 'Title: "' + cdinfo.title + '"'
    if cdinfo.artist <> '':
        print 'Artist: ' + cdinfo.artist
    for arg in sys.argv[1:]:
        if arg == '-v':
            verbose = 1
            continue
        x = eval(arg)
        try:
            l = len(x)
            r.appendstretch(x[0], x[1])
        except TypeError:
            r.appendtrack(x)
    try:
        oldparams = [AL.OUTPUT_RATE, 0]
        params = oldparams[:]
        al.getparams(AL.DEFAULT_DEVICE, oldparams)
        params[1] = AL.RATE_44100
        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)

        for i in range(8):
            r.setcallback(i, callback, None)
        if verbose:
            r.setcallback(CD.PTIME, tcallback, None)
            r.setcallback(CD.ATIME, tcallback, None)
        else:
            r.removecallback(CD.PTIME)
            r.removecallback(CD.ATIME)
        r.setcallback(CD.PNUM, prtrack, cdinfo)
        r.setcallback(CD.AUDIO, playaudio, port)

        data = r.play()
    except KeyboardInterrupt:
        status = r.getstatus()
        print 'Interrupted at '+triple(status[2])+' into track '+ \
           `status[1]`+' (absolute time '+triple(status[3])+')'
    al.setparams(AL.DEFAULT_DEVICE, oldparams)
コード例 #21
0
ファイル: Vrecb.py プロジェクト: olympu/ancient-pythons
def initaudio(filename, stop, start, done):
    import thread, aifc
    afile = aifc.open(filename, 'w')
    afile.setnchannels(AL.MONO)
    afile.setsampwidth(AL.SAMPLE_8)
    params = [AL.INPUT_RATE, 0]
    al.getparams(AL.DEFAULT_DEVICE, params)
    print 'audio sampling rate =', params[1]
    afile.setframerate(params[1])
    c = al.newconfig()
    c.setchannels(AL.MONO)
    c.setqueuesize(AQSIZE)
    c.setwidth(AL.SAMPLE_8)
    aport = al.openport(filename, 'r', c)
    thread.start_new_thread(audiorecord, (afile, aport, stop, start, done))
コード例 #22
0
ファイル: Vrec.py プロジェクト: asottile/ancient-pythons
def initaudio(filename, stop, done):
	import thread, aifc
	afile = aifc.open(filename, 'w')
	afile.setnchannels(AL.MONO)
	afile.setsampwidth(AL.SAMPLE_8)
	params = [AL.INPUT_RATE, 0]
	al.getparams(AL.DEFAULT_DEVICE, params)
	print 'audio sampling rate =', params[1]
	afile.setframerate(params[1])
	c = al.newconfig()
	c.setchannels(AL.MONO)
	c.setqueuesize(AQSIZE)
	c.setwidth(AL.SAMPLE_8)
	aport = al.openport(filename, 'r', c)
	thread.start_new_thread(audiorecord, (afile, aport, stop, done))
コード例 #23
0
def initaudio(filename):
	import thread, aiff
	global recording, stop_recording
	afile = aiff.Aiff().init(filename, 'w')
	afile.nchannels = AL.MONO
	afile.sampwidth = AL.SAMPLE_8
	params = [AL.INPUT_RATE, 0]
	al.getparams(AL.DEFAULT_DEVICE, params)
	print 'rate =', params[1]
	afile.samprate = params[1]
	c = al.newconfig()
	c.setchannels(AL.MONO)
	c.setqueuesize(AQSIZE)
	c.setwidth(AL.SAMPLE_8)
	aport = al.openport(filename, 'r', c)
	recording = thread.allocate_lock()
	recording.acquire()
	stop_recording = 0
	thread.start_new_thread(recorder, (afile, aport))
	return afile
コード例 #24
0
ファイル: listen.py プロジェクト: Claruarius/stblinux-2.6.37
def main():
	if len(sys.argv) <> 2:
		sys.stderr.write('usage: ' + sys.argv[0] + ' hostname\n')
		sys.exit(2)
	hostname = sys.argv[1]
	cmd = 'exec rsh </dev/null ' + hostname + \
		' "cd /ufs/guido/mm/demo/audio; ' + \
		'exec /ufs/guido/bin/sgi/python record.py"'
	pipe = posix.popen(cmd, 'r')
	config = al.newconfig()
	config.setchannels(AL.MONO)
	config.setqueuesize(QSIZE)
	port = al.openport('', 'w', config)
	while 1:
		data = pipe.read(BUFSIZE)
		if not data:
			sts = pipe.close()
			sys.stderr.write(sys.argv[0] + ': end of data\n')
			if sts: sys.stderr.write('rsh exit status '+`sts`+'\n')
			sys.exit(1)
		port.writesamps(data)
		del data
コード例 #25
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)
コード例 #26
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)
コード例 #27
0
def main():
    if len(sys.argv) <> 2:
        sys.stderr.write('usage: ' + sys.argv[0] + ' hostname\n')
        sys.exit(2)
    hostname = sys.argv[1]
    cmd = 'exec rsh </dev/null ' + hostname + \
     ' "cd /ufs/guido/mm/demo/audio; ' + \
     'exec /ufs/guido/bin/sgi/python record.py"'
    pipe = posix.popen(cmd, 'r')
    config = al.newconfig()
    config.setchannels(AL.MONO)
    config.setqueuesize(QSIZE)
    port = al.openport('', 'w', config)
    while 1:
        data = pipe.read(BUFSIZE)
        if not data:
            sts = pipe.close()
            sys.stderr.write(sys.argv[0] + ': end of data\n')
            if sts: sys.stderr.write('rsh exit status ' + ` sts ` + '\n')
            sys.exit(1)
        port.writesamps(data)
        del data
コード例 #28
0
ファイル: unicast.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
# unicast host [port]
#
# Similar to "broadcast.py" but sends to a specific host only;
# use "radio.py" on the designated host to receive.
# This is less stressful on other hosts on the same ethernet segment
# if you need to send to one host only.
import sys, al
from socket import *
host = sys.argv[1]
port = 5555
if sys.argv[2:]: port = eval(sys.argv[1])
s = socket(AF_INET, SOCK_DGRAM)
p = al.openport('unicast', 'r')
address = host, port
while 1:
	# 700 samples equals 1400 bytes, or about the max packet size!
	data = p.readsamps(700)
	s.sendto(data, address)
コード例 #29
0
ファイル: audiodev.py プロジェクト: mcyril/ravel-ftn
"""Classes for manipulating audio devices (currently only for Sun and SGI)"""
コード例 #30
0
ファイル: playaiff.py プロジェクト: mcyril/ravel-ftn
import aiff
コード例 #31
0
ファイル: rec_play.py プロジェクト: mcyril/ravel-ftn
#
コード例 #32
0
ファイル: Vrec.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
コード例 #33
0
#! /usr/bin/env python
# broadcast [port]
#
# Broadcast audio input on the network as UDP packets;
# they can be received on any SGI machine with "radio.py".
# This uses the input sampling rate, input source etc. set by apanel.
# It uses the default sample width and #channels (16 bit/sample stereo).
# (This is 192,000 Bytes at a sampling speed of 48 kHz, or ~137
# packets/second -- use with caution!!!)
import sys, al
from socket import *
port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])
s = socket(AF_INET, SOCK_DGRAM)
s.allowbroadcast(1)
p = al.openport('broadcast', 'r')
address = '<broadcast>', port
while 1:
    # 700 samples equals 1400 bytes, or about the max packet size!
    data = p.readsamps(700)
    s.sendto(data, address)

コード例 #34
0
ファイル: radio.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
# radio [port]
#
# Receive audio packets broadcast by "broadcast.py" on another SGI machine.
# Use apanel to set the output sampling rate to match that of the broadcast.
import sys, al
from socket import *
port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])
s = socket(AF_INET, SOCK_DGRAM)
s.bind('', port)
p = al.openport('radio', 'w')
while 1:
	data = s.recv(1400)
	p.writesamps(data)
コード例 #35
0
ファイル: cmpaf.py プロジェクト: mcyril/ravel-ftn
# Compare different audio compression schemes.
コード例 #36
0
# Compare different audio compression schemes.
コード例 #37
0
#! /usr/local/bin/python

# broadcast [port]
#
# Broadcast audio input on the network as UDP packets;
# they can be received on any SGI machine with "radio.py".
# This uses the input sampling rate, input source etc. set by apanel.
# It uses the default sample width and #channels (16 bit/sample stereo).
# (This is 192,000 Bytes at a sampling speed of 48 kHz, or ~137
# packets/second -- use with caution!!!)

import sys, al
from socket import *

port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])

s = socket(AF_INET, SOCK_DGRAM)
s.allowbroadcast(1)

p = al.openport('broadcast', 'r')

address = '<broadcast>', port
while 1:
    # 700 samples equals 1400 bytes, or about the max packet size!
    data = p.readsamps(700)
    s.sendto(data, address)
コード例 #38
0
ファイル: audiodev.py プロジェクト: mcyril/ravel-ftn
"""Classes for manipulating audio devices (currently only for Sun and SGI)"""
コード例 #39
0
ファイル: record.py プロジェクト: mcyril/ravel-ftn
# Record mono 16bits samples from the audio device and send them to stdout.
コード例 #40
0
ファイル: aplay.py プロジェクト: asottile/ancient-pythons
		  ain.getnframes() * ain.getnchannels() * ain.getsampwidth()

	print 'Opening audio output port..'
	c = al.newconfig()
	c.setchannels(ain.getnchannels())
	c.setwidth(ain.getsampwidth())
	nullsample = '\0' * ain.getsampwidth()
	samples_per_second = ain.getnchannels() * ain.getframerate()
	if qsize <= 0: qsize = samples_per_second / 10
	qsize = max(qsize, 512)
	c.setqueuesize(qsize)
	saveparams = [AL.OUTPUT_RATE, 0]
	al.getparams(AL.DEFAULT_DEVICE, saveparams)
	newparams = [AL.OUTPUT_RATE, ain.getframerate()]
	al.setparams(AL.DEFAULT_DEVICE, newparams)
	aport = al.openport(audiofile, 'w', c)

	print 'Opening video output window..'
	gl.foreground()
	gl.prefsize(vin.width, vin.height)
	wid = gl.winopen(videofile + ' + ' + audiofile)
	gl.clear()
	vin.initcolormap()

	print 'Playing..'
	gl.qdevice(DEVICE.ESCKEY)
	gl.qdevice(DEVICE.LEFTARROWKEY)
	gl.qdevice(DEVICE.RIGHTARROWKEY)
##	gl.qdevice(DEVICE.UPARROWKEY)
##	gl.qdevice(DEVICE.DOWNARROWKEY)
	gl.qdevice(DEVICE.SPACEKEY)
コード例 #41
0
#! /usr/bin/env python
# radio [port]
#
# Receive audio packets broadcast by "broadcast.py" on another SGI machine.
# Use apanel to set the output sampling rate to match that of the broadcast.
import sys, al
from socket import *
port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])
s = socket(AF_INET, SOCK_DGRAM)
s.bind('', port)
p = al.openport('radio', 'w')
while 1:
    data = s.recv(1400)
    p.writesamps(data)

コード例 #42
0
ファイル: aplay.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
# Play synchronous video and audio.
# Highly experimental!
import sys
import getopt
import string
import os
import VFile
import aifc
import gl, GL, DEVICE
import al, AL

def usage():
	sys.stderr.write( \
		'usage: aplay [-o offset] [-q qsize] videofile audiofile\n')
	sys.exit(2)
def main():
	offset = 0
	qsize = 0 # This defaults to 1/10 second of sound
	videofile = 'film.video'
	audiofile = 'film.aiff'
	try:
		opts, args = getopt.getopt(sys.argv[1:], 'o:q:')
	except getopt.error, msg:
		sys.stderr.write(msg + '\n')
		usage()
	try:
		for o, a in opts:
			if o == '-o':
				offset = string.atoi(a)
コード例 #43
0
ファイル: radio.py プロジェクト: Claruarius/stblinux-2.6.37
#! /usr/bin/env python

# radio [port]
#
# Receive audio packets broadcast by "broadcast.py" on another SGI machine.
# Use apanel to set the output sampling rate to match that of the broadcast.

import sys, al
from socket import *

port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])

s = socket(AF_INET, SOCK_DGRAM)
s.bind('', port)

p = al.openport('radio', 'w')

while 1:
	data = s.recv(1400)
	p.writesamps(data)
コード例 #44
0
ファイル: intercom.py プロジェクト: mcyril/ravel-ftn
# intercom -- use mike and headset to *talk* to a person on another host.
コード例 #45
0
ファイル: Vrecb.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
コード例 #46
0
       ain.getnframes() * ain.getnchannels() * ain.getsampwidth()

    print 'Opening audio output port..'
    c = al.newconfig()
    c.setchannels(ain.getnchannels())
    c.setwidth(ain.getsampwidth())
    nullsample = '\0' * ain.getsampwidth()
    samples_per_second = ain.getnchannels() * ain.getframerate()
    if qsize <= 0: qsize = samples_per_second / 10
    qsize = max(qsize, 512)
    c.setqueuesize(qsize)
    saveparams = [AL.OUTPUT_RATE, 0]
    al.getparams(AL.DEFAULT_DEVICE, saveparams)
    newparams = [AL.OUTPUT_RATE, ain.getframerate()]
    al.setparams(AL.DEFAULT_DEVICE, newparams)
    aport = al.openport(audiofile, 'w', c)

    print 'Opening video output window..'
    gl.foreground()
    gl.prefsize(vin.width, vin.height)
    wid = gl.winopen(videofile + ' + ' + audiofile)
    gl.clear()
    vin.initcolormap()

    print 'Playing..'
    gl.qdevice(DEVICE.ESCKEY)
    gl.qdevice(DEVICE.LEFTARROWKEY)
    gl.qdevice(DEVICE.RIGHTARROWKEY)
    ##	gl.qdevice(DEVICE.UPARROWKEY)
    ##	gl.qdevice(DEVICE.DOWNARROWKEY)
    gl.qdevice(DEVICE.SPACEKEY)
コード例 #47
0
#! /ufs/guido/bin/sgi/python

# radio [port]
#
# Receive audio packets broadcast by "broadcast.py" on another SGI machine.
# Use apanel to set the output sampling rate to match that of the broadcast.

import sys, al
from socket import *

port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])

s = socket(AF_INET, SOCK_DGRAM)
s.bind('', port)

p = al.openport('radio', 'w')

while 1:
    data = s.recv(1400)
    p.writesamps(data)
コード例 #48
0
ファイル: playold.py プロジェクト: mcyril/ravel-ftn
# Play old style sound files (Guido's private format)
コード例 #49
0
ファイル: playold.py プロジェクト: mcyril/ravel-ftn
# Play old style sound files (Guido's private format)
コード例 #50
0
ファイル: unicast.py プロジェクト: carol8421/gosh
#! /usr/bin/env python

# unicast host [port]
#
# Similar to "broadcast.py" but sends to a specific host only;
# use "radio.py" on the designated host to receive.
# This is less stressful on other hosts on the same ethernet segment
# if you need to send to one host only.

import sys, al
from socket import *

host = sys.argv[1]

port = 5555
if sys.argv[2:]: port = eval(sys.argv[1])

s = socket(AF_INET, SOCK_DGRAM)

p = al.openport('unicast', 'r')

address = host, port
while 1:
	# 700 samples equals 1400 bytes, or about the max packet size!
	data = p.readsamps(700)
	s.sendto(data, address)
コード例 #51
0
ファイル: broadcast.py プロジェクト: asottile/ancient-pythons
#! /usr/local/bin/python

# broadcast [port]
#
# Broadcast audio input on the network as UDP packets;
# they can be received on any SGI machine with "radio.py".
# This uses the input sampling rate, input source etc. set by apanel.
# It uses the default sample width and #channels (16 bit/sample stereo).
# (This is 192,000 Bytes at a sampling speed of 48 kHz, or ~137
# packets/second -- use with caution!!!)

import sys, al
from socket import *

port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])

s = socket(AF_INET, SOCK_DGRAM)
s.allowbroadcast(1)

p = al.openport('broadcast', 'r')

address = '<broadcast>', port
while 1:
	# 700 samples equals 1400 bytes, or about the max packet size!
	data = p.readsamps(700)
	s.sendto(data, address)
コード例 #52
0
ファイル: broadcast.py プロジェクト: mcyril/ravel-ftn
#! /usr/bin/env python
# broadcast [port]
#
# Broadcast audio input on the network as UDP packets;
# they can be received on any SGI machine with "radio.py".
# This uses the input sampling rate, input source etc. set by apanel.
# It uses the default sample width and #channels (16 bit/sample stereo).
# (This is 192,000 Bytes at a sampling speed of 48 kHz, or ~137
# packets/second -- use with caution!!!)
import sys, al
from socket import *
port = 5555
if sys.argv[1:]: port = eval(sys.argv[1])
s = socket(AF_INET, SOCK_DGRAM)
s.allowbroadcast(1)
p = al.openport('broadcast', 'r')
address = '<broadcast>', port
while 1:
	# 700 samples equals 1400 bytes, or about the max packet size!
	data = p.readsamps(700)
	s.sendto(data, address)
コード例 #53
0
ファイル: rec_play.py プロジェクト: mcyril/ravel-ftn
#
コード例 #54
0
#! /usr/bin/env python
コード例 #55
0
ファイル: record.py プロジェクト: mcyril/ravel-ftn
# Record mono 16bits samples from the audio device and send them to stdout.