SphinxBase  5prealpha
bio.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
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
16  * distribution.
17  *
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.
21  *
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.
33  *
34  * ====================================================================
35  *
36  */
37 /*
38  * bio.h -- Sphinx-3 binary file I/O functions.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1996 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  * $Log: bio.h,v $
49  * Revision 1.8 2005/06/21 20:40:46 arthchan2003
50  * 1, Fixed doxygen documentation, 2, Add the $ keyword.
51  *
52  * Revision 1.5 2005/06/13 04:02:57 archan
53  * Fixed most doxygen-style documentation under libs3decoder.
54  *
55  * Revision 1.4 2005/05/10 21:21:52 archan
56  * Three functionalities added but not tested. Code on 1) addition/deletion of LM in mode 4. 2) reading text-based LM 3) Converting txt-based LM to dmp-based LM.
57  *
58  * Revision 1.3 2005/03/30 01:22:46 archan
59  * Fixed mistakes in last updates. Add
60  *
61  *
62  * 28-Apr-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
63  * Created.
64  */
65 
66 
67 #ifndef _S3_BIO_H_
68 #define _S3_BIO_H_
69 
70 #include <stdio.h>
71 #include <stdarg.h>
72 
73 /* Win32/WinCE DLL gunk */
74 #include <sphinxbase/sphinxbase_export.h>
75 #include <sphinxbase/prim_type.h>
76 #include <sphinxbase/byteorder.h>
77 
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 #if 0
88 /* Fool Emacs. */
89 }
90 #endif
91 
92 #define BYTE_ORDER_MAGIC (0x11223344)
93 
98 #if (__BIG_ENDIAN__)
99 #define REVERSE_SENSE_SWAP_INT16(x) x = ( (((x)<<8)&0x0000ff00) | (((x)>>8)&0x00ff) )
100 #define REVERSE_SENSE_SWAP_INT32(x) x = ( (((x)<<24)&0xff000000) | (((x)<<8)&0x00ff0000) | \
101  (((x)>>8)&0x0000ff00) | (((x)>>24)&0x000000ff) )
102 #else
103 #define REVERSE_SENSE_SWAP_INT16(x)
104 #define REVERSE_SENSE_SWAP_INT32(x)
105 
106 #endif
107 
108 
109 
124 SPHINXBASE_EXPORT
125 int32 bio_readhdr (FILE *fp,
126  char ***name,
127  char ***val,
128  int32 *swap
129  );
135 SPHINXBASE_EXPORT
136 int32 bio_writehdr_version (FILE *fp,
137  char *version
138  );
139 
140 
145 SPHINXBASE_EXPORT
146 int32 bio_writehdr(FILE *fp, ...);
147 
151 SPHINXBASE_EXPORT
152 void bio_hdrarg_free (char **name,
153  char **val
154  );
155 
162 SPHINXBASE_EXPORT
163 int32 bio_fread (void *buf,
164  int32 el_sz,
165  int32 n_el,
166  FILE *fp,
167  int32 swap,
168  uint32 *chksum
169  );
170 
176 SPHINXBASE_EXPORT
177 int32 bio_fwrite(const void *buf,
178  int32 el_sz,
179  int32 n_el,
180  FILE *fp,
181  int32 swap,
182  uint32 *chksum
183  );
184 
195 SPHINXBASE_EXPORT
196 int32 bio_fread_1d (void **buf,
198  size_t el_sz,
199  uint32 *n_el,
200  FILE *fp,
201  int32 sw,
202  uint32 *ck
203  );
204 
215 SPHINXBASE_EXPORT
216 int32 bio_fread_2d(void ***arr,
217  size_t e_sz,
218  uint32 *d1,
219  uint32 *d2,
220  FILE *fp,
221  uint32 swap,
222  uint32 *chksum);
223 
234 SPHINXBASE_EXPORT
235 int32 bio_fread_3d(void ****arr,
236  size_t e_sz,
237  uint32 *d1,
238  uint32 *d2,
239  uint32 *d3,
240  FILE *fp,
241  uint32 swap,
242  uint32 *chksum);
243 
248 SPHINXBASE_EXPORT
249 void bio_verify_chksum (FILE *fp,
250  int32 byteswap,
251  uint32 chksum
252  );
253 
254 
255 
262 SPHINXBASE_EXPORT
263 int bio_fwrite_1d(void *arr,
264  size_t e_sz,
265  uint32 d1,
266  FILE *fp,
267  uint32 *chksum
268  );
269 
276 SPHINXBASE_EXPORT
277 int bio_fwrite_3d(void ***arr,
278  size_t e_sz,
279  uint32 d1,
280  uint32 d2,
281  uint32 d3,
282  FILE *fp,
283  uint32 *chksum
284  );
285 
291 SPHINXBASE_EXPORT
292 int16* bio_read_wavfile(char const *directory,
293  char const *filename,
294  char const *extension,
295  int32 header,
296  int32 endian,
297  size_t *nsamps
298  );
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif
SPHINXBASE_EXPORT int32 bio_fread_3d(void ****arr, size_t e_sz, uint32 *d1, uint32 *d2, uint32 *d3, FILE *fp, uint32 swap, uint32 *chksum)
Read a 3-d array (set of matrices)
Definition: bio.c:430
SPHINXBASE_EXPORT int16 * bio_read_wavfile(char const *directory, char const *filename, char const *extension, int32 header, int32 endian, size_t *nsamps)
Read raw data from the wav file.
Definition: bio.c:592
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT int bio_fwrite_1d(void *arr, size_t e_sz, uint32 d1, FILE *fp, uint32 *chksum)
Write a 1-d array.
Definition: bio.c:558
SPHINXBASE_EXPORT int32 bio_writehdr(FILE *fp,...)
Write a simple binary file header with only byte order magic word.
Definition: bio.c:155
SPHINXBASE_EXPORT int32 bio_fwrite(const void *buf, int32 el_sz, int32 n_el, FILE *fp, int32 swap, uint32 *chksum)
Like fwrite but perform byteswapping and accumulate checksum (the 2 extra arguments).
Definition: bio.c:342
SPHINXBASE_EXPORT int32 bio_fread_1d(void **buf, size_t el_sz, uint32 *n_el, FILE *fp, int32 sw, uint32 *ck)
Read a 1-d array (fashioned after fread):
Definition: bio.c:364
SPHINXBASE_EXPORT int bio_fwrite_3d(void ***arr, size_t e_sz, uint32 d1, uint32 d2, uint32 d3, FILE *fp, uint32 *chksum)
Write a 3-d array (set of matrices).
Definition: bio.c:507
SPHINXBASE_EXPORT int32 bio_fread_2d(void ***arr, size_t e_sz, uint32 *d1, uint32 *d2, FILE *fp, uint32 swap, uint32 *chksum)
Read a 2-d matrix:
Definition: bio.c:384
SPHINXBASE_EXPORT int32 bio_writehdr_version(FILE *fp, char *version)
Write a simple binary file header, containing only the version string.
Definition: bio.c:137
SPHINXBASE_EXPORT int32 bio_fread(void *buf, int32 el_sz, int32 n_el, FILE *fp, int32 swap, uint32 *chksum)
Like fread but perform byteswapping and accumulate checksum (the 2 extra arguments).
Definition: bio.c:326
SPHINXBASE_EXPORT void bio_verify_chksum(FILE *fp, int32 byteswap, uint32 chksum)
Read and verify checksum at the end of binary file.
Definition: bio.c:492
SPHINXBASE_EXPORT void bio_hdrarg_free(char **name, char **val)
Free name and value strings previously allocated and returned by bio_readhdr.
Definition: bio.c:121
SPHINXBASE_EXPORT int32 bio_readhdr(FILE *fp, char ***name, char ***val, int32 *swap)
Read binary file format header: has the following format.
Definition: bio.c:187