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 <sys/stat.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
00095 #define IO_ERR (-1)
00096 #define IO_SUCCESS (0)
00097
00098 #define SHOW_ALL "-1"
00099
00100
00101 #define NUM_COEFF "13"
00102
00103
00104
00105
00106 #define DISPLAY_SIZE "10"
00107 #define STR_MAX_INT "2147483647"
00108
00109 static arg_t arg[] = {
00110
00111 {"-logfn",
00112 ARG_STRING,
00113 NULL,
00114 "Log file (default stdout/stderr)"},
00115 {"-i",
00116 ARG_INT32,
00117 NUM_COEFF,
00118 "Number of coefficients in the feature vector."},
00119 {"-d",
00120 ARG_INT32,
00121 DISPLAY_SIZE,
00122 "Number of displayed coefficients."},
00123 {"-header",
00124 ARG_INT32,
00125 "0",
00126 "Whether header is shown."},
00127 {"-describe",
00128 ARG_INT32,
00129 "0",
00130 "Whether description will be shown."},
00131 {"-b",
00132 ARG_INT32,
00133 "0",
00134 "The beginning frame 0-based."},
00135 {"-e",
00136 ARG_INT32,
00137 "2147483647",
00138 "The ending frame."},
00139 {"-f",
00140 ARG_STRING,
00141 NULL,
00142 "Input feature file."},
00143 {NULL, ARG_INT32, NULL, NULL}
00144 };
00145
00146 int read_cep(char const *file, float ***cep, int *nframes, int numcep);
00147
00148 int
00149 main(int argc, char *argv[])
00150 {
00151 int i, j, offset;
00152 int32 noframe, vsize, dsize, column;
00153 int32 frm_begin, frm_end;
00154 int is_header, is_describe;
00155 float *z, **cep;
00156 char const *cepfile;
00157
00158 print_appl_info(argv[0]);
00159 cmd_ln_appl_enter(argc, argv, "default.arg", arg);
00160
00161 vsize = cmd_ln_int32("-i");
00162 dsize = cmd_ln_int32("-d");
00163 frm_begin = cmd_ln_int32("-b");
00164 frm_end = cmd_ln_int32("-e");
00165 is_header = cmd_ln_int32("-header");
00166 is_describe = cmd_ln_int32("-describe");
00167
00168 if (vsize < 0)
00169 E_FATAL("-i : Input vector size should be larger than 0.\n");
00170 if (dsize < 0)
00171 E_FATAL("-d : Column size should be larger than 0\n");
00172 if (frm_begin < 0)
00173 E_FATAL("-b : Beginning frame should be larger than 0\n");
00174
00175
00176
00177 if (frm_begin >= frm_end)
00178 E_FATAL
00179 ("Ending frame (-e) should be larger than beginning frame (-b).\n");
00180
00181 if ((cepfile = cmd_ln_str("-f")) == NULL) {
00182 E_FATAL("Input file was not specified with (-f)\n");
00183 }
00184 if (read_cep(cepfile, &cep, &noframe, vsize) == IO_ERR)
00185 E_FATAL("ERROR opening %s for reading\n", cepfile);
00186
00187 z = cep[0];
00188
00189 offset = 0;
00190 column = (vsize > dsize) ? dsize : vsize;
00191 frm_end = (frm_end > noframe) ? noframe : frm_end;
00192
00193 E_INFO("Displaying %d out of %d columns per frame\n", column, vsize);
00194 E_INFO("Total %d frames\n\n", noframe);
00195
00196
00197
00198
00199 if (is_header) {
00200 if (is_describe) {
00201 printf("\n%6s", "frame#:");
00202 }
00203
00204 for (j = 0; j < column; ++j) {
00205 printf("%3s%3d%s ", "c[", j, "]");
00206 }
00207 printf("\n");
00208 }
00209
00210 offset += frm_begin * vsize;
00211 for (i = frm_begin; i < frm_end; ++i) {
00212 if (is_describe) {
00213 printf("%6d:", i);
00214 }
00215 for (j = 0; j < column; ++j)
00216 printf("%7.3f ", z[offset + j]);
00217 printf("\n");
00218
00219 offset += vsize;
00220 }
00221 fflush(stdout);
00222 cmd_ln_appl_exit();
00223 ckd_free_2d(cep);
00224
00225 return (IO_SUCCESS);
00226
00227 }
00228
00229 int
00230 read_cep(char const *file, float ***cep, int *numframes, int cepsize)
00231 {
00232 FILE *fp;
00233 int n_float;
00234 struct stat statbuf;
00235 int i, n, byterev, sf, ef;
00236 float32 **mfcbuf;
00237
00238 if (stat(file, &statbuf) < 0) {
00239 printf("stat(%s) failed\n", file);
00240 return IO_ERR;
00241 }
00242
00243 if ((fp = fopen(file, "rb")) == NULL) {
00244 printf("fopen(%s, rb) failed\n", file);
00245 return IO_ERR;
00246 }
00247
00248
00249 if (fread(&n_float, sizeof(int), 1, fp) != 1) {
00250 fclose(fp);
00251 return IO_ERR;
00252 }
00253
00254
00255 byterev = FALSE;
00256 if ((int) (n_float * sizeof(float) + 4) != statbuf.st_size) {
00257 n = n_float;
00258 SWAP_INT32(&n);
00259
00260 if ((int) (n * sizeof(float) + 4) != statbuf.st_size) {
00261 printf
00262 ("Header size field: %d(%08x); filesize: %d(%08x)\n",
00263 n_float, n_float, (int) statbuf.st_size,
00264 (int) statbuf.st_size);
00265 fclose(fp);
00266 return IO_ERR;
00267 }
00268
00269 n_float = n;
00270 byterev = TRUE;
00271 }
00272 if (n_float <= 0) {
00273 printf("Header size field: %d\n", n_float);
00274 fclose(fp);
00275 return IO_ERR;
00276 }
00277
00278
00279 n = n_float / cepsize;
00280 if (n * cepsize != n_float) {
00281 printf("Header size field: %d; not multiple of %d\n",
00282 n_float, cepsize);
00283 fclose(fp);
00284 return IO_ERR;
00285 }
00286 sf = 0;
00287 ef = n;
00288
00289 mfcbuf = (float **) ckd_calloc_2d(n, cepsize, sizeof(float32));
00290
00291
00292 n_float = n * cepsize;
00293 if ((int) fread(mfcbuf[0], sizeof(float), n_float, fp) != n_float) {
00294 printf("Error reading mfc data\n");
00295 fclose(fp);
00296 return IO_ERR;
00297 }
00298 if (byterev) {
00299 for (i = 0; i < n_float; i++)
00300 SWAP_FLOAT32(&(mfcbuf[0][i]));
00301 }
00302 fclose(fp);
00303
00304 *numframes = n;
00305 *cep = mfcbuf;
00306 return IO_SUCCESS;
00307 }