• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  catrans.c  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 
21 static const char pat_tran[] = "$Id: catrans.c,v 1.3.10.2 2007/08/31 17:44:51 dahan Exp $";
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 
27 #ifdef unix
28 #include <unistd.h>
29 #endif
30 #include <assert.h>
31 
32 #include"simapi.h"
33 
CA_AllocateTransform(void)34 CA_Transform *CA_AllocateTransform(void)
35 {
36   CA_Transform *hTransform = NULL;
37   TRY_CA_EXCEPT
38 
39 
40   hTransform = (CA_Transform *) VAR_ALLOCATE_CLR(1, sizeof(CA_Transform), "ca.hTransform");
41   hTransform->is_loaded = False;
42   hTransform->is_setup = False;
43 
44   return (hTransform);
45 
46   BEG_CATCH_CA_EXCEPT
47   END_CATCH_CA_EXCEPT(hTransform)
48 }
49 
50 
CA_FreeTransform(CA_Transform * hTransform)51 void CA_FreeTransform(CA_Transform *hTransform)
52 {
53   TRY_CA_EXCEPT
54 
55   ASSERT(hTransform);
56   VAR_FREE((char *) hTransform, "hTransform");
57   return;
58 
59   BEG_CATCH_CA_EXCEPT
60   END_CATCH_CA_EXCEPT(hTransform)
61 }
62 
63 
CA_LoadTransform(CA_Transform * hTransform,int dimen)64 int CA_LoadTransform(CA_Transform *hTransform, int dimen)
65 {
66   TRY_CA_EXCEPT
67 
68   ASSERT(hTransform);
69   ASSERT(dimen > 0);
70 
71   if (hTransform->is_loaded == True)
72     SERVICE_ERROR(PATTERN_ALREADY_LOADED);
73 
74   hTransform->dim = dimen;
75 
76   hTransform->imelda_acc.between = create_accumulate_matrix(hTransform->dim);
77   hTransform->imelda_acc.bmean = (accdata *) VAR_ALLOCATE(hTransform->dim,
78                                  sizeof(accdata), "ca.hTransform->imelda_acc.bmean");
79   hTransform->imelda_acc.within = create_accumulate_matrix(dimen);
80   hTransform->imelda_acc.wmean = (accdata *) VAR_ALLOCATE(hTransform->dim,
81                                  sizeof(accdata), "ca.hTransform->imelda_acc.wmean");
82   hTransform->mllr_acc.between = create_accumulate_matrix(hTransform->dim + 1);
83   hTransform->mllr_acc.within = create_accumulate_matrix(hTransform->dim + 1);
84 
85   hTransform->is_loaded = True;
86 
87   return (True);
88 
89   BEG_CATCH_CA_EXCEPT
90   END_CATCH_CA_EXCEPT(hTransform)
91 }
92 
93 
CA_ConfigureTransform(CA_Transform * hTransform,int do_mllr,int do_imelda)94 void CA_ConfigureTransform(CA_Transform *hTransform, int do_mllr, int do_imelda)
95 {
96   TRY_CA_EXCEPT
97 
98   ASSERT(hTransform);
99 
100   hTransform->do_mllr = do_mllr;
101   hTransform->do_imelda = do_imelda;
102 
103   return;
104 
105   BEG_CATCH_CA_EXCEPT
106   END_CATCH_CA_EXCEPT(hTransform)
107 }
108 
109 
CA_UnloadTransform(CA_Transform * hTransform)110 void CA_UnloadTransform(CA_Transform *hTransform)
111 {
112   TRY_CA_EXCEPT
113   ASSERT(hTransform);
114   if (hTransform->is_loaded == False)
115     SERVICE_ERROR(PATTERN_NOT_LOADED);
116 
117   delete_accumulate_matrix(hTransform->imelda_acc.between, hTransform->dim);
118   delete_accumulate_matrix(hTransform->imelda_acc.within, hTransform->dim);
119   delete_accumulate_matrix(hTransform->mllr_acc.between, hTransform->dim + 1);
120   delete_accumulate_matrix(hTransform->mllr_acc.within, hTransform->dim + 1);
121   VAR_FREE(hTransform->imelda_acc.bmean, "hTransform->imelda_acc.bmean");
122   VAR_FREE(hTransform->imelda_acc.wmean, "hTransform->imelda_acc.wmean");
123 
124   hTransform->is_loaded = False;
125 
126   return;
127 
128   BEG_CATCH_CA_EXCEPT
129   END_CATCH_CA_EXCEPT(hTransform)
130 }
131 
132 
CA_ClearTransform(CA_Transform * hTransform)133 void CA_ClearTransform(CA_Transform *hTransform)
134 {
135   TRY_CA_EXCEPT
136   int ii, jj;
137 
138   if (hTransform->is_loaded == False)
139     SERVICE_ERROR(PATTERN_NOT_LOADED);
140 
141   ASSERT(hTransform->imelda_acc.within);
142   ASSERT(hTransform->imelda_acc.between);
143   ASSERT(hTransform->imelda_acc.wmean);
144   ASSERT(hTransform->imelda_acc.bmean);
145   ASSERT(hTransform->mllr_acc.within);
146   ASSERT(hTransform->mllr_acc.between);
147 
148   for (ii = 0; ii <= hTransform->dim; ii++)
149   {
150     for (jj = 0; jj <= hTransform->dim; jj++)
151     {
152       hTransform->mllr_acc.between[ii][jj] = 0;
153       hTransform->mllr_acc.within[ii][jj] = 0;
154     }
155   }
156 
157   for (ii = 0; ii < hTransform->dim; ii++)
158   {
159     hTransform->imelda_acc.wmean[ii] = 0;
160     hTransform->imelda_acc.bmean[ii] = 0;
161     for (jj = 0; jj < hTransform->dim; jj++)
162     {
163       hTransform->imelda_acc.between[ii][jj] = 0;
164       hTransform->imelda_acc.within[ii][jj] = 0;
165     }
166   }
167   hTransform->imelda_acc.num = 0;
168   return;
169 
170   BEG_CATCH_CA_EXCEPT
171   END_CATCH_CA_EXCEPT(hTransform)
172 }
173 
174 
CA_InheritAccumulates(CA_Transform * hTransform,CA_Pattern * hPattern)175 void CA_InheritAccumulates(CA_Transform *hTransform, CA_Pattern *hPattern)
176 {
177   TRY_CA_EXCEPT
178   int ii, jj;
179 
180   ASSERT(hPattern);
181   if (hPattern->is_loaded == False)
182     SERVICE_ERROR(PATTERN_NOT_LOADED);
183   ASSERT(hTransform);
184   if (hTransform->is_loaded == False)
185     SERVICE_ERROR(PATTERN_NOT_LOADED);
186 
187   ASSERT(hTransform->dim == hPattern->data.dim);
188 
189   if (hTransform->do_mllr)
190   {
191 
192     ASSERT(hPattern->true_accumulates);
193     ASSERT(hPattern->data.do_mllr);
194     ASSERT(hPattern->data.mllr_acc.between);
195     ASSERT(hTransform->mllr_acc.between);
196 
197     for (ii = 0; ii <= hTransform->dim; ii++)
198       for (jj = 0; jj <= hTransform->dim; jj++)
199       {
200 
201         hTransform->mllr_acc.between[ii][jj] +=
202           hPattern->data.mllr_acc.between[ii][jj];
203         hTransform->mllr_acc.within[ii][jj] +=
204           hPattern->data.mllr_acc.within[ii][jj];
205 
206       }
207 
208     log_report("\nCA_InheritAccumulates MLLR inheriting %f frames (total now %f)\n\n", hPattern->data.mllr_acc.within[hTransform->dim][hTransform->dim], hTransform->mllr_acc.within[hTransform->dim][hTransform->dim]);
209   }
210 
211   if (hTransform->do_imelda)
212   {
213 
214     ASSERT(hPattern->data.do_imelda);
215     ASSERT(hPattern->data.mllr_acc.between);
216     ASSERT(hTransform->mllr_acc.between);
217 
218     for (ii = 0; ii < hTransform->dim; ii++)
219       for (jj = 0; jj < hTransform->dim; jj++)
220       {
221 
222         hTransform->imelda_acc.between[ii][jj] +=
223           hPattern->data.imelda_acc.between[ii][jj];
224         hTransform->imelda_acc.within[ii][jj] +=
225           hPattern->data.imelda_acc.within[ii][jj];
226       }
227 
228     for (ii = 0; ii < hTransform->dim; ii++)
229     {
230 
231       hTransform->imelda_acc.bmean[ii] +=
232         hPattern->data.imelda_acc.bmean[ii];
233       hTransform->imelda_acc.wmean[ii] +=
234         hPattern->data.imelda_acc.wmean[ii];
235     }
236 
237     hTransform->imelda_acc.num += hPattern->data.imelda_acc.num;
238 
239     log_report("\nCA_InheritAccumulates Imelda inheriting %d frames (total now %d)\n\n", hPattern->data.imelda_acc.num, hTransform->imelda_acc.num);
240   }
241 
242   return;
243 
244   BEG_CATCH_CA_EXCEPT
245   END_CATCH_CA_EXCEPT(hPattern)
246 }
247 
248 
CA_LoadTransformAccumulates(CA_Pattern * hPattern,CA_Transform * hTransform)249 void CA_LoadTransformAccumulates(CA_Pattern *hPattern,
250                                  CA_Transform *hTransform)
251 {
252   TRY_CA_EXCEPT
253   int ii, jj;
254 
255   ASSERT(hPattern);
256   if (hPattern->is_loaded == False)
257     SERVICE_ERROR(PATTERN_NOT_LOADED);
258   ASSERT(hTransform);
259   if (hTransform->is_loaded == False)
260     SERVICE_ERROR(PATTERN_NOT_LOADED);
261 
262   ASSERT(hTransform->dim == hPattern->data.dim);
263 
264   if (hTransform->do_mllr)
265   {
266 
267     ASSERT(hPattern->data.do_mllr);
268     ASSERT(hPattern->data.mllr_acc.between);
269     ASSERT(hTransform->mllr_acc.between);
270 
271     for (ii = 0; ii <= hTransform->dim; ii++)
272       for (jj = 0; jj <= hTransform->dim; jj++)
273       {
274 
275         hPattern->data.mllr_acc.between[ii][jj] =
276           hTransform->mllr_acc.between[ii][jj];
277         hPattern->data.mllr_acc.within[ii][jj] =
278           hTransform->mllr_acc.within[ii][jj];
279       }
280   }
281 
282   if (hTransform->do_imelda)
283   {
284 
285     ASSERT(hPattern->data.do_imelda);
286     ASSERT(hPattern->data.mllr_acc.between);
287     ASSERT(hTransform->mllr_acc.between);
288 
289     for (ii = 0; ii < hTransform->dim; ii++)
290       for (jj = 0; jj < hTransform->dim; jj++)
291       {
292 
293         hPattern->data.imelda_acc.between[ii][jj] =
294           hTransform->imelda_acc.between[ii][jj];
295         hPattern->data.imelda_acc.within[ii][jj] =
296           hTransform->imelda_acc.within[ii][jj];
297       }
298 
299     for (ii = 0; ii < hTransform->dim; ii++)
300     {
301 
302       hPattern->data.imelda_acc.bmean[ii] =
303         hTransform->imelda_acc.bmean[ii];
304       hPattern->data.imelda_acc.wmean[ii] =
305         hTransform->imelda_acc.wmean[ii];
306     }
307 
308     hPattern->data.imelda_acc.num = hTransform->imelda_acc.num;
309 
310   }
311 
312   return;
313 
314   BEG_CATCH_CA_EXCEPT
315   END_CATCH_CA_EXCEPT(hPattern)
316 }
317 
318 
319