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))
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()
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: return
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')) def readfp(fp): data = '' while 1: buf = fp.read(102400) # Reads most samples in one fell swoop if not buf: return data data = data + buf