commit 531c33391dbd8c2d619d09cf5e41c9e9dfa272ad
parent 5b59813e2bdd8eadf0a126b88620b466c3d70a09
Author: zavok <an2qzavok@gmail.com>
Date: Wed, 6 Nov 2019 22:13:06 +0300
fixed phase modulation
Diffstat:
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/fm.c b/fm.c
@@ -40,8 +40,8 @@ fm_synth(struct voice *v)
if (v->velocity == 0) return 0;
ch = &fm_channels[v->channel];
dt = (double)(0xff00)*(tune[v->note%12] * (1 << (v->note/12)))/44100.0;
- out = op_fetch(&v->op[1], dt) * v->velocity / 0x7f;
- out += op_fetch(&v->op[0], dt) * v->velocity / 0x7f;
+ out = op_fetch(&v->op[1], dt*2, 0);
+ out = op_fetch(&v->op[0], dt*3, out) * v->velocity / 0x7f;
return out;
}
@@ -94,12 +94,12 @@ fm_note_on(uint8_t *mm)
v = &fm_voices[nmin];
v->op[0].p = 0;
v->op[0].conf.waveform = wavetable[1];
- v->op[0].conf.gain = 0x40;
+ v->op[0].conf.gain = 0xff;
v->op[0].conf.freq_multiplier = 1;
v->op[1].p = 0;
v->op[1].conf.waveform = wavetable[1];
- v->op[1].conf.gain = 0x40;
- v->op[1].conf.freq_multiplier = 1.01;
+ v->op[1].conf.gain = 0xff;
+ v->op[1].conf.freq_multiplier = 1;
v->id = nmax+1;
v->channel = mm[1];
v->note = mm[2];
diff --git a/operator.c b/operator.c
@@ -3,11 +3,11 @@
#include "operator.h"
int64_t
-op_fetch(struct op_state *op, size_t dp)
+op_fetch(struct op_state *op, size_t dp, int16_t mod)
{
uint8_t pos;
op->p += dp * op->conf.freq_multiplier;
- pos = op->p >> 8;
- return op->conf.waveform[pos] * op->conf.gain / 0x7f;
+ pos = (mod + op->p) >> 8;
+ return op->conf.waveform[pos] * op->conf.gain / 0xff;
}
diff --git a/operator.h b/operator.h
@@ -9,5 +9,5 @@ struct op_state {
size_t p;
};
-int64_t op_fetch(struct op_state*, size_t);
+int64_t op_fetch(struct op_state*, size_t, int16_t);