PocketSphinx 5prealpha
bin_mdef.h File Reference

Binary format model definition files, with support for heterogeneous topologies and variable-size N-phones. More...

#include <sphinxbase/mmio.h>
#include <sphinxbase/cmd_ln.h>
#include <pocketsphinx_export.h>
#include "mdef.h"

Go to the source code of this file.

Data Structures

struct  mdef_entry_s
 
struct  cd_tree_s
 
struct  bin_mdef_s
 

Macros

#define BIN_MDEF_FORMAT_VERSION   1
 
#define BIN_MDEF_NATIVE_ENDIAN   0x46444d42 /* 'BMDF' in little-endian order */
 
#define BIN_MDEF_OTHER_ENDIAN   0x424d4446 /* 'BMDF' in big-endian order */
 
#define __ATTRIBUTE_PACKED
 
#define BAD_SSID   0xffff
 Invalid senone sequence ID (limited to 16 bits for PocketSphinx). More...
 
#define BAD_SENID   0xffff
 Invalid senone ID (limited to 16 bits for PocketSphinx). More...
 
#define bin_mdef_is_fillerphone(m, p)
 
#define bin_mdef_is_ciphone(m, p)   ((p) < (m)->n_ciphone)
 
#define bin_mdef_n_ciphone(m)   ((m)->n_ciphone)
 
#define bin_mdef_n_phone(m)   ((m)->n_phone)
 
#define bin_mdef_n_sseq(m)   ((m)->n_sseq)
 
#define bin_mdef_n_emit_state(m)   ((m)->n_emit_state)
 
#define bin_mdef_n_emit_state_phone(m, p)
 
#define bin_mdef_n_sen(m)   ((m)->n_sen)
 
#define bin_mdef_n_tmat(m)   ((m)->n_tmat)
 
#define bin_mdef_pid2ssid(m, p)   ((m)->phone[p].ssid)
 
#define bin_mdef_pid2tmatid(m, p)   ((m)->phone[p].tmat)
 
#define bin_mdef_silphone(m)   ((m)->sil)
 
#define bin_mdef_sen2cimap(m, s)   ((m)->sen2cimap[s])
 
#define bin_mdef_sseq2sen(m, ss, pos)   ((m)->sseq[ss][pos])
 
#define bin_mdef_pid2ci(m, p)
 

Typedefs

typedef struct mdef_entry_s mdef_entry_t
 Phone entry (on-disk, 12 bytes) More...
 
typedef struct cd_tree_s cd_tree_t
 Node in CD phone tree (on-disk, 8 bytes). More...
 
typedef struct bin_mdef_s bin_mdef_t
 Model definition structure (in-memory). More...
 

Functions

POCKETSPHINX_EXPORT bin_mdef_tbin_mdef_read (cmd_ln_t *config, const char *filename)
 Read a binary mdef from a file. More...
 
POCKETSPHINX_EXPORT bin_mdef_tbin_mdef_read_text (cmd_ln_t *config, const char *filename)
 Read a text mdef from a file (creating an in-memory binary mdef). More...
 
POCKETSPHINX_EXPORT int bin_mdef_write (bin_mdef_t *m, const char *filename)
 Write a binary mdef to a file. More...
 
POCKETSPHINX_EXPORT int bin_mdef_write_text (bin_mdef_t *m, const char *filename)
 Write a binary mdef to a text file. More...
 
bin_mdef_tbin_mdef_retain (bin_mdef_t *m)
 Retain a pointer to a bin_mdef_t. More...
 
int bin_mdef_free (bin_mdef_t *m)
 Release a pointer to a binary mdef. More...
 
int bin_mdef_ciphone_id (bin_mdef_t *m, const char *ciphone)
 Context-independent phone lookup. More...
 
int bin_mdef_ciphone_id_nocase (bin_mdef_t *m, const char *ciphone)
 Case-insensitive context-independent phone lookup. More...
 
const char * bin_mdef_ciphone_str (bin_mdef_t *m, int32 ci)
 In: ciphone id for which name wanted. More...
 
int bin_mdef_phone_id (bin_mdef_t *m, int32 b, int32 l, int32 r, int32 pos)
 In: Word position. More...
 
int bin_mdef_phone_id_nearest (bin_mdef_t *m, int32 b, int32 l, int32 r, int32 pos)
 
int bin_mdef_phone_str (bin_mdef_t *m, int pid, char *buf)
 Create a phone string for the given phone (base or triphone) id in the given buf. More...
 

Variables

struct mdef_entry_s __ATTRIBUTE_PACKED
 

Detailed Description

Binary format model definition files, with support for heterogeneous topologies and variable-size N-phones.

Author
David Huggins-Daines dhugg.nosp@m.ins@.nosp@m.cs.cm.nosp@m.u.ed.nosp@m.u

Definition in file bin_mdef.h.

Macro Definition Documentation

◆ __ATTRIBUTE_PACKED

#define __ATTRIBUTE_PACKED

Definition at line 66 of file bin_mdef.h.

◆ BAD_SENID

#define BAD_SENID   0xffff

Invalid senone ID (limited to 16 bits for PocketSphinx).

Definition at line 98 of file bin_mdef.h.

◆ BAD_SSID

#define BAD_SSID   0xffff

Invalid senone sequence ID (limited to 16 bits for PocketSphinx).

Definition at line 94 of file bin_mdef.h.

◆ BIN_MDEF_FORMAT_VERSION

#define BIN_MDEF_FORMAT_VERSION   1

Definition at line 59 of file bin_mdef.h.

◆ bin_mdef_is_ciphone

#define bin_mdef_is_ciphone (   m,
 
)    ((p) < (m)->n_ciphone)

Definition at line 148 of file bin_mdef.h.

◆ bin_mdef_is_fillerphone

#define bin_mdef_is_fillerphone (   m,
 
)
Value:
(((p) < (m)->n_ciphone) \
? (m)->phone[p].info.ci.filler \
: (m)->phone[(m)->phone[p].info.cd.ctx[0]].info.ci.filler)

Definition at line 145 of file bin_mdef.h.

◆ bin_mdef_n_ciphone

#define bin_mdef_n_ciphone (   m)    ((m)->n_ciphone)

Definition at line 149 of file bin_mdef.h.

◆ bin_mdef_n_emit_state

#define bin_mdef_n_emit_state (   m)    ((m)->n_emit_state)

Definition at line 152 of file bin_mdef.h.

◆ bin_mdef_n_emit_state_phone

#define bin_mdef_n_emit_state_phone (   m,
 
)
Value:
((m)->n_emit_state ? (m)->n_emit_state \
: (m)->sseq_len[(m)->phone[p].ssid])

Definition at line 153 of file bin_mdef.h.

◆ bin_mdef_n_phone

#define bin_mdef_n_phone (   m)    ((m)->n_phone)

Definition at line 150 of file bin_mdef.h.

◆ bin_mdef_n_sen

#define bin_mdef_n_sen (   m)    ((m)->n_sen)

Definition at line 155 of file bin_mdef.h.

◆ bin_mdef_n_sseq

#define bin_mdef_n_sseq (   m)    ((m)->n_sseq)

Definition at line 151 of file bin_mdef.h.

◆ bin_mdef_n_tmat

#define bin_mdef_n_tmat (   m)    ((m)->n_tmat)

Definition at line 156 of file bin_mdef.h.

◆ BIN_MDEF_NATIVE_ENDIAN

#define BIN_MDEF_NATIVE_ENDIAN   0x46444d42 /* 'BMDF' in little-endian order */

Definition at line 61 of file bin_mdef.h.

◆ BIN_MDEF_OTHER_ENDIAN

#define BIN_MDEF_OTHER_ENDIAN   0x424d4446 /* 'BMDF' in big-endian order */

Definition at line 62 of file bin_mdef.h.

◆ bin_mdef_pid2ci

#define bin_mdef_pid2ci (   m,
 
)
Value:
(((p) < (m)->n_ciphone) ? (p) \
: (m)->phone[p].info.cd.ctx[0])

Definition at line 162 of file bin_mdef.h.

◆ bin_mdef_pid2ssid

#define bin_mdef_pid2ssid (   m,
 
)    ((m)->phone[p].ssid)

Definition at line 157 of file bin_mdef.h.

◆ bin_mdef_pid2tmatid

#define bin_mdef_pid2tmatid (   m,
 
)    ((m)->phone[p].tmat)

Definition at line 158 of file bin_mdef.h.

◆ bin_mdef_sen2cimap

#define bin_mdef_sen2cimap (   m,
 
)    ((m)->sen2cimap[s])

Definition at line 160 of file bin_mdef.h.

◆ bin_mdef_silphone

#define bin_mdef_silphone (   m)    ((m)->sil)

Definition at line 159 of file bin_mdef.h.

◆ bin_mdef_sseq2sen

#define bin_mdef_sseq2sen (   m,
  ss,
  pos 
)    ((m)->sseq[ss][pos])

Definition at line 161 of file bin_mdef.h.

Typedef Documentation

◆ bin_mdef_t

typedef struct bin_mdef_s bin_mdef_t

Model definition structure (in-memory).

Definition at line 116 of file bin_mdef.h.

◆ cd_tree_t

typedef struct cd_tree_s cd_tree_t

Node in CD phone tree (on-disk, 8 bytes).

Definition at line 103 of file bin_mdef.h.

◆ mdef_entry_t

typedef struct mdef_entry_s mdef_entry_t

Phone entry (on-disk, 12 bytes)

Definition at line 72 of file bin_mdef.h.

Function Documentation

◆ bin_mdef_ciphone_id()

int bin_mdef_ciphone_id ( bin_mdef_t m,
const char *  ciphone 
)

Context-independent phone lookup.

Returns
phone id for ciphone. In: ciphone for which id wanted
Parameters
mIn: Model structure being queried

Definition at line 691 of file bin_mdef.c.

References bin_mdef_s::ciname, and bin_mdef_s::n_ciphone.

Referenced by ps_add_word().

◆ bin_mdef_ciphone_id_nocase()

int bin_mdef_ciphone_id_nocase ( bin_mdef_t m,
const char *  ciphone 
)

Case-insensitive context-independent phone lookup.

Returns
phone id for ciphone. In: ciphone for which id wanted
Parameters
mIn: Model structure being queried

Definition at line 714 of file bin_mdef.c.

References bin_mdef_s::ciname, and bin_mdef_s::n_ciphone.

◆ bin_mdef_ciphone_str()

const char * bin_mdef_ciphone_str ( bin_mdef_t m,
int32  ci 
)

In: ciphone id for which name wanted.

Parameters
mIn: Model structure being queried

Definition at line 737 of file bin_mdef.c.

References bin_mdef_s::ciname.

Referenced by bin_mdef_phone_str(), and dict_ciphone_str().

◆ bin_mdef_free()

int bin_mdef_free ( bin_mdef_t m)

◆ bin_mdef_phone_id()

int bin_mdef_phone_id ( bin_mdef_t m,
int32  b,
int32  l,
int32  r,
int32  pos 
)

In: Word position.

Parameters
mIn: Model structure being queried
bIn: base ciphone id
lIn: left context ciphone id
rIn: right context ciphone id

Definition at line 745 of file bin_mdef.c.

References bin_mdef_s::cd_tree, mdef_entry_s::ci, bin_mdef_s::ciname, cd_tree_s::ctx, cd_tree_s::down, cd_tree_s::n_down, N_WORD_POSN, bin_mdef_s::phone, cd_tree_s::pid, and bin_mdef_s::sil.

◆ bin_mdef_phone_id_nearest()

int bin_mdef_phone_id_nearest ( bin_mdef_t m,
int32  b,
int32  l,
int32  r,
int32  pos 
)

Definition at line 814 of file bin_mdef.c.

◆ bin_mdef_phone_str()

int bin_mdef_phone_str ( bin_mdef_t m,
int  pid,
char *  buf 
)

Create a phone string for the given phone (base or triphone) id in the given buf.

Returns
0 if successful, -1 if error. Out: On return, buf has the string
Parameters
mIn: Model structure being queried
pidIn: phone id being queried

Definition at line 868 of file bin_mdef.c.

References bin_mdef_ciphone_str(), mdef_entry_s::ctx, bin_mdef_s::phone, and WPOS_NAME.

◆ bin_mdef_read()

POCKETSPHINX_EXPORT bin_mdef_t * bin_mdef_read ( cmd_ln_t *  config,
const char *  filename 
)

Read a binary mdef from a file.

Definition at line 323 of file bin_mdef.c.

References bin_mdef_read_text().

◆ bin_mdef_read_text()

◆ bin_mdef_retain()

bin_mdef_t * bin_mdef_retain ( bin_mdef_t m)

Retain a pointer to a bin_mdef_t.

Definition at line 265 of file bin_mdef.c.

Referenced by dict2pid_build().

◆ bin_mdef_write()

POCKETSPHINX_EXPORT int bin_mdef_write ( bin_mdef_t m,
const char *  filename 
)

Write a binary mdef to a file.

Definition at line 522 of file bin_mdef.c.

◆ bin_mdef_write_text()

POCKETSPHINX_EXPORT int bin_mdef_write_text ( bin_mdef_t m,
const char *  filename 
)