Esempio n. 1
0
        /// <summary>
        /// Initializes systems and loads the native libraries. Can only be called once.
        /// </summary>
        /// <param name="preInitAction">Executes before initialization, but after the native instance creation.</param>
        public static void Init(
            FMODMode mode,
            string rootDir,
            int maxChannels                       = 256,
            uint dspBufferLength                  = 4,
            int dspBufferCount                    = 32,
            FMOD.INITFLAGS coreInitFlags          = FMOD.INITFLAGS.CHANNEL_LOWPASS | FMOD.INITFLAGS.CHANNEL_DISTANCEFILTER,
            FMOD.Studio.INITFLAGS studioInitFlags = FMOD.Studio.INITFLAGS.NORMAL,
            Action preInitAction                  = null
            )
        {
            if (_initialized)
            {
                throw new Exception("Manager is already initialized!");
            }
            _initialized = true;
            _mode        = mode;

            FileLoader.RootDirectory = rootDir;
            NativeLibraryLoader.LoadNativeLibrary("fmod");

            if (UsesStudio)
            {
                NativeLibraryLoader.LoadNativeLibrary("fmodstudio");

                FMOD.Studio.System.create(out StudioSystem.Native);

                StudioSystem.Native.getCoreSystem(out CoreSystem.Native);

                preInitAction?.Invoke();

                // This also will init core system.
                StudioSystem.Native.initialize(maxChannels, studioInitFlags, coreInitFlags, (IntPtr)0);
            }
            else
            {
                FMOD.Factory.System_Create(out CoreSystem.Native);

                preInitAction?.Invoke();

                CoreSystem.Native.init(maxChannels, coreInitFlags, (IntPtr)0);
            }

            // Too high values will cause sound lag.
            CoreSystem.Native.setDSPBufferSize(dspBufferLength, dspBufferCount);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes FMOD with custom parameters.
        ///
        /// If you want to use only the default wrapper, call
        /// LoadNativeLibrary() instead.
        /// </summary>
        public static void Init(
            string rootDir,
            uint dspBufferLength,
            int dspBufferCount,
            int maxChannels,
            FMOD.INITFLAGS initFlags
            )
        {
            _rootDir = rootDir;
            LoadNativeLibrary();

            FMOD.Factory.System_Create(out FMOD.System system);
            FMODSystem = system;

            // Too high values will cause sound lag.
            FMODSystem.setDSPBufferSize(dspBufferLength, dspBufferCount);

            FMODSystem.init(maxChannels, initFlags, (IntPtr)0);
        }
Esempio n. 3
0
    public void init(int maxChannels, FMOD.INITFLAGS flags, IntPtr extraDriverData, FMOD.EVENT_INITFLAGS eventFlags)
    {
        if (m_eventSystemWasInit == false)
        {
            m_eventSystemWasInit = true;
            FMOD.RESULT result = getEventSystem().init(maxChannels, flags, extraDriverData, eventFlags);
            ERRCHECK(result);

            result = m_system.init(maxChannels, flags, extraDriverData);
            ERRCHECK(result);

            result = m_system.set3DSettings(1.0f, 1.0f, 1.0f);
            ERRCHECK(result);
        }
        else
        {
            Debug.LogWarning("FMOD_Unity: FmodEventSystem: FMOD Event System already init");
        }
    }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of FMODSystem and starts an FMOD.System with the specified parameters
        /// </summary>
        /// <param name="channels">The number of channels</param>
        /// <param name="flags">The FMOD.INITFLAGS to pass to the system on initialization</param>
        /// <param name="pollingInterval">This parameter defines how often the system is polled for status</param>
        /// <param name="extraDriverData">The extra driver data to pass to the system on intialization</param>
        public FMODSystem(int channels, FMOD.INITFLAGS flags, IntPtr extraDriverData, TimeSpan pollingInterval)
        {
            if (pollingInterval.Ticks / TimeSpan.TicksPerMillisecond < 1)
            {
                throw new ArgumentOutOfRangeException("PollingInterval must be a timespan of more than 0 milliseconds!");
            }
            FMOD.RESULT result = FMOD.Factory.System_Create(ref this.system);
            if (result != FMOD.RESULT.OK)
            {
                throw new FMODException("Unable to create FMOD System", result);
            }
            result = this.system.init(channels, FMOD.INITFLAGS.NORMAL, extraDriverData);
            if (result != FMOD.RESULT.OK)
            {
                throw new FMODException("Unable to Initialize FMOD System", result);
            }
            this.pollingInterval = pollingInterval;
            this.soundChecker    = new Timer(this.CheckChannels, null, this.pollingInterval.Ticks / TimeSpan.TicksPerMillisecond, Timeout.Infinite);

            //ServiceManager.RegisterService(this);
        }
Esempio n. 5
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);
        }
 private static extern RESULT FMOD_Studio_System_Initialize(IntPtr studiosystem, int maxchannels, INITFLAGS studioFlags, FMOD.INITFLAGS flags, IntPtr extradriverdata);
 // Initialization / system functions.
 public RESULT init(int maxchannels, INITFLAGS studioFlags, FMOD.INITFLAGS flags, IntPtr extradriverdata)
 {
     return(FMOD_Studio_System_Initialize(rawPtr, maxchannels, studioFlags, flags, extradriverdata));
 }
        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);
                }
            };
        }
Esempio n. 9
0
 /// <summary>
 /// Calls <see cref="FMODSystem(int, FMOD.INITFLAGS, TimeSpan)"/> with the timespan parameter set to a timespan of 50 milliseconds
 /// </summary>
 /// <param name="channels"></param>
 /// <param name="flags"></param>
 public FMODSystem(int channels, FMOD.INITFLAGS flags)
     : this(channels, flags, TimeSpan.FromMilliseconds(50))
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Calls <see cref="FMODSystem(int, FMOD.INITFLAGS, IntPtr, TimeSpan)"/> with the specified values and a <see cref="IntPtr.Zero"/> pointer
 /// </summary>
 /// <param name="channels"></param>
 /// <param name="flags"></param>
 /// <param name="pollingInterval"></param>
 public FMODSystem(int channels, FMOD.INITFLAGS flags, TimeSpan pollingInterval)
     : this(channels, flags, IntPtr.Zero, pollingInterval)
 {
 }