\doxysection{fixpoint.\+h}
\label{fixpoint_8h_source}\index{include/sphinxbase/fixpoint.h@{include/sphinxbase/fixpoint.h}}

\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)\ 2005\ 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\ }
\DoxyCodeLine{00036\ \textcolor{comment}{/*\ Fixed-\/point\ arithmetic\ macros.}}
\DoxyCodeLine{00037\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ Author:\ David\ Huggins-\/Daines\ <dhuggins@cs.cmu.edu>}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#ifndef\ \_FIXPOINT\_H\_}}
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#define\ \_FIXPOINT\_H\_}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <limits.h>}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \textcolor{comment}{/*\ Win32/WinCE\ DLL\ gunk\ */}}
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#include\ <sphinxbase/sphinxbase\_export.h>}}
\DoxyCodeLine{00048\ \textcolor{preprocessor}{\#include\ <sphinxbase/prim\_type.h>}}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00050\ \textcolor{preprocessor}{\#ifdef\ \_\_cplusplus}}
\DoxyCodeLine{00051\ \textcolor{keyword}{extern}\ \textcolor{stringliteral}{"{}C"{}}\ \{}
\DoxyCodeLine{00052\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00053\ \textcolor{preprocessor}{\#if\ 0}}
\DoxyCodeLine{00054\ \textcolor{comment}{/*\ Fool\ Emacs.\ */}}
\DoxyCodeLine{00055\ \}}
\DoxyCodeLine{00056\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#ifndef\ DEFAULT\_RADIX}}
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#define\ DEFAULT\_RADIX\ 12}}
\DoxyCodeLine{00060\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00063\ \textcolor{keyword}{typedef}\ int32\ fixed32;}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00066\ \textcolor{preprocessor}{\#define\ FLOAT2FIX\_ANY(x,radix)\ \(\backslash\)}}
\DoxyCodeLine{00067\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ (((x)<0.0)\ ?\ \(\backslash\)}}
\DoxyCodeLine{00068\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ ((fixed32)((x)*(float32)(1<<(radix))\ -\/\ 0.5))\ \(\backslash\)}}
\DoxyCodeLine{00069\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ :\ ((fixed32)((x)*(float32)(1<<(radix))\ +\ 0.5)))}}
\DoxyCodeLine{00070\ \textcolor{preprocessor}{\#define\ FLOAT2FIX(x)\ FLOAT2FIX\_ANY(x,DEFAULT\_RADIX)}}
\DoxyCodeLine{00072\ \textcolor{preprocessor}{\#define\ FIX2FLOAT\_ANY(x,radix)\ ((float32)(x)/(1<<(radix)))}}
\DoxyCodeLine{00073\ \textcolor{preprocessor}{\#define\ FIX2FLOAT(x)\ FIX2FLOAT\_ANY(x,DEFAULT\_RADIX)}}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00083\ \textcolor{comment}{/*\ }}
\DoxyCodeLine{00084\ \textcolor{comment}{\ *\ This\ works\ on\ most\ modern\ ARMs\ but\ *only*\ in\ ARM\ mode\ (for\ obvious}}
\DoxyCodeLine{00085\ \textcolor{comment}{\ *\ reasons),\ so\ don't\ use\ it\ in\ Thumb\ mode\ (but\ why\ are\ you\ building}}
\DoxyCodeLine{00086\ \textcolor{comment}{\ *\ signal\ processing\ code\ in\ Thumb\ mode?!)}}
\DoxyCodeLine{00087\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00088\ \textcolor{preprocessor}{\#if\ defined(\_\_arm\_\_)\ \&\&\ !defined(\_\_thumb\_\_)}}
\DoxyCodeLine{00089\ \textcolor{preprocessor}{\#define\ FIXMUL(a,b)\ FIXMUL\_ANY(a,b,DEFAULT\_RADIX)}}
\DoxyCodeLine{00090\ \textcolor{preprocessor}{\#define\ FIXMUL\_ANY(a,b,r)\ (\{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00091\ \textcolor{preprocessor}{\ \ \ \ \ \ int\ cl,\ ch,\ \_a\ =\ a,\ \_b\ =\ b;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00092\ \textcolor{preprocessor}{\ \ \ \ \ \ \_\_asm\_\_\ ("{}smull\ \%0,\ \%1,\ \%2,\ \%3\(\backslash\)n"{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00093\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ "{}mov\ \%0,\ \%0,\ lsr\ \%4\(\backslash\)n"{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00094\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ "{}orr\ \%0,\ \%0,\ \%1,\ lsl\ \%5\(\backslash\)n"{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00095\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ :\ "{}=\&r"{}\ (cl),\ "{}=\&r"{}\ (ch)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00096\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ :\ "{}r"{}\ (\_a),\ "{}r"{}\ (\_b),\ "{}i"{}\ (r),\ "{}i"{}\ (32-\/(r)));\(\backslash\)}}
\DoxyCodeLine{00097\ \textcolor{preprocessor}{\ \ \ \ \ \ cl;\ \})}}
\DoxyCodeLine{00098\ \textcolor{preprocessor}{\#elif\ defined(BFIN)\ \&\&\ DEFAULT\_RADIX\ ==\ 16}}
\DoxyCodeLine{00099\ \textcolor{comment}{/*\ Blackfin\ magic\ */}}
\DoxyCodeLine{00100\ \textcolor{preprocessor}{\#undef\ FIXMUL}}
\DoxyCodeLine{00101\ \textcolor{comment}{/*\ Use\ the\ accumulators\ for\ the\ 16.16\ case\ (probably\ not\ as\ efficient\ as\ it\ could\ be).\ */}}
\DoxyCodeLine{00102\ \textcolor{preprocessor}{\#define\ FIXMUL(a,b)\ (\{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00103\ \textcolor{preprocessor}{\ \ \ \ \ \ int\ c,\ \_a\ =\ a,\ \_b\ =\ b;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00104\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \_\_asm\_\_("{}\%0.L\ =\ \%1.l\ *\ \%2.l\ (FU);\(\backslash\)n\(\backslash\)t"{}\ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00105\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ "{}\%0.H\ =\ \%1.h\ *\ \%2.h\ (IS);\(\backslash\)n\(\backslash\)t"{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00106\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ "{}A1\ =\ \%0;\(\backslash\)n\(\backslash\)t"{}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00107\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ "{}A1\ +=\ \%1.h\ *\ \%2.l\ (IS,\ M);\(\backslash\)n\(\backslash\)t"{}\ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00108\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ "{}\%0\ =\ (A1\ +=\ \%2.h\ *\ \%1.l)\ (IS,\ M);\(\backslash\)n\(\backslash\)t"{}\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00109\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ :\ "{}=\&W"{}\ (c)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00110\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ :\ "{}d"{}\ (\_a),\ "{}d"{}\ (\_b)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00111\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ :\ "{}A1"{},\ "{}cc"{});\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00112\ \textcolor{preprocessor}{\ \ \ \ \ \ c;\ \})}}
\DoxyCodeLine{00113\ \textcolor{preprocessor}{\#define\ FIXMUL\_ANY(a,b,radix)\ ((fixed32)(((int64)(a)*(b))>>(radix)))}}
\DoxyCodeLine{00114\ \textcolor{preprocessor}{\#elif\ defined(\_MSC\_VER)\ ||\ (defined(HAVE\_LONG\_LONG)\ \&\&\ SIZEOF\_LONG\_LONG\ ==\ 8)}}
\DoxyCodeLine{00115\ \textcolor{preprocessor}{\#define\ FIXMUL(a,b)\ FIXMUL\_ANY(a,b,DEFAULT\_RADIX)}}
\DoxyCodeLine{00116\ \textcolor{preprocessor}{\#define\ FIXMUL\_ANY(a,b,radix)\ ((fixed32)(((int64)(a)*(b))>>(radix)))}}
\DoxyCodeLine{00117\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ Most\ general\ case\ where\ 'long\ long'\ doesn't\ exist\ or\ is\ slow.\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00118\ \textcolor{preprocessor}{\#define\ FIXMUL(a,b)\ FIXMUL\_ANY(a,b,DEFAULT\_RADIX)}}
\DoxyCodeLine{00119\ \textcolor{preprocessor}{\#define\ FIXMUL\_ANY(a,b,radix)\ \(\backslash\)}}
\DoxyCodeLine{00120\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ (fixed32)(((((uint32)(a))\&((1<<(radix))-\/1))\ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00121\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ *\ (((uint32)(b))\&((1<<(radix))-\/1))\ >>\ (radix))\ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00122\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ +\ (((((int32)(a))>>(radix))\ *\ (((int32)(b))>>(radix)))\ <<\ (radix))\ \(\backslash\)}}
\DoxyCodeLine{00123\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ +\ ((((uint32)(a))\&((1<<(radix))-\/1))\ *\ (((int32)(b))>>(radix)))\ \(\backslash\)}}
\DoxyCodeLine{00124\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ +\ ((((uint32)(b))\&((1<<(radix))-\/1))\ *\ (((int32)(a))>>(radix))))}}
\DoxyCodeLine{00125\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \textcolor{comment}{/*\ Various\ fixed-\/point\ logarithmic\ functions\ that\ we\ need.\ */}}
\DoxyCodeLine{00129\ \textcolor{preprocessor}{\#define\ MIN\_FIXLOG\ -\/2829416\ \ }\textcolor{comment}{/*\ log(1e-\/300)\ *\ (1<<DEFAULT\_RADIX)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00130\ \textcolor{preprocessor}{\#define\ MIN\_FIXLOG2\ -\/4081985\ }\textcolor{comment}{/*\ log2(1e-\/300)\ *\ (1<<DEFAULT\_RADIX)\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00132\ \textcolor{preprocessor}{\#define\ FIXLN\_2\ \ \ \ \ \ \ \ \ ((fixed32)(0.693147180559945\ *\ (1<<DEFAULT\_RADIX)))}}
\DoxyCodeLine{00134\ \textcolor{preprocessor}{\#define\ FIXLN(x)\ (fixlog(x)\ -\/\ (FIXLN\_2\ *\ DEFAULT\_RADIX))}}
\DoxyCodeLine{00139\ int32\ fixlog(uint32\ x);}
\DoxyCodeLine{00144\ int32\ fixlog2(uint32\ x);}
\DoxyCodeLine{00145\ }
\DoxyCodeLine{00146\ \textcolor{preprocessor}{\#ifdef\ \_\_cplusplus}}
\DoxyCodeLine{00147\ \}}
\DoxyCodeLine{00148\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ \_FIXPOINT\_H\_\ */}\textcolor{preprocessor}{}}

\end{DoxyCode}
