Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 0b420d0fce195cf4115dc6a3be5c2da2 > files > 328

sphinxbase-devel-0.7-1.fc14.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>SphinxBase: src/sphinx_fe/sphinx_fe.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">SphinxBase&#160;<span id="projectnumber">0.6</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('sphinx__fe_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>src/sphinx_fe/sphinx_fe.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* ====================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> * Copyright (c) 1996-2004 Carnegie Mellon University.  All rights </span>
<a name="l00004"></a>00004 <span class="comment"> * reserved.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00007"></a>00007 <span class="comment"> * modification, are permitted provided that the following conditions</span>
<a name="l00008"></a>00008 <span class="comment"> * are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<a name="l00011"></a>00011 <span class="comment"> *    notice, this list of conditions and the following disclaimer. </span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> *    notice, this list of conditions and the following disclaimer in</span>
<a name="l00015"></a>00015 <span class="comment"> *    the documentation and/or other materials provided with the</span>
<a name="l00016"></a>00016 <span class="comment"> *    distribution.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * This work was supported in part by funding from the Defense Advanced </span>
<a name="l00019"></a>00019 <span class="comment"> * Research Projects Agency and the National Science Foundation of the </span>
<a name="l00020"></a>00020 <span class="comment"> * United States of America, and the CMU Sphinx Speech Consortium.</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS&#39;&#39; AND </span>
<a name="l00023"></a>00023 <span class="comment"> * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, </span>
<a name="l00024"></a>00024 <span class="comment"> * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
<a name="l00025"></a>00025 <span class="comment"> * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY</span>
<a name="l00026"></a>00026 <span class="comment"> * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00027"></a>00027 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT </span>
<a name="l00028"></a>00028 <span class="comment"> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, </span>
<a name="l00029"></a>00029 <span class="comment"> * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY </span>
<a name="l00030"></a>00030 <span class="comment"> * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT </span>
<a name="l00031"></a>00031 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </span>
<a name="l00032"></a>00032 <span class="comment"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00033"></a>00033 <span class="comment"> *</span>
<a name="l00034"></a>00034 <span class="comment"> * ====================================================================</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> */</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#endif</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span>
<a name="l00047"></a>00047 <span class="preprocessor">#ifdef HAVE_SNDFILE_H</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sndfile.h&gt;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#endif</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;sphinxbase/fe.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;sphinxbase/strfuncs.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;sphinxbase/pio.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;sphinxbase/filename.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;sphinxbase/cmd_ln.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;sphinxbase/err.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;sphinxbase/ckd_alloc.h&gt;</span>
<a name="l00058"></a>00058 <span class="preprocessor">#include &lt;sphinxbase/byteorder.h&gt;</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &lt;sphinxbase/hash_table.h&gt;</span>
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 <span class="preprocessor">#include &quot;sphinx_wave2feat.h&quot;</span>
<a name="l00062"></a>00062 <span class="preprocessor">#include &quot;cmd_ln_defn.h&quot;</span>
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="structaudio__type__s.html">00064</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structaudio__type__s.html">audio_type_s</a> {
<a name="l00065"></a>00065     <span class="keywordtype">char</span> <span class="keyword">const</span> *name;
<a name="l00066"></a>00066     int (*detect)(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile);
<a name="l00067"></a>00067     int (*decode)(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf);
<a name="l00068"></a>00068 } <a class="code" href="structaudio__type__s.html">audio_type_t</a>;
<a name="l00069"></a>00069 
<a name="l00070"></a><a class="code" href="structoutput__type__s.html">00070</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structoutput__type__s.html">output_type_s</a> {
<a name="l00071"></a>00071     <span class="keywordtype">char</span> <span class="keyword">const</span> *name;
<a name="l00072"></a>00072     int (*output_header)(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">int</span> nfloat);
<a name="l00073"></a>00073     int (*output_frames)(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, mfcc_t **frames, <span class="keywordtype">int</span> nfr);
<a name="l00074"></a>00074 } <a class="code" href="structoutput__type__s.html">output_type_t</a>;
<a name="l00075"></a>00075 
<a name="l00076"></a><a class="code" href="structsphinx__wave2feat__s.html">00076</a> <span class="keyword">struct </span><a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_s</a> {
<a name="l00077"></a><a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51">00077</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51" title="Reference count.">refcount</a>;     
<a name="l00078"></a><a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d">00078</a>     <a class="code" href="structcmd__ln__t.html" title="Opaque structure used to hold the results of command-line parsing.">cmd_ln_t</a> *<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>; 
<a name="l00079"></a><a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b">00079</a>     <a class="code" href="structfe__s.html" title="Structure for the front-end computation.">fe_t</a> *<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>;         
<a name="l00080"></a><a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c">00080</a>     <span class="keywordtype">char</span> *<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>;     
<a name="l00081"></a><a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf">00081</a>     <span class="keywordtype">char</span> *<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a>;    
<a name="l00082"></a><a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7">00082</a>     FILE *<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>;       
<a name="l00083"></a><a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671">00083</a>     FILE *<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>;      
<a name="l00084"></a><a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5">00084</a>     <span class="keywordtype">short</span> *<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>;     
<a name="l00085"></a><a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae">00085</a>     mfcc_t **<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>;    
<a name="l00086"></a><a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1">00086</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a>;    
<a name="l00087"></a><a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c">00087</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a>;     
<a name="l00088"></a><a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89">00088</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>;       
<a name="l00089"></a><a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a">00089</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>;    
<a name="l00090"></a><a class="code" href="structsphinx__wave2feat__s.html#a030717e2736fd04d1a281f51e5db2799">00090</a>     <span class="keywordtype">int</span> <a class="code" href="structsphinx__wave2feat__s.html#a030717e2736fd04d1a281f51e5db2799" title="Whether byteswapping is necessary.">byteswap</a>;     
<a name="l00091"></a>00091 <span class="preprocessor">#ifdef HAVE_SNDFILE_H</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span>    SNDFILE *insfh;   
<a name="l00093"></a>00093 <span class="preprocessor">#endif</span>
<a name="l00094"></a><a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917">00094</a> <span class="preprocessor"></span>    <a class="code" href="structoutput__type__s.html">output_type_t</a> <span class="keyword">const</span> *<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>;
<a name="l00095"></a>00095 };
<a name="l00096"></a>00096 
<a name="l00098"></a><a class="code" href="structRIFFHeader.html">00098</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structRIFFHeader.html" title="RIFF 44-byte header structure for MS wav files.">RIFFHeader</a>{
<a name="l00099"></a>00099     <span class="keywordtype">char</span> rifftag[4];      <span class="comment">/* &quot;RIFF&quot; string */</span>
<a name="l00100"></a>00100     int32 TotalLength;      <span class="comment">/* Total length */</span>
<a name="l00101"></a>00101     <span class="keywordtype">char</span> wavefmttag[8];   <span class="comment">/* &quot;WAVEfmt &quot; string (note space after &#39;t&#39;) */</span>
<a name="l00102"></a>00102     int32 RemainingLength;  <span class="comment">/* Remaining length */</span>
<a name="l00103"></a>00103     int16 data_format;    <span class="comment">/* data format tag, 1 = PCM */</span>
<a name="l00104"></a>00104     int16 numchannels;    <span class="comment">/* Number of channels in file */</span>
<a name="l00105"></a>00105     int32 SamplingFreq;     <span class="comment">/* Sampling frequency */</span>
<a name="l00106"></a>00106     int32 BytesPerSec;      <span class="comment">/* Average bytes/sec */</span>
<a name="l00107"></a>00107     int16 BlockAlign;     <span class="comment">/* Block align */</span>
<a name="l00108"></a>00108     int16 BitsPerSample;  <span class="comment">/* 8 or 16 bit */</span>
<a name="l00109"></a>00109     <span class="keywordtype">char</span> datatag[4];      <span class="comment">/* &quot;data&quot; string */</span>
<a name="l00110"></a>00110     int32 datalength;       <span class="comment">/* Raw data length */</span>
<a name="l00111"></a>00111 } <a class="code" href="structRIFFHeader.html" title="RIFF 44-byte header structure for MS wav files.">MSWAV_hdr</a>;
<a name="l00112"></a>00112 
<a name="l00118"></a>00118 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00119"></a>00119 detect_riff(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121     FILE *fh;
<a name="l00122"></a>00122     <a class="code" href="structRIFFHeader.html" title="RIFF 44-byte header structure for MS wav files.">MSWAV_hdr</a> hdr;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124     <span class="keywordflow">if</span> ((fh = fopen(infile, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL) {
<a name="l00125"></a>00125         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open %s&quot;</span>, infile);
<a name="l00126"></a>00126         <span class="keywordflow">return</span> -1;
<a name="l00127"></a>00127     }
<a name="l00128"></a>00128     <span class="keywordflow">if</span> (fread(&amp;hdr, <span class="keyword">sizeof</span>(hdr), 1, fh) != 1) {
<a name="l00129"></a>00129         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to read RIFF header&quot;</span>);
<a name="l00130"></a>00130         fclose(fh);
<a name="l00131"></a>00131         <span class="keywordflow">return</span> -1;
<a name="l00132"></a>00132     }
<a name="l00133"></a>00133     <span class="comment">/* Make sure it is actually a RIFF file. */</span>
<a name="l00134"></a>00134     <span class="keywordflow">if</span> (0 != memcmp(hdr.rifftag, <span class="stringliteral">&quot;RIFF&quot;</span>, 4)) {
<a name="l00135"></a>00135         fclose(fh);
<a name="l00136"></a>00136         <span class="keywordflow">return</span> FALSE;
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     <span class="comment">/* Get relevant information. */</span>
<a name="l00140"></a>00140     cmd_ln_set_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>, hdr.numchannels);
<a name="l00141"></a>00141     cmd_ln_set_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-samprate&quot;</span>, hdr.SamplingFreq);
<a name="l00142"></a>00142     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00143"></a>00143         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00144"></a>00144     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00145"></a>00145     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = fh;
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     <span class="keywordflow">return</span> TRUE;
<a name="l00148"></a>00148 }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00151"></a>00151 open_nist_file(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile, FILE **out_fh)
<a name="l00152"></a>00152 {
<a name="l00153"></a>00153     <span class="keywordtype">char</span> nist[7];
<a name="l00154"></a>00154     <a class="code" href="structlineiter__t.html" title="Line iterator for files.">lineiter_t</a> *li;
<a name="l00155"></a>00155     FILE *fh;
<a name="l00156"></a>00156 
<a name="l00157"></a>00157     <span class="keywordflow">if</span> ((fh = fopen(infile, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL) {
<a name="l00158"></a>00158         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open %s&quot;</span>, infile);
<a name="l00159"></a>00159         <span class="keywordflow">return</span> -1;
<a name="l00160"></a>00160     }
<a name="l00161"></a>00161     <span class="keywordflow">if</span> (fread(&amp;nist, 1, 7, fh) != 7) {
<a name="l00162"></a>00162         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to read NIST header&quot;</span>);
<a name="l00163"></a>00163         fclose(fh);
<a name="l00164"></a>00164         <span class="keywordflow">return</span> -1;
<a name="l00165"></a>00165     }
<a name="l00166"></a>00166     <span class="comment">/* Is this actually a NIST file? */</span>
<a name="l00167"></a>00167     <span class="keywordflow">if</span> (0 != strncmp(nist, <span class="stringliteral">&quot;NIST_1A&quot;</span>, 7)) {
<a name="l00168"></a>00168         fclose(fh);
<a name="l00169"></a>00169         <span class="keywordflow">return</span> FALSE;
<a name="l00170"></a>00170     }
<a name="l00171"></a>00171     <span class="comment">/* Rewind, parse lines. */</span>
<a name="l00172"></a>00172     fseek(fh, 0, SEEK_SET);
<a name="l00173"></a>00173     <span class="keywordflow">for</span> (li = <a class="code" href="pio_8h.html#a22d0125ab198f02f8bbe543417d99566" title="Start reading lines from a file.">lineiter_start</a>(fh); li; li = <a class="code" href="pio_8h.html#aff8df0b6928746d61b3520555263f71e" title="Move to the next line in the file.">lineiter_next</a>(li)) {
<a name="l00174"></a>00174         <span class="keywordtype">char</span> **words;
<a name="l00175"></a>00175         <span class="keywordtype">int</span> nword;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         <a class="code" href="strfuncs_8h.html#ac36a095632a4f16cf4e0fbcdb01de5ad" title="Remove whitespace from a string, modifying it in-place.">string_trim</a>(li-&gt;buf, <a class="code" href="strfuncs_8h.html#ab5c9ca15770a4bd3047705762b815df9a4fcbb0fe16fa4aa48723ba3ba10c26dd" title="Both ends of string.">STRING_BOTH</a>);
<a name="l00178"></a>00178         <span class="keywordflow">if</span> (strlen(li-&gt;buf) == 0) {
<a name="l00179"></a>00179             <a class="code" href="pio_8h.html#a3f80e5d4d666426cef229dd41237d9cf" title="Stop reading lines from a file.">lineiter_free</a>(li);
<a name="l00180"></a>00180             <span class="keywordflow">break</span>;
<a name="l00181"></a>00181         }
<a name="l00182"></a>00182         nword = <a class="code" href="strfuncs_8h.html#a5b520fdebcca599db86faaf75a82173f" title="Convert a line to an array of &amp;quot;words&amp;quot;, based on whitespace separators.">str2words</a>(li-&gt;buf, NULL, 0);
<a name="l00183"></a>00183         <span class="keywordflow">if</span> (nword != 3)
<a name="l00184"></a>00184             <span class="keywordflow">continue</span>;
<a name="l00185"></a>00185         words = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(nword, <span class="keyword">sizeof</span>(*words));
<a name="l00186"></a>00186         <a class="code" href="strfuncs_8h.html#a5b520fdebcca599db86faaf75a82173f" title="Convert a line to an array of &amp;quot;words&amp;quot;, based on whitespace separators.">str2words</a>(li-&gt;buf, words, nword);
<a name="l00187"></a>00187         <span class="keywordflow">if</span> (0 == strcmp(words[0], <span class="stringliteral">&quot;sample_rate&quot;</span>)) {
<a name="l00188"></a>00188             cmd_ln_set_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-samprate&quot;</span>, <a class="code" href="strfuncs_8h.html#ab708351fe7308551632a782bfad75a1e" title="Locale independent version of atof().">atof_c</a>(words[2]));
<a name="l00189"></a>00189         }
<a name="l00190"></a>00190         <span class="keywordflow">if</span> (0 == strcmp(words[0], <span class="stringliteral">&quot;channel_count&quot;</span>)) {
<a name="l00191"></a>00191             cmd_ln_set_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>, atoi(words[2]));
<a name="l00192"></a>00192         }
<a name="l00193"></a>00193         <span class="keywordflow">if</span> (0 == strcmp(words[0], <span class="stringliteral">&quot;sample_byte_format&quot;</span>)) {
<a name="l00194"></a>00194             <a class="code" href="cmd__ln_8h.html#a3868b219fd3eaf64e902db38145c1c59" title="Set a string in a command-line object.">cmd_ln_set_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-input_endian&quot;</span>,
<a name="l00195"></a>00195                              (0 == strcmp(words[2], <span class="stringliteral">&quot;10&quot;</span>)) ? <span class="stringliteral">&quot;big&quot;</span> : <span class="stringliteral">&quot;little&quot;</span>);
<a name="l00196"></a>00196         }
<a name="l00197"></a>00197         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(words);
<a name="l00198"></a>00198     }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     fseek(fh, 1024, SEEK_SET);
<a name="l00201"></a>00201     <span class="keywordflow">if</span> (out_fh)
<a name="l00202"></a>00202         *out_fh = fh;
<a name="l00203"></a>00203     <span class="keywordflow">else</span>
<a name="l00204"></a>00204         fclose(fh);
<a name="l00205"></a>00205     <span class="keywordflow">return</span> TRUE;
<a name="l00206"></a>00206 }
<a name="l00207"></a>00207 
<a name="l00208"></a>00208 <span class="preprocessor">#ifdef HAVE_POPEN</span>
<a name="l00209"></a>00209 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00210"></a>00210 detect_sph2pipe(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     FILE *fh;
<a name="l00213"></a>00213     <span class="keywordtype">char</span> *cmdline;
<a name="l00214"></a>00214     <span class="keywordtype">int</span> rv;
<a name="l00215"></a>00215 
<a name="l00216"></a>00216     <span class="comment">/* Determine if it&#39;s NIST file and get parameters. */</span>
<a name="l00217"></a>00217     <span class="keywordflow">if</span> ((rv = open_nist_file(wtf, infile, NULL)) != TRUE)
<a name="l00218"></a>00218         <span class="keywordflow">return</span> rv;
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     <span class="comment">/* Now popen it with sph2pipe. */</span>
<a name="l00221"></a>00221     cmdline = <a class="code" href="strfuncs_8h.html#a317522f23d291311e366de34ef86b777" title="Concatenate a NULL-terminated argument list of strings, returning a newly allocated string...">string_join</a>(<span class="stringliteral">&quot;sph2pipe -f raw &#39;&quot;</span>, infile, <span class="stringliteral">&quot;&#39;&quot;</span>, NULL);
<a name="l00222"></a>00222     <span class="keywordflow">if</span> ((fh = popen(cmdline, <span class="stringliteral">&quot;r&quot;</span>)) == NULL) {
<a name="l00223"></a>00223         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to popen(\&quot;sph2pipe -f raw &#39;%s&#39;\&quot;)&quot;</span>, infile);
<a name="l00224"></a>00224         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(cmdline);
<a name="l00225"></a>00225         <span class="keywordflow">return</span> -1;
<a name="l00226"></a>00226     }
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00229"></a>00229         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00230"></a>00230     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00231"></a>00231     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = fh;
<a name="l00232"></a>00232     <span class="keywordflow">return</span> TRUE;
<a name="l00233"></a>00233 }
<a name="l00234"></a>00234 <span class="preprocessor">#else </span><span class="comment">/* !HAVE_POPEN */</span>
<a name="l00235"></a>00235 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00236"></a>00236 detect_sph2pipe(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238     <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;popen() not available, cannot run sph2pipe\n&quot;</span>);
<a name="l00239"></a>00239     <span class="keywordflow">return</span> -1;
<a name="l00240"></a>00240 }
<a name="l00241"></a>00241 <span class="preprocessor">#endif </span><span class="comment">/* !HAVE_POPEN */</span>
<a name="l00242"></a>00242 
<a name="l00248"></a>00248 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00249"></a>00249 detect_nist(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251     FILE *fh;
<a name="l00252"></a>00252     <span class="keywordtype">int</span> rv;
<a name="l00253"></a>00253 
<a name="l00254"></a>00254     <span class="keywordflow">if</span> ((rv = open_nist_file(wtf, infile, &amp;fh)) != TRUE)
<a name="l00255"></a>00255         <span class="keywordflow">return</span> rv;
<a name="l00256"></a>00256     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00257"></a>00257         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00258"></a>00258     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00259"></a>00259     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = fh;
<a name="l00260"></a>00260     <span class="keywordflow">return</span> TRUE;
<a name="l00261"></a>00261 }
<a name="l00262"></a>00262 
<a name="l00263"></a>00263 
<a name="l00270"></a>00270 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00271"></a>00271 detect_raw(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     FILE *fh;
<a name="l00274"></a>00274 
<a name="l00275"></a>00275     <span class="keywordflow">if</span> ((fh = fopen(infile, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL) {
<a name="l00276"></a>00276         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open %s&quot;</span>, infile);
<a name="l00277"></a>00277         <span class="keywordflow">return</span> -1;
<a name="l00278"></a>00278     }
<a name="l00279"></a>00279     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00280"></a>00280         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00281"></a>00281     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00282"></a>00282     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = fh;
<a name="l00283"></a>00283     <span class="keywordflow">return</span> TRUE;
<a name="l00284"></a>00284 }
<a name="l00285"></a>00285 
<a name="l00292"></a>00292 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00293"></a>00293 detect_sphinx_mfc(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295     FILE *fh;
<a name="l00296"></a>00296     int32 len;
<a name="l00297"></a>00297     <span class="keywordtype">long</span> flen;
<a name="l00298"></a>00298 
<a name="l00299"></a>00299     <span class="keywordflow">if</span> ((fh = fopen(infile, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL) {
<a name="l00300"></a>00300         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open %s&quot;</span>, infile);
<a name="l00301"></a>00301         <span class="keywordflow">return</span> -1;
<a name="l00302"></a>00302     }
<a name="l00303"></a>00303     <span class="keywordflow">if</span> (fread(&amp;len, 4, 1, fh) != 1) {
<a name="l00304"></a>00304         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to read header from %s\n&quot;</span>, infile);
<a name="l00305"></a>00305         <span class="keywordflow">return</span> -1;
<a name="l00306"></a>00306     }
<a name="l00307"></a>00307     fseek(fh, 0, SEEK_END);
<a name="l00308"></a>00308     flen = ftell(fh);
<a name="l00309"></a>00309 
<a name="l00310"></a>00310     <span class="comment">/* figure out whether to byteswap */</span>
<a name="l00311"></a>00311     flen = (flen / 4) - 1;
<a name="l00312"></a>00312     <span class="keywordflow">if</span> (flen != len) {
<a name="l00313"></a>00313         <span class="comment">/* First make sure this is an endianness problem, otherwise fail. */</span>
<a name="l00314"></a>00314         SWAP_INT32(&amp;len);
<a name="l00315"></a>00315         <span class="keywordflow">if</span> (flen != len) {
<a name="l00316"></a>00316             SWAP_INT32(&amp;len);
<a name="l00317"></a>00317             <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Mismatch in header/file lengths: 0x%08x vs 0x%08x\n&quot;</span>,
<a name="l00318"></a>00318                     len, flen);
<a name="l00319"></a>00319             <span class="keywordflow">return</span> -1;
<a name="l00320"></a>00320         }
<a name="l00321"></a>00321         <span class="comment">/* Set the input endianness to the opposite of the machine endianness... */</span>
<a name="l00322"></a>00322         <a class="code" href="cmd__ln_8h.html#a3868b219fd3eaf64e902db38145c1c59" title="Set a string in a command-line object.">cmd_ln_set_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-input_endian&quot;</span>,
<a name="l00323"></a>00323                          (0 == strcmp(<span class="stringliteral">&quot;big&quot;</span>, <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-mach_endian&quot;</span>))
<a name="l00324"></a>00324                           ? <span class="stringliteral">&quot;little&quot;</span> : <span class="stringliteral">&quot;big&quot;</span>));
<a name="l00325"></a>00325     }
<a name="l00326"></a>00326     
<a name="l00327"></a>00327     fseek(fh, 4, SEEK_SET);
<a name="l00328"></a>00328     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00329"></a>00329         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00330"></a>00330     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00331"></a>00331     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = fh;
<a name="l00332"></a>00332     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-spec2cep&quot;</span>)) {
<a name="l00333"></a>00333         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a> = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nfilt&quot;</span>);
<a name="l00334"></a>00334     }
<a name="l00335"></a>00335     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-cep2spec&quot;</span>)) {
<a name="l00336"></a>00336         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a> = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-ncep&quot;</span>);
<a name="l00337"></a>00337         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nfilt&quot;</span>);
<a name="l00338"></a>00338     }
<a name="l00339"></a>00339     <span class="keywordflow">else</span> {
<a name="l00340"></a>00340         <span class="comment">/* Should not happen. */</span>
<a name="l00341"></a>00341         <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Sphinx MFCC file reading requested but -spec2cep/-cep2spec not given\n&quot;</span>);
<a name="l00342"></a>00342         assert(FALSE);
<a name="l00343"></a>00343     }
<a name="l00344"></a>00344             
<a name="l00345"></a>00345     <span class="keywordflow">return</span> TRUE;
<a name="l00346"></a>00346 }
<a name="l00347"></a>00347 
<a name="l00348"></a>00348 <span class="keywordtype">int</span>
<a name="l00349"></a>00349 mixnpick_channels(int16 *buf, int32 nsamp, int32 nchans, int32 whichchan)
<a name="l00350"></a>00350 {
<a name="l00351"></a>00351     <span class="keywordtype">int</span> i, j;
<a name="l00352"></a>00352 
<a name="l00353"></a>00353     <span class="keywordflow">if</span> (whichchan &gt; 0) {
<a name="l00354"></a>00354         <span class="keywordflow">for</span> (i = whichchan - 1; i &lt; nsamp; i += nchans)
<a name="l00355"></a>00355             buf[i/nchans] = buf[i];
<a name="l00356"></a>00356     }
<a name="l00357"></a>00357     <span class="keywordflow">else</span> {
<a name="l00358"></a>00358         <span class="keywordflow">for</span> (i = 0; i &lt; nsamp; i += nchans) {
<a name="l00359"></a>00359             float64 tmp = 0.0;
<a name="l00360"></a>00360             <span class="keywordflow">for</span> (j = 0; j &lt; nchans &amp;&amp; i + j &lt; nsamp; ++j) {
<a name="l00361"></a>00361                 tmp += buf[i + j];
<a name="l00362"></a>00362             }
<a name="l00363"></a>00363             buf[i/nchans] = (int16)(tmp / nchans);
<a name="l00364"></a>00364         }
<a name="l00365"></a>00365     }
<a name="l00366"></a>00366     <span class="keywordflow">return</span> i/nchans;
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 <span class="preprocessor">#ifdef HAVE_SNDFILE_H</span>
<a name="l00370"></a>00370 <span class="preprocessor"></span>
<a name="l00375"></a>00375 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00376"></a>00376 detect_sndfile(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00377"></a>00377 {
<a name="l00378"></a>00378     SNDFILE *sf;
<a name="l00379"></a>00379     SF_INFO sfinfo;
<a name="l00380"></a>00380 
<a name="l00381"></a>00381     memset(&amp;sfinfo, 0, <span class="keyword">sizeof</span>(sfinfo));
<a name="l00382"></a>00382     <span class="comment">/* We let other detectors catch I/O errors, since there is</span>
<a name="l00383"></a>00383 <span class="comment">       no way to tell them from format errors when opening :( */</span>
<a name="l00384"></a>00384     <span class="keywordflow">if</span> ((sf = sf_open(infile, SFM_READ, &amp;sfinfo)) == NULL) {
<a name="l00385"></a>00385         <span class="keywordflow">return</span> FALSE;
<a name="l00386"></a>00386     }
<a name="l00387"></a>00387     <span class="comment">/* Get relevant information. */</span>
<a name="l00388"></a>00388     cmd_ln_set_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>, sfinfo.channels);
<a name="l00389"></a>00389     cmd_ln_set_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-samprate&quot;</span>, sfinfo.samplerate);
<a name="l00390"></a>00390     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>)
<a name="l00391"></a>00391         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00392"></a>00392     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(infile);
<a name="l00393"></a>00393     wtf-&gt;insfh = sf;
<a name="l00394"></a>00394     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = NULL;
<a name="l00395"></a>00395 
<a name="l00396"></a>00396     <span class="keywordflow">return</span> TRUE;
<a name="l00397"></a>00397 }
<a name="l00398"></a>00398 
<a name="l00403"></a>00403 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00404"></a>00404 decode_sndfile(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf)
<a name="l00405"></a>00405 {
<a name="l00406"></a>00406     <span class="keywordtype">size_t</span> nsamp;
<a name="l00407"></a>00407     int32 nfr, nchans, whichchan;
<a name="l00408"></a>00408     <span class="keywordtype">int</span> nfloat, n;
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     nchans = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>);
<a name="l00411"></a>00411     whichchan = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-whichchan&quot;</span>);
<a name="l00412"></a>00412     fe_start_utt(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>);
<a name="l00413"></a>00413     nfloat = 0;
<a name="l00414"></a>00414     <span class="keywordflow">while</span> ((nsamp = sf_read_short(wtf-&gt;insfh,
<a name="l00415"></a>00415                                   wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>,
<a name="l00416"></a>00416                                   wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a>)) != 0) {
<a name="l00417"></a>00417         int16 <span class="keyword">const</span> *inspeech;
<a name="l00418"></a>00418         <span class="keywordtype">size_t</span> nvec;
<a name="l00419"></a>00419 
<a name="l00420"></a>00420         <span class="comment">/* Mix or pick channels. */</span>
<a name="l00421"></a>00421         <span class="keywordflow">if</span> (nchans &gt; 1)
<a name="l00422"></a>00422             nsamp = mixnpick_channels(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>, nsamp, nchans, whichchan);
<a name="l00423"></a>00423 
<a name="l00424"></a>00424         inspeech = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>;
<a name="l00425"></a>00425         nvec = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a>;
<a name="l00426"></a>00426         <span class="comment">/* Consume all samples. */</span>
<a name="l00427"></a>00427         <span class="keywordflow">while</span> (nsamp) {
<a name="l00428"></a>00428             nfr = nvec;
<a name="l00429"></a>00429             fe_process_frames(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, &amp;inspeech, &amp;nsamp, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, &amp;nfr);
<a name="l00430"></a>00430             <span class="keywordflow">if</span> (nfr) {
<a name="l00431"></a>00431                 <span class="keywordflow">if</span> ((n = (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_frames)(wtf, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr)) &lt; 0)
<a name="l00432"></a>00432                     <span class="keywordflow">return</span> -1;
<a name="l00433"></a>00433                 nfloat += n;
<a name="l00434"></a>00434             }
<a name="l00435"></a>00435         }
<a name="l00436"></a>00436         inspeech = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>;
<a name="l00437"></a>00437     }
<a name="l00438"></a>00438     <span class="comment">/* Now process any leftover audio frames. */</span>
<a name="l00439"></a>00439     fe_end_utt(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[0], &amp;nfr);
<a name="l00440"></a>00440     <span class="keywordflow">if</span> (nfr) {
<a name="l00441"></a>00441         <span class="keywordflow">if</span> ((n = (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_frames)(wtf, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr)) &lt; 0)
<a name="l00442"></a>00442             <span class="keywordflow">return</span> -1;
<a name="l00443"></a>00443         nfloat += n;
<a name="l00444"></a>00444     }
<a name="l00445"></a>00445 
<a name="l00446"></a>00446     sf_close(wtf-&gt;insfh);
<a name="l00447"></a>00447     wtf-&gt;insfh = NULL;
<a name="l00448"></a>00448     <span class="keywordflow">return</span> nfloat;
<a name="l00449"></a>00449 }
<a name="l00450"></a>00450 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_SNDFILE_H */</span>
<a name="l00451"></a>00451 
<a name="l00456"></a>00456 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00457"></a>00457 decode_pcm(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf)
<a name="l00458"></a>00458 {
<a name="l00459"></a>00459     <span class="keywordtype">size_t</span> nsamp;
<a name="l00460"></a>00460     int32 nfr, nchans, whichchan;
<a name="l00461"></a>00461     <span class="keywordtype">int</span> nfloat, n;
<a name="l00462"></a>00462 
<a name="l00463"></a>00463     nchans = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>);
<a name="l00464"></a>00464     whichchan = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-whichchan&quot;</span>);
<a name="l00465"></a>00465     fe_start_utt(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>);
<a name="l00466"></a>00466     nfloat = 0;
<a name="l00467"></a>00467     <span class="keywordflow">while</span> ((nsamp = fread(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>, 2, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>)) != 0) {
<a name="l00468"></a>00468         <span class="keywordtype">size_t</span> nvec;
<a name="l00469"></a>00469         int16 <span class="keyword">const</span> *inspeech;
<a name="l00470"></a>00470 
<a name="l00471"></a>00471         <span class="comment">/* Byteswap stuff here if necessary. */</span>
<a name="l00472"></a>00472         <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a030717e2736fd04d1a281f51e5db2799" title="Whether byteswapping is necessary.">byteswap</a>) {
<a name="l00473"></a>00473             <span class="keywordflow">for</span> (n = 0; n &lt; nsamp; ++n)
<a name="l00474"></a>00474                 SWAP_INT16(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a> + n);
<a name="l00475"></a>00475         }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477         <span class="comment">/* Mix or pick channels. */</span>
<a name="l00478"></a>00478         <span class="keywordflow">if</span> (nchans &gt; 1)
<a name="l00479"></a>00479             nsamp = mixnpick_channels(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>, nsamp, nchans, whichchan);
<a name="l00480"></a>00480             
<a name="l00481"></a>00481         inspeech = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>;
<a name="l00482"></a>00482         nvec = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a>;
<a name="l00483"></a>00483         <span class="comment">/* Consume all samples. */</span>
<a name="l00484"></a>00484         <span class="keywordflow">while</span> (nsamp) {
<a name="l00485"></a>00485             nfr = nvec;
<a name="l00486"></a>00486             fe_process_frames(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, &amp;inspeech, &amp;nsamp, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, &amp;nfr);
<a name="l00487"></a>00487             <span class="keywordflow">if</span> (nfr) {
<a name="l00488"></a>00488                 <span class="keywordflow">if</span> ((n = (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_frames)(wtf, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr)) &lt; 0)
<a name="l00489"></a>00489                     <span class="keywordflow">return</span> -1;
<a name="l00490"></a>00490                 nfloat += n;
<a name="l00491"></a>00491             }
<a name="l00492"></a>00492         }
<a name="l00493"></a>00493         inspeech = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>;
<a name="l00494"></a>00494     }
<a name="l00495"></a>00495     <span class="comment">/* Now process any leftover audio frames. */</span>
<a name="l00496"></a>00496     fe_end_utt(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[0], &amp;nfr);
<a name="l00497"></a>00497     <span class="keywordflow">if</span> (nfr) {
<a name="l00498"></a>00498         <span class="keywordflow">if</span> ((n = (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_frames)(wtf, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr)) &lt; 0)
<a name="l00499"></a>00499             <span class="keywordflow">return</span> -1;
<a name="l00500"></a>00500         nfloat += n;
<a name="l00501"></a>00501     }
<a name="l00502"></a>00502 
<a name="l00503"></a>00503     <span class="keywordflow">if</span> (fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>) == EOF)
<a name="l00504"></a>00504         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close input file&quot;</span>);
<a name="l00505"></a>00505     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = NULL;
<a name="l00506"></a>00506     <span class="keywordflow">return</span> nfloat;
<a name="l00507"></a>00507 }
<a name="l00508"></a>00508 
<a name="l00513"></a>00513 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00514"></a>00514 decode_sphinx_mfc(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf)
<a name="l00515"></a>00515 {
<a name="l00516"></a>00516     <span class="keywordtype">int</span> nfloat = 0, n;
<a name="l00517"></a>00517     <span class="keywordtype">int</span> featsize = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a>;
<a name="l00518"></a>00518 
<a name="l00519"></a>00519     <span class="comment">/* If the input vector length is less than the output length, we</span>
<a name="l00520"></a>00520 <span class="comment">     * need to do this one frame at a time, because there&#39;s empty</span>
<a name="l00521"></a>00521 <span class="comment">     * space at the end of each vector in wtf-&gt;feat. */</span>
<a name="l00522"></a>00522     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a> &lt; wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>)
<a name="l00523"></a>00523         featsize = 1;
<a name="l00524"></a>00524     <span class="keywordflow">while</span> ((n = fread(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[0], <span class="keyword">sizeof</span>(**wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>),
<a name="l00525"></a>00525                       featsize * wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>)) != 0) {
<a name="l00526"></a>00526         <span class="keywordtype">int</span> i, nfr = n / wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>;
<a name="l00527"></a>00527         <span class="keywordflow">if</span> (n % wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>) {
<a name="l00528"></a>00528             <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Size of file %d not a multiple of veclen %d\n&quot;</span>,
<a name="l00529"></a>00529                     n, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>);
<a name="l00530"></a>00530             <span class="keywordflow">return</span> -1;
<a name="l00531"></a>00531         }
<a name="l00532"></a>00532         <span class="comment">/* Byteswap stuff here if necessary. */</span>
<a name="l00533"></a>00533         <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a030717e2736fd04d1a281f51e5db2799" title="Whether byteswapping is necessary.">byteswap</a>) {
<a name="l00534"></a>00534             <span class="keywordflow">for</span> (i = 0; i &lt; n; ++i)
<a name="l00535"></a>00535                 SWAP_FLOAT32(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[0] + i);
<a name="l00536"></a>00536         }
<a name="l00537"></a>00537         fe_float_to_mfcc(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, (float32 **)wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr);
<a name="l00538"></a>00538         <span class="keywordflow">for</span> (i = 0; i &lt; nfr; ++i) {
<a name="l00539"></a>00539             <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-spec2cep&quot;</span>)) {
<a name="l00540"></a>00540                 <span class="keywordflow">if</span> (0 == strcmp(<a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-transform&quot;</span>), <span class="stringliteral">&quot;legacy&quot;</span>))
<a name="l00541"></a>00541                     fe_logspec_to_mfcc(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i], wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i]);
<a name="l00542"></a>00542                 <span class="keywordflow">else</span>
<a name="l00543"></a>00543                     fe_logspec_dct2(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i], wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i]);
<a name="l00544"></a>00544             }
<a name="l00545"></a>00545             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-cep2spec&quot;</span>)) {
<a name="l00546"></a>00546                 fe_mfcc_dct3(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i], wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>[i]);
<a name="l00547"></a>00547             }
<a name="l00548"></a>00548         }
<a name="l00549"></a>00549         <span class="keywordflow">if</span> ((n = (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_frames)(wtf, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>, nfr)) &lt; 0)
<a name="l00550"></a>00550             <span class="keywordflow">return</span> -1;
<a name="l00551"></a>00551         nfloat += n;
<a name="l00552"></a>00552     }
<a name="l00553"></a>00553 
<a name="l00554"></a>00554     <span class="keywordflow">if</span> (fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>) == EOF)
<a name="l00555"></a>00555         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close input file&quot;</span>);
<a name="l00556"></a>00556     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = NULL;
<a name="l00557"></a>00557     <span class="keywordflow">return</span> nfloat;
<a name="l00558"></a>00558 }
<a name="l00559"></a>00559 
<a name="l00560"></a>00560 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structaudio__type__s.html">audio_type_t</a> types[] = {
<a name="l00561"></a>00561 <span class="preprocessor">#ifdef HAVE_SNDFILE_H</span>
<a name="l00562"></a>00562 <span class="preprocessor"></span>    { <span class="stringliteral">&quot;-sndfile&quot;</span>, &amp;detect_sndfile, &amp;decode_sndfile },
<a name="l00563"></a>00563 <span class="preprocessor">#endif</span>
<a name="l00564"></a>00564 <span class="preprocessor"></span>    { <span class="stringliteral">&quot;-mswav&quot;</span>, &amp;detect_riff, &amp;decode_pcm },
<a name="l00565"></a>00565     { <span class="stringliteral">&quot;-nist&quot;</span>, &amp;detect_nist, &amp;decode_pcm },
<a name="l00566"></a>00566     { <span class="stringliteral">&quot;-raw&quot;</span>, &amp;detect_raw, &amp;decode_pcm },
<a name="l00567"></a>00567     { <span class="stringliteral">&quot;-sph2pipe&quot;</span>, &amp;detect_sph2pipe, &amp;decode_pcm }
<a name="l00568"></a>00568 };
<a name="l00569"></a>00569 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> ntypes = <span class="keyword">sizeof</span>(types)/<span class="keyword">sizeof</span>(types[0]);
<a name="l00570"></a>00570 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structaudio__type__s.html">audio_type_t</a> mfcc_type = {
<a name="l00571"></a>00571     <span class="stringliteral">&quot;sphinx_mfc&quot;</span>, &amp;detect_sphinx_mfc, &amp;decode_sphinx_mfc
<a name="l00572"></a>00572 };
<a name="l00573"></a>00573 
<a name="l00579"></a>00579 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00580"></a>00580 output_header_sphinx(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, int32 nfloat)
<a name="l00581"></a>00581 {
<a name="l00582"></a>00582     <span class="keywordflow">if</span> (fwrite(&amp;nfloat, 4, 1, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != 1) {
<a name="l00583"></a>00583         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to write to %s&quot;</span>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a>);
<a name="l00584"></a>00584         <span class="keywordflow">return</span> -1;
<a name="l00585"></a>00585     }
<a name="l00586"></a>00586     <span class="keywordflow">return</span> 0;
<a name="l00587"></a>00587 }
<a name="l00588"></a>00588 
<a name="l00594"></a>00594 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00595"></a>00595 output_frames_sphinx(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, mfcc_t **frames, <span class="keywordtype">int</span> nfr)
<a name="l00596"></a>00596 {
<a name="l00597"></a>00597     <span class="keywordtype">int</span> i, nfloat = 0;
<a name="l00598"></a>00598 
<a name="l00599"></a>00599     fe_mfcc_to_float(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, frames, (float32 **)frames, nfr);
<a name="l00600"></a>00600     <span class="keywordflow">for</span> (i = 0; i &lt; nfr; ++i) {
<a name="l00601"></a>00601         <span class="keywordflow">if</span> (fwrite(frames[i], <span class="keyword">sizeof</span>(float32), wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>) {
<a name="l00602"></a>00602             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Writing %d values to %s failed&quot;</span>,
<a name="l00603"></a>00603                            wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a>);
<a name="l00604"></a>00604             <span class="keywordflow">return</span> -1;
<a name="l00605"></a>00605         }
<a name="l00606"></a>00606         nfloat += wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>;
<a name="l00607"></a>00607     }
<a name="l00608"></a>00608     <span class="keywordflow">return</span> nfloat;
<a name="l00609"></a>00609 }
<a name="l00610"></a>00610 
<a name="l00611"></a>00611 <span class="keyword">typedef</span> <span class="keyword">enum</span> htk_feature_kind_e {
<a name="l00612"></a>00612     WAVEFORM = 0,   <span class="comment">/* PCM audio (rarely used) */</span>
<a name="l00613"></a>00613     LPC = 1,        <span class="comment">/* LPC filter coefficients */</span>
<a name="l00614"></a>00614     LPCREFC = 2,    <span class="comment">/* LPC reflection coefficients */</span>
<a name="l00615"></a>00615     LPCEPSTRA = 3,  <span class="comment">/* LPC-based cepstral coefficients */</span>
<a name="l00616"></a>00616     LPCDELCEP = 4,  <span class="comment">/* LPCC plus deltas */</span>
<a name="l00617"></a>00617     IREFC = 5,      <span class="comment">/* 16-bit integer LPC reflection coefficients */</span>
<a name="l00618"></a>00618     MFCC = 6,       <span class="comment">/* MFCCs */</span>
<a name="l00619"></a>00619     FBANK = 7,      <span class="comment">/* Log mel spectrum */</span>
<a name="l00620"></a>00620     MELSPEC = 8,    <span class="comment">/* Linear mel spectrum */</span>
<a name="l00621"></a>00621     USER = 9,       <span class="comment">/* User defined */</span>
<a name="l00622"></a>00622     DISCRETE = 10,  <span class="comment">/* Vector quantized data */</span>
<a name="l00623"></a>00623     PLP = 11        <span class="comment">/* PLP coefficients */</span>
<a name="l00624"></a>00624 } htk_feature_kind_t;
<a name="l00625"></a>00625 
<a name="l00626"></a>00626 <span class="keyword">typedef</span> <span class="keyword">enum</span> htk_feature_flag_e {
<a name="l00627"></a>00627     _E = 0000100, <span class="comment">/* has energy */</span>
<a name="l00628"></a>00628     _N = 0000200, <span class="comment">/* absolute energy supressed */</span>
<a name="l00629"></a>00629     _D = 0000400, <span class="comment">/* has delta coefficients */</span>
<a name="l00630"></a>00630     _A = 0001000, <span class="comment">/* has acceleration (delta-delta) coefficients */</span>
<a name="l00631"></a>00631     _C = 0002000, <span class="comment">/* is compressed */</span>
<a name="l00632"></a>00632     _Z = 0004000, <span class="comment">/* has zero mean static coefficients (i.e. CMN) */</span>
<a name="l00633"></a>00633     _K = 0010000, <span class="comment">/* has CRC checksum */</span>
<a name="l00634"></a>00634     _O = 0020000, <span class="comment">/* has 0th cepstral coefficient */</span>
<a name="l00635"></a>00635     _V = 0040000, <span class="comment">/* has VQ data */</span>
<a name="l00636"></a>00636     _T = 0100000  <span class="comment">/* has third differential coefficients */</span>
<a name="l00637"></a>00637 } htk_feature_flag_t;
<a name="l00638"></a>00638 
<a name="l00642"></a>00642 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00643"></a>00643 output_header_htk(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, int32 nfloat)
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645     int32 samp_period;
<a name="l00646"></a>00646     int16 samp_size;
<a name="l00647"></a>00647     int16 param_kind;
<a name="l00648"></a>00648     <span class="keywordtype">int</span> swap = FALSE;
<a name="l00649"></a>00649 
<a name="l00650"></a>00650     <span class="comment">/* HTK files are big-endian. */</span>
<a name="l00651"></a>00651     <span class="keywordflow">if</span> (0 == strcmp(<span class="stringliteral">&quot;little&quot;</span>, <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-mach_endian&quot;</span>)))
<a name="l00652"></a>00652         swap = TRUE;
<a name="l00653"></a>00653     <span class="comment">/* Same file size thing as in Sphinx files (I think) */</span>
<a name="l00654"></a>00654     <span class="keywordflow">if</span> (swap) SWAP_INT32(&amp;nfloat);
<a name="l00655"></a>00655     <span class="keywordflow">if</span> (fwrite(&amp;nfloat, 4, 1, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != 1)
<a name="l00656"></a>00656         <span class="keywordflow">return</span> -1;
<a name="l00657"></a>00657     <span class="comment">/* Sample period in 100ns units. */</span>
<a name="l00658"></a>00658     samp_period = (int32)(1e+7 / cmd_ln_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-frate&quot;</span>));
<a name="l00659"></a>00659     <span class="keywordflow">if</span> (swap) SWAP_INT32(&amp;samp_period);
<a name="l00660"></a>00660     <span class="keywordflow">if</span> (fwrite(&amp;samp_period, 4, 1, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != 1)
<a name="l00661"></a>00661         <span class="keywordflow">return</span> -1;
<a name="l00662"></a>00662     <span class="comment">/* Sample size - veclen * sizeof each sample. */</span>
<a name="l00663"></a>00663     samp_size = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> * 4;
<a name="l00664"></a>00664     <span class="keywordflow">if</span> (swap) SWAP_INT16(&amp;samp_size);
<a name="l00665"></a>00665     <span class="keywordflow">if</span> (fwrite(&amp;samp_size, 2, 1, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != 1)
<a name="l00666"></a>00666         <span class="keywordflow">return</span> -1;
<a name="l00667"></a>00667     <span class="comment">/* Format and flags. */</span>
<a name="l00668"></a>00668     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-logspec&quot;</span>)
<a name="l00669"></a>00669         || <a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-cep2spec&quot;</span>))
<a name="l00670"></a>00670         param_kind = FBANK; <span class="comment">/* log mel-filter bank outputs */</span>
<a name="l00671"></a>00671     <span class="keywordflow">else</span>
<a name="l00672"></a>00672         param_kind = MFCC | _O; <span class="comment">/* MFCC + CEP0 (note reordering...) */</span>
<a name="l00673"></a>00673     <span class="keywordflow">if</span> (swap) SWAP_INT16(&amp;param_kind);
<a name="l00674"></a>00674     <span class="keywordflow">if</span> (fwrite(&amp;param_kind, 2, 1, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != 1)
<a name="l00675"></a>00675         <span class="keywordflow">return</span> -1;
<a name="l00676"></a>00676 
<a name="l00677"></a>00677     <span class="keywordflow">return</span> 0;
<a name="l00678"></a>00678 }
<a name="l00679"></a>00679 
<a name="l00683"></a>00683 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00684"></a>00684 output_frames_htk(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, mfcc_t **frames, <span class="keywordtype">int</span> nfr)
<a name="l00685"></a>00685 {
<a name="l00686"></a>00686     <span class="keywordtype">int</span> i, j, swap, htk_reorder, nfloat = 0;
<a name="l00687"></a>00687 
<a name="l00688"></a>00688     fe_mfcc_to_float(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, frames, (float32 **)frames, nfr);
<a name="l00689"></a>00689     <span class="comment">/* This is possibly inefficient, but probably not a big deal. */</span>
<a name="l00690"></a>00690     swap = (0 == strcmp(<span class="stringliteral">&quot;little&quot;</span>, <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-mach_endian&quot;</span>)));
<a name="l00691"></a>00691     htk_reorder = (0 == strcmp(<span class="stringliteral">&quot;htk&quot;</span>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;name)
<a name="l00692"></a>00692                    &amp;&amp; !(<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-logspec&quot;</span>)
<a name="l00693"></a>00693                         || <a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-cep2spec&quot;</span>)));
<a name="l00694"></a>00694     <span class="keywordflow">for</span> (i = 0; i &lt; nfr; ++i) {
<a name="l00695"></a>00695         <span class="keywordflow">if</span> (htk_reorder) {
<a name="l00696"></a>00696             mfcc_t c0 = frames[i][0];
<a name="l00697"></a>00697             memmove(frames[i] + 1, frames[i], (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> - 1) * 4);
<a name="l00698"></a>00698             frames[i][wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> - 1] = c0;
<a name="l00699"></a>00699         }
<a name="l00700"></a>00700         <span class="keywordflow">if</span> (swap)
<a name="l00701"></a>00701             <span class="keywordflow">for</span> (j = 0; j &lt; wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>; ++j)
<a name="l00702"></a>00702                 SWAP_FLOAT32(frames[i] + j);
<a name="l00703"></a>00703         <span class="keywordflow">if</span> (fwrite(frames[i], <span class="keyword">sizeof</span>(float32), wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) != wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>) {
<a name="l00704"></a>00704             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Writing %d values to %s failed&quot;</span>,
<a name="l00705"></a>00705                            wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>, wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a>);
<a name="l00706"></a>00706             <span class="keywordflow">return</span> -1;
<a name="l00707"></a>00707         }
<a name="l00708"></a>00708         nfloat += wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>;
<a name="l00709"></a>00709     }
<a name="l00710"></a>00710     <span class="keywordflow">return</span> nfloat;
<a name="l00711"></a>00711 }
<a name="l00712"></a>00712 
<a name="l00716"></a>00716 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00717"></a>00717 output_frames_text(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, mfcc_t **frames, <span class="keywordtype">int</span> nfr)
<a name="l00718"></a>00718 {
<a name="l00719"></a>00719     <span class="keywordtype">int</span> i, j, nfloat = 0;
<a name="l00720"></a>00720 
<a name="l00721"></a>00721     fe_mfcc_to_float(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, frames, (float32 **)frames, nfr);
<a name="l00722"></a>00722     <span class="keywordflow">for</span> (i = 0; i &lt; nfr; ++i) {
<a name="l00723"></a>00723         <span class="keywordflow">for</span> (j = 0; j &lt; wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>; ++j) {
<a name="l00724"></a>00724             fprintf(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>, <span class="stringliteral">&quot;%.5g&quot;</span>, frames[i][j]);
<a name="l00725"></a>00725             <span class="keywordflow">if</span> (j == wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> - 1)
<a name="l00726"></a>00726                 fprintf(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00727"></a>00727             <span class="keywordflow">else</span>
<a name="l00728"></a>00728                 fprintf(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>, <span class="stringliteral">&quot; &quot;</span>);
<a name="l00729"></a>00729         }
<a name="l00730"></a>00730         nfloat += wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>;
<a name="l00731"></a>00731     }
<a name="l00732"></a>00732     <span class="keywordflow">return</span> nfloat;
<a name="l00733"></a>00733 }
<a name="l00734"></a>00734 
<a name="l00735"></a>00735 <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structoutput__type__s.html">output_type_t</a> outtypes[] = {
<a name="l00736"></a>00736     { <span class="stringliteral">&quot;sphinx&quot;</span>, &amp;output_header_sphinx, &amp;output_frames_sphinx },
<a name="l00737"></a>00737     { <span class="stringliteral">&quot;htk&quot;</span>, &amp;output_header_htk, &amp;output_frames_htk },
<a name="l00738"></a>00738     { <span class="stringliteral">&quot;text&quot;</span>, NULL, &amp;output_frames_text }
<a name="l00739"></a>00739 };
<a name="l00740"></a>00740 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> nouttypes = <span class="keyword">sizeof</span>(outtypes)/<span class="keyword">sizeof</span>(outtypes[0]);
<a name="l00741"></a>00741 
<a name="l00742"></a>00742 <a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *
<a name="l00743"></a>00743 sphinx_wave2feat_init(<a class="code" href="structcmd__ln__t.html" title="Opaque structure used to hold the results of command-line parsing.">cmd_ln_t</a> *config)
<a name="l00744"></a>00744 {
<a name="l00745"></a>00745     <a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf;
<a name="l00746"></a>00746     <span class="keywordtype">int</span> i;
<a name="l00747"></a>00747 
<a name="l00748"></a>00748     wtf = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(1, <span class="keyword">sizeof</span>(*wtf));
<a name="l00749"></a>00749     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51" title="Reference count.">refcount</a> = 1;
<a name="l00750"></a>00750     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a> = <a class="code" href="cmd__ln_8h.html#a975f5bf7b6f4fc95f426d1979281f73b" title="Retain ownership of a command-line argument set.">cmd_ln_retain</a>(config);
<a name="l00751"></a>00751     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a> = fe_init_auto_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>);
<a name="l00752"></a>00752     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a> = outtypes; <span class="comment">/* Default (sphinx) type. */</span>
<a name="l00753"></a>00753     <span class="keywordflow">for</span> (i = 0; i &lt; nouttypes; ++i) {
<a name="l00754"></a>00754         <a class="code" href="structoutput__type__s.html">output_type_t</a> <span class="keyword">const</span> *otype = &amp;outtypes[i];
<a name="l00755"></a>00755         <span class="keywordflow">if</span> (0 == strcmp(<a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-ofmt&quot;</span>), otype-&gt;name)) {
<a name="l00756"></a>00756             wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a> = otype;
<a name="l00757"></a>00757             <span class="keywordflow">break</span>;
<a name="l00758"></a>00758         }
<a name="l00759"></a>00759     }
<a name="l00760"></a>00760     <span class="keywordflow">if</span> (i == nouttypes) {
<a name="l00761"></a>00761         <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Unknown output type: &#39;%s&#39;\n&quot;</span>,
<a name="l00762"></a>00762                 <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-ofmt&quot;</span>));
<a name="l00763"></a>00763         sphinx_wave2feat_free(wtf);
<a name="l00764"></a>00764         <span class="keywordflow">return</span> NULL;
<a name="l00765"></a>00765     }
<a name="l00766"></a>00766 
<a name="l00767"></a>00767     <span class="keywordflow">return</span> wtf;
<a name="l00768"></a>00768 }
<a name="l00769"></a>00769 
<a name="l00770"></a>00770 <span class="keywordtype">int</span>
<a name="l00771"></a>00771 sphinx_wave2feat_free(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf)
<a name="l00772"></a>00772 {
<a name="l00773"></a>00773     <span class="keywordflow">if</span> (wtf == NULL)
<a name="l00774"></a>00774         <span class="keywordflow">return</span> 0;
<a name="l00775"></a>00775     <span class="keywordflow">if</span> (--wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51" title="Reference count.">refcount</a> &gt; 0)
<a name="l00776"></a>00776         <span class="keywordflow">return</span> wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51" title="Reference count.">refcount</a>;
<a name="l00777"></a>00777 
<a name="l00778"></a>00778     <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>);
<a name="l00779"></a>00779     <a class="code" href="ckd__alloc_8h.html#a8246c071ac12e98b7e1df9fe6da15aef" title="Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.">ckd_free_2d</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>);
<a name="l00780"></a>00780     <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a6d4d1b1be4e3a3c1de82943e9e6fa65c" title="Path to input file.">infile</a>);
<a name="l00781"></a>00781     <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a>);
<a name="l00782"></a>00782     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>) {
<a name="l00783"></a>00783         <span class="keywordflow">if</span> (fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>) == EOF)
<a name="l00784"></a>00784             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close input file&quot;</span>);
<a name="l00785"></a>00785     }
<a name="l00786"></a>00786     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) {
<a name="l00787"></a>00787         <span class="keywordflow">if</span> (fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) == EOF)
<a name="l00788"></a>00788             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close output file&quot;</span>);
<a name="l00789"></a>00789     }
<a name="l00790"></a>00790     <a class="code" href="cmd__ln_8h.html#a26707fc85e87d8999e368a680e7873cd" title="Release a command-line argument set and all associated strings.">cmd_ln_free_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>);
<a name="l00791"></a>00791     fe_free(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>);
<a name="l00792"></a>00792     <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(wtf);
<a name="l00793"></a>00793 
<a name="l00794"></a>00794     <span class="keywordflow">return</span> 0;
<a name="l00795"></a>00795 }
<a name="l00796"></a>00796 
<a name="l00797"></a>00797 <a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *
<a name="l00798"></a>00798 sphinx_wave2feat_retain(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf)
<a name="l00799"></a>00799 {
<a name="l00800"></a>00800     ++wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ae9b2fc4bfa6a3adbf2ee5a71796cdb51" title="Reference count.">refcount</a>;
<a name="l00801"></a>00801     <span class="keywordflow">return</span> wtf;
<a name="l00802"></a>00802 }
<a name="l00803"></a>00803 
<a name="l00804"></a>00804 <span class="keyword">static</span> <a class="code" href="structaudio__type__s.html">audio_type_t</a> <span class="keyword">const</span> *
<a name="l00805"></a>00805 detect_audio_type(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *infile)
<a name="l00806"></a>00806 {
<a name="l00807"></a>00807     <a class="code" href="structaudio__type__s.html">audio_type_t</a> <span class="keyword">const</span> *atype;
<a name="l00808"></a>00808     <span class="keywordtype">int</span> i;
<a name="l00809"></a>00809 
<a name="l00810"></a>00810     <span class="comment">/* Special case audio type for Sphinx MFCC inputs. */</span>
<a name="l00811"></a>00811     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-spec2cep&quot;</span>)
<a name="l00812"></a>00812         || <a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-cep2spec&quot;</span>)) {
<a name="l00813"></a>00813         <span class="keywordtype">int</span> rv = mfcc_type.detect(wtf, infile);
<a name="l00814"></a>00814         <span class="keywordflow">if</span> (rv == -1)
<a name="l00815"></a>00815             <span class="keywordflow">goto</span> error_out;
<a name="l00816"></a>00816         <span class="keywordflow">return</span> &amp;mfcc_type;
<a name="l00817"></a>00817     }
<a name="l00818"></a>00818 
<a name="l00819"></a>00819     <span class="comment">/* Try to use the type of infile given on the command line. */</span>
<a name="l00820"></a>00820     <span class="keywordflow">for</span> (i = 0; i &lt; ntypes; ++i) {
<a name="l00821"></a>00821         <span class="keywordtype">int</span> rv;
<a name="l00822"></a>00822         atype = &amp;types[i];
<a name="l00823"></a>00823         <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, atype-&gt;name)) {
<a name="l00824"></a>00824             rv = (*atype-&gt;detect)(wtf, infile);
<a name="l00825"></a>00825             <span class="keywordflow">if</span> (rv == -1)
<a name="l00826"></a>00826                 <span class="keywordflow">goto</span> error_out;
<a name="l00827"></a>00827             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (rv == TRUE)
<a name="l00828"></a>00828                 <span class="keywordflow">break</span>;
<a name="l00829"></a>00829         }
<a name="l00830"></a>00830     }
<a name="l00831"></a>00831     <span class="keywordflow">if</span> (i == ntypes) {
<a name="l00832"></a>00832         <span class="comment">/* Detect file type of infile and get parameters. */</span>
<a name="l00833"></a>00833         <span class="keywordflow">for</span> (i = 0; i &lt; ntypes; ++i) {
<a name="l00834"></a>00834             <span class="keywordtype">int</span> rv;
<a name="l00835"></a>00835             atype = &amp;types[i];
<a name="l00836"></a>00836             rv = (*atype-&gt;detect)(wtf, infile);
<a name="l00837"></a>00837             <span class="keywordflow">if</span> (rv == -1)
<a name="l00838"></a>00838                 <span class="keywordflow">goto</span> error_out;
<a name="l00839"></a>00839             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (rv == TRUE)
<a name="l00840"></a>00840                 <span class="keywordflow">break</span>;
<a name="l00841"></a>00841         }
<a name="l00842"></a>00842         <span class="keywordflow">if</span> (i == ntypes)
<a name="l00843"></a>00843             <span class="keywordflow">goto</span> error_out;
<a name="l00844"></a>00844     }
<a name="l00845"></a>00845     <span class="keywordflow">return</span> atype;
<a name="l00846"></a>00846  error_out:
<a name="l00847"></a>00847     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>)
<a name="l00848"></a>00848         fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a>);
<a name="l00849"></a>00849     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad86834e597d4677aed93e7c06cebccb7" title="Input file handle.">infh</a> = NULL;
<a name="l00850"></a>00850     <span class="keywordflow">return</span> NULL;
<a name="l00851"></a>00851 }
<a name="l00852"></a>00852 
<a name="l00853"></a>00853 <span class="keywordtype">int</span>
<a name="l00854"></a>00854 sphinx_wave2feat_convert_file(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf,
<a name="l00855"></a>00855                               <span class="keywordtype">char</span> <span class="keyword">const</span> *infile, <span class="keywordtype">char</span> <span class="keyword">const</span> *outfile)
<a name="l00856"></a>00856 {
<a name="l00857"></a>00857     <span class="keywordtype">int</span> nchans, minfft, nfft, nfloat, veclen;
<a name="l00858"></a>00858     <a class="code" href="structaudio__type__s.html">audio_type_t</a> <span class="keyword">const</span> *atype;
<a name="l00859"></a>00859     <span class="keywordtype">int</span> fshift, fsize;
<a name="l00860"></a>00860 
<a name="l00861"></a>00861     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-verbose&quot;</span>))
<a name="l00862"></a>00862         <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Converting %s to %s\n&quot;</span>, infile, outfile);
<a name="l00863"></a>00863 
<a name="l00864"></a>00864     <span class="comment">/* Detect input file type. */</span>
<a name="l00865"></a>00865     <span class="keywordflow">if</span> ((atype = detect_audio_type(wtf, infile)) == NULL)
<a name="l00866"></a>00866         <span class="keywordflow">return</span> -1;
<a name="l00867"></a>00867 
<a name="l00868"></a>00868     <span class="comment">/* Determine whether to byteswap input. */</span>
<a name="l00869"></a>00869     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a030717e2736fd04d1a281f51e5db2799" title="Whether byteswapping is necessary.">byteswap</a> = strcmp(<a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-mach_endian&quot;</span>),
<a name="l00870"></a>00870                            <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-input_endian&quot;</span>));
<a name="l00871"></a>00871 
<a name="l00872"></a>00872     <span class="comment">/* Make sure the FFT size is sufficiently large. */</span>
<a name="l00873"></a>00873     minfft = (int)(cmd_ln_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-samprate&quot;</span>)
<a name="l00874"></a>00874                    * cmd_ln_float32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-wlen&quot;</span>) + 0.5);
<a name="l00875"></a>00875     <span class="keywordflow">for</span> (nfft = 1; nfft &lt; minfft; nfft &lt;&lt;= 1)
<a name="l00876"></a>00876         ;
<a name="l00877"></a>00877     <span class="keywordflow">if</span> (nfft &gt; cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nfft&quot;</span>)) {
<a name="l00878"></a>00878         <a class="code" href="err_8h.html#a6a794bec721b555ac1f2167f9e12f662" title="Print warning information to standard error stream.">E_WARN</a>(<span class="stringliteral">&quot;Value of -nfft = %d is too small, increasing to %d\n&quot;</span>,
<a name="l00879"></a>00879                cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nfft&quot;</span>), nfft);
<a name="l00880"></a>00880         cmd_ln_set_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nfft&quot;</span>, nfft);
<a name="l00881"></a>00881         fe_free(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>);
<a name="l00882"></a>00882         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a> = fe_init_auto_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>);
<a name="l00883"></a>00883     }
<a name="l00884"></a>00884 
<a name="l00885"></a>00885     <span class="comment">/* Get the output frame size (if not already set). */</span>
<a name="l00886"></a>00886     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> == 0)
<a name="l00887"></a>00887         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a> = fe_get_output_size(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>);
<a name="l00888"></a>00888 
<a name="l00889"></a>00889     <span class="comment">/* Set up the input and output buffers. */</span>
<a name="l00890"></a>00890     fe_get_input_size(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a5882f148fe200890855304b46f00ee4b" title="Front end object.">fe</a>, &amp;fshift, &amp;fsize);
<a name="l00891"></a>00891     <span class="comment">/* Want to get at least a whole frame plus shift in here.  Also we</span>
<a name="l00892"></a>00892 <span class="comment">       will either pick or mix multiple channels so we need to read</span>
<a name="l00893"></a>00893 <span class="comment">       them all at once. */</span>
<a name="l00894"></a>00894     nchans = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nchans&quot;</span>);
<a name="l00895"></a>00895     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a> = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-blocksize&quot;</span>) * nchans;
<a name="l00896"></a>00896     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a> &lt; (fsize + fshift) * nchans) {
<a name="l00897"></a>00897         <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Block size of %d too small, increasing to %d\n&quot;</span>,
<a name="l00898"></a>00898                wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a>,
<a name="l00899"></a>00899                (fsize + fshift) * nchans);
<a name="l00900"></a>00900         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a> = (fsize + fshift) * nchans;
<a name="l00901"></a>00901     }
<a name="l00902"></a>00902     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a> = <a class="code" href="ckd__alloc_8h.html#aa00ef21903bc4f8a972488417adc8d2e" title="Macros to simplify the use of above functions.">ckd_calloc</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a>, <span class="keyword">sizeof</span>(*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a776c72734abe1e34162a5ee347f533e5" title="Audio buffer.">audio</a>));
<a name="l00903"></a>00903     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a> = (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aff2646e41780ceb9dcd234c719fd25f1" title="Size of audio buffer.">blocksize</a> / nchans - fsize) / fshift;
<a name="l00904"></a>00904 
<a name="l00905"></a>00905     <span class="comment">/* Use the maximum of the input and output frame sizes to allocate this. */</span>
<a name="l00906"></a>00906     veclen = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad71e5fca7c13ae0258bcee81a6f1fa89" title="Length of each output vector.">veclen</a>;
<a name="l00907"></a>00907     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a> &gt; veclen) veclen = wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a3410a9e0c05c0057f31452550fb5380a" title="Length of each input vector (for cep&amp;lt;-&amp;gt;spec).">in_veclen</a>;
<a name="l00908"></a>00908     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a> = <a class="code" href="ckd__alloc_8h.html#a949e7b50fcd9697b1563fa57f50e9c4f" title="Macro for __ckd_calloc_2d__.">ckd_calloc_2d</a>(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ac041852de738a42752be67cceb16660c" title="Size of feature buffer.">featsize</a>, veclen, <span class="keyword">sizeof</span>(**wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ab43d8d5721133bcaf02da23c0bbb58ae" title="Feature buffer.">feat</a>));
<a name="l00909"></a>00909 
<a name="l00910"></a>00910     <span class="comment">/* Let&#39;s go! */</span>
<a name="l00911"></a>00911     <span class="keywordflow">if</span> ((wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a> = fopen(outfile, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL) {
<a name="l00912"></a>00912         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open %s for writing&quot;</span>, outfile);
<a name="l00913"></a>00913         <span class="keywordflow">return</span> -1;
<a name="l00914"></a>00914     }
<a name="l00915"></a>00915     <span class="comment">/* Write an empty header, which we&#39;ll fill in later. */</span>
<a name="l00916"></a>00916     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_header &amp;&amp;
<a name="l00917"></a>00917         (*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_header)(wtf, 0) &lt; 0) {
<a name="l00918"></a>00918         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to write empty header to %s\n&quot;</span>, outfile);
<a name="l00919"></a>00919         <span class="keywordflow">goto</span> error_out;
<a name="l00920"></a>00920     }
<a name="l00921"></a>00921     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#aa50405dc75074933912da57295ec5fbf" title="Path to output file.">outfile</a> = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(outfile);
<a name="l00922"></a>00922 
<a name="l00923"></a>00923     <span class="keywordflow">if</span> ((nfloat = (*atype-&gt;decode)(wtf)) &lt; 0)
<a name="l00924"></a>00924         <span class="keywordflow">return</span> -1;
<a name="l00925"></a>00925 
<a name="l00926"></a>00926     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_header) {
<a name="l00927"></a>00927         <span class="keywordflow">if</span> (fseek(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>, 0, SEEK_SET) &lt; 0) {
<a name="l00928"></a>00928             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to seek to beginning of %s\n&quot;</span>, outfile);
<a name="l00929"></a>00929             <span class="keywordflow">goto</span> error_out;
<a name="l00930"></a>00930         }
<a name="l00931"></a>00931         <span class="keywordflow">if</span> ((*wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a929e05e041ad922f6a2e35637a98c917" title="Output type object.">ot</a>-&gt;output_header)(wtf, nfloat) &lt; 0) {
<a name="l00932"></a>00932             <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to write header to %s\n&quot;</span>, outfile);
<a name="l00933"></a>00933             <span class="keywordflow">goto</span> error_out;
<a name="l00934"></a>00934         }
<a name="l00935"></a>00935     }
<a name="l00936"></a>00936     <span class="keywordflow">if</span> (fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) == EOF)
<a name="l00937"></a>00937         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close output file&quot;</span>);
<a name="l00938"></a>00938     wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a> = NULL;
<a name="l00939"></a>00939 
<a name="l00940"></a>00940     <span class="keywordflow">return</span> 0;
<a name="l00941"></a>00941 error_out:
<a name="l00942"></a>00942     <span class="keywordflow">if</span> (wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>) {
<a name="l00943"></a>00943         fclose(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a>);
<a name="l00944"></a>00944         wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#ad7340fab24fb182cbff2c73fd1fb3671" title="Output file handle.">outfh</a> = NULL;
<a name="l00945"></a>00945     }
<a name="l00946"></a>00946     <span class="keywordflow">return</span> -1;
<a name="l00947"></a>00947 }
<a name="l00948"></a>00948 
<a name="l00949"></a>00949 <span class="keywordtype">void</span>
<a name="l00950"></a>00950 build_filenames(<a class="code" href="structcmd__ln__t.html" title="Opaque structure used to hold the results of command-line parsing.">cmd_ln_t</a> *config, <span class="keywordtype">char</span> <span class="keyword">const</span> *basename,
<a name="l00951"></a>00951                 <span class="keywordtype">char</span> **out_infile, <span class="keywordtype">char</span> **out_outfile)
<a name="l00952"></a>00952 {
<a name="l00953"></a>00953     <span class="keywordtype">char</span> <span class="keyword">const</span> *di, *do_, *ei, *eo;
<a name="l00954"></a>00954 
<a name="l00955"></a>00955     di = <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-di&quot;</span>);
<a name="l00956"></a>00956     do_ = <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-do&quot;</span>);
<a name="l00957"></a>00957     ei = <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-ei&quot;</span>);
<a name="l00958"></a>00958     eo = <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-eo&quot;</span>);
<a name="l00959"></a>00959 
<a name="l00960"></a>00960     *out_infile = <a class="code" href="strfuncs_8h.html#a317522f23d291311e366de34ef86b777" title="Concatenate a NULL-terminated argument list of strings, returning a newly allocated string...">string_join</a>(di ? di : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00961"></a>00961                               di ? <span class="stringliteral">&quot;/&quot;</span> : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00962"></a>00962                               basename,
<a name="l00963"></a>00963                               ei ? <span class="stringliteral">&quot;.&quot;</span> : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00964"></a>00964                               ei ? ei : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00965"></a>00965                               NULL);
<a name="l00966"></a>00966     *out_outfile = <a class="code" href="strfuncs_8h.html#a317522f23d291311e366de34ef86b777" title="Concatenate a NULL-terminated argument list of strings, returning a newly allocated string...">string_join</a>(do_ ? do_ : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00967"></a>00967                                do_ ? <span class="stringliteral">&quot;/&quot;</span> : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00968"></a>00968                                basename,
<a name="l00969"></a>00969                                eo ? <span class="stringliteral">&quot;.&quot;</span> : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00970"></a>00970                                eo ? eo : <span class="stringliteral">&quot;&quot;</span>,
<a name="l00971"></a>00971                               NULL);
<a name="l00972"></a>00972     <span class="comment">/* Build output directory structure if possible/requested (it is</span>
<a name="l00973"></a>00973 <span class="comment">     * by default). */</span>
<a name="l00974"></a>00974     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#a159e691c95089689cf9a8f85a67830a6" title="Retrieve a boolean value from a command-line object.">cmd_ln_boolean_r</a>(config, <span class="stringliteral">&quot;-build_outdirs&quot;</span>)) {
<a name="l00975"></a>00975         <span class="keywordtype">char</span> *dirname = <a class="code" href="ckd__alloc_8h.html#ad313f92478859f9e4ea99d0f6e78c393" title="Macro for __ckd_salloc__.">ckd_salloc</a>(*out_outfile);
<a name="l00976"></a>00976         <a class="code" href="filename_8h.html#a678be92ddb74695f26a9e4f527b073b0" title="Strip off filename from the given path and copy the directory name into dir Caller must have allocate...">path2dirname</a>(*out_outfile, dirname);
<a name="l00977"></a>00977         <a class="code" href="pio_8h.html#a6df697b8a08cd4d11fe7b864dcb99012" title="Create a directory and all of its parent directories, as needed.">build_directory</a>(dirname);
<a name="l00978"></a>00978         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(dirname);
<a name="l00979"></a>00979     }
<a name="l00980"></a>00980 }
<a name="l00981"></a>00981 
<a name="l00982"></a>00982 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00983"></a>00983 run_control_file(<a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf, <span class="keywordtype">char</span> <span class="keyword">const</span> *ctlfile)
<a name="l00984"></a>00984 {
<a name="l00985"></a>00985     <a class="code" href="structhash__table__t.html">hash_table_t</a> *files;
<a name="l00986"></a>00986     <a class="code" href="structhash__iter__s.html">hash_iter_t</a> *itor;
<a name="l00987"></a>00987     <a class="code" href="structlineiter__t.html" title="Line iterator for files.">lineiter_t</a> *li;
<a name="l00988"></a>00988     FILE *ctlfh;
<a name="l00989"></a>00989     <span class="keywordtype">int</span> nskip, runlen, npart, rv = 0;
<a name="l00990"></a>00990 
<a name="l00991"></a>00991     <span class="keywordflow">if</span> ((ctlfh = fopen(ctlfile, <span class="stringliteral">&quot;r&quot;</span>)) == NULL) {
<a name="l00992"></a>00992         <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to open control file %s&quot;</span>, ctlfile);
<a name="l00993"></a>00993         <span class="keywordflow">return</span> -1;
<a name="l00994"></a>00994     }
<a name="l00995"></a>00995     nskip = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-nskip&quot;</span>);
<a name="l00996"></a>00996     runlen = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-runlen&quot;</span>);
<a name="l00997"></a>00997     <span class="keywordflow">if</span> ((npart = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-npart&quot;</span>))) {
<a name="l00998"></a>00998         <span class="comment">/* Count lines in the file. */</span>
<a name="l00999"></a>00999         <span class="keywordtype">int</span> partlen, part, nlines = 0;
<a name="l01000"></a>01000         part = cmd_ln_int32_r(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, <span class="stringliteral">&quot;-part&quot;</span>);
<a name="l01001"></a>01001         <span class="keywordflow">for</span> (li = <a class="code" href="pio_8h.html#a22d0125ab198f02f8bbe543417d99566" title="Start reading lines from a file.">lineiter_start</a>(ctlfh); li; li = <a class="code" href="pio_8h.html#aff8df0b6928746d61b3520555263f71e" title="Move to the next line in the file.">lineiter_next</a>(li))
<a name="l01002"></a>01002             ++nlines;
<a name="l01003"></a>01003         fseek(ctlfh, 0, SEEK_SET);
<a name="l01004"></a>01004         partlen = nlines / npart;
<a name="l01005"></a>01005         nskip = partlen * (part - 1);
<a name="l01006"></a>01006         <span class="keywordflow">if</span> (part == npart)
<a name="l01007"></a>01007             runlen = -1;
<a name="l01008"></a>01008         <span class="keywordflow">else</span>
<a name="l01009"></a>01009             runlen = partlen;
<a name="l01010"></a>01010     }
<a name="l01011"></a>01011     <span class="keywordflow">if</span> (runlen != -1){
<a name="l01012"></a>01012         <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Processing %d utterances at position %d\n&quot;</span>, runlen, nskip);
<a name="l01013"></a>01013         files = <a class="code" href="hash__table_8h.html#a56d93e8c03e066b77377ac6eab50cfae" title="Allocate a new hash table for a given expected size.">hash_table_new</a>(runlen, HASH_CASE_YES);
<a name="l01014"></a>01014     }
<a name="l01015"></a>01015     <span class="keywordflow">else</span> {
<a name="l01016"></a>01016         <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Processing all remaining utterances at position %d\n&quot;</span>, nskip);
<a name="l01017"></a>01017         files = <a class="code" href="hash__table_8h.html#a56d93e8c03e066b77377ac6eab50cfae" title="Allocate a new hash table for a given expected size.">hash_table_new</a>(1000, HASH_CASE_YES);
<a name="l01018"></a>01018     }
<a name="l01019"></a>01019     <span class="keywordflow">for</span> (li = <a class="code" href="pio_8h.html#a22d0125ab198f02f8bbe543417d99566" title="Start reading lines from a file.">lineiter_start</a>(ctlfh); li; li = <a class="code" href="pio_8h.html#aff8df0b6928746d61b3520555263f71e" title="Move to the next line in the file.">lineiter_next</a>(li)) {
<a name="l01020"></a>01020         <span class="keywordtype">char</span> *c, *infile, *outfile;
<a name="l01021"></a>01021 
<a name="l01022"></a>01022         <span class="keywordflow">if</span> (nskip-- &gt; 0)
<a name="l01023"></a>01023             <span class="keywordflow">continue</span>;
<a name="l01024"></a>01024         <span class="keywordflow">if</span> (runlen == 0) {
<a name="l01025"></a>01025             <a class="code" href="pio_8h.html#a3f80e5d4d666426cef229dd41237d9cf" title="Stop reading lines from a file.">lineiter_free</a>(li);
<a name="l01026"></a>01026             <span class="keywordflow">break</span>;
<a name="l01027"></a>01027         }
<a name="l01028"></a>01028         --runlen;
<a name="l01029"></a>01029 
<a name="l01030"></a>01030         <a class="code" href="strfuncs_8h.html#ac36a095632a4f16cf4e0fbcdb01de5ad" title="Remove whitespace from a string, modifying it in-place.">string_trim</a>(li-&gt;buf, <a class="code" href="strfuncs_8h.html#ab5c9ca15770a4bd3047705762b815df9a4fcbb0fe16fa4aa48723ba3ba10c26dd" title="Both ends of string.">STRING_BOTH</a>);
<a name="l01031"></a>01031         <span class="comment">/* Extract the file ID from the control line. */</span>
<a name="l01032"></a>01032         <span class="keywordflow">if</span> ((c = strchr(li-&gt;buf, <span class="charliteral">&#39; &#39;</span>)) != NULL)
<a name="l01033"></a>01033             *c = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l01034"></a>01034         build_filenames(wtf-&gt;<a class="code" href="structsphinx__wave2feat__s.html#a484d308befbde315664da8520ebc410d" title="Configuration parameters.">config</a>, li-&gt;buf, &amp;infile, &amp;outfile);
<a name="l01035"></a>01035         <span class="keywordflow">if</span> (<a class="code" href="hash__table_8h.html#a9a1e5ed410eb96f514b00fdce770fbd7" title="Look up a key in a hash table and optionally return the associated value.">hash_table_lookup</a>(files, infile, NULL) == 0)
<a name="l01036"></a>01036             <span class="keywordflow">continue</span>;
<a name="l01037"></a>01037         rv = sphinx_wave2feat_convert_file(wtf, infile, outfile);
<a name="l01038"></a>01038         <a class="code" href="hash__table_8h.html#aebfe63c3869c271b125a8413ee384412" title="Try to add a new entry with given key and associated value to hash table h.">hash_table_enter</a>(files, infile, outfile);
<a name="l01039"></a>01039         <span class="keywordflow">if</span> (rv != 0) {
<a name="l01040"></a>01040             <a class="code" href="pio_8h.html#a3f80e5d4d666426cef229dd41237d9cf" title="Stop reading lines from a file.">lineiter_free</a>(li);
<a name="l01041"></a>01041             <span class="keywordflow">if</span> (fclose(ctlfh) == EOF)
<a name="l01042"></a>01042                 <a class="code" href="err_8h.html#a54ffbfe898d74595c586a1f48f32ef03" title="Print error text; Call perror(&amp;quot;&amp;quot;);.">E_ERROR_SYSTEM</a>(<span class="stringliteral">&quot;Failed to close control file&quot;</span>);
<a name="l01043"></a>01043             <span class="keywordflow">break</span>;
<a name="l01044"></a>01044         }
<a name="l01045"></a>01045     }
<a name="l01046"></a>01046     <span class="keywordflow">for</span> (itor = <a class="code" href="hash__table_8h.html#aae6e6373d3c371d57861a9a875edb207" title="Start iterating over key-value pairs in a hash table.">hash_table_iter</a>(files); itor;
<a name="l01047"></a>01047          itor = <a class="code" href="hash__table_8h.html#ad023321efab26a30bd6d855fbdbe08a3" title="Get the next key-value pair in iteration.">hash_table_iter_next</a>(itor)) {
<a name="l01048"></a>01048         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>((<span class="keywordtype">void</span> *)hash_entry_key(itor-&gt;<a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>));
<a name="l01049"></a>01049         <a class="code" href="ckd__alloc_8h.html#a31c6b405558620ac37599737b5722fbf" title="Test and free a 1-D array.">ckd_free</a>(<a class="code" href="hash__table_8h.html#ac98525ff8ec582358783aecbd388842d" title="Access macros.">hash_entry_val</a>(itor-&gt;<a class="code" href="structhash__iter__s.html#a8aa7d6656a165e2e74c42ae4c48ed78f" title="Current entry in that table.">ent</a>));
<a name="l01050"></a>01050     }
<a name="l01051"></a>01051     <a class="code" href="hash__table_8h.html#a0a588c22946f8cc16328973035ed19e3" title="Free the specified hash table; the caller is responsible for freeing the key strings pointed to by th...">hash_table_free</a>(files);
<a name="l01052"></a>01052     <span class="keywordflow">return</span> rv;
<a name="l01053"></a>01053 }
<a name="l01054"></a>01054 
<a name="l01055"></a>01055 <span class="keywordtype">int</span>
<a name="l01056"></a>01056 main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l01057"></a>01057 {
<a name="l01058"></a>01058     <a class="code" href="structsphinx__wave2feat__s.html">sphinx_wave2feat_t</a> *wtf;
<a name="l01059"></a>01059     <a class="code" href="structcmd__ln__t.html" title="Opaque structure used to hold the results of command-line parsing.">cmd_ln_t</a> *config;
<a name="l01060"></a>01060     <span class="keywordtype">int</span> rv;
<a name="l01061"></a>01061 
<a name="l01062"></a>01062     <span class="comment">/* Initialize config. */</span>
<a name="l01063"></a>01063     <span class="keywordflow">if</span> ((config = <a class="code" href="cmd__ln_8h.html#aa5a3a9e49198d8fd0dd3424fb880b6b6" title="Parse a list of strings into argumetns.">cmd_ln_parse_r</a>(NULL, defn, argc, argv, TRUE)) == NULL)
<a name="l01064"></a>01064         <span class="keywordflow">return</span> 2;
<a name="l01065"></a>01065 
<a name="l01066"></a>01066     <span class="comment">/* Parse an argument file if there&#39;s one in there. */</span>
<a name="l01067"></a>01067     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-argfile&quot;</span>))
<a name="l01068"></a>01068         config = <a class="code" href="cmd__ln_8h.html#a57f54649952a07b8bef888af4e416550" title="Parse an arguments file by deliminating on &amp;quot; \r\t\n&amp;quot; and putting each tokens into an argv[]...">cmd_ln_parse_file_r</a>(config, defn,
<a name="l01069"></a>01069                                      <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-argfile&quot;</span>), FALSE);
<a name="l01070"></a>01070     <span class="keywordflow">if</span> (config == NULL) {
<a name="l01071"></a>01071         <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Command line parsing failed\n&quot;</span>);
<a name="l01072"></a>01072         <span class="keywordflow">return</span> 1;
<a name="l01073"></a>01073     }
<a name="l01074"></a>01074     <span class="keywordflow">if</span> ((wtf = sphinx_wave2feat_init(config)) == NULL) {
<a name="l01075"></a>01075         <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Failed to initialize wave2feat object\n&quot;</span>);
<a name="l01076"></a>01076         <span class="keywordflow">return</span> 1;
<a name="l01077"></a>01077     }
<a name="l01078"></a>01078 
<a name="l01079"></a>01079     <span class="comment">/* If there&#39;s a control file run through it, otherwise we will do</span>
<a name="l01080"></a>01080 <span class="comment">     * a single file (which is what run_control_file will do</span>
<a name="l01081"></a>01081 <span class="comment">     * internally too) */</span>
<a name="l01082"></a>01082     <span class="keywordflow">if</span> (<a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-c&quot;</span>))
<a name="l01083"></a>01083         rv = run_control_file(wtf, <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-c&quot;</span>));
<a name="l01084"></a>01084     <span class="keywordflow">else</span>
<a name="l01085"></a>01085         rv = sphinx_wave2feat_convert_file(wtf, <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-i&quot;</span>),
<a name="l01086"></a>01086                                            <a class="code" href="cmd__ln_8h.html#af0aa15288e06fc8271298e4fa7cdc91a" title="Retrieve a string from a command-line object.">cmd_ln_str_r</a>(config, <span class="stringliteral">&quot;-o&quot;</span>));
<a name="l01087"></a>01087 
<a name="l01088"></a>01088     sphinx_wave2feat_free(wtf);
<a name="l01089"></a>01089     <span class="keywordflow">return</span> rv;
<a name="l01090"></a>01090 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>sphinx_fe.c</b>      </li>
      <li class="footer">Generated on Tue Apr 19 2011 for SphinxBase by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>