commit 5b59813e2bdd8eadf0a126b88620b466c3d70a09
parent 3506acd641e4bb48d2302d03564ce88db96bd041
Author: zavok <an2qzavok@gmail.com>
Date: Tue, 5 Nov 2019 21:27:47 +0300
some minor changes
Diffstat:
2 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
@@ -5,7 +5,7 @@ MANDIR = $(PREFIX)/share/man/man1
BIN = usynth
MAN = $(BIN).1
-OBJ = $(BIN:=.o) audio.o fm.o midi.o operator.o
+OBJ = $(BIN:=.o) audio.o fm.o midi.o operator.o wavetable.o
LDFLAGS=-lsndio
@@ -14,7 +14,7 @@ all: $(BIN)
$(BIN): $(OBJ)
$(CC) $(OBJ) $(LDFLAGS) $(LIBS) -o $@
-$(OBJ): audio.c fm.c midi.c operator.c usynth.c
+$(OBJ): audio.c fm.c midi.c operator.c usynth.c wavetable.c
install: $(BIN)
mkdir -p $(DESTDIR)$(PREFIX)/bin/
diff --git a/fm.c b/fm.c
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include "fm.h"
#include "operator.h"
-
+#include "wavetable.h"
#include "tune.h"
size_t c;
@@ -27,21 +27,21 @@ struct channel{
struct channel fm_channels[16];
struct voice fm_voices[32];
-int16_t *triangle;
-
int64_t fm_synth(struct voice*);
int16_t fm_mix(void);
int64_t
fm_synth(struct voice *v)
{
+ struct channel *ch;
size_t dt;
int64_t out;
if (v->id < 0) return 0;
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);
- out = op_fetch(&v->op[0], dt + out) * v->velocity / 0x7f;
+ out = op_fetch(&v->op[1], dt) * v->velocity / 0x7f;
+ out += op_fetch(&v->op[0], dt) * v->velocity / 0x7f;
return out;
}
@@ -92,12 +92,14 @@ fm_note_on(uint8_t *mm)
if (fm_voices[i].id>fm_voices[nmax].id) nmax = i;
}
v = &fm_voices[nmin];
- v->op[0].conf.waveform = triangle;
- v->op[0].conf.gain = 0x7f;
+ v->op[0].p = 0;
+ v->op[0].conf.waveform = wavetable[1];
+ v->op[0].conf.gain = 0x40;
v->op[0].conf.freq_multiplier = 1;
- v->op[1].conf.waveform = triangle;
- v->op[1].conf.gain = 0x1f;
- v->op[1].conf.freq_multiplier = 0.5;
+ 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->id = nmax+1;
v->channel = mm[1];
v->note = mm[2];
@@ -133,13 +135,7 @@ void
fm_init(void)
{
int i;
- int16_t d;
- triangle = malloc(sizeof(int16_t) * 0xff);
- d = 0;
- for (i=0x00; i<0x40; i++) triangle[i] = d+=0x01ff;
- for (i=0x40; i<0x80; i++) triangle[i] = d-=0x01ff;
- for (i=0x80; i<0xc0; i++) triangle[i] = d-=0x01ff;
- for (i=0xc0; i<0xff; i++) triangle[i] = d+=0x01ff;
+ wt_init();
for (i=0; i<16; i++){
struct channel *ch;
ch = &fm_channels[i];