Julius 4.2
|
00001 00019 /* 00020 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00021 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00022 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00023 * All rights reserved 00024 */ 00025 00026 #include <sent/stddefs.h> 00027 #include <sent/htk_hmm.h> 00028 #include <sent/ptree.h> 00029 00038 static boolean 00039 save_hmmlist_callback(void *data, FILE *fp) 00040 { 00041 HMM_Logical *l = data; 00042 char *s; 00043 int len; 00044 00045 if (myfwrite(&(l->is_pseudo), sizeof(boolean), 1, fp) < 1) return FALSE; 00046 len = strlen(l->name) + 1; 00047 if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE; 00048 if (myfwrite(l->name, len, 1, fp) < 1) return FALSE; 00049 if (l->is_pseudo) { 00050 s = l->body.pseudo->name; 00051 } else { 00052 s = l->body.defined->name; 00053 } 00054 len = strlen(s) + 1; 00055 if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE; 00056 if (myfwrite(s, len, 1, fp) < 1) return FALSE; 00057 00058 return TRUE; 00059 } 00060 00069 static boolean 00070 save_cdset_callback(void *data, FILE *fp) 00071 { 00072 CD_Set *cd = data; 00073 int len; 00074 int i, j; 00075 00076 len = strlen(cd->name) + 1; 00077 if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE; 00078 if (myfwrite(cd->name, len, 1, fp) < 1) return FALSE; 00079 if (myfwrite(&(cd->tr->id), sizeof(int), 1, fp) < 1) return FALSE; 00080 if (myfwrite(&(cd->state_num), sizeof(unsigned short), 1, fp) < 1) return FALSE; 00081 for(i=0;i<cd->state_num;i++) { 00082 if (myfwrite(&(cd->stateset[i].num), sizeof(unsigned short), 1, fp) < 1) return FALSE; 00083 for(j=0;j<cd->stateset[i].num;j++) { 00084 if (myfwrite(&(cd->stateset[i].s[j]->id), sizeof(int), 1, fp) < 1) return FALSE; 00085 00086 } 00087 } 00088 00089 return TRUE; 00090 } 00091 00101 boolean 00102 save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo) 00103 { 00104 /* write 4 byte as NULL to auto detect file format at read time */ 00105 /* this mark will be read in init_hmminfo() */ 00106 int x = 0; 00107 if (myfwrite(&x, sizeof(int), 1, fp) < 1) { 00108 jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n"); 00109 return FALSE; 00110 } 00111 /* write hmmlist */ 00112 if (aptree_write(fp, hmminfo->logical_root, save_hmmlist_callback) == FALSE) { 00113 jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n"); 00114 return FALSE; 00115 } 00116 /* write cdset */ 00117 if (aptree_write(fp, hmminfo->cdset_info.cdtree, save_cdset_callback) == FALSE) { 00118 jlog("Error: save_hmmlist_bin: failed to write cdset to binary file\n"); 00119 return FALSE; 00120 } 00121 return TRUE; 00122 }