OSDN Git Service

Better logging of sound/listener locations
authorMojito Sorbet <mojitotech@gmail.com>
Mon, 31 May 2010 15:49:59 +0000 (15:49 +0000)
committerMojito Sorbet <mojitotech@gmail.com>
Mon, 31 May 2010 15:49:59 +0000 (15:49 +0000)
git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@665 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Media/BufferSound.cs
Radegast/Core/Media/MediaManager.cs
Radegast/Core/Media/Speech.cs

index e6b880e..4b7baec 100644 (file)
@@ -78,6 +78,15 @@ namespace Radegast.Media
             volumeSetting = vol;\r
             loopSound = loop;\r
 \r
+            Logger.Log(\r
+                String.Format(\r
+                    "Playing sound at <{0:0.0},{1:0.0},{2:0.0}> ID {3}",\r
+                    position.x,\r
+                    position.y,\r
+                    position.z,\r
+                    Id.ToString()),\r
+                Helpers.LogLevel.Debug);\r
+\r
             // Set flags to determine how it will be played.\r
             mode = FMOD.MODE.SOFTWARE | // Need software processing for all the features\r
                 FMOD.MODE._3D |         // Need 3D effects for placement\r
@@ -245,7 +254,7 @@ namespace Radegast.Media
                                 1.2f,       // Any closer than this gets no louder\r
                                 100.0f));     // Further than this gets no softer.\r
 \r
-                    // Set the sound point of origin.  This is in GLOBAL coordinates.\r
+                    // Set the sound point of origin.  This is in SIM coordinates.\r
                     FMODExec(channel.set3DAttributes(ref position, ref ZeroVector));\r
 \r
                     // Turn off pause mode.  The sound will start playing now.\r
@@ -286,21 +295,25 @@ namespace Radegast.Media
         {\r
             Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug);\r
 \r
-            // Release the buffer to avoid a big memory leak.\r
-            if (channel != null)\r
+            invoke(new SoundDelegate(delegate\r
             {\r
-                channel.stop();\r
+                // Release the buffer to avoid a big memory leak.\r
+                if (channel != null)\r
+                {\r
+                    channel.stop();\r
+                    channel = null;\r
+                }\r
+                if (sound != null)\r
+                {\r
+                    sound.release();\r
+                    sound = null;\r
+                }\r
                 channel = null;\r
-            }\r
-            if (sound != null)\r
-            {\r
-                sound.release();\r
-                sound = null;\r
-            }\r
-            channel = null;\r
 \r
-            lock (allBuffers)\r
-                allBuffers.Remove(Id);\r
+                lock (allBuffers)\r
+                    allBuffers.Remove(Id);\r
+            }));\r
+\r
         }\r
 \r
     }\r
index fba9a2b..ccf6c31 100644 (file)
@@ -301,8 +301,14 @@ namespace Radegast.Media
                 forward.y = 0.0f;
                 forward.z = (float)Math.Cos(angle); // East
 
-                int facing = (int)(angle * 180.0 / 3.141592);
-                Logger.Log("Facing "+facing.ToString(), Helpers.LogLevel.Debug);
+                Logger.Log(
+                    String.Format(
+                        "Standing at <{0:0.0},{1:0.0},{2:0.0}> facing {3:d}",
+                            listenerpos.x,
+                            listenerpos.y,
+                            listenerpos.z,
+                            (int)(angle * 180.0 / 3.141592)),
+                    Helpers.LogLevel.Debug);
 
                 // Tell FMOD the new orientation.
                 invoke( new SoundDelegate( delegate
@@ -372,9 +378,6 @@ namespace Radegast.Media
                 fullPosition += parentP.Position;
             }
 
-            Logger.Log("Attached sound " + e.SoundID.ToString(),
-                Helpers.LogLevel.Debug);
-
             new BufferSound(
                 e.SoundID,
                 (e.Flags & SoundFlags.Loop) == SoundFlags.Loop,
@@ -393,10 +396,6 @@ namespace Radegast.Media
         {
             if (e.SoundID == UUID.Zero) return;
 
-            Logger.Log("Prefetch sound " + e.SoundID.ToString() +
-                " in object " + e.ObjectID.ToString(),
-                Helpers.LogLevel.Debug);
-
             new BufferSound( e.SoundID );
         }
 
@@ -433,7 +432,7 @@ namespace Radegast.Media
         }
 
         /// <summary>
-        /// Command object sound processing for various Update events
+        /// Common object sound processing for various Update events
         /// </summary>
         /// <param name="p"></param>
         /// <param name="s"></param>
@@ -449,10 +448,6 @@ namespace Radegast.Media
                 return;
             }
 
-            Logger.Log("Object sound " + p.Sound.ToString() +
-                " in object " + p.ID.ToString(),
-                Helpers.LogLevel.Debug);
-
             // If this is a child prim, its position is relative to the root prim.
             Vector3 fullPosition = p.Position;
             if (p.ParentID != 0)
@@ -462,13 +457,25 @@ namespace Radegast.Media
                 fullPosition += parentP.Position;
             }
   
-            // Create a sound object for this.
-            new BufferSound(
-                p.Sound,
-                (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
-                true,
-                fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition),
-                p.SoundGain * ObjectVolume);
+            // See if this is an update to  something we already know about.
+            if (allBuffers.ContainsKey(p.Sound))
+            {
+                // Exists already, so modify existing sound.
+                //TODO posible to change sound on the same object.  Key by Object?
+                BufferSound snd = allBuffers[p.Sound];
+                snd.Volume = p.SoundGain * ObjectVolume;
+                snd.Position = fullPosition;
+            }
+            else
+            {
+                // Does not exist, so create a new one.
+                new BufferSound(
+                    p.Sound,
+                    (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
+                    true,
+                    fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition),
+                    p.SoundGain * ObjectVolume);
+            }
         }
 
         /// <summary>
@@ -492,31 +499,42 @@ namespace Radegast.Media
         {
             set
             {
-                if (value)
+                try
                 {
-                    // Subscribe to events about inworld sounds
-                    Instance.Client.Sound.SoundTrigger += new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
-                    Instance.Client.Sound.AttachedSound += new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
-                    Instance.Client.Sound.PreloadSound += new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
-                    Instance.Client.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
-                    Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
-                    Instance.Client.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
-                    Instance.Client.Network.SimChanged += new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+                    if (value)
+                    {
+                        // Subscribe to events about inworld sounds
+                        Instance.Client.Sound.SoundTrigger += new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
+                        Instance.Client.Sound.AttachedSound += new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
+                        Instance.Client.Sound.PreloadSound += new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
+                        Instance.Client.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
+                        Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
+                        Instance.Client.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
+                        Instance.Client.Network.SimChanged += new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+                        Logger.Log("Inworld sound enabled", Helpers.LogLevel.Info);
+                    }
+                    else
+                    {
+                        // Subscribe to events about inworld sounds
+                        Instance.Client.Sound.SoundTrigger -= new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
+                        Instance.Client.Sound.AttachedSound -= new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
+                        Instance.Client.Sound.PreloadSound -= new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
+                        Instance.Client.Objects.ObjectUpdate -= new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
+                        Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
+                        Instance.Client.Objects.KillObject -= new EventHandler<KillObjectEventArgs>(Objects_KillObject);
+                        Instance.Client.Network.SimChanged -= new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+
+                        // Stop all running sounds
+                        BufferSound.KillAll();
+
+                        Logger.Log("Inworld sound disabled", Helpers.LogLevel.Info);
+                    }
                 }
-                else
+                catch (Exception e)
                 {
-                    // Subscribe to events about inworld sounds
-                    Instance.Client.Sound.SoundTrigger -= new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
-                    Instance.Client.Sound.AttachedSound -= new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
-                    Instance.Client.Sound.PreloadSound -= new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
-                    Instance.Client.Objects.ObjectUpdate -= new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
-                    Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
-                    Instance.Client.Objects.KillObject -= new EventHandler<KillObjectEventArgs>(Objects_KillObject);
-                    Instance.Client.Network.SimChanged -= new EventHandler<SimChangedEventArgs>(Network_SimChanged);
-
-                    // Stop all running sounds
-                    BufferSound.KillAll();
+                    System.Console.WriteLine("Error on enable/disable: "+e.Message);
                 }
+
                 m_objectEnabled = value;
             }
             get { return m_objectEnabled; }
index 1706b26..6cbbb1b 100644 (file)
@@ -144,6 +144,14 @@ namespace Radegast.Media
                            ref position,\r
                            ref ZeroVector));\r
 \r
+                        Logger.Log(\r
+                            String.Format(\r
+                                "Speech at <{0:0.0},{1:0.0},{2:0.0}>",\r
+                                position.x,\r
+                                position.y,\r
+                                position.z),\r
+                            Helpers.LogLevel.Debug);\r
+\r
                         // SET a handler for when it finishes.\r
                         FMODExec(channel.setCallback(endCallback));\r
                         RegisterChannel( channel );\r