1
/* ====================================================================
2
* Copyright (c) 1996-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
* Read/write interpolation lambda files
44
* Eric Thayer (eht@cs.cmu.edu)
45
*********************************************************************/
47
#include <s3/s3lamb_io.h>
54
s3lamb_read(const char *fn,
61
uint32 rd_chksum = 0, sv_chksum, ignore;
66
fp = s3open(fn, "rb", &swap);
70
/* check version io */
71
ver = s3get_gvn_fattr("version");
73
if (strcmp(ver, LAMBDA_FILE_VERSION) != 0) {
74
E_FATAL("Version mismatch for %s, file ver: %s != reader ver: %s\n",
75
fn, ver, LAMBDA_FILE_VERSION);
79
E_FATAL("No version attribute for %s\n", fn);
82
/* if do_chk is non-NULL, there is a checksum after the data in the file */
83
do_chk = s3get_gvn_fattr("chksum0");
85
if (s3read_1d((void **)&lambda,
90
&rd_chksum) != S3_SUCCESS)
94
/* See if the checksum in the file matches that which
95
was computed from the read data */
97
if (s3read(&sv_chksum, sizeof(uint32), 1, fp, swap, &ignore) != 1) {
103
if (sv_chksum != rd_chksum) {
104
E_FATAL("Checksum error; read corrupt data.\n");
110
*out_lambda = lambda;
111
*out_n_lambda = n_lambda;
113
E_INFO("Read %s [%u array]\n", fn, n_lambda);
119
s3lamb_write(const char *fn,
120
const float32 *lambda,
128
s3add_fattr("version", LAMBDA_FILE_VERSION, TRUE);
129
s3add_fattr("chksum0", "yes", TRUE);
132
fp = s3open(fn, "wb", NULL);
136
if (s3write_1d((void *)lambda, sizeof(float32), n_lambda, fp, &chksum) != S3_SUCCESS) {
141
if (s3write(&chksum, sizeof(uint32), 1, fp, &ignore) != 1) {
149
E_INFO("Wrote %s [%u array]\n", fn, n_lambda);
155
s3lambcnt_read(const char *fn,
156
uint32 **out_lambda_cnt,
157
uint32 *out_n_lambda_cnt)
162
uint32 rd_chksum = 0, sv_chksum, ignore;
167
fp = s3open(fn, "rb", &swap);
171
/* check version io */
172
ver = s3get_gvn_fattr("version");
174
if (strcmp(ver, LAMBDACNT_FILE_VERSION) != 0) {
175
E_FATAL("Version mismatch for %s, file ver: %s != reader ver: %s\n",
176
fn, ver, LAMBDACNT_FILE_VERSION);
180
E_FATAL("No version attribute for %s\n", fn);
183
/* if do_chk is non-NULL, there is a checksum after the data in the file */
184
do_chk = s3get_gvn_fattr("chksum0");
186
if (s3read_1d((void **)&lambda_cnt,
191
&rd_chksum) != S3_SUCCESS)
195
/* See if the checksum in the file matches that which
196
was computed from the read data */
198
if (s3read(&sv_chksum, sizeof(uint32), 1, fp, swap, &ignore) != 1) {
204
if (sv_chksum != rd_chksum) {
205
E_FATAL("Checksum error; read corrupt data.\n");
211
*out_lambda_cnt = lambda_cnt;
212
*out_n_lambda_cnt = n_lambda_cnt;
214
E_INFO("Read %s [%u array]\n", fn, n_lambda_cnt);
220
s3lambcnt_write(const char *fn,
221
const uint32 *lambda_cnt,
229
s3add_fattr("version", LAMBDACNT_FILE_VERSION, TRUE);
230
s3add_fattr("chksum0", "yes", TRUE);
233
fp = s3open(fn, "wb", NULL);
237
if (s3write_1d((void *)lambda_cnt, sizeof(uint32), n_lambda_cnt, fp, &chksum) != S3_SUCCESS) {
242
if (s3write(&chksum, sizeof(uint32), 1, fp, &ignore) != 1) {
250
E_INFO("Wrote %s [%u array]\n", fn, n_lambda_cnt);
256
* Log record. Maintained by RCS.
259
* Revision 1.4 2004/07/21 18:05:40 egouvea
260
* Changed the license terms to make it the same as sphinx2 and sphinx3.
262
* Revision 1.3 2001/04/05 20:02:31 awb
263
* *** empty log message ***
265
* Revision 1.2 2000/09/29 22:35:13 awb
266
* *** empty log message ***
268
* Revision 1.1 2000/09/24 21:38:31 awb
269
* *** empty log message ***
271
* Revision 1.1 97/03/17 15:01:49 eht