usynth

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

commit 428fdf59a82f5b9315caaaaca136292dfc0f00d1
parent 9f9e9c13f0a360b87a353e9bae81a34c7cf1c8eb
Author: zavok <an2qzavok@gmail.com>
Date:   Sun, 29 Dec 2019 13:51:43 +0300

brand new day, brand new commit

Diffstat:
MMakefile | 3++-
Amachine.c | 0
Amachine.h | 0
Mmidi.h | 5+++--
Musynth.c | 7++-----
Awavetable.c | 40++++++++++++++++++++++++++++++++++++++++
Awavetable.h | 5+++++
7 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,7 +5,8 @@ MANDIR = $(PREFIX)/share/man/man1 BIN = usynth MAN = $(BIN).1 -OBJ = $(BIN:=.o) audio.o fm.o midi.o operator.o wavetable.o +OBJ = $(BIN:=.o) audio.o fm.o midi.o \ + machine.o operator.o wavetable.o LDFLAGS=-lsndio diff --git a/machine.c b/machine.c diff --git a/machine.h b/machine.h diff --git a/midi.h b/midi.h @@ -1,4 +1,5 @@ -struct m_vector{ +typedef struct Mvector Mvector; +struct Mvector { void(*note_on)(uint8_t*); void(*note_off)(uint8_t*); void(*key_pressure)(uint8_t*); @@ -9,7 +10,7 @@ struct m_vector{ void(*sys_message)(uint8_t*); }; -struct m_vector m_vector; +Mvector m_vector; void m_init(char *mdev); void m_read(void); diff --git a/usynth.c b/usynth.c @@ -12,7 +12,7 @@ size_t bs; int16_t *sbuf; void -sinit(void) +s_init(void) { char *sdev = "rsnd/0";//SIO_DEVANY; struct sio_par par; @@ -30,8 +30,6 @@ sinit(void) //bs = 256 + par.round; //bs -= bs % par.round; bs = par.round; - printf("bufsz=%d\nappbufsz=%d\nround=%d\nbs=%lu\n", - par.bufsz, par.appbufsz, par.round, bs); sbuf = malloc(bs * 2 * sizeof(int16_t)); sio_start(sh); } @@ -39,14 +37,13 @@ sinit(void) int main(int argc, char **argv) { - sinit(); + s_init(); m_init("rmidi/0"); fm_init(); m_vector.note_on = fm_note_on; m_vector.note_off = fm_note_off; m_vector.ctl_change = fm_ctl_change; m_vector.prog_change = fm_prog_change; - printf("entering main loop\n"); while (1){ size_t n; m_read(); diff --git a/wavetable.c b/wavetable.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include "wavetable.h" + +void wt_triangle(int16_t*); +void wt_sin(int16_t*); +void wt_pulse(int16_t*); +void wt_saw(int16_t*); + +void +wt_init(void) +{ + int i; + wavetable = malloc(sizeof(int16_t*) * WT_SIZE); + for (i=0;i<8;i++) wavetable[i] = malloc(sizeof(int16_t) * WT_LENGTH); + //wt_sin(wavetable[0]); + wt_triangle(wavetable[1]); + wt_pulse(wavetable[2]); +} + +void +wt_triangle(int16_t* w) +{ + size_t i, pos; + for (i=0; i<WT_LENGTH; i++){ + pos = (i-WT_LENGTH/4)%WT_LENGTH; + if (i < WT_LENGTH/2) w[pos] = -0x7fff + 0xffff*i/WT_LENGTH; + else w[pos] = 0x7fff - 0xffff*i/WT_LENGTH; + } +} + +void +wt_pulse(int16_t* w) +{ + size_t i; + for (i=0; i<WT_LENGTH; i++) + if (i < WT_LENGTH/2) w[i] = 0x7fff; + else w[i] = -0x7fff; +} diff --git a/wavetable.h b/wavetable.h @@ -0,0 +1,5 @@ +#define WT_LENGTH 0x100 +#define WT_SIZE 8 +int16_t **wavetable; + +void wt_init(void);