Too much DSP Load?

Hi, I’m just wanting to use a 16 tap delay in an OnAudioFilterRead function.
It’s taking about 3% of CPU according to the stats display. That seems far too much, all it does is this:-

Is there any way to make it faster? The buffer is just an array of floats.

int Modulus(int mod)
    {
        while (mod < 0)
        {
            mod = bufferSize - 1 + mod;
        }
        while (mod >= bufferSize)
        {
            mod -= bufferSize;
        }
        return mod;
    }

    void OnAudioFilterRead(float[] data, int channels)
    {

        for (int i = 0; i < data.Length; i+=channels)
        {
            float a = 0.0f;
            buffer[bufPos] = data;     //...Stick just the left hand sound into the buffer.

            for (int t = 0; t < numReflections; t++)
            {
                a = buffer[Modulus(bufPos - reflections[t].delay)];
                for (int ch = 0; ch < channels; ch++)
                {
                    data[i+ch] += a * reflections[t].volume[ch];
                }
            }

            bufPos = (bufPos + 1) % (bufferSize - 1);
        }
    }

So, I’m guessing that C# can’t do DSP very well at all then.
So it’s off to Native plug-ins for me! yay…

@DaveHoskins
Any further info on this?
Did you find a dll was more efficient or maybe there’s an overhead for the filter callback?

I seem to remember I called the native dll directly from that filter callback, and still got a 10X+ speedup.

1 Like