1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 1994-2001 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * This work was supported in part by funding from the Defense Advanced
19 * Research Projects Agency and the National Science Foundation of the
20 * United States of America, and the CMU Sphinx Speech Consortium.
22 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * ====================================================================
39 * circa 1994 P J Moreno at Carnegie Mellon
42 * For history information, please use 'cvs log'
44 * Revision 1.11 2006/02/24 04:06:43 arthchan2003
45 * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: Changed commands to macro. Used E_INFO instead of printf in displaying no. of friends
48 * Revision 1.10 2005/08/18 21:18:09 egouvea
49 * Added E_INFO displaying information about how many columns are being printed, and how many frames
51 * Revision 1.9.4.2 2005/09/07 23:51:05 arthchan2003
52 * Fixed keyword expansion problem
54 * Revision 1.9.4.1 2005/07/18 23:21:23 arthchan2003
55 * Tied command-line arguments with marcos
57 * Revision 1.10 2005/08/18 21:18:09 egouvea
58 * Added E_INFO displaying information about how many columns are being printed, and how many frames
60 * Revision 1.9 2005/06/22 05:38:45 arthchan2003
63 * Revision 1.2 2005/03/30 00:43:41 archan
66 * Revision 1.11 2006/02/24 04:06:43 arthchan2003
67 * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: Changed commands to macro. Used E_INFO instead of printf in displaying no. of friends
77 #pragma warning (disable: 4996)
84 #include <sphinxbase/strfuncs.h>
85 #include <sphinxbase/prim_type.h>
86 #include <sphinxbase/cmd_ln.h>
87 #include <sphinxbase/ckd_alloc.h>
88 #include <sphinxbase/info.h>
89 #include <sphinxbase/err.h>
90 #include <sphinxbase/bio.h>
91 #include <sphinxbase/pio.h>
93 /** \file main_cepview.c
94 \brief Main driver of cepview
97 #define IO_SUCCESS (0)
101 /* Default cepstral vector size */
102 #define NUM_COEFF "13"
104 /* Default display size, i.e., number of coefficients displayed, less
105 * than the vector size so we display one frame per line.
107 #define DISPLAY_SIZE "10"
108 #define STR_MAX_INT "2147483647"
110 static arg_t arg[] = {
115 "Log file (default stdout/stderr)"},
119 "Number of coefficients in the feature vector."},
123 "Number of displayed coefficients."},
127 "Whether header is shown."},
131 "Whether description will be shown."},
135 "The beginning frame 0-based."},
139 "The ending frame."},
143 "Input feature file."},
144 {NULL, ARG_INT32, NULL, NULL}
147 int read_cep(char const *file, float ***cep, int *nframes, int numcep);
150 main(int argc, char *argv[])
153 int32 noframe, vsize, dsize, column;
154 int32 frm_begin, frm_end;
155 int is_header, is_describe;
159 print_appl_info(argv[0]);
160 cmd_ln_appl_enter(argc, argv, "default.arg", arg);
162 vsize = cmd_ln_int32("-i");
163 dsize = cmd_ln_int32("-d");
164 frm_begin = cmd_ln_int32("-b");
165 frm_end = cmd_ln_int32("-e");
166 is_header = cmd_ln_int32("-header");
167 is_describe = cmd_ln_int32("-describe");
170 E_FATAL("-i : Input vector size should be larger than 0.\n");
172 E_FATAL("-d : Column size should be larger than 0\n");
174 E_FATAL("-b : Beginning frame should be larger than 0\n");
175 /* The following condition is redundant
176 * if (frm_end < 0) E_FATAL("-e : Ending frame should be larger than 0\n");
178 if (frm_begin >= frm_end)
180 ("Ending frame (-e) should be larger than beginning frame (-b).\n");
182 if ((cepfile = cmd_ln_str("-f")) == NULL) {
183 E_FATAL("Input file was not specified with (-f)\n");
185 if (read_cep(cepfile, &cep, &noframe, vsize) == IO_ERR)
186 E_FATAL("ERROR opening %s for reading\n", cepfile);
191 column = (vsize > dsize) ? dsize : vsize;
192 frm_end = (frm_end > noframe) ? noframe : frm_end;
194 E_INFO("Displaying %d out of %d columns per frame\n", column, vsize);
195 E_INFO("Total %d frames\n\n", noframe);
197 /* This part should be moved to a special library if this file is
198 longer than 300 lines. */
202 printf("\n%6s", "frame#:");
205 for (j = 0; j < column; ++j) {
206 printf("%3s%3d%s ", "c[", j, "]");
211 offset += frm_begin * vsize;
212 for (i = frm_begin; i < frm_end; ++i) {
216 for (j = 0; j < column; ++j)
217 printf("%7.3f ", z[offset + j]);
231 read_cep(char const *file, float ***cep, int *numframes, int cepsize)
236 int i, n, byterev, sf, ef;
239 if (stat_retry(file, &statbuf) < 0) {
240 printf("stat(%s) failed\n", file);
244 if ((fp = fopen(file, "rb")) == NULL) {
245 printf("Failed to open '%s' for reading: %s\n", file, strerror(errno));
249 /* Read #floats in header */
250 if (fread(&n_float, sizeof(int), 1, fp) != 1) {
255 /* Check if n_float matches file size */
257 if ((int) (n_float * sizeof(float) + 4) != statbuf.st_size) {
261 if ((int) (n * sizeof(float) + 4) != statbuf.st_size) {
263 ("Header size field: %d(%08x); filesize: %d(%08x)\n",
264 n_float, n_float, (int) statbuf.st_size,
265 (int) statbuf.st_size);
274 printf("Header size field: %d\n", n_float);
279 /* n = #frames of input */
280 n = n_float / cepsize;
281 if (n * cepsize != n_float) {
282 printf("Header size field: %d; not multiple of %d\n",
290 mfcbuf = (float **) ckd_calloc_2d(n, cepsize, sizeof(float32));
292 /* Read mfc data and byteswap if necessary */
293 n_float = n * cepsize;
294 if ((int) fread(mfcbuf[0], sizeof(float), n_float, fp) != n_float) {
295 printf("Error reading mfc data\n");
300 for (i = 0; i < n_float; i++)
301 SWAP_FLOAT32(&(mfcbuf[0][i]));
310 /** Silvio Moioli: Windows CE/Mobile entry point added. */
311 #if defined(_WIN32_WCE)
312 #pragma comment(linker,"/entry:mainWCRTStartup")
314 //Windows Mobile has the Unicode main only
315 int wmain(int32 argc, wchar_t *wargv[]) {
321 argv = malloc(argc*sizeof(char*));
322 for (i=0; i<argc; i++){
323 wlen = lstrlenW(wargv[i]);
324 len = wcstombs(NULL, wargv[i], wlen);
325 argv[i] = malloc(len+1);
326 wcstombs(argv[i], wargv[i], wlen);
329 //assuming ASCII parameters
330 return main(argc, argv);