示例#1
0
    private RESULT myDSPCallback(ref DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels)
    {
        if (btn.interactable)
        {
            return(RESULT.OK);
        }
        buffer            = new float[length * inchannels];
        singleSampleRange = ((currentSampleRate / 2) / length); // nyquist
        float currentSample;

        int i = 0;

        try
        {
            for (i = 0; i < length * inchannels; i++)
            {
                //test dostepu pamieci
                var currentPtr = new IntPtr(inbuffer.ToInt32() + (i * sizeof(float)));
                currentSample = (float)System.Runtime.InteropServices.Marshal.PtrToStructure(
                    currentPtr, typeof(float));

                float sampleOutput;

                sampleOutput = wahwah.ProcessSample(currentSample, (i / inchannels), (i % inchannels), currentSampleRate, inchannels);
                sampleOutput = lowpass.ProcessSample(sampleOutput, (i / inchannels), (i % inchannels), currentSampleRate, inchannels);

                buffer[i] = sampleOutput;
            }

            //kopiujemy caly bufor do wskaznika data
            System.Runtime.InteropServices.Marshal.Copy(buffer, 0, outbuffer, (int)length * inchannels);
            outchannels = inchannels;
        }
        catch (NullReferenceException nre)
        {
            UnityEngine.Debug.Log("Samples broke at sample:" + i);
            throw new NullReferenceException(nre.Message);
        }

        catch (IndexOutOfRangeException ioore)
        {
            UnityEngine.Debug.Log("Samples broke at sample:" + i);
            throw new NullReferenceException(ioore.Message);
        }

        return(RESULT.OK);
    }