bio.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* bio.h -- Sphinx-3 binary file I/O functions.
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1996 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*
* HISTORY
* $Log: bio.h,v $
* Revision 1.8 2005/06/21 20:40:46 arthchan2003
* 1, Fixed doxygen documentation, 2, Add the $ keyword.
*
* Revision 1.5 2005/06/13 04:02:57 archan
* Fixed most doxygen-style documentation under libs3decoder.
*
* Revision 1.4 2005/05/10 21:21:52 archan
* 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.
*
* Revision 1.3 2005/03/30 01:22:46 archan
* Fixed mistakes in last updates. Add
*
*
* 28-Apr-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Created.
*/
#ifndef _S3_BIO_H_
#define _S3_BIO_H_
#include <stdio.h>
#include <stdarg.h>
/* Win32/WinCE DLL gunk */
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#include <sphinxbase/byteorder.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
#define BYTE_ORDER_MAGIC (0x11223344)
#if (__BIG_ENDIAN__)
#define REVERSE_SENSE_SWAP_INT16(x) x = ( (((x)<<8)&0x0000ff00) | (((x)>>8)&0x00ff) )
#define REVERSE_SENSE_SWAP_INT32(x) x = ( (((x)<<24)&0xff000000) | (((x)<<8)&0x00ff0000) | \
(((x)>>8)&0x0000ff00) | (((x)>>24)&0x000000ff) )
#else
#define REVERSE_SENSE_SWAP_INT16(x)
#define REVERSE_SENSE_SWAP_INT32(x)
#endif
SPHINXBASE_EXPORT
int32 bio_readhdr (FILE *fp,
char ***name,
char ***val,
int32 *swap
);
SPHINXBASE_EXPORT
int32 bio_writehdr_version (FILE *fp,
char *version
);
SPHINXBASE_EXPORT
int32 bio_writehdr(FILE *fp, ...);
SPHINXBASE_EXPORT
void bio_hdrarg_free (char **name,
char **val
);
SPHINXBASE_EXPORT
int32 bio_fread (void *buf,
int32 el_sz,
int32 n_el,
FILE *fp,
int32 swap,
uint32 *chksum
);
SPHINXBASE_EXPORT
int32 bio_fwrite(void *buf,
int32 el_sz,
int32 n_el,
FILE *fp,
int32 swap,
uint32 *chksum
);
SPHINXBASE_EXPORT
int32 bio_fread_1d (void **buf,
size_t el_sz,
uint32 *n_el,
FILE *fp,
int32 sw,
uint32 *ck
);
SPHINXBASE_EXPORT
int32 bio_fread_2d(void ***arr,
size_t e_sz,
uint32 *d1,
uint32 *d2,
FILE *fp,
uint32 swap,
uint32 *chksum);
SPHINXBASE_EXPORT
int32 bio_fread_3d(void ****arr,
size_t e_sz,
uint32 *d1,
uint32 *d2,
uint32 *d3,
FILE *fp,
uint32 swap,
uint32 *chksum);
SPHINXBASE_EXPORT
void bio_verify_chksum (FILE *fp,
int32 byteswap,
uint32 chksum
);
SPHINXBASE_EXPORT
int16* bio_read_wavfile(char const *directory,
char const *filename,
char const *extension,
int32 header,
int32 endian,
int32 *nsamps);
#ifdef __cplusplus
}
#endif
#endif
bio_read_wavfile
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
bio_fread_3d
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
prim_type.h
Basic type definitions used in Sphinx.
bio_fread_1d
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
bio_fwrite
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
bio_fread_2d
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
bio_writehdr_version
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
bio_fread
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
bio_verify_chksum
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
bio_hdrarg_free
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
bio_readhdr
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