1
/* ====================================================================
2
* Copyright (c) 1997-2000 Carnegie Mellon University. All rights
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in
14
* the documentation and/or other materials provided with the
17
* This work was supported in part by funding from the Defense Advanced
18
* Research Projects Agency and the National Science Foundation of the
19
* United States of America, and the CMU Sphinx Speech Consortium.
21
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
22
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
* ====================================================================
36
/*********************************************************************
41
* Copies parameters from an input file to and output file
44
* Eric H. Thayer (eht@cs.cmu.edu)
45
*********************************************************************/
47
#include "parse_cmd_ln.h"
48
#include <s3/s3mixw_io.h>
49
#include <s3/s3gau_io.h>
50
#include <s3/s3tmat_io.h>
51
#include <s3/gauden.h>
52
#include <sphinxbase/ckd_alloc.h>
53
#include <sphinxbase/cmd_ln.h>
59
static int rd_parm(void);
60
static int cp_parm(void);
61
static int wr_parm(void);
64
static float32 ***imixw;
65
static uint32 n_mixw_i;
66
static float32 ***omixw;
67
static uint32 n_mixw_o;
69
static uint32 n_stream;
70
static uint32 n_density;
72
static vector_t ***igau;
73
static vector_t ****igau_full;
75
static vector_t ***ogau;
76
static vector_t ****ogau_full;
78
static uint32 *veclen;
80
static float32 ***itmat;
81
static uint32 n_tmat_i;
82
static float32 ***otmat;
83
static uint32 n_tmat_o;
84
static uint32 n_state_pm;
89
rd_mixw(const char *fn, uint32 n_o)
95
&n_density) != S3_SUCCESS)
100
omixw = (float32 ***)ckd_calloc_3d(n_mixw_o,
113
printf("mixw %u <= %u\n", o, i);
116
for (j = 0; j < n_stream; j++) {
117
for (k = 0; k < n_density; k++) {
118
omixw[o][j][k] = imixw[i][j][k];
124
wr_mixw(const char *fn)
130
n_density) != S3_SUCCESS)
133
ckd_free_3d((void ***)omixw);
134
ckd_free_3d((void ***)imixw);
140
rd_tmat(const char *fn, uint32 n_o)
145
&n_state_pm) != S3_SUCCESS)
150
otmat = (float32 ***)ckd_calloc_3d(n_tmat_o,
163
printf("tmat %u <= %u\n", o, i);
165
for (j = 0; j < n_state_pm-1; j++) {
166
for (k = 0; k < n_state_pm; k++) {
167
otmat[o][j][k] = itmat[i][j][k];
173
wr_tmat(const char *fn)
178
n_state_pm) != S3_SUCCESS)
181
ckd_free_3d((void ***)otmat);
182
ckd_free_3d((void ***)itmat);
188
rd_gau(const char *fn, uint32 n_o)
195
&veclen) != S3_SUCCESS)
200
ogau = (vector_t ***)gauden_alloc_param(n_cb_o,
212
printf("gau %u <= %u\n", o, i);
214
for (j = 0; j < n_stream; j++) {
215
for (k = 0; k < n_density; k++) {
216
for (l = 0; l < veclen[j]; l++) {
217
ogau[o][j][k][l] = igau[i][j][k][l];
224
wr_gau(const char *fn)
227
(const vector_t ***)ogau,
231
veclen) != S3_SUCCESS)
234
gauden_free_param(ogau);
235
gauden_free_param(igau);
241
rd_gau_full(const char *fn, uint32 n_o)
243
if (s3gau_read_full(fn,
248
&veclen) != S3_SUCCESS)
253
ogau_full = (vector_t ****)gauden_alloc_param_full(n_cb_o,
260
cp_gau_full(uint32 o,
265
printf("gau %u <= %u\n", o, i);
267
for (j = 0; j < n_stream; j++) {
268
for (k = 0; k < n_density; k++) {
269
for (l = 0; l < veclen[j]; l++) {
270
for (ll = 0; ll < veclen[j]; ll++) {
271
ogau_full[o][j][k][l][ll] = igau_full[i][j][k][l][ll];
279
wr_gau_full(const char *fn)
281
if (s3gau_write_full(fn,
282
(const vector_t ****)ogau_full,
286
veclen) != S3_SUCCESS)
289
gauden_free_param_full(ogau_full);
290
gauden_free_param_full(igau_full);
298
if(cmd_ln_str("-imixwfn") ==NULL&&
299
cmd_ln_str("-igaufn") ==NULL&&
300
cmd_ln_str("-ifullgaufn")==NULL&&
301
cmd_ln_str("-itmatfn") ==NULL
303
E_INFO("Please specify one of the following: -imixwfn, -igaufn, -ifullgaufn, -itmatfn\n");
307
if (cmd_ln_str("-imixwfn")) {
308
if(cmd_ln_str("-nmixwout")==NULL){
309
E_INFO("Please specify -nmixwout\n");
312
rd_mixw(cmd_ln_str("-imixwfn"),
313
cmd_ln_int32("-nmixwout"));
315
if (cmd_ln_str("-igaufn")) {
316
if(cmd_ln_str("-ncbout")==NULL){
317
E_INFO("Please specify -ncbout\n");
320
rd_gau(cmd_ln_str("-igaufn"),
321
cmd_ln_int32("-ncbout"));
323
if (cmd_ln_str("-ifullgaufn")) {
324
if(cmd_ln_str("-ncbout")==NULL){
325
E_INFO("Please specify -ncbout\n");
328
rd_gau_full(cmd_ln_str("-ifullgaufn"),
329
cmd_ln_int32("-ncbout"));
331
if (cmd_ln_str("-itmatfn")) {
332
if(cmd_ln_str("-ntmatout")==NULL){
333
E_INFO("Please specify -ntmatout\n");
336
rd_tmat(cmd_ln_str("-itmatfn"),
337
cmd_ln_int32("-ntmatout"));
349
/* Open the file first to see whether command-line parameters
353
if(cmd_ln_str("-cpopsfn")==NULL) {
354
E_INFO("Please specify -cpopsfn\n");
357
fp = fopen(cmd_ln_str("-cpopsfn"), "r");
359
E_INFO("Unable to open cpops file\n");
363
while (fscanf(fp, "%u %u", &o, &i) == 2) {
370
if(max != n_mixw_o) {
371
E_INFO("Mismatch between cp operation file (max out %d) and -nmixout (%d)\n",max, n_mixw_o);
378
E_INFO("Mismatch between cp operation file (max out %d) and -ncbout (%d)\n",max, n_cb_o);
385
E_INFO("Mismatch between cp operation file (max out %d) and -ncbout (%d)\n",max, n_cb_o);
391
if(max != n_tmat_o) {
392
E_INFO("Mismatch between cp operation file (max out %d) and -ntmatout (%d)\n",max, n_tmat_o);
399
fp = fopen(cmd_ln_str("-cpopsfn"), "r");
400
while (fscanf(fp, "%u %u", &o, &i) == 2) {
423
if(cmd_ln_str("-omixwfn") == NULL) {
424
E_INFO("Please specify -omixwfn\n");
427
wr_mixw(cmd_ln_str("-omixwfn"));
430
if(cmd_ln_str("-ogaufn") == NULL) {
431
E_INFO("Please specify -ogaufn\n");
434
wr_gau(cmd_ln_str("-ogaufn"));
437
if(cmd_ln_str("-ofullgaufn") == NULL) {
438
E_INFO("Please specify -ofullgaufn\n");
441
wr_gau_full(cmd_ln_str("-ofullgaufn"));
444
if(cmd_ln_str("-otmatfn") == NULL) {
445
E_INFO("Please specify -otmatfn\n");
448
wr_tmat(cmd_ln_str("-otmatfn"));
454
main(int argc, char *argv[])
457
parse_cmd_ln(argc, argv);
459
if(rd_parm()==S3_ERROR) {
460
E_FATAL("Problem in reading input parameters.\n");
462
if(cp_parm()==S3_ERROR) {
463
E_FATAL("Problem in copying parameters.\n");
465
if(wr_parm()==S3_ERROR) {
466
E_FATAL("Problem in writing output parameters.\n");