From: slack Date: Tue, 16 Jun 2009 18:09:05 +0000 (+0200) Subject: LPF/HPF changed. WIP X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=5979680a0e5b8aba287a753311a3d9cf9e48ee90;p=lolailo.git LPF/HPF changed. WIP --- diff --git a/lolailo.c b/lolailo.c index 8f4e484..6897770 100644 --- a/lolailo.c +++ b/lolailo.c @@ -75,9 +75,9 @@ void _start() { float v = drawbuf[i]; if (v>1.0f) v = 1.0f; - if (v<0.0f) v = 0.0f; + if (v<-1.0f) v = -1.0f; - int y1 = (1.0f-v)*479.0f; + int y1 = (1.0f-(v*0.5f+0.5f))*479.0f; float ymin, ymax; if (y0 < y1) { ymin=y0; ymax=y1; } else { ymin=y1; ymax=y0; } diff --git a/synth.c b/synth.c index bd1f3f1..cfd0d8c 100644 --- a/synth.c +++ b/synth.c @@ -1,6 +1,7 @@ #include "synth.h" #include #include +#include #include float detune(float base, int coarse, int fine) @@ -72,49 +73,28 @@ uint8 synth(Voice *v, int len, float *mix_buf) { // TODO: cutoff should be a wave // op1, op2: cutoff, resonance - float cutoff = detune(1.0f, op1, 0); - float r = (op2)/100.0f; - + float cutoff = v->waves[op1][i]; + float r = (op2)/5.0f; //printf("op1=%d, op2=%d, cutoff=%f; r=%f\n", op1, op2, cutoff, r); - float sample = v->waves[wave-1][i]; - - // Compute filter coefficients - float c, c2,a1,a2,b1,b2; - - // Extraemos algunos calculos que son redundantes en HP y LP - float param_tan = PI_samplerate * cutoff; - - if (ins==LPF) { // Low-pass - c=1.0f / tanf(param_tan); - c2 = c*c; - - a1 = 1.0f / ( 1.0f + r * c + c2); - a2 = 2.0f * a1; - b1 = 2.0f * ( 1.0f - c2) * a1; - } else { // High-pass - c = tanf(-param_tan); - c2 = c*c; - - a1 = 1.0f / ( 1.0f + r * c + c2); - a2 = -2*a1; - b1 = 2.0f * ( c2 - 1.0f) * a1; - } - - b2 = ( 1.0f - r*c + c2) * a1; - - // data [0,1,2] = y(0), y(-1), y(-2) - // data [3,4] = x(-1), x(-2) + float input = v->waves[wave-1][i]; float *data = (float*)v->data[wave]; - data[0] = a1*sample + a2*data[3] + a1*data[4] - - b1*data[1] - b2*data[2]; - - data[4]=data[3]; - data[3]=sample; - data[2]=data[1]; - data[1]=data[0]; - - v->waves[wave][i] = data[0]; + // data[0-3] == pole1..pole4 + // Arif Ove Karlsen's 24dB Ladder Approximation, 3.nov 2007 + // http://musicdsp.org/showArchiveComment.php?ArchiveID=141 + //printf("BEFORE: input=%f, pole1=%f, pole2=%f, pole3=%f, pole4=%f\n", input, data[0], data[1], data[2], data[3]); + float rez = data[3]*r; if (rez > 1) rez = 1; + input = input-rez; + data[0] = data[0] + ((-data[0]+input) * cutoff); + data[1] = data[1] + ((-data[1]+data[0]) * cutoff); + data[2] = data[2] + ((-data[2]+data[1]) * cutoff); + data[3] = data[3] + ((-data[3]+data[2]) * cutoff); + + if (ins == LPF) + v->waves[wave][i] = data[3]; + else + v->waves[wave][i] = data[3] - input; + //printf("AFTER: input=%f, pole1=%f, pole2=%f, pole3=%f, pole4=%f\n", input, data[0], data[1], data[2], data[3]); break; } default: diff --git a/thesong.c b/thesong.c index bbeda3e..6cc4a08 100644 --- a/thesong.c +++ b/thesong.c @@ -12,10 +12,10 @@ Song thesong={ {{45,0,0,0,43,0,0,0,41,0,0,0,40,0,0,0}, 0}, }, // end tracks { // begin instrument data - SINE,24,0, - SQUARE,0,10, - SUM,0,1, - LPF,100,10, + SINE,-80,0, + SQUARE,0,50, + LPF,0,6, + MUL,0,2, END, }, // end instrument data { // begin playlist