data/fonts/DejaVu-Copyright.txt
Sounds:
-
+data/sounds/sources.txt
Running the Game
--- /dev/null
+Sources of sound files
+======================
+
+silence.ogg
+-----------
+
+Notes:
+ Generated 2 secs of silence - dd if=/dev/zero of=silence.pcm bs=176400 count=2 ; oggenc -r silence.pcm
+ Generated by Neil Muller, Aug 2010
+ Not copyrightable.
+
+
+mouth_pop_2a.ogg
+----------------
+
+URL:
+ http://archive.org/download/Berklee44v5/Berklee44v5.zip
+Source:
+ http://archive.org/details/Berklee44v5
+License:
+ http://creativecommons.org/licenses/by/3.0
+Notes:
+ Ogg generated using 'oggenc -q -1 mouth_pop_2a.wav'
+
+
FONTS = {
'sans': 'DejaVuSans.ttf',
}
+
+# Sound stuff
+FREQ = 44100
+BITSIZE = -16
+CHANNELS = 2
+BUFFER = 1024
+DEFAULT_VOLUME = 1.0
+
+NO_SOUND = os.environ.get("TABAK_NO_SOUND", "").lower() in ("1", "y", "yes")
import pygame.image
import pygame.font
import pygame.display
+import pygame.mixer
from .constants import DEBUG
# Do we need to cache this?
return font
+ def load_sound(self, *parts):
+ """Return a pygame sound"""
+ fn = self.full_path("sounds", *parts)
+ sound = self._cache.get(fn, None)
+ if not sound:
+ sound = pygame.mixer.Sound(fn)
+ self._cache[fn] = sound
+ return sound
+
_DATA_PREFIX = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "data"))
from .engine import Engine
from .gamestate import GameState
from .scenes.menu import MenuScene
+from .sound import sound
def main():
pygame.display.set_mode(SCREEN_SIZE, pgl.SWSURFACE)
pygame.display.set_caption(TITLE)
# TODO: set an icon
+ sound.init()
screen = pygame.display.get_surface()
gamestate = GameState()
--- /dev/null
+
+from pygame import mixer
+
+from .constants import FREQ, BITSIZE, CHANNELS, BUFFER, DEFAULT_VOLUME, NO_SOUND
+from .loader import loader
+
+class SoundManager(object):
+
+ def init(self):
+ """This is not in __init__, because we want to delay until after
+ other pygame initialistion"""
+ self._init = False
+ if not NO_SOUND:
+ mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
+ silence = loader.load_sound("silence.ogg")
+ if silence.get_length() < 1:
+ raise RuntimeError("Sound load error - silence.ogg too short")
+ try:
+ self.play_sound("silence.ogg")
+ self._init = True
+ except Exception, err:
+ print "Failed to enable sound: %r" % err
+
+ def play_sound(self, name, volume=DEFAULT_VOLUME):
+ if self._init:
+ sound = loader.load_sound(name)
+ if sound is not None:
+ sound.set_volume(volume)
+ sound.play()
+
+ def play_music(self, name, volume=DEFAULT_VOLUME):
+ pass
+
+ def stop(self):
+ if self._init:
+ mixer.fadeout(1000)
+ mixer.music.stop()
+
+
+sound = SoundManager()