示例#1
0
int main(int argc, char **argv)
{
   int l = LENG, cbsize = CBSIZE, index;
   FILE *fp = stdin, *fpcb = NULL;
   double *x, *cb;

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

   fseek(fpcb, 0, 2);
#ifdef DOUBLE
   cbsize = ftell(fpcb) / sizeof(double) / l;
#else
   cbsize = ftell(fpcb) / sizeof(float) / l;
#endif                          /* DOUBLE */
   rewind(fpcb);

   x = dgetmem(l + cbsize * l);
   cb = x + l;

   if (freadf(cb, sizeof(*cb), cbsize * l, fpcb) != cbsize * l) {
      fprintf(stderr, "%s : Codebook size error!\n", cmnd);
      return (1);
   }

   while (freadx(&index, sizeof(index), 1, fp) == 1) {
      ivq(index, cb, l, x);
      fwritef(x, sizeof(*x), l, stdout);
   }

   return (0);
}
示例#2
0
文件: dlm_vq.c 项目: gitgun/dLabPro
INT16 CGEN_IGNORE dlm_ivq(FLOAT64* Y, INT32 nRY, FLOAT64* Q, INT32 nCQ, INT32 nRQ, INT32* I) {
  INT32 iR = 0;
  extern void ivq(const INT32, FLOAT64*, const INT32, FLOAT64*);

  for (iR = 0; iR < nRY; iR++) {
    ivq(I[iR], Q, nCQ, Y + iR * nCQ);
  }
  return O_K;
}
示例#3
0
文件: vq.c 项目: golden1232004/SPTK
void main(int argc, char **argv)
{
    int		l = LENG, cbsize = CBSIZE, index;
    Boolean	qflag = QFLAG;
    FILE	*fp = stdin, *fpcb = NULL;
    double	*x, *qx, *cb;

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

    fseek(fpcb,0,2);
#ifdef DOUBLE
    cbsize = ftell(fpcb)/sizeof(double)/l;
#else
    cbsize = ftell(fpcb)/sizeof(float)/l;
#endif
    rewind(fpcb);

    x = dgetmem(l+l+cbsize*l);
    qx = x + l;
    cb = qx + l;
    
    if(freadf(cb, sizeof(*cb), cbsize*l, fpcb) != cbsize*l){
	fprintf(stderr,"%s : Codebook size error !\n",cmnd);
	exit(1);
    }

    if(! qflag)
	while (freadf(x, sizeof(*x), l, fp) == l){
	    index = vq(x, cb, l, cbsize);
	    fwrite(&index, sizeof(index), 1, stdout);
	}
    else
	while (freadf(x, sizeof(*x), l, fp) == l){
	    index = vq(x, cb, l, cbsize);
	    ivq(index, cb, l, qx);
	    fwritef(qx, sizeof(*qx), l, stdout);
	}
    
    exit(0);
}