예제 #1
0
def sound_negative_duration_play_failure():
    s = Sound(TEST_SOUND_LONG)
    try:
        s.play(duration=-1)
    except ValueError:
        return True
    return False
예제 #2
0
def sound_chaining_test_timed():
    # Same as sound_chaining_test(), but time it.  Does not include Sound()
    # time, as it may take a while to load an uncached sound.
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait().play(duration=0.1).wait().play().stop()
    return verify_duration(start, TEST_SOUND_LENGTH + 0.1)
예제 #3
0
def sound_negative_duration_play_failure():
    s = Sound(TEST_SOUND_LONG)
    try:
        s.play(duration=-1)
    except ValueError:
        return True
    return False
예제 #4
0
def sound_chaining_test_timed():
    # Same as sound_chaining_test(), but time it.  Does not include Sound()
    # time, as it may take a while to load an uncached sound.
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait().play(duration=0.1).wait().play().stop()
    return verify_duration(start, TEST_SOUND_LENGTH + 0.1)
예제 #5
0
def sound_not_is_playing_after_play():
    s = Sound(TEST_SOUND)
    print("before play")
    s.play()
    print("after play")
    time.sleep(TEST_SOUND_LENGTH + 0.5)
    print("after wait: ", s.is_playing())
    return not s.is_playing()
예제 #6
0
def sound_play_test_sound_and_note_mixed():
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    n.stop()
    return True
예제 #7
0
def sound_stop_time():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
예제 #8
0
def sound_stop_time():
    #s = Sound(TEST_SOUND_LONG)
    s = Sound('/opt/sonic-pi/etc/samples/loop_garzul.wav')
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
예제 #9
0
def sound_manual_play_test_sound_and_note_mixed():
    '''The sound match1.wav will play TWO TIMES on the speaker, mixed with an
    'A' note.
    '''
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    s.play()
    s.wait()
    n.stop()
예제 #10
0
def sound_master_volume():
    '''The sound match1.wav will play on the speaker 5 times (about 0.5 seconds
    each), at 60, 70, 80, 90 and 100% master volume.  Lower volumes are too low
    to hear with an unamplified speaker.
    '''
    master_volume(60)
    Sound(TEST_SOUND).play().wait()
    master_volume(70)
    Sound(TEST_SOUND).play().wait()
    master_volume(80)
    Sound(TEST_SOUND).play().wait()
    master_volume(90)
    Sound(TEST_SOUND).play().wait()
    master_volume(100)
    Sound(TEST_SOUND).play().wait()
예제 #11
0
def sound_play_then_replay():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(0.5)
    playing_firsttime = s.is_playing()
    s.play(duration=1.0)
    time.sleep(0.5)
    playing_secondtime_before_end = s.is_playing()
    time.sleep(1.0)
    playing_secondtime_after_end = s.is_playing()
    s.stop()
    print('playing_firsttime: ', playing_firsttime)
    print('playing_secondtime_before_end: ', playing_secondtime_before_end)
    print('playing_secondtime_after_end: ', playing_secondtime_after_end)
    return playing_firsttime and playing_secondtime_before_end and not playing_secondtime_after_end
예제 #12
0
def sound_manual_play_test_sound_and_note_mixed():
    '''The sound match1.wav will play TWO TIMES on the speaker, mixed with an
    'A' note.
    '''
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    s.play()
    s.wait()
    n.stop()
예제 #13
0
def sound_play_play():
    '''Tests race condition case where a very short sound playing could cause a
    followup wait() to never complete.  The curious call to Note() is there
    because it caused the race codition to occur more reliably frequently.
    '''
    import signal

    class TimeoutException(Exception):
        pass

    def handler(signum, frame):
        raise TimeoutException()

    signal.signal(signal.SIGALRM, handler)

    signal.alarm(5)
    timeout = False
    try:
        Note('A').play().play()
        Sound(TEST_SOUND).play().wait().play(duration=0.001).wait()
    except TimeoutException:
        timeout = True
    signal.alarm(0)

    return not timeout
예제 #14
0
def sound_flood_test():
    sounds = [Sound('fire.wav') for i in range(10)]

    for i in range(10):
        for s in sounds:
            s.play()
            time.sleep(0.05)
    return True
예제 #15
0
def sound_short_latency():
    s = Sound(TEST_SOUND)
    s.stop()
    start = time.time()
    s.play()
    s.wait()
    duration = time.time() - start
    latency = duration - TEST_SOUND_LENGTH
    print("Latency: ", latency)
    return latency > 0 and latency < 0.050
예제 #16
0
def sound_playing_before_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(0.5)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #17
0
def sound_not_playing_after_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 + 0.5)
    playing = s.is_playing()
    s.stop()
    return not playing
예제 #18
0
def sound_not_playing_after_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    time.sleep(2.5)
    playing = s.is_playing()
    s.stop()
    return not playing
예제 #19
0
def sound_playing_before_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 - 0.5)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #20
0
def sound_short_latency():
    s = Sound(TEST_SOUND)
    s.stop()
    start = time.time()
    s.play()
    s.wait()
    duration = time.time() - start
    latency = duration - TEST_SOUND_LENGTH
    print("Latency: ", latency)
    return latency > 0 and latency < 0.050
예제 #21
0
def sound_sound_volume():
    '''The long test sound will play for 10 second with increasing volume.  '''
    master_volume(100)
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=10)
    for i in range(20):
        s.volume += 15
        time.sleep(0.5)
    s.wait()
예제 #22
0
def sound_get_set_volume():
    # Verify Sound volume attribute can be get/set.
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=0.5)
    for i in range(10):
        s.volume += 10
        time.sleep(0.05)
    s.wait()
    return s.volume == 100
예제 #23
0
def sound_playing_before_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(0.5)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #24
0
def sound_playing_before_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 - 0.5)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #25
0
def sound_not_playing_after_end_of_2_loops():
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    time.sleep(TEST_SOUND_LENGTH * 2 + 0.5)
    playing = s.is_playing()
    s.stop()
    return not playing
예제 #26
0
def sound_not_playing_after_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    time.sleep(2.5)
    playing = s.is_playing()
    s.stop()
    return not playing
예제 #27
0
def sound_play_test_sound_and_note_mixed():
    n = Note('A')
    s = Sound(TEST_SOUND)
    n.play(duration=None)
    s.play()
    s.wait()
    n.stop()
    return True
예제 #28
0
def sound_not_is_playing_after_play():
    s = Sound(TEST_SOUND)
    print("before play")
    s.play()
    print("after play")
    time.sleep(TEST_SOUND_LENGTH + 0.5)
    print("after wait: ", s.is_playing())
    return not s.is_playing()
예제 #29
0
def sound_sound_volume():
    '''The long test sound will play for 10 second with increasing volume.  '''
    master_volume(100)
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=10)
    for i in range(20):
        s.volume += 15
        time.sleep(0.5)
    s.wait()
예제 #30
0
def sound_get_set_volume():
    # Verify Sound volume attribute can be get/set.
    s = Sound(TEST_SOUND_LONG)
    s.volume = 0
    s.play(duration=0.5)
    for i in range(10):
        s.volume += 10
        time.sleep(0.05)
    s.wait()
    return s.volume == 100
예제 #31
0
def sound_stop_time():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(1)
    start = time.time()
    s.stop()
    end = time.time()
    duration = end - start
    print(start, end)
    print("stop() duration: ", duration)
    return duration > 0 and duration < 0.150
예제 #32
0
def verify_cpu():
    s = Sound(TEST_SOUND_LONG)
    return testing.verify_cpu()
예제 #33
0
def sound_playing_before_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #34
0
def sound_play_chainable():
    Sound(TEST_SOUND).play().play()
    return True
예제 #35
0
def sound_play_test_sound():
    '''The sound match1.wav will play on the speaker (about 0.5 seconds).'''
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
예제 #36
0
def sound_playing_before_end_of_2_loops_of_fixed_duration():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0, loops=2)
    playing = s.is_playing()
    s.stop()
    return playing
예제 #37
0
def sound_not_playing_after_end_of_duration_play():
    s = Sound(TEST_SOUND_LONG)
    s.play(duration=1.0)
    time.sleep(1.5)
    return not s.is_playing()
예제 #38
0
def sound_wait_verify_duration_with_duration_and_loops():
    s = Sound(TEST_SOUND_LONG)
    start = time.time()
    s.play(duration=1, loops=3).wait()
    return verify_duration(start, 3)
예제 #39
0
def sound_play_test_sound():
    '''The sound match1.wav will play on the speaker (about 0.5 seconds).'''
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
예제 #40
0
def sound_wait_verify_duration():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play().wait()
    return verify_duration(start, TEST_SOUND_LENGTH)
예제 #41
0
def sound_wait_verify_duration_with_loops():
    s = Sound(TEST_SOUND)
    start = time.time()
    s.play(loops=3).wait()
    return verify_duration(start, 3*TEST_SOUND_LENGTH)
예제 #42
0
def sound_init_with_known_good_sound():
    s = Sound(TEST_SOUND)
    return isinstance(s, Sound)
예제 #43
0
def sound_is_playing_at_play_middle():
    s = Sound(TEST_SOUND)
    s.play()
    time.sleep(TEST_SOUND_LENGTH/2)
    return s.is_playing()
예제 #44
0
def sound_is_playing_at_play_start():
    s = Sound(TEST_SOUND)
    s.play()
    return s.is_playing()
예제 #45
0
def sound_play_test_sound_loop_2():
    '''The sound match1.wav will play TWO TIMES on the speaker (about 0.5 seconds each).'''
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    s.wait()
예제 #46
0
def sound_stop():
    s = Sound(TEST_SOUND)
    s.play()
    s.stop()
    return not s.is_playing()
예제 #47
0
def sound_chaining_test():
    # Sound should be chainable from init->play->wait
    Sound(TEST_SOUND).play().wait().play(duration=0.1).wait().play().stop()
    return True
예제 #48
0
def sound_wait_chainable():
    Sound(TEST_SOUND).wait().wait()
    return True
예제 #49
0
def sound_wait():
    s = Sound(TEST_SOUND)
    s.play()
    s.wait()
    return not s.is_playing()
예제 #50
0
def sound_stop_chainable():
    Sound(TEST_SOUND).stop().stop()
    return True
예제 #51
0
def sound_init_abs_filename():
    return isinstance(Sound(TEST_SOUND_ABS_PATH), Sound)
예제 #52
0
def sound_not_is_playing_before_play():
    s = Sound(TEST_SOUND)
    return not s.is_playing()
예제 #53
0
def verify_cpu_while_playing():
    Sound(TEST_SOUND_LONG).play()
    return testing.verify_cpu(15)
예제 #54
0
def sound_play_then_replay():
    s = Sound(TEST_SOUND_LONG)
    s.play()
    time.sleep(0.5)
    playing_firsttime = s.is_playing()
    s.play(duration=1.0)
    time.sleep(0.5)
    playing_secondtime_before_end = s.is_playing()
    time.sleep(1.0)
    playing_secondtime_after_end = s.is_playing()
    s.stop()
    print('playing_firsttime: ', playing_firsttime)
    print('playing_secondtime_before_end: ', playing_secondtime_before_end)
    print('playing_secondtime_after_end: ', playing_secondtime_after_end)
    return playing_firsttime and playing_secondtime_before_end and not playing_secondtime_after_end
예제 #55
0
def sound_play_test_sound_loop_2():
    '''The sound match1.wav will play TWO TIMES on the speaker (about 0.5 seconds each).'''
    s = Sound(TEST_SOUND)
    s.play(loops=2)
    s.wait()
예제 #56
0
def sound_length():
    expected = Sound(TEST_SOUND).length()
    actual = TEST_SOUND_LENGTH
    print("Expected: ", expected)
    print("Actual: ", actual)
    return expected == actual
예제 #57
0
    -F-
    FAF
    ''')
TILT_FORCE = 0.1
SPACESHIP_STEP = 0.1

# Initialize aliens
ALIENS_STEP_TIME = .8

# Initialize missiles
fire_button = Button(7)
MISSILE_COLOR = 10
MISSILE_STEP_TIME = 0.1     
        
# Initialize sounds     
fire_sound = Sound("fire.wav")
hit_sound = Sound("hit.wav")
notes = [Note('B5'), Note('G5'), Note('E5'), Note('C5')]
notes_cycle = cycle(notes)
while True:
    fire_button.presses()
    while True:
        if scroll(start_text, cancel=fire_button.presses):
            break
    
    spaceship_middle = 1
    spaceship_position = fb.width / 2
    alien_columns = [0, 1, 2, 3]
    alien_row = fb.height - 1
    alien_start_time = time.time()
    alien_direction = 1
예제 #58
0
def sound_init_rel_filename():
    return isinstance(Sound(TEST_SOUND_REL_PATH), Sound)