\doxysection{sphinx\+\_\+fe.\+c}
\label{sphinx__fe_8c_source}\index{src/sphinx\_fe/sphinx\_fe.c@{src/sphinx\_fe/sphinx\_fe.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)\ 1996-\/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{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00039\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#include\ <time.h>}}
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#include\ <assert.h>}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#ifdef\ HAVE\_CONFIG\_H}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00046\ }
\DoxyCodeLine{00047\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SNDFILE\_H}}
\DoxyCodeLine{00048\ \textcolor{preprocessor}{\#include\ <sndfile.h>}}
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#include\ <sphinxbase/fe.h>}}
\DoxyCodeLine{00052\ \textcolor{preprocessor}{\#include\ <sphinxbase/strfuncs.h>}}
\DoxyCodeLine{00053\ \textcolor{preprocessor}{\#include\ <sphinxbase/pio.h>}}
\DoxyCodeLine{00054\ \textcolor{preprocessor}{\#include\ <sphinxbase/filename.h>}}
\DoxyCodeLine{00055\ \textcolor{preprocessor}{\#include\ <sphinxbase/cmd\_ln.h>}}
\DoxyCodeLine{00056\ \textcolor{preprocessor}{\#include\ <sphinxbase/err.h>}}
\DoxyCodeLine{00057\ \textcolor{preprocessor}{\#include\ <sphinxbase/ckd\_alloc.h>}}
\DoxyCodeLine{00058\ \textcolor{preprocessor}{\#include\ <sphinxbase/byteorder.h>}}
\DoxyCodeLine{00059\ \textcolor{preprocessor}{\#include\ <sphinxbase/hash\_table.h>}}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \textcolor{preprocessor}{\#include\ "{}sphinx\_wave2feat.h"{}}}
\DoxyCodeLine{00062\ \textcolor{preprocessor}{\#include\ "{}cmd\_ln\_defn.h"{}}}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }audio\_type\_s\ \{}
\DoxyCodeLine{00065\ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *name;}
\DoxyCodeLine{00066\ \ \ \ \ int\ (*detect)(sphinx\_wave2feat\_t\ *wtf);}
\DoxyCodeLine{00067\ \ \ \ \ int\ (*decode)(sphinx\_wave2feat\_t\ *wtf);}
\DoxyCodeLine{00068\ \}\ audio\_type\_t;}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }output\_type\_s\ \{}
\DoxyCodeLine{00071\ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *name;}
\DoxyCodeLine{00072\ \ \ \ \ int\ (*output\_header)(sphinx\_wave2feat\_t\ *wtf,\ \textcolor{keywordtype}{int}\ nfloat);}
\DoxyCodeLine{00073\ \ \ \ \ int\ (*output\_frames)(sphinx\_wave2feat\_t\ *wtf,\ mfcc\_t\ **frames,\ \textcolor{keywordtype}{int}\ nfr);}
\DoxyCodeLine{00074\ \}\ output\_type\_t;}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \textcolor{keyword}{struct\ }sphinx\_wave2feat\_s\ \{}
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keywordtype}{int}\ refcount;\ \ \ \ \ }
\DoxyCodeLine{00078\ \ \ \ \ cmd\_ln\_t\ *config;\ }
\DoxyCodeLine{00079\ \ \ \ \ fe\_t\ *fe;\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordtype}{char}\ *infile;\ \ \ \ \ }
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordtype}{char}\ *outfile;\ \ \ \ }
\DoxyCodeLine{00082\ \ \ \ \ FILE\ *infh;\ \ \ \ \ \ \ }
\DoxyCodeLine{00083\ \ \ \ \ FILE\ *outfh;\ \ \ \ \ \ }
\DoxyCodeLine{00084\ \ \ \ \ \textcolor{keywordtype}{short}\ *audio;\ \ \ \ \ }
\DoxyCodeLine{00085\ \ \ \ \ mfcc\_t\ **feat;\ \ \ \ }
\DoxyCodeLine{00086\ \ \ \ \ \textcolor{keywordtype}{int}\ blocksize;\ \ \ \ }
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{keywordtype}{int}\ featsize;\ \ \ \ \ }
\DoxyCodeLine{00088\ \ \ \ \ \textcolor{keywordtype}{int}\ veclen;\ \ \ \ \ \ \ }
\DoxyCodeLine{00089\ \ \ \ \ \textcolor{keywordtype}{int}\ in\_veclen;\ \ \ \ }
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keywordtype}{int}\ byteswap;\ \ \ \ \ }
\DoxyCodeLine{00091\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SNDFILE\_H}}
\DoxyCodeLine{00092\ \ \ \ \ SNDFILE\ *insfh;\ \ \ }
\DoxyCodeLine{00093\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00094\ \ \ \ \ output\_type\_t\ \textcolor{keyword}{const}\ *ot;}
\DoxyCodeLine{00095\ \};}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00098\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }RIFFHeader\{}
\DoxyCodeLine{00099\ \ \ \ \ \textcolor{keywordtype}{char}\ rifftag[4];\ \ \ \ \ \ \textcolor{comment}{/*\ "{}RIFF"{}\ string\ */}}
\DoxyCodeLine{00100\ \ \ \ \ int32\ TotalLength;\ \ \ \ \ \ \textcolor{comment}{/*\ Total\ length\ */}}
\DoxyCodeLine{00101\ \ \ \ \ \textcolor{keywordtype}{char}\ wavefmttag[8];\ \ \ \textcolor{comment}{/*\ "{}WAVEfmt\ "{}\ string\ (note\ space\ after\ 't')\ */}}
\DoxyCodeLine{00102\ \ \ \ \ int32\ RemainingLength;\ \ \textcolor{comment}{/*\ Remaining\ length\ */}}
\DoxyCodeLine{00103\ \ \ \ \ int16\ data\_format;\ \ \ \ \textcolor{comment}{/*\ data\ format\ tag,\ 1\ =\ PCM\ */}}
\DoxyCodeLine{00104\ \ \ \ \ int16\ numchannels;\ \ \ \ \textcolor{comment}{/*\ Number\ of\ channels\ in\ file\ */}}
\DoxyCodeLine{00105\ \ \ \ \ int32\ SamplingFreq;\ \ \ \ \ \textcolor{comment}{/*\ Sampling\ frequency\ */}}
\DoxyCodeLine{00106\ \ \ \ \ int32\ BytesPerSec;\ \ \ \ \ \ \textcolor{comment}{/*\ Average\ bytes/sec\ */}}
\DoxyCodeLine{00107\ \ \ \ \ int16\ BlockAlign;\ \ \ \ \ \textcolor{comment}{/*\ Block\ align\ */}}
\DoxyCodeLine{00108\ \ \ \ \ int16\ BitsPerSample;\ \ \textcolor{comment}{/*\ 8\ or\ 16\ bit\ */}}
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{keywordtype}{char}\ datatag[4];\ \ \ \ \ \ \textcolor{comment}{/*\ "{}data"{}\ string\ */}}
\DoxyCodeLine{00110\ \ \ \ \ int32\ datalength;\ \ \ \ \ \ \ \textcolor{comment}{/*\ Raw\ data\ length\ */}}
\DoxyCodeLine{00111\ \}\ MSWAV\_hdr;}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00118\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00119\ detect\_riff(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00120\ \{}
\DoxyCodeLine{00121\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00122\ \ \ \ \ MSWAV\_hdr\ hdr;}
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen(wtf-\/>infile,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00125\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ \%s"{}},\ wtf-\/>infile);}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00127\ \ \ \ \ \}}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(\&hdr,\ \textcolor{keyword}{sizeof}(hdr),\ 1,\ fh)\ !=\ 1)\ \{}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ read\ RIFF\ header"{}});}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00132\ \ \ \ \ \}}
\DoxyCodeLine{00133\ \ \ \ \ \textcolor{comment}{/*\ Make\ sure\ it\ is\ actually\ a\ RIFF\ file.\ */}}
\DoxyCodeLine{00134\ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ !=\ memcmp(hdr.rifftag,\ \textcolor{stringliteral}{"{}RIFF"{}},\ 4))\ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ FALSE;}
\DoxyCodeLine{00137\ \ \ \ \ \}}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{comment}{/*\ Get\ relevant\ information.\ */}}
\DoxyCodeLine{00140\ \ \ \ \ cmd\_ln\_set\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}},\ hdr.numchannels);}
\DoxyCodeLine{00141\ \ \ \ \ cmd\_ln\_set\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/samprate"{}},\ hdr.SamplingFreq);}
\DoxyCodeLine{00142\ \ \ \ \ wtf-\/>infh\ =\ fh;}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00145\ \}}
\DoxyCodeLine{00146\ }
\DoxyCodeLine{00147\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00148\ open\_nist\_file(sphinx\_wave2feat\_t\ *wtf,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *infile,\ FILE\ **out\_fh,\ \textcolor{keywordtype}{int}\ detect\_endian)}
\DoxyCodeLine{00149\ \{}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keywordtype}{char}\ nist[7];}
\DoxyCodeLine{00151\ \ \ \ \ lineiter\_t\ *li;}
\DoxyCodeLine{00152\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen(infile,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ \%s"{}},\ infile);}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00157\ \ \ \ \ \}}
\DoxyCodeLine{00158\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(\&nist,\ 1,\ 7,\ fh)\ !=\ 7)\ \{}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ read\ NIST\ header"{}});}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00162\ \ \ \ \ \}}
\DoxyCodeLine{00163\ \ \ \ \ \textcolor{comment}{/*\ Is\ this\ actually\ a\ NIST\ file?\ */}}
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ !=\ strncmp(nist,\ \textcolor{stringliteral}{"{}NIST\_1A"{}},\ 7))\ \{}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ FALSE;}
\DoxyCodeLine{00167\ \ \ \ \ \}}
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{comment}{/*\ Rewind,\ parse\ lines.\ */}}
\DoxyCodeLine{00169\ \ \ \ \ fseek(fh,\ 0,\ SEEK\_SET);}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{for}\ (li\ =\ lineiter\_start(fh);\ li;\ li\ =\ lineiter\_next(li))\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ **words;}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ nword;}
\DoxyCodeLine{00173\ }
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ string\_trim(li-\/>buf,\ STRING\_BOTH);}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strlen(li-\/>buf)\ ==\ 0)\ \{}
\DoxyCodeLine{00176\ \ \ \ \ \ \ \ \ \ \ \ \ lineiter\_free(li);}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ nword\ =\ str2words(li-\/>buf,\ NULL,\ 0);}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nword\ !=\ 3)}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ words\ =\ ckd\_calloc(nword,\ \textcolor{keyword}{sizeof}(*words));}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ str2words(li-\/>buf,\ words,\ nword);}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(words[0],\ \textcolor{stringliteral}{"{}sample\_rate"{}}))\ \{}
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_set\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/samprate"{}},\ atof\_c(words[2]));}
\DoxyCodeLine{00186\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(words[0],\ \textcolor{stringliteral}{"{}channel\_count"{}}))\ \{}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_set\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}},\ atoi(words[2]));}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (detect\_endian\ \&\&\ 0\ ==\ strcmp(words[0],\ \textcolor{stringliteral}{"{}sample\_byte\_format"{}}))\ \{}
\DoxyCodeLine{00191\ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_set\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/input\_endian"{}},}
\DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (0\ ==\ strcmp(words[2],\ \textcolor{stringliteral}{"{}10"{}}))\ ?\ \textcolor{stringliteral}{"{}big"{}}\ :\ \textcolor{stringliteral}{"{}little"{}});}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ ckd\_free(words);}
\DoxyCodeLine{00195\ \ \ \ \ \}}
\DoxyCodeLine{00196\ }
\DoxyCodeLine{00197\ \ \ \ \ fseek(fh,\ 1024,\ SEEK\_SET);}
\DoxyCodeLine{00198\ \ \ \ \ \textcolor{keywordflow}{if}\ (out\_fh)}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ *out\_fh\ =\ fh;}
\DoxyCodeLine{00200\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00203\ \}}
\DoxyCodeLine{00204\ }
\DoxyCodeLine{00205\ \textcolor{preprocessor}{\#ifdef\ HAVE\_POPEN}}
\DoxyCodeLine{00206\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00207\ detect\_sph2pipe(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00208\ \{}
\DoxyCodeLine{00209\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00210\ \ \ \ \ \textcolor{keywordtype}{char}\ *cmdline;}
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \ \ \ \ \textcolor{comment}{/*\ Determine\ if\ it's\ NIST\ file\ and\ get\ parameters.\ */}}
\DoxyCodeLine{00214\ \ \ \ \ \textcolor{keywordflow}{if}\ ((rv\ =\ open\_nist\_file(wtf,\ wtf-\/>infile,\ NULL,\ FALSE))\ !=\ TRUE)}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{00216\ }
\DoxyCodeLine{00217\ \ \ \ \ \textcolor{comment}{/*\ Now\ popen\ it\ with\ sph2pipe.\ */}}
\DoxyCodeLine{00218\ \ \ \ \ cmdline\ =\ string\_join(\textcolor{stringliteral}{"{}sph2pipe\ -\/f\ raw\ '"{}},\ wtf-\/>infile,\ \textcolor{stringliteral}{"{}'"{}},\ NULL);}
\DoxyCodeLine{00219\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ popen(cmdline,\ \textcolor{stringliteral}{"{}r"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ popen(\(\backslash\)"{}sph2pipe\ -\/f\ raw\ '\%s'\(\backslash\)"{})"{}},\ wtf-\/>infile);}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ ckd\_free(cmdline);}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00223\ \ \ \ \ \}}
\DoxyCodeLine{00224\ }
\DoxyCodeLine{00225\ \ \ \ \ wtf-\/>infh\ =\ fh;}
\DoxyCodeLine{00226\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00227\ \}}
\DoxyCodeLine{00228\ \textcolor{preprocessor}{\#else\ }\textcolor{comment}{/*\ !HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00229\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00230\ detect\_sph2pipe(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00231\ \{}
\DoxyCodeLine{00232\ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}popen()\ not\ available,\ cannot\ run\ sph2pipe\(\backslash\)n"{}});}
\DoxyCodeLine{00233\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00234\ \}}
\DoxyCodeLine{00235\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ !HAVE\_POPEN\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00236\ }
\DoxyCodeLine{00242\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00243\ detect\_nist(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00244\ \{}
\DoxyCodeLine{00245\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00246\ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00247\ }
\DoxyCodeLine{00248\ \ \ \ \ \textcolor{keywordflow}{if}\ ((rv\ =\ open\_nist\_file(wtf,\ wtf-\/>infile,\ \&fh,\ TRUE))\ !=\ TRUE)}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{00250\ \ \ \ \ wtf-\/>infh\ =\ fh;}
\DoxyCodeLine{00251\ }
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00253\ \}}
\DoxyCodeLine{00254\ }
\DoxyCodeLine{00255\ }
\DoxyCodeLine{00262\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00263\ detect\_raw(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00264\ \{}
\DoxyCodeLine{00265\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00266\ }
\DoxyCodeLine{00267\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen(wtf-\/>infile,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00268\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ \%s"{}},\ wtf-\/>infile);}
\DoxyCodeLine{00269\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00270\ \ \ \ \ \}}
\DoxyCodeLine{00271\ \ \ \ \ wtf-\/>infh\ =\ fh;}
\DoxyCodeLine{00272\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00273\ \}}
\DoxyCodeLine{00274\ }
\DoxyCodeLine{00281\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00282\ detect\_sphinx\_mfc(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00283\ \{}
\DoxyCodeLine{00284\ \ \ \ \ FILE\ *fh;}
\DoxyCodeLine{00285\ \ \ \ \ int32\ len;}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{keywordtype}{long}\ flen;}
\DoxyCodeLine{00287\ }
\DoxyCodeLine{00288\ \ \ \ \ \textcolor{keywordflow}{if}\ ((fh\ =\ fopen(wtf-\/>infile,\ \textcolor{stringliteral}{"{}rb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00289\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ \%s"{}},\ wtf-\/>infile);}
\DoxyCodeLine{00290\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00291\ \ \ \ \ \}}
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keywordflow}{if}\ (fread(\&len,\ 4,\ 1,\ fh)\ !=\ 1)\ \{}
\DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ read\ header\ from\ \%s\(\backslash\)n"{}},\ wtf-\/>infile);}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ fclose(fh);}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00296\ \ \ \ \ \}}
\DoxyCodeLine{00297\ \ \ \ \ fseek(fh,\ 0,\ SEEK\_END);}
\DoxyCodeLine{00298\ \ \ \ \ flen\ =\ ftell(fh);}
\DoxyCodeLine{00299\ }
\DoxyCodeLine{00300\ \ \ \ \ \textcolor{comment}{/*\ figure\ out\ whether\ to\ byteswap\ */}}
\DoxyCodeLine{00301\ \ \ \ \ flen\ =\ (flen\ /\ 4)\ -\/\ 1;}
\DoxyCodeLine{00302\ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ !=\ len)\ \{}
\DoxyCodeLine{00303\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ First\ make\ sure\ this\ is\ an\ endianness\ problem,\ otherwise\ fail.\ */}}
\DoxyCodeLine{00304\ \ \ \ \ \ \ \ \ SWAP\_INT32(\&len);}
\DoxyCodeLine{00305\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (flen\ !=\ len)\ \{}
\DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_INT32(\&len);}
\DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Mismatch\ in\ header/file\ lengths:\ 0x\%08x\ vs\ 0x\%08x\(\backslash\)n"{}},}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ len,\ flen);}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00311\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Set\ the\ input\ endianness\ to\ the\ opposite\ of\ the\ machine\ endianness...\ */}}
\DoxyCodeLine{00312\ \ \ \ \ \ \ \ \ cmd\_ln\_set\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/input\_endian"{}},}
\DoxyCodeLine{00313\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (0\ ==\ strcmp(\textcolor{stringliteral}{"{}big"{}},\ cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/mach\_endian"{}}))}
\DoxyCodeLine{00314\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ?\ \textcolor{stringliteral}{"{}little"{}}\ :\ \textcolor{stringliteral}{"{}big"{}}));}
\DoxyCodeLine{00315\ \ \ \ \ \}}
\DoxyCodeLine{00316\ \ \ \ \ }
\DoxyCodeLine{00317\ \ \ \ \ fseek(fh,\ 4,\ SEEK\_SET);}
\DoxyCodeLine{00318\ \ \ \ \ wtf-\/>infh\ =\ fh;}
\DoxyCodeLine{00319\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/spec2cep"{}}))\ \{}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ wtf-\/>in\_veclen\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nfilt"{}});}
\DoxyCodeLine{00321\ \ \ \ \ \}}
\DoxyCodeLine{00322\ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/cep2spec"{}}))\ \{}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ wtf-\/>in\_veclen\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/ncep"{}});}
\DoxyCodeLine{00324\ \ \ \ \ \ \ \ \ wtf-\/>veclen\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nfilt"{}});}
\DoxyCodeLine{00325\ \ \ \ \ \}}
\DoxyCodeLine{00326\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00327\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Should\ not\ happen.\ */}}
\DoxyCodeLine{00328\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Sphinx\ MFCC\ file\ reading\ requested\ but\ -\/spec2cep/-\/cep2spec\ not\ given\(\backslash\)n"{}});}
\DoxyCodeLine{00329\ \ \ \ \ \ \ \ \ assert(FALSE);}
\DoxyCodeLine{00330\ \ \ \ \ \}}
\DoxyCodeLine{00331\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00332\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00333\ \}}
\DoxyCodeLine{00334\ }
\DoxyCodeLine{00335\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00336\ mixnpick\_channels(int16\ *buf,\ int32\ nsamp,\ int32\ nchans,\ int32\ whichchan)}
\DoxyCodeLine{00337\ \{}
\DoxyCodeLine{00338\ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ j;}
\DoxyCodeLine{00339\ }
\DoxyCodeLine{00340\ \ \ \ \ \textcolor{keywordflow}{if}\ (whichchan\ >\ 0)\ \{}
\DoxyCodeLine{00341\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ whichchan\ -\/\ 1;\ i\ <\ nsamp;\ i\ +=\ nchans)}
\DoxyCodeLine{00342\ \ \ \ \ \ \ \ \ \ \ \ \ buf[i/nchans]\ =\ buf[i];}
\DoxyCodeLine{00343\ \ \ \ \ \}}
\DoxyCodeLine{00344\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00345\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nsamp;\ i\ +=\ nchans)\ \{}
\DoxyCodeLine{00346\ \ \ \ \ \ \ \ \ \ \ \ \ float64\ tmp\ =\ 0.0;}
\DoxyCodeLine{00347\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ nchans\ \&\&\ i\ +\ j\ <\ nsamp;\ ++j)\ \{}
\DoxyCodeLine{00348\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tmp\ +=\ buf[i\ +\ j];}
\DoxyCodeLine{00349\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00350\ \ \ \ \ \ \ \ \ \ \ \ \ buf[i/nchans]\ =\ (int16)(tmp\ /\ nchans);}
\DoxyCodeLine{00351\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00352\ \ \ \ \ \}}
\DoxyCodeLine{00353\ \ \ \ \ \textcolor{keywordflow}{return}\ i/nchans;}
\DoxyCodeLine{00354\ \}}
\DoxyCodeLine{00355\ }
\DoxyCodeLine{00356\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SNDFILE\_H}}
\DoxyCodeLine{00362\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00363\ detect\_sndfile(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00364\ \{}
\DoxyCodeLine{00365\ \ \ \ \ SNDFILE\ *sf;}
\DoxyCodeLine{00366\ \ \ \ \ SF\_INFO\ sfinfo;}
\DoxyCodeLine{00367\ }
\DoxyCodeLine{00368\ \ \ \ \ memset(\&sfinfo,\ 0,\ \textcolor{keyword}{sizeof}(sfinfo));}
\DoxyCodeLine{00369\ \ \ \ \ \textcolor{comment}{/*\ We\ let\ other\ detectors\ catch\ I/O\ errors,\ since\ there\ is}}
\DoxyCodeLine{00370\ \textcolor{comment}{\ \ \ \ \ \ \ no\ way\ to\ tell\ them\ from\ format\ errors\ when\ opening\ :(\ */}}
\DoxyCodeLine{00371\ \ \ \ \ \textcolor{keywordflow}{if}\ ((sf\ =\ sf\_open(wtf-\/>infile,\ SFM\_READ,\ \&sfinfo))\ ==\ NULL)\ \{}
\DoxyCodeLine{00372\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ FALSE;}
\DoxyCodeLine{00373\ \ \ \ \ \}}
\DoxyCodeLine{00374\ \ \ \ \ \textcolor{comment}{/*\ Get\ relevant\ information.\ */}}
\DoxyCodeLine{00375\ \ \ \ \ cmd\_ln\_set\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}},\ sfinfo.channels);}
\DoxyCodeLine{00376\ \ \ \ \ cmd\_ln\_set\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/samprate"{}},\ sfinfo.samplerate);}
\DoxyCodeLine{00377\ \ \ \ \ wtf-\/>insfh\ =\ sf;}
\DoxyCodeLine{00378\ \ \ \ \ wtf-\/>infh\ =\ NULL;}
\DoxyCodeLine{00379\ }
\DoxyCodeLine{00380\ \ \ \ \ \textcolor{keywordflow}{return}\ TRUE;}
\DoxyCodeLine{00381\ \}}
\DoxyCodeLine{00382\ }
\DoxyCodeLine{00387\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00388\ decode\_sndfile(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00389\ \{}
\DoxyCodeLine{00390\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ nsamp;}
\DoxyCodeLine{00391\ \ \ \ \ int32\ nfr,\ nchans,\ whichchan;}
\DoxyCodeLine{00392\ \ \ \ \ \textcolor{keywordtype}{int}\ nfloat,\ n;}
\DoxyCodeLine{00393\ }
\DoxyCodeLine{00394\ \ \ \ \ nchans\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}});}
\DoxyCodeLine{00395\ \ \ \ \ whichchan\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/whichchan"{}});}
\DoxyCodeLine{00396\ \ \ \ \ fe\_start\_utt(wtf-\/>fe);}
\DoxyCodeLine{00397\ \ \ \ \ nfloat\ =\ 0;}
\DoxyCodeLine{00398\ \ \ \ \ \textcolor{keywordflow}{while}\ ((nsamp\ =\ sf\_read\_short(wtf-\/>insfh,}
\DoxyCodeLine{00399\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>audio,}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>blocksize))\ !=\ 0)\ \{}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ int16\ \textcolor{keyword}{const}\ *inspeech;}
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ nvec;}
\DoxyCodeLine{00403\ }
\DoxyCodeLine{00404\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Mix\ or\ pick\ channels.\ */}}
\DoxyCodeLine{00405\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nchans\ >\ 1)}
\DoxyCodeLine{00406\ \ \ \ \ \ \ \ \ \ \ \ \ nsamp\ =\ mixnpick\_channels(wtf-\/>audio,\ nsamp,\ nchans,\ whichchan);}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ inspeech\ =\ wtf-\/>audio;}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ nvec\ =\ wtf-\/>featsize;}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Consume\ all\ samples.\ */}}
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (nsamp)\ \{}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ \ \ \ \ nfr\ =\ nvec;}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \ \ \ \ fe\_process\_frames(wtf-\/>fe,\ \&inspeech,\ \&nsamp,\ wtf-\/>feat,\ \&nfr);}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nfr)\ \{}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ =\ (*wtf-\/>ot-\/>output\_frames)(wtf,\ wtf-\/>feat,\ nfr))\ <\ 0)}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ nfloat\ +=\ n;}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00419\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ inspeech\ =\ wtf-\/>audio;}
\DoxyCodeLine{00421\ \ \ \ \ \}}
\DoxyCodeLine{00422\ \ \ \ \ \textcolor{comment}{/*\ Now\ process\ any\ leftover\ audio\ frames.\ */}}
\DoxyCodeLine{00423\ \ \ \ \ fe\_end\_utt(wtf-\/>fe,\ wtf-\/>feat[0],\ \&nfr);}
\DoxyCodeLine{00424\ \ \ \ \ \textcolor{keywordflow}{if}\ (nfr)\ \{}
\DoxyCodeLine{00425\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ =\ (*wtf-\/>ot-\/>output\_frames)(wtf,\ wtf-\/>feat,\ nfr))\ <\ 0)}
\DoxyCodeLine{00426\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ nfloat\ +=\ n;}
\DoxyCodeLine{00428\ \ \ \ \ \}}
\DoxyCodeLine{00429\ }
\DoxyCodeLine{00430\ \ \ \ \ sf\_close(wtf-\/>insfh);}
\DoxyCodeLine{00431\ \ \ \ \ wtf-\/>insfh\ =\ NULL;}
\DoxyCodeLine{00432\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00433\ \}}
\DoxyCodeLine{00434\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ HAVE\_SNDFILE\_H\ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00435\ }
\DoxyCodeLine{00440\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00441\ decode\_pcm(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00442\ \{}
\DoxyCodeLine{00443\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ nsamp;}
\DoxyCodeLine{00444\ \ \ \ \ int32\ nfr,\ nchans,\ whichchan;}
\DoxyCodeLine{00445\ \ \ \ \ \textcolor{keywordtype}{int}\ nfloat,\ n;}
\DoxyCodeLine{00446\ }
\DoxyCodeLine{00447\ \ \ \ \ nchans\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}});}
\DoxyCodeLine{00448\ \ \ \ \ whichchan\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/whichchan"{}});}
\DoxyCodeLine{00449\ \ \ \ \ fe\_start\_utt(wtf-\/>fe);}
\DoxyCodeLine{00450\ \ \ \ \ nfloat\ =\ 0;}
\DoxyCodeLine{00451\ \ \ \ \ \textcolor{keywordflow}{while}\ ((nsamp\ =\ fread(wtf-\/>audio,\ 2,\ wtf-\/>blocksize,\ wtf-\/>infh))\ !=\ 0)\ \{}
\DoxyCodeLine{00452\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ nvec;}
\DoxyCodeLine{00453\ \ \ \ \ \ \ \ \ int16\ \textcolor{keyword}{const}\ *inspeech;}
\DoxyCodeLine{00454\ }
\DoxyCodeLine{00455\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Byteswap\ stuff\ here\ if\ necessary.\ */}}
\DoxyCodeLine{00456\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>byteswap)\ \{}
\DoxyCodeLine{00457\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (n\ =\ 0;\ n\ <\ nsamp;\ ++n)}
\DoxyCodeLine{00458\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_INT16(wtf-\/>audio\ +\ n);}
\DoxyCodeLine{00459\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00460\ }
\DoxyCodeLine{00461\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Mix\ or\ pick\ channels.\ */}}
\DoxyCodeLine{00462\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nchans\ >\ 1)}
\DoxyCodeLine{00463\ \ \ \ \ \ \ \ \ \ \ \ \ nsamp\ =\ mixnpick\_channels(wtf-\/>audio,\ nsamp,\ nchans,\ whichchan);}
\DoxyCodeLine{00464\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00465\ \ \ \ \ \ \ \ \ inspeech\ =\ wtf-\/>audio;}
\DoxyCodeLine{00466\ \ \ \ \ \ \ \ \ nvec\ =\ wtf-\/>featsize;}
\DoxyCodeLine{00467\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Consume\ all\ samples.\ */}}
\DoxyCodeLine{00468\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (nsamp)\ \{}
\DoxyCodeLine{00469\ \ \ \ \ \ \ \ \ \ \ \ \ nfr\ =\ nvec;}
\DoxyCodeLine{00470\ \ \ \ \ \ \ \ \ \ \ \ \ fe\_process\_frames(wtf-\/>fe,\ \&inspeech,\ \&nsamp,\ wtf-\/>feat,\ \&nfr);}
\DoxyCodeLine{00471\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nfr)\ \{}
\DoxyCodeLine{00472\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ =\ (*wtf-\/>ot-\/>output\_frames)(wtf,\ wtf-\/>feat,\ nfr))\ <\ 0)}
\DoxyCodeLine{00473\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ nfloat\ +=\ n;}
\DoxyCodeLine{00475\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00476\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00477\ \ \ \ \ \ \ \ \ inspeech\ =\ wtf-\/>audio;}
\DoxyCodeLine{00478\ \ \ \ \ \}}
\DoxyCodeLine{00479\ \ \ \ \ \textcolor{comment}{/*\ Now\ process\ any\ leftover\ audio\ frames.\ */}}
\DoxyCodeLine{00480\ \ \ \ \ fe\_end\_utt(wtf-\/>fe,\ wtf-\/>feat[0],\ \&nfr);}
\DoxyCodeLine{00481\ \ \ \ \ \textcolor{keywordflow}{if}\ (nfr)\ \{}
\DoxyCodeLine{00482\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ =\ (*wtf-\/>ot-\/>output\_frames)(wtf,\ wtf-\/>feat,\ nfr))\ <\ 0)}
\DoxyCodeLine{00483\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00484\ \ \ \ \ \ \ \ \ nfloat\ +=\ n;}
\DoxyCodeLine{00485\ \ \ \ \ \}}
\DoxyCodeLine{00486\ }
\DoxyCodeLine{00487\ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>infh)\ ==\ EOF)}
\DoxyCodeLine{00488\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ input\ file"{}});}
\DoxyCodeLine{00489\ \ \ \ \ wtf-\/>infh\ =\ NULL;}
\DoxyCodeLine{00490\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00491\ \}}
\DoxyCodeLine{00492\ }
\DoxyCodeLine{00497\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00498\ decode\_sphinx\_mfc(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00499\ \{}
\DoxyCodeLine{00500\ \ \ \ \ \textcolor{keywordtype}{int}\ nfloat\ =\ 0,\ n;}
\DoxyCodeLine{00501\ \ \ \ \ \textcolor{keywordtype}{int}\ featsize\ =\ wtf-\/>featsize;}
\DoxyCodeLine{00502\ }
\DoxyCodeLine{00503\ \ \ \ \ \textcolor{comment}{/*\ If\ the\ input\ vector\ length\ is\ less\ than\ the\ output\ length,\ we}}
\DoxyCodeLine{00504\ \textcolor{comment}{\ \ \ \ \ *\ need\ to\ do\ this\ one\ frame\ at\ a\ time,\ because\ there's\ empty}}
\DoxyCodeLine{00505\ \textcolor{comment}{\ \ \ \ \ *\ space\ at\ the\ end\ of\ each\ vector\ in\ wtf-\/>feat.\ */}}
\DoxyCodeLine{00506\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>in\_veclen\ <\ wtf-\/>veclen)}
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ featsize\ =\ 1;}
\DoxyCodeLine{00508\ \ \ \ \ \textcolor{keywordflow}{while}\ ((n\ =\ fread(wtf-\/>feat[0],\ \textcolor{keyword}{sizeof}(**wtf-\/>feat),}
\DoxyCodeLine{00509\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ featsize\ *\ wtf-\/>in\_veclen,\ wtf-\/>infh))\ !=\ 0)\ \{}
\DoxyCodeLine{00510\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ nfr\ =\ n\ /\ wtf-\/>in\_veclen;}
\DoxyCodeLine{00511\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (n\ \%\ wtf-\/>in\_veclen)\ \{}
\DoxyCodeLine{00512\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Size\ of\ file\ \%d\ not\ a\ multiple\ of\ veclen\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00513\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ n,\ wtf-\/>in\_veclen);}
\DoxyCodeLine{00514\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00515\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00516\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Byteswap\ stuff\ here\ if\ necessary.\ */}}
\DoxyCodeLine{00517\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>byteswap)\ \{}
\DoxyCodeLine{00518\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ n;\ ++i)}
\DoxyCodeLine{00519\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_FLOAT32(wtf-\/>feat[0]\ +\ i);}
\DoxyCodeLine{00520\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00521\ \ \ \ \ \ \ \ \ fe\_float\_to\_mfcc(wtf-\/>fe,\ (float32\ **)wtf-\/>feat,\ wtf-\/>feat,\ nfr);}
\DoxyCodeLine{00522\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nfr;\ ++i)\ \{}
\DoxyCodeLine{00523\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/spec2cep"{}}))\ \{}
\DoxyCodeLine{00524\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/transform"{}}),\ \textcolor{stringliteral}{"{}legacy"{}}))}
\DoxyCodeLine{00525\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fe\_logspec\_to\_mfcc(wtf-\/>fe,\ wtf-\/>feat[i],\ wtf-\/>feat[i]);}
\DoxyCodeLine{00526\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00527\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fe\_logspec\_dct2(wtf-\/>fe,\ wtf-\/>feat[i],\ wtf-\/>feat[i]);}
\DoxyCodeLine{00528\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00529\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/cep2spec"{}}))\ \{}
\DoxyCodeLine{00530\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fe\_mfcc\_dct3(wtf-\/>fe,\ wtf-\/>feat[i],\ wtf-\/>feat[i]);}
\DoxyCodeLine{00531\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00532\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00533\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((n\ =\ (*wtf-\/>ot-\/>output\_frames)(wtf,\ wtf-\/>feat,\ nfr))\ <\ 0)}
\DoxyCodeLine{00534\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00535\ \ \ \ \ \ \ \ \ nfloat\ +=\ n;}
\DoxyCodeLine{00536\ \ \ \ \ \}}
\DoxyCodeLine{00537\ }
\DoxyCodeLine{00538\ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>infh)\ ==\ EOF)}
\DoxyCodeLine{00539\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ input\ file"{}});}
\DoxyCodeLine{00540\ \ \ \ \ wtf-\/>infh\ =\ NULL;}
\DoxyCodeLine{00541\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00542\ \}}
\DoxyCodeLine{00543\ }
\DoxyCodeLine{00544\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ audio\_type\_t\ types[]\ =\ \{}
\DoxyCodeLine{00545\ \textcolor{preprocessor}{\#ifdef\ HAVE\_SNDFILE\_H}}
\DoxyCodeLine{00546\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}-\/sndfile"{}},\ \&detect\_sndfile,\ \&decode\_sndfile\ \},}
\DoxyCodeLine{00547\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00548\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}-\/mswav"{}},\ \&detect\_riff,\ \&decode\_pcm\ \},}
\DoxyCodeLine{00549\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}-\/nist"{}},\ \&detect\_nist,\ \&decode\_pcm\ \},}
\DoxyCodeLine{00550\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}-\/raw"{}},\ \&detect\_raw,\ \&decode\_pcm\ \},}
\DoxyCodeLine{00551\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}-\/sph2pipe"{}},\ \&detect\_sph2pipe,\ \&decode\_pcm\ \}}
\DoxyCodeLine{00552\ \};}
\DoxyCodeLine{00553\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ ntypes\ =\ \textcolor{keyword}{sizeof}(types)/\textcolor{keyword}{sizeof}(types[0]);}
\DoxyCodeLine{00554\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ audio\_type\_t\ mfcc\_type\ =\ \{}
\DoxyCodeLine{00555\ \ \ \ \ \textcolor{stringliteral}{"{}sphinx\_mfc"{}},\ \&detect\_sphinx\_mfc,\ \&decode\_sphinx\_mfc}
\DoxyCodeLine{00556\ \};}
\DoxyCodeLine{00557\ }
\DoxyCodeLine{00563\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00564\ output\_header\_sphinx(sphinx\_wave2feat\_t\ *wtf,\ int32\ nfloat)}
\DoxyCodeLine{00565\ \{}
\DoxyCodeLine{00566\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&nfloat,\ 4,\ 1,\ wtf-\/>outfh)\ !=\ 1)\ \{}
\DoxyCodeLine{00567\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ write\ to\ \%s"{}},\ wtf-\/>outfile);}
\DoxyCodeLine{00568\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00569\ \ \ \ \ \}}
\DoxyCodeLine{00570\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00571\ \}}
\DoxyCodeLine{00572\ }
\DoxyCodeLine{00578\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00579\ output\_frames\_sphinx(sphinx\_wave2feat\_t\ *wtf,\ mfcc\_t\ **frames,\ \textcolor{keywordtype}{int}\ nfr)}
\DoxyCodeLine{00580\ \{}
\DoxyCodeLine{00581\ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ nfloat\ =\ 0;}
\DoxyCodeLine{00582\ }
\DoxyCodeLine{00583\ \ \ \ \ fe\_mfcc\_to\_float(wtf-\/>fe,\ frames,\ (float32\ **)frames,\ nfr);}
\DoxyCodeLine{00584\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nfr;\ ++i)\ \{}
\DoxyCodeLine{00585\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(frames[i],\ \textcolor{keyword}{sizeof}(float32),\ wtf-\/>veclen,\ wtf-\/>outfh)\ !=\ wtf-\/>veclen)\ \{}
\DoxyCodeLine{00586\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Writing\ \%d\ values\ to\ \%s\ failed"{}},}
\DoxyCodeLine{00587\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>veclen,\ wtf-\/>outfile);}
\DoxyCodeLine{00588\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00589\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00590\ \ \ \ \ \ \ \ \ nfloat\ +=\ wtf-\/>veclen;}
\DoxyCodeLine{00591\ \ \ \ \ \}}
\DoxyCodeLine{00592\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00593\ \}}
\DoxyCodeLine{00594\ }
\DoxyCodeLine{00595\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}\ htk\_feature\_kind\_e\ \{}
\DoxyCodeLine{00596\ \ \ \ \ WAVEFORM\ =\ 0,\ \ \ \textcolor{comment}{/*\ PCM\ audio\ (rarely\ used)\ */}}
\DoxyCodeLine{00597\ \ \ \ \ LPC\ =\ 1,\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ LPC\ filter\ coefficients\ */}}
\DoxyCodeLine{00598\ \ \ \ \ LPCREFC\ =\ 2,\ \ \ \ \textcolor{comment}{/*\ LPC\ reflection\ coefficients\ */}}
\DoxyCodeLine{00599\ \ \ \ \ LPCEPSTRA\ =\ 3,\ \ \textcolor{comment}{/*\ LPC-\/based\ cepstral\ coefficients\ */}}
\DoxyCodeLine{00600\ \ \ \ \ LPCDELCEP\ =\ 4,\ \ \textcolor{comment}{/*\ LPCC\ plus\ deltas\ */}}
\DoxyCodeLine{00601\ \ \ \ \ IREFC\ =\ 5,\ \ \ \ \ \ \textcolor{comment}{/*\ 16-\/bit\ integer\ LPC\ reflection\ coefficients\ */}}
\DoxyCodeLine{00602\ \ \ \ \ MFCC\ =\ 6,\ \ \ \ \ \ \ \textcolor{comment}{/*\ MFCCs\ */}}
\DoxyCodeLine{00603\ \ \ \ \ FBANK\ =\ 7,\ \ \ \ \ \ \textcolor{comment}{/*\ Log\ mel\ spectrum\ */}}
\DoxyCodeLine{00604\ \ \ \ \ MELSPEC\ =\ 8,\ \ \ \ \textcolor{comment}{/*\ Linear\ mel\ spectrum\ */}}
\DoxyCodeLine{00605\ \ \ \ \ USER\ =\ 9,\ \ \ \ \ \ \ \textcolor{comment}{/*\ User\ defined\ */}}
\DoxyCodeLine{00606\ \ \ \ \ DISCRETE\ =\ 10,\ \ \textcolor{comment}{/*\ Vector\ quantized\ data\ */}}
\DoxyCodeLine{00607\ \ \ \ \ PLP\ =\ 11\ \ \ \ \ \ \ \ \textcolor{comment}{/*\ PLP\ coefficients\ */}}
\DoxyCodeLine{00608\ \}\ htk\_feature\_kind\_t;}
\DoxyCodeLine{00609\ }
\DoxyCodeLine{00610\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}\ htk\_feature\_flag\_e\ \{}
\DoxyCodeLine{00611\ \ \ \ \ \_E\ =\ 0000100,\ \textcolor{comment}{/*\ has\ energy\ */}}
\DoxyCodeLine{00612\ \ \ \ \ \_N\ =\ 0000200,\ \textcolor{comment}{/*\ absolute\ energy\ supressed\ */}}
\DoxyCodeLine{00613\ \ \ \ \ \_D\ =\ 0000400,\ \textcolor{comment}{/*\ has\ delta\ coefficients\ */}}
\DoxyCodeLine{00614\ \ \ \ \ \_A\ =\ 0001000,\ \textcolor{comment}{/*\ has\ acceleration\ (delta-\/delta)\ coefficients\ */}}
\DoxyCodeLine{00615\ \ \ \ \ \_C\ =\ 0002000,\ \textcolor{comment}{/*\ is\ compressed\ */}}
\DoxyCodeLine{00616\ \ \ \ \ \_Z\ =\ 0004000,\ \textcolor{comment}{/*\ has\ zero\ mean\ static\ coefficients\ (i.e.\ CMN)\ */}}
\DoxyCodeLine{00617\ \ \ \ \ \_K\ =\ 0010000,\ \textcolor{comment}{/*\ has\ CRC\ checksum\ */}}
\DoxyCodeLine{00618\ \ \ \ \ \_O\ =\ 0020000,\ \textcolor{comment}{/*\ has\ 0th\ cepstral\ coefficient\ */}}
\DoxyCodeLine{00619\ \ \ \ \ \_V\ =\ 0040000,\ \textcolor{comment}{/*\ has\ VQ\ data\ */}}
\DoxyCodeLine{00620\ \ \ \ \ \_T\ =\ 0100000\ \ \textcolor{comment}{/*\ has\ third\ differential\ coefficients\ */}}
\DoxyCodeLine{00621\ \}\ htk\_feature\_flag\_t;}
\DoxyCodeLine{00622\ }
\DoxyCodeLine{00626\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00627\ output\_header\_htk(sphinx\_wave2feat\_t\ *wtf,\ int32\ nfloat)}
\DoxyCodeLine{00628\ \{}
\DoxyCodeLine{00629\ \ \ \ \ int32\ samp\_period;}
\DoxyCodeLine{00630\ \ \ \ \ int16\ samp\_size;}
\DoxyCodeLine{00631\ \ \ \ \ int16\ param\_kind;}
\DoxyCodeLine{00632\ \ \ \ \ \textcolor{keywordtype}{int}\ swap\ =\ FALSE;}
\DoxyCodeLine{00633\ }
\DoxyCodeLine{00634\ \ \ \ \ \textcolor{comment}{/*\ HTK\ files\ are\ big-\/endian.\ */}}
\DoxyCodeLine{00635\ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(\textcolor{stringliteral}{"{}little"{}},\ cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/mach\_endian"{}})))}
\DoxyCodeLine{00636\ \ \ \ \ \ \ \ \ swap\ =\ TRUE;}
\DoxyCodeLine{00637\ \ \ \ \ \textcolor{comment}{/*\ Same\ file\ size\ thing\ as\ in\ Sphinx\ files\ (I\ think)\ */}}
\DoxyCodeLine{00638\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)\ SWAP\_INT32(\&nfloat);}
\DoxyCodeLine{00639\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&nfloat,\ 4,\ 1,\ wtf-\/>outfh)\ !=\ 1)}
\DoxyCodeLine{00640\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00641\ \ \ \ \ \textcolor{comment}{/*\ Sample\ period\ in\ 100ns\ units.\ */}}
\DoxyCodeLine{00642\ \ \ \ \ samp\_period\ =\ (int32)(1e+7\ /\ cmd\_ln\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/frate"{}}));}
\DoxyCodeLine{00643\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)\ SWAP\_INT32(\&samp\_period);}
\DoxyCodeLine{00644\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&samp\_period,\ 4,\ 1,\ wtf-\/>outfh)\ !=\ 1)}
\DoxyCodeLine{00645\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00646\ \ \ \ \ \textcolor{comment}{/*\ Sample\ size\ -\/\ veclen\ *\ sizeof\ each\ sample.\ */}}
\DoxyCodeLine{00647\ \ \ \ \ samp\_size\ =\ wtf-\/>veclen\ *\ 4;}
\DoxyCodeLine{00648\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)\ SWAP\_INT16(\&samp\_size);}
\DoxyCodeLine{00649\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&samp\_size,\ 2,\ 1,\ wtf-\/>outfh)\ !=\ 1)}
\DoxyCodeLine{00650\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00651\ \ \ \ \ \textcolor{comment}{/*\ Format\ and\ flags.\ */}}
\DoxyCodeLine{00652\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/logspec"{}})}
\DoxyCodeLine{00653\ \ \ \ \ \ \ \ \ ||\ cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/cep2spec"{}}))}
\DoxyCodeLine{00654\ \ \ \ \ \ \ \ \ param\_kind\ =\ FBANK;\ \textcolor{comment}{/*\ log\ mel-\/filter\ bank\ outputs\ */}}
\DoxyCodeLine{00655\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00656\ \ \ \ \ \ \ \ \ param\_kind\ =\ MFCC\ |\ \_O;\ \textcolor{comment}{/*\ MFCC\ +\ CEP0\ (note\ reordering...)\ */}}
\DoxyCodeLine{00657\ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)\ SWAP\_INT16(\&param\_kind);}
\DoxyCodeLine{00658\ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(\&param\_kind,\ 2,\ 1,\ wtf-\/>outfh)\ !=\ 1)}
\DoxyCodeLine{00659\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00660\ }
\DoxyCodeLine{00661\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00662\ \}}
\DoxyCodeLine{00663\ }
\DoxyCodeLine{00667\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00668\ output\_frames\_htk(sphinx\_wave2feat\_t\ *wtf,\ mfcc\_t\ **frames,\ \textcolor{keywordtype}{int}\ nfr)}
\DoxyCodeLine{00669\ \{}
\DoxyCodeLine{00670\ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ j,\ swap,\ htk\_reorder,\ nfloat\ =\ 0;}
\DoxyCodeLine{00671\ }
\DoxyCodeLine{00672\ \ \ \ \ fe\_mfcc\_to\_float(wtf-\/>fe,\ frames,\ (float32\ **)frames,\ nfr);}
\DoxyCodeLine{00673\ \ \ \ \ \textcolor{comment}{/*\ This\ is\ possibly\ inefficient,\ but\ probably\ not\ a\ big\ deal.\ */}}
\DoxyCodeLine{00674\ \ \ \ \ swap\ =\ (0\ ==\ strcmp(\textcolor{stringliteral}{"{}little"{}},\ cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/mach\_endian"{}})));}
\DoxyCodeLine{00675\ \ \ \ \ htk\_reorder\ =\ (0\ ==\ strcmp(\textcolor{stringliteral}{"{}htk"{}},\ wtf-\/>ot-\/>name)}
\DoxyCodeLine{00676\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \&\&\ !(cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/logspec"{}})}
\DoxyCodeLine{00677\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ||\ cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/cep2spec"{}})));}
\DoxyCodeLine{00678\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nfr;\ ++i)\ \{}
\DoxyCodeLine{00679\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (htk\_reorder)\ \{}
\DoxyCodeLine{00680\ \ \ \ \ \ \ \ \ \ \ \ \ mfcc\_t\ c0\ =\ frames[i][0];}
\DoxyCodeLine{00681\ \ \ \ \ \ \ \ \ \ \ \ \ memmove(frames[i]\ +\ 1,\ frames[i],\ (wtf-\/>veclen\ -\/\ 1)\ *\ 4);}
\DoxyCodeLine{00682\ \ \ \ \ \ \ \ \ \ \ \ \ frames[i][wtf-\/>veclen\ -\/\ 1]\ =\ c0;}
\DoxyCodeLine{00683\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00684\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (swap)}
\DoxyCodeLine{00685\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ wtf-\/>veclen;\ ++j)}
\DoxyCodeLine{00686\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ SWAP\_FLOAT32(frames[i]\ +\ j);}
\DoxyCodeLine{00687\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fwrite(frames[i],\ \textcolor{keyword}{sizeof}(float32),\ wtf-\/>veclen,\ wtf-\/>outfh)\ !=\ wtf-\/>veclen)\ \{}
\DoxyCodeLine{00688\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Writing\ \%d\ values\ to\ \%s\ failed"{}},}
\DoxyCodeLine{00689\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>veclen,\ wtf-\/>outfile);}
\DoxyCodeLine{00690\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00691\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00692\ \ \ \ \ \ \ \ \ nfloat\ +=\ wtf-\/>veclen;}
\DoxyCodeLine{00693\ \ \ \ \ \}}
\DoxyCodeLine{00694\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00695\ \}}
\DoxyCodeLine{00696\ }
\DoxyCodeLine{00700\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00701\ output\_frames\_text(sphinx\_wave2feat\_t\ *wtf,\ mfcc\_t\ **frames,\ \textcolor{keywordtype}{int}\ nfr)}
\DoxyCodeLine{00702\ \{}
\DoxyCodeLine{00703\ \ \ \ \ \textcolor{keywordtype}{int}\ i,\ j,\ nfloat\ =\ 0;}
\DoxyCodeLine{00704\ }
\DoxyCodeLine{00705\ \ \ \ \ fe\_mfcc\_to\_float(wtf-\/>fe,\ frames,\ (float32\ **)frames,\ nfr);}
\DoxyCodeLine{00706\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nfr;\ ++i)\ \{}
\DoxyCodeLine{00707\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (j\ =\ 0;\ j\ <\ wtf-\/>veclen;\ ++j)\ \{}
\DoxyCodeLine{00708\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(wtf-\/>outfh,\ \textcolor{stringliteral}{"{}\%.5g"{}},\ frames[i][j]);}
\DoxyCodeLine{00709\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (j\ ==\ wtf-\/>veclen\ -\/\ 1)}
\DoxyCodeLine{00710\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(wtf-\/>outfh,\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{00711\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00712\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(wtf-\/>outfh,\ \textcolor{stringliteral}{"{}\ "{}});}
\DoxyCodeLine{00713\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00714\ \ \ \ \ \ \ \ \ nfloat\ +=\ wtf-\/>veclen;}
\DoxyCodeLine{00715\ \ \ \ \ \}}
\DoxyCodeLine{00716\ \ \ \ \ \textcolor{keywordflow}{return}\ nfloat;}
\DoxyCodeLine{00717\ \}}
\DoxyCodeLine{00718\ }
\DoxyCodeLine{00719\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ output\_type\_t\ outtypes[]\ =\ \{}
\DoxyCodeLine{00720\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}sphinx"{}},\ \&output\_header\_sphinx,\ \&output\_frames\_sphinx\ \},}
\DoxyCodeLine{00721\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}htk"{}},\ \&output\_header\_htk,\ \&output\_frames\_htk\ \},}
\DoxyCodeLine{00722\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}text"{}},\ NULL,\ \&output\_frames\_text\ \}}
\DoxyCodeLine{00723\ \};}
\DoxyCodeLine{00724\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ nouttypes\ =\ \textcolor{keyword}{sizeof}(outtypes)/\textcolor{keyword}{sizeof}(outtypes[0]);}
\DoxyCodeLine{00725\ }
\DoxyCodeLine{00726\ sphinx\_wave2feat\_t\ *}
\DoxyCodeLine{00727\ sphinx\_wave2feat\_init(cmd\_ln\_t\ *config)}
\DoxyCodeLine{00728\ \{}
\DoxyCodeLine{00729\ \ \ \ \ sphinx\_wave2feat\_t\ *wtf;}
\DoxyCodeLine{00730\ \ \ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{00731\ }
\DoxyCodeLine{00732\ \ \ \ \ wtf\ =\ ckd\_calloc(1,\ \textcolor{keyword}{sizeof}(*wtf));}
\DoxyCodeLine{00733\ \ \ \ \ wtf-\/>refcount\ =\ 1;}
\DoxyCodeLine{00734\ \ \ \ \ wtf-\/>config\ =\ cmd\_ln\_retain(config);}
\DoxyCodeLine{00735\ \ \ \ \ wtf-\/>fe\ =\ fe\_init\_auto\_r(wtf-\/>config);}
\DoxyCodeLine{00736\ \ \ \ \ wtf-\/>ot\ =\ outtypes;\ \textcolor{comment}{/*\ Default\ (sphinx)\ type.\ */}}
\DoxyCodeLine{00737\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ nouttypes;\ ++i)\ \{}
\DoxyCodeLine{00738\ \ \ \ \ \ \ \ \ output\_type\_t\ \textcolor{keyword}{const}\ *otype\ =\ \&outtypes[i];}
\DoxyCodeLine{00739\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (0\ ==\ strcmp(cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ofmt"{}}),\ otype-\/>name))\ \{}
\DoxyCodeLine{00740\ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>ot\ =\ otype;}
\DoxyCodeLine{00741\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00742\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00743\ \ \ \ \ \}}
\DoxyCodeLine{00744\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ nouttypes)\ \{}
\DoxyCodeLine{00745\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Unknown\ output\ type:\ '\%s'\(\backslash\)n"{}},}
\DoxyCodeLine{00746\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ofmt"{}}));}
\DoxyCodeLine{00747\ \ \ \ \ \ \ \ \ sphinx\_wave2feat\_free(wtf);}
\DoxyCodeLine{00748\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00749\ \ \ \ \ \}}
\DoxyCodeLine{00750\ }
\DoxyCodeLine{00751\ \ \ \ \ \textcolor{keywordflow}{return}\ wtf;}
\DoxyCodeLine{00752\ \}}
\DoxyCodeLine{00753\ }
\DoxyCodeLine{00754\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00755\ sphinx\_wave2feat\_free(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00756\ \{}
\DoxyCodeLine{00757\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf\ ==\ NULL)}
\DoxyCodeLine{00758\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00759\ \ \ \ \ \textcolor{keywordflow}{if}\ (-\/-\/wtf-\/>refcount\ >\ 0)}
\DoxyCodeLine{00760\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ wtf-\/>refcount;}
\DoxyCodeLine{00761\ }
\DoxyCodeLine{00762\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>audio)}
\DoxyCodeLine{00763\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>audio);}
\DoxyCodeLine{00764\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>feat)}
\DoxyCodeLine{00765\ \ \ \ \ \ \ \ \ ckd\_free\_2d(wtf-\/>feat);}
\DoxyCodeLine{00766\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>infile)}
\DoxyCodeLine{00767\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>infile);}
\DoxyCodeLine{00768\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfile)}
\DoxyCodeLine{00769\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>outfile);}
\DoxyCodeLine{00770\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>infh)\ \{}
\DoxyCodeLine{00771\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>infh)\ ==\ EOF)}
\DoxyCodeLine{00772\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ input\ file"{}});}
\DoxyCodeLine{00773\ \ \ \ \ \}}
\DoxyCodeLine{00774\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfh)\ \{}
\DoxyCodeLine{00775\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>outfh)\ ==\ EOF)}
\DoxyCodeLine{00776\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ output\ file"{}});}
\DoxyCodeLine{00777\ \ \ \ \ \}}
\DoxyCodeLine{00778\ \ \ \ \ cmd\_ln\_free\_r(wtf-\/>config);}
\DoxyCodeLine{00779\ \ \ \ \ fe\_free(wtf-\/>fe);}
\DoxyCodeLine{00780\ \ \ \ \ ckd\_free(wtf);}
\DoxyCodeLine{00781\ }
\DoxyCodeLine{00782\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00783\ \}}
\DoxyCodeLine{00784\ }
\DoxyCodeLine{00785\ sphinx\_wave2feat\_t\ *}
\DoxyCodeLine{00786\ sphinx\_wave2feat\_retain(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00787\ \{}
\DoxyCodeLine{00788\ \ \ \ \ ++wtf-\/>refcount;}
\DoxyCodeLine{00789\ \ \ \ \ \textcolor{keywordflow}{return}\ wtf;}
\DoxyCodeLine{00790\ \}}
\DoxyCodeLine{00791\ }
\DoxyCodeLine{00792\ \textcolor{keyword}{static}\ audio\_type\_t\ \textcolor{keyword}{const}\ *}
\DoxyCodeLine{00793\ detect\_audio\_type(sphinx\_wave2feat\_t\ *wtf)}
\DoxyCodeLine{00794\ \{}
\DoxyCodeLine{00795\ \ \ \ \ audio\_type\_t\ \textcolor{keyword}{const}\ *atype;}
\DoxyCodeLine{00796\ \ \ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{00797\ }
\DoxyCodeLine{00798\ \ \ \ \ \textcolor{comment}{/*\ Special\ case\ audio\ type\ for\ Sphinx\ MFCC\ inputs.\ */}}
\DoxyCodeLine{00799\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/spec2cep"{}})}
\DoxyCodeLine{00800\ \ \ \ \ \ \ \ \ ||\ cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/cep2spec"{}}))\ \{}
\DoxyCodeLine{00801\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ rv\ =\ mfcc\_type.detect(wtf);}
\DoxyCodeLine{00802\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ ==\ -\/1)}
\DoxyCodeLine{00803\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00804\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \&mfcc\_type;}
\DoxyCodeLine{00805\ \ \ \ \ \}}
\DoxyCodeLine{00806\ }
\DoxyCodeLine{00807\ \ \ \ \ \textcolor{comment}{/*\ Try\ to\ use\ the\ type\ of\ infile\ given\ on\ the\ command\ line.\ */}}
\DoxyCodeLine{00808\ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ ntypes;\ ++i)\ \{}
\DoxyCodeLine{00809\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00810\ \ \ \ \ \ \ \ \ atype\ =\ \&types[i];}
\DoxyCodeLine{00811\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ atype-\/>name))\ \{}
\DoxyCodeLine{00812\ \ \ \ \ \ \ \ \ \ \ \ \ rv\ =\ (*atype-\/>detect)(wtf);}
\DoxyCodeLine{00813\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ ==\ -\/1)}
\DoxyCodeLine{00814\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00815\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (rv\ ==\ TRUE)}
\DoxyCodeLine{00816\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00817\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00818\ \ \ \ \ \}}
\DoxyCodeLine{00819\ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ ntypes)\ \{}
\DoxyCodeLine{00820\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Detect\ file\ type\ of\ infile\ and\ get\ parameters.\ */}}
\DoxyCodeLine{00821\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ ntypes;\ ++i)\ \{}
\DoxyCodeLine{00822\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{00823\ \ \ \ \ \ \ \ \ \ \ \ \ atype\ =\ \&types[i];}
\DoxyCodeLine{00824\ \ \ \ \ \ \ \ \ \ \ \ \ rv\ =\ (*atype-\/>detect)(wtf);}
\DoxyCodeLine{00825\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ ==\ -\/1)}
\DoxyCodeLine{00826\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00827\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (rv\ ==\ TRUE)}
\DoxyCodeLine{00828\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00829\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00830\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ ntypes)}
\DoxyCodeLine{00831\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00832\ \ \ \ \ \}}
\DoxyCodeLine{00833\ \ \ \ \ \textcolor{keywordflow}{return}\ atype;}
\DoxyCodeLine{00834\ \ error\_out:}
\DoxyCodeLine{00835\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>infh)}
\DoxyCodeLine{00836\ \ \ \ \ \ \ \ \ fclose(wtf-\/>infh);}
\DoxyCodeLine{00837\ \ \ \ \ wtf-\/>infh\ =\ NULL;}
\DoxyCodeLine{00838\ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{00839\ \}}
\DoxyCodeLine{00840\ }
\DoxyCodeLine{00841\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00842\ sphinx\_wave2feat\_convert\_file(sphinx\_wave2feat\_t\ *wtf,}
\DoxyCodeLine{00843\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *infile,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *outfile)}
\DoxyCodeLine{00844\ \{}
\DoxyCodeLine{00845\ \ \ \ \ \textcolor{keywordtype}{int}\ nchans,\ minfft,\ nfft,\ nfloat,\ veclen;}
\DoxyCodeLine{00846\ \ \ \ \ audio\_type\_t\ \textcolor{keyword}{const}\ *atype;}
\DoxyCodeLine{00847\ \ \ \ \ \textcolor{keywordtype}{int}\ fshift,\ fsize;}
\DoxyCodeLine{00848\ }
\DoxyCodeLine{00849\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/verbose"{}}))}
\DoxyCodeLine{00850\ \ \ \ \ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}Converting\ \%s\ to\ \%s\(\backslash\)n"{}},\ infile,\ outfile);}
\DoxyCodeLine{00851\ }
\DoxyCodeLine{00852\ \ \ \ \ wtf-\/>infile\ =\ ckd\_salloc(infile);}
\DoxyCodeLine{00853\ }
\DoxyCodeLine{00854\ \ \ \ \ \textcolor{comment}{/*\ Detect\ input\ file\ type.\ */}}
\DoxyCodeLine{00855\ \ \ \ \ \textcolor{keywordflow}{if}\ ((atype\ =\ detect\_audio\_type(wtf))\ ==\ NULL)}
\DoxyCodeLine{00856\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00857\ }
\DoxyCodeLine{00858\ \ \ \ \ \textcolor{comment}{/*\ Determine\ whether\ to\ byteswap\ input.\ */}}
\DoxyCodeLine{00859\ \ \ \ \ wtf-\/>byteswap\ =\ strcmp(cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/mach\_endian"{}}),}
\DoxyCodeLine{00860\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/input\_endian"{}}));}
\DoxyCodeLine{00861\ }
\DoxyCodeLine{00862\ \ \ \ \ \textcolor{comment}{/*\ Make\ sure\ the\ FFT\ size\ is\ sufficiently\ large.\ */}}
\DoxyCodeLine{00863\ \ \ \ \ minfft\ =\ (int)(cmd\_ln\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/samprate"{}})}
\DoxyCodeLine{00864\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ *\ cmd\_ln\_float32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/wlen"{}})\ +\ 0.5);}
\DoxyCodeLine{00865\ \ \ \ \ \textcolor{keywordflow}{for}\ (nfft\ =\ 1;\ nfft\ <\ minfft;\ nfft\ <<=\ 1)}
\DoxyCodeLine{00866\ \ \ \ \ \ \ \ \ ;}
\DoxyCodeLine{00867\ \ \ \ \ \textcolor{keywordflow}{if}\ (nfft\ >\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nfft"{}}))\ \{}
\DoxyCodeLine{00868\ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Value\ of\ -\/nfft\ =\ \%d\ is\ too\ small,\ increasing\ to\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00869\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nfft"{}}),\ nfft);}
\DoxyCodeLine{00870\ \ \ \ \ \ \ \ \ cmd\_ln\_set\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nfft"{}},\ nfft);}
\DoxyCodeLine{00871\ \ \ \ \ \ \ \ \ fe\_free(wtf-\/>fe);}
\DoxyCodeLine{00872\ \ \ \ \ \ \ \ \ wtf-\/>fe\ =\ fe\_init\_auto\_r(wtf-\/>config);}
\DoxyCodeLine{00873\ \ \ \ \ \}}
\DoxyCodeLine{00874\ }
\DoxyCodeLine{00875\ \ \ \ \ \textcolor{comment}{/*\ Get\ the\ output\ frame\ size\ (if\ not\ already\ set).\ */}}
\DoxyCodeLine{00876\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>veclen\ ==\ 0)}
\DoxyCodeLine{00877\ \ \ \ \ \ \ \ \ wtf-\/>veclen\ =\ fe\_get\_output\_size(wtf-\/>fe);}
\DoxyCodeLine{00878\ }
\DoxyCodeLine{00879\ \ \ \ \ \textcolor{comment}{/*\ Set\ up\ the\ input\ and\ output\ buffers.\ */}}
\DoxyCodeLine{00880\ \ \ \ \ fe\_get\_input\_size(wtf-\/>fe,\ \&fshift,\ \&fsize);}
\DoxyCodeLine{00881\ \ \ \ \ \textcolor{comment}{/*\ Want\ to\ get\ at\ least\ a\ whole\ frame\ plus\ shift\ in\ here.\ \ Also\ we}}
\DoxyCodeLine{00882\ \textcolor{comment}{\ \ \ \ \ \ \ will\ either\ pick\ or\ mix\ multiple\ channels\ so\ we\ need\ to\ read}}
\DoxyCodeLine{00883\ \textcolor{comment}{\ \ \ \ \ \ \ them\ all\ at\ once.\ */}}
\DoxyCodeLine{00884\ \ \ \ \ nchans\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nchans"{}});}
\DoxyCodeLine{00885\ \ \ \ \ wtf-\/>blocksize\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/blocksize"{}})\ *\ nchans;}
\DoxyCodeLine{00886\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>blocksize\ <\ (fsize\ +\ fshift)\ *\ nchans)\ \{}
\DoxyCodeLine{00887\ \ \ \ \ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}Block\ size\ of\ \%d\ too\ small,\ increasing\ to\ \%d\(\backslash\)n"{}},}
\DoxyCodeLine{00888\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ wtf-\/>blocksize,}
\DoxyCodeLine{00889\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (fsize\ +\ fshift)\ *\ nchans);}
\DoxyCodeLine{00890\ \ \ \ \ \ \ \ \ wtf-\/>blocksize\ =\ (fsize\ +\ fshift)\ *\ nchans;}
\DoxyCodeLine{00891\ \ \ \ \ \}}
\DoxyCodeLine{00892\ \ \ \ \ wtf-\/>audio\ =\ ckd\_calloc(wtf-\/>blocksize,\ \textcolor{keyword}{sizeof}(*wtf-\/>audio));}
\DoxyCodeLine{00893\ \ \ \ \ wtf-\/>featsize\ =\ (wtf-\/>blocksize\ /\ nchans\ -\/\ fsize)\ /\ fshift;}
\DoxyCodeLine{00894\ }
\DoxyCodeLine{00895\ \ \ \ \ \textcolor{comment}{/*\ Use\ the\ maximum\ of\ the\ input\ and\ output\ frame\ sizes\ to\ allocate\ this.\ */}}
\DoxyCodeLine{00896\ \ \ \ \ veclen\ =\ wtf-\/>veclen;}
\DoxyCodeLine{00897\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>in\_veclen\ >\ veclen)\ veclen\ =\ wtf-\/>in\_veclen;}
\DoxyCodeLine{00898\ \ \ \ \ }
\DoxyCodeLine{00899\ \ \ \ \ wtf-\/>feat\ =\ ckd\_calloc\_2d(wtf-\/>featsize,\ veclen,\ \textcolor{keyword}{sizeof}(**wtf-\/>feat));}
\DoxyCodeLine{00900\ }
\DoxyCodeLine{00901\ \ \ \ \ \textcolor{comment}{/*\ Let's\ go!\ */}}
\DoxyCodeLine{00902\ \ \ \ \ \textcolor{keywordflow}{if}\ ((wtf-\/>outfh\ =\ fopen(outfile,\ \textcolor{stringliteral}{"{}wb"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{00903\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ \%s\ for\ writing"{}},\ outfile);}
\DoxyCodeLine{00904\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00905\ \ \ \ \ \}}
\DoxyCodeLine{00906\ \ \ \ \ \textcolor{comment}{/*\ Write\ an\ empty\ header,\ which\ we'll\ fill\ in\ later.\ */}}
\DoxyCodeLine{00907\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>ot-\/>output\_header\ \&\&}
\DoxyCodeLine{00908\ \ \ \ \ \ \ \ \ (*wtf-\/>ot-\/>output\_header)(wtf,\ 0)\ <\ 0)\ \{}
\DoxyCodeLine{00909\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ write\ empty\ header\ to\ \%s\(\backslash\)n"{}},\ outfile);}
\DoxyCodeLine{00910\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00911\ \ \ \ \ \}}
\DoxyCodeLine{00912\ \ \ \ \ wtf-\/>outfile\ =\ ckd\_salloc(outfile);}
\DoxyCodeLine{00913\ }
\DoxyCodeLine{00914\ \ \ \ \ \textcolor{keywordflow}{if}\ ((nfloat\ =\ (*atype-\/>decode)(wtf))\ <\ 0)\ \{}
\DoxyCodeLine{00915\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Failed\ to\ convert"{}});}
\DoxyCodeLine{00916\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00917\ \ \ \ \ \}}
\DoxyCodeLine{00918\ }
\DoxyCodeLine{00919\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>ot-\/>output\_header)\ \{}
\DoxyCodeLine{00920\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fseek(wtf-\/>outfh,\ 0,\ SEEK\_SET)\ <\ 0)\ \{}
\DoxyCodeLine{00921\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ seek\ to\ beginning\ of\ \%s\(\backslash\)n"{}},\ outfile);}
\DoxyCodeLine{00922\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00923\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00924\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((*wtf-\/>ot-\/>output\_header)(wtf,\ nfloat)\ <\ 0)\ \{}
\DoxyCodeLine{00925\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ write\ header\ to\ \%s\(\backslash\)n"{}},\ outfile);}
\DoxyCodeLine{00926\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ error\_out;}
\DoxyCodeLine{00927\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00928\ \ \ \ \ \}}
\DoxyCodeLine{00929\ \ \ \ \ }
\DoxyCodeLine{00930\ }
\DoxyCodeLine{00931\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>audio)}
\DoxyCodeLine{00932\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>audio);}
\DoxyCodeLine{00933\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>feat)}
\DoxyCodeLine{00934\ \ \ \ \ \ \ \ \ ckd\_free\_2d(wtf-\/>feat);}
\DoxyCodeLine{00935\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>infile)}
\DoxyCodeLine{00936\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>infile);}
\DoxyCodeLine{00937\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfile)}
\DoxyCodeLine{00938\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>outfile);}
\DoxyCodeLine{00939\ }
\DoxyCodeLine{00940\ \ \ \ \ wtf-\/>audio\ =\ NULL;}
\DoxyCodeLine{00941\ \ \ \ \ wtf-\/>infile\ =\ NULL;}
\DoxyCodeLine{00942\ \ \ \ \ wtf-\/>feat\ =\ NULL;}
\DoxyCodeLine{00943\ \ \ \ \ wtf-\/>outfile\ =\ NULL;}
\DoxyCodeLine{00944\ }
\DoxyCodeLine{00945\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfh)}
\DoxyCodeLine{00946\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>outfh)\ ==\ EOF)}
\DoxyCodeLine{00947\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ output\ file"{}});}
\DoxyCodeLine{00948\ \ \ \ \ wtf-\/>outfh\ =\ NULL;}
\DoxyCodeLine{00949\ }
\DoxyCodeLine{00950\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00951\ }
\DoxyCodeLine{00952\ error\_out:}
\DoxyCodeLine{00953\ }
\DoxyCodeLine{00954\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>audio)}
\DoxyCodeLine{00955\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>audio);}
\DoxyCodeLine{00956\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>feat)}
\DoxyCodeLine{00957\ \ \ \ \ \ \ \ \ ckd\_free\_2d(wtf-\/>feat);}
\DoxyCodeLine{00958\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>infile)}
\DoxyCodeLine{00959\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>infile);}
\DoxyCodeLine{00960\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfile)}
\DoxyCodeLine{00961\ \ \ \ \ \ \ \ \ ckd\_free(wtf-\/>outfile);}
\DoxyCodeLine{00962\ }
\DoxyCodeLine{00963\ \ \ \ \ wtf-\/>audio\ =\ NULL;}
\DoxyCodeLine{00964\ \ \ \ \ wtf-\/>infile\ =\ NULL;}
\DoxyCodeLine{00965\ \ \ \ \ wtf-\/>feat\ =\ NULL;}
\DoxyCodeLine{00966\ \ \ \ \ wtf-\/>outfile\ =\ NULL;}
\DoxyCodeLine{00967\ }
\DoxyCodeLine{00968\ \ \ \ \ \textcolor{keywordflow}{if}\ (wtf-\/>outfh)}
\DoxyCodeLine{00969\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(wtf-\/>outfh)\ ==\ EOF)}
\DoxyCodeLine{00970\ \ \ \ \ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ output\ file"{}});}
\DoxyCodeLine{00971\ \ \ \ \ wtf-\/>outfh\ =\ NULL;}
\DoxyCodeLine{00972\ }
\DoxyCodeLine{00973\ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{00974\ \}}
\DoxyCodeLine{00975\ }
\DoxyCodeLine{00976\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{00977\ build\_filenames(cmd\_ln\_t\ *config,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *basename,}
\DoxyCodeLine{00978\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ **out\_infile,\ \textcolor{keywordtype}{char}\ **out\_outfile)}
\DoxyCodeLine{00979\ \{}
\DoxyCodeLine{00980\ \ \ \ \ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *di,\ *do\_,\ *ei,\ *eo;}
\DoxyCodeLine{00981\ }
\DoxyCodeLine{00982\ \ \ \ \ di\ =\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/di"{}});}
\DoxyCodeLine{00983\ \ \ \ \ do\_\ =\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/do"{}});}
\DoxyCodeLine{00984\ \ \ \ \ ei\ =\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/ei"{}});}
\DoxyCodeLine{00985\ \ \ \ \ eo\ =\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/eo"{}});}
\DoxyCodeLine{00986\ }
\DoxyCodeLine{00987\ \ \ \ \ *out\_infile\ =\ string\_join(di\ ?\ di\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00988\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ di\ ?\ \textcolor{stringliteral}{"{}/"{}}\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00989\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ basename,}
\DoxyCodeLine{00990\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ei\ ?\ \textcolor{stringliteral}{"{}."{}}\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00991\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ei\ ?\ ei\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00992\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NULL);}
\DoxyCodeLine{00993\ \ \ \ \ *out\_outfile\ =\ string\_join(do\_\ ?\ do\_\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00994\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ do\_\ ?\ \textcolor{stringliteral}{"{}/"{}}\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00995\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ basename,}
\DoxyCodeLine{00996\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ eo\ ?\ \textcolor{stringliteral}{"{}."{}}\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00997\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ eo\ ?\ eo\ :\ \textcolor{stringliteral}{"{}"{}},}
\DoxyCodeLine{00998\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NULL);}
\DoxyCodeLine{00999\ \ \ \ \ \textcolor{comment}{/*\ Build\ output\ directory\ structure\ if\ possible/requested\ (it\ is}}
\DoxyCodeLine{01000\ \textcolor{comment}{\ \ \ \ \ *\ by\ default).\ */}}
\DoxyCodeLine{01001\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_boolean\_r(config,\ \textcolor{stringliteral}{"{}-\/build\_outdirs"{}}))\ \{}
\DoxyCodeLine{01002\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *dirname\ =\ ckd\_salloc(*out\_outfile);}
\DoxyCodeLine{01003\ \ \ \ \ \ \ \ \ path2dirname(*out\_outfile,\ dirname);}
\DoxyCodeLine{01004\ \ \ \ \ \ \ \ \ build\_directory(dirname);}
\DoxyCodeLine{01005\ \ \ \ \ \ \ \ \ ckd\_free(dirname);}
\DoxyCodeLine{01006\ \ \ \ \ \}}
\DoxyCodeLine{01007\ \}}
\DoxyCodeLine{01008\ }
\DoxyCodeLine{01009\ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{01010\ run\_control\_file(sphinx\_wave2feat\_t\ *wtf,\ \textcolor{keywordtype}{char}\ \textcolor{keyword}{const}\ *ctlfile)}
\DoxyCodeLine{01011\ \{}
\DoxyCodeLine{01012\ \ \ \ \ hash\_table\_t\ *files;}
\DoxyCodeLine{01013\ \ \ \ \ hash\_iter\_t\ *itor;}
\DoxyCodeLine{01014\ \ \ \ \ lineiter\_t\ *li;}
\DoxyCodeLine{01015\ \ \ \ \ FILE\ *ctlfh;}
\DoxyCodeLine{01016\ \ \ \ \ \textcolor{keywordtype}{int}\ nskip,\ runlen,\ npart,\ rv\ =\ 0;}
\DoxyCodeLine{01017\ }
\DoxyCodeLine{01018\ \ \ \ \ \textcolor{keywordflow}{if}\ ((ctlfh\ =\ fopen(ctlfile,\ \textcolor{stringliteral}{"{}r"{}}))\ ==\ NULL)\ \{}
\DoxyCodeLine{01019\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ open\ control\ file\ \%s"{}},\ ctlfile);}
\DoxyCodeLine{01020\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{01021\ \ \ \ \ \}}
\DoxyCodeLine{01022\ \ \ \ \ nskip\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/nskip"{}});}
\DoxyCodeLine{01023\ \ \ \ \ runlen\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/runlen"{}});}
\DoxyCodeLine{01024\ \ \ \ \ \textcolor{keywordflow}{if}\ ((npart\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/npart"{}})))\ \{}
\DoxyCodeLine{01025\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Count\ lines\ in\ the\ file.\ */}}
\DoxyCodeLine{01026\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ partlen,\ part,\ nlines\ =\ 0;}
\DoxyCodeLine{01027\ \ \ \ \ \ \ \ \ part\ =\ cmd\_ln\_int32\_r(wtf-\/>config,\ \textcolor{stringliteral}{"{}-\/part"{}});}
\DoxyCodeLine{01028\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (li\ =\ lineiter\_start(ctlfh);\ li;\ li\ =\ lineiter\_next(li))}
\DoxyCodeLine{01029\ \ \ \ \ \ \ \ \ \ \ \ \ ++nlines;}
\DoxyCodeLine{01030\ \ \ \ \ \ \ \ \ fseek(ctlfh,\ 0,\ SEEK\_SET);}
\DoxyCodeLine{01031\ \ \ \ \ \ \ \ \ partlen\ =\ nlines\ /\ npart;}
\DoxyCodeLine{01032\ \ \ \ \ \ \ \ \ nskip\ =\ partlen\ *\ (part\ -\/\ 1);}
\DoxyCodeLine{01033\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (part\ ==\ npart)}
\DoxyCodeLine{01034\ \ \ \ \ \ \ \ \ \ \ \ \ runlen\ =\ -\/1;}
\DoxyCodeLine{01035\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{01036\ \ \ \ \ \ \ \ \ \ \ \ \ runlen\ =\ partlen;}
\DoxyCodeLine{01037\ \ \ \ \ \}}
\DoxyCodeLine{01038\ \ \ \ \ \textcolor{keywordflow}{if}\ (runlen\ !=\ -\/1)\{}
\DoxyCodeLine{01039\ \ \ \ \ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}Processing\ \%d\ utterances\ at\ position\ \%d\(\backslash\)n"{}},\ runlen,\ nskip);}
\DoxyCodeLine{01040\ \ \ \ \ \ \ \ \ files\ =\ hash\_table\_new(runlen,\ HASH\_CASE\_YES);}
\DoxyCodeLine{01041\ \ \ \ \ \}}
\DoxyCodeLine{01042\ \ \ \ \ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{01043\ \ \ \ \ \ \ \ \ E\_INFO(\textcolor{stringliteral}{"{}Processing\ all\ remaining\ utterances\ at\ position\ \%d\(\backslash\)n"{}},\ nskip);}
\DoxyCodeLine{01044\ \ \ \ \ \ \ \ \ files\ =\ hash\_table\_new(1000,\ HASH\_CASE\_YES);}
\DoxyCodeLine{01045\ \ \ \ \ \}}
\DoxyCodeLine{01046\ \ \ \ \ \textcolor{keywordflow}{for}\ (li\ =\ lineiter\_start(ctlfh);\ li;\ li\ =\ lineiter\_next(li))\ \{}
\DoxyCodeLine{01047\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *c,\ *infile,\ *outfile;}
\DoxyCodeLine{01048\ }
\DoxyCodeLine{01049\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (nskip-\/-\/\ >\ 0)}
\DoxyCodeLine{01050\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{01051\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (runlen\ ==\ 0)\ \{}
\DoxyCodeLine{01052\ \ \ \ \ \ \ \ \ \ \ \ \ lineiter\_free(li);}
\DoxyCodeLine{01053\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{01054\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01055\ \ \ \ \ \ \ \ \ -\/-\/runlen;}
\DoxyCodeLine{01056\ }
\DoxyCodeLine{01057\ \ \ \ \ \ \ \ \ string\_trim(li-\/>buf,\ STRING\_BOTH);}
\DoxyCodeLine{01058\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ Extract\ the\ file\ ID\ from\ the\ control\ line.\ */}}
\DoxyCodeLine{01059\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((c\ =\ strchr(li-\/>buf,\ \textcolor{charliteral}{'\ '}))\ !=\ NULL)}
\DoxyCodeLine{01060\ \ \ \ \ \ \ \ \ \ \ \ \ *c\ =\ \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{01061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (strlen(li-\/>buf)\ ==\ 0)\ \{}
\DoxyCodeLine{01062\ \ \ \ \ \ \ \ \ \ \ \ \ E\_WARN(\textcolor{stringliteral}{"{}Empty\ line\ \%d\ in\ control\ file,\ skipping\(\backslash\)n"{}},\ li-\/>lineno);}
\DoxyCodeLine{01063\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{01064\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01065\ \ \ \ \ \ \ \ \ build\_filenames(wtf-\/>config,\ li-\/>buf,\ \&infile,\ \&outfile);}
\DoxyCodeLine{01066\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (hash\_table\_lookup(files,\ infile,\ NULL)\ ==\ 0)}
\DoxyCodeLine{01067\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{continue};}
\DoxyCodeLine{01068\ \ \ \ \ \ \ \ \ rv\ =\ sphinx\_wave2feat\_convert\_file(wtf,\ infile,\ outfile);}
\DoxyCodeLine{01069\ \ \ \ \ \ \ \ \ hash\_table\_enter(files,\ infile,\ outfile);}
\DoxyCodeLine{01070\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (rv\ !=\ 0)\ \{}
\DoxyCodeLine{01071\ \ \ \ \ \ \ \ \ \ \ \ \ lineiter\_free(li);}
\DoxyCodeLine{01072\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{01073\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{01074\ \ \ \ \ \}}
\DoxyCodeLine{01075\ \ \ \ \ \textcolor{keywordflow}{for}\ (itor\ =\ hash\_table\_iter(files);\ itor;}
\DoxyCodeLine{01076\ \ \ \ \ \ \ \ \ \ itor\ =\ hash\_table\_iter\_next(itor))\ \{}
\DoxyCodeLine{01077\ \ \ \ \ \ \ \ \ ckd\_free((\textcolor{keywordtype}{void}\ *)hash\_entry\_key(itor-\/>ent));}
\DoxyCodeLine{01078\ \ \ \ \ \ \ \ \ ckd\_free(hash\_entry\_val(itor-\/>ent));}
\DoxyCodeLine{01079\ \ \ \ \ \}}
\DoxyCodeLine{01080\ \ \ \ \ hash\_table\_free(files);}
\DoxyCodeLine{01081\ }
\DoxyCodeLine{01082\ \ \ \ \ \textcolor{keywordflow}{if}\ (fclose(ctlfh)\ ==\ EOF)}
\DoxyCodeLine{01083\ \ \ \ \ \ \ \ \ E\_ERROR\_SYSTEM(\textcolor{stringliteral}{"{}Failed\ to\ close\ control\ file"{}});}
\DoxyCodeLine{01084\ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{01085\ \}}
\DoxyCodeLine{01086\ }
\DoxyCodeLine{01087\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{01088\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{01089\ \{}
\DoxyCodeLine{01090\ \ \ \ \ sphinx\_wave2feat\_t\ *wtf;}
\DoxyCodeLine{01091\ \ \ \ \ cmd\_ln\_t\ *config;}
\DoxyCodeLine{01092\ \ \ \ \ \textcolor{keywordtype}{int}\ rv;}
\DoxyCodeLine{01093\ }
\DoxyCodeLine{01094\ \ \ \ \ \textcolor{comment}{/*\ Initialize\ config.\ */}}
\DoxyCodeLine{01095\ \ \ \ \ \textcolor{keywordflow}{if}\ ((config\ =\ cmd\_ln\_parse\_r(NULL,\ defn,\ argc,\ argv,\ TRUE))\ ==\ NULL)}
\DoxyCodeLine{01096\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 2;}
\DoxyCodeLine{01097\ }
\DoxyCodeLine{01098\ \ \ \ \ \textcolor{comment}{/*\ Parse\ an\ argument\ file\ if\ there's\ one\ in\ there.\ */}}
\DoxyCodeLine{01099\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/argfile"{}}))}
\DoxyCodeLine{01100\ \ \ \ \ \ \ \ \ config\ =\ cmd\_ln\_parse\_file\_r(config,\ defn,}
\DoxyCodeLine{01101\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/argfile"{}}),\ FALSE);}
\DoxyCodeLine{01102\ \ \ \ \ \textcolor{keywordflow}{if}\ (config\ ==\ NULL)\ \{}
\DoxyCodeLine{01103\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Command\ line\ parsing\ failed\(\backslash\)n"{}});}
\DoxyCodeLine{01104\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{01105\ \ \ \ \ \}}
\DoxyCodeLine{01106\ \ \ \ \ \textcolor{keywordflow}{if}\ ((wtf\ =\ sphinx\_wave2feat\_init(config))\ ==\ NULL)\ \{}
\DoxyCodeLine{01107\ \ \ \ \ \ \ \ \ E\_ERROR(\textcolor{stringliteral}{"{}Failed\ to\ initialize\ wave2feat\ object\(\backslash\)n"{}});}
\DoxyCodeLine{01108\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 1;}
\DoxyCodeLine{01109\ \ \ \ \ \}}
\DoxyCodeLine{01110\ }
\DoxyCodeLine{01111\ \ \ \ \ \textcolor{comment}{/*\ If\ there's\ a\ control\ file\ run\ through\ it,\ otherwise\ we\ will\ do}}
\DoxyCodeLine{01112\ \textcolor{comment}{\ \ \ \ \ *\ a\ single\ file\ (which\ is\ what\ run\_control\_file\ will\ do}}
\DoxyCodeLine{01113\ \textcolor{comment}{\ \ \ \ \ *\ internally\ too)\ */}}
\DoxyCodeLine{01114\ \ \ \ \ \textcolor{keywordflow}{if}\ (cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/c"{}}))}
\DoxyCodeLine{01115\ \ \ \ \ \ \ \ \ rv\ =\ run\_control\_file(wtf,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/c"{}}));}
\DoxyCodeLine{01116\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{01117\ \ \ \ \ \ \ \ \ rv\ =\ sphinx\_wave2feat\_convert\_file(wtf,\ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/i"{}}),}
\DoxyCodeLine{01118\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cmd\_ln\_str\_r(config,\ \textcolor{stringliteral}{"{}-\/o"{}}));}
\DoxyCodeLine{01119\ }
\DoxyCodeLine{01120\ \ \ \ \ sphinx\_wave2feat\_free(wtf);}
\DoxyCodeLine{01121\ \ \ \ \ cmd\_ln\_free\_r(config);}
\DoxyCodeLine{01122\ \ \ \ \ \textcolor{keywordflow}{return}\ rv;}
\DoxyCodeLine{01123\ \}}

\end{DoxyCode}
