SphinxBase 0.6
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>
76#include <sphinxbase/byteorder.h>
77
84#ifdef __cplusplus
85extern "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
124SPHINXBASE_EXPORT
125int32 bio_readhdr (FILE *fp,
126 char ***name,
127 char ***val,
128 int32 *swap
129 );
135SPHINXBASE_EXPORT
136int32 bio_writehdr_version (FILE *fp,
137 char *version
138 );
139
140
141SPHINXBASE_EXPORT
142int32 bio_writehdr(FILE *fp, ...);
143
147SPHINXBASE_EXPORT
148void bio_hdrarg_free (char **name,
149 char **val
150 );
151
157SPHINXBASE_EXPORT
158int32 bio_fread (void *buf,
159 int32 el_sz,
160 int32 n_el,
161 FILE *fp,
162 int32 swap,
163 uint32 *chksum
164 );
165
170SPHINXBASE_EXPORT
171int32 bio_fwrite(void *buf,
172 int32 el_sz,
173 int32 n_el,
174 FILE *fp,
175 int32 swap,
176 uint32 *chksum
177 );
178
189SPHINXBASE_EXPORT
190int32 bio_fread_1d (void **buf,
192 size_t el_sz,
193 uint32 *n_el,
194 FILE *fp,
195 int32 sw,
196 uint32 *ck
197 );
198
209SPHINXBASE_EXPORT
210int32 bio_fread_2d(void ***arr,
211 size_t e_sz,
212 uint32 *d1,
213 uint32 *d2,
214 FILE *fp,
215 uint32 swap,
216 uint32 *chksum);
217
228SPHINXBASE_EXPORT
229int32 bio_fread_3d(void ****arr,
230 size_t e_sz,
231 uint32 *d1,
232 uint32 *d2,
233 uint32 *d3,
234 FILE *fp,
235 uint32 swap,
236 uint32 *chksum);
237
242SPHINXBASE_EXPORT
243void bio_verify_chksum (FILE *fp,
244 int32 byteswap,
245 uint32 chksum
246 );
247
248
260SPHINXBASE_EXPORT
261int16* bio_read_wavfile(char const *directory,
262 char const *filename,
263 char const *extension,
264 int32 header,
265 int32 endian,
266 int32 *nsamps);
267
268#ifdef __cplusplus
269}
270#endif
271
272#endif
SPHINXBASE_EXPORT int32 bio_fwrite(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 int16 * bio_read_wavfile(char const *directory, char const *filename, char const *extension, int32 header, int32 endian, int32 *nsamps)
Read raw data from the wav file.
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_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 int32 bio_readhdr(FILE *fp, char ***name, char ***val, int32 *swap)
Read binary file format header: has the following format.
Definition bio.c:187
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_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 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 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
Basic type definitions used in Sphinx.