libsent/src/anlz/paramtypes.c

Go to the documentation of this file.
00001 
00022 /*
00023  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00024  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00025  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00026  * All rights reserved
00027  */
00028 
00029 #include <sent/stddefs.h>
00030 #include <sent/htk_defs.h>
00031 #include <sent/htk_param.h>
00032 
00033 
00035 static OptionStr pbase[] = {
00036   {"WAVEFORM", F_WAVEFORM, "sampled waveform", FALSE},
00037   {"DISCRETE", F_DISCRETE, "Discrete", FALSE},
00038   {"LPC", F_LPC, "LPC", TRUE},
00039   {"LPCEPSTRA", F_LPCEPSTRA, "LPC cepstral", TRUE},
00040   {"MFCC", F_MFCC, "mel-frequency cepstral", TRUE},
00041   {"FBANK", F_FBANK, "log mel-filter bank", TRUE},
00042   {"MELSPEC", F_MELSPEC, "linear mel-filter bank", TRUE},
00043   {"LPREFC", F_LPREFC, "LPC(reflection)", TRUE},
00044   {"LPDELCEP", F_LPDELCEP, "LPC+Delta", TRUE},
00045   {"USER", F_USER, "user defined sample kind", TRUE},
00046   {NULL,0,NULL,FALSE}
00047 };
00049 static OptionStr pqual[] = {
00050   {"_E", F_ENERGY, "log energy coef.", TRUE},
00051   {"_N", F_ENERGY_SUP, "uppress absolute energy", TRUE},
00052   {"_D", F_DELTA, "delta coef.", TRUE},
00053   {"_A", F_ACCL, "acceleration coef.", TRUE},
00054   {"_C", F_COMPRESS, "compressed", TRUE},
00055   {"_Z", F_CEPNORM, "cepstral mean normalization", TRUE},
00056   {"_K", F_CHECKSUM, "CRC checksum added", TRUE},
00057   {"_0", F_ZEROTH, "0'th cepstral parameter", TRUE},
00058   {NULL,0,NULL,FALSE}
00059 };
00060 
00068 short
00069 param_qualstr2code(char *s)
00070 {
00071   int i, qlen;
00072   char *p;
00073   short qual_type;
00074 
00075   qual_type = 0;
00076   p = s;
00077 
00078   /* parse qualifiers */
00079   while (*p == '_') {
00080     for (i=0;pqual[i].name!=NULL;i++) {
00081       qlen = strlen(pqual[i].name);
00082       if (strncasecmp(p, pqual[i].name, qlen) == 0) {
00083         qual_type |= pqual[i].type;
00084         break;
00085       }
00086     }
00087     if (pqual[i].name == NULL) {        /* qualifier not found */
00088       j_printerr("ERROR: unknown parameter qualifier: %2s\n", p);
00089       return(F_ERR_INVALID);
00090     }
00091     p += 2;
00092   }
00093 
00094   return(qual_type);
00095 }
00096 
00104 short
00105 param_str2code(char *s)
00106 {
00107   int i;
00108   short param_type, qual_type;
00109   char *p, *buf;
00110 
00111   /* determine base type */
00112   /* cutout base part to *buf */
00113   buf = strcpy((char *)mymalloc(strlen(s)+1), s);
00114   p = strchr(buf, '_');
00115   if (p != NULL) *p = '\0';
00116   
00117   for (i=0;pbase[i].name!=NULL;i++) {
00118     if (strcasecmp(buf, pbase[i].name) == 0) {
00119       param_type = pbase[i].type;
00120       /* qualifiers */
00121       qual_type = param_qualstr2code(s + strlen(buf));
00122       if (qual_type == F_ERR_INVALID) {
00123         free(buf);
00124         return(F_ERR_INVALID);
00125       } else {
00126         param_type |= qual_type;
00127         free(buf);
00128         return(param_type);
00129       }
00130     }
00131   }
00132   /* base type not found */
00133   free(buf);
00134   return(F_ERR_INVALID);
00135 }
00136 
00147 char *
00148 param_qualcode2str(char *buf, short type, boolean descflag)
00149 {
00150   int i;
00151 
00152   /* qualifier */
00153   for (i=0;pqual[i].name!=NULL;i++) {
00154     if (type & pqual[i].type) {
00155       if (descflag) {
00156         sprintf(buf, " %s %s\n", pqual[i].desc,
00157                 (pqual[i].supported ? "" : "(not supported)"));
00158       } else {
00159         strcat(buf, pqual[i].name);
00160       }
00161     }
00162   }
00163   return(buf);
00164 }
00165 
00176 char *
00177 param_code2str(char *buf, short type, boolean descflag)
00178 {
00179   int i;
00180   short btype;
00181 
00182   /* basetype */
00183   btype = type & F_BASEMASK;
00184   for (i = 0; pbase[i].name != NULL; i++) {
00185     if (pbase[i].type == btype) {
00186       if (descflag) {
00187         sprintf(buf, "%s %s with:\n", pbase[i].desc,
00188                 (pbase[i].supported ? "" : "(not supported)"));
00189       } else {
00190         strcpy(buf, pbase[i].name);
00191       }
00192       break;
00193     }
00194   }
00195   if (pbase[i].name  == NULL) { /* not found */
00196     sprintf(buf, "ERROR: unknown basetype ID: %d\n", btype);
00197     return(buf);
00198   }
00199 
00200   /* add qualifier string to buf */
00201   param_qualcode2str(buf, type, descflag);
00202 
00203   return(buf);
00204 }

Generated on Tue Dec 26 16:16:33 2006 for Julius by  doxygen 1.5.0