From b5f3a01a5f99395351cccbe8959de6fdf5df96e5 Mon Sep 17 00:00:00 2001 From: Mojito Sorbet Date: Wed, 2 Jun 2010 15:46:34 +0000 Subject: [PATCH] Disable volume/position updates until we find why it gets Invalid Handle. 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 | 31 +++++++++++---- Radegast/Core/Media/MediaManager.cs | 12 +++--- Radegast/Core/Media/MediaObject.cs | 44 +++++++++++++++++----- Radegast/Core/Media/Speech.cs | 6 ++- .../RadSpeech/Conversation/Surroundings.cs | 10 +++-- .../RadSpeech/Environment/People.cs | 3 ++ 6 files changed, 78 insertions(+), 28 deletions(-) diff --git a/Radegast/Core/Media/BufferSound.cs b/Radegast/Core/Media/BufferSound.cs index 07bdcd2..0567842 100644 --- a/Radegast/Core/Media/BufferSound.cs +++ b/Radegast/Core/Media/BufferSound.cs @@ -42,6 +42,7 @@ namespace Radegast.Media public class BufferSound : MediaObject { private UUID Id; + private UUID ContainerId; private Boolean prefetchOnly = false; private FMOD.MODE mode; public Sound Sound { get { return sound; } } @@ -55,24 +56,25 @@ namespace Radegast.Media /// Creates a new sound object /// /// Sound system - public BufferSound( UUID soundId, bool loop, bool global, Vector3 worldpos, float vol ) + public BufferSound( UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol ) :base() { - InitBuffer(soundId, loop, global, worldpos, vol); + InitBuffer(objectId, soundId, loop, global, worldpos, vol); } - public BufferSound(UUID soundId, bool loop, bool global, Vector3d worldpos, float vol) + public BufferSound(UUID objectId, UUID soundId, bool loop, bool global, Vector3d worldpos, float vol) : base() { - InitBuffer(soundId, loop, global, new Vector3(worldpos), vol); + InitBuffer(objectId, soundId, loop, global, new Vector3(worldpos), vol); } - private void InitBuffer(UUID soundId, bool loop, bool global, Vector3 worldpos, float vol) + private void InitBuffer(UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol) { // Do not let this get garbage-collected. lock (allBuffers) - allBuffers[soundId] =this; + allBuffers[objectId] =this; + ContainerId = objectId; Id = soundId; position = FromOMVSpace(worldpos); volumeSetting = vol; @@ -158,6 +160,7 @@ namespace Radegast.Media allBuffers[soundId] = this; prefetchOnly = true; + ContainerId = UUID.Zero; Id = soundId; manager.Instance.Client.Assets.RequestAsset( @@ -244,6 +247,12 @@ namespace Radegast.Media // Allocate a channel and set initial volume. Initially paused. FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel)); + Logger.Log( + String.Format("Channel {0} for {1} assigned to {2}", + channel.getRaw().ToString("X"), + sound.getRaw().ToString("X"), + Id), + Helpers.LogLevel.Debug); FMODExec(channel.setVolume(volumeSetting * AllObjectVolume )); // Take note of when the sound is finished playing. @@ -293,10 +302,16 @@ namespace Radegast.Media protected void StopSound() { - Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug); + finished = true; invoke(new SoundDelegate(delegate { + Logger.Log( String.Format("Removing channel {0} sound {1} ID {2}", + channel.getRaw().ToString("X"), + sound.getRaw().ToString("X"), + Id.ToString()), + Helpers.LogLevel.Debug); + // Release the buffer to avoid a big memory leak. if (channel != null) { @@ -311,7 +326,7 @@ namespace Radegast.Media channel = null; lock (allBuffers) - allBuffers.Remove(Id); + allBuffers.Remove(ContainerId); })); } diff --git a/Radegast/Core/Media/MediaManager.cs b/Radegast/Core/Media/MediaManager.cs index e795545..b8cd1d8 100644 --- a/Radegast/Core/Media/MediaManager.cs +++ b/Radegast/Core/Media/MediaManager.cs @@ -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, diff --git a/Radegast/Core/Media/MediaObject.cs b/Radegast/Core/Media/MediaObject.cs index 070ff72..00389e5 100644 --- a/Radegast/Core/Media/MediaObject.cs +++ b/Radegast/Core/Media/MediaObject.cs @@ -45,7 +45,8 @@ namespace Radegast.Media /// 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); } } /// - /// 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. /// /// 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 } } diff --git a/Radegast/Core/Media/Speech.cs b/Radegast/Core/Media/Speech.cs index 6cbbb1b..4752744 100644 --- a/Radegast/Core/Media/Speech.cs +++ b/Radegast/Core/Media/Speech.cs @@ -158,8 +158,6 @@ namespace Radegast.Media // Un-pause the sound. FMODExec(channel.setPaused(false)); - -// system.update(); } catch (Exception ex) { @@ -170,6 +168,10 @@ namespace Radegast.Media return RESULT.OK; } + /// + /// Handler for reaching the end of playback of a speech. + /// + /// protected override RESULT EndCallbackHandler() { invoke(new SoundDelegate( diff --git a/plugins/Radegast.Plugin.Speech/RadSpeech/Conversation/Surroundings.cs b/plugins/Radegast.Plugin.Speech/RadSpeech/Conversation/Surroundings.cs index e7ada3e..f37225c 100644 --- a/plugins/Radegast.Plugin.Speech/RadSpeech/Conversation/Surroundings.cs +++ b/plugins/Radegast.Plugin.Speech/RadSpeech/Conversation/Surroundings.cs @@ -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 ) ); } diff --git a/plugins/Radegast.Plugin.Speech/RadSpeech/Environment/People.cs b/plugins/Radegast.Plugin.Speech/RadSpeech/Environment/People.cs index 4aaf7e3..2c0cc76 100644 --- a/plugins/Radegast.Plugin.Speech/RadSpeech/Environment/People.cs +++ b/plugins/Radegast.Plugin.Speech/RadSpeech/Environment/People.cs @@ -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; } -- 2.11.0