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>
76 #include <sphinxbase/prim_type.h>
77 #include <sphinxbase/cmd_ln.h>
78 
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 #if 0
84 /* Fool Emacs. */
85 }
86 #endif
87 
93 typedef struct logadd_s logadd_t;
94 struct logadd_s {
96  void *table;
98  uint32 table_size;
100  uint8 width;
102  int8 shift;
103 };
104 
108 typedef struct logmath_s logmath_t;
109 
113 #define LOGMATH_TABLE(lm) ((logadd_t *)lm)
114 
122 SPHINXBASE_EXPORT
123 logmath_t *logmath_init(float64 base, int shift, int use_table);
124 
128 SPHINXBASE_EXPORT
129 logmath_t *logmath_read(const char *filename);
130 
134 SPHINXBASE_EXPORT
135 int32 logmath_write(logmath_t *lmath, const char *filename);
136 
140 SPHINXBASE_EXPORT
141 int32 logmath_get_table_shape(logmath_t *lmath, uint32 *out_size,
142  uint32 *out_width, uint32 *out_shift);
143 
147 SPHINXBASE_EXPORT
148 float64 logmath_get_base(logmath_t *lmath);
149 
153 SPHINXBASE_EXPORT
154 int logmath_get_zero(logmath_t *lmath);
155 
159 SPHINXBASE_EXPORT
160 int logmath_get_width(logmath_t *lmath);
161 
165 SPHINXBASE_EXPORT
166 int logmath_get_shift(logmath_t *lmath);
167 
173 SPHINXBASE_EXPORT
175 
181 SPHINXBASE_EXPORT
182 int logmath_free(logmath_t *lmath);
183 
187 SPHINXBASE_EXPORT
188 int logmath_add_exact(logmath_t *lmath, int logb_p, int logb_q);
189 
193 SPHINXBASE_EXPORT
194 int logmath_add(logmath_t *lmath, int logb_p, int logb_q);
195 
199 SPHINXBASE_EXPORT
200 int logmath_log(logmath_t *lmath, float64 p);
201 
205 SPHINXBASE_EXPORT
206 float64 logmath_exp(logmath_t *lmath, int logb_p);
207 
211 SPHINXBASE_EXPORT
212 int logmath_ln_to_log(logmath_t *lmath, float64 log_p);
213 
217 SPHINXBASE_EXPORT
218 float64 logmath_log_to_ln(logmath_t *lmath, int logb_p);
219 
223 SPHINXBASE_EXPORT
224 int logmath_log10_to_log(logmath_t *lmath, float64 log_p);
225 
229 SPHINXBASE_EXPORT
230 float logmath_log10_to_log_float(logmath_t *lmath, float64 log_p);
231 
235 SPHINXBASE_EXPORT
236 float64 logmath_log_to_log10(logmath_t *lmath, int logb_p);
237 
241 SPHINXBASE_EXPORT
242 float64 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 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_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_free(logmath_t *lmath)
Free a log table.
Definition: logmath.c:342
Basic type definitions used in Sphinx.
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 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 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 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
uint32 table_size
Number of elements in (table).
Definition: logmath.h:98
SPHINXBASE_EXPORT int logmath_get_shift(logmath_t *lmath)
Get the shift of the values in a log table.
Definition: logmath.c:386
SPHINXBASE_EXPORT float64 logmath_get_base(logmath_t *lmath)
Get the log base.
Definition: logmath.c:368
SPHINXBASE_EXPORT logmath_t * logmath_retain(logmath_t *lmath)
Retain ownership of a log table.
Definition: logmath.c:335
void * table
Table, in unsigned integers of (width) bytes.
Definition: logmath.h:96
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 int logmath_get_zero(logmath_t *lmath)
Get the smallest possible value represented in this base.
Definition: logmath.c:374
int8 shift
Right shift applied to elements in (table).
Definition: logmath.h:102
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_get_width(logmath_t *lmath)
Get the width of the values in a log table.
Definition: logmath.c:380
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
uint8 width
Width of elements of (table).
Definition: logmath.h:100
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_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_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 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 int logmath_add(logmath_t *lmath, int logb_p, int logb_q)
Add two values in log space (i.e.
Definition: logmath.c:392