Browse Source

api to change cutoff

Joe Shochet 21 years ago
parent
commit
a34532500e
1 changed files with 12 additions and 8 deletions
  1. 12 8
      direct/src/showbase/SfxPlayer.py

+ 12 - 8
direct/src/showbase/SfxPlayer.py

@@ -10,24 +10,28 @@ class SfxPlayer:
     UseInverseSquare = 0
 
     def __init__(self):
-        # Distance at which sounds can no longer be heard
-        # This was determined experimentally
-        self.cutoffDistance = 120.0
-
-        # cutoff for inverse square attenuation
-        if SfxPlayer.UseInverseSquare:
-            self.cutoffDistance = 300.0
         # volume attenuates according to the inverse square of the
         # distance from the source. volume = 1/(distance^2)
         # this is the volume at which a sound is nearly inaudible
         self.cutoffVolume = .02
+
+        # cutoff for inverse square attenuation
+        if SfxPlayer.UseInverseSquare:
+            self.setCutoffDistance(300.0)
+        else:
+            # Distance at which sounds can no longer be heard
+            # This was determined experimentally
+            self.setCutoffDistance(120.0)
+
+    def setCutoffDistance(self, d):
+        self.cutoffDistance = d
         # this is the 'raw' distance at which the volume of a sound will
         # be equal to the cutoff volume
         rawCutoffDistance = math.sqrt(1./self.cutoffVolume)
         # this is a scale factor to convert distances so that a sound
         # located at self.cutoffDistance will have a volume
         # of self.cutoffVolume
-        self.distanceScale = rawCutoffDistance / self.cutoffDistance
+        self.distanceScale = rawCutoffDistance / self.cutoffDistance        
 
     def getLocalizedVolume(self, node):
         """