I am creating a C # script for sound filters in the Unity engine.
My problem is that after starting through my filter, the resulting sound has sequential and frequent “clicks”, “pops up” or “skips”. It is like an old radio.
I am not sure what causes this.
Here is my code:
public float cutoff; public float resonance; int sampleRate; void Start() { cutoff = 200; resonance = 1; sampleRate = AudioSettings.outputSampleRate; } void OnAudioFilterRead(float[] data, int channels) { float c = 2 * Mathf.PI * cutoff/sampleRate; float r = 1 / resonance; float v0 = 0; float v1 = 0; for (int i = 0; i < data.Length; i++) { v0 = (1 - r * c) * v0 - (c) * v1 + (c) * data[i]; v1 = (1 - r * c) * v1 + (c) * v0; data[i] = v1; } }
Here is the documentation for OnAudioFilterRead () .
Here I got the original bottom pass code .
When cropping approaches its maximum value (127), clicks and pop-ups become quieter.
I am new to the audio program, as this may be obvious, so I'm not sure what it would cause.
Can someone more knowledgeable than me explain what I'm doing wrong?
Thanks!
source share