diff --git a/makefile b/makefile index cc53ac6..f4f9516 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -CFLAGS = -fPIC +CFLAGS = -O3 -fPIC FLAGS = -shared TARGET = libsynth.so diff --git a/synth.c b/synth.c index 06515a2..85442c0 100644 --- a/synth.c +++ b/synth.c @@ -6,7 +6,13 @@ typedef double D; #define DO(n,stm) {I i=0,_n=(n); for(;i<_n;i++){stm}} #define DECL_ARR(t, v, l) t *v = malloc(sizeof(t)*(l)) +void filter11(I,D*,D,D); +void filter21(I,D*,D,D,D); +void filter32(I,D*,D,D,D,D,D); void filter(I length, D* a, I lx, D* xc, I ly, D* yc) { + if (lx==1 && ly==1) { return filter11(length,a,xc[0],yc[0]); } + if (lx==2 && ly==1) { return filter21(length,a,xc[0],xc[1],yc[0]); } + if (lx==3 && ly==2) { return filter32(length,a,xc[0],xc[1],xc[2],yc[0],yc[1]); } DECL_ARR(D, x, lx); DECL_ARR(D, y, ly); DO(lx, x[i]=0;); DO(ly, y[i]=0;); int j, ix=0, iy=0; @@ -17,6 +23,35 @@ void filter(I length, D* a, I lx, D* xc, I ly, D* yc) { DO(ly, a[j] += y[(iy+i)%ly] * yc[i];); y[iy++] = a[j]; iy%=ly; } + free(x); free(y); + return; +} + +void filter11(I length, D* a, D xc0, D yc0) { + D x0=0, y0=0; int j; + for (j=0; j