I am working again to implement an audio filter in Unity3d for flexible use in synths: C64 synth, speak and spell voice synth, ambient sounds synth… I didnt know unity has awesome audio DSP potential, all i need now is 2-3 filter functions to apply to a sound samples array,
i.e. var sound= new float[44100] is a 1 second sawtooth wave,
i want function bandpass(sound:float[ ] , cutoffrequency :float ) etc
So i have found a page full of commercially useable filter codes, but i don’t know very well what language they are written in and how to use them in Unity. I learnt to code in UnityScript and Reaktor DSP studio so i am not great a C#.
even the first lines: #include <stdlib.h> doesn’t compile
How can i implement a standard filter from here:
http://musicdsp.org/archive.php?classid=3#263
so i can work on some giant synths in unity with 20 oscillators and everything.
for example, this moog filter code is fairly clear, but i am not sure what the loop consists of, and how to apply it to array samples:
//Init
cutoff = cutoff freq in Hz
fs = sampling frequency //(e.g. 44100Hz)
res = resonance [0 - 1] //(minimum - maximum)
f = 2 * cutoff / fs; //[0 - 1]
k = 3.6*f - 1.6*f*f -1; //(Empirical tunning)
p = (k+1)*0.5;
scale = e^((1-p)*1.386249;
r = res*scale;
y4 = output;
y1=y2=y3=y4=oldx=oldy1=oldy2=oldy3=0;
//Loop
//--Inverted feed back for corner peaking
x = input - r*y4;
//Four cascaded onepole filters (bilinear transform)
y1=x*p + oldx*p - k*y1;
y2=y1*p+oldy1*p - k*y2;
y3=y2*p+oldy2*p - k*y3;
y4=y3*p+oldy3*p - k*y4;
//Clipper band limited sigmoid
y4 = y4 - (y4^3)/6;
oldx = x;
oldy1 = y1;
oldy2 = y2;
oldy3 = y3;