Пример #1
0
int main(int argc, char **argv)
{
   int m = ORDER, flng = FLENG, ilng = FLENG, itype = ITYPE, etype = ETYPE,
       fftsz = FFTSZ, itr1 = MINITR, itr2 = MAXITR, flag = 0;
   FILE *fp = stdin;
   double *mc, *x, a = ALPHA, t = THETA, end = END, e = EPS, f = MINDET, s =
       SAMPLEF, T = EMPHHZ;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'a':
            a = atof(*++argv);
            --argc;
            break;
         case 't':
            t = atof(*++argv);
            --argc;
            break;
         case 'T':
            T = atof(*++argv);
            --argc;
            break;
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'l':
            flng = atoi(*++argv);
            --argc;
            break;
         case 's':
            s = atof(*++argv);
            --argc;
            break;
         case 'L':
            fftsz = atoi(*++argv);
            --argc;
            break;
         case 'q':
            itype = atoi(*++argv);
            --argc;
            break;
         case 'i':
            itr1 = atoi(*++argv);
            --argc;
            break;
         case 'j':
            itr2 = atoi(*++argv);
            --argc;
            break;
         case 'd':
            end = atof(*++argv);
            --argc;
            break;
         case 'e':
            etype = 1;
            e = atof(*++argv);
            --argc;
            break;
         case 'E':
            etype = 2;
            e = atof(*++argv);
            --argc;
            break;
         case 'f':
            f = 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, "rb");

   if (T != 0.00 && t != 0.00) {
      fprintf(stderr, "%s : option t and T can't be used at the same time!\n",
              cmnd);
      usage(1);
   } else if (T > 1000 * (s / 2)) {
      fprintf(stderr, "%s : value of T must be T <= 1000*s/2 !\n", cmnd);
      usage(1);
   } else if (T > 0.00) {
      T /= 1000;
      t = (T / (s / 2));
   }

   t *= M_PI;

   if (itype == 0)
      ilng = flng;
   else
      ilng = flng / 2 + 1;

   x = dgetmem(flng + m + 1);
   mc = x + flng;

   while (freadf(x, sizeof(*x), ilng, fp) == ilng) {

      flag =
          smcep(x, flng, mc, m, fftsz, a, t, itr1, itr2, end, etype, e, f,
                itype);

      fwritef(mc, sizeof(*mc), m + 1, stdout);
   }

   return (0);
}
Пример #2
0
int main(int argc, char **argv)
{
   int m = ORDER, flng = FLENG, ilng = FLENG, itr1 = MINITR, itr2 =
       MAXITR, itype = ITYPE, norm = NORM, flag = 0;
   FILE *fp = stdin;
   double *gc, *x, g = GAMMA, end = END, e = EPS, f = MINDET;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;

   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'l':
            flng = atoi(*++argv);
            --argc;
            break;
         case 'q':
            itype = atoi(*++argv);
            --argc;
            break;
         case 'g':
            g = atof(*++argv);
            --argc;
            break;
         case 'c':
            g = atoi(*++argv);
            --argc;
            if (g < 1)
               fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd);
            g = -1.0 / g;
            break;
         case 'n':
            norm = 1 - norm;
            break;
         case 'i':
            itr1 = atoi(*++argv);
            --argc;
            break;
         case 'j':
            itr2 = atoi(*++argv);
            --argc;
            break;
         case 'd':
            end = atof(*++argv);
            --argc;
            break;
         case 'e':
            e = atof(*++argv);
            --argc;
            break;
         case 'f':
            f = 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, "rb");

   if (itype == 0)
      ilng = flng;
   else
      ilng = flng / 2 + 1;

   x = dgetmem(flng + m + 1);
   gc = x + flng;

   while (freadf(x, sizeof(*x), ilng, fp) == ilng) {
      flag = gcep(x, flng, gc, m, g, itr1, itr2, end, e, f, itype);
      if (!norm)
         ignorm(gc, gc, m, g);
      fwritef(gc, sizeof(*gc), m + 1, stdout);
   }

   return 0;
}
Пример #3
0
Файл: vstat.c Проект: EQ4/SPTK
int main(int argc, char *argv[])
{
   FILE *fp = stdin;
   double *x, *mean, *med = NULL, **mtmp = NULL, **cov = NULL, **invcov =
       NULL, *var = NULL, conf = CONFLEV, *upper = NULL, *lower = NULL, t, err;
   int leng = LENG, nv = -1, i, j, k = 0, lp = 0, m, outtype = 0, count = 0;
   Boolean outmean = OUTMEAN, outcov = OUTCOV, outconf = OUTCONF,
       outmed = OUTMED, diagc = DIAGC, inv = INV, corr = CORR;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'l':
            leng = atoi(*++argv);
            --argc;
            break;
         case 'n':
            leng = atoi(*++argv) + 1;
            --argc;
            break;
         case 't':
            nv = atoi(*++argv);
            --argc;
            break;
         case 'o':
            outtype = atoi(*++argv);
            --argc;
            break;
         case 'c':
            conf = atof(*++argv);
            --argc;
            break;
         case 'd':
            diagc = 1 - diagc;
            break;
         case 'i':
            inv = 1 - inv;
            break;
         case 'r':
            corr = 1 - corr;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   if (conf < 0 || conf > 100) {
      fprintf(stderr,
              "%s : Confidence level must be greater than 0 and less than 1.0!\n",
              cmnd);
   }
   switch (outtype) {
   case 1:
      outcov = FA;
      break;
   case 2:
      outmean = FA;
      break;
   case 3:
      outcov = FA;
      outconf = TR;
      break;
   case 4:
      outcov = FA;
      outmean = FA;
      outmed = TR;
      break;
   }
   if (diagc && corr)
      diagc = FA;
   if (diagc && inv)
      diagc = FA;
   if (corr && inv)
      corr = FA;

   mean = dgetmem(leng + leng);

   x = mean + leng;

   if (outmed) {

      if (nv == -1) {
         typedef struct _float_list {
            float *f;
            struct _float_list *next;
         } float_list;

         float_list *top = NULL, *prev = NULL, *cur = NULL;
         top = prev = (float_list *) getmem(1, sizeof(float_list));
         prev->next = NULL;
         while (freadf(x, sizeof(*x), leng, fp) == leng) {
            cur = (float_list *) getmem(1, sizeof(float_list));
            cur->f = fgetmem(leng);
            for (i = 0; i < leng; i++) {
               cur->f[i] = (float) x[i];
            }
            count++;
            prev->next = cur;
            cur->next = NULL;
            prev = cur;
         }
         k = count;

         mtmp = (double **) getmem(leng, sizeof(*mtmp));
         mtmp[0] = dgetmem(leng * k);
         for (i = 1; i < leng; i++)
            mtmp[i] = mtmp[i - 1] + k;

         med = dgetmem(leng);

         for (j = 0, cur = top->next; j < k; j++, cur = cur->next) {
            for (i = 0; i < leng; i++) {
               mtmp[i][j] = (double) cur->f[i];
            }
         }
      } else {

         k = nv;

         mtmp = (double **) getmem(leng, sizeof(*mtmp));
         mtmp[0] = dgetmem(leng * k);
         for (i = 1; i < leng; i++)
            mtmp[i] = mtmp[i - 1] + k;

         med = dgetmem(leng);

         for (j = 0; j < k; j++) {
            for (i = 0; i < leng; i++) {
               freadf(&mtmp[i][j], sizeof(**mtmp), 1, fp);
            }
         }
      }

      if (k % 2 == 0) {
         fprintf(stderr, "%s : warning: the number of vectors is even!\n",
                 cmnd);
      }

      for (i = 0; i < leng; i++) {
         quicksort(mtmp[i], 0, k - 1);
         if (k % 2 == 1) {
            med[i] = mtmp[i][k / 2];
         } else {
            med[i] = ((mtmp[i][k / 2] + mtmp[i][k / 2 - 1]) / 2);
         }
      }

      fwritef(med, sizeof(*med), leng, stdout);

      return (0);

   }

   if (outcov) {
      if (!diagc) {
         cov = (double **) getmem(leng, sizeof(*cov));
         cov[0] = dgetmem(leng * leng);
         for (i = 1; i < leng; i++)
            cov[i] = cov[i - 1] + leng;

         if (inv) {
            invcov = (double **) getmem(leng, sizeof(*invcov));
            invcov[0] = dgetmem(leng * leng);
            for (i = 1; i < leng; i++)
               invcov[i] = invcov[i - 1] + leng;
         }
      } else
         var = dgetmem(leng);
   }
   if (outconf) {
      var = dgetmem(leng);
      upper = dgetmem(leng);
      lower = dgetmem(leng);
   }



   while (!feof(fp)) {
      for (i = 0; i < leng; i++) {
         mean[i] = 0.0;
         if (outcov) {
            if (!diagc)
               for (j = 0; j < leng; j++)
                  cov[i][j] = 0.0;
            else
               var[i] = 0.0;
         }
         if (outconf) {
            var[i] = 0.0;
         }
      }

      for (lp = nv; lp;) {
         if (freadf(x, sizeof(*x), leng, fp) != leng)
            break;
         for (i = 0; i < leng; i++) {
            mean[i] += x[i];
            if (outcov) {
               if (!diagc)
                  for (j = i; j < leng; j++)
                     cov[i][j] += x[i] * x[j];
               else
                  var[i] += x[i] * x[i];
            }
            if (outconf) {
               var[i] += x[i] * x[i];
            }
         }
         --lp;
      }

      if (lp == 0 || nv == -1) {
         if (nv > 0)
            k = nv;
         else
            k = -lp - 1;
         for (i = 0; i < leng; i++)
            mean[i] /= k;
         if (outcov) {
            if (!diagc)
               for (i = 0; i < leng; i++)
                  for (j = i; j < leng; j++)
                     cov[j][i] = cov[i][j] = cov[i][j] / k - mean[i] * mean[j];
            else
               for (i = 0; i < leng; i++)
                  var[i] = var[i] / k - mean[i] * mean[i];
         }
         if (outconf) {
            for (i = 0; i < leng; i++) {
               var[i] = (var[i] - k * mean[i] * mean[i]) / (k - 1);
            }
            t = t_percent(conf / 100, k - 1);
            for (i = 0; i < leng; i++) {
               err = t * sqrt(var[i] / k);
               upper[i] = mean[i] + err;
               lower[i] = mean[i] - err;
            }
         }

         if (corr) {
            for (i = 0; i < leng; i++)
               for (j = i + 1; j < leng; j++)
                  cov[j][i] = cov[i][j] =
                      cov[i][j] / sqrt(cov[i][i] * cov[j][j]);
            for (i = 0; i < leng; i++)
               cov[i][i] = 1.0;
         }

         if (outmean)
            fwritef(mean, sizeof(*mean), leng, stdout);

         if (outcov) {
            if (!diagc) {
               if (inv) {
                  for (i = 0; i < leng; i++) {
                     for (j = i + 1; j < leng; j++) {
                        cov[j][i] /= cov[i][i];
                        for (m = i + 1; m < leng; m++)
                           cov[j][m] -= cov[i][m] * cov[j][i];
                     }
                  }

                  for (m = 0; m < leng; m++) {
                     for (i = 0; i < leng; i++) {
                        if (i == m)
                           invcov[i][m] = 1.0;
                        else
                           invcov[i][m] = 0.0;
                     }
                     for (i = 0; i < leng; i++) {
                        for (j = i + 1; j < leng; j++)
                           invcov[j][m] -= invcov[i][m] * cov[j][i];
                     }
                     for (i = leng - 1; i >= 0; i--) {
                        for (j = i + 1; j < leng; j++)
                           invcov[i][m] -= cov[i][j] * invcov[j][m];
                        invcov[i][m] /= cov[i][i];
                     }
                  }
                  fwritef(invcov[0], sizeof(*invcov[0]), leng * leng, stdout);
               } else
                  fwritef(cov[0], sizeof(*cov[0]), leng * leng, stdout);
            } else
               fwritef(var, sizeof(*var), leng, stdout);
         }
         if (outconf) {
            fwritef(upper, sizeof(*upper), leng, stdout);
            fwritef(lower, sizeof(*lower), leng, stdout);
         }
      }

   }

   return (0);
}
Пример #4
0
int main(int argc, char **argv)
{
   int m = ORDER, fprd = FPERIOD, iprd = IPERIOD, i, j;
   FILE *fp = stdin, *fpc = NULL;
   double *c, *inc, *cc, *d, x;
   Boolean ngain = NGAIN;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'p':
            fprd = atoi(*++argv);
            --argc;
            break;
         case 'i':
            iprd = atoi(*++argv);
            --argc;
            break;
         case 'k':
            ngain = 1 - ngain;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else if (fpc == NULL)
         fpc = getfp(*argv, "rb");
      else
         fp = getfp(*argv, "rb");

   if (fpc == NULL) {
      fprintf(stderr, "%s : Cannot open cepstrum file!\n", cmnd);
      return (1);
   }

   c = dgetmem(m + m + m + 3 + m);
   cc = c + m + 1;
   inc = cc + m + 1;
   d = inc + m + 1;

   if (freadf(c, sizeof(*c), m + 1, fpc) != m + 1)
      return (1);

   for (;;) {
      if (freadf(cc, sizeof(*cc), m + 1, fpc) != m + 1)
         return (0);

      for (i = 0; i <= m; i++)
         inc[i] = (cc[i] - c[i]) * iprd / fprd;

      for (j = fprd, i = (iprd + 1) / 2; j--;) {
         if (freadf(&x, sizeof(x), 1, fp) != 1)
            return (0);

         if (!ngain)
            x *= c[0];
         x = ltcdf(x, c, m, d);

         fwritef(&x, sizeof(x), 1, stdout);

         if (!--i) {
            for (i = 0; i <= m; i++)
               c[i] += inc[i];
            i = iprd;
         }
      }
      movem(cc, c, sizeof(*cc), m + 1);
   }

   return (0);
}
Пример #5
0
int main(int argc, char **argv)
{
   int m = ORDER, otype = OTYPE, n = SPNUM, p = MAXITR, i;
   FILE *fp = stdin;
   double *a, *lsp, end = END, sampling = SAMPLING;
   Boolean gain = GAIN, loggain = LOGGAIN;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 's':
            sampling = atof(*++argv);
            --argc;
            break;
         case 'o':
            otype = atoi(*++argv);
            --argc;
            break;
         case 'p':
            p = atoi(*++argv);
            --argc;
            break;
         case 'n':
            n = atoi(*++argv);
            --argc;
            break;
         case 'd':
            end = atof(*++argv);
            --argc;
            break;
         case 'k':
            gain = 1 - gain;
            break;
         case 'l':
         case 'L':
            loggain = 1 - loggain;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   lsp = dgetmem(m + m + 1);
   a = lsp + m;

   while (freadf(a, sizeof(*a), m + 1, fp) == m + 1) {
      lpc2lsp(a, lsp, m, n, p, end);

      if (otype == 0)
         for (i = 0; i < m; i++)
            lsp[i] *= PI2;
      else if (otype == 2 || otype == 3)
         for (i = 0; i < m; i++)
            lsp[i] *= sampling;
      if (otype == 3)
         for (i = 0; i < m; i++)
            lsp[i] *= 1000;

      if (gain) {
         if (loggain)
            *a = log(*a);
         fwritef(a, sizeof(*a), 1, stdout);
      }
      fwritef(lsp, sizeof(*lsp), m, stdout);
   }

   return (0);
}
Пример #6
0
Файл: c2ndps.c Проект: EQ4/SPTK
int main(int argc, char **argv)
{
   int m = ORDER, l = FLENG, pz = 0, i;
   FILE *fp = stdin;
   double *c, *n;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
         case 'l':
            if (isdigit(**(argv + 1)) == 0) {
               if ((**(argv + 1)) != '+') {
                  fprintf(stderr,
                          "%s : %s option need positive value !\n", cmnd,
                          *argv);
                  usage(1);
               } else if (isdigit(*(*(argv + 1) + 1)) == 0) {
                  fprintf(stderr,
                          "%s : %s option need positive value !\n", cmnd,
                          *argv);
                  usage(1);
               }
            }
            if ((*(*argv + 1)) == 'm')
               m = atoi(*++argv);
            else if ((*(*argv + 1)) == 'l')
               l = atoi(*++argv);
            --argc;
            break;

         case 'p':
         case 'z':
            if (pz != 0) {
               fprintf(stderr,
                       "%s : make a choice between -p and -z option !\n", cmnd);
               usage(1);
            } else if ((*(*argv + 1)) == 'p')
               pz = 1;
            else
               pz = -1;
            break;

         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   c = dgetmem(m + 1);
   n = dgetmem(l);

   while (freadf(c, sizeof(*c), m + 1, fp) == m + 1) {
      c2ndps(c, m, n, l);

      if (pz != 0) {
         for (i = 0; i < l; i++) {
            if (pz == 1 && n[i] < 0)
               n[i] = 0;
            else if (pz == -1 && n[i] > 0)
               n[i] = 0;
         }
      }

      fwritef(n, sizeof(*n), (l / 2) + 1, stdout);
   }

   free(c);
   free(n);

   return (0);
}
Пример #7
0
Файл: gmmp.c Проект: EQ4/SPTK
int main(int argc, char **argv)
{
   FILE *fp = stdin, *fgmm = NULL;
   GMM gmm;
   double logp, ave_logp, *x;
   int M = DEF_M, L = DEF_L, T;
   Boolean aflag = DEF_A, full = FULL;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;


   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'h':
            usage(0);
            break;
         case 'l':
            L = atoi(*++argv);
            --argc;
            break;
         case 'm':
            M = atoi(*++argv);
            --argc;
            break;
         case 'f':
            full = TR - full;
            break;
         case 'a':
            aflag = TR;
            break;
         default:
            fprintf(stderr, "%s: Illegal option \"%s\".\n", cmnd, *argv);
            usage(1);
         }
      } else if (fgmm == NULL)
         fgmm = getfp(*argv, "rb");
      else
         fp = getfp(*argv, "rb");


   /* Read GMM parameters */
   if (fgmm == NULL) {
      fprintf(stderr, "%s: GMM file must be specified!\n", cmnd);
      usage(1);
   }

   alloc_GMM(&gmm, M, L, full);
   load_GMM(&gmm, fgmm);
   prepareCovInv_GMM(&gmm);
   prepareGconst_GMM(&gmm);

   fclose(fgmm);

   /* Calculate and output log-probability */
   T = 0;
   ave_logp = 0.0;
   x = dgetmem(L);
   while (freadf(x, sizeof(*x), L, fp) == L) {
      if (!aflag) {
         logp = log_outp(&gmm, L, x);
         fwritef(&logp, sizeof(double), 1, stdout);
      } else {
         ave_logp += log_outp(&gmm, L, x);
         T++;
      }
   }
   fclose(fp);

   if (aflag) {
      if (T == 0) {
         fprintf(stderr, "%s: No input data!\n", cmnd);
         usage(1);
      } else {
         ave_logp /= (double) T;
         fwritef(&ave_logp, sizeof(double), 1, stdout);
      }
   }

   return (0);
}
Пример #8
0
int main(int argc, char **argv)
{
   int m = ORDER, itype = ITYPE, i, gain = GAIN;
   FILE *fp = stdin;
   double *a, *lsp, sampling = SAMPLING;
   Boolean loggain = LOGGAIN;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 's':
            sampling = atof(*++argv);
            --argc;
            break;
         case 'k':
            gain = 0;
            break;
         case 'l':
         case 'L':
            loggain = TR;
            break;
         case 'i':
         case 'q':
            itype = atoi(*++argv);
            --argc;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   lsp = dgetmem(m + m + 1 + gain);
   a = lsp + m + gain;

   while (freadf(lsp, sizeof(*lsp), m + gain, fp) == m + gain) {
      if (itype == 0)
         for (i = gain; i < m + gain; i++)
            lsp[i] /= PI2;
      else if (itype == 2 || itype == 3)
         for (i = gain; i < m + gain; i++)
            lsp[i] /= sampling;

      if (itype == 3)
         for (i = gain; i < m + gain; i++)
            lsp[i] /= 1000;

      lsp2lpc(lsp + gain, a, m);

      if (gain) {
         if (loggain)
            *lsp = exp(*lsp);
         fwritef(lsp, sizeof(*lsp), 1, stdout);
      }
      fwritef(a + gain, sizeof(*a), m + 1 - gain, stdout);
   }

   return (0);
}
Пример #9
0
Файл: mglsadf.c Проект: EQ4/SPTK
int main(int argc, char **argv)
{
   int m = ORDER, fprd = FPERIOD, iprd = IPERIOD, stage = STAGE, pd =
       PADEORDER, i, j;
   Boolean transpose = TRANSPOSE, ngain = NGAIN, inverse = INVERSE;
   FILE *fp = stdin, *fpc = NULL;
   double alpha = ALPHA, gamma = -1 / (double) STAGE, x, *c, *inc, *cc, *d;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'a':
            alpha = atof(*++argv);
            --argc;
            break;
         case 'c':
            stage = atoi(*++argv);
            --argc;
            break;
         case 'p':
            fprd = atoi(*++argv);
            --argc;
            break;
         case 'i':
            iprd = atoi(*++argv);
            --argc;
            break;
         case 't':
            transpose = 1 - transpose;
            break;
         case 'v':
            inverse = 1 - inverse;
            break;
         case 'k':
            ngain = 1 - ngain;
            break;
         case 'P':
            pd = atoi(*++argv);
            --argc;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else if (fpc == NULL)
         fpc = getfp(*argv, "rb");
      else
         fp = getfp(*argv, "rb");

   if (fpc == NULL) {
      fprintf(stderr, "%s : Cannot open cepstrum file!\n", cmnd);
      return (1);
   }

   if (inverse) {
      if (stage == 0) {
         fprintf(stderr, "%s : gamma should not equal to 0 in Inverse MGLSA!\n",
                 cmnd);
         usage(1);
      }
   }

   if (stage != 0) {            /* MGLSA */
      gamma = -1 / (double) stage;
   } else {                     /* MLSA */
      if ((pd < 4) || (pd > 5)) {
         fprintf(stderr, "%s : Order of Pade approximation should be 4 or 5!\n",
                 cmnd);
         return (1);
      }
   }

   c = (stage != 0) ? dgetmem(m + m + m + 3 + (m + 1) * stage)  /* MGLSA */
       : dgetmem(3 * (m + 1) + 3 * (pd + 1) + pd * (m + 2));    /* MLSA  */
   cc = c + m + 1;
   inc = cc + m + 1;
   d = inc + m + 1;

   if (freadf(c, sizeof(*c), m + 1, fpc) != m + 1)
      return (1);
   mc2b(c, c, m, alpha);
   if (stage != 0) {            /* MGLSA */
      gnorm(c, c, m, gamma);
      c[0] = log(c[0]);
      for (i = 1; i <= m; i++)
         c[i] *= gamma;
   }


   for (;;) {
      if (freadf(cc, sizeof(*cc), m + 1, fpc) != m + 1)
         return (0);
      mc2b(cc, cc, m, alpha);
      if (stage != 0) {
         gnorm(cc, cc, m, gamma);
         cc[0] = log(cc[0]);
         for (i = 1; i <= m; i++)
            cc[i] *= gamma;
      }

      for (i = 0; i <= m; i++)
         inc[i] = (cc[i] - c[i]) * iprd / fprd;

      for (j = fprd, i = (iprd + 1) / 2; j--;) {
         if (freadf(&x, sizeof(x), 1, fp) != 1)
            return (0);


         if (inverse) {         /* IMGLSA */
            if (!ngain)
               x /= exp(c[0]);
            if (transpose)
               x = imglsadft(x, c, m, alpha, stage, d);
            else
               x = imglsadf(x, c, m, alpha, stage, d);
         } else {
            if (stage != 0) {   /* MGLSA */
               if (!ngain)
                  x *= exp(c[0]);
               if (transpose)
                  x = mglsadft(x, c, m, alpha, stage, d);
               else
                  x = mglsadf(x, c, m, alpha, stage, d);
            } else {            /* MLSA */
               if (!ngain)
                  x *= exp(c[0]);
               x = mlsadf(x, c, m, alpha, pd, d);
            }
         }

         fwritef(&x, sizeof(x), 1, stdout);

         if (!--i) {
            for (i = 0; i <= m; i++)
               c[i] += inc[i];
            i = iprd;
         }
      }

      movem(cc, c, sizeof(*cc), m + 1);
   }

   return (0);
}
Пример #10
0
int main(int argc, char **argv)
{
   int length, frame_shift = FRAME_SHIFT, atype = ATYPE, otype = OTYPE;
   double *x, thresh_rapt = THRESH_RAPT, thresh_swipe =
       THRESH_SWIPE, thresh_reaper = THRESH_REAPER, sample_freq = SAMPLE_FREQ,
       L = LOW, H = HIGH;
   FILE *fp = stdin;
   float_list *top, *cur, *prev;
   void rapt(float_list * flist, int length, double sample_freq,
             int frame_shift, double min, double max, double threshold,
             int otype);
   void swipe(float_list * input, int length, double sample_freq,
              int frame_shift, double min, double max, double threshold,
              int otype);
   void reaper(float_list * input, int length, double sample_freq,
               int frame_shift, double min, double max, double threshold,
               int otype);

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'a':
            atype = atoi(*++argv);
            --argc;
            break;
         case 's':
            sample_freq = atof(*++argv);
            --argc;
            break;
         case 'p':
            frame_shift = atoi(*++argv);
            --argc;
            break;
         case 't':
            if ((*(*argv + 2)) == '0') {
               thresh_rapt = atof(*++argv);
               --argc;
            } else if ((*(*argv + 2)) == '1') {
               thresh_swipe = atof(*++argv);
               --argc;
            } else {
               thresh_reaper = atof(*++argv);
               --argc;
            }
            break;
         case 'L':
            L = atof(*++argv);
            --argc;
            break;
         case 'H':
            H = atof(*++argv);
            --argc;
            break;
         case 'o':
            otype = atoi(*++argv);
            --argc;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else {
         fp = getfp(*argv, "rb");
      }
   sample_freq *= 1000.0;

   x = dgetmem(1);
   top = prev = (float_list *) malloc(sizeof(float_list));
   length = 0;
   prev->next = NULL;
   while (freadf(x, sizeof(*x), 1, fp) == 1) {
      cur = (float_list *) malloc(sizeof(float_list));
      cur->f = (float) x[0];
      length++;
      prev->next = cur;
      cur->next = NULL;
      prev = cur;
   }

   if (atype == 0) {
      rapt(top->next, length, sample_freq, frame_shift, L, H, thresh_rapt,
           otype);
   } else if (atype == 1) {
      swipe(top->next, length, sample_freq, frame_shift, L, H, thresh_swipe,
            otype);
   } else {
      reaper(top->next, length, sample_freq, frame_shift, L, H, thresh_reaper,
             otype);
   }

   return (0);
}
Пример #11
0
int main(int argc, char **argv)
{
   int l = LENG, fprd = FPERIOD, ns, i, rnum, ts, cs;
   FILE *fp = stdin;
   Boolean noctr = NOCTR;
   double *x, *xx, *p1, *p2, *p;
   char *s, c;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (*(s = *++argv) == '-') {
         c = *++s;
         switch (c) {
         case 'l':
            l = atoi(*++argv);
            --argc;
            break;
         case 'p':
            fprd = atoi(*++argv);
            --argc;
            break;
         case 'n':
            noctr = 1 - noctr;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   x = dgetmem(l);
   if (!noctr) {
      i = (int) ((l + 1) / 2);
      rnum = freadf(&x[(int) (l / 2)], sizeof(*x), i, fp);
   } else
      rnum = freadf(x, sizeof(*x), l, fp);
   if (rnum == 0)
      return 0;
   cs = rnum;
   fwritef(x, sizeof(*x), l, stdout);

   if ((ns = (l - fprd)) > 0) {
      p = &x[fprd];
      for (;;) {
         p1 = x;
         p2 = p;
         i = ns;
         while (i--) {
            *p1++ = *p2++;
         }
         rnum = freadf(p1, sizeof(*p1), fprd, fp);
         if (rnum < fprd) {
            ts = fprd - rnum;
            cs -= ts;
            while (rnum--)
               p1++;
            while (ts--)
               *p1++ = 0.0;
         }
         if (cs <= 0)
            break;
         fwritef(x, sizeof(*x), l, stdout);
      }
   } else {
      i = -ns;
      xx = dgetmem(i);
      for (;;) {
         if (freadf(xx, sizeof(*xx), i, fp) != i)
            break;
         rnum = freadf(x, sizeof(*x), l, fp);
         if (rnum < l) {
            if (rnum == 0)
               break;
            ts = l - rnum;
            p1 = x;
            while (rnum--)
               p1++;
            while (ts--)
               *p1++ = 0.0;
         }
         fwritef(x, sizeof(*x), l, stdout);
      }
   }

   return 0;
}
Пример #12
0
int sopr(FILE * fp)
{
   double x, y;
   int k, i;
   Boolean skipflg = FA;

   while (freadf(&x, sizeof(x), 1, fp) == 1) {
      for (k = 0; k < MEMSIZE; ++k)
         mem[k] = 0;
      for (k = 0; k < nopr; ++k) {
         y = optbl[k].d;
         if (optbl[k].magic) {  /* -magic or -MAGIC */
            if (optbl[k].ifrep) {       /* -MAGIC */
               if (x == optbl[mopr].d) {        /* still remains magic number */
                  x = y;        /* substitute by new magic number */
                  skipflg = FA;
               }
            } else if (x == y) {        /* -magic */
               skipflg = TR;
            }
         } else if (skipflg == FA) {
            switch (optbl[k].op[0]) {
            case 'r':
               x = mem[(int) y];
               break;
            case 'w':
               mem[(int) y] = x;
               break;
            case '+':
               x += mem[(int) y];
               break;
            case '-':
               x -= mem[(int) y];
               break;
            case '*':
               x *= mem[(int) y];
               break;
            case '/':
               x /= mem[(int) y];
               break;
            case 'a':
               x += y;
               break;
            case 's':
               x -= y;
               break;
            case 'm':
               x *= y;
               break;
            case 'd':
               x /= y;
               break;
            case 'f':
               x = (x < y) ? y : x;
               break;
            case 'c':
               x = (x > y) ? y : x;
               break;
            case 'A':
               if (optbl[k].op[1] == 'T')
                  x = atan(x);
               else if (x < 0)
                  x = -x;
               break;
            case 'C':
               if (optbl[k].op[1] == 'L') {
                  if (x < 0)
                     x = 0;
               } else
                  x = cos(x);
               break;
            case 'I':
               x = 1 / x;
               break;
            case 'P':
               if (optbl[k].op[1] == 'O' && optbl[k].op[3] == '1')
                  x = pow(10.0, x);
               else if (optbl[k].op[1] == 'O' && optbl[k].op[3] == '2')
                  x = pow(2.0, x);
               else
                  x *= x;
               break;
            case 'R':
               x = sqrt(x);
               break;
            case 'S':
               if (optbl[k].op[1] == 'Q')
                  x = sqrt(x);
               else
                  x = sin(x);
               break;
            case 'E':
               x = exp(x);
               break;
            case 'L':
               if (optbl[k].op[3] == '1')
                  x = log10(x);
               else if (optbl[k].op[3] == '2')
                  x = LOG2(x);
               else
                  x = log(x);
               break;
            case 'F':
               if (x < 0)
                  i = x - 0.5;
               else
                  i = x + 0.5;
               x = i;
               break;
            case 'T':
               x = tan(x);
               break;
            case 'U':
               if (x < 0)
                  x = 0;
               else
                  x = 1;
            case 'M':

            default:
               break;
            }
         }
      }
      if (skipflg == FA)
         fwritef(&x, sizeof(x), 1, stdout);
      skipflg = FA;
   }
   return (0);
}
Пример #13
0
int main(int argc, char *argv[])
{
   int flng = FLMLNG, m = -1, n = -1;
   int unlap = UNLAP;
   double *p, *z, *ph;
   char *file_z = "", *file_p = "";
   FILE *fp_z = NULL, *fp_p = NULL;
   int no;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;

   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'n':
            n = atoi(*++argv);
            --argc;
            break;
         case 'l':
            flng = atoi(*++argv);
            --argc;
            break;
         case 'z':
            file_z = *++argv;
            --argc;
            break;
         case 'p':
            file_p = *++argv;
            --argc;
            break;
         case 'u':
            unlap = 1 - unlap;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else {
         fprintf(stderr, "%s : Input file is not available!\n", cmnd);
         usage(1);
      }
   if (m < 0)
      m = flng - 1;
   if (n < 0)
      n = flng - 1;
   no = flng / 2 + 1;

   p = dgetmem(2 * flng + n);
   z = &p[flng];
   ph = &z[flng];

   if (*file_z != '\0')
      fp_z = getfp(file_z, "rb");

   if (*file_p != '\0')
      fp_p = getfp(file_p, "rb");

   if (*file_z == '\0' && *file_p == '\0')
      fp_z = stdin;
   for (;;) {
      if (*file_z == '\0' && *file_p != '\0') {
         z[0] = 1;
         n = 0;
      } else {
         if (freadf(z, sizeof(*z), n + 1, fp_z) == 0)
            return (0);
      }

      if (*file_p == '\0') {
         p[0] = 1;
         m = 0;
      } else {
         if (freadf(p, sizeof(*p), m + 1, fp_p) == 0)
            return (0);
      }
      phase(p, m, z, n, ph, flng, unlap);
      fwritef(ph, sizeof(*ph), no, stdout);
   }

   return (0);
}
Пример #14
0
Файл: ifft.c Проект: rhdunn/sptk
int main(int argc, char *argv[])
{
   FILE *fp;
   char *s, *infile = NULL, c;
   int size2;
   double *x, *y;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;

   while (--argc) {
      if (*(s = *++argv) == '-') {
         c = *++s;
         if ((c == 'l') && (*++s == '\0')) {
            s = *++argv;
            --argc;
         }
         switch (c) {
         case 'l':
            size = atoi(s);
            break;
         case 'i':
         case 'r':
            c -= ('a' - 'A');
         case 'I':
         case 'R':
            out = c;
            break;
         case 'h':
         default:
            usage();
         }
      } else
         infile = s;
   }

   fp = stdin;

   if (infile) {
      fp = getfp(infile, "rb");
   }

   x = dgetmem(size2 = size + size);
   y = x + size;

   while (!feof(fp)) {
      if (freadf(x, sizeof(*x), size2, fp) != size2)
         break;

      ifft(x, y, size);

      if (out != 'I')
         fwritef(x, sizeof(*x), size, stdout);
      if (out != 'R')
         fwritef(y, sizeof(*y), size, stdout);
   }

   if (infile) {
      fclose(fp);
   }

   return (0);
}
Пример #15
0
Файл: fftr.c Проект: rhdunn/sptk
int main(int argc, char *argv[])
{
   FILE *fp;
   char *s, *infile = NULL, c;
   int size = SIZE, nout = 0, k, nd = -1, out = ' ';
   double *x, *y;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc) {
      if (*(s = *++argv) == '-') {
         c = *++s;
         if ((c == 'l' || c == 'm') && (*++s == '\0')) {
            s = *++argv;
            --argc;
         }
         switch (c) {
         case 'l':
            size = atoi(s);
            break;
         case 'm':
            nd = atoi(s) + 1;
            break;
         case 'H':
            nout = 1;
            break;
         case 'i':
         case 'p':
         case 'r':
            c -= ('a' - 'A');
         case 'A':
         case 'I':
         case 'P':
         case 'R':
            out = c;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, c);
            usage(1);
         }
      } else
         infile = s;
   }

   if (nd == -1)
      nd = size;
   if (nd > size) {
      fprintf(stderr,
              "%s : Order of sequence %d should be less than the FFT size %d!\n",
              cmnd, nd, size);
      return (1);
   }

   nout = (nout) ? size / 2 + 1 : size;

   fp = stdin;

   if (infile) {
      fp = getfp(infile, "rb");
   }

   x = dgetmem(size + size);
   y = x + size;

   while (!feof(fp)) {
      fillz(x, size, sizeof(*x));
      if (freadf(x, sizeof(*x), nd, fp) == 0)
         break;
      fftr(x, y, size);
      if (out == 'P')
         for (k = 0; k < size; k++)
            x[k] = x[k] * x[k] + y[k] * y[k];
      else if (out == 'A')
         for (k = 0; k < size; k++)
            x[k] = sqrt(x[k] * x[k] + y[k] * y[k]);
      if (out != 'I')
         fwritef(x, sizeof(*x), nout, stdout);
      if (out == ' ' || out == 'I')
         fwritef(y, sizeof(*y), nout, stdout);
   }

   if (infile) {
      fclose(fp);
   }

   return (0);
}
Пример #16
0
int main(int argc, char **argv)
{
    int m1 = ORDER1, m2 = ORDER2, i;
    double a1 = ALPHA1, a2 = ALPHA2, g1 = GAMMA1, g2 = GAMMA2, *c1, *c2;
    Boolean norm1 = NORMFLG1, norm2 = NORMFLG2, mulg1 = MULGFLG1, mulg2 =
                                          MULGFLG2;
    FILE *fp = stdin;

    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 'g':
                g1 = atof(*++argv);
                --argc;
                break;
            case 'c':
                g1 = atoi(*++argv);
                --argc;
                if (g1 < 1)
                    fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd);
                g1 = -1.0 / g1;
                break;
            case 'G':
                g2 = atof(*++argv);
                --argc;
                break;
            case 'C':
                g2 = atoi(*++argv);
                --argc;
                if (g2 < 1)
                    fprintf(stderr, "%s : value of C must be C>=1!\n", cmnd);
                g2 = -1.0 / g2;
                break;
            case 'n':
                norm1 = 1 - norm1;
                break;
            case 'N':
                norm2 = 1 - norm2;
                break;
            case 'u':
                mulg1 = 1 - mulg1;
                break;
            case 'U':
                mulg2 = 1 - mulg2;
                break;
            case 'h':
                usage(0);
            default:
                fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
                usage(1);
            }
        } else
            fp = getfp(*argv, "rb");

    c1 = dgetmem(m1 + m2 + 2);
    c2 = c1 + m1 + 1;

    if (mulg1 && g1 == 0) {
        fprintf(stderr,
                "%s : gamma for input mgc coefficients should not equal to 0 if you specify -u option!\n",
                cmnd);
        usage(1);
    }

    while (freadf(c1, sizeof(*c1), m1 + 1, fp) == m1 + 1) {

        if (norm1)
            ignorm(c1, c1, m1, g1);
        else if (mulg1) {
            c1[0] = (c1[0] - 1.0) / g1;
            for (i = m1; i >= 1; i--)
                c1[i] /= g1;
        }

        mgc2mgc(c1, m1, a1, g1, c2, m2, a2, g2);

        if (norm2)
            gnorm(c2, c2, m2, g2);
        else if (mulg2)
            c1[0] = c1[0] * g2 + 1.0;

        if (mulg2)
            for (i = m2; i >= 1; i--)
                c2[i] *= g2;

        fwritef(c2, sizeof(*c2), m2 + 1, stdout);
    }

    return (0);
}
Пример #17
0
int main(int argc, char **argv)
{
   int l = LENG, ii, end;
   FILE *fp = stdin;
   double i = MIN, j = MAX, x1, y1, x2, y2, y, x, t;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'l':
            l = atoi(*++argv) - 1;
            --argc;
            break;
         case 'm':
            l = atoi(*++argv);
            --argc;
            break;
         case 'x':
            i = atof(*++argv);
            --argc;
            j = atof(*++argv);
            --argc;
            break;
         case 'i':
            i = atof(*++argv);
            --argc;
            break;
         case 'j':
            j = 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, "rb");

   t = (j - i) / (double) l;

   for (;;) {
      if (freadf(&x2, sizeof(x2), 1, fp) != 1)
         break;
      if (freadf(&y2, sizeof(y2), 1, fp) != 1)
         break;

      fwritef(&y2, sizeof(y2), 1, stdout);

      for (end = 0, ii = 1; end == 0;) {
         x1 = x2;
         y1 = y2;
         if (freadf(&x2, sizeof(x2), 1, fp) != 1)
            break;
         if (freadf(&y2, sizeof(y2), 1, fp) != 1)
            break;

         if (x2 == j)
            end = 1;
         for (;; ii++) {
            x = i + t * ii;
            if (x > x2)
               break;
            y = ((y1 - y2) * x + x1 * y2 - x2 * y1) / (x1 - x2);
            fwritef(&y, sizeof(y), 1, stdout);
         }
      }
   }

   return (0);
}
Пример #18
0
int main(int argc, char **argv)
{
   int m = ORDER, l = LENG, otype = OTYPE, no, i;
   double alpha = ALPHA, gamma = GAMMA, *c, *x, *y, logk;
   Boolean norm = NORM, phase = PHASE, mulg = MULG;
   FILE *fp = stdin;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'a':
            alpha = atof(*++argv);
            --argc;
            break;
         case 'g':
            gamma = atof(*++argv);
            --argc;
            break;
         case 'c':
            gamma = atoi(*++argv);
            --argc;
            if (gamma < 1)
               fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd);
            gamma = -1.0 / gamma;
            break;
         case 'n':
            norm = 1 - norm;
            break;
         case 'u':
            mulg = 1 - mulg;
            break;
         case 'l':
            l = atoi(*++argv);
            --argc;
            break;
         case 'o':
            otype = atoi(*++argv);
            --argc;
            break;
         case 'p':
            phase = 1 - phase;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   x = dgetmem(l + l + m + 1);
   y = x + l;
   c = y + l;

   no = l / 2 + 1;
   logk = 20.0 / log(10.0);

   while (freadf(c, sizeof(*c), m + 1, fp) == m + 1) {
      if (norm)
         ignorm(c, c, m, gamma);
      else if (mulg) {
         if (gamma == 0) {
            fprintf(stderr,
                    "%s : gamma for input mgc coefficients should not equal to 0 if you specify -u option!\n",
                    cmnd);
            usage(1);
         }
         c[0] = (c[0] - 1.0) / gamma;
      }

      if (mulg) {
         if (gamma == 0) {
            fprintf(stderr,
                    "%s : gamma for input mgc coefficients should not equal to 0 if you specify -u option!\n",
                    cmnd);
            usage(1);
         }
         for (i = m; i > 0; i--)
            c[i] /= gamma;
      }

      mgc2sp(c, m, alpha, gamma, x, y, l);

      if (phase)
         switch (otype) {
         case 1:
            for (i = no; i--;)
               x[i] = y[i];
            break;
         case 2:
            for (i = no; i--;)
               x[i] = y[i] * 180 / PI;
            break;
         default:
            for (i = no; i--;)
               x[i] = y[i] / PI;
            break;
      } else
         switch (otype) {
         case 1:
            break;
         case 2:
            for (i = no; i--;)
               x[i] = exp(x[i]);
            break;
         case 3:
            for (i = no; i--;)
               x[i] = exp(2 * x[i]);
            break;
         default:
            for (i = no; i--;)
               x[i] *= logk;
            break;
         }

      fwritef(x, sizeof(*x), no, stdout);
   }

   return (0);
}
Пример #19
0
int main(int argc, char **argv)
{
   int leng = LENG, m = ORDER, itype = ITYPE, otype = OTYPE, gain = GAIN;
   double alpha = ALPHA, gamma = GAMMA;
   FILE *fp = stdin;
   double logk, sampling = SAMPLING;
   double *x, *lsp;
   int i, no, loggain = 1;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;
   while (--argc)
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'a':
         case 'g':
         case 'c':
            if (isdigit(**(argv + 1)) == 0) {   /* Check the value is correct */
               if (**(argv + 1) != '+' && **(argv + 1) != '-') {
                  fprintf(stderr, "%s : need numerical number !\n", cmnd);
                  usage(1);
               } else if (isdigit(*(*(argv + 1) + 1)) == 0) {
                  fprintf(stderr, "%s : need numerical number !\n", cmnd);
                  usage(1);
               }
            }

            if ((*(*argv + 1)) == 'a') {
               alpha = atof(*++argv);
            } else if ((*(*argv + 1)) == 'g') {
               gamma = atof(*++argv);
               if (gamma == 0.0) {
                  fprintf(stderr, "%s : value of g must not be zero!\n", cmnd);
               }
            } else {
               gamma = atof(*++argv);
               if (gamma < 1)
                  fprintf(stderr, "%s : value of c must be c>=1!\n", cmnd);
               gamma = -1.0 / gamma;
            }

            --argc;
            break;

         case 'm':
         case 's':
         case 'l':
         case 'i':
         case 'q':
         case 'o':
            if (isdigit(**(argv + 1)) == 0) {
               if ((**(argv + 1)) != '+') {
                  fprintf(stderr,
                          "%s : %s option need positive value !\n", cmnd,
                          *argv);
                  usage(1);
               } else if (isdigit(*(*(argv + 1) + 1)) == 0) {
                  fprintf(stderr,
                          "%s : %s option need positive value !\n", cmnd,
                          *argv);
                  usage(1);
               }
            }

            if ((*(*argv + 1)) == 'm')
               m = atoi(*++argv);
            else if ((*(*argv + 1)) == 's')
               sampling = atof(*++argv);
            else if ((*(*argv + 1)) == 'l')
               leng = atoi(*++argv);
            else if ((*(*argv + 1)) == 'i' || (*(*argv + 1)) == 'q')
               itype = atoi(*++argv);
            else if ((*(*argv + 1)) == 'o')
               otype = atoi(*++argv);
            --argc;
            break;
         case 'L':
            loggain = 0;
            break;
         case 'k':
            gain = 0;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else
         fp = getfp(*argv, "rb");

   lsp = dgetmem(m + gain);
   no = leng / 2 + 1;
   x = dgetmem(no);
   logk = 20.0 / log(10.0);

   while (freadf(lsp, sizeof(*lsp), m + gain, fp) == m + gain) {

      if (itype == 1)
         for (i = gain; i < m + gain; i++)
            lsp[i] *= PI2;
      else if (itype == 2 || itype == 3) {
         for (i = gain; i < m + gain; i++)
            lsp[i] = lsp[i] / sampling * PI2;
      }

      if (loggain == 0)
         *lsp = log(*lsp);

      mgclsp2sp(alpha, gamma, lsp, m, x, no, gain);

      switch (otype) {
      case 1:
         break;
      case 2:
         for (i = no; i--;)
            x[i] = exp(x[i]);
         break;
      case 3:
         for (i = no; i--;)
            x[i] = exp(2 * x[i]);
         break;
      default:
         for (i = no; i--;)
            x[i] *= logk;
         break;
      }
      fwritef(x, sizeof(*x), no, stdout);
   }

   free(lsp);
   free(x);

   return (0);
}
Пример #20
0
int main(int argc, char **argv)
{
   int m = ORDER, pd = PADEORDER, fftlen = FFTLENGTH, stable_condition =
       STABLE1, frame = 0, c = 0;
   double *mcep, a = ALPHA, r = PADE4_THRESH1, R = 0.0;
   FILE *fp = stdin;

   if ((cmnd = strrchr(argv[0], '/')) == NULL) {
      cmnd = argv[0];
   } else {
      cmnd++;
   }
   while (--argc) {
      if (**++argv == '-') {
         switch (*(*argv + 1)) {
         case 'm':
            m = atoi(*++argv);
            --argc;
            break;
         case 'a':
            a = atof(*++argv);
            --argc;
            break;
         case 'P':
            pd = atoi(*++argv);
            --argc;
            break;
         case 'l':
            fftlen = atoi(*++argv);
            --argc;
            break;
         case 'c':
            c = atoi(*++argv);
            if ((c != 0 && c != 1 && c != 2 && c != 3 && c != 4)
                || isdigit(**argv) == 0) {
               fprintf(stderr,
                       "%s : '-c' option must be specified with 0, 1, 2, 3 or 4.\n",
                       cmnd);
               usage(1);
            }
            --argc;
            break;
         case 'r':
            stable_condition = atoi(*++argv);
            if (stable_condition != STABLE1 && stable_condition != STABLE2) {
               fprintf(stderr,
                       "%s : '-r' option must be specified with %d or %d.\n",
                       cmnd, STABLE1, STABLE2);
               usage(1);
            }
            --argc;
            break;
         case 'R':
            R = atof(*++argv);
            if (isdigit(**argv) == 0) {
               fprintf(stderr,
                       "%s : '-R' option must be specified by real number !\n",
                       cmnd);
               usage(1);
            }
            --argc;
            break;
         case 'h':
            usage(0);
         default:
            fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1));
            usage(1);
         }
      } else {
         fp = getfp(*argv, "rb");
      }
   }

   switch (pd) {
   case 4:
      if (stable_condition == STABLE1)
         r = PADE4_THRESH1;
      else
         r = PADE4_THRESH2;
      break;
   case 5:
      if (stable_condition == STABLE1)
         r = PADE5_THRESH1;
      else
         r = PADE5_THRESH2;
      break;
   default:
      fprintf(stderr, "%s : Order of Pade approximation should be 4 or 5!\n",
              cmnd);
      usage(1);
   }
   if (R != 0.0)
      r = R;

   mcep = dgetmem(m + 1);

   /* check stability of MLSA filter and output */
   while (freadf(mcep, sizeof(*mcep), m + 1, fp) == m + 1) {
      mlsacheck(mcep, m, fftlen, frame, a, r, c);
      frame++;
   }

   return (0);
}
Пример #21
0
int main(int argc, char *argv[])
{
   char *s;
   int c, k, odr = ORDER, itrat = ITER, form = 0, a_zero = 0;
   double *a, *d, eps = EPS;
   FILE *fp = stdin;
   complex *x;

   if ((cmnd = strrchr(argv[0], '/')) == NULL)
      cmnd = argv[0];
   else
      cmnd++;

   while (--argc > 0) {
      if (*(s = *++argv) == '-') {
         c = *++s;
         switch (c) {
         case 'i':
            a_zero = 1;
            break;
         case 'r':
            form |= 1;
            break;
         case 's':
            form |= 2;
            break;
         case 'e':
            if (*++s == '\0') {
               s = *++argv;
               --argc;
            }
            eps = atof(s);
            break;
         case 'm':
            if (*++s == '\0') {
               s = *++argv;
               --argc;
            }
            odr = atoi(s);
            break;
         case 'n':
            if (*++s == '\0') {
               s = *++argv;
               --argc;
            }
            itrat = atoi(s);
            break;
         default:
            usage();
         }
      } else
         fp = getfp(*argv, "rb");
   }

   a = dgetmem(odr + 1);
   odr = freadf(a, sizeof(*a), odr, fp) - 1;

   d = dgetmem(odr + 1);
   x = cplx_getmem(odr + 1);

   for (k = 0; k <= odr; ++k)
      d[k] = a[k];

   root_pol(d, odr, x, a_zero, eps, itrat);
   output_root_pol(x, odr, form);

   return (0);
}