diff -urN midi_prog-/rawmix2.c midi_prog/rawmix2.c --- midi_prog-/rawmix2.c Sat Aug 29 00:00:00 2015 +++ midi_prog/rawmix2.c Tue Sep 1 00:00:00 2015 @@ -55,6 +55,7 @@ for(i=0; ien) continue; if(m->in.fp == NULL){ fprintf(stderr, "i=%d fn=%s\n", i, m->in.fn); ERR("Can't open"); diff -urN midi_prog-/tool.c midi_prog/tool.c --- midi_prog-/tool.c Fri Aug 28 00:00:00 2015 +++ midi_prog/tool.c Tue Sep 1 00:00:00 2015 @@ -80,16 +80,53 @@ struct pitdet *pd; int note; double on_sec; + int pre_release; + int cut_over_tone; } note_onoff[ NOTE_N ]; void -note_onoff_init(struct note_onoff *nto, struct pitdet *pd, int note, int lmt_sec) +note_onoff_init(struct note_onoff *nto, struct pitdet *pd, int note, int ac, char **av) { + double lmt_sec = opt_double("-lmt_sec", ac, av, 2.0/32); chatt_init(&nto->ct, lmt_sec); abuf_init(&nto->ab, pd->tick_freq, 2*4*4); nto->pd = pd; nto->note = note; nto->on_sec = -1; + nto->pre_release = opt_double("-pre_release", ac, av, 0); + nto->cut_over_tone = opt_idx("-cut_over_tone", ac, av) > 0; +} + +int +note_onoff_velo(struct note_onoff *nto, double on_sec, double off_sec) +{ + double v = abuf_mean(&nto->ab, on_sec, off_sec); + int velo = (int)(128 * v / nto->pd->max_v); + if(velo < 0) velo = 0; + if(velo > 127) velo = 127; + return velo; +} + +int +note_onoff_is_overtone(struct note_onoff *nto, double on_sec, double off_sec, int velo) +{ + /* Fundamental, Overtone */ + + int lst[] = { 12, 12+7, 12*2, 12*2+4, 12*2+7 }; + int lst_n = ARR_N(lst); + int i, t; + + for(i=0; inote - lst[i]) < 0) continue; + funda = ¬e_onoff[t]; /* ! */ + velo_f = note_onoff_velo(funda, on_sec, off_sec); + + if(velo_f >= velo * 0.7) return 1; + } + return 0; } void @@ -113,11 +150,14 @@ off_sec = nto->ct.sec; nto->on_sec = -1; - v = abuf_mean(&nto->ab, on_sec, off_sec); - - velo = (int)(128 * v / nto->pd->max_v); - if(velo <= 0) return; - if(velo > 127) velo = 127; + if(nto->pre_release > 0){ + int off_lmt = on_sec + nto->ct.lmt_sec; + off_sec -= nto->pre_release; + if(off_sec < off_lmt) off_sec = off_lmt; + } + + if((velo = note_onoff_velo(nto, on_sec, off_sec)) == 0) return; + if(nto->cut_over_tone && note_onoff_is_overtone(nto, on_sec, off_sec, velo)) return; tick = pitdet_sec_to_tick(nto->pd, on_sec); printf("abs=%08d %s ch=%d note=%d velo=%d\n", @@ -163,13 +203,12 @@ 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); int sec, s; in_init(&in, ac, av, NULL); pitdet_init(&pd, in.smp_freq, ac, av); - for(i=0; i 0){ int j;