static void CreateSystem() { UnityEngine.Debug.Log("FMOD Studio: Creating editor system instance"); RuntimeUtils.EnforceLibraryOrder(); FMOD.RESULT result = FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG, FMOD.DEBUG_MODE.FILE, null, "fmod_editor.log"); if (result != FMOD.RESULT.OK) { UnityEngine.Debug.LogWarning("FMOD Studio: Cannot open fmod_editor.log. Logging will be disabled for importing and previewing"); } CheckResult(FMOD.Studio.System.create(out system)); FMOD.System lowlevel; CheckResult(system.getCoreSystem(out lowlevel)); // Use play-in-editor speaker mode for event browser preview and metering lowlevel.setSoftwareFormat(0, (FMOD.SPEAKERMODE)Settings.Instance.GetSpeakerMode(FMODPlatform.Default), 0); CheckResult(system.initialize(256, FMOD.Studio.INITFLAGS.ALLOW_MISSING_PLUGINS | FMOD.Studio.INITFLAGS.SYNCHRONOUS_UPDATE, FMOD.INITFLAGS.NORMAL, IntPtr.Zero)); FMOD.ChannelGroup master; CheckResult(lowlevel.getMasterChannelGroup(out master)); FMOD.DSP masterHead; CheckResult(master.getDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, out masterHead)); CheckResult(masterHead.setMeteringEnabled(false, true)); }
public static void About() { FMOD.System lowlevel; CheckResult(System.getCoreSystem(out lowlevel)); uint version; CheckResult(lowlevel.getVersion(out version)); EditorUtility.DisplayDialog("FMOD Studio Unity Integration", "Version: " + VerionNumberToString(version) + "\n\nCopyright \u00A9 Firelight Technologies Pty, Ltd. 2014-2019 \n\nSee LICENSE.TXT for additional license information.", "OK"); }
public Spread <String> GetDriverInfo() { FMOD.System coreSystem; _system.getCoreSystem(out coreSystem); int numDrivers; int speakerModeChannels, systemRate; SPEAKERMODE speakerMode; Guid guid; string name; coreSystem.getNumDrivers(out numDrivers); SpreadBuilder <string> sb = new SpreadBuilder <string>(); for (int i = 0; i < numDrivers; i++) { coreSystem.getDriverInfo(i, out name, 255, out guid, out systemRate, out speakerMode, out speakerModeChannels); sb.Add(string.Format("{0} @ {1}, Channels: {2}, Mode: {3}", new object[] { name, systemRate, speakerModeChannels, speakerMode.ToString() })); } return(sb.ToSpread()); }
FMOD.RESULT Initialize() { #if UNITY_EDITOR AssemblyReloadEvents.beforeAssemblyReload += HandleBeforeAssemblyReload; EditorApplication.playModeStateChanged += HandlePlayModeStateChange; #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); 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 || DEVELOPMENT_BUILD result = FMOD.Debug.Initialize(fmodSettings.LoggingLevel, FMOD.DEBUG_MODE.CALLBACK, DEBUG_CALLBACK, null); 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; advancedSettings.profilePort = fmodSettings.LiveUpdatePort; } retry: result = FMOD.Studio.System.create(out studioSystem); CheckInitResult(result, "FMOD.Studio.System.create"); result = studioSystem.getCoreSystem(out coreSystem); CheckInitResult(result, "FMOD.Studio.System.getCoreSystem"); result = coreSystem.setOutput(outputType); CheckInitResult(result, "FMOD.System.setOutput"); result = coreSystem.setSoftwareChannels(realChannels); CheckInitResult(result, "FMOD.System.setSoftwareChannels"); result = coreSystem.setSoftwareFormat(sampleRate, speakerMode, 0); CheckInitResult(result, "FMOD.System.setSoftwareFormat"); result = coreSystem.setAdvancedSettings(ref advancedSettings); CheckInitResult(result, "FMOD.System.setAdvancedSettings"); if (!string.IsNullOrEmpty(Settings.Instance.EncryptionKey)) { FMOD.Studio.ADVANCEDSETTINGS studioAdvancedSettings = new FMOD.Studio.ADVANCEDSETTINGS(); result = studioSystem.setAdvancedSettings(studioAdvancedSettings, Settings.Instance.EncryptionKey); CheckInitResult(result, "FMOD.Studio.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::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] 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); }
FMOD.RESULT Initialize() { #if UNITY_EDITOR EditorApplication.playModeStateChanged += HandlePlayModeStateChange; #endif // UNITY_EDITOR FMOD.RESULT result = FMOD.RESULT.OK; FMOD.RESULT initResult = FMOD.RESULT.OK; Settings fmodSettings = Settings.Instance; currentPlatform = fmodSettings.FindCurrentPlatform(); int sampleRate = currentPlatform.SampleRate; int realChannels = Math.Min(currentPlatform.RealChannelCount, 256); int virtualChannels = currentPlatform.VirtualChannelCount; uint dspBufferLength = (uint)currentPlatform.DSPBufferLength; int dspBufferCount = currentPlatform.DSPBufferCount; FMOD.SPEAKERMODE speakerMode = currentPlatform.SpeakerMode; FMOD.OUTPUTTYPE outputType = currentPlatform.GetOutputType(); FMOD.ADVANCEDSETTINGS advancedSettings = new FMOD.ADVANCEDSETTINGS(); advancedSettings.randomSeed = (uint)DateTime.UtcNow.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 SetThreadAffinities(currentPlatform); currentPlatform.PreSystemCreate(CheckInitResult); #if UNITY_EDITOR || DEVELOPMENT_BUILD result = FMOD.Debug.Initialize(fmodSettings.LoggingLevel, FMOD.DEBUG_MODE.CALLBACK, DEBUG_CALLBACK, null); if (result == FMOD.RESULT.ERR_UNSUPPORTED) { Debug.LogWarning("[FMOD] Unable to initialize debug logging: Logging will be disabled.\nCheck the Import Settings of the FMOD libs to enable the logging library."); } else { CheckInitResult(result, "FMOD.Debug.Initialize"); } #endif FMOD.Studio.INITFLAGS studioInitFlags = FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS; if (currentPlatform.IsLiveUpdateEnabled) { studioInitFlags |= FMOD.Studio.INITFLAGS.LIVEUPDATE; advancedSettings.profilePort = (ushort)currentPlatform.LiveUpdatePort; } retry: result = FMOD.Studio.System.create(out studioSystem); CheckInitResult(result, "FMOD.Studio.System.create"); cachedStudioSystemHandle = (long)studioSystem.handle; result = studioSystem.getCoreSystem(out coreSystem); CheckInitResult(result, "FMOD.Studio.System.getCoreSystem"); result = coreSystem.setOutput(outputType); CheckInitResult(result, "FMOD.System.setOutput"); result = coreSystem.setSoftwareChannels(realChannels); CheckInitResult(result, "FMOD.System.setSoftwareChannels"); result = coreSystem.setSoftwareFormat(sampleRate, speakerMode, 0); CheckInitResult(result, "FMOD.System.setSoftwareFormat"); if (dspBufferLength > 0 && dspBufferCount > 0) { result = coreSystem.setDSPBufferSize(dspBufferLength, dspBufferCount); CheckInitResult(result, "FMOD.System.setDSPBufferSize"); } result = coreSystem.setAdvancedSettings(ref advancedSettings); CheckInitResult(result, "FMOD.System.setAdvancedSettings"); if (!string.IsNullOrEmpty(Settings.Instance.EncryptionKey)) { FMOD.Studio.ADVANCEDSETTINGS studioAdvancedSettings = new FMOD.Studio.ADVANCEDSETTINGS(); result = studioSystem.setAdvancedSettings(studioAdvancedSettings, Settings.Instance.EncryptionKey); CheckInitResult(result, "FMOD.Studio.System.setAdvancedSettings"); } if (Settings.Instance.EnableMemoryTracking) { studioInitFlags |= FMOD.Studio.INITFLAGS.MEMORY_TRACKING; } currentPlatform.PreInitialize(studioSystem); PlatformCallbackHandler callbackHandler = currentPlatform.CallbackHandler; if (callbackHandler != null) { callbackHandler.PreInitialize(studioSystem, CheckInitResult); } 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::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] 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; } } currentPlatform.LoadPlugins(coreSystem, CheckInitResult); LoadBanks(fmodSettings); #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR RegisterSuspendCallback(HandleInterrupt); #endif return(initResult); }