def test_timing_parse1(): line = r""" [0.409 s, 1 proof obligation] verified""" d = get_time(line) assert d is not None assert d["time_s"] == 0.409 assert d["obligations"] == 1 assert d["result"] == "ok"
def main(): pyaud = pyaudio.PyAudio() stream = pyaud.open(format=pyaudio.paInt16, channels=2, rate=44100, input_device_index=1, input=True) last_note = last_vol = last_time = 0 while True: t = timing.get_time() rawsamps = stream.read(SAMPLE_SIZE) samps = numpy.fromstring(rawsamps, dtype=numpy.int16) event = '' midi_note = analyse.musical_detect_pitch(samps, min_note=28.0) if midi_note: midi_note += OCTAVE_CORRECTION latest_note = notes.midi_to_note(midi_note) latest_vol = analyse.loudness(samps) attacked = latest_vol - last_vol > ATTACK_THRESHOLD if latest_note != last_note or attacked: if latest_vol > MINIMUM_VOLUME: event = {'note': latest_note, 'time': t} last_time = t last_note = latest_note last_vol = latest_vol elif last_note: last_note = None print event sys.stdout.flush()
def sort(algo, n): ''' Sorter en tilfældig liste af størrelse n med algo ''' # Lav tilfældig liste lst = random.sample(xrange(n**2), n) # Liste over mulige algoritmer algorithms = ['insertion_sort', 'bubble_sort', 'merge_sort', 'quick_sort', 'builtin_sort'] # Vælg algoritme (Alle som standard) algos = algorithms if algo in algorithms: # En gyldig algoritme blev valg: Vælg kun den algos = [algo] # Kør alle algoritmer på listen og mål tid results = [] for algo in algos: result = timing.get_time(getattr(sorting, algo), list(lst)) results.append(result) return results
def main(): pyaud = pyaudio.PyAudio() stream = pyaud.open(format=pyaudio.paInt16, channels=2, rate=44100, input_device_index=1, input=True) last_note = last_vol = last_time = 0 while True: t = timing.get_time() rawsamps = stream.read(SAMPLE_SIZE) samps = numpy.fromstring(rawsamps, dtype=numpy.int16) event = "" midi_note = analyse.musical_detect_pitch(samps, min_note=28.0) if midi_note: midi_note += OCTAVE_CORRECTION latest_note = notes.midi_to_note(midi_note) latest_vol = analyse.loudness(samps) attacked = latest_vol - last_vol > ATTACK_THRESHOLD if latest_note != last_note or attacked: if latest_vol > MINIMUM_VOLUME: event = {"note": latest_note, "time": t} last_time = t last_note = latest_note last_vol = latest_vol elif last_note: last_note = None print event sys.stdout.flush()
last_note = last_vol = last_time = 0 ################################################################################ while True: events = pygame.event.get() for ev in events: if ev.type == pygame.QUIT: sys.exit() if events: re.distribute_events(*events) re.refresh() t = timing.get_time() available = stream.get_read_available() sample_size = int(paramaters.sample_size) if not available > sample_size: time.sleep(0.01) continue rawsamps = stream.read(available) samps = numpy.fromstring(rawsamps, dtype=numpy.int16, count=sample_size) event = '' midi_note = analyse.musical_detect_pitch(samps, min_note=28.0) if midi_note:
last_note = last_vol = last_time = 0 ################################################################################ while True: events = pygame.event.get () for ev in events: if ev.type == pygame.QUIT: sys.exit () if events: re.distribute_events (*events) re.refresh () t = timing.get_time() available = stream.get_read_available() sample_size = int(paramaters.sample_size) if not available > sample_size: time.sleep(0.01) continue rawsamps = stream.read(available) samps = numpy.fromstring(rawsamps, dtype=numpy.int16, count=sample_size) event = '' midi_note = analyse.musical_detect_pitch(samps, min_note=28.0) if midi_note:
def test_timing_parse3(): line = r""" [60.987 s, 161 proof obligations] timed out""" d = get_time(line) assert d is not None assert d["time_s"] == 60.987 assert d["result"] == "timeout"
def test_timing_parse2(): line = r""" [0.360 s, 50 proof obligations] verified""" d = get_time(line) assert d is not None assert d["time_s"] == 0.360 assert d["obligations"] == 50