#include "synth.h"
#include <string.h>
#include <math.h>
+#include <stdio.h>
#include <stdlib.h>
float detune(float base, int coarse, int fine)
{
// 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:
{{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