00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <string.h>
00075 #include <strfuncs.h>
00076
00077 #ifdef _WIN32
00078 #pragma warning (disable: 4996)
00079 #endif
00080
00081 #ifdef HAVE_CONFIG_H
00082 #include <config.h>
00083 #endif
00084
00085 #include "prim_type.h"
00086 #include "cmd_ln.h"
00087 #include "ckd_alloc.h"
00088 #include "info.h"
00089 #include "err.h"
00090 #include "bio.h"
00091
00092
00093 #include "pio.h"
00094
00098 #define IO_ERR (-1)
00099 #define IO_SUCCESS (0)
00100
00101 #define SHOW_ALL "-1"
00102
00103
00104 #define NUM_COEFF "13"
00105
00106
00107
00108
00109 #define DISPLAY_SIZE "10"
00110 #define STR_MAX_INT "2147483647"
00111
00112 static arg_t arg[] = {
00113
00114 {"-logfn",
00115 ARG_STRING,
00116 NULL,
00117 "Log file (default stdout/stderr)"},
00118 {"-i",
00119 ARG_INT32,
00120 NUM_COEFF,
00121 "Number of coefficients in the feature vector."},
00122 {"-d",
00123 ARG_INT32,
00124 DISPLAY_SIZE,
00125 "Number of displayed coefficients."},
00126 {"-header",
00127 ARG_INT32,
00128 "0",
00129 "Whether header is shown."},
00130 {"-describe",
00131 ARG_INT32,
00132 "0",
00133 "Whether description will be shown."},
00134 {"-b",
00135 ARG_INT32,
00136 "0",
00137 "The beginning frame 0-based."},
00138 {"-e",
00139 ARG_INT32,
00140 "2147483647",
00141 "The ending frame."},
00142 {"-f",
00143 ARG_STRING,
00144 NULL,
00145 "Input feature file."},
00146 {NULL, ARG_INT32, NULL, NULL}
00147 };
00148
00149 int read_cep(char const *file, float ***cep, int *nframes, int numcep);
00150
00151 int
00152 main(int argc, char *argv[])
00153 {
00154 int i, j, offset;
00155 int32 noframe, vsize, dsize, column;
00156 int32 frm_begin, frm_end;
00157 int is_header, is_describe;
00158 float *z, **cep;
00159 char const *cepfile;
00160
00161 print_appl_info(argv[0]);
00162 cmd_ln_appl_enter(argc, argv, "default.arg", arg);
00163
00164 vsize = cmd_ln_int32("-i");
00165 dsize = cmd_ln_int32("-d");
00166 frm_begin = cmd_ln_int32("-b");
00167 frm_end = cmd_ln_int32("-e");
00168 is_header = cmd_ln_int32("-header");
00169 is_describe = cmd_ln_int32("-describe");
00170
00171 if (vsize < 0)
00172 E_FATAL("-i : Input vector size should be larger than 0.\n");
00173 if (dsize < 0)
00174 E_FATAL("-d : Column size should be larger than 0\n");
00175 if (frm_begin < 0)
00176 E_FATAL("-b : Beginning frame should be larger than 0\n");
00177
00178
00179
00180 if (frm_begin >= frm_end)
00181 E_FATAL
00182 ("Ending frame (-e) should be larger than beginning frame (-b).\n");
00183
00184 if ((cepfile = cmd_ln_str("-f")) == NULL) {
00185 E_FATAL("Input file was not specified with (-f)\n");
00186 }
00187 if (read_cep(cepfile, &cep, &noframe, vsize) == IO_ERR)
00188 E_FATAL("ERROR opening %s for reading\n", cepfile);
00189
00190 z = cep[0];
00191
00192 offset = 0;
00193 column = (vsize > dsize) ? dsize : vsize;
00194 frm_end = (frm_end > noframe) ? noframe : frm_end;
00195
00196 E_INFO("Displaying %d out of %d columns per frame\n", column, vsize);
00197 E_INFO("Total %d frames\n\n", noframe);
00198
00199
00200
00201
00202 if (is_header) {
00203 if (is_describe) {
00204 printf("\n%6s", "frame#:");
00205 }
00206
00207 for (j = 0; j < column; ++j) {
00208 printf("%3s%3d%s ", "c[", j, "]");
00209 }
00210 printf("\n");
00211 }
00212
00213 offset += frm_begin * vsize;
00214 for (i = frm_begin; i < frm_end; ++i) {
00215 if (is_describe) {
00216 printf("%6d:", i);
00217 }
00218 for (j = 0; j < column; ++j)
00219 printf("%7.3f ", z[offset + j]);
00220 printf("\n");
00221
00222 offset += vsize;
00223 }
00224 fflush(stdout);
00225 cmd_ln_appl_exit();
00226 ckd_free_2d(cep);
00227
00228 return (IO_SUCCESS);
00229
00230 }
00231
00232 int
00233 read_cep(char const *file, float ***cep, int *numframes, int cepsize)
00234 {
00235 FILE *fp;
00236 int n_float;
00237 struct stat statbuf;
00238 int i, n, byterev, sf, ef;
00239 float32 **mfcbuf;
00240
00241 if (stat_retry(file, &statbuf) < 0) {
00242 printf("stat(%s) failed\n", file);
00243 return IO_ERR;
00244 }
00245
00246 if ((fp = fopen(file, "rb")) == NULL) {
00247 printf("fopen(%s, rb) failed\n", file);
00248 return IO_ERR;
00249 }
00250
00251
00252 if (fread(&n_float, sizeof(int), 1, fp) != 1) {
00253 fclose(fp);
00254 return IO_ERR;
00255 }
00256
00257
00258 byterev = FALSE;
00259 if ((int) (n_float * sizeof(float) + 4) != statbuf.st_size) {
00260 n = n_float;
00261 SWAP_INT32(&n);
00262
00263 if ((int) (n * sizeof(float) + 4) != statbuf.st_size) {
00264 printf
00265 ("Header size field: %d(%08x); filesize: %d(%08x)\n",
00266 n_float, n_float, (int) statbuf.st_size,
00267 (int) statbuf.st_size);
00268 fclose(fp);
00269 return IO_ERR;
00270 }
00271
00272 n_float = n;
00273 byterev = TRUE;
00274 }
00275 if (n_float <= 0) {
00276 printf("Header size field: %d\n", n_float);
00277 fclose(fp);
00278 return IO_ERR;
00279 }
00280
00281
00282 n = n_float / cepsize;
00283 if (n * cepsize != n_float) {
00284 printf("Header size field: %d; not multiple of %d\n",
00285 n_float, cepsize);
00286 fclose(fp);
00287 return IO_ERR;
00288 }
00289 sf = 0;
00290 ef = n;
00291
00292 mfcbuf = (float **) ckd_calloc_2d(n, cepsize, sizeof(float32));
00293
00294
00295 n_float = n * cepsize;
00296 if ((int) fread(mfcbuf[0], sizeof(float), n_float, fp) != n_float) {
00297 printf("Error reading mfc data\n");
00298 fclose(fp);
00299 return IO_ERR;
00300 }
00301 if (byterev) {
00302 for (i = 0; i < n_float; i++)
00303 SWAP_FLOAT32(&(mfcbuf[0][i]));
00304 }
00305 fclose(fp);
00306
00307 *numframes = n;
00308 *cep = mfcbuf;
00309 return IO_SUCCESS;
00310 }
00311
00313 #if defined(_WIN32_WCE)
00314 #pragma comment(linker,"/entry:mainWCRTStartup")
00315
00316
00317 int wmain(int32 argc, wchar_t *wargv[]) {
00318 char** argv;
00319 size_t wlen;
00320 size_t len;
00321 int i;
00322
00323 argv = malloc(argc*sizeof(char*));
00324 for (i=0; i<argc; i++){
00325 wlen = lstrlenW(wargv[i]);
00326 len = wcstombs(NULL, wargv[i], wlen);
00327 argv[i] = malloc(len+1);
00328 wcstombs(argv[i], wargv[i], wlen);
00329 }
00330
00331
00332 return main(argc, argv);
00333 }
00334 #endif