コード例 #1
0
ファイル: RuntimeManager.cs プロジェクト: Eelazar/AGJ19
        void DrawDebugOverlay(int windowID)
        {
            if (lastDebugUpdate + 0.25f < Time.unscaledTime)
            {
                if (initException != null)
                {
                    lastDebugText = initException.Message;
                }
                else
                {
                    if (!mixerHead.hasHandle())
                    {
                        FMOD.ChannelGroup master;
                        lowlevelSystem.getMasterChannelGroup(out master);
                        master.getDSP(0, out mixerHead);
                        mixerHead.setMeteringEnabled(false, true);
                    }

                    StringBuilder debug = new StringBuilder();

                    FMOD.Studio.CPU_USAGE cpuUsage;
                    studioSystem.getCPUUsage(out cpuUsage);
                    debug.AppendFormat("CPU: dsp = {0:F1}%, studio = {1:F1}%\n", cpuUsage.dspusage, cpuUsage.studiousage);

                    int currentAlloc, maxAlloc;
                    FMOD.Memory.GetStats(out currentAlloc, out maxAlloc);
                    debug.AppendFormat("MEMORY: cur = {0}MB, max = {1}MB\n", currentAlloc >> 20, maxAlloc >> 20);

                    int realchannels, channels;
                    lowlevelSystem.getChannelsPlaying(out channels, out realchannels);
                    debug.AppendFormat("CHANNELS: real = {0}, total = {1}\n", realchannels, channels);

                    FMOD.DSP_METERING_INFO outputMetering;
                    mixerHead.getMeteringInfo(IntPtr.Zero, out outputMetering);
                    float rms = 0;
                    for (int i = 0; i < outputMetering.numchannels; i++)
                    {
                        rms += outputMetering.rmslevel[i] * outputMetering.rmslevel[i];
                    }
                    rms = Mathf.Sqrt(rms / (float)outputMetering.numchannels);

                    float db = rms > 0 ? 20.0f * Mathf.Log10(rms * Mathf.Sqrt(2.0f)) : -80.0f;
                    if (db > 10.0f)
                    {
                        db = 10.0f;
                    }

                    debug.AppendFormat("VOLUME: RMS = {0:f2}db\n", db);
                    lastDebugText   = debug.ToString();
                    lastDebugUpdate = Time.unscaledTime;
                }
            }

            GUI.Label(new Rect(10, 20, 290, 100), lastDebugText);
            GUI.DragWindow();
        }
コード例 #2
0
        // Initializes and returns the FMOD Resonance Audio Listener Plugin.
        private static FMOD.DSP Initialize()
        {
            // Search through all busses on in banks.
            int numBanks = 0;

            FMOD.DSP           dsp   = new FMOD.DSP();
            FMOD.Studio.Bank[] banks = null;
            RuntimeManager.StudioSystem.getBankCount(out numBanks);
            RuntimeManager.StudioSystem.getBankList(out banks);
            for (int currentBank = 0; currentBank < numBanks; ++currentBank)
            {
                int numBusses            = 0;
                FMOD.Studio.Bus[] busses = null;
                banks[currentBank].getBusCount(out numBusses);
                banks[currentBank].getBusList(out busses);
                RuntimeManager.StudioSystem.flushCommands();
                for (int currentBus = 0; currentBus < numBusses; ++currentBus)
                {
                    // Make sure the channel group of the current bus is assigned properly.
                    string busPath = null;
                    busses[currentBus].getPath(out busPath);
                    RuntimeManager.StudioSystem.getBus(busPath, out busses[currentBus]);
                    RuntimeManager.StudioSystem.flushCommands();
                    FMOD.ChannelGroup channelGroup;
                    busses[currentBus].getChannelGroup(out channelGroup);
                    RuntimeManager.StudioSystem.flushCommands();
                    if (channelGroup.hasHandle())
                    {
                        int numDsps = 0;
                        channelGroup.getNumDSPs(out numDsps);
                        for (int currentDsp = 0; currentDsp < numDsps; ++currentDsp)
                        {
                            channelGroup.getDSP(currentDsp, out dsp);
                            string dspNameSb;
                            int    unusedInt  = 0;
                            uint   unusedUint = 0;
                            dsp.getInfo(out dspNameSb, out unusedUint, out unusedInt, out unusedInt, out unusedInt);
                            if (dspNameSb.ToString().Equals(listenerPluginName) && dsp.hasHandle())
                            {
                                return(dsp);
                            }
                        }
                    }
                }
            }
            Debug.LogError(listenerPluginName + " not found in the FMOD project.");
            return(dsp);
        }