progsynth.c (1027B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <stdint.h> 5 #include <sndio.h> 6 #include "midi.h" 7 #include "operator.h" 8 #include "fm.h" 9 #include "machine.h" 10 11 struct sio_hdl *sh; 12 size_t bs; 13 int16_t *sbuf; 14 15 void 16 s_init(char *sdev) 17 { 18 struct sio_par par; 19 sh = sio_open(sdev, SIO_PLAY, 0); 20 sio_initpar(&par); 21 par.pchan = 2; 22 par.sig = 1; 23 par.bits = 16; 24 par.le = 1; 25 par.rate = 44100; 26 par.xrun = SIO_SYNC; 27 par.appbufsz = 1024; 28 sio_setpar(sh, &par); 29 sio_getpar(sh, &par); 30 //bs = 256 + par.round; 31 //bs -= bs % par.round; 32 bs = par.round; 33 sbuf = malloc(bs * 2 * sizeof(int16_t)); 34 sio_start(sh); 35 } 36 37 int 38 main(int argc, char **argv) 39 { 40 s_init("snd/0"); 41 m_init("midi/0"); 42 fm_init(); 43 m_vector.note_on = fm_key_on; 44 m_vector.note_off = fm_key_off; 45 m_vector.ctl_change = fm_ctl_change; 46 m_vector.prog_change = fm_prog_change; 47 while (1){ 48 size_t n; 49 m_read(); 50 fm_fillbuf(sbuf, bs * 2); 51 n = sio_write(sh, sbuf, bs * 2 * sizeof(int16_t)); 52 write (1, sbuf, bs * 2 * sizeof (int16_t)); 53 } 54 return 0; 55 } 56