// 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);
        }
Exemple #2
0
        private static FMOD.RESULT READCALLBACK(ref FMOD.DSP_STATE dsp_state, IntPtr inbuf, IntPtr outbuf, uint length, int inchannels, int outchannels)
        {
            uint   count, temp = 0;
            int    count2, temp1 = 0;
            IntPtr thisdspraw = dsp_state.instance;

            thisdsp.setRaw(thisdspraw);

            /*
             *  This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to
             *  call a DSP information function.
             */
            StringBuilder name = new StringBuilder();

            thisdsp.getInfo(name, ref temp, ref temp1, ref temp1, ref temp1);

            /*
             *  This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0'
             *  as the number of channels in FMOD_DSP_DESCRIPTION.
             *  Specifying an actual channel count will mean you have to take care of any number of channels coming in,
             *  but outputting the number of channels specified.  Generally it is best to keep the channel
             *  count at 0 for maximum compatibility.
             */
            unsafe
            {
                float *inbuffer  = (float *)inbuf.ToPointer();
                float *outbuffer = (float *)outbuf.ToPointer();

                for (count = 0; count < length; count++)
                {
                    /*
                     *  Feel free to unroll this.
                     */
                    for (count2 = 0; count2 < outchannels; count2++)
                    {
                        /*
                         *  This DSP filter just halves the volume!
                         *  Input is modified, and sent to output.
                         */
                        outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2] * 0.2f;
                    }
                }
            }

            return(FMOD.RESULT.OK);
        }