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  * ms_mgau.h -- Essentially a wrapper that wrap up gauden and
39  * senone. It supports multi-stream.
40  *
41  *
42  * **********************************************
43  * CMU ARPA Speech Project
44  *
45  * Copyright (c) 1997 Carnegie Mellon University.
46  * ALL RIGHTS RESERVED.
47  * **********************************************
48  * HISTORY
49  * $Log$
50  * Revision 1.1  2006/04/05  20:27:30  dhdfu
51  * A Great Reorganzation of header files and executables
52  *
53  * Revision 1.3  2006/02/22 16:57:15  arthchan2003
54  * Fixed minor dox-doc issue
55  *
56  * Revision 1.2  2006/02/22 16:56:01  arthchan2003
57  * Merged from SPHINX3_5_2_RCI_IRII_BRANCH: Added ms_mgau.[ch] into the trunk. It is a wrapper of ms_gauden and ms_senone
58  *
59  * Revision 1.1.2.4  2005/09/25 18:55:19  arthchan2003
60  * Added a flag to turn on and off precomputation.
61  *
62  * Revision 1.1.2.3  2005/08/03 18:53:44  dhdfu
63  * Add memory deallocation functions.  Also move all the initialization
64  * of ms_mgau_model_t into ms_mgau_init (duh!), which entails removing it
65  * from decode_anytopo and friends.
66  *
67  * Revision 1.1.2.2  2005/08/02 21:05:38  arthchan2003
68  * 1, Added dist and mgau_active as intermediate variable for computation. 2, Added ms_cont_mgau_frame_eval, which is a multi stream version of GMM computation mainly s3.0 family of tools. 3, Fixed dox-doc.
69  *
70  * Revision 1.1.2.1  2005/07/20 19:37:09  arthchan2003
71  * Added a multi-stream cont_mgau (ms_mgau) which is a wrapper of both gauden and senone.  Add ms_mgau_init and model_set_mllr.  This allow eliminating 600 lines of code in decode_anytopo/align/allphone.
72  *
73  *
74  *
75  */
76 
77 /** \file ms_mgau.h
78  *
79  * \brief (Sphinx 3.0 specific) A module that wraps up the code of
80  * gauden and senone because they are closely related.
81  *
82  * At the time at Sphinx 3.1 to 3.2, Ravi has decided to rewrite only
83  * single-stream part of the code into cont_mgau.[ch].  This marks the
84  * beginning of historical problem of having two sets of Gaussian
85  * distribution computation routine, one for single-stream and one of
86  * multi-stream.
87  *
88  * In Sphinx 3.5, when we figure out that it is possible to allow both
89  * 3.0 family of tools and 3.x family of tools to coexist.  This
90  * becomes one problem we found that very hard to reconcile.  That is
91  * why we currently allow two versions of the code in the code
92  * base. This is likely to change in the future.
93  */
94 
95 
96 #ifndef _LIBFBS_MS_CONT_MGAU_H_
97 #define _LIBFBS_MS_CONT_MGAU_H_
98 
99 #include <prim_type.h>
100 #include <cmd_ln.h>
101 #include <logmath.h>
102 #include <s3types.h>
103 #include <ms_gauden.h>
104 #include <ms_senone.h>
105 #include <interp.h>
106 #include <feat.h>
107 #include <mdef.h>
108 #include <ascr.h>
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 #if 0
114 /* Fool Emacs. */
115 }
116 #endif
117 
118 /* Lists of senones sharing each mixture Gaussian codebook */
119 /* \struct mgau2sen_t
120    \brief a mapping from gaussian to senone
121 */
122 typedef struct mgau2sen_s {
123     s3senid_t sen;		/**< Senone shared by this mixture Gaussian */
124     struct mgau2sen_s *next;	/**< Next entry in list for this mixture Gaussian */
125 } mgau2sen_t;
126 
127 /** \struct ms_mgau_t
128     \brief Multi-stream mixture gaussian. It is not necessary to be continr
129 */
130 
131 typedef struct {
132     gauden_t* g;   /**< The codebook */
133     senone_t* s;   /**< The senone */
134     mgau2sen_t **mgau2sen; /**< Senones sharing mixture Gaussian codebooks */
135     interp_t* i;   /**< The interplotion weight file */
136     int32 topn;    /**< Top-n gaussian will be computed */
137 
138     /**< Intermediate used in computation */
139     gauden_dist_t ***dist;
140     int8 *mgau_active;
141 
142 } ms_mgau_model_t;
143 
144 #define ms_mgau_gauden(msg) (msg->g)
145 #define ms_mgau_senone(msg) (msg->s)
146 #define ms_mgau_interp(msg) (msg->i)
147 #define ms_mgau_mgau2sen(msg) (msg->mgau2sen)
148 #define ms_mgau_topn(msg) (msg->topn)
149 
150 ms_mgau_model_t* ms_mgau_init (const char *meanfile,	/**< In: File containing means of mixture gaussians */
151 			       const char *varfile,	/**< In: File containing variances of mixture gaussians */
152 			       float64 varfloor,	/**< In: Floor value applied to variances; e.g., 0.0001 */
153 			       const char *mixwfile,	/**< In: File containing mixture weights */
154 			       float64 mixwfloor,	/**< In: Floor value for mixture weights; e.g., 0.0000001 */
155 			       int32 precomp,
156 			       const char* senmgau,	/**< In: type of the gaussians distribution, .cont. or .semi. FIX
157 							   me! This is confusing!*/
158 			       const char* lambdafile, /**< In: Interplation file */
159 			       int32 topn,        /**< In: Top-n gaussian will be computed */
160 			       logmath_t *logmath
161     );
162 
163 /** Free memory allocated by ms_mgau_init */
164 void ms_mgau_free(ms_mgau_model_t *g /**< In: A set of models to free */
165     );
166 
167 S3DECODER_EXPORT
168 int32 ms_cont_mgau_frame_eval (ascr_t *ascr,   /**< In: An ascr object*/
169 			       ms_mgau_model_t *msg, /**< In: A multi-stream mgau mode */
170 			       mdef_t *mdef,   /**< In: A mdef */
171 			       float32** feat
172     );
173 
174 
175 S3DECODER_EXPORT
176 int32 model_set_mllr(ms_mgau_model_t* msg, /**< The model-stream Gaussian distribution model */
177                      const char *mllrfile, /**< The MLLR file name */
178                      const char *cb2mllrfile, /**< The codebook to MLLR file name */
179                      feat_t* fcb,            /**< FCB object */
180                      mdef_t *mdef,            /**< A model definition */
181                      cmd_ln_t *config
182     );
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 
189 #endif /* _LIBFBS_MS_CONT_MGAU_H_*/
190 
191