mdef.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* mdef.h -- HMM model definition: base (CI) phones and triphones
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1999 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*/
#ifndef __MDEF_H__
#define __MDEF_H__
/* System headers. */
#include <stdio.h>
/* SphinxBase headers. */
#include <sphinxbase/hash_table.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
WORD_POSN_INTERNAL = 0,
WORD_POSN_BEGIN = 1,
WORD_POSN_END = 2,
WORD_POSN_SINGLE = 3,
WORD_POSN_UNDEFINED = 4
} word_posn_t;
#define N_WORD_POSN 4
#define WPOS_NAME "ibesu"
#define S3_SILENCE_CIPHONE "SIL"
typedef struct {
char *name;
int32 filler;
} ciphone_t;
typedef struct {
int32 ssid;
int32 tmat;
int16 ci, lc, rc;
word_posn_t wpos;
} phone_t;
typedef struct ph_rc_s {
int16 rc;
int32 pid;
struct ph_rc_s *next;
} ph_rc_t;
typedef struct ph_lc_s {
int16 lc;
ph_rc_t *rclist;
struct ph_lc_s *next;
} ph_lc_t;
typedef struct {
int32 n_ciphone;
int32 n_phone;
int32 n_emit_state;
int32 n_ci_sen;
int32 n_sen;
int32 n_tmat;
hash_table_t *ciphone_ht;
ciphone_t *ciphone;
phone_t *phone;
uint16 **sseq;
int32 n_sseq;
int16 *cd2cisen;
int16 *sen2cimap;
int16 sil;
ph_lc_t ***wpos_ci_lclist;
} mdef_t;
#define mdef_is_fillerphone(m,p) ((m)->ciphone[p].filler)
#define mdef_n_ciphone(m) ((m)->n_ciphone)
#define mdef_n_phone(m) ((m)->n_phone)
#define mdef_n_sseq(m) ((m)->n_sseq)
#define mdef_n_emit_state(m) ((m)->n_emit_state)
#define mdef_n_sen(m) ((m)->n_sen)
#define mdef_n_tmat(m) ((m)->n_tmat)
#define mdef_pid2ssid(m,p) ((m)->phone[p].ssid)
#define mdef_pid2tmatid(m,p) ((m)->phone[p].tmat)
#define mdef_silphone(m) ((m)->sil)
#define mdef_sen2cimap(m) ((m)->sen2cimap)
#define mdef_sseq2sen(m,ss,pos) ((m)->sseq[ss][pos])
#define mdef_pid2ci(m,p) ((m)->phone[p].ci)
#define mdef_cd2cisen(m) ((m)->cd2cisen)
mdef_t *mdef_init (char *mdeffile,
int breport
);
int mdef_ciphone_id(mdef_t *m,
char *ciphone
);
const char *mdef_ciphone_str(mdef_t *m,
int ci
);
int mdef_is_ciphone (mdef_t *m,
int p
);
int mdef_is_cisenone(mdef_t *m,
int s
);
int mdef_phone_id (mdef_t *m,
int b,
int l,
int r,
word_posn_t pos
);
int mdef_phone_str(mdef_t *m,
int pid,
char *buf
);
int mdef_hmm_cmp (mdef_t *m,
int p1,
int p2
);
void mdef_report(mdef_t *m
);
void mdef_free_recursive_lc (ph_lc_t *lc
);
void mdef_free_recursive_rc (ph_rc_t *rc
);
void mdef_free (mdef_t *mdef
);
#ifdef __cplusplus
}
#endif
#endif
mdef_t::n_sseq
int32 n_sseq
No.
Definition: mdef.h:148
mdef_t
The main model definition structure.
Definition: mdef.h:135
mdef_t::n_ciphone
int32 n_ciphone
number basephones actually present
Definition: mdef.h:136
ph_lc_s::next
struct ph_lc_s * next
Next lc entry for same parent <wpos,ci>
Definition: mdef.h:126
phone_t::wpos
word_posn_t wpos
Word position.
Definition: mdef.h:103
ph_rc_s
Definition: mdef.h:112
WORD_POSN_SINGLE
Single phone word (i.e.
Definition: mdef.h:76
ciphone_t::filler
int32 filler
Whether a filler phone; if so, can be substituted by silence phone in left or right context position...
Definition: mdef.h:89
WORD_POSN_END
Ending phone of word.
Definition: mdef.h:75
mdef_t::n_phone
int32 n_phone
number basephones + number triphones actually present
Definition: mdef.h:137
phone_t::rc
int16 rc
Base, left, right context ciphones.
Definition: mdef.h:102
mdef_is_ciphone
int mdef_is_ciphone(mdef_t *m, int p)
Decide whether the phone is ci phone.
Definition: mdef.c:251
ciphone_t::name
char * name
The name of the CI phone.
Definition: mdef.h:88
mdef_t::cd2cisen
int16 * cd2cisen
Parent CI-senone id for each senone; the first n_ci_sen are identity mappings; the CD-senones are con...
Definition: mdef.h:150
mdef_free
void mdef_free(mdef_t *mdef)
Free an mdef_t.
Definition: mdef.c:720
mdef_t::n_ci_sen
int32 n_ci_sen
number CI senones; these are the first
Definition: mdef.h:139
phone_t::ssid
int32 ssid
State sequence (or senone sequence) ID, considering the n_emit_state senone-ids are a unit...
Definition: mdef.h:98
mdef_report
void mdef_report(mdef_t *m)
Report the model definition&#39;s parameters.
Definition: mdef.c:665
ph_lc_t
Structures for storing the left context.
ph_lc_s::lc
int16 lc
Specific lc for a parent <wpos,ci>
Definition: mdef.h:124
mdef_hmm_cmp
int mdef_hmm_cmp(mdef_t *m, int p1, int p2)
Compare the underlying HMMs for two given phones (i.e., compare the two transition matrix IDs and the...
mdef_phone_str
int mdef_phone_str(mdef_t *m, int pid, char *buf)
Create a phone string for the given phone (base or triphone) id in the given buf. ...
Definition: mdef.c:196
ph_rc_s::rc
int16 rc
Specific rc for a parent <wpos,ci,lc>
Definition: mdef.h:113
mdef_t::sseq
uint16 ** sseq
Unique state (or senone) sequences in this model, shared among all phones/triphones.
Definition: mdef.h:146
ph_rc_s::pid
int32 pid
Triphone id for above rc instance.
Definition: mdef.h:114
WORD_POSN_UNDEFINED
Undefined value, used for initial conditions, etc.
Definition: mdef.h:77
mdef_init
mdef_t * mdef_init(char *mdeffile, int breport)
Initialize the phone structure from the given model definition file.
phone_t
Triphone information, including base phones as a subset.
Definition: mdef.h:97
ph_lc_s::rclist
ph_rc_t * rclist
rc list for above lc instance
Definition: mdef.h:125
mdef_ciphone_str
const char * mdef_ciphone_str(mdef_t *m, int ci)
Get the phone string given the ci phone id.
Definition: mdef.c:186
mdef_phone_id
int mdef_phone_id(mdef_t *m, int b, int l, int r, word_posn_t pos)
Decide the phone id given the left, right and base phones.
Definition: mdef.c:219
mdef_t::ciphone
ciphone_t * ciphone
CI-phone information for all ciphones.
Definition: mdef.h:144
mdef_t::ciphone_ht
hash_table_t * ciphone_ht
Hash table for mapping ciphone strings to ids.
Definition: mdef.h:143
ciphone_t
CI phone information.
Definition: mdef.h:87
mdef_free_recursive_lc
void mdef_free_recursive_lc(ph_lc_t *lc)
RAH, For freeing memory.
Definition: mdef.c:688
mdef_t::n_sen
int32 n_sen
number senones (CI+CD)
Definition: mdef.h:140
WORD_POSN_BEGIN
Beginning phone of word.
Definition: mdef.h:74
phone_t::tmat
int32 tmat
Transition matrix id.
Definition: mdef.h:101
mdef_ciphone_id
int mdef_ciphone_id(mdef_t *m, char *ciphone)
Get the ciphone id given a string name.
Definition: mdef.c:176
ph_lc_s
Definition: mdef.h:123
mdef_t::sen2cimap
int16 * sen2cimap
Parent CI-phone for each senone (CI or CD)
Definition: mdef.h:153
ph_rc_s::next
struct ph_rc_s * next
Next rc entry for same parent <wpos,ci,lc>
Definition: mdef.h:115
WORD_POSN_INTERNAL
Internal phone of word.
Definition: mdef.h:73
mdef_t::n_tmat
int32 n_tmat
number transition matrices
Definition: mdef.h:141
mdef_is_cisenone
int mdef_is_cisenone(mdef_t *m, int s)
Decide whether the senone is a senone for a ci phone, or a ci senone.
Definition: mdef.c:260
word_posn_t
word_posn_t
Union of different type of word position.
Definition: mdef.h:72
mdef_t::n_emit_state
int32 n_emit_state
number emitting states per phone
Definition: mdef.h:138
mdef_t::sil
int16 sil
SILENCE_CIPHONE id.
Definition: mdef.h:155
mdef_t::wpos_ci_lclist
ph_lc_t *** wpos_ci_lclist
wpos_ci_lclist[wpos][ci] = list of lc for <wpos,ci>.
Definition: mdef.h:157
ph_rc_t
Structures needed for mapping <ci,lc,rc,wpos> into pid.
mdef_free_recursive_rc
void mdef_free_recursive_rc(ph_rc_t *rc)
Definition: mdef.c:703
mdef_t::phone
phone_t * phone
Information for all ciphones and triphones.
Definition: mdef.h:145