volumeSetting = vol;\r
loopSound = loop;\r
\r
+ Logger.Log(\r
+ String.Format(\r
+ "Playing sound at <{0:0.0},{1:0.0},{2:0.0}> ID {3}",\r
+ position.x,\r
+ position.y,\r
+ position.z,\r
+ Id.ToString()),\r
+ Helpers.LogLevel.Debug);\r
+\r
// 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
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 GLOBAL coordinates.\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
{\r
Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug);\r
\r
- // Release the buffer to avoid a big memory leak.\r
- if (channel != null)\r
+ invoke(new SoundDelegate(delegate\r
{\r
- channel.stop();\r
+ // Release the buffer to avoid a big memory leak.\r
+ if (channel != null)\r
+ {\r
+ channel.stop();\r
+ channel = null;\r
+ }\r
+ if (sound != null)\r
+ {\r
+ sound.release();\r
+ sound = null;\r
+ }\r
channel = null;\r
- }\r
- if (sound != null)\r
- {\r
- sound.release();\r
- sound = null;\r
- }\r
- channel = null;\r
\r
- lock (allBuffers)\r
- allBuffers.Remove(Id);\r
+ lock (allBuffers)\r
+ allBuffers.Remove(Id);\r
+ }));\r
+\r
}\r
\r
}\r
forward.y = 0.0f;
forward.z = (float)Math.Cos(angle); // East
- int facing = (int)(angle * 180.0 / 3.141592);
- Logger.Log("Facing "+facing.ToString(), Helpers.LogLevel.Debug);
+ Logger.Log(
+ String.Format(
+ "Standing at <{0:0.0},{1:0.0},{2:0.0}> facing {3:d}",
+ listenerpos.x,
+ listenerpos.y,
+ listenerpos.z,
+ (int)(angle * 180.0 / 3.141592)),
+ Helpers.LogLevel.Debug);
// Tell FMOD the new orientation.
invoke( new SoundDelegate( delegate
fullPosition += parentP.Position;
}
- Logger.Log("Attached sound " + e.SoundID.ToString(),
- Helpers.LogLevel.Debug);
-
new BufferSound(
e.SoundID,
(e.Flags & SoundFlags.Loop) == SoundFlags.Loop,
{
if (e.SoundID == UUID.Zero) return;
- Logger.Log("Prefetch sound " + e.SoundID.ToString() +
- " in object " + e.ObjectID.ToString(),
- Helpers.LogLevel.Debug);
-
new BufferSound( e.SoundID );
}
}
/// <summary>
- /// Command object sound processing for various Update events
+ /// Common object sound processing for various Update events
/// </summary>
/// <param name="p"></param>
/// <param name="s"></param>
return;
}
- Logger.Log("Object sound " + p.Sound.ToString() +
- " in object " + p.ID.ToString(),
- Helpers.LogLevel.Debug);
-
// If this is a child prim, its position is relative to the root prim.
Vector3 fullPosition = p.Position;
if (p.ParentID != 0)
fullPosition += parentP.Position;
}
- // Create a sound object for this.
- new BufferSound(
- p.Sound,
- (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
- true,
- fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition),
- p.SoundGain * ObjectVolume);
+ // See if this is an update to something we already know about.
+ if (allBuffers.ContainsKey(p.Sound))
+ {
+ // Exists already, so modify existing sound.
+ //TODO posible to change sound on the same object. Key by Object?
+ BufferSound snd = allBuffers[p.Sound];
+ snd.Volume = p.SoundGain * ObjectVolume;
+ snd.Position = fullPosition;
+ }
+ else
+ {
+ // Does not exist, so create a new one.
+ new BufferSound(
+ p.Sound,
+ (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
+ true,
+ fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition),
+ p.SoundGain * ObjectVolume);
+ }
}
/// <summary>
{
set
{
- if (value)
+ try
{
- // Subscribe to events about inworld sounds
- Instance.Client.Sound.SoundTrigger += new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
- Instance.Client.Sound.AttachedSound += new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
- Instance.Client.Sound.PreloadSound += new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
- Instance.Client.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
- Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
- Instance.Client.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
- Instance.Client.Network.SimChanged += new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+ if (value)
+ {
+ // Subscribe to events about inworld sounds
+ Instance.Client.Sound.SoundTrigger += new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
+ Instance.Client.Sound.AttachedSound += new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
+ Instance.Client.Sound.PreloadSound += new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
+ Instance.Client.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
+ Instance.Client.Objects.ObjectPropertiesUpdated += new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
+ Instance.Client.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
+ Instance.Client.Network.SimChanged += new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+ Logger.Log("Inworld sound enabled", Helpers.LogLevel.Info);
+ }
+ else
+ {
+ // Subscribe to events about inworld sounds
+ Instance.Client.Sound.SoundTrigger -= new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
+ Instance.Client.Sound.AttachedSound -= new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
+ Instance.Client.Sound.PreloadSound -= new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
+ Instance.Client.Objects.ObjectUpdate -= new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
+ Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
+ Instance.Client.Objects.KillObject -= new EventHandler<KillObjectEventArgs>(Objects_KillObject);
+ Instance.Client.Network.SimChanged -= new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+
+ // Stop all running sounds
+ BufferSound.KillAll();
+
+ Logger.Log("Inworld sound disabled", Helpers.LogLevel.Info);
+ }
}
- else
+ catch (Exception e)
{
- // Subscribe to events about inworld sounds
- Instance.Client.Sound.SoundTrigger -= new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
- Instance.Client.Sound.AttachedSound -= new EventHandler<AttachedSoundEventArgs>(Sound_AttachedSound);
- Instance.Client.Sound.PreloadSound -= new EventHandler<PreloadSoundEventArgs>(Sound_PreloadSound);
- Instance.Client.Objects.ObjectUpdate -= new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
- Instance.Client.Objects.ObjectPropertiesUpdated -= new EventHandler<ObjectPropertiesUpdatedEventArgs>(Objects_ObjectPropertiesUpdated);
- Instance.Client.Objects.KillObject -= new EventHandler<KillObjectEventArgs>(Objects_KillObject);
- Instance.Client.Network.SimChanged -= new EventHandler<SimChangedEventArgs>(Network_SimChanged);
-
- // Stop all running sounds
- BufferSound.KillAll();
+ System.Console.WriteLine("Error on enable/disable: "+e.Message);
}
+
m_objectEnabled = value;
}
get { return m_objectEnabled; }