usynth

simple midi synth for sndio
git clone git://nsmpr.xyz/usynth.git
Log | Files | Refs

commit c1e257d07042dd6435b5b6238c56e6b0ac119172
parent 13ee9dbb5659e65b375ba58cd883787a7dc3da49
Author: prenev <an2qzavok@gmail.com>
Date:   Thu,  8 Apr 2021 15:45:22 +0300

break things for the usynths sake

Diffstat:
MMakefile | 4++--
Mmachine.c | 18+++++++++---------
Mmachine.h | 5++---
Musynth.c | 20++++++++------------
4 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,8 +5,8 @@ OBJ = ${SRC:.c=.o} BIN = progsynth MAN = $(BIN).1 -OBJ = $(BIN:=.o) fm.o midi.o\ - machine.o operator.o wavetable.o +# OBJ = $(BIN:=.o) fm.o midi.o\ +# machine.o operator.o wavetable.o all: usynth diff --git a/machine.c b/machine.c @@ -2,8 +2,6 @@ #include <assert.h> #include <stdio.h> #include <stdint.h> -#include "operator.h" -#include "fm.h" #include "wavetable.h" #include "machine.h" #include "tune.h" @@ -49,20 +47,21 @@ int16_t sprog[] = { //I_LIT, 1, //I_OP|0x0000, //I_WAVE|0x0003, - I_NOTE, - I_2DT, - I_OP|0x0000, - I_WAVE|0x0000, + //I_NOTE, + //I_2DT, + //I_OP|0x0000, + //I_WAVE|0x0000, + //I_COMB, + //I_ADSR|0x0000, //I_COMB, - I_ADSR|0x0000, - I_COMB, I_HALT }; void -vm_set(VM *vm, Channel *channel, Voice *voice) +vm_set(VM *vm) { vm->prog = sprog; + vm->active = 0; } int16_t @@ -70,6 +69,7 @@ vm_run(VM *vm) { instruction inst; if (vm->prog == 0) return 0; + if (vm->active == 0) return 0; vm->halted = 0; vm->pc = 0; vm->sp = 0; diff --git a/machine.h b/machine.h @@ -21,6 +21,7 @@ enum { typedef struct VM VM; struct VM { + int active; int halted; int status; uint8_t key; @@ -30,12 +31,10 @@ struct VM { int16_t sp; int16_t *prog; int16_t pc; - Voice *voice; - Channel *channel; }; static VM vms[32]; -void vm_set(VM*, Channel*, Voice*); +void vm_set(VM*); int16_t vm_run(VM*); diff --git a/usynth.c b/usynth.c @@ -4,15 +4,16 @@ #include <stdint.h> #include <sndio.h> #include "midi.h" +#include "machine.h" struct sio_hdl *sh; size_t bs; int16_t *sbuf; +VM vm; 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) @@ -37,16 +38,17 @@ s_init(char *sdev) int main(void) { - s_init("rsnd/0"); - m_init("rmidi/0"); + s_init("snd/0"); + m_init("midithru/0"); m_vector.note_on = note_on; m_vector.note_off = note_off; + vm_set(&vm); while (1){ size_t n; m_read(); fillbuf(sbuf, bs * 2); - write(1, sbuf, B - + n = sio_write(sh, sbuf, bs * 2 * sizeof(int16_t)); + // write(1, sbuf, bs * 2 * sizeof(int16_t)); } } @@ -65,12 +67,6 @@ fillbuf(int16_t* buf, size_t n) { size_t i; for (i=0; i < n; i+=2) { - bif[i] = buf[i+1] = mix(); + buf[i] = buf[i+1] = vm_run(&vm); } } - -int16_t -mix(void) -{ - return 0; -}