Esempio n. 1
0
/** 
 * Convert a binary type code to string.
 *
 * @param buf [out] buffer to store the resulting string (must have enough length)
 * @param type [in] binary type code to convert.
 * @param descflag [in] set to TRUE if you want result in description string
 * instead of base and qualifier string.
 * 
 * @return @a buf on success, NULL on failure.
 */
char *
param_code2str(char *buf, short type, boolean descflag)
{
  int i;
  short btype;

  /* basetype */
  btype = type & F_BASEMASK;
  for (i = 0; pbase[i].name != NULL; i++) {
    if (pbase[i].type == btype) {
      if (descflag) {
	sprintf(buf, "%s %s with:\n", pbase[i].desc,
		(pbase[i].supported ? "" : "(not supported)"));
      } else {
	strcpy(buf, pbase[i].name);
      }
      break;
    }
  }
  if (pbase[i].name  == NULL) {	/* not found */
    sprintf(buf, "ERROR: unknown basetype ID: %d\n", btype);
    return(buf);
  }

  /* add qualifier string to buf */
  param_qualcode2str(buf, type, descflag);

  return(buf);
}
Esempio n. 2
0
/**
 * Compare source parameter type and required type in HTK %HMM, and set mark.
 *
 * @param src [in] input parameter
 * @param dst_type_arg [in] required parameter type
 * @param vmark [in] mark buffer
 * @param vlen [in] length of vmark
 * @param new_type [out] return the new type
 *
 * @return TRUE on success, FALSE on failure.
 */
static boolean
select_param_vmark(HTK_Param *src, short dst_type_arg, int *vmark, int vlen, short *new_type)
{
    short dst_type;
    short del_type, add_type;
    int basenum, pb[3],pe[3],p0[3]; /* location */
    int i, len;
    char srcstr[80], dststr[80], buf[80];
    short src_type;

    src_type = src->header.samptype & ~(F_COMPRESS | F_CHECKSUM);
    src_type &= ~(F_BASEMASK);	/* only qualifier code needed */
    srcstr[0] = '\0';
    param_qualcode2str(srcstr, src_type, FALSE);
    dst_type = dst_type_arg & ~(F_COMPRESS | F_CHECKSUM);
    dst_type &= ~(F_BASEMASK);	/* only qualifier code needed */
    dststr[0] = '\0';
    param_qualcode2str(dststr, dst_type, FALSE);

#ifdef DEBUG
    printf("try to select qualifiers: %s -> %s\n", srcstr, dststr);
#endif

    if (dst_type == F_ERR_INVALID) {
        jlog("Error: paramselect: unknown parameter kind for selection: %s\n", dststr);
        return(FALSE);
    }

    /* guess base coefficient num */
    basenum = guess_basenum(src, src_type);
    if (basenum < 0) {		/* error */
        return(FALSE);
    }
#ifdef DEBUG
    printf("base num = %d\n", basenum);
#endif

    /* determine which component to use */
    del_type = src_type & (~(dst_type));
    add_type = (~(src_type)) & dst_type;

    /* vector layout for exclusion*/
    pb[0] = 0;
    if ((src_type & F_ENERGY) && (src_type & F_ZEROTH)) {
        p0[0] = basenum;
        pe[0] = basenum + 1;
        len = basenum + 2;
    } else if ((src_type & F_ENERGY) || (src_type & F_ZEROTH)) {
        p0[0] = pe[0] = basenum;
        len = basenum + 1;
    } else {
        p0[0] = pe[0] = 0;
        len = basenum;
    }
    for (i=1; i<3; i++) {
        pb[i] = pb[i-1] + len;
        pe[i] = pe[i-1] + len;
        p0[i] = p0[i-1] + len;
    }
    if (src_type & F_ENERGY_SUP) {
        pe[0] = 0;
        for (i=1; i<3; i++) {
            pb[i]--;
            pe[i]--;
            p0[i]--;
        }
    }

    /* modification begin */
    /* qualifier addition: "_N" */
#ifdef DEBUG
    buf[0] = '\0';
    printf("try to add: %s\n", param_qualcode2str(buf, add_type, FALSE));
#endif

    if (add_type & F_ENERGY_SUP) {
        if (src_type & F_ENERGY) {
            mark_exclude_vector(pe[0], 1, vmark, vlen);
            src_type = src_type | F_ENERGY_SUP;
        } else if (src_type & F_ZEROTH) {
            mark_exclude_vector(p0[0], 1, vmark, vlen);
            src_type = src_type | F_ENERGY_SUP;
        } else {
            jlog("Warning: paramselect: \"_N\" needs \"_E\" or \"_0\". ignored\n");
        }
        add_type = add_type & (~(F_ENERGY_SUP)); /* set to 0 */
    }
    if (add_type != 0) {		/* others left */
        buf[0] = '\0';
        jlog("Warning: paramselect: can do only parameter exclusion. qualifiers %s ignored\n", param_qualcode2str(buf, add_type, FALSE));
    }

    /* qualifier excludeion: "_D","_A","_0","_E" */
#ifdef DEBUG
    buf[0] = '\0';
    printf("try to del: %s\n", param_qualcode2str(buf, del_type, FALSE));
#endif

    if (del_type & F_DELTA) del_type |= F_ACCL;
    /* mark delete vector */
    if (del_type & F_ACCL) {
        mark_exclude_vector(pb[2], len, vmark, vlen);
        src_type &= ~(F_ACCL);
        del_type &= ~(F_ACCL);
    }
    if (del_type & F_DELTA) {
        mark_exclude_vector(pb[1], len, vmark, vlen);
        src_type &= ~(F_DELTA);
        del_type &= ~(F_DELTA);
    }

    if (del_type & F_ENERGY) {
        mark_exclude_vector(pe[2], 1, vmark, vlen);
        mark_exclude_vector(pe[1], 1, vmark, vlen);
        if (!(src_type & F_ENERGY_SUP)) {
            mark_exclude_vector(pe[0], 1, vmark, vlen);
        }
        src_type &= ~(F_ENERGY | F_ENERGY_SUP);
        del_type &= ~(F_ENERGY | F_ENERGY_SUP);
    }
    if (del_type & F_ZEROTH) {
        mark_exclude_vector(p0[2], 1, vmark, vlen);
        mark_exclude_vector(p0[1], 1, vmark, vlen);
        if (!(src_type & F_ENERGY_SUP)) {
            mark_exclude_vector(p0[0], 1, vmark, vlen);
        }
        src_type &= ~(F_ZEROTH | F_ENERGY_SUP);
        del_type &= ~(F_ZEROTH | F_ENERGY_SUP);
    }

    if (del_type != 0) {		/* left */
        buf[0] = '\0';
        jlog("Warning: paramselect: cannot exclude qualifiers %s. selection ignored\n", param_qualcode2str(buf, del_type, FALSE));
    }


    *new_type = src_type;

    return(TRUE);
}