1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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.
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.
34 * ====================================================================
37 /*************************************************
38 * CMU ARPA Speech Project
40 * Copyright (c) 2000 Carnegie Mellon University.
41 * ALL RIGHTS RESERVED.
42 * **********************************************
44 * 30-Dec-2000 Rita Singh (rsingh@cs.cmu.edu) at Carnegie Mellon University
54 #pragma warning (disable: 4244)
57 #include "sphinxbase/ckd_alloc.h"
58 #include "sphinxbase/err.h"
59 #include "sphinxbase/cmn.h"
62 cmn_prior_set(cmn_t *cmn, mfcc_t const * vec)
66 E_INFO("cmn_prior_set: from < ");
67 for (i = 0; i < cmn->veclen; i++)
68 E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
71 for (i = 0; i < cmn->veclen; i++) {
72 cmn->cmn_mean[i] = vec[i];
73 cmn->sum[i] = vec[i] * CMN_WIN;
75 cmn->nframe = CMN_WIN;
77 E_INFO("cmn_prior_set: to < ");
78 for (i = 0; i < cmn->veclen; i++)
79 E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
84 cmn_prior_get(cmn_t *cmn, mfcc_t * vec)
88 for (i = 0; i < cmn->veclen; i++)
89 vec[i] = cmn->cmn_mean[i];
94 cmn_prior_shiftwin(cmn_t *cmn)
99 sf = FLOAT2MFCC(1.0) / cmn->nframe;
100 for (i = 0; i < cmn->veclen; i++)
101 cmn->cmn_mean[i] = cmn->sum[i] / cmn->nframe; /* sum[i] * sf */
103 /* Make the accumulation decay exponentially */
104 if (cmn->nframe >= CMN_WIN_HWM) {
106 for (i = 0; i < cmn->veclen; i++)
107 cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
108 cmn->nframe = CMN_WIN;
113 cmn_prior_update(cmn_t *cmn)
118 if (cmn->nframe <= 0)
121 E_INFO("cmn_prior_update: from < ");
122 for (i = 0; i < cmn->veclen; i++)
123 E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
126 /* Update mean buffer */
127 sf = FLOAT2MFCC(1.0) / cmn->nframe;
128 for (i = 0; i < cmn->veclen; i++)
129 cmn->cmn_mean[i] = cmn->sum[i] / cmn->nframe; /* sum[i] * sf; */
131 /* Make the accumulation decay exponentially */
132 if (cmn->nframe > CMN_WIN_HWM) {
134 for (i = 0; i < cmn->veclen; i++)
135 cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
136 cmn->nframe = CMN_WIN;
139 E_INFO("cmn_prior_update: to < ");
140 for (i = 0; i < cmn->veclen; i++)
141 E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
146 cmn_prior(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
152 ("Variance normalization not implemented in live mode decode\n");
157 for (i = 0; i < nfr; i++) {
158 for (j = 0; j < cmn->veclen; j++) {
159 cmn->sum[j] += incep[i][j];
160 incep[i][j] -= cmn->cmn_mean[j];
165 /* Shift buffer down if we have more than CMN_WIN_HWM frames */
166 if (cmn->nframe > CMN_WIN_HWM)
167 cmn_prior_shiftwin(cmn);