Exemplo n.º 1
0
def load_sound(filename):
    global _loaded_sounds
    if filename not in _loaded_sounds:
        sound_buffer = sf.SoundBuffer()
        fname = os.path.join(_base_sounds_dir, filename)
        if not sound_buffer.LoadFromFile(fname):
            raise RuntimeError("Sound %s couldn't be loaded" % fname)
        _loaded_sounds[filename] = sound_buffer
    return sf.Sound(_loaded_sounds[filename])
Exemplo n.º 2
0
	def Open(self, Filename):
		# Load the sound data into a sound buffer
		self.SoundData = sf.SoundBuffer()
		if not self.SoundData.LoadFromFile(Filename):
			return False
		# Initialize the stream with the sound parameters
		self.Initialize(self.SoundData.GetChannelsCount(), self.SoundData.GetSampleRate())
		# Copy the audio samples into our internal array
		self.myBuffer = self.SoundData.GetSamples()
		return True
Exemplo n.º 3
0
    def __init__(self, filename, magic=False):
        """Do not call this directly."""
        self.soundbuffer = sf.SoundBuffer()
        self.filename = filename
        if not tf.PRODUCTION:
            self.sounds = set()

        self._do_update(0)

        if not tf.PRODUCTION:
            # This makes the stat() checks spread out
            self.last_gametick_updated += \
                ((len(self.all_soundfiles)+1)
                 % self.GAMETICKS_BEFORE_UPDATE_CHECK)

        if magic is True and self.filename not in self.all_soundfiles:
            self.all_soundfiles[self.filename] = self
        else:
            raise tf.TribeFlameException(\
                "Warning, you are not using soundfile.py properly. " + \
                    "Call soundfile.new_soundbuffer instead.")
Exemplo n.º 4
0
def Main():
    Buffer = sf.SoundBuffer()
    if not Buffer.LoadFromFile("data/fart.wav"):  # Loads the sound
        return
    Fart = sf.Sound(Buffer, False)

    WindowWidth, WindowHeight = 640, 480
    App = sf.RenderWindow(sf.VideoMode(WindowWidth, WindowHeight, 32),
                          "Sound with PySFML", sf.Style.Close,
                          sf.ContextSettings(24, 8, 0))
    App.SetFramerateLimit(30)

    EventHandler = sf.Event()
    InputHandler = App.GetInput()

    Text = sf.Text(
        "Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners."
    )
    Text.SetX(30.)
    Text.SetY(20.)
    Text.SetColor(sf.Color(150, 100, 10, 255))

    while App.IsOpened():  # Main loop
        while App.GetEvent(EventHandler):  # Event Handler
            if EventHandler.Type == sf.Event.Closed:
                App.Close()
            if EventHandler.Type == sf.Event.KeyPressed and EventHandler.Key.Code == sf.Key.Escape:
                App.Close()
            if EventHandler.Type == sf.Event.MouseButtonPressed and EventHandler.MouseButton.Button == sf.Mouse.Left:
                Fart.SetPitch(1.5 -
                              1. * InputHandler.GetMouseY() / WindowHeight)
                Fart.SetPosition(
                    1. * (InputHandler.GetMouseX() - WindowWidth / 2) /
                    (WindowWidth / 20), 2., -2.)
                Fart.Play()
        App.Draw(Text)
        App.Display()
        App.Clear(sf.Color.Black)
Exemplo n.º 5
0
from PySFML import sf

_liste = ['ds1', 'ds2', 'ds3', 'elf', 'jet', 'plash', 'm/a1', 'm/a2', 'm/a3', 't/a1', 't/a2']
_bufs = []
sounds = {}
for e in _liste:
	x = sf.SoundBuffer()
	x.LoadFromFile('son/{}.ogg'.format(e))
	_bufs.append(x)
	y = sf.Sound(x)
	sounds[e] = y