public GetSampleDuration ( int sizeInBytes ) : System.TimeSpan | ||
sizeInBytes | int | |
return | System.TimeSpan |
/// <summary> /// Plays the effect. /// </summary> /// <param name="asEffect">Set to false for music, true for sound effects.</param> public void Play(bool asEffect, AudioEffects effect = AudioEffects.None, float volume = 1.0f) { double now = UltimaGame.TotalMS; CullExpiredEffects(now); m_ThisInstance = GetNewInstance(asEffect); if (m_ThisInstance == null) { this.Dispose(); return; } switch (effect) { case AudioEffects.PitchVariation: float pitch = (float)Utility.RandomValue(-5, 5) * .025f; m_ThisInstance.Pitch = pitch; break; } BeforePlay(); byte[] buffer = GetBuffer(); if (buffer != null && buffer.Length > 0) { m_ThisInstance.BufferNeeded += new EventHandler<EventArgs>(OnBufferNeeded); m_ThisInstance.SubmitBuffer(buffer); m_ThisInstance.Volume = volume; m_ThisInstance.Play(); List<Tuple<DynamicSoundEffectInstance, double>> list = (asEffect) ? m_EffectInstances : m_MusicInstances; double ms = m_ThisInstance.GetSampleDuration(buffer.Length).TotalMilliseconds; list.Add(new Tuple<DynamicSoundEffectInstance, double>(m_ThisInstance, now + ms)); } }
public void Play() { float now = UltimaVars.EngineVars.TheTime; // Check to see if any existing instances of this sound effect have stopped playing. If // they have, remove the reference to them so the garbage collector can collect them. for (int i = 0; i < m_instances.Count; i++) if (m_instances[i].Item2 < now) { m_instances.RemoveAt(i); i--; } DynamicSoundEffectInstance instance = new DynamicSoundEffectInstance(22050, AudioChannels.Mono); instance.BufferNeeded += new EventHandler<EventArgs>(instance_BufferNeeded); instance.SubmitBuffer(m_waveBuffer); instance.Play(); m_instances.Add(new Tuple<DynamicSoundEffectInstance, float>(instance, now + (instance.GetSampleDuration(m_waveBuffer.Length).Milliseconds / 1000f))); }
/// <summary> /// Plays the effect. /// </summary> /// <param name="asEffect">Set to false for music, true for sound effects.</param> public void Play(bool asEffect = true) { double now = UltimaGame.TotalMS; CullExpiredEffects(now); m_ThisInstance = GetNewInstance(asEffect); if (m_ThisInstance == null) { this.Dispose(); return; } BeforePlay(); byte[] buffer = GetBuffer(); if (buffer != null && buffer.Length > 0) { m_ThisInstance.BufferNeeded += new EventHandler<EventArgs>(OnBufferNeeded); m_ThisInstance.SubmitBuffer(buffer); m_ThisInstance.Play(); List<Tuple<DynamicSoundEffectInstance, double>> list = (asEffect) ? m_EffectInstances : m_MusicInstances; list.Add(new Tuple<DynamicSoundEffectInstance, double>(m_ThisInstance, now + (m_ThisInstance.GetSampleDuration(buffer.Length).Milliseconds))); } }