OSDN Git Service

Disable volume/position updates until we find why it gets Invalid Handle. sounds
authorMojito Sorbet <mojitotech@gmail.com>
Wed, 2 Jun 2010 15:46:34 +0000 (15:46 +0000)
committerMojito Sorbet <mojitotech@gmail.com>
Wed, 2 Jun 2010 15:46:34 +0000 (15:46 +0000)
Changed Object announcements to use correct positions.

git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@668 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Media/BufferSound.cs
Radegast/Core/Media/MediaManager.cs
Radegast/Core/Media/MediaObject.cs
Radegast/Core/Media/Speech.cs
plugins/Radegast.Plugin.Speech/RadSpeech/Conversation/Surroundings.cs
plugins/Radegast.Plugin.Speech/RadSpeech/Environment/People.cs

index 07bdcd2..0567842 100644 (file)
@@ -42,6 +42,7 @@ namespace Radegast.Media
     public class BufferSound : MediaObject\r
     {\r
         private UUID Id;\r
+        private UUID ContainerId;\r
         private Boolean prefetchOnly = false;\r
         private FMOD.MODE mode;\r
         public Sound Sound { get { return sound; } }\r
@@ -55,24 +56,25 @@ namespace Radegast.Media
         /// Creates a new sound object\r
         /// </summary>\r
         /// <param name="system">Sound system</param>\r
-        public BufferSound( UUID soundId, bool loop, bool global, Vector3 worldpos, float vol )\r
+        public BufferSound( UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol )\r
             :base()\r
         {\r
-            InitBuffer(soundId, loop, global, worldpos, vol);\r
+            InitBuffer(objectId, soundId, loop, global, worldpos, vol);\r
         }\r
 \r
-        public BufferSound(UUID soundId, bool loop, bool global, Vector3d worldpos, float vol)\r
+        public BufferSound(UUID objectId, UUID soundId, bool loop, bool global, Vector3d worldpos, float vol)\r
             : base()\r
         {\r
-            InitBuffer(soundId, loop, global, new Vector3(worldpos), vol);\r
+            InitBuffer(objectId, soundId, loop, global, new Vector3(worldpos), vol);\r
         }\r
 \r
-        private void InitBuffer(UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)\r
+        private void InitBuffer(UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)\r
         {\r
             // Do not let this get garbage-collected.\r
             lock (allBuffers)\r
-                allBuffers[soundId] =this;\r
+                allBuffers[objectId] =this;\r
 \r
+            ContainerId = objectId;\r
             Id = soundId;\r
             position = FromOMVSpace(worldpos);\r
             volumeSetting = vol;\r
@@ -158,6 +160,7 @@ namespace Radegast.Media
                 allBuffers[soundId] = this;\r
 \r
             prefetchOnly = true;\r
+            ContainerId = UUID.Zero;\r
             Id = soundId;\r
 \r
             manager.Instance.Client.Assets.RequestAsset(\r
@@ -244,6 +247,12 @@ namespace Radegast.Media
 \r
                     // Allocate a channel and set initial volume.  Initially paused.\r
                     FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
+                    Logger.Log(\r
+                        String.Format("Channel {0} for {1} assigned to {2}",\r
+                             channel.getRaw().ToString("X"),\r
+                             sound.getRaw().ToString("X"),\r
+                             Id),\r
+                        Helpers.LogLevel.Debug);\r
                     FMODExec(channel.setVolume(volumeSetting * AllObjectVolume ));\r
 \r
                     // Take note of when the sound is finished playing.\r
@@ -293,10 +302,16 @@ namespace Radegast.Media
 \r
         protected void StopSound()\r
         {\r
-            Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug);\r
+            finished = true;\r
 \r
             invoke(new SoundDelegate(delegate\r
             {\r
+                Logger.Log( String.Format("Removing channel {0} sound {1} ID {2}",\r
+                        channel.getRaw().ToString("X"),\r
+                        sound.getRaw().ToString("X"),\r
+                        Id.ToString()),\r
+                    Helpers.LogLevel.Debug);\r
+\r
                 // Release the buffer to avoid a big memory leak.\r
                 if (channel != null)\r
                 {\r
@@ -311,7 +326,7 @@ namespace Radegast.Media
                 channel = null;\r
 \r
                 lock (allBuffers)\r
-                    allBuffers.Remove(Id);\r
+                    allBuffers.Remove(ContainerId);\r
             }));\r
 \r
         }\r
index e795545..b8cd1d8 100644 (file)
@@ -122,7 +122,6 @@ namespace Radegast.Media
                 }
                 catch (Exception e)
                 {
-
                     Logger.Log("Error in sound action:\n    " + e.Message + "\n" + e.StackTrace,
                         Helpers.LogLevel.Error);
                 }
@@ -300,7 +299,7 @@ namespace Radegast.Media
                 // Construct facing unit vector in FMOD coordinates.
                 // Z is East, X is South, Y is up.
                 FMOD.VECTOR forward = new FMOD.VECTOR();
-                forward.x = (float)Math.Sin(-angle); // South
+                forward.x = (float)Math.Sin(angle); // South
                 forward.y = 0.0f;
                 forward.z = (float)Math.Cos(angle); // East
 
@@ -342,6 +341,7 @@ namespace Radegast.Media
                 Helpers.LogLevel.Debug);
 
             new BufferSound(
+                e.ObjectID,
                 e.SoundID,
                 false,
                 true,
@@ -382,6 +382,7 @@ namespace Radegast.Media
             }
 
             new BufferSound(
+                e.ObjectID,
                 e.SoundID,
                 (e.Flags & SoundFlags.Loop) == SoundFlags.Loop,
                 true,
@@ -447,7 +448,7 @@ namespace Radegast.Media
            
             if ((p.SoundFlags & SoundFlags.Stop) == SoundFlags.Stop)
             {
-                BufferSound.Kill(p.Sound);
+                BufferSound.Kill(p.ID);
                 return;
             }
 
@@ -461,11 +462,11 @@ namespace Radegast.Media
             }
   
             // See if this is an update to  something we already know about.
-            if (allBuffers.ContainsKey(p.Sound))
+            if (allBuffers.ContainsKey(p.ID))
             {
                 // Exists already, so modify existing sound.
                 //TODO posible to change sound on the same object.  Key by Object?
-                BufferSound snd = allBuffers[p.Sound];
+                BufferSound snd = allBuffers[p.ID];
                 snd.Volume = p.SoundGain * ObjectVolume;
                 snd.Position = fullPosition;
             }
@@ -473,6 +474,7 @@ namespace Radegast.Media
             {
                 // Does not exist, so create a new one.
                 new BufferSound(
+                    p.ID,
                     p.Sound,
                     (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
                     true,
index 070ff72..00389e5 100644 (file)
@@ -45,7 +45,8 @@ namespace Radegast.Media
         /// </summary>
         public bool Disposed { get { return disposed; } }
         private bool disposed = false;
+        protected Boolean finished = false;
+
         /// All commands are made through queued delegate calls, so they
         /// are guaranteed to take place in the same thread.  FMOD requires this.
         public delegate void SoundDelegate();
@@ -103,7 +104,8 @@ namespace Radegast.Media
         public bool Active { get { return (sound != null); } }
 
         /// <summary>
-        /// Put a delegate call on the command queue.
+        /// Put a delegate call on the command queue.  These will be executed on
+        /// the FMOD control thread.   All FMOD calls must happen there.
         /// </summary>
         /// <param name="action"></param>
         protected void invoke(SoundDelegate action)
@@ -133,13 +135,28 @@ namespace Radegast.Media
             set
             {
                 volume = value;
+#if NOT
+// This is getting Bad Handle errors, so disabled for now
                 if (channel == null) return;
 
                 invoke(new SoundDelegate(delegate
                 {
-                    FMODExec(channel.setVolume(volume));
-//                    system.update();
+                    try
+                    {
+                        Logger.Log(
+                            String.Format("Volume on channel {0} sound {1} finished {2}",
+                               channel.getRaw().ToString("X"),
+                               sound.getRaw().ToString("X"),
+                               finished),
+                             Helpers.LogLevel.Debug);
+                        FMODExec(channel.setVolume(volume));
+                    }
+                    catch (Exception ex)
+                    {
+                        Logger.Log("Error changing volume", Helpers.LogLevel.Error, ex);
+                    }
                 }));
+#endif
             }
         }
 
@@ -152,14 +169,23 @@ namespace Radegast.Media
             set
             {
                 position = FromOMVSpace(value);
+#if NOT
+// This is getting Bad Handle errors, so disabled for now
+                if (channel == null) return;
+
                 invoke(new SoundDelegate(delegate
                     {
-                        if (channel != null)
-                            FMODExec(channel.set3DAttributes(
-                                ref position,
-                                ref ZeroVector));
-//                        system.update();
+                        Logger.Log(
+                            String.Format("Position on channel {0} sound {1} finished {2}",
+                                channel.getRaw().ToString("X"),
+                                sound.getRaw().ToString("X"),
+                                finished),
+                            Helpers.LogLevel.Debug);
+                        FMODExec(channel.set3DAttributes(
+                            ref position,
+                            ref ZeroVector));
                     }));
+#endif
             }
         }
 
index 6cbbb1b..4752744 100644 (file)
@@ -158,8 +158,6 @@ namespace Radegast.Media
 \r
                         // Un-pause the sound.\r
                         FMODExec(channel.setPaused(false));\r
-\r
-//                        system.update();\r
                     }\r
                     catch (Exception ex)\r
                     {\r
@@ -170,6 +168,10 @@ namespace Radegast.Media
             return RESULT.OK;\r
         }\r
 \r
+        /// <summary>\r
+        /// Handler for reaching the end of playback of a speech.\r
+        /// </summary>\r
+        /// <returns></returns>\r
         protected override RESULT EndCallbackHandler()\r
         {\r
             invoke(new SoundDelegate(\r
index e7ada3e..f37225c 100644 (file)
@@ -116,12 +116,12 @@ namespace RadegastSpeech.Conversation
 
             if (currentPrim.Properties == null)
             {
-                description = "Object data still loading.  Please wait.";
+                Talker.Say( "Object data still loading.  Please wait." );
+                return;
             }
             else
             {
-                description = currentPrim.Properties.Name;
-                description += control.env.people.Location(currentPrim.Position);
+                description = control.env.people.Location(currentPrim.Position);
 
                 if ((currentPrim.Flags & PrimFlags.Scripted) != 0)
                     description += " scripted,";
@@ -131,7 +131,9 @@ namespace RadegastSpeech.Conversation
                     description += " is touchable";
             }
 
-            Talker.SayMore(description,
+            Talker.SayObject(
+                currentPrim.Properties.Name,
+                description,
                 control.env.people.SameDirection( currentPrim.Position ) );
       }
 
index 4aaf7e3..2c0cc76 100644 (file)
@@ -140,6 +140,9 @@ namespace RadegastSpeech.Environment
             Vector3 pointer = Vector3.Multiply(
                 Vector3.Normalize( difference ), 4.0f );
 
+            // Add my position back
+            pointer += my.SimPosition;
+
             return pointer;
         }