public class BufferSound : MediaObject\r
{\r
private UUID Id;\r
+ private UUID ContainerId;\r
private Boolean prefetchOnly = false;\r
private FMOD.MODE mode;\r
public Sound Sound { get { return sound; } }\r
/// Creates a new sound object\r
/// </summary>\r
/// <param name="system">Sound system</param>\r
- public BufferSound( UUID soundId, bool loop, bool global, Vector3 worldpos, float vol )\r
+ public BufferSound( UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol )\r
:base()\r
{\r
- InitBuffer(soundId, loop, global, worldpos, vol);\r
+ InitBuffer(objectId, soundId, loop, global, worldpos, vol);\r
}\r
\r
- public BufferSound(UUID soundId, bool loop, bool global, Vector3d worldpos, float vol)\r
+ public BufferSound(UUID objectId, UUID soundId, bool loop, bool global, Vector3d worldpos, float vol)\r
: base()\r
{\r
- InitBuffer(soundId, loop, global, new Vector3(worldpos), vol);\r
+ InitBuffer(objectId, soundId, loop, global, new Vector3(worldpos), vol);\r
}\r
\r
- private void InitBuffer(UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)\r
+ private void InitBuffer(UUID objectId, UUID soundId, bool loop, bool global, Vector3 worldpos, float vol)\r
{\r
// Do not let this get garbage-collected.\r
lock (allBuffers)\r
- allBuffers[soundId] =this;\r
+ allBuffers[objectId] =this;\r
\r
+ ContainerId = objectId;\r
Id = soundId;\r
position = FromOMVSpace(worldpos);\r
volumeSetting = vol;\r
allBuffers[soundId] = this;\r
\r
prefetchOnly = true;\r
+ ContainerId = UUID.Zero;\r
Id = soundId;\r
\r
manager.Instance.Client.Assets.RequestAsset(\r
\r
// Allocate a channel and set initial volume. Initially paused.\r
FMODExec(system.playSound(CHANNELINDEX.FREE, sound, true, ref channel));\r
+ Logger.Log(\r
+ String.Format("Channel {0} for {1} assigned to {2}",\r
+ channel.getRaw().ToString("X"),\r
+ sound.getRaw().ToString("X"),\r
+ Id),\r
+ Helpers.LogLevel.Debug);\r
FMODExec(channel.setVolume(volumeSetting * AllObjectVolume ));\r
\r
// Take note of when the sound is finished playing.\r
\r
protected void StopSound()\r
{\r
- Logger.Log("Removing sound " + Id.ToString(), Helpers.LogLevel.Debug);\r
+ finished = true;\r
\r
invoke(new SoundDelegate(delegate\r
{\r
+ Logger.Log( String.Format("Removing channel {0} sound {1} ID {2}",\r
+ channel.getRaw().ToString("X"),\r
+ sound.getRaw().ToString("X"),\r
+ Id.ToString()),\r
+ Helpers.LogLevel.Debug);\r
+\r
// Release the buffer to avoid a big memory leak.\r
if (channel != null)\r
{\r
channel = null;\r
\r
lock (allBuffers)\r
- allBuffers.Remove(Id);\r
+ allBuffers.Remove(ContainerId);\r
}));\r
\r
}\r
}
catch (Exception e)
{
-
Logger.Log("Error in sound action:\n " + e.Message + "\n" + e.StackTrace,
Helpers.LogLevel.Error);
}
// 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
Helpers.LogLevel.Debug);
new BufferSound(
+ e.ObjectID,
e.SoundID,
false,
true,
}
new BufferSound(
+ e.ObjectID,
e.SoundID,
(e.Flags & SoundFlags.Loop) == SoundFlags.Loop,
true,
if ((p.SoundFlags & SoundFlags.Stop) == SoundFlags.Stop)
{
- BufferSound.Kill(p.Sound);
+ BufferSound.Kill(p.ID);
return;
}
}
// 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;
}
{
// Does not exist, so create a new one.
new BufferSound(
+ p.ID,
p.Sound,
(p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop,
true,
/// </summary>
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();
public bool Active { get { return (sound != null); } }
/// <summary>
- /// 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.
/// </summary>
/// <param name="action"></param>
protected void invoke(SoundDelegate action)
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
}
}
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
}
}
\r
// Un-pause the sound.\r
FMODExec(channel.setPaused(false));\r
-\r
-// system.update();\r
}\r
catch (Exception ex)\r
{\r
return RESULT.OK;\r
}\r
\r
+ /// <summary>\r
+ /// Handler for reaching the end of playback of a speech.\r
+ /// </summary>\r
+ /// <returns></returns>\r
protected override RESULT EndCallbackHandler()\r
{\r
invoke(new SoundDelegate(\r
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,";
description += " is touchable";
}
- Talker.SayMore(description,
+ Talker.SayObject(
+ currentPrim.Properties.Name,
+ description,
control.env.people.SameDirection( currentPrim.Position ) );
}
Vector3 pointer = Vector3.Multiply(
Vector3.Normalize( difference ), 4.0f );
+ // Add my position back
+ pointer += my.SimPosition;
+
return pointer;
}