From 1f216465a882ade9953b1759243d295070507502 Mon Sep 17 00:00:00 2001 From: Mojito Sorbet Date: Mon, 31 May 2010 15:49:59 +0000 Subject: [PATCH] Better logging of sound/listener locations git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@665 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/Core/Media/BufferSound.cs | 39 +++++++++----- Radegast/Core/Media/MediaManager.cs | 102 +++++++++++++++++++++--------------- Radegast/Core/Media/Speech.cs | 8 +++ 3 files changed, 94 insertions(+), 55 deletions(-) diff --git a/Radegast/Core/Media/BufferSound.cs b/Radegast/Core/Media/BufferSound.cs index e6b880e..4b7baec 100644 --- a/Radegast/Core/Media/BufferSound.cs +++ b/Radegast/Core/Media/BufferSound.cs @@ -78,6 +78,15 @@ namespace Radegast.Media volumeSetting = vol; loopSound = loop; + Logger.Log( + String.Format( + "Playing sound at <{0:0.0},{1:0.0},{2:0.0}> ID {3}", + position.x, + position.y, + position.z, + Id.ToString()), + Helpers.LogLevel.Debug); + // Set flags to determine how it will be played. mode = FMOD.MODE.SOFTWARE | // Need software processing for all the features FMOD.MODE._3D | // Need 3D effects for placement @@ -245,7 +254,7 @@ namespace Radegast.Media 1.2f, // Any closer than this gets no louder 100.0f)); // Further than this gets no softer. - // Set the sound point of origin. This is in GLOBAL coordinates. + // Set the sound point of origin. This is in SIM coordinates. FMODExec(channel.set3DAttributes(ref position, ref ZeroVector)); // Turn off pause mode. The sound will start playing now. @@ -286,21 +295,25 @@ namespace Radegast.Media { Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug); - // Release the buffer to avoid a big memory leak. - if (channel != null) + invoke(new SoundDelegate(delegate { - channel.stop(); + // Release the buffer to avoid a big memory leak. + if (channel != null) + { + channel.stop(); + channel = null; + } + if (sound != null) + { + sound.release(); + sound = null; + } channel = null; - } - if (sound != null) - { - sound.release(); - sound = null; - } - channel = null; - lock (allBuffers) - allBuffers.Remove(Id); + lock (allBuffers) + allBuffers.Remove(Id); + })); + } } diff --git a/Radegast/Core/Media/MediaManager.cs b/Radegast/Core/Media/MediaManager.cs index fba9a2b..ccf6c31 100644 --- a/Radegast/Core/Media/MediaManager.cs +++ b/Radegast/Core/Media/MediaManager.cs @@ -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 } /// - /// Command object sound processing for various Update events + /// Common object sound processing for various Update events /// /// /// @@ -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); + } } /// @@ -492,31 +499,42 @@ namespace Radegast.Media { set { - if (value) + try { - // Subscribe to events about inworld sounds - Instance.Client.Sound.SoundTrigger += new EventHandler(Sound_SoundTrigger); - Instance.Client.Sound.AttachedSound += new EventHandler(Sound_AttachedSound); - Instance.Client.Sound.PreloadSound += new EventHandler(Sound_PreloadSound); - Instance.Client.Objects.ObjectUpdate += new EventHandler(Objects_ObjectUpdate); - Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler(Objects_ObjectPropertiesUpdated); - Instance.Client.Objects.KillObject += new EventHandler(Objects_KillObject); - Instance.Client.Network.SimChanged += new EventHandler(Network_SimChanged); + if (value) + { + // Subscribe to events about inworld sounds + Instance.Client.Sound.SoundTrigger += new EventHandler(Sound_SoundTrigger); + Instance.Client.Sound.AttachedSound += new EventHandler(Sound_AttachedSound); + Instance.Client.Sound.PreloadSound += new EventHandler(Sound_PreloadSound); + Instance.Client.Objects.ObjectUpdate += new EventHandler(Objects_ObjectUpdate); + Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler(Objects_ObjectPropertiesUpdated); + Instance.Client.Objects.KillObject += new EventHandler(Objects_KillObject); + Instance.Client.Network.SimChanged += new EventHandler(Network_SimChanged); + Logger.Log("Inworld sound enabled", Helpers.LogLevel.Info); + } + else + { + // Subscribe to events about inworld sounds + Instance.Client.Sound.SoundTrigger -= new EventHandler(Sound_SoundTrigger); + Instance.Client.Sound.AttachedSound -= new EventHandler(Sound_AttachedSound); + Instance.Client.Sound.PreloadSound -= new EventHandler(Sound_PreloadSound); + Instance.Client.Objects.ObjectUpdate -= new EventHandler(Objects_ObjectUpdate); + Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler(Objects_ObjectPropertiesUpdated); + Instance.Client.Objects.KillObject -= new EventHandler(Objects_KillObject); + Instance.Client.Network.SimChanged -= new EventHandler(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(Sound_SoundTrigger); - Instance.Client.Sound.AttachedSound -= new EventHandler(Sound_AttachedSound); - Instance.Client.Sound.PreloadSound -= new EventHandler(Sound_PreloadSound); - Instance.Client.Objects.ObjectUpdate -= new EventHandler(Objects_ObjectUpdate); - Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler(Objects_ObjectPropertiesUpdated); - Instance.Client.Objects.KillObject -= new EventHandler(Objects_KillObject); - Instance.Client.Network.SimChanged -= new EventHandler(Network_SimChanged); - - // Stop all running sounds - BufferSound.KillAll(); + System.Console.WriteLine("Error on enable/disable: "+e.Message); } + m_objectEnabled = value; } get { return m_objectEnabled; } diff --git a/Radegast/Core/Media/Speech.cs b/Radegast/Core/Media/Speech.cs index 1706b26..6cbbb1b 100644 --- a/Radegast/Core/Media/Speech.cs +++ b/Radegast/Core/Media/Speech.cs @@ -144,6 +144,14 @@ namespace Radegast.Media ref position, ref ZeroVector)); + Logger.Log( + String.Format( + "Speech at <{0:0.0},{1:0.0},{2:0.0}>", + position.x, + position.y, + position.z), + Helpers.LogLevel.Debug); + // SET a handler for when it finishes. FMODExec(channel.setCallback(endCallback)); RegisterChannel( channel ); -- 2.11.0