SphinxBase 0.6
include/sphinxbase/bio.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 /*
00038  * bio.h -- Sphinx-3 binary file I/O functions.
00039  * 
00040  * **********************************************
00041  * CMU ARPA Speech Project
00042  *
00043  * Copyright (c) 1996 Carnegie Mellon University.
00044  * ALL RIGHTS RESERVED.
00045  * **********************************************
00046  * 
00047  * HISTORY
00048  * $Log: bio.h,v $
00049  * Revision 1.8  2005/06/21 20:40:46  arthchan2003
00050  * 1, Fixed doxygen documentation, 2, Add the $ keyword.
00051  *
00052  * Revision 1.5  2005/06/13 04:02:57  archan
00053  * Fixed most doxygen-style documentation under libs3decoder.
00054  *
00055  * Revision 1.4  2005/05/10 21:21:52  archan
00056  * 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.
00057  *
00058  * Revision 1.3  2005/03/30 01:22:46  archan
00059  * Fixed mistakes in last updates. Add
00060  *
00061  * 
00062  * 28-Apr-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
00063  *              Created.
00064  */
00065 
00066 
00067 #ifndef _S3_BIO_H_
00068 #define _S3_BIO_H_
00069 
00070 #include <stdio.h>
00071 #include <stdarg.h>
00072 
00073 /* Win32/WinCE DLL gunk */
00074 #include <sphinxbase/sphinxbase_export.h>
00075 #include <sphinxbase/prim_type.h>
00076 #include <sphinxbase/byteorder.h>
00077 
00084 #ifdef __cplusplus
00085 extern "C" {
00086 #endif
00087 #if 0
00088 /* Fool Emacs. */
00089 }
00090 #endif
00091 
00092 #define BYTE_ORDER_MAGIC        (0x11223344)
00093 
00098 #if (__BIG_ENDIAN__)
00099 #define REVERSE_SENSE_SWAP_INT16(x)  x = ( (((x)<<8)&0x0000ff00) | (((x)>>8)&0x00ff) )
00100 #define REVERSE_SENSE_SWAP_INT32(x)  x = ( (((x)<<24)&0xff000000) | (((x)<<8)&0x00ff0000) | \
00101                          (((x)>>8)&0x0000ff00) | (((x)>>24)&0x000000ff) )
00102 #else
00103 #define REVERSE_SENSE_SWAP_INT16(x)
00104 #define REVERSE_SENSE_SWAP_INT32(x)
00105 
00106 #endif
00107 
00108 
00109 
00124 SPHINXBASE_EXPORT
00125 int32 bio_readhdr (FILE *fp,            
00126                    char ***name,        
00127                    char ***val,         
00128                    int32 *swap  
00129                    );
00135 SPHINXBASE_EXPORT
00136 int32 bio_writehdr_version (FILE *fp,  
00137                             char *version 
00138         );
00139 
00140 
00141 SPHINXBASE_EXPORT
00142 int32 bio_writehdr(FILE *fp, ...);
00143 
00147 SPHINXBASE_EXPORT
00148 void bio_hdrarg_free (char **name,      
00149                       char **val        
00150                       );
00151 
00157 SPHINXBASE_EXPORT
00158 int32 bio_fread (void *buf,
00159                  int32 el_sz,
00160                  int32 n_el,
00161                  FILE *fp,              
00162                  int32 swap,            
00163                  uint32 *chksum 
00164                  );
00165 
00170 SPHINXBASE_EXPORT
00171 int32 bio_fwrite(void *buf,
00172                  int32 el_sz,
00173                  int32 n_el,
00174                  FILE *fp,              
00175                  int32 swap,            
00176                  uint32 *chksum 
00177                  );
00178 
00189 SPHINXBASE_EXPORT
00190 int32 bio_fread_1d (void **buf,         
00192                     size_t el_sz,       
00193                     uint32 *n_el,       
00194                     FILE *fp,           
00195                     int32 sw,           
00196                     uint32 *ck  
00197                     );
00198 
00209 SPHINXBASE_EXPORT
00210 int32 bio_fread_2d(void ***arr,
00211                    size_t e_sz,
00212                    uint32 *d1,
00213                    uint32 *d2,
00214                    FILE *fp,
00215                    uint32 swap,
00216                    uint32 *chksum);
00217 
00228 SPHINXBASE_EXPORT
00229 int32 bio_fread_3d(void ****arr,
00230                    size_t e_sz,
00231                    uint32 *d1,
00232                    uint32 *d2,
00233                    uint32 *d3,
00234                    FILE *fp,
00235                    uint32 swap,
00236                    uint32 *chksum);
00237 
00242 SPHINXBASE_EXPORT
00243 void bio_verify_chksum (FILE *fp,       
00244                         int32 byteswap, 
00245                         uint32 chksum   
00246                         );
00247 
00248 
00260 int16*
00261 bio_read_wavfile(char const *directory,
00262                  char const *filename,
00263                  char const *extension,
00264                  int32 header,
00265                  int32 endian,
00266                  int32 *nsamps);
00267 
00268 #ifdef __cplusplus
00269 }
00270 #endif
00271 
00272 #endif