public static void Kill(UUID id) { if (allBuffers.ContainsKey(id)) { BufferSound bs = allBuffers[id]; bs.StopSound(true); } }
/// <summary> /// Common object sound processing for various Update events /// </summary> /// <param name="p"></param> /// <param name="s"></param> private void HandleObjectSound(Primitive p, Simulator s) { // Objects without sounds are not interesting. if (p.Sound == UUID.Zero) { return; } if ((p.SoundFlags & SoundFlags.Stop) == SoundFlags.Stop) { BufferSound.Kill(p.ID); return; } // If this is a child prim, its position is relative to the root prim. Vector3 fullPosition = p.Position; if (p.ParentID != 0) { Primitive parentP; if (!s.ObjectsPrimitives.TryGetValue(p.ParentID, out parentP)) { return; } fullPosition += parentP.Position; } // See if this is an update to something we already know about. if (allBuffers.ContainsKey(p.ID)) { // Exists already, so modify existing sound. BufferSound snd = allBuffers[p.ID]; snd.Volume = p.SoundGain * ObjectVolume; snd.Position = fullPosition; } else { // Does not exist, so create a new one. new BufferSound( p.ID, p.Sound, (p.SoundFlags & SoundFlags.Loop) == SoundFlags.Loop, true, fullPosition, //Instance.State.GlobalPosition(e.Simulator, fullPosition), p.SoundGain * ObjectVolume); } }
/// <summary> /// Handle deletion of a noise-making object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Objects_KillObject(object sender, KillObjectEventArgs e) { Primitive p = null; if (!e.Simulator.ObjectsPrimitives.TryGetValue(e.ObjectLocalID, out p)) { return; } // Objects without sounds are not interesting. if (p.Sound == UUID.Zero) { return; } BufferSound.Kill(p.ID); }
/// <summary> /// Watch for Teleports to cancel all the old sounds /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Network_SimChanged(object sender, SimChangedEventArgs e) { BufferSound.KillAll(); }
/// <summary> /// Handle sound attached to an object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Sound_AttachedSound(object sender, AttachedSoundEventArgs e) { // This event tells us the Object ID, but not the Prim info directly. // So we look it up in our internal Object memory. Simulator sim = e.Simulator; Primitive p = sim.ObjectsPrimitives.Find((Primitive p2) => { return(p2.ID == e.ObjectID); }); if (p == null) { return; } // Only one attached sound per prim, so we kill any previous BufferSound.Kill(p.ID); // If this is stop sound, we're done since we've already killed sound for this object if ((e.Flags & SoundFlags.Stop) == SoundFlags.Stop) { return; } // We seem to get a lot of these zero sounds. if (e.SoundID == UUID.Zero) { return; } // If this is a child prim, its position is relative to the root. Vector3 fullPosition = p.Position; while (p != null && p.ParentID != 0) { Avatar av; if (sim.ObjectsAvatars.TryGetValue(p.ParentID, out av)) { p = av; fullPosition += p.Position; } else { if (sim.ObjectsPrimitives.TryGetValue(p.ParentID, out p)) { fullPosition += p.Position; } } } // Didn't find root prim if (p == null) { return; } new BufferSound( e.ObjectID, e.SoundID, (e.Flags & SoundFlags.Loop) == SoundFlags.Loop, true, fullPosition, e.Gain * ObjectVolume); }