From 3df40f58a561f103172c7c312397a06646a321ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 22 Sep 2018 17:13:32 +0300 Subject: [PATCH] Implement sound --- README.md | 4 ---- sipsi-8.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b2607c7..9fa0d77 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,6 @@ which maps to 7 8 9 E A 0 B F -Sound ------ -Not yet implemented - Games ----- Get some [here](http://www.pong-story.com/chip8/) or [here](https://github.com/dmatlack/chip8/tree/master/roms) diff --git a/sipsi-8.py b/sipsi-8.py index 63bf03b..bbbb38a 100644 --- a/sipsi-8.py +++ b/sipsi-8.py @@ -357,7 +357,15 @@ def tick_timers(): # The timer should tick down at 60Hz delay_timer -= 1 - # TODO: Do sth about the sound timer + # Play a sound using pyglet if we have a non-zero sound timer + # It will run asynchronously from the other parts, which means it + # won't experience slowdown similarily to the delay timer + # Unsure if this is good or bad + if sound_timer > 0: + # sound_timer is in the unit of 1/60th of a second, while + # Square takes length in seconds + pyglet.media.procedural.Square(sound_timer/60).play() + sound_timer = 0 def advance_interpreter(dt): global cpu_speed @@ -610,7 +618,6 @@ def initialize_screen(): def initialize_timers(): global delay_timer, sound_timer - # Tick timers down at 60Hz delay_timer = 0 sound_timer = 0