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