public static PlayingSound PlaySound3DToChannel(AudioEngine.SoundEffect sound, float x, float y, float z, SoundTrackChannel channel, WaitHandle waitHandle = null) { PlayingSound s = new PlayingSound(sound.CreateInstance(), channel, waitHandle); s.Instance.SetPosition(false, new Math.Vector3(x, y, z)); s.Play(); _playingSounds.Add(s); return(s); /*AudioSource source = getFreeSource(null); * if (source != null) * { * source.IsLooping * * Al.alSourcei(source, Al.AL_BUFFER, sound.Buffer); * Al.alSource3f(source, Al.AL_POSITION, x, y, z); * Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, Al.AL_FALSE); * Al.alSourcef(source, Al.AL_MAX_DISTANCE, sound.DefaultMaxDistance); * Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, sound.DefaultMinDistance); * Al.alSourcePlay(source); * * _channelSounds[channel].Add(source);// BUG: this should be adding this sound to a collection! * * return new PlayingSound(source, false); * } * * return new PlayingSound();*/ }
public static PlayingSound PlaySound2DToChannel(AudioEngine.SoundEffect sound, SoundTrackChannel channel, WaitHandle waitHandle = null) { PlayingSound s = new PlayingSound(sound.CreateInstance(), channel, waitHandle); s.Instance.SetPosition(true, Math.Vector3.Zero); s.Play(); _playingSounds.Add(s); return(s); }
public Resource.Resource Load(string filename, Resource.ResourceManager content) { if (filename.IndexOf('.') < 0) { filename += ".WAV"; } System.IO.Stream stream = FileSystem.Open(filename); AudioEngine.SoundEffect sound = new AudioEngine.SoundEffect(filename, stream); stream.Close(); return(sound); }
public SoundTrackSoundNode(Resource.InfoSection soundSection, Resource.ResourceManager content) { foreach (Resource.InfoLine line in soundSection.Lines) { // TODO: this code is messy and could be more efficient string sdummy; int idummy; float fdummy; if (line.TryGetAttribute("Name", out sdummy)) { _name = sdummy; } else if (line.TryGetIntAttribute("Volume", out idummy)) { _volume = idummy / 100.0f; } else if (line.TryGetIntAttribute("Repeat", out idummy)) { _repeat = idummy; } else if (line.TryGetIntAttribute("Random", out idummy)) { _random = idummy / 100.0f; } else if (line.TryGetIntAttribute("Loop", out idummy)) { _loop = idummy != 0; } else if (line.TryGetIntAttribute("FadeInMS", out idummy)) { _fadeIn = idummy; } else if (line.TryGetIntAttribute("FadeOutMS", out idummy)) { _fadeOut = idummy; } else if (line.TryGetIntAttribute("StopMethod", out idummy)) { _stopMethod = (SoundStopMethod)idummy; } else if (line.TryGetIntAttribute("3D", out idummy)) { _3d = idummy != 0; } else if (line.TryGetIntAttribute("MinDist", out idummy)) { _minDist = idummy; } else if (line.TryGetIntAttribute("MaxDist", out idummy)) { _maxDist = idummy; } else if (line.TryGetFloatAttribute("X", out fdummy)) { _x = fdummy; } else if (line.TryGetFloatAttribute("Y", out fdummy)) { _y = fdummy; } else if (line.TryGetFloatAttribute("Z", out fdummy)) { _z = fdummy; } else if (line.TryGetAttribute("Follow", out sdummy)) { _follow = sdummy; } } // load the sound if (string.IsNullOrEmpty(_name) == false) { // make sure it ends in ".wav" string fileToLoad = _name; if (fileToLoad.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) == false) { fileToLoad = fileToLoad + ".wav"; } try { _sound = content.Load <AudioEngine.SoundEffect>(fileToLoad); // _sound.DefaultMinDistance = _minDist; // _sound.DefaultMaxDistance = _maxDist; // _sound.DefaultVolume = _volume; } catch { // for some reason it seems like it's possible for requested sounds // not to exist! Console.CurrentConsole.WriteLine(ConsoleSeverity.Warning, "Unable to load sound referenced in STK: {0}", fileToLoad); } } if (_repeat > 0) { _repeatEnabled = true; } }