/* HTS_b2en: calculate frame energy */ static double HTS_b2en(HTS_Vocoder * v, const double *b, const size_t m, const double a) { size_t i; double en = 0.0; double *cep; double *ir; if (v->spectrum2en_size < m) { if (v->spectrum2en_buff != NULL) cst_free(v->spectrum2en_buff); v->spectrum2en_buff = cst_alloc(double,((m + 1) + 2 * IRLENG)); v->spectrum2en_size = m; } cep = v->spectrum2en_buff + m + 1; ir = cep + IRLENG; b2mc(b, v->spectrum2en_buff, m, a); freqt(v->spectrum2en_buff, m, cep, IRLENG, -a); c2ir(cep, IRLENG, ir); for (i = 0; i < IRLENG; i++) en += ir[i] * ir[i]; return (en); }
void mgc2mgc(double *c1, const int m1, const double a1, const double g1, double *c2, const int m2, const double a2, const double g2) { double a; static double *ca = NULL; static int size_a; if (ca == NULL) { ca = dgetmem(m1 + 1); size_a = m1; } if (m1 > size_a) { free(ca); ca = dgetmem(m1 + 1); size_a = m1; } a = (a2 - a1) / (1 - a1 * a2); if (a == 0) { movem(c1, ca, sizeof(*c1), m1 + 1); gnorm(ca, ca, m1, g1); gc2gc(ca, m1, g1, c2, m2, g2); ignorm(c2, c2, m2, g2); } else { freqt(c1, m1, c2, m2, a); gnorm(c2, c2, m2, g1); gc2gc(c2, m2, g1, c2, m2, g2); ignorm(c2, c2, m2, g2); } return; }
void main(int argc, char **argv) { int m1 = ORDERC1, m2 = ORDERC2; FILE *fp = stdin; double *c1, *c2, a1 = ALPHA1, a2 = ALPHA2, a, atof(); if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv+1)) { case 'm': m1 = atoi(*++argv); --argc; break; case 'M': m2 = atoi(*++argv); --argc; break; case 'a': a1 = atof(*++argv); --argc; break; case 'A': a2 = atof(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c' !\n", cmnd, *(*argv+1)); usage(1); } } else fp = getfp(*argv, "r"); c1 = dgetmem(m1+m2+2); c2 = c1 + m1 + 1; a = (a2 - a1) / (1 - a1*a2); while (freadf(c1, sizeof(*c1), m1+1, fp) == m1+1){ freqt(c1, m1, c2, m2, a); fwritef(c2, sizeof(*c2), m2+1, stdout); } exit(0); }
int mcep(double *xw, const int flng, double *mc, const int m, const double a, const int itr1, const int itr2, const double dd, const int etype, const double e, const double f, const int itype) { int i, j; int flag = 0, f2, m2; double t, s, eps = 0.0, min, max; static double *x = NULL, *y, *c, *d, *al, *b; static int size_x, size_d; if (etype == 1 && e < 0.0) { fprintf(stderr, "mcep : value of e must be e>=0!\n"); exit(1); } if (etype == 2 && e >= 0.0) { fprintf(stderr, "mcep : value of E must be E<0!\n"); exit(1); } if (etype == 1) { eps = e; } if (x == NULL) { x = dgetmem(3 * flng); y = x + flng; c = y + flng; size_x = flng; d = dgetmem(3 * m + 3); al = d + (m + 1); b = al + (m + 1); size_d = m; } if (flng > size_x) { free(x); x = dgetmem(3 * flng); y = x + flng; c = y + flng; size_x = flng; } if (m > size_d) { free(d); d = dgetmem(3 * m + 3); al = d + (m + 1); b = al + (m + 1); size_d = m; } f2 = flng / 2; m2 = m + m; movem(xw, x, sizeof(*x), flng); switch (itype) { case 0: /* windowed data sequence */ fftr(x, y, flng); for (i = 0; i < flng; i++) { x[i] = x[i] * x[i] + y[i] * y[i] + eps; /* periodogram */ } break; case 1: /* dB */ for (i = 0; i <= flng / 2; i++) { x[i] = exp((x[i] / 20.0) * log(10.0)); /* dB -> amplitude spectrum */ x[i] = x[i] * x[i] + eps; /* amplitude -> periodogram */ } break; case 2: /* log */ for (i = 0; i <= flng / 2; i++) { x[i] = exp(x[i]); /* log -> amplitude spectrum */ x[i] = x[i] * x[i] + eps; /* amplitude -> periodogram */ } break; case 3: /* amplitude */ for (i = 0; i <= flng / 2; i++) { x[i] = x[i] * x[i] + eps; /* amplitude -> periodogram */ } break; case 4: /* periodogram */ for (i = 0; i <= flng / 2; i++) { x[i] = x[i] + eps; } break; default: fprintf(stderr, "mcep : input type %d is not supported!\n", itype); exit(1); } if (itype > 0) { for (i = 1; i < flng / 2; i++) x[flng - i] = x[i]; } if (etype == 2 && e < 0.0) { max = x[0]; for (i = 1; i < flng; i++) { if (max < x[i]) max = x[i]; } max = sqrt(max); min = max * pow(10.0, e / 20.0); /* floor is 20*log10(min/max) */ min = min * min; for (i = 0; i < flng; i++) { if (x[i] < min) x[i] = min; } } for (i = 0; i < flng; i++) { if (x[i] <= 0.0) { fprintf(stderr, "mcep : periodogram has '0', use '-e' option to floor it!\n"); exit(1); } c[i] = log(x[i]); } /* 1, (-a), (-a)^2, ..., (-a)^M */ al[0] = 1.0; for (i = 1; i <= m; i++) al[i] = -a * al[i - 1]; /* initial value of cepstrum */ ifftr(c, y, flng); /* c : IFFT[x] */ c[0] /= 2.0; c[f2] /= 2.0; freqt(c, f2, mc, m, a); /* mc : mel cep. */ s = c[0]; /* Newton Raphson method */ for (j = 1; j <= itr2; j++) { fillz(c, sizeof(*c), flng); freqt(mc, m, c, f2, -a); /* mc : mel cep. */ fftr(c, y, flng); /* c, y : FFT[mc] */ for (i = 0; i < flng; i++) c[i] = x[i] / exp(c[i] + c[i]); ifftr(c, y, flng); frqtr(c, f2, c, m2, a); /* c : r(k) */ t = c[0]; if (j >= itr1) { if (fabs((t - s) / t) < dd) { flag = 1; break; } s = t; } for (i = 0; i <= m; i++) b[i] = c[i] - al[i]; for (i = 0; i <= m2; i++) y[i] = c[i]; for (i = 0; i <= m2; i += 2) y[i] -= c[0]; for (i = 2; i <= m; i += 2) c[i] += c[0]; c[0] += c[0]; if (theq(c, y, d, b, m + 1, f)) { fprintf(stderr, "mcep : Error in theq() at %dth iteration !\n", j); exit(1); } for (i = 0; i <= m; i++) mc[i] += d[i]; } if (flag) return (0); else return (-1); }