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);
}
}