I'd probably assign a single player for both reloading and firing then switch sources as needed, since you usually can't reload and fire at the same time. Same with walking, jumping, and swimming, etc. Try mapping out the various actions a character can take and the contexts in which they happen to figure out just how many players they may need, that can help you calculate how many sounds you may have playing at once and what your potential load may be. If your dealing with dynamically generated enemies, you could keep a pool of available players and pass them to any newly created characters for use, then release them for reuse when out of range or the characters are killed. This could dictate how many characters could be spawned at a time however, not including players for ambient or environmental effects. Although you could also try assigning players more dynamically based on what characters actions are in the moment and release them back into a central idle player pool when finished as well, so as not to have characters or effects constantly take up players that could be used elsewhere when not in use.
As for Pyglet or PyAL examples, theres a bunch in my repository with listeners, players, and source classes, which you can find [here], [here], and [here], note that for the advanced stuff like HRTF or EFX you'll need to copy over some of pyglets openal driver scripts or use PyAL, and use OpenAL Soft. For an example on what that might look like with a game implementation using those classes:
import pyglet
from pyglet.window import key
from pyglet.media.drivers.openal import lib_openal as al
from pyglet.media.drivers.openal import lib_alc as alc
#imports for sound loading and wait during example
import wave
import time
import sys
import os
class Example(pyglet.window.Window):
def __init__(self):
super(Example, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Example")
self.clear()
#load listener
self.listener = listener()
#initialize sound
self.sound = load_sound('tone5.wav')
#load sound player
self.player = Player()
#set the player to loop indefinitely until stopped
self.player.loop = True
#key input buffer
self.key_input = []
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
if 'SPACE press' in self.key_input:
#if player is playing, stop it
if self.player.playing() == True:
self.player.stop()
#make sure there is no source currently in the player
self.player.remove()
#load new source
self.player.add(self.sound)
#play source
self.player.play()
if 'SPACE release' in self.key_input:
#if player is playing, stop it
if self.player.playing() == True:
self.player.stop()
#purge the player of the current sample, if any
self.player.remove()
#clear key input buffer
if len(self.key_input) > 0:
self.key_input = []
#draw screen
self.draw()
def draw(self):
self.clear()
def on_key_press(self,symbol,modifiers):
self.key_input.append(key.symbol_string(symbol) + " press")
if symbol == key.ESCAPE:
self.sound.delete()
self.player.delete()
self.listener.delete()
self.close()
def on_key_release(self,symbol,modifiers):
self.key_input.append(key.symbol_string(symbol) + " release")
-
BrushTone v1.3.3: Accessible Paint Tool
-
AudiMesh3D v1.0.0: Accessible 3D Model Viewer