Sophie

Sophie

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

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_adtools/cont_fileseg.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('cont__fileseg_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>src/sphinx_adtools/cont_fileseg.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) 1999-2001 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="comment">/*</span>
<a name="l00038"></a>00038 <span class="comment"> * cont_fileseg.c -- Read input file, filter silence regions, and segment into utterances.</span>
<a name="l00039"></a>00039 <span class="comment"> * </span>
<a name="l00040"></a>00040 <span class="comment"> * HISTORY</span>
<a name="l00041"></a>00041 <span class="comment"> * </span>
<a name="l00042"></a>00042 <span class="comment"> * $Log: cont_fileseg.c,v $</span>
<a name="l00043"></a>00043 <span class="comment"> * Revision 1.1.1.1  2006/05/23 18:45:02  dhuggins</span>
<a name="l00044"></a>00044 <span class="comment"> * re-importation</span>
<a name="l00045"></a>00045 <span class="comment"> *</span>
<a name="l00046"></a>00046 <span class="comment"> * Revision 1.13  2005/06/30 00:28:46  rkm</span>
<a name="l00047"></a>00047 <span class="comment"> * Kept within-utterance silences in rawmode</span>
<a name="l00048"></a>00048 <span class="comment"> *</span>
<a name="l00049"></a>00049 <span class="comment"> * </span>
<a name="l00050"></a>00050 <span class="comment"> * 28-Jun-2005  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University</span>
<a name="l00051"></a>00051 <span class="comment"> *              Modified to use new state variables in cont_ad_t.</span>
<a name="l00052"></a>00052 <span class="comment"> * </span>
<a name="l00053"></a>00053 <span class="comment"> * Revision 1.12  2005/05/31 15:54:38  rkm</span>
<a name="l00054"></a>00054 <span class="comment"> * *** empty log message ***</span>
<a name="l00055"></a>00055 <span class="comment"> *</span>
<a name="l00056"></a>00056 <span class="comment"> * Revision 1.11  2005/05/24 20:56:58  rkm</span>
<a name="l00057"></a>00057 <span class="comment"> * Added min/max-noise parameters to cont_fileseg</span>
<a name="l00058"></a>00058 <span class="comment"> *</span>
<a name="l00059"></a>00059 <span class="comment"> * Revision 1.10  2005/05/13 23:28:43  egouvea</span>
<a name="l00060"></a>00060 <span class="comment"> * Changed null device to system dependent one: NUL for windows, /dev/null for everything else</span>
<a name="l00061"></a>00061 <span class="comment"> * </span>
<a name="l00062"></a>00062 <span class="comment"> * $Log: cont_fileseg.c,v $</span>
<a name="l00063"></a>00063 <span class="comment"> * Revision 1.1.1.1  2006/05/23 18:45:02  dhuggins</span>
<a name="l00064"></a>00064 <span class="comment"> * re-importation</span>
<a name="l00065"></a>00065 <span class="comment"> *</span>
<a name="l00066"></a>00066 <span class="comment"> * Revision 1.13  2005/06/30 00:28:46  rkm</span>
<a name="l00067"></a>00067 <span class="comment"> * Kept within-utterance silences in rawmode</span>
<a name="l00068"></a>00068 <span class="comment"> *</span>
<a name="l00069"></a>00069 <span class="comment"> * Revision 1.12  2005/05/31 15:54:38  rkm</span>
<a name="l00070"></a>00070 <span class="comment"> * *** empty log message ***</span>
<a name="l00071"></a>00071 <span class="comment"> *</span>
<a name="l00072"></a>00072 <span class="comment"> * Revision 1.11  2005/05/24 20:56:58  rkm</span>
<a name="l00073"></a>00073 <span class="comment"> * Added min/max-noise parameters to cont_fileseg</span>
<a name="l00074"></a>00074 <span class="comment"> *</span>
<a name="l00075"></a>00075 <span class="comment"> * Revision 1.9  2005/02/13 01:29:48  rkm</span>
<a name="l00076"></a>00076 <span class="comment"> * Fixed cont_ad_read to never cross sil/speech boundary, and rawmode</span>
<a name="l00077"></a>00077 <span class="comment"> *</span>
<a name="l00078"></a>00078 <span class="comment"> * Revision 1.8  2005/02/01 22:21:13  rkm</span>
<a name="l00079"></a>00079 <span class="comment"> * Added raw data logging, and raw data pass-through mode to cont_ad</span>
<a name="l00080"></a>00080 <span class="comment"> *</span>
<a name="l00081"></a>00081 <span class="comment"> * Revision 1.7  2004/07/16 00:57:11  egouvea</span>
<a name="l00082"></a>00082 <span class="comment"> * Added Ravi&#39;s implementation of FSG support.</span>
<a name="l00083"></a>00083 <span class="comment"> *</span>
<a name="l00084"></a>00084 <span class="comment"> * Revision 1.3  2004/06/25 14:58:05  rkm</span>
<a name="l00085"></a>00085 <span class="comment"> * *** empty log message ***</span>
<a name="l00086"></a>00086 <span class="comment"> *</span>
<a name="l00087"></a>00087 <span class="comment"> * Revision 1.2  2004/06/23 20:32:08  rkm</span>
<a name="l00088"></a>00088 <span class="comment"> * Exposed several cont_ad config parameters</span>
<a name="l00089"></a>00089 <span class="comment"> *</span>
<a name="l00090"></a>00090 <span class="comment"> * </span>
<a name="l00091"></a>00091 <span class="comment"> * 27-Jun-96    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University</span>
<a name="l00092"></a>00092 <span class="comment"> *              Created.</span>
<a name="l00093"></a>00093 <span class="comment"> */</span>
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00096"></a>00096 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00097"></a>00097 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00098"></a>00098 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00099"></a>00099 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="preprocessor">#include &lt;sphinxbase/prim_type.h&gt;</span>
<a name="l00102"></a>00102 <span class="preprocessor">#include &lt;sphinxbase/ad.h&gt;</span>
<a name="l00103"></a>00103 <span class="preprocessor">#include &lt;sphinxbase/cont_ad.h&gt;</span>
<a name="l00104"></a>00104 <span class="preprocessor">#include &lt;sphinxbase/err.h&gt;</span>
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="keyword">static</span> FILE *infp;              <span class="comment">/* File being segmented */</span>
<a name="l00107"></a>00107 <span class="keyword">static</span> int32 swap;
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 <span class="comment">/* Max size read by file_ad_read function on each invocation, for debugging */</span>
<a name="l00110"></a>00110 <span class="keyword">static</span> int32 max_ad_read_size;
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 <span class="preprocessor">#if defined(WIN32) &amp;&amp; !defined(GNUWINCE)</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span><span class="preprocessor">#define NULL_DEVICE &quot;NUL&quot;</span>
<a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#define NULL_DEVICE &quot;/dev/null&quot;</span>
<a name="l00116"></a>00116 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00117"></a>00117 <span class="preprocessor"></span>
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="comment">/*</span>
<a name="l00120"></a>00120 <span class="comment"> * Need to provide cont_ad_init with a read function to read the input file.</span>
<a name="l00121"></a>00121 <span class="comment"> * This is it.  The ad_rec_t *r argument is ignored since there is no A/D</span>
<a name="l00122"></a>00122 <span class="comment"> * device involved.</span>
<a name="l00123"></a>00123 <span class="comment"> */</span>
<a name="l00124"></a>00124 <span class="keyword">static</span> int32
<a name="l00125"></a>00125 file_ad_read(<a class="code" href="structad__rec__t.html">ad_rec_t</a> * r, int16 * buf, int32 max)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127     int32 i, k;
<a name="l00128"></a>00128 
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (max &gt; max_ad_read_size)
<a name="l00130"></a>00130         max = max_ad_read_size;
<a name="l00131"></a>00131 
<a name="l00132"></a>00132     k = fread(buf, <span class="keyword">sizeof</span>(int16), max, infp);
<a name="l00133"></a>00133     <span class="keywordflow">if</span> (swap) {
<a name="l00134"></a>00134         <span class="keywordflow">for</span> (i = 0; i &lt; k; i++) {
<a name="l00135"></a>00135             buf[i] = ((buf[i] &gt;&gt; 8) &amp; 0x00ff) | ((buf[i] &lt;&lt; 8) &amp; 0xff00);
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     <span class="keywordflow">return</span> ((k &gt; 0) ? k : -1);
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00144"></a>00144 usagemsg(<span class="keywordtype">char</span> *pgm)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Usage: %s \\\n&quot;</span>, pgm);
<a name="l00147"></a>00147     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-? | -h] \\\n&quot;</span>);
<a name="l00148"></a>00148     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-d | -debug] \\\n&quot;</span>);
<a name="l00149"></a>00149     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-sps &lt;sampling-rate&gt; (16000)] \\\n&quot;</span>);
<a name="l00150"></a>00150     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-b | -byteswap] \\\n&quot;</span>);
<a name="l00151"></a>00151     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>
<a name="l00152"></a>00152         (<span class="stringliteral">&quot;\t[{-s | -silsep} &lt;length-silence-separator(sec) (0.5)]&gt; \\\n&quot;</span>);
<a name="l00153"></a>00153     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-w | -writeseg] \\\n&quot;</span>);
<a name="l00154"></a>00154     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-min-noise &lt;min-noise&gt;] \\\n&quot;</span>);
<a name="l00155"></a>00155     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-max-noise &lt;max-noise&gt;] \\\n&quot;</span>);
<a name="l00156"></a>00156     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-delta-sil &lt;delta-sil&gt;] \\\n&quot;</span>);
<a name="l00157"></a>00157     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-delta-speech &lt;delta-speech&gt;] \\\n&quot;</span>);
<a name="l00158"></a>00158     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-sil-onset &lt;sil-onset&gt;] \\\n&quot;</span>);
<a name="l00159"></a>00159     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-speech-onset &lt;speech-onset&gt;] \\\n&quot;</span>);
<a name="l00160"></a>00160     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-adapt-rate &lt;adapt-rate&gt;] \\\n&quot;</span>);
<a name="l00161"></a>00161     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-max-adreadsize &lt;ad_read_blksize&gt;] \\\n&quot;</span>);
<a name="l00162"></a>00162     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-c &lt;copy-input-file&gt;] \\\n&quot;</span>);
<a name="l00163"></a>00163     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t[-r | -rawmode] \\\n&quot;</span>);
<a name="l00164"></a>00164     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\t-i &lt;input-file&gt;\n&quot;</span>);
<a name="l00165"></a>00165 
<a name="l00166"></a>00166     exit(0);
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169 <span class="comment">/*</span>
<a name="l00170"></a>00170 <span class="comment"> * Read specified input file, segment it into utterances wherever a silence segment of</span>
<a name="l00171"></a>00171 <span class="comment"> * a given minimum duration is encountered.  Filter out long silences.</span>
<a name="l00172"></a>00172 <span class="comment"> * Utterances are written to files named 00000000.raw, 00000001.raw, 00000002.raw, etc.</span>
<a name="l00173"></a>00173 <span class="comment"> */</span>
<a name="l00174"></a>00174 <span class="keywordtype">int</span>
<a name="l00175"></a>00175 main(int32 argc, <span class="keywordtype">char</span> **argv)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177     <a class="code" href="structcont__ad__t.html" title="Continuous listening module or object Continuous listening module or object.">cont_ad_t</a> *cont;
<a name="l00178"></a>00178     int32 uttid, uttlen, starttime, siltime, sps, debug, writeseg, rawmode;
<a name="l00179"></a>00179     int16 buf[4096];
<a name="l00180"></a>00180     <span class="keywordtype">char</span> *infile, *copyfile, segfile[1024];
<a name="l00181"></a>00181     FILE *fp;
<a name="l00182"></a>00182     <span class="keywordtype">float</span> endsil;
<a name="l00183"></a>00183     <a class="code" href="structad__rec__t.html">ad_rec_t</a> ad;
<a name="l00184"></a>00184     int32 i, k;
<a name="l00185"></a>00185     int32 winsize, leader, trailer;
<a name="l00186"></a>00186     int32 orig_min_noise, orig_max_noise;
<a name="l00187"></a>00187     int32 orig_delta_sil, orig_delta_speech;
<a name="l00188"></a>00188     int32 orig_speech_onset, orig_sil_onset;
<a name="l00189"></a>00189     int32 min_noise, max_noise;
<a name="l00190"></a>00190     int32 delta_sil, delta_speech;
<a name="l00191"></a>00191     int32 sil_onset, speech_onset;
<a name="l00192"></a>00192     float32 orig_adapt_rate;
<a name="l00193"></a>00193     float32 adapt_rate;
<a name="l00194"></a>00194     int32 total_speech_samples;
<a name="l00195"></a>00195     float32 total_speech_sec;
<a name="l00196"></a>00196     FILE *rawfp;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198     <span class="comment">/* Set argument defaults */</span>
<a name="l00199"></a>00199     cont = NULL;
<a name="l00200"></a>00200     sps = 16000;
<a name="l00201"></a>00201     swap = 0;
<a name="l00202"></a>00202     endsil = 0.5;
<a name="l00203"></a>00203     writeseg = 0;
<a name="l00204"></a>00204     min_noise = max_noise = -1;
<a name="l00205"></a>00205     delta_sil = delta_speech = -1;
<a name="l00206"></a>00206     sil_onset = speech_onset = -1;
<a name="l00207"></a>00207     adapt_rate = -1.0;
<a name="l00208"></a>00208     max_ad_read_size = (int32) 0x7ffffff0;
<a name="l00209"></a>00209     debug = 0;
<a name="l00210"></a>00210     infile = NULL;
<a name="l00211"></a>00211     copyfile = NULL;
<a name="l00212"></a>00212     rawfp = NULL;
<a name="l00213"></a>00213     rawmode = 0;
<a name="l00214"></a>00214 
<a name="l00215"></a>00215     <span class="comment">/* Parse arguments */</span>
<a name="l00216"></a>00216     <span class="keywordflow">for</span> (i = 1; i &lt; argc; i++) {
<a name="l00217"></a>00217         <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-help&quot;</span>) == 0)
<a name="l00218"></a>00218             || (strcmp(argv[i], <span class="stringliteral">&quot;-h&quot;</span>) == 0)
<a name="l00219"></a>00219             || (strcmp(argv[i], <span class="stringliteral">&quot;-?&quot;</span>) == 0)) {
<a name="l00220"></a>00220             usagemsg(argv[0]);
<a name="l00221"></a>00221         }
<a name="l00222"></a>00222         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-debug&quot;</span>) == 0)
<a name="l00223"></a>00223                  || (strcmp(argv[i], <span class="stringliteral">&quot;-d&quot;</span>) == 0)) {
<a name="l00224"></a>00224             debug = 1;
<a name="l00225"></a>00225         }
<a name="l00226"></a>00226         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-sps&quot;</span>) == 0) {
<a name="l00227"></a>00227             i++;
<a name="l00228"></a>00228             <span class="keywordflow">if</span> ((i == argc)
<a name="l00229"></a>00229                 || (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;sps) != 1)
<a name="l00230"></a>00230                 || (sps &lt;= 0)) {
<a name="l00231"></a>00231                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -sps argument\n&quot;</span>);
<a name="l00232"></a>00232                 usagemsg(argv[0]);
<a name="l00233"></a>00233             }
<a name="l00234"></a>00234         }
<a name="l00235"></a>00235         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-byteswap&quot;</span>) == 0)
<a name="l00236"></a>00236                  || (strcmp(argv[i], <span class="stringliteral">&quot;-b&quot;</span>) == 0)) {
<a name="l00237"></a>00237             swap = 1;
<a name="l00238"></a>00238         }
<a name="l00239"></a>00239         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-silsep&quot;</span>) == 0)
<a name="l00240"></a>00240                  || (strcmp(argv[i], <span class="stringliteral">&quot;-s&quot;</span>) == 0)) {
<a name="l00241"></a>00241             i++;
<a name="l00242"></a>00242             <span class="keywordflow">if</span> ((i == argc)
<a name="l00243"></a>00243                 || (sscanf(argv[i], <span class="stringliteral">&quot;%f&quot;</span>, &amp;endsil) != 1)
<a name="l00244"></a>00244                 || (endsil &lt;= 0.0)) {
<a name="l00245"></a>00245                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -silsep argument\n&quot;</span>);
<a name="l00246"></a>00246                 usagemsg(argv[0]);
<a name="l00247"></a>00247             }
<a name="l00248"></a>00248         }
<a name="l00249"></a>00249         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-writeseg&quot;</span>) == 0)
<a name="l00250"></a>00250                  || (strcmp(argv[i], <span class="stringliteral">&quot;-w&quot;</span>) == 0)) {
<a name="l00251"></a>00251             writeseg = 1;
<a name="l00252"></a>00252         }
<a name="l00253"></a>00253         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-min-noise&quot;</span>) == 0) {
<a name="l00254"></a>00254             i++;
<a name="l00255"></a>00255             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00256"></a>00256                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;min_noise) != 1) ||
<a name="l00257"></a>00257                 (min_noise &lt; 0)) {
<a name="l00258"></a>00258                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -min-noise argument\n&quot;</span>);
<a name="l00259"></a>00259                 usagemsg(argv[0]);
<a name="l00260"></a>00260             }
<a name="l00261"></a>00261         }
<a name="l00262"></a>00262         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-max-noise&quot;</span>) == 0) {
<a name="l00263"></a>00263             i++;
<a name="l00264"></a>00264             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00265"></a>00265                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;max_noise) != 1) ||
<a name="l00266"></a>00266                 (max_noise &lt; 0)) {
<a name="l00267"></a>00267                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -max-noise argument\n&quot;</span>);
<a name="l00268"></a>00268                 usagemsg(argv[0]);
<a name="l00269"></a>00269             }
<a name="l00270"></a>00270         }
<a name="l00271"></a>00271         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-delta-sil&quot;</span>) == 0) {
<a name="l00272"></a>00272             i++;
<a name="l00273"></a>00273             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00274"></a>00274                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;delta_sil) != 1) ||
<a name="l00275"></a>00275                 (delta_sil &lt; 0)) {
<a name="l00276"></a>00276                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -delta-sil argument\n&quot;</span>);
<a name="l00277"></a>00277                 usagemsg(argv[0]);
<a name="l00278"></a>00278             }
<a name="l00279"></a>00279         }
<a name="l00280"></a>00280         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-delta-speech&quot;</span>) == 0) {
<a name="l00281"></a>00281             i++;
<a name="l00282"></a>00282             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00283"></a>00283                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;delta_speech) != 1) ||
<a name="l00284"></a>00284                 (delta_speech &lt; 0)) {
<a name="l00285"></a>00285                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -delta-speech argument\n&quot;</span>);
<a name="l00286"></a>00286                 usagemsg(argv[0]);
<a name="l00287"></a>00287             }
<a name="l00288"></a>00288         }
<a name="l00289"></a>00289         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-sil-onset&quot;</span>) == 0) {
<a name="l00290"></a>00290             i++;
<a name="l00291"></a>00291             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00292"></a>00292                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;sil_onset) != 1) ||
<a name="l00293"></a>00293                 (sil_onset &lt; 1)) {
<a name="l00294"></a>00294                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -sil-onset argument\n&quot;</span>);
<a name="l00295"></a>00295                 usagemsg(argv[0]);
<a name="l00296"></a>00296             }
<a name="l00297"></a>00297         }
<a name="l00298"></a>00298         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-speech-onset&quot;</span>) == 0) {
<a name="l00299"></a>00299             i++;
<a name="l00300"></a>00300             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00301"></a>00301                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;speech_onset) != 1) ||
<a name="l00302"></a>00302                 (speech_onset &lt; 1)) {
<a name="l00303"></a>00303                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -speech-onset argument\n&quot;</span>);
<a name="l00304"></a>00304                 usagemsg(argv[0]);
<a name="l00305"></a>00305             }
<a name="l00306"></a>00306         }
<a name="l00307"></a>00307         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-adapt-rate&quot;</span>) == 0) {
<a name="l00308"></a>00308             i++;
<a name="l00309"></a>00309             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00310"></a>00310                 (sscanf(argv[i], <span class="stringliteral">&quot;%f&quot;</span>, &amp;adapt_rate) != 1) ||
<a name="l00311"></a>00311                 (adapt_rate &lt; 0.0) || (adapt_rate &gt; 1.0)) {
<a name="l00312"></a>00312                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -adapt-rate argument\n&quot;</span>);
<a name="l00313"></a>00313                 usagemsg(argv[0]);
<a name="l00314"></a>00314             }
<a name="l00315"></a>00315         }
<a name="l00316"></a>00316         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-max-adreadsize&quot;</span>) == 0) {
<a name="l00317"></a>00317             i++;
<a name="l00318"></a>00318             <span class="keywordflow">if</span> ((i == argc) ||
<a name="l00319"></a>00319                 (sscanf(argv[i], <span class="stringliteral">&quot;%d&quot;</span>, &amp;max_ad_read_size) != 1) ||
<a name="l00320"></a>00320                 (max_ad_read_size &lt; 1)) {
<a name="l00321"></a>00321                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -max-adreadsize argument\n&quot;</span>);
<a name="l00322"></a>00322                 usagemsg(argv[0]);
<a name="l00323"></a>00323             }
<a name="l00324"></a>00324         }
<a name="l00325"></a>00325         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-c&quot;</span>) == 0) {
<a name="l00326"></a>00326             i++;
<a name="l00327"></a>00327             <span class="keywordflow">if</span> (i == argc) {
<a name="l00328"></a>00328                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -c argument\n&quot;</span>);
<a name="l00329"></a>00329                 usagemsg(argv[0]);
<a name="l00330"></a>00330             }
<a name="l00331"></a>00331             copyfile = argv[i];
<a name="l00332"></a>00332         }
<a name="l00333"></a>00333         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((strcmp(argv[i], <span class="stringliteral">&quot;-rawmode&quot;</span>) == 0)
<a name="l00334"></a>00334                  || (strcmp(argv[i], <span class="stringliteral">&quot;-r&quot;</span>) == 0)) {
<a name="l00335"></a>00335             rawmode = 1;
<a name="l00336"></a>00336         }
<a name="l00337"></a>00337         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[i], <span class="stringliteral">&quot;-i&quot;</span>) == 0) {
<a name="l00338"></a>00338             i++;
<a name="l00339"></a>00339             <span class="keywordflow">if</span> (i == argc) {
<a name="l00340"></a>00340                 <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;Invalid -i argument\n&quot;</span>);
<a name="l00341"></a>00341                 usagemsg(argv[0]);
<a name="l00342"></a>00342             }
<a name="l00343"></a>00343             infile = argv[i];
<a name="l00344"></a>00344         }
<a name="l00345"></a>00345         <span class="keywordflow">else</span> {
<a name="l00346"></a>00346             usagemsg(argv[0]);
<a name="l00347"></a>00347         }
<a name="l00348"></a>00348     }
<a name="l00349"></a>00349 
<a name="l00350"></a>00350     <span class="keywordflow">if</span> (infile == NULL) {
<a name="l00351"></a>00351         <a class="code" href="err_8h.html#a5f7b2f58f5a663a6bdd51f197ae21993" title="Print error message to standard error stream.">E_ERROR</a>(<span class="stringliteral">&quot;No input file specified\n&quot;</span>);
<a name="l00352"></a>00352         usagemsg(argv[0]);
<a name="l00353"></a>00353     }
<a name="l00354"></a>00354 
<a name="l00355"></a>00355     <span class="keywordflow">if</span> ((infp = fopen(infile, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL)
<a name="l00356"></a>00356         <a class="code" href="err_8h.html#a1a4495946ab2449d61108fe829a94613" title="Exit with non-zero status after error message.">E_FATAL</a>(<span class="stringliteral">&quot;Failed to open &#39;%s&#39; for reading: %s\n&quot;</span>, infile, strerror(errno));
<a name="l00357"></a>00357 
<a name="l00358"></a>00358     <span class="comment">/*</span>
<a name="l00359"></a>00359 <span class="comment">     * Associate continuous listening module with opened input file and read function.</span>
<a name="l00360"></a>00360 <span class="comment">     * No A/D device is involved, but need to fill in ad-&gt;sps.</span>
<a name="l00361"></a>00361 <span class="comment">     * Calibrate input data using first few seconds of file, but then rewind it!!</span>
<a name="l00362"></a>00362 <span class="comment">     */</span>
<a name="l00363"></a>00363     ad.<a class="code" href="structad__rec__t.html#ac8ccccdc755f68cb4ad24007b36d6c8a" title="Samples/sec.">sps</a> = sps;
<a name="l00364"></a>00364     ad.<a class="code" href="structad__rec__t.html#ade5a608978908d87deea7fa9827f8510" title="Bytes/sample.">bps</a> = <span class="keyword">sizeof</span>(int16);
<a name="l00365"></a>00365     <span class="keywordflow">if</span> (!rawmode)
<a name="l00366"></a>00366         cont = <a class="code" href="cont__ad_8h.html#af28bf56f17d5cfebf4d960ebed44ca64" title="Initialize a continuous listening/silence filtering object.">cont_ad_init</a>(&amp;ad, file_ad_read);
<a name="l00367"></a>00367     <span class="keywordflow">else</span>
<a name="l00368"></a>00368         cont = <a class="code" href="cont__ad_8h.html#a1a9bbf961917827f5d03adcd409dda35" title="Initializes a continuous listening object which simply passes data through (!)">cont_ad_init_rawmode</a>(&amp;ad, file_ad_read);
<a name="l00369"></a>00369 
<a name="l00370"></a>00370     printf(<span class="stringliteral">&quot;Calibrating ...&quot;</span>);
<a name="l00371"></a>00371     fflush(stdout);
<a name="l00372"></a>00372     <span class="keywordflow">if</span> (<a class="code" href="cont__ad_8h.html#a7a1d0eaf8292a4549b00a97163999321" title="Calibrate the silence filter.">cont_ad_calib</a>(cont) &lt; 0)
<a name="l00373"></a>00373         printf(<span class="stringliteral">&quot; failed; file too short?\n&quot;</span>);
<a name="l00374"></a>00374     <span class="keywordflow">else</span>
<a name="l00375"></a>00375         printf(<span class="stringliteral">&quot; done\n&quot;</span>);
<a name="l00376"></a>00376     rewind(infp);
<a name="l00377"></a>00377 
<a name="l00378"></a>00378     <span class="comment">/* Convert desired min. inter-utterance silence duration to #samples */</span>
<a name="l00379"></a>00379     siltime = (int32) (endsil * sps);
<a name="l00380"></a>00380 
<a name="l00381"></a>00381     <span class="comment">/* Enable writing raw input to output by the cont module if specified */</span>
<a name="l00382"></a>00382     <span class="keywordflow">if</span> (copyfile) {
<a name="l00383"></a>00383         <span class="keywordflow">if</span> ((rawfp = fopen(copyfile, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL)
<a name="l00384"></a>00384             <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 open raw output file &#39;%s&#39; for writing: %s\n&quot;</span>,
<a name="l00385"></a>00385                     copyfile, strerror(errno));
<a name="l00386"></a>00386         <span class="keywordflow">else</span>
<a name="l00387"></a>00387             <a class="code" href="cont__ad_8h.html#a662ed7c409479060e3b5ac8eb7bd1865" title="Set a file for dumping raw audio input.">cont_ad_set_rawfp</a>(cont, rawfp);
<a name="l00388"></a>00388     }
<a name="l00389"></a>00389 
<a name="l00390"></a>00390     <a class="code" href="cont__ad_8h.html#aedd013bc2c6aca14fba02049ed7645d7" title="PWP 1/14/98 -- get the changable params.">cont_ad_get_params</a>(cont,
<a name="l00391"></a>00391                        &amp;orig_delta_sil, &amp;orig_delta_speech,
<a name="l00392"></a>00392                        &amp;orig_min_noise, &amp;orig_max_noise,
<a name="l00393"></a>00393                        &amp;winsize,
<a name="l00394"></a>00394                        &amp;orig_speech_onset, &amp;orig_sil_onset,
<a name="l00395"></a>00395                        &amp;leader, &amp;trailer, &amp;orig_adapt_rate);
<a name="l00396"></a>00396 
<a name="l00397"></a>00397     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Default parameters:\n&quot;</span>);
<a name="l00398"></a>00398     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tmin-noise = %d, max-noise = %d\n&quot;</span>,
<a name="l00399"></a>00399                orig_min_noise, orig_max_noise);
<a name="l00400"></a>00400     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tdelta-sil = %d, delta-speech = %d\n&quot;</span>,
<a name="l00401"></a>00401                orig_delta_sil, orig_delta_speech);
<a name="l00402"></a>00402     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tsil-onset = %d, speech-onset = %d\n&quot;</span>,
<a name="l00403"></a>00403                orig_sil_onset, orig_speech_onset);
<a name="l00404"></a>00404     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tadapt_rate = %.3f\n&quot;</span>, orig_adapt_rate);
<a name="l00405"></a>00405 
<a name="l00406"></a>00406     <span class="keywordflow">if</span> (min_noise &lt; 0)
<a name="l00407"></a>00407         min_noise = orig_min_noise;
<a name="l00408"></a>00408     <span class="keywordflow">if</span> (max_noise &lt; 0)
<a name="l00409"></a>00409         max_noise = orig_max_noise;
<a name="l00410"></a>00410     <span class="keywordflow">if</span> (delta_sil &lt; 0)
<a name="l00411"></a>00411         delta_sil = orig_delta_sil;
<a name="l00412"></a>00412     <span class="keywordflow">if</span> (delta_speech &lt; 0)
<a name="l00413"></a>00413         delta_speech = orig_delta_speech;
<a name="l00414"></a>00414     <span class="keywordflow">if</span> (sil_onset &lt; 0)
<a name="l00415"></a>00415         sil_onset = orig_sil_onset;
<a name="l00416"></a>00416     <span class="keywordflow">if</span> (speech_onset &lt; 0)
<a name="l00417"></a>00417         speech_onset = orig_speech_onset;
<a name="l00418"></a>00418     <span class="keywordflow">if</span> (adapt_rate &lt; 0.0)
<a name="l00419"></a>00419         adapt_rate = orig_adapt_rate;
<a name="l00420"></a>00420 
<a name="l00421"></a>00421     <a class="code" href="cont__ad_8h.html#aa402397c575922ea352afe5e66c02a34" title="Set the changable parameters.">cont_ad_set_params</a>(cont,
<a name="l00422"></a>00422                        delta_sil, delta_speech,
<a name="l00423"></a>00423                        min_noise, max_noise,
<a name="l00424"></a>00424                        winsize,
<a name="l00425"></a>00425                        speech_onset, sil_onset,
<a name="l00426"></a>00426                        leader, trailer, adapt_rate);
<a name="l00427"></a>00427 
<a name="l00428"></a>00428     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Current parameters:\n&quot;</span>);
<a name="l00429"></a>00429     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tmin-noise = %d, max-noise = %d\n&quot;</span>, min_noise, max_noise);
<a name="l00430"></a>00430     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tdelta-sil = %d, delta-speech = %d\n&quot;</span>, delta_sil,
<a name="l00431"></a>00431                delta_speech);
<a name="l00432"></a>00432     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tsil-onset = %d, speech-onset = %d\n&quot;</span>, sil_onset,
<a name="l00433"></a>00433                speech_onset);
<a name="l00434"></a>00434     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;\tadapt_rate = %.3f\n&quot;</span>, adapt_rate);
<a name="l00435"></a>00435 
<a name="l00436"></a>00436     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Sampling rate: %d&quot;</span>, sps);
<a name="l00437"></a>00437     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;; Byteswap: %s&quot;</span>, swap ? <span class="stringliteral">&quot;Yes&quot;</span> : <span class="stringliteral">&quot;No&quot;</span>);
<a name="l00438"></a>00438     <a class="code" href="err_8h.html#ae5a17ac5be8c738d3d977b1bea2d4538" title="Print logging information without header, to standard error stream.">E_INFOCONT</a>(<span class="stringliteral">&quot;; Max ad-read size: %d\n&quot;</span>, max_ad_read_size);
<a name="l00439"></a>00439 
<a name="l00440"></a>00440     <span class="keywordflow">if</span> (debug)
<a name="l00441"></a>00441         <a class="code" href="cont__ad_8h.html#a16c5810eb19ed89522ef4c3394bbfe83" title="Set the file to which cont_ad logs its progress.">cont_ad_set_logfp</a>(cont, stdout);
<a name="l00442"></a>00442 
<a name="l00443"></a>00443     total_speech_samples = 0;
<a name="l00444"></a>00444     total_speech_sec = 0.0;
<a name="l00445"></a>00445 
<a name="l00446"></a>00446     uttid = 0;
<a name="l00447"></a>00447     uttlen = 0;
<a name="l00448"></a>00448     starttime = 0;
<a name="l00449"></a>00449     fp = NULL;
<a name="l00450"></a>00450 
<a name="l00451"></a>00451     <span class="comment">/* Process data */</span>
<a name="l00452"></a>00452     <span class="keywordflow">for</span> (;;) {
<a name="l00453"></a>00453         <span class="comment">/* Get audio data from continuous listening module */</span>
<a name="l00454"></a>00454         k = <a class="code" href="cont__ad_8h.html#ae664132adc514db01a1d5c1209ded4ba" title="Read raw audio data into the silence filter.">cont_ad_read</a>(cont, buf, 4096);
<a name="l00455"></a>00455 
<a name="l00456"></a>00456         <span class="keywordflow">if</span> (k &lt; 0) {            <span class="comment">/* End of input audio file; close any open output file and exit */</span>
<a name="l00457"></a>00457             <span class="keywordflow">if</span> (fp != NULL) {
<a name="l00458"></a>00458                 fclose(fp);
<a name="l00459"></a>00459                 fp = NULL;
<a name="l00460"></a>00460 
<a name="l00461"></a>00461                 printf
<a name="l00462"></a>00462                     (<span class="stringliteral">&quot;Utt %08d, st= %8.2fs, et= %8.2fs, seg= %7.2fs (#samp= %10d)\n&quot;</span>,
<a name="l00463"></a>00463                      uttid, (<span class="keywordtype">double</span>) starttime / (<span class="keywordtype">double</span>) sps,
<a name="l00464"></a>00464                      (<span class="keywordtype">double</span>) (starttime + uttlen) / (<span class="keywordtype">double</span>) sps,
<a name="l00465"></a>00465                      (<span class="keywordtype">double</span>) uttlen / (<span class="keywordtype">double</span>) sps, uttlen);
<a name="l00466"></a>00466                 fflush(stdout);
<a name="l00467"></a>00467 
<a name="l00468"></a>00468                 total_speech_samples += uttlen;
<a name="l00469"></a>00469                 total_speech_sec += (double) uttlen / (<span class="keywordtype">double</span>) sps;
<a name="l00470"></a>00470 
<a name="l00471"></a>00471                 uttid++;
<a name="l00472"></a>00472             }
<a name="l00473"></a>00473 
<a name="l00474"></a>00474             <span class="keywordflow">break</span>;
<a name="l00475"></a>00475         }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477         <span class="keywordflow">if</span> (cont-&gt;<a class="code" href="structcont__ad__t.html#a5d9420ea711733d1eea9b8f29a638fdb" title="State of data returned by most recent cont_ad_read call; CONT_AD_STATE_SIL or CONT_AD_STATE_SPEECH.">state</a> == CONT_AD_STATE_SIL) { <span class="comment">/* Silence data got */</span>
<a name="l00478"></a>00478             <span class="keywordflow">if</span> (fp != NULL) {   <span class="comment">/* Currently in an utterance */</span>
<a name="l00479"></a>00479                 <span class="keywordflow">if</span> (cont-&gt;<a class="code" href="structcont__ad__t.html#a478939247e09a8ae142c8996ec17d8c8" title="Total no.">seglen</a> &gt; siltime) {   <span class="comment">/* Long enough silence detected; end the utterance */</span>
<a name="l00480"></a>00480                     fclose(fp);
<a name="l00481"></a>00481                     fp = NULL;
<a name="l00482"></a>00482 
<a name="l00483"></a>00483                     printf
<a name="l00484"></a>00484                         (<span class="stringliteral">&quot;Utt %08d, st= %8.2fs, et= %8.2fs, seg= %7.2fs (#samp= %10d)\n&quot;</span>,
<a name="l00485"></a>00485                          uttid, (<span class="keywordtype">double</span>) starttime / (<span class="keywordtype">double</span>) sps,
<a name="l00486"></a>00486                          (<span class="keywordtype">double</span>) (starttime + uttlen) / (<span class="keywordtype">double</span>) sps,
<a name="l00487"></a>00487                          (<span class="keywordtype">double</span>) uttlen / (<span class="keywordtype">double</span>) sps, uttlen);
<a name="l00488"></a>00488                     fflush(stdout);
<a name="l00489"></a>00489 
<a name="l00490"></a>00490                     total_speech_samples += uttlen;
<a name="l00491"></a>00491                     total_speech_sec += (double) uttlen / (<span class="keywordtype">double</span>) sps;
<a name="l00492"></a>00492 
<a name="l00493"></a>00493                     uttid++;
<a name="l00494"></a>00494                 }
<a name="l00495"></a>00495                 <span class="keywordflow">else</span> {
<a name="l00496"></a>00496                     <span class="comment">/*</span>
<a name="l00497"></a>00497 <span class="comment">                     * Short silence within utt; write it to output.  (Some extra trailing silence</span>
<a name="l00498"></a>00498 <span class="comment">                     * is included in the utterance, as a result.  Not to worry about it.)</span>
<a name="l00499"></a>00499 <span class="comment">                     */</span>
<a name="l00500"></a>00500                     <span class="keywordflow">if</span> (k &gt; 0) {
<a name="l00501"></a>00501                         fwrite(buf, <span class="keyword">sizeof</span>(int16), k, fp);
<a name="l00502"></a>00502                         uttlen += k;
<a name="l00503"></a>00503                     }
<a name="l00504"></a>00504                 }
<a name="l00505"></a>00505             }
<a name="l00506"></a>00506         }
<a name="l00507"></a>00507         <span class="keywordflow">else</span> {
<a name="l00508"></a>00508             assert(cont-&gt;<a class="code" href="structcont__ad__t.html#a5d9420ea711733d1eea9b8f29a638fdb" title="State of data returned by most recent cont_ad_read call; CONT_AD_STATE_SIL or CONT_AD_STATE_SPEECH.">state</a> == CONT_AD_STATE_SPEECH);
<a name="l00509"></a>00509 
<a name="l00510"></a>00510             <span class="keywordflow">if</span> (fp == NULL) {   <span class="comment">/* Not in an utt; open a new output file */</span>
<a name="l00511"></a>00511                 <span class="keywordflow">if</span> (writeseg)
<a name="l00512"></a>00512                     sprintf(segfile, <span class="stringliteral">&quot;%08d.raw&quot;</span>, uttid);
<a name="l00513"></a>00513                 <span class="keywordflow">else</span>
<a name="l00514"></a>00514                     strcpy(segfile, NULL_DEVICE);
<a name="l00515"></a>00515                 <span class="keywordflow">if</span> ((fp = fopen(segfile, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL)
<a name="l00516"></a>00516                     <a class="code" href="err_8h.html#a1a4495946ab2449d61108fe829a94613" title="Exit with non-zero status after error message.">E_FATAL</a>(<span class="stringliteral">&quot;Failed to open segmentation file &#39;%s&#39; for writing: %s\n&quot;</span>, segfile, strerror(errno));
<a name="l00517"></a>00517 
<a name="l00518"></a>00518                 starttime = cont-&gt;<a class="code" href="structcont__ad__t.html#a7b71e87abfcb3ca4ae73af34c86f955e" title="Absolute timestamp (total no.">read_ts</a> - k;
<a name="l00519"></a>00519                 uttlen = 0;
<a name="l00520"></a>00520             }
<a name="l00521"></a>00521 
<a name="l00522"></a>00522             <span class="comment">/* Write data obtained to output file */</span>
<a name="l00523"></a>00523             <span class="keywordflow">if</span> (k &gt; 0) {
<a name="l00524"></a>00524                 fwrite(buf, <span class="keyword">sizeof</span>(int16), k, fp);
<a name="l00525"></a>00525                 uttlen += k;
<a name="l00526"></a>00526             }
<a name="l00527"></a>00527         }
<a name="l00528"></a>00528     }
<a name="l00529"></a>00529 
<a name="l00530"></a>00530     <span class="keywordflow">if</span> (rawfp)
<a name="l00531"></a>00531         fclose(rawfp);
<a name="l00532"></a>00532 
<a name="l00533"></a>00533     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Total raw input speech = %d frames, %d samples, %.2f sec\n&quot;</span>,
<a name="l00534"></a>00534            cont-&gt;<a class="code" href="structcont__ad__t.html#a4ed32427e6a785b571b1346c85481899" title="Total number of frames of A/D data read, including consumed ones.">tot_frm</a>, cont-&gt;<a class="code" href="structcont__ad__t.html#a4ed32427e6a785b571b1346c85481899" title="Total number of frames of A/D data read, including consumed ones.">tot_frm</a> * cont-&gt;<a class="code" href="structcont__ad__t.html#a55f701abf33b5f68f9ef4cbf95dfaf73" title="Samples/frame; audio level is analyzed within frames.">spf</a>,
<a name="l00535"></a>00535            (cont-&gt;<a class="code" href="structcont__ad__t.html#a4ed32427e6a785b571b1346c85481899" title="Total number of frames of A/D data read, including consumed ones.">tot_frm</a> * cont-&gt;<a class="code" href="structcont__ad__t.html#a55f701abf33b5f68f9ef4cbf95dfaf73" title="Samples/frame; audio level is analyzed within frames.">spf</a>) / (float32) cont-&gt;<a class="code" href="structcont__ad__t.html#a11a4bb48870007b39f8fa46e4b8f111a" title="Samples/sec; moved from ad-&amp;gt;sps to break dependence on ad by N.">sps</a>);
<a name="l00536"></a>00536     <a class="code" href="err_8h.html#ac3c705943d946708cea0a1443be1c853" title="Print logging information to standard error stream.">E_INFO</a>(<span class="stringliteral">&quot;Total speech detected = %d samples, %.2f sec\n&quot;</span>,
<a name="l00537"></a>00537            total_speech_samples, total_speech_sec);
<a name="l00538"></a>00538 
<a name="l00539"></a>00539     <a class="code" href="cont__ad_8h.html#a381c3df971d43a20e8e8b8da43d2872d" title="Close the continuous listening object.">cont_ad_close</a>(cont);
<a name="l00540"></a>00540 
<a name="l00541"></a>00541     <span class="keywordflow">return</span> 0;
<a name="l00542"></a>00542 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>cont_fileseg.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>