different way of antialiasing

This commit is contained in:
Gordon JC Pearce 2024-09-04 00:26:02 +01:00
parent 8e9b6adf86
commit 152b0c62a5
2 changed files with 35 additions and 8 deletions

View File

@ -55,14 +55,39 @@ void Voice::off() {
}
void Voice::run(Synth &s, float *buffer, uint32_t samples) {
float y;
env = ((target - env) * 0.01) + env;
float y, t;
env = ((target - env) * 0.1) + env;
for (uint32_t i = 0; i < samples; i++) {
phase += omega;
if (phase > 1) phase -= 1;
y = (2 * phase) - 1;
y -= blep(phase, omega);
buffer[i] += (0.25 * y * env) * s.p.saw;
// prepare the delay slot
out = delay;
delay = 0;
phase += omega;
//delay = 1-(2*phase);
if (phase > 1.0f) {
phase -= 1.0f;
t = phase / omega;
out -= (t*t*t) - 0.5 * (t*t*t*t);
//delay -= (2 * t) - (t * t) - 1;
t = 1-(phase / omega);
delay = (t*t*t) - 0.5 * (t*t*t*t);
//out -= (2*t) + (t*t) + 1;
}
delay += (phase);
y = 0.5 * (out-0.5) * env;// * s.p.saw;
// y -= blep(phase, omega);
buffer[i] += y;// (0.25 * y * env) * s.p.saw;
}
}

View File

@ -30,7 +30,7 @@ class Patch {
class Voice {
public:
uint8_t note;
uint8_t note = 72;
void on(uint32_t key, bool reset);
@ -50,6 +50,8 @@ class Voice {
K_SUSTAIN } keyState = K_OFF;
float phase, omega;
float env, target;
float out, delay;
};
class Synth {