Пример #1
0
        public void UnloadData()
        {
            MyLog.Default.WriteLine("MyAudio.UnloadData - START");

            if (m_canPlay)
            {
                m_audioEngine.StopEngine();
                if (m_cueBank != null)
                {
                    m_cueBank.Dispose();
                }
            }

            SoloCue = null;

            DisposeVoices();

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

            m_canPlay = false;

            MyLog.Default.WriteLine("MyAudio.UnloadData - END");
        }
Пример #2
0
        public void UnloadData()
        {
            MyLog.Default.WriteLine("MyAudio.UnloadData - START");

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

            if (m_canPlay)
            {
                m_audioEngine.StopEngine();
                if (m_cueBank != null)
                {
                    m_cueBank.Dispose();
                }
            }

            SoloCue = null;

            DisposeVoices();
            //Debug.Assert(m_musicCue == null || m_musicCue.Voice == null || m_musicCue.Voice.IsDisposed);
            if (m_audioEngine != null)
            {
                m_audioEngine.CriticalError -= m_audioEngine_CriticalError;
                m_audioEngine.Dispose();
                m_audioEngine = null;
            }

            m_canPlay = false;

            MyLog.Default.WriteLine("MyAudio.UnloadData - END");
        }
Пример #3
0
 public override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (sourceVoice != null)
         {
             sourceVoice.FlushSourceBuffers();
             sourceVoice.Stop();
             sourceVoice.Dispose();
             sourceVoice = null;
         }
         if (xAudioBuffer != null)
         {
             xAudioBuffer.Stream.Dispose();
             xAudioBuffer.Stream = null;
             xAudioBuffer        = null;
         }
         if (xAudio != null)
         {
             xAudio.StopEngine();
             xAudio.Dispose();
             xAudio = null;
         }
     }
 }
Пример #4
0
        void CloseDevice()
        {
            _sourceVoice?.Stop(PlayFlags.None, XAUDIO2_COMMIT_NOW);
            _sourceVoice?.FlushSourceBuffers();
            _sourceVoice?.DestroyVoice();
            _sourceVoice?.Dispose();

            _xaudio2?.StopEngine();

            _masteringVoice?.DestroyVoice();
            _masteringVoice?.Dispose();

            _xaudio2?.Dispose();

            _sourceVoice    = null;
            _masteringVoice = null;
            _xaudio2        = null;

            //if (_hidden.handle.IsAllocated)
            //{
            //    _hidden.handle.Free();
            //    _hidden.device = IntPtr.Zero;
            //}

            if (_hidden.mixbuf != null)
            {
                Marshal.FreeHGlobal((IntPtr)_hidden.mixbuf);
                _hidden.mixbuf = null;
            }

            _dev = null;
        }
Пример #5
0
        public void CanStopEngine()
        {
            XAudio2 obj = XAudio2.Create();

            obj.StartEngine();
            obj.StopEngine();
        }
Пример #6
0
        // Does someone actually need to call this if it only happens when the whole
        // game closes? And if so, who would make the call?
        internal static void Shutdown()
        {
            MasterVoice.DestroyVoice();
            MasterVoice.Dispose();

            Device.StopEngine();
            Device.Dispose();
        }
Пример #7
0
        public void Dispose()
        {
            foreach (var wave in Sounds)
            {
                wave.Value.Buffer.Stream.Dispose();
            }

            xAudio2.StopEngine();
            masteringVoice?.Dispose();
            xAudio2?.Dispose();
        }
Пример #8
0
 public void Shutdown()
 {
     buffer.Dispose();
     sourceVoice.FlushSourceBuffers();
     buffer = null;
     sourceVoice.Dispose();
     sourceVoice = null;
     masteringVoice.Dispose();
     masteringVoice = null;
     device.StopEngine();
     device.Dispose();
 }
 private void Dispose(bool disposing)
 {
     if (audio != null)
     {
         audio.StopEngine();
         audio.Dispose();
         audio = null;
         foreach (SourceVoice voice in voices)
         {
             voice.Dispose();
         }
         foreach (SoundStream stream in streams)
         {
             stream.Dispose();
         }
     }
 }
Пример #10
0
        public void Dispose(bool disposing)
        {
            if (_audio != null)
            {
                _audio.StopEngine();
                _audio.Dispose();
                _audio = null;

                foreach (var sourceVoice in _sourceVoices)
                {
                    sourceVoice.Dispose();
                }
                foreach (var soundStream in _soundStreams)
                {
                    soundStream.Dispose();
                }
            }
        }
Пример #11
0
        private void DestroyImpl()
        {
            if (MasteringVoice != null)
            {
                MasteringVoice.Dispose();
                MasteringVoice = null;
            }

            if (XAudio2 != null)
            {
                XAudio2.StopEngine();
                XAudio2.Dispose();
                XAudio2 = null;
            }

            PlatformSpecificDispose();

            if (mediaEngineStarted && nbOfAudioEngineInstances == 0)
            {
                MediaManager.Shutdown();
                mediaEngineStarted = false;
            }
        }
Пример #12
0
        internal override void DestroyAudioEngine()
        {
            if (MasteringVoice != null)
            {
                MasteringVoice.Dispose();
                MasteringVoice = null;
            }

            if (XAudio2 != null)
            {
                XAudio2.StopEngine();
                XAudio2.Dispose();
                XAudio2 = null;
            }

            DisposeImpl();

            if (mediaEngineStarted && nbOfAudioEngineInstances == 0)
            {
                MediaManager.Shutdown();
                mediaEngineStarted = false;
            }
        }
Пример #13
0
 /// <summary>
 ///
 /// </summary>
 public void StopEngine()
 {
     XAudio2.StopEngine();
 }
Пример #14
0
 void PlayForm_Closed(object sender, EventArgs e)
 {
     sourceVoice.Stop(PlayFlags.None, 0);
     xaudio2.StopEngine();
 }
Пример #15
0
        public static void Main(string[] args)
        {
            xaudio2 = new XAudio2();
            xaudio2.StartEngine();
            var masteringVoice = new MasteringVoice(xaudio2);

            if (!string.IsNullOrEmpty(Properties.Settings.Default.BackgroundMusicPath) &&
                Directory.Exists(Properties.Settings.Default.BackgroundMusicPath))
            {
                var musicFiles = Directory.GetFiles(Properties.Settings.Default.BackgroundMusicPath, "*.wav");
                if (musicFiles.Length > 0)
                {
                    backgroundPlayer = new TrackPlayer(xaudio2, musicFiles);
                }
            }

            var listener = new UdpClient(10009);

            listener.BeginReceive(new AsyncCallback(ReceiveCallback), listener);

            effectManager = new EffectManager(xaudio2, 4, Properties.Settings.Default.FXPath);

            // Wait until its done
            int count = 1;

            while (true)
            {
                Thread.Sleep(10);

                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }

                    switch (key.Key)
                    {
                    case ConsoleKey.A:
                        effectManager.Play("Scream.wav");
                        break;

                    case ConsoleKey.B:
                        effectManager.Play("Violin screech.wav");
                        break;

                    case ConsoleKey.N:
                        if (backgroundPlayer != null)
                        {
                            backgroundPlayer.NextTrack();
                        }
                        break;

                    case ConsoleKey.V:
                        if (key.Modifiers.HasFlag(ConsoleModifiers.Shift))
                        {
                            backgroundVolume -= 0.1f;
                        }
                        else
                        {
                            backgroundVolume += 0.1f;
                        }

                        if (backgroundVolume < 0f)
                        {
                            backgroundVolume = 0f;
                        }
                        if (backgroundVolume > 1f)
                        {
                            backgroundVolume = 1f;
                        }
                        break;
                    }
                }

                var muteMusic = effectManager.AreAnyPlaying && autoMuteBackground ? 0.2f : 0f;
                if (backgroundPlayer != null)
                {
                    backgroundPlayer.Volume = backgroundVolume - muteMusic;
                }

                if (count % 50 == 0)
                {
                    Console.Write(".");
                    Console.Out.Flush();
                }

                Thread.Sleep(10);
                count++;
            }

            listener.Close();

            if (backgroundPlayer != null)
            {
                backgroundPlayer.Stop();
            }
            if (trackPlayer != null)
            {
                trackPlayer.Stop();
            }

            effectManager.Dispose();

            Thread.Sleep(500);

            masteringVoice.Dispose();
            xaudio2.StopEngine();
            xaudio2.Dispose();
        }
Пример #16
0
 public void Destroy()
 {
     MasteringVoice.Dispose();
     XAudio.StopEngine();
 }