Exemple #1
0
        // --- initialization and deinitialization ---

        /// <summary>Initializes audio. A call to Deinitialize must be made when terminating the program.</summary>
        /// <returns>Whether initializing audio was successful.</returns>
        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.alcOpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.alcCreateContext(OpenAlDevice, IntPtr.Zero);
                if (OpenAlContext != IntPtr.Zero)
                {
                    Alc.alcMakeContextCurrent(OpenAlContext);
                    try {
                        Al.alSpeedOfSound(343.0f);
                    } catch {
                        MessageBox.Show("OpenAL 1.1 is required. You seem to have OpenAL 1.0.", "openBVE", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    Al.alDistanceModel(Al.AL_NONE);
                    return(true);
                }
                else
                {
                    Alc.alcCloseDevice(OpenAlDevice);
                    OpenAlDevice = IntPtr.Zero;
                    MessageBox.Show("The OpenAL context could not be created.", "openBVE", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return(false);
                }
            }
            else
            {
                OpenAlContext = IntPtr.Zero;
                MessageBox.Show("The OpenAL sound device could not be opened.", "openBVE", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return(false);
            }
        }
Exemple #2
0
 // deinitialize
 internal static void Deinitialize()
 {
     if (OpenAlContext != IntPtr.Zero)
     {
         SoundManager.StopAllSounds(true);
         SoundManager.UnuseAllSoundsBuffers();
         Alc.alcMakeContextCurrent(IntPtr.Zero);
         Alc.alcDestroyContext(OpenAlContext);
         OpenAlContext = IntPtr.Zero;
     }
     if (OpenAlDevice != IntPtr.Zero)
     {
         Alc.alcCloseDevice(OpenAlDevice);
         OpenAlDevice = IntPtr.Zero;
     }
 }
Exemple #3
0
 /// <summary>Deinitializes audio.</summary>
 internal static void Deinitialize()
 {
     StopAllSounds();
     UnloadAllBuffers();
     if (OpenAlContext != IntPtr.Zero)
     {
         Alc.alcMakeContextCurrent(IntPtr.Zero);
         Alc.alcDestroyContext(OpenAlContext);
         OpenAlContext = IntPtr.Zero;
     }
     if (OpenAlDevice != IntPtr.Zero)
     {
         Alc.alcCloseDevice(OpenAlDevice);
         OpenAlDevice = IntPtr.Zero;
     }
 }
Exemple #4
0
        // initialize
        internal static void Initialize()
        {
            // openal
            OpenAlDevice = Alc.alcOpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.alcCreateContext(OpenAlDevice, IntPtr.Zero);
                if (OpenAlContext != IntPtr.Zero)
                {
                    Alc.alcMakeContextCurrent(OpenAlContext);
                    Al.alSpeedOfSound(343.0f);
                    Al.alDistanceModel(Al.AL_NONE);
                }
                else
                {
                    Alc.alcCloseDevice(OpenAlDevice);
                    OpenAlDevice = IntPtr.Zero;
                    System.Windows.Forms.MessageBox.Show("The sound device could be opened, but the sound context could not be created.", "openBVE", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
            }
            else
            {
                OpenAlContext = IntPtr.Zero;
                System.Windows.Forms.MessageBox.Show("The sound device could not be opened.", "openBVE", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            // outer radius
            switch (Interface.CurrentOptions.SoundRange)
            {
            case Interface.SoundRange.Low:
                OuterRadiusFactorMinimum = 2.0;
                OuterRadiusFactorMaximum = 8.0;
                break;

            case Interface.SoundRange.Medium:
                OuterRadiusFactorMinimum = 4.0;
                OuterRadiusFactorMaximum = 16.0;
                break;

            case Interface.SoundRange.High:
                OuterRadiusFactorMinimum = 8.0;
                OuterRadiusFactorMaximum = 32.0;
                break;
            }
            OuterRadiusFactor = OuterRadiusFactorMaximum;
        }
Exemple #5
0
        protected override void ShutdownLibrary()
        {
            if (thread != null)
            {
                needAbortThread = true;
                Thread.Sleep(50);
                thread.Abort();
            }

            if (realChannels != null)
            {
                foreach (OpenALRealChannel realChannel in realChannels)
                {
                    if (realChannel.alSource != 0)
                    {
                        Al.alDeleteSources(1, ref realChannel.alSource);
                        realChannel.alSource = 0;
                    }
                }
            }

            try
            {
                Alc.alcMakeContextCurrent(IntPtr.Zero);
                Alc.alcDestroyContext(alContext);
                Alc.alcCloseDevice(alDevice);
            }
            catch { }

            if (realChannels != null)
            {
                realChannels.Clear();
                realChannels = null;
            }

            if (criticalSection != null)
            {
                criticalSection.Dispose();
                criticalSection = null;
            }

            instance = null;
        }