Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback for the DSP unit
        /// </summary>
        /// <param name="dsp_state"></param>
        /// <param name="inbuffer"></param>
        /// <param name="outbuffer"></param>
        /// <param name="length"></param>
        /// <param name="inchannels"></param>
        /// <param name="outchannels"></param>
        /// <returns></returns>
        FMOD.RESULT myDSPCallback(ref FMOD.DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels)
        {
            //getting unsafe here to handle raw pointers to the buffer
            unsafe
            {
                //create raw pointers for the buffers
                float *outBuff = (float *)outbuffer.ToPointer();
                float *inBuff  = (float *)inbuffer.ToPointer();

                for (uint samp = 0; samp < length; samp++)
                {
                    //assumes in channels is the same as out channels
                    for (int chan = 0; chan < outchannels; chan++)
                    {
                        //all we are doing in this DSP is pumping the input to the output,
                        //and copying the sample to a buffer we can read for visualizations
                        outBuff[(samp * outchannels) + chan] = inBuff[(samp * inchannels) + chan];
                    }
                }

                //length of the buffer
                var bufferLength = (length * outchannels);

                //create a buffer if we don't have one, or if the length has changed.
                if (_sampleBuffer == null || _sampleBuffer.Length != bufferLength)
                {
                    //create new instance of the buffer
                    _sampleBuffer = new float[bufferLength];
                }

                //copy outbuffer to our sample buffer
                Marshal.Copy(outbuffer, _sampleBuffer, 0, _sampleBuffer.Length);
            }

            //return ok
            return(FMOD.RESULT.OK);
        }