OSDN Git Service

FMOD calls a callback after object collected. Not found it yet
authorMojito Sorbet <mojitotech@gmail.com>
Tue, 18 May 2010 03:15:11 +0000 (03:15 +0000)
committerMojito Sorbet <mojitotech@gmail.com>
Tue, 18 May 2010 03:15:11 +0000 (03:15 +0000)
git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@638 f7a694da-4d33-11de-9ad6-1127a62b9fcd

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

index 407dc51..e331c1c 100644 (file)
@@ -54,6 +54,7 @@ namespace Radegast.Media
             : base()
         {
             this.instance = instance;
+            manager = this;
 
             // Start the background thread that does all the FMOD calls.
             soundThread = new Thread(new ThreadStart(CommandLoop));
@@ -88,29 +89,29 @@ namespace Radegast.Media
             // Initialize the command queue.
             queue = new Queue<SoundDelegate>();
 
-            try
+            while (true)
             {
-                while (true)
+                // Wait for something to show up in the queue.
+                lock (queue)
                 {
-                    // Wait for something to show up in the queue.
-                    lock (queue)
+                    while (queue.Count == 0)
                     {
-                        while (queue.Count == 0)
-                        {
-                            Monitor.Wait(queue);
-                        }
-
-                        action = queue.Dequeue();
+                        Monitor.Wait(queue);
                     }
+                    action = queue.Dequeue();
+                }
 
-                    // We have an action, so call it.
+                // We have an action, so call it.
+                try
+                {
                     action();
                     action = null;
                 }
-            }
-            catch (Exception e)
-            {
-                System.Console.WriteLine("Sound shutdown " + e.Message);
+                catch (Exception e)
+                {
+                    Logger.Log("Error in sound action: " + e.Message,
+                        Helpers.LogLevel.Error);
+                }
             }
         }
 
@@ -222,6 +223,7 @@ namespace Radegast.Media
 
             if (system != null)
             {
+                Logger.Log("FMOD interface stopping", Helpers.LogLevel.Info);
                 system.release();
                 system = null;
             }
@@ -256,7 +258,7 @@ namespace Radegast.Media
                 {
                     invoke(new SoundDelegate(delegate
                     {
-                        system.update();
+                        FMODExec(system.update());
                     }));
                     continue;
                 }
@@ -287,7 +289,7 @@ namespace Radegast.Media
                         ref forward,           // Facing direction
                         ref UpVector ));       // Top of head
 
-                    system.update();
+                    FMODExec(system.update());
                 }));
             }
         }
index ba8ec5e..4c48037 100644 (file)
@@ -53,6 +53,7 @@ namespace Radegast.Media
         /// 
         /// </summary>
         protected static Queue<SoundDelegate> queue;
+        protected static MediaManager manager;
 
         /// <summary>
         /// FMOD channel controller, should not be used directly, add methods to Radegast.Media.Sound
@@ -81,7 +82,6 @@ namespace Radegast.Media
         {
             extraInfo = new FMOD.CREATESOUNDEXINFO();
             extraInfo.cbsize = Marshal.SizeOf(extraInfo);
-
         }
 
         protected bool Cloned = false;
@@ -134,11 +134,14 @@ namespace Radegast.Media
                 invoke(new SoundDelegate(delegate
                 {
                     FMODExec(channel.setVolume(volume));
-                    system.update();
+//                    system.update();
                 }));
             }
         }
 
+        /// <summary>
+        /// Update the 3D position of a sound source.
+        /// </summary>
         protected FMOD.VECTOR position = new FMOD.VECTOR();
         public OpenMetaverse.Vector3 Position
         {
@@ -151,7 +154,7 @@ namespace Radegast.Media
                             FMODExec(channel.set3DAttributes(
                                 ref position,
                                 ref ZeroVector));
-                        system.update();
+//                        system.update();
                     }));
             }
         }
@@ -225,7 +228,7 @@ namespace Radegast.Media
         protected virtual FMOD.RESULT NonBlockCallbackHandler( RESULT result ) { return RESULT.OK; }
         protected virtual FMOD.RESULT EndCallbackHandler() { return RESULT.OK; }
 
-        protected RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
+        public RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
         {
             if (allSounds.ContainsKey(soundraw))
             {
@@ -242,13 +245,16 @@ namespace Radegast.Media
             IntPtr commanddata1,
             IntPtr commanddata2)
         {
-            // Ignore other callback types.
-            if (type != CHANNEL_CALLBACKTYPE.END) return RESULT.OK;
-
-            if (allChannels.ContainsKey(channelraw))
+            // There are several callback types
+            switch (type)
             {
-                MediaObject sndobj = allChannels[channelraw];
-                return sndobj.EndCallbackHandler();
+                case CHANNEL_CALLBACKTYPE.END:
+                    if (allChannels.ContainsKey(channelraw))
+                    {
+                        MediaObject sndobj = allChannels[channelraw];
+                        return sndobj.EndCallbackHandler();
+                    }
+                    break;
             }
 
             return RESULT.OK;
index 9c891d6..68c0608 100644 (file)
@@ -57,7 +57,6 @@ namespace Radegast.Media
         public Speech()\r
             :base()\r
        {\r
-           extraInfo.nonblockcallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);\r
            extraInfo.format = SOUND_FORMAT.PCM16;\r
        }\r
 \r
@@ -93,7 +92,9 @@ namespace Radegast.Media
             else\r
                 mode |= FMOD.MODE._3D_HEADRELATIVE;\r
 \r
-            invoke( new SoundDelegate(\r
+            extraInfo.nonblockcallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);\r
+\r
+            invoke(new SoundDelegate(\r
                 delegate {\r
                     FMODExec(\r
                         system.createSound(filename,\r
@@ -113,6 +114,8 @@ namespace Radegast.Media
         /// <returns></returns>\r
         protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
         {\r
+            extraInfo.nonblockcallback = null;\r
+\r
             if (instatus != RESULT.OK)\r
             {\r
                 Logger.Log("Error opening speech file " +\r
@@ -148,7 +151,7 @@ namespace Radegast.Media
                         // Un-pause the sound.\r
                         FMODExec(channel.setPaused(false));\r
 \r
-                        system.update();\r
+//                        system.update();\r
                     }\r
                     catch (Exception ex)\r
                     {\r
@@ -164,6 +167,7 @@ namespace Radegast.Media
             invoke(new SoundDelegate(\r
                  delegate\r
                  {\r
+ //                    FMODExec(channel.setCallback(null));\r
                      UnRegisterChannel();\r
                      channel = null;\r
                      UnRegisterSound();\r