• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

src/libsphinxbase/feat/cmn_prior.c

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  * CMU ARPA Speech Project
00039  *
00040  * Copyright (c) 2000 Carnegie Mellon University.
00041  * ALL RIGHTS RESERVED.
00042  * **********************************************
00043  * 
00044  * 30-Dec-2000  Rita Singh (rsingh@cs.cmu.edu) at Carnegie Mellon University
00045  * Created
00046  */
00047 
00048 
00049 #ifdef HAVE_CONFIG_H
00050 #include <config.h>
00051 #endif
00052 
00053 #ifdef _MSC_VER
00054 #pragma warning (disable: 4244)
00055 #endif
00056 
00057 #include "ckd_alloc.h"
00058 #include "err.h"
00059 #include "cmn.h"
00060 
00061 void
00062 cmn_prior_set(cmn_t *cmn, mfcc_t const * vec)
00063 {
00064     int32 i;
00065 
00066     E_INFO("cmn_prior_set: from < ");
00067     for (i = 0; i < cmn->veclen; i++)
00068         E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
00069     E_INFOCONT(">\n");
00070 
00071     for (i = 0; i < cmn->veclen; i++) {
00072         cmn->cmn_mean[i] = vec[i];
00073         cmn->sum[i] = vec[i] * CMN_WIN;
00074     }
00075     cmn->nframe = CMN_WIN;
00076 
00077     E_INFO("cmn_prior_set: to   < ");
00078     for (i = 0; i < cmn->veclen; i++)
00079         E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
00080     E_INFOCONT(">\n");
00081 }
00082 
00083 void
00084 cmn_prior_get(cmn_t *cmn, mfcc_t * vec)
00085 {
00086     int32 i;
00087 
00088     for (i = 0; i < cmn->veclen; i++)
00089         vec[i] = cmn->cmn_mean[i];
00090 
00091 }
00092 
00093 static void
00094 cmn_prior_shiftwin(cmn_t *cmn)
00095 {
00096     mfcc_t sf;
00097     int32 i;
00098 
00099     sf = FLOAT2MFCC(1.0) / cmn->nframe;
00100     for (i = 0; i < cmn->veclen; i++)
00101         cmn->cmn_mean[i] = cmn->sum[i] / cmn->nframe; /* sum[i] * sf */
00102 
00103     /* Make the accumulation decay exponentially */
00104     if (cmn->nframe >= CMN_WIN_HWM) {
00105         sf = CMN_WIN * sf;
00106         for (i = 0; i < cmn->veclen; i++)
00107             cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
00108         cmn->nframe = CMN_WIN;
00109     }
00110 }
00111 
00112 void
00113 cmn_prior_update(cmn_t *cmn)
00114 {
00115     mfcc_t sf;
00116     int32 i;
00117 
00118     if (cmn->nframe <= 0)
00119         return;
00120 
00121     E_INFO("cmn_prior_update: from < ");
00122     for (i = 0; i < cmn->veclen; i++)
00123         E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
00124     E_INFOCONT(">\n");
00125 
00126     /* Update mean buffer */
00127     sf = FLOAT2MFCC(1.0) / cmn->nframe;
00128     for (i = 0; i < cmn->veclen; i++)
00129         cmn->cmn_mean[i] = cmn->sum[i] / cmn->nframe; /* sum[i] * sf; */
00130 
00131     /* Make the accumulation decay exponentially */
00132     if (cmn->nframe > CMN_WIN_HWM) {
00133         sf = CMN_WIN * sf;
00134         for (i = 0; i < cmn->veclen; i++)
00135             cmn->sum[i] = MFCCMUL(cmn->sum[i], sf);
00136         cmn->nframe = CMN_WIN;
00137     }
00138 
00139     E_INFO("cmn_prior_update: to   < ");
00140     for (i = 0; i < cmn->veclen; i++)
00141         E_INFOCONT("%5.2f ", MFCC2FLOAT(cmn->cmn_mean[i]));
00142     E_INFOCONT(">\n");
00143 }
00144 
00145 void
00146 cmn_prior(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr)
00147 {
00148     int32 i, j;
00149 
00150     if (varnorm)
00151         E_FATAL
00152             ("Variance normalization not implemented in live mode decode\n");
00153 
00154     if (nfr <= 0)
00155         return;
00156 
00157     for (i = 0; i < nfr; i++) {
00158         for (j = 0; j < cmn->veclen; j++) {
00159             cmn->sum[j] += incep[i][j];
00160             incep[i][j] -= cmn->cmn_mean[j];
00161         }
00162         ++cmn->nframe;
00163     }
00164 
00165     /* Shift buffer down if we have more than CMN_WIN_HWM frames */
00166     if (cmn->nframe > CMN_WIN_HWM)
00167         cmn_prior_shiftwin(cmn);
00168 }

Generated on Fri Jan 14 2011 for SphinxBase by  doxygen 1.7.1