|
|
|
@ -5,8 +5,8 @@
|
|
|
|
|
#include "osc.h"
|
|
|
|
|
#include "env.h"
|
|
|
|
|
#include "filter.h"
|
|
|
|
|
#include "voice.h"
|
|
|
|
|
#include "control.h"
|
|
|
|
|
#include "voice.h"
|
|
|
|
|
#include "engine.h"
|
|
|
|
|
#include "psyn.h"
|
|
|
|
|
#include "rng.h"
|
|
|
|
@ -27,18 +27,12 @@ void voice_init(struct voice_t *voice, double freq)
|
|
|
|
|
// bw_filter_init_lp(&voice->bw[0], _engine.lowpass.value, 1.0);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < VOICE_OSCILLATORS; i++) {
|
|
|
|
|
voice->osc[i].shape = _engine.osc_shape[i].value;
|
|
|
|
|
voice->osc[i].level = _engine.osc_level[i].value;
|
|
|
|
|
}
|
|
|
|
|
voice->osc[i].shape = _engine.params[i].shape.value;
|
|
|
|
|
voice->osc[i].level = _engine.params[i].level.value;
|
|
|
|
|
|
|
|
|
|
osc_setfreq(&voice->osc[0], freq);
|
|
|
|
|
osc_setphase(&voice->osc[0], 0.0);
|
|
|
|
|
osc_setfreq(&voice->osc[1], freq);// * 1.4983);
|
|
|
|
|
osc_setphase(&voice->osc[1], 0.25);
|
|
|
|
|
osc_setfreq(&voice->osc[2], freq * 2);
|
|
|
|
|
osc_setphase(&voice->osc[2], 0.0);
|
|
|
|
|
osc_setfreq(&voice->osc[3], 2500.0);
|
|
|
|
|
osc_setphase(&voice->osc[3], 0.0);
|
|
|
|
|
osc_setfreq(&voice->osc[i], freq * _engine.params[i].freq_mult.value);
|
|
|
|
|
osc_setphase(&voice->osc[i], _engine.params[i].phase.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void voice_tick(struct voice_t *voice)
|
|
|
|
@ -54,37 +48,34 @@ static inline void voice_tick(struct voice_t *voice)
|
|
|
|
|
void voice_run(struct voice_t *voice, uint32_t samples, float *left, float *right)
|
|
|
|
|
{
|
|
|
|
|
// uint32_t pos;
|
|
|
|
|
double amplitude;
|
|
|
|
|
double l;
|
|
|
|
|
double r;
|
|
|
|
|
int i;
|
|
|
|
|
double a[VOICE_OSCILLATORS];
|
|
|
|
|
double l = 0.0;
|
|
|
|
|
double r = 0.0;
|
|
|
|
|
|
|
|
|
|
//for (pos = 0; pos < samples; pos++) {
|
|
|
|
|
voice_tick(voice);
|
|
|
|
|
|
|
|
|
|
amplitude = env_getamplitude(&_env, voice->sample, voice->released);
|
|
|
|
|
double amplitude = 0.0;
|
|
|
|
|
for (i = 0; i < VOICE_OSCILLATORS; i++) {
|
|
|
|
|
a[i] = env_getamplitude(&_engine.params[i].env, voice->sample, voice->released);
|
|
|
|
|
amplitude += a[i];
|
|
|
|
|
a[i] *= voice->velocity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (amplitude <= 0.0001) {
|
|
|
|
|
voice->playing = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
amplitude *= voice->velocity;
|
|
|
|
|
|
|
|
|
|
float s;
|
|
|
|
|
|
|
|
|
|
s = osc_getsample(&voice->osc[0]);
|
|
|
|
|
l = amplitude * s;// * (1.0 + rng() * 0.25);
|
|
|
|
|
r = amplitude * s;// * (1.0 + rng() * 0.25);
|
|
|
|
|
|
|
|
|
|
s = osc_getsample(&voice->osc[1]);
|
|
|
|
|
l += amplitude * s;
|
|
|
|
|
r += amplitude * s;
|
|
|
|
|
for (i = 0; i < VOICE_OSCILLATORS; i++) {
|
|
|
|
|
float s = osc_getsample(&voice->osc[i]);
|
|
|
|
|
|
|
|
|
|
s = osc_getsample(&voice->osc[2]);
|
|
|
|
|
l += amplitude * s;
|
|
|
|
|
r += amplitude * s;
|
|
|
|
|
// Mix
|
|
|
|
|
l += a[i] * s;
|
|
|
|
|
r += a[i] * s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = osc_getsample(&_engine.osc[0]);
|
|
|
|
|
// Amplitude mod
|
|
|
|
|
// l *= 1.0 + s;
|
|
|
|
|
// r *= 1.0 + s;
|
|
|
|
@ -109,7 +100,7 @@ void voice_run(struct voice_t *voice, uint32_t samples, float *left, float *righ
|
|
|
|
|
|
|
|
|
|
double out_l, out_r;
|
|
|
|
|
|
|
|
|
|
double cutoff = max(env_getamplitude(&_env2, voice->sample, 0), _engine.aftertouch.value) * 8000.0;
|
|
|
|
|
double cutoff = max(env_getamplitude(&_engine.cutoff_env, voice->sample, 0), _engine.aftertouch.value) * 8000.0;
|
|
|
|
|
bw_filter_init_lp(&voice->bw[0], _engine.lowpass.value + cutoff, 1.0);
|
|
|
|
|
bw_filter_run(&voice->bw[0], l, r, &out_l, &out_r);
|
|
|
|
|
// filter_run_lp(&voice->fil[0], l, r);
|
|
|
|
|