コード例 #1
0
        private void _shutdownAudio()
        {
            foreach (var source in _audioSources.Values.ToArray())
            {
                if (source.TryGetTarget(out var target))
                {
                    target.Dispose();
                }
            }

            foreach (var source in _bufferedAudioSources.Values.ToArray())
            {
                if (source.TryGetTarget(out var target))
                {
                    target.Dispose();
                }
            }

            if (_openALContext != ContextHandle.Zero)
            {
                Alc.DestroyContext(_openALContext);
            }

            if (_openALDevice != IntPtr.Zero)
            {
                Alc.CloseDevice(_openALDevice);
            }
        }
コード例 #2
0
        private void Dispose(bool manual)
        {
            if (!disposed)
            {
                if (this.IsCurrent)
                {
                    this.IsCurrent = false;
                }

                if (context_handle != ContextHandle.Zero)
                {
                    available_contexts.Remove(context_handle);
                    Alc.DestroyContext(context_handle);
                }

                if (Device != IntPtr.Zero)
                {
                    Alc.CloseDevice(Device);
                }

                if (manual)
                {
                }
                disposed = true;
            }
        }
コード例 #3
0
        protected void Dispose(bool bManagedDispose)
        {
            this.eOutputDevice = ESoundDeviceType.Unknown;                      // まず出力停止する(Dispose中にクラス内にアクセスされることを防ぐ)
            if (bManagedDispose)
            {
                #region [ 経緯時間計測用サウンドバッファを解放。]
                //-----------------
                if (this.sd経過時間計測用サウンドバッファ != null)
                {
                    this.sd経過時間計測用サウンドバッファ.tサウンドを停止する();
                    CCommon.tDispose(ref this.sd経過時間計測用サウンドバッファ);
                }
                //-----------------
                #endregion

                CCommon.tDispose(this.tmSystemTimer);
            }
            if (ctimer != null)
            {
                CCommon.tDispose(ref this.ctimer);
            }
            //使わなくなったデータをクリーンアップ
            Alc.MakeContextCurrent(ContextHandle.Zero);
            Alc.DestroyContext(this.context);
            Alc.CloseDevice(this.device);
        }
コード例 #4
0
        public void Dispose()
        {
            if (!disposed)
            {
                devicecount--;
                disposed = true;
                GC.SuppressFinalize(this);
                try
                {
                    Alc.MakeContextCurrent(new ContextHandle(IntPtr.Zero));
                }
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
                catch
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
                {
                }
                if (_hContext.Handle != IntPtr.Zero)
                {
                    Alc.DestroyContext(_hContext);
                }
                if (_hDevice != IntPtr.Zero)
                {
                    Alc.CloseDevice(_hDevice);
                }
            }
        }
コード例 #5
0
        protected void Dispose(bool bManagedDispose)
        {
            this.e出力デバイス = ESoundDeviceType.Unknown;                            // まず出力停止する(Dispose中にクラス内にアクセスされることを防ぐ)
            if (bManagedDispose)
            {
                #region [ 経緯時間計測用サウンドバッファを解放。]
                //-----------------
                if (this.sd経過時間計測用サウンドバッファ != null)
                {
                    this.sd経過時間計測用サウンドバッファ.tサウンドを停止する();
                    C共通.tDisposeする(ref this.sd経過時間計測用サウンドバッファ);
                }
                //-----------------
                #endregion
                #region [ 単位繰り上げ用スレッド停止。]
                //-----------------
                if (this.th経過時間測定用スレッド != null)
                {
                    this.th経過時間測定用スレッド.Abort();
                    this.th経過時間測定用スレッド = null;
                }
                //-----------------
                #endregion

                C共通.tDisposeする(this.tmシステムタイマ);
            }
            if (ctimer != null)
            {
                C共通.tDisposeする(ref this.ctimer);
            }
            //使わなくなったデータをクリーンアップ
            Alc.MakeContextCurrent(ContextHandle.Zero);
            Alc.DestroyContext(this.context);
            Alc.CloseDevice(this.device);
        }
コード例 #6
0
ファイル: AudioDevice.cs プロジェクト: layshua/Alexandria
 public void Close()
 {
     if (handle != IntPtr.Zero)
     {
         Alc.CloseDevice(handle);
     }
     handle = IntPtr.Zero;
 }
コード例 #7
0
 internal static void Cleanup()
 {
     Window.Close();
     GraphicsContext.Dispose();
     Alc.MakeContextCurrent(ContextHandle.Zero);
     Alc.DestroyContext(AudioContext);
     Alc.CloseDevice(AudioDevice);
 }
コード例 #8
0
        public void Dispose()
        {
            AL.DeleteSources(1, ref _source);

            Alc.MakeContextCurrent(ContextHandle.Zero);
            Alc.DestroyContext(_context);
            Alc.CloseDevice(_device);
        }
コード例 #9
0
        protected override void Dispose(bool disposing)
        {
            if (_device != IntPtr.Zero)
            {
                Alc.CloseDevice(_device);
            }

            _device = IntPtr.Zero;
        }
コード例 #10
0
        public void Dispose()
        {
            if (device == IntPtr.Zero)
            {
                return;
            }

            Alc.CloseDevice(device);
            device = IntPtr.Zero;
        }
コード例 #11
0
ファイル: MainWindow.cs プロジェクト: polytronicgr/Demo
        void shutDownAudio()
        {
            ContextHandle alContext    = Alc.GetCurrentContext();
            IntPtr        alDevice     = Alc.GetContextsDevice(alContext);
            ContextHandle emptyContext = ContextHandle.Zero;

            Alc.MakeContextCurrent(emptyContext);
            Alc.DestroyContext(alContext);
            Alc.CloseDevice(alDevice);
        }
コード例 #12
0
        public void CleanAndExit()
        {
            ContextHandle alContext    = Alc.GetCurrentContext();
            IntPtr        alDevice     = Alc.GetContextsDevice(alContext);
            ContextHandle emptyContext = ContextHandle.Zero;

            Alc.MakeContextCurrent(emptyContext);
            Alc.DestroyContext(alContext);
            Alc.CloseDevice(alDevice);
        }
コード例 #13
0
ファイル: AudioManager.cs プロジェクト: shff/gk3tools
        public static void Shutdown()
        {
            for (int i = 0; i < _maxSources; i++)
            {
                _sources[i].Source.Dispose();
                _sources[i].Owner = null;
            }

            Alc.DestroyContext(_context);
            Alc.CloseDevice(_device);
        }
コード例 #14
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 (Options.Current.SoundRange)
            {
            case SoundRange.Low:
                OuterRadiusFactorMinimum      = 2.0;
                OuterRadiusFactorMaximum      = 8.0;
                OuterRadiusFactorMaximumSpeed = 1.0;
                break;

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

            case 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, new int[0]);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    try {
                        AL.SpeedOfSound(343.0f);
                    } catch {
                        Debug.AddMessage(Debug.MessageType.Error, false, "OpenAL 1.1 is required. You seem to have OpenAL 1.0.");
                    }
                    AL.DistanceModel(ALDistanceModel.None);
                    return(true);
                }
                AlcError error = Alc.GetError(OpenAlDevice);
                Alc.CloseDevice(OpenAlDevice);
                OpenAlDevice = IntPtr.Zero;
                Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL context could not be created: " + error);
                return(false);
            }
            ALError devError = AL.GetError();

            OpenAlContext = ContextHandle.Zero;
            Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL sound device could not be opened: " + AL.GetErrorString(devError));
            return(false);
        }
コード例 #15
0
 public void Dispose()
 {
     Device = Alc.GetContextsDevice(context);
     Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero);
     if (context != OpenTK.ContextHandle.Zero)
     {
         Alc.DestroyContext(context);
     }
     if (Device != IntPtr.Zero)
     {
         Alc.CloseDevice(Device);
     }
 }
コード例 #16
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var device  = Alc.OpenDevice(null);
            var context = Alc.CreateContext(device, (int[])null);

            Alc.MakeContextCurrent(context);
            Application.Run(new MainWindow());
            Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero);
            Alc.DestroyContext(context);
            Alc.CloseDevice(device);
        }
コード例 #17
0
ファイル: Sounds.cs プロジェクト: piotrulos/OpenBVE
        // --- 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 void 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;
                }
                Alc.CloseDevice(OpenAlDevice);
                OpenAlDevice = IntPtr.Zero;
                //MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_context"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            OpenAlContext = ContextHandle.Zero;
            //MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_device"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
コード例 #18
0
 private void CleanUpOpenAL()
 {
     Alc.MakeContextCurrent(ContextHandle.Zero);
     if (_context != ContextHandle.Zero)
     {
         Alc.DestroyContext(_context);
         _context = ContextHandle.Zero;
     }
     if (_device != IntPtr.Zero)
     {
         Alc.CloseDevice(_device);
         _device = IntPtr.Zero;
     }
 }
コード例 #19
0
ファイル: OpenALDevice.cs プロジェクト: TheDuderist/MonoGame
 public void Dispose()
 {
     Alc.MakeContextCurrent(ContextHandle.Zero);
     if (alContext != ContextHandle.Zero)
     {
         Alc.DestroyContext(alContext);
         alContext = ContextHandle.Zero;
     }
     if (alDevice != IntPtr.Zero)
     {
         Alc.CloseDevice(alDevice);
         alDevice = IntPtr.Zero;
     }
     Instance = null;
 }
コード例 #20
0
        public void Dispose()
        {
            if (_context != ContextHandle.Zero)
            {
                Alc.MakeContextCurrent(ContextHandle.Zero);

                Alc.DestroyContext(_context);
            }
            _context = ContextHandle.Zero;

            if (_device != IntPtr.Zero)
            {
                Alc.CloseDevice(_device);
            }
            _device = IntPtr.Zero;
        }
コード例 #21
0
 // deinitialize
 internal static void Deinitialize()
 {
     if (OpenAlContext != ContextHandle.Zero)
     {
         SoundManager.StopAllSounds(true);
         SoundManager.UnuseAllSoundsBuffers();
         Alc.MakeContextCurrent(ContextHandle.Zero);
         Alc.DestroyContext(OpenAlContext);
         OpenAlContext = ContextHandle.Zero;
     }
     if (OpenAlDevice != IntPtr.Zero)
     {
         Alc.CloseDevice(OpenAlDevice);
         OpenAlDevice = IntPtr.Zero;
     }
 }
コード例 #22
0
ファイル: Sounds.cs プロジェクト: City-busz/OpenBVE
 /// <summary>Deinitializes audio.</summary>
 internal static void Deinitialize()
 {
     StopAllSounds();
     UnloadAllBuffers();
     if (OpenAlContext != ContextHandle.Zero)
     {
         Alc.MakeContextCurrent(ContextHandle.Zero);
         Alc.DestroyContext(OpenAlContext);
         OpenAlContext = ContextHandle.Zero;
     }
     if (OpenAlDevice != IntPtr.Zero)
     {
         Alc.CloseDevice(OpenAlDevice);
         OpenAlDevice = IntPtr.Zero;
     }
 }
コード例 #23
0
        /// <summary>
        ///
        /// </summary>
        private void CleanUpOpenAl()
        {
            Alc.MakeContextCurrent(NullContext);

            if (_context != NullContext)
            {
                Alc.DestroyContext(_context);
                _context = NullContext;
            }
            if (_device != IntPtr.Zero)
            {
                Alc.CloseDevice(_device);
                _device = IntPtr.Zero;
            }

            _bSoundAvailable = false;
        }
コード例 #24
0
        static void Dispose(ref IntPtr device, ref ContextHandle context)
        {
            if (context != ContextHandle.Zero)
            {
                Alc.MakeContextCurrent(ContextHandle.Zero);
                Alc.DestroyContext(context);
            }

            context = ContextHandle.Zero;

            if (device != IntPtr.Zero)
            {
                Alc.CloseDevice(device);
            }

            device = IntPtr.Zero;
        }
コード例 #25
0
 public static void Teardown()
 {
     foreach (object o in Sounds.Keys)
     {
         Sound sound = (Sound)Sounds[o];
         AL.SourceStop(sound.SourceId);
         AL.DeleteSource(sound.SourceId);
         AL.DeleteBuffer(sound.BufferId);
     }
     if (Alc.MakeContextCurrent(ContextHandle.Zero))
     {
         Alc.DestroyContext(AudioCtx);
         if (Alc.CloseDevice(AudioDevice))
         {
         }
     }
 }
コード例 #26
0
        // initialize
        internal static void Initialize()
        {
            // openal
            OpenAlDevice = Alc.OpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.CreateContext(OpenAlDevice, (int[])null);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    AL.SpeedOfSound(343.0f);
                    AL.DistanceModel(ALDistanceModel.None);
                }
                else
                {
                    Alc.CloseDevice(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 = ContextHandle.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;
        }
コード例 #27
0
ファイル: MAudioListener2.cs プロジェクト: BigFun123/Massive
        public override void Dispose()
        {
            base.Dispose();

            ///Dispose
            if (context != ContextHandle.Zero)
            {
                Alc.MakeContextCurrent(ContextHandle.Zero);
                Alc.DestroyContext(context);
            }
            context = ContextHandle.Zero;

            if (device != IntPtr.Zero)
            {
                Alc.CloseDevice(device);
            }
            device = IntPtr.Zero;
        }
コード例 #28
0
 private void Dispose(bool force)
 {
     if (INTERNAL_soundAvailable || force)
     {
         Alc.MakeContextCurrent(ContextHandle.Zero);
         if (_context != ContextHandle.Zero)
         {
             Alc.DestroyContext(_context);
             _context = ContextHandle.Zero;
         }
         if (_device != IntPtr.Zero)
         {
             Alc.CloseDevice(_device);
             _device = IntPtr.Zero;
         }
         INTERNAL_soundAvailable = false;
     }
 }
コード例 #29
0
        public void Dispose()
        {
            if (Disabled)
            {
                return;
            }

            lock (playingChannels)
            {
                for (int i = 0; i < playingChannels.Length; i++)
                {
                    for (int j = 0; j < playingChannels[i].Length; j++)
                    {
                        if (playingChannels[i][j] != null)
                        {
                            playingChannels[i][j].Dispose();
                        }
                    }
                }
            }
            if (streamingThread != null && !streamingThread.ThreadState.HasFlag(ThreadState.Stopped))
            {
                streamingThread.Join();
            }
            for (int i = loadedSounds.Count - 1; i >= 0; i--)
            {
                loadedSounds[i].Dispose();
            }
            sourcePools[(int)SourcePoolIndex.Default]?.Dispose();
            sourcePools[(int)SourcePoolIndex.Voice]?.Dispose();

            if (!Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero))
            {
                throw new Exception("Failed to detach the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
            }

            Alc.DestroyContext(alcContext);

            if (!Alc.CloseDevice(alcDevice))
            {
                throw new Exception("Failed to close ALC device!");
            }
        }
コード例 #30
0
ファイル: SoundManager.cs プロジェクト: shoter/Barotrauma
        public void Dispose()
        {
            lock (playingChannels)
            {
                for (int i = 0; i < SOURCE_COUNT; i++)
                {
                    if (playingChannels[i] != null)
                    {
                        playingChannels[i].Dispose();
                    }
                }
            }
            if (streamingThread != null && streamingThread.ThreadState == ThreadState.Running)
            {
                streamingThread.Join();
            }
            for (int i = loadedSounds.Count - 1; i >= 0; i--)
            {
                loadedSounds[i].Dispose();
            }
            for (int i = 0; i < SOURCE_COUNT; i++)
            {
                AL.DeleteSource(ref alSources[i]);
                ALError alError = AL.GetError();
                if (alError != ALError.NoError)
                {
                    throw new Exception("Failed to delete alSources[" + i.ToString() + "]: " + AL.GetErrorString(alError));
                }
            }

            if (!Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero))
            {
                throw new Exception("Failed to detach the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
            }

            Alc.DestroyContext(alcContext);

            if (!Alc.CloseDevice(alcDevice))
            {
                throw new Exception("Failed to close ALC device!");
            }
        }