Exemplo n.º 1
0
 private void LoadPlugins(Settings fmodSettings)
 {
     #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
     FmodUnityNativePluginInit(lowlevelSystem.handle);
     #else
     FMOD.RESULT result;
     foreach (var pluginName in fmodSettings.Plugins)
     {
         if (string.IsNullOrEmpty(pluginName))
         {
             continue;
         }
         string pluginPath = RuntimeUtils.GetPluginPath(pluginName);
         uint   handle;
         result = lowlevelSystem.loadPlugin(pluginPath, out handle);
         #if UNITY_64 || UNITY_EDITOR_64
         // Add a "64" suffix and try again
         if (result == FMOD.RESULT.ERR_FILE_BAD || result == FMOD.RESULT.ERR_FILE_NOTFOUND)
         {
             string pluginPath64 = RuntimeUtils.GetPluginPath(pluginName + "64");
             result = lowlevelSystem.loadPlugin(pluginPath64, out handle);
         }
         #endif
         CheckInitResult(result, String.Format("Loading plugin '{0}' from '{1}'", pluginName, pluginPath));
         loadedPlugins.Add(pluginName, handle);
     }
     #endif
 }
Exemplo n.º 2
0
        // Loads dynamic FMOD plugins for this platform.
        public virtual void LoadDynamicPlugins(FMOD.System coreSystem, Action <FMOD.RESULT, string> reportResult)
        {
            List <string> pluginNames = Plugins;

            if (pluginNames == null)
            {
                return;
            }

            foreach (string pluginName in pluginNames)
            {
                if (string.IsNullOrEmpty(pluginName))
                {
                    continue;
                }

                string pluginPath = GetPluginPath(pluginName);
                uint   handle;

                FMOD.RESULT result = coreSystem.loadPlugin(pluginPath, out handle);

#if UNITY_64 || UNITY_EDITOR_64
                // Add a "64" suffix and try again
                if (result == FMOD.RESULT.ERR_FILE_BAD || result == FMOD.RESULT.ERR_FILE_NOTFOUND)
                {
                    string pluginPath64 = GetPluginPath(pluginName + "64");
                    result = coreSystem.loadPlugin(pluginPath64, out handle);
                }
#endif

                reportResult(result, string.Format("Loading plugin '{0}' from '{1}'", pluginName, pluginPath));
            }
        }
Exemplo n.º 3
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            uint version = 0;

            FMOD.RESULT result;

            /*
             *  Create a System object and initialize.
             */
            result = FMOD.Factory.System_Create(ref system);
            ERRCHECK(result);

            result = system.getVersion(ref version);
            ERRCHECK(result);
            if (version < FMOD.VERSION.number)
            {
                MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
                Application.Exit();
            }

            /*
             *   Set the source directory for all of the FMOD plugins.
             */
            result = system.setPluginPath("../../../../../api/plugins");
            ERRCHECK(result);

            /*
             *  Load up an extra plugin that is not normally used by FMOD.
             */
            uint handle = 0;

            result = system.loadPlugin("output_mp3.dll", ref handle, 0);
            if (result == FMOD.RESULT.ERR_FILE_NOTFOUND)
            {
                /*
                 *  If it isn't in the same directory, try for the plugin directory.
                 */
                result = system.loadPlugin("../../../../../examples/plugin_dev/output_mp3/output_mp3.dll", ref handle, 0);
                ERRCHECK(result);
            }

            /*
             *  Display plugins
             */
            {
                int           num  = 0;
                StringBuilder name = new StringBuilder(256);

                result = system.getNumPlugins(FMOD.PLUGINTYPE.CODEC, ref num);
                ERRCHECK(result);
                for (int count = 0; count < num; count++)
                {
                    FMOD.PLUGINTYPE plugin_type = FMOD.PLUGINTYPE.CODEC;

                    result = system.getPluginHandle(FMOD.PLUGINTYPE.CODEC, count, ref handle);
                    ERRCHECK(result);

                    result = system.getPluginInfo(handle, ref plugin_type, name, name.Capacity, ref version);
                    ERRCHECK(result);

                    codecList.Items.Add(name);
                }

                result = system.getNumPlugins(FMOD.PLUGINTYPE.DSP, ref num);
                ERRCHECK(result);
                for (int count = 0; count < num; count++)
                {
                    FMOD.PLUGINTYPE plugin_type = FMOD.PLUGINTYPE.DSP;

                    result = system.getPluginHandle(FMOD.PLUGINTYPE.DSP, count, ref handle);
                    ERRCHECK(result);

                    result = system.getPluginInfo(handle, ref plugin_type, name, name.Capacity, ref version);
                    ERRCHECK(result);

                    dspList.Items.Add(name);
                }

                result = system.getNumPlugins(FMOD.PLUGINTYPE.OUTPUT, ref num);
                ERRCHECK(result);
                for (int count = 0; count < num; count++)
                {
                    FMOD.PLUGINTYPE plugin_type = FMOD.PLUGINTYPE.OUTPUT;

                    result = system.getPluginHandle(FMOD.PLUGINTYPE.OUTPUT, count, ref handle);
                    ERRCHECK(result);

                    result = system.getPluginInfo(handle, ref plugin_type, name, name.Capacity, ref version);
                    ERRCHECK(result);

                    outputList.Items.Add(name);
                }
            }
        }
Exemplo n.º 4
0
        void Initialiase(bool forceNoNetwork)
        {
            UnityEngine.Debug.Log("FMOD Studio: Creating runtime system instance");

            FMOD.RESULT result;
            result = FMOD.Studio.System.create(out studioSystem);
            CheckInitResult(result, "Creating System Object");
            studioSystem.getLowLevelSystem(out lowlevelSystem);

            Settings fmodSettings = Settings.Instance;

            fmodPlatform = RuntimeUtils.GetCurrentPlatform();

            #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)
            {
#if UNITY_5_X
                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
                Debug.LogWarning(string.Format("FMOD Studio: Cannot open FMOD debug log file '{0}', logs will be missing for this session.", System.IO.Path.Combine(Application.dataPath, RuntimeUtils.LogFileName)));
#endif
            }
            else
            {
                CheckInitResult(result, "Applying debug settings");
            }
            #endif

            int realChannels = fmodSettings.GetRealChannels(fmodPlatform);

            realChannels = Math.Min(realChannels, 256); // Prior to 1.08.10 we didn't clamp this properly in the settings screen

            result = lowlevelSystem.setSoftwareChannels(realChannels);
            CheckInitResult(result, "Set software channels");
            result = lowlevelSystem.setSoftwareFormat(
                fmodSettings.GetSampleRate(fmodPlatform),
                (FMOD.SPEAKERMODE)fmodSettings.GetSpeakerMode(fmodPlatform),
                0 // raw not supported
                );
            CheckInitResult(result, "Set software format");

            // Setup up the platforms recommended codec to match the real channel count
            FMOD.ADVANCEDSETTINGS advancedsettings = new FMOD.ADVANCEDSETTINGS();
            #if UNITY_EDITOR || UNITY_STANDALONE
            advancedsettings.maxVorbisCodecs = realChannels;
            #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8_1 || UNITY_PSP2 || UNITY_WII
            advancedsettings.maxFADPCMCodecs = realChannels;
            #elif UNITY_XBOXONE
            advancedsettings.maxXMACodecs = realChannels;
            #elif UNITY_PS4
            advancedsettings.maxAT9Codecs = realChannels;
            #endif

            #if UNITY_5_0 || UNITY_5_1
            if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork)
            {
                UnityEngine.Debug.LogWarning("FMOD Studio: Detected Unity 5, running on port 9265");
                advancedsettings.profilePort = 9265;
            }
            #endif

            advancedsettings.randomSeed = (uint)DateTime.Now.Ticks;
            result = lowlevelSystem.setAdvancedSettings(ref advancedsettings);
            CheckInitResult(result, "Set advanced settings");

            FMOD.INITFLAGS        lowlevelInitFlags = FMOD.INITFLAGS.NORMAL;
            FMOD.Studio.INITFLAGS studioInitFlags   = FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS;

            if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork)
            {
                studioInitFlags |= FMOD.Studio.INITFLAGS.LIVEUPDATE;
            }

            FMOD.RESULT initResult = studioSystem.initialize(
                fmodSettings.GetVirtualChannels(fmodPlatform),
                studioInitFlags,
                lowlevelInitFlags,
                IntPtr.Zero
                );

            CheckInitResult(initResult, "Calling initialize");

            // Dummy flush and update to get network state
            studioSystem.flushCommands();
            FMOD.RESULT updateResult = studioSystem.update();

            // Restart without liveupdate if there was a socket error
            if (updateResult == FMOD.RESULT.ERR_NET_SOCKET_ERROR)
            {
                studioSystem.release();
                UnityEngine.Debug.LogWarning("FMOD Studio: Cannot open network port for Live Update, restarting with Live Update disabled. Check for other applications that are running FMOD Studio");
                Initialiase(true);
            }
            else
            {
                // Load plugins (before banks)
                        #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
                FmodUnityNativePluginInit(lowlevelSystem.getRaw());
                                #else
                foreach (var pluginName in fmodSettings.Plugins)
                {
                    string pluginPath = RuntimeUtils.GetPluginPath(pluginName);
                    uint   handle;
                    result = lowlevelSystem.loadPlugin(pluginPath, out handle);
                    #if UNITY_64 || UNITY_EDITOR_64
                    // Add a "64" suffix and try again
                    if (result == FMOD.RESULT.ERR_FILE_BAD || result == FMOD.RESULT.ERR_FILE_NOTFOUND)
                    {
                        string pluginPath64 = RuntimeUtils.GetPluginPath(pluginName + "64");
                        result = lowlevelSystem.loadPlugin(pluginPath64, out handle);
                    }
                    #endif
                    CheckInitResult(result, String.Format("Loading plugin '{0}' from '{1}'", pluginName, pluginPath));
                    loadedPlugins.Add(pluginName, handle);
                }
                #endif

                if (fmodSettings.ImportType == ImportType.StreamingAssets)
                {
                    // Always load strings bank
                    try
                    {
                        LoadBank(fmodSettings.MasterBank + ".strings", fmodSettings.AutomaticSampleLoading);
                    }
                    catch (BankLoadException e)
                    {
                        UnityEngine.Debug.LogException(e);
                    }

                    if (fmodSettings.AutomaticEventLoading)
                    {
                        try
                        {
                            LoadBank(fmodSettings.MasterBank, fmodSettings.AutomaticSampleLoading);
                        }
                        catch (BankLoadException e)
                        {
                            UnityEngine.Debug.LogException(e);
                        }

                        foreach (var bank in fmodSettings.Banks)
                        {
                            try
                            {
                                LoadBank(bank, fmodSettings.AutomaticSampleLoading);
                            }
                            catch (BankLoadException e)
                            {
                                UnityEngine.Debug.LogException(e);
                            }
                        }

                        WaitForAllLoads();
                    }
                }
            };

            FMOD.ChannelGroup master;
            lowlevelSystem.getMasterChannelGroup(out master);
            master.getDSP(0, out mixerHead);
            mixerHead.setMeteringEnabled(false, true);
        }
        void Initialiase(bool forceNoNetwork)
        {
            FMOD.RESULT result;
            result = FMOD.Studio.System.create(out studioSystem);
            CheckInitResult(result, "Creating System Object");
            studioSystem.getLowLevelSystem(out lowlevelSystem);

            Settings     fmodSettings = Settings.Instance;
            FMODPlatform fmodPlatform = RuntimeUtils.GetCurrentPlatform();


            #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);
            CheckInitResult(result, "Applying debug settings");
            #endif

            int realChannels = fmodSettings.GetRealChannels(fmodPlatform);
            result = lowlevelSystem.setSoftwareChannels(realChannels);
            CheckInitResult(result, "Set software channels");
            result = lowlevelSystem.setSoftwareFormat(
                fmodSettings.GetSampleRate(fmodPlatform),
                (FMOD.SPEAKERMODE)fmodSettings.GetSpeakerMode(fmodPlatform),
                0 // raw not supported
                );
            CheckInitResult(result, "Set software format");

            // Setup up the platforms recommended codec to match the real channel count
            FMOD.ADVANCEDSETTINGS advancedsettings = new FMOD.ADVANCEDSETTINGS();
            #if UNITY_EDITOR || UNITY_STANDALONE
            advancedsettings.maxVorbisCodecs = realChannels;
            #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8_1 || UNITY_PSP2 || UNITY_WII
            advancedsettings.maxFADPCMCodecs = realChannels;
            #elif UNITY_XBOXONE
            advancedsettings.maxXMACodecs = realChannels;
            #elif UNITY_PS4
            advancedsettings.maxAT9Codecs = realChannels;
            #endif

            #if UNITY_5_0 || UNITY_5_1
            if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork)
            {
                UnityEngine.Debug.LogWarning("FMOD Studio: Detected Unity 5, running on port 9265");
                advancedsettings.profilePort = 9265;
            }
            #endif

            advancedsettings.randomSeed = (uint)DateTime.Now.Ticks;
            result = lowlevelSystem.setAdvancedSettings(ref advancedsettings);
            CheckInitResult(result, "Set advanced settings");

            FMOD.INITFLAGS        lowlevelInitFlags = FMOD.INITFLAGS.NORMAL;
            FMOD.Studio.INITFLAGS studioInitFlags   = FMOD.Studio.INITFLAGS.NORMAL | FMOD.Studio.INITFLAGS.DEFERRED_CALLBACKS;

            if (fmodSettings.IsLiveUpdateEnabled(fmodPlatform) && !forceNoNetwork)
            {
                studioInitFlags |= FMOD.Studio.INITFLAGS.LIVEUPDATE;
            }

            FMOD.RESULT initResult = studioSystem.initialize(
                fmodSettings.GetVirtualChannels(fmodPlatform),
                studioInitFlags,
                lowlevelInitFlags,
                IntPtr.Zero
                );

            CheckInitResult(initResult, "Calling initialize");

            // Dummy flush and update to get network state
            studioSystem.flushCommands();
            FMOD.RESULT updateResult = studioSystem.update();

            // Restart without liveupdate if there was a socket error
            if (updateResult == FMOD.RESULT.ERR_NET_SOCKET_ERROR)
            {
                studioSystem.release();
                UnityEngine.Debug.LogWarning("FMOD Studio: Cannot network port for Live Update, restarting with Live Update disabled. Check for other applications that are running FMOD Studio");
                Initialiase(true);
            }
            else
            {
                try
                {
                    // Always load strings bank
                    LoadBank(fmodSettings.MasterBank + ".strings", fmodSettings.AutomaticSampleLoading);

                    if (fmodSettings.AutomaticEventLoading)
                    {
                        LoadBank(fmodSettings.MasterBank, fmodSettings.AutomaticSampleLoading);

                        foreach (var bank in fmodSettings.Banks)
                        {
                            LoadBank(bank, fmodSettings.AutomaticSampleLoading);
                        }
                    }
                }
                catch (BankLoadException e)
                {
                    throw new SystemNotInitializedException(e.Result, String.Format("Loading Bank '{0}'", e.Path));
                }

                foreach (var pluginName in fmodSettings.Plugins)
                {
                    string pluginPath = RuntimeUtils.GetPluginPath(pluginName);
                    uint   handle;
                    result = lowlevelSystem.loadPlugin(pluginPath, out handle);
                    CheckInitResult(result, String.Format("Loading plugin '{0}' from '{1}'", pluginName, pluginPath));
                    loadedPlugins.Add(pluginName, handle);
                }
            };
        }