SphinxBase 0.6
cmn_prior.c
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 * CMU ARPA Speech Project
39 *
40 * Copyright (c) 2000 Carnegie Mellon University.
41 * ALL RIGHTS RESERVED.
42 * **********************************************
43 *
44 * 30-Dec-2000 Rita Singh (rsingh@cs.cmu.edu) at Carnegie Mellon University
45 * Created
46 */
47
48
49#ifdef HAVE_CONFIG_H
50#include <config.h>
51#endif
52
53#ifdef _MSC_VER
54#pragma warning (disable: 4244)
55#endif
56
58#include "sphinxbase/err.h"
59#include "sphinxbase/cmn.h"
60
61void
62cmn_prior_set(cmn_t *cmn, mfcc_t const * vec)
63{
64 int32 i;
65
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]));
69 E_INFOCONT(">\n");
70
71 for (i = 0; i < cmn->veclen; i++) {
72 cmn->cmn_mean[i] = vec[i];
73 cmn->sum[i] = vec[i] * CMN_WIN;
74 }
75 cmn->nframe = CMN_WIN;
76
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]));
80 E_INFOCONT(">\n");
81}
82
83void
84cmn_prior_get(cmn_t *cmn, mfcc_t * vec)
85{
86 int32 i;
87
88 for (i = 0; i < cmn->veclen; i++)
89 vec[i] = cmn->cmn_mean[i];
90
91}
92
93static void
94cmn_prior_shiftwin(cmn_t *cmn)
95{
96 mfcc_t sf;
97 int32 i;
98
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 */
102
103 /* Make the accumulation decay exponentially */
104 if (cmn->nframe >= CMN_WIN_HWM) {
105 sf = CMN_WIN * sf;
106 for (i = 0; i < cmn->veclen; i++)
107 cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
108 cmn->nframe = CMN_WIN;
109 }
110}
111
112void
114{
115 mfcc_t sf;
116 int32 i;
117
118 if (cmn->nframe <= 0)
119 return;
120
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]));
124 E_INFOCONT(">\n");
125
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; */
130
131 /* Make the accumulation decay exponentially */
132 if (cmn->nframe > CMN_WIN_HWM) {
133 sf = CMN_WIN * sf;
134 for (i = 0; i < cmn->veclen; i++)
135 cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
136 cmn->nframe = CMN_WIN;
137 }
138
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]));
142 E_INFOCONT(">\n");
143}
144
145void
146cmn_prior(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
147{
148 int32 i, j;
149
150 if (varnorm)
151 E_FATAL
152 ("Variance normalization not implemented in live mode decode\n");
153
154 if (nfr <= 0)
155 return;
156
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];
161 }
162 ++cmn->nframe;
163 }
164
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);
168}
Sphinx's memory allocation/deallocation routines.
Apply Cepstral Mean Normalization (CMN) to the set of input mfc frames.
SPHINXBASE_EXPORT void cmn_prior_set(cmn_t *cmn, mfcc_t const *vec)
Set the prior mean.
Definition cmn_prior.c:62
SPHINXBASE_EXPORT void cmn_prior_get(cmn_t *cmn, mfcc_t *vec)
Get the prior mean.
Definition cmn_prior.c:84
SPHINXBASE_EXPORT void cmn_prior(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
CMN for one block of data, using prior mean.
Definition cmn_prior.c:146
SPHINXBASE_EXPORT void cmn_prior_update(cmn_t *cmn)
Update prior mean based on observed data.
Definition cmn_prior.c:113
SPHINXBASE_EXPORT void cmn(cmn_t *cmn, mfcc_t **mfc, int32 varnorm, int32 n_frame)
CMN for the whole sentence.
Definition cmn.c:150
Implementation of logging routines.
#define E_FATAL
Exit with non-zero status after error message.
Definition err.h:127
#define E_INFO
Print logging information to standard error stream.
Definition err.h:147
#define E_INFOCONT
Print logging information without header, to standard error stream.
Definition err.h:153
wrapper of operation of the cepstral mean normalization.
Definition cmn.h:128