OpenBve.Sounds.Initialize C# (CSharp) Method

Initialize() static private method

Initializes audio. A call to Deinitialize must be made when terminating the program.
static private Initialize ( ) : bool
return bool
		internal static bool Initialize() {
			Deinitialize();
			switch (Interface.CurrentOptions.SoundRange) {
				case Interface.SoundRange.Low:
					OuterRadiusFactorMinimum = 2.0;
					OuterRadiusFactorMaximum = 8.0;
					OuterRadiusFactorMaximumSpeed = 1.0;
					break;
				case Interface.SoundRange.Medium:
					OuterRadiusFactorMinimum = 4.0;
					OuterRadiusFactorMaximum = 16.0;
					OuterRadiusFactorMaximumSpeed = 2.0;
					break;
				case Interface.SoundRange.High:
					OuterRadiusFactorMinimum = 6.0;
					OuterRadiusFactorMaximum = 24.0;
					OuterRadiusFactorMaximumSpeed = 3.0;
					break;
			}
			OuterRadiusFactor = Math.Sqrt(OuterRadiusFactorMinimum * OuterRadiusFactorMaximum);
			OuterRadiusFactorSpeed = 0.0;
			OpenAlDevice = Alc.OpenDevice(null);
			if (OpenAlDevice != IntPtr.Zero)
			{
                OpenAlContext = Alc.CreateContext(OpenAlDevice, (int[])null);
				if (OpenAlContext != ContextHandle.Zero) {
					Alc.MakeContextCurrent(OpenAlContext);
					try {
						AL.SpeedOfSound(343.0f);
					} catch {
                        MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_version"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
					}
					AL.DistanceModel(ALDistanceModel.None);
					return true;
				}
			    Alc.CloseDevice(OpenAlDevice);
			    OpenAlDevice = IntPtr.Zero;
                MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_context"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
			    return false;
			}
		    OpenAlContext = ContextHandle.Zero;
            MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_device"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
		    return false;
		}
		

Usage Example

Beispiel #1
0
        /// <summary>Initializes the program. A matching call to deinitialize must be made when the program is terminated.</summary>
        /// <returns>Whether the initialization was successful.</returns>
        private static bool Initialize()
        {
            if (!Plugins.LoadPlugins())
            {
                return(false);
            }
            if (!Screen.Initialize())
            {
                MessageBox.Show("SDL failed to initialize the video subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
            if (!Joysticks.Initialize())
            {
                MessageBox.Show("SDL failed to initialize the joystick subsystem.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
            Sounds.Initialize();
            // begin HACK //
            const double degrees = 0.0174532925199433;

            World.VerticalViewingAngle         = 45.0 * degrees;
            World.HorizontalViewingAngle       = 2.0 * Math.Atan(Math.Tan(0.5 * World.VerticalViewingAngle) * World.AspectRatio);
            World.OriginalVerticalViewingAngle = World.VerticalViewingAngle;
            World.ExtraViewingDistance         = 50.0;
            World.ForwardViewingDistance       = (double)Interface.CurrentOptions.ViewingDistance;
            World.BackwardViewingDistance      = 0.0;
            World.BackgroundImageDistance      = (double)Interface.CurrentOptions.ViewingDistance;
            // end HACK //
            ClearLogFile();
            return(true);
        }
All Usage Examples Of OpenBve.Sounds::Initialize