예제 #1
0
    private void Init()
    {
        UnityUtil.Log("FMOD_StudioSystem: Initialize");
        if (FMOD_StudioSystem.isInitialized)
        {
            return;
        }
        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
        UnityUtil.Log("FMOD_StudioSystem: System_Create");
        FMOD_StudioSystem.ERRCHECK(FMOD.Studio.System.create(out this.system));
        FMOD.Studio.INITFLAGS iNITFLAGS = FMOD.Studio.INITFLAGS.NORMAL;
        FMOD.System           system;
        FMOD_StudioSystem.ERRCHECK(this.system.getLowLevelSystem(out system));
        FMOD.ADVANCEDSETTINGS aDVANCEDSETTINGS = default(FMOD.ADVANCEDSETTINGS);
        aDVANCEDSETTINGS.randomSeed = (uint)DateTime.Now.Ticks;
        FMOD_StudioSystem.ERRCHECK(system.setAdvancedSettings(ref aDVANCEDSETTINGS));
        UnityUtil.Log("FMOD_StudioSystem: system.init");
        RESULT rESULT = this.system.initialize(1024, iNITFLAGS, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);

        if (rESULT == RESULT.ERR_HEADER_MISMATCH)
        {
            UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue.");
        }
        else
        {
            FMOD_StudioSystem.ERRCHECK(rESULT);
        }
        FMOD_StudioSystem.ERRCHECK(this.system.flushCommands());
        rESULT = this.system.update();
        if (rESULT == RESULT.ERR_NET_SOCKET_ERROR)
        {
            UnityUtil.LogWarning("LiveUpdate disabled: socket in already in use");
            iNITFLAGS &= ~FMOD.Studio.INITFLAGS.LIVEUPDATE;
            FMOD_StudioSystem.ERRCHECK(this.system.release());
            FMOD_StudioSystem.ERRCHECK(FMOD.Studio.System.create(out this.system));
            FMOD_StudioSystem.ERRCHECK(this.system.getLowLevelSystem(out system));
            aDVANCEDSETTINGS            = default(FMOD.ADVANCEDSETTINGS);
            aDVANCEDSETTINGS.randomSeed = (uint)DateTime.Now.Ticks;
            FMOD_StudioSystem.ERRCHECK(system.setAdvancedSettings(ref aDVANCEDSETTINGS));
            rESULT = this.system.initialize(1024, iNITFLAGS, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
            FMOD_StudioSystem.ERRCHECK(rESULT);
        }
        FMOD_StudioSystem.isInitialized = true;
    }
예제 #2
0
        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);
        }
예제 #3
0
    private void Init()
    {
        UnityUtil.Log("FMOD_StudioSystem: Initialize");
        if (this.isInitialized)
        {
            return;
        }
        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
        this.LiveUpdateEnabled = false;
        string[] commandLineArgs = Environment.GetCommandLineArgs();
        for (int i = 0; i < commandLineArgs.Length; i++)
        {
            string a = commandLineArgs[i];
            if (a == "-FMODLiveUpdate")
            {
                this.LiveUpdateEnabled = true;
                break;
            }
        }
        UnityUtil.Log("FMOD_StudioSystem: System_Create");
        FMOD_StudioSystem.ERRCHECK(FMOD.Studio.System.create(out this.system));
        FMOD.Studio.INITFLAGS iNITFLAGS        = FMOD.Studio.INITFLAGS.NORMAL;
        FMOD.ADVANCEDSETTINGS aDVANCEDSETTINGS = default(FMOD.ADVANCEDSETTINGS);
        if (this.LiveUpdateEnabled)
        {
            iNITFLAGS |= FMOD.Studio.INITFLAGS.LIVEUPDATE;
            if (Application.unityVersion.StartsWith("5"))
            {
                UnityUtil.LogWarning("FMOD_StudioSystem: detected Unity 5, running on port 9265");
                aDVANCEDSETTINGS.profilePort = 9265;
            }
        }
        int @int = PlayerPrefs.GetInt("VoiceCount", 128);

        FMOD.System system;
        FMOD_StudioSystem.ERRCHECK(this.system.getLowLevelSystem(out system));
        FMOD_StudioSystem.ERRCHECK(system.setSoftwareChannels(@int));
        aDVANCEDSETTINGS.maxVorbisCodecs = @int;
        FMOD_StudioSystem.ERRCHECK(system.setAdvancedSettings(ref aDVANCEDSETTINGS));
        int           num  = 48000;
        StringBuilder name = new StringBuilder();
        Guid          guid;
        SPEAKERMODE   sPEAKERMODE;
        int           num2;

        FMOD_StudioSystem.ERRCHECK(system.getDriverInfo(0, name, 0, out guid, out num, out sPEAKERMODE, out num2));
        if (num > 48000)
        {
            uint bufferlength = 0u;
            int  num3         = 0;
            FMOD_StudioSystem.ERRCHECK(system.getDSPBufferSize(out bufferlength, out num3));
            FMOD_StudioSystem.ERRCHECK(system.setDSPBufferSize(bufferlength, num3 * 2));
        }
        num = Math.Min(num, 48000);
        FMOD_StudioSystem.ERRCHECK(system.setSoftwareFormat(num, SPEAKERMODE._5POINT1, 0));
        UnityUtil.Log("FMOD_StudioSystem: system.init");
        RESULT rESULT = this.system.initialize(1024, iNITFLAGS, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);

        if (rESULT == RESULT.ERR_NET_SOCKET_ERROR)
        {
            UnityUtil.LogError("Unable to initalize with LiveUpdate: socket is already in use");
        }
        else if (rESULT == RESULT.ERR_HEADER_MISMATCH)
        {
            UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue.");
        }
        else
        {
            FMOD_StudioSystem.ERRCHECK(rESULT);
        }
        this.isInitialized = true;
    }
예제 #4
0
        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);
        }