OSDN Git Service

Dynamic inworld volume adjustment.
[radegast/radegast.git] / Radegast / Core / Media / BufferSound.cs
index 11d1e43..e6b880e 100644 (file)
@@ -46,6 +46,10 @@ namespace Radegast.Media
         private FMOD.MODE mode;\r
         public Sound Sound { get { return sound; } }\r
         private Boolean loopSound = false;\r
+        /// <summary>\r
+        /// The individual volume setting for THIS object\r
+        /// </summary>\r
+        private float volumeSetting = 0.5f;\r
 \r
         /// <summary>\r
         /// Creates a new sound object\r
@@ -71,7 +75,7 @@ namespace Radegast.Media
 \r
             Id = soundId;\r
             position = FromOMVSpace(worldpos);\r
-            volume = vol;\r
+            volumeSetting = vol;\r
             loopSound = loop;\r
 \r
             // Set flags to determine how it will be played.\r
@@ -118,6 +122,25 @@ namespace Radegast.Media
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Adjust volumes of all playing sounds to observe the new global sound volume\r
+        /// </summary>\r
+        public static void AdjustVolumes()\r
+        {\r
+            foreach (BufferSound s in allBuffers.Values)\r
+            {\r
+                s.AdjustVolume();\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Adjust the volume of THIS sound when all are being adjusted.\r
+        /// </summary>\r
+        private void AdjustVolume()\r
+        {\r
+            Volume = volumeSetting * AllObjectVolume;\r
+        }\r
+\r
         // A simpler constructor used by PreFetchSound.\r
         public BufferSound( UUID soundId )\r
             : base()\r
@@ -212,7 +235,7 @@ namespace Radegast.Media
 \r
                     // Allocate a channel and set initial volume.  Initially paused.\r
                     FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
-                    FMODExec(channel.setVolume(volume * m_objectVolume ));\r
+                    FMODExec(channel.setVolume(volumeSetting * AllObjectVolume ));\r
 \r
                     // Take note of when the sound is finished playing.\r
                     FMODExec(channel.setCallback(endCallback));\r