public MySourceVoicePool(XAudio2 audioEngine, WaveFormat waveformat, MyCueBank owner)
 {
     m_audioEngine     = audioEngine;
     m_waveFormat      = waveformat;
     m_owner           = owner;
     m_availableVoices = new MyConcurrentQueue <MySourceVoice>(MAX_COUNT);
     m_fadingOutVoices = new List <MySourceVoice>();
     m_currentCount    = 0;
 }
 public void Dispose()
 {
     m_availableVoices.Clear();
     m_fadingOutVoices.Clear();
     m_currentCount = 0;
     m_audioEngine  = null;
     m_owner        = null;
     foreach (var v in m_allVoices)
     {
         v.Cleanup();
         m_voiceBuffer.Add(v);
     }
     m_allVoices.Clear();
 }
Exemplo n.º 3
0
        public void LoadData(MyAudioInitParams initParams, ListReader <MySoundData> sounds, ListReader <MyAudioEffect> effects)
        {
            MyLog.Default.WriteLine("MyAudio.LoadData - START");
            MyLog.Default.IncreaseIndent();
            m_initParams = initParams;
            m_sounds     = sounds;
            m_effects    = effects;
            m_canPlay    = true;
            try
            {
                if (sounds.Count > 0)
                {
                    Init();
                }
                else
                {
                    MyLog.Default.WriteLine("Unable to load audio data. Game continues, but without sound", LoggingOptions.AUDIO);
                    m_canPlay = false;
                }
            }
            catch (Exception ex)
            {
                MyLog.Default.WriteLine("Exception during loading audio engine. Game continues, but without sound. Details: " + ex.ToString(), LoggingOptions.AUDIO);
                MyLog.Default.WriteLine("Device ID: " + m_deviceDetails.DeviceID, LoggingOptions.AUDIO);
                MyLog.Default.WriteLine("Device name: " + m_deviceDetails.DisplayName, LoggingOptions.AUDIO);
                MyLog.Default.WriteLine("Device role: " + m_deviceDetails.Role, LoggingOptions.AUDIO);
                MyLog.Default.WriteLine("Output format: " + m_deviceDetails.OutputFormat, LoggingOptions.AUDIO);

                //  This exception is the only way I can know if we can play sound (e.g. if computer doesn't have sound card).
                //  I didn't find other ways of checking it.
                m_canPlay = false;
            }

            if (m_initParams.SimulateNoSoundCard)
            {
                m_canPlay = false;
            }

            if (m_canPlay)
            {
                m_cueBank = new MyCueBank(m_audioEngine, sounds);
                m_cueBank.DisablePooling = initParams.DisablePooling;
                m_effectBank             = new MyEffectBank(effects, m_audioEngine);
                m_3Dsounds = new List <IMy3DSoundEmitter>();
                m_listener = new Listener();
                m_listener.SetDefaultValues();
                m_helperEmitter = new Emitter();
                m_helperEmitter.SetDefaultValues();

                //  This is reverb turned to off, so we hear sounds as they are defined in wav files
                ApplyReverb = false;

                m_musicOn      = true;
                m_gameSoundsOn = true;

                m_musicAllowed = true;

                if ((m_musicCue != null) && m_musicCue.IsPlaying)
                {
                    // restarts music cue
                    m_musicCue = PlaySound(m_musicCue.CueEnum);
                    if (m_musicCue != null)
                    {
                        m_musicCue.SetOutputVoices(m_musicAudioVoiceDesc);
                    }

                    UpdateMusic(0);
                }
                else
                {
                    m_musicState = MyMusicState.Stopped;
                }
                m_loopMusic = true;

                m_transitionForward       = false;
                m_timeFromTransitionStart = 0;

                m_soundInstancesTotal2D = 0;
                m_soundInstancesTotal3D = 0;
            }

            MyLog.Default.DecreaseIndent();
            MyLog.Default.WriteLine("MyAudio.LoadData - END");
        }