void Init() { FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: Initialize"); if (isInitialized) { return; } DontDestroyOnLoad(gameObject); FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: System_Create"); ERRCHECK(FMOD.Studio.System.create(out system)); FMOD.Studio.INITFLAGS flags = FMOD.Studio.INITFLAGS.NORMAL; #if FMOD_LIVEUPDATE flags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; // Unity 5 liveupdate workaround if (Application.unityVersion.StartsWith("5")) { FMOD.Studio.UnityUtil.LogWarning("FMOD_StudioSystem: detected Unity 5, running on port 9265"); FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); FMOD.ADVANCEDSETTINGS advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.profilePort = 9265; ERRCHECK(sys.setAdvancedSettings(ref advancedSettings)); } #endif int outputRate = 48000; #if true //UNITY_ANDROID && !UNITY_EDITOR // Force the system sample rate to the output rate to allow for the fast mixer if (FMOD.VERSION.number >= 0x00010500) { FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); { System.Text.StringBuilder str = new System.Text.StringBuilder(); FMOD.GUID guid; FMOD.SPEAKERMODE speakermode; int speakermodechannels; ERRCHECK(sys.getDriverInfo(0, str, str.Capacity, out guid, out outputRate, out speakermode, out speakermodechannels)); } ERRCHECK(sys.setSoftwareFormat(outputRate, FMOD.SPEAKERMODE.DEFAULT, 0)); } #endif FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: system.init"); FMOD.RESULT result = FMOD.RESULT.OK; result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); if (result == FMOD.RESULT.ERR_HEADER_MISMATCH) { FMOD.Studio.UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue."); } else { ERRCHECK(result); } // Dummy flush and update to get network state ERRCHECK(system.flushCommands()); result = system.update(); // Restart without liveupdate if there was a socket error if (result == FMOD.RESULT.ERR_NET_SOCKET_ERROR) { FMOD.Studio.UnityUtil.LogWarning("LiveUpdate disabled: socket in already in use"); flags &= ~FMOD.Studio.INITFLAGS.LIVEUPDATE; ERRCHECK(system.release()); ERRCHECK(FMOD.Studio.System.create(out system)); FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); ERRCHECK(sys.setSoftwareFormat(outputRate, FMOD.SPEAKERMODE.DEFAULT, 0)); result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); ERRCHECK(result); } isInitialized = true; }
public void FlushCommands() { _system.flushCommands(); }
void Init() { FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: Initialize"); if (isInitialized) { return; } DontDestroyOnLoad(gameObject); FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: System_Create"); ERRCHECK(FMOD.Studio.System.create(out system)); FMOD.Studio.INITFLAGS flags = FMOD.Studio.INITFLAGS.NORMAL; FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); FMOD.ADVANCEDSETTINGS advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.randomSeed = (uint)DateTime.Now.Ticks; #if FMOD_LIVEUPDATE flags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; // Unity 5 liveupdate workaround if (Application.unityVersion.StartsWith("5")) { FMOD.Studio.UnityUtil.LogWarning("FMOD_StudioSystem: detected Unity 5, running on port 9265"); advancedSettings.profilePort = 9265; } #endif ERRCHECK(sys.setAdvancedSettings(ref advancedSettings)); #if FMOD_DEBUG FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.FILE, null, "fmod.log"); #endif FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: system.init"); FMOD.RESULT result = FMOD.RESULT.OK; result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); if (result == FMOD.RESULT.ERR_HEADER_MISMATCH) { FMOD.Studio.UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue."); } else { ERRCHECK(result); } // Dummy flush and update to get network state ERRCHECK(system.flushCommands()); result = system.update(); // Restart without liveupdate if there was a socket error if (result == FMOD.RESULT.ERR_NET_SOCKET_ERROR) { FMOD.Studio.UnityUtil.LogWarning("LiveUpdate disabled: socket in already in use"); flags &= ~FMOD.Studio.INITFLAGS.LIVEUPDATE; ERRCHECK(system.release()); ERRCHECK(FMOD.Studio.System.create(out system)); ERRCHECK(system.getLowLevelSystem(out sys)); advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.randomSeed = (uint)DateTime.Now.Ticks; ERRCHECK(sys.setAdvancedSettings(ref advancedSettings)); result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); ERRCHECK(result); } #if UNITY_EDITOR && FMOD_DEBUG var fileStream = new FileStream("fmod.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); logReader = new StreamReader(fileStream); #endif isInitialized = true; }
void Init() { FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: Initialize"); if (isInitialized) { return; } DontDestroyOnLoad(gameObject); FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: System_Create"); ERRCHECK(FMOD.Studio.System.create(out system)); FMOD.Studio.INITFLAGS flags = FMOD.Studio.INITFLAGS.NORMAL; #if FMOD_LIVEUPDATE flags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; // Unity 5 liveupdate workaround if (Application.unityVersion.StartsWith("5")) { FMOD.Studio.UnityUtil.LogWarning("FMOD_StudioSystem: detected Unity 5, running on port 9265"); FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); FMOD.ADVANCEDSETTINGS advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.profilePort = 9265; ERRCHECK(sys.setAdvancedSettings(ref advancedSettings)); } #endif #if FMOD_DEBUG #if UNITY_XBOXONE // Can't go managed -> native -> managed apparently so log to a file FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.FILE, null, "fmod.log"); #else FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.CALLBACK, LogCallback, null); #endif #endif FMOD.Studio.UnityUtil.Log("FMOD_StudioSystem: system.init"); FMOD.RESULT result = FMOD.RESULT.OK; result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); if (result == FMOD.RESULT.ERR_HEADER_MISMATCH) { FMOD.Studio.UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue."); } else { ERRCHECK(result); } // Dummy flush and update to get network state ERRCHECK(system.flushCommands()); result = system.update(); // Restart without liveupdate if there was a socket error if (result == FMOD.RESULT.ERR_NET_SOCKET_ERROR) { FMOD.Studio.UnityUtil.LogWarning("LiveUpdate disabled: socket in already in use"); flags &= ~FMOD.Studio.INITFLAGS.LIVEUPDATE; ERRCHECK(system.release()); ERRCHECK(FMOD.Studio.System.create(out system)); FMOD.System sys; ERRCHECK(system.getLowLevelSystem(out sys)); result = system.initialize(1024, flags, FMOD.INITFLAGS.NORMAL, global::System.IntPtr.Zero); ERRCHECK(result); } isInitialized = true; }
private RESULT Initialize() { initializedSuccessfully = false; RESULT rESULT = RESULT.OK; RESULT rESULT2 = RESULT.OK; Settings settings = Settings.Instance; fmodPlatform = RuntimeUtils.GetCurrentPlatform(); int sampleRate = settings.GetSampleRate(fmodPlatform); int num = Math.Min(settings.GetRealChannels(fmodPlatform), 256); int virtualChannels = settings.GetVirtualChannels(fmodPlatform); SPEAKERMODE speakerMode = (SPEAKERMODE)settings.GetSpeakerMode(fmodPlatform); OUTPUTTYPE output = OUTPUTTYPE.AUTODETECT; FMOD.ADVANCEDSETTINGS settings2 = default(FMOD.ADVANCEDSETTINGS); settings2.randomSeed = (uint)DateTime.Now.Ticks; settings2.maxVorbisCodecs = num; FMOD.Studio.INITFLAGS iNITFLAGS = FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS; if (settings.IsLiveUpdateEnabled(fmodPlatform)) { iNITFLAGS |= FMOD.Studio.INITFLAGS.LIVEUPDATE; } while (true) { rESULT = FMOD.Studio.System.create(out studioSystem); CheckInitResult(rESULT, "FMOD.Studio.System.create"); rESULT = studioSystem.getLowLevelSystem(out lowlevelSystem); CheckInitResult(rESULT, "FMOD.Studio.System.getLowLevelSystem"); rESULT = lowlevelSystem.setOutput(output); CheckInitResult(rESULT, "FMOD.System.setOutput"); rESULT = lowlevelSystem.setSoftwareChannels(num); CheckInitResult(rESULT, "FMOD.System.setSoftwareChannels"); rESULT = lowlevelSystem.setSoftwareFormat(sampleRate, speakerMode, 0); CheckInitResult(rESULT, "FMOD.System.setSoftwareFormat"); rESULT = lowlevelSystem.setAdvancedSettings(ref settings2); CheckInitResult(rESULT, "FMOD.System.setAdvancedSettings"); rESULT = studioSystem.initialize(virtualChannels, iNITFLAGS, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); if (rESULT != 0 && rESULT2 == RESULT.OK) { rESULT2 = rESULT; output = OUTPUTTYPE.NOSOUND; Debug.LogWarningFormat("FMOD Studio: Studio::System::initialize returned {0}, defaulting to no-sound mode.", rESULT.ToString()); } else { CheckInitResult(rESULT, "Studio::System::initialize"); if ((iNITFLAGS & FMOD.Studio.INITFLAGS.LIVEUPDATE) == FMOD.Studio.INITFLAGS.NORMAL) { break; } studioSystem.flushCommands(); rESULT = studioSystem.update(); if (rESULT != RESULT.ERR_NET_SOCKET_ERROR) { break; } iNITFLAGS = (FMOD.Studio.INITFLAGS)((int)iNITFLAGS & -2); Debug.LogWarning("FMOD Studio: Cannot open network port for Live Update (in-use), restarting with Live Update disabled."); rESULT = studioSystem.release(); CheckInitResult(rESULT, "FMOD.Studio.System.Release"); } } LoadPlugins(settings); LoadBanks(settings); initializedSuccessfully = (rESULT == RESULT.OK); return(rESULT2); }
FMOD.RESULT Initialize() { #if UNITY_EDITOR #if UNITY_2017_2_OR_NEWER EditorApplication.playModeStateChanged += HandlePlayModeStateChange; #elif UNITY_2017_1_OR_NEWER EditorApplication.playmodeStateChanged += HandleOnPlayModeChanged; #endif // UNITY_2017_2_OR_NEWER #endif // UNITY_EDITOR FMOD.RESULT result = FMOD.RESULT.OK; FMOD.RESULT initResult = FMOD.RESULT.OK; Settings fmodSettings = Settings.Instance; fmodPlatform = RuntimeUtils.GetCurrentPlatform(); int sampleRate = fmodSettings.GetSampleRate(fmodPlatform); int realChannels = Math.Min(fmodSettings.GetRealChannels(fmodPlatform), 256); // Prior to 1.08.10 we didn't clamp this properly in the settings screen int virtualChannels = fmodSettings.GetVirtualChannels(fmodPlatform); FMOD.SPEAKERMODE speakerMode = (FMOD.SPEAKERMODE)fmodSettings.GetSpeakerMode(fmodPlatform); FMOD.OUTPUTTYPE outputType = FMOD.OUTPUTTYPE.AUTODETECT; FMOD.ADVANCEDSETTINGS advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.randomSeed = (uint)DateTime.Now.Ticks; #if UNITY_EDITOR || UNITY_STANDALONE advancedSettings.maxVorbisCodecs = realChannels; #elif UNITY_XBOXONE advancedSettings.maxXMACodecs = realChannels; #elif UNITY_PS4 advancedSettings.maxAT9Codecs = realChannels; #else advancedSettings.maxFADPCMCodecs = realChannels; #endif SetThreadAffinity(); #if UNITY_EDITOR || ((UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX) && DEVELOPMENT_BUILD) result = FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.FILE, null, RuntimeUtils.LogFileName); if (result == FMOD.RESULT.ERR_FILE_NOTFOUND) { UnityEngine.Debug.LogWarningFormat("FMOD Studio: Cannot open FMOD debug log file '{0}', logs will be missing for this session.", System.IO.Path.Combine(Application.dataPath, RuntimeUtils.LogFileName)); } else { CheckInitResult(result, "FMOD.Debug.Initialize"); } #endif FMOD.Studio.INITFLAGS studioInitFlags = FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS; if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform)) { studioInitFlags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; #if UNITY_5_0 || UNITY_5_1 // These versions of Unity shipped with FMOD4 profiling enabled consuming our port number. UnityEngine.Debug.LogWarning("FMOD Studio: Live Update port in-use by Unity, switching to port 9265"); advancedSettings.profilePort = 9265; #endif } retry: result = FMOD.Studio.System.create(out studioSystem); CheckInitResult(result, "FMOD.Studio.System.create"); result = studioSystem.getLowLevelSystem(out lowlevelSystem); CheckInitResult(result, "FMOD.Studio.System.getLowLevelSystem"); result = lowlevelSystem.setOutput(outputType); CheckInitResult(result, "FMOD.System.setOutput"); result = lowlevelSystem.setSoftwareChannels(realChannels); CheckInitResult(result, "FMOD.System.setSoftwareChannels"); result = lowlevelSystem.setSoftwareFormat(sampleRate, speakerMode, 0); CheckInitResult(result, "FMOD.System.setSoftwareFormat"); result = lowlevelSystem.setAdvancedSettings(ref advancedSettings); CheckInitResult(result, "FMOD.System.setAdvancedSettings"); result = studioSystem.initialize(virtualChannels, studioInitFlags, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); if (result != FMOD.RESULT.OK && initResult == FMOD.RESULT.OK) { initResult = result; // Save this to throw at the end (we'll attempt NO SOUND to shield ourselves from unexpected device failures) outputType = FMOD.OUTPUTTYPE.NOSOUND; UnityEngine.Debug.LogErrorFormat("FMOD Studio: Studio::System::initialize returned {0}, defaulting to no-sound mode.", result.ToString()); goto retry; } CheckInitResult(result, "Studio::System::initialize"); // Test network functionality triggered during System::update if ((studioInitFlags & FMOD.Studio.INITFLAGS.LIVEUPDATE) != 0) { studioSystem.flushCommands(); // Any error will be returned through Studio.System.update result = studioSystem.update(); if (result == FMOD.RESULT.ERR_NET_SOCKET_ERROR) { studioInitFlags &= ~FMOD.Studio.INITFLAGS.LIVEUPDATE; UnityEngine.Debug.LogWarning("FMOD Studio: Cannot open network port for Live Update (in-use), restarting with Live Update disabled."); result = studioSystem.release(); CheckInitResult(result, "FMOD.Studio.System.Release"); goto retry; } } LoadPlugins(fmodSettings); LoadBanks(fmodSettings); return(initResult); }