Ejemplo n.º 1
0
    def load_sound(self, filename, sound_type=SOUND_PLAY):
        this_sound = sound.load_sound(filename)

        if sound_type == SOUND_BLOCK:
            self.sound_block = this_sound

        elif sound_type == SOUND_HIT:
            self.sound_hit = this_sound

        elif sound_type == SOUND_MISS:
            self.sound_miss = this_sound

        else:
            self.sound = this_sound
Ejemplo n.º 2
0
def invert_noisy_subbands(target_envs,
                          final_sr,
                          env_sr,
                          mid_sr=20000,
                          low_lim=20,
                          hi_lim=10000,
                          comp_exp=0.3,
                          scale_volume=2.):
    # number of subbands (w/o high/low pass)
    nbands = target_envs.shape[1] - 2
    snd_len = int(np.ceil(target_envs.shape[0] * float(mid_sr) /
                          float(env_sr)))
    snd_len -= (snd_len % 100)
    target_envs = np.clip(target_envs, 0, 1)

    filts, _, _ = erb_filters(snd_len, mid_sr, nbands, low_lim, hi_lim)
    synth_sound = np.random.randn(snd_len)
    if 0:
        print('using pink noise')
        noise_snd = sound.load_sound(
            '/data/vision/billf/aho-stuff/vis/lib/soundtex/pink_noise_20s_20kHz.wav'
        )
        noise_snd = noise_snd.normalized().to_mono()
        noise_snd = noise_snd.samples
        i = np.random.choice(
            list(range(noise_snd.shape[0] - synth_sound.shape[0])))
        synth_sound = 100 * noise_snd[i:i + synth_sound.shape[0]]
        print('stdev', np.std(synth_sound))
        #sound.play(synth_sound, mid_sr)

    # Forward pass: current sound -> downsampled envelopes and full-res phases
    synth_subbands = subbands_from_sound(synth_sound, filts)
    analytic = scipy.signal.hilbert(synth_subbands, axis=0)
    synth_envs = np.abs(analytic)
    #phases = analytic / synth_envs
    phases = analytic

    #up_target_envs = resample(target_envs, mid_sr / env_sr)
    up_target_envs = scipy.signal.resample(target_envs, phases.shape[0])
    up_target_envs = np.maximum(up_target_envs, 0.)
    up_target_envs **= (1. / comp_exp)

    new_analytic = phases * up_target_envs
    synth_subbands = np.real(new_analytic)
    synth_sound = sound_from_subbands(synth_subbands, filts)

    synth_sound = resample(synth_sound, final_sr / float(mid_sr))
    synth_sound = synth_sound * scale_volume
    synth_sound = np.clip(synth_sound, -1., 1.)
    return sound.Sound(None, final_sr, synth_sound)
Ejemplo n.º 3
0
    def load_sound(self, filename, sound_type=SOUND_PLAY):
        this_sound = sound.load_sound(filename)

        if sound_type == SOUND_BLOCK:
            self.sound_block = this_sound

        elif sound_type == SOUND_HIT:
            self.sound_hit = this_sound

        elif sound_type == SOUND_MISS:
            self.sound_miss = this_sound

        else:
            self.sound = this_sound
Ejemplo n.º 4
0
        while i < patrol:
            arranged = 0
            if  (float(patrol) / (minimum)) > 0.85:
                arranged = 5

            board2.random_placing(ships[k][0] + str(i), 5 - k, arranged)
            i += 1

        k += 1
    return e_list


if __name__ == "__main__":
    save = "no"
    sink = sound.load_sound("sink.wav")
    ship_dict = {"p": "patrol", "d": "destroyer", "s": "submarine", \
                 "a": "aircraft"}
    print "\n***********WELCOME TO BATTLESHIP******************************"
    new_user = raw_input("Are you a new user? (if yes please type new) : ")
    print "Please type your username and password "
    username = raw_input("Username : "******"Password : "******"if you want to create new account please type\
'new' : ")
        username = raw_input("Username : "******"Password : ")
        users = validation(username, password, new_user)
Ejemplo n.º 5
0
import pygcurse, pygame, game, sound, var
from pygame.locals import *

pygame.font.init()
pygame.mixer.init()

var.snd_explode1 = sound.load_sound('explode1.wav')

_font = pygame.font.Font('ProggySquare.ttf', 24)

var.main_menu = [{'text':'Start','action':'game'},{'text':'Options','action':'options'},{'text':'Exit','action':'exit'}]

var.clock = pygame.time.Clock()
var.window = pygcurse.PygcurseWindow(var.win_size[0], var.win_size[1],font=_font,caption='ASCIItest')
var.window.autoupdate = False

game.setup()
Ejemplo n.º 6
0
 def load_sound(self, filename, sound_type=SOUND_PLAY):
     this_sound = sound.load_sound(filename)
     self.sound = this_sound
Ejemplo n.º 7
0
    end (type: int): The ending index for the range of samples. This is non-inclusive.

    Returns:
    (type: int) The maximum left channel value in samples between the start
    and end indices.
    """

    # initialize max value to left channel value in the first sample in the range
    first = my_sound[start]
    max_val = abs(first.left)

    # loop through all other samples in the range and keep track of the
    # largest left channel sample value.
    for i in range(start + 1, end):
        sample = my_sound[i]
        left_val = abs(sample.left)
        if (left_val > max_val):
            max_val = left_val

    return max_val


# To Do: Define your set_extremes function below this line.

jolly = sound.load_sound("jolly.wav")
jolly.play()
sound.wait_until_played()  # waits until jolly is done playing
jolly.display()

# To Do: Add new test code after this line.
Ejemplo n.º 8
0
"""
Module: comp110_lab03

Practice code for working with sounds in Python.
"""
import sound


love_sound = sound.load_sound("love.wav")
love_sound.play()
sound.wait_until_played()  # waits until love_sound is done playing

# change the volume of the love sound
for i in range(len(love_sound)):
    sample = love_sound.get_sample(i)
    new_left_val = sample.get_left() * 2
    new_right_val = sample.get_right() * 2
    sample.set_left(new_left_val)
    sample.set_right(new_right_val)

love_sound.play()
sound.wait_until_played()  # waits until love_sound is done playing
Ejemplo n.º 9
0
 def load_sound(self, filename, sound_type=SOUND_PLAY):
     this_sound = sound.load_sound(filename)
     self.sound = this_sound
Ejemplo n.º 10
0
def main():
	print "Working"

	mysound = sound.load_sound("/Users/eos/Desktop/Vocal Processing/airplane.wav")
	fade(mysound, 2000)
Ejemplo n.º 11
0
def game_loop():
    global BORDER_LOWER, BORDER_LEFT, BORDER_RIGHT
    global TICKS_PER_SECOND
    global SHOT_SPEED,SHIP_SPEED
    enemies = []
    generate_enemy_wave(enemies)
    screen = pygame.display.get_surface()
    
    shoot_sound = sound.load_sound('psh.ogg')
    enemy_explosion_sound = sound.load_sound('uddh.ogg')
    
    position = [(SCREEN_SIZE[0]) / 2, BORDER_LOWER-10]
    
    ship_sprite = PlayerShip.PlayerShip(position)
    shot_sprite = Shot.Shot([0,0])
    enemy_shot_sprite = Shot.Shot([0,0])
    ship_sprite.size = ship_sprite.image.get_size()
#    shotX, shotY = shot_sprite.image.get_size()
#    enemy_shotX, enemy_shotY = shotX, shotY
    
    ship_sprite.coorX = ship_sprite.position[0]
    ship_sprite.coorY = ship_sprite.position[1]
    
#    shot_coorX = 0.0
#    shot_coorY = 0.0
    ship_sprite.coorX = (SCREEN_SIZE[0] - ship_sprite.size[0]) / 2
    ship_sprite.coorY = BORDER_LOWER - ship_sprite.size[1]
    shot_exists = False
    enemy_shot_exists = False
    score = 0
    clock = pygame.time.Clock()
    ticks = 0
    done = False
    # Main game loop
    while not done:
        clock.tick(TICKS_PER_SECOND)
        ticks += 1
        if (ticks % TICKS_PER_SECOND) == 0:
            fps = clock.get_fps()
#            print fps
        #####################################################################################
        # read keyboard and move player ship
        events = pygame.event.get()
        keystate = pygame.key.get_pressed()
        if keystate[K_ESCAPE] == 1:
            done = True
            break
        if keystate[K_a] == 1:
            ship_sprite.move_left()
        if keystate[K_d] == 1:
            ship_sprite.move_right()
        if keystate[K_SPACE] == 1:
            if not shot_exists:
                shoot_sound.play()
                shot_exists = True
                shot_sprite.position[0], shot_sprite.position[1] = ship_sprite.position[0] + (ship_sprite.size[0] - shot_sprite.size[0]) / 2, ship_sprite.position[1] - shot_sprite.size[1] #generate shot near top middle of gun
        if keystate[K_e] == 1:
            if not enemy_shot_exists:
                #shoot_sound.play()
                enemy_shot_exists = True
                enemy_shot_sprite.position[0] = 400.0 #random.randint(BORDER_LEFT, BORDER_RIGHT)
                enemy_shot_sprite.position[1] = 400.0
                #shot_coorX, shot_coorY = ship_sprite.coorX + (ship_sprite.size[0] - shotX) / 2, ship_sprite.coorY - shotY #generate shot near top middle of gun
        for event in events: 
            if event.type == QUIT: 
                done = True
                break

        #######################################################################################
        # collision detection shot <-> enemies
        dying_enemies = [] # empty list that gets filled as enemies get shot
        for i in range(len(enemies)):
            if shot_exists:
                if collidesWith(shot_sprite,enemies[i]):
                    # Collision!
                    score += enemies[i].get_score()
                    dying_enemies.append(i)
                    shot_exists = False
                    enemy_explosion_sound.play()
                    # TODO: enemy explosion graphics
                    explosion.create(enemies[i].position)
                    #print "zerstort"
        # remove all enemies that were hit.
        delta = 0
        for i in range(len(dying_enemies)):
            del enemies[dying_enemies[i + delta]]
            delta += 1 # each time we remove one, the index of all the others must be reduced. This assumes that the list of dying enemies is sorted
            
        # collision detection enemy_shot <-> PlayerShip
        #dying_enemies = [] # empty list that gets filled as enemies get shot
        
        if enemy_shot_exists:
            if collidesWith(enemy_shot_sprite,ship_sprite):
                # Collision!
                enemy_shot_exists = False
                enemy_explosion_sound.play()
                # TODO: ship explosion graphics
        # remove all enemies that were hit.
        # detect end of wave
        if len(enemies) == 0:
            generate_enemy_wave(enemies)
        ############################################################################################
        if shot_exists:
            #move shot
            shot_sprite.position[1] -= SHOT_SPEED
            if shot_sprite.position[1] <= BORDER_UPPER:
                shot_exists = False
        if enemy_shot_exists:
            #move shot
            enemy_shot_sprite.position[1] += SHOT_SPEED
            if enemy_shot_sprite.position[1] >= BORDER_LOWER:
                enemy_shot_exists = False
        ############################################################################################
        graphics.draw_background(screen)
        text.draw_text(screen, score)
        if shot_exists:
            # draw shot
            screen.blit (shot_sprite.image, (shot_sprite.position[0], shot_sprite.position[1]))
        if enemy_shot_exists:
            # draw shot
            screen.blit (shot_sprite.image, (enemy_shot_sprite.position[0], enemy_shot_sprite.position[1]))

        for i in range(len(enemies)):
            enemies[i].draw(screen)
        explosion.draw(screen)
        # draw player ship
        ship_sprite.draw(screen)
        # swap back and front buffers
        pygame.display.flip()
Ejemplo n.º 12
0
def open_file(file_path):
    ''' return a sound object for the given file name'''
    return sound.load_sound(file_path)
Ejemplo n.º 13
0
def change_volume(original_sound):
    """
    Modifies the volume of the given sound.

    Parameters:
    original_sound (type: Sound): The original sound.

    Returns:
    Sound object: Like the original sound, but with the volume changed.
    """

    pass  # replace this line with your code


# First, test the change_volume with the love.wav audio
love = sound.load_sound("love.wav")
love.play()
sound.wait_until_played()

changed_love = change_volume(love)
changed_love.play()
sound.wait_until_played()

# Now, test our function with the doglake.wav audio
doglake_sound = sound.load_sound("doglake.wav")
doglake_sound.play()
sound.wait_until_played()

changed_doglake_sound = change_volume(doglake_sound)
changed_doglake_sound.play()
sound.wait_until_played()