Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 56b1fde4ed0e5f3d153fe0391e13cdf1 > files > 172

pocketsphinx-devel-0.7-1.fc14.x86_64.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>PocketSphinx: src/libpocketsphinx/pocketsphinx.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">PocketSphinx&#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="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('pocketsphinx_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>src/libpocketsphinx/pocketsphinx.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) 2008 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 
<a name="l00038"></a>00038 <span class="comment">/* System headers. */</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="comment">/* SphinxBase headers. */</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;sphinxbase/err.h&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;sphinxbase/strfuncs.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;sphinxbase/filename.h&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &lt;sphinxbase/pio.h&gt;</span>
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="comment">/* Local headers. */</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &quot;cmdln_macro.h&quot;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &quot;<a class="code" href="pocketsphinx__internal_8h.html" title="Internal implementation of PocketSphinx decoder.">pocketsphinx_internal.h</a>&quot;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &quot;<a class="code" href="ps__lattice__internal_8h.html" title="Word graph search implementation.">ps_lattice_internal.h</a>&quot;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &quot;<a class="code" href="phone__loop__search_8h.html" title="Fast and rough context-independent phoneme loop search.">phone_loop_search.h</a>&quot;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &quot;fsg_search_internal.h&quot;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &quot;<a class="code" href="ngram__search_8h.html" title="N-Gram based multi-pass search (&amp;quot;FBS&amp;quot;)">ngram_search.h</a>&quot;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &quot;<a class="code" href="ngram__search__fwdtree_8h.html" title="Lexicon tree based Viterbi search.">ngram_search_fwdtree.h</a>&quot;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &quot;<a class="code" href="ngram__search__fwdflat_8h.html" title="Flat lexicon based Viterbi search.">ngram_search_fwdflat.h</a>&quot;</span>
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 <span class="keyword">static</span> <span class="keyword">const</span> arg_t ps_args_def[] = {
<a name="l00059"></a>00059     POCKETSPHINX_OPTIONS,
<a name="l00060"></a>00060     CMDLN_EMPTY_OPTION
<a name="l00061"></a>00061 };
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">/* I&#39;m not sure what the portable way to do this is. */</span>
<a name="l00064"></a>00064 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00065"></a>00065 file_exists(<span class="keyword">const</span> <span class="keywordtype">char</span> *path)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067     FILE *tmp;
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     tmp = fopen(path, <span class="stringliteral">&quot;rb&quot;</span>);
<a name="l00070"></a>00070     <span class="keywordflow">if</span> (tmp) fclose(tmp);
<a name="l00071"></a>00071     <span class="keywordflow">return</span> (tmp != NULL);
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 
<a name="l00074"></a>00074 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00075"></a>00075 hmmdir_exists(<span class="keyword">const</span> <span class="keywordtype">char</span> *path)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077     FILE *tmp;
<a name="l00078"></a>00078     <span class="keywordtype">char</span> *mdef = string_join(path, <span class="stringliteral">&quot;/mdef&quot;</span>, NULL);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     tmp = fopen(mdef, <span class="stringliteral">&quot;rb&quot;</span>);
<a name="l00081"></a>00081     <span class="keywordflow">if</span> (tmp) fclose(tmp);
<a name="l00082"></a>00082     ckd_free(mdef);
<a name="l00083"></a>00083     <span class="keywordflow">return</span> (tmp != NULL);
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00087"></a>00087 ps_add_file(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keyword">const</span> <span class="keywordtype">char</span> *arg,
<a name="l00088"></a>00088             <span class="keyword">const</span> <span class="keywordtype">char</span> *hmmdir, <span class="keyword">const</span> <span class="keywordtype">char</span> *file)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090     <span class="keywordtype">char</span> *tmp = string_join(hmmdir, <span class="stringliteral">&quot;/&quot;</span>, file, NULL);
<a name="l00091"></a>00091 
<a name="l00092"></a>00092     <span class="keywordflow">if</span> (cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, arg) == NULL &amp;&amp; file_exists(tmp))
<a name="l00093"></a>00093         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, arg, tmp);
<a name="l00094"></a>00094     ckd_free(tmp);
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00098"></a>00098 ps_init_defaults(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100     <span class="keywordtype">char</span> <span class="keyword">const</span> *hmmdir, *lmfile, *dictfile;
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     <span class="comment">/* Disable memory mapping on Blackfin (FIXME: should be uClinux in general). */</span>
<a name="l00103"></a>00103 <span class="preprocessor">#ifdef __ADSPBLACKFIN__</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span>    E_INFO(<span class="stringliteral">&quot;Will not use mmap() on uClinux/Blackfin.&quot;</span>);
<a name="l00105"></a>00105     cmd_ln_set_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-mmap&quot;</span>, FALSE);
<a name="l00106"></a>00106 <span class="preprocessor">#endif</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span>
<a name="l00108"></a>00108 <span class="preprocessor">#ifdef MODELDIR</span>
<a name="l00109"></a>00109 <span class="preprocessor"></span>    <span class="comment">/* Set default acoustic and language models. */</span>
<a name="l00110"></a>00110     hmmdir = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-hmm&quot;</span>);
<a name="l00111"></a>00111     lmfile = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-lm&quot;</span>);
<a name="l00112"></a>00112     dictfile = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-dict&quot;</span>);
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (hmmdir == NULL &amp;&amp; hmmdir_exists(MODELDIR <span class="stringliteral">&quot;/hmm/en_US/hub4wsj_sc_8k&quot;</span>)) {
<a name="l00114"></a>00114         hmmdir = MODELDIR <span class="stringliteral">&quot;/hmm/en_US/hub4wsj_sc_8k&quot;</span>;
<a name="l00115"></a>00115         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-hmm&quot;</span>, hmmdir);
<a name="l00116"></a>00116     }
<a name="l00117"></a>00117     <span class="keywordflow">if</span> (lmfile == NULL &amp;&amp; !cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fsg&quot;</span>)
<a name="l00118"></a>00118         &amp;&amp; !cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-jsgf&quot;</span>)
<a name="l00119"></a>00119         &amp;&amp; file_exists(MODELDIR <span class="stringliteral">&quot;/lm/en_US/hub4.5000.DMP&quot;</span>)) {
<a name="l00120"></a>00120         lmfile = MODELDIR <span class="stringliteral">&quot;/lm/en_US/hub4.5000.DMP&quot;</span>;
<a name="l00121"></a>00121         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-lm&quot;</span>, lmfile);
<a name="l00122"></a>00122     }
<a name="l00123"></a>00123     <span class="keywordflow">if</span> (dictfile == NULL &amp;&amp; file_exists(MODELDIR <span class="stringliteral">&quot;/lm/en_US/cmu07a.dic&quot;</span>)) {
<a name="l00124"></a>00124         dictfile = MODELDIR <span class="stringliteral">&quot;/lm/en_US/cmu07a.dic&quot;</span>;
<a name="l00125"></a>00125         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-dict&quot;</span>, dictfile);
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     <span class="comment">/* Expand acoustic and language model filenames relative to installation path. */</span>
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (hmmdir &amp;&amp; !path_is_absolute(hmmdir) &amp;&amp; !hmmdir_exists(hmmdir)) {
<a name="l00130"></a>00130         <span class="keywordtype">char</span> *tmphmm = string_join(MODELDIR <span class="stringliteral">&quot;/hmm/&quot;</span>, hmmdir, NULL);
<a name="l00131"></a>00131         <span class="keywordflow">if</span> (hmmdir_exists(tmphmm)) {
<a name="l00132"></a>00132             cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-hmm&quot;</span>, tmphmm);
<a name="l00133"></a>00133         } <span class="keywordflow">else</span> {
<a name="l00134"></a>00134             E_ERROR(<span class="stringliteral">&quot;Failed to find mdef file inside the model folder specified with -hmm &#39;%s&#39;\n&quot;</span>, hmmdir);
<a name="l00135"></a>00135         }
<a name="l00136"></a>00136         ckd_free(tmphmm);
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     <span class="keywordflow">if</span> (lmfile &amp;&amp; !path_is_absolute(lmfile) &amp;&amp; !file_exists(lmfile)) {
<a name="l00139"></a>00139         <span class="keywordtype">char</span> *tmplm = string_join(MODELDIR <span class="stringliteral">&quot;/lm/&quot;</span>, lmfile, NULL);
<a name="l00140"></a>00140         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-lm&quot;</span>, tmplm);
<a name="l00141"></a>00141         ckd_free(tmplm);
<a name="l00142"></a>00142     }
<a name="l00143"></a>00143     <span class="keywordflow">if</span> (dictfile &amp;&amp; !path_is_absolute(dictfile) &amp;&amp; !file_exists(dictfile)) {
<a name="l00144"></a>00144         <span class="keywordtype">char</span> *tmpdict = string_join(MODELDIR <span class="stringliteral">&quot;/lm/&quot;</span>, dictfile, NULL);
<a name="l00145"></a>00145         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-dict&quot;</span>, tmpdict);
<a name="l00146"></a>00146         ckd_free(tmpdict);
<a name="l00147"></a>00147     }
<a name="l00148"></a>00148 <span class="preprocessor">#endif</span>
<a name="l00149"></a>00149 <span class="preprocessor"></span>
<a name="l00150"></a>00150     <span class="comment">/* Get acoustic model filenames and add them to the command-line */</span>
<a name="l00151"></a>00151     <span class="keywordflow">if</span> ((hmmdir = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-hmm&quot;</span>)) != NULL) {
<a name="l00152"></a>00152         ps_add_file(ps, <span class="stringliteral">&quot;-mdef&quot;</span>, hmmdir, <span class="stringliteral">&quot;mdef&quot;</span>);
<a name="l00153"></a>00153         ps_add_file(ps, <span class="stringliteral">&quot;-mean&quot;</span>, hmmdir, <span class="stringliteral">&quot;means&quot;</span>);
<a name="l00154"></a>00154         ps_add_file(ps, <span class="stringliteral">&quot;-var&quot;</span>, hmmdir, <span class="stringliteral">&quot;variances&quot;</span>);
<a name="l00155"></a>00155         ps_add_file(ps, <span class="stringliteral">&quot;-tmat&quot;</span>, hmmdir, <span class="stringliteral">&quot;transition_matrices&quot;</span>);
<a name="l00156"></a>00156         ps_add_file(ps, <span class="stringliteral">&quot;-mixw&quot;</span>, hmmdir, <span class="stringliteral">&quot;mixture_weights&quot;</span>);
<a name="l00157"></a>00157         ps_add_file(ps, <span class="stringliteral">&quot;-sendump&quot;</span>, hmmdir, <span class="stringliteral">&quot;sendump&quot;</span>);
<a name="l00158"></a>00158         ps_add_file(ps, <span class="stringliteral">&quot;-fdict&quot;</span>, hmmdir, <span class="stringliteral">&quot;noisedict&quot;</span>);
<a name="l00159"></a>00159         ps_add_file(ps, <span class="stringliteral">&quot;-lda&quot;</span>, hmmdir, <span class="stringliteral">&quot;feature_transform&quot;</span>);
<a name="l00160"></a>00160         ps_add_file(ps, <span class="stringliteral">&quot;-featparams&quot;</span>, hmmdir, <span class="stringliteral">&quot;feat.params&quot;</span>);
<a name="l00161"></a>00161         ps_add_file(ps, <span class="stringliteral">&quot;-senmgau&quot;</span>, hmmdir, <span class="stringliteral">&quot;senmgau&quot;</span>);
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00166"></a>00166 ps_free_searches(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168     gnode_t *gn;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> == NULL)
<a name="l00171"></a>00171         <span class="keywordflow">return</span>;
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="keywordflow">for</span> (gn = ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>; gn; gn = gnode_next(gn))
<a name="l00174"></a>00174         ps_search_free(gnode_ptr(gn));
<a name="l00175"></a>00175     glist_free(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>);
<a name="l00176"></a>00176     ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = NULL;
<a name="l00177"></a>00177     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> = NULL;
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 <span class="keyword">static</span> <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *
<a name="l00181"></a>00181 ps_find_search(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">char</span> <span class="keyword">const</span> *name)
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183     gnode_t *gn;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185     <span class="keywordflow">for</span> (gn = ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>; gn; gn = gnode_next(gn)) {
<a name="l00186"></a>00186         <span class="keywordflow">if</span> (0 == strcmp(ps_search_name(gnode_ptr(gn)), name))
<a name="l00187"></a>00187             <span class="keywordflow">return</span> (<a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *)gnode_ptr(gn);
<a name="l00188"></a>00188     }
<a name="l00189"></a>00189     <span class="keywordflow">return</span> NULL;
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192 <span class="keywordtype">int</span>
<a name="l00193"></a><a class="code" href="pocketsphinx_8h.html#a391679e7edb0de1e324aa302ee820287">00193</a> <a class="code" href="pocketsphinx_8h.html#a391679e7edb0de1e324aa302ee820287" title="Reinitialize the decoder with updated configuration.">ps_reinit</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, cmd_ln_t *config)
<a name="l00194"></a>00194 {
<a name="l00195"></a>00195     <span class="keywordtype">char</span> <span class="keyword">const</span> *lmfile, *lmctl = NULL;
<a name="l00196"></a>00196 
<a name="l00197"></a>00197     <span class="keywordflow">if</span> (config &amp;&amp; config != ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>) {
<a name="l00198"></a>00198         cmd_ln_free_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>);
<a name="l00199"></a>00199         ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a> = config;
<a name="l00200"></a>00200     }
<a name="l00201"></a>00201 <span class="preprocessor">#ifndef _WIN32_WCE</span>
<a name="l00202"></a>00202 <span class="preprocessor"></span>    <span class="comment">/* Set up logging. */</span>
<a name="l00203"></a>00203     <span class="keywordflow">if</span> (cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-logfn&quot;</span>))
<a name="l00204"></a>00204         err_set_logfile(cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-logfn&quot;</span>));
<a name="l00205"></a>00205 <span class="preprocessor">#endif</span>
<a name="l00206"></a>00206 <span class="preprocessor"></span>    err_set_debug_level(cmd_ln_int32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-debug&quot;</span>));
<a name="l00207"></a>00207     ps-&gt;<a class="code" href="structps__decoder__s.html#a8bb5ef8791798b8dd9bc82b1ec016663" title="Log directory for MFCC files.">mfclogdir</a> = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-mfclogdir&quot;</span>);
<a name="l00208"></a>00208     ps-&gt;<a class="code" href="structps__decoder__s.html#aa2610c52a9267ee18ca095169bf34bfd" title="Log directory for audio files.">rawlogdir</a> = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-rawlogdir&quot;</span>);
<a name="l00209"></a>00209     ps-&gt;<a class="code" href="structps__decoder__s.html#a0ed3476113fe3d63b13ac5e8da3f3b4f" title="Log directory for senone score files.">senlogdir</a> = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-senlogdir&quot;</span>);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     <span class="comment">/* Fill in some default arguments. */</span>
<a name="l00212"></a>00212     ps_init_defaults(ps);
<a name="l00213"></a>00213 
<a name="l00214"></a>00214     <span class="comment">/* Free old searches (do this before other reinit) */</span>
<a name="l00215"></a>00215     ps_free_searches(ps);
<a name="l00216"></a>00216 
<a name="l00217"></a>00217     <span class="comment">/* Free old acmod. */</span>
<a name="l00218"></a>00218     <a class="code" href="acmod_8c.html#a1e3345e8ef8b060fc04e88f86e6afa4a" title="Finalize an acoustic model.">acmod_free</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>);
<a name="l00219"></a>00219     ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a> = NULL;
<a name="l00220"></a>00220 
<a name="l00221"></a>00221     <span class="comment">/* Free old dictionary (must be done after the two things above) */</span>
<a name="l00222"></a>00222     dict_free(ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>);
<a name="l00223"></a>00223     ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a> = NULL;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 
<a name="l00226"></a>00226     <span class="comment">/* Logmath computation (used in acmod and search) */</span>
<a name="l00227"></a>00227     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a> == NULL
<a name="l00228"></a>00228         || (logmath_get_base(ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>) != 
<a name="l00229"></a>00229             (float64)cmd_ln_float32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-logbase&quot;</span>))) {
<a name="l00230"></a>00230         <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>)
<a name="l00231"></a>00231             logmath_free(ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>);
<a name="l00232"></a>00232         ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a> = logmath_init
<a name="l00233"></a>00233             ((float64)cmd_ln_float32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-logbase&quot;</span>), 0,
<a name="l00234"></a>00234              cmd_ln_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-bestpath&quot;</span>));
<a name="l00235"></a>00235     }
<a name="l00236"></a>00236 
<a name="l00237"></a>00237     <span class="comment">/* Acoustic model (this is basically everything that</span>
<a name="l00238"></a>00238 <span class="comment">     * uttproc.c, senscr.c, and others used to do) */</span>
<a name="l00239"></a>00239     <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a> = <a class="code" href="acmod_8c.html#a6f32b623cbc3d15a1e3c5d09aba7dabf" title="Initialize an acoustic model.">acmod_init</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>, NULL, NULL)) == NULL)
<a name="l00240"></a>00240         <span class="keywordflow">return</span> -1;
<a name="l00241"></a>00241     <span class="comment">/* Make the acmod&#39;s feature buffer growable if we are doing two-pass search. */</span>
<a name="l00242"></a>00242     <span class="keywordflow">if</span> (cmd_ln_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fwdflat&quot;</span>)
<a name="l00243"></a>00243         &amp;&amp; cmd_ln_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fwdtree&quot;</span>))
<a name="l00244"></a>00244         <a class="code" href="acmod_8c.html#a1555dac8fa27f644d709c5c89bbfa881" title="Set memory allocation policy for utterance processing.">acmod_set_grow</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, TRUE);
<a name="l00245"></a>00245 
<a name="l00246"></a>00246     <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#a0f0a6681ffd98af789f6bed556c814e4" title="Window size for phoneme lookahead.">pl_window</a> = cmd_ln_int32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-pl_window&quot;</span>))) {
<a name="l00247"></a>00247         <span class="comment">/* Initialize an auxiliary phone loop search, which will run in</span>
<a name="l00248"></a>00248 <span class="comment">         * &quot;parallel&quot; with FSG or N-Gram search. */</span>
<a name="l00249"></a>00249         <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a> = phone_loop_search_init(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>,
<a name="l00250"></a>00250                                                      ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>)) == NULL)
<a name="l00251"></a>00251             <span class="keywordflow">return</span> -1;
<a name="l00252"></a>00252         ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = glist_add_ptr(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>);
<a name="l00253"></a>00253     }
<a name="l00254"></a>00254 
<a name="l00255"></a>00255     <span class="comment">/* Dictionary and triphone mappings (depends on acmod). */</span>
<a name="l00256"></a>00256     <span class="comment">/* FIXME: pass config, change arguments, implement LTS, etc. */</span>
<a name="l00257"></a>00257     <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a> = dict_init(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>)) == NULL)
<a name="l00258"></a>00258         <span class="keywordflow">return</span> -1;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260     <span class="comment">/* Determine whether we are starting out in FSG or N-Gram search mode. */</span>
<a name="l00261"></a>00261     <span class="keywordflow">if</span> (cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fsg&quot;</span>) || cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-jsgf&quot;</span>)) {
<a name="l00262"></a>00262         <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *fsgs;
<a name="l00263"></a>00263 
<a name="l00264"></a>00264         <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a> = <a class="code" href="dict2pid_8c.html#addd541f2275b79e284575fb11b7986e1" title="Build the dict2pid structure for the given model/dictionary.">dict2pid_build</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>)) == NULL)
<a name="l00265"></a>00265             <span class="keywordflow">return</span> -1;
<a name="l00266"></a>00266         <span class="keywordflow">if</span> ((fsgs = fsg_search_init(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>)) == NULL)
<a name="l00267"></a>00267             <span class="keywordflow">return</span> -1;
<a name="l00268"></a>00268         fsgs-&gt;<a class="code" href="structps__search__s.html#a2a33b7698fb237b42e007788f65cd46c" title="Phoneme loop for lookahead.">pls</a> = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>;
<a name="l00269"></a>00269         ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = glist_add_ptr(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>, fsgs);
<a name="l00270"></a>00270         ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> = fsgs;
<a name="l00271"></a>00271     }
<a name="l00272"></a>00272     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((lmfile = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-lm&quot;</span>))
<a name="l00273"></a>00273              || (lmctl = cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-lmctl&quot;</span>))) {
<a name="l00274"></a>00274         <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *ngs;
<a name="l00275"></a>00275 
<a name="l00276"></a>00276         <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a> = <a class="code" href="dict2pid_8c.html#addd541f2275b79e284575fb11b7986e1" title="Build the dict2pid structure for the given model/dictionary.">dict2pid_build</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>)) == NULL)
<a name="l00277"></a>00277             <span class="keywordflow">return</span> -1;
<a name="l00278"></a>00278         <span class="keywordflow">if</span> ((ngs = <a class="code" href="ngram__search_8c.html#afa0dcbb86340083bce1412c9309742bc" title="Initialize the N-Gram search module.">ngram_search_init</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>)) == NULL)
<a name="l00279"></a>00279             <span class="keywordflow">return</span> -1;
<a name="l00280"></a>00280         ngs-&gt;<a class="code" href="structps__search__s.html#a2a33b7698fb237b42e007788f65cd46c" title="Phoneme loop for lookahead.">pls</a> = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>;
<a name="l00281"></a>00281         ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = glist_add_ptr(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>, ngs);
<a name="l00282"></a>00282         ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> = ngs;
<a name="l00283"></a>00283     }
<a name="l00284"></a>00284     <span class="comment">/* Otherwise, we will initialize the search whenever the user</span>
<a name="l00285"></a>00285 <span class="comment">     * decides to load an FSG or a language model. */</span>
<a name="l00286"></a>00286     <span class="keywordflow">else</span> {
<a name="l00287"></a>00287         <span class="keywordflow">if</span> ((ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a> = <a class="code" href="dict2pid_8c.html#addd541f2275b79e284575fb11b7986e1" title="Build the dict2pid structure for the given model/dictionary.">dict2pid_build</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>)) == NULL)
<a name="l00288"></a>00288             <span class="keywordflow">return</span> -1;
<a name="l00289"></a>00289     }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291     <span class="comment">/* Initialize performance timer. */</span>
<a name="l00292"></a>00292     ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>.name = <span class="stringliteral">&quot;decode&quot;</span>;
<a name="l00293"></a>00293     ptmr_init(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00294"></a>00294 
<a name="l00295"></a>00295     <span class="keywordflow">return</span> 0;
<a name="l00296"></a>00296 }
<a name="l00297"></a>00297 
<a name="l00298"></a>00298 <a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *
<a name="l00299"></a><a class="code" href="pocketsphinx_8h.html#ad033da98d0f7785d6ab89a41dac3cc7c">00299</a> <a class="code" href="pocketsphinx_8h.html#ad033da98d0f7785d6ab89a41dac3cc7c" title="Initialize the decoder from a configuration object.">ps_init</a>(cmd_ln_t *config)
<a name="l00300"></a>00300 {
<a name="l00301"></a>00301     <a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps;
<a name="l00302"></a>00302 
<a name="l00303"></a>00303     ps = ckd_calloc(1, <span class="keyword">sizeof</span>(*ps));
<a name="l00304"></a>00304     ps-&gt;<a class="code" href="structps__decoder__s.html#aa5ab90180288b6c9039eb86b496f76aa" title="Reference count.">refcount</a> = 1;
<a name="l00305"></a>00305     <span class="keywordflow">if</span> (<a class="code" href="pocketsphinx_8h.html#a391679e7edb0de1e324aa302ee820287" title="Reinitialize the decoder with updated configuration.">ps_reinit</a>(ps, config) &lt; 0) {
<a name="l00306"></a>00306         <a class="code" href="pocketsphinx_8h.html#ad8fd9b79ae9f87703af3f4755b3ab567" title="Finalize the decoder.">ps_free</a>(ps);
<a name="l00307"></a>00307         <span class="keywordflow">return</span> NULL;
<a name="l00308"></a>00308     }
<a name="l00309"></a>00309     <span class="keywordflow">return</span> ps;
<a name="l00310"></a>00310 }
<a name="l00311"></a>00311 
<a name="l00312"></a>00312 arg_t <span class="keyword">const</span> *
<a name="l00313"></a><a class="code" href="pocketsphinx_8h.html#ad873ea6e20f91a3284963d5c34331c58">00313</a> <a class="code" href="pocketsphinx_8h.html#ad873ea6e20f91a3284963d5c34331c58" title="Returns the argument definitions used in ps_init().">ps_args</a>(<span class="keywordtype">void</span>)
<a name="l00314"></a>00314 {
<a name="l00315"></a>00315     <span class="keywordflow">return</span> ps_args_def;
<a name="l00316"></a>00316 }
<a name="l00317"></a>00317 
<a name="l00318"></a>00318 <a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *
<a name="l00319"></a><a class="code" href="pocketsphinx_8h.html#a8d912ce9a5fea61b7b10db1750531c34">00319</a> <a class="code" href="pocketsphinx_8h.html#a8d912ce9a5fea61b7b10db1750531c34" title="Retain a pointer to the decoder.">ps_retain</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00320"></a>00320 {
<a name="l00321"></a>00321     ++ps-&gt;<a class="code" href="structps__decoder__s.html#aa5ab90180288b6c9039eb86b496f76aa" title="Reference count.">refcount</a>;
<a name="l00322"></a>00322     <span class="keywordflow">return</span> ps;
<a name="l00323"></a>00323 }
<a name="l00324"></a>00324 
<a name="l00325"></a>00325 <span class="keywordtype">int</span>
<a name="l00326"></a><a class="code" href="pocketsphinx_8h.html#ad8fd9b79ae9f87703af3f4755b3ab567">00326</a> <a class="code" href="pocketsphinx_8h.html#ad8fd9b79ae9f87703af3f4755b3ab567" title="Finalize the decoder.">ps_free</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00327"></a>00327 {
<a name="l00328"></a>00328     gnode_t *gn;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     <span class="keywordflow">if</span> (ps == NULL)
<a name="l00331"></a>00331         <span class="keywordflow">return</span> 0;
<a name="l00332"></a>00332     <span class="keywordflow">if</span> (--ps-&gt;<a class="code" href="structps__decoder__s.html#aa5ab90180288b6c9039eb86b496f76aa" title="Reference count.">refcount</a> &gt; 0)
<a name="l00333"></a>00333         <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#aa5ab90180288b6c9039eb86b496f76aa" title="Reference count.">refcount</a>;
<a name="l00334"></a>00334     <span class="keywordflow">for</span> (gn = ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>; gn; gn = gnode_next(gn))
<a name="l00335"></a>00335         ps_search_free(gnode_ptr(gn));
<a name="l00336"></a>00336     glist_free(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>);
<a name="l00337"></a>00337     dict_free(ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>);
<a name="l00338"></a>00338     <a class="code" href="dict2pid_8c.html#a293253226550e812c448ae096b364d0d" title="Free the memory dict2pid structure.">dict2pid_free</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>);
<a name="l00339"></a>00339     <a class="code" href="acmod_8c.html#a1e3345e8ef8b060fc04e88f86e6afa4a" title="Finalize an acoustic model.">acmod_free</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>);
<a name="l00340"></a>00340     logmath_free(ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>);
<a name="l00341"></a>00341     cmd_ln_free_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>);
<a name="l00342"></a>00342     ckd_free(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>);
<a name="l00343"></a>00343     ckd_free(ps);
<a name="l00344"></a>00344     <span class="keywordflow">return</span> 0;
<a name="l00345"></a>00345 }
<a name="l00346"></a>00346 
<a name="l00347"></a>00347 <span class="keywordtype">char</span> <span class="keyword">const</span> *
<a name="l00348"></a><a class="code" href="pocketsphinx_8h.html#a4a949fc555734d1e1b9f6fd4a19008c2">00348</a> <a class="code" href="pocketsphinx_8h.html#a4a949fc555734d1e1b9f6fd4a19008c2" title="Get current utterance ID.">ps_get_uttid</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>;
<a name="l00351"></a>00351 }
<a name="l00352"></a>00352 
<a name="l00353"></a>00353 cmd_ln_t *
<a name="l00354"></a><a class="code" href="pocketsphinx_8h.html#abb9256d8f7217a1e929509090df1f35b">00354</a> <a class="code" href="pocketsphinx_8h.html#abb9256d8f7217a1e929509090df1f35b" title="Get the configuration object for this decoder.">ps_get_config</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00355"></a>00355 {
<a name="l00356"></a>00356     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>;
<a name="l00357"></a>00357 }
<a name="l00358"></a>00358 
<a name="l00359"></a>00359 logmath_t *
<a name="l00360"></a><a class="code" href="pocketsphinx_8h.html#a249cfc383b7d9111a28b550945a606b5">00360</a> <a class="code" href="pocketsphinx_8h.html#a249cfc383b7d9111a28b550945a606b5" title="Get the log-math computation object for this decoder.">ps_get_logmath</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00361"></a>00361 {
<a name="l00362"></a>00362     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#abd17fe329f2fb219c5a534f3217c5b95" title="Log math computation.">lmath</a>;
<a name="l00363"></a>00363 }
<a name="l00364"></a>00364 
<a name="l00365"></a>00365 fe_t *
<a name="l00366"></a><a class="code" href="pocketsphinx_8h.html#a6237e2822756f230b88019b533a28724">00366</a> <a class="code" href="pocketsphinx_8h.html#a6237e2822756f230b88019b533a28724" title="Get the feature extraction object for this decoder.">ps_get_fe</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00367"></a>00367 {
<a name="l00368"></a>00368     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a56eaceb9b6a1cbcccd09cf42cfa87231" title="Acoustic feature computation.">fe</a>;
<a name="l00369"></a>00369 }
<a name="l00370"></a>00370 
<a name="l00371"></a>00371 feat_t *
<a name="l00372"></a><a class="code" href="pocketsphinx_8h.html#a0d74d90f0db0782386487cc061a09218">00372</a> <a class="code" href="pocketsphinx_8h.html#a0d74d90f0db0782386487cc061a09218" title="Get the dynamic feature computation object for this decoder.">ps_get_feat</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00373"></a>00373 {
<a name="l00374"></a>00374     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a37ec6c2b1f3ada764842e08481239b34" title="Dynamic feature computation.">fcb</a>;
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376 
<a name="l00377"></a>00377 <a class="code" href="structps__mllr__s.html" title="Feature space linear transform structure.">ps_mllr_t</a> *
<a name="l00378"></a><a class="code" href="pocketsphinx_8h.html#a85e04bcbf5366f1bdad555dbb4d73d5d">00378</a> <a class="code" href="pocketsphinx_8h.html#a85e04bcbf5366f1bdad555dbb4d73d5d" title="Adapt current acoustic model using a linear transform.">ps_update_mllr</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <a class="code" href="structps__mllr__s.html" title="Feature space linear transform structure.">ps_mllr_t</a> *mllr)
<a name="l00379"></a>00379 {
<a name="l00380"></a>00380     <span class="keywordflow">return</span> <a class="code" href="acmod_8c.html#a4205b92d38db562577eafc3c432593ab" title="Adapt acoustic model using a linear transform.">acmod_update_mllr</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, mllr);
<a name="l00381"></a>00381 }
<a name="l00382"></a>00382 
<a name="l00383"></a>00383 ngram_model_t *
<a name="l00384"></a><a class="code" href="pocketsphinx_8h.html#ab9e59bf2ebf2aa1a6a781371685f8740">00384</a> <a class="code" href="pocketsphinx_8h.html#ab9e59bf2ebf2aa1a6a781371685f8740" title="Get the language model set object for this decoder.">ps_get_lmset</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00385"></a>00385 {
<a name="l00386"></a>00386     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> == NULL
<a name="l00387"></a>00387         || 0 != strcmp(ps_search_name(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>), <span class="stringliteral">&quot;ngram&quot;</span>))
<a name="l00388"></a>00388         <span class="keywordflow">return</span> NULL;
<a name="l00389"></a>00389     <span class="keywordflow">return</span> ((<a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *)ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>)-&gt;lmset;
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391 
<a name="l00392"></a>00392 ngram_model_t *
<a name="l00393"></a><a class="code" href="pocketsphinx_8h.html#ae00bebeadaa6fc6fa8eb93b450651dc5">00393</a> <a class="code" href="pocketsphinx_8h.html#ae00bebeadaa6fc6fa8eb93b450651dc5" title="Update the language model set object for this decoder.">ps_update_lmset</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, ngram_model_t *lmset)
<a name="l00394"></a>00394 {
<a name="l00395"></a>00395     <a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *ngs;
<a name="l00396"></a>00396     <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search;
<a name="l00397"></a>00397 
<a name="l00398"></a>00398     <span class="comment">/* Look for N-Gram search. */</span>
<a name="l00399"></a>00399     search = ps_find_search(ps, <span class="stringliteral">&quot;ngram&quot;</span>);
<a name="l00400"></a>00400     <span class="keywordflow">if</span> (search == NULL) {
<a name="l00401"></a>00401         <span class="comment">/* Initialize N-Gram search. */</span>
<a name="l00402"></a>00402         search = <a class="code" href="ngram__search_8c.html#afa0dcbb86340083bce1412c9309742bc" title="Initialize the N-Gram search module.">ngram_search_init</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>);
<a name="l00403"></a>00403         <span class="keywordflow">if</span> (search == NULL)
<a name="l00404"></a>00404             <span class="keywordflow">return</span> NULL;
<a name="l00405"></a>00405         search-&gt;<a class="code" href="structps__search__s.html#a2a33b7698fb237b42e007788f65cd46c" title="Phoneme loop for lookahead.">pls</a> = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>;
<a name="l00406"></a>00406         ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = glist_add_ptr(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>, search);
<a name="l00407"></a>00407         ngs = (<a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *)search;
<a name="l00408"></a>00408     }
<a name="l00409"></a>00409     <span class="keywordflow">else</span> {
<a name="l00410"></a>00410         ngs = (<a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *)search;
<a name="l00411"></a>00411         <span class="comment">/* Free any previous lmset if this is a new one. */</span>
<a name="l00412"></a>00412         <span class="keywordflow">if</span> (ngs-&gt;<a class="code" href="structngram__search__s.html#a6127a6d8fb53832e67456c11aa6ad9c4" title="Set of language models.">lmset</a> != NULL &amp;&amp; ngs-&gt;<a class="code" href="structngram__search__s.html#a6127a6d8fb53832e67456c11aa6ad9c4" title="Set of language models.">lmset</a> != lmset)
<a name="l00413"></a>00413             ngram_model_free(ngs-&gt;<a class="code" href="structngram__search__s.html#a6127a6d8fb53832e67456c11aa6ad9c4" title="Set of language models.">lmset</a>);
<a name="l00414"></a>00414         ngs-&gt;<a class="code" href="structngram__search__s.html#a6127a6d8fb53832e67456c11aa6ad9c4" title="Set of language models.">lmset</a> = lmset;
<a name="l00415"></a>00415         <span class="comment">/* Tell N-Gram search to update its view of the world. */</span>
<a name="l00416"></a>00416         <span class="keywordflow">if</span> (ps_search_reinit(search, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>) &lt; 0)
<a name="l00417"></a>00417             <span class="keywordflow">return</span> NULL;
<a name="l00418"></a>00418     }
<a name="l00419"></a>00419     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> = search;
<a name="l00420"></a>00420     <span class="keywordflow">return</span> ngs-&gt;<a class="code" href="structngram__search__s.html#a6127a6d8fb53832e67456c11aa6ad9c4" title="Set of language models.">lmset</a>;
<a name="l00421"></a>00421 }
<a name="l00422"></a>00422 
<a name="l00423"></a>00423 <a class="code" href="structfsg__search__s.html" title="Implementation of FSG search (and &amp;quot;FSG set&amp;quot;) structure.">fsg_set_t</a> *
<a name="l00424"></a><a class="code" href="pocketsphinx_8h.html#a784b72a30fc7ec25e26a0380df46f8be">00424</a> <a class="code" href="pocketsphinx_8h.html#a784b72a30fc7ec25e26a0380df46f8be" title="Get the finite-state grammar set object for this decoder.">ps_get_fsgset</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00425"></a>00425 {
<a name="l00426"></a>00426     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> == NULL
<a name="l00427"></a>00427         || 0 != strcmp(ps_search_name(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>), <span class="stringliteral">&quot;fsg&quot;</span>))
<a name="l00428"></a>00428         <span class="keywordflow">return</span> NULL;
<a name="l00429"></a>00429     <span class="keywordflow">return</span> (<a class="code" href="structfsg__search__s.html" title="Implementation of FSG search (and &amp;quot;FSG set&amp;quot;) structure.">fsg_set_t</a> *)ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>;
<a name="l00430"></a>00430 }
<a name="l00431"></a>00431 
<a name="l00432"></a>00432 <a class="code" href="structfsg__search__s.html" title="Implementation of FSG search (and &amp;quot;FSG set&amp;quot;) structure.">fsg_set_t</a> *
<a name="l00433"></a><a class="code" href="pocketsphinx_8h.html#a3aaadef189cda344cd109c3110606aba">00433</a> <a class="code" href="pocketsphinx_8h.html#a3aaadef189cda344cd109c3110606aba" title="Update the finite-state grammar set object for this decoder.">ps_update_fsgset</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00434"></a>00434 {
<a name="l00435"></a>00435     <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search;
<a name="l00436"></a>00436 
<a name="l00437"></a>00437     <span class="comment">/* Look for FSG search. */</span>
<a name="l00438"></a>00438     search = ps_find_search(ps, <span class="stringliteral">&quot;fsg&quot;</span>);
<a name="l00439"></a>00439     <span class="keywordflow">if</span> (search == NULL) {
<a name="l00440"></a>00440         <span class="comment">/* Initialize FSG search. */</span>
<a name="l00441"></a>00441         search = fsg_search_init(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>,
<a name="l00442"></a>00442                                  ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>);
<a name="l00443"></a>00443         search-&gt;<a class="code" href="structps__search__s.html#a2a33b7698fb237b42e007788f65cd46c" title="Phoneme loop for lookahead.">pls</a> = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>;
<a name="l00444"></a>00444         ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a> = glist_add_ptr(ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>, search);
<a name="l00445"></a>00445     }
<a name="l00446"></a>00446     <span class="keywordflow">else</span> {
<a name="l00447"></a>00447         <span class="comment">/* Tell FSG search to update its view of the world. */</span>
<a name="l00448"></a>00448         <span class="keywordflow">if</span> (ps_search_reinit(search, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>) &lt; 0)
<a name="l00449"></a>00449             <span class="keywordflow">return</span> NULL;
<a name="l00450"></a>00450     }
<a name="l00451"></a>00451     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> = search;
<a name="l00452"></a>00452     <span class="keywordflow">return</span> (<a class="code" href="structfsg__search__s.html" title="Implementation of FSG search (and &amp;quot;FSG set&amp;quot;) structure.">fsg_set_t</a> *)search;
<a name="l00453"></a>00453 }
<a name="l00454"></a>00454 
<a name="l00455"></a>00455 <span class="keywordtype">int</span>
<a name="l00456"></a><a class="code" href="pocketsphinx_8h.html#a824f46e51681d931b7e2706a86c3d86f">00456</a> <a class="code" href="pocketsphinx_8h.html#a824f46e51681d931b7e2706a86c3d86f" title="Reload the pronunciation dictionary from a file.">ps_load_dict</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">char</span> <span class="keyword">const</span> *dictfile,
<a name="l00457"></a>00457              <span class="keywordtype">char</span> <span class="keyword">const</span> *fdictfile, <span class="keywordtype">char</span> <span class="keyword">const</span> *format)
<a name="l00458"></a>00458 {
<a name="l00459"></a>00459     cmd_ln_t *newconfig;
<a name="l00460"></a>00460     <a class="code" href="structdict2pid__t.html" title="Building composite triphone (as well as word internal triphones) with the dictionary.">dict2pid_t</a> *d2p;
<a name="l00461"></a>00461     <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *dict;
<a name="l00462"></a>00462     gnode_t *gn;
<a name="l00463"></a>00463     <span class="keywordtype">int</span> rv;
<a name="l00464"></a>00464 
<a name="l00465"></a>00465     <span class="comment">/* Create a new scratch config to load this dict (so existing one</span>
<a name="l00466"></a>00466 <span class="comment">     * won&#39;t be affected if it fails) */</span>
<a name="l00467"></a>00467     newconfig = cmd_ln_init(NULL, <a class="code" href="pocketsphinx_8h.html#ad873ea6e20f91a3284963d5c34331c58" title="Returns the argument definitions used in ps_init().">ps_args</a>(), TRUE, NULL);
<a name="l00468"></a>00468     cmd_ln_set_boolean_r(newconfig, <span class="stringliteral">&quot;-dictcase&quot;</span>,
<a name="l00469"></a>00469                          cmd_ln_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-dictcase&quot;</span>));
<a name="l00470"></a>00470     cmd_ln_set_str_r(newconfig, <span class="stringliteral">&quot;-dict&quot;</span>, dictfile);
<a name="l00471"></a>00471     <span class="keywordflow">if</span> (fdictfile)
<a name="l00472"></a>00472         cmd_ln_set_str_r(newconfig, <span class="stringliteral">&quot;-fdict&quot;</span>, fdictfile);
<a name="l00473"></a>00473     <span class="keywordflow">else</span>
<a name="l00474"></a>00474         cmd_ln_set_str_r(newconfig, <span class="stringliteral">&quot;-fdict&quot;</span>,
<a name="l00475"></a>00475                          cmd_ln_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fdict&quot;</span>));
<a name="l00476"></a>00476 
<a name="l00477"></a>00477     <span class="comment">/* Try to load it. */</span>
<a name="l00478"></a>00478     <span class="keywordflow">if</span> ((dict = dict_init(newconfig, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>)) == NULL) {
<a name="l00479"></a>00479         cmd_ln_free_r(newconfig);
<a name="l00480"></a>00480         <span class="keywordflow">return</span> -1;
<a name="l00481"></a>00481     }
<a name="l00482"></a>00482 
<a name="l00483"></a>00483     <span class="comment">/* Reinit the dict2pid. */</span>
<a name="l00484"></a>00484     <span class="keywordflow">if</span> ((d2p = <a class="code" href="dict2pid_8c.html#addd541f2275b79e284575fb11b7986e1" title="Build the dict2pid structure for the given model/dictionary.">dict2pid_build</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>, dict)) == NULL) {
<a name="l00485"></a>00485         cmd_ln_free_r(newconfig);
<a name="l00486"></a>00486         <span class="keywordflow">return</span> -1;
<a name="l00487"></a>00487     }
<a name="l00488"></a>00488 
<a name="l00489"></a>00489     <span class="comment">/* Success!  Update the existing config to reflect new dicts and</span>
<a name="l00490"></a>00490 <span class="comment">     * drop everything into place. */</span>
<a name="l00491"></a>00491     cmd_ln_free_r(newconfig);
<a name="l00492"></a>00492     cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-dict&quot;</span>, dictfile);
<a name="l00493"></a>00493     <span class="keywordflow">if</span> (fdictfile)
<a name="l00494"></a>00494         cmd_ln_set_str_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-fdict&quot;</span>, fdictfile);
<a name="l00495"></a>00495     dict_free(ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>);
<a name="l00496"></a>00496     ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a> = dict;
<a name="l00497"></a>00497     <a class="code" href="dict2pid_8c.html#a293253226550e812c448ae096b364d0d" title="Free the memory dict2pid structure.">dict2pid_free</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>);
<a name="l00498"></a>00498     ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a> = d2p;
<a name="l00499"></a>00499 
<a name="l00500"></a>00500     <span class="comment">/* And tell all searches to reconfigure themselves. */</span>
<a name="l00501"></a>00501     <span class="keywordflow">for</span> (gn = ps-&gt;<a class="code" href="structps__decoder__s.html#aa04a75334c8bc39c6e1dc4b1de1d760f" title="List of search modules.">searches</a>; gn; gn = gnode_next(gn)) {
<a name="l00502"></a>00502         <a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search = gnode_ptr(gn);
<a name="l00503"></a>00503         <span class="keywordflow">if</span> ((rv = ps_search_reinit(search, dict, d2p)) &lt; 0)
<a name="l00504"></a>00504             <span class="keywordflow">return</span> rv;
<a name="l00505"></a>00505     }
<a name="l00506"></a>00506 
<a name="l00507"></a>00507     <span class="keywordflow">return</span> 0;
<a name="l00508"></a>00508 }
<a name="l00509"></a>00509 
<a name="l00510"></a>00510 <span class="keywordtype">int</span>
<a name="l00511"></a><a class="code" href="pocketsphinx_8h.html#a5e278377cc57d921591ce95b980760d5">00511</a> <a class="code" href="pocketsphinx_8h.html#a5e278377cc57d921591ce95b980760d5" title="Dump the current pronunciation dictionary to a file.">ps_save_dict</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">char</span> <span class="keyword">const</span> *dictfile,
<a name="l00512"></a>00512              <span class="keywordtype">char</span> <span class="keyword">const</span> *format)
<a name="l00513"></a>00513 {
<a name="l00514"></a>00514     <span class="keywordflow">return</span> dict_write(ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, dictfile, format);
<a name="l00515"></a>00515 }
<a name="l00516"></a>00516 
<a name="l00517"></a>00517 <span class="keywordtype">int</span>
<a name="l00518"></a><a class="code" href="pocketsphinx_8h.html#a5f3c4fcdbef34915c4e785ac9a1c6005">00518</a> <a class="code" href="pocketsphinx_8h.html#a5f3c4fcdbef34915c4e785ac9a1c6005" title="Add a word to the pronunciation dictionary.">ps_add_word</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps,
<a name="l00519"></a>00519             <span class="keywordtype">char</span> <span class="keyword">const</span> *word,
<a name="l00520"></a>00520             <span class="keywordtype">char</span> <span class="keyword">const</span> *<a class="code" href="structphone__loop__search__s.html#af543cdcfbfd8d43e5beba4bd6c47fd80" title="Array of phone arcs.">phones</a>,
<a name="l00521"></a>00521             <span class="keywordtype">int</span> update)
<a name="l00522"></a>00522 {
<a name="l00523"></a>00523     int32 wid, lmwid;
<a name="l00524"></a>00524     ngram_model_t *lmset;
<a name="l00525"></a>00525     <a class="code" href="s3types_8h.html#ae5f70241ce62a79747f0611029a6409d" title="Size definitions for more semantially meaningful units.">s3cipid_t</a> *pron;
<a name="l00526"></a>00526     <span class="keywordtype">char</span> **phonestr, *tmp;
<a name="l00527"></a>00527     <span class="keywordtype">int</span> np, i, rv;
<a name="l00528"></a>00528 
<a name="l00529"></a>00529     <span class="comment">/* Parse phones into an array of phone IDs. */</span>
<a name="l00530"></a>00530     tmp = ckd_salloc(phones);
<a name="l00531"></a>00531     np = str2words(tmp, NULL, 0);
<a name="l00532"></a>00532     phonestr = ckd_calloc(np, <span class="keyword">sizeof</span>(*phonestr));
<a name="l00533"></a>00533     str2words(tmp, phonestr, np);
<a name="l00534"></a>00534     pron = ckd_calloc(np, <span class="keyword">sizeof</span>(*pron));
<a name="l00535"></a>00535     <span class="keywordflow">for</span> (i = 0; i &lt; np; ++i) {
<a name="l00536"></a>00536         pron[i] = bin_mdef_ciphone_id(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>, phonestr[i]);
<a name="l00537"></a>00537         <span class="keywordflow">if</span> (pron[i] == -1) {
<a name="l00538"></a>00538             E_ERROR(<span class="stringliteral">&quot;Unknown phone %s in phone string %s\n&quot;</span>,
<a name="l00539"></a>00539                     phonestr[i], tmp);
<a name="l00540"></a>00540             ckd_free(phonestr);
<a name="l00541"></a>00541             ckd_free(tmp);
<a name="l00542"></a>00542             ckd_free(pron);
<a name="l00543"></a>00543             <span class="keywordflow">return</span> -1;
<a name="l00544"></a>00544         }
<a name="l00545"></a>00545     }
<a name="l00546"></a>00546     <span class="comment">/* No longer needed. */</span>
<a name="l00547"></a>00547     ckd_free(phonestr);
<a name="l00548"></a>00548     ckd_free(tmp);
<a name="l00549"></a>00549 
<a name="l00550"></a>00550     <span class="comment">/* Add it to the dictionary. */</span>
<a name="l00551"></a>00551     <span class="keywordflow">if</span> ((wid = dict_add_word(ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, word, pron, np)) == -1) {
<a name="l00552"></a>00552         ckd_free(pron);
<a name="l00553"></a>00553         <span class="keywordflow">return</span> -1;
<a name="l00554"></a>00554     }
<a name="l00555"></a>00555     <span class="comment">/* No longer needed. */</span>
<a name="l00556"></a>00556     ckd_free(pron);
<a name="l00557"></a>00557 
<a name="l00558"></a>00558     <span class="comment">/* Now we also have to add it to dict2pid. */</span>
<a name="l00559"></a>00559     <a class="code" href="dict2pid_8c.html#aa94120dcea4b17807576e29484b8a008" title="Add a word to the dict2pid structure (after adding it to dict).">dict2pid_add_word</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>, wid);
<a name="l00560"></a>00560 
<a name="l00561"></a>00561     <span class="keywordflow">if</span> ((lmset = <a class="code" href="pocketsphinx_8h.html#ab9e59bf2ebf2aa1a6a781371685f8740" title="Get the language model set object for this decoder.">ps_get_lmset</a>(ps)) != NULL) {
<a name="l00562"></a>00562         <span class="comment">/* Add it to the LM set (meaning, the current LM).  In a perfect</span>
<a name="l00563"></a>00563 <span class="comment">         * world, this would result in the same WID, but because of the</span>
<a name="l00564"></a>00564 <span class="comment">         * weird way that word IDs are handled, it doesn&#39;t. */</span>
<a name="l00565"></a>00565         <span class="keywordflow">if</span> ((lmwid = ngram_model_add_word(lmset, word, 1.0))
<a name="l00566"></a>00566             == NGRAM_INVALID_WID)
<a name="l00567"></a>00567             <span class="keywordflow">return</span> -1;
<a name="l00568"></a>00568     }
<a name="l00569"></a>00569  
<a name="l00570"></a>00570     <span class="comment">/* Rebuild the widmap and search tree if requested. */</span>
<a name="l00571"></a>00571     <span class="keywordflow">if</span> (update) {
<a name="l00572"></a>00572         <span class="keywordflow">if</span> ((rv = ps_search_reinit(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#aef6228c17907cc1d0cef835b238b5d91" title="Pronunciation dictionary.">dict</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#ae6515cbc261686f3f3bbd95719f79793" title="Dictionary to senone mapping.">d2p</a>) &lt; 0))
<a name="l00573"></a>00573             <span class="keywordflow">return</span> rv;
<a name="l00574"></a>00574     }
<a name="l00575"></a>00575     <span class="keywordflow">return</span> wid;
<a name="l00576"></a>00576 }
<a name="l00577"></a>00577 
<a name="l00578"></a>00578 <span class="keywordtype">int</span>
<a name="l00579"></a><a class="code" href="pocketsphinx_8h.html#ac9a9a0df5cebda28876c1e95bd197321">00579</a> <a class="code" href="pocketsphinx_8h.html#ac9a9a0df5cebda28876c1e95bd197321" title="Decode a raw audio stream.">ps_decode_raw</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, FILE *rawfh,
<a name="l00580"></a>00580               <span class="keywordtype">char</span> <span class="keyword">const</span> *uttid, <span class="keywordtype">long</span> maxsamps)
<a name="l00581"></a>00581 {
<a name="l00582"></a>00582     <span class="keywordtype">long</span> total, pos;
<a name="l00583"></a>00583 
<a name="l00584"></a>00584     <a class="code" href="pocketsphinx_8h.html#a0b70e54570e21ad3a784b40071818579" title="Start utterance processing.">ps_start_utt</a>(ps, uttid);
<a name="l00585"></a>00585     <span class="comment">/* If this file is seekable or maxsamps is specified, then decode</span>
<a name="l00586"></a>00586 <span class="comment">     * the whole thing at once. */</span>
<a name="l00587"></a>00587     <span class="keywordflow">if</span> (maxsamps != -1 || (pos = ftell(rawfh)) &gt;= 0) {
<a name="l00588"></a>00588         int16 *data;
<a name="l00589"></a>00589 
<a name="l00590"></a>00590         <span class="keywordflow">if</span> (maxsamps == -1) {
<a name="l00591"></a>00591             <span class="keywordtype">long</span> endpos;
<a name="l00592"></a>00592             fseek(rawfh, 0, SEEK_END);
<a name="l00593"></a>00593             endpos = ftell(rawfh);
<a name="l00594"></a>00594             fseek(rawfh, pos, SEEK_SET);
<a name="l00595"></a>00595             maxsamps = endpos - pos;
<a name="l00596"></a>00596         }
<a name="l00597"></a>00597         data = ckd_calloc(maxsamps, <span class="keyword">sizeof</span>(*data));
<a name="l00598"></a>00598         total = fread(data, <span class="keyword">sizeof</span>(*data), maxsamps, rawfh);
<a name="l00599"></a>00599         <a class="code" href="pocketsphinx_8h.html#a572ad08651b4caae820d178a12c8f95f" title="Decode raw audio data.">ps_process_raw</a>(ps, data, total, FALSE, TRUE);
<a name="l00600"></a>00600         ckd_free(data);
<a name="l00601"></a>00601     }
<a name="l00602"></a>00602     <span class="keywordflow">else</span> {
<a name="l00603"></a>00603         <span class="comment">/* Otherwise decode it in a stream. */</span>
<a name="l00604"></a>00604         total = 0;
<a name="l00605"></a>00605         <span class="keywordflow">while</span> (!feof(rawfh)) {
<a name="l00606"></a>00606             int16 data[256];
<a name="l00607"></a>00607             <span class="keywordtype">size_t</span> nread;
<a name="l00608"></a>00608 
<a name="l00609"></a>00609             nread = fread(data, <span class="keyword">sizeof</span>(*data), <span class="keyword">sizeof</span>(data)/<span class="keyword">sizeof</span>(*data), rawfh);
<a name="l00610"></a>00610             <a class="code" href="pocketsphinx_8h.html#a572ad08651b4caae820d178a12c8f95f" title="Decode raw audio data.">ps_process_raw</a>(ps, data, nread, FALSE, FALSE);
<a name="l00611"></a>00611             total += nread;
<a name="l00612"></a>00612         }
<a name="l00613"></a>00613     }
<a name="l00614"></a>00614     <a class="code" href="pocketsphinx_8h.html#ab9339de730713b68cbd68a7f36dc8730" title="End utterance processing.">ps_end_utt</a>(ps);
<a name="l00615"></a>00615     <span class="keywordflow">return</span> total;
<a name="l00616"></a>00616 }
<a name="l00617"></a>00617 
<a name="l00618"></a>00618 <span class="keywordtype">int</span>
<a name="l00619"></a><a class="code" href="pocketsphinx_8h.html#a0b70e54570e21ad3a784b40071818579">00619</a> <a class="code" href="pocketsphinx_8h.html#a0b70e54570e21ad3a784b40071818579" title="Start utterance processing.">ps_start_utt</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">char</span> <span class="keyword">const</span> *uttid)
<a name="l00620"></a>00620 {
<a name="l00621"></a>00621     <span class="keywordtype">int</span> rv;
<a name="l00622"></a>00622 
<a name="l00623"></a>00623     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> == NULL) {
<a name="l00624"></a>00624         E_ERROR(<span class="stringliteral">&quot;No search module is selected, did you forget to &quot;</span>
<a name="l00625"></a>00625                 <span class="stringliteral">&quot;specify a language model or grammar?\n&quot;</span>);
<a name="l00626"></a>00626         <span class="keywordflow">return</span> -1;
<a name="l00627"></a>00627     }
<a name="l00628"></a>00628 
<a name="l00629"></a>00629     ptmr_reset(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00630"></a>00630     ptmr_start(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00631"></a>00631 
<a name="l00632"></a>00632     <span class="keywordflow">if</span> (uttid) {
<a name="l00633"></a>00633         ckd_free(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>);
<a name="l00634"></a>00634         ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a> = ckd_salloc(uttid);
<a name="l00635"></a>00635     }
<a name="l00636"></a>00636     <span class="keywordflow">else</span> {
<a name="l00637"></a>00637         <span class="keywordtype">char</span> nuttid[16];
<a name="l00638"></a>00638         ckd_free(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>);
<a name="l00639"></a>00639         sprintf(nuttid, <span class="stringliteral">&quot;%09u&quot;</span>, ps-&gt;<a class="code" href="structps__decoder__s.html#a0f597370dd162c2799efe216c9b991fc" title="Utterance counter.">uttno</a>);
<a name="l00640"></a>00640         ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a> = ckd_salloc(nuttid);
<a name="l00641"></a>00641         ++ps-&gt;<a class="code" href="structps__decoder__s.html#a0f597370dd162c2799efe216c9b991fc" title="Utterance counter.">uttno</a>;
<a name="l00642"></a>00642     }
<a name="l00643"></a>00643     <span class="comment">/* Remove any residual word lattice and hypothesis. */</span>
<a name="l00644"></a>00644     <a class="code" href="ps__lattice_8h.html#a3f90e846bde47cd1acdff165b92f5c22" title="Free a lattice.">ps_lattice_free</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#a897f46c55d17e817ff1364f555b31463" title="Current hypothesis word graph.">dag</a>);
<a name="l00645"></a>00645     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#a897f46c55d17e817ff1364f555b31463" title="Current hypothesis word graph.">dag</a> = NULL;
<a name="l00646"></a>00646     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#aa3020ef7bd4e56713dfe2fbad52e6e4f" title="Final link in best path.">last_link</a> = NULL;
<a name="l00647"></a>00647     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#a721a656d0e34f7604ea8c52a1bdf14ff" title="Utterance posterior probability.">post</a> = 0;
<a name="l00648"></a>00648     ckd_free(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#aa398c736a887af97e42b2a562359adc3" title="Current hypothesis string.">hyp_str</a>);
<a name="l00649"></a>00649     ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>-&gt;<a class="code" href="structps__search__s.html#aa398c736a887af97e42b2a562359adc3" title="Current hypothesis string.">hyp_str</a> = NULL;
<a name="l00650"></a>00650 
<a name="l00651"></a>00651     <span class="keywordflow">if</span> ((rv = <a class="code" href="acmod_8c.html#aa3a5a89f76338e3e1bcfa7a2cecc5845" title="Mark the start of an utterance.">acmod_start_utt</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>)) &lt; 0)
<a name="l00652"></a>00652         <span class="keywordflow">return</span> rv;
<a name="l00653"></a>00653 
<a name="l00654"></a>00654     <span class="comment">/* Start logging features and audio if requested. */</span>
<a name="l00655"></a>00655     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#a8bb5ef8791798b8dd9bc82b1ec016663" title="Log directory for MFCC files.">mfclogdir</a>) {
<a name="l00656"></a>00656         <span class="keywordtype">char</span> *logfn = string_join(ps-&gt;<a class="code" href="structps__decoder__s.html#a8bb5ef8791798b8dd9bc82b1ec016663" title="Log directory for MFCC files.">mfclogdir</a>, <span class="stringliteral">&quot;/&quot;</span>,
<a name="l00657"></a>00657                                   ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>, <span class="stringliteral">&quot;.mfc&quot;</span>, NULL);
<a name="l00658"></a>00658         FILE *mfcfh;
<a name="l00659"></a>00659         E_INFO(<span class="stringliteral">&quot;Writing MFCC log file: %s\n&quot;</span>, logfn);
<a name="l00660"></a>00660         <span class="keywordflow">if</span> ((mfcfh = fopen(logfn, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL) {
<a name="l00661"></a>00661             E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to open MFCC log file %s&quot;</span>, logfn);
<a name="l00662"></a>00662             ckd_free(logfn);
<a name="l00663"></a>00663             <span class="keywordflow">return</span> -1;
<a name="l00664"></a>00664         }
<a name="l00665"></a>00665         ckd_free(logfn);
<a name="l00666"></a>00666         <a class="code" href="acmod_8c.html#a5753caa516c75bdc74b385d7aa66a97c" title="Start logging MFCCs to a filehandle.">acmod_set_mfcfh</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, mfcfh);
<a name="l00667"></a>00667     }
<a name="l00668"></a>00668     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#aa2610c52a9267ee18ca095169bf34bfd" title="Log directory for audio files.">rawlogdir</a>) {
<a name="l00669"></a>00669         <span class="keywordtype">char</span> *logfn = string_join(ps-&gt;<a class="code" href="structps__decoder__s.html#aa2610c52a9267ee18ca095169bf34bfd" title="Log directory for audio files.">rawlogdir</a>, <span class="stringliteral">&quot;/&quot;</span>,
<a name="l00670"></a>00670                                   ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>, <span class="stringliteral">&quot;.raw&quot;</span>, NULL);
<a name="l00671"></a>00671         FILE *rawfh;
<a name="l00672"></a>00672         E_INFO(<span class="stringliteral">&quot;Writing raw audio log file: %s\n&quot;</span>, logfn);
<a name="l00673"></a>00673         <span class="keywordflow">if</span> ((rawfh = fopen(logfn, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL) {
<a name="l00674"></a>00674             E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to open raw audio log file %s&quot;</span>, logfn);
<a name="l00675"></a>00675             ckd_free(logfn);
<a name="l00676"></a>00676             <span class="keywordflow">return</span> -1;
<a name="l00677"></a>00677         }
<a name="l00678"></a>00678         ckd_free(logfn);
<a name="l00679"></a>00679         <a class="code" href="acmod_8c.html#a6979441ae866ea846ef41f8471b105a0" title="Start logging raw audio to a filehandle.">acmod_set_rawfh</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, rawfh);
<a name="l00680"></a>00680     }
<a name="l00681"></a>00681     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#a0ed3476113fe3d63b13ac5e8da3f3b4f" title="Log directory for senone score files.">senlogdir</a>) {
<a name="l00682"></a>00682         <span class="keywordtype">char</span> *logfn = string_join(ps-&gt;<a class="code" href="structps__decoder__s.html#a0ed3476113fe3d63b13ac5e8da3f3b4f" title="Log directory for senone score files.">senlogdir</a>, <span class="stringliteral">&quot;/&quot;</span>,
<a name="l00683"></a>00683                                   ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>, <span class="stringliteral">&quot;.sen&quot;</span>, NULL);
<a name="l00684"></a>00684         FILE *senfh;
<a name="l00685"></a>00685         E_INFO(<span class="stringliteral">&quot;Writing senone score log file: %s\n&quot;</span>, logfn);
<a name="l00686"></a>00686         <span class="keywordflow">if</span> ((senfh = fopen(logfn, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL) {
<a name="l00687"></a>00687             E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to open senone score log file %s&quot;</span>, logfn);
<a name="l00688"></a>00688             ckd_free(logfn);
<a name="l00689"></a>00689             <span class="keywordflow">return</span> -1;
<a name="l00690"></a>00690         }
<a name="l00691"></a>00691         ckd_free(logfn);
<a name="l00692"></a>00692         <a class="code" href="acmod_8c.html#ab35cb48cdf326a3fb5223589d73ae0ce" title="Start logging senone scores to a filehandle.">acmod_set_senfh</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, senfh);
<a name="l00693"></a>00693     }
<a name="l00694"></a>00694 
<a name="l00695"></a>00695     <span class="comment">/* Start auxiliary phone loop search. */</span>
<a name="l00696"></a>00696     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>)
<a name="l00697"></a>00697         ps_search_start(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>);
<a name="l00698"></a>00698 
<a name="l00699"></a>00699     <span class="keywordflow">return</span> ps_search_start(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>);
<a name="l00700"></a>00700 }
<a name="l00701"></a>00701 
<a name="l00702"></a>00702 <span class="keyword">static</span> <span class="keywordtype">int</span>
<a name="l00703"></a>00703 ps_search_forward(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00704"></a>00704 {
<a name="l00705"></a>00705     <span class="keywordtype">int</span> nfr;
<a name="l00706"></a>00706 
<a name="l00707"></a>00707     nfr = 0;
<a name="l00708"></a>00708     <span class="keywordflow">while</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a815a68a4006e26c992f183b291137d10" title="Number of frames active in feat_buf.">n_feat_frame</a> &gt; 0) {
<a name="l00709"></a>00709         <span class="keywordtype">int</span> k;
<a name="l00710"></a>00710         <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>)
<a name="l00711"></a>00711             <span class="keywordflow">if</span> ((k = ps_search_step(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>, ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a>)) &lt; 0)
<a name="l00712"></a>00712                 <span class="keywordflow">return</span> k;
<a name="l00713"></a>00713         <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a> &gt;= ps-&gt;<a class="code" href="structps__decoder__s.html#a0f0a6681ffd98af789f6bed556c814e4" title="Window size for phoneme lookahead.">pl_window</a>)
<a name="l00714"></a>00714             <span class="keywordflow">if</span> ((k = ps_search_step(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>,
<a name="l00715"></a>00715                                     ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a> - ps-&gt;<a class="code" href="structps__decoder__s.html#a0f0a6681ffd98af789f6bed556c814e4" title="Window size for phoneme lookahead.">pl_window</a>)) &lt; 0)
<a name="l00716"></a>00716                 <span class="keywordflow">return</span> k;
<a name="l00717"></a>00717         <a class="code" href="acmod_8c.html#a338971ea0aa27fb4796d224e4767642b" title="Advance the frame index.">acmod_advance</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>);
<a name="l00718"></a>00718         ++ps-&gt;<a class="code" href="structps__decoder__s.html#a2886b321c576c7def449ebb2f37899fd" title="Total number of frames processed.">n_frame</a>;
<a name="l00719"></a>00719         ++nfr;
<a name="l00720"></a>00720     }
<a name="l00721"></a>00721     <span class="keywordflow">return</span> nfr;
<a name="l00722"></a>00722 }
<a name="l00723"></a>00723 
<a name="l00724"></a>00724 <span class="keywordtype">int</span>
<a name="l00725"></a><a class="code" href="pocketsphinx_8h.html#aa2957bf4fb90d6a78d1daffd3dd82c3f">00725</a> <a class="code" href="pocketsphinx_8h.html#aa2957bf4fb90d6a78d1daffd3dd82c3f" title="Decode a senone score dump file.">ps_decode_senscr</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, FILE *senfh,
<a name="l00726"></a>00726                  <span class="keywordtype">char</span> <span class="keyword">const</span> *uttid)
<a name="l00727"></a>00727 {
<a name="l00728"></a>00728     <span class="keywordtype">int</span> nfr, n_searchfr;
<a name="l00729"></a>00729 
<a name="l00730"></a>00730     <a class="code" href="pocketsphinx_8h.html#a0b70e54570e21ad3a784b40071818579" title="Start utterance processing.">ps_start_utt</a>(ps, uttid);
<a name="l00731"></a>00731     n_searchfr = 0;
<a name="l00732"></a>00732     <a class="code" href="acmod_8c.html#a58bd6038bec5d3901ac2057cacdd778a" title="Set up a senone score dump file for input.">acmod_set_insenfh</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, senfh);
<a name="l00733"></a>00733     <span class="keywordflow">while</span> ((nfr = <a class="code" href="acmod_8c.html#a5c193164be78ad42944b7fb1be6299a2" title="Read one frame of scores from senone score dump file.">acmod_read_scores</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>)) &gt; 0) {
<a name="l00734"></a>00734         <span class="keywordflow">if</span> ((nfr = ps_search_forward(ps)) &lt; 0) {
<a name="l00735"></a>00735             <a class="code" href="pocketsphinx_8h.html#ab9339de730713b68cbd68a7f36dc8730" title="End utterance processing.">ps_end_utt</a>(ps);
<a name="l00736"></a>00736             <span class="keywordflow">return</span> nfr;
<a name="l00737"></a>00737         }
<a name="l00738"></a>00738         n_searchfr += nfr;
<a name="l00739"></a>00739     }
<a name="l00740"></a>00740     <a class="code" href="pocketsphinx_8h.html#ab9339de730713b68cbd68a7f36dc8730" title="End utterance processing.">ps_end_utt</a>(ps);
<a name="l00741"></a>00741     <a class="code" href="acmod_8c.html#a58bd6038bec5d3901ac2057cacdd778a" title="Set up a senone score dump file for input.">acmod_set_insenfh</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, NULL);
<a name="l00742"></a>00742 
<a name="l00743"></a>00743     <span class="keywordflow">return</span> n_searchfr;
<a name="l00744"></a>00744 }
<a name="l00745"></a>00745 
<a name="l00746"></a>00746 <span class="keywordtype">int</span>
<a name="l00747"></a><a class="code" href="pocketsphinx_8h.html#a572ad08651b4caae820d178a12c8f95f">00747</a> <a class="code" href="pocketsphinx_8h.html#a572ad08651b4caae820d178a12c8f95f" title="Decode raw audio data.">ps_process_raw</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps,
<a name="l00748"></a>00748                int16 <span class="keyword">const</span> *data,
<a name="l00749"></a>00749                <span class="keywordtype">size_t</span> n_samples,
<a name="l00750"></a>00750                <span class="keywordtype">int</span> no_search,
<a name="l00751"></a>00751                <span class="keywordtype">int</span> full_utt)
<a name="l00752"></a>00752 {
<a name="l00753"></a>00753     <span class="keywordtype">int</span> n_searchfr = 0;
<a name="l00754"></a>00754 
<a name="l00755"></a>00755     <span class="keywordflow">if</span> (no_search)
<a name="l00756"></a>00756         <a class="code" href="acmod_8c.html#a1555dac8fa27f644d709c5c89bbfa881" title="Set memory allocation policy for utterance processing.">acmod_set_grow</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, TRUE);
<a name="l00757"></a>00757 
<a name="l00758"></a>00758     <span class="keywordflow">while</span> (n_samples) {
<a name="l00759"></a>00759         <span class="keywordtype">int</span> nfr;
<a name="l00760"></a>00760 
<a name="l00761"></a>00761         <span class="comment">/* Process some data into features. */</span>
<a name="l00762"></a>00762         <span class="keywordflow">if</span> ((nfr = <a class="code" href="acmod_8c.html#a23e63c8833e6128ae248e183d42f9b2b" title="TODO: Set queue length for utterance processing.">acmod_process_raw</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, &amp;data,
<a name="l00763"></a>00763                                      &amp;n_samples, full_utt)) &lt; 0)
<a name="l00764"></a>00764             <span class="keywordflow">return</span> nfr;
<a name="l00765"></a>00765 
<a name="l00766"></a>00766         <span class="comment">/* Score and search as much data as possible */</span>
<a name="l00767"></a>00767         <span class="keywordflow">if</span> (no_search)
<a name="l00768"></a>00768             <span class="keywordflow">continue</span>;
<a name="l00769"></a>00769         <span class="keywordflow">if</span> ((nfr = ps_search_forward(ps)) &lt; 0)
<a name="l00770"></a>00770             <span class="keywordflow">return</span> nfr;
<a name="l00771"></a>00771         n_searchfr += nfr;
<a name="l00772"></a>00772     }
<a name="l00773"></a>00773 
<a name="l00774"></a>00774     <span class="keywordflow">return</span> n_searchfr;
<a name="l00775"></a>00775 }
<a name="l00776"></a>00776 
<a name="l00777"></a>00777 <span class="keywordtype">int</span>
<a name="l00778"></a>00778 <a class="code" href="pocketsphinx_8h.html#adc0ab735d6460142126bc31a9e9d2ba0" title="Decode acoustic feature data.">ps_process_cep</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps,
<a name="l00779"></a>00779                mfcc_t **data,
<a name="l00780"></a>00780                int32 n_frames,
<a name="l00781"></a>00781                <span class="keywordtype">int</span> no_search,
<a name="l00782"></a>00782                <span class="keywordtype">int</span> full_utt)
<a name="l00783"></a>00783 {
<a name="l00784"></a>00784     <span class="keywordtype">int</span> n_searchfr = 0;
<a name="l00785"></a>00785 
<a name="l00786"></a>00786     <span class="keywordflow">if</span> (no_search)
<a name="l00787"></a>00787         <a class="code" href="acmod_8c.html#a1555dac8fa27f644d709c5c89bbfa881" title="Set memory allocation policy for utterance processing.">acmod_set_grow</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, TRUE);
<a name="l00788"></a>00788 
<a name="l00789"></a>00789     <span class="keywordflow">while</span> (n_frames) {
<a name="l00790"></a>00790         <span class="keywordtype">int</span> nfr;
<a name="l00791"></a>00791 
<a name="l00792"></a>00792         <span class="comment">/* Process some data into features. */</span>
<a name="l00793"></a>00793         <span class="keywordflow">if</span> ((nfr = <a class="code" href="acmod_8c.html#a9464f7708a361171469d613d401619fe" title="Feed acoustic feature data into the acoustic model for scoring.">acmod_process_cep</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>, &amp;data,
<a name="l00794"></a>00794                                      &amp;n_frames, full_utt)) &lt; 0)
<a name="l00795"></a>00795             <span class="keywordflow">return</span> nfr;
<a name="l00796"></a>00796 
<a name="l00797"></a>00797         <span class="comment">/* Score and search as much data as possible */</span>
<a name="l00798"></a>00798         <span class="keywordflow">if</span> (no_search)
<a name="l00799"></a>00799             <span class="keywordflow">continue</span>;
<a name="l00800"></a>00800         <span class="keywordflow">if</span> ((nfr = ps_search_forward(ps)) &lt; 0)
<a name="l00801"></a>00801             <span class="keywordflow">return</span> nfr;
<a name="l00802"></a>00802         n_searchfr += nfr;
<a name="l00803"></a>00803     }
<a name="l00804"></a>00804 
<a name="l00805"></a>00805     <span class="keywordflow">return</span> n_searchfr;
<a name="l00806"></a>00806 }
<a name="l00807"></a>00807 
<a name="l00808"></a>00808 <span class="keywordtype">int</span>
<a name="l00809"></a><a class="code" href="pocketsphinx_8h.html#ab9339de730713b68cbd68a7f36dc8730">00809</a> <a class="code" href="pocketsphinx_8h.html#ab9339de730713b68cbd68a7f36dc8730" title="End utterance processing.">ps_end_utt</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00810"></a>00810 {
<a name="l00811"></a>00811     <span class="keywordtype">int</span> rv, i;
<a name="l00812"></a>00812 
<a name="l00813"></a>00813     <a class="code" href="acmod_8c.html#a262372bdd6063f61e64b5417a449c1a9" title="Mark the end of an utterance.">acmod_end_utt</a>(ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>);
<a name="l00814"></a>00814 
<a name="l00815"></a>00815     <span class="comment">/* Search any remaining frames. */</span>
<a name="l00816"></a>00816     <span class="keywordflow">if</span> ((rv = ps_search_forward(ps)) &lt; 0) {
<a name="l00817"></a>00817         ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00818"></a>00818         <span class="keywordflow">return</span> rv;
<a name="l00819"></a>00819     }
<a name="l00820"></a>00820     <span class="comment">/* Finish phone loop search. */</span>
<a name="l00821"></a>00821     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>) {
<a name="l00822"></a>00822         <span class="keywordflow">if</span> ((rv = ps_search_finish(ps-&gt;<a class="code" href="structps__decoder__s.html#a0c6d141d7a71a1287be00a1ebcc7643d" title="Phone loop search for lookahead.">phone_loop</a>)) &lt; 0) {
<a name="l00823"></a>00823             ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00824"></a>00824             <span class="keywordflow">return</span> rv;
<a name="l00825"></a>00825         }
<a name="l00826"></a>00826     }
<a name="l00827"></a>00827     <span class="comment">/* Search any frames remaining in the lookahead window. */</span>
<a name="l00828"></a>00828     <span class="keywordflow">for</span> (i = ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a> - ps-&gt;<a class="code" href="structps__decoder__s.html#a0f0a6681ffd98af789f6bed556c814e4" title="Window size for phoneme lookahead.">pl_window</a>;
<a name="l00829"></a>00829          i &lt; ps-&gt;acmod-&gt;output_frame; ++i)
<a name="l00830"></a>00830         ps_search_step(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>, i);
<a name="l00831"></a>00831     <span class="comment">/* Finish main search. */</span>
<a name="l00832"></a>00832     <span class="keywordflow">if</span> ((rv = ps_search_finish(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>)) &lt; 0) {
<a name="l00833"></a>00833         ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00834"></a>00834         <span class="keywordflow">return</span> rv;
<a name="l00835"></a>00835     }
<a name="l00836"></a>00836     ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00837"></a>00837 
<a name="l00838"></a>00838     <span class="comment">/* Log a backtrace if requested. */</span>
<a name="l00839"></a>00839     <span class="keywordflow">if</span> (cmd_ln_boolean_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-backtrace&quot;</span>)) {
<a name="l00840"></a>00840         <span class="keywordtype">char</span> <span class="keyword">const</span> *uttid, *hyp;
<a name="l00841"></a>00841         <a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg;
<a name="l00842"></a>00842         int32 score;
<a name="l00843"></a>00843 
<a name="l00844"></a>00844         hyp = <a class="code" href="pocketsphinx_8h.html#ae4130fef938568440c014abae0e4de5e" title="Get hypothesis string and path score.">ps_get_hyp</a>(ps, &amp;score, &amp;uttid);
<a name="l00845"></a>00845         E_INFO(<span class="stringliteral">&quot;%s: %s (%d)\n&quot;</span>, uttid, hyp, score);
<a name="l00846"></a>00846         E_INFO_NOFN(<span class="stringliteral">&quot;%-20s %-5s %-5s %-5s %-10s %-10s %-3s\n&quot;</span>,
<a name="l00847"></a>00847                     <span class="stringliteral">&quot;word&quot;</span>, <span class="stringliteral">&quot;start&quot;</span>, <span class="stringliteral">&quot;end&quot;</span>, <span class="stringliteral">&quot;pprob&quot;</span>, <span class="stringliteral">&quot;ascr&quot;</span>, <span class="stringliteral">&quot;lscr&quot;</span>, <span class="stringliteral">&quot;lback&quot;</span>);
<a name="l00848"></a>00848         <span class="keywordflow">for</span> (seg = <a class="code" href="pocketsphinx_8h.html#a2216f6ff53f6bc9c78f285ee3fe0d665" title="Get an iterator over the word segmentation for the best hypothesis.">ps_seg_iter</a>(ps, &amp;score); seg;
<a name="l00849"></a>00849              seg = <a class="code" href="pocketsphinx_8h.html#ae16ba181f654ffc9bfbbe861e9315f12" title="Get the next segment in a word segmentation.">ps_seg_next</a>(seg)) {
<a name="l00850"></a>00850             <span class="keywordtype">char</span> <span class="keyword">const</span> *word;
<a name="l00851"></a>00851             <span class="keywordtype">int</span> sf, ef;
<a name="l00852"></a>00852             int32 post, lscr, ascr, lback;
<a name="l00853"></a>00853 
<a name="l00854"></a>00854             word = <a class="code" href="pocketsphinx_8h.html#a8a4fed34b58885627b53e99e90514169" title="Get word string from a segmentation iterator.">ps_seg_word</a>(seg);
<a name="l00855"></a>00855             <a class="code" href="pocketsphinx_8h.html#a045a044726b816678965514f2ee7d8c7" title="Get inclusive start and end frames from a segmentation iterator.">ps_seg_frames</a>(seg, &amp;sf, &amp;ef);
<a name="l00856"></a>00856             post = <a class="code" href="pocketsphinx_8h.html#adfd45d93c3fc9de6b7be89d5417f6abb" title="Get language, acoustic, and posterior probabilities from a segmentation iterator.">ps_seg_prob</a>(seg, &amp;ascr, &amp;lscr, &amp;lback);
<a name="l00857"></a>00857             E_INFO_NOFN(<span class="stringliteral">&quot;%-20s %-5d %-5d %-1.3f %-10d %-10d %-3d\n&quot;</span>,
<a name="l00858"></a>00858                         word, sf, ef, logmath_exp(<a class="code" href="pocketsphinx_8h.html#a249cfc383b7d9111a28b550945a606b5" title="Get the log-math computation object for this decoder.">ps_get_logmath</a>(ps), post), ascr, lscr, lback);
<a name="l00859"></a>00859         }
<a name="l00860"></a>00860     }
<a name="l00861"></a>00861     <span class="keywordflow">return</span> rv;
<a name="l00862"></a>00862 }
<a name="l00863"></a>00863 
<a name="l00864"></a>00864 <span class="keywordtype">char</span> <span class="keyword">const</span> *
<a name="l00865"></a><a class="code" href="pocketsphinx_8h.html#ae4130fef938568440c014abae0e4de5e">00865</a> <a class="code" href="pocketsphinx_8h.html#ae4130fef938568440c014abae0e4de5e" title="Get hypothesis string and path score.">ps_get_hyp</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, int32 *out_best_score, <span class="keywordtype">char</span> <span class="keyword">const</span> **out_uttid)
<a name="l00866"></a>00866 {
<a name="l00867"></a>00867     <span class="keywordtype">char</span> <span class="keyword">const</span> *hyp;
<a name="l00868"></a>00868 
<a name="l00869"></a>00869     ptmr_start(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00870"></a>00870     hyp = ps_search_hyp(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>, out_best_score);
<a name="l00871"></a>00871     <span class="keywordflow">if</span> (out_uttid)
<a name="l00872"></a>00872         *out_uttid = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>;
<a name="l00873"></a>00873     ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00874"></a>00874     <span class="keywordflow">return</span> hyp;
<a name="l00875"></a>00875 }
<a name="l00876"></a>00876 
<a name="l00877"></a>00877 int32
<a name="l00878"></a><a class="code" href="pocketsphinx_8h.html#afa6631ae5c30a30eec08c7bf1ef41ef5">00878</a> <a class="code" href="pocketsphinx_8h.html#afa6631ae5c30a30eec08c7bf1ef41ef5" title="Get posterior probability.">ps_get_prob</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">char</span> <span class="keyword">const</span> **out_uttid)
<a name="l00879"></a>00879 {
<a name="l00880"></a>00880     int32 prob;
<a name="l00881"></a>00881 
<a name="l00882"></a>00882     ptmr_start(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00883"></a>00883     prob = ps_search_prob(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>);
<a name="l00884"></a>00884     <span class="keywordflow">if</span> (out_uttid)
<a name="l00885"></a>00885         *out_uttid = ps-&gt;<a class="code" href="structps__decoder__s.html#a0c21a99a0cb1e71cf7811f99cc17c105" title="Utterance ID for current utterance.">uttid</a>;
<a name="l00886"></a>00886     ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00887"></a>00887     <span class="keywordflow">return</span> prob;
<a name="l00888"></a>00888 }
<a name="l00889"></a>00889 
<a name="l00890"></a>00890 <a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *
<a name="l00891"></a><a class="code" href="pocketsphinx_8h.html#a2216f6ff53f6bc9c78f285ee3fe0d665">00891</a> <a class="code" href="pocketsphinx_8h.html#a2216f6ff53f6bc9c78f285ee3fe0d665" title="Get an iterator over the word segmentation for the best hypothesis.">ps_seg_iter</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, int32 *out_best_score)
<a name="l00892"></a>00892 {
<a name="l00893"></a>00893     <a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *itor;
<a name="l00894"></a>00894 
<a name="l00895"></a>00895     ptmr_start(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00896"></a>00896     itor = ps_search_seg_iter(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>, out_best_score);
<a name="l00897"></a>00897     ptmr_stop(&amp;ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>);
<a name="l00898"></a>00898     <span class="keywordflow">return</span> itor;
<a name="l00899"></a>00899 }
<a name="l00900"></a>00900 
<a name="l00901"></a>00901 <a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *
<a name="l00902"></a><a class="code" href="pocketsphinx_8h.html#ae16ba181f654ffc9bfbbe861e9315f12">00902</a> <a class="code" href="pocketsphinx_8h.html#ae16ba181f654ffc9bfbbe861e9315f12" title="Get the next segment in a word segmentation.">ps_seg_next</a>(<a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg)
<a name="l00903"></a>00903 {
<a name="l00904"></a>00904     <span class="keywordflow">return</span> ps_search_seg_next(seg);
<a name="l00905"></a>00905 }
<a name="l00906"></a>00906 
<a name="l00907"></a>00907 <span class="keywordtype">char</span> <span class="keyword">const</span> *
<a name="l00908"></a><a class="code" href="pocketsphinx_8h.html#a8a4fed34b58885627b53e99e90514169">00908</a> <a class="code" href="pocketsphinx_8h.html#a8a4fed34b58885627b53e99e90514169" title="Get word string from a segmentation iterator.">ps_seg_word</a>(<a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg)
<a name="l00909"></a>00909 {
<a name="l00910"></a>00910     <span class="keywordflow">return</span> seg-&gt;<a class="code" href="structps__seg__s.html#a97a0dc7db931c7e3f98d23d21ce27f04" title="Word string (pointer into dictionary hash)">word</a>;
<a name="l00911"></a>00911 }
<a name="l00912"></a>00912 
<a name="l00913"></a>00913 <span class="keywordtype">void</span>
<a name="l00914"></a><a class="code" href="pocketsphinx_8h.html#a045a044726b816678965514f2ee7d8c7">00914</a> <a class="code" href="pocketsphinx_8h.html#a045a044726b816678965514f2ee7d8c7" title="Get inclusive start and end frames from a segmentation iterator.">ps_seg_frames</a>(<a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg, <span class="keywordtype">int</span> *out_sf, <span class="keywordtype">int</span> *out_ef)
<a name="l00915"></a>00915 {
<a name="l00916"></a>00916     <span class="keywordflow">if</span> (out_sf) *out_sf = seg-&gt;<a class="code" href="structps__seg__s.html#ac292e31304906addf3d49f1473df8ead" title="Start frame.">sf</a>;
<a name="l00917"></a>00917     <span class="keywordflow">if</span> (out_ef) *out_ef = seg-&gt;<a class="code" href="structps__seg__s.html#a2043ca87b07df0cd80d0fb65c3521c04" title="End frame.">ef</a>;
<a name="l00918"></a>00918 }
<a name="l00919"></a>00919 
<a name="l00920"></a>00920 int32
<a name="l00921"></a><a class="code" href="pocketsphinx_8h.html#adfd45d93c3fc9de6b7be89d5417f6abb">00921</a> <a class="code" href="pocketsphinx_8h.html#adfd45d93c3fc9de6b7be89d5417f6abb" title="Get language, acoustic, and posterior probabilities from a segmentation iterator.">ps_seg_prob</a>(<a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback)
<a name="l00922"></a>00922 {
<a name="l00923"></a>00923     <span class="keywordflow">if</span> (out_ascr) *out_ascr = seg-&gt;<a class="code" href="structps__seg__s.html#a6f7706ec4c0d0ec8ecafaf0f29f41f4b" title="Acoustic score.">ascr</a>;
<a name="l00924"></a>00924     <span class="keywordflow">if</span> (out_lscr) *out_lscr = seg-&gt;<a class="code" href="structps__seg__s.html#a69e605f422eeed1a9c67437e8ddd8b08" title="Language model score.">lscr</a>;
<a name="l00925"></a>00925     <span class="keywordflow">if</span> (out_lback) *out_lback = seg-&gt;<a class="code" href="structps__seg__s.html#a4d86c21f1ed2dc3eb3b1b1b37ce9bb48" title="Language model backoff.">lback</a>;
<a name="l00926"></a>00926     <span class="keywordflow">return</span> seg-&gt;<a class="code" href="structps__seg__s.html#ae683244d90d0a5339930b47757778432" title="Log posterior probability.">prob</a>;
<a name="l00927"></a>00927 }
<a name="l00928"></a>00928 
<a name="l00929"></a>00929 <span class="keywordtype">void</span>
<a name="l00930"></a><a class="code" href="pocketsphinx_8h.html#ac02cea69794b0fbd17e6a4c5265b2255">00930</a> <a class="code" href="pocketsphinx_8h.html#ac02cea69794b0fbd17e6a4c5265b2255" title="Finish iterating over a word segmentation early, freeing resources.">ps_seg_free</a>(<a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *seg)
<a name="l00931"></a>00931 {
<a name="l00932"></a>00932     ps_search_seg_free(seg);
<a name="l00933"></a>00933 }
<a name="l00934"></a>00934 
<a name="l00935"></a>00935 <a class="code" href="structps__lattice__s.html" title="Word graph structure used in bestpath/nbest search.">ps_lattice_t</a> *
<a name="l00936"></a><a class="code" href="pocketsphinx_8h.html#ac7e8897e5eed452f284bef3ee53d2429">00936</a> <a class="code" href="pocketsphinx_8h.html#ac7e8897e5eed452f284bef3ee53d2429" title="Get word lattice.">ps_get_lattice</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l00937"></a>00937 {
<a name="l00938"></a>00938     <span class="keywordflow">return</span> ps_search_lattice(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>);
<a name="l00939"></a>00939 }
<a name="l00940"></a>00940 
<a name="l00941"></a>00941 <a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *
<a name="l00942"></a><a class="code" href="pocketsphinx_8h.html#af4bb6ba47844a135745db428919d9810">00942</a> <a class="code" href="pocketsphinx_8h.html#af4bb6ba47844a135745db428919d9810" title="Get an iterator over the best hypotheses, optionally within a selected region of the utterance...">ps_nbest</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">int</span> sf, <span class="keywordtype">int</span> ef,
<a name="l00943"></a>00943          <span class="keywordtype">char</span> <span class="keyword">const</span> *ctx1, <span class="keywordtype">char</span> <span class="keyword">const</span> *ctx2)
<a name="l00944"></a>00944 {
<a name="l00945"></a>00945     <a class="code" href="structps__lattice__s.html" title="Word graph structure used in bestpath/nbest search.">ps_lattice_t</a> *dag;
<a name="l00946"></a>00946     ngram_model_t *lmset;
<a name="l00947"></a>00947     <a class="code" href="structps__astar__s.html" title="A* search structure.">ps_astar_t</a> *nbest;
<a name="l00948"></a>00948     float32 lwf;
<a name="l00949"></a>00949     int32 w1, w2;
<a name="l00950"></a>00950 
<a name="l00951"></a>00951     <span class="keywordflow">if</span> (ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a> == NULL)
<a name="l00952"></a>00952         <span class="keywordflow">return</span> NULL;
<a name="l00953"></a>00953     <span class="keywordflow">if</span> ((dag = <a class="code" href="pocketsphinx_8h.html#ac7e8897e5eed452f284bef3ee53d2429" title="Get word lattice.">ps_get_lattice</a>(ps)) == NULL)
<a name="l00954"></a>00954         <span class="keywordflow">return</span> NULL;
<a name="l00955"></a>00955 
<a name="l00956"></a>00956     <span class="comment">/* FIXME: This is all quite specific to N-Gram search.  Either we</span>
<a name="l00957"></a>00957 <span class="comment">     * should make N-best a method for each search module or it needs</span>
<a name="l00958"></a>00958 <span class="comment">     * to be abstracted to work for N-Gram and FSG. */</span>
<a name="l00959"></a>00959     <span class="keywordflow">if</span> (0 != strcmp(ps_search_name(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>), <span class="stringliteral">&quot;ngram&quot;</span>)) {
<a name="l00960"></a>00960         lmset = NULL;
<a name="l00961"></a>00961         lwf = 1.0f;
<a name="l00962"></a>00962     }
<a name="l00963"></a>00963     <span class="keywordflow">else</span> {
<a name="l00964"></a>00964         lmset = ((<a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *)ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>)-&gt;lmset;
<a name="l00965"></a>00965         lwf = ((<a class="code" href="structngram__search__s.html" title="N-Gram search module structure.">ngram_search_t</a> *)ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>)-&gt;bestpath_fwdtree_lw_ratio;
<a name="l00966"></a>00966     }
<a name="l00967"></a>00967 
<a name="l00968"></a>00968     w1 = ctx1 ? dict_wordid(ps_search_dict(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>), ctx1) : -1;
<a name="l00969"></a>00969     w2 = ctx2 ? dict_wordid(ps_search_dict(ps-&gt;<a class="code" href="structps__decoder__s.html#ad337270efc93613cf8dd7594f6515799" title="Currently active search module.">search</a>), ctx2) : -1;
<a name="l00970"></a>00970     nbest = <a class="code" href="ps__lattice_8c.html#aaf9aedd3cd8bd1d45053e10828215a25" title="Begin N-Gram based A* search on a word graph.">ps_astar_start</a>(dag, lmset, lwf, sf, ef, w1, w2);
<a name="l00971"></a>00971 
<a name="l00972"></a>00972     <span class="keywordflow">return</span> (<a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *)nbest;
<a name="l00973"></a>00973 }
<a name="l00974"></a>00974 
<a name="l00975"></a>00975 <span class="keywordtype">void</span>
<a name="l00976"></a><a class="code" href="pocketsphinx_8h.html#a83379b2da95eebdf5070d29196a9b067">00976</a> <a class="code" href="pocketsphinx_8h.html#a83379b2da95eebdf5070d29196a9b067" title="Finish N-best search early, releasing resources.">ps_nbest_free</a>(<a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *nbest)
<a name="l00977"></a>00977 {
<a name="l00978"></a>00978     <a class="code" href="ps__lattice_8c.html#abfb03e9e0fcbe3def45120f5ba43be14" title="Finish N-best search, releasing resources associated with it.">ps_astar_finish</a>(nbest);
<a name="l00979"></a>00979 }
<a name="l00980"></a>00980 
<a name="l00981"></a>00981 <a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *
<a name="l00982"></a><a class="code" href="pocketsphinx_8h.html#a0942b8c0570009319a5be20ef1b52821">00982</a> <a class="code" href="pocketsphinx_8h.html#a0942b8c0570009319a5be20ef1b52821" title="Move an N-best list iterator forward.">ps_nbest_next</a>(<a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *nbest)
<a name="l00983"></a>00983 {
<a name="l00984"></a>00984     <a class="code" href="structps__latpath__s.html" title="Partial path structure used in N-best (A*) search.">ps_latpath_t</a> *next;
<a name="l00985"></a>00985 
<a name="l00986"></a>00986     next = <a class="code" href="ps__lattice_8c.html#a6bea95f8fb827af790bbe6ce1920908c" title="Find next best hypothesis of A* on a word graph.">ps_astar_next</a>(nbest);
<a name="l00987"></a>00987     <span class="keywordflow">if</span> (next == NULL) {
<a name="l00988"></a>00988         <a class="code" href="pocketsphinx_8h.html#a83379b2da95eebdf5070d29196a9b067" title="Finish N-best search early, releasing resources.">ps_nbest_free</a>(nbest);
<a name="l00989"></a>00989         <span class="keywordflow">return</span> NULL;
<a name="l00990"></a>00990     }
<a name="l00991"></a>00991     <span class="keywordflow">return</span> nbest;
<a name="l00992"></a>00992 }
<a name="l00993"></a>00993 
<a name="l00994"></a>00994 <span class="keywordtype">char</span> <span class="keyword">const</span> *
<a name="l00995"></a><a class="code" href="pocketsphinx_8h.html#a250c5f72d3addd0d0254f3ceeaa17ace">00995</a> <a class="code" href="pocketsphinx_8h.html#a250c5f72d3addd0d0254f3ceeaa17ace" title="Get the hypothesis string from an N-best list iterator.">ps_nbest_hyp</a>(<a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *nbest, int32 *out_score)
<a name="l00996"></a>00996 {
<a name="l00997"></a>00997     <span class="keywordflow">if</span> (nbest-&gt;top == NULL)
<a name="l00998"></a>00998         <span class="keywordflow">return</span> NULL;
<a name="l00999"></a>00999     <span class="keywordflow">if</span> (out_score) *out_score = nbest-&gt;top-&gt;<a class="code" href="structps__latpath__s.html#a9249fb528f754db992df1d494a69b580" title="Exact score from start node up to node-&amp;gt;sf.">score</a>;
<a name="l01000"></a>01000     <span class="keywordflow">return</span> <a class="code" href="ps__lattice_8c.html#ac7372b5c5ec111f6814ce1ba495593e4" title="Get hypothesis string from A* search.">ps_astar_hyp</a>(nbest, nbest-&gt;top);
<a name="l01001"></a>01001 }
<a name="l01002"></a>01002 
<a name="l01003"></a>01003 <a class="code" href="structps__seg__s.html" title="Base structure for hypothesis segmentation iterator.">ps_seg_t</a> *
<a name="l01004"></a><a class="code" href="pocketsphinx_8h.html#a1d2b6fd873d8213bd53a915ff2758785">01004</a> <a class="code" href="pocketsphinx_8h.html#a1d2b6fd873d8213bd53a915ff2758785" title="Get the word segmentation from an N-best list iterator.">ps_nbest_seg</a>(<a class="code" href="structps__astar__s.html" title="A* search structure.">ps_nbest_t</a> *nbest, int32 *out_score)
<a name="l01005"></a>01005 {
<a name="l01006"></a>01006     <span class="keywordflow">if</span> (nbest-&gt;top == NULL)
<a name="l01007"></a>01007         <span class="keywordflow">return</span> NULL;
<a name="l01008"></a>01008     <span class="keywordflow">if</span> (out_score) *out_score = nbest-&gt;top-&gt;<a class="code" href="structps__latpath__s.html#a9249fb528f754db992df1d494a69b580" title="Exact score from start node up to node-&amp;gt;sf.">score</a>;
<a name="l01009"></a>01009     <span class="keywordflow">return</span> <a class="code" href="ps__lattice_8c.html#ac8e3dff7276c03c93377d0cb79fbdbd7" title="Get hypothesis segmentation from A* search.">ps_astar_seg_iter</a>(nbest, nbest-&gt;top, 1.0);
<a name="l01010"></a>01010 }
<a name="l01011"></a>01011 
<a name="l01012"></a>01012 <span class="keywordtype">int</span>
<a name="l01013"></a><a class="code" href="pocketsphinx_8h.html#abb3527e41c2f4cd64dccbdbd5f812d1d">01013</a> <a class="code" href="pocketsphinx_8h.html#abb3527e41c2f4cd64dccbdbd5f812d1d" title="Get the number of frames of data searched.">ps_get_n_frames</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps)
<a name="l01014"></a>01014 {
<a name="l01015"></a>01015     <span class="keywordflow">return</span> ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a> + 1;
<a name="l01016"></a>01016 }
<a name="l01017"></a>01017 
<a name="l01018"></a>01018 <span class="keywordtype">void</span>
<a name="l01019"></a><a class="code" href="pocketsphinx_8h.html#aac7070c934a2d03d0d5b34e19614360f">01019</a> <a class="code" href="pocketsphinx_8h.html#aac7070c934a2d03d0d5b34e19614360f" title="Get performance information for the current utterance.">ps_get_utt_time</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">double</span> *out_nspeech,
<a name="l01020"></a>01020                 <span class="keywordtype">double</span> *out_ncpu, <span class="keywordtype">double</span> *out_nwall)
<a name="l01021"></a>01021 {
<a name="l01022"></a>01022     int32 frate;
<a name="l01023"></a>01023 
<a name="l01024"></a>01024     frate = cmd_ln_int32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-frate&quot;</span>);
<a name="l01025"></a>01025     *out_nspeech = (double)ps-&gt;<a class="code" href="structps__decoder__s.html#af834d2bc1d44c1d9ef607b025413a0b8" title="Acoustic model.">acmod</a>-&gt;<a class="code" href="structacmod__s.html#a00fe2b63f5618d433c33daea2dd54260" title="Index of next frame of dynamic features.">output_frame</a> / frate;
<a name="l01026"></a>01026     *out_ncpu = ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>.t_cpu;
<a name="l01027"></a>01027     *out_nwall = ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>.t_elapsed;
<a name="l01028"></a>01028 }
<a name="l01029"></a>01029 
<a name="l01030"></a>01030 <span class="keywordtype">void</span>
<a name="l01031"></a><a class="code" href="pocketsphinx_8h.html#a61fb92154c5c731cf4a24e0976263da0">01031</a> <a class="code" href="pocketsphinx_8h.html#a61fb92154c5c731cf4a24e0976263da0" title="Get overall performance information.">ps_get_all_time</a>(<a class="code" href="structps__decoder__s.html" title="Decoder object.">ps_decoder_t</a> *ps, <span class="keywordtype">double</span> *out_nspeech,
<a name="l01032"></a>01032                 <span class="keywordtype">double</span> *out_ncpu, <span class="keywordtype">double</span> *out_nwall)
<a name="l01033"></a>01033 {
<a name="l01034"></a>01034     int32 frate;
<a name="l01035"></a>01035 
<a name="l01036"></a>01036     frate = cmd_ln_int32_r(ps-&gt;<a class="code" href="structps__decoder__s.html#a0565ed97b32408bd05c8104f020cef05" title="Configuration.">config</a>, <span class="stringliteral">&quot;-frate&quot;</span>);
<a name="l01037"></a>01037     *out_nspeech = (double)ps-&gt;<a class="code" href="structps__decoder__s.html#a2886b321c576c7def449ebb2f37899fd" title="Total number of frames processed.">n_frame</a> / frate;
<a name="l01038"></a>01038     *out_ncpu = ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>.t_tot_cpu;
<a name="l01039"></a>01039     *out_nwall = ps-&gt;<a class="code" href="structps__decoder__s.html#ab42d1d1e300d2a6df5dd3cd796a27d43" title="Performance counter for all of decoding.">perf</a>.t_tot_elapsed;
<a name="l01040"></a>01040 }
<a name="l01041"></a>01041 
<a name="l01042"></a>01042 <span class="keywordtype">void</span>
<a name="l01043"></a><a class="code" href="pocketsphinx__internal_8h.html#ad848d8d0cf0398542bfb74a2e34dbff3">01043</a> ps_search_init(<a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search, <a class="code" href="structps__searchfuncs__s.html" title="V-table for search algorithm.">ps_searchfuncs_t</a> *vt,
<a name="l01044"></a>01044                cmd_ln_t *config, <a class="code" href="structacmod__s.html" title="Acoustic model structure.">acmod_t</a> *acmod, <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *dict,
<a name="l01045"></a>01045                <a class="code" href="structdict2pid__t.html" title="Building composite triphone (as well as word internal triphones) with the dictionary.">dict2pid_t</a> *d2p)
<a name="l01046"></a>01046 {
<a name="l01047"></a>01047     search-&gt;<a class="code" href="structps__search__s.html#aa51e88956bbe9c05359d32526180809b" title="V-table of search methods.">vt</a> = vt;
<a name="l01048"></a>01048     search-&gt;<a class="code" href="structps__search__s.html#aa6e3e18165bbc70084a06575d5703042" title="Configuration.">config</a> = config;
<a name="l01049"></a>01049     search-&gt;<a class="code" href="structps__search__s.html#a0fdf6fe8c4d9c28f10c48c09517c6b91" title="Acoustic model.">acmod</a> = acmod;
<a name="l01050"></a>01050     <span class="keywordflow">if</span> (d2p)
<a name="l01051"></a>01051         search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a> = <a class="code" href="dict2pid_8c.html#a85a8de8009445e1129766186ddaa949a" title="Retain a pointer to dict2pid.">dict2pid_retain</a>(d2p);
<a name="l01052"></a>01052     <span class="keywordflow">else</span>
<a name="l01053"></a>01053         search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a> = NULL;
<a name="l01054"></a>01054     <span class="keywordflow">if</span> (dict) {
<a name="l01055"></a>01055         search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a> = dict_retain(dict);
<a name="l01056"></a>01056         search-&gt;<a class="code" href="structps__search__s.html#ae1a9fa33bfc851ec91ce96870714b3cc" title="Start word ID.">start_wid</a> = dict_startwid(dict);
<a name="l01057"></a>01057         search-&gt;<a class="code" href="structps__search__s.html#a0fb4d79f1084bdbbc0a808513f7c1ca7" title="Finish word ID.">finish_wid</a> = dict_finishwid(dict);
<a name="l01058"></a>01058         search-&gt;<a class="code" href="structps__search__s.html#ab6851b4675f38ab6b3683d75521f000b" title="Silence word ID.">silence_wid</a> = dict_silwid(dict);
<a name="l01059"></a>01059         search-&gt;<a class="code" href="structps__search__s.html#ad4d98deb905bd664ec44313ea0065b1a" title="Number of words known to search (may be less than in the dictionary)">n_words</a> = <a class="code" href="dict_8h.html#a361b948b42f9cfdf5c7fa9dfc8a71a94" title="Packaged macro access to dictionary members.">dict_size</a>(dict);
<a name="l01060"></a>01060     }
<a name="l01061"></a>01061     <span class="keywordflow">else</span> {
<a name="l01062"></a>01062         search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a> = NULL;
<a name="l01063"></a>01063         search-&gt;<a class="code" href="structps__search__s.html#ae1a9fa33bfc851ec91ce96870714b3cc" title="Start word ID.">start_wid</a> = search-&gt;<a class="code" href="structps__search__s.html#a0fb4d79f1084bdbbc0a808513f7c1ca7" title="Finish word ID.">finish_wid</a> = search-&gt;<a class="code" href="structps__search__s.html#ab6851b4675f38ab6b3683d75521f000b" title="Silence word ID.">silence_wid</a> = -1;
<a name="l01064"></a>01064         search-&gt;<a class="code" href="structps__search__s.html#ad4d98deb905bd664ec44313ea0065b1a" title="Number of words known to search (may be less than in the dictionary)">n_words</a> = 0;
<a name="l01065"></a>01065     }
<a name="l01066"></a>01066 }
<a name="l01067"></a>01067 
<a name="l01068"></a>01068 <span class="keywordtype">void</span>
<a name="l01069"></a><a class="code" href="pocketsphinx__internal_8h.html#a307801961f27bd5f4b82a3e6b83e0ca1">01069</a> ps_search_base_reinit(<a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search, <a class="code" href="structdict__t.html" title="a structure for a dictionary.">dict_t</a> *dict,
<a name="l01070"></a>01070                       <a class="code" href="structdict2pid__t.html" title="Building composite triphone (as well as word internal triphones) with the dictionary.">dict2pid_t</a> *d2p)
<a name="l01071"></a>01071 {
<a name="l01072"></a>01072     dict_free(search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a>);
<a name="l01073"></a>01073     <a class="code" href="dict2pid_8c.html#a293253226550e812c448ae096b364d0d" title="Free the memory dict2pid structure.">dict2pid_free</a>(search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a>);
<a name="l01074"></a>01074     <span class="comment">/* FIXME: _retain() should just return NULL if passed NULL. */</span>
<a name="l01075"></a>01075     <span class="keywordflow">if</span> (dict) {
<a name="l01076"></a>01076         search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a> = dict_retain(dict);
<a name="l01077"></a>01077         search-&gt;<a class="code" href="structps__search__s.html#ae1a9fa33bfc851ec91ce96870714b3cc" title="Start word ID.">start_wid</a> = dict_startwid(dict);
<a name="l01078"></a>01078         search-&gt;<a class="code" href="structps__search__s.html#a0fb4d79f1084bdbbc0a808513f7c1ca7" title="Finish word ID.">finish_wid</a> = dict_finishwid(dict);
<a name="l01079"></a>01079         search-&gt;<a class="code" href="structps__search__s.html#ab6851b4675f38ab6b3683d75521f000b" title="Silence word ID.">silence_wid</a> = dict_silwid(dict);
<a name="l01080"></a>01080         search-&gt;<a class="code" href="structps__search__s.html#ad4d98deb905bd664ec44313ea0065b1a" title="Number of words known to search (may be less than in the dictionary)">n_words</a> = <a class="code" href="dict_8h.html#a361b948b42f9cfdf5c7fa9dfc8a71a94" title="Packaged macro access to dictionary members.">dict_size</a>(dict);
<a name="l01081"></a>01081     }
<a name="l01082"></a>01082     <span class="keywordflow">else</span> {
<a name="l01083"></a>01083         search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a> = NULL;
<a name="l01084"></a>01084         search-&gt;<a class="code" href="structps__search__s.html#ae1a9fa33bfc851ec91ce96870714b3cc" title="Start word ID.">start_wid</a> = search-&gt;<a class="code" href="structps__search__s.html#a0fb4d79f1084bdbbc0a808513f7c1ca7" title="Finish word ID.">finish_wid</a> = search-&gt;<a class="code" href="structps__search__s.html#ab6851b4675f38ab6b3683d75521f000b" title="Silence word ID.">silence_wid</a> = -1;
<a name="l01085"></a>01085         search-&gt;<a class="code" href="structps__search__s.html#ad4d98deb905bd664ec44313ea0065b1a" title="Number of words known to search (may be less than in the dictionary)">n_words</a> = 0;
<a name="l01086"></a>01086     }
<a name="l01087"></a>01087     <span class="keywordflow">if</span> (d2p)
<a name="l01088"></a>01088         search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a> = <a class="code" href="dict2pid_8c.html#a85a8de8009445e1129766186ddaa949a" title="Retain a pointer to dict2pid.">dict2pid_retain</a>(d2p);
<a name="l01089"></a>01089     <span class="keywordflow">else</span>
<a name="l01090"></a>01090         search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a> = NULL;
<a name="l01091"></a>01091 }
<a name="l01092"></a>01092 
<a name="l01093"></a>01093 
<a name="l01094"></a>01094 <span class="keywordtype">void</span>
<a name="l01095"></a><a class="code" href="pocketsphinx__internal_8h.html#a1299496b3498166928702d0701934e50">01095</a> ps_search_deinit(<a class="code" href="structps__search__s.html" title="Base structure for search module.">ps_search_t</a> *search)
<a name="l01096"></a>01096 {
<a name="l01097"></a>01097     <span class="comment">/* FIXME: We will have refcounting on acmod, config, etc, at which</span>
<a name="l01098"></a>01098 <span class="comment">     * point we will free them here too. */</span>
<a name="l01099"></a>01099     dict_free(search-&gt;<a class="code" href="structps__search__s.html#a918f243fa966e72c47f697fb9e60089d" title="Pronunciation dictionary.">dict</a>);
<a name="l01100"></a>01100     <a class="code" href="dict2pid_8c.html#a293253226550e812c448ae096b364d0d" title="Free the memory dict2pid structure.">dict2pid_free</a>(search-&gt;<a class="code" href="structps__search__s.html#a81b461e7ef3a080d046039e186134a15" title="Dictionary to senone mappings.">d2p</a>);
<a name="l01101"></a>01101     ckd_free(search-&gt;<a class="code" href="structps__search__s.html#aa398c736a887af97e42b2a562359adc3" title="Current hypothesis string.">hyp_str</a>);
<a name="l01102"></a>01102     <a class="code" href="ps__lattice_8h.html#a3f90e846bde47cd1acdff165b92f5c22" title="Free a lattice.">ps_lattice_free</a>(search-&gt;<a class="code" href="structps__search__s.html#a897f46c55d17e817ff1364f555b31463" title="Current hypothesis word graph.">dag</a>);
<a name="l01103"></a>01103 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>pocketsphinx.c</b>      </li>
      <li class="footer">Generated on Wed Apr 20 2011 for PocketSphinx 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>