So I have a 2D game and I am trying to get some positional audio going just 
for some sound effects. One of the things I am trying to achieve is to have 
environmental sound effects, so for instance if you are near a water 
stream, you can hear water and it gets quieter as you move away. All I want 
is a simple x, y position and a radius or distance from the position where 
you can hear the audio and as you move closer to the player, it gets 
louder. 

So I've tried messing with the min_distance and max_distance but those 
don't seem to do much of anything. I tried looking at the documentation but 
it had zero information on this. I looked into OpenAL and someone said the 
minimum distance is where it's the loudest, and the max distance is where 
it's the quietest. I've tried setting the max_distance but I can still hear 
the sound no matter how far I moved the listener from the player, even if I 
set it to something small like 10. Even so, the audio is very strange, I 
can be practically right next to the source and it's somewhat quiet, then 
I'll move my listener a few pixels closer and then it's blaring.

I also don't know the frame of reference for distance. What is Position 
(0,0) to (0,1)? My coordinate system is just based on pixels, which I don't 
think this is, how do I convert this properly? 

class EnvironmentSound(pyglet.media.Player):
    """ Player will only play a specific sound in a loop. """
    def __init__(self, filename, x, y, volume, minDistance, maxDistance, 
gain):
        pyglet.media.Player.__init__(self)
        self.setPosition(x, y, 0)
        self.eos_action = pyglet.media.Player.EOS_LOOP # Loops the sound
        staticSource = 
StaticSource(pyglet.media.load(os.path.join(SOUND_FOLDER, filename)))
        self.min_distance = 1 # In pixels from position
        self.max_distance = 10 # In pixels from position
        self.playSound(staticSource)
        
    def setPosition(self, x, y, z=0):
        self.position = (x, y, z)
        
    def playSound(self, source):
        self.queue(source)
        self.play()
        
    def stopSound(self):
        self.eos_action = pyglet.media.Player.EOS_STOP

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to