Ejemplo n.º 1
0
def samp(n):
       savegain = audio.getoutgain()
       try:
               audio.setoutgain(0)
               x = raw_input('Hit Enter to sample ' + `n` + ' seconds: ')
               return audio.read(n*RATE)
       finally:
               audio.setoutgain(savegain)
Ejemplo n.º 2
0
def play_on_hook(self):
       stop_vu()
       audio.setrate(G.rate)
       audio.setoutgain(G.gain)
       audio.start_playing(G.data)
       G.playing = 1
       G.recbtn.enable(0)
       G.window.settimer(max(10 * len(G.data) / Rates[G.rate], 1))
Ejemplo n.º 3
0
def play_on_hook(self):
	stop_vu()
	audio.setrate(G.rate)
	audio.setoutgain(G.gain)
	audio.start_playing(G.data)
	G.playing = 1
	G.recbtn.enable(0)
	G.window.settimer(max(10 * len(G.data) / Rates[G.rate], 1))
Ejemplo n.º 4
0
def play_off_hook(self):
	if not G.playing:
		return
	x = audio.stop_playing()
	G.playing = 0
	audio.setoutgain(G.nomuting * G.gain)
	G.recbtn.enable(1)
	G.window.settimer(0)
	start_vu()
Ejemplo n.º 5
0
def main():
       audio.setrate(3)
       audio.setoutgain(0)
       w = WindowParent().create('VU Meter', (200, 100))
       v = MyVUMeter().define(w)
       v.start()
       w.realize()
       while 1:
               w.dispatch(stdwin.getevent())
Ejemplo n.º 6
0
def play_off_hook(self):
       if not G.playing:
               return
       x = audio.stop_playing()
       G.playing = 0
       audio.setoutgain(G.nomuting * G.gain)
       G.recbtn.enable(1)
       G.window.settimer(0)
       start_vu()
Ejemplo n.º 7
0
def record_on_hook(self):
       stop_vu()
       close_sogram()
       audio.setrate(G.rate)
       audio.setoutgain(G.nomuting * G.gain)
       audio.start_recording(BUFSIZE)
       G.recording = 1
       G.playbtn.enable(0)
       G.window.settimer(10 * BUFSIZE / Rates[G.rate])
Ejemplo n.º 8
0
def main():
	audio.setrate(3)
	audio.setoutgain(0)
	w = WindowParent().create('VU Meter', (200, 100))
	v = MyVUMeter().define(w)
	v.start()
	w.realize()
	while 1:
		w.dispatch(stdwin.getevent())
Ejemplo n.º 9
0
def record_on_hook(self):
	stop_vu()
	close_sogram()
	audio.setrate(G.rate)
	audio.setoutgain(G.nomuting * G.gain)
	audio.start_recording(BUFSIZE)
	G.recording = 1
	G.playbtn.enable(0)
	G.window.settimer(10 * BUFSIZE / Rates[G.rate])
Ejemplo n.º 10
0
 def record(a):
     p = a.back
     size = int(10.0 * 8192.0 * p.recordsize.val)
     a.val = 1.0
     a.fixact()
     panel.drawpanel()
     audio.setoutgain(0)
     p.sample = audio.read(size)
     a.val = 0.0
     a.fixact()
Ejemplo n.º 11
0
 def playback(a):
     p = a.back
     gain = int(255.0 * p.outputgain.val)
     a.val = 1.0
     a.fixact()
     panel.drawpanel()
     audio.setoutgain(gain)
     audio.write(p.sample)
     audio.setoutgain(0)
     a.val = 0.0
     a.fixact()
Ejemplo n.º 12
0
def record_off_hook(self):
       if not G.recording:
               return
       G.data = audio.stop_recording()
       G.recording = 0
       G.sizebtn.settext(`len(G.data)` + ' bytes')
       audio.setoutgain(G.nomuting * G.gain)
       G.playbtn.enable((len(G.data) > 0))
       G.savebtn.enable((len(G.data) > 0))
       #G.showbtn.enable((len(G.data) > 0))
       G.window.settimer(0)
       start_vu()
Ejemplo n.º 13
0
def record_off_hook(self):
	if not G.recording:
		return
	G.data = audio.stop_recording()
	G.recording = 0
	G.sizebtn.settext(`len(G.data)` + ' bytes')
	audio.setoutgain(G.nomuting * G.gain)
	G.playbtn.enable((len(G.data) > 0))
	G.savebtn.enable((len(G.data) > 0))
	#G.showbtn.enable((len(G.data) > 0))
	G.window.settimer(0)
	start_vu()
Ejemplo n.º 14
0
def main():
	#
	gain = 100
	rate = 0
	starter = audio.write
	stopper = 0
	#
	optlist, args = getopt.getopt(sys.argv[1:], 'adg:r:')
	#
	for optname, optarg in optlist:
		if 0:
			pass
		elif optname == '-d':
			debug.append(1)
		elif optname == '-g':
			gain = string.atoi(optarg)
			if not (0 < gain < 256):
				raise optarg.error, '-g gain out of range'
		elif optname == '-r':
			rate = string.atoi(optarg)
			if not (1 <= rate <= 3):
				raise optarg.error, '-r rate out of range'
		elif optname == '-a':
			starter = audio.start_playing
			stopper = audio.wait_playing
	#
	audio.setoutgain(gain)
	audio.setrate(rate)
	#
	if not args:
		play(starter, rate, auds.loadfp(sys.stdin))
	else:
		real_stopper = 0
		for file in args:
			if real_stopper:
				real_stopper()
			play(starter, rate, auds.load(file))
			real_stopper = stopper
Ejemplo n.º 15
0
def main():
	G.synchronous = 0	# If set, use synchronous audio.write()
	G.debug = 0		# If set, print debug messages
	G.gain = 75		# Output gain
	G.rate = 3		# Sampling rate
	G.busy = 0		# Set while asynchronous playing is active
	G.windows = []		# List of open windows (except control)
	G.mode = 'mac'		# Macintosh mode
	G.tempprefix = '/usr/tmp/@j' + `rand.rand()` + '-'
	#
	optlist, args = getopt.getopt(sys.argv[1:], 'dg:r:sSa')
	for optname, optarg in optlist:
		if   optname == '-d':
			G.debug = 1
		elif optname == '-g':
			G.gain = string.atoi(optarg)
			if not (0 < G.gain < 256):
				raise optarg.error, '-g gain out of range'
		elif optname == '-r':
			G.rate = string.atoi(optarg)
			if not (1 <= G.rate <= 3):
				raise optarg.error, '-r rate out of range'
		elif optname == '-s':
			G.synchronous = 1
		elif optname == '-S':
			G.mode = 'sgi'
		elif optname == '-a':
			G.mode = 'sun'
	#
	if not args:
		args = [DEF_DB]
	#
	G.cw = opencontrolwindow()
	for dirname in args:
		G.windows.append(openlistwindow(dirname))
	#
	#
	savegain = audio.getoutgain()
	try:
		# Initialize stdaudio
		audio.setoutgain(0)
		audio.start_playing('')
		dummy = audio.wait_playing()
		audio.setoutgain(0)
		maineventloop()
	finally:
		audio.setoutgain(savegain)
		audio.done()
		clearcache()
Ejemplo n.º 16
0
#! /usr/bin/env python
Ejemplo n.º 17
0
		data_size = hdr[0]
		data = fp.read(data_size)
		# XXX this doesn't work yet, need to convert from uLAW!!!
		del fp
	else:
		del fp
		data = readfile(tempname)
	if G.debug: print len(data), 'bytes read from', tempname
	if G.busy:
		G.busy = 0
		dummy = audio.stop_playing()
	#
	# Completely reset the audio device
	audio.setrate(G.rate)
	audio.setduration(0)
	audio.setoutgain(G.gain)
	#
	if G.synchronous:
		audio.write(data)
		audio.setoutgain(0)
	else:
		try:
			audio.start_playing(data)
			G.busy = 1
		except:
			stdwin.fleep()
	del data

def readfile(filename):
	return readfp(open(filename, 'r'))
Ejemplo n.º 18
0
def mute_hook(self):
	G.nomuting = (not self.selected)
	audio.setoutgain(G.nomuting * G.gain)
Ejemplo n.º 19
0
                 G.gain = string.atoi(optarg)
                 if not (0 < G.gain < 256):
                         raise optarg.error, '-g gain out of range'
         elif optname = '-m':
                 G.nomuting = (not G.nomuting)
         elif optname = '-r':
                 G.rate = string.atoi(optarg)
                 if not (1 <= G.rate <= 3):
                         raise optarg.error, '-r rate out of range'
 #
 if args:
         G.savefile = args[0]
 #
 # Initialize the sound package
 #
 audio.setoutgain(G.nomuting * G.gain)   # Silence the speaker
 audio.setrate(G.rate)
 #
 # Create the WindowParent and VSplit
 #
 G.window = WindowParent().create('Recorder', (0, 0))
 w = G.vsplit = VSplit().create(G.window)
 #
 # VU-meter
 #
 G.vubtn = VUMeter().define(w)
 #
 # Radiobuttons for rates
 #
 r1btn = RadioButton().definetext(w, '32 K/sec')
 r1btn.on_hook = rate_hook
Ejemplo n.º 20
0
def stop_hook(self):
	if G.busy:
		audio.setoutgain(0)
		dummy = audio.stop_playing()
		G.busy = 0
Ejemplo n.º 21
0
def mute_hook(self):
       G.nomuting = (not self.selected)
       audio.setoutgain(G.nomuting * G.gain)
Ejemplo n.º 22
0
def gain_setval_hook(self):
	G.gain = self.val
	if G.busy: audio.setoutgain(G.gain)
Ejemplo n.º 23
0
			G.mode = 'sgi'
		elif optname = '-a':
			G.mode = 'sun'
	#
	if not args:
		args = [DEF_DB]
	#
	G.cw = opencontrolwindow()
	for dirname in args:
		G.windows.append(openlistwindow(dirname))
	#
	#
	savegain = audio.getoutgain()
	try:
		# Initialize stdaudio
		audio.setoutgain(0)
		audio.start_playing('')
		dummy = audio.wait_playing()
		audio.setoutgain(0)
		maineventloop()
	finally:
		audio.setoutgain(savegain)
		audio.done()
		clearcache()

def maineventloop():
	mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
	while G.windows:
		type, w, detail = event = stdwin.getevent()
		if w = G.cw.win:
			if type = WE_CLOSE:
Ejemplo n.º 24
0
def gain_hook(self):
       G.gain = self.val
       if G.playing or G.nomuting: audio.setoutgain(G.gain)
Ejemplo n.º 25
0
def main():
    #
    # Turn off scroll bars
    #
    stdwin.setdefscrollbars(0, 0)
    #
    # Set default state
    #
    G.gain = 60
    G.rate = 3
    G.nomuting = 0
    G.savefile = '@rec'
    #
    # Set default values
    #
    G.data = ''
    G.playing = 0
    G.recording = 0
    G.sogram = 0
    #
    # Parse options
    #
    optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:')
    #
    for optname, optarg in optlist:
        if 0:  # (So all cases start with elif)
            pass
        elif optname == '-d':
            G.debug = 1
        elif optname == '-g':
            G.gain = string.atoi(optarg)
            if not (0 < G.gain < 256):
                raise optarg.error, '-g gain out of range'
        elif optname == '-m':
            G.nomuting = (not G.nomuting)
        elif optname == '-r':
            G.rate = string.atoi(optarg)
            if not (1 <= G.rate <= 3):
                raise optarg.error, '-r rate out of range'
    #
    if args:
        G.savefile = args[0]
    #
    # Initialize the sound package
    #
    audio.setoutgain(G.nomuting * G.gain)  # Silence the speaker
    audio.setrate(G.rate)
    #
    # Create the WindowParent and VSplit
    #
    G.window = WindowParent().create('Recorder', (0, 0))
    w = G.vsplit = VSplit().create(G.window)
    #
    # VU-meter
    #
    G.vubtn = VUMeter().define(w)
    #
    # Radiobuttons for rates
    #
    r1btn = RadioButton().definetext(w, '32 K/sec')
    r1btn.on_hook = rate_hook
    r1btn.rate = 1
    #
    r2btn = RadioButton().definetext(w, '16 K/sec')
    r2btn.on_hook = rate_hook
    r2btn.rate = 2
    #
    r3btn = RadioButton().definetext(w, '8 K/sec')
    r3btn.on_hook = rate_hook
    r3btn.rate = 3
    #
    radios = [r1btn, r2btn, r3btn]
    r1btn.group = r2btn.group = r3btn.group = radios
    for r in radios:
        if r.rate == G.rate: r.select(1)
    #
    # Other controls
    #
    G.recbtn = TimeOutToggleButton().definetext(w, 'Record')
    G.recbtn.on_hook = record_on_hook
    G.recbtn.timer_hook = record_timer_hook
    G.recbtn.off_hook = record_off_hook
    #
    G.mutebtn = CheckButton().definetext(w, 'Mute')
    G.mutebtn.select(not G.nomuting)
    G.mutebtn.hook = mute_hook
    #
    G.playbtn = TimeOutToggleButton().definetext(w, 'Playback')
    G.playbtn.on_hook = play_on_hook
    G.playbtn.timer_hook = play_timer_hook
    G.playbtn.off_hook = play_off_hook
    #
    G.gainbtn = ComplexSlider().define(w)
    G.gainbtn.settexts('  Volume: ', '  ')
    G.gainbtn.setminvalmax(0, G.gain, 255)
    G.gainbtn.sethook(gain_hook)
    #
    G.sizebtn = Label().definetext(w, ` len(G.data) ` + ' bytes')
    #
    #G.showbtn = PushButton().definetext(w, 'Sound-o-gram...')
    #G.showbtn.hook = show_hook
    #
    G.savebtn = PushButton().definetext(w, 'Save...')
    G.savebtn.hook = save_hook
    #
    G.quitbtn = PushButton().definetext(w, 'Quit')
    G.quitbtn.hook = quit_hook
    G.playbtn.enable(0)
    G.savebtn.enable(0)
    #G.showbtn.enable(0)
    start_vu()
    G.window.realize()
    #
    # Event loop
    #
    MainLoop()
Ejemplo n.º 26
0
def main():
	#
	# Turn off scroll bars
	#
	stdwin.setdefscrollbars(0, 0)
	#
	# Set default state
	#
	G.gain = 60
	G.rate = 3
	G.nomuting = 0
	G.savefile = '@rec'
	#
	# Set default values
	#
	G.data = ''
	G.playing = 0
	G.recording = 0
	G.sogram = 0
	#
	# Parse options
	#
	optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:')
	#
	for optname, optarg in optlist:
		if 0: # (So all cases start with elif)
			pass
		elif optname == '-d':
			G.debug = 1
		elif optname == '-g':
			G.gain = string.atoi(optarg)
			if not (0 < G.gain < 256):
				raise optarg.error, '-g gain out of range'
		elif optname == '-m':
			G.nomuting = (not G.nomuting)
		elif optname == '-r':
			G.rate = string.atoi(optarg)
			if not (1 <= G.rate <= 3):
				raise optarg.error, '-r rate out of range'
	#
	if args:
		G.savefile = args[0]
	#
	# Initialize the sound package
	#
	audio.setoutgain(G.nomuting * G.gain)	# Silence the speaker
	audio.setrate(G.rate)
	#
	# Create the WindowParent and VSplit
	#
	G.window = WindowParent().create('Recorder', (0, 0))
	w = G.vsplit = VSplit().create(G.window)
	#
	# VU-meter
	#
	G.vubtn = VUMeter().define(w)
	#
	# Radiobuttons for rates
	#
	r1btn = RadioButton().definetext(w, '32 K/sec')
	r1btn.on_hook = rate_hook
	r1btn.rate = 1
	#
	r2btn = RadioButton().definetext(w, '16 K/sec')
	r2btn.on_hook = rate_hook
	r2btn.rate = 2
	#
	r3btn = RadioButton().definetext(w, '8 K/sec')
	r3btn.on_hook = rate_hook
	r3btn.rate = 3
	#
	radios = [r1btn, r2btn, r3btn]
	r1btn.group = r2btn.group = r3btn.group = radios
	for r in radios:
		if r.rate == G.rate: r.select(1)
	#
	# Other controls
	#
	G.recbtn = TimeOutToggleButton().definetext(w, 'Record')
	G.recbtn.on_hook = record_on_hook
	G.recbtn.timer_hook = record_timer_hook
	G.recbtn.off_hook = record_off_hook
	#
	G.mutebtn = CheckButton().definetext(w, 'Mute')
	G.mutebtn.select(not G.nomuting)
	G.mutebtn.hook = mute_hook
	#
	G.playbtn = TimeOutToggleButton().definetext(w, 'Playback')
	G.playbtn.on_hook = play_on_hook
	G.playbtn.timer_hook = play_timer_hook
	G.playbtn.off_hook = play_off_hook
	#
	G.gainbtn = ComplexSlider().define(w)
	G.gainbtn.settexts('  Volume: ', '  ')
	G.gainbtn.setminvalmax(0, G.gain, 255)
	G.gainbtn.sethook(gain_hook)
	#
	G.sizebtn = Label().definetext(w, `len(G.data)` + ' bytes')
	#
	#G.showbtn = PushButton().definetext(w, 'Sound-o-gram...')
	#G.showbtn.hook = show_hook
	#
	G.savebtn = PushButton().definetext(w, 'Save...')
	G.savebtn.hook = save_hook
	#
	G.quitbtn = PushButton().definetext(w, 'Quit')
	G.quitbtn.hook = quit_hook
	G.playbtn.enable(0)
	G.savebtn.enable(0)
	#G.showbtn.enable(0)
	start_vu()
	G.window.realize()
	#
	# Event loop
	#
	MainLoop()
Ejemplo n.º 27
0
def gain_hook(self):
	G.gain = self.val
	if G.playing or G.nomuting: audio.setoutgain(G.gain)
Ejemplo n.º 28
0
def gain_setval_hook(self):
	G.gain = self.val
	if G.busy: audio.setoutgain(G.gain)
Ejemplo n.º 29
0
import audio

RATE = 8192

# Initialize the audio stuff
audio.setrate(3)
audio.setoutgain(100)  # for speaker

play = audio.write

def samp(n):
       savegain = audio.getoutgain()
       try:
               audio.setoutgain(0)
               x = raw_input('Hit Enter to sample ' + `n` + ' seconds: ')
               return audio.read(n*RATE)
       finally:
               audio.setoutgain(savegain)

def echo(s, delay, gain):
       return s[:delay] + audio.add(s[delay:], audio.amplify(s, gain, gain))

def save(s, file):
       f = open(file, 'w')
       f.write(s)

def load(file):
       return loadfp(open(file, 'r'))

def loadfp(fp):
       s = ''
Ejemplo n.º 30
0
def stop_hook(self):
	if G.busy:
		audio.setoutgain(0)
		dummy = audio.stop_playing()
		G.busy = 0
Ejemplo n.º 31
0
                       pass
               elif optname = '-d':
                       debug.append(1)
               elif optname = '-g':
                       gain = string.atoi(optarg)
                       if not (0 < gain < 256):
                               raise optarg.error, '-g gain out of range'
               elif optname = '-r':
                       rate = string.atoi(optarg)
                       if not (1 <= rate <= 3):
                               raise optarg.error, '-r rate out of range'
               elif optname = '-a':
                       starter = audio.start_playing
                       stopper = audio.wait_playing
       #
       audio.setoutgain(gain)
       audio.setrate(rate)
       #
       if not args:
               play(starter, rate, auds.loadfp(sys.stdin))
       else:
               real_stopper = 0
               for file in args:
                       if real_stopper:
                               real_stopper()
                       play(starter, rate, auds.load(file))
                       real_stopper = stopper

def play(starter, rate, data):
       magic = data[:4]
       if magic = '0008':
Ejemplo n.º 32
0
#! /usr/bin/env python