diff -urN midi_prog-/buf.c midi_prog/buf.c --- midi_prog-/buf.c 2015-09-11 00:00:00.000000000 +0900 +++ midi_prog/buf.c 2015-09-30 00:00:00.000000000 +0900 @@ -303,7 +303,7 @@ tbuf_init(&ab->tb, smp_freq, wsec, is_complex); ab->max_v = 0; ab->sum = 0; - ab->type = 0; + ab->type = ABUF_TYPE_ABUF; } void @@ -366,109 +366,102 @@ return tv; } - -/* a2buf */ - -void -a2buf_init(struct a2buf *a2b, struct abuf *a, struct abuf *b, - double A2, double B2, double AB, double A, double B, double C) +double +abuf_get_by_type(struct abuf *ab, double sec) { - struct abuf *c = a ? a : b; + if(!ab) return 0; - a2b->a = a; - a2b->b = b; - a2b->A2 = A2; - a2b->B2 = B2; - a2b->AB = AB; - a2b->A = A; - a2b->B = B; - a2b->C = C; - - a2b->ab.type = 1; - - a2b->tb = c->type == 0 ? &c->tb : ((struct a2buf *)c)->tb; -} - -static double -a2buf_abuf_get(struct abuf *ab, double sec) -{ - return ab->type == 0 ? abuf_get(ab, sec) : a2buf_get( (struct a2buf *)ab, sec); + switch(ab->type){ + case ABUF_TYPE_ABUF: + return abuf_get(ab, sec); + case ABUF_TYPE_A2BUF: + return a2buf_get( (struct a2buf *)ab, sec); + case ABUF_TYPE_ABUF_N: + return abuf_n_get( (struct abuf_n *)ab, sec); + default: + break; + } + ERR("unkown abuf type"); } -double -a2buf_get(struct a2buf *a2b, double sec) +struct tbuf * +abuf_get_tbuf_by_type(struct abuf *ab) { - double v_a = a2b->a ? a2buf_abuf_get(a2b->a, sec) : 0; - double v_b = a2b->b ? a2buf_abuf_get(a2b->b, sec) : 0; - double sum = a2b->C; - - if(a2b->A != 0 && v_a != 0) sum += a2b->A * v_a; - if(a2b->B != 0 && v_b != 0) sum += a2b->B * v_b; - - if(a2b->AB != 0 && v_a != 0 && v_b != 0) sum += a2b->AB * v_a * v_b; - - if(a2b->A2 != 0 && v_a != 0) sum += a2b->A2 * v_a * v_a; - if(a2b->B2 != 0 && v_b != 0) sum += a2b->B2 * v_b * v_b; + if(!ab) return NULL; - return sum; + switch(ab->type){ + case ABUF_TYPE_ABUF: + return &ab->tb; + case ABUF_TYPE_A2BUF: + return ( (struct a2buf *)ab )->tb; + case ABUF_TYPE_ABUF_N: + return ( (struct abuf_n *)ab )->tb; + default: + break; + } + ERR("unkown abuf type"); } double -a2buf_sum(struct a2buf *a2b, double from_sec, double to_sec, int *ret_n) +abuf_sum_by_type(struct abuf *ab, double from_sec, double to_sec, int *ret_n) { - struct tbuf *tb = a2b->tb; - int i, from_i, to_i, n = tbuf_from_to_num(tb, from_sec, to_sec, &from_i, &to_i); + struct tbuf *tb = abuf_get_tbuf_by_type(ab); + int i, from_i, to_i, n; double sum = 0; + + if(!tb) return 0; + + n = tbuf_from_to_num(tb, from_sec, to_sec, &from_i, &to_i); if(ret_n) *ret_n = n; for(i=from_i; i 0 ? sum / n : 0; } double -a2buf_stdev(struct a2buf *a2b, double from_sec, double to_sec, int *ret_n, double *ret_mean) +abuf_stdev_by_type(struct abuf *ab, double from_sec, double to_sec, int *ret_n, double *ret_mean) { - double mean = a2buf_mean(a2b, from_sec, to_sec, ret_n); + double mean = abuf_mean_by_type(ab, from_sec, to_sec, ret_n); struct a2buf t, t2; if(ret_mean) *ret_mean = mean; - a2buf_init(&t, &a2b->ab, NULL, 0,0,0,1,0,mean); + a2buf_init(&t, ab, NULL, 0,0,0,1,0,-mean); a2buf_init(&t2, &t.ab, NULL, 1,0,0,0,0,0); - return sqrt(a2buf_mean(&t2, from_sec, to_sec, NULL)); + return sqrt(abuf_mean_by_type(&t2.ab, from_sec, to_sec, NULL)); } double -a2buf_correlation(struct a2buf *a2b_a, struct a2buf *a2b_b, double from_sec, double to_sec, int *ret_n) +abuf_correlation_by_type(struct abuf *a, struct abuf *b, double from_sec, double to_sec, int *ret_n) { - double mean_a, stdev_a = a2buf_stdev(a2b_a, from_sec, to_sec, ret_n, &mean_a); - double mean_b, stdev_b = a2buf_stdev(a2b_b, from_sec, to_sec, NULL, &mean_b); + double mean_a, stdev_a = abuf_stdev_by_type(a, from_sec, to_sec, ret_n, &mean_a); + double mean_b, stdev_b = abuf_stdev_by_type(b, from_sec, to_sec, NULL, &mean_b); double div = stdev_a * stdev_b; struct a2buf ta, tb, t; if(div == 0) return 0; - a2buf_init(&ta, &a2b_a->ab, NULL, 0,0,0,1,0,mean_a); - a2buf_init(&tb, &a2b_b->ab, NULL, 0,0,0,1,0,mean_b); + a2buf_init(&ta, a, NULL, 0,0,0,1,0,-mean_a); + a2buf_init(&tb, b, NULL, 0,0,0,1,0,-mean_b); a2buf_init(&t, &ta.ab, &tb.ab, 0,0,1,0,0,0); - return a2buf_mean(&t, from_sec, to_sec, NULL) / div; + return abuf_mean_by_type(&t.ab, from_sec, to_sec, NULL) / div; } double -a2buf_corr_k(struct a2buf *a2b_a, struct a2buf *a2b_b, double from_sec, double to_sec, int *ret_n) +abuf_corr_k_by_type(struct abuf *a, struct abuf *b, double from_sec, double to_sec, int *ret_n) { - double stdev_a = a2buf_stdev(a2b_a, from_sec, to_sec, ret_n, NULL); - double stdev_b = a2buf_stdev(a2b_b, from_sec, to_sec, NULL, NULL); + double stdev_a = abuf_stdev_by_type(a, from_sec, to_sec, ret_n, NULL); + double stdev_b = abuf_stdev_by_type(b, from_sec, to_sec, NULL, NULL); double k_r = 0; double k_l = stdev_b / stdev_a * 1.2; // !!! double k, v; @@ -476,11 +469,80 @@ do{ k = (k_l + k_r) * 0.5; - a2buf_init(&t, &a2b_a->ab, &a2b_b->ab, 0,0,0,-k,1,0); - v = a2buf_correlation(a2b_a, &t, from_sec, to_sec, NULL); - + a2buf_init(&t, a, b, 0,0,0,-k,1,0); + v = abuf_correlation_by_type(a, &t.ab, from_sec, to_sec, NULL); if(v < 0) k_l = k; else k_r = k; - }while(ABS(v) > 0.001); // !!! + //fprintf(stderr, "k_l=%f k=%f k_r=%f v=%f\n", k_l, k, k_r, v); + }while(ABS(v) > 0.001 && k_l - k_r > 0.001); // !!! return k; } + + +/* a2buf */ + +void +a2buf_init(struct a2buf *a2b, struct abuf *a, struct abuf *b, + double A2, double B2, double AB, double A, double B, double C) +{ + struct abuf *c = a ? a : b; + + a2b->ab.type = ABUF_TYPE_A2BUF; + + a2b->a = a; + a2b->b = b; + a2b->A2 = A2; + a2b->B2 = B2; + a2b->AB = AB; + a2b->A = A; + a2b->B = B; + a2b->C = C; + + a2b->tb = abuf_get_tbuf_by_type(c); +} + +double +a2buf_get(struct a2buf *a2b, double sec) +{ + double v_a = abuf_get_by_type(a2b->a, sec); + double v_b = abuf_get_by_type(a2b->b, sec); + double sum = a2b->C; + + if(a2b->A != 0 && v_a != 0) sum += a2b->A * v_a; + if(a2b->B != 0 && v_b != 0) sum += a2b->B * v_b; + + if(a2b->AB != 0 && v_a != 0 && v_b != 0) sum += a2b->AB * v_a * v_b; + + if(a2b->A2 != 0 && v_a != 0) sum += a2b->A2 * v_a * v_a; + if(a2b->B2 != 0 && v_b != 0) sum += a2b->B2 * v_b * v_b; + + return sum; +} + + +/* abuf_n */ + +void +abuf_n_init(struct abuf_n *ab_n, struct abuf **lst, int n) +{ + int i; + + if(n > ABUF_N_MAX) ERR("Over ABUF_N_MAX"); + + ab_n->ab.type = ABUF_TYPE_ABUF_N; + + if(lst) for(i=0; ip[i] = lst[i]; + ab_n->n = n; + + ab_n->tb = NULL; + for(i=0; itb; i++) ab_n->tb = abuf_get_tbuf_by_type(ab_n->p[i]); +} + +double +abuf_n_get(struct abuf_n *ab_n, double sec) +{ + int i; + double sum = 0; + for(i=0; in; i++) sum += abuf_get_by_type(ab_n->p[i], sec); + return sum; +} diff -urN midi_prog-/buf.h midi_prog/buf.h --- midi_prog-/buf.h 2015-09-11 00:00:00.000000000 +0900 +++ midi_prog/buf.h 2015-09-30 00:00:00.000000000 +0900 @@ -78,6 +78,11 @@ double complex sbuf_sum_mean_all(struct sbuf *sb); +#define ABUF_TYPE_ABUF 0 +#define ABUF_CORR_MID 0.4 +#define ABUF_CORR_STRONG 0.7 +#define ABUF_CORR_JUDGE ABUF_CORR_MID + struct abuf{ struct tbuf tb; double max_v; @@ -92,6 +97,16 @@ double abuf_mean(struct abuf *ab, double from_sec, double to_sec, int *ret_n); double abuf_max(struct abuf *ab, double from_sec, double to_sec, double *ret_sec); +double abuf_get_by_type(struct abuf *ab, double sec); +struct tbuf *abuf_get_tbuf_by_type(struct abuf *ab); +double abuf_sum_by_type(struct abuf *ab, double from_sec, double to_sec, int *ret_n); +double abuf_mean_by_type(struct abuf *ab, double from_sec, double to_sec, int *ret_n); +double abuf_stdev_by_type(struct abuf *ab, double from_sec, double to_sec, int *ret_n, double *ret_mean); +double abuf_correlation_by_type(struct abuf *a, struct abuf *b, double from_sec, double to_sec, int *ret_n); +double abuf_corr_k_by_type(struct abuf *a, struct abuf *b, double from_sec, double to_sec, int *ret_n); + + +#define ABUF_TYPE_A2BUF 1 struct a2buf{ struct abuf ab, *a, *b; @@ -105,10 +120,17 @@ double A2, double B2, double AB, double A, double B, double C); double a2buf_get(struct a2buf *a2b, double sec); -double a2buf_sum(struct a2buf *a2b, double from_sec, double to_sec, int *ret_n); -double a2buf_mean(struct a2buf *a2b, double from_sec, double to_sec, int *ret_n); -double a2buf_stdev(struct a2buf *a2b, double from_sec, double to_sec, int *ret_n, double *ret_mean); -double a2buf_correlation(struct a2buf *a2b_a, struct a2buf *a2b_b, double from_sec, double to_sec, int *ret_n); -double a2buf_corr_k(struct a2buf *a2b_a, struct a2buf *a2b_b, double from_sec, double to_sec, int *ret_n); + +#define ABUF_TYPE_ABUF_N 2 +#define ABUF_N_MAX 100 + +struct abuf_n{ + struct abuf ab, *p[ ABUF_N_MAX ]; + struct tbuf *tb; + int n; +}; + +void abuf_n_init(struct abuf_n *ab_n, struct abuf **lst, int n); +double abuf_n_get(struct abuf_n *ab_n, double sec); #endif diff -urN midi_prog-/pitch.c midi_prog/pitch.c --- midi_prog-/pitch.c 2015-09-25 00:00:00.000000000 +0900 +++ midi_prog/pitch.c 2015-09-30 00:00:00.000000000 +0900 @@ -123,6 +123,7 @@ p->wn = wn; sbuf_init(&p->sb, smp_freq, pitch_wsec(p->freq, wn)); abuf_init(&p->ab, tick_freq, abuf_wsec); + abuf_init(&p->ab_bak, tick_freq, abuf_wsec); onoff_stat_init(&p->ost, &p->ab, ac, av); } @@ -137,6 +138,8 @@ sbuf_add(&p->sb, v * cexp(-arg)); if(tbuf_is_over_sec(&p->ab.tb, sec - stb->wsec * 0.5)){ - abuf_add(&p->ab, cabs( sbuf_sum_mean_all(&p->sb) ) ); + double v = cabs( sbuf_sum_mean_all(&p->sb) ); + abuf_add(&p->ab, v); + abuf_add(&p->ab_bak, v); } } diff -urN midi_prog-/pitch.h midi_prog/pitch.h --- midi_prog-/pitch.h 2015-09-25 00:00:00.000000000 +0900 +++ midi_prog/pitch.h 2015-09-30 00:00:00.000000000 +0900 @@ -24,7 +24,7 @@ double freq; int wn; struct sbuf sb; - struct abuf ab; + struct abuf ab, ab_bak; struct onoff_stat ost; }; diff -urN midi_prog-/pitdet.c midi_prog/pitdet.c --- midi_prog-/pitdet.c 2015-09-27 00:00:00.000000000 +0900 +++ midi_prog/pitdet.c 2015-09-30 00:00:00.000000000 +0900 @@ -113,6 +113,7 @@ for(j=0; jm; j++){ double v = MAX(pd->wk[j].v, 0); tbuf_set_dbl(&pd->arr[j].ab.tb, sec, v); + tbuf_set_dbl(&pd->arr[j].ab_bak.tb, sec, v); } } @@ -182,46 +183,65 @@ struct corr_info{ double n; - int j; struct pitch *p; struct abuf *ab; - struct a2buf t; + double on_sec, off_sec; double corr; }; static void -corr_info_get(struct pitdet *pd, int j, struct a2buf *a2b, struct onoff_stat *ost, struct corr_info *ci) +corr_info_get(struct pitdet *pd, int j, struct abuf *ab, struct onoff_stat *ost, struct corr_info *ci) { - if((ci->j = freq_n_idx(pd, j, ci->n)) < 0) return; - ci->p = &pd->arr[ci->j]; + double l, r, c, lmt, v; + + if((ci->p = pitdet_pitch_get(pd, j, ci->n)) == NULL) return; ci->ab = &ci->p->ab; - a2buf_init(&ci->t, ci->ab, NULL, 0,0,0,1,0,0); - ci->corr = a2buf_correlation(a2b, &ci->t, ost->on_sec, ost->off_sec, NULL); + ci->on_sec = ost->on_sec; + ci->off_sec = ost->off_sec; + ci->corr = abuf_correlation_by_type(ab, ci->ab, ci->on_sec, ci->off_sec, NULL); + if(ci->corr >= ABUF_CORR_STRONG) return; + + c = (ci->on_sec + ci->off_sec) * 0.5; + v = abuf_correlation_by_type(ab, ci->ab, ci->on_sec, c, NULL); + if(v < ABUF_CORR_STRONG) return; + l = c; + ci->corr = v; + r = ci->off_sec; + lmt = (r - l) * 0.001; + while(r - l > lmt){ + c = (l + r) * 0.5; + v = abuf_correlation_by_type(ab, ci->ab, ci->on_sec, c, NULL); + if(v >= ABUF_CORR_STRONG){ + l = c; + ci->corr = v; + } else r = c; + } + ci->off_sec = l; } static void -cut_tone(struct a2buf *low, struct a2buf *hi, struct onoff_stat *ost) +cut_tone(struct abuf *low, struct abuf *hi, double on_sec, double off_sec) { int from_i, to_i, i; struct a2buf t; struct tbuf *tb; - double k = a2buf_corr_k(low, hi, ost->on_sec, ost->off_sec, NULL); + double k = abuf_corr_k_by_type(low, hi, on_sec, off_sec, NULL); - a2buf_init(&t, &low->ab, &hi->ab, 0,0,0,-k,1,0); - tb = hi->tb; - tbuf_from_to_num(hi->tb, ost->on_sec, ost->off_sec, &from_i, &to_i); + a2buf_init(&t, low, hi, 0,0,0,-k,1,0); + tb = abuf_get_tbuf_by_type(hi); + tbuf_from_to_num(tb, on_sec, off_sec, &from_i, &to_i); for(i=from_i; irb, i, MAX(v, 0)); } - a2buf_init(&t, &low->ab, NULL, 0,0,0,1+k,0,0); - tb = low->tb; - tbuf_from_to_num(tb, ost->on_sec, ost->off_sec, &from_i, &to_i); + a2buf_init(&t, low, NULL, 0,0,0,1+k,0,0); + tb = abuf_get_tbuf_by_type(low); + tbuf_from_to_num(tb, on_sec, off_sec, &from_i, &to_i); for(i=from_i; irb, i, MAX(v, 0)); } } @@ -252,38 +272,18 @@ pitdet_cut_overtone(struct pitdet *pd, int j) { struct corr_info ci[] = { - { 1.0/2 }, { 1.0/3 }, { 1.0/4 }, - { 2 }, { 3 }, { 4 } + { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, }; int i, n = ARR_N(ci); struct pitch *p = &pd->arr[j]; struct onoff_stat *ost = &p->ost; - struct a2buf a2b; - - a2buf_init(&a2b, &p->ab, NULL, 0,0,0,1,0,0); - - for(;;){ - int near_i = -1; - double near_v; - - for(i=0; iab, ost, &ci[i]); + if(ci[i].p == NULL || ci[i].corr < ABUF_CORR_STRONG) continue; + cut_tone(&p->ab, ci[i].ab, ci[i].on_sec, ci[i].off_sec); recalc_onoff_stat(pd, ci[i].p); recalc_onoff_stat(pd, p); - - if(ci[i].n < 1) break; } } @@ -294,6 +294,15 @@ return abuf_get(&p->ab, sec); } +struct pitch * +pitdet_pitch_get(struct pitdet *pd, int j, double freq_n) +{ + if(freq_n != 1){ + if((j = freq_n_idx(pd, j, freq_n)) < 0) return NULL; + } + return &pd->arr[j]; +} + static void wrt_dbl(FILE *fp, double v) { @@ -331,6 +340,7 @@ double v; if(rd_dbl(pd->load, &v) == EOF) return EOF; abuf_add(&p->ab, v); + abuf_add(&p->ab_bak, v); } pd->oldest.sec = tbuf_oldest_sec(&pd->arr[0].ab.tb); return 0; @@ -345,6 +355,7 @@ for(j=0; jm; j++){ struct pitch *p = &pd->arr[j]; abuf_add(&p->ab, 0); + abuf_add(&p->ab_bak, 0); } pd->oldest.sec = tbuf_oldest_sec(&pd->arr[0].ab.tb); } diff -urN midi_prog-/pitdet.h midi_prog/pitdet.h --- midi_prog-/pitdet.h 2015-09-25 00:00:00.000000000 +0900 +++ midi_prog/pitdet.h 2015-09-30 00:00:00.000000000 +0900 @@ -44,6 +44,7 @@ void pitdet_add_after(struct pitdet *pd); void pitdet_cut_overtone(struct pitdet *pd, int j); double pitdet_get(struct pitdet *pd, int j, double sec); +struct pitch *pitdet_pitch_get(struct pitdet *pd, int j, double freq_n); void pitdet_save(struct pitdet *pd); int pitdet_load(struct pitdet *pd); diff -urN midi_prog-/rawmix2.c midi_prog/rawmix2.c --- midi_prog-/rawmix2.c 2015-09-01 00:00:00.000000000 +0900 +++ midi_prog/rawmix2.c 2015-09-30 00:00:00.000000000 +0900 @@ -26,6 +26,26 @@ m->pan = opt_double("-pan", a_ac, a_av, 0.5); } +static int +is_org_pan(struct mix *m) +{ + return m->in.ch_num == 2 && m->pan < 0; +} + +static int +org_pan(struct mix *m, double *vs) +{ + int ret; + + if((ret = in_do2(&m->in, vs)) == EOF){ + m->en = 0; + return EOF; + } + vs[0] *= m->vol; + vs[1] *= m->vol; + return ret; +} + int mix_get(struct mix *m, double *vs) { @@ -33,6 +53,9 @@ double v = 0; if(!m->en) return EOF; + if(is_org_pan(m)){ + return org_pan(m, vs); + } if((ret = in_do_mono(&m->in, &v)) == EOF){ m->en = 0; return EOF; diff -urN midi_prog-/tool.c midi_prog/tool.c --- midi_prog-/tool.c 2015-09-26 00:00:00.000000000 +0900 +++ midi_prog/tool.c 2015-09-30 00:00:00.000000000 +0900 @@ -99,6 +99,166 @@ } } +struct ch_inf{ + int cnt; + int rates[3]; + int ch; +} ch_infs[16]; + +static int ovr_wrt_cnt; + +void +ch_inf_init(void) +{ + int i; + for(i=0; icnt = 0; + p->ch = i; + } + ch_infs[9].cnt = -1; /* skip */ + + ovr_wrt_cnt = 0; +} + +struct ch_inf * +ch_inf_get(int *rates) +{ + struct ch_inf *p, *free = NULL, *low_cnt = NULL; + int i, j, n = ARR_N(ch_infs), rate_n = ARR_N(ch_infs[0].rates); + + for(i=0; icnt < 0) continue; /* skip */ + if(p->cnt == 0){ + if(!free) free = p; + continue; + } + for(j=0; jrates[j]) break; + if(j >= rate_n){ + p->cnt++; + return p; + } + if(!low_cnt || p->cnt < low_cnt->cnt) low_cnt = p; + } + if(!free){ + free = low_cnt; + ovr_wrt_cnt++; + } + if(!free) ERR("???"); + p = free; + p->cnt = 1; + for(j=0; jrates[j] = rates[j]; + return p; +} + +static int +cmp_f(const void *a, const void *b) +{ + struct ch_inf *p1 = (struct ch_inf *)a; + struct ch_inf *p2 = (struct ch_inf *)b; + return p1->cnt - p2->cnt; +} + +void +ch_inf_show(void) +{ + int i; + + qsort(ch_infs, ARR_N(ch_infs), sizeof(ch_infs[0]), cmp_f); + + for(i=0; ich, p->rates[0], p->rates[1], p->rates[2], p->cnt); + } + fprintf(stderr, "ovr_wrt_cnt=%d\n", ovr_wrt_cnt); + fprintf(stderr, "\n"); +} + +int +ch_get(int note, struct pitdet *pd, double on_sec, double off_sec) +{ + double from = on_sec + (off_sec - on_sec) * 0; + double to = on_sec + (off_sec - on_sec) * 0.9; + int rates[3], i; + struct abuf_n ab_n[4]; + + for(i=0; idiv; k++){ + int j = note * pd->div + k; + struct pitch *p = pitdet_pitch_get(pd, j, ov); + ab_n[i].p[k] = p ? (ov == 1 ? &p->ab : &p->ab_bak) : NULL; + //ab_n[i].p[k] = p ? &p->ab_bak : NULL; + //ab_n[i].p[k] = p ? &p->ab : NULL; + } + abuf_n_init(&ab_n[i], NULL, pd->div); + } + for(i=0; idiv; k++){ + double c = abuf_correlation_by_type(ab_n[0].p[k], ab_n[i+1].p[k], from, to, NULL); +//fprintf(stderr, "ov=%d k=%d c=%f\n", i+2, k, c); + if(k_max < 0 || c > corr){ + corr = c; + k_max = k; + } + } + k = k_max; + + //if(corr < ABUF_CORR_STRONG) continue; + if(corr < ABUF_CORR_MID) continue; + +#if 1 +fprintf(stderr, "ck1 %f\n", +abuf_correlation_by_type(ab_n[0].p[k], ab_n[i+1].p[k], from, to, NULL) +); +#endif + + K = abuf_corr_k_by_type(ab_n[0].p[k], ab_n[i+1].p[k], from, to, NULL); +fprintf(stderr, "K=%f Kcnt=%d\n", K, Kcnt++); + +#if 0 + +ck1 0.749551 +K=0.573503 Kcnt=318 + 9 [ 0 0 0 ] cnt=-1 + 7 [ 4 777 777 ] cnt=2 +13 [ 2 1 0 ] cnt=2 + 8 [ 8 777 777 ] cnt=3 +10 [ 777 4 777 ] cnt=3 +12 [ 777 1 0 ] cnt=3 +14 [ 777 777 1 ] cnt=3 + 6 [ 1 0 777 ] cnt=7 + 2 [ 777 2 777 ] cnt=9 +15 [ 0 777 777 ] cnt=13 + 3 [ 777 1 777 ] cnt=15 + 4 [ 5 777 777 ] cnt=15 +11 [ 3 777 777 ] cnt=25 + 5 [ 2 777 777 ] cnt=39 + 1 [ 1 777 777 ] cnt=42 + 0 [ 777 777 777 ] cnt=9270 +ovr_wrt_cnt=89 + +#endif + + + rates[i] = (int)(K * 5); + } + return ch_inf_get(rates)->ch; +} + struct note_onoff{ struct onoff_stat ost; struct abuf ab; @@ -117,6 +277,8 @@ nto->note = note; nto->pre_release = opt_double("-pre_release", ac, av, 0); nto->onoff = 0; + + ch_inf_init(); } double @@ -136,10 +298,10 @@ } void -note_onoff_add(struct note_onoff *nto, double sec, double v, int ch) +note_onoff_add(struct note_onoff *nto, double sec, double v) { double on_sec, off_sec; - int tick, velo, chg_v; + int tick, velo, chg_v, ch; abuf_add(&nto->ab, v); @@ -160,6 +322,8 @@ if((velo = note_onoff_velo(nto, on_sec, off_sec)) == 0) return; + if((ch = ch_get(nto->note, nto->pd, on_sec, off_sec)) < 0) return; + tick = pitdet_sec_to_tick(nto->pd, on_sec); printf("abs=%08d %s ch=%d note=%d velo=%d\n", tick, "on ", ch, nto->note, velo); @@ -176,19 +340,21 @@ { double sec = pd->oldest.sec; int i, k; - int ch = 0; if(sec < 0) return; for(i=0; idiv; k++){ int j = i * pd->div + k; - v = pitdet_get(pd, j, sec); - sum += MAX(v, 0); + struct pitch *p = pitdet_pitch_get(pd, j, 1); + ab_n.p[k] = p ? &p->ab : NULL; } - v = sum; - note_onoff_add(¬e_onoff[i], sec, v, ch); + abuf_n_init(&ab_n, NULL, pd->div); + v = abuf_n_get(&ab_n, sec); + note_onoff_add(¬e_onoff[i], sec, v); } } @@ -228,15 +394,17 @@ if(opt_idx("-pitch_show", ac, av) > 0){ int j; for(j=0; jfreq, p->wn, p->sb.tb.wsec); } } while(pd_load){ - if(pitdet_load(&pd) == EOF) return 0; - + if(pitdet_load(&pd) == EOF){ + ch_inf_show(); + return 0; + } pitdet_add_after(&pd); show_sec(&pd);