diff -urN midi_prog-/in.c midi_prog/in.c --- midi_prog-/in.c Fri Aug 7 00:00:00 2015 +++ midi_prog/in.c Fri Aug 28 00:00:00 2015 @@ -1,12 +1,13 @@ #include "in.h" void -in_init(in_rec_t *inp, int ac, char **av) +in_init(in_rec_t *inp, int ac, char **av, char *ifn) { struct out_rec otr; out_init(&otr, ac, av); *inp = otr; - inp->fp = stdin; + if(ifn == NULL) ifn = "-i"; + inp->fp = fp_get(ifn, ac, av, "-", "r"); } int diff -urN midi_prog-/in.h midi_prog/in.h --- midi_prog-/in.h Fri Aug 7 00:00:00 2015 +++ midi_prog/in.h Fri Aug 28 00:00:00 2015 @@ -5,7 +5,7 @@ typedef struct out_rec in_rec_t; -void in_init(in_rec_t *inp, int ac, char **av); +void in_init(in_rec_t *inp, int ac, char **av, char *ifn); int in_do(in_rec_t *inp, double *vp); int in_do2(in_rec_t *inp, double *vp); int in_do_mono(in_rec_t *inp, double *vp); diff -urN midi_prog-/midtxt.c midi_prog/midtxt.c --- midi_prog-/midtxt.c Thu Jun 25 00:00:00 2015 +++ midi_prog/midtxt.c Fri Aug 28 00:00:00 2015 @@ -429,15 +429,20 @@ int def_ch = opt_int("-ch", ac, av, 0); int def_velo = opt_int("-velo", ac, av, 100); int len, len_on, ch, note, velo, delta, l_ac, i; - char buf[BUFSZ], lbuf[BUFSZ], *l_av[AVSZ], notes_buf[BUFSZ], note_buf[BUFSZ]; + + //char buf[BUFSZ], lbuf[BUFSZ], *l_av[AVSZ], notes_buf[BUFSZ], note_buf[BUFSZ]; + char buf[BUFSZ], *l_av[AVSZ], notes_buf[BUFSZ], note_buf[BUFSZ]; + char *len_buf, *vp, *notes_str, *chord_str, *sla, *np; while(fgets(buf, sizeof(buf), stdin)){ if(buf[0] == '#' || buf[0] == ';' || buf[0] == '\n' || buf[0] == '\0') continue; - strcpy(lbuf, buf); + //strcpy(lbuf, buf); l_ac = ARR_N(l_av); - line_to_ac_av(lbuf, &l_ac, l_av); + + //line_to_ac_av(lbuf, &l_ac, l_av); + line_to_ac_av(buf, &l_ac, l_av); if((len_buf = opt_prefix("len=", l_ac, l_av)) == NULL){ fputs(buf, stdout); diff -urN midi_prog-/out.c midi_prog/out.c --- midi_prog-/out.c Tue Jun 9 00:00:00 2015 +++ midi_prog/out.c Fri Aug 28 00:00:00 2015 @@ -32,7 +32,7 @@ ot->sign = (opt_idx("-u", ac, av) < 0); ot->ch_num = opt_int("-c", ac, av, 2); - ot->fp = stdout; + ot->fp = fp_get("-o", ac, av, "-", "w"); cmd[0] = '\0'; fn = ""; if(opt_idx("-play", ac, av) >= 0){ @@ -82,6 +82,14 @@ { int i; for(i=0; ich_num; i++) out_do(ot, vp[i]); +} + +void +out_show_info(struct out_rec *ot) +{ + fprintf(stderr, "smp_freq=%d smp_cnt=%d bit_len=%d sign=%d ch_num=%d fp=%s\n", + ot->smp_freq, ot->smp_cnt, ot->bit_len, ot->sign, ot->ch_num, + ot->fp == stdout ? "stdout" : ot->fp == stdin ? "stdin ???" : "(file)"); } /* EOF */ diff -urN midi_prog-/out.h midi_prog/out.h --- midi_prog-/out.h Wed Apr 29 00:00:00 2015 +++ midi_prog/out.h Fri Aug 28 00:00:00 2015 @@ -21,4 +21,6 @@ void out_do(struct out_rec *ot, double v); void out_do2(struct out_rec *ot, double *vp); +void out_show_info(struct out_rec *ot); + #endif diff -urN midi_prog-/pitdet.c midi_prog/pitdet.c --- midi_prog-/pitdet.c Thu Aug 27 00:00:00 2015 +++ midi_prog/pitdet.c Fri Aug 28 00:00:00 2015 @@ -13,14 +13,19 @@ } void -pitdet_init(struct pitdet *pd, double smp_freq, int adj_cent, - int div, double tick_freq, double abuf_wsec, double thres) +pitdet_init(struct pitdet *pd, double smp_freq, int ac, char **av) { int j; - pd->div = div; - pd->adj_cent = adj_cent; - pd->m = pd->div * 128; + pd->div = opt_int("-div", ac, av, 1); + pd->adj_cent = opt_int("-adj_cent", ac, av, 0); + pd->abuf_wsec = opt_double("-abuf_wsec", ac, av, 2*4*4); + pd->thres = opt_double("-thres", ac, av, 0.01); + pd->lmt_sec = opt_double("-pd_lmt_sec", ac, av, -1); + pd->shadow_cut_en = opt_int("-shadow_cut_en", ac, av, 1); + pd->tick_freq = opt_double("-tick_freq", ac, av, 2*96); + + pd->m = pd->div * NOTE_N; if((pd->arr = malloc(sizeof(*pd->arr) * pd->m)) == NULL) ERR("No Mem"); for(j=0; jm; j++){ @@ -30,7 +35,9 @@ double next_freq = pitdet_note_to_freq(pd, next_note); int wn = (int) pitch_wn(freq, next_freq); - pitch_init(&pd->arr[j], smp_freq, freq, wn, tick_freq, abuf_wsec); + if(pd->lmt_sec > 0) while(wn > 1 && wn / (2 * freq) > pd->lmt_sec) wn--; + + pitch_init(&pd->arr[j], smp_freq, freq, wn, pd->tick_freq, pd->abuf_wsec); } pd->oldest.sec = -1; @@ -39,7 +46,6 @@ pd->newest.update = 0; pd->max_v = -1; - pd->thres = thres; if((pd->wk = malloc(sizeof(*pd->wk) * pd->m)) == NULL) ERR("No Mem"); } @@ -50,12 +56,14 @@ int j; for(j=0; jm; j++){ - double v; - int onoff = pitdet_onoff(pd, sec, j, &v); + double v = tbuf_get_dbl(&pd->arr[j].ab.tb, sec); + int onoff = pitdet_onoff_judge(pd, v); pd->wk[j].stat = onoff ? 0 : -1; - if(onoff) pd->wk[j].v = v; + pd->wk[j].v = onoff ? v : -1; } + if(!pd->shadow_cut_en) return; + while(1){ int t = -1; double v_max = 0; @@ -94,12 +102,6 @@ if(!pitdet_onoff_judge(pd, pd->wk[j].v)) pd->wk[j].stat = -1; } } - - for(j=0; jm; j++){ - struct pitch *p = &pd->arr[j]; - double v = pd->wk[j].stat >= 0 ? pd->wk[j].v : -1; - tbuf_set_dbl(&p->ab.tb, sec, v); - } } void @@ -115,17 +117,17 @@ pitch_add(p, v); sec = tbuf_oldest_sec(&p->ab.tb); - if(osec < 0 || sec > osec) osec = sec; + if(osec == -1 || sec > osec) osec = sec; sec = tbuf_newest_sec(&p->ab.tb); - if(nsec < 0 || sec < nsec) nsec = sec; + if(nsec == -1 || sec < nsec) nsec = sec; if(p->ab.max_v > pd->max_v) pd->max_v = p->ab.max_v; } if((pd->oldest.update = (pd->oldest.sec != osec)) != 0) pd->oldest.sec = osec; if((pd->newest.update = (pd->newest.sec != nsec)) != 0) pd->newest.sec = nsec; - if(pd->oldest.update && pd->oldest.sec >= 0) shadow_cut(pd, pd->oldest.sec); + if(pd->newest.update && pd->newest.sec >= 0) shadow_cut(pd, pd->newest.sec); } int @@ -139,12 +141,4 @@ pitdet_onoff_judge(struct pitdet *pd, double v) { return v / pd->max_v >= pd->thres; -} - -int -pitdet_onoff(struct pitdet *pd, double sec, int j, double *ret_v) -{ - double v = tbuf_get_dbl(&pd->arr[j].ab.tb, sec); - if(ret_v) *ret_v = v; - return pitdet_onoff_judge(pd, v); } diff -urN midi_prog-/pitdet.h midi_prog/pitdet.h --- midi_prog-/pitdet.h Thu Aug 27 12:53:34 2015 +++ midi_prog/pitdet.h Fri Aug 28 00:00:00 2015 @@ -3,9 +3,17 @@ #include "pitch.h" +#define NOTE_N 128 + struct pitdet{ int div; int adj_cent; + double abuf_wsec; + double thres; + double lmt_sec; + int shadow_cut_en; + double tick_freq; + int m; struct pitch *arr; @@ -15,7 +23,6 @@ } oldest, newest; double max_v; - double thres; struct{ int stat; @@ -26,13 +33,10 @@ double pitdet_note_to_freq(struct pitdet *pd, double note); double pitdet_freq_to_note(struct pitdet *pd, double freq); -void pitdet_init(struct pitdet *pd, double smp_freq, int adj_cent, - int div, double tick_freq, double abuf_wsec, double thres); - +void pitdet_init(struct pitdet *pd, double smp_freq, int ac, char **av); void pitdet_add(struct pitdet *pd, double v); int pitdet_sec_to_tick(struct pitdet *pd, double sec); int pitdet_onoff_judge(struct pitdet *pd, double v); -int pitdet_onoff(struct pitdet *pd, double sec, int j, double *ret_v); #endif diff -urN midi_prog-/rawmix2.c midi_prog/rawmix2.c --- midi_prog-/rawmix2.c Tue Aug 25 00:00:00 2015 +++ midi_prog/rawmix2.c Fri Aug 28 00:00:00 2015 @@ -5,33 +5,33 @@ int main(int ac, char **av) { - FILE *fp_l = fp_get("-l", ac, av, "-", "r"); - FILE *fp_r = fp_get("-r", ac, av, "-", "r"); - FILE *fp_o = fp_get("-o", ac, av, "-", "w"); struct out_rec otr; in_rec_t in_l, in_r; - if(fp_l == NULL || fp_r == NULL || fp_o == NULL) ERR("Can't open"); + char *l_opt = opt_str("-L", ac, av, NULL); + char *r_opt = opt_str("-R", ac, av, NULL); + char *l_av[ AVSZ ], *r_av[ AVSZ ]; + int l_ac = AVSZ, r_ac = AVSZ; + opt_show(ac, av); + + line_to_ac_av(l_opt, &l_ac, l_av); + line_to_ac_av(r_opt, &r_ac, r_av); + + in_init(&in_l, l_ac, l_av, NULL); + in_init(&in_r, r_ac, r_av, NULL); out_init(&otr, ac, av); - otr.fp = fp_o; - in_init(&in_l, ac, av); - in_l.fp = fp_l; - in_l.ch_num = 1; - - in_init(&in_r, ac, av); - in_r.fp = fp_r; - in_r.ch_num = 1; + out_show_info(&otr); + + if(in_l.fp == NULL || in_r.fp == NULL || otr.fp == NULL) ERR("Can't open"); while(1){ double v[2]; - if(in_do(&in_l, &v[0]) == EOF) break; - if(in_do(&in_r, &v[1]) == EOF) break; + if(in_do_mono(&in_l, &v[0]) == EOF) break; + if(in_do_mono(&in_r, &v[1]) == EOF) break; out_do2(&otr, v); } - - fclose(fp_l); - fclose(fp_r); + fclose(otr.fp); return 0; } diff -urN midi_prog-/tool.c midi_prog/tool.c --- midi_prog-/tool.c Thu Aug 27 00:00:00 2015 +++ midi_prog/tool.c Fri Aug 28 00:00:00 2015 @@ -54,7 +54,7 @@ { int j, js, je; char s[32]; - double sec = pd->oldest.sec; + double sec = pd->newest.sec; sprintf(s, "sec=%f ", sec); printf("%s", s); @@ -62,8 +62,7 @@ show_spectre_modify_area(pd, ac, av, s, &js, &je); for(j=js; jarr[j]; - double v = tbuf_get_dbl(&p->ab.tb, sec); + double v = pd->wk[j].v; int iv = (int)(10 * v / pd->max_v); if(iv < 0) iv = -1; @@ -75,43 +74,6 @@ putchar('\n'); } -#define NOTE_N 128 - -struct chatt{ - double lmt_sec, sec, chg_try_sec; - int onoff; -}; - -void -chatt_init(struct chatt *ct, double lmt_sec) -{ - ct->lmt_sec = lmt_sec; - ct->sec = 0; - ct->chg_try_sec = -1; - ct->onoff = 0; -} - -int -chatt_add(struct chatt *ct, double sec, int onoff) -{ - if(onoff == ct->onoff){ - ct->chg_try_sec = -1; - return 0; - } - if(sec - ct->sec < ct->lmt_sec) return 0; - - if(ct->chg_try_sec < 0){ - ct->chg_try_sec = sec; - return 0; - } - if(sec - ct->chg_try_sec < ct->lmt_sec) return 0; - - ct->sec = ct->chg_try_sec; - ct->onoff = onoff; - ct->chg_try_sec = -1; - return 1; -} - struct note_onoff{ struct chatt ct; struct abuf ab; @@ -121,10 +83,10 @@ } note_onoff[ NOTE_N ]; void -note_onoff_init(struct note_onoff *nto, double lmt_sec, double tick_freq, struct pitdet *pd, int note) +note_onoff_init(struct note_onoff *nto, struct pitdet *pd, int note, int lmt_sec) { chatt_init(&nto->ct, lmt_sec); - abuf_init(&nto->ab, tick_freq, 2*4*4); + abuf_init(&nto->ab, pd->tick_freq, 2*4*4); nto->pd = pd; nto->note = note; nto->on_sec = -1; @@ -171,7 +133,7 @@ static void midi_out(struct pitdet *pd) { - double sec = pd->oldest.sec; + double sec = pd->newest.sec; int i, k; int ch = 0; @@ -180,7 +142,8 @@ double sum = 0, v; for(k=0; kdiv; k++){ int j = i * pd->div + k; - int o = pitdet_onoff(pd, sec, j, &v); + v = pd->wk[j].v; + int o = pitdet_onoff_judge(pd, v); onoff |= o; if(o) sum += v; } @@ -197,32 +160,36 @@ int i; struct pitdet pd; - int adj_cent = opt_int("-adj_cent", ac, av, 0); - int div = opt_int("-div", ac, av, 1); - double abuf_wsec = opt_double("-abuf_wsec", ac, av, 2.5); - double tick_freq = opt_double("-tick_freq", ac, av, 2*96); int show = opt_idx("-show", ac, av) > 0; int midi = opt_idx("-midi", ac, av) > 0; int abuf_wsec_chk = opt_idx("-abuf_wsec_chk", ac, av) > 0; double lmt_sec = opt_double("-lmt_sec", ac, av, 2.0/32); - double thres = opt_double("-thres", ac, av, 0.1); int sec, s; - in_init(&in, ac, av); - pitdet_init(&pd, in.smp_freq, adj_cent, div, tick_freq, abuf_wsec, thres); + in_init(&in, ac, av, NULL); + pitdet_init(&pd, in.smp_freq, ac, av); + + for(i=0; i 0){ + int j; + for(j=0; jfreq, p->wn, p->sb.tb.wsec); + } + } while(in_do_mono(&in, &v) != EOF){ pitdet_add(&pd, v); - if(!pd.oldest.update) continue; + if(!pd.newest.update) continue; - if((s = (int)pd.oldest.sec) != sec){ + if((s = (int)pd.newest.sec) != sec){ sec = s; fprintf(stderr, "%d sec \r", sec); } - if(pd.oldest.sec < 0) continue; + if(pd.newest.sec < 0) continue; if(show) show_spectre(&pd, ac, av); if(midi) midi_out(&pd); diff -urN midi_prog-/util.c midi_prog/util.c --- midi_prog-/util.c Tue Aug 25 00:00:00 2015 +++ midi_prog/util.c Fri Aug 28 00:00:00 2015 @@ -1,11 +1,19 @@ #include "util.h" +void +opt_show(int ac, char **av) +{ + int i; + fprintf(stderr, "ac=%d\n", ac); + for(i=0; ilmt_sec = lmt_sec; + ct->sec = 0; + ct->chg_try_sec = -1; + ct->onoff = 0; +} + +int +chatt_add(struct chatt *ct, double sec, int onoff) +{ + if(onoff == ct->onoff){ + ct->chg_try_sec = -1; + return 0; + } + if(sec - ct->sec < ct->lmt_sec) return 0; + + if(ct->chg_try_sec < 0){ + ct->chg_try_sec = sec; + return 0; + } + if(sec - ct->chg_try_sec < ct->lmt_sec) return 0; + + ct->sec = ct->chg_try_sec; + ct->onoff = onoff; + ct->chg_try_sec = -1; + return 1; } /* EOF */ diff -urN midi_prog-/util.h midi_prog/util.h --- midi_prog-/util.h Tue Aug 25 00:00:00 2015 +++ midi_prog/util.h Fri Aug 28 00:00:00 2015 @@ -20,6 +20,7 @@ #define MAX(a, b) ( (a) > (b) ? (a) : (b) ) #define MIN(a, b) ( (a) < (b) ? (a) : (b) ) +void opt_show(int ac, char **av); 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); @@ -46,5 +47,14 @@ int dbl_max_idx(double *p, int next_bytes, int n, double *ret_v); FILE *fp_get(char *key, int ac, char **av, char *def_fn, char *mode); + + +struct chatt{ + double lmt_sec, sec, chg_try_sec; + int onoff; +}; + +void chatt_init(struct chatt *ct, double lmt_sec); +int chatt_add(struct chatt *ct, double sec, int onoff); #endif diff -urN midi_prog-/voco.c midi_prog/voco.c --- midi_prog-/voco.c Tue Aug 25 00:00:00 2015 +++ midi_prog/voco.c Fri Aug 28 00:00:00 2015 @@ -98,11 +98,11 @@ out_init(&otr, ac, av); otr.fp = fp_get("-o", ac, av, "-", "w"); - in_carrier = in_voice = otr; - if((in_carrier.fp = fp_get("-carrier", ac, av, NULL, "r")) == NULL){ + in_init(&in_carrier, ac, av, "-carrier"); + if(in_carrier.fp == NULL){ vco_init(&vco, ac, av); } - in_voice.fp = fp_get("-voice", ac, av, NULL, "r"); + in_init(&in_voice, ac, av, "-voice"); if((voco_inf = malloc(sizeof(*voco_inf) * band.n)) == NULL) ERR("No Mem"); for(i=0; i