Esempio n. 1
0
 public MySourceVoicePool(XAudio2 audioEngine, WaveFormat waveformat, MyCueBank owner)
 {
     m_audioEngine = audioEngine;
     m_waveFormat = waveformat;
     m_owner = owner;
     m_availableVoices = new MyConcurrentQueue<MySourceVoice>(32);
     m_fadingOutVoices = new List<MySourceVoice>();
     m_currentCount = 0;
 }
Esempio n. 2
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.UseSameSoundLimiter = m_useSameSoundLimiter;
                m_cueBank.SetSameSoundLimiter();
                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();

                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);
                        m_musicAudioVoice.SetVolume(m_volumeMusic);
                    }

                    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");
        }
 internal void SubmitSourceBuffer(MyStringId cue, MyInMemoryWave wave, MyCueBank.CuePart part)
 {
     m_loopBuffers[(int)part] = wave;
     m_cue = cue;
     m_isLoopable |= (wave.Buffer.LoopCount > 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();
 }
Esempio n. 5
0
        public static new void LoadData()
        {
            MySandboxGame.Log.WriteLine("MyAudio.LoadData - START");
            MySandboxGame.Log.IncreaseIndent();

            m_canPlay = true;
            MyObjectBuilder_CueDefinitions ob = null;
            try
            {
#if DEBUG
                bool result = false;
                try
                {
                    result = MyObjectBuilder_Base.DeserializeXML(MyCreateFileAudioSBA.GetFilenameSBA(), out ob);
                }
                catch (FileNotFoundException)
                {
                    // generates the Audio.sba file
                    MyCreateFileAudioSBA.Create();
                    result = MyObjectBuilder_Base.DeserializeXML(MyCreateFileAudioSBA.GetFilenameSBA(), out ob);
                }
#else
                bool result = MyObjectBuilder_Base.DeserializeXML(MyCreateFileAudioSBA.GetFilenameSBA(), out ob);
#endif //DEBUG

                if (result)
                {
                    Init();
                }
                else
                {
                    MySandboxGame.Log.WriteLine("Unable to load audio data. Game continues, but without sound", LoggingOptions.AUDIO);
                    m_canPlay = false;
                }
            }
            catch (Exception ex)
            {
                MySandboxGame.Log.WriteLine("Exception during loading audio engine. Game continues, but without sound. Details: " + ex.ToString(), LoggingOptions.AUDIO);
                MySandboxGame.Log.WriteLine("Device ID: " + m_deviceDetails.DeviceID, LoggingOptions.AUDIO);
                MySandboxGame.Log.WriteLine("Device name: " + m_deviceDetails.DisplayName, LoggingOptions.AUDIO);
                MySandboxGame.Log.WriteLine("Device role: " + m_deviceDetails.Role, LoggingOptions.AUDIO);
                MySandboxGame.Log.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 (MyFakes.SIMULATE_NO_SOUND_CARD)
                m_canPlay = false;

            if (m_canPlay)
            {
                m_cueBank = new MyCueBank(m_audioEngine, ob);
                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;

                //  Volume from config
                VolumeMusic = MyConfig.MusicVolume;
                VolumeGame = MyConfig.GameVolume;
                VolumeHud = MyConfig.GameVolume;
                MyConfig.MusicVolume = VolumeMusic;
                MyConfig.GameVolume = VolumeGame;

                m_mute = false;
                m_musicAllowed = true;

                m_musicState = MyMusicState.Stopped;
                m_loopMusic = true;

                m_transitionForward = false;
                m_timeFromTransitionStart = 0;

                m_soundInstancesTotal2D = 0;
                m_soundInstancesTotal3D = 0;
            }

            MySandboxGame.Log.DecreaseIndent();
            MySandboxGame.Log.WriteLine("MyAudio.LoadData - END");
        }