\doxysection{cmn\+\_\+prior.\+c}
\label{cmn__prior_8c_source}\index{src/libsphinxbase/feat/cmn\_prior.c@{src/libsphinxbase/feat/cmn\_prior.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 1999-\/2004\ Carnegie\ Mellon\ University.\ \ All\ rights}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*************************************************}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ CMU\ ARPA\ Speech\ Project}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2000\ Carnegie\ Mellon\ University.}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *\ ALL\ RIGHTS\ RESERVED.}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ *\ **********************************************}}
\DoxyCodeLine{00043\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00044\ \textcolor{comment}{\ *\ 30-\/Dec-\/2000\ \ Rita\ Singh\ (rsingh@cs.cmu.edu)\ at\ Carnegie\ Mellon\ University}}
\DoxyCodeLine{00045\ \textcolor{comment}{\ *\ Created}}
\DoxyCodeLine{00046\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00047\ }
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#ifdef\ HAVE\_CONFIG\_H}}
\DoxyCodeLine{00050\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ \textcolor{preprocessor}{\#ifdef\ \_MSC\_VER}}
\DoxyCodeLine{00054\ \textcolor{preprocessor}{\#pragma\ warning\ (disable:\ 4244)}}
\DoxyCodeLine{00055\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/ckd\_alloc.h"{}}}
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/err.h"{}}}
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/cmn.h"{}}}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00062\ cmn\_prior\_set(cmn\_t\ *cmn,\ mfcc\_t\ \textcolor{keyword}{const}\ *\ vec)}
\DoxyCodeLine{00063\ \{}
\DoxyCodeLine{00064\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}cmn\_prior\_set:\ from\ <\ "{}});}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%5.2f\ "{}},\ MFCC2FLOAT(cmn-\/>cmn\_mean[i]));}
\DoxyCodeLine{00069\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}>\(\backslash\)n"{}});}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00071\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)\ \{}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ cmn-\/>cmn\_mean[i]\ =\ vec[i];}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ cmn-\/>sum[i]\ =\ vec[i]\ *\ CMN\_WIN;}
\DoxyCodeLine{00074\ \ \ \ \ \}}
\DoxyCodeLine{00075\ \ \ \ \ cmn-\/>nframe\ =\ CMN\_WIN;}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}cmn\_prior\_set:\ to\ \ \ <\ "{}});}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%5.2f\ "{}},\ MFCC2FLOAT(cmn-\/>cmn\_mean[i]));}
\DoxyCodeLine{00080\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}>\(\backslash\)n"{}});}
\DoxyCodeLine{00081\ \}}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00084\ cmn\_prior\_get(cmn\_t\ *cmn,\ mfcc\_t\ *\ vec)}
\DoxyCodeLine{00085\ \{}
\DoxyCodeLine{00086\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \ \ vec[i]\ =\ cmn-\/>cmn\_mean[i];}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00091\ \}}
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00093\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00094\ cmn\_prior\_shiftwin(cmn\_t\ *cmn)}
\DoxyCodeLine{00095\ \{}
\DoxyCodeLine{00096\ \ \ \ \ mfcc\_t\ sf;}
\DoxyCodeLine{00097\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00098\ }
\DoxyCodeLine{00099\ \ \ \ \ sf\ =\ FLOAT2MFCC(1.0)\ /\ cmn-\/>nframe;}
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ cmn-\/>cmn\_mean[i]\ =\ cmn-\/>sum[i]\ /\ cmn-\/>nframe;\ \textcolor{comment}{/*\ sum[i]\ *\ sf\ */}}
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{comment}{/*\ Make\ the\ accumulation\ decay\ exponentially\ */}}
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmn-\/>nframe\ >=\ CMN\_WIN\_HWM)\ \{}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ sf\ =\ CMN\_WIN\ *\ sf;}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \ \ \ \ cmn-\/>sum[i]\ =\ MFCCMUL(cmn-\/>sum[i],\ sf);}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ cmn-\/>nframe\ =\ CMN\_WIN;}
\DoxyCodeLine{00109\ \ \ \ \ \}}
\DoxyCodeLine{00110\ \}}
\DoxyCodeLine{00111\ }
\DoxyCodeLine{00112\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00113\ cmn\_prior\_update(cmn\_t\ *cmn)}
\DoxyCodeLine{00114\ \{}
\DoxyCodeLine{00115\ \ \ \ \ mfcc\_t\ sf;}
\DoxyCodeLine{00116\ \ \ \ \ int32\ i;}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmn-\/>nframe\ <=\ 0)}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}cmn\_prior\_update:\ from\ <\ "{}});}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%5.2f\ "{}},\ MFCC2FLOAT(cmn-\/>cmn\_mean[i]));}
\DoxyCodeLine{00124\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}>\(\backslash\)n"{}});}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ \ \ \ \ \textcolor{comment}{/*\ Update\ mean\ buffer\ */}}
\DoxyCodeLine{00127\ \ \ \ \ sf\ =\ FLOAT2MFCC(1.0)\ /\ cmn-\/>nframe;}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ cmn-\/>cmn\_mean[i]\ =\ cmn-\/>sum[i]\ /\ cmn-\/>nframe;\ \textcolor{comment}{/*\ sum[i]\ *\ sf;\ */}}
\DoxyCodeLine{00130\ }
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{comment}{/*\ Make\ the\ accumulation\ decay\ exponentially\ */}}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmn-\/>nframe\ >\ CMN\_WIN\_HWM)\ \{}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ sf\ =\ CMN\_WIN\ *\ sf;}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ cmn-\/>sum[i]\ =\ MFCCMUL(cmn-\/>sum[i],\ sf);}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ cmn-\/>nframe\ =\ CMN\_WIN;}
\DoxyCodeLine{00137\ \ \ \ \ \}}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00139\ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}cmn\_prior\_update:\ to\ \ \ <\ "{}});}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ cmn-\/>veclen;\ i++)}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}\%5.2f\ "{}},\ MFCC2FLOAT(cmn-\/>cmn\_mean[i]));}
\DoxyCodeLine{00142\ \ \ \ \ E\_INFOCONT(\textcolor{stringliteral}{"{}>\(\backslash\)n"{}});}
\DoxyCodeLine{00143\ \}}
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00145\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00146\ cmn\_prior(cmn\_t\ *cmn,\ mfcc\_t\ **incep,\ int32\ varnorm,\ int32\ nfr)}
\DoxyCodeLine{00147\ \{}
\DoxyCodeLine{00148\ \ \ \ \ int32\ i,\ j;}
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordflow}{if}\ (varnorm)}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ E\_FATAL}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{stringliteral}{"{}Variance\ normalization\ not\ implemented\ in\ live\ mode\ decode\(\backslash\)n"{}});}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordflow}{if}\ (nfr\ <=\ 0)}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nfr;\ i++)\ \{}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ cmn-\/>veclen;\ j++)\ \{}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \ \ \ \ cmn-\/>sum[j]\ +=\ incep[i][j];}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \ \ \ \ incep[i][j]\ -\/=\ cmn-\/>cmn\_mean[j];}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ ++cmn-\/>nframe;}
\DoxyCodeLine{00163\ \ \ \ \ \}}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{comment}{/*\ Shift\ buffer\ down\ if\ we\ have\ more\ than\ CMN\_WIN\_HWM\ frames\ */}}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmn-\/>nframe\ >\ CMN\_WIN\_HWM)}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ cmn\_prior\_shiftwin(cmn);}
\DoxyCodeLine{00168\ \}}

\end{DoxyCode}
