Revision: 9757
http://cmusphinx.svn.sourceforge.net/cmusphinx/?rev=9757&view=rev
Author: dhdfu
Date: 2010-02-28 20:55:10 +0000 (Sun, 28 Feb 2010)
Log Message:
-----------
merge a huge number of changes from the trunk
Modified Paths:
--------------
branches/pocketsphinx-0.6/sphinxbase/include/bitvec.h
branches/pocketsphinx-0.6/sphinxbase/include/fe.h
branches/pocketsphinx-0.6/sphinxbase/include/fixpoint.h
branches/pocketsphinx-0.6/sphinxbase/include/ngram_model.h
branches/pocketsphinx-0.6/sphinxbase/include/sphinx_config.h.in
branches/pocketsphinx-0.6/sphinxbase/sphinxbase.sln
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/fe/fixlog.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/_jsgf_scanner.l
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.h
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.h
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model_arpa.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/err.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/filename.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/pio.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/profile.c
branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/sbthread.c
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/cmd_ln_defn.h
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_lmtools/sphinx_lm_convert.c
branches/pocketsphinx-0.6/sphinxbase/test/regression/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ad/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ad/test_ad_copy.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ad/test_ad_read.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_alloc/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_bitvec/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_lcase1.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_fe/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_fe/test_fe.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_fe/test_pitch.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_feat/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_feat/test_feat_fe.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ngram/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ngram/test_lm_set.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ngram/test_macros.h
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/strtest.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_thread/Makefile.am
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_thread/test_thread.c
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_thread/test_tls_log.c
branches/pocketsphinx-0.6/sphinxbase/win32/sphinx_cepview/sphinx_cepview.vcproj
branches/pocketsphinx-0.6/sphinxbase/win32/sphinx_fe/sphinx_fe.vcproj
branches/pocketsphinx-0.6/sphinxbase/win32/sphinx_jsgf2fsg/sphinx_jsgf2fsg.vcproj
Added Paths:
-----------
branches/pocketsphinx-0.6/sphinxbase/build_for_iphone.sh
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_fe.c
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_wave2feat.h
branches/pocketsphinx-0.6/sphinxbase/test/regression/chan3.ctl
branches/pocketsphinx-0.6/sphinxbase/test/regression/chan3.sph
branches/pocketsphinx-0.6/sphinxbase/test/regression/chan3.wav
branches/pocketsphinx-0.6/sphinxbase/test/regression/test-sphinx_fe-ctl.sh
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ngram/test_lm_casefold.c
Removed Paths:
-------------
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/wave2feat.c
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/wave2feat.h
Property Changed:
----------------
branches/pocketsphinx-0.6/sphinxbase/
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_adtools/
branches/pocketsphinx-0.6/sphinxbase/src/sphinx_lmtools/
branches/pocketsphinx-0.6/sphinxbase/test/regression/
branches/pocketsphinx-0.6/sphinxbase/test/regression/testfuncs.sh.in
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ad/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_alloc/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_bitvec/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_lcase1.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_lcase2.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_lcase3.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_strcmp1.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_strcmp2.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_strcmp3.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_ucase1.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_ucase2.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_case/_ucase3.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/_test_parse_badargs.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/_test_parse_defaults.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/_test_parse_defaults_r.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/_test_parse_goodargs.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_cmdln/_test_parse_multiple.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_fe/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_feat/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_feat/_test_feat.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_fsg/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/_hash_delete1.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/_hash_delete2.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/_hash_delete3.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/_hash_delete4.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_hash/_hash_delete5.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_logmath/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_matrix/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_matrix/_test_determinant.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_matrix/_test_invert.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_matrix/_test_solve.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_ngram/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_fread_line.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_fread_line.txt
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_nextword.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_str2words.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_string_join.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_string/_string_trim.test
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_thread/
branches/pocketsphinx-0.6/sphinxbase/test/unit/test_util/
branches/pocketsphinx-0.6/sphinxbase/test/unit/testfuncs.sh.in
Property changes on: branches/pocketsphinx-0.6/sphinxbase
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/pocketsphinx-0.5/sphinxbase:8806-8837
/trunk/sphinxbase:9597-9676
+ /branches/pocketsphinx-0.5/sphinxbase:8806-8837
/trunk/sphinxbase:9597-9756
Copied: branches/pocketsphinx-0.6/sphinxbase/build_for_iphone.sh (from rev 9756, trunk/sphinxbase/build_for_iphone.sh)
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/build_for_iphone.sh (rev 0)
+++ branches/pocketsphinx-0.6/sphinxbase/build_for_iphone.sh 2010-02-28 20:55:10 UTC (rev 9757)
@@ -0,0 +1,135 @@
+#!/bin/bash
+#
+# This script drives ./configure for cross-platform (ie simulator and device) building on
+# MacOS X.
+#
+################################################################################
+#
+# Copyright (c) 2008-2009 Christopher J. Stawarz
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+################################################################################
+
+
+
+# Disallow undefined variables
+set -u
+
+default_gcc_version=4.2
+default_iphoneos_version=3.1.2
+default_macos_version=10.5
+
+GCC_VERSION="${GCC_VERSION:-$default_gcc_version}"
+export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}"
+export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-$default_macos_version}"
+
+
+usage ()
+{
+ cat >&2 << EOF
+Usage: ${0##*/} [-ht] [-p prefix] target [configure_args]
+ -h Print help message
+ -p Installation prefix (default: \$HOME/Developer/Platforms/...)
+ -t Use 16-bit Thumb instruction set (instead of 32-bit ARM)
+
+The target must be "device" or "simulator". Any additional arguments
+are passed to configure.
+
+The following environment variables affect the build process:
+
+ GCC_VERSION (default: $default_gcc_version)
+ IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version)
+ MACOSX_DEPLOYMENT_TARGET (default: $default_macos_version)
+
+EOF
+}
+
+
+while getopts ":hp:t" opt; do
+ case $opt in
+ h ) usage ; exit 0 ;;
+ p ) prefix="$OPTARG" ;;
+ t ) thumb_opt=thumb ;;
+ \? ) usage ; exit 2 ;;
+ esac
+done
+shift $(( $OPTIND - 1 ))
+
+if (( $# < 1 )); then
+ usage
+ exit 2
+fi
+
+target=$1
+shift
+
+case $target in
+
+ device )
+ arch=armv6
+ platform=iPhoneOS
+ extra_cflags="-m${thumb_opt:-no-thumb} -mthumb-interwork"
+ ;;
+
+ simulator )
+ arch=i386
+ platform=iPhoneSimulator
+ extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
+ ;;
+
+ * )
+ usage
+ exit 2
+
+esac
+
+
+platform_dir="/Developer/Platforms/${platform}.platform/Developer"
+platform_bin_dir="${platform_dir}/usr/bin"
+platform_sdk_dir="${platform_dir}/SDKs/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk"
+prefix="${prefix:-${HOME}${platform_sdk_dir}}"
+
+export CC="${platform_bin_dir}/gcc-${GCC_VERSION}"
+export CFLAGS="-arch ${arch} -pipe -Os -gdwarf-2 -isysroot ${platform_sdk_dir} ${extra_cflags}"
+export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}"
+export CXX="${platform_bin_dir}/g++-${GCC_VERSION}"
+export CXXFLAGS="${CFLAGS}"
+export CPP="/Developer/usr/bin/cpp-${GCC_VERSION}"
+export CXXCPP="${CPP}"
+
+
+./configure \
+ --prefix="${prefix}" \
+ --host="${arch}-apple-darwin" \
+ --disable-shared \
+ --enable-static \
+ "$@" || exit
+
+make install || exit
+
+cat >&2 << EOF
+
+Build succeeded! Files were installed in
+
+ $prefix
+
+EOF
Modified: branches/pocketsphinx-0.6/sphinxbase/include/bitvec.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/include/bitvec.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/include/bitvec.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -94,6 +94,15 @@
#define bitvec_set(v,b) (v[(b)/BITVEC_BITS] |= (1UL << ((b) & (BITVEC_BITS-1))))
/**
+ * Set all n bits in bit vector v
+ * @param v is a vector
+ * @param n is the number of bits
+ */
+
+#define bitvec_set_all(v,n) memset(v, (bitvec_t)-1, \
+ (((n)+BITVEC_BITS-1)/BITVEC_BITS) * \
+ sizeof(bitvec_t))
+/**
* Clear the b-th bit of bit vector v
* @param v is a vector
* @param b is the bit which will be set
Modified: branches/pocketsphinx-0.6/sphinxbase/include/fe.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/include/fe.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/include/fe.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -119,16 +119,6 @@
"legacy", \
"Which type of transform to use to calculate cepstra (legacy, dct, or htk)" }, \
\
- { "-spec2cep", \
- ARG_BOOLEAN, \
- "no", \
- "Input is log spectral files, output is cepstral files" }, \
- \
- { "-cep2spec", \
- ARG_BOOLEAN, \
- "no", \
- "Input is cepstral files, output is log spectral files" }, \
- \
{ "-alpha", \
ARG_FLOAT32, \
ARG_STRINGIFY(DEFAULT_PRE_EMPHASIS_ALPHA), \
@@ -223,12 +213,13 @@
ARG_BOOLEAN, \
"no", \
"Remove DC offset from each frame" }, \
- \
+ \
{ "-verbose", \
ARG_BOOLEAN, \
"no", \
- "Show input filenames" }
+ "Show input filenames" } \
+
#ifdef FIXED_POINT
/** MFCC computation type. */
typedef fixed32 mfcc_t;
Modified: branches/pocketsphinx-0.6/sphinxbase/include/fixpoint.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/include/fixpoint.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/include/fixpoint.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -55,7 +55,9 @@
}
#endif
-#define DEFAULT_RADIX (12)
+#ifndef DEFAULT_RADIX
+#define DEFAULT_RADIX 12
+#endif
/** Fixed-point computation type. */
typedef int32 fixed32;
@@ -76,11 +78,16 @@
* A veritable multiplicity of implementations exist, starting with
* the fastest ones...
*/
-#if defined(__arm__) /* Actually this is StrongARM-specific... */
+
+
+/* Actually this is StrongARM-specific and not armv6-compatible.
+ * Skip out iPhone targets by skipping __APPLE__ builds.
+ */
+#if defined(__arm__) && !defined(__APPLE__)
#define FIXMUL(a,b) FIXMUL_ANY(a,b,DEFAULT_RADIX)
#define FIXMUL_ANY(a,b,r) ({ \
int cl, ch, _a = a, _b = b; \
- asm ("smull %0, %1, %2, %3\n" \
+ __asm__ ("smull %0, %1, %2, %3\n" \
"mov %0, %0, lsr %4\n" \
"orr %0, %0, %1, lsl %5\n" \
: "=&r" (cl), "=&r" (ch) \
@@ -92,7 +99,7 @@
/* Use the accumulators for the 16.16 case (probably not as efficient as it could be). */
#define FIXMUL(a,b) ({ \
int c, _a = a, _b = b; \
- asm("%0.L = %1.l * %2.l (FU);\n\t" \
+ __asm__("%0.L = %1.l * %2.l (FU);\n\t" \
"%0.H = %1.h * %2.h (IS);\n\t" \
"A1 = %0;\n\t" \
"A1 += %1.h * %2.l (IS, M);\n\t" \
Modified: branches/pocketsphinx-0.6/sphinxbase/include/ngram_model.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/include/ngram_model.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/include/ngram_model.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -178,6 +178,23 @@
int ngram_model_recode(ngram_model_t *model, const char *from, const char *to);
/**
+ * Constants for case folding.
+ */
+typedef enum ngram_case_e {
+ NGRAM_UPPER,
+ NGRAM_LOWER
+} ngram_case_t;
+
+/**
+ * Case-fold word strings in an N-Gram model.
+ *
+ * WARNING: This is not Unicode aware, so any non-ASCII characters
+ * will not be converted.
+ */
+SPHINXBASE_EXPORT
+int ngram_model_casefold(ngram_model_t *model, int kase);
+
+/**
* Apply a language weight, insertion penalty, and unigram weight to a
* language model.
*
Modified: branches/pocketsphinx-0.6/sphinxbase/include/sphinx_config.h.in
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/include/sphinx_config.h.in 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/include/sphinx_config.h.in 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,6 +1,4 @@
-/* sphinx_config.h: Externally visible configuration parameters for
- * SphinxBase.
- */
+/* sphinx_config.h: Externally visible configuration parameters */
/* Use ALSA library for sound I/O */
#undef AD_BACKEND_ALSA
Modified: branches/pocketsphinx-0.6/sphinxbase/sphinxbase.sln
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/sphinxbase.sln 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/sphinxbase.sln 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,6 +1,6 @@
-Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual Studio 2005
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sphinx_cepview", "win32\sphinx_cepview\sphinx_cepview.vcproj", "{06364F13-FBCE-4E2B-9289-0DD39E246205}"
ProjectSection(ProjectDependencies) = postProject
{2F025EAD-99BD-40F5-B2CC-F0A28CAD7F2D} = {2F025EAD-99BD-40F5-B2CC-F0A28CAD7F2D}
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/fe/fixlog.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/fe/fixlog.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/fe/fixlog.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -46,9 +46,8 @@
#endif
#include "prim_type.h"
+#include "fe_internal.h"
#include "fixpoint.h"
-#include "fe.h"
-#include "fe_internal.h"
/* Table of log2(x/64)*(1<<DEFAULT_RADIX) */
/* perl -e 'for (0..63) {my $x = 1 + $_/64; print "\t(uint32)(", log($x)/log(2), "*(1<<DEFAULT_RADIX)),\n"}' */
@@ -128,15 +127,16 @@
return MIN_FIXLOG2;
/* Get the exponent. */
-#ifdef __i386__
- asm("bsrl %1, %0\n": "=r"(y): "g"(x):"cc");
+
+#ifdef __i386__
+ __asm__("bsrl %1, %0\n": "=r"(y): "g"(x):"cc");
x <<= (31 - y);
#elif defined(__ppc__)
- asm("cntlzw %0, %1\n": "=r"(y):"r"(x));
+ __asm__("cntlzw %0, %1\n": "=r"(y):"r"(x));
x <<= y;
y = 31 - y;
#elif defined __ARM_ARCH_5__ || defined __ARM_ARCH_5T__ || defined __ARM_ARCH_5TE__
- asm("clz %0, %1\n": "=r"(y):"r"(x));
+ __asm__("clz %0, %1\n": "=r"(y):"r"(x));
x <<= y;
y = 31 - y;
#else
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/_jsgf_scanner.l
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/_jsgf_scanner.l 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/_jsgf_scanner.l 2010-02-28 20:55:10 UTC (rev 9757)
@@ -46,7 +46,7 @@
%option header-file="jsgf_scanner.h"
%s COMMENT
-ws [ \t\n]
+ws [ \t\r\n]
rulename \<[^<>]+\>
tag \{(\\.|[^\}]+)*\}
weight \/[0-9]*(\.[0-9]+)?\/
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,24 +1,23 @@
-/* A Bison parser, made by GNU Bison 2.3. */
+/* A Bison parser, made by GNU Bison 2.4.1. */
+
/* Skeleton implementation for Bison's Yacc-like parsers in C
-
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
+
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
@@ -29,7 +28,7 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
-
+
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
@@ -47,7 +46,7 @@
#define YYBISON 1
/* Bison version. */
-#define YYBISON_VERSION "2.3"
+#define YYBISON_VERSION "2.4.1"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
@@ -55,41 +54,20 @@
/* Pure parsers. */
#define YYPURE 1
+/* Push parsers. */
+#define YYPUSH 0
+
+/* Pull parsers. */
+#define YYPULL 1
+
/* Using locations. */
#define YYLSP_NEEDED 0
-/* Tokens. */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- HEADER = 258,
- GRAMMAR = 259,
- IMPORT = 260,
- PUBLIC = 261,
- TOKEN = 262,
- RULENAME = 263,
- TAG = 264,
- WEIGHT = 265
- };
-#endif
-/* Tokens. */
-#define HEADER 258
-#define GRAMMAR 259
-#define IMPORT 260
-#define PUBLIC 261
-#define TOKEN 262
-#define RULENAME 263
-#define TAG 264
-#define WEIGHT 265
+/* Copy the first part of user declarations. */
-
-
-
-/* Copy the first part of user declarations. */
+/* Line 189 of yacc.c */
#line 37 "jsgf_parser.y"
#include <stdio.h>
@@ -107,6 +85,9 @@
+/* Line 189 of yacc.c */
+#line 90 "jsgf_parser.c"
+
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -125,31 +106,65 @@
# define YYTOKEN_TABLE 0
#endif
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ HEADER = 258,
+ GRAMMAR = 259,
+ IMPORT = 260,
+ PUBLIC = 261,
+ TOKEN = 262,
+ RULENAME = 263,
+ TAG = 264,
+ WEIGHT = 265
+ };
+#endif
+/* Tokens. */
+#define HEADER 258
+#define GRAMMAR 259
+#define IMPORT 260
+#define PUBLIC 261
+#define TOKEN 262
+#define RULENAME 263
+#define TAG 264
+#define WEIGHT 265
+
+
+
+
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
+{
+
+/* Line 214 of yacc.c */
#line 58 "jsgf_parser.y"
-{
+
char *name;
float weight;
jsgf_rule_t *rule;
jsgf_rhs_t *rhs;
jsgf_atom_t *atom;
-}
-/* Line 187 of yacc.c. */
-#line 140 "jsgf_parser.c"
- YYSTYPE;
+
+
+
+/* Line 214 of yacc.c */
+#line 156 "jsgf_parser.c"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
#endif
-
/* Copy the second part of user declarations. */
-/* Line 216 of yacc.c. */
-#line 153 "jsgf_parser.c"
+/* Line 264 of yacc.c */
+#line 168 "jsgf_parser.c"
#ifdef short
# undef short
@@ -224,14 +239,14 @@
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static int
-YYID (int i)
+YYID (int yyi)
#else
static int
-YYID (i)
- int i;
+YYID (yyi)
+ int yyi;
#endif
{
- return i;
+ return yyi;
}
#endif
@@ -312,9 +327,9 @@
/* A type that is properly aligned for any stack member. */
union yyalloc
{
- yytype_int16 yyss;
- YYSTYPE yyvs;
- };
+ yytype_int16 yyss_alloc;
+ YYSTYPE yyvs_alloc;
+};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
@@ -348,12 +363,12 @@
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
-# define YYSTACK_RELOCATE(Stack) \
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYSIZE_T yynewbytes; \
- YYCOPY (&yyptr->Stack, Stack, yysize); \
- Stack = &yyptr->Stack; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / sizeof (*yyptr); \
} \
@@ -759,17 +774,20 @@
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
#else
static void
-yy_stack_print (bottom, top)
- yytype_int16 *bottom;
- yytype_int16 *top;
+yy_stack_print (yybottom, yytop)
+ yytype_int16 *yybottom;
+ yytype_int16 *yytop;
#endif
{
YYFPRINTF (stderr, "Stack now");
- for (; bottom <= top; ++bottom)
- YYFPRINTF (stderr, " %d", *bottom);
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
YYFPRINTF (stderr, "\n");
}
@@ -805,11 +823,11 @@
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
- fprintf (stderr, " $%d = ", yyi + 1);
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
, yyscanner, jsgf);
- fprintf (stderr, "\n");
+ YYFPRINTF (stderr, "\n");
}
}
@@ -1093,10 +1111,8 @@
break;
}
}
-
/* Prevent warnings from -Wmissing-prototypes. */
-
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
@@ -1115,11 +1131,10 @@
+/*-------------------------.
+| yyparse or yypush_parse. |
+`-------------------------*/
-/*----------.
-| yyparse. |
-`----------*/
-
#ifdef YYPARSE_PARAM
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
@@ -1143,22 +1158,46 @@
#endif
#endif
{
- /* The look-ahead symbol. */
+/* The lookahead symbol. */
int yychar;
-/* The semantic value of the look-ahead symbol. */
+/* The semantic value of the lookahead symbol. */
YYSTYPE yylval;
-/* Number of syntax errors so far. */
-int yynerrs;
+ /* Number of syntax errors so far. */
+ int yynerrs;
- int yystate;
+ int yystate;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+
+ /* The stacks and their tools:
+ `yyss': related to states.
+ `yyvs': related to semantic values.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs;
+ YYSTYPE *yyvsp;
+
+ YYSIZE_T yystacksize;
+
int yyn;
int yyresult;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
- /* Look-ahead token as an internal (translated) token number. */
- int yytoken = 0;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
#if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
@@ -1166,51 +1205,28 @@
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
- /* Three stacks and their tools:
- `yyss': related to states,
- `yyvs': related to semantic values,
- `yyls': related to locations.
-
- Refer to the stacks thru separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
-
- /* The state stack. */
- yytype_int16 yyssa[YYINITDEPTH];
- yytype_int16 *yyss = yyssa;
- yytype_int16 *yyssp;
-
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs = yyvsa;
- YYSTYPE *yyvsp;
-
-
-
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
- YYSIZE_T yystacksize = YYINITDEPTH;
-
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;
-
-
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
+ yytoken = 0;
+ yyss = yyssa;
+ yyvs = yyvsa;
+ yystacksize = YYINITDEPTH;
+
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
+ yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
so that they stay on the same level as the state stack.
The wasted elements are never initialized. */
-
yyssp = yyss;
yyvsp = yyvs;
@@ -1240,7 +1256,6 @@
YYSTYPE *yyvs1 = yyvs;
yytype_int16 *yyss1 = yyss;
-
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
@@ -1248,7 +1263,6 @@
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
-
&yystacksize);
yyss = yyss1;
@@ -1271,9 +1285,8 @@
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
if (! yyptr)
goto yyexhaustedlab;
- YYSTACK_RELOCATE (yyss);
- YYSTACK_RELOCATE (yyvs);
-
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
@@ -1284,7 +1297,6 @@
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
-
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
@@ -1294,6 +1306,9 @@
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
goto yybackup;
/*-----------.
@@ -1302,16 +1317,16 @@
yybackup:
/* Do appropriate processing given the current state. Read a
- look-ahead token if we need one and don't already have one. */
+ lookahead token if we need one and don't already have one. */
- /* First try to decide what to do without reference to look-ahead token. */
+ /* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yyn == YYPACT_NINF)
goto yydefault;
- /* Not known => get a look-ahead token if don't already have one. */
+ /* Not known => get a lookahead token if don't already have one. */
- /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
@@ -1343,20 +1358,16 @@
goto yyreduce;
}
- if (yyn == YYFINAL)
- YYACCEPT;
-
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
- /* Shift the look-ahead token. */
+ /* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
- /* Discard the shifted token unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;
yystate = yyn;
*++yyvsp = yylval;
@@ -1396,52 +1407,72 @@
switch (yyn)
{
case 5:
+
+/* Line 1455 of yacc.c */
#line 80 "jsgf_parser.y"
{ jsgf->name = (yyvsp[(2) - (2)].name); }
break;
case 7:
+
+/* Line 1455 of yacc.c */
#line 84 "jsgf_parser.y"
{ jsgf->version = (yyvsp[(2) - (3)].name); }
break;
case 8:
+
+/* Line 1455 of yacc.c */
#line 85 "jsgf_parser.y"
{ jsgf->version = (yyvsp[(2) - (4)].name); jsgf->charset = (yyvsp[(3) - (4)].name); }
break;
case 9:
+
+/* Line 1455 of yacc.c */
#line 86 "jsgf_parser.y"
{ jsgf->version = (yyvsp[(2) - (5)].name); jsgf->charset = (yyvsp[(3) - (5)].name);
jsgf->locale = (yyvsp[(4) - (5)].name); }
break;
case 10:
+
+/* Line 1455 of yacc.c */
#line 90 "jsgf_parser.y"
{ (yyval.name) = (yyvsp[(2) - (3)].name); }
break;
case 13:
+
+/* Line 1455 of yacc.c */
#line 97 "jsgf_parser.y"
{ jsgf_import_rule(jsgf, (yyvsp[(2) - (3)].name)); ckd_free((yyvsp[(2) - (3)].name)); }
break;
case 16:
+
+/* Line 1455 of yacc.c */
#line 104 "jsgf_parser.y"
{ jsgf_define_rule(jsgf, (yyvsp[(1) - (4)].name), (yyvsp[(3) - (4)].rhs), 0); ckd_free((yyvsp[(1) - (4)].name)); }
break;
case 17:
+
+/* Line 1455 of yacc.c */
#line 105 "jsgf_parser.y"
{ jsgf_define_rule(jsgf, (yyvsp[(2) - (5)].name), (yyvsp[(4) - (5)].rhs), 1); ckd_free((yyvsp[(2) - (5)].name)); }
break;
case 18:
+
+/* Line 1455 of yacc.c */
#line 108 "jsgf_parser.y"
{ (yyval.rhs) = (yyvsp[(1) - (1)].rhs); (yyval.rhs)->atoms = glist_reverse((yyval.rhs)->atoms); }
break;
case 19:
+
+/* Line 1455 of yacc.c */
#line 109 "jsgf_parser.y"
{ (yyval.rhs) = (yyvsp[(3) - (3)].rhs);
(yyval.rhs)->atoms = glist_reverse((yyval.rhs)->atoms);
@@ -1449,71 +1480,96 @@
break;
case 20:
+
+/* Line 1455 of yacc.c */
#line 114 "jsgf_parser.y"
{ (yyval.rhs) = ckd_calloc(1, sizeof(*(yyval.rhs)));
(yyval.rhs)->atoms = glist_add_ptr((yyval.rhs)->atoms, (yyvsp[(1) - (1)].atom)); }
break;
case 21:
+
+/* Line 1455 of yacc.c */
#line 116 "jsgf_parser.y"
{ (yyval.rhs) = (yyvsp[(1) - (2)].rhs);
(yyval.rhs)->atoms = glist_add_ptr((yyval.rhs)->atoms, (yyvsp[(2) - (2)].atom)); }
break;
case 23:
+
+/* Line 1455 of yacc.c */
#line 121 "jsgf_parser.y"
{ (yyval.atom) = (yyvsp[(1) - (2)].atom);
(yyval.atom)->tags = glist_add_ptr((yyval.atom)->tags, (yyvsp[(2) - (2)].name)); }
break;
case 25:
+
+/* Line 1455 of yacc.c */
#line 126 "jsgf_parser.y"
{ (yyval.atom) = (yyvsp[(2) - (2)].atom); (yyval.atom)->weight = (yyvsp[(1) - (2)].weight); }
break;
case 26:
+
+/* Line 1455 of yacc.c */
#line 129 "jsgf_parser.y"
{ (yyval.rule) = jsgf_define_rule(jsgf, NULL, (yyvsp[(2) - (3)].rhs), 0); }
break;
case 27:
+
+/* Line 1455 of yacc.c */
#line 132 "jsgf_parser.y"
{ (yyval.rule) = jsgf_optional_new(jsgf, (yyvsp[(2) - (3)].rhs)); }
break;
case 28:
+
+/* Line 1455 of yacc.c */
#line 135 "jsgf_parser.y"
{ (yyval.atom) = jsgf_atom_new((yyvsp[(1) - (1)].name), 1.0); ckd_free((yyvsp[(1) - (1)].name)); }
break;
case 29:
+
+/* Line 1455 of yacc.c */
#line 136 "jsgf_parser.y"
{ (yyval.atom) = jsgf_atom_new((yyvsp[(1) - (1)].name), 1.0); ckd_free((yyvsp[(1) - (1)].name)); }
break;
case 30:
+
+/* Line 1455 of yacc.c */
#line 137 "jsgf_parser.y"
{ (yyval.atom) = jsgf_atom_new((yyvsp[(1) - (1)].rule)->name, 1.0); }
break;
case 31:
+
+/* Line 1455 of yacc.c */
#line 138 "jsgf_parser.y"
{ (yyval.atom) = jsgf_atom_new((yyvsp[(1) - (1)].rule)->name, 1.0); }
break;
case 32:
+
+/* Line 1455 of yacc.c */
#line 139 "jsgf_parser.y"
{ (yyval.atom) = jsgf_kleene_new(jsgf, (yyvsp[(1) - (2)].atom), 0); }
break;
case 33:
+
+/* Line 1455 of yacc.c */
#line 140 "jsgf_parser.y"
{ (yyval.atom) = jsgf_kleene_new(jsgf, (yyvsp[(1) - (2)].atom), 1); }
break;
-/* Line 1267 of yacc.c. */
-#line 1517 "jsgf_parser.c"
+
+/* Line 1455 of yacc.c */
+#line 1573 "jsgf_parser.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1524,7 +1580,6 @@
*++yyvsp = yyval;
-
/* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
@@ -1589,7 +1644,7 @@
if (yyerrstatus == 3)
{
- /* If just tried and failed to reuse look-ahead token after an
+ /* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
@@ -1606,7 +1661,7 @@
}
}
- /* Else will try to reuse look-ahead token after shifting the error
+ /* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
@@ -1663,9 +1718,6 @@
YY_STACK_PRINT (yyss, yyssp);
}
- if (yyn == YYFINAL)
- YYACCEPT;
-
*++yyvsp = yylval;
@@ -1690,7 +1742,7 @@
yyresult = 1;
goto yyreturn;
-#ifndef yyoverflow
+#if !defined(yyoverflow) || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
@@ -1701,7 +1753,7 @@
#endif
yyreturn:
- if (yychar != YYEOF && yychar != YYEMPTY)
+ if (yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, yyscanner, jsgf);
/* Do not reclaim the symbols of the rule which action triggered
@@ -1727,6 +1779,8 @@
}
+
+/* Line 1675 of yacc.c */
#line 143 "jsgf_parser.y"
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_parser.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,24 +1,23 @@
-/* A Bison parser, made by GNU Bison 2.3. */
+/* A Bison parser, made by GNU Bison 2.4.1. */
+
/* Skeleton interface for Bison's Yacc-like parsers in C
-
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
+
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
@@ -29,10 +28,11 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
-
+
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
+
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
@@ -64,21 +64,27 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
+{
+
+/* Line 1676 of yacc.c */
#line 58 "jsgf_parser.y"
-{
+
char *name;
float weight;
jsgf_rule_t *rule;
jsgf_rhs_t *rhs;
jsgf_atom_t *atom;
-}
-/* Line 1489 of yacc.c. */
-#line 77 "jsgf_parser.h"
- YYSTYPE;
+
+
+
+/* Line 1676 of yacc.c */
+#line 82 "jsgf_parser.h"
+} YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
-# define YYSTYPE_IS_TRIVIAL 1
#endif
+
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -2,11 +2,6 @@
#line 4 "jsgf_scanner.c"
-/* Silvio Moioli: Windows CE string functions added. */
-#if defined(_WIN32_WCE)
- #include "string_wce.h"
-#endif
-
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
@@ -14,7 +9,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 34
+#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@@ -59,7 +54,6 @@
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
-#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@@ -90,6 +84,8 @@
#define UINT32_MAX (4294967295U)
#endif
+#endif /* ! C99 */
+
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@@ -163,7 +159,15 @@
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
@@ -197,13 +201,6 @@
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- * Given that the standard has decreed that size_t exists since 1989,
- * I guess we can afford to depend on it. Manoj.
- */
-
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
@@ -370,34 +367,34 @@
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[72] =
+static yyconst flex_int16_t yy_accept[73] =
{ 0,
- 0, 0, 0, 0, 17, 12, 1, 1, 12, 12,
- 15, 15, 15, 12, 12, 12, 15, 5, 1, 5,
- 12, 12, 0, 12, 12, 12, 3, 0, 14, 0,
- 0, 12, 12, 12, 0, 0, 11, 4, 13, 0,
- 12, 0, 12, 12, 12, 0, 0, 2, 14, 10,
- 12, 12, 12, 0, 0, 11, 13, 0, 12, 12,
- 12, 12, 6, 12, 12, 12, 12, 8, 9, 7,
- 0
+ 0, 0, 0, 0, 17, 12, 1, 1, 1, 12,
+ 12, 15, 15, 15, 12, 12, 12, 15, 5, 1,
+ 5, 12, 12, 0, 12, 12, 12, 3, 0, 14,
+ 0, 0, 12, 12, 12, 0, 0, 11, 4, 13,
+ 0, 12, 0, 12, 12, 12, 0, 0, 2, 14,
+ 10, 12, 12, 12, 0, 0, 11, 13, 0, 12,
+ 12, 12, 12, 6, 12, 12, 12, 12, 8, 9,
+ 7, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 4, 5, 1, 1, 1, 1, 6,
- 6, 7, 6, 1, 1, 8, 9, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 1, 6, 11,
- 6, 12, 1, 1, 1, 1, 1, 1, 1, 13,
- 14, 1, 1, 15, 1, 1, 1, 1, 1, 1,
- 1, 1, 16, 1, 1, 1, 1, 1, 1, 1,
- 6, 17, 6, 1, 1, 1, 18, 19, 20, 1,
+ 1, 2, 1, 5, 6, 1, 1, 1, 1, 7,
+ 7, 8, 7, 1, 1, 9, 10, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 1, 7, 12,
+ 7, 13, 1, 1, 1, 1, 1, 1, 1, 14,
+ 15, 1, 1, 16, 1, 1, 1, 1, 1, 1,
+ 1, 1, 17, 1, 1, 1, 1, 1, 1, 1,
+ 7, 18, 7, 1, 1, 1, 19, 20, 21, 1,
- 1, 1, 21, 1, 22, 1, 1, 23, 24, 1,
- 25, 26, 1, 27, 1, 28, 29, 1, 1, 1,
- 1, 1, 30, 6, 31, 1, 1, 1, 1, 1,
+ 1, 1, 22, 1, 23, 1, 1, 24, 25, 1,
+ 26, 27, 1, 28, 1, 29, 30, 1, 1, 1,
+ 1, 1, 31, 7, 32, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -414,94 +411,96 @@
1, 1, 1, 1, 1
} ;
-static yyconst flex_int32_t yy_meta[32] =
+static yyconst flex_int32_t yy_meta[33] =
{ 0,
- 1, 2, 2, 1, 1, 2, 2, 1, 2, 1,
- 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
- 2
+ 1, 2, 2, 1, 1, 1, 2, 2, 1, 2,
+ 1, 3, 3, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2
} ;
-static yyconst flex_int16_t yy_base[82] =
+static yyconst flex_int16_t yy_base[83] =
{ 0,
- 0, 0, 30, 32, 138, 0, 186, 186, 38, 121,
- 186, 44, 0, 106, 103, 97, 26, 186, 186, 115,
- 0, 68, 42, 0, 98, 107, 186, 112, 118, 52,
- 108, 101, 92, 97, 47, 64, 186, 186, 186, 79,
- 0, 59, 0, 128, 100, 56, 110, 186, 186, 186,
- 84, 69, 70, 56, 86, 75, 80, 108, 78, 66,
- 61, 64, 0, 40, 28, 28, 11, 0, 0, 0,
- 186, 159, 35, 162, 165, 167, 170, 173, 176, 179,
- 182
+ 0, 0, 31, 34, 133, 0, 193, 193, 0, 41,
+ 116, 193, 47, 0, 103, 105, 99, 29, 193, 193,
+ 118, 0, 72, 45, 0, 103, 110, 193, 115, 122,
+ 55, 111, 103, 93, 99, 44, 49, 193, 193, 193,
+ 65, 0, 73, 0, 134, 103, 30, 114, 193, 193,
+ 193, 89, 81, 74, 68, 91, 69, 84, 94, 82,
+ 70, 65, 69, 0, 69, 42, 48, 32, 0, 0,
+ 0, 193, 166, 44, 169, 172, 174, 177, 180, 183,
+ 186, 189
} ;
-static yyconst flex_int16_t yy_def[82] =
+static yyconst flex_int16_t yy_def[83] =
{ 0,
- 71, 1, 72, 72, 71, 73, 71, 71, 74, 73,
- 71, 71, 75, 73, 73, 73, 76, 71, 71, 71,
- 73, 74, 77, 73, 78, 73, 71, 71, 79, 71,
- 75, 73, 73, 73, 76, 80, 71, 71, 71, 81,
- 22, 77, 22, 78, 73, 71, 79, 71, 71, 71,
- 73, 73, 73, 76, 80, 76, 77, 81, 73, 73,
- 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
- 0, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71
+ 72, 1, 73, 73, 72, 74, 72, 72, 74, 75,
+ 74, 72, 72, 76, 74, 74, 74, 77, 72, 72,
+ 72, 74, 75, 78, 74, 79, 74, 72, 72, 80,
+ 72, 76, 74, 74, 74, 77, 81, 72, 72, 72,
+ 82, 23, 78, 23, 79, 74, 72, 80, 72, 72,
+ 72, 74, 74, 74, 77, 81, 77, 78, 82, 74,
+ 74, 74, 74, 74, 74, 74, 74, 74, 74, 74,
+ 74, 0, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72
} ;
-static yyconst flex_int16_t yy_nxt[218] =
+static yyconst flex_int16_t yy_nxt[226] =
{ 0,
- 6, 7, 8, 9, 10, 11, 11, 6, 12, 6,
- 13, 11, 6, 6, 6, 6, 6, 6, 6, 6,
- 14, 15, 6, 6, 6, 16, 6, 6, 6, 17,
- 11, 19, 8, 19, 8, 21, 20, 70, 20, 23,
- 23, 24, 36, 23, 23, 39, 23, 69, 23, 23,
- 27, 28, 29, 30, 25, 68, 37, 67, 40, 28,
- 49, 30, 39, 36, 49, 46, 35, 23, 23, 23,
- 23, 24, 36, 23, 23, 40, 23, 37, 23, 23,
- 55, 23, 57, 39, 25, 66, 37, 65, 35, 64,
- 63, 36, 62, 61, 56, 58, 40, 23, 23, 42,
+ 6, 7, 8, 9, 10, 11, 12, 12, 6, 13,
+ 6, 14, 12, 6, 6, 6, 6, 6, 6, 6,
+ 6, 15, 16, 6, 6, 6, 17, 6, 6, 6,
+ 18, 12, 20, 8, 20, 20, 8, 20, 21, 50,
+ 47, 21, 24, 24, 22, 25, 37, 24, 24, 40,
+ 24, 36, 24, 24, 28, 29, 30, 31, 26, 71,
+ 38, 37, 41, 29, 50, 31, 56, 24, 70, 58,
+ 69, 24, 24, 24, 24, 38, 25, 40, 24, 24,
+ 57, 24, 59, 24, 24, 37, 37, 68, 40, 26,
+ 41, 67, 66, 36, 65, 64, 24, 63, 58, 38,
- 23, 43, 55, 42, 42, 37, 42, 60, 42, 42,
- 23, 57, 48, 59, 44, 53, 56, 52, 51, 50,
- 48, 46, 45, 38, 58, 34, 33, 42, 42, 42,
- 23, 43, 32, 42, 42, 26, 42, 71, 42, 42,
- 71, 71, 71, 71, 44, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 42, 42, 18,
- 18, 18, 22, 22, 22, 31, 31, 35, 35, 35,
- 23, 23, 23, 41, 41, 41, 47, 47, 47, 54,
- 54, 54, 42, 42, 42, 5, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 38, 41, 24, 24, 43, 24, 62, 44, 56, 43,
+ 43, 59, 43, 61, 43, 43, 49, 60, 54, 53,
+ 45, 52, 57, 51, 49, 47, 46, 39, 35, 34,
+ 33, 27, 72, 43, 43, 43, 24, 72, 44, 72,
+ 43, 43, 72, 43, 72, 43, 43, 72, 72, 72,
+ 72, 45, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72, 72, 72, 43, 43, 19, 19, 19, 23,
+ 23, 23, 32, 32, 36, 36, 36, 24, 24, 24,
+ 42, 42, 42, 48, 48, 48, 55, 55, 55, 43,
+ 43, 43, 5, 72, 72, 72, 72, 72, 72, 72,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71
+ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72, 72, 72, 72
} ;
-static yyconst flex_int16_t yy_chk[218] =
+static yyconst flex_int16_t yy_chk[226] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 3, 3, 4, 4, 73, 3, 67, 4, 9,
- 9, 9, 17, 9, 9, 23, 9, 66, 9, 9,
- 12, 12, 12, 12, 9, 65, 17, 64, 23, 30,
- 30, 30, 42, 35, 46, 46, 36, 9, 9, 22,
- 22, 22, 54, 22, 22, 42, 22, 35, 22, 22,
- 36, 40, 40, 57, 22, 62, 54, 61, 55, 60,
- 59, 56, 53, 52, 36, 40, 57, 22, 22, 25,
+ 1, 1, 3, 3, 3, 4, 4, 4, 3, 47,
+ 47, 4, 10, 10, 74, 10, 18, 10, 10, 24,
+ 10, 37, 10, 10, 13, 13, 13, 13, 10, 68,
+ 18, 36, 24, 31, 31, 31, 37, 41, 67, 41,
+ 66, 10, 10, 23, 23, 36, 23, 43, 23, 23,
+ 37, 23, 41, 23, 23, 55, 57, 65, 58, 23,
+ 43, 63, 62, 56, 61, 60, 59, 54, 59, 55,
- 25, 25, 55, 25, 25, 56, 25, 51, 25, 25,
- 58, 58, 47, 45, 25, 34, 55, 33, 32, 31,
- 29, 28, 26, 20, 58, 16, 15, 25, 25, 44,
- 44, 44, 14, 44, 44, 10, 44, 5, 44, 44,
- 0, 0, 0, 0, 44, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 44, 44, 72,
- 72, 72, 74, 74, 74, 75, 75, 76, 76, 76,
- 77, 77, 77, 78, 78, 78, 79, 79, 79, 80,
- 80, 80, 81, 81, 81, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 57, 58, 23, 23, 26, 26, 53, 26, 56, 26,
+ 26, 59, 26, 52, 26, 26, 48, 46, 35, 34,
+ 26, 33, 56, 32, 30, 29, 27, 21, 17, 16,
+ 15, 11, 5, 26, 26, 45, 45, 0, 45, 0,
+ 45, 45, 0, 45, 0, 45, 45, 0, 0, 0,
+ 0, 45, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 45, 45, 73, 73, 73, 75,
+ 75, 75, 76, 76, 77, 77, 77, 78, 78, 78,
+ 79, 79, 79, 80, 80, 80, 81, 81, 81, 82,
+ 82, 82, 72, 72, 72, 72, 72, 72, 72, 72,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71
+ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
+ 72, 72, 72, 72, 72
} ;
/* The intent behind this definition is that it'll catch
@@ -555,7 +554,7 @@
#include "jsgf_parser.h"
-#line 554 "jsgf_scanner.c"
+#line 558 "jsgf_scanner.c"
#define INITIAL 0
#define COMMENT 1
@@ -685,7 +684,12 @@
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
@@ -693,7 +697,7 @@
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
-#define ECHO fwrite( yytext, yyleng, 1, yyout )
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@@ -704,7 +708,7 @@
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- int n; \
+ size_t n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -792,7 +796,7 @@
#line 56 "_jsgf_scanner.l"
-#line 791 "jsgf_scanner.c"
+#line 800 "jsgf_scanner.c"
yylval = yylval_param;
@@ -847,13 +851,13 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
+ if ( yy_current_state >= 73 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 186 );
+ while ( yy_base[yy_current_state] != 193 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@@ -962,7 +966,7 @@
#line 77 "_jsgf_scanner.l"
ECHO;
YY_BREAK
-#line 961 "jsgf_scanner.c"
+#line 970 "jsgf_scanner.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(COMMENT):
yyterminate();
@@ -1257,7 +1261,7 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
+ if ( yy_current_state >= 73 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1286,11 +1290,11 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
+ if ( yy_current_state >= 73 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 71);
+ yy_is_jam = (yy_current_state == 72);
return yy_is_jam ? 0 : yy_current_state;
}
@@ -1550,12 +1554,8 @@
b->yy_bs_column = 0;
}
- #if !defined(_WIN32_WCE)
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
- #else
- b->yy_is_interactive = 0;
- #endif
-
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
errno = oerrno;
}
@@ -1739,8 +1739,8 @@
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
* scan from a @e copy of @a bytes.
- * @param bytes the byte buffer to scan
- * @param len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/jsgf_scanner.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -13,7 +13,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 34
+#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@@ -58,7 +58,6 @@
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
-#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@@ -89,6 +88,8 @@
#define UINT32_MAX (4294967295U)
#endif
+#endif /* ! C99 */
+
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@@ -131,7 +132,15 @@
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
#endif
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
@@ -139,13 +148,6 @@
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
-/* The following is because we cannot portably get our hands on size_t
- * (without autoconf's help, which isn't available because we want
- * flex-generated scanners to compile on their own).
- * Given that the standard has decreed that size_t exists since 1989,
- * I guess we can afford to depend on it. Manoj.
- */
-
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
@@ -306,7 +308,12 @@
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
#endif
/* Number of entries by which start-condition stack grows. */
@@ -344,6 +351,6 @@
#line 77 "_jsgf_scanner.l"
-#line 348 "jsgf_scanner.h"
+#line 355 "jsgf_scanner.h"
#undef yyIN_HEADER
#endif /* yyHEADER_H */
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -292,7 +292,58 @@
return 0;
}
+int
+ngram_model_casefold(ngram_model_t *model, int kase)
+{
+ int writable, i;
+ hash_table_t *new_wid;
+ /* Were word strings already allocated? */
+ writable = model->writable;
+ /* Either way, we are going to allocate some word strings. */
+ model->writable = TRUE;
+
+ /* And, don't forget, we need to rebuild the word to unigram ID
+ * mapping. */
+ new_wid = hash_table_new(model->n_words, FALSE);
+ for (i = 0; i < model->n_words; ++i) {
+ char *outstr;
+ if (writable) {
+ outstr = model->word_str[i];
+ }
+ else {
+ outstr = ckd_salloc(model->word_str[i]);
+ }
+ /* Don't case-fold <tags> or [classes] */
+ if (outstr[0] == '<' || outstr[0] == '[') {
+ }
+ else {
+ switch (kase) {
+ case NGRAM_UPPER:
+ ucase(outstr);
+ break;
+ case NGRAM_LOWER:
+ lcase(outstr);
+ break;
+ default:
+ ;
+ }
+ }
+ model->word_str[i] = outstr;
+
+ /* Now update the hash table. We might have terrible
+ * collisions here, so warn about them. */
+ if (hash_table_enter_int32(new_wid, model->word_str[i], i) != i) {
+ E_WARN("Duplicate word in dictionary after conversion: %s\n",
+ model->word_str[i]);
+ }
+ }
+ /* Swap out the hash table. */
+ hash_table_free(model->wid);
+ model->wid = new_wid;
+ return 0;
+}
+
#ifdef HAVE_ICONV
int
ngram_model_recode(ngram_model_t *model, const char *from, const char *to)
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model_arpa.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model_arpa.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/lm/ngram_model_arpa.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -61,28 +61,25 @@
* Read and return #unigrams, #bigrams, #trigrams as stated in input file.
*/
static int
-ReadNgramCounts(FILE * fp, int32 * n_ug, int32 * n_bg, int32 * n_tg)
+ReadNgramCounts(lineiter_t **li, int32 * n_ug, int32 * n_bg, int32 * n_tg)
{
- char string[256];
int32 ngram, ngram_cnt;
/* skip file until past the '\data\' marker */
- do {
- if (fgets(string, sizeof(string), fp) == NULL) {
- E_ERROR_SYSTEM("Failed to read N-gram counts");
- return -1;
- }
+ while (*li) {
+ string_trim((*li)->buf, STRING_BOTH);
+ if (strcmp((*li)->buf, "\\data\\") == 0)
+ break;
+ *li = lineiter_next(*li);
}
- while ((strcmp(string, "\\data\\\n") != 0) && (!feof(fp)));
-
- if (strcmp(string, "\\data\\\n") != 0) {
+ if (*li == NULL || strcmp((*li)->buf, "\\data\\") != 0) {
E_ERROR("No \\data\\ mark in LM file\n");
return -1;
}
*n_ug = *n_bg = *n_tg = 0;
- while (fgets(string, sizeof(string), fp) != NULL) {
- if (sscanf(string, "ngram %d=%d", &ngram, &ngram_cnt) != 2)
+ while ((*li = lineiter_next(*li))) {
+ if (sscanf((*li)->buf, "ngram %d=%d", &ngram, &ngram_cnt) != 2)
break;
switch (ngram) {
case 1:
@@ -99,14 +96,21 @@
return -1;
}
}
+ if (*li == NULL) {
+ E_ERROR("EOF while reading ngram counts\n");
+ return -1;
+ }
- /* Position file to just after the unigrams header '\1-grams:\' */
- while ((strcmp(string, "\\1-grams:\n") != 0) && (!feof(fp))) {
- if (fgets(string, sizeof(string), fp) == NULL) {
- E_ERROR_SYSTEM("Failed to read \\1-grams: mark");
- return -1;
- }
+ /* Position iterator to the unigrams header '\1-grams:\' */
+ while ((*li = lineiter_next(*li))) {
+ string_trim((*li)->buf, STRING_BOTH);
+ if (strcmp((*li)->buf, "\\1-grams:") == 0)
+ break;
}
+ if (*li == NULL) {
+ E_ERROR_SYSTEM("Failed to read \\1-grams: mark");
+ return -1;
+ }
/* Check counts; NOTE: #trigrams *CAN* be 0 */
if ((*n_ug <= 0) || (*n_bg <= 0) || (*n_tg < 0)) {
@@ -117,30 +121,32 @@
}
/*
- * Read in the unigrams from given file into the LM structure model. On
- * entry to this procedure, the file pointer is positioned just after the
+ * Read in the unigrams from given file into the LM structure model.
+ * On entry to this procedure, the iterator is positioned to the
* header line '\1-grams:'.
*/
static int
-ReadUnigrams(FILE * fp, ngram_model_arpa_t * model)
+ReadUnigrams(lineiter_t **li, ngram_model_arpa_t * model)
{
ngram_model_t *base = &model->base;
- char string[256];
int32 wcnt;
float p1;
E_INFO("Reading unigrams\n");
wcnt = 0;
- while ((fgets(string, sizeof(string), fp) != NULL) &&
- (strcmp(string, "\\2-grams:\n") != 0)) {
+ while ((*li = lineiter_next(*li))) {
char *wptr[3], *name;
float32 bo_wt = 0.0f;
int n;
- if ((n = str2words(string, wptr, 3)) < 2) {
- if (string[0] != '\n')
- E_WARN("Format error; unigram ignored: %s\n", string);
+ string_trim((*li)->buf, STRING_BOTH);
+ if (strcmp((*li)->buf, "\\2-grams:") == 0)
+ break;
+
+ if ((n = str2words((*li)->buf, wptr, 3)) < 2) {
+ if ((*li)->buf[0] != '\0')
+ E_WARN("Format error; unigram ignored: %s\n", (*li)->buf);
continue;
}
else {
@@ -179,10 +185,9 @@
* Read bigrams from given file into given model structure.
*/
static int
-ReadBigrams(FILE * fp, ngram_model_arpa_t * model)
+ReadBigrams(lineiter_t **li, ngram_model_arpa_t * model)
{
ngram_model_t *base = &model->base;
- char string[1024];
int32 w1, w2, prev_w1, bgcount;
bigram_t *bgptr;
@@ -192,15 +197,16 @@
bgptr = model->lm3g.bigrams;
prev_w1 = -1;
- while (fgets(string, sizeof(string), fp) != NULL) {
+ while ((*li = lineiter_next(*li))) {
float32 p, bo_wt = 0.0f;
int32 p2, bo_wt2;
char *wptr[4], *word1, *word2;
int n;
+ string_trim((*li)->buf, STRING_BOTH);
wptr[3] = NULL;
- if ((n = str2words(string, wptr, 4)) < 3) {
- if (string[0] != '\n')
+ if ((n = str2words((*li)->buf, wptr, 4)) < 3) {
+ if ((*li)->buf[0] != '\0')
break;
continue;
}
@@ -258,9 +264,9 @@
E_INFOCONT(".");
}
}
- if ((strcmp(string, "\\end\\") != 0)
- && (strcmp(string, "\\3-grams:") != 0)) {
- E_ERROR("Bad bigram: %s\n", string);
+ if (*li == NULL || ((strcmp((*li)->buf, "\\end\\") != 0)
+ && (strcmp((*li)->buf, "\\3-grams:") != 0))) {
+ E_ERROR("Bad bigram: %s\n", (*li)->buf);
return -1;
}
@@ -274,10 +280,9 @@
* Very similar to ReadBigrams.
*/
static int
-ReadTrigrams(FILE * fp, ngram_model_arpa_t * model)
+ReadTrigrams(lineiter_t **li, ngram_model_arpa_t * model)
{
ngram_model_t *base = &model->base;
- char string[1024];
int32 i, w1, w2, w3, prev_w1, prev_w2, tgcount, prev_bg, bg, endbg;
int32 seg, prev_seg, prev_seg_lastbg;
trigram_t *tgptr;
@@ -292,13 +297,14 @@
prev_bg = -1;
prev_seg = -1;
- while (fgets(string, sizeof(string), fp) != NULL) {
+ while ((*li = lineiter_next(*li))) {
float32 p;
int32 p3;
char *wptr[4], *word1, *word2, *word3;
- if (str2words(string, wptr, 4) != 4) {
- if (string[0] != '\n')
+ string_trim((*li)->buf, STRING_BOTH);
+ if (str2words((*li)->buf, wptr, 4) != 4) {
+ if ((*li)->buf[0] != '\0')
break;
continue;
}
@@ -351,7 +357,7 @@
bgptr = model->lm3g.bigrams + bg;
for (; (bg < endbg) && (bgptr->wid != w2); bg++, bgptr++);
if (bg >= endbg) {
- E_ERROR("Missing bigram for trigram: %s", string);
+ E_ERROR("Missing bigram for trigram: %s", (*li)->buf);
return -1;
}
@@ -408,8 +414,8 @@
E_INFOCONT(".");
}
}
- if (strcmp(string, "\\end\\") != 0) {
- E_ERROR("Bad trigram: %s\n", string);
+ if (*li == NULL || strcmp((*li)->buf, "\\end\\") != 0) {
+ E_ERROR("Bad trigram: %s\n", (*li)->buf);
return -1;
}
@@ -445,6 +451,7 @@
const char *file_name,
logmath_t *lmath)
{
+ lineiter_t *li;
FILE *fp;
int32 is_pipe;
int32 n_unigram;
@@ -458,9 +465,11 @@
E_ERROR("File %s not found\n", file_name);
return NULL;
}
+ li = lineiter_start(fp);
/* Read #unigrams, #bigrams, #trigrams from file */
- if (ReadNgramCounts(fp, &n_unigram, &n_bigram, &n_trigram) == -1) {
+ if (ReadNgramCounts(&li, &n_unigram, &n_bigram, &n_trigram) == -1) {
+ lineiter_free(li);
fclose_comp(fp, is_pipe);
return NULL;
}
@@ -498,7 +507,7 @@
ckd_calloc((n_bigram + 1) / BG_SEG_SZ + 1,
sizeof(int32));
}
- if (ReadUnigrams(fp, model) == -1) {
+ if (ReadUnigrams(&li, model) == -1) {
fclose_comp(fp, is_pipe);
ngram_model_free(base);
return NULL;
@@ -509,7 +518,7 @@
if (base->n_counts[2] > 0)
init_sorted_list(&model->sorted_bo_wt2);
- if (ReadBigrams(fp, model) == -1) {
+ if (ReadBigrams(&li, model) == -1) {
fclose_comp(fp, is_pipe);
ngram_model_free(base);
return NULL;
@@ -531,7 +540,7 @@
init_sorted_list(&model->sorted_prob3);
- if (ReadTrigrams(fp, model) == -1) {
+ if (ReadTrigrams(&li, model) == -1) {
fclose_comp(fp, is_pipe);
ngram_model_free(base);
return NULL;
@@ -550,6 +559,7 @@
model->lm3g.le = listelem_alloc_init(sizeof(tginfo_t));
}
+ lineiter_free(li);
fclose_comp(fp, is_pipe);
return base;
}
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/err.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/err.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/err.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -106,7 +106,7 @@
pthread_setspecific(logfp_index, (void *)fh);
}
-#elif defined(WIN32)
+#elif defined(_WIN32) || defined(__CYGWIN__) /* Use Windows TLS on Cygwin */
#include <windows.h>
static DWORD logfp_index; /** TLS index for log file */
static LONG logfp_index_once = 0; /** True if we have initialized TLS */
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/filename.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/filename.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/filename.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -77,7 +77,7 @@
int32 i, l;
l = strlen(path);
-#ifdef WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
for (i = l - 1; (i >= 0) && !(path[i] == '/' || path[i] == '\\'); --i);
#else
for (i = l - 1; (i >= 0) && !(path[i] == '/'); --i);
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/pio.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/pio.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/pio.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -169,7 +169,7 @@
{
if (ispipe) {
#ifdef HAVE_POPEN
-#if defined(WIN32)
+#if defined(_WIN32)
_pclose(fp);
#else
pclose(fp);
@@ -295,6 +295,8 @@
void
lineiter_free(lineiter_t *li)
{
+ if (li == NULL)
+ return;
ckd_free(li->buf);
ckd_free(li);
}
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/profile.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/profile.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/profile.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -147,7 +147,7 @@
}
-#if (WIN32) && !defined(GNUWINCE)
+#if defined(_WIN32) && !defined(GNUWINCE)
#define TM_LOWSCALE 1e-7
#define TM_HIGHSCALE (4294967296.0 * TM_LOWSCALE);
@@ -177,7 +177,7 @@
void
ptmr_start(ptmr_t * tm)
{
-#if (! WIN32) || defined(GNUWINCE)
+#if (! defined(_WIN32)) || defined(GNUWINCE)
struct timeval e_start; /* Elapsed time */
#if (! _HPUX_SOURCE)
@@ -213,7 +213,7 @@
{
float64 dt_cpu, dt_elapsed;
-#if (! WIN32) || defined(GNUWINCE)
+#if (! defined(_WIN32)) || defined(GNUWINCE)
struct timeval e_stop; /* Elapsed time */
#if (! _HPUX_SOURCE)
Modified: branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/sbthread.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/sbthread.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/libsphinxbase/util/sbthread.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -50,7 +50,7 @@
/*
* Platform-specific parts: threads, mutexes, and signals.
*/
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__) /* Use Windows threads on Cygwin too */
#define _WIN32_WINNT 0x0400
#include <windows.h>
Property changes on: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_adtools
___________________________________________________________________
Modified: svn:ignore
- .deps
.libs
Makefile.in
Makefile
sphinx_cont_adseg
sphinx_cont_fileseg
sphinx_pitch
+ .deps
.libs
Makefile.in
Makefile
sphinx_cont_adseg
sphinx_cont_fileseg
sphinx_pitch
*.exe
Modified: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/Makefile.am
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/Makefile.am 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/Makefile.am 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,9 +1,9 @@
bin_PROGRAMS = sphinx_fe
-sphinx_fe_SOURCES = wave2feat.c
+sphinx_fe_SOURCES = sphinx_fe.c
noinst_HEADERS = cmd_ln_defn.h \
- wave2feat.h
+ sphinx_wave2feat.h
sphinx_fe_LDADD = \
$(top_builddir)/src/libsphinxbase/libsphinxbase.la
Modified: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/cmd_ln_defn.h
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/cmd_ln_defn.h 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/cmd_ln_defn.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -49,7 +49,6 @@
#include "cmd_ln.h"
#include "fe.h"
-#include "wave2feat.h"
const char helpstr[] =
"Description: \n\
@@ -71,7 +70,6 @@
\n\
sphinx_fe -i input.raw \n\
-o output.mfc \n\
- -raw yes \n\
-input_endian little \n\
-samprate 16000 \n\
-lowerf 130 \n\
@@ -170,7 +168,7 @@
{ "-feat",
ARG_STRING,
"sphinx",
- "SPHINX format - big endian" },
+ "Format of output files - currently only 'sphinx' is supported, 'htk' might work soon too." },
{ "-mach_endian",
ARG_STRING,
@@ -183,9 +181,19 @@
{ "-blocksize",
ARG_INT32,
- "200000",
- "Block size, used to limit the number of samples used at a time when reading very large audio files" },
-
+ "2048",
+ "Number of samples to read at a time." },
+
+ { "-spec2cep",
+ ARG_BOOLEAN,
+ "no",
+ "Input is log spectral files, output is cepstral files" },
+
+ { "-cep2spec",
+ ARG_BOOLEAN,
+ "no",
+ "Input is cepstral files, output is log spectral files" },
+
{ NULL, 0, NULL, NULL }
};
Copied: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_fe.c (from rev 9756, trunk/sphinxbase/src/sphinx_fe/sphinx_fe.c)
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_fe.c (rev 0)
+++ branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_fe.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -0,0 +1,663 @@
+/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* ====================================================================
+ * Copyright (c) 1996-2004 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.
+ *
+ * ====================================================================
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <assert.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "fe.h"
+#include "strfuncs.h"
+#include "pio.h"
+#include "cmd_ln.h"
+#include "err.h"
+#include "ckd_alloc.h"
+#include "byteorder.h"
+
+#include "sphinx_wave2feat.h"
+#include "cmd_ln_defn.h"
+
+struct sphinx_wave2feat_s {
+ int refcount; /**< Reference count. */
+ cmd_ln_t *config; /**< Configuration parameters. */
+ fe_t *fe; /**< Front end object. */
+ char *infile; /**< Path to input file. */
+ char *outfile; /**< Path to output file. */
+ FILE *infh; /**< Input file handle. */
+ FILE *outfh; /**< Output file handle. */
+ short *audio; /**< Audio buffer. */
+ mfcc_t **feat; /**< Feature buffer. */
+ int blocksize; /**< Size of audio buffer. */
+ int featsize; /**< Size of feature buffer. */
+ int veclen; /**< Length of each output vector. */
+ int in_veclen; /**< Length of each input vector (for cep<->spec). */
+ int byteswap; /**< Whether byteswapping is necessary. */
+};
+
+/** RIFF 44-byte header structure for MS wav files */
+typedef struct RIFFHeader{
+ char rifftag[4]; /* "RIFF" string */
+ int32 TotalLength; /* Total length */
+ char wavefmttag[8]; /* "WAVEfmt " string (note space after 't') */
+ int32 RemainingLength; /* Remaining length */
+ int16 data_format; /* data format tag, 1 = PCM */
+ int16 numchannels; /* Number of channels in file */
+ int32 SamplingFreq; /* Sampling frequency */
+ int32 BytesPerSec; /* Average bytes/sec */
+ int16 BlockAlign; /* Block align */
+ int16 BitsPerSample; /* 8 or 16 bit */
+ char datatag[4]; /* "data" string */
+ int32 datalength; /* Raw data length */
+} MSWAV_hdr;
+
+/**
+ * Output frames from sphinx_wave2feat_t, in whatever format, etc, is configured.
+ *
+ * @return 0 for success, <0 for error.
+ */
+static int
+output_frames(sphinx_wave2feat_t *wtf, mfcc_t **frames, int nfr)
+{
+ int i, nfloat = 0;
+
+ fe_mfcc_to_float(wtf->fe, frames, (float32 **)frames, nfr);
+ for (i = 0; i < nfr; ++i) {
+ if (fwrite(frames[i], sizeof(float32), wtf->veclen, wtf->outfh) != wtf->veclen) {
+ E_ERROR_SYSTEM("Writing %d values to %s failed",
+ wtf->veclen, wtf->outfile);
+ return -1;
+ }
+ nfloat += wtf->veclen;
+ }
+ return nfloat;
+}
+
+/**
+ * Detect RIFF file and parse its header if detected.
+ *
+ * @return TRUE if it's a RIFF file, FALSE if not, -1 if an error occurred.
+ */
+static int
+detect_riff(sphinx_wave2feat_t *wtf, char const *infile)
+{
+ FILE *fh;
+ MSWAV_hdr hdr;
+
+ if ((fh = fopen(infile, "rb")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open %s", infile);
+ return -1;
+ }
+ if (fread(&hdr, sizeof(hdr), 1, fh) != 1) {
+ E_ERROR_SYSTEM("Failed to read RIFF header");
+ fclose(fh);
+ return -1;
+ }
+ /* Make sure it is actually a RIFF file. */
+ if (0 != memcmp(hdr.rifftag, "RIFF", 4))
+ return FALSE;
+
+ /* Get relevant information. */
+ cmd_ln_set_int32_r(wtf->config, "-nchans", hdr.numchannels);
+ cmd_ln_set_float32_r(wtf->config, "-samprate", hdr.SamplingFreq);
+ wtf->infile = ckd_salloc(infile);
+ wtf->infh = fh;
+
+ return TRUE;
+}
+
+/**
+ * Detect NIST file and parse its header if detected.
+ *
+ * @return TRUE if it's a NIST file, FALSE if not, -1 if an error occurred.
+ */
+static int
+detect_nist(sphinx_wave2feat_t *wtf, char const *infile)
+{
+ char nist[7];
+ lineiter_t *li;
+ FILE *fh;
+
+ if ((fh = fopen(infile, "rb")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open %s", infile);
+ return -1;
+ }
+ if (fread(&nist, 1, 7, fh) != 7) {
+ E_ERROR_SYSTEM("Failed to read NIST header");
+ fclose(fh);
+ return -1;
+ }
+ /* Is this actually a NIST file? */
+ if (0 != strncmp(nist, "NIST_1A", 7)) {
+ fclose(fh);
+ return FALSE;
+ }
+ /* Rewind, parse lines. */
+ fseek(fh, 0, SEEK_SET);
+ for (li = lineiter_start(fh); li; li = lineiter_next(li)) {
+ char **words;
+ int nword;
+
+ string_trim(li->buf, STRING_BOTH);
+ if (strlen(li->buf) == 0)
+ break;
+ nword = str2words(li->buf, NULL, 0);
+ if (nword != 3)
+ continue;
+ words = ckd_calloc(nword, sizeof(*words));
+ str2words(li->buf, words, nword);
+ if (0 == strcmp(words[0], "sample_rate")) {
+ cmd_ln_set_float32_r(wtf->config, "-samprate", atof_c(words[2]));
+ }
+ if (0 == strcmp(words[0], "channel_count")) {
+ cmd_ln_set_float32_r(wtf->config, "-nchans", atoi(words[2]));
+ }
+ if (0 == strcmp(words[0], "sample_byte_format")) {
+ cmd_ln_set_str_r(wtf->config, "-input_endian",
+ (0 == strcmp(words[2], "10")) ? "big" : "little");
+ }
+ /* FIMXE: Warn about shorten-compressed data. */
+ ckd_free(words);
+ }
+ fseek(fh, 1024, SEEK_SET);
+ wtf->infile = ckd_salloc(infile);
+ wtf->infh = fh;
+ return TRUE;
+}
+
+
+/**
+ * Default "detection" function, just opens the file and keeps the
+ * default configuration parameters.
+ *
+ * @return TRUE, or -1 on error.
+ */
+static int
+detect_raw(sphinx_wave2feat_t *wtf, char const *infile)
+{
+ FILE *fh;
+
+ if ((fh = fopen(infile, "rb")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open %s", infile);
+ return -1;
+ }
+ wtf->infile = ckd_salloc(infile);
+ wtf->infh = fh;
+ return TRUE;
+}
+
+/**
+ * "Detect" Sphinx MFCC files, meaning verify their lousy headers, and
+ * set up some parameters from the config object.
+ *
+ * @return TRUE, or -1 on error.
+ */
+static int
+detect_sphinx_mfc(sphinx_wave2feat_t *wtf, char const *infile)
+{
+ FILE *fh;
+ int32 len;
+ long flen;
+
+ if ((fh = fopen(infile, "rb")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open %s", infile);
+ return -1;
+ }
+ if (fread(&len, 4, 1, fh) != 1) {
+ E_ERROR_SYSTEM("Failed to read header from %s\n", infile);
+ return -1;
+ }
+ fseek(fh, 0, SEEK_END);
+ flen = ftell(fh);
+
+ /* figure out whether to byteswap */
+ flen = (flen / 4) - 1;
+ if (flen != len) {
+ /* First make sure this is an endianness problem, otherwise fail. */
+ SWAP_INT32(&len);
+ if (flen != len) {
+ SWAP_INT32(&len);
+ E_ERROR("Mismatch in header/file lengths: 0x%08x vs 0x%08x\n",
+ len, flen);
+ return -1;
+ }
+ /* Set the input endianness to the opposite of the machine endianness... */
+ cmd_ln_set_str_r(wtf->config, "-input_endian",
+ (0 == strcmp("big", cmd_ln_str_r(wtf->config, "-mach_endian"))
+ ? "little" : "big"));
+ }
+
+ fseek(fh, 4, SEEK_SET);
+ wtf->infile = ckd_salloc(infile);
+ wtf->infh = fh;
+ if (cmd_ln_boolean_r(wtf->config, "-spec2cep")) {
+ wtf->in_veclen = cmd_ln_int32_r(wtf->config, "-nfilt");
+ }
+ else if (cmd_ln_boolean_r(wtf->config, "-cep2spec")) {
+ wtf->in_veclen = cmd_ln_int32_r(wtf->config, "-ncep");
+ wtf->veclen = cmd_ln_int32_r(wtf->config, "-nfilt");
+ }
+ else {
+ /* Should not happen. */
+ E_ERROR("Sphinx MFCC file reading requested but -spec2cep/-cep2spec not given\n");
+ assert(FALSE);
+ }
+
+ return TRUE;
+}
+
+/**
+ * Process PCM audio from a filehandle. Assume that wtf->infh is
+ * positioned just after the file header.
+ */
+static int
+decode_pcm(sphinx_wave2feat_t *wtf)
+{
+ size_t nsamp;
+ int32 nfr;
+ int nfloat, n;
+
+ fe_start_utt(wtf->fe);
+ nsamp = wtf->blocksize;
+ nfloat = 0;
+ while ((nsamp = fread(wtf->audio, 2, nsamp, wtf->infh)) != 0) {
+ size_t nvec;
+ int16 const *inspeech;
+
+
+ /* Byteswap stuff here if necessary. */
+ if (wtf->byteswap) {
+ for (n = 0; n < nsamp; ++n)
+ SWAP_INT16(wtf->audio + n);
+ }
+
+ inspeech = wtf->audio;
+ nvec = wtf->featsize;
+
+ /* Consume all samples. */
+ while (nsamp) {
+ nfr = nvec;
+ fe_process_frames(wtf->fe, &inspeech, &nsamp, wtf->feat, &nfr);
+ if (nfr) {
+ if ((n = output_frames(wtf, wtf->feat, nfr)) < 0)
+ return -1;
+ nfloat += n;
+ }
+ }
+ inspeech = wtf->audio;
+ }
+ /* Now process any leftover audio frames. */
+ fe_end_utt(wtf->fe, wtf->feat[0], &nfr);
+ if (nfr) {
+ if ((n = output_frames(wtf, wtf->feat, nfr)) < 0)
+ return -1;
+ nfloat += n;
+ }
+
+ fclose(wtf->infh);
+ wtf->infh = NULL;
+ return nfloat;
+}
+
+/**
+ * Process Sphinx MFCCs/logspectra from a filehandle. Assume that
+ * wtf->infh is positioned just after the file header.
+ */
+static int
+decode_sphinx_mfc(sphinx_wave2feat_t *wtf)
+{
+ int nfloat = 0, n;
+ int featsize = wtf->featsize;
+
+ /* If the input vector length is less than the output length, we
+ * need to do this one frame at a time, because there's empty
+ * space at the end of each vector in wtf->feat. */
+ if (wtf->in_veclen < wtf->veclen)
+ featsize = 1;
+ while ((n = fread(wtf->feat[0], sizeof(**wtf->feat),
+ featsize * wtf->in_veclen, wtf->infh)) != 0) {
+ int i, nfr = n / wtf->in_veclen;
+ if (n % wtf->in_veclen) {
+ E_ERROR("Size of file %d not a multiple of veclen %d\n",
+ n, wtf->in_veclen);
+ return -1;
+ }
+ /* Byteswap stuff here if necessary. */
+ if (wtf->byteswap) {
+ for (i = 0; i < n; ++i)
+ SWAP_FLOAT32(wtf->feat[0] + i);
+ }
+ fe_float_to_mfcc(wtf->fe, (float32 **)wtf->feat, wtf->feat, nfr);
+ for (i = 0; i < nfr; ++i) {
+ if (cmd_ln_boolean_r(wtf->config, "-spec2cep")) {
+ if (0 == strcmp(cmd_ln_str_r(wtf->config, "-transform"), "legacy"))
+ fe_logspec_to_mfcc(wtf->fe, wtf->feat[i], wtf->feat[i]);
+ else
+ fe_logspec_dct2(wtf->fe, wtf->feat[i], wtf->feat[i]);
+ }
+ else if (cmd_ln_boolean_r(wtf->config, "-cep2spec")) {
+ fe_mfcc_dct3(wtf->fe, wtf->feat[i], wtf->feat[i]);
+ }
+ }
+ if ((n = output_frames(wtf, wtf->feat, nfr)) < 0)
+ return -1;
+ nfloat += n;
+ }
+
+ fclose(wtf->infh);
+ wtf->infh = NULL;
+ return nfloat;
+}
+
+sphinx_wave2feat_t *
+sphinx_wave2feat_init(cmd_ln_t *config)
+{
+ sphinx_wave2feat_t *wtf;
+
+ wtf = ckd_calloc(1, sizeof(*wtf));
+ wtf->refcount = 1;
+ wtf->config = cmd_ln_retain(config);
+ wtf->fe = fe_init_auto_r(wtf->config);
+
+ return wtf;
+}
+
+int
+sphinx_wave2feat_free(sphinx_wave2feat_t *wtf)
+{
+ if (wtf == NULL)
+ return 0;
+ if (--wtf->refcount > 0)
+ return wtf->refcount;
+
+ ckd_free(wtf->audio);
+ ckd_free_2d(wtf->feat);
+ ckd_free(wtf->infile);
+ ckd_free(wtf->outfile);
+ if (wtf->infh)
+ fclose(wtf->infh);
+ if (wtf->outfh)
+ fclose(wtf->outfh);
+ cmd_ln_free_r(wtf->config);
+ fe_free(wtf->fe);
+ ckd_free(wtf);
+
+ return 0;
+}
+
+sphinx_wave2feat_t *
+sphinx_wave2feat_retain(sphinx_wave2feat_t *wtf)
+{
+ ++wtf->refcount;
+ return wtf;
+}
+
+typedef struct audio_type_s {
+ char const *name;
+ int (*detect)(sphinx_wave2feat_t *wtf, char const *infile);
+ int (*decode)(sphinx_wave2feat_t *wtf);
+} audio_type_t;
+
+static const audio_type_t types[] = {
+ { "-mswav", &detect_riff, &decode_pcm },
+ { "-nist", &detect_nist, &decode_pcm },
+#ifdef HAVE_SNDFILE
+ { "-sndfile", &detect_sndfile, &decode_sndfile },
+#endif
+ { "-raw", &detect_raw, &decode_pcm },
+};
+static const int ntypes = sizeof(types)/sizeof(types[0]);
+static const audio_type_t mfcc_type = {
+ "sphinx_mfc", &detect_sphinx_mfc, &decode_sphinx_mfc
+};
+
+static audio_type_t const *
+detect_audio_type(sphinx_wave2feat_t *wtf, char const *infile)
+{
+ audio_type_t const *atype;
+ int i;
+
+ /* Special case audio type for Sphinx MFCC inputs. */
+ if (cmd_ln_boolean_r(wtf->config, "-spec2cep")
+ || cmd_ln_boolean_r(wtf->config, "-cep2spec")) {
+ int rv = mfcc_type.detect(wtf, infile);
+ if (rv == -1)
+ return NULL;
+ return &mfcc_type;
+ }
+
+ /* Try to use the type of infile given on the command line. */
+ for (i = 0; i < ntypes; ++i) {
+ int rv;
+ atype = &types[i];
+ if (cmd_ln_boolean_r(wtf->config, atype->name)) {
+ rv = (*atype->detect)(wtf, infile);
+ if (rv == -1)
+ return NULL;
+ break;
+ }
+ }
+ if (i == ntypes) {
+ /* Detect file type of infile and get parameters. */
+ for (i = 0; i < ntypes; ++i) {
+ int rv;
+ atype = &types[i];
+ rv = (*atype->detect)(wtf, infile);
+ if (rv == -1)
+ return NULL;
+ else if (rv == TRUE)
+ break;
+ }
+ if (i == ntypes)
+ atype = NULL;
+ }
+ return atype;
+}
+
+int
+sphinx_wave2feat_convert_file(sphinx_wave2feat_t *wtf,
+ char const *infile, char const *outfile)
+{
+ int minfft, nfft, nfloat, veclen;
+ int32 zero = 0;
+ audio_type_t const *atype;
+ int fshift, fsize;
+
+ if (cmd_ln_boolean_r(wtf->config, "-verbose"))
+ E_INFO("Converting %s to %s\n", infile, outfile);
+
+ /* Detect input file type. */
+ if ((atype = detect_audio_type(wtf, infile)) == NULL)
+ return -1;
+
+ /* Determine whether to byteswap input (we never byteswap output
+ * anymore) */
+ wtf->byteswap = strcmp(cmd_ln_str_r(wtf->config, "-mach_endian"),
+ cmd_ln_str_r(wtf->config, "-input_endian"));
+
+ /* Make sure the FFT size is sufficiently large. */
+ minfft = (int)(cmd_ln_float32_r(wtf->config, "-samprate")
+ * cmd_ln_float32_r(wtf->config, "-wlen") + 0.5);
+ for (nfft = 1; nfft < minfft; nfft <<= 1)
+ ;
+ if (nfft > cmd_ln_int32_r(wtf->config, "-nfft")) {
+ E_WARN("Value of -nfft = %d is too small, increasing to %d\n",
+ cmd_ln_int32_r(wtf->config, "-nfft"), nfft);
+ cmd_ln_set_int32_r(wtf->config, "-nfft", nfft);
+ fe_free(wtf->fe);
+ wtf->fe = fe_init_auto_r(wtf->config);
+ }
+
+ /* Get the output frame size (if not already set). */
+ if (wtf->veclen == 0)
+ wtf->veclen = fe_get_output_size(wtf->fe);
+
+ /* Set up the input and output buffers. */
+ fe_get_input_size(wtf->fe, &fshift, &fsize);
+ /* Want to get at least a whole frame plus shift in here. */
+ wtf->blocksize = cmd_ln_int32_r(wtf->config, "-blocksize");
+ if (wtf->blocksize < fsize + fshift) {
+ E_INFO("Block size of %d too small, increasing to %d\n",
+ wtf->blocksize, fsize + fshift);
+ wtf->blocksize = fsize + fshift;
+ }
+ wtf->audio = ckd_calloc(wtf->blocksize, sizeof(*wtf->audio));
+ wtf->featsize = (wtf->blocksize - fsize) / fshift;
+
+ /* Use the maximum of the input and output frame sizes to allocate this. */
+ veclen = wtf->veclen;
+ if (wtf->in_veclen > veclen) veclen = wtf->in_veclen;
+ wtf->feat = ckd_calloc_2d(wtf->featsize, veclen, sizeof(**wtf->feat));
+
+ /* Let's go! */
+ if ((wtf->outfh = fopen(outfile, "wb")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open %s for writing", outfile);
+ return -1;
+ }
+ /* Leave blank space for float count at start of mfcc file. */
+ if (fwrite(&zero, 4, 1, wtf->outfh) != 1) {
+ E_ERROR_SYSTEM("Failed to write to %s", outfile);
+ return -1;
+ }
+ wtf->outfile = ckd_salloc(outfile);
+
+ if ((nfloat = (*atype->decode)(wtf)) < 0)
+ return -1;
+
+ /* Fix up the float count. */
+ if (fseek(wtf->outfh, 0, SEEK_SET) < 0) {
+ E_ERROR_SYSTEM("Failed to seek to beginning of %s\n", outfile);
+ }
+ if (fwrite(&nfloat, 4, 1, wtf->outfh) != 1) {
+ E_ERROR_SYSTEM("Failed to write value count to %s\n", outfile);
+ }
+ fclose(wtf->outfh);
+ wtf->outfh = NULL;
+
+ return 0;
+}
+
+void
+build_filenames(cmd_ln_t *config, char const *basename,
+ char **out_infile, char **out_outfile)
+{
+ char const *di, *do_, *ei, *eo;
+
+ di = cmd_ln_str_r(config, "-di");
+ do_ = cmd_ln_str_r(config, "-do");
+ ei = cmd_ln_str_r(config, "-ei");
+ eo = cmd_ln_str_r(config, "-eo");
+
+ *out_infile = string_join(di ? di : "",
+ di ? "/" : "",
+ basename,
+ ei ? "." : "",
+ ei ? ei : "",
+ NULL);
+ *out_outfile = string_join(do_ ? do_ : "",
+ do_ ? "/" : "",
+ basename,
+ eo ? "." : "",
+ eo ? eo : "",
+ NULL);
+}
+
+static int
+run_control_file(sphinx_wave2feat_t *wtf, char const *ctlfile)
+{
+ lineiter_t *li;
+ FILE *ctlfh;
+
+ if ((ctlfh = fopen(ctlfile, "r")) == NULL) {
+ E_ERROR_SYSTEM("Failed to open control file %s", ctlfile);
+ return -1;
+ }
+ for (li = lineiter_start(ctlfh); li; li = lineiter_next(li)) {
+ char *infile, *outfile;
+ int rv;
+
+ string_trim(li->buf, STRING_BOTH);
+ build_filenames(wtf->config, li->buf, &infile, &outfile);
+ rv = sphinx_wave2feat_convert_file(wtf, infile, outfile);
+ ckd_free(infile);
+ ckd_free(outfile);
+ if (rv != 0) {
+ lineiter_free(li);
+ fclose(ctlfh);
+ return rv;
+ }
+ }
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+ sphinx_wave2feat_t *wtf;
+ cmd_ln_t *config;
+ int rv;
+
+ /* Initialize config. */
+ config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE);
+ /* Parse an argument file if there's one in there. */
+ if (cmd_ln_str_r(config, "-argfile"))
+ config = cmd_ln_parse_file_r(config, defn,
+ cmd_ln_str_r(config, "-argfile"), FALSE);
+ if (config == NULL) {
+ E_ERROR("Command line parsing failed\n");
+ return 1;
+ }
+ if ((wtf = sphinx_wave2feat_init(config)) == NULL) {
+ E_ERROR("Failed to initialize wave2feat object\n");
+ return 1;
+ }
+
+ /* If there's a control file run through it, otherwise we will do
+ * a single file (which is what run_control_file will do
+ * internally too) */
+ if (cmd_ln_str_r(config, "-c"))
+ rv = run_control_file(wtf, cmd_ln_str_r(config, "-c"));
+ else
+ rv = sphinx_wave2feat_convert_file(wtf, cmd_ln_str_r(config, "-i"),
+ cmd_ln_str_r(config, "-o"));
+
+ sphinx_wave2feat_free(wtf);
+ return rv;
+}
Copied: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_wave2feat.h (from rev 9756, trunk/sphinxbase/src/sphinx_fe/sphinx_wave2feat.h)
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_wave2feat.h (rev 0)
+++ branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/sphinx_wave2feat.h 2010-02-28 20:55:10 UTC (rev 9757)
@@ -0,0 +1,66 @@
+/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* ====================================================================
+ * Copyright (c) 1996-2004 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 __SPHINX_FE_H__
+#define __SPHINX_FE_H__
+
+/**
+ * Waveform to feature converter object.
+ */
+typedef struct sphinx_wave2feat_s sphinx_wave2feat_t;
+
+/**
+ * Initialize waveform to feature converter.
+ */
+sphinx_wave2feat_t *sphinx_wave2feat_init(cmd_ln_t *config);
+
+/**
+ * Release a waveform to feature converter.
+ */
+int sphinx_wave2feat_free(sphinx_wave2feat_t *w2f);
+
+/**
+ * Retain a waveform to feature converter.
+ */
+sphinx_wave2feat_t *sphinx_wave2feat_retain(sphinx_wave2feat_t *w2f);
+
+/**
+ * Convert one file.
+ */
+int sphinx_wave2feat_convert_file(sphinx_wave2feat_t *w2f,
+ char const *infile, char const *outfile);
+
+#endif /* __SPHINX_FE_H__ */
Deleted: branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/wave2feat.c
===================================================================
--- branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/wave2feat.c 2010-02-28 20:41:14 UTC (rev 9756)
+++ branches/pocketsphinx-0.6/sphinxbase/src/sphinx_fe/wave2feat.c 2010-02-28 20:55:10 UTC (rev 9757)
@@ -1,1247 +0,0 @@
-/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* ====================================================================
- * Copyright (c) 1996-2004 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.
- *
- * ====================================================================
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <assert.h>
-
-#ifdef _WIN32
-#pragma warning (disable: 4996 4018)
-#endif
-
-#if defined(WIN32) && !defined(GNUWINCE) && !defined(_WIN32_WCE)
-#include <errno.h>
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "fe.h"
-#include "strfuncs.h"
-#include "cmd_ln.h"
-#include "err.h"
-#include "ckd_alloc.h"
-#include "byteorder.h"
-
-#include "wave2feat.h"
-#include "cmd_ln_defn.h"
-
-struct globals_s {
- cmd_ln_t *config;
- int32 nskip;
- int32 runlen;
- char const *wavfile;
- char const *cepfile;
- char const *ctlfile;
- char const *wavdir;
- char const *cepdir;
- char const *wavext;
- char const *cepext;
- int32 input_format;
- int32 is_batch;
- int32 is_single;
- int32 blocksize;
- int32 machine_endian;
- int32 input_endian;
- int32 output_endian;
- int32 nchans;
- int32 whichchan;
- int32 convert;
- int32 verbose;
- int32 logspec;
-};
-typedef struct globals_s globals_t;
-
-globals_t *fe_parse_options(int argc, char **argv);
-int32 fe_convert_files(globals_t * P);
-int32 fe_build_filenames(globals_t * P, char *fileroot, char **infilename,
- char **outfilename);
-int32 fe_openfiles(globals_t * P, fe_t * FE, char *infile, FILE **fh_in,
- int32 * nsamps, int32 * nframes, int32 * nblocks,
- char *outfile, FILE **fh_out);
-int32 fe_readblock_spch(globals_t * P, FILE *fh, int32 nsamps,
- int16 * buf);
-int32 fe_writeblock_feat(globals_t * P, fe_t * FE, FILE *fh, int32 nframes,
- mfcc_t ** feat);
-int32 fe_closefiles(globals_t *P, FILE *fh_in, FILE *fh_out);
-int32 fe_convert_with_dct(globals_t * P, fe_t * FE, char *infile, char *outfile);
-
-/*
- 7-Feb-00 M. Seltzer - wrapper created for new front end -
- does blockstyle processing if necessary. If input stream is
- greater than DEFAULT_BLOCKSIZE samples (currently 200000)
- then it will read and write in DEFAULT_BLOCKSIZE chunks.
-
- Had to change fe_process_utt(). Now the 2d feature array
- is allocated internally to that function rather than
- externally in the wrapper.
-
- Added usage display with -help switch for help
-
- 14-Feb-00 M. Seltzer - added NIST header parsing for
- big endian/little endian parsing. kind of a hack.
-
- changed -wav switch to -nist to avoid future confusion with
- MS wav files
-
- added -mach_endian switch to specify machine's byte format
-*/
-
-int32
-main(int32 argc, char **argv)
-{
- globals_t *P;
-
- P = fe_parse_options(argc, argv);
- if (fe_convert_files(P) != FE_SUCCESS) {
- E_FATAL("error converting files...exiting\n");
- }
- free(P);
- return (0);
-}
-
-
-int32
-fe_convert_files(globals_t * P)
-{
-
- fe_t *FE;
- char *infile, *outfile, fileroot[MAXCHARS];
- FILE *ctlfile;
- int16 *spdata = NULL;
- int32 splen =
- 0, total_samps, frames_proc, nframes, nblocks, last_frame;
- int32 last_blocksize = 0, curr_block, total_frames;
- FILE *fh_in, *fh_out;
- mfcc_t **cep = NULL, **last_frame_cep;
- int32 return_value;
- int32 warn_zero_energy = 0;
- int32 process_utt_return_value;
-
- if ((FE = fe_init_auto_r(P->config)) == NULL) {
- E_ERROR("memory alloc failed...exiting\n");
- return (FE_MEM_ALLOC_ERROR);
- }
-
- if (P->is_batch) {
- int32 nskip = P->nskip;
- int32 runlen = P->runlen;
-
- if ((ctlfile = fopen(P->ctlfile, "r")) == NULL) {
- E_ERROR("Unable to open control file %s\n", P->ctlfile);
- fe_free(FE);
- return (FE_CONTROL_FILE_ERROR);
- }
- while (fscanf(ctlfile, "%s", fileroot) != EOF) {
- if (nskip > 0) {
- --nskip;
- continue;
- }
- if (runlen > 0) {
- --runlen;
- }
- else if (runlen == 0) {
- break;
- }
-
- fe_build_filenames(P, fileroot, &infile, &outfile);
-
- if (P->verbose)
- E_INFO("%s\n", infile);
-
- if (P->convert) {
- /* Special case for doing various DCTs */
- return_value = fe_convert_with_dct(P, FE, infile, outfile);
- ckd_free(infile);
- ckd_free(outfile);
- infile = outfile = NULL;
- if (return_value != FE_SUCCESS) {
- fe_free(FE);
- return return_value;
- }
- continue;
- }
- return_value =
- fe_openfiles(P, FE, infile, &fh_in,
- &total_samps, &nframes, &nblocks,
- outfile, &fh_out);
- ckd_free(infile);
- ckd_free(outfile);
- infile = outfile = NULL;
- if (return_value != FE_SUCCESS) {
- fe_free(FE);
- return (return_value);
- }
-
- warn_zero_energy = 0;
-
- if (nblocks * P->blocksize >= total_samps)
- last_blocksize =
- total_samps - (nblocks - 1) * P->blocksize;
-
- if (!fe_start_utt(FE)) {
- curr_block = 1;
- total_frames = frames_proc = 0;
- /*execute this loop only if there is more than 1 block to
- be processed */
- while (curr_block < nblocks) {
- splen = P->blocksize;
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|