OSDN Git Service

Give up on non blocking fmod calls, causes too much trouble.
authorLatif Khalifa <latifer@streamgrid.net>
Tue, 8 Jun 2010 11:46:27 +0000 (11:46 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Tue, 8 Jun 2010 11:46:27 +0000 (11:46 +0000)
(fixes sounds and speech on XP)

git-svn-id: https://radegast.googlecode.com/svn/trunk@695 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
Radegast/Core/Media/Stream.cs

index a1e1501..522dcc1 100644 (file)
@@ -94,8 +94,7 @@ namespace Radegast.Media
             // 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
-                FMOD.MODE.OPENMEMORY |  // Use sound data in memory\r
-                FMOD.MODE.NONBLOCKING;\r
+                FMOD.MODE.OPENMEMORY;   // Use sound data in memory\r
 \r
             // Set coordinate space interpretation.\r
             if (global)\r
@@ -212,55 +211,34 @@ namespace Radegast.Media
 \r
                 // Describe the data to FMOD\r
                 extraInfo.length = (uint)data.Length;\r
-                extraInfo.nonblockcallback = loadCallback;\r
                 extraInfo.cbsize = Marshal.SizeOf(extraInfo);\r
 \r
                 invoke(new SoundDelegate(delegate\r
                 {\r
-                    // Create an FMOD sound of this Ogg data.\r
-                    FMODExec(system.createSound(\r
-                        data,\r
-                        mode,\r
-                        ref extraInfo,\r
-                        ref sound));\r
-\r
-                    // Register for callbacks.\r
-                    RegisterSound(sound);\r
-                }));\r
-            }\r
-            else\r
-            {\r
-                Logger.Log("Failed to download sound: " + transfer.Status.ToString(),\r
-                                        Helpers.LogLevel.Error);\r
-            }\r
-        }\r
-\r
-        protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
-        {\r
-            // Check if we killed the sound before it was decoded\r
-            if (sound == null) return RESULT.OK;\r
-\r
-            if (instatus != RESULT.OK)\r
-            {\r
-                Logger.Log("Error opening sound: " + instatus, Helpers.LogLevel.Error);\r
-                return RESULT.OK;\r
-            }\r
-\r
-            invoke(new SoundDelegate(delegate\r
-            {\r
-                try\r
-                {\r
-                    // If looping is requested, loop the entire thing.\r
-                    if (loopSound)\r
+                    try\r
                     {\r
-                        uint soundlen = 0;\r
-                        FMODExec(sound.getLength(ref soundlen, TIMEUNIT.PCM));\r
-                        FMODExec(sound.setLoopPoints(0, TIMEUNIT.PCM, soundlen - 1, TIMEUNIT.PCM));\r
-                        FMODExec(sound.setLoopCount(-1));\r
-                    }\r
-\r
-                    // Allocate a channel and set initial volume.  Initially paused.\r
-                    FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
+                        // Create an FMOD sound of this Ogg data.\r
+                        FMODExec(system.createSound(\r
+                            data,\r
+                            mode,\r
+                            ref extraInfo,\r
+                            ref sound));\r
+\r
+                        // Register for callbacks.\r
+                        RegisterSound(sound);\r
+\r
+\r
+                        // If looping is requested, loop the entire thing.\r
+                        if (loopSound)\r
+                        {\r
+                            uint soundlen = 0;\r
+                            FMODExec(sound.getLength(ref soundlen, TIMEUNIT.PCM));\r
+                            FMODExec(sound.setLoopPoints(0, TIMEUNIT.PCM, soundlen - 1, TIMEUNIT.PCM));\r
+                            FMODExec(sound.setLoopCount(-1));\r
+                        }\r
+\r
+                        // Allocate a channel and set initial volume.  Initially paused.\r
+                        FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
 #if TRACE_SOUND\r
                     Logger.Log(\r
                         String.Format("Channel {0} for {1} assigned to {2}",\r
@@ -269,32 +247,35 @@ namespace Radegast.Media
                              Id),\r
                         Helpers.LogLevel.Debug);\r
 #endif\r
-                    lock (allChannels)\r
-                        allChannels[channel.getRaw()] = this;\r
+                        RegisterChannel(channel);\r
 \r
-                    FMODExec(channel.setVolume(volumeSetting * AllObjectVolume));\r
+                        FMODExec(channel.setVolume(volumeSetting * AllObjectVolume));\r
 \r
-                    // Take note of when the sound is finished playing.\r
-                    FMODExec(channel.setCallback(endCallback));\r
+                        // Take note of when the sound is finished playing.\r
+                        FMODExec(channel.setCallback(endCallback));\r
 \r
-                    // Set attenuation limits.\r
-                    FMODExec(sound.set3DMinMaxDistance(\r
-                                1.2f,       // Any closer than this gets no louder\r
-                                100.0f));     // Further than this gets no softer.\r
+                        // Set attenuation limits.\r
+                        FMODExec(sound.set3DMinMaxDistance(\r
+                                    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 SIM coordinates.\r
-                    FMODExec(channel.set3DAttributes(ref position, ref ZeroVector));\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
-                    FMODExec(channel.setPaused(false));\r
-                }\r
-                catch (Exception ex)\r
-                {\r
-                    Logger.Log("Error starting sound: ", Helpers.LogLevel.Error, ex);\r
-                }\r
-            }));\r
-\r
-            return RESULT.OK;\r
+                        // Turn off pause mode.  The sound will start playing now.\r
+                        FMODExec(channel.setPaused(false));\r
+                    }\r
+                    catch (Exception ex)\r
+                    {\r
+                        Logger.Log("Error playing sound: ", Helpers.LogLevel.Error, ex);\r
+                    }\r
+                }));\r
+            }\r
+            else\r
+            {\r
+                Logger.Log("Failed to download sound: " + transfer.Status.ToString(),\r
+                                        Helpers.LogLevel.Error);\r
+            }\r
         }\r
 \r
         /// <summary>\r
index b4e1133..eae2aa6 100644 (file)
@@ -58,8 +58,6 @@ namespace Radegast.Media
             this.Instance = instance;
             manager = this;
 
-
-            loadCallback = new FMOD.SOUND_NONBLOCKCALLBACK(DispatchNonBlockCallback);
             endCallback = new FMOD.CHANNEL_CALLBACK(DispatchEndCallback);
             allBuffers = new Dictionary<UUID, BufferSound>();
 
index a1244a3..4a70e69 100644 (file)
@@ -69,7 +69,6 @@ namespace Radegast.Media
         // Additional info for callbacks goes here.
         protected FMOD.CREATESOUNDEXINFO extraInfo;
         protected static FMOD.CHANNEL_CALLBACK endCallback;
-        protected static FMOD.SOUND_NONBLOCKCALLBACK loadCallback;
 
         // Vectors used for orienting spatial axes.
         protected static FMOD.VECTOR UpVector;
@@ -259,27 +258,9 @@ namespace Radegast.Media
         /// <returns></returns>
 
         // Subclasses override these methods to handle callbacks.
-        protected virtual FMOD.RESULT NonBlockCallbackHandler( RESULT result ) { return RESULT.OK; }
         protected virtual FMOD.RESULT EndCallbackHandler() { return RESULT.OK; }
 
         /// <summary>
-        /// Main handler for sound-loading callback.
-        /// </summary>
-        /// <param name="soundraw"></param>
-        /// <param name="result"></param>
-        /// <returns></returns>
-        public RESULT DispatchNonBlockCallback(IntPtr soundraw, RESULT result)
-        {
-            if (allSounds.ContainsKey(soundraw))
-            {
-                MediaObject sndobj = allSounds[soundraw];
-                return sndobj.NonBlockCallbackHandler( result );
-            }
-
-            return FMOD.RESULT.OK;
-        }
-
-        /// <summary>
         /// Main handler for playback-end callback.
         /// </summary>
         /// <param name="channelraw"></param>
@@ -308,8 +289,6 @@ namespace Radegast.Media
             return RESULT.OK;
         }
 
-        public delegate RESULT SOUND_NONBLOCKCALLBACK(IntPtr soundraw, RESULT result);
-
         protected static void FMODExec(FMOD.RESULT result)
         {
             if (result != FMOD.RESULT.OK)
index 6c51390..4105411 100644 (file)
@@ -65,10 +65,10 @@ namespace Radegast.Media
         /// </summary>\r
         /// <param name="system">Sound system</param>\r
         public Speech()\r
-            :base()\r
-       {\r
-           extraInfo.format = SOUND_FORMAT.PCM16;\r
-       }\r
+            : base()\r
+        {\r
+            extraInfo.format = SOUND_FORMAT.PCM16;\r
+        }\r
 \r
 \r
         /// <summary>\r
@@ -94,7 +94,7 @@ namespace Radegast.Media
             filename = speakfile;\r
 \r
             // Set flags to determine how it will be played.\r
-            FMOD.MODE mode = FMOD.MODE.SOFTWARE | FMOD.MODE._3D | MODE.NONBLOCKING;\r
+            FMOD.MODE mode = FMOD.MODE.SOFTWARE | FMOD.MODE._3D;\r
 \r
             // Set coordinate space interpretation.\r
             if (global)\r
@@ -102,44 +102,20 @@ namespace Radegast.Media
             else\r
                 mode |= FMOD.MODE._3D_HEADRELATIVE;\r
 \r
-            extraInfo.nonblockcallback = loadCallback;\r
-\r
             invoke(new SoundDelegate(\r
-                delegate {\r
-                    FMODExec(\r
+                delegate\r
+                {\r
+                    try\r
+                    {\r
+                        FMODExec(\r
                         system.createSound(filename,\r
                         mode,\r
                         ref extraInfo,\r
                         ref sound));\r
 \r
-                    // Register for callbacks.\r
-                    RegisterSound(sound);\r
-                }));\r
-         }\r
+                        // Register for callbacks.\r
+                        RegisterSound(sound);\r
 \r
-        /// <summary>\r
-        /// Callback when a stream has been loaded\r
-        /// </summary>\r
-        /// <param name="instatus"></param>\r
-        /// <returns></returns>\r
-        protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
-        {\r
-            extraInfo.nonblockcallback = null;\r
-\r
-            if (instatus != RESULT.OK)\r
-            {\r
-                Logger.Log("FMOD error opening speech file " +\r
-                        filename +\r
-                        ": " + instatus,\r
-                    Helpers.LogLevel.Error);\r
-                return RESULT.OK;\r
-            }\r
-\r
-            invoke(new SoundDelegate(\r
-                delegate\r
-                {\r
-                    try\r
-                    {\r
                         // Allocate a channel, initially paused.\r
                         FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
 \r
@@ -175,7 +151,7 @@ namespace Radegast.Media
 \r
                         // SET a handler for when it finishes.\r
                         FMODExec(channel.setCallback(endCallback));\r
-                        RegisterChannel( channel );\r
+                        RegisterChannel(channel);\r
 \r
                         // Un-pause the sound.\r
                         FMODExec(channel.setPaused(false));\r
@@ -185,8 +161,6 @@ namespace Radegast.Media
                         Logger.Log("Error playing speech: ", Helpers.LogLevel.Error, ex);\r
                     }\r
                 }));\r
-\r
-            return RESULT.OK;\r
         }\r
 \r
         /// <summary>\r
@@ -219,5 +193,5 @@ namespace Radegast.Media
 \r
             return RESULT.OK;\r
         }\r
-   }\r
+    }\r
 }\r
index b468a99..469bba5 100644 (file)
@@ -125,41 +125,21 @@ namespace Radegast.Media
             // Stop old stream first.\r
             StopStream();\r
 \r
-            extraInfo.nonblockcallback = loadCallback;\r
             extraInfo.format = SOUND_FORMAT.PCM16;\r
 \r
             invoke(new SoundDelegate(\r
                 delegate\r
                 {\r
-                    FMODExec(\r
-                        system.createSound(url,\r
-                        (MODE.HARDWARE | MODE._2D | MODE.CREATESTREAM | MODE.NONBLOCKING),\r
-                        ref extraInfo,\r
-                        ref sound), "Stream load");\r
-                    // Register for callbacks.\r
-                    RegisterSound(sound);\r
-                }));\r
-        }\r
-\r
-        /// <summary>\r
-        /// Callback when a stream has been loaded\r
-        /// </summary>\r
-        /// <param name="instatus"></param>\r
-        /// <returns></returns>\r
-        protected override RESULT NonBlockCallbackHandler(RESULT instatus)\r
-        {\r
-            if (instatus != RESULT.OK)\r
-            {\r
-                Logger.Log("Error opening audio stream: " + instatus,\r
-                    Helpers.LogLevel.Debug);\r
-                return RESULT.OK;\r
-            }\r
-\r
-            invoke(new SoundDelegate(\r
-                delegate\r
-                {\r
                     try\r
                     {\r
+                        FMODExec(\r
+                            system.createSound(url,\r
+                            (MODE.HARDWARE | MODE._2D | MODE.CREATESTREAM),\r
+                            ref extraInfo,\r
+                            ref sound), "Stream load");\r
+                        // Register for callbacks.\r
+                        RegisterSound(sound);\r
+\r
                         // Allocate a channel and set initial volume.\r
                         FMODExec(system.playSound(\r
                             CHANNELINDEX.FREE,\r
@@ -184,11 +164,9 @@ namespace Radegast.Media
                         Logger.Log("Error playing stream: ", Helpers.LogLevel.Debug, ex);\r
                     }\r
                 }));\r
-\r
-            Logger.Log("Stream playing", Helpers.LogLevel.Info);\r
-            return RESULT.OK;\r
         }\r
 \r
+\r
 #if GET_STREAM_TAGS\r
         private void CheckTags(object sender)\r
         {\r