From 0f6b92f5c352c1b4a0bf6e6a79911be202fdcae0 Mon Sep 17 00:00:00 2001 From: Mojito Sorbet Date: Sat, 29 May 2010 16:17:50 +0000 Subject: [PATCH] Looped sounds appear to be working. Entering a new sim now kills all sounds. git-svn-id: https://radegast.googlecode.com/svn/branches/sounds@656 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/Core/Media/BufferSound.cs | 29 ++++++++++++++++++++++++----- Radegast/Core/Media/MediaManager.cs | 20 +++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Radegast/Core/Media/BufferSound.cs b/Radegast/Core/Media/BufferSound.cs index ec1a010..00e55a5 100644 --- a/Radegast/Core/Media/BufferSound.cs +++ b/Radegast/Core/Media/BufferSound.cs @@ -103,6 +103,21 @@ namespace Radegast.Media } } + /// + /// Stop all playing sounds in the environment + /// + public static void KillAll() + { + // Make a list from the dictionary so we do not get a deadlock + // on it when removing entries. + List list = new List(allBuffers.Values); + + foreach (BufferSound s in list) + { + s.StopSound(); + } + } + // A simpler constructor used by PreFetchSound. public BufferSound( UUID soundId ) : base() @@ -165,9 +180,6 @@ namespace Radegast.Media // Register for callbacks. RegisterSound(sound); - - if (loopSound) - FMODExec(sound.setLoopCount(-1)); })); } else @@ -189,9 +201,16 @@ namespace Radegast.Media { try { + // If looping is requested, loop the entire thing. + if (loopSound) + { + uint soundlen = 0; + FMODExec(sound.getLength(ref soundlen, TIMEUNIT.PCM)); + FMODExec( sound.setLoopPoints( 0, TIMEUNIT.PCM, soundlen-1, TIMEUNIT.PCM )); + FMODExec(sound.setLoopCount(-1)); + } + // Allocate a channel and set initial volume. Initially paused. - uint soundlen = 0; - FMODExec(sound.getLength(ref soundlen, TIMEUNIT.MS)); FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel)); FMODExec(channel.setVolume(volume)); diff --git a/Radegast/Core/Media/MediaManager.cs b/Radegast/Core/Media/MediaManager.cs index 9c0fbf1..013ef20 100644 --- a/Radegast/Core/Media/MediaManager.cs +++ b/Radegast/Core/Media/MediaManager.cs @@ -74,18 +74,23 @@ namespace Radegast.Media listenerThread.Start(); // Subscribe to events about inworld sounds - instance.Client.Objects.ObjectPropertiesUpdated +=new EventHandler(Objects_ObjectPropertiesUpdated); 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); } + /// + /// Thread that processes FMOD calls. + /// private void CommandLoop() { SoundDelegate action = null; + // Initialze a bunch of static values UpVector.x = 0.0f; UpVector.y = 1.0f; UpVector.z = 0.0f; @@ -96,6 +101,7 @@ namespace Radegast.Media allSounds = new Dictionary(); allChannels = new Dictionary(); + // Initialize the FMOD sound package InitFMOD(); if (!this.soundSystemAvailable) return; @@ -464,6 +470,18 @@ namespace Radegast.Media fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition), p.SoundGain); } + + /// + /// Watch for Teleports to cancel all the old sounds + /// + /// + /// + void Network_SimChanged(object sender, SimChangedEventArgs e) + { + BufferSound.KillAll(); + } + + } public class MediaException : Exception -- 2.11.0