calls blep every time

This commit is contained in:
Gordon JC Pearce 2024-09-06 20:04:56 +01:00
parent d6c8212410
commit f527691deb
2 changed files with 30 additions and 13 deletions

View File

@ -111,6 +111,7 @@ void Chassis::noteOn(uint8_t note) {
vPtr++;
if (vPtr == NUM_VOICES) vPtr = 0;
if (s.voice[vPtr].isFree()) {
//printf("voice %d is free, existing note = %d, note = %d\n", vPtr, s.voice[i].note, note);
// if it's an existing note don't reset
s.voice[vPtr].on(note, s.voice[i].note != note);
//printf("note on %d for voice %d\n", note, vPtr);

View File

@ -19,19 +19,25 @@
#include "voice.hpp"
#include <math.h>
#include <cstdio>
static float blep(float phase, float theta) {
static float blep(float p, float theta) {
float t;
if (phase < theta) {
t = phase / theta;
// low (late) side of step
if (p < theta) {
//printf("phase < theta, %f %f\n", p, theta);
t = p / theta;
return (2 * t) - (t * t) - 1;
}
if (phase > (1 - theta)) {
t = (phase - 1) / theta;
// high (early) side of step
if (p > (1 - theta)) {
//printf("phase > 1-theta %f %f \n", p, theta);
t = (p - 1) / theta;
return (2 * t) + (t * t) + 1;
}
//printf("no action\n");
return 0;
}
@ -46,15 +52,18 @@ void Voice::on(uint32_t key, bool reset = 0) {
if (reset) env = 0;
omega = (261.63 * powf(2, (note - 60) / 12.0f)) / 48000.0f;
target = 1;
env = 1;
}
void Voice::off() {
keyState = K_OFF;
// envState = RELEASE;
envState = RELEASE;
target = 0;
}
void Voice::gate() {
/*
if (keyState == K_WAIT) {
envState = ATTACK;
keyState = K_ON;
@ -65,21 +74,22 @@ void Voice::gate() {
envState = RELEASE;
target = 0;
}
env = target; //((target - env) * 0.01) + env;
*/
env = ((target - env) * 0.005f) + env;
}
void Voice::run(Synth &s, float *buffer, uint32_t samples) {
float y, offset, pw = 0;
env = ((target - env) * 0.01) + env;
s.p.sqr = 1;
s.p.saw = 1;
for (uint32_t i = 0; i < samples; i++) {
// sawtooth
y = 1 - (2 * phase);
y += blep(phase, omega);
// y += blep(phase, omega);
// need this if either saw or square is on;
y *= (s.p.saw + s.p.sqr);
@ -93,11 +103,17 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) {
if (offset > 1) offset -= 1;
y -= (1 - (2 * offset)) * s.p.sqr;
y -= blep(offset, omega) * s.p.sqr;
// y -= blep(offset, omega) * s.p.sqr;
// s.lastpw = pw_rc;
buffer[i] += (0.125 * y * env);
phase += omega;
if (phase > 1) phase -= 1;
if (phase > 1) {
// printf("step\n");
phase -= 1;
}
buffer[i] += (0.125 * y * env);
}
}