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"); }
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"); }