logmath.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 2007 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
#ifndef __LOGMATH_H__
#define __LOGMATH_H__
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#include <sphinxbase/cmd_ln.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
typedef struct logadd_s logadd_t;
struct logadd_s {
void *table;
uint32 table_size;
uint8 width;
int8 shift;
};
typedef struct logmath_s logmath_t;
#define LOGMATH_TABLE(lm) ((logadd_t *)lm)
SPHINXBASE_EXPORT
logmath_t *logmath_init(float64 base, int shift, int use_table);
SPHINXBASE_EXPORT
logmath_t *logmath_read(const char *filename);
SPHINXBASE_EXPORT
int32 logmath_write(logmath_t *lmath, const char *filename);
SPHINXBASE_EXPORT
int32 logmath_get_table_shape(logmath_t *lmath, uint32 *out_size,
uint32 *out_width, uint32 *out_shift);
SPHINXBASE_EXPORT
float64 logmath_get_base(logmath_t *lmath);
SPHINXBASE_EXPORT
int logmath_get_zero(logmath_t *lmath);
SPHINXBASE_EXPORT
int logmath_get_width(logmath_t *lmath);
SPHINXBASE_EXPORT
int logmath_get_shift(logmath_t *lmath);
SPHINXBASE_EXPORT
logmath_t *logmath_retain(logmath_t *lmath);
SPHINXBASE_EXPORT
int logmath_free(logmath_t *lmath);
SPHINXBASE_EXPORT
int logmath_add_exact(logmath_t *lmath, int logb_p, int logb_q);
SPHINXBASE_EXPORT
int logmath_add(logmath_t *lmath, int logb_p, int logb_q);
SPHINXBASE_EXPORT
int logmath_log(logmath_t *lmath, float64 p);
SPHINXBASE_EXPORT
float64 logmath_exp(logmath_t *lmath, int logb_p);
SPHINXBASE_EXPORT
int logmath_ln_to_log(logmath_t *lmath, float64 log_p);
SPHINXBASE_EXPORT
float64 logmath_log_to_ln(logmath_t *lmath, int logb_p);
SPHINXBASE_EXPORT
int logmath_log10_to_log(logmath_t *lmath, float64 log_p);
SPHINXBASE_EXPORT
float64 logmath_log_to_log10(logmath_t *lmath, int logb_p);
#ifdef __cplusplus
}
#endif
#endif /* __LOGMATH_H__ */
cmd_ln.h
Command-line and other configurationparsing and handling.
logmath_get_table_shape
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
logmath_s
Definition: logmath.c:49
logmath_log
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
logmath_free
SPHINXBASE_EXPORT int logmath_free(logmath_t *lmath)
Free a log table.
Definition: logmath.c:342
prim_type.h
Basic type definitions used in Sphinx.
logmath_init
SPHINXBASE_EXPORT logmath_t * logmath_init(float64 base, int shift, int use_table)
Initialize a log math computation table.
Definition: logmath.c:62
logmath_add_exact
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
logmath_log_to_ln
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
logadd_s::table_size
uint32 table_size
Number of elements in (table).
Definition: logmath.h:98
logmath_get_shift
SPHINXBASE_EXPORT int logmath_get_shift(logmath_t *lmath)
Get the shift of the values in a log table.
Definition: logmath.c:386
logmath_get_base
SPHINXBASE_EXPORT float64 logmath_get_base(logmath_t *lmath)
Get the log base.
Definition: logmath.c:368
logmath_retain
SPHINXBASE_EXPORT logmath_t * logmath_retain(logmath_t *lmath)
Retain ownership of a log table.
Definition: logmath.c:335
logadd_s::table
void * table
Table, in unsigned integers of (width) bytes.
Definition: logmath.h:96
logmath_get_zero
SPHINXBASE_EXPORT int logmath_get_zero(logmath_t *lmath)
Get the smallest possible value represented in this base.
Definition: logmath.c:374
logadd_s::shift
int8 shift
Right shift applied to elements in (table).
Definition: logmath.h:102
logmath_read
SPHINXBASE_EXPORT logmath_t * logmath_read(const char *filename)
Memory-map (or read) a log table from a file.
Definition: logmath.c:164
logmath_get_width
SPHINXBASE_EXPORT int logmath_get_width(logmath_t *lmath)
Get the width of the values in a log table.
Definition: logmath.c:380
logadd_s
Definition: logmath.h:94
logmath_log_to_log10
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:480
logadd_s::width
uint8 width
Width of elements of (table).
Definition: logmath.h:100
logmath_write
SPHINXBASE_EXPORT int32 logmath_write(logmath_t *lmath, const char *filename)
Write a log table to a file.
Definition: logmath.c:272
logmath_exp
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
logmath_log10_to_log
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
logmath_ln_to_log
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
logmath_add
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