Example #1
0
		void PlaySound(IAudioOutput output, float volume) {
			try {
				output.Initalise(chunk);
				//uint newSrc = output.GetSource();
				//output.SetSource(newSrc);
				output.SetVolume(volume);
				
				/*LocalPlayer player = game.LocalPlayer;
				
				Vector3 camPos = game.CurrentCameraPos;
				Vector3 eyePos = game.LocalPlayer.EyePosition;
				Vector3 oneY = Vector3.UnitY;
				
				Vector3 lookPos;
				//lookPos.X = (float)(Math.Cos(player.HeadX) * Math.Sin(player.HeadY));
				//lookPos.Y = (float)(-Math.Sin(player.HeadX));
				//lookPos.Z = (float)(Math.Cos(player.HeadY) * Math.Cos(player.HeadX));
				lookPos.X = game.Graphics.View.Row1.X;
				lookPos.Y = game.Graphics.View.Row1.Y;
				lookPos.Z = game.Graphics.View.Row1.Z;
				lookPos = Vector3.Normalize(lookPos);
				
				Vector3 upPos;
				upPos.X = game.Graphics.View.Row2.X;
				upPos.Y = game.Graphics.View.Row2.Y;
				upPos.Z = game.Graphics.View.Row2.Z;
				upPos = Vector3.Normalize(upPos);*/
				
				Vector3 pos = game.LocalPlayer.EyePosition;
				Vector3 feetPos = game.LocalPlayer.Position;
				Vector3 vel = game.LocalPlayer.Velocity;
				float yaw = game.LocalPlayer.HeadY;
				output.SetSoundGain(0f);
				output.SetSoundRefDist(0.5f);
				output.SetSoundMaxDist(1000f);
				output.SetListenerPos(0, 0, 0);
				//output.SetListenerPos(pos.X, pos.Y, pos.Z);
				//output.SetListenerVel(vel.X, vel.Y, vel.Z);
				//output.SetListenerDir(yaw);
				//output.SetSoundPos(feetPos.X, feetPos.Y, feetPos.Z);
				if (!output.IsPosSet()) {
				//	output.SetSoundPos(feetPos.X, feetPos.Y, feetPos.Z);
				//	output.SetSoundVel(0, 0, 0);
				}
				output.SetSoundPos(0, 0, 0);
				//output.SetSoundRelative(true);
				
				output.PlayRawAsync(chunk);
			} catch (InvalidOperationException ex) {
				ErrorHandler.LogError("AudioPlayer.PlayCurrentSound()", ex);
				if (ex.Message == "No audio devices found")
					game.Chat.Add("&cNo audio devices found, disabling sounds.");
				else
					game.Chat.Add("&cAn error occured when trying to play sounds, disabling sounds.");
				
				SetSounds(0);
				game.SoundsVolume = 0;
			}
		}