calls blep every time
This commit is contained in:
parent
d6c8212410
commit
f527691deb
@ -111,6 +111,7 @@ void Chassis::noteOn(uint8_t note) {
|
|||||||
vPtr++;
|
vPtr++;
|
||||||
if (vPtr == NUM_VOICES) vPtr = 0;
|
if (vPtr == NUM_VOICES) vPtr = 0;
|
||||||
if (s.voice[vPtr].isFree()) {
|
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
|
// if it's an existing note don't reset
|
||||||
s.voice[vPtr].on(note, s.voice[i].note != note);
|
s.voice[vPtr].on(note, s.voice[i].note != note);
|
||||||
//printf("note on %d for voice %d\n", note, vPtr);
|
//printf("note on %d for voice %d\n", note, vPtr);
|
||||||
|
@ -19,19 +19,25 @@
|
|||||||
#include "voice.hpp"
|
#include "voice.hpp"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
static float blep(float phase, float theta) {
|
static float blep(float p, float theta) {
|
||||||
float t;
|
float t;
|
||||||
|
|
||||||
if (phase < theta) {
|
// low (late) side of step
|
||||||
t = phase / theta;
|
if (p < theta) {
|
||||||
|
//printf("phase < theta, %f %f\n", p, theta);
|
||||||
|
t = p / theta;
|
||||||
return (2 * t) - (t * t) - 1;
|
return (2 * t) - (t * t) - 1;
|
||||||
}
|
}
|
||||||
if (phase > (1 - theta)) {
|
// high (early) side of step
|
||||||
t = (phase - 1) / theta;
|
if (p > (1 - theta)) {
|
||||||
|
//printf("phase > 1-theta %f %f \n", p, theta);
|
||||||
|
t = (p - 1) / theta;
|
||||||
return (2 * t) + (t * t) + 1;
|
return (2 * t) + (t * t) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf("no action\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,15 +52,18 @@ void Voice::on(uint32_t key, bool reset = 0) {
|
|||||||
if (reset) env = 0;
|
if (reset) env = 0;
|
||||||
omega = (261.63 * powf(2, (note - 60) / 12.0f)) / 48000.0f;
|
omega = (261.63 * powf(2, (note - 60) / 12.0f)) / 48000.0f;
|
||||||
target = 1;
|
target = 1;
|
||||||
|
env = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::off() {
|
void Voice::off() {
|
||||||
keyState = K_OFF;
|
keyState = K_OFF;
|
||||||
// envState = RELEASE;
|
envState = RELEASE;
|
||||||
target = 0;
|
target = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::gate() {
|
void Voice::gate() {
|
||||||
|
/*
|
||||||
if (keyState == K_WAIT) {
|
if (keyState == K_WAIT) {
|
||||||
envState = ATTACK;
|
envState = ATTACK;
|
||||||
keyState = K_ON;
|
keyState = K_ON;
|
||||||
@ -65,21 +74,22 @@ void Voice::gate() {
|
|||||||
envState = RELEASE;
|
envState = RELEASE;
|
||||||
target = 0;
|
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) {
|
void Voice::run(Synth &s, float *buffer, uint32_t samples) {
|
||||||
float y, offset, pw = 0;
|
float y, offset, pw = 0;
|
||||||
env = ((target - env) * 0.01) + env;
|
|
||||||
|
|
||||||
s.p.sqr = 1;
|
s.p.sqr = 1;
|
||||||
s.p.saw = 1;
|
s.p.saw = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < samples; i++) {
|
for (uint32_t i = 0; i < samples; i++) {
|
||||||
// sawtooth
|
// sawtooth
|
||||||
y = 1 - (2 * phase);
|
y = 1 - (2 * phase);
|
||||||
y += blep(phase, omega);
|
// y += blep(phase, omega);
|
||||||
|
|
||||||
// need this if either saw or square is on;
|
// need this if either saw or square is on;
|
||||||
y *= (s.p.saw + s.p.sqr);
|
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;
|
if (offset > 1) offset -= 1;
|
||||||
|
|
||||||
y -= (1 - (2 * offset)) * s.p.sqr;
|
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;
|
// s.lastpw = pw_rc;
|
||||||
|
|
||||||
buffer[i] += (0.125 * y * env);
|
|
||||||
phase += omega;
|
phase += omega;
|
||||||
if (phase > 1) phase -= 1;
|
if (phase > 1) {
|
||||||
|
// printf("step\n");
|
||||||
|
phase -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[i] += (0.125 * y * env);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user