public SoundChannel(SoundResource soundResource, IChannelGlue channel) { CurrentSoundResource = soundResource; if (channel != null) { InitiateChannelGlue(channel); } else { state = PlayState.NotReady; } SoundManager.Instance.RegisterChannel(this); }
//public Vector2 _3DMinMaxDistance //{ // get { return minMaxDistance; } // set { minMaxDistance = value; if (SoundGlue != null) SoundGlue._3DMinMaxDistance = new Vector2(value.X, value.Y); } //} //private Vector2 minMaxDistance; private SoundChannel PlayAnySound(PlayArgs args) { IChannelGlue channelGlue = SoundManager.Instance.SystemGlue.PlaySound(SoundGlue, true, args.Looping); var soundChannel = new SoundChannel(this, channelGlue) { Paused = true, WantsToPlaySound = SoundGlue, WantsToPlaySoundArgs = args }; // TODO: add args stuff if (Is3DSound) { soundChannel._3DPanLevel = SoundManager.Instance._3DPanLevel; //soundChannel._3DSpread = SoundManager.Instance._3DSpread; } return(soundChannel); }
private void InitiateChannelGlue(IChannelGlue channel) { SoundResource soundResource = (SoundResource)CurrentSoundResource; ChannelGlue = channel; channel.SoundEnds += new EventHandler(channel_SoundEnds); channel.GoesVirtual += new EventHandler(channel_GoesVirtual); channel.LeavesVirtual += new EventHandler(channel_LeavesVirtual); baseFrequency = channel.Frequency; if (soundResource.Is3DSound) { channel._3DPanLevel = panLevel; } // Fetch correct variables values volume = channel.Volume; //if (soundResource.Is3DSound) // minMaxDistance = channel._3DMinMaxDistance; }
private void InitiateChannelGlue(IChannelGlue channel) { SoundResource soundResource = (SoundResource)CurrentSoundResource; ChannelGlue = channel; channel.SoundEnds += new EventHandler(channel_SoundEnds); channel.GoesVirtual += new EventHandler(channel_GoesVirtual); channel.LeavesVirtual += new EventHandler(channel_LeavesVirtual); baseFrequency = channel.Frequency; if (soundResource.Is3DSound) channel._3DPanLevel = panLevel; // Fetch correct variables values volume = channel.Volume; //if (soundResource.Is3DSound) // minMaxDistance = channel._3DMinMaxDistance; }
public SoundChannel(SoundResource soundResource, IChannelGlue channel) { CurrentSoundResource = soundResource; if (channel != null) InitiateChannelGlue(channel); else state = PlayState.NotReady; SoundManager.Instance.RegisterChannel(this); }
public void Update(float dtime) { switch (state) { case PlayState.FadingIn: fadeInTimeLeft -= dtime; ChannelGlue.Volume = FadedVolume; if (fadeInTimeLeft <= 0) { state = PlayState.Playing; } break; case PlayState.FadingOut: fadeTimeLeft -= dtime; if (fadeTimeLeft <= 0) { Stop(); } else { ChannelGlue.Volume = FadedVolume; } break; case PlayState.NotReady: sb.AppendLine("NotReady update"); // NOTE: If things are done right you shouldn't end up here with fade-in time > 0 (except for maybe // when you first launch the program) //if (WantsToPlaySoundArgs.FadeInTime > 0) // throw new NotImplementedException( // Please update ticket #1467 // String.Format("This is untested. Tried to fade in \"{0}\", but the stream was not ready yet. Please update ticket #1467 with current stack trace and setting information on where you received this error.", // CurrentSoundResource.Name)); IChannelGlue channelGlue = SoundManager.Instance.SystemGlue.PlaySound(WantsToPlaySound, true, WantsToPlaySoundArgs.Looping); if (channelGlue == null) // still not ready { return; } sb.AppendLine("Playback started"); #if DEBUG_ASYNC_SOUND System.IO.File.WriteAllText("soundteststuff.txt", sb.ToString()); #endif state = PlayState.Playing; InitiateChannelGlue(channelGlue); // execute queued commands foreach (var f in queuedCommands) { f.Invoke(); } break; case PlayState.Stopped: SoundManager.Instance.DeregisterChannel(this); break; } if (GetObjectPosition != null && GetObjectVelocity != null) { ChannelGlue.Set3DAttributes(GetObjectPosition.Invoke(), GetObjectVelocity.Invoke()); } }