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).
#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.
int | bin_mdef_ciphone_id_nocase (bin_mdef_t *m, const char *ciphone)
| Case-insensitive context-independent phone lookup.
const char * | bin_mdef_ciphone_str (bin_mdef_t *m, int32 ci)
| In: ciphone id for which name wanted.
int | bin_mdef_phone_id (bin_mdef_t *m, int32 b, int32 l, int32 r, int32 pos)
| In: Word position.
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.

## 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
| ) |  | ((p) < (m)->n_ciphone)

Definition at line 148 of file bin_mdef.h.

## 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_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,
|  |  | 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_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,
|  |  | p
| ) |  |

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,
|  |  | p
| ) |  | ((m)->phone[p].ssid)

Definition at line 157 of file bin_mdef.h.

## bin_mdef_pid2tmatid

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

Definition at line 158 of file bin_mdef.h.

## bin_mdef_sen2cimap

#define bin_mdef_sen2cimap | ( |  | m,
|  |  | s
| ) |  | ((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

  m | In: Model structure being queried

Definition at line 691 of file bin_mdef.c.

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

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

  m | In: Model structure being queried

Definition at line 737 of file bin_mdef.c.

References bin_mdef_s::ciname.

## bin_mdef_free()

int bin_mdef_free | ( | bin_mdef_t * | m | ) |

Release a pointer to a binary mdef.

Definition at line 272 of file bin_mdef.c.

References bin_mdef_s::alloc_mode, bin_mdef_s::cd2cisen, bin_mdef_s::cd_tree, bin_mdef_s::ciname, bin_mdef_s::filemap, bin_mdef_s::phone, bin_mdef_s::sen2cimap, and bin_mdef_s::sseq.

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

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

Definition at line 868 of file bin_mdef.c.

References 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_s::alloc_mode, bin_mdef_s::cd2cisen, bin_mdef_s::cd_tree, bin_mdef_s::ciname, cd_tree_s::ctx, cd_tree_s::down, bin_mdef_s::filemap, bin_mdef_s::n_cd_tree, bin_mdef_s::n_ci_sen, bin_mdef_s::n_ciphone, bin_mdef_s::n_ctx, cd_tree_s::n_down, bin_mdef_s::n_emit_state, bin_mdef_s::n_phone, bin_mdef_s::n_sen, bin_mdef_s::n_sseq, bin_mdef_s::n_tmat, bin_mdef_s::phone, S3_SILENCE_CIPHONE, bin_mdef_s::sen2cimap, bin_mdef_s::sil, bin_mdef_s::sseq, bin_mdef_s::sseq_len, mdef_entry_s::ssid, and mdef_entry_s::tmat.

## bin_mdef_read_text()

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).

Definition at line 66 of file bin_mdef.c.

References bin_mdef_s::alloc_mode, BAD_SENID, BAD_SSID, bin_mdef_s::cd2cisen, mdef_t::cd2cisen, bin_mdef_s::cd_tree, mdef_entry_s::ci, bin_mdef_s::ciname, mdef_t::ciphone, mdef_entry_s::ctx, cd_tree_s::ctx, cd_tree_s::down, ciphone_t::filler, bin_mdef_s::n_cd_tree, bin_mdef_s::n_ci_sen, mdef_t::n_ci_sen, bin_mdef_s::n_ciphone, mdef_t::n_ciphone, bin_mdef_s::n_ctx, cd_tree_s::n_down, bin_mdef_s::n_emit_state, mdef_t::n_emit_state, bin_mdef_s::n_phone, mdef_t::n_phone, bin_mdef_s::n_sen, mdef_t::n_sen, bin_mdef_s::n_sseq, mdef_t::n_sseq, bin_mdef_s::n_tmat, mdef_t::n_tmat, N_WORD_POSN, ciphone_t::name, bin_mdef_s::phone, mdef_t::phone, cd_tree_s::pid, phone_t::rc, bin_mdef_s::sen2cimap, mdef_t::sen2cimap, bin_mdef_s::sil, mdef_t::sil, bin_mdef_s::sseq, mdef_t::sseq, mdef_entry_s::ssid, phone_t::ssid, mdef_entry_s::tmat, phone_t::tmat, phone_t::wpos, mdef_t::wpos_ci_lclist, and WPOS_NAME.

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

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

References bin_mdef_s::cd_tree, bin_mdef_s::ciname, bin_mdef_s::n_cd_tree, bin_mdef_s::n_ci_sen, bin_mdef_s::n_ciphone, bin_mdef_s::n_ctx, bin_mdef_s::n_emit_state, bin_mdef_s::n_phone, bin_mdef_s::n_sen, bin_mdef_s::n_sseq, bin_mdef_s::n_tmat, bin_mdef_s::phone, bin_mdef_s::sil, bin_mdef_s::sseq, and bin_mdef_s::sseq_len.

## bin_mdef_write_text()

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

Write a binary mdef to a text file.

Definition at line 606 of file bin_mdef.c.

References bin_mdef_s::ciname, mdef_entry_s::ctx, bin_mdef_s::n_ci_sen, bin_mdef_s::n_ciphone, bin_mdef_s::n_emit_state, bin_mdef_s::n_phone, bin_mdef_s::n_sen, bin_mdef_s::n_tmat, bin_mdef_s::phone, bin_mdef_s::sseq, bin_mdef_s::sseq_len, mdef_entry_s::ssid, mdef_entry_s::tmat, and WPOS_NAME.