bin_mdef.h File Reference
`#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).
#define | BAD_SENID 0xffff
| Invalid senone ID (limited to 16 bits for PocketSphinx).
#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)
typedef struct cd_tree_s | cd_tree_t
| Node in CD phone tree (on-disk, 8 bytes).
typedef struct bin_mdef_s | bin_mdef_t
| Model definition structure (in-memory).

## Functions

POCKETSPHINX_EXPORT bin_mdef_t * | bin_mdef_read (cmd_ln_t *config, const char *filename)
| Read a binary mdef from a file.
POCKETSPHINX_EXPORT bin_mdef_t * | bin_mdef_read_text (cmd_ln_t *config, const char *filename)
| Read a text mdef from a file (creating an in-memory binary mdef).
POCKETSPHINX_EXPORT int | bin_mdef_write (bin_mdef_t *m, const char *filename)
| Write a binary mdef to a file.
POCKETSPHINX_EXPORT int | bin_mdef_write_text (bin_mdef_t *m, const char *filename)
| Write a binary mdef to a text file.
bin_mdef_t * | bin_mdef_retain (bin_mdef_t *m)
| Retain a pointer to a bin_mdef_t.
int | bin_mdef_free (bin_mdef_t *m)
| Release a pointer to a binary mdef.
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

## bin_mdef_is_fillerphone

#define bin_mdef_is_fillerphone | ( |  | m,
|  |  | p
| ) |  |

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_emit_state_phone

#define bin_mdef_n_emit_state_phone | ( |  | m,
|  |  | p
| ) |  |

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_pid2ci

#define bin_mdef_pid2ci | ( |  | m,
|  |  | p
| ) |  |

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

Definition at line 162 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

  m | In: Model structure being queried

Definition at line 690 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

  m | In: Model structure being queried

Definition at line 713 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

  m | In: Model structure being queried

Definition at line 736 of file bin_mdef.c.

References bin_mdef_s::ciname.

Referenced by bin_mdef_phone_str(), and dict_ciphone_str().

## 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

  m | In: Model structure being queried
  b | In: base ciphone id
  l | In: left context ciphone id
  r | In: right context ciphone id

Definition at line 744 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_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

  m | In: Model structure being queried
  pid | In: phone id being queried

Definition at line 867 of file bin_mdef.c.

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