diff -urN midi_prog-/Makefile midi_prog/Makefile --- midi_prog-/Makefile 2015-04-19 00:00:00.000000000 +0900 +++ midi_prog/Makefile 2015-04-20 00:00:00.000000000 +0900 @@ -6,15 +6,18 @@ OBJS += cui_tone.o CFLAGS += -Wall -I.. -all: $(TARG) +VCD_OBJS = vcd.o in.o filter.o out.o util.o + +all: $(TARG) vcd $(TARG): $(OBJS) $(CC) -o $@ $(OBJS) $(LIB) -#txprm: txprm.c util.o -# $(CC) -o $@ txprm.c util.o -lm +vcd: $(VCD_OBJS) + $(CC) -o $@ $(VCD_OBJS) -lm clean: rm -f $(TARG) $(OBJS) *~ + rm -f vcd $(VCD_OBJS) # EOF diff -urN midi_prog-/in.c midi_prog/in.c --- midi_prog-/in.c 1970-01-01 09:00:00.000000000 +0900 +++ midi_prog/in.c 2015-04-20 00:00:00.000000000 +0900 @@ -0,0 +1,13 @@ +#include "in.h" + +int +in_do(in_rec_t *inp, double *vp) +{ + int c = EOF; + + if((c = fgetc(inp->fp)) == EOF) return c; + if(inp->bit_len == 16) c |= fgetc(inp->fp) << 8; + if(c > inp->iv_max) c -= inp->iv_max * 2; + *vp = (double)(c - inp->base) / inp->amp; + return 0; +} diff -urN midi_prog-/in.h midi_prog/in.h --- midi_prog-/in.h 1970-01-01 09:00:00.000000000 +0900 +++ midi_prog/in.h 2015-04-20 00:00:00.000000000 +0900 @@ -0,0 +1,10 @@ +#ifndef __IN_H__ +#define __IN_H__ + +#include "out.h" + +typedef struct out_rec in_rec_t; + +int in_do(in_rec_t *inp, double *vp); + +#endif diff -urN midi_prog-/util.c midi_prog/util.c --- midi_prog-/util.c 2015-04-17 00:00:00.000000000 +0900 +++ midi_prog/util.c 2015-04-20 00:00:00.000000000 +0900 @@ -28,6 +28,15 @@ return strtol(s, NULL, 0); } +double +opt_double(char *key, int ac, char **av, double def) +{ + char *s; + + if((s = opt_str(key, ac, av, NULL)) == NULL) return def; + return strtod(s, NULL); +} + struct stklst * stklst_alloc(int size, struct stklst *prev) { diff -urN midi_prog-/util.h midi_prog/util.h --- midi_prog-/util.h 2015-04-17 00:00:00.000000000 +0900 +++ midi_prog/util.h 2015-04-20 00:00:00.000000000 +0900 @@ -17,6 +17,7 @@ int opt_idx(char *key, int ac, char **av); char *opt_str(char *key, int ac, char **av, char *def); int opt_int(char *key, int ac, char **av, int def); +double opt_double(char *key, int ac, char **av, double def); struct stklst{ diff -urN midi_prog-/vcd.c midi_prog/vcd.c --- midi_prog-/vcd.c 1970-01-01 09:00:00.000000000 +0900 +++ midi_prog/vcd.c 2015-04-20 00:00:00.000000000 +0900 @@ -0,0 +1,71 @@ +#include "util.h" +#include "in.h" +#include "filter.h" +#include "out.h" +#include "ch.h" + +struct vcd_rec{ + struct filter_rec fl; + struct filter_stat_rec stat; + struct out_rec *ot; + FILE *ofp; +} vcd_inf[ MIDI_CH_N ]; + +double +vcd_freq(int ch) +{ + int H = MIDI_CH_N / 2; + return ch < H ? + 500 + (1000.0 - 500) * ch / (H-1) : + 1500 + (3000.0 - 1500) * (ch-H) / (H-1); +} + +void +vcd_init(struct vcd_rec *vcd, int ch, double fl_Q, struct out_rec *ot, char *name) +{ + char fname[1024]; + + vcd->fl.type = BPF; + vcd->fl.freq = vcd_freq(ch); + vcd->fl.Q = fl_Q; + filter_init(&vcd->fl, &vcd->stat, ot->smp_t); + + vcd->ot = ot; + sprintf(fname, "%s-%d", name, ch); + vcd->ofp = fopen(fname, "w"); +} + +void +vcd_fini(struct vcd_rec *vcd) +{ + fclose(vcd->ofp); +} + +void +vcd_out(struct vcd_rec *vcd, double v) +{ + v = filter_out(&vcd->stat, v); + vcd->ot->fp = vcd->ofp; + out_do(vcd->ot, v); +} + +int +main(int ac, char **av) +{ + struct out_rec otr; + in_rec_t irec; + char *name = opt_str("-name", ac, av, "test"); + double v, fl_Q = opt_double("-Q", ac, av, 1.0); + int i; + + out_init(&otr, ac, av); + irec = otr; + irec.fp = stdin; + + for(i=0; i