Example #1
0
        private static void SetVolumeExceptCategory(float volume, AudioCategory? ignoreCategory)
        {
            if (m_canPlay == false || !m_gameSoundsOn) return;

            //  We need to clamp the pitch, because app fails if we set it with zero value
            m_volumeDefault = MathHelper.Clamp(volume, MyAudioConstants.GAME_MASTER_VOLUME_MIN, MyAudioConstants.GAME_MASTER_VOLUME_MAX);
            foreach (AudioCategory category in m_gameCategories)
            {
                if (ignoreCategory.HasValue && category == ignoreCategory.Value)
                    continue;

                category.SetVolume(m_volumeDefault);
            }

            if (OnSetVolumeGame != null) OnSetVolumeGame(m_volumeDefault);
        }
Example #2
0
        public static void LoadData()
        {
            MyMwcLog.WriteLine("MyAudio.LoadData - START");
            MyMwcLog.IncreaseIndent();

            m_canPlay = true;
            try
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("new AudioEngine");
                //TimeSpan timeSpan = TimeSpan.FromMilliseconds(250);
                //m_audioEngine = new AudioEngine(MyPlugins.GetAudioFolder() + "Audio.xgs", timeSpan, "");
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Audio.xgs"))
                {
                    m_audioEngine = new AudioEngine(file);
                    m_cuePool = new MyCuePool(m_audioEngine);
                }

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("new MyX3DAudio");

                m_x3dAudio = new MyX3DAudio(m_audioEngine);

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            }
            catch (Exception ex)
            {
                MyMwcLog.WriteLine("Exception during loading audio engine. Game continues, but without sound. Details: " + ex.ToString(), 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_canPlay)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyXactVariables.LoadData");
                MyXactVariables.LoadData();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("AddWaveBanks");
                // IMPORTANT!!! Currently, there is problem with multiple XACT projects, that when anything changes in Music.xap or Voice.xap,
                // it is necessary to open and save Sounds.xap also, in order to run the game properly(otherwise it has problem to load the SoundBank.xsb)
                // this will be solved later in future
                AddWaveBanks();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Adding sound banks");

                MyMwcLog.WriteLine("Adding sound banks", LoggingOptions.AUDIO);
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Music.xsb"))
                {
                    m_musicSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Sounds.xsb"))
                {
                    m_sfxSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Dialogues.xsb"))
                {
                    m_dialogueSoundBank = new SoundBank(m_audioEngine, file);
                }
                using (var file = File.OpenRead(MyPlugins.GetAudioFolder() + "Voice.xsb"))
                {
                    m_voiceSoundBank = new SoundBank(m_audioEngine, file);
                }

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Categories");

                //m_voiceSoundBank = new SoundBank(m_audioEngine, MyPlugins.GetAudioFolder() + "Voice.xsb");
                m_listener = new Listener();
                m_listener.SetDefaultValues();
                m_helperEmitter = new Emitter();
                m_helperEmitter.SetDefaultValues();
                m_defaultCategory = m_audioEngine.GetCategoryInstance("Default");
                m_wep2DCategory = m_audioEngine.GetCategoryInstance("wep2d");
                m_cockpitCategory = m_audioEngine.GetCategoryInstance("Cockpit");
                m_musicCategory = m_audioEngine.GetCategoryInstance("Music");
                m_guiCategory = m_audioEngine.GetCategoryInstance("Gui");
                m_doorCategory = m_audioEngine.GetCategoryInstance("Door");
                m_enginesCategory = m_audioEngine.GetCategoryInstance("Engines");
                m_dialogueCategory = m_audioEngine.GetCategoryInstance("Dialogues");
                m_shoutsCategory = m_audioEngine.GetCategoryInstance("Shouts");
                m_hudCategory = m_audioEngine.GetCategoryInstance("VocHud");
                m_ambCategory = m_audioEngine.GetCategoryInstance("Amb");
                m_drillsCategory = m_audioEngine.GetCategoryInstance("Drills");
                m_impCategory = m_audioEngine.GetCategoryInstance("Imp");
                m_importantsCategory = m_audioEngine.GetCategoryInstance("IMPORTANTS");
                m_sfxCategory = m_audioEngine.GetCategoryInstance("Sfx");
                m_voiceCategory = m_audioEngine.GetCategoryInstance("Voice");
                m_welcomeCategory = m_audioEngine.GetCategoryInstance("Welcomes");
                m_wep3DCategory = m_audioEngine.GetCategoryInstance("Wep3D");
                m_xCategory = m_audioEngine.GetCategoryInstance("X");

                m_gameCategories = new List<AudioCategory>();
                m_gameCategories.Add(m_defaultCategory);
                m_gameCategories.Add(m_wep2DCategory);
                m_gameCategories.Add(m_cockpitCategory);
                m_gameCategories.Add(m_doorCategory);
                m_gameCategories.Add(m_enginesCategory);
                m_gameCategories.Add(m_dialogueCategory);
                m_gameCategories.Add(m_shoutsCategory);
                m_gameCategories.Add(m_hudCategory);
                m_gameCategories.Add(m_ambCategory);
                m_gameCategories.Add(m_drillsCategory);
                m_gameCategories.Add(m_impCategory);
                m_gameCategories.Add(m_importantsCategory);
                m_gameCategories.Add(m_sfxCategory);
                m_gameCategories.Add(m_voiceCategory);
                m_gameCategories.Add(m_welcomeCategory);
                m_gameCategories.Add(m_wep3DCategory);
                m_gameCategories.Add(m_xCategory);

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("WaitForWaveBanks");

                //  AudioEngine.Update needs to be called at least once before a streaming wave bank is ready
                MyMwcLog.WriteLine("Updating audio engine...", LoggingOptions.AUDIO);
                WaitForWaveBanks();

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

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("PreloadCueInfo");

                PreloadCueInfo(); // Takes about 26 ms

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("ValidateCues");

#if DEBUG
                ThreadPool.QueueUserWorkItem(ValidateCue_Thread); // Takes 4000 ms on background thread
#endif

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitCueParameters");

                InitCueParameters();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("InitNonLoopableCuesLimitRemoveHelper");

                InitNonLoopableCuesLimitRemoveHelper();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyHudAudio.LoadData");

                MyHudAudio.LoadData();

                //  Volume from config
                m_musicOn = true;
                m_gameSoundsOn = true;
                m_musicAllowed = true;
                VolumeMusic = MyConfig.MusicVolume;
                VolumeGame = MyConfig.GameVolume;
                VolumeGui = MyConfig.GameVolume;
                MyConfig.MusicVolume = VolumeMusic;
                MyConfig.GameVolume = VolumeGame;

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Save");

                MyConfig.Save();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
            }

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