commit 13ee9dbb5659e65b375ba58cd883787a7dc3da49
parent 1303155d62f2321fcd424f6e28df453244227ca2
Author: prenev <an2qzavok@gmail.com>
Date: Wed, 24 Feb 2021 13:29:46 +0300
commit some initial work on new usynth
Diffstat:
10 files changed, 117 insertions(+), 27 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,35 +1,36 @@
-.POSIX:
+include config.mk
-PREFIX = /usr/local
-MANDIR = $(PREFIX)/share/man/man1
+SRC = usynth.c fm.c machine.c midi.c operator.c wavetable.c
+OBJ = ${SRC:.c=.o}
BIN = progsynth
MAN = $(BIN).1
OBJ = $(BIN:=.o) fm.o midi.o\
machine.o operator.o wavetable.o
-LDFLAGS=-lsndio -lm
+all: usynth
-all: $(BIN)
+.c.o:
+ ${CC} -c ${CFLAGS} $<
-$(BIN): $(OBJ)
- $(CC) $(OBJ) $(LDFLAGS) $(LIBS) -o $@
+${OBJ}:
-$(OBJ): fm.h midi.h operator.h wavetable.h
+usynth: ${OBJ}
+ ${CC} -o $@ ${OBJ} ${LDFLAGS}
-install: $(BIN)
- mkdir -p $(DESTDIR)$(PREFIX)/bin/
- cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin/
- chmod 555 $(DESTDIR)$(PREFIX)/bin/$(BIN)
- mkdir -p $(DESTDIR)$(MANDIR)
- cp -f $(MAN) $(DESTDIR)$(MANDIR)
+install: all
+ mkdir -p ${DESTDIR}${PREFIX}/bin/
+ cp -f usynth $(DESTDIR)${PREFIX}/bin/
+ chmod 755 ${DESTDIR}${PREFIX}/bin/pcmprint
+ mkdir -p ${DESTDIR}${MANPREFIX}/man1
+ cp -f usynth.1 ${DESTDIR}${MANPREFIX}/man1/pcmprint.1
+ chmod 644 ${DESTDIR}${MANPREFIX}/man1/pcmprint.1
uninstall:
- rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
- rm -f $(DESTDIR)$(MANDIR)/$(MAN)
+ rm -f ${DESTDIR}${PREFIX}/bin/usynth\
+ ${DESTDIR}${MANDIR}/usynth.1
clean:
- rm -f $(BIN) $(OBJ)
+ rm -f usynth ${OBJ}
-.c.o:
- $(CC) $(CFLAGS) -c $<
+.PHONY: all clean instal uninstall
diff --git a/config.mk b/config.mk
@@ -0,0 +1,12 @@
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+INCS =
+LIBS = -lsndio -lm
+
+CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L
+CFLAGS = -g -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
+LDFLAGS = ${LIBS}
+
+CC = cc
+
diff --git a/fm.c b/fm.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include "operator.h"
#include "wavetable.h"
#include "fm.h"
diff --git a/fm.h b/fm.h
@@ -18,8 +18,8 @@ struct Channel {
int16_t pitch;
};
-Channel fm_channels[16];
-Voice fm_voices[32];
+static Channel fm_channels[16];
+static Voice fm_voices[32];
int64_t fm_synth(Voice*);
int16_t fm_mix(void);
diff --git a/machine.c b/machine.c
@@ -97,7 +97,7 @@ void
vm_fatal(VM* vm, char *errstr)
{
dprintf(2, "VM FATAL: %s\n", errstr);
- dprintf(2, "pc = \n", vm->pc);
+ dprintf(2, "pc = %d\n", vm->pc);
exit(-1);
}
diff --git a/machine.h b/machine.h
@@ -34,7 +34,7 @@ struct VM {
Channel *channel;
};
-VM vms[32];
+static VM vms[32];
void vm_set(VM*, Channel*, Voice*);
int16_t vm_run(VM*);
diff --git a/midi.h b/midi.h
@@ -10,7 +10,7 @@ struct Mvector {
void(*sys_message)(uint8_t*);
};
-Mvector m_vector;
+static Mvector m_vector;
void m_init(char *mdev);
void m_read(void);
diff --git a/progsynth.c b/progsynth.c
@@ -37,8 +37,8 @@ s_init(char *sdev)
int
main(int argc, char **argv)
{
- s_init("rsnd/0");
- m_init("rmidi/0");
+ s_init("snd/0");
+ m_init("midi/0");
fm_init();
m_vector.note_on = fm_key_on;
m_vector.note_off = fm_key_off;
diff --git a/usynth.c b/usynth.c
@@ -0,0 +1,76 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sndio.h>
+#include "midi.h"
+
+struct sio_hdl *sh;
+size_t bs;
+int16_t *sbuf;
+
+void note_on(uint8_t*);
+void note_off(uint8_t*);
+void fillbuf(int16_t*, size_t);
+int16_t mix(void);
+
+void
+s_init(char *sdev)
+{
+ struct sio_par par;
+ sh = sio_open(sdev, SIO_PLAY, 0);
+ sio_initpar(&par);
+ par.pchan = 2;
+ par.sig = 1;
+ par.bits = 16;
+ par.le = 0;
+ par.rate = 44100;
+ par.xrun = SIO_SYNC;
+ par.appbufsz = 1024;
+ sio_setpar(sh, &par);
+ sio_getpar(sh, &par);
+ bs = par.round;
+ sbuf = malloc(bs * 2 * sizeof(int16_t));
+ sio_start(sh);
+}
+
+int
+main(void)
+{
+ s_init("rsnd/0");
+ m_init("rmidi/0");
+ m_vector.note_on = note_on;
+ m_vector.note_off = note_off;
+ while (1){
+ size_t n;
+ m_read();
+ fillbuf(sbuf, bs * 2);
+ write(1, sbuf, B
+
+ }
+}
+
+void
+note_on(uint8_t *m)
+{
+}
+
+void
+note_off(uint8_t *m)
+{
+}
+
+void
+fillbuf(int16_t* buf, size_t n)
+{
+ size_t i;
+ for (i=0; i < n; i+=2) {
+ bif[i] = buf[i+1] = mix();
+ }
+}
+
+int16_t
+mix(void)
+{
+ return 0;
+}
diff --git a/wavetable.h b/wavetable.h
@@ -1,5 +1,5 @@
#define WT_LENGTH 256
#define WT_SIZE 8
-int16_t **wavetable;
+static int16_t **wavetable;
void wt_init(void);