def test2(): a = seq.build(seq.track1, player.bitRate) screen.init() screen.draw(a, player.bitRate / seq.track1[0]["frequency"]) b = gen.sin(440, player.bitRate, 10, 0) player.play(a) player.play(b)
def test1(): # generate samples, note conversion to float32 array s1 = gen.squ(f1, fs, duration, 1 / 2) # s2 = gen.sin(f2, fs, duration) # s3 = gen.squ(f3, fs, duration) # samples = np.nan_to_num(s1*(s2))/2 # samples = s1 * gen.rah(s2) * gen.rah(s3) samples = s1 screen.init() screen.draw(samples, fs / f1) # for paFloat32 sample values must be in range [-1.0, 1.0] stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True) # play. May repeat with different volume values (if done interactively) stream.write(volume * samples) stream.stop_stream() stream.close() p.terminate()
def draw_graphics(self, screen): ''' show the result of everything ''' screen.draw()
messenger.Messenger.pc = player.Player(200, 200) messenger.Messenger.agents = [npc.Thug(300, 300), npc.Thug(250, 350)] messenger.Messenger.items = [] screen = screen.Screen(messenger.Messenger.pc, messenger.Messenger.agents, messenger.Messenger.items) clock = pygame.time.Clock() while True: pc = messenger.Messenger.pc agents = messenger.Messenger.agents items = messenger.Messenger.items clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() quit() elif event.type == KEYDOWN: if event.key == K_w: pc.y -= 10 elif event.key == K_s: pc.y += 10 elif event.key == K_d: pc.x += 10 elif event.key == K_a: pc.x -= 10 if event.key == K_UP: screen.y += 10 elif event.key == K_DOWN: screen.y -= 10 elif event.key == K_RIGHT: screen.x -= 10 elif event.key == K_LEFT: screen.x += 10 if event.key == K_SPACE: pc.attack(agents) elif event.type == MOUSEBUTTONDOWN: x, y = event.pos pc.look(x, y, screen) screen.draw()
p = pyaudio.PyAudio() volume = 0.2 # range [0.0, 1.0] fs = 44100 # sampling rate, Hz, must be integer duration = 10.0 # in seconds, may be float f1 = 440.0 # sine frequency, Hz, may be float f2 = 20.0 # sine frequency, Hz, may be float f3 = 11 # sine frequency, Hz, may be float # generate samples, note conversion to float32 array s1 = sin(f1, fs, duration) s2 = sin(f2, fs, duration) s3 = squ(f3, fs, duration) # samples = np.nan_to_num(s1*(s2))/2 samples = s1 * rah(s2) * rah(s3) screen.init() screen.draw(samples, fs / f2) # for paFloat32 sample values must be in range [-1.0, 1.0] stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True) # play. May repeat with different volume values (if done interactively) stream.write(volume * samples) stream.stop_stream() stream.close() p.terminate()