SphinxBase 5prealpha
logmath.h
Go to the documentation of this file.
1/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/* ====================================================================
3 * Copyright (c) 2007 Carnegie Mellon University. All rights
4 * reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * This work was supported in part by funding from the Defense Advanced
19 * Research Projects Agency and the National Science Foundation of the
20 * United States of America, and the CMU Sphinx Speech Consortium.
21 *
22 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * ====================================================================
35 *
36 */
72#ifndef __LOGMATH_H__
73#define __LOGMATH_H__
74
75#include <sphinxbase/sphinxbase_export.h>
77#include <sphinxbase/cmd_ln.h>
78
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83#if 0
84/* Fool Emacs. */
85}
86#endif
87
93typedef struct logadd_s logadd_t;
94struct logadd_s {
96 void *table;
98 uint32 table_size;
100 uint8 width;
102 int8 shift;
103};
104
108typedef struct logmath_s logmath_t;
109
113#define LOGMATH_TABLE(lm) ((logadd_t *)lm)
114
122SPHINXBASE_EXPORT
123logmath_t *logmath_init(float64 base, int shift, int use_table);
124
128SPHINXBASE_EXPORT
129logmath_t *logmath_read(const char *filename);
130
134SPHINXBASE_EXPORT
135int32 logmath_write(logmath_t *lmath, const char *filename);
136
140SPHINXBASE_EXPORT
141int32 logmath_get_table_shape(logmath_t *lmath, uint32 *out_size,
142 uint32 *out_width, uint32 *out_shift);
143
147SPHINXBASE_EXPORT
148float64 logmath_get_base(logmath_t *lmath);
149
153SPHINXBASE_EXPORT
154int logmath_get_zero(logmath_t *lmath);
155
159SPHINXBASE_EXPORT
160int logmath_get_width(logmath_t *lmath);
161
165SPHINXBASE_EXPORT
166int logmath_get_shift(logmath_t *lmath);
167
173SPHINXBASE_EXPORT
175
181SPHINXBASE_EXPORT
182int logmath_free(logmath_t *lmath);
183
187SPHINXBASE_EXPORT
188int logmath_add_exact(logmath_t *lmath, int logb_p, int logb_q);
189
193SPHINXBASE_EXPORT
194int logmath_add(logmath_t *lmath, int logb_p, int logb_q);
195
199SPHINXBASE_EXPORT
200int logmath_log(logmath_t *lmath, float64 p);
201
205SPHINXBASE_EXPORT
206float64 logmath_exp(logmath_t *lmath, int logb_p);
207
211SPHINXBASE_EXPORT
212int logmath_ln_to_log(logmath_t *lmath, float64 log_p);
213
217SPHINXBASE_EXPORT
218float64 logmath_log_to_ln(logmath_t *lmath, int logb_p);
219
223SPHINXBASE_EXPORT
224int logmath_log10_to_log(logmath_t *lmath, float64 log_p);
225
229SPHINXBASE_EXPORT
230float logmath_log10_to_log_float(logmath_t *lmath, float64 log_p);
231
235SPHINXBASE_EXPORT
236float64 logmath_log_to_log10(logmath_t *lmath, int logb_p);
237
241SPHINXBASE_EXPORT
242float64 logmath_log_float_to_log10(logmath_t *lmath, float log_p);
243
244#ifdef __cplusplus
245}
246#endif
247
248
249#endif /* __LOGMATH_H__ */
Command-line and other configurationparsing and handling.
SPHINXBASE_EXPORT int logmath_get_width(logmath_t *lmath)
Get the width of the values in a log table.
Definition logmath.c:380
SPHINXBASE_EXPORT int logmath_get_zero(logmath_t *lmath)
Get the smallest possible value represented in this base.
Definition logmath.c:374
SPHINXBASE_EXPORT float logmath_log10_to_log_float(logmath_t *lmath, float64 log_p)
Convert base 10 log (in floating point) to float log in base B.
Definition logmath.c:480
SPHINXBASE_EXPORT float64 logmath_log_float_to_log10(logmath_t *lmath, float log_p)
Convert float log in base B to base 10 log.
Definition logmath.c:496
SPHINXBASE_EXPORT int32 logmath_get_table_shape(logmath_t *lmath, uint32 *out_size, uint32 *out_width, uint32 *out_shift)
Get the log table size and dimensions.
Definition logmath.c:357
SPHINXBASE_EXPORT int logmath_ln_to_log(logmath_t *lmath, float64 log_p)
Convert natural log (in floating point) to integer log in base B.
Definition logmath.c:462
SPHINXBASE_EXPORT logmath_t * logmath_read(const char *filename)
Memory-map (or read) a log table from a file.
Definition logmath.c:164
SPHINXBASE_EXPORT int logmath_add(logmath_t *lmath, int logb_p, int logb_q)
Add two values in log space (i.e.
Definition logmath.c:392
SPHINXBASE_EXPORT float64 logmath_get_base(logmath_t *lmath)
Get the log base.
Definition logmath.c:368
SPHINXBASE_EXPORT int logmath_add_exact(logmath_t *lmath, int logb_p, int logb_q)
Add two values in log space exactly and slowly (without using add table).
Definition logmath.c:439
SPHINXBASE_EXPORT int32 logmath_write(logmath_t *lmath, const char *filename)
Write a log table to a file.
Definition logmath.c:272
SPHINXBASE_EXPORT float64 logmath_log_to_log10(logmath_t *lmath, int logb_p)
Convert integer log in base B to base 10 log (in floating point).
Definition logmath.c:490
SPHINXBASE_EXPORT float64 logmath_log_to_ln(logmath_t *lmath, int logb_p)
Convert integer log in base B to natural log (in floating point).
Definition logmath.c:468
SPHINXBASE_EXPORT int logmath_free(logmath_t *lmath)
Free a log table.
Definition logmath.c:342
SPHINXBASE_EXPORT int logmath_log10_to_log(logmath_t *lmath, float64 log_p)
Convert base 10 log (in floating point) to integer log in base B.
Definition logmath.c:474
SPHINXBASE_EXPORT logmath_t * logmath_init(float64 base, int shift, int use_table)
Initialize a log math computation table.
Definition logmath.c:62
SPHINXBASE_EXPORT logmath_t * logmath_retain(logmath_t *lmath)
Retain ownership of a log table.
Definition logmath.c:335
SPHINXBASE_EXPORT float64 logmath_exp(logmath_t *lmath, int logb_p)
Convert integer log in base B to linear floating point.
Definition logmath.c:456
SPHINXBASE_EXPORT int logmath_log(logmath_t *lmath, float64 p)
Convert linear floating point number to integer log in base B.
Definition logmath.c:447
SPHINXBASE_EXPORT int logmath_get_shift(logmath_t *lmath)
Get the shift of the values in a log table.
Definition logmath.c:386
Basic type definitions used in Sphinx.
void * table
Table, in unsigned integers of (width) bytes.
Definition logmath.h:96
int8 shift
Right shift applied to elements in (table).
Definition logmath.h:102
uint32 table_size
Number of elements in (table).
Definition logmath.h:98
uint8 width
Width of elements of (table).
Definition logmath.h:100