Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > e9280da098bff237733732ce38a34d57 > files > 19

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>PocketSphinx: src/libpocketsphinx/bin_mdef.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('bin__mdef_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>src/libpocketsphinx/bin_mdef.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) 2005 Carnegie Mellon University.  All rights </span>
<a name="l00004"></a>00004 <span class="comment"> * reserved.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00007"></a>00007 <span class="comment"> * modification, are permitted provided that the following conditions</span>
<a name="l00008"></a>00008 <span class="comment"> * are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<a name="l00011"></a>00011 <span class="comment"> *    notice, this list of conditions and the following disclaimer. </span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> *    notice, this list of conditions and the following disclaimer in</span>
<a name="l00015"></a>00015 <span class="comment"> *    the documentation and/or other materials provided with the</span>
<a name="l00016"></a>00016 <span class="comment"> *    distribution.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * This work was supported in part by funding from the Defense Advanced </span>
<a name="l00019"></a>00019 <span class="comment"> * Research Projects Agency and the National Science Foundation of the </span>
<a name="l00020"></a>00020 <span class="comment"> * United States of America, and the CMU Sphinx Speech Consortium.</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS&#39;&#39; AND </span>
<a name="l00023"></a>00023 <span class="comment"> * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, </span>
<a name="l00024"></a>00024 <span class="comment"> * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span>
<a name="l00025"></a>00025 <span class="comment"> * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY</span>
<a name="l00026"></a>00026 <span class="comment"> * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00027"></a>00027 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT </span>
<a name="l00028"></a>00028 <span class="comment"> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, </span>
<a name="l00029"></a>00029 <span class="comment"> * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY </span>
<a name="l00030"></a>00030 <span class="comment"> * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT </span>
<a name="l00031"></a>00031 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </span>
<a name="l00032"></a>00032 <span class="comment"> * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00033"></a>00033 <span class="comment"> *</span>
<a name="l00034"></a>00034 <span class="comment"> * ====================================================================</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> */</span>
<a name="l00037"></a>00037 <span class="comment">/*********************************************************************</span>
<a name="l00038"></a>00038 <span class="comment"> *</span>
<a name="l00039"></a>00039 <span class="comment"> * File: bin_mdef.c</span>
<a name="l00040"></a>00040 <span class="comment"> * </span>
<a name="l00041"></a>00041 <span class="comment"> * Description: </span>
<a name="l00042"></a>00042 <span class="comment"> *      Binary format model definition files, with support for</span>
<a name="l00043"></a>00043 <span class="comment"> *      heterogeneous topologies and variable-size N-phones</span>
<a name="l00044"></a>00044 <span class="comment"> *</span>
<a name="l00045"></a>00045 <span class="comment"> * Author: </span>
<a name="l00046"></a>00046 <span class="comment"> *      David Huggins-Daines &lt;dhuggins@cs.cmu.edu&gt;</span>
<a name="l00047"></a>00047 <span class="comment"> *********************************************************************/</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="comment">/* System headers. */</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00053"></a>00053 
<a name="l00054"></a>00054 <span class="comment">/* SphinxBase headers. */</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;sphinxbase/prim_type.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;sphinxbase/ckd_alloc.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;sphinxbase/byteorder.h&gt;</span>
<a name="l00058"></a>00058 <span class="preprocessor">#include &lt;sphinxbase/case.h&gt;</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &lt;sphinxbase/err.h&gt;</span>
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 <span class="comment">/* Local headers. */</span>
<a name="l00062"></a>00062 <span class="preprocessor">#include &quot;<a class="code" href="mdef_8h.html" title="Model definition.">mdef.h</a>&quot;</span>
<a name="l00063"></a>00063 <span class="preprocessor">#include &quot;<a class="code" href="bin__mdef_8h.html" title="Binary format model definition files, with support for heterogeneous topologies and variable-size N-p...">bin_mdef.h</a>&quot;</span>
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *
<a name="l00066"></a><a class="code" href="bin__mdef_8h.html#a6e0b10d8bf2c17f268e090f36fe0a60e">00066</a> bin_mdef_read_text(cmd_ln_t *<a class="code" href="structacmod__s.html#a3563f4d0bdc48d3ee140b9e28806279d" title="Configuration.">config</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068     <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *bmdef;
<a name="l00069"></a>00069     <a class="code" href="structmdef__t.html" title="The main model definition structure.">mdef_t</a> *<a class="code" href="structacmod__s.html#a351548ff5547c29b4a684e10434a51dd" title="Model definition.">mdef</a>;
<a name="l00070"></a>00070     <span class="keywordtype">int</span> i, nodes, ci_idx, lc_idx, rc_idx;
<a name="l00071"></a>00071     <span class="keywordtype">int</span> nchars;
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="keywordflow">if</span> ((mdef = <a class="code" href="mdef_8h.html#a8f2fb119373324175bf82ad2c403e2be" title="Initialize the phone structure from the given model definition file.">mdef_init</a>((<span class="keywordtype">char</span> *) filename, TRUE)) == NULL)
<a name="l00074"></a>00074         <span class="keywordflow">return</span> NULL;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="comment">/* Enforce some limits.  */</span>
<a name="l00077"></a>00077     <span class="keywordflow">if</span> (mdef-&gt;<a class="code" href="structmdef__t.html#a966e28ae25bd8e766dbe81549cbdcd36" title="number senones (CI+CD)">n_sen</a> &gt; <a class="code" href="bin__mdef_8h.html#ab6c771eca798ab8c94e0933a1f8daafc" title="Invalid senone ID (limited to 16 bits for PocketSphinx).">BAD_SENID</a>) {
<a name="l00078"></a>00078         E_ERROR(<span class="stringliteral">&quot;Number of senones exceeds limit: %d &gt; %d\n&quot;</span>,
<a name="l00079"></a>00079                 mdef-&gt;<a class="code" href="structmdef__t.html#a966e28ae25bd8e766dbe81549cbdcd36" title="number senones (CI+CD)">n_sen</a>, <a class="code" href="bin__mdef_8h.html#ab6c771eca798ab8c94e0933a1f8daafc" title="Invalid senone ID (limited to 16 bits for PocketSphinx).">BAD_SENID</a>);
<a name="l00080"></a>00080         mdef_free(mdef);
<a name="l00081"></a>00081         <span class="keywordflow">return</span> NULL;
<a name="l00082"></a>00082     }
<a name="l00083"></a>00083     <span class="keywordflow">if</span> (mdef-&gt;<a class="code" href="structmdef__t.html#ad9afd537734fe1f336e20218da28fb2c" title="No.">n_sseq</a> &gt; <a class="code" href="bin__mdef_8h.html#a8ee283c316e9f4aa8e6d18c1d44026bc" title="Invalid senone sequence ID (limited to 16 bits for PocketSphinx).">BAD_SSID</a>) {
<a name="l00084"></a>00084         E_ERROR(<span class="stringliteral">&quot;Number of senone sequences exceeds limit: %d &gt; %d\n&quot;</span>,
<a name="l00085"></a>00085                 mdef-&gt;<a class="code" href="structmdef__t.html#ad9afd537734fe1f336e20218da28fb2c" title="No.">n_sseq</a>, <a class="code" href="bin__mdef_8h.html#a8ee283c316e9f4aa8e6d18c1d44026bc" title="Invalid senone sequence ID (limited to 16 bits for PocketSphinx).">BAD_SSID</a>);
<a name="l00086"></a>00086         mdef_free(mdef);
<a name="l00087"></a>00087         <span class="keywordflow">return</span> NULL;
<a name="l00088"></a>00088     }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 
<a name="l00091"></a>00091     bmdef = ckd_calloc(1, <span class="keyword">sizeof</span>(*bmdef));
<a name="l00092"></a>00092     bmdef-&gt;refcnt = 1;
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="comment">/* Easy stuff.  The mdef.c code has done the heavy lifting for us. */</span>
<a name="l00095"></a>00095     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a> = mdef-&gt;<a class="code" href="structmdef__t.html#af460d8d703782cf50ed99164cee17347" title="number basephones actually present">n_ciphone</a>;
<a name="l00096"></a>00096     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a987f0b9bc4c951ac031f5d283960bd9f" title="number basephones + number triphones actually present">n_phone</a>;
<a name="l00097"></a>00097     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a4a7ffa9d1b9a95a3bf3cca7bd955020a" title="number emitting states per phone">n_emit_state</a>;
<a name="l00098"></a>00098     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a68c3cc85b849363609fd5dadf412a38c" title="number CI senones; these are the first">n_ci_sen</a>;
<a name="l00099"></a>00099     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a966e28ae25bd8e766dbe81549cbdcd36" title="number senones (CI+CD)">n_sen</a>;
<a name="l00100"></a>00100     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a979557ad4f8369e84d93f633512345ca" title="Number of transition matrices.">n_tmat</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a44d1d9fd99db66f1c37937e89172fed9" title="number transition matrices">n_tmat</a>;
<a name="l00101"></a>00101     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a> = mdef-&gt;<a class="code" href="structmdef__t.html#ad9afd537734fe1f336e20218da28fb2c" title="No.">n_sseq</a>;
<a name="l00102"></a>00102     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a2472170a66d451d2d4873a9a6e64adc7" title="Unique state (or senone) sequences in this model, shared among all phones/triphones.">sseq</a>;
<a name="l00103"></a>00103     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a> = mdef-&gt;<a class="code" href="structmdef__t.html#ae2ba90b39a79603022daae3c9270a0b7" title="Parent CI-senone id for each senone; the first n_ci_sen are identity mappings; the CD-senones are con...">cd2cisen</a>;
<a name="l00104"></a>00104     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a4aafd791a1e1adaa9b5b28bf0cfbd624" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>;
<a name="l00105"></a>00105     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a31b5cda5136c6f72816da8889719bfe2" title="Number of phones of context.">n_ctx</a> = 3;           <span class="comment">/* Triphones only. */</span>
<a name="l00106"></a>00106     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> = mdef-&gt;<a class="code" href="structmdef__t.html#acc9a57b57bbecaef55cc72be57b875f6" title="SILENCE_CIPHONE id.">sil</a>;
<a name="l00107"></a>00107     mdef-&gt;<a class="code" href="structmdef__t.html#a2472170a66d451d2d4873a9a6e64adc7" title="Unique state (or senone) sequences in this model, shared among all phones/triphones.">sseq</a> = NULL;          <span class="comment">/* We are taking over this one. */</span>
<a name="l00108"></a>00108     mdef-&gt;<a class="code" href="structmdef__t.html#ae2ba90b39a79603022daae3c9270a0b7" title="Parent CI-senone id for each senone; the first n_ci_sen are identity mappings; the CD-senones are con...">cd2cisen</a> = NULL;      <span class="comment">/* And this one. */</span>
<a name="l00109"></a>00109     mdef-&gt;<a class="code" href="structmdef__t.html#a4aafd791a1e1adaa9b5b28bf0cfbd624" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a> = NULL;     <span class="comment">/* And this one. */</span>
<a name="l00110"></a>00110 
<a name="l00111"></a>00111     <span class="comment">/* Get the phone names.  If they are not sorted</span>
<a name="l00112"></a>00112 <span class="comment">     * ASCII-betically then we are in a world of hurt and</span>
<a name="l00113"></a>00113 <span class="comment">     * therefore will simply refuse to continue. */</span>
<a name="l00114"></a>00114     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a> = ckd_calloc(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>, <span class="keyword">sizeof</span>(*bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>));
<a name="l00115"></a>00115     nchars = 0;
<a name="l00116"></a>00116     <span class="keywordflow">for</span> (i = 0; i &lt; bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>; ++i)
<a name="l00117"></a>00117         nchars += strlen(mdef-&gt;<a class="code" href="structmdef__t.html#aae4a51202b87f71394b6c5b3138b77c7" title="CI-phone information for all ciphones.">ciphone</a>[i].<a class="code" href="structciphone__t.html#a2327c5f09fa245c25926c718fdab642d" title="The name of the CI phone.">name</a>) + 1;
<a name="l00118"></a>00118     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0] = ckd_calloc(nchars, 1);
<a name="l00119"></a>00119     strcpy(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0], mdef-&gt;<a class="code" href="structmdef__t.html#aae4a51202b87f71394b6c5b3138b77c7" title="CI-phone information for all ciphones.">ciphone</a>[0].<a class="code" href="structciphone__t.html#a2327c5f09fa245c25926c718fdab642d" title="The name of the CI phone.">name</a>);
<a name="l00120"></a>00120     <span class="keywordflow">for</span> (i = 1; i &lt; bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>; ++i) {
<a name="l00121"></a>00121         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i] =
<a name="l00122"></a>00122             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1] + strlen(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1]) + 1;
<a name="l00123"></a>00123         strcpy(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i], mdef-&gt;<a class="code" href="structmdef__t.html#aae4a51202b87f71394b6c5b3138b77c7" title="CI-phone information for all ciphones.">ciphone</a>[i].<a class="code" href="structciphone__t.html#a2327c5f09fa245c25926c718fdab642d" title="The name of the CI phone.">name</a>);
<a name="l00124"></a>00124         <span class="keywordflow">if</span> (i &gt; 0 &amp;&amp; strcmp(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1], bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i]) &gt; 0) {
<a name="l00125"></a>00125             <span class="comment">/* FIXME: there should be a solution to this, actually. */</span>
<a name="l00126"></a>00126             E_ERROR(<span class="stringliteral">&quot;Phone names are not in sorted order, sorry.&quot;</span>);
<a name="l00127"></a>00127             bin_mdef_free(bmdef);
<a name="l00128"></a>00128             <span class="keywordflow">return</span> NULL;
<a name="l00129"></a>00129         }
<a name="l00130"></a>00130     }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132     <span class="comment">/* Copy over phone information. */</span>
<a name="l00133"></a>00133     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a> = ckd_calloc(bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>, <span class="keyword">sizeof</span>(*bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>));
<a name="l00134"></a>00134     <span class="keywordflow">for</span> (i = 0; i &lt; mdef-&gt;<a class="code" href="structmdef__t.html#a987f0b9bc4c951ac031f5d283960bd9f" title="number basephones + number triphones actually present">n_phone</a>; ++i) {
<a name="l00135"></a>00135         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].<a class="code" href="structphone__t.html#af2f31836358c1c29c38a361b3923b859" title="State sequence (or senone sequence) ID, considering the n_emit_state senone-ids are a unit...">ssid</a>;
<a name="l00136"></a>00136         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a90758df5d6eb00d3a70135ac4475c7a1" title="Transition matrix ID.">tmat</a> = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].<a class="code" href="structphone__t.html#acbe38b7fc991bfbcb745fb6131d812f0" title="Transition matrix id.">tmat</a>;
<a name="l00137"></a>00137         <span class="keywordflow">if</span> (i &lt; bmdef-&gt;n_ciphone) {
<a name="l00138"></a>00138             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].info.<a class="code" href="structmdef__entry__s.html#a24e5db7af5e705b310e82154055043ec" title="CD phone information - context info.">ci</a>.filler = mdef-&gt;<a class="code" href="structmdef__t.html#aae4a51202b87f71394b6c5b3138b77c7" title="CI-phone information for all ciphones.">ciphone</a>[i].<a class="code" href="structciphone__t.html#a96e20b175c00c4edcd75d922dba067cd" title="Whether a filler phone; if so, can be substituted by silence phone in left or right context position...">filler</a>;
<a name="l00139"></a>00139         }
<a name="l00140"></a>00140         <span class="keywordflow">else</span> {
<a name="l00141"></a>00141             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].info.cd.wpos = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].<a class="code" href="structphone__t.html#a5436db1dd178ef5ead83359c84963c83" title="Word position.">wpos</a>;
<a name="l00142"></a>00142             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].info.cd.ctx[0] = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].ci;
<a name="l00143"></a>00143             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].info.cd.ctx[1] = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].lc;
<a name="l00144"></a>00144             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].info.cd.ctx[2] = mdef-&gt;<a class="code" href="structmdef__t.html#a2b9aaf78e5648fe14655d1fe8da5f164" title="Information for all ciphones and triphones.">phone</a>[i].<a class="code" href="structphone__t.html#a334106cbedf3d95a6bdebc4704e028cd" title="Base, left, right context ciphones.">rc</a>;
<a name="l00145"></a>00145         }
<a name="l00146"></a>00146     }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     <span class="comment">/* Walk the wpos_ci_lclist once to find the total number of</span>
<a name="l00149"></a>00149 <span class="comment">     * nodes and the starting locations for each level. */</span>
<a name="l00150"></a>00150     nodes = lc_idx = ci_idx = rc_idx = 0;
<a name="l00151"></a>00151     <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>; ++i) {
<a name="l00152"></a>00152         <span class="keywordtype">int</span> j;
<a name="l00153"></a>00153         <span class="keywordflow">for</span> (j = 0; j &lt; mdef-&gt;<a class="code" href="structmdef__t.html#af460d8d703782cf50ed99164cee17347" title="number basephones actually present">n_ciphone</a>; ++j) {
<a name="l00154"></a>00154             <a class="code" href="structph__lc__t.html" title="Structures for storing the left context.">ph_lc_t</a> *lc;
<a name="l00155"></a>00155 
<a name="l00156"></a>00156             <span class="keywordflow">for</span> (lc = mdef-&gt;<a class="code" href="structmdef__t.html#a5dd5c3d3058a314f4c971a14d1df5f38" title="wpos_ci_lclist[wpos][ci] = list of lc for &amp;lt;wpos,ci&amp;gt;.">wpos_ci_lclist</a>[i][j]; lc; lc = lc-&gt;next) {
<a name="l00157"></a>00157                 <a class="code" href="structph__rc__t.html" title="Structures needed for mapping &amp;lt;ci,lc,rc,wpos&amp;gt; into pid.">ph_rc_t</a> *rc;
<a name="l00158"></a>00158                 <span class="keywordflow">for</span> (rc = lc-&gt;rclist; rc; rc = rc-&gt;next) {
<a name="l00159"></a>00159                     ++nodes;    <span class="comment">/* RC node */</span>
<a name="l00160"></a>00160                 }
<a name="l00161"></a>00161                 ++nodes;        <span class="comment">/* LC node */</span>
<a name="l00162"></a>00162                 ++rc_idx;       <span class="comment">/* Start of RC nodes (after LC nodes) */</span>
<a name="l00163"></a>00163             }
<a name="l00164"></a>00164             ++nodes;            <span class="comment">/* CI node */</span>
<a name="l00165"></a>00165             ++lc_idx;           <span class="comment">/* Start of LC nodes (after CI nodes) */</span>
<a name="l00166"></a>00166             ++rc_idx;           <span class="comment">/* Start of RC nodes (after CI and LC nodes) */</span>
<a name="l00167"></a>00167         }
<a name="l00168"></a>00168         ++nodes;                <span class="comment">/* wpos node */</span>
<a name="l00169"></a>00169         ++ci_idx;               <span class="comment">/* Start of CI nodes (after wpos nodes) */</span>
<a name="l00170"></a>00170         ++lc_idx;               <span class="comment">/* Start of LC nodes (after CI nodes) */</span>
<a name="l00171"></a>00171         ++rc_idx;               <span class="comment">/* STart of RC nodes (after wpos, CI, and LC nodes) */</span>
<a name="l00172"></a>00172     }
<a name="l00173"></a>00173     E_INFO(<span class="stringliteral">&quot;Allocating %d * %d bytes (%d KiB) for CD tree\n&quot;</span>,
<a name="l00174"></a>00174            nodes, <span class="keyword">sizeof</span>(*bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>), 
<a name="l00175"></a>00175            nodes * <span class="keyword">sizeof</span>(*bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>) / 1024);
<a name="l00176"></a>00176     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a> = nodes;
<a name="l00177"></a>00177     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a> = ckd_calloc(nodes, <span class="keyword">sizeof</span>(*bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>));
<a name="l00178"></a>00178     <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>; ++i) {
<a name="l00179"></a>00179         <span class="keywordtype">int</span> j;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a> = i;
<a name="l00182"></a>00182         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a> = mdef-&gt;<a class="code" href="structmdef__t.html#af460d8d703782cf50ed99164cee17347" title="number basephones actually present">n_ciphone</a>;
<a name="l00183"></a>00183         bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a> = ci_idx;
<a name="l00184"></a>00184 <span class="preprocessor">#if 0</span>
<a name="l00185"></a>00185 <span class="preprocessor"></span>        E_INFO(<span class="stringliteral">&quot;%d =&gt; %c (%d@%d)\n&quot;</span>,
<a name="l00186"></a>00186                i, (<a class="code" href="mdef_8h.html#a89ef0442ded2ff90176ba6d02563923d" title="Printable code for each word position above.">WPOS_NAME</a>)[i],
<a name="l00187"></a>00187                bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>, bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00188"></a>00188 <span class="preprocessor">#endif</span>
<a name="l00189"></a>00189 <span class="preprocessor"></span>
<a name="l00190"></a>00190         <span class="comment">/* Now we can build the rest of the tree. */</span>
<a name="l00191"></a>00191         <span class="keywordflow">for</span> (j = 0; j &lt; mdef-&gt;<a class="code" href="structmdef__t.html#af460d8d703782cf50ed99164cee17347" title="number basephones actually present">n_ciphone</a>; ++j) {
<a name="l00192"></a>00192             <a class="code" href="structph__lc__t.html" title="Structures for storing the left context.">ph_lc_t</a> *lc;
<a name="l00193"></a>00193 
<a name="l00194"></a>00194             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a> = j;
<a name="l00195"></a>00195             bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a> = lc_idx;
<a name="l00196"></a>00196             <span class="keywordflow">for</span> (lc = mdef-&gt;<a class="code" href="structmdef__t.html#a5dd5c3d3058a314f4c971a14d1df5f38" title="wpos_ci_lclist[wpos][ci] = list of lc for &amp;lt;wpos,ci&amp;gt;.">wpos_ci_lclist</a>[i][j]; lc; lc = lc-&gt;next) {
<a name="l00197"></a>00197                 <a class="code" href="structph__rc__t.html" title="Structures needed for mapping &amp;lt;ci,lc,rc,wpos&amp;gt; into pid.">ph_rc_t</a> *rc;
<a name="l00198"></a>00198 
<a name="l00199"></a>00199                 bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a> = lc-&gt;lc;
<a name="l00200"></a>00200                 bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a> = rc_idx;
<a name="l00201"></a>00201                 <span class="keywordflow">for</span> (rc = lc-&gt;rclist; rc; rc = rc-&gt;next) {
<a name="l00202"></a>00202                     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[rc_idx].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a> = rc-&gt;rc;
<a name="l00203"></a>00203                     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[rc_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a> = 0;
<a name="l00204"></a>00204                     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[rc_idx].c.<a class="code" href="structcd__tree__s.html#a6635c35ad6fe74ad045389c76349016d" title="Phone ID (leafnode)">pid</a> = rc-&gt;pid;
<a name="l00205"></a>00205 <span class="preprocessor">#if 0</span>
<a name="l00206"></a>00206 <span class="preprocessor"></span>                    E_INFO(<span class="stringliteral">&quot;%d =&gt; %s %s %s %c (%d@%d)\n&quot;</span>,
<a name="l00207"></a>00207                            rc_idx,
<a name="l00208"></a>00208                            bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[j],
<a name="l00209"></a>00209                            bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[lc-&gt;lc],
<a name="l00210"></a>00210                            bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[rc-&gt;rc],
<a name="l00211"></a>00211                            (<a class="code" href="mdef_8h.html#a89ef0442ded2ff90176ba6d02563923d" title="Printable code for each word position above.">WPOS_NAME</a>)[i],
<a name="l00212"></a>00212                            bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[rc_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>,
<a name="l00213"></a>00213                            bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[rc_idx].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00214"></a>00214 <span class="preprocessor">#endif</span>
<a name="l00215"></a>00215 <span class="preprocessor"></span>
<a name="l00216"></a>00216                     ++bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>;
<a name="l00217"></a>00217                     ++rc_idx;
<a name="l00218"></a>00218                 }
<a name="l00219"></a>00219                 <span class="comment">/* If there are no triphones here,</span>
<a name="l00220"></a>00220 <span class="comment">                 * this is considered a leafnode, so</span>
<a name="l00221"></a>00221 <span class="comment">                 * set the pid to -1. */</span>
<a name="l00222"></a>00222                 <span class="keywordflow">if</span> (bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a> == 0)
<a name="l00223"></a>00223                     bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].c.<a class="code" href="structcd__tree__s.html#a6635c35ad6fe74ad045389c76349016d" title="Phone ID (leafnode)">pid</a> = -1;
<a name="l00224"></a>00224 <span class="preprocessor">#if 0</span>
<a name="l00225"></a>00225 <span class="preprocessor"></span>                E_INFO(<span class="stringliteral">&quot;%d =&gt; %s %s %c (%d@%d)\n&quot;</span>,
<a name="l00226"></a>00226                        lc_idx,
<a name="l00227"></a>00227                        bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[j],
<a name="l00228"></a>00228                        bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[lc-&gt;lc],
<a name="l00229"></a>00229                        (<a class="code" href="mdef_8h.html#a89ef0442ded2ff90176ba6d02563923d" title="Printable code for each word position above.">WPOS_NAME</a>)[i],
<a name="l00230"></a>00230                        bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>,
<a name="l00231"></a>00231                        bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[lc_idx].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00232"></a>00232 <span class="preprocessor">#endif</span>
<a name="l00233"></a>00233 <span class="preprocessor"></span>
<a name="l00234"></a>00234                 ++bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>;
<a name="l00235"></a>00235                 ++lc_idx;
<a name="l00236"></a>00236             }
<a name="l00237"></a>00237 
<a name="l00238"></a>00238             <span class="comment">/* As above, so below. */</span>
<a name="l00239"></a>00239             <span class="keywordflow">if</span> (bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a> == 0)
<a name="l00240"></a>00240                 bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].c.<a class="code" href="structcd__tree__s.html#a6635c35ad6fe74ad045389c76349016d" title="Phone ID (leafnode)">pid</a> = -1;
<a name="l00241"></a>00241 <span class="preprocessor">#if 0</span>
<a name="l00242"></a>00242 <span class="preprocessor"></span>            E_INFO(<span class="stringliteral">&quot;%d =&gt; %d=%s (%d@%d)\n&quot;</span>,
<a name="l00243"></a>00243                    ci_idx, j, bmdef-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[j],
<a name="l00244"></a>00244                    bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>,
<a name="l00245"></a>00245                    bmdef-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[ci_idx].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00246"></a>00246 <span class="preprocessor">#endif</span>
<a name="l00247"></a>00247 <span class="preprocessor"></span>
<a name="l00248"></a>00248             ++ci_idx;
<a name="l00249"></a>00249         }
<a name="l00250"></a>00250     }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252     mdef_free(mdef);
<a name="l00253"></a>00253 
<a name="l00254"></a>00254     bmdef-&gt;alloc_mode = BIN_MDEF_FROM_TEXT;
<a name="l00255"></a>00255     <span class="keywordflow">return</span> bmdef;
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 
<a name="l00258"></a>00258 <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *
<a name="l00259"></a><a class="code" href="bin__mdef_8h.html#a297167f03662a9cbd650743d3f4cf8f8">00259</a> bin_mdef_retain(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *m)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261     ++m-&gt;refcnt;
<a name="l00262"></a>00262     <span class="keywordflow">return</span> m;
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <span class="keywordtype">int</span>
<a name="l00266"></a><a class="code" href="bin__mdef_8h.html#afe7ed87e2a2d22b228c14ed8225e4b2c">00266</a> bin_mdef_free(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m)
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268     <span class="keywordflow">if</span> (m == NULL)
<a name="l00269"></a>00269         <span class="keywordflow">return</span> 0;
<a name="l00270"></a>00270     <span class="keywordflow">if</span> (--m-&gt;refcnt &gt; 0)
<a name="l00271"></a>00271         <span class="keywordflow">return</span> m-&gt;refcnt;
<a name="l00272"></a>00272 
<a name="l00273"></a>00273     <span class="keywordflow">switch</span> (m-&gt;alloc_mode) {
<a name="l00274"></a>00274     <span class="keywordflow">case</span> BIN_MDEF_FROM_TEXT:
<a name="l00275"></a>00275         ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0]);
<a name="l00276"></a>00276         ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0]);
<a name="l00277"></a>00277         ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>);
<a name="l00278"></a>00278         ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>);
<a name="l00279"></a>00279         <span class="keywordflow">break</span>;
<a name="l00280"></a>00280     <span class="keywordflow">case</span> BIN_MDEF_IN_MEMORY:
<a name="l00281"></a>00281         ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0]);
<a name="l00282"></a>00282         <span class="keywordflow">break</span>;
<a name="l00283"></a>00283     <span class="keywordflow">case</span> BIN_MDEF_ON_DISK:
<a name="l00284"></a>00284         <span class="keywordflow">break</span>;
<a name="l00285"></a>00285     }
<a name="l00286"></a>00286     <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a3358a80c50bf3f62417596553adf9c5e" title="File map for this file (if any)">filemap</a>)
<a name="l00287"></a>00287         mmio_file_unmap(m-&gt;<a class="code" href="structbin__mdef__s.html#a3358a80c50bf3f62417596553adf9c5e" title="File map for this file (if any)">filemap</a>);
<a name="l00288"></a>00288     ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a>);
<a name="l00289"></a>00289     ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>);
<a name="l00290"></a>00290     ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>);
<a name="l00291"></a>00291     ckd_free(m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>);
<a name="l00292"></a>00292     ckd_free(m);
<a name="l00293"></a>00293     <span class="keywordflow">return</span> 0;
<a name="l00294"></a>00294 }
<a name="l00295"></a>00295 
<a name="l00296"></a>00296 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> format_desc[] =
<a name="l00297"></a>00297     <span class="stringliteral">&quot;BEGIN FILE FORMAT DESCRIPTION\n&quot;</span>
<a name="l00298"></a>00298     <span class="stringliteral">&quot;int32 n_ciphone;    /**&lt; Number of base (CI) phones */\n&quot;</span>
<a name="l00299"></a>00299     <span class="stringliteral">&quot;int32 n_phone;          /**&lt; Number of base (CI) phones + (CD) triphones */\n&quot;</span>
<a name="l00300"></a>00300     <span class="stringliteral">&quot;int32 n_emit_state; /**&lt; Number of emitting states per phone (0 if heterogeneous) */\n&quot;</span>
<a name="l00301"></a>00301     <span class="stringliteral">&quot;int32 n_ci_sen;     /**&lt; Number of CI senones; these are the first */\n&quot;</span>
<a name="l00302"></a>00302     <span class="stringliteral">&quot;int32 n_sen;            /**&lt; Number of senones (CI+CD) */\n&quot;</span>
<a name="l00303"></a>00303     <span class="stringliteral">&quot;int32 n_tmat;           /**&lt; Number of transition matrices */\n&quot;</span>
<a name="l00304"></a>00304     <span class="stringliteral">&quot;int32 n_sseq;       /**&lt; Number of unique senone sequences */\n&quot;</span>
<a name="l00305"></a>00305     <span class="stringliteral">&quot;int32 n_ctx;            /**&lt; Number of phones of context */\n&quot;</span>
<a name="l00306"></a>00306     <span class="stringliteral">&quot;int32 n_cd_tree;    /**&lt; Number of nodes in CD tree structure */\n&quot;</span>
<a name="l00307"></a>00307     <span class="stringliteral">&quot;int32 sil;      /**&lt; CI phone ID for silence */\n&quot;</span>
<a name="l00308"></a>00308     <span class="stringliteral">&quot;char ciphones[][];  /**&lt; CI phone strings (null-terminated) */\n&quot;</span>
<a name="l00309"></a>00309     <span class="stringliteral">&quot;char padding[];     /**&lt; Padding to a 4-bytes boundary */\n&quot;</span>
<a name="l00310"></a>00310     <span class="stringliteral">&quot;struct { int16 ctx; int16 n_down; int32 pid/down } cd_tree[];\n&quot;</span>
<a name="l00311"></a>00311     <span class="stringliteral">&quot;struct { int32 ssid; int32 tmat; int8 attr[4] } phones[];\n&quot;</span>
<a name="l00312"></a>00312     <span class="stringliteral">&quot;int16 sseq[];       /**&lt; Unique senone sequences */\n&quot;</span>
<a name="l00313"></a>00313     <span class="stringliteral">&quot;int8 sseq_len[];    /**&lt; Number of states in each sseq (none if homogeneous) */\n&quot;</span>
<a name="l00314"></a>00314     <span class="stringliteral">&quot;END FILE FORMAT DESCRIPTION\n&quot;</span>;
<a name="l00315"></a>00315 
<a name="l00316"></a>00316 <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *
<a name="l00317"></a><a class="code" href="bin__mdef_8h.html#a2c16ffe816aaa870f271048036833d44">00317</a> bin_mdef_read(cmd_ln_t *<a class="code" href="structacmod__s.html#a3563f4d0bdc48d3ee140b9e28806279d" title="Configuration.">config</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00318"></a>00318 {
<a name="l00319"></a>00319     <a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> *m;
<a name="l00320"></a>00320     FILE *fh;
<a name="l00321"></a>00321     <span class="keywordtype">size_t</span> tree_start;
<a name="l00322"></a>00322     int32 val, i, swap, pos, end;
<a name="l00323"></a>00323     int32 *sseq_size;
<a name="l00324"></a>00324     <span class="keywordtype">int</span> do_mmap;
<a name="l00325"></a>00325 
<a name="l00326"></a>00326     <span class="comment">/* Try to read it as text first. */</span>
<a name="l00327"></a>00327     <span class="keywordflow">if</span> ((m = bin_mdef_read_text(config, filename)) != NULL)
<a name="l00328"></a>00328         <span class="keywordflow">return</span> m;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     E_INFO(<span class="stringliteral">&quot;Reading binary model definition: %s\n&quot;</span>, filename);
<a name="l00331"></a>00331     <span class="keywordflow">if</span> ((fh = fopen(filename, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL)
<a name="l00332"></a>00332         <span class="keywordflow">return</span> NULL;
<a name="l00333"></a>00333 
<a name="l00334"></a>00334     <span class="keywordflow">if</span> (fread(&amp;val, 4, 1, fh) != 1) {
<a name="l00335"></a>00335         fclose(fh);
<a name="l00336"></a>00336         E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to read byte-order marker from %s\n&quot;</span>,
<a name="l00337"></a>00337                        filename);
<a name="l00338"></a>00338         <span class="keywordflow">return</span> NULL;
<a name="l00339"></a>00339     }
<a name="l00340"></a>00340     swap = 0;
<a name="l00341"></a>00341     <span class="keywordflow">if</span> (val == BIN_MDEF_OTHER_ENDIAN) {
<a name="l00342"></a>00342         swap = 1;
<a name="l00343"></a>00343         E_INFO(<span class="stringliteral">&quot;Must byte-swap %s\n&quot;</span>, filename);
<a name="l00344"></a>00344     }
<a name="l00345"></a>00345     <span class="keywordflow">if</span> (fread(&amp;val, 4, 1, fh) != 1) {
<a name="l00346"></a>00346         fclose(fh);
<a name="l00347"></a>00347         E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to read version from %s\n&quot;</span>, filename);
<a name="l00348"></a>00348         <span class="keywordflow">return</span> NULL;
<a name="l00349"></a>00349     }
<a name="l00350"></a>00350     <span class="keywordflow">if</span> (swap)
<a name="l00351"></a>00351         SWAP_INT32(&amp;val);
<a name="l00352"></a>00352     <span class="keywordflow">if</span> (val &gt; BIN_MDEF_FORMAT_VERSION) {
<a name="l00353"></a>00353         E_ERROR(<span class="stringliteral">&quot;File format version %d for %s is newer than library\n&quot;</span>,
<a name="l00354"></a>00354                 val, filename);
<a name="l00355"></a>00355         fclose(fh);
<a name="l00356"></a>00356         <span class="keywordflow">return</span> NULL;
<a name="l00357"></a>00357     }
<a name="l00358"></a>00358     <span class="keywordflow">if</span> (fread(&amp;val, 4, 1, fh) != 1) {
<a name="l00359"></a>00359         fclose(fh);
<a name="l00360"></a>00360         E_ERROR_SYSTEM(<span class="stringliteral">&quot;Failed to read header length from %s\n&quot;</span>, filename);
<a name="l00361"></a>00361         <span class="keywordflow">return</span> NULL;
<a name="l00362"></a>00362     }
<a name="l00363"></a>00363     <span class="keywordflow">if</span> (swap)
<a name="l00364"></a>00364         SWAP_INT32(&amp;val);
<a name="l00365"></a>00365     <span class="comment">/* Skip format descriptor. */</span>
<a name="l00366"></a>00366     fseek(fh, val, SEEK_CUR);
<a name="l00367"></a>00367 
<a name="l00368"></a>00368     <span class="comment">/* Finally allocate it. */</span>
<a name="l00369"></a>00369     m = ckd_calloc(1, <span class="keyword">sizeof</span>(*m));
<a name="l00370"></a>00370     m-&gt;refcnt = 1;
<a name="l00371"></a>00371 
<a name="l00372"></a>00372     <span class="comment">/* Check these, to make gcc/glibc shut up. */</span>
<a name="l00373"></a>00373 <span class="preprocessor">#define FREAD_SWAP32_CHK(dest)                                          \</span>
<a name="l00374"></a>00374 <span class="preprocessor">    if (fread((dest), 4, 1, fh) != 1) {                                 \</span>
<a name="l00375"></a>00375 <span class="preprocessor">        fclose(fh);                                                     \</span>
<a name="l00376"></a>00376 <span class="preprocessor">        ckd_free(m);                                                    \</span>
<a name="l00377"></a>00377 <span class="preprocessor">        E_ERROR_SYSTEM(&quot;Failed to read %s from %s\n&quot;, #dest, filename); \</span>
<a name="l00378"></a>00378 <span class="preprocessor">        return NULL;                                                    \</span>
<a name="l00379"></a>00379 <span class="preprocessor">    }                                                                   \</span>
<a name="l00380"></a>00380 <span class="preprocessor">    if (swap) SWAP_INT32(dest);</span>
<a name="l00381"></a>00381 <span class="preprocessor"></span>    
<a name="l00382"></a>00382     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>);
<a name="l00383"></a>00383     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>);
<a name="l00384"></a>00384     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>);
<a name="l00385"></a>00385     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a>);
<a name="l00386"></a>00386     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>);
<a name="l00387"></a>00387     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a979557ad4f8369e84d93f633512345ca" title="Number of transition matrices.">n_tmat</a>);
<a name="l00388"></a>00388     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>);
<a name="l00389"></a>00389     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a31b5cda5136c6f72816da8889719bfe2" title="Number of phones of context.">n_ctx</a>);
<a name="l00390"></a>00390     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a>);
<a name="l00391"></a>00391     FREAD_SWAP32_CHK(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a>);
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     <span class="comment">/* CI names are first in the file. */</span>
<a name="l00394"></a>00394     m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a> = ckd_calloc(m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>, <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>));
<a name="l00395"></a>00395 
<a name="l00396"></a>00396     <span class="comment">/* Decide whether to read in the whole file or mmap it. */</span>
<a name="l00397"></a>00397     do_mmap = config ? cmd_ln_boolean_r(config, <span class="stringliteral">&quot;-mmap&quot;</span>) : TRUE;
<a name="l00398"></a>00398     <span class="keywordflow">if</span> (swap) {
<a name="l00399"></a>00399         E_WARN(<span class="stringliteral">&quot;-mmap specified, but mdef is other-endian.  Will not memory-map.\n&quot;</span>);
<a name="l00400"></a>00400         do_mmap = FALSE;
<a name="l00401"></a>00401     } 
<a name="l00402"></a>00402     <span class="comment">/* Actually try to mmap it. */</span>
<a name="l00403"></a>00403     <span class="keywordflow">if</span> (do_mmap) {
<a name="l00404"></a>00404         m-&gt;<a class="code" href="structbin__mdef__s.html#a3358a80c50bf3f62417596553adf9c5e" title="File map for this file (if any)">filemap</a> = mmio_file_read(filename);
<a name="l00405"></a>00405         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a3358a80c50bf3f62417596553adf9c5e" title="File map for this file (if any)">filemap</a> == NULL)
<a name="l00406"></a>00406             do_mmap = FALSE;
<a name="l00407"></a>00407     }
<a name="l00408"></a>00408     pos = ftell(fh);
<a name="l00409"></a>00409     <span class="keywordflow">if</span> (do_mmap) {
<a name="l00410"></a>00410         <span class="comment">/* Get the base pointer from the memory map. */</span>
<a name="l00411"></a>00411         m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0] = (<span class="keywordtype">char</span> *)mmio_file_ptr(m-&gt;<a class="code" href="structbin__mdef__s.html#a3358a80c50bf3f62417596553adf9c5e" title="File map for this file (if any)">filemap</a>) + pos;
<a name="l00412"></a>00412         <span class="comment">/* Success! */</span>
<a name="l00413"></a>00413         m-&gt;alloc_mode = BIN_MDEF_ON_DISK;
<a name="l00414"></a>00414     }
<a name="l00415"></a>00415     <span class="keywordflow">else</span> {
<a name="l00416"></a>00416         <span class="comment">/* Read everything into memory. */</span>
<a name="l00417"></a>00417         m-&gt;alloc_mode = BIN_MDEF_IN_MEMORY;
<a name="l00418"></a>00418         fseek(fh, 0, SEEK_END);
<a name="l00419"></a>00419         end = ftell(fh);
<a name="l00420"></a>00420         fseek(fh, pos, SEEK_SET);
<a name="l00421"></a>00421         m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0] = ckd_malloc(end - pos);
<a name="l00422"></a>00422         <span class="keywordflow">if</span> (fread(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0], 1, end - pos, fh) != end - pos)
<a name="l00423"></a>00423             E_FATAL(<span class="stringliteral">&quot;Failed to read %d bytes of data from %s\n&quot;</span>, end - pos, filename);
<a name="l00424"></a>00424     }
<a name="l00425"></a>00425 
<a name="l00426"></a>00426     <span class="keywordflow">for</span> (i = 1; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>; ++i)
<a name="l00427"></a>00427         m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i] = m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1] + strlen(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1]) + 1;
<a name="l00428"></a>00428 
<a name="l00429"></a>00429     <span class="comment">/* Skip past the padding. */</span>
<a name="l00430"></a>00430     tree_start =
<a name="l00431"></a>00431         m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1] + strlen(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i - 1]) + 1 - m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0];
<a name="l00432"></a>00432     tree_start = (tree_start + 3) &amp; ~3;
<a name="l00433"></a>00433     m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a> = (<a class="code" href="structcd__tree__s.html">cd_tree_t</a> *) (m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[0] + tree_start);
<a name="l00434"></a>00434     <span class="keywordflow">if</span> (swap) {
<a name="l00435"></a>00435         <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a>; ++i) {
<a name="l00436"></a>00436             SWAP_INT16(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a>);
<a name="l00437"></a>00437             SWAP_INT16(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>);
<a name="l00438"></a>00438             SWAP_INT32(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>[i].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00439"></a>00439         }
<a name="l00440"></a>00440     }
<a name="l00441"></a>00441     m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a> = (<a class="code" href="structmdef__entry__s.html">mdef_entry_t</a> *) (m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a> + m-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a>);
<a name="l00442"></a>00442     <span class="keywordflow">if</span> (swap) {
<a name="l00443"></a>00443         <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>; ++i) {
<a name="l00444"></a>00444             SWAP_INT32(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>);
<a name="l00445"></a>00445             SWAP_INT32(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a90758df5d6eb00d3a70135ac4475c7a1" title="Transition matrix ID.">tmat</a>);
<a name="l00446"></a>00446         }
<a name="l00447"></a>00447     }
<a name="l00448"></a>00448     sseq_size = (int32 *) (m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a> + m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>);
<a name="l00449"></a>00449     <span class="keywordflow">if</span> (swap)
<a name="l00450"></a>00450         SWAP_INT32(sseq_size);
<a name="l00451"></a>00451     m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a> = ckd_calloc(m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>, <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>));
<a name="l00452"></a>00452     m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0] = (uint16 *) (sseq_size + 1);
<a name="l00453"></a>00453     <span class="keywordflow">if</span> (swap) {
<a name="l00454"></a>00454         <span class="keywordflow">for</span> (i = 0; i &lt; *sseq_size; ++i)
<a name="l00455"></a>00455             SWAP_INT16(m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0] + i);
<a name="l00456"></a>00456     }
<a name="l00457"></a>00457     <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>) {
<a name="l00458"></a>00458         <span class="keywordflow">for</span> (i = 1; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>; ++i)
<a name="l00459"></a>00459             m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[i] = m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0] + i * m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>;
<a name="l00460"></a>00460     }
<a name="l00461"></a>00461     <span class="keywordflow">else</span> {
<a name="l00462"></a>00462         m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a> = (uint8 *) (m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0] + *sseq_size);
<a name="l00463"></a>00463         <span class="keywordflow">for</span> (i = 1; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>; ++i)
<a name="l00464"></a>00464             m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[i] = m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[i - 1] + m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>[i - 1];
<a name="l00465"></a>00465     }
<a name="l00466"></a>00466 
<a name="l00467"></a>00467     <span class="comment">/* Now build the CD-to-CI mappings using the senone sequences.</span>
<a name="l00468"></a>00468 <span class="comment">     * This is the only really accurate way to do it, though it is</span>
<a name="l00469"></a>00469 <span class="comment">     * still inaccurate in the case of heterogeneous topologies or</span>
<a name="l00470"></a>00470 <span class="comment">     * cross-state tying. */</span>
<a name="l00471"></a>00471     m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a> = (int16 *) ckd_malloc(m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a> * <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a>));
<a name="l00472"></a>00472     m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a> = (int16 *) ckd_malloc(m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a> * <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>));
<a name="l00473"></a>00473 
<a name="l00474"></a>00474     <span class="comment">/* Default mappings (identity, none) */</span>
<a name="l00475"></a>00475     <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a>; ++i)
<a name="l00476"></a>00476         m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a>[i] = i;
<a name="l00477"></a>00477     for (; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>; ++i)
<a name="l00478"></a>00478         m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a>[i] = -1;
<a name="l00479"></a>00479     for (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>; ++i)
<a name="l00480"></a>00480         m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>[i] = -1;
<a name="l00481"></a>00481     for (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>; ++i) {
<a name="l00482"></a>00482         int32 j, ssid = m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>;
<a name="l00483"></a>00483 
<a name="l00484"></a>00484         <span class="keywordflow">for</span> (j = 0; j &lt; bin_mdef_n_emit_state_phone(m, i); ++j) {
<a name="l00485"></a>00485             <span class="keywordtype">int</span> s = bin_mdef_sseq2sen(m, ssid, j);
<a name="l00486"></a>00486             <span class="keywordtype">int</span> ci = bin_mdef_pid2ci(m, i);
<a name="l00487"></a>00487             <span class="comment">/* Take the first one and warn if we have cross-state tying. */</span>
<a name="l00488"></a>00488             <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>[s] == -1)
<a name="l00489"></a>00489                 m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>[s] = ci;
<a name="l00490"></a>00490             <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a457e5352e52a57de5d1536bcd6b331a9" title="Parent CI-phone for each senone (CI or CD)">sen2cimap</a>[s] != ci)
<a name="l00491"></a>00491                 E_WARN
<a name="l00492"></a>00492                     (<span class="stringliteral">&quot;Senone %d is shared between multiple base phones\n&quot;</span>,
<a name="l00493"></a>00493                      s);
<a name="l00494"></a>00494 
<a name="l00495"></a>00495             <span class="keywordflow">if</span> (j &gt; bin_mdef_n_emit_state_phone(m, ci))
<a name="l00496"></a>00496                 E_WARN(<span class="stringliteral">&quot;CD phone %d has fewer states than CI phone %d\n&quot;</span>,
<a name="l00497"></a>00497                        i, ci);
<a name="l00498"></a>00498             <span class="keywordflow">else</span>
<a name="l00499"></a>00499                 m-&gt;<a class="code" href="structbin__mdef__s.html#ad5e814ffa116c85d46359e3ffd40bff7" title="Parent CI-senone id for each senone.">cd2cisen</a>[s] =
<a name="l00500"></a>00500                     bin_mdef_sseq2sen(m, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[ci].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>, j);
<a name="l00501"></a>00501         }
<a name="l00502"></a>00502     }
<a name="l00503"></a>00503 
<a name="l00504"></a>00504     <span class="comment">/* Set the silence phone. */</span>
<a name="l00505"></a>00505     m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> = bin_mdef_ciphone_id(m, <a class="code" href="mdef_8h.html#a87b279af2566a60666495e16d09a8aee" title="Hard-coded silence CI phone name.">S3_SILENCE_CIPHONE</a>);
<a name="l00506"></a>00506 
<a name="l00507"></a>00507     E_INFO
<a name="l00508"></a>00508         (<span class="stringliteral">&quot;%d CI-phone, %d CD-phone, %d emitstate/phone, %d CI-sen, %d Sen, %d Sen-Seq\n&quot;</span>,
<a name="l00509"></a>00509          m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>, m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a> - m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>, m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>,
<a name="l00510"></a>00510          m-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a>, m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>, m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>);
<a name="l00511"></a>00511     fclose(fh);
<a name="l00512"></a>00512     <span class="keywordflow">return</span> m;
<a name="l00513"></a>00513 }
<a name="l00514"></a>00514 
<a name="l00515"></a>00515 <span class="keywordtype">int</span>
<a name="l00516"></a><a class="code" href="bin__mdef_8h.html#a27f911970399b7b053114d946d700cd0">00516</a> bin_mdef_write(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00517"></a>00517 {
<a name="l00518"></a>00518     FILE *fh;
<a name="l00519"></a>00519     int32 val, i;
<a name="l00520"></a>00520 
<a name="l00521"></a>00521     <span class="keywordflow">if</span> ((fh = fopen(filename, <span class="stringliteral">&quot;wb&quot;</span>)) == NULL)
<a name="l00522"></a>00522         <span class="keywordflow">return</span> -1;
<a name="l00523"></a>00523 
<a name="l00524"></a>00524     <span class="comment">/* Byteorder marker. */</span>
<a name="l00525"></a>00525     val = BIN_MDEF_NATIVE_ENDIAN;
<a name="l00526"></a>00526     fwrite(&amp;val, 1, 4, fh);
<a name="l00527"></a>00527     <span class="comment">/* Version. */</span>
<a name="l00528"></a>00528     val = BIN_MDEF_FORMAT_VERSION;
<a name="l00529"></a>00529     fwrite(&amp;val, 1, <span class="keyword">sizeof</span>(val), fh);
<a name="l00530"></a>00530 
<a name="l00531"></a>00531     <span class="comment">/* Round the format descriptor size up to a 4-byte boundary. */</span>
<a name="l00532"></a>00532     val = ((<span class="keyword">sizeof</span>(format_desc) + 3) &amp; ~3);
<a name="l00533"></a>00533     fwrite(&amp;val, 1, <span class="keyword">sizeof</span>(val), fh);
<a name="l00534"></a>00534     fwrite(format_desc, 1, <span class="keyword">sizeof</span>(format_desc), fh);
<a name="l00535"></a>00535     <span class="comment">/* Pad it with zeros. */</span>
<a name="l00536"></a>00536     i = 0;
<a name="l00537"></a>00537     fwrite(&amp;i, 1, val - <span class="keyword">sizeof</span>(format_desc), fh);
<a name="l00538"></a>00538 
<a name="l00539"></a>00539     <span class="comment">/* Binary header things. */</span>
<a name="l00540"></a>00540     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>, 4, 1, fh);
<a name="l00541"></a>00541     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>, 4, 1, fh);
<a name="l00542"></a>00542     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>, 4, 1, fh);
<a name="l00543"></a>00543     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a>, 4, 1, fh);
<a name="l00544"></a>00544     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>, 4, 1, fh);
<a name="l00545"></a>00545     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a979557ad4f8369e84d93f633512345ca" title="Number of transition matrices.">n_tmat</a>, 4, 1, fh);
<a name="l00546"></a>00546     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>, 4, 1, fh);
<a name="l00547"></a>00547     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#a31b5cda5136c6f72816da8889719bfe2" title="Number of phones of context.">n_ctx</a>, 4, 1, fh);
<a name="l00548"></a>00548     fwrite(&amp;m-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a>, 4, 1, fh);
<a name="l00549"></a>00549     <span class="comment">/* Write this as a 32-bit value to preserve alignment for the</span>
<a name="l00550"></a>00550 <span class="comment">     * non-mmap case (we want things aligned both from the</span>
<a name="l00551"></a>00551 <span class="comment">     * beginning of the file and the beginning of the phone</span>
<a name="l00552"></a>00552 <span class="comment">     * strings). */</span>
<a name="l00553"></a>00553     val = m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a>;
<a name="l00554"></a>00554     fwrite(&amp;val, 4, 1, fh);
<a name="l00555"></a>00555 
<a name="l00556"></a>00556     <span class="comment">/* Phone strings. */</span>
<a name="l00557"></a>00557     <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>; ++i)
<a name="l00558"></a>00558         fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i], 1, strlen(m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[i]) + 1, fh);
<a name="l00559"></a>00559     <span class="comment">/* Pad with zeros. */</span>
<a name="l00560"></a>00560     val = (ftell(fh) + 3) &amp; ~3;
<a name="l00561"></a>00561     i = 0;
<a name="l00562"></a>00562     fwrite(&amp;i, 1, val - ftell(fh), fh);
<a name="l00563"></a>00563 
<a name="l00564"></a>00564     <span class="comment">/* Write CD-tree */</span>
<a name="l00565"></a>00565     fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>, <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>), m-&gt;<a class="code" href="structbin__mdef__s.html#ad625c3c55d5f42ed275b8b5638a6d80b" title="Number of nodes in cd_tree (below)">n_cd_tree</a>, fh);
<a name="l00566"></a>00566     <span class="comment">/* Write phones */</span>
<a name="l00567"></a>00567     fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>, <span class="keyword">sizeof</span>(*m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>), m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>, fh);
<a name="l00568"></a>00568     <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>) {
<a name="l00569"></a>00569         <span class="comment">/* Write size of sseq */</span>
<a name="l00570"></a>00570         val = m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a> * m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>;
<a name="l00571"></a>00571         fwrite(&amp;val, 4, 1, fh);
<a name="l00572"></a>00572 
<a name="l00573"></a>00573         <span class="comment">/* Write sseq */</span>
<a name="l00574"></a>00574         fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0], <span class="keyword">sizeof</span>(**m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>),
<a name="l00575"></a>00575                m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a> * m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>, fh);
<a name="l00576"></a>00576     }
<a name="l00577"></a>00577     <span class="keywordflow">else</span> {
<a name="l00578"></a>00578         int32 n;
<a name="l00579"></a>00579 
<a name="l00580"></a>00580         <span class="comment">/* Calcluate size of sseq */</span>
<a name="l00581"></a>00581         n = 0;
<a name="l00582"></a>00582         <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>; ++i)
<a name="l00583"></a>00583             n += m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>[i];
<a name="l00584"></a>00584 
<a name="l00585"></a>00585         <span class="comment">/* Write size of sseq */</span>
<a name="l00586"></a>00586         fwrite(&amp;n, 4, 1, fh);
<a name="l00587"></a>00587 
<a name="l00588"></a>00588         <span class="comment">/* Write sseq */</span>
<a name="l00589"></a>00589         fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[0], <span class="keyword">sizeof</span>(**m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>), n, fh);
<a name="l00590"></a>00590 
<a name="l00591"></a>00591         <span class="comment">/* Write sseq_len */</span>
<a name="l00592"></a>00592         fwrite(m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>, 1, m-&gt;<a class="code" href="structbin__mdef__s.html#ab9dad211cbc12eb6f848482bcf78d47f" title="Number of unique senone sequences.">n_sseq</a>, fh);
<a name="l00593"></a>00593     }
<a name="l00594"></a>00594     fclose(fh);
<a name="l00595"></a>00595 
<a name="l00596"></a>00596     <span class="keywordflow">return</span> 0;
<a name="l00597"></a>00597 }
<a name="l00598"></a>00598 
<a name="l00599"></a>00599 <span class="keywordtype">int</span>
<a name="l00600"></a><a class="code" href="bin__mdef_8h.html#aae7eaa3db4c1c6925210014a4f867e53">00600</a> bin_mdef_write_text(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename)
<a name="l00601"></a>00601 {
<a name="l00602"></a>00602     FILE *fh;
<a name="l00603"></a>00603     <span class="keywordtype">int</span> p, i, n_total_state;
<a name="l00604"></a>00604 
<a name="l00605"></a>00605     <span class="keywordflow">if</span> (strcmp(filename, <span class="stringliteral">&quot;-&quot;</span>) == 0)
<a name="l00606"></a>00606         fh = stdout;
<a name="l00607"></a>00607     <span class="keywordflow">else</span> {
<a name="l00608"></a>00608         <span class="keywordflow">if</span> ((fh = fopen(filename, <span class="stringliteral">&quot;w&quot;</span>)) == NULL)
<a name="l00609"></a>00609             <span class="keywordflow">return</span> -1;
<a name="l00610"></a>00610     }
<a name="l00611"></a>00611 
<a name="l00612"></a>00612     fprintf(fh, <span class="stringliteral">&quot;0.3\n&quot;</span>);
<a name="l00613"></a>00613     fprintf(fh, <span class="stringliteral">&quot;%d n_base\n&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>);
<a name="l00614"></a>00614     fprintf(fh, <span class="stringliteral">&quot;%d n_tri\n&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a> - m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>);
<a name="l00615"></a>00615     <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>)
<a name="l00616"></a>00616         n_total_state = m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a> * (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a> + 1);
<a name="l00617"></a>00617     <span class="keywordflow">else</span> {
<a name="l00618"></a>00618         n_total_state = 0;
<a name="l00619"></a>00619         <span class="keywordflow">for</span> (i = 0; i &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>; ++i)
<a name="l00620"></a>00620             n_total_state += m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[i].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>] + 1;
<a name="l00621"></a>00621     }
<a name="l00622"></a>00622     fprintf(fh, <span class="stringliteral">&quot;%d n_state_map\n&quot;</span>, n_total_state);
<a name="l00623"></a>00623     fprintf(fh, <span class="stringliteral">&quot;%d n_tied_state\n&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#a3d1c202165d8e5e153a73d708ca28109" title="Number of senones (CI+CD)">n_sen</a>);
<a name="l00624"></a>00624     fprintf(fh, <span class="stringliteral">&quot;%d n_tied_ci_state\n&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#ad7c318d6db85fd4b8ac13a81c145bbb8" title="Number of CI senones; these are the first.">n_ci_sen</a>);
<a name="l00625"></a>00625     fprintf(fh, <span class="stringliteral">&quot;%d n_tied_tmat\n&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#a979557ad4f8369e84d93f633512345ca" title="Number of transition matrices.">n_tmat</a>);
<a name="l00626"></a>00626     fprintf(fh, <span class="stringliteral">&quot;#\n# Columns definitions\n&quot;</span>);
<a name="l00627"></a>00627     fprintf(fh, <span class="stringliteral">&quot;#%4s %3s %3s %1s %6s %4s %s\n&quot;</span>,
<a name="l00628"></a>00628             <span class="stringliteral">&quot;base&quot;</span>, <span class="stringliteral">&quot;lft&quot;</span>, <span class="stringliteral">&quot;rt&quot;</span>, <span class="stringliteral">&quot;p&quot;</span>, <span class="stringliteral">&quot;attrib&quot;</span>, <span class="stringliteral">&quot;tmat&quot;</span>,
<a name="l00629"></a>00629             <span class="stringliteral">&quot;     ... state id&#39;s ...&quot;</span>);
<a name="l00630"></a>00630 
<a name="l00631"></a>00631     <span class="keywordflow">for</span> (p = 0; p &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>; p++) {
<a name="l00632"></a>00632         <span class="keywordtype">int</span> n_state;
<a name="l00633"></a>00633 
<a name="l00634"></a>00634         fprintf(fh, <span class="stringliteral">&quot;%5s %3s %3s %1s&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[p], <span class="stringliteral">&quot;-&quot;</span>, <span class="stringliteral">&quot;-&quot;</span>, <span class="stringliteral">&quot;-&quot;</span>);
<a name="l00635"></a>00635 
<a name="l00636"></a>00636         <span class="keywordflow">if</span> (bin_mdef_is_fillerphone(m, p))
<a name="l00637"></a>00637             fprintf(fh, <span class="stringliteral">&quot; %6s&quot;</span>, <span class="stringliteral">&quot;filler&quot;</span>);
<a name="l00638"></a>00638         <span class="keywordflow">else</span>
<a name="l00639"></a>00639             fprintf(fh, <span class="stringliteral">&quot; %6s&quot;</span>, <span class="stringliteral">&quot;n/a&quot;</span>);
<a name="l00640"></a>00640         fprintf(fh, <span class="stringliteral">&quot; %4d&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a90758df5d6eb00d3a70135ac4475c7a1" title="Transition matrix ID.">tmat</a>);
<a name="l00641"></a>00641 
<a name="l00642"></a>00642         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>)
<a name="l00643"></a>00643             n_state = m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>;
<a name="l00644"></a>00644         <span class="keywordflow">else</span>
<a name="l00645"></a>00645             n_state = m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>];
<a name="l00646"></a>00646         <span class="keywordflow">for</span> (i = 0; i &lt; n_state; i++) {
<a name="l00647"></a>00647             fprintf(fh, <span class="stringliteral">&quot; %6u&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>][i]);
<a name="l00648"></a>00648         }
<a name="l00649"></a>00649         fprintf(fh, <span class="stringliteral">&quot; N\n&quot;</span>);
<a name="l00650"></a>00650     }
<a name="l00651"></a>00651 
<a name="l00652"></a>00652 
<a name="l00653"></a>00653     <span class="keywordflow">for</span> (; p &lt; m-&gt;<a class="code" href="structbin__mdef__s.html#ad746dbb3f8108f575a95182f96b4b18f" title="Number of base (CI) phones + (CD) triphones.">n_phone</a>; p++) {
<a name="l00654"></a>00654         <span class="keywordtype">int</span> n_state;
<a name="l00655"></a>00655 
<a name="l00656"></a>00656         fprintf(fh, <span class="stringliteral">&quot;%5s %3s %3s %c&quot;</span>,
<a name="l00657"></a>00657                 m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].info.cd.ctx[0]],
<a name="l00658"></a>00658                 m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].info.cd.ctx[1]],
<a name="l00659"></a>00659                 m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].info.cd.ctx[2]],
<a name="l00660"></a>00660                 (<a class="code" href="mdef_8h.html#a89ef0442ded2ff90176ba6d02563923d" title="Printable code for each word position above.">WPOS_NAME</a>)[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].info.cd.wpos]);
<a name="l00661"></a>00661 
<a name="l00662"></a>00662         <span class="keywordflow">if</span> (bin_mdef_is_fillerphone(m, p))
<a name="l00663"></a>00663             fprintf(fh, <span class="stringliteral">&quot; %6s&quot;</span>, <span class="stringliteral">&quot;filler&quot;</span>);
<a name="l00664"></a>00664         <span class="keywordflow">else</span>
<a name="l00665"></a>00665             fprintf(fh, <span class="stringliteral">&quot; %6s&quot;</span>, <span class="stringliteral">&quot;n/a&quot;</span>);
<a name="l00666"></a>00666         fprintf(fh, <span class="stringliteral">&quot; %4d&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a90758df5d6eb00d3a70135ac4475c7a1" title="Transition matrix ID.">tmat</a>);
<a name="l00667"></a>00667 
<a name="l00668"></a>00668 
<a name="l00669"></a>00669         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>)
<a name="l00670"></a>00670             n_state = m-&gt;<a class="code" href="structbin__mdef__s.html#a2ad87254182be424ac6ff1234274f134" title="Number of emitting states per phone (0 for heterogeneous)">n_emit_state</a>;
<a name="l00671"></a>00671         <span class="keywordflow">else</span>
<a name="l00672"></a>00672             n_state = m-&gt;<a class="code" href="structbin__mdef__s.html#ab534bbd280015795b8e8ca4e296f4946" title="Number of states in each sseq (NULL for homogeneous)">sseq_len</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>];
<a name="l00673"></a>00673         <span class="keywordflow">for</span> (i = 0; i &lt; n_state; i++) {
<a name="l00674"></a>00674             fprintf(fh, <span class="stringliteral">&quot; %6u&quot;</span>, m-&gt;<a class="code" href="structbin__mdef__s.html#acb58480658812de7a357dcbd25ad7b41" title="Unique senone sequences (2D array built at load time)">sseq</a>[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[p].<a class="code" href="structmdef__entry__s.html#a12986649de9c59de3cc805e375b2c9a2" title="Senone sequence ID.">ssid</a>][i]);
<a name="l00675"></a>00675         }
<a name="l00676"></a>00676         fprintf(fh, <span class="stringliteral">&quot; N\n&quot;</span>);
<a name="l00677"></a>00677     }
<a name="l00678"></a>00678 
<a name="l00679"></a>00679     <span class="keywordflow">if</span> (strcmp(filename, <span class="stringliteral">&quot;-&quot;</span>) != 0)
<a name="l00680"></a>00680         fclose(fh);
<a name="l00681"></a>00681     <span class="keywordflow">return</span> 0;
<a name="l00682"></a>00682 }
<a name="l00683"></a>00683 
<a name="l00684"></a>00684 <span class="keywordtype">int</span>
<a name="l00685"></a><a class="code" href="bin__mdef_8h.html#af592f710731474b77166a29530716672">00685</a> bin_mdef_ciphone_id(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, <span class="keyword">const</span> <span class="keywordtype">char</span> *ciphone)
<a name="l00686"></a>00686 {
<a name="l00687"></a>00687     <span class="keywordtype">int</span> low, mid, high;
<a name="l00688"></a>00688 
<a name="l00689"></a>00689     <span class="comment">/* Exact binary search on m-&gt;ciphone */</span>
<a name="l00690"></a>00690     low = 0;
<a name="l00691"></a>00691     high = m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>;
<a name="l00692"></a>00692     <span class="keywordflow">while</span> (low &lt; high) {
<a name="l00693"></a>00693         <span class="keywordtype">int</span> c;
<a name="l00694"></a>00694 
<a name="l00695"></a>00695         mid = (low + high) / 2;
<a name="l00696"></a>00696         c = strcmp(ciphone, m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[mid]);
<a name="l00697"></a>00697         <span class="keywordflow">if</span> (c == 0)
<a name="l00698"></a>00698             <span class="keywordflow">return</span> mid;
<a name="l00699"></a>00699         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (c &gt; 0)
<a name="l00700"></a>00700             low = mid + 1;
<a name="l00701"></a>00701         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (c &lt; 0)
<a name="l00702"></a>00702             high = mid;
<a name="l00703"></a>00703     }
<a name="l00704"></a>00704     <span class="keywordflow">return</span> -1;
<a name="l00705"></a>00705 }
<a name="l00706"></a>00706 
<a name="l00707"></a>00707 <span class="keywordtype">int</span>
<a name="l00708"></a><a class="code" href="bin__mdef_8h.html#af437f39a8a9b52dd3187f7f0fc098cab">00708</a> bin_mdef_ciphone_id_nocase(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, <span class="keyword">const</span> <span class="keywordtype">char</span> *ciphone)
<a name="l00709"></a>00709 {
<a name="l00710"></a>00710     <span class="keywordtype">int</span> low, mid, high;
<a name="l00711"></a>00711 
<a name="l00712"></a>00712     <span class="comment">/* Exact binary search on m-&gt;ciphone */</span>
<a name="l00713"></a>00713     low = 0;
<a name="l00714"></a>00714     high = m-&gt;<a class="code" href="structbin__mdef__s.html#a84d5f7acc6d85ba8c7611945f9c5e4e7" title="Number of base (CI) phones.">n_ciphone</a>;
<a name="l00715"></a>00715     <span class="keywordflow">while</span> (low &lt; high) {
<a name="l00716"></a>00716         <span class="keywordtype">int</span> c;
<a name="l00717"></a>00717 
<a name="l00718"></a>00718         mid = (low + high) / 2;
<a name="l00719"></a>00719         c = strcmp_nocase(ciphone, m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[mid]);
<a name="l00720"></a>00720         <span class="keywordflow">if</span> (c == 0)
<a name="l00721"></a>00721             <span class="keywordflow">return</span> mid;
<a name="l00722"></a>00722         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (c &gt; 0)
<a name="l00723"></a>00723             low = mid + 1;
<a name="l00724"></a>00724         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (c &lt; 0)
<a name="l00725"></a>00725             high = mid;
<a name="l00726"></a>00726     }
<a name="l00727"></a>00727     <span class="keywordflow">return</span> -1;
<a name="l00728"></a>00728 }
<a name="l00729"></a>00729 
<a name="l00730"></a>00730 <span class="keyword">const</span> <span class="keywordtype">char</span> *
<a name="l00731"></a><a class="code" href="bin__mdef_8h.html#a9498ffff0caf3965060b8a549348be9b">00731</a> bin_mdef_ciphone_str(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, int32 ci)
<a name="l00732"></a>00732 {
<a name="l00733"></a>00733     assert(m != NULL);
<a name="l00734"></a>00734     assert(ci &lt; m-&gt;n_ciphone);
<a name="l00735"></a>00735     <span class="keywordflow">return</span> m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[ci];
<a name="l00736"></a>00736 }
<a name="l00737"></a>00737 
<a name="l00738"></a>00738 <span class="keywordtype">int</span>
<a name="l00739"></a><a class="code" href="bin__mdef_8h.html#a99cd766df3a6a74eab9e316586189d54">00739</a> bin_mdef_phone_id(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, int32 ci, int32 lc, int32 rc, int32 wpos)
<a name="l00740"></a>00740 {
<a name="l00741"></a>00741     <a class="code" href="structcd__tree__s.html">cd_tree_t</a> *cd_tree;
<a name="l00742"></a>00742     <span class="keywordtype">int</span> level, max;
<a name="l00743"></a>00743     int16 ctx[4];
<a name="l00744"></a>00744 
<a name="l00745"></a>00745     assert(m);
<a name="l00746"></a>00746 
<a name="l00747"></a>00747     <span class="comment">/* In the future, we might back off when context is not available,</span>
<a name="l00748"></a>00748 <span class="comment">     * but for now we&#39;ll just return the CI phone. */</span>
<a name="l00749"></a>00749     <span class="keywordflow">if</span> (lc &lt; 0 || rc &lt; 0)
<a name="l00750"></a>00750         <span class="keywordflow">return</span> ci;
<a name="l00751"></a>00751 
<a name="l00752"></a>00752     assert((ci &gt;= 0) &amp;&amp; (ci &lt; m-&gt;n_ciphone));
<a name="l00753"></a>00753     assert((lc &gt;= 0) &amp;&amp; (lc &lt; m-&gt;n_ciphone));
<a name="l00754"></a>00754     assert((rc &gt;= 0) &amp;&amp; (rc &lt; m-&gt;n_ciphone));
<a name="l00755"></a>00755     assert((wpos &gt;= 0) &amp;&amp; (wpos &lt; <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>));
<a name="l00756"></a>00756 
<a name="l00757"></a>00757     <span class="comment">/* Create a context list, mapping fillers to silence. */</span>
<a name="l00758"></a>00758     ctx[0] = wpos;
<a name="l00759"></a>00759     ctx[1] = ci;
<a name="l00760"></a>00760     ctx[2] = (m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> &gt;= 0
<a name="l00761"></a>00761               &amp;&amp; m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[lc].info.<a class="code" href="structmdef__entry__s.html#a24e5db7af5e705b310e82154055043ec" title="CD phone information - context info.">ci</a>.filler) ? m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> : lc;
<a name="l00762"></a>00762     ctx[3] = (m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> &gt;= 0
<a name="l00763"></a>00763               &amp;&amp; m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[rc].info.<a class="code" href="structmdef__entry__s.html#a24e5db7af5e705b310e82154055043ec" title="CD phone information - context info.">ci</a>.filler) ? m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> : rc;
<a name="l00764"></a>00764 
<a name="l00765"></a>00765     <span class="comment">/* Walk down the cd_tree. */</span>
<a name="l00766"></a>00766     cd_tree = m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>;
<a name="l00767"></a>00767     level = 0;                  <span class="comment">/* What level we are on. */</span>
<a name="l00768"></a>00768     max = <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>;          <span class="comment">/* Number of nodes on this level. */</span>
<a name="l00769"></a>00769     <span class="keywordflow">while</span> (level &lt; 4) {
<a name="l00770"></a>00770         <span class="keywordtype">int</span> i;
<a name="l00771"></a>00771 
<a name="l00772"></a>00772 <span class="preprocessor">#if 0</span>
<a name="l00773"></a>00773 <span class="preprocessor"></span>        E_INFO(<span class="stringliteral">&quot;Looking for context %d=%s in %d at %d\n&quot;</span>,
<a name="l00774"></a>00774                ctx[level], m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[ctx[level]],
<a name="l00775"></a>00775                max, cd_tree - m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>);
<a name="l00776"></a>00776 <span class="preprocessor">#endif</span>
<a name="l00777"></a>00777 <span class="preprocessor"></span>        <span class="keywordflow">for</span> (i = 0; i &lt; max; ++i) {
<a name="l00778"></a>00778 <span class="preprocessor">#if 0</span>
<a name="l00779"></a>00779 <span class="preprocessor"></span>            E_INFO(<span class="stringliteral">&quot;Look at context %d=%s at %d\n&quot;</span>,
<a name="l00780"></a>00780                    cd_tree[i].ctx,
<a name="l00781"></a>00781                    m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[cd_tree[i].<a class="code" href="structcd__tree__s.html#a2168538bf6cc21ad1a2c99fa2deb4559" title="Context (word position or CI phone)">ctx</a>], cd_tree + i - m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>);
<a name="l00782"></a>00782 <span class="preprocessor">#endif</span>
<a name="l00783"></a>00783 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (cd_tree[i].ctx == ctx[level])
<a name="l00784"></a>00784                 <span class="keywordflow">break</span>;
<a name="l00785"></a>00785         }
<a name="l00786"></a>00786         <span class="keywordflow">if</span> (i == max)
<a name="l00787"></a>00787             <span class="keywordflow">return</span> -1;
<a name="l00788"></a>00788 <span class="preprocessor">#if 0</span>
<a name="l00789"></a>00789 <span class="preprocessor"></span>        E_INFO(<span class="stringliteral">&quot;Found context %d=%s at %d, n_down=%d, down=%d\n&quot;</span>,
<a name="l00790"></a>00790                ctx[level], m-&gt;<a class="code" href="structbin__mdef__s.html#afdd0df913746b0656186fc8c3e8a9206" title="CI phone names.">ciname</a>[ctx[level]],
<a name="l00791"></a>00791                cd_tree + i - m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a>,
<a name="l00792"></a>00792                cd_tree[i].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>, cd_tree[i].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>);
<a name="l00793"></a>00793 <span class="preprocessor">#endif</span>
<a name="l00794"></a>00794 <span class="preprocessor"></span>        <span class="comment">/* Leaf node, stop here. */</span>
<a name="l00795"></a>00795         <span class="keywordflow">if</span> (cd_tree[i].n_down == 0)
<a name="l00796"></a>00796             <span class="keywordflow">return</span> cd_tree[i].c.<a class="code" href="structcd__tree__s.html#a6635c35ad6fe74ad045389c76349016d" title="Phone ID (leafnode)">pid</a>;
<a name="l00797"></a>00797 
<a name="l00798"></a>00798         <span class="comment">/* Go down one level. */</span>
<a name="l00799"></a>00799         max = cd_tree[i].<a class="code" href="structcd__tree__s.html#ae5e735d325b0f278ff2ad55293faa616" title="Number of children (0 for leafnode)">n_down</a>;
<a name="l00800"></a>00800         cd_tree = m-&gt;<a class="code" href="structbin__mdef__s.html#a0642be2bb56149689ad3fc1dad1e5d55" title="Tree mapping CD phones to phone IDs.">cd_tree</a> + cd_tree[i].c.<a class="code" href="structcd__tree__s.html#aa536f1cbd93e2cded1238b39b8aa3751" title="Next level of the tree (offset from start of cd_trees)">down</a>;
<a name="l00801"></a>00801         ++level;
<a name="l00802"></a>00802     }
<a name="l00803"></a>00803     <span class="comment">/* We probably shouldn&#39;t get here. */</span>
<a name="l00804"></a>00804     <span class="keywordflow">return</span> -1;
<a name="l00805"></a>00805 }
<a name="l00806"></a>00806 
<a name="l00807"></a>00807 <span class="keywordtype">int</span>
<a name="l00808"></a>00808 bin_mdef_phone_id_nearest(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, int32 b, int32 l, int32 r, int32 pos)
<a name="l00809"></a>00809 {
<a name="l00810"></a>00810     <span class="keywordtype">int</span> p, tmppos;
<a name="l00811"></a>00811 
<a name="l00812"></a>00812 
<a name="l00813"></a>00813 
<a name="l00814"></a>00814     <span class="comment">/* In the future, we might back off when context is not available,</span>
<a name="l00815"></a>00815 <span class="comment">     * but for now we&#39;ll just return the CI phone. */</span>
<a name="l00816"></a>00816     <span class="keywordflow">if</span> (l &lt; 0 || r &lt; 0)
<a name="l00817"></a>00817         <span class="keywordflow">return</span> b;
<a name="l00818"></a>00818 
<a name="l00819"></a>00819     p = bin_mdef_phone_id(m, b, l, r, pos);
<a name="l00820"></a>00820     <span class="keywordflow">if</span> (p &gt;= 0)
<a name="l00821"></a>00821         <span class="keywordflow">return</span> p;
<a name="l00822"></a>00822 
<a name="l00823"></a>00823     <span class="comment">/* Exact triphone not found; backoff to other word positions */</span>
<a name="l00824"></a>00824     <span class="keywordflow">for</span> (tmppos = 0; tmppos &lt; <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>; tmppos++) {
<a name="l00825"></a>00825         <span class="keywordflow">if</span> (tmppos != pos) {
<a name="l00826"></a>00826             p = bin_mdef_phone_id(m, b, l, r, tmppos);
<a name="l00827"></a>00827             <span class="keywordflow">if</span> (p &gt;= 0)
<a name="l00828"></a>00828                 <span class="keywordflow">return</span> p;
<a name="l00829"></a>00829         }
<a name="l00830"></a>00830     }
<a name="l00831"></a>00831 
<a name="l00832"></a>00832     <span class="comment">/* Nothing yet; backoff to silence phone if non-silence filler context */</span>
<a name="l00833"></a>00833     <span class="comment">/* In addition, backoff to silence phone on left/right if in beginning/end position */</span>
<a name="l00834"></a>00834     <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a> &gt;= 0) {
<a name="l00835"></a>00835         <span class="keywordtype">int</span> newl = l, newr = r;
<a name="l00836"></a>00836         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[(<span class="keywordtype">int</span>)l].info.<a class="code" href="structmdef__entry__s.html#a24e5db7af5e705b310e82154055043ec" title="CD phone information - context info.">ci</a>.filler
<a name="l00837"></a>00837             || pos == <a class="code" href="mdef_8h.html#a71b2bcae7b6e79bad584cc5500b20e8fa8ca058a8d25d38d074e028460833c8a9" title="Beginning phone of word.">WORD_POSN_BEGIN</a> || pos == <a class="code" href="mdef_8h.html#a71b2bcae7b6e79bad584cc5500b20e8fa34f808e43d8f6e9312054f34a8bd74ac" title="Single phone word (i.e.">WORD_POSN_SINGLE</a>)
<a name="l00838"></a>00838             newl = m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a>;
<a name="l00839"></a>00839         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[(<span class="keywordtype">int</span>)r].info.<a class="code" href="structmdef__entry__s.html#a24e5db7af5e705b310e82154055043ec" title="CD phone information - context info.">ci</a>.filler
<a name="l00840"></a>00840             || pos == <a class="code" href="mdef_8h.html#a71b2bcae7b6e79bad584cc5500b20e8fa85b62e42f20399f933b33099290989c3" title="Ending phone of word.">WORD_POSN_END</a> || pos == <a class="code" href="mdef_8h.html#a71b2bcae7b6e79bad584cc5500b20e8fa34f808e43d8f6e9312054f34a8bd74ac" title="Single phone word (i.e.">WORD_POSN_SINGLE</a>)
<a name="l00841"></a>00841             newr = m-&gt;<a class="code" href="structbin__mdef__s.html#a9071b7698132c1c2ce92a6f742e1c82f" title="CI phone ID for silence.">sil</a>;
<a name="l00842"></a>00842         <span class="keywordflow">if</span> ((newl != l) || (newr != r)) {
<a name="l00843"></a>00843             p = bin_mdef_phone_id(m, b, newl, newr, pos);
<a name="l00844"></a>00844             <span class="keywordflow">if</span> (p &gt;= 0)
<a name="l00845"></a>00845                 <span class="keywordflow">return</span> p;
<a name="l00846"></a>00846 
<a name="l00847"></a>00847             <span class="keywordflow">for</span> (tmppos = 0; tmppos &lt; <a class="code" href="mdef_8h.html#ac271413770c3e95b993b856967b61487" title="total # of word positions (excluding undefined)">N_WORD_POSN</a>; tmppos++) {
<a name="l00848"></a>00848                 <span class="keywordflow">if</span> (tmppos != pos) {
<a name="l00849"></a>00849                     p = bin_mdef_phone_id(m, b, newl, newr, tmppos);
<a name="l00850"></a>00850                     <span class="keywordflow">if</span> (p &gt;= 0)
<a name="l00851"></a>00851                         <span class="keywordflow">return</span> p;
<a name="l00852"></a>00852                 }
<a name="l00853"></a>00853             }
<a name="l00854"></a>00854         }
<a name="l00855"></a>00855     }
<a name="l00856"></a>00856 
<a name="l00857"></a>00857     <span class="comment">/* Nothing yet; backoff to base phone */</span>
<a name="l00858"></a>00858     <span class="keywordflow">return</span> b;
<a name="l00859"></a>00859 }
<a name="l00860"></a>00860 
<a name="l00861"></a>00861 <span class="keywordtype">int</span>
<a name="l00862"></a><a class="code" href="bin__mdef_8h.html#a35d0676dd56e11508c62e84947901503">00862</a> bin_mdef_phone_str(<a class="code" href="structbin__mdef__s.html">bin_mdef_t</a> * m, <span class="keywordtype">int</span> pid, <span class="keywordtype">char</span> *buf)
<a name="l00863"></a>00863 {
<a name="l00864"></a>00864     <span class="keywordtype">char</span> *wpos_name;
<a name="l00865"></a>00865 
<a name="l00866"></a>00866     assert(m);
<a name="l00867"></a>00867     assert((pid &gt;= 0) &amp;&amp; (pid &lt; m-&gt;n_phone));
<a name="l00868"></a>00868     wpos_name = <a class="code" href="mdef_8h.html#a89ef0442ded2ff90176ba6d02563923d" title="Printable code for each word position above.">WPOS_NAME</a>;
<a name="l00869"></a>00869 
<a name="l00870"></a>00870     buf[0] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00871"></a>00871     <span class="keywordflow">if</span> (pid &lt; m-&gt;n_ciphone)
<a name="l00872"></a>00872         sprintf(buf, <span class="stringliteral">&quot;%s&quot;</span>, bin_mdef_ciphone_str(m, pid));
<a name="l00873"></a>00873     <span class="keywordflow">else</span> {
<a name="l00874"></a>00874         sprintf(buf, <span class="stringliteral">&quot;%s %s %s %c&quot;</span>,
<a name="l00875"></a>00875                 bin_mdef_ciphone_str(m, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[pid].info.cd.ctx[0]),
<a name="l00876"></a>00876                 bin_mdef_ciphone_str(m, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[pid].info.cd.ctx[1]),
<a name="l00877"></a>00877                 bin_mdef_ciphone_str(m, m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[pid].info.cd.ctx[2]),
<a name="l00878"></a>00878                 wpos_name[m-&gt;<a class="code" href="structbin__mdef__s.html#a2c73ae900d198460a30bce4f641d8398" title="All phone structures.">phone</a>[pid].info.cd.wpos]);
<a name="l00879"></a>00879     }
<a name="l00880"></a>00880     <span class="keywordflow">return</span> 0;
<a name="l00881"></a>00881 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>bin_mdef.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>