From: Shikano M. <sh...@us...> - 2016-11-02 07:06:42
|
Update of /cvsroot/sp-tk/SPTK/src/bin/lmadf In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7985 Modified Files: lmadf.c _lmadf.c Log Message: addition of cascaded filter Index: _lmadf.c =================================================================== RCS file: /cvsroot/sp-tk/SPTK/src/bin/lmadf/_lmadf.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** _lmadf.c 14 Dec 2015 01:14:17 -0000 1.19 --- _lmadf.c 2 Nov 2016 07:06:40 -0000 1.20 *************** *** 110,115 **** ppade = &pade[pd * (pd + 1) / 2]; ! x = lmadf1(x, c, m, d, 1, 1, pd); /* D1(z) */ ! x = lmadf1(x, c, m, &d[(m + 1) * pd], 2, m, pd); /* D2(z) */ return (x); --- 110,133 ---- ppade = &pade[pd * (pd + 1) / 2]; ! x = lmadf1(x, c, m, d, pd, 1, 1); /* D1(z) */ ! x = lmadf1(x, c, m, &d[(m + 1) * pd], pd, 2, m); /* D2(z) */ ! ! return (x); ! } ! ! double cascade_lmadf(double x, double *c, const int m, const int pd, double *d, ! const int block_num, int *block_size) ! { ! int i, block_start = 1, block_end = 0; ! ppade = &pade[pd * (pd + 1) / 2]; ! ! for (i = 0; i < block_num; i++) { ! block_end += abs(block_size[i]); ! if (block_size[i] > 0) { ! x = lmadf1(x, c, m, d, pd, block_start, block_end); ! } ! d += (m + 1) * pd; ! block_start += abs(block_size[i]); ! } return (x); *************** *** 130,135 **** *****************************************************************/ ! double lmadf1(double x, double *c, const int m, double *d, const int m1, ! const int m2, const int pd) { double y, t, *pt; --- 148,153 ---- *****************************************************************/ ! double lmadf1(double x, double *c, const int m, double *d, const int pd, ! const int m1, const int m2) { double y, t, *pt; *************** *** 150,155 **** } - /* transpose */ - double lmadf1t(double x, double *b, const int pd, double *d) { --- 168,171 ---- *************** *** 174,189 **** } ! static double lmafirt(double x, double *b, const int m, double *d) { int i; double y = 0.0; ! y = d[0]; ! d[m] = b[m] * x; ! for (i = m - 1; i > 1; i--) d[i] += b[i] * x; - d[1] += 0; - for (i = 0; i < m; i++) d[i] = d[i + 1]; --- 190,204 ---- } ! static double lmafirt(double x, double *b, const int m, double *d, const int m1, ! const int m2) { int i; double y = 0.0; ! y = d[1]; ! d[m2] = b[m2] * x; ! for (i = m2 - 1; i >= m1; i--) d[i] += b[i] * x; for (i = 0; i < m; i++) d[i] = d[i + 1]; *************** *** 192,204 **** } ! static double lmadf2t(double x, double *b, const int m, const int pd, double *d) { double v, out = 0.0, *pt; int i; ! pt = &d[pd * (m + 2)]; for (i = pd; i >= 1; i--) { ! pt[i] = lmafirt(pt[i - 1], b, m, &d[(i - 1) * (m + 2)]); v = pt[i] * ppade[i]; --- 207,220 ---- } ! double lmadf2t(double x, double *b, const int m, const int pd, double *d, ! const int m1, const int m2) { double v, out = 0.0, *pt; int i; ! pt = &d[pd * (m + 1)]; for (i = pd; i >= 1; i--) { ! pt[i] = lmafirt(pt[i - 1], b, m, &d[(i - 1) * (m + 1)], m1, m2); v = pt[i] * ppade[i]; *************** *** 213,222 **** } ! double lmadft(double x, double *c, const int m, const int pd, double *d) { ppade = &pade[pd * (pd + 1) / 2]; x = lmadf1t(x, c, pd, d); ! x = lmadf2t(x, c, m, pd, &d[2 * (pd + 1)]); return (x); --- 229,248 ---- } ! double lmadft(double x, double *c, const int m, const int pd, double *d, ! int block_num, int *block_size) { + int i, block_start = 2, block_end = 1; ppade = &pade[pd * (pd + 1) / 2]; x = lmadf1t(x, c, pd, d); ! ! for (i = 1; i < block_num; i++) { ! block_end += abs(block_size[i]); ! if (block_size[i] > 0) { ! x = lmadf2t(x, c, m, pd, &d[2 * (pd + 1)], block_start, block_end); ! } ! d += pd * (m + 1) + (pd + 1); ! block_start += abs(block_size[i]); ! } return (x); Index: lmadf.c =================================================================== RCS file: /cvsroot/sp-tk/SPTK/src/bin/lmadf/lmadf.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** lmadf.c 14 Dec 2015 01:14:17 -0000 1.33 --- lmadf.c 2 Nov 2016 07:06:40 -0000 1.34 *************** *** 43,77 **** /* ----------------------------------------------------------------- */ ! /************************************************************************ ! * * ! * LMA Digital Filter for Speech Synthesis * ! * * ! * 1986.6 K.Tokuda * ! * 1996.1 K.Koishida * ! * * ! * usage: * ! * lmadf [ options ] cfile [ infile ] > stdout * ! * options: * ! * -m m : order of cepstrum [25] * ! * -p p : frame period [100] * ! * -i i : interpolation period [1] * ! * -P P : order of Pade approximation [4] * ! * -k : filtering without gain [FALSE] * ! * -v : inverse filter [FALSE] * ! * -t : transpose filter [FALSE] * ! * infile: * ! * cepstral coefficients * ! * , c~(0), c~(1), ..., c~(M), * ! * excitation sequence * ! * , x(0), x(1), ..., * ! * stdout: * ! * filtered sequence * ! * , y(0), y(1), ..., * ! * notice: * ! * P = 4 or 5 * ! * require: * ! * lmadf() * ! * * ! ************************************************************************/ static char *rcs_id = "$Id$"; --- 43,80 ---- /* ----------------------------------------------------------------- */ ! /***************************************************************************** ! * * ! * LMA Digital Filter for Speech Synthesis * ! * * ! * 1986.6 K.Tokuda * ! * 1996.1 K.Koishida * ! * * ! * usage: * ! * lmadf [ options ] cfile [ infile ] > stdout * ! * options: * ! * -m m : order of cepstrum [25] * ! * -p p : frame period [100] * ! * -i i : interpolation period [1] * ! * -P P : order of Pade approximation [4] * ! * -k : filtering without gain [FALSE] * ! * -v : inverse filter [FALSE] * ! * -t : transpose filter [FALSE] * ! * (level 2) * ! * -B B1 B2 ... Bn : block size of cascaded filter [FALSE] * ! * where (|B1|+...+|Bn|) = m * ! * infile: * ! * cepstral coefficients * ! * , c~(0), c~(1), ..., c~(M), * ! * excitation sequence * ! * , x(0), x(1), ..., * ! * stdout: * ! * filtered sequence * ! * , y(0), y(1), ..., * ! * notice: * ! * P = 4 or 5 * ! * require: * ! * lmadf() * ! * * ! *****************************************************************************/ static char *rcs_id = "$Id$"; *************** *** 107,110 **** --- 110,114 ---- #define INVERSE FA #define TRANSPOSE FA + #define BLOCK FA char *BOOL[] = { "FALSE", "TRUE" }; *************** *** 122,141 **** fprintf(stderr, " %s [ options ] cfile [ infile ] > stdout\n", cmnd); fprintf(stderr, " options:\n"); ! fprintf(stderr, " -m m : order of cepstrum [%d]\n", ORDER); ! fprintf(stderr, " -p p : frame period [%d]\n", FPERIOD); ! fprintf(stderr, " -i i : interpolation period [%d]\n", IPERIOD); ! fprintf(stderr, " -P P : order of Pade approximation [%d]\n", PADEORD); ! fprintf(stderr, " -v : inverse filter [%s]\n", BOOL[INVERSE]); ! fprintf(stderr, " -t : transpose filter [%s]\n", BOOL[TRANSPOSE]); ! fprintf(stderr, " -k : filtering without gain [%s]\n", BOOL[NGAIN]); fprintf(stderr, " -h : print this message\n"); fprintf(stderr, " infile:\n"); ! fprintf(stderr, " filter input (%s) [stdin]\n", FORMAT); fprintf(stderr, " stdout:\n"); fprintf(stderr, " filter output (%s)\n", FORMAT); --- 126,159 ---- fprintf(stderr, " %s [ options ] cfile [ infile ] > stdout\n", cmnd); fprintf(stderr, " options:\n"); ! fprintf(stderr, ! " -m m : order of cepstrum [%d]\n", ! ORDER); ! fprintf(stderr, ! " -p p : frame period [%d]\n", FPERIOD); ! fprintf(stderr, ! " -i i : interpolation period [%d]\n", IPERIOD); ! fprintf(stderr, ! " -P P : order of Pade approximation [%d]\n", PADEORD); ! fprintf(stderr, ! " -v : inverse filter [%s]\n", BOOL[INVERSE]); ! fprintf(stderr, ! " -t : transpose filter [%s]\n", BOOL[TRANSPOSE]); ! fprintf(stderr, ! " -k : filtering without gain [%s]\n", BOOL[NGAIN]); + fprintf(stderr, " (level 2)\n"); + fprintf(stderr, + " -B B1 B2 ... Bn : block size of cascaded filter [%s]\n", + BOOL[BLOCK]); + fprintf(stderr, " where (|B1|+ ... +|Bn|) = m \n"); fprintf(stderr, " -h : print this message\n"); fprintf(stderr, " infile:\n"); ! fprintf(stderr, " filter input (%s) [stdin]\n", ! FORMAT); fprintf(stderr, " stdout:\n"); fprintf(stderr, " filter output (%s)\n", FORMAT); *************** *** 159,163 **** FILE *fp = stdin, *fpc = NULL; double *c, *inc, *cc, *d, x; ! Boolean ngain = NGAIN, inverse = INVERSE, transpose = TRANSPOSE; if ((cmnd = strrchr(argv[0], '/')) == NULL) --- 177,184 ---- FILE *fp = stdin, *fpc = NULL; double *c, *inc, *cc, *d, x; ! Boolean ngain = NGAIN, inverse = INVERSE, transpose = TRANSPOSE, block = ! BLOCK; ! int block_num = 0, block_sum = 0, *block_size; ! char **pt_block; if ((cmnd = strrchr(argv[0], '/')) == NULL) *************** *** 165,169 **** else cmnd++; ! while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { --- 186,190 ---- else cmnd++; ! while (--argc) { if (**++argv == '-') { switch (*(*argv + 1)) { *************** *** 193,196 **** --- 214,240 ---- inverse = 1 - inverse; break; + case 'B': + block = TR; + i = 0; + pt_block = argv; + while (*(*argv++) != '\0') { + if (!isdigit(**argv) + && !((**argv == '-') && isdigit(*(*argv + 1)))) { + break; + } + i++; + if (--argc <= 1) { + break; + } + } + argv = pt_block; + block_num = i; + block_sum = 0; + block_size = (int *) malloc(sizeof(int) * block_num); + for (i = 0; i < block_num; i++) { + block_size[i] = atoi(*++argv); + block_sum += abs(block_size[i]); + } + break; case 'h': usage(0); *************** *** 199,207 **** usage(1); } ! } else if (fpc == NULL) fpc = getfp(*argv, "rb"); ! else fp = getfp(*argv, "rb"); ! if ((pd < 4) || (pd > 5)) { fprintf(stderr, "%s : Order of Pade approximation should be 4 or 5!\n", --- 243,252 ---- usage(1); } ! } else if (fpc == NULL) { fpc = getfp(*argv, "rb"); ! } else { fp = getfp(*argv, "rb"); ! } ! } if ((pd < 4) || (pd > 5)) { fprintf(stderr, "%s : Order of Pade approximation should be 4 or 5!\n", *************** *** 214,219 **** return (1); } ! c = dgetmem(m + m + m + 3 + (m + 1) * pd * 2); cc = c + m + 1; inc = cc + m + 1; --- 259,281 ---- return (1); } + if (block == TR && block_sum != m) { + fprintf(stderr, "%s : block size must coincide with the value of m !\n", + cmnd); + return (1); + } ! if (!transpose) { ! if (block_num == 0) { ! c = dgetmem(m + m + m + 3 + (m + 1) * pd * 2); ! } else { ! c = dgetmem(m + m + m + 3 + ((m + 1) * pd) * block_num); ! } ! } else { ! if (block_num == 0) { ! c = dgetmem(m + m + m + 3 + ((m + 1) * pd + (pd + 1)) * 2); ! } else { ! c = dgetmem(m + m + m + 3 + ((m + 1) * pd + (pd + 1)) * block_num); ! } ! } cc = c + m + 1; inc = cc + m + 1; *************** *** 255,262 **** if (!ngain) x *= exp(c[0]); ! if (transpose) ! x = lmadft(x, c, m, pd, d); ! else ! x = lmadf(x, c, m, pd, d); fwritef(&x, sizeof(x), 1, stdout); --- 317,335 ---- if (!ngain) x *= exp(c[0]); ! if (transpose) { ! if (block_num == 0) { ! block_num = 2; ! block_size = (int *) malloc(sizeof(int) * block_num); ! block_size[0] = 1; ! block_size[1] = m - 1; ! } ! x = lmadft(x, c, m, pd, d, block_num, block_size); ! } else { ! if (block_num == 0) { ! x = lmadf(x, c, m, pd, d); ! } else { ! x = cascade_lmadf(x, c, m, pd, d, block_num, block_size); ! } ! } fwritef(&x, sizeof(x), 1, stdout); |