def updateActor(self, interval, world): """Update the actor""" super(SoundTexture, self).updateActor(interval, world) # # Update the volume of all sounds if self.listener: for sound in self.sounds: # # Update the sound volume current_volume = sound.get_volume() target_volume = sound.get_scaled_volume( (self.listener.x, self.listener.y)) # # Damp changes in the sound volume if self.damping is None: new_volume = target_volume * self._master_volume else: new_volume = max( 0.0, min(1.0, interval / 1000.0 * self.damping) * (target_volume - current_volume) + current_volume) * self._master_volume sound.set_volume(new_volume) elif self._listener_required: raise NoListener( 'A listener has not been set for this texture (%s)' % self.getNiceName()) # # Play any random sounds if self._playing: for sound in self.random_sounds: sound.try_to_play(interval)
def updateActor(self, interval, world): """Update the actor""" super(SoundTexture, self).updateActor(interval, world) # # Update the volume of all sounds if self.listener: for sound in self.sounds: # # Update the sound volume current_volume = sound.get_volume() target_volume = sound.get_scaled_volume((self.listener.x, self.listener.y)) # # Damp changes in the sound volume if self.damping is None: new_volume = target_volume*self._master_volume else: new_volume = max(0.0, min(1.0, interval/1000.0*self.damping)* (target_volume - current_volume) + current_volume)*self._master_volume sound.set_volume(new_volume) elif self._listener_required: raise NoListener('A listener has not been set for this texture (%s)' % self.getNiceName()) # # Play any random sounds if self._playing: for sound in self.random_sounds: sound.try_to_play(interval)
def set_volume(self, volume): """Set the master volume This affects the volume of all sounds. The target volume for a sound is multiplied by this master. :param volume: master volume setting (0=silent, 1=full volume) """ self._master_volume = volume for sound in self.getSounds(): sound.set_volume(volume)