[DEV] 2.4 tools

This commit is contained in:
Edouard DUPIN 2015-09-19 10:52:26 +02:00
commit b6ae08bd22
945 changed files with 186828 additions and 0 deletions

291
INSTALL Normal file
View File

@ -0,0 +1,291 @@
INSTALLATION
Release notes
This documentation covers version 2.4 of the Edinburgh Speech Tools
Library. While previous versions of the speech tools were primarily
released solely to support the Festival Speech Synthesis System, the
Edinburgh Speech Tools Library now contains sufficiently useful tools
that it is of use in its own right.
Although hope that the speech tools has stabilised to a certain extent
and less structural changes will occur in future versions we don't
guaranteed future compatibility, although every effort will be made to
make upgrading as easy as possible. In addition, we warn that while
several programs and routines are quite mature, others are young and
have not be rigorously tested. Please do not assume these programs
work.
Requirements
In order to compile and install the Edinburgh Speech Tools you need
the following
GNU make
Any recent version, the various make programs that come with different
UNIX systems are wildly varying and hence it makes it too difficult to
write Makefiles which are portable, so we depend on a version of make
which is available for all of the platforms we are aiming at.
A C++ compiler
The system was developed primarily with GNU C++ (various versions from
version 2.7.2), but we also have compiled it successfully with a
number of other versions of gcc, and Visual C++.
Hopefully we have now sanitized the code sufficiently to to make it
possible for ports to other C++ compilers without too much
difficulty. But please note C++ is not a fully standardized language
and each compiler follows the incomplete standard to various
degrees. Often there are many but simple problems when porting to new
C++ compilers. We are trying to deal with this by increasing our
support. However, it is likely that small changes will be required for
C++ compilers we have not yet tested the system under.
However we feel this is stable enough to make it worthwhile attempting
ports to other C++ compilers that we haven't tried yet.
Before installing the speech tools it is worth ensuring you have a
fully installed and working version of your C++ compiler. Most of the
problems people have had in installing the speech tools have been due
to incomplete or bad compiler installation. It might be worth checking
if the following program works, if you don't know if anyone has used
your C++ installation before.
#include <iostream.h>
int main (int argc, char **argv)
{
cout << "Hello world\n";
}
Supported Systems
We have successfully compiled and tested the speech tools on the
following systems, except where specified we include support for both
shared and static versions of the libraries:
Sun Sparc Solaris 2.5.1/2.6/2.7/2.9
GCC 2.7.2, GCC 2.8.1, gcc-2.95.3, gcc-3.2 gcc-3.3
MacOS GCC 4.2.1 (Snow Leopard default)
Linux GCC 4.2 - 4.8.0
Windows 7/8 GCC (from Cygwin 1.7), Visual C++ (VS2010,VS2012).
As stated before C++ compilers are not standard and it is non-trivial
to find the correct dialect which compiles under all. We recommend
the use of GCC 4.6 if you can use it, it is the most likely one to
work. Some of the compilers listed above produce a large number of
warnings when compiling the code.
Previous versions of the system have successfully compiled under SGI
IRIX 5.3, 6.x, OSF (Alphas) and HPUX but at time of writing this we have
not yet rechecked this version. AIX4.3 probably works.
Java is no longer supported!
The java directory contains optional Java classes which give some
access to speech tools facilities from Java programs. This has been
created to support the fringe graphical interface. There are three
levels of support enabled by the JAVA JAVA_MEDIA and JAVA_CPP options
in the config file. JAVA compiles some very basic classes intended to
allow very simple simulation of speech tools facilities in pure Java
programs. JAVA_MEDIA is similar but uses the Jva Media Framework to
play sound. JAVA_CPP compiles classes which use the Java native
interface to provide access to the actual speech tools C++ classes.
You may (for instance on Solaris using gcc) need to make shared
libraries for some compiler support libraries in order to comple the
full JAVA_CPP support. See Appendix A for details.
Windows 95/98/NT/XP/Vista/7/8 Port
We have done two ports of this code to Windows machines, one uses the
Cygwin package, which provides a Unix like environment under on Win32
systems, the other is a native port using Visual C++.
We recommend using only Windows 7.
The port using Visual C++ does not provide all of the
features of the Unix and Cygwin versions. You will need access to a
Unix or Cygwin system to create the makefiles used for the Visual C++
compilation.
Both Cygwin and Visual C++ ports have a number of limitations.
Shared library creation is not supported.
Creation of Windows DLLs is different enough from creation of Unix
shared libraries that the support does not carry directly across, and
we haven't yet had time to work on it.
Java not supported
Because the Java support is related to the creation of shared
libraries, this is also not yet implemented for Windows.
Command line editing limited
Because of the limits of the Windows DOS console window, the
command line editing in siod is less reliable (for instance on
very long lines).
(Visual C++) Networking not supported
Networking under Win32 is different from Unix in a number of
fairly fundamental ways, we haven't tackled this at all.
There are no doubt other differences we have not noticed. We don't use
Windows for any of our work and so the Windows builds of our systems
don't get the extensive use the unix builds do.
BUILDING IT
Configuration
All compile-time configuration for the system is done through GNU
configure. On most systems you can configure the system
by
unix$ ./configure
This creates the file config/config which for most machines will be
suitable. In some circumstances the default.s generated from this
may not be what you want and you may wish to edit this file.
For Linux we now fully support shared libraries and even recommend
them. However if you are going to do a lot of development and don't
understand the consequences of shared libraries and getting
LD_LIBRARY_PATH correct (or what that is) we recommend you compile
unshared, the default. If you are going to simply run the speech tools
(and festival) then shared is a reasonable option. Uncomment the line
in the config file
# SHARED = 2
Shared support under Solaris is complete for all the speech tools. If
you need to exec festival scripts using a version of festival built
with shared libraries, you must either execute them from a featureful
shell (e.g. bash), install the shared libraries in a standard place or
explicitly set LD_LIBRARY_PATH. Solaris's standard shell doesn't
support script execution of shells within shells.
Simple choices for common set ups are given near the top of this
file. But for some sub-systems you will also need to change pathnames
for external library support.
Compilation
Once you have configured config/config you can compile the system.
unix$ gmake
Note this must be GNU make, which may be called make on your system,
or gmake or gnumake. This will compile all library functions and all
the executables. If you wish to only compile the library itself then
use
unix$ gmake make_library
Note that if you compile with -g (uncommenting DEBUG = 1 is
config/config the library and the corresponding binaries will be
large. Particularly the executables, you will need in order of 150
megabytes to compile the system, if your C++ libraries are not
compiled as shared libraries. If you compile without -g the whole
library directory is about 12 megabytes on Linux (which has shared
libraries for libstdc++ or about 26 megabytes of Sparc Solaris (which
does not have a shared library libstdc++ by default). This is almost
entirely due to the size of the executables. C++ does not make small
binaries.
In general we have made the system compile with no warnings. However
for some compilers this has proved to be near impossible. SunOS
include files have a number of system declarations missing, so many
system functions (e.g. fprintf) will appear to be undeclared. Sun's CC
compiler also likes to complain about missing source for some code
even though the code exists within our system and is deliberately in
separate files ro make it modular.
To test the system after compilation
unix$ gmake test
Installing the system
All executables are linked to from speech_tools/bin and you should add
that to your PATH in order to use them.
Include files are speech_tools/include/ and the three generated
libraries are speech_tools/lib/libestools.a,
speech_tools/lib/libestbase.a and speech_tools/lib/libestring.a. For
most cases a three will be required.
If space is a premium, compiled with the shared option (binaries
will be then be substantially smaller) and you can delete all .o files
Some aspects of the system have further dependencies which depend of
the option selected at compile time. Specifically the readline
libraries and Netaudio libraries.
These are uptodate instructions for Visual C++ builds.
VS2010 was tested but older versions may work
Requirements:
MS Windows 7 (or Windows 8)
Visual C++ (VS2010 or VS2012)
cygwin 1.7 or later
speech_tools-2.3
festival-2.3
Download and install cygwin.
Optionally download emacs so you have a decent editor :)
Download speech_tools and festival tar.gz files.
Download required festival lexicons and voices.
Using cygwins bash shell:
mkdir C:/festival
cd C:/festival
Using cygwin's tar command unpack:
tar xvfz speech_tools-2.3.tar.gz
tar xvfz festival-2.3.tar.gz
tar xvfz festlex... festvox...
(where festlex... and festvox... are the voice and lexicon files you
need. Do not use winzip to unpack the voices it corrupts them!)
Create Visual C++ make files: (this may be slow...)
cd speech_tools
make VCMakefile
cp config/vc_config_make_rules-dist config/vc_config_make_rules
cd ../festival
make VCMakefile
cp config/vc_config_make_rules-dist config/vc_config_make_rules
Finally make festival init_modules code. (If you add new modules you
either need to edit init_modules.cc by hand or rerun this step.)
make -C src/modules init_modules.cc
edit config/vc_config_make_rules and change:
SYSTEM_LIB=c:\\festival\\lib
to:
SYSTEM_LIB=c:\\festival\\festival\\lib
(or to wherever you unpacked festival)
Now switch to a windows command prompt.
If necessary execute: VCVARSALL.BAT from the VC++ directory structure to set up
VC++ environment. (you may do this automatically at boot or login, or it should be
automatic if using the terminal provided by Visual studio)
Build speech_tools and festival:
cd c:\festival\speech_tools
nmake /nologo /FVCMakefile
cd ..\festival
nmake /nologo /FVCMakefile
At this point you should be able to run festival by typing:
src\main\festival

115
Makefile Normal file
View File

@ -0,0 +1,115 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996-2014 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
## ##
## Top level Makefile for Edinburgh Speech tools library ##
## Authors: Paul Taylor, Simon King, Alan W Black, Richard Caley ##
## and others (see ACKNOWLEDGEMENTS) ##
## Version: 2.4 release December 2014 ##
## ##
###########################################################################
TOP=.
DIRNAME=.
LIB_BUILD_DIRS = audio utils base_class ling_class speech_class sigpr \
stats grammar intonation
# Development directories are those that contain non-stable code
#DEV_DIRS = $(shell if [ -f DEV_DIRS ]; then cat DEV_DIRS; fi )
BUILD_DIRS = $(LIB_BUILD_DIRS) lib main scripts testsuite bin
TEMPLATE_DIRS=include audio utils base_class base_class/string \
ling_class speech_class sigpr stats grammar siod
EXTRA_DIRS=siod java rxp wrappers
ALL_DIRS = include $(BUILD_DIRS) $(EXTRA_DIRS) config doc
VERSION=$(PROJECT_VERSION)
CONFIG=configure configure.in config.sub config.guess \
missing install-sh mkinstalldirs
FILES=Makefile README INSTALL $(CONFIG)
LOCAL_CLEAN= Build.trace Test.trace Templates.DB
ALL = .config_error .sub_directories
# Try and say if config hasn't been created
config_dummy := $(shell test -f config/config || ( echo '*** '; echo '*** Making default config file ***'; echo '*** '; ./configure; ) >&2)
# force a check on the system file
system_dummy := $(shell $(MAKE) -C $(TOP)/config -f make_system.mak TOP=.. system.mak)
include $(TOP)/config/common_make_rules
dist: backup
backup: time-stamp
@ $(MAKE) file-list
@ sed 's/^\.\///' <FileList | sed 's/^/speech_tools\//' >FileList.all
@ (cd ..; tar cvf - `cat speech_tools/FileList.all` speech_tools/.time-stamp | gzip > speech_tools/speech_tools-$(VERSION)-$(PROJECT_STATE).tar.gz)
@ $(RM) -f $(TOP)/FileList.all
@ ls -l speech_tools-$(VERSION)-$(PROJECT_STATE).tar.gz
time-stamp :
@ echo speech_tools $(VERSION) >.time-stamp
@ date >>.time-stamp
minrev: backup
@mv speech_tools-$(VERSION).tar.gz speech_tools-$(VERSION).`date +%y%m%d`.tar.gz
tags:
@ $(RM) -f FileList
@ $(MAKE) --no-print-directory FileList
@ etags `grep ".[ch]c*$$" FileList`
test: make_library
@ $(MAKE) --no-print-directory -C testsuite test
rebuild_and_test:
$(MAKE) -k clean
$(MAKE) -k depend
$(MAKE) -k all >Build.trace 2>&1
$(MAKE) -k test >Test.trace 2>&1
@if egrep 'FAILED|INCORRECT' Test.trace ;\
then \
echo test failed ;\
exit 1 ;\
fi
@if cat Build.trace Test.trace | egrep 'warning:' ;\
then \
echo warnings found ;\
exit 2 ;\
fi
config/config: config/config.in config.status
./config.status
configure: configure.in
autoconf
include $(TOP)/config/rules/top_level.mak
include $(TOP)/config/rules/install.mak

251
README Normal file
View File

@ -0,0 +1,251 @@
EDINBURGH SPEECH TOOLS LIBRARY
VERSION 2.4 December 2014
Principal authors: Alan W Black, Paul Taylor, Richard Caley,
Simon King, Rob Clark and Korin Richmond
Centre for Speech Technology
University of Edinburgh
Informatics Forum
10 Crichton Street
Edinburgh EH8 9AB, UK
http://www.cstr.ed.ac.uk/projects/speech_tools
Although this is a considered stable release, there are still a number
of known parts are missing or incomplete.
------------------------------------------------------------------------
The Edinburgh speech tools system is a library of C++ classes, functions
and utility programs that are frequently used in speech software. The
system compiles to a single unix library .a file which can be linked
with software. At present, C++ classes for several useful speech and
language classes have been written, along with audio software and some
basic signal processing software.
========================================================================
Edinburgh Speech Tools Library version 2.4
Centre for Speech Technology Research
University of Edinburgh, UK
Copyright (c) 1994-2014
All Rights Reserved.
Permission is hereby granted, free of charge, to use and distribute
this software and its documentation without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of this work, and to
permit persons to whom this work is furnished to do so, subject to
the following conditions:
1. The code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Any modifications must be clearly marked as such.
3. Original authors' names are not deleted.
4. The authors' names are not used to endorse or promote products
derived from this software without specific prior written
permission.
THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK
DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
========================================================================
The following c++ programs are available:
na_play: generic playback program for use with net_audio and CSTR ao.
ch_wave: Waveform file conversion program.
ch_lab: label file conversion program.
ch_track: Track file conversion program.
wagon: a CART tree build and test program
And others
The following C++ sub-libraries are available
audio: C++ audio functions for Network Audio system, Suns
Linux and FreeBSD
speech_class: C++ speech classes, including waveform and track.
ling_class: C++ linguistic classes.
sigpr: Signal processing
utils: Various utilities.
COPYING
------------------------------------------------------------------------
Some files in the distribution do not fall under the above copyright.
However none have any commercial restrictions, and no files fall under
the GPL. Specifically files that have different licences are as
follows:
grammar/wfst/wfst_train.cc
Copyright Carnegie Mellon University (under the same
open licences as much of the rest of the code).
siod/
include/siod*.h
lib/siod/siod.scm
Apart from some new functionality under our licence the SIOD
files fall under the licence given in siod/slib.cc copyright
Paradigm Associates. This code has been substantially modified
by us though our changes are under that licence.
editline.c editline.h el_complete.c el_sysunix.c el_unix.h
are copyright 1992 Simmule Turner and Rich Salz under the
"BSD like" licence in siod/editline.c Again substantial
changes have been made by us which continue to be under that
licence
rxp/
include/rxp/
Is Copyright Richard Tobin. We have a specific version of RXP
which allows free (including non-commercial) use.
base_class/raveconv.cc
Is copyright 1992, 1995 by Markus Mummert
base_class/string/reg*.{c,cc}
Copyright (c) 1986 by University of Toronto.
base_class/string/EST_strcasecmp.c
Copyright (c) 1987, 1993
The Regents of the University of California. All rights reserved.
The standard BSD licence
ACKNOWLEDGEMENTS
------------------------------------------------------------------------
Most of the software was written by Paul Taylor, Alan W Black, Simon
King, Richard Caley, Rob Clark and Korin Richmond. Additional
contributions have been made by the following people. Slightly
different licence agreements accompany these pieces of code, so it is
important that the various agreements be properly understood.
Tony Robinson: some signal processing code.
Markus Mummert: sample rate converter (rateconv.cc).
Craig Reese and Joe Campbell: ulaw conversion code.
Paul Bagshaw: pitch tracker.
Theo Veenker: IRIX audio support.
Stan Chen: AIX support
Paradigm Assoc. and George Carrett: For Scheme In One Defun
Simmule Turner and Rich Salz: for editline
Henry Spencer: for regex code
The Regents of the University of California: some string comparison code
Richard Tobin: RXP, XML parser.
Arthur Toth: Windows server code
Pierre Lorenzon <devel@pollock-nageoire.net> gcc-4.7 patches
Sergio Oller: for making the documentation work again
INSTALLATION
************
see INSTALL file for details
FILE/DIRECTORY STRUCTURE
------------------------------------------------------------------------
The main directory contains minimal wrap-around main() functions
which compile to form executables which use the algorithms in the
speech tools. All these main() functions really do is to read
command line options and read and write files, the algorithms
themselves are completely contained within the libraries.
The directory structure is as follows:
config:
shared make rules and configuration make rules
speech_class:
general speech class files, including waveforms, contours etc.
ling_class:
general linguistic class files, including a stream-based architecture.
sigpr:
signal processing code.
doc:
basic documentation, generates html, info and postscript
include:
class and general header files.
lib:
where the .a files are kept
main:
Directory containing main files which compile to executables.
DOCUMENTATION
------------------------------------------------------------------------
There are two sources of documentation.
Man pages exist for the more important stand-alone programs. These are
found in the main directory.
The library documentation has substantiall improved in this version
using an integrated DOC++, JADE and docbook combination. Classes are
described at the overview, theorectical, practical and code level.
The build process for the documentation is still dependent on some
more obscure packages so it is recommended that you take the
pre-built documentation. Or access it on-line through
http://www.cstr.ed.ac.uk/projects/speech_tools
The library documentation is in texinfo format which can be converted
into GNU info HTML and postscript, see Makefile in doc/
Note the documentation is not up to date. We are in the process of moving the documentation to Doxygen.
BUGS/COMMENTS ETC
------------------------------------------------------------------------
Substantial parts of this release are considered mature and should be
relatively free of bugs, however there are newer parts which have not
been rigourously tested yet. If you find any bugs, please send a bug
report to speechtools@cstr.ed.ac.uk. Any useful comments will also be
appreciated. See also the bugs file in the doc directory.
If you have some software that you think could be integrated into the
speechtools system, please contact us at
speechtools@cstr.ed.ac.uk. The whole point of writing and releasing
code such as this is to prevent duplication of effort, and therefore
we would appreciate greatly any code which will add to the usefulness
of the system. Signal processing routines are particularly welcome.
======================================================================
ADDITIONAL SOFTWARE
======================================================================
CSTR supplies a number of different speech technology systems
including speech synthesis systems and (in the future) a recognition
system. To find out more information checkout http://www.cstr.ed.ac.uk/

74
audio/Makefile Normal file
View File

@ -0,0 +1,74 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
## Author : Paul Taylor ##
## Date : March 1995 ##
##-----------------------------------------------------------------------##
## Audio System Makefile ##
## ##
##=======================================================================##
TOP=..
DIRNAME=audio
LOCAL_DEFAULT_LIBRARY = estbase
H = audioP.h
CPPSRCS = gen_audio.cc nas.cc esd.cc sun16audio.cc \
mplayer.cc win32audio.cc irixaudio.cc os2audio.cc \
macosxaudio.cc linux_sound.cc
SRCS = $(CPPSRCS)
OBJS = $(SRCS:.cc=.o)
FILES = $(CPPSRCS) $(H) Makefile
ALL = .buildlib
WIN_CFLAGS = $$(DEBUGFLAGS) $$(OPTFLAGS) $$(INCLUDEFLAGS)
include $(TOP)/config/common_make_rules
DEFINES += $(AUDIO_DEFINES)
INCLUDES += $(AUDIO_INCLUDES)

56
audio/audioP.h Normal file
View File

@ -0,0 +1,56 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : May 1996 */
/*=======================================================================*/
/* Shared (private) audio declarations */
/* */
/*=======================================================================*/
#ifndef __AUDIOP_H__
#define __AUDIOP_H__
int play_nas_wave(EST_Wave &inwave, EST_Option &al);
int play_esd_wave(EST_Wave &inwave, EST_Option &al);
int play_sun16_wave(EST_Wave &inwave, EST_Option &al);
int play_linux_wave(EST_Wave &inwave, EST_Option &al);
int play_mplayer_wave(EST_Wave &inwave, EST_Option &al);
int play_win32audio_wave(EST_Wave &inwave, EST_Option &al);
int play_irix_wave(EST_Wave &inwave, EST_Option &al);
int play_macosx_wave(EST_Wave &inwave, EST_Option &al);
int record_nas_wave(EST_Wave &inwave, EST_Option &al);
int record_esd_wave(EST_Wave &inwave, EST_Option &al);
int record_sun16_wave(EST_Wave &inwave, EST_Option &al);
int record_linux_wave(EST_Wave &inwave, EST_Option &al);
#endif /* __AUDIOP_H__ */

168
audio/esd.cc Normal file
View File

@ -0,0 +1,168 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Richard Caley */
/* ------------------------------------------------------------------- */
/* EST audio module using the enlightenment speech daemon. */
/* */
/*************************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sys/stat.h>
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#ifdef SUPPORT_ESD
// Hack hack. aupvlist.h is broken at least on FBSD 3.1.1
#undef __cplusplus
extern "C"
{
#include <aupvlist.h>
}
#define __cplusplus
#include <esd.h>
#define au_serverrate 16000
bool esd_supported = TRUE;
static int endian_int = 1;
#define ESD_BIG_ENDIAN (((char *)&endian_int)[0] == 0)
EST_String server;
void get_server(EST_Option &al)
{
if (al.present("-display"))
{
EST_String display = al.val("-display");
if (display.contains(":"))
{
server = display.before(":");
}
else
{
server = display;
}
}
else
server = "";
}
int play_esd_wave(EST_Wave &inwave, EST_Option &al)
{
get_server(al);
int format;
switch (inwave.num_channels())
{
case 1: format=ESD_MONO;
break;
case 2: format=ESD_STEREO;
break;
default:
cerr << "EST: " << inwave.num_channels() << " channel data not supported\n";
return -1;
}
format |= ESD_BITS16 | ESD_STREAM | ESD_PLAY;
int sample_rate = inwave.sample_rate();
int esd = esd_play_stream( format, sample_rate,
server==EST_String::Empty?NULL:(const char *)server, "from est");
int n = inwave.num_samples() * sizeof(short) * inwave.num_channels();
int nw=0, tot=0;
const char *data = (const char *)(inwave.values().memory());
while(n > 0 && (nw = write(esd, data+tot, n)) >0)
{
n -= nw;
tot+=nw;
}
if (nw < 0)
{
cerr << "ESD: error writing - " << strerror(errno) << "\n";
}
esd_close(esd);
return 1;
}
int record_esd_wave(EST_Wave &wave, EST_Option &al)
{
(void)wave;
(void)al;
cerr << "ESD: record not written yet\n";
return -1;
}
#else
int esd_supported = FALSE;
int play_esd_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "ESD playback not supported" << endl;
return -1;
}
int record_esd_wave(EST_Wave &wave, EST_Option &al)
{
(void)wave;
(void)al;
cerr << "ESD record not supported" << endl;
return -1;
}
#endif

377
audio/gen_audio.cc Normal file
View File

@ -0,0 +1,377 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : March 95 */
/*-----------------------------------------------------------------------*/
/* Generalised playback function */
/* */
/*=======================================================================*/
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <fcntl.h>
#include "EST_system.h"
#include "EST_socket.h"
#include "EST_Option.h"
#include "EST_Wave.h"
#include "EST_io_aux.h"
#include "audioP.h"
#include "EST_audio.h"
#include "EST_wave_aux.h"
static int play_sunau_wave(EST_Wave &inwave, EST_Option &al);
static int play_socket_wave(EST_Wave &inwave, EST_Option &al);
static int play_aucomm_wave(EST_Wave &inwave, EST_Option &al);
static int record_sunau_wave(EST_Wave &wave, EST_Option &al);
int play_wave(EST_Wave &inwave, EST_Option &al)
{
EST_String protocol;
EST_Wave wtmp;
EST_Wave *toplay;
char *quality;
char *sr;
if ((sr = getenv("NA_PLAY_HOST")) != NULL)
if (!al.present("-display"))
al.add_item("-display", sr);
if ((quality = getenv("NA_PLAY_QUALITY")) != NULL)
if (!al.present("-quality"))
al.add_item("-quality", quality);
if (al.present("-p"))
protocol = al.val("-p");
else if ((sr=getenv("NA_PLAY_PROTOCOL")) != NULL)
protocol = sr;
else if (protocol == "")
{
if (nas_supported)
protocol = "netaudio"; // the default protocol
else if (esd_supported)
protocol = "esdaudio";
else if (sun16_supported)
protocol = "sun16audio";
else if (freebsd16_supported)
protocol = "freebsd16audio";
else if (linux16_supported)
protocol = "linux16audio";
else if (irix_supported)
protocol = "irixaudio";
else if (macosx_supported)
protocol = "macosxaudio";
else if (win32audio_supported)
protocol = "win32audio";
else if (mplayer_supported)
protocol = "mplayeraudio";
else
protocol = "sunaudio";
}
// OS X can handle multichannel audio, don't know about other systems.
if (inwave.num_channels() > 1 && upcase(protocol) != "MACOSXAUDIO" )
{
wave_combine_channels(wtmp,inwave);
toplay = &wtmp;
}
else
toplay = &inwave;
if (upcase(protocol) == "NETAUDIO")
return play_nas_wave(*toplay,al);
else if (upcase(protocol) == "ESDAUDIO")
return play_esd_wave(*toplay,al);
else if (upcase(protocol) == "SUNAUDIO")
return play_sunau_wave(*toplay,al);
else if (upcase(protocol) == "SUN16AUDIO")
return play_sun16_wave(*toplay,al);
else if ((upcase(protocol) == "FREEBSD16AUDIO") ||
(upcase(protocol) == "LINUX16AUDIO"))
return play_linux_wave(*toplay,al);
else if (upcase(protocol) == "IRIXAUDIO")
return play_irix_wave(*toplay,al);
else if (upcase(protocol) == "MACOSXAUDIO")
return play_macosx_wave(*toplay,al);
else if (upcase(protocol) == "MPLAYERAUDIO")
return play_mplayer_wave(*toplay,al);
else if (upcase(protocol) == "WIN32AUDIO")
return play_win32audio_wave(*toplay,al);
else if (upcase(protocol) == "AUDIO_COMMAND")
return play_aucomm_wave(*toplay,al);
else if (upcase(protocol) == "SOCKET")
return play_socket_wave(*toplay,al);
else
{
cerr << "Unknown audio server protocol " << protocol << endl;
return -1;
}
}
static int play_socket_wave(EST_Wave &inwave, EST_Option &al)
{
// Send inwave down the given fd (a socket)
SOCKET_FD fd;
EST_String otype;
EST_String tmpfile = make_tmp_filename();
if (al.present("socket_fd"))
fd = al.ival("socket_fd");
else
{
cerr << "Socket audio mode: no socket_fd specified" << endl;
return -1;
}
if (al.present("socket_otype"))
otype = al.val("socket_otype"); // file type to send to client
else
otype = "riff";
inwave.save(tmpfile,otype);
// Because the client may receive many different types of file
// I send WV\n to it before the file itself
send(fd,"WV\n",3,0);
socket_send_file(fd,tmpfile);
unlink(tmpfile);
return 0;
}
static int play_aucomm_wave(EST_Wave &inwave, EST_Option &al)
{
// Play wave by specified command
EST_String usrcommand, otype;
char tmpfile[2048];
char pref[2048];
if (al.present("-command"))
usrcommand = al.val("-command");
else if (getenv("NA_PLAY_COMMAND") != NULL)
usrcommand = getenv("NA_PLAY_COMMAND");
else
{
cerr << "Audio protocol set to COMMAND but no command specified\n";
return -1;
}
sprintf(tmpfile,"/tmp/audiofile_%05ld",(long)getpid());
if (al.present("-rate"))
inwave.resample(al.ival("-rate"));
if (al.present("-otype"))
otype = al.val("-otype");
else
otype = "raw";
if (inwave.save(tmpfile,otype) != write_ok)
{
cerr << "Audio writing file \"" << tmpfile << "\" in type \"" <<
otype << " failed " << endl;
return -1;
}
sprintf(pref,"FILE=%s;SR=%d;",tmpfile,inwave.sample_rate());
system((EST_String)pref+usrcommand.unquote('"'));
unlink(tmpfile); // so we don't fill up /tmp
return 0;
}
static int play_sunau_wave(EST_Wave &inwave, EST_Option &al)
{
// Play wave through /dev/audio using 8K ulaw encoding
// works for Suns as well as Linux and FreeBSD machines
int rcode;
const char *audiodevice;
inwave.resample(8000);
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/audio";
// Should really do something cute about checking if /dev/audio
// is not in use
rcode = inwave.save(audiodevice,"ulaw");
return rcode;
}
EST_String options_supported_audio(void)
{
// returns list of supported audio types
EST_String audios = "";
audios += "sunaudio"; // we always support this in spite of the hardware
audios += " audio_command";
if (nas_supported)
audios += " netaudio";
else if (esd_supported)
audios += " esdaudio";
if (sun16_supported)
audios += " sun16audio";
if (freebsd16_supported)
audios += " freebsd16audio";
if (linux16_supported)
audios += " linux16audio";
if (irix_supported)
audios += " irixaudio";
if (mplayer_supported)
audios += " mplayeraudio";
if (macosx_supported)
audios += "macosxaudio";
if (win32audio_supported)
audios += " win32audio";
if (os2audio_supported)
audios += " os2audio";
return audios;
}
int record_wave(EST_Wave &wave, EST_Option &al)
{
// Record wave from audio device
char *sr;
EST_String protocol;
// For archaic reasons, if you are using NAS use DISPLAY or
// AUDIOSERVER
if ((sr = getenv("NA_PLAY_HOST")) != NULL)
if (!al.present("-display"))
al.add_item("-display", sr);
if (al.present("-p"))
protocol = al.val("-p");
else if ((sr=getenv("NA_PLAY_PROTOCOL")) != NULL)
protocol = sr;
else if (protocol == "")
{
if (nas_supported)
protocol = "netaudio"; // the default protocol
else if (esd_supported)
protocol = "esdaudio"; // the default protocol
else if (sun16_supported)
protocol = "sun16audio";
else if (freebsd16_supported)
protocol = "freebsd16audio";
else if (linux16_supported)
protocol = "linux16audio";
else if (irix_supported)
protocol = "irixaudio";
else if (win32audio_supported)
protocol = "win32audio";
else if (mplayer_supported)
protocol = "mplayeraudio";
else
protocol = "sunaudio";
}
if (upcase(protocol) == "NETAUDIO")
return record_nas_wave(wave,al);
else if (upcase(protocol) == "ESDAUDIO")
return record_esd_wave(wave,al);
else if (upcase(protocol) == "SUN16AUDIO")
return record_sun16_wave(wave,al);
else if ((upcase(protocol) == "FREEBSD16AUDIO") ||
(upcase(protocol) == "LINUX16AUDIO"))
return record_linux_wave(wave,al);
else if (upcase(protocol) == "SUNAUDIO")
return record_sunau_wave(wave,al);
else
{
cerr << "NA_RECORD: \"" << protocol <<
"\" EST current has no record support" << endl;
return -1;
}
}
static int record_sunau_wave(EST_Wave &wave, EST_Option &al)
{
int num_samples,i,r,n;
int audio;
unsigned char *ulawwave;
short *waveform;
const int AUDIOBUFFSIZE = 256;
const char *audiodevice;
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/audio";
if ((audio = open(audiodevice, O_RDONLY)) == -1)
{
cerr << "SUN16: can't open " << audiodevice << " for reading" << endl;
return -1;
}
num_samples = (int)(8000*al.fval("-time"));
ulawwave = walloc(unsigned char,num_samples);
for (r=i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = read(audio,&ulawwave[i], n);
if (r <= 0)
{
cerr << "sunaudio: failed to read from audio device" << endl;
close(audio);
wfree(ulawwave);
return -1;
}
}
wave.resize(num_samples);
wave.set_sample_rate(8000);
waveform = wave.values().memory();
ulaw_to_short(ulawwave,waveform,num_samples);
wave.resample(al.ival("-sample_rate"));
close(audio);
wfree(ulawwave);
return 0;
}

96
audio/irixaudio.cc Normal file
View File

@ -0,0 +1,96 @@
/*************************************************************************/
/* Author : Theo Veenker (Utrecht University) */
/* Date : September 1997 */
/*-----------------------------------------------------------------------*/
/* Optional 16bit linear support for audio on IRIS 4D workstations */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include "EST_unix.h"
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#if defined (SUPPORT_IRIX) || defined (SUPPORT_IRIX53)
#include <audio.h>
#include <unistd.h>
int irix_supported = TRUE;
int play_irix_wave(EST_Wave &inwave, EST_Option &al)
{
int sample_rate;
short *waveform;
int num_samples;
ALconfig config;
ALport port;
int r;
(void)al;
waveform = inwave.values().memory();
num_samples = inwave.num_samples();
sample_rate = inwave.sample_rate();
config = ALnewconfig();
ALsetsampfmt(config, AL_SAMPFMT_TWOSCOMP);
ALsetwidth(config, AL_SAMPLE_16);
ALsetchannels(config, AL_MONO);
long pvbuf[2];
pvbuf[0] = AL_OUTPUT_RATE;
pvbuf[1] = sample_rate;
ALsetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
/*
ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 2);
if (pvbuf[1] != sample_rate)
{
cerr << "IRIX: sample rate " << sample_rate <<
" not supported; using " << pvbuf[1] << endl;
}
*/
port = ALopenport("speech-tools", "w", config);
if (!port)
{
cerr << "IRIX: can't open audio port" << endl;
ALfreeconfig(config);
return -1;
}
r = ALwritesamps(port, waveform, num_samples);
if (r != 0)
cerr << "IRIX: failed to write to buffer" << endl;
// Wait until all samples are played.
// IRIX 5.3 doesn't have usleep
#ifdef SUPPORT_IRIX53
while (ALgetfilled(port)) sginap(1);
#elseif
while (ALgetfilled(port)) usleep(10000);
#endif
ALcloseport(port);
ALfreeconfig(config);
return 1;
}
#else
int irix_supported = FALSE;
int play_irix_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "IRIX 16bit linear not supported" << endl;
return -1;
}
#endif

953
audio/linux_sound.cc Normal file
View File

@ -0,0 +1,953 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1997,1998 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : July 1997 */
/*-----------------------------------------------------------------------*/
/* Optional support for /dev/dsp under FreeBSD and Linux */
/* These use the same underlying sound drivers (voxware). This uses */
/* 16bit linear if the device supports it otherwise it uses 8bit. The */
/* 8bit driver is still better than falling back to the "sunaudio" ulaw */
/* 8K as this driver can cope with various sample rates (and saves on */
/* resampling). */
/* */
/* Combined FreeBSD and Voxware code Feb 98 */
/* */
/* This may work on NetBSD and OpenBSD but I haven't tried it */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sys/stat.h>
#include "EST_cutils.h"
#include "EST_walloc.h"
#include "EST_Wave.h"
#include "EST_wave_aux.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#include "EST_error.h"
#ifdef SUPPORT_FREEBSD16
#include <sys/soundcard.h>
#include <fcntl.h>
int freebsd16_supported = TRUE;
int linux16_supported = FALSE;
static char *aud_sys_name = "FreeBSD";
#endif /*SUPPORT_FREEBSD16 */
#ifdef SUPPORT_VOXWARE
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int linux16_supported = TRUE;
int freebsd16_supported = FALSE;
static const char *aud_sys_name = "Linux";
static int stereo_only = 0;
// Code to block signals while sound is playing.
// Needed inside Java on (at least some) linux systems
// as scheduling interrupts seem to break the writes.
#if defined(SUPPORT_LINUX16) || defined(SUPPORT_FREEBSD16)
#include <csignal>
#include <pthread.h>
#define THREAD_DECS() \
sigset_t oldmask \
#define THREAD_PROTECT() do { \
sigset_t newmask; \
\
sigfillset(&newmask); \
\
pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); \
} while(0)
#define THREAD_UNPROTECT() do { \
pthread_sigmask(SIG_SETMASK, &oldmask, NULL); \
} while (0)
#else
#define THREAD_DECS() //empty
#define THREAD_PROTECT() //empty
#define THREAD_UNPROTECT() //empty
#endif /* LINUX_16/FREEBSD16 */
static int sb_set_sample_rate(int sbdevice, int samp_rate)
{
int fmt;
int sfmts;
int stereo=0;
int sstereo;
int channels=1;
ioctl(sbdevice,SNDCTL_DSP_RESET,0);
ioctl(sbdevice,SNDCTL_DSP_SPEED,&samp_rate);
sstereo = stereo;
ioctl(sbdevice,SNDCTL_DSP_STEREO,&sstereo);
/* Some devices don't do mono even when you ask them nicely */
if (sstereo != stereo)
stereo_only = 1;
ioctl(sbdevice,SNDCTL_DSP_CHANNELS,&channels);
ioctl(sbdevice,SNDCTL_DSP_GETFMTS,&sfmts);
if (sfmts == AFMT_U8)
fmt = AFMT_U8; // its really an 8 bit only device
else if (EST_LITTLE_ENDIAN)
fmt = AFMT_S16_LE;
else
fmt = AFMT_S16_BE;
ioctl(sbdevice,SNDCTL_DSP_SETFMT,&fmt);
return fmt;
}
#define AUDIOBUFFSIZE 256
// #define AUDIOBUFFSIZE 20480
int play_linux_wave(EST_Wave &inwave, EST_Option &al)
{
int sample_rate;
short *waveform;
short *waveform2 = 0;
int num_samples;
int audio,actual_fmt;
int i,r,n;
const char *audiodevice;
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/dsp";
if ((audio = open(audiodevice,O_WRONLY)) == -1)
{
cerr << aud_sys_name << ": can't open " << audiodevice << endl;
return -1;
}
// int tmp=open("/tmp/vox_play_wave",O_WRONLY|O_CREAT);
waveform = inwave.values().memory();
num_samples = inwave.num_samples();
sample_rate = inwave.sample_rate();
actual_fmt = sb_set_sample_rate(audio,sample_rate);
if (stereo_only)
{
waveform2 = walloc(short,num_samples*2);
for (i=0; i<num_samples; i++)
{
waveform2[i*2] = inwave.a(i);
waveform2[(i*2)+1] = inwave.a(i);
}
waveform = waveform2;
num_samples *= 2;
}
THREAD_DECS();
THREAD_PROTECT();
if (sb_set_sample_rate(audio,sample_rate) == AFMT_U8)
{
// Its actually 8bit unsigned so convert the buffer;
unsigned char *uchars = walloc(unsigned char,num_samples);
for (i=0; i < num_samples; i++)
uchars[i] = waveform[i]/256+128;
for (i=0; i < num_samples; i += r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
// r = write(tmp,&uchars[i], n);
r = write(audio,&uchars[i], n);
if (r == 0)
{
THREAD_UNPROTECT();
cerr << aud_sys_name << ": failed to write to buffer" <<
sample_rate << endl;
close(audio);
return -1;
}
}
wfree(uchars);
}
else if ((actual_fmt == AFMT_S16_LE) ||
(actual_fmt == AFMT_S16_BE))
{
int blksize, nbuf, c;
short *buf;
ioctl (audio, SNDCTL_DSP_GETBLKSIZE, &blksize);
nbuf=blksize;
buf=new short[nbuf];
for (i=0; i < num_samples; i += r/2)
{
if (num_samples > i+nbuf)
n = nbuf;
else
n = num_samples-i;
for(c=0; c<n;c++)
buf[c]=waveform[c+i];
for(; c<nbuf;c++)
buf[c]=waveform[n-1];
// r = write(tmp,&waveform[i], n*2);
// r = write(audio,&waveform[i], n*2);
r=write(audio, buf, nbuf*2);
if (r <= 0)
{
THREAD_UNPROTECT();
EST_warning("%s: failed to write to buffer (sr=%d)",aud_sys_name, sample_rate );
close(audio);
return -1;
}
// ioctl(audio, SNDCTL_DSP_SYNC, 0);
// fprintf(stderr,"[%d]", r);
}
delete [] buf;
}
else
{
THREAD_UNPROTECT();
cerr << aud_sys_name << ": unable to set sample rate " <<
sample_rate << endl;
close(audio);
return -1;
}
// ioctl(audio, SNDCTL_DSP_SYNC, 0);
// fprintf(stderr, "End Play\n");
// close(tmp);
close(audio);
if (waveform2)
wfree(waveform2);
THREAD_UNPROTECT();
return 1;
}
int record_linux_wave(EST_Wave &inwave, EST_Option &al)
{
int sample_rate=16000; // egcs needs the initialized for some reason
short *waveform;
short *waveform2=0;
int num_samples;
int audio=-1,actual_fmt;
int i,r,n;
const char *audiodevice;
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/dsp";
sample_rate = al.ival("-sample_rate");
if ((audio = open(audiodevice,O_RDONLY)) == -1)
{
cerr << aud_sys_name << ": can't open " << audiodevice
<< "for reading" << endl;
return -1;
}
actual_fmt = sb_set_sample_rate(audio,sample_rate);
if ((actual_fmt == AFMT_S16_LE) ||
(actual_fmt == AFMT_S16_BE))
{
// We assume that the device returns audio in native byte order
// by default
inwave.resize((int)(sample_rate*al.fval("-time")));
inwave.set_sample_rate(sample_rate);
num_samples = inwave.num_samples();
waveform = inwave.values().memory();
if (stereo_only)
{
waveform2 = walloc(short,num_samples*2);
num_samples *= 2;
}
else
waveform2 = waveform;
for (i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = read(audio,&waveform2[i], n*2);
r /= 2;
if (r <= 0)
{
cerr << aud_sys_name << ": failed to read from audio device"
<< endl;
close(audio);
return -1;
}
}
}
else if (actual_fmt == AFMT_U8)
{
inwave.resize((int)(sample_rate*al.fval("-time")));
inwave.set_sample_rate(sample_rate);
num_samples = inwave.num_samples();
waveform = inwave.values().memory();
unsigned char *u8wave = walloc(unsigned char,num_samples);
for (i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = read(audio,&u8wave[i],n);
if (r <= 0)
{
cerr << aud_sys_name << ": failed to read from audio device"
<< endl;
close(audio);
wfree(u8wave);
return -1;
}
}
uchar_to_short(u8wave,waveform,num_samples);
wfree(u8wave);
}
else
{
cerr << aud_sys_name << ": unknown audio format from device: " <<
actual_fmt << endl;
close(audio);
return -1;
}
if (stereo_only)
{
for (i=0; i<num_samples; i+=2)
waveform[i/2] = waveform2[i];
wfree(waveform2);
}
close(audio);
return 0;
}
#else
/*-----------------------------------------------------------------------*/
/* Support for alsa, the voxware stuff just doesn't work on most */
/* machines now. This code is a modification of the vanilla voxware */
/* support */
/* */
/* Based on the alsa support in Flite provided by Lukas Loehrer */
/* */
/*=======================================================================*/
#ifdef SUPPORT_ALSALINUX
#include <sys/ioctl.h>
#include <alsa/asoundlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
static const char *aud_sys_name = "ALSALINUX";
// Code to block signals while sound is playing.
// Needed inside Java on (at least some) linux systems
// as scheduling interrupts seem to break the writes.
int linux16_supported = TRUE;
int freebsd16_supported = FALSE;
#ifdef THREAD_SAFETY
#include <csignal>
#include <pthread.h>
#define THREAD_DECS() \
sigset_t oldmask \
#define THREAD_PROTECT() do { \
sigset_t newmask; \
\
sigfillset(&newmask); \
\
pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); \
} while(0)
#define THREAD_UNPROTECT() do { \
pthread_sigmask(SIG_SETMASK, &oldmask, NULL); \
} while (0)
#else
#define THREAD_DECS() //empty
#define THREAD_PROTECT() //empty
#define THREAD_UNPROTECT() //empty
#endif /* THREAD_SAFETY */
static const char *pcm_dev_name ="default";
typedef enum {
CST_AUDIO_LINEAR16 = 0,
CST_AUDIO_LINEAR8,
CST_AUDIO_MULAW
} cst_audiofmt;
typedef struct cst_audiodev_struct {
int sps, real_sps;
int channels, real_channels;
cst_audiofmt fmt, real_fmt;
int byteswap;
/* cst_rateconv *rateconv; */
void *platform_data;
} cst_audiodev;
static int audio_bps(cst_audiofmt fmt)
{
switch (fmt)
{
case CST_AUDIO_LINEAR16:
return 2;
case CST_AUDIO_LINEAR8:
case CST_AUDIO_MULAW:
return 1;
}
return 0;
}
static inline void print_pcm_state(snd_pcm_t *handle, char *msg)
{
fprintf(stderr, "PCM state at %s = %s\n", msg,
snd_pcm_state_name(snd_pcm_state(handle)));
}
cst_audiodev *audio_open_alsa(int sps, int channels, cst_audiofmt fmt)
{
cst_audiodev *ad;
unsigned int real_rate;
int err;
/* alsa specific stuff */
snd_pcm_t *pcm_handle;
snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
snd_pcm_hw_params_t *hwparams;
snd_pcm_format_t format;
snd_pcm_access_t access = SND_PCM_ACCESS_RW_INTERLEAVED;
/* Allocate the snd_pcm_hw_params_t structure on the stack. */
snd_pcm_hw_params_alloca(&hwparams);
/* Open pcm device */
err = snd_pcm_open(&pcm_handle, pcm_dev_name, stream, 0);
if (err < 0)
{
EST_warning("audio_open_alsa: failed to open audio device %s. %s\n",
pcm_dev_name, snd_strerror(err));
return NULL;
}
/* Init hwparams with full configuration space */
err = snd_pcm_hw_params_any(pcm_handle, hwparams);
if (err < 0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to get hardware parameters from audio device. %s\n", snd_strerror(err));
return NULL;
}
/* Set access mode */
err = snd_pcm_hw_params_set_access(pcm_handle, hwparams, access);
if (err < 0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to set access mode. %s.\n", snd_strerror(err));
return NULL;
}
/* Determine matching alsa sample format */
/* This could be implemented in a more */
/* flexible way (byte order conversion). */
switch (fmt)
{
case CST_AUDIO_LINEAR16:
if (EST_LITTLE_ENDIAN)
format = SND_PCM_FORMAT_S16_LE;
else
format = SND_PCM_FORMAT_S16_BE;
break;
case CST_AUDIO_LINEAR8:
format = SND_PCM_FORMAT_U8;
break;
case CST_AUDIO_MULAW:
format = SND_PCM_FORMAT_MU_LAW;
break;
default:
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to find suitable format.\n");
return NULL;
break;
}
/* Set samble format */
err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format);
if (err <0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to set format. %s.\n", snd_strerror(err));
return NULL;
}
/* Set sample rate near the disired rate */
real_rate = sps;
err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &real_rate, 0);
if (err < 0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to set sample rate near %d. %s.\n", sps, snd_strerror(err));
return NULL;
}
/* Set number of channels */
assert(channels >0);
err = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, channels);
if (err < 0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to set number of channels to %d. %s.\n", channels, snd_strerror(err));
return NULL;
}
/* Commit hardware parameters */
err = snd_pcm_hw_params(pcm_handle, hwparams);
if (err < 0)
{
snd_pcm_close(pcm_handle);
EST_warning("audio_open_alsa: failed to set hw parameters. %s.\n", snd_strerror(err));
return NULL;
}
/* Make sure the device is ready to accept data */
assert(snd_pcm_state(pcm_handle) == SND_PCM_STATE_PREPARED);
/* Write hardware parameters to flite audio device data structure */
ad = walloc(cst_audiodev, 1);
assert(ad != NULL);
ad->real_sps = ad->sps = sps;
ad->real_channels = ad->channels = channels;
ad->real_fmt = ad->fmt = fmt;
ad->platform_data = (void *) pcm_handle;
return ad;
}
int audio_close_alsa(cst_audiodev *ad)
{
int result;
snd_pcm_t *pcm_handle;
if (ad == NULL)
return 0;
pcm_handle = (snd_pcm_t *) ad->platform_data;
snd_pcm_drain(pcm_handle); /* wait for current stuff in buffer to finish */
result = snd_pcm_close(pcm_handle);
if (result < 0)
{
EST_warning("audio_close_alsa: Error: %s.\n", snd_strerror(result));
}
wfree(ad);
return result;
}
/* Returns zero if recovery was successful. */
static int recover_from_error(snd_pcm_t *pcm_handle, ssize_t res)
{
if (res == -EPIPE) /* xrun */
{
res = snd_pcm_prepare(pcm_handle);
if (res < 0)
{
/* Failed to recover from xrun */
EST_warning("recover_from_write_error: failed to recover from xrun. %s\n.", snd_strerror(res));
return res;
}
}
else if (res == -ESTRPIPE) /* Suspend */
{
while ((res = snd_pcm_resume(pcm_handle)) == -EAGAIN)
{
snd_pcm_wait(pcm_handle, 1000);
}
if (res < 0)
{
res = snd_pcm_prepare(pcm_handle);
if (res <0)
{
/* Resume failed */
EST_warning("audio_recover_from_write_error: failed to resume after suspend. %s\n.", snd_strerror(res));
return res;
}
}
}
else if (res < 0)
{
/* Unknown failure */
EST_warning("audio_recover_from_write_error: %s.\n", snd_strerror(res));
return res;
}
return 0;
}
int audio_write_alsa(cst_audiodev *ad, void *samples, int num_bytes)
{
size_t frame_size;
ssize_t num_frames, res;
snd_pcm_t *pcm_handle;
char *buf = (char *) samples;
/* Determine frame size in bytes */
frame_size = audio_bps(ad->real_fmt) * ad->real_channels;
/* Require that only complete frames are handed in */
assert((num_bytes % frame_size) == 0);
num_frames = num_bytes / frame_size;
pcm_handle = (snd_pcm_t *) ad->platform_data;
while (num_frames > 0)
{
res = snd_pcm_writei(pcm_handle, buf, num_frames);
if (res != num_frames)
{
if (res == -EAGAIN || (res > 0 && res < num_frames))
{
snd_pcm_wait(pcm_handle, 100);
}
else if (recover_from_error(pcm_handle, res) < 0)
{
return -1;
}
}
if (res >0)
{
num_frames -= res;
buf += res * frame_size;
}
}
return num_bytes;
}
int audio_flush_alsa(cst_audiodev *ad)
{
int result;
result = snd_pcm_drain((snd_pcm_t *) ad->platform_data);
if (result < 0)
{
EST_warning("audio_flush_alsa: Error: %s.\n", snd_strerror(result));
}
/* Prepare device for more data */
result = snd_pcm_prepare((snd_pcm_t *) ad->platform_data);
if (result < 0)
{
EST_warning("audio_flush_alsa: Error: %s.\n", snd_strerror(result));
}
return result;
}
int audio_drain_alsa(cst_audiodev *ad)
{
int result;
result = snd_pcm_drop((snd_pcm_t *) ad->platform_data);
if (result < 0)
{
EST_warning("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
}
/* Prepare device for more data */
result = snd_pcm_prepare((snd_pcm_t *) ad->platform_data);
if (result < 0)
{
EST_warning("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
}
return result;
}
#define AUDIOBUFFSIZE 256
// #define AUDIOBUFFSIZE 20480
int play_linux_wave(EST_Wave &inwave, EST_Option &al)
{
int sample_rate;
short *waveform;
int num_samples;
const char *audiodevice;
cst_audiodev *ad;
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/dsp";
waveform = inwave.values().memory();
num_samples = inwave.num_samples();
sample_rate = inwave.sample_rate();
ad = audio_open_alsa(sample_rate,1,CST_AUDIO_LINEAR16);
THREAD_DECS();
THREAD_PROTECT();
audio_write_alsa(ad,waveform,num_samples*sizeof(short));
audio_close_alsa(ad);
THREAD_UNPROTECT();
return 1;
}
int record_linux_wave(EST_Wave &inwave, EST_Option &al)
{
#if 0
int sample_rate=16000; // egcs needs the initialized for some reason
short *waveform;
short *waveform2=0;
int num_samples;
int audio=-1,actual_fmt;
int i,r,n;
char *audiodevice;
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else
audiodevice = "/dev/dsp";
sample_rate = al.ival("-sample_rate");
if ((audio = open(audiodevice,O_RDONLY)) == -1)
{
cerr << aud_sys_name << ": can't open " << audiodevice
<< "for reading" << endl;
return -1;
}
actual_fmt = sb_set_sample_rate(audio,sample_rate);
if ((actual_fmt == AFMT_S16_LE) ||
(actual_fmt == AFMT_S16_BE))
{
// We assume that the device returns audio in native byte order
// by default
inwave.resize((int)(sample_rate*al.fval("-time")));
inwave.set_sample_rate(sample_rate);
num_samples = inwave.num_samples();
waveform = inwave.values().memory();
if (stereo_only)
{
waveform2 = walloc(short,num_samples*2);
num_samples *= 2;
}
else
waveform2 = waveform;
for (i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = read(audio,&waveform2[i], n*2);
r /= 2;
if (r <= 0)
{
cerr << aud_sys_name << ": failed to read from audio device"
<< endl;
close(audio);
return -1;
}
}
}
else if (actual_fmt == AFMT_U8)
{
inwave.resize((int)(sample_rate*al.fval("-time")));
inwave.set_sample_rate(sample_rate);
num_samples = inwave.num_samples();
waveform = inwave.values().memory();
unsigned char *u8wave = walloc(unsigned char,num_samples);
for (i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = read(audio,&u8wave[i],n);
if (r <= 0)
{
cerr << aud_sys_name << ": failed to read from audio device"
<< endl;
close(audio);
wfree(u8wave);
return -1;
}
}
uchar_to_short(u8wave,waveform,num_samples);
wfree(u8wave);
}
else
{
cerr << aud_sys_name << ": unknown audio format from device: " <<
actual_fmt << endl;
close(audio);
return -1;
}
if (stereo_only)
{
for (i=0; i<num_samples; i+=2)
waveform[i/2] = waveform2[i];
wfree(waveform2);
}
close(audio);
#endif /* 0 */
return 0;
}
#else
#ifdef SUPPORT_PULSEAUDIO
#include <pulse/simple.h>
int freebsd16_supported = FALSE;
int linux16_supported = TRUE;
static const char *aud_sys_name = "PULSEAUDIO";
#define AUDIOBUFFSIZE 256
// #define AUDIOBUFFSIZE 20480
int play_linux_wave(EST_Wave &inwave, EST_Option &al)
{
pa_sample_spec *ss;
pa_simple *s;
short *waveform;
int num_samples;
int err=0, i, r;
ss = walloc(pa_sample_spec,1);
ss->rate = inwave.sample_rate();
ss->channels = inwave.num_channels();
if (EST_BIG_ENDIAN)
ss->format = PA_SAMPLE_S16BE;
else
ss->format = PA_SAMPLE_S16LE;
s = pa_simple_new(
NULL, /* use default server */
"festival",
PA_STREAM_PLAYBACK,
NULL, /* use default device */
"Speech",
ss,
NULL, /* default channel map */
NULL, /* default buffering attributes */
&err);
if (err < 0)
return NULL;
waveform = inwave.values().memory();
num_samples = inwave.num_samples();
for (i=0; i < num_samples; i += AUDIOBUFFSIZE/2)
{
if (i + AUDIOBUFFSIZE/2 < num_samples)
pa_simple_write(s,&waveform[i],(size_t)AUDIOBUFFSIZE,&err);
else
pa_simple_write(s,&waveform[i],(size_t)(num_samples-i)*2,&err);
}
pa_simple_drain(s,&err);
pa_simple_free(s);
wfree(ss);
return 1;
}
int record_linux_wave(EST_Wave &inwave, EST_Option &al)
{
return -1;
}
#else /* not supported */
int freebsd16_supported = FALSE;
int linux16_supported = FALSE;
int play_linux_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "MacOS X audio support not compiled." << endl;
return -1;
}
int record_linux_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "MacOS X audio support not compiled." << endl;
return -1;
}
#endif /* ALSA */
#endif /* PULSEAUDIO */
#endif /* VOXWARE */

227
audio/macosxaudio.cc Normal file
View File

@ -0,0 +1,227 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996-2009 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Brian Foley */
/* bfoley@compsoc.nuigalway.ie */
/* Date : February 2004 */
/*************************************************************************/
/* OSX 10.6 updates */
/* Author : Rob Clark */
/* robert@cstr.ed.ac.uk */
/* Date : Jan 2009 */
/*=======================================================================*/
#include "EST_unix.h"
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#if defined (SUPPORT_MACOSX_AUDIO)
#include <CoreServices/CoreServices.h>
#include <stdio.h>
#include <unistd.h>
#include <CoreAudio/CoreAudio.h>
#include <AudioUnit/AudioUnit.h>
int macosx_supported = TRUE;
AudioUnit outau;
EST_SMatrix *waveMatrix;
UInt32 waveSize;
UInt32 waveIndex;
bool done;
OSStatus render_callback(void *inref,
AudioUnitRenderActionFlags *inflags,
const AudioTimeStamp *instamp,
UInt32 inbus,
UInt32 inframes,
AudioBufferList *ioData)
{
// fill each channel with available audio data
UInt32 channels = ioData->mNumberBuffers;
int totalNumberOfBytes = waveSize;
int channelBytesLeft = totalNumberOfBytes - waveIndex;
int bufferSize = ioData->mBuffers[0].mDataByteSize;
if(channelBytesLeft > 0) {
if(channelBytesLeft < bufferSize) {
for(UInt32 i = 0; i < channels; ++i) {
waveMatrix->copy_column((int)i, (int short*)ioData->mBuffers[i].mData, waveIndex/2, channelBytesLeft/2);
memset((char*)ioData->mBuffers[i].mData + channelBytesLeft, 0, bufferSize - channelBytesLeft) ;
}
waveIndex += channelBytesLeft;
} else {
for(UInt32 i = 0; i < channels; ++i)
waveMatrix->copy_column((int)i, (int short*)ioData->mBuffers[i].mData, waveIndex/2, bufferSize/2);
waveIndex += bufferSize;
}
} else {
for(UInt32 i = 0; i < channels; ++i)
memset(ioData->mBuffers[i].mData, 0, ioData->mBuffers[i].mDataByteSize);
done = TRUE;
}
return noErr;
}
void CreateDefaultAU()
{
OSStatus err = noErr;
// Open the default output unit
ComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
Component comp = FindNextComponent(NULL, &desc);
if (comp == NULL) { printf ("FindNextComponent\n"); return; }
err = OpenAComponent(comp, &outau);
if (comp == NULL) { printf ("OpenAComponent=%ld\n", long(err)); return; }
// Set up render callback
AURenderCallbackStruct input;
input.inputProc = render_callback;
input.inputProcRefCon = NULL;
err = AudioUnitSetProperty (outau,
kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input,
0,
&input,
sizeof(input));
if (err) { printf ("AudioUnitSetProperty-CB=%ld\n", long(err)); return; }
}
int play_macosx_wave(EST_Wave &inwave, EST_Option &al)
{
OSStatus err;
AudioStreamBasicDescription waveformat, outformat;
UInt32 size = sizeof(AudioStreamBasicDescription);
UInt32 running;
CreateDefaultAU();
// The EST_Wave structure will allow us to access individula channels
// so this is set up using kAudioFormatFlagIsNonInterleaved format.
// Here the per packet and per frame info is per channel.
waveformat.mSampleRate = (Float64)inwave.sample_rate();
waveformat.mFormatID = kAudioFormatLinearPCM;
waveformat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger
| kAudioFormatFlagsNativeEndian
| kLinearPCMFormatFlagIsPacked
| kAudioFormatFlagIsNonInterleaved;
waveformat.mFramesPerPacket = 1;
waveformat.mChannelsPerFrame = inwave.num_channels();
waveformat.mBytesPerPacket = 2;
waveformat.mBytesPerFrame = 2;
waveformat.mBitsPerChannel = 16;
err = AudioUnitSetProperty(outau,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&waveformat,
size);
if (err != noErr) {
cerr << "Error setting input audio stream format." << endl;
CloseComponent(outau);
return -1;
}
err = AudioUnitGetProperty(outau,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
0,
&outformat,
&size);
if (err != noErr) {
cerr << "Error getting output audio stream format." << endl;
CloseComponent(outau);
return -1;
}
err = AudioUnitInitialize(outau);
if (err) {
printf ("AudioUnitInitialize=%ld\n", long(err));
return -1;
}
// set up for playing
waveSize = inwave.num_samples()*sizeof(short);
waveMatrix = &inwave.values();
done = FALSE;
waveIndex = 0;
err = AudioOutputUnitStart(outau);
if (err != noErr) {
cerr << "Error starting audio outup: " << err << endl;
CloseComponent(outau);
return -1;
}
// Poll every 50ms whether the sound has stopped playing yet.
// Probably not the best way of doing things.
size = sizeof(UInt32);
do {
usleep(50 * 1000);
err = AudioUnitGetProperty(outau, kAudioOutputUnitProperty_IsRunning,
kAudioUnitScope_Global, 0, &running, &size);
} while (err == noErr && running && !done);
CloseComponent (outau);
return 1;
}
#else
int macosx_supported = FALSE;
int play_macosx_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "OS X Core Audio in not supported in this configuration." << endl;
return -1;
}
#endif

106
audio/mplayer.cc Normal file
View File

@ -0,0 +1,106 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Richard Caley */
/* Date : August 1997 */
/*-----------------------------------------------------------------------*/
/* Optional 16bit linear support for Windows NT/95 */
/* */
/*=======================================================================*/
#include <cstdio>
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "EST_io_aux.h"
#include "EST_Pathname.h"
#ifdef SUPPORT_MPLAYER
int mplayer_supported = TRUE;
static EST_Pathname tempfile;
static EST_Pathname temppath;
static EST_Pathname tempdir;
static void find_tempfile(void)
{
const char *s=NULL;
if (!(s=getenv("TMP")))
if (!(s=getenv("TMPDIR")))
if (!(s=getenv("TEMPDIR")))
s="\tmp";
tempdir = s;
char buffer[512];
sprintf(buffer, "est%4d.wav", getpid());
tempfile = buffer;
temppath = EST_Pathname::append(tempdir.as_directory(), tempfile);
}
int play_mplayer_wave(EST_Wave &inwave, EST_Option &al)
{
if (tempfile == "")
find_tempfile();
inwave.save(temppath, "riff");
char command[1000];
sprintf(command,
"mplayer /play %s\\%s",
(const char *)tempdir,
(const char *)tempfile);
cout << "command '" << command <<"'\n";
system(command);
unlink(temppath);
return 1;
}
#else
int mplayer_supported = FALSE;
int play_mplayer_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Windows mplayer not supported" << endl;
return -1;
}
#endif

185
audio/nas.cc Normal file
View File

@ -0,0 +1,185 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor & Alan Black */
/* Date : April 1995 & 96 */
/*-----------------------------------------------------------------------*/
/* Playback function for NCD's NAS server (formerly called netaudio) */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sys/stat.h>
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#ifdef SUPPORT_NAS
#include <audio/audiolib.h>
#include <audio/soundlib.h>
#define VOL(volume) ((1 << 16) * (volume) / 100)
#define au_serverrate 16000
static int nas_playing = 0;
int nas_supported = TRUE;
int endian_int = 1;
#define NAS_BIG_ENDIAN (((char *)&endian_int)[0] == 0)
static void na_sync_play_cb(AuServer *aud, AuEventHandlerRec *handler,
AuEvent *ev, AuPointer data)
{
int *d = (int *) data;
(void)aud; // unused parameter
(void)handler; // unused parameter
(void)ev; // unused parameter
nas_playing = 0;
*d = 1;
return;
}
int play_nas_wave(EST_Wave &inwave, EST_Option &al)
{
AuServer *aud = NULL;
/* legal sampling frequencies for Sun dbri device */
/* But what about when we are using Linux of FreeBSD ? */
int dev_sr[] = {8000, 9600, 11025, 16000, 18900, 22050, 32000,
37800, 44100, 48000, -1};
Sound in;
char *auservername = NULL;
int d = 0;
int i;
int ret;
AuEvent ev;
AuEventHandlerRec *er;
short *waveform;
int num_samps, samp_rate;
if (al.present("-display"))
auservername = wstrdup(al.val("-display"));
aud = AuOpenServer(auservername, 0, NULL, 0, NULL, NULL);
if (aud == NULL)
{
cerr << "Can't access NAS server " << auservername << endl;
return -1;
}
/* Check sample rate of server -- should really check the if it */
/* only supports individual sample rate of which this wave is not */
/* one then we should resample. */
samp_rate = inwave.sample_rate();
bool samp_rate_ok = FALSE;
for (i=0; dev_sr[i] != -1; i++)
if (samp_rate == dev_sr[i])
samp_rate_ok = TRUE;
if (samp_rate_ok == FALSE)
{
if (samp_rate == 10000)
inwave.resample(9600); // just sounds much better than 16000
else
inwave.resample(16000);
}
waveform = inwave.values().memory();
num_samps = inwave.num_samples();
samp_rate = inwave.sample_rate();
if (num_samps > 0)
{
if (inwave.sample_type() == "mulaw")
in = SoundCreate(SoundFileFormatNone,
AuFormatULAW8,
inwave.num_channels(),
samp_rate, num_samps, NULL);
else
in = SoundCreate(SoundFileFormatNone,
(NAS_BIG_ENDIAN ?
AuFormatLinearSigned16MSB :
AuFormatLinearSigned16LSB),
inwave.num_channels(),
samp_rate, num_samps,NULL);
er = AuSoundPlayFromData(aud, in, waveform, AuNone, VOL(100),
na_sync_play_cb,
(AuPointer) &d,(AuFlowID *) NULL,
(int *) NULL, (int *) NULL, &ret);
while (1)
{
AuNextEvent(aud, AuTrue, &ev);
AuDispatchEvent(aud, &ev);
if (d) break;
}
}
AuCloseServer(aud);
return 1;
}
int record_nas_wave(EST_Wave &wave, EST_Option &al)
{
(void)wave;
(void)al;
cerr << "NAS: record not written yet\n";
return -1;
}
#else
int nas_supported = FALSE;
int play_nas_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "NAS playback not supported" << endl;
return -1;
}
int record_nas_wave(EST_Wave &wave, EST_Option &al)
{
(void)wave;
(void)al;
cerr << "NAS record not supported" << endl;
return -1;
}
#endif

269
audio/os2audio.cc Normal file
View File

@ -0,0 +1,269 @@
/* Check all of ./speech_tools and ./festival for reference to win32audio, */
/* and add the equivalent for the os2audio module. You will need -los2me */
/* to compile this os2audio module. */
/* OS/2 16bit realtime DART Audio support for Festival */
/* Samuel Audet <guardia@cam.org> */
/* DeviceID is setup in here. Can be used as an external variable! */
#ifdef SUPPORT_OS2AUDIO
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#include "EST_unix.h"
int os2audio_supported = TRUE;
#define INCL_OS2MM
#define INCL_DOS
#include <os2.h>
#include <os2me.h>
USHORT DeviceID = 0; /* 0 = default sound device, 1 = 1st sound device, etc. */
/* new stuff */
#define MIX_BUFFER_EOS 1
#define NUM_BUFFERS 8 /* Number of audio buffer usable */
static ULONG ulMCIBuffers; /* warning, minimum 2 */
static MCI_AMP_OPEN_PARMS maop;
static MCI_MIXSETUP_PARMS mmp;
static MCI_BUFFER_PARMS mbp;
static MCI_GENERIC_PARMS mgp = {0};
static MCI_MIX_BUFFER MixBuffers[NUM_BUFFERS];
static unsigned char *wave, *startwave, *endwave;
static ULONG sizewave;
static HEV dataplayed;
static void MciError(ULONG ulError)
{
unsigned char buffer[128];
unsigned char string[128];
ULONG rc;
rc = mciGetErrorString(ulError, buffer, sizeof(buffer));
if (rc == MCIERR_SUCCESS)
sprintf(string,"MCI Error %d: %s",ULONG_LOWD(ulError),buffer);
else
sprintf(string,"MCI Error %d: Cannot query error message.",ULONG_LOWD(rc));
cerr << string << endl;
}
static LONG APIENTRY MyEvent(ULONG ulStatus, PMCI_MIX_BUFFER PlayedBuffer, ULONG ulFlags)
{
if(PlayedBuffer->ulFlags == MIX_BUFFER_EOS)
DosPostEventSem(dataplayed);
else
switch(ulFlags)
{
case MIX_STREAM_ERROR | MIX_WRITE_COMPLETE: /* error occur in device */
if ( ulStatus == ERROR_DEVICE_UNDERRUN)
/* Write buffers to rekick off the amp mixer. */
mmp.pmixWrite( mmp.ulMixHandle,
MixBuffers,
ulMCIBuffers );
break;
case MIX_WRITE_COMPLETE: /* for playback */
if(wave < endwave)
{
/* copy new data in the played buffer */
if(wave + PlayedBuffer->ulBufferLength >= endwave)
{
PlayedBuffer->ulFlags = MIX_BUFFER_EOS; /* set end of stream */
PlayedBuffer->ulBufferLength = (ULONG) (endwave - wave);
}
memcpy(PlayedBuffer->pBuffer, wave, PlayedBuffer->ulBufferLength);
wave += PlayedBuffer->ulBufferLength;
mmp.pmixWrite( mmp.ulMixHandle,
PlayedBuffer /* contains new data */,
1 );
}
break;
} /* end switch */
return( TRUE );
} /* end MyEvent */
int play_os2audio_wave(EST_Wave &inwave, EST_Option &al)
{
ULONG i,rc;
startwave = (unsigned char *) inwave.values().memory();
sizewave = inwave.num_samples()*sizeof(short)*inwave.num_channels();
endwave = startwave + sizewave;
wave = startwave;
/* open the mixer device */
memset (&maop, 0, sizeof(maop));
maop.usDeviceID = 0;
maop.pszDeviceType = (PSZ) MAKEULONG(MCI_DEVTYPE_AUDIO_AMPMIX, DeviceID);
rc = mciSendCommand(0,
MCI_OPEN,
MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
&maop,
0);
if (rc != MCIERR_SUCCESS)
{
MciError(rc);
return(-1);
}
/* Set the MCI_MIXSETUP_PARMS data structure to match the audio stream. */
memset(&mmp, 0, sizeof(mmp));
mmp.ulBitsPerSample = 16;
mmp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
mmp.ulSamplesPerSec = inwave.sample_rate();
mmp.ulChannels = inwave.num_channels();
/* Setup the mixer for playback of wave data */
mmp.ulFormatMode = MCI_PLAY;
mmp.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
mmp.pmixEvent = MyEvent;
rc = mciSendCommand( maop.usDeviceID,
MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_INIT,
&mmp,
0 );
if ( rc != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
/* Set up the BufferParms data structure and allocate
* device buffers from the Amp-Mixer */
ulMCIBuffers = NUM_BUFFERS;
mbp.ulNumBuffers = ulMCIBuffers;
mbp.ulBufferSize = mmp.ulBufferSize;
memset(MixBuffers, 0, sizeof(MixBuffers[0])*NUM_BUFFERS);
mbp.pBufList = MixBuffers;
rc = mciSendCommand( maop.usDeviceID,
MCI_BUFFER,
MCI_WAIT | MCI_ALLOCATE_MEMORY,
(PVOID) &mbp,
0 );
if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
ulMCIBuffers = mbp.ulNumBuffers; /* never know! */
/* Fill all device buffers with data from the wave stream. */
for(i = 0; i < ulMCIBuffers; i++)
{
if(wave < endwave)
{
MixBuffers[i].ulFlags = 0;
MixBuffers[i].ulBufferLength = mbp.ulBufferSize;
if(wave + MixBuffers[i].ulBufferLength >= endwave)
{
MixBuffers[i].ulFlags = MIX_BUFFER_EOS; /* set end of stream */
MixBuffers[i].ulBufferLength = (ULONG) (endwave - wave);
}
memcpy(MixBuffers[i].pBuffer, wave, MixBuffers[i].ulBufferLength);
wave += MixBuffers[i].ulBufferLength;
}
}
/* Create a semaphore to know when data has been played by the DART thread */
DosCreateEventSem(NULL,&dataplayed,0,FALSE);
/* Write buffers to kick off the amp mixer. */
rc = mmp.pmixWrite( mmp.ulMixHandle,
MixBuffers,
ulMCIBuffers );
if ( rc != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
DosWaitEventSem(dataplayed, -1);
DosCloseEventSem(dataplayed);
rc = mciSendCommand( maop.usDeviceID,
MCI_BUFFER,
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
&mbp,
0 );
if ( rc != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
rc = mciSendCommand( maop.usDeviceID,
MCI_CLOSE,
MCI_WAIT ,
&mgp,
0 );
if ( rc != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
return TRUE;
}
#else
# include "EST_Wave.h"
# include "EST_Option.h"
int os2audio_supported = FALSE;
int play_os2audio_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "OS/2 16bit realtime DART playback not supported." << endl;
return -1;
}
#endif

336
audio/sun16audio.cc Normal file
View File

@ -0,0 +1,336 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : July 1997 */
/*-----------------------------------------------------------------------*/
/* Optional Sun 16bit linear support for /dev/audio */
/* This only works when compiled under Solaris or SunOS as it requires */
/* Sun's headers, and much more importantly Sun's /dev/audio. This */
/* of course will access the *local* machine's /dev/audio definite not */
/* the "network is the computer" maxim but sometimes you might want */
/* this */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "audioP.h"
#include "EST_io_aux.h"
#include "EST_unix.h"
#ifdef SUPPORT_SUN16
#include <sys/filio.h>
#if defined(__svr4__) || defined(SYSV) || defined(SVR4)
/* Solaris */
#include <sys/audioio.h>
#else
/* Sunos */
#include <sun/audioio.h>
#endif
static int sun16_check_device(int audio);
static int sun16_set_info(int audio, int sample_rate);
int sun16_supported = TRUE;
/* supported sampling frequencies for Sun dbri device */
static int dev_sr[] = {8000, 9600, 11025, 16000, 18900, 22050, 32000,
37800, 44100, 48000, -1};
#define AUDIOBUFFSIZE 256
int play_sun16_wave(EST_Wave &inwave, EST_Option &al)
{
int sample_rate;
short *waveform;
FILE *fdaudio;
int num_samples;
int audio;
int i,r,n;
char *audiodevice;
sample_rate = inwave.sample_rate();
int samp_rate_ok = FALSE;
for (i=0; dev_sr[i] != -1; i++)
if (sample_rate == dev_sr[i])
samp_rate_ok = TRUE;
if (samp_rate_ok == FALSE)
{
if (sample_rate == 10000)
inwave.resample(9600); // just sounds much better than 16000
else
inwave.resample(16000);
}
if (al.present("-audiodevice"))
audiodevice = al.val("-audiodevice");
else if ((audiodevice = getenv("AUDIODEV")) == NULL)
audiodevice = "/dev/audio";
if ((fdaudio = fopen(audiodevice,"wb")) == NULL)
{
cerr << "SUN16: can't open " << audiodevice << endl;
return -1;
}
// As I can't find open in an Sun CC include file I'll avoid it
audio = fileno(fdaudio);
waveform = inwave.values().memory();
num_samples = inwave.num_samples();
sample_rate = inwave.sample_rate();
if (sun16_check_device(audio) == FALSE)
{
cerr << "SUN16: device doesn't support 16bit linear." << endl;
fclose(fdaudio);
return -1;
}
if (sun16_set_info(audio,sample_rate) == FALSE)
{
cerr << "SUN16: unable to set sample rate " <<
sample_rate << endl;
fclose(fdaudio);
return -1;
}
for (i=0; i < num_samples; i += r/2)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
r = write(audio,&waveform[i], n*2);
if (r == 0)
{
cerr << "SUN16: failed to write to buffer" <<
sample_rate << endl;
fclose(fdaudio);
return -1;
}
// needed to prevent foul ups under Java.
// ioctl(audio, AUDIO_DRAIN, 0);
}
fclose(fdaudio);
return 1;
}
static int sun16_check_device(int audio)
{
#ifdef __svr4__
/* Solaris */
audio_device_t type;
ioctl(audio, AUDIO_DRAIN, 0); /* drain everything out */
if ((ioctl(audio, AUDIO_GETDEV, &type) != -1) &&
((streq("SUNW,CS4231",type.name)) || /* Newer Suns (ultras) */
(streq("SUNW,dbri",type.name)) || /* Older Suns (SS10s SS20s) */
(streq("SUNW,audiots",type.name)) || /* For stations more advanced than ultras */
(streq("SUNW,sb16",type.name)))) /* i386 machines */
return TRUE;
else
return FALSE;
#else
/* SunOS */
int type;
ioctl(audio, AUDIO_DRAIN, 0); /* drain everything out */
if ((ioctl(audio, AUDIO_GETDEV, &type) != -1) &&
((type == AUDIO_DEV_SPEAKERBOX) || (type == AUDIO_DEV_CODEC)))
return TRUE;
else
return FALSE;
#endif
}
static int sun16_set_info(int audio, int sample_rate)
{
audio_info_t info;
ioctl(audio, AUDIO_GETINFO, &info);
info.play.sample_rate = sample_rate;
info.play.encoding = AUDIO_ENCODING_LINEAR;
info.play.precision = 16;
info.play.channels = 1;
if (ioctl(audio, AUDIO_SETINFO, &info) == -1)
return FALSE;
else
return TRUE;
}
static int sun16_setrecord_info(int audio, int sample_rate)
{
/* As the device is always recording, changing sample rate/encoding */
/* can mess up the stream, so stop recording, flush the buffer and */
/* then set the formats and restart recording */
audio_info_t info;
int read_size,i,r;
unsigned char buff[64];
ioctl(audio, AUDIO_GETINFO, &info);
info.record.pause = 1;
ioctl(audio, AUDIO_SETINFO, &info);
/* Read any existing recorded stuff in the buffer */
ioctl(audio, FIONREAD, &read_size);
for (r=i=0; (i < read_size); i += r)
r = read(audio,buff,64);
/* Now set up the recording format */
ioctl(audio, AUDIO_GETINFO, &info);
info.record.sample_rate = sample_rate;
info.record.encoding = AUDIO_ENCODING_LINEAR;
info.record.precision = 16;
info.record.channels = 1;
info.record.pause = 0;
info.record.samples = 0;
info.record.error = 0;
if (ioctl(audio, AUDIO_SETINFO, &info) == -1)
return FALSE;
else
return TRUE;
}
int record_sun16_wave(EST_Wave &wave, EST_Option &al)
{
int desired_sample_rate = 16000;
int actual_sample_rate;
short *waveform;
int audio=-1;
int num_samples;
int i,r,n;
desired_sample_rate = al.ival("-sample_rate");
actual_sample_rate = -1;
for (i=0; dev_sr[i] != -1; i++)
if (desired_sample_rate == dev_sr[i])
actual_sample_rate = desired_sample_rate;
if (actual_sample_rate == -1)
actual_sample_rate = 16000;
if ((audio = open("/dev/audio",O_RDONLY)) == -1)
{
cerr << "SUN16: can't open /dev/audio for reading" << endl;
return -1;
}
if (sun16_check_device(audio) == FALSE)
{
cerr << "SUN16: device doesn't support 16bit linear." << endl;
close(audio);
return -1;
}
if (sun16_setrecord_info(audio,actual_sample_rate) == FALSE)
{
cerr << "SUN16: unable to set sample rate " <<
actual_sample_rate << endl;
close(audio);
return -1;
}
wave.resize((int)(actual_sample_rate*al.fval("-time")));
wave.set_sample_rate(actual_sample_rate);
num_samples = wave.num_samples();
waveform = wave.values().memory();
int read_size;
for (r=i=0; i < num_samples; i+= r)
{
if (num_samples > i+AUDIOBUFFSIZE)
n = AUDIOBUFFSIZE;
else
n = num_samples-i;
ioctl(audio, FIONREAD, &read_size);
if (read_size == 0)
{
r = 0;
continue; // nothing to read yet
}
if (n > read_size/2)
n = read_size/2;
r = read(audio,&waveform[i], n*2);
r /= 2;
if (r <= 0)
{
cerr << "SUN16: failed to read from audio device" << endl;
close(audio);
return -1;
}
}
close(audio);
if (actual_sample_rate != desired_sample_rate)
wave.resample(desired_sample_rate);
return 0;
}
#else
int sun16_supported = FALSE;
int play_sun16_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Sun 16bit linear not supported" << endl;
return -1;
}
int record_sun16_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Sun 16bit linear not supported" << endl;
return -1;
}
#endif

134
audio/win32audio.cc Normal file
View File

@ -0,0 +1,134 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Richard Caley */
/* Date : August 1997 */
/*-----------------------------------------------------------------------*/
/* Optional 16bit linear support for Windows NT/95 */
/* */
/*=======================================================================*/
#include <cstdio>
#include "EST_cutils.h"
#include "EST_Wave.h"
#include "EST_Option.h"
#include "EST_io_aux.h"
#include "EST_Pathname.h"
#ifdef SUPPORT_WIN32AUDIO
#include <EST_system.h>
#ifdef SYSTEM_IS_UNIX
// Even if we think we are unix, this must be Win32 if we are asked
// to support win32 audio, presumably under cygnus gunwin32 These definitions
// aren't in the gnuwin32 headers
#undef TRUE
#undef FALSE
/* Changed for cygwin 1
#include <Windows32/BASE.h>
#define SND_MEMORY 0x0004
#define WAVE_FORMAT_PCM 1
*/
#include <windows.h>
/* This is no longer required
extern "C" {
WINBOOL STDCALL PlaySoundA(LPCSTR pszSound, HMODULE hmod, DWORD fdwSound);
};
#define PlaySound PlaySoundA
*/
#endif
int win32audio_supported = TRUE;
struct riff_header {
char riff[4];
int file_size;
char wave[4];
char fmt[4];
int header_size;
short sample_format;
short n_channels;
int sample_rate;
int bytes_per_second;
short block_align;
short bits_per_sample;
char data[4];
int data_size;
};
int play_win32audio_wave(EST_Wave &inwave, EST_Option &al)
{
char *buffer = new char[sizeof(riff_header) + inwave.length()*inwave.num_channels() * sizeof(short)];
struct riff_header *hdr = (struct riff_header *)buffer;
char *data = buffer + sizeof(struct riff_header);
strncpy(hdr->riff, "RIFF", 4);
hdr->file_size = sizeof(riff_header) + inwave.length()*sizeof(short);
strncpy(hdr->wave, "WAVE", 4);
strncpy(hdr->fmt, "fmt ", 4);
hdr->header_size = 16;
hdr->sample_format = WAVE_FORMAT_PCM;
hdr->n_channels = inwave.num_channels();
hdr->sample_rate = inwave.sample_rate();
hdr->bytes_per_second = hdr->sample_rate * hdr->n_channels * 2;
hdr->block_align = hdr->n_channels * 2;
hdr->bits_per_sample = 16;
strncpy(hdr->data, "data", 4);
hdr->data_size = hdr->n_channels * 2 * inwave.num_samples();
memcpy(data, inwave.values().memory(), hdr->n_channels * 2 * inwave.num_samples());
PlaySound( buffer,
NULL,
SND_MEMORY);
delete [] buffer;
return 1;
}
#else
int win32audio_supported = FALSE;
int play_win32audio_wave(EST_Wave &inwave, EST_Option &al)
{
(void)inwave;
(void)al;
cerr << "Windows win32 audio not supported" << endl;
return -1;
}
#endif

115
base_class/EST_Complex.cc Normal file
View File

@ -0,0 +1,115 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : December 1997 */
/*-----------------------------------------------------------------------*/
/* */
/*=======================================================================*/
#include "EST_Complex.h"
// Addition
EST_Complex operator + (const EST_Complex& z1, const EST_Complex &z2)
{
return EST_Complex(z1.r + z2.r, z1.i + z2.i);
}
EST_Complex operator + (const EST_Complex& z, float x)
{
return EST_Complex(z.r + x, z.i);
}
EST_Complex operator + (float x, const EST_Complex &z)
{
return EST_Complex(z.r + x, z.i);
}
// Subtraction
EST_Complex operator - (const EST_Complex& z1, const EST_Complex &z2)
{
return EST_Complex(z1.r - z2.r, z1.i - z2.i);
}
EST_Complex operator - (const EST_Complex& z, float x)
{
return EST_Complex(z.r -x, z.i);
}
EST_Complex operator - (float x, const EST_Complex &z)
{
return EST_Complex(x - z.r, - z.i);
}
// Multiplication
EST_Complex operator * (const EST_Complex& z1, const EST_Complex &z2)
{
return EST_Complex((z1.r * z2.r) - (z1.i * z2.i), (z1.r * z2.i) + (z1.i * z2.r));
}
EST_Complex operator * (const EST_Complex& z, float x)
{
return EST_Complex(z.r * x, z.i *x);
}
EST_Complex operator * (float x, const EST_Complex &z)
{
return EST_Complex(z.r * x, z.i *x);
}
// Division
EST_Complex operator / (const EST_Complex& z1, const EST_Complex &z2)
{
double m = z1.mag();
EST_Complex inv(z1.r / m, z1.i /m);
return inv * z2;
}
EST_Complex operator / (const EST_Complex& z, float x)
{
return EST_Complex(z.r / x, z.i / x);
}
EST_Complex operator / (float x, const EST_Complex &z)
{
EST_Complex a(x, 0.0);
return (z / a);
}

815
base_class/EST_DMatrix.cc Normal file
View File

@ -0,0 +1,815 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Simon King */
/* Date : February 1999 */
/* --------------------------------------------------------------------- */
/* Double matrix class - copied from DMatrix ! */
/* */
/*************************************************************************/
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <climits>
#include "EST_String.h"
#include "EST_types.h"
#include "EST_FileType.h"
#include "EST_Option.h"
#include "EST_DMatrix.h"
#include "EST_cutils.h" // for swap functions
#include "EST_Token.h"
#include "rateconv.h"
EST_String EST_DMatrix::default_file_type = "est_ascii";
EST_DMatrix::EST_DMatrix(const EST_DMatrix &a, int b)
:EST_TSimpleMatrix<double>(a.num_rows(), a.num_columns())
{
double vv = 0.0;
if (b < 0)
return;
if (b == 0)
fill(vv);
}
EST_DMatrix & EST_DMatrix::operator+=(const EST_DMatrix &a)
{
int i, j;
if (a.num_columns() != num_columns())
{
cerr <<"Matrix addition error: bad number of columns\n";
return *this;
}
if (a.num_rows() != num_rows())
{
cerr <<"Matrix addition error: bad number of rows\n";
return *this;
}
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) += a.a_no_check(i,j);
return *this;
}
EST_DMatrix & EST_DMatrix::operator-=(const EST_DMatrix &a)
{
int i, j;
if (a.num_columns() != num_columns())
{
cerr <<"Matrix subtraction error: bad number of columns\n";
return *this;
}
if (a.num_rows() != num_rows())
{
cerr <<"Matrix subtraction error: bad number of rows\n";
return *this;
}
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) -= a.a_no_check(i,j);
return *this;
}
EST_DMatrix & EST_DMatrix::operator*=(const double f)
{
int i,j;
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) *= f;
return *this;
}
EST_DMatrix & EST_DMatrix::operator/=(const double f)
{
int i,j;
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) /= f;
return *this;
}
EST_DMatrix operator+(const EST_DMatrix &a, const EST_DMatrix &b)
{
EST_DMatrix ab;
int i, j;
if (a.num_columns() != b.num_columns())
{
cerr <<"Matrix addition error: bad number of columns\n";
return ab;
}
if (a.num_rows() != b.num_rows())
{
cerr <<"Matrix addition error: bad number of rows\n";
return ab;
}
ab.resize(a.num_rows(), a.num_columns());
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
ab.a_no_check(i, j) = a.a_no_check(i, j) + b.a_no_check(i, j);
return ab;
}
EST_DMatrix operator-(const EST_DMatrix &a,const EST_DMatrix &b)
{
EST_DMatrix ab;
int i, j;
if (a.num_columns() != b.num_columns())
{
cerr <<"Matrix subtraction error: bad number of columns:" <<
a.num_columns() << " and " << b.num_columns() << endl;
return ab;
}
if (a.num_rows() != b.num_rows())
{
cerr <<"Matrix subtraction error: bad number of rows\n";
return ab;
}
ab.resize(a.num_rows(), a.num_columns());
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
ab.a_no_check(i, j) = a.a_no_check(i, j) - b.a_no_check(i, j);
return ab;
}
EST_DMatrix operator*(const EST_DMatrix &a, const double x)
{
EST_DMatrix b(a, 0);
int i, j;
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
b.a_no_check(i,j) = a.a_no_check(i,j) * x;
return b;
}
EST_DVector operator*(const EST_DMatrix &a, const EST_DVector &v)
{
// treat the vector as a column vector
// multiply each row of the matrix in turn by the vector
EST_DVector b;
b.resize(a.num_rows());
if(a.num_columns() != v.n())
{
cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
<< endl;
return b;
}
int i, j;
for (i = 0; i < a.num_rows(); ++i){
b[i] = 0.0;
for (j = 0; j < a.num_columns(); ++j)
b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
}
return b;
}
EST_DVector operator+(const EST_DVector &a, const EST_DVector &b)
{
EST_DVector ab;
int i;
if (a.length() != b.length())
{
cerr <<"Vector addition error: mismatched lengths\n";
return ab;
}
ab.resize(a.length());
for (i = 0; i < a.length(); ++i)
ab.a_no_check(i) = a.a_no_check(i) + b.a_no_check(i);
return ab;
}
EST_DVector operator-(const EST_DVector &a, const EST_DVector &b)
{
EST_DVector ab;
int i;
if (a.length() != b.length())
{
cerr <<"Vector subtraction error: mismatched lengths\n";
return ab;
}
ab.resize(a.length());
for (i = 0; i < a.length(); ++i)
ab.a_no_check(i) = a.a_no_check(i) - b.a_no_check(i);
return ab;
}
EST_DVector operator*(const EST_DVector &v,const EST_DMatrix &a)
{
// treat the vector as a row vector
// multiply the vector by each column of the matrix in turn
EST_DVector b;
b.resize(a.num_columns());
if(a.num_columns() != v.n())
{
cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
<< endl;
return b;
}
int i, j;
for (j = 0; j < a.num_columns(); ++j){
b[j] = 0.0;
for (i = 0; i < a.num_rows(); ++i)
b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
}
return b;
}
#if 0
EST_DMatrix operator/(const EST_DMatrix &a, double x)
{
return (a * (1/x));
}
#endif
EST_DMatrix operator*(const EST_DMatrix &a, const EST_DMatrix &b)
{
EST_DMatrix ab;
multiply(a,b,ab);
return ab;
}
void multiply(const EST_DMatrix &a, const EST_DMatrix &b, EST_DMatrix &ab)
{
if (a.num_columns() != b.num_rows())
{
cerr <<"Matrix multiply error: a.num_columns() != b.num_rows()\n";
return;
}
ab.resize(a.num_rows(), b.num_columns());
int i, j, k, n;
n = a.num_columns(); // could also be b.num_rows()
for (i = 0; i < a.num_rows(); ++i)
for (k = 0; k < b.num_columns(); ++k)
{
ab.a_no_check(i, k) = 0.0;
for (j = 0; j < n; ++j)
ab.a_no_check(i, k) +=
a.a_no_check(i, j) * b.a_no_check(j, k);
}
}
void EST_DMatrix::copyin(double **inx, int rows, int cols)
{
int i, j;
resize(rows, cols);
for (i = 0; i < rows; ++i)
for (j = 0; j < cols; ++j)
a_no_check(i,j) = inx[i][j];
}
EST_write_status EST_DMatrix::save(const EST_String &filename,
const EST_String &type)
{
if ((type == "est_ascii") || (type == "est_binary"))
return est_save(filename,type);
else
{ // the old stuff raw unheadered
int i, j;
ostream *outf;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
outf->precision(25);
if (!(*outf))
{
cerr << "DMatrix: can't open file \"" << filename
<<"\" for writing" << endl;
return misc_write_error;
}
for (i = 0; i < num_rows(); ++i)
{
for (j = 0; j < num_columns(); ++j)
*outf << a_no_check(i,j) << " ";
*outf << endl;
}
if (outf != &cout)
delete outf;
return write_ok;
}
}
EST_write_status EST_DMatrix::est_save(const EST_String &filename,
const EST_String &type)
{
// Binary save with short header for byte swap and sizes
int i,j;
FILE *fd;
if (filename == "-")
fd = stdout;
else if ((fd = fopen(filename, "wb")) == NULL)
{
cerr << "EST_DMatrix: binsave: failed to open \"" << filename <<
"\" for writing" << endl;
return misc_write_error;
}
fprintf(fd,"EST_File dmatrix\n");
fprintf(fd,"version 1\n");
if (type == "est_binary")
{
fprintf(fd,"DataType binary\n");
if (EST_LITTLE_ENDIAN)
fprintf(fd,"ByteOrder LittleEndian\n");
else
fprintf(fd,"ByteOrder BigEndian\n");
}
else
fprintf(fd,"DataType ascii\n");
fprintf(fd,"rows %d\n",num_rows());
fprintf(fd,"columns %d\n",num_columns());
fprintf(fd,"EST_Header_End\n");
if (type == "est_binary")
{
for (i = 0; i < num_rows(); ++i)
for (j=0; j < num_columns(); j++)
if (fwrite(&a_no_check(i,j),sizeof(double),1,fd) != 1)
{
cerr << "EST_DMatrix: binsave: failed to write row "
<< i << " column " << j
<< " to \"" << filename << "\"" << endl;
return misc_write_error;
}
}
else
{ // est_ascii
for (i = 0; i < num_rows(); ++i)
{
for (j=0; j < num_columns(); j++)
fprintf(fd,"%.25f ",a_no_check(i,j));
fprintf(fd,"\n");
}
}
if (fd != stdout)
fclose(fd);
return write_ok;
}
EST_read_status EST_DMatrix::est_load(const EST_String &filename)
{
// ascii/binary load with short header for byte swap and sizes
int i,j,k;
int rows, cols, swap;
EST_TokenStream ts;
EST_read_status r;
EST_EstFileType t;
EST_Option hinfo;
bool ascii;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "DMatrix: can't open DMatrix input file "
<< filename << endl;
return misc_read_error;
}
if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
return r;
if (t != est_file_dmatrix)
return misc_read_error;
if (hinfo.ival("version") != 1)
{
cerr << "DMatrix load: " << ts.pos_description() <<
" wrong version of DMatrix format expected 1 but found " <<
hinfo.ival("version") << endl;
return misc_read_error;
}
rows = hinfo.ival("rows");
cols = hinfo.ival("columns");
resize(rows,cols);
if (ascii)
{ // an ascii file
for (i = 0; i < num_rows(); ++i)
{
for (j = 0; j < num_columns(); ++j)
a_no_check(i,j) = atof(ts.get().string());
if (!ts.eoln())
{
cerr << "DMatrix load: " << ts.pos_description() <<
" missing end of line at end of row " << i << endl;
return misc_read_error;
}
}
}
else
{ // a binary file
double *buff;
if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
(EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
swap = TRUE;
else
swap = FALSE;
buff = walloc(double,rows*cols);
// A single read is *much* faster than multiple reads
if (ts.fread(buff,sizeof(double),rows*cols) != rows*cols)
{
cerr << "EST_DMatrix: binload: short file in \""
<< filename << "\"" << endl;
return misc_read_error;
}
if (swap)
swap_bytes_double(buff,rows*cols);
for (k = i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i,j) = buff[k++];
wfree(buff);
}
ts.close();
return read_ok;
}
EST_read_status EST_DMatrix::load(const EST_String &filename)
{
EST_read_status r;
if ((r = est_load(filename)) == format_ok)
return r;
else if (r == wrong_format)
{ // maybe its an ancient ascii file
EST_TokenStream ts, tt;
EST_StrList sl;
int i, j, n_rows=0, n_cols=0;
EST_String t;
EST_Litem *p;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "Can't open DMatrix file " << filename << endl;
return misc_read_error;
}
// set up the character constant values for this stream
ts.set_SingleCharSymbols(";");
// first read in as list
for (n_rows = 0; !ts.eof(); ++n_rows)
sl.append(ts.get_upto_eoln().string());
if (n_rows > 0)
{
tt.open_string(sl.first());
for (n_cols = 0; !tt.eof(); ++n_cols)
tt.get().string();
}
// resize track and copy values in
resize(n_rows, n_cols);
for (p = sl.head(), i = 0; p != 0; ++i, p = p->next())
{
tt.open_string(sl(p));
for (j = 0; !tt.eof(); ++j)
a_no_check(i,j) = atof(tt.get().string());
if (j != n_cols)
{
cerr << "Wrong number of points in row " << i << endl;
cerr << "Expected " << n_cols << " got " << j << endl;
return misc_read_error;
}
}
return format_ok;
}
else
return r;
return format_ok;
}
EST_read_status EST_DVector::est_load(const EST_String &filename)
{
// ascii/binary load with short header for byte swap and sizes
int i,k;
int l, swap;
EST_TokenStream ts;
EST_read_status r;
EST_EstFileType t;
EST_Option hinfo;
bool ascii;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "DVector: can't open DVector input file "
<< filename << endl;
return misc_read_error;
}
if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
return r;
if (t != est_file_dvector)
return misc_read_error;
if (hinfo.ival("version") != 1)
{
cerr << "DVector load: " << ts.pos_description() <<
" wrong version of DVector format expected 1 but found " <<
hinfo.ival("version") << endl;
return misc_read_error;
}
l = hinfo.ival("length");
resize(l);
if (ascii)
{ // an ascii file
for (i = 0; i < length(); ++i)
a_no_check(i) = atof(ts.get().string());
}
else
{ // a binary file
double *buff;
if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
(EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
swap = TRUE;
else
swap = FALSE;
buff = walloc(double,l);
// A single read is *much* faster than multiple reads
if (ts.fread(buff,sizeof(double),l) != l)
{
cerr << "EST_DVector: binload: short file in \""
<< filename << "\"" << endl;
return misc_read_error;
}
if (swap)
swap_bytes_double(buff,l);
for (k = i = 0; i < length(); ++i)
a_no_check(i) = buff[k++];
wfree(buff);
}
ts.close();
return read_ok;
}
EST_read_status EST_DVector::load(const EST_String &filename)
{
EST_read_status r;
if ((r = est_load(filename)) == format_ok)
return r;
else if (r == wrong_format)
{ // maybe its an ancient ascii file
EST_TokenStream ts;
EST_String s;
int i;
i = 0;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
ts.set_SingleCharSymbols(";");
while (!ts.eof())
{
ts.get();
++i;
}
resize(i);
ts.close();
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
for (i = 0; !ts.eof(); ++i)
{
s = ts.get().string();
(*this)[i] = atof(s); // actually returns double
}
ts.close();
return format_ok;
}
else
return r;
return format_ok;
}
EST_DVector & EST_DVector::operator+=(const EST_DVector &s)
{
int i;
if(n() != s.n()){
cerr << "Cannot elementwise add vectors of differing lengths"
<< endl;
return *this;
}
for (i = 0; i < n(); ++i)
(*this)[i] += s(i);
return *this;
}
EST_DVector& EST_DVector::operator*=(const EST_DVector &s)
{
if(n() != s.n()){
cerr << "Cannot elementwise multiply vectors of differing lengths"
<< endl;
return *this;
}
for (int i = 0; i < n(); ++i)
(*this)[i] *= s(i);
return *this;
}
EST_DVector& EST_DVector::operator*=(const double f)
{
for (int i = 0; i < n(); ++i)
(*this)[i] *= f;
return *this;
}
double operator*(const EST_DVector &v1, const EST_DVector &v2)
{
if(v1.length() != v2.length())
{
cerr << "Can't do vector dot prod - differing vector sizes !" << endl;
return 0;
}
double p=0;
for (int i = 0; i < v1.length(); ++i)
p += v1.a_no_check(i) * v2.a_no_check(i);
return p;
}
EST_DVector& EST_DVector::operator/=(const double f)
{
for (int i = 0; i < n(); ++i)
(*this)[i] /= f;
return *this;
}
EST_write_status EST_DVector::save(const EST_String &filename,
const EST_String &type)
{
if ((type == "est_ascii") || (type == "est_binary"))
return est_save(filename,type);
else
{ // the old stuff raw unheadered
int i;
ostream *outf;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
outf->precision(25);
if (!(*outf))
{
cerr << "DVector: can't open file \"" << filename
<<"\" for writing" << endl;
return misc_write_error;
}
for (i = 0; i < length(); ++i)
*outf << a_no_check(i) << " ";
*outf << endl;
if (outf != &cout)
delete outf;
return write_ok;
}
}
EST_write_status EST_DVector::est_save(const EST_String &filename,
const EST_String &type)
{
// Binary save with short header for byte swap and sizes
int i;
FILE *fd;
if (filename == "-")
fd = stdout;
else if ((fd = fopen(filename, "wb")) == NULL)
{
cerr << "EST_DVector: binsave: failed to open \"" << filename <<
"\" for writing" << endl;
return misc_write_error;
}
fprintf(fd,"EST_File dvector\n");
fprintf(fd,"version 1\n");
if (type == "est_binary")
{
fprintf(fd,"DataType binary\n");
if (EST_LITTLE_ENDIAN)
fprintf(fd,"ByteOrder LittleEndian\n");
else
fprintf(fd,"ByteOrder BigEndian\n");
}
else
fprintf(fd,"DataType ascii\n");
fprintf(fd,"length %d\n",length());
fprintf(fd,"EST_Header_End\n");
if (type == "est_binary")
{
for (i = 0; i < length(); ++i)
if (fwrite(&a_no_check(i),sizeof(double),1,fd) != 1)
{
cerr << "EST_DVector: binsave: failed to write item "
<< i << " to \"" << filename << "\"" << endl;
return misc_write_error;
}
}
else
{ // est_ascii
for (i = 0; i < length(); ++i)
fprintf(fd,"%.25f ",a_no_check(i));
fprintf(fd,"\n");
}
if (fd != stdout)
fclose(fd);
return write_ok;
}

920
base_class/EST_FMatrix.cc Normal file
View File

@ -0,0 +1,920 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : April 1995 */
/*-----------------------------------------------------------------------*/
/* Matrix Class for floats */
/* */
/*=======================================================================*/
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <climits>
using namespace std;
#include "EST_String.h"
#include "EST_types.h"
#include "EST_FileType.h"
#include "EST_Option.h"
#include "EST_FMatrix.h"
#include "EST_cutils.h" // for swap functions
#include "EST_Token.h"
/* EST_FVector may used as EST_Val */
VAL_REGISTER_CLASS(fvector,EST_FVector)
/* EST_FMatrix may used as EST_Val */
VAL_REGISTER_CLASS(fmatrix,EST_FMatrix)
EST_String EST_FMatrix::default_file_type = "est_ascii";
EST_FMatrix::EST_FMatrix(const EST_FMatrix &a, int b)
:EST_TSimpleMatrix<float>(a.num_rows(), a.num_columns())
{
float vv = 0.0;
if (b < 0)
return;
if (b == 0)
fill(vv);
}
EST_FMatrix & EST_FMatrix::operator+=(const EST_FMatrix &a)
{
int i, j;
if (a.num_columns() != num_columns())
{
cerr <<"Matrix addition error: bad number of columns\n";
return *this;
}
if (a.num_rows() != num_rows())
{
cerr <<"Matrix addition error: bad number of rows\n";
return *this;
}
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) += a.a_no_check(i,j);
return *this;
}
EST_FMatrix & EST_FMatrix::operator-=(const EST_FMatrix &a)
{
int i, j;
if (a.num_columns() != num_columns())
{
cerr <<"Matrix subtraction error: bad number of columns\n";
return *this;
}
if (a.num_rows() != num_rows())
{
cerr <<"Matrix subtraction error: bad number of rows\n";
return *this;
}
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) -= a.a_no_check(i,j);
return *this;
}
EST_FMatrix & EST_FMatrix::operator*=(const float f)
{
int i,j;
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) *= f;
return *this;
}
EST_FMatrix & EST_FMatrix::operator/=(const float f)
{
int i,j;
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i, j) /= f;
return *this;
}
EST_FMatrix operator+(const EST_FMatrix &a, const EST_FMatrix &b)
{
EST_FMatrix ab;
int i, j;
if (a.num_columns() != b.num_columns())
{
cerr <<"Matrix addition error: bad number of columns\n";
return ab;
}
if (a.num_rows() != b.num_rows())
{
cerr <<"Matrix addition error: bad number of rows\n";
return ab;
}
ab.resize(a.num_rows(), a.num_columns());
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
ab.a_no_check(i, j) = a.a_no_check(i, j) + b.a_no_check(i, j);
return ab;
}
EST_FMatrix operator-(const EST_FMatrix &a,const EST_FMatrix &b)
{
EST_FMatrix ab;
int i, j;
if (a.num_columns() != b.num_columns())
{
cerr <<"Matrix subtraction error: bad number of columns:" <<
a.num_columns() << " and " << b.num_columns() << endl;
return ab;
}
if (a.num_rows() != b.num_rows())
{
cerr <<"Matrix subtraction error: bad number of rows\n";
return ab;
}
ab.resize(a.num_rows(), a.num_columns());
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
ab.a_no_check(i, j) = a.a_no_check(i, j) - b.a_no_check(i, j);
return ab;
}
EST_FMatrix operator*(const EST_FMatrix &a, const float x)
{
EST_FMatrix b(a, 0);
int i, j;
for (i = 0; i < a.num_rows(); ++i)
for (j = 0; j < a.num_columns(); ++j)
b.a_no_check(i,j) = a.a_no_check(i,j) * x;
return b;
}
int operator !=(const EST_FVector &fv1,
const EST_FVector &fv2)
{
int i;
if(fv1.length() != fv2.length())
return FALSE;
for(i=0;i<fv1.length();i++)
if(fv1.a_no_check(i) != fv2.a_no_check(i))
return FALSE;
return TRUE;
}
EST_FVector operator*(const EST_FMatrix &a, const EST_FVector &v)
{
// treat the vector as a column vector
// multiply each row of the matrix in turn by the vector
EST_FVector b;
b.resize(a.num_rows());
if(a.num_columns() != v.n())
{
cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
<< endl;
return b;
}
int i, j;
for (i = 0; i < a.num_rows(); ++i){
b[i] = 0.0;
for (j = 0; j < a.num_columns(); ++j)
b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
}
return b;
}
EST_FVector operator+(const EST_FVector &a, const EST_FVector &b)
{
EST_FVector ab;
int i;
if (a.length() != b.length())
{
cerr <<"Vector addition error: mismatched lengths\n";
return ab;
}
ab.resize(a.length());
for (i = 0; i < a.length(); ++i)
ab.a_no_check(i) = a.a_no_check(i) + b.a_no_check(i);
return ab;
}
EST_FVector operator-(const EST_FVector &a, const EST_FVector &b)
{
EST_FVector ab;
int i;
if (a.length() != b.length())
{
cerr <<"Vector subtraction error: mismatched lengths\n";
return ab;
}
ab.resize(a.length());
for (i = 0; i < a.length(); ++i)
ab.a_no_check(i) = a.a_no_check(i) - b.a_no_check(i);
return ab;
}
EST_FVector operator*(const EST_FVector &v,const EST_FMatrix &a)
{
// treat the vector as a row vector
// multiply the vector by each column of the matrix in turn
EST_FVector b;
b.resize(a.num_columns());
if(a.num_columns() != v.n())
{
cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
<< endl;
return b;
}
int i, j;
for (j = 0; j < a.num_columns(); ++j){
b[j] = 0.0;
for (i = 0; i < a.num_rows(); ++i)
b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
}
return b;
}
#if 0
EST_FMatrix operator/(const EST_FMatrix &a, float x)
{
return (a * (1/x));
}
#endif
EST_FMatrix operator*(const EST_FMatrix &a, const EST_FMatrix &b)
{
EST_FMatrix ab;
multiply(a,b,ab);
return ab;
}
void multiply(const EST_FMatrix &a, const EST_FMatrix &b, EST_FMatrix &ab)
{
if (a.num_columns() != b.num_rows())
{
cerr <<"Matrix multiply error: a.num_columns() != b.num_rows()\n";
return;
}
ab.resize(a.num_rows(), b.num_columns());
int i, j, k, n;
n = a.num_columns(); // could also be b.num_rows()
for (i = 0; i < a.num_rows(); ++i)
for (k = 0; k < b.num_columns(); ++k)
{
ab.a_no_check(i, k) = 0.0;
for (j = 0; j < n; ++j)
ab.a_no_check(i, k) +=
a.a_no_check(i, j) * b.a_no_check(j, k);
}
}
void EST_FMatrix::copyin(float **inx, int rows, int cols)
{
int i, j;
resize(rows, cols);
for (i = 0; i < rows; ++i)
for (j = 0; j < cols; ++j)
a_no_check(i,j) = inx[i][j];
}
EST_write_status EST_FMatrix::save(const EST_String &filename,
const EST_String &type)
{
if ((type == "est_ascii") || (type == "est_binary"))
return est_save(filename,type);
else
{ // the old stuff raw unheadered
int i, j;
ostream *outf;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
if (!(*outf))
{
cerr << "FMatrix: can't open file \"" << filename
<<"\" for writing" << endl;
return misc_write_error;
}
for (i = 0; i < num_rows(); ++i)
{
for (j = 0; j < num_columns(); ++j)
*outf << a_no_check(i,j) << " ";
*outf << endl;
}
if (outf != &cout)
delete outf;
return write_ok;
}
}
EST_write_status EST_FMatrix::est_save(const EST_String &filename,
const EST_String &type)
{
// Binary save with short header for byte swap and sizes
int i,j;
FILE *fd;
if (filename == "-")
fd = stdout;
else if ((fd = fopen(filename, "wb")) == NULL)
{
cerr << "EST_FMatrix: binsave: failed to open \"" << filename <<
"\" for writing" << endl;
return misc_write_error;
}
fprintf(fd,"EST_File fmatrix\n");
fprintf(fd,"version 1\n");
if (type == "est_binary")
{
fprintf(fd,"DataType binary\n");
if (EST_LITTLE_ENDIAN)
fprintf(fd,"ByteOrder LittleEndian\n");
else
fprintf(fd,"ByteOrder BigEndian\n");
}
else
fprintf(fd,"DataType ascii\n");
fprintf(fd,"rows %d\n",num_rows());
fprintf(fd,"columns %d\n",num_columns());
fprintf(fd,"EST_Header_End\n");
if (type == "est_binary")
{
for (i = 0; i < num_rows(); ++i)
for (j=0; j < num_columns(); j++)
if (fwrite(&a_no_check(i,j),sizeof(float),1,fd) != 1)
{
cerr << "EST_FMatrix: binsave: failed to write row "
<< i << " column " << j
<< " to \"" << filename << "\"" << endl;
return misc_write_error;
}
}
else
{ // est_ascii
for (i = 0; i < num_rows(); ++i)
{
for (j=0; j < num_columns(); j++)
fprintf(fd,"%f ",a_no_check(i,j));
fprintf(fd,"\n");
}
}
if (fd != stdout)
fclose(fd);
return write_ok;
}
EST_read_status EST_FMatrix::est_load(const EST_String &filename)
{
// ascii/binary load with short header for byte swap and sizes
int i,j,k;
int rows, cols, swap;
EST_TokenStream ts;
EST_read_status r;
EST_EstFileType t;
EST_Option hinfo;
bool ascii;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "FMatrix: can't open fmatrix input file "
<< filename << endl;
return misc_read_error;
}
if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
return r;
if (t != est_file_fmatrix)
return misc_read_error;
if (hinfo.ival("version") != 1)
{
cerr << "FMatrix load: " << ts.pos_description() <<
" wrong version of fmatrix format expected 1 but found " <<
hinfo.ival("version") << endl;
return misc_read_error;
}
rows = hinfo.ival("rows");
cols = hinfo.ival("columns");
resize(rows,cols);
if (ascii)
{ // an ascii file
for (i = 0; i < num_rows(); ++i)
{
for (j = 0; j < num_columns(); ++j)
a_no_check(i,j) = atof(ts.get().string());
if (!ts.eoln())
{
cerr << "FMatrix load: " << ts.pos_description() <<
" missing end of line at end of row " << i << endl;
return misc_read_error;
}
}
}
else
{ // a binary file
float *buff;
if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
(EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
swap = TRUE;
else
swap = FALSE;
buff = walloc(float,rows*cols);
// A single read is *much* faster than multiple reads
if (ts.fread(buff,sizeof(float),rows*cols) != rows*cols)
{
cerr << "EST_FMatrix: binload: short file in \""
<< filename << "\"" << endl;
return misc_read_error;
}
if (swap)
swap_bytes_float(buff,rows*cols);
for (k = i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
a_no_check(i,j) = buff[k++];
wfree(buff);
}
ts.close();
return read_ok;
}
EST_read_status EST_FMatrix::load(const EST_String &filename)
{
EST_read_status r;
if ((r = est_load(filename)) == format_ok)
return r;
else if (r == wrong_format)
{ // maybe its an ancient ascii file
EST_TokenStream ts, tt;
EST_StrList sl;
int i, j, n_rows=0, n_cols=0;
EST_String t;
EST_Litem *p;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "Can't open fmatrix file " << filename << endl;
return misc_read_error;
}
// set up the character constant values for this stream
ts.set_SingleCharSymbols(";");
// first read in as list
for (n_rows = 0; !ts.eof(); ++n_rows)
sl.append(ts.get_upto_eoln().string());
if (n_rows > 0)
{
tt.open_string(sl.first());
for (n_cols = 0; !tt.eof(); ++n_cols)
tt.get().string();
}
// resize track and copy values in
resize(n_rows, n_cols);
for (p = sl.head(), i = 0; p != 0; ++i, p = p->next())
{
tt.open_string(sl(p));
for (j = 0; !tt.eof(); ++j)
a_no_check(i,j) = atof(tt.get().string());
if (j != n_cols)
{
cerr << "Wrong number of points in row " << i << endl;
cerr << "Expected " << n_cols << " got " << j << endl;
return misc_read_error;
}
}
return format_ok;
}
else
return r;
}
EST_FVector & EST_FVector::operator+=(const EST_FVector &s)
{
int i;
if(n() != s.n()){
cerr << "Cannot elementwise add vectors of differing lengths"
<< endl;
return *this;
}
for (i = 0; i < n(); ++i)
(*this)[i] += s(i);
return *this;
}
EST_FVector& EST_FVector::operator*=(const EST_FVector &s)
{
if(n() != s.n()){
cerr << "Cannot elementwise multiply vectors of differing lengths"
<< endl;
return *this;
}
for (int i = 0; i < n(); ++i)
(*this)[i] *= s(i);
return *this;
}
EST_FVector& EST_FVector::operator*=(const float f)
{
for (int i = 0; i < n(); ++i)
(*this)[i] *= f;
return *this;
}
EST_FVector& EST_FVector::operator/=(const float f)
{
for (int i = 0; i < n(); ++i)
(*this)[i] /= f;
return *this;
}
EST_read_status EST_FVector::est_load(const EST_String &filename)
{
// ascii/binary load with short header for byte swap and sizes
int i,k;
int l, swap;
EST_TokenStream ts;
EST_read_status r;
EST_EstFileType t;
EST_Option hinfo;
bool ascii;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "FVector: can't open FVector input file "
<< filename << endl;
return misc_read_error;
}
if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
return r;
if (t != est_file_fvector)
return misc_read_error;
if (hinfo.ival("version") != 1)
{
cerr << "FVector load: " << ts.pos_description() <<
" wrong version of FVector format expected 1 but found " <<
hinfo.ival("version") << endl;
return misc_read_error;
}
l = hinfo.ival("length");
resize(l);
if (ascii)
{ // an ascii file
for (i = 0; i < length(); ++i)
a_no_check(i) = atof(ts.get().string());
}
else
{ // a binary file
float *buff;
if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
(EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
swap = TRUE;
else
swap = FALSE;
buff = walloc(float,l);
// A single read is *much* faster than multiple reads
if (ts.fread(buff,sizeof(float),l) != l)
{
cerr << "EST_FVector: binload: short file in \""
<< filename << "\"" << endl;
return misc_read_error;
}
if (swap)
swap_bytes_float(buff,l);
for (k = i = 0; i < length(); ++i)
a_no_check(i) = buff[k++];
wfree(buff);
}
ts.close();
return read_ok;
}
EST_read_status EST_FVector::load(const EST_String &filename)
{
EST_read_status r;
if ((r = est_load(filename)) == format_ok)
return r;
else if (r == wrong_format)
{ // maybe its an ancient ascii file
EST_TokenStream ts;
EST_String s;
int i;
i = 0;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
ts.set_SingleCharSymbols(";");
while (!ts.eof())
{
ts.get();
++i;
}
resize(i);
ts.close();
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
for (i = 0; !ts.eof(); ++i)
{
s = ts.get().string();
(*this)[i] = (float)(atof(s)); // actually returns double
}
ts.close();
return format_ok;
}
else
return r;
return format_ok;
}
/*
EST_read_status EST_FVector::load(EST_String &filename)
{
EST_TokenStream ts;
EST_String s;
int i;
i = 0;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
ts.set_SingleCharSymbols(";");
while (!ts.eof())
{
ts.get();
++i;
}
resize(i);
ts.close();
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open vector input file " << filename << endl;
return misc_read_error;
}
for (i = 0; !ts.eof(); ++i)
{
s = ts.get().string();
(*this)[i] = atof(s);
}
ts.close();
return format_ok;
}
*/
// EST_read_status EST_DVector::load(EST_String &filename)
// {
// EST_TokenStream ts;
// EST_String s;
// int i;
// i = 0;
// if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
// {
// cerr << "can't open vector input file " << filename << endl;
// return misc_read_error;
// }
// ts.set_SingleCharSymbols(";");
// while (!ts.eof())
// {
// ts.get();
// ++i;
// }
// resize(i);
// ts.close();
// if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
// {
// cerr << "can't open vector input file " << filename << endl;
// return misc_read_error;
// }
// for (i = 0; !ts.eof(); ++i)
// {
// s = ts.get().string();
// (*this)[i] = atof(s); // actually returns double
// }
// ts.close();
// return format_ok;
// }
float operator*(const EST_FVector &v1, const EST_FVector &v2)
{
// dot product
float b=0;
if(v1.length() != v2.length())
{
cerr <<"Vector dot product error: differing vector size"
<< endl;
return b;
}
int i;
for (i = 0; i < v1.length(); ++i)
b += v1.a_no_check(i) * v2.a_no_check(i);
return b;
}
EST_write_status EST_FVector::save(const EST_String &filename,
const EST_String &type)
{
if ((type == "est_ascii") || (type == "est_binary"))
return est_save(filename,type);
else
{ // the old stuff raw unheadered
int i;
ostream *outf;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
outf->precision(25);
if (!(*outf))
{
cerr << "FVector: can't open file \"" << filename
<<"\" for writing" << endl;
return misc_write_error;
}
for (i = 0; i < length(); ++i)
*outf << a_no_check(i) << " ";
*outf << endl;
if (outf != &cout)
delete outf;
return write_ok;
}
}
EST_write_status EST_FVector::est_save(const EST_String &filename,
const EST_String &type)
{
// Binary save with short header for byte swap and sizes
int i;
FILE *fd;
if (filename == "-")
fd = stdout;
else if ((fd = fopen(filename, "wb")) == NULL)
{
cerr << "EST_FVector: binsave: failed to open \"" << filename <<
"\" for writing" << endl;
return misc_write_error;
}
fprintf(fd,"EST_File fvector\n");
fprintf(fd,"version 1\n");
if (type == "est_binary")
{
fprintf(fd,"DataType binary\n");
if (EST_LITTLE_ENDIAN)
fprintf(fd,"ByteOrder LittleEndian\n");
else
fprintf(fd,"ByteOrder BigEndian\n");
}
else
fprintf(fd,"DataType ascii\n");
fprintf(fd,"length %d\n",length());
fprintf(fd,"EST_Header_End\n");
if (type == "est_binary")
{
for (i = 0; i < length(); ++i)
if (fwrite(&a_no_check(i),sizeof(float),1,fd) != 1)
{
cerr << "EST_FVector: binsave: failed to write item "
<< i << " to \"" << filename << "\"" << endl;
return misc_write_error;
}
}
else
{ // est_ascii
for (i = 0; i < length(); ++i)
fprintf(fd,"%.25f ",a_no_check(i));
fprintf(fd,"\n");
}
if (fd != stdout)
fclose(fd);
return write_ok;
}

View File

@ -0,0 +1,529 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Paul Taylor Caley */
/* Date: July 1998 */
/* -------------------------------------------------------------------- */
/* Feature Data Class */
/* */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_Val.h"
#include "EST_FeatureData.h"
#include "EST_string_aux.h"
#include "EST_Token.h"
#include "EST_FileType.h"
#include "EST_error.h"
#include <iostream>
#include <fstream>
#include "EST_THash.h"
EST_FeatureData::EST_FeatureData()
{
default_vals();
}
EST_FeatureData::EST_FeatureData(const EST_FeatureData &a)
{
default_vals();
copy(a);
}
EST_FeatureData::~EST_FeatureData(void)
{
}
int EST_FeatureData::num_samples() const
{
return fd.num_rows();
}
int EST_FeatureData::num_features() const
{
return fd.num_columns();
}
void EST_FeatureData::default_vals()
{
/* cout << "Default values\n";
p_sub_fd = false;
p_info = new EST_FeatureInfo;
*/
}
void EST_FeatureData::set_num_samples(int num_samples, bool preserve)
{
fd.resize(num_samples, fd.num_columns(), preserve);
}
void EST_FeatureData::resize(int num_samples, int num_features, bool preserve)
{
// If enlargement is required, give new features dummy names
// and set their types to <STRING>. If preserve is set to 0
// rename all features this way.
if (num_features > fd.num_columns())
{
int i;
if (preserve)
i = fd.num_columns();
else
i = 0;
for (; i < num_features; ++i)
info.set("unnamed_" + itoString(i), "<STRING>");
}
fd.resize(num_samples, num_features, preserve);
}
void EST_FeatureData::resize(int num_samples, EST_Features &f, bool preserve)
{
fd.resize(num_samples, f.length(), preserve);
info = f;
}
EST_String EST_FeatureData::type(const EST_String &feature_name)
{
EST_String t = info.S(feature_name);
if (t.contains("<", 0)) // i.e. a predefined type
return t;
return "undef";
}
EST_StrList EST_FeatureData::values(const EST_String &feature_name)
{
EST_StrList v;
EST_String t = info.S(feature_name);
// check for infinite set:
if ((t == "<FLOAT>") || (t == "<INT>") || (t == "<STRING>"))
return v;
StringtoStrList(t, v);
return v;
}
int EST_FeatureData::feature_position(const EST_String &feature_name)
{
int i;
EST_Features::Entries p;
for (i = 0, p.begin(info); p; ++p, ++i)
{
// cout << "looking at " << info.fname(p) << endl;
// cout << "i = " << i << endl;
if (p->k == feature_name)
return i;
}
EST_error("No such feature %s\n", (const char *) feature_name);
return 0;
}
int EST_FeatureData::update_values(const EST_String &feature_name, int max)
{
// This should be converted back to Hash tables once extra
// iteration functions are added the EST_Hash.
int i, col;
EST_Features values;
EST_String v;
// EST_TStringHash<int> values(max);
col = feature_position(feature_name);
for (i = 0; i < num_samples(); ++i)
values.set(fd.a(i, col).string(), 1);
// check to see if there are more types than allowed, if so
// just set to open set STRING
if (values.length() > max)
v = "<STRING>";
else
{
EST_Features::Entries p;
for(p.begin(values); p; ++p)
v += p->k + " ";
}
info.set(feature_name, v);
return values.length();
}
EST_FeatureData & EST_FeatureData::copy(const EST_FeatureData &a)
{
(void) a;
/* // copy on a sub can't alter header information
if (!p_sub_fd)
{
delete p_info;
*p_info = *(a.p_info);
}
// but data can be copied so long as no resizing is involved.
EST_ValMatrix::operator=(a);
*/
return *this;
}
/*void EST_FeatureData::a(int i, int j)
{
return EST_ValMatrix::a(i, j);
}
*/
/*
EST_Val &EST_FeatureData::operator()(int i, int j)
{
return a(i, j);
}
EST_Val &EST_FeatureData::operator()(int s, const EST_String &f)
{
int i = info().field_index(f);
return a(s, i);
}
EST_FeatureData &EST_FeatureData::operator=(const EST_FeatureData &f)
{
return copy(f);
}
*/
EST_Val &EST_FeatureData::a(int i, const EST_String &f)
{
(void)f;
return fd.a(i, 0);
}
EST_Val &EST_FeatureData::a(int i, int j)
{
return fd.a(i, j);
}
const EST_Val &EST_FeatureData::a(int i, const EST_String &f) const
{
(void)f;
return fd.a(i, 0);
}
const EST_Val &EST_FeatureData::a(int i, int j) const
{
return fd.a(i, j);
}
/*
void EST_FeatureData::sub_samples(EST_FeatureData &f, int start, int num)
{
sub_matrix(f, start, num);
f.p_info = p_info;
f.p_sub_fd = true;
}
void EST_FeatureData::extract_named_fields(const EST_String &fields)
{
EST_FeatureData n;
// there must be a more efficient way than a copy?
extract_named_fields(n, fields);
*this = n;
}
void EST_FeatureData::extract_named_fields(const EST_StrList &fields)
{
EST_FeatureData n;
// there must be a more efficient way than a copy?
extract_named_fields(n, fields);
*this = n;
}
void EST_FeatureData::extract_numbered_fields(const EST_String &fields)
{
EST_FeatureData n;
// there must be a more efficient way than a copy?
extract_numbered_fields(n, fields);
*this = n;
}
void EST_FeatureData::extract_numbered_fields(const EST_IList &fields)
{
EST_FeatureData n;
// there must be a more efficient way than a copy?
extract_numbered_fields(n, fields);
*this = n;
}
void EST_FeatureData::extract_named_fields(EST_FeatureData &f,
const EST_String &fields) const
{
EST_StrList s;
StringtoStrList(fields, s);
extract_named_fields(f, s);
}
void EST_FeatureData::extract_named_fields(EST_FeatureData &f,
const EST_StrList &n_fields) const
{
EST_Litem *p;
EST_StrList n_types;
int i, j;
info().extract_named_fields(*(f.p_info), n_fields);
for (p = n_fields.head(), i = 0; i < f.num_fields(); ++i, p = p->next())
for (j = 0; j < f.num_samples(); ++j)
f(j, i) = a(j, n_fields(p));
}
void EST_FeatureData::extract_numbered_fields(EST_FeatureData &f,
const EST_IList &fields) const
{
EST_Litem *p;
EST_StrList n_fields;
int i, j;
for (p = fields.head(); p; p = p->next())
n_fields.append(info().field_name(fields(p)));
info().extract_named_fields(*(f.p_info), n_fields);
for (p = fields.head(), i = 0; i < f.num_fields(); ++i, p = p->next())
for (j = 0; j < f.num_samples(); ++j)
f(j, i) = a(j, fields(p));
}
void EST_FeatureData::extract_numbered_fields(EST_FeatureData &f,
const EST_String &fields) const
{
EST_StrList s;
EST_IList il;
StringtoStrList(fields, s);
StrListtoIList(s, il);
extract_numbered_fields(f, il);
}
*/
EST_write_status save_est(const EST_FeatureData &f, const EST_String &filename)
{
(void)f;
(void)filename;
/*
ostream *outf;
EST_Litem *s, *e;
int i;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
if (!(*outf))
return write_fail;
outf->precision(5);
outf->setf(ios::fixed, ios::floatfield);
outf->width(8);
*outf << "EST_File feature_data\n"; // EST header identifier
*outf << "DataType ascii\n";
*outf << "NumSamples " << f.num_samples() << endl;
*outf << "NumFields " << f.num_fields() << endl;
*outf << "FieldNames " << f.info().field_names();
*outf << "FieldTypes " << f.info().field_types();
if (f.info().group_start.length() > 0)
for (s = f.info().group_start.head(), e = f.info().group_end.head();
s; s = s->next(), e = e->next())
*outf << "Group " << f.info().group_start.key(s) << " " <<
f.info().group_start.val(s) << " " << f.info().group_end.val(e) << endl;
for (i = 0; i < f.num_fields(); ++i)
if (f.info().field_values(i).length() > 0)
*outf << "Field_" << i << "_Values "
<< f.info().field_values(i) << endl;
*outf << "EST_Header_End\n"; // EST end of header identifier
// *outf << ((EST_ValMatrix ) f);
*outf << f;
*/
return write_ok;
}
EST_write_status EST_FeatureData::save(const EST_String &filename,
const EST_String &file_type) const
{
if ((file_type == "est") || (file_type == ""))
return save_est(*this, filename);
/* else if (file_type = "octave")
return save_octave(*this, filename);
else if (file_type = "ascii")
return save_ascii(*this, filename);
*/
cerr << "Can't save feature data in format \"" << file_type << endl;
return write_fail;
}
EST_read_status EST_FeatureData::load(const EST_String &filename)
{
int i, j;
EST_Option hinfo;
EST_String k, v;
EST_read_status r;
bool ascii;
EST_TokenStream ts;
EST_EstFileType t;
int ns, nf;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "Can't open track file " << filename << endl;
return misc_read_error;
}
// set up the character constant values for this stream
ts.set_SingleCharSymbols(";");
ts.set_quotes('"','\\');
if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
{
cerr << "Error reading est header of file " << filename << endl;
return r;
}
if (t != est_file_feature_data)
{
cerr << "Not a EST Feature Data file: " << filename << endl;
return misc_read_error;
}
ns = hinfo.ival("NumSamples");
nf = hinfo.ival("NumFeatures");
cout << "ns: " << ns << endl;
cout << "nf: " << nf << endl;
resize(ns, nf);
info.clear(); // because resize will make default names
for (i = 0; i < nf; ++i)
{
k = "Feature_" + itoString(i+1);
if (hinfo.present(k))
{
v = hinfo.val(k);
info.set(v.before(" "), v.after(" "));
cout << "value: " << v.after(" ") << endl;
}
else
EST_error("No feature definition given for feature %d\n", i);
}
for (i = 0; i < ns; ++i)
{
EST_Features::Entries p;
for (p.begin(info), j = 0; j < nf; ++j, ++p)
{
if (p->k == "<FLOAT>")
a(i, j) = atof(ts.get().string());
else if (p->k == "<BOOL>")
a(i, j) = atoi(ts.get().string());
else if (p->k == "<INT>")
a(i, j) = atoi(ts.get().string());
else
a(i, j) = ts.get().string();
}
}
return format_ok;
}
/*ostream& operator << (ostream &st, const EST_FeatureInfo &a)
{
// st << a.field_names() << endl;
// st << a.field_types() << endl;
return st;
}
*/
ostream& operator << (ostream &st, const EST_FeatureData &d)
{
int i, j;
EST_String t;
EST_Val v;
// st << a;
// EST_ValMatrix::operator<<(st, (EST_ValMatrix)a);
for (i = 0; i < d.num_samples(); ++i)
{
for (j = 0; j < d.num_features(); ++j)
{
v = d.a(i, j);
st << v << " ";
// cout << "field type " << a.info().field_type(j) << endl;
/* else if (a.info().field_type(j) == "float")
st << a.a(i, j);
else if (a.info().field_type(j) == "int")
st << a.a(i, j);
else if (a.info().field_type(j) == "string")
{
// st << "\"" << a.a(i, j) << "\"";
t = a.a(i, j);
t.gsub(" ", "_");
st << t;
}
*/
}
st << endl;
}
return st;
}

105
base_class/EST_Featured.cc Normal file
View File

@ -0,0 +1,105 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* */
/* -------------------------------------------------------------------- */
/* A class encapsulating the mechanics of objects which have features. */
/* */
/*************************************************************************/
#include "EST_Featured.h"
EST_Featured::EST_Featured(void)
{
init_features();
}
EST_Featured::EST_Featured(const EST_Featured &f)
{
init_features();
copy_features(f);
}
EST_Featured::~EST_Featured(void)
{
clear_features();
}
void EST_Featured::init_features()
{
p_features=NULL;
}
void EST_Featured::clear_features()
{
if (p_features)
{
delete p_features;
p_features=NULL;
}
init_features();
}
const EST_Val &EST_Featured::f_Val(const char *name) const
{
if (p_features)
return p_features->val(name);
else
return EST_Features::feature_default_value;
}
const EST_Val &EST_Featured::f_Val(const char *name, const EST_Val &def) const
{
if (p_features)
return p_features->val(name);
else
return def;
}
void EST_Featured::copy_features(const EST_Featured &f)
{
clear_features();
if (f.p_features)
p_features = new EST_Features(*(f.p_features));
}
#if defined(INSTANTIATE_TEMPLATES)
typedef EST_TKVI<EST_String, EST_Val> EST_Featured_Entry;
Instantiate_TStructIterator_T(EST_Featured, EST_Featured::IPointer_feat,EST_Featured_Entry, Featured_itt)
Instantiate_TIterator_T(EST_Featured, EST_Featured::IPointer_feat,EST_Featured_Entry, Featured_itt)
#endif

217
base_class/EST_Features.cc Normal file
View File

@ -0,0 +1,217 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1998 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : March 1998 */
/*-----------------------------------------------------------------------*/
/* Feature value pairs in a EST_TKVL */
/*=======================================================================*/
#include <cstdlib>
#include "EST_Features.h"
#include "ling_class/EST_Item.h"
#include "EST_error.h"
#include "EST_String.h"
#include "EST_Token.h"
/* Features may used as Vals */
VAL_REGISTER_CLASS(feats,EST_Features)
EST_Val EST_Features::feature_default_value("0");
// Sometimes we need a set of features even though there aren't any
static EST_Features default_features;
EST_Features::EST_Features()
{
features = new EST_TKVL<EST_String, EST_Val>;
}
EST_Features::EST_Features(const EST_Features &f)
{
features = new EST_TKVL<EST_String, EST_Val>;
*features = *f.features;
}
EST_Features::~EST_Features()
{
if (features != NULL)
{
delete features;
features=NULL;
}
}
const EST_Val &EST_Features::val(const char *name, const EST_Val &def) const
{
// Because so many access are from char* literals we all access
// directly rather than requiring the creation of an EST_String
EST_Litem *p;
for (p=features->list.head(); p; p=p->next())
{
if (features->list(p).k == name)
return features->list(p).v;
}
return def;
}
const EST_Val &EST_Features::val(const char *name) const
{
// Because so many access are from char* literals we all access
// directly rather than requiring the creation of an EST_String
EST_Litem *p;
for (p=features->list.head(); p; p=p->next())
{
if (features->list(p).k == name)
return features->list(p).v;
}
EST_error("{FND} Feature %s not defined\n", name);
return feature_default_value;
}
const EST_Val &EST_Features::val_path(const EST_String &name, const EST_Val &d) const
{
// For when name contains references to sub-features
if (strchr(name,'.') == NULL)
return val(name, d);
else
{
EST_String nname = name;
EST_String fname = nname.before(".");
const EST_Val &v = val(fname, d);
if (v.type() == val_type_feats)
return feats(v)->val_path(nname.after("."), d);
else
return d;
}
}
const EST_Val &EST_Features::val_path(const EST_String &name) const
{
// For when name contains references to sub-features
if (strchr(name,'.') == NULL)
return val(name);
else
{
EST_String nname = name;
EST_String fname = nname.before(".");
const EST_Val &v = val(fname);
if (v.type() == val_type_feats)
return feats(v)->val_path(nname.after("."));
else
EST_error("Feature %s not feature valued\n", (const char *)fname);
return feature_default_value; // wont get here
}
}
EST_Features &EST_Features::A(const EST_String &path,EST_Features &def) const
{
EST_Features *ff = new EST_Features(def);
return *feats(val(path,est_val(ff)));
}
int EST_Features::present(const EST_String &name) const
{
if (strchr(name,'.') == NULL)
return features->present(name);
EST_String nname = name;
if (features->present(nname.before(".")))
{
const EST_Val &v = val(nname.before("."));
if (v.type() == val_type_feats)
return feats(v)->present(nname.after("."));
else
return FALSE;
}
else
return FALSE;
}
void EST_Features::set_path(const EST_String &name, const EST_Val &sval)
{
// Builds sub features (if necessary)
if (strchr(name,'.') == NULL)
set_val(name,sval);
else
{
EST_String nname = name;
EST_String fname = nname.before(".");
if (present(fname))
{
const EST_Val &v = val(fname);
if (v.type() == val_type_feats)
feats(v)->set_path(nname.after("."),sval);
else
EST_error("Feature %s not feature valued\n",
(const char *)fname);
}
else
{
EST_Features f;
set(fname,f);
A(fname).set_path(nname.after("."),sval);
}
}
}
EST_Features &EST_Features::operator=(const EST_Features &x)
{
*features = *x.features;
return *this;
}
void merge_features(EST_Features &to,EST_Features &from)
{
EST_Features::Entries p;
for(p.begin(from); p; ++p)
to.set_val(p->k,p->v);
}
EST_String error_name(const EST_Features &a)
{
(void)a;
return "<<Features>>";
}
#if defined(INSTANTIATE_TEMPLATES)
typedef EST_TKVI<EST_String, EST_Val> EST_Features_Entry;
Instantiate_TStructIterator_T(EST_Features, EST_Features::IPointer, EST_Features_Entry, Features_itt)
Instantiate_TIterator_T(EST_Features, EST_Features::IPointer, EST_Features_Entry, Features_itt)
#endif

64
base_class/EST_IMatrix.cc Normal file
View File

@ -0,0 +1,64 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : April 1995 */
/*-----------------------------------------------------------------------*/
/* Matrix Class for ints */
/* */
/*=======================================================================*/
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <climits>
#include "EST_String.h"
#include "EST_types.h"
#include "EST_FileType.h"
#include "EST_Option.h"
#include "EST_IMatrix.h"
#include "EST_cutils.h" // for swap functions
#include "EST_Token.h"
#include "rateconv.h"
EST_IMatrix::EST_IMatrix(EST_IMatrix &a, int b)
:EST_TSimpleMatrix<int>(a.num_rows(), a.num_columns())
{
int vv = 0;
if (b < 0)
return;
if (b == 0)
fill(vv);
}

191
base_class/EST_Option.cc Normal file
View File

@ -0,0 +1,191 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : April 1995 */
/*-----------------------------------------------------------------------*/
/* EST_Option Class */
/* */
/*=======================================================================*/
#include <cstdlib>
#include "EST_Option.h"
#include "EST_io_aux.h"
#include "EST_Token.h"
static const EST_String Empty_String("");
// Fills in keyval pair. If Key already exists, overwrites value.
int EST_Option::override_val(const EST_String rkey, const EST_String rval)
{
if (rval == "")
return 0;
return add_item(rkey, rval);
}
int EST_Option::override_fval(const EST_String rkey, const float rval)
{
EST_String tmp;
char ctmp[100];
sprintf(ctmp, "%f", rval);
tmp = ctmp;
return override_val(rkey, tmp);
}
int EST_Option::override_ival(const EST_String rkey, const int rval)
{
EST_String tmp;
char ctmp[100];
sprintf(ctmp, "%d", rval);
tmp = ctmp;
return override_val(rkey, tmp);
}
int EST_Option::ival(const EST_String &rkey, int must) const
{
const EST_String &tval = val_def(rkey, Empty_String);
if (tval != "")
return atoi(tval);
if (must)
cerr << "EST_Option: No value set for " << rkey << endl;
return 0;
}
const EST_String &EST_Option::sval(const EST_String &rkey, int must) const
{
const EST_String &tval = val_def(rkey, Empty_String);
if (tval != Empty_String)
return tval;
if (must)
cerr << "EST_Option: No value set for " << rkey << endl;
return Empty_String;
}
float EST_Option::fval(const EST_String &rkey, int must) const
{
const EST_String &tval = val_def(rkey, Empty_String);
if (tval != Empty_String)
return atof(tval);
if (must)
cerr << "EST_Option: No value set for " << rkey << endl;
return 0.0;
}
double EST_Option::dval(const EST_String &rkey, int must) const
{
const EST_String &tval = val_def(rkey,Empty_String);
if (tval != Empty_String)
return atof(tval);
if (must)
cerr << "EST_Option: No value set for " << rkey << endl;
return 0.0;
}
int EST_Option::add_iitem(const EST_String &rkey, const int &rval)
{
char tmp[100];
sprintf(tmp, "%d", rval);
return add_item(rkey, tmp);
}
int EST_Option::add_fitem(const EST_String &rkey, const float &rval)
{
char tmp[100];
sprintf(tmp, "%f", rval);
return add_item(rkey, tmp);
}
// load in Options from files. This function has a recursive include
// facility fpr reading nested files. Maybe there should be a check on
// the max number of allowable open files.
EST_read_status EST_Option::load(const EST_String &filename,
const EST_String &comment)
{
EST_TokenStream ts;
EST_String k, v;
if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
{
cerr << "can't open EST_Option input file " << filename << endl;
return misc_read_error;
}
// set up the character constant values for this stream
while(!ts.eof())
{
k = ts.get().string();
v = ts.get_upto_eoln().string();
if (v.contains(RXwhite, 0))
v = v.after(RXwhite);
if (k.contains("#include")) //recursively load additional files
{
cout << "Include directive\n";
this->load(v);
}
if (!k.contains(comment, 0))
add_item(k, v, 0); // e a search is required.
}
return format_ok;
}
void EST_Option::add_prefix(EST_String prefix)
{
EST_Litem *ptr;
for (ptr = list.head(); ptr; ptr = ptr->next())
change_key(ptr, prefix + key(ptr));
}
void EST_Option::remove_prefix(EST_String prefix)
{
(void)prefix;
}
ostream& operator << (ostream& s, const EST_Option &kv)
{
EST_Litem *ptr;
for (ptr = kv.list.head(); ptr; ptr = ptr->next())
s << kv.key(ptr) << "\t" << kv.val((EST_Litem *)ptr) << endl;
return s;
}

View File

@ -0,0 +1,206 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Mar 18 1997 */
/************************************************************************/
/* */
/* Implementation of a class for manipulating filenames and so on. */
/* */
/* This is all hard coded to be unix filenames. I think the best */
/* strategy is to have a separate version of this for any other */
/* pathname format rather than trying to parameterise this. Most of */
/* it is fairly simple. */
/* */
/************************************************************************/
#include "EST_unix.h"
#include "EST_Pathname.h"
void EST_Pathname::setup(void)
{
}
int EST_Pathname::is_absolute(void) const
{
return length()>0 && (*this)(0) == '/';
}
int EST_Pathname::is_dirname(void) const
{
return length()>0 && (*this)(length()-1) == '/';
}
EST_Pathname EST_Pathname::directory(void) const {
if (is_dirname())
return *this;
int pos;
if ((pos=index("/", -1)) >=0)
return before(pos+1);
else
return "./";
}
EST_Pathname EST_Pathname::as_file(void) const
{
if (is_filename())
return *this;
if (length() > 0)
return before(-1);
return ".";
}
EST_Pathname EST_Pathname::as_directory(void) const
{
if (is_dirname())
return *this;
if (length() > 0)
{
EST_String xx;
xx = EST_String(*this) + "/";
return xx;
}
return "./";
}
EST_Pathname EST_Pathname::construct(EST_Pathname dir,
EST_String filename)
{
EST_String result(dir.as_directory());
result += filename;
return result;
}
EST_Pathname EST_Pathname::construct(EST_Pathname dir,
EST_String basename,
EST_String extension)
{
EST_Pathname filename(basename + "." + extension);
return EST_Pathname::construct(dir, filename);
}
EST_TList<EST_String> EST_Pathname::entries(int check_for_directories) const
{
DIR *dir;
EST_TList<EST_String> list;
if ((dir = opendir(this->as_directory()))!=NULL)
{
struct dirent *entry;
while ((entry = readdir(dir)) != NULL)
{
EST_Pathname name(entry->d_name);
struct stat buf;
if (check_for_directories &&
stat((EST_String)this->as_directory() + (EST_String)name, &buf)==0 &&
(buf.st_mode & S_IFDIR))
list.append(name.as_directory());
else
list.append(name);
}
closedir(dir);
}
return list;
}
EST_Pathname operator + (const EST_Pathname p, const EST_Pathname addition)
{return EST_Pathname::append(p, addition); }
EST_Pathname operator + (const char *p, const EST_Pathname addition)
{return EST_Pathname::append(p, addition); }
#if 0
EST_Pathname operator += (EST_Pathname p, const EST_Pathname addition)
{ EST_String q = EST_Pathname::append(p, addition); return q; }
EST_Pathname operator += (EST_Pathname p, const EST_String addition)
{ EST_String q = EST_Pathname::append(p, addition); return q; }
#endif
EST_Pathname EST_Pathname::append(EST_Pathname directory, EST_Pathname addition)
{
if (addition.is_absolute())
return addition;
EST_String add(addition);
EST_String result(directory.as_directory());
result += add;
return result;
}
EST_String EST_Pathname::extension(void) const
{
EST_String result("");
if (length() <= 0)
return result;
if (contains("."))
result = after(index(".",-1));
return result;
}
EST_Pathname EST_Pathname::filename(void) const
{
EST_String result(this->as_file());
if (contains("/"))
result = result.after(index("/",-1));
return result;
}
EST_String EST_Pathname::basename(int remove_all) const
{
EST_String result(this->as_file().filename());
if (remove_all)
{
if (result.contains("."))
result = result.before(".");
}
return result;
}

View File

@ -0,0 +1,201 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Mar 18 1997 */
/************************************************************************/
/* */
/* Implementation of a class for manipulating filenames and so on. */
/* */
/* This is all hard coded to be unix filenames. I think the best */
/* strategy is to have a separate version of this for any other */
/* pathname format rather than trying to parameterise this. Most of */
/* it is fairly simple. */
/* */
/************************************************************************/
#include <cstdio>
#include "EST_System.h"
#include "EST_Pathname.h"
void EST_Pathname::setup(void)
{
this->gsub("/", "\\");
}
int EST_Pathname::is_absolute(void) const
{
return length()>0 && (*this)[0] == '\\';
}
int EST_Pathname::is_dirname(void) const
{
return length()>0 && (*this)[length()-1] == '\\';
}
EST_Pathname EST_Pathname::directory(void) const {
if (is_dirname())
return *this;
int pos;
if ((pos=index("\\", -1)) >=0)
return before(pos+1);
else
return ".\\";
}
EST_Pathname EST_Pathname::as_file(void) const
{
if (is_filename())
return *this;
if (length() > 0)
return before(-1);
return ".";
}
EST_Pathname EST_Pathname::as_directory(void) const
{
if (is_dirname())
return *this;
if (length() > 0)
return ((EST_String)(*this) + (EST_String)"\\");
return ".\\";
}
EST_Pathname EST_Pathname::construct(EST_Pathname dir,
EST_String filename)
{
EST_Pathname result(dir.as_directory());
result += filename;
return result;
}
EST_Pathname EST_Pathname::construct(EST_Pathname dir,
EST_String basename,
EST_String extension)
{
EST_Pathname filename(basename + "." + extension);
return EST_Pathname::construct(dir, filename);
}
EST_TList<EST_String> EST_Pathname::entries(int check_for_directories) const
{
WIN32_FIND_DATA find_data;
HANDLE handle;
EST_TList<EST_String> list;
EST_Pathname pattern(this->as_directory() + EST_Pathname("*"));
handle = FindFirstFile(pattern, &find_data);
if (handle != INVALID_HANDLE_VALUE)
while (1==1)
{
EST_Pathname name(find_data.cFileName);
if (check_for_directories
&& (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
list.append(name.as_directory());
else
list.append(name);
if (!FindNextFile(handle, &find_data))
break;
}
FindClose(handle);
return list;
}
EST_Pathname EST_Pathname::append(EST_Pathname directory, EST_Pathname addition)
{
if (addition.is_absolute())
return addition;
EST_String add(addition);
EST_Pathname result(directory.as_directory());
result.EST_String::operator += (add);
return result;
}
EST_String EST_Pathname::extension(void) const
{
EST_String result("");
if (length() <= 0)
return result;
if (contains("."))
result = after(index(".",-1));
return result;
}
EST_Pathname EST_Pathname::filename(void) const
{
EST_String result(this->as_file());
if (contains("\\"))
result = result.after(index("\\",-1));
return result;
}
EST_String EST_Pathname::basename(int remove_all) const
{
EST_String result(this->as_file().filename());
if (remove_all)
{
if (result.contains("."))
result = result.before(".");
}
return result;
}
EST_Pathname operator + (const EST_Pathname p, const EST_Pathname addition)
{return EST_Pathname::append(p, addition); }
EST_Pathname operator + (const char *p, const EST_Pathname addition)
{return EST_Pathname::append(p, addition); }
EST_Pathname &operator += (EST_Pathname p, const EST_Pathname addition)
{ p = EST_Pathname::append(p, addition); return p; }
EST_Pathname &operator += (EST_Pathname p, const EST_String addition)
{ p = EST_Pathname::append(p, addition); return p; }

105
base_class/EST_SMatrix.cc Normal file
View File

@ -0,0 +1,105 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : April 1995 */
/*-----------------------------------------------------------------------*/
/* Matrix Class for shorts */
/* */
/*=======================================================================*/
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <climits>
#include "EST_String.h"
#include "EST_types.h"
#include "EST_FileType.h"
#include "EST_Option.h"
#include "EST_SMatrix.h"
#include "EST_cutils.h" // for swap functions
#include "EST_Token.h"
#include "rateconv.h"
EST_SMatrix::EST_SMatrix(EST_SMatrix &a, int b)
:EST_TSimpleMatrix<short>(a.num_rows(), a.num_columns())
{
short vv = 0;
if (b < 0)
return;
if (b == 0)
fill(vv);
}
int EST_SMatrix::rateconv(int in_samp_freq, int out_samp_freq)
{
short *in_buf = new short[num_rows()];
short ** results = new short *[num_columns()];
int *len = new int[num_columns()];
int max_len=0;
for(int c=0; c<num_columns(); c++)
{
short *out_buf;
int osize;
copy_column(c, in_buf);
if (::rateconv(in_buf,
num_rows(), &out_buf, &osize,
in_samp_freq, out_samp_freq) == 0)
{
results[c]=out_buf;
len[c]=osize;
if (osize > max_len)
max_len = osize;
}
else
return -1;
}
delete [] in_buf;
resize(max_len, EST_CURRENT, 0);
fill(0);
for(int c1=0; c1<num_columns(); c1++)
{
set_column(c1, results[c1], 0, len[c1]);
delete [] results[c1];
}
delete [] results;
delete [] len;
return 0;
}

View File

@ -0,0 +1,171 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : June 1996 */
/*-----------------------------------------------------------------------*/
/* */
/* A class for building EST_String (char-based) tries for indexing */
/* arbitrary objects by Strings */
/* */
/*=======================================================================*/
#include "EST_String.h"
#include "EST_StringTrie.h"
#include <cstring>
#define TRIEWIDTH 256
static void (* trie_delete_function)(void *n) = 0;
static inline int char2idx(unsigned char k)
{
// return k & 0x7f; // only seven significant bits;
return k;
}
EST_TrieNode::EST_TrieNode(const int width)
{
// Initialise a node of given width
w=width;
d= new EST_TrieNode *[w];
contents=0;
memset(d,0,w*sizeof(EST_TrieNode *));
}
EST_TrieNode::~EST_TrieNode()
{
int i;
if (trie_delete_function != 0) /* user supplied delete function */
trie_delete_function(contents);
for (i=0; i<w; i++)
delete d[i];
delete [] d;
}
void *EST_TrieNode::lookup(const unsigned char *key) const
{
// find key in EST_TrieNode, 0 if not found
if (*key == '\0')
return contents; // base case
else
{
int idx = char2idx(*key);
if (d[idx] == 0)
return 0; // not there
else
return d[idx]->lookup(key+1);
}
}
void EST_TrieNode::copy_into(EST_StringTrie &trie,
const EST_String &path) const
{
// find all items and add them to trie
if (contents != 0)
trie.add(path,contents);
for (int i=0; i < w; i++)
{
if (d[i] != 0)
{
char tail[2];
tail[0] = (char)i;
tail[1] = '\0';
d[i]->copy_into(trie,path+tail);
}
}
}
void EST_TrieNode::add(const unsigned char *key,void *value)
{
// add this value
if (*key == '\0')
contents = value;
else
{
int idx = char2idx(*key);
if (d[idx] == 0) // need new subnode
d[idx] = new EST_TrieNode(w);
d[idx]->add(key+1,value);
}
}
EST_StringTrie::EST_StringTrie()
{
tree = new EST_TrieNode(TRIEWIDTH);
}
void EST_StringTrie::copy(const EST_StringTrie &trie)
{
// This can't work because of the void* pointers in contents
delete tree;
tree = new EST_TrieNode(TRIEWIDTH);
trie.tree->copy_into(*this,"");
}
EST_StringTrie::~EST_StringTrie()
{
delete tree;
}
void *EST_StringTrie::lookup(const EST_String &key) const
{
const unsigned char *ckey = (const unsigned char *)(void *)(const char *)key;
return tree->lookup(ckey);
}
void EST_StringTrie::add(const EST_String &key,void *item)
{
const unsigned char *ckey = (const unsigned char *)(void *)(const char *)key;
tree->add(ckey,item);
return;
}
void EST_StringTrie::clear(void)
{
delete tree;
tree = new EST_TrieNode(TRIEWIDTH);
}
void EST_StringTrie::clear(void (*deletenode)(void *n))
{
// This wont work if we go multi-thread
trie_delete_function = deletenode;
delete tree;
trie_delete_function = 0;
tree = new EST_TrieNode(TRIEWIDTH);
}

157
base_class/EST_TBuffer.cc Normal file
View File

@ -0,0 +1,157 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Extending buffers, i.e. arrays which grow as needed. I got fed up */
/* of writing this code all over the place. */
/* */
/*************************************************************************/
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include "EST_unix.h"
#include "EST_TBuffer.h"
template<class T>
EST_TBuffer<T>::EST_TBuffer(unsigned int size, int step)
{
p_buffer = NULL;
init(size, step);
}
template<class T>
EST_TBuffer<T>::~EST_TBuffer(void)
{
// save the buffer if we have a slot
for(int i=0; i<TBUFFER_N_OLD; i++)
if (EST_old_buffers[i].mem == NULL)
{
EST_old_buffers[i].mem = p_buffer;
EST_old_buffers[i].size = p_size*sizeof(T);
p_buffer = NULL;
p_size =0;
break;
}
if (p_buffer)
{
delete[] p_buffer;
p_buffer = NULL;
p_size = 0;
}
}
template<class T>
void EST_TBuffer<T>::init(unsigned int size, int step)
{
for(int i=0; i<TBUFFER_N_OLD; i++)
if (EST_old_buffers[i].size/sizeof(T) >= size)
{
p_buffer = (T *)EST_old_buffers[i].mem;
p_size = EST_old_buffers[i].size/sizeof(T);
EST_old_buffers[i].mem = NULL;
EST_old_buffers[i].size = 0;
break;
}
if (p_buffer == NULL)
{
p_buffer = new T[size];
p_size = size;
}
p_step = step;
}
template<class T>
void EST_TBuffer<T>::expand_to(unsigned int req_size, bool copy)
{
if (req_size > p_size)
{
unsigned int new_size = p_size;
while(new_size < req_size)
if (p_step >0)
new_size += p_step;
else
new_size = (int)(new_size*(float)(-p_step)/100.0);
T * new_buffer = new T[new_size];
if (copy)
memcpy(new_buffer, p_buffer, p_size*sizeof(T));
delete[] p_buffer;
p_buffer = new_buffer;
p_size = new_size;
}
}
template<class T>
void EST_TBuffer<T>::expand_to(unsigned int req_size, const T &set_to, int howmany)
{
if (req_size > p_size)
{
unsigned int new_size = p_size;
while(new_size < req_size)
if (p_step >0)
new_size += p_step;
else
new_size = (int)(new_size*(float)(-p_step)/100.0);
T * new_buffer = new T[new_size];
if (howmany<0)
howmany=new_size;
for(int i=0; i<howmany; i++)
new_buffer[i] = set_to;
delete[] p_buffer;
p_buffer = new_buffer;
p_size = new_size;
}
}
template<class T>
void EST_TBuffer<T>::set(const T &set_to, int howmany)
{
if (howmany < 0)
howmany = p_size;
for(int i=0; i<howmany; i++)
p_buffer[i] = set_to;
}

235
base_class/EST_TDeque.cc Normal file
View File

@ -0,0 +1,235 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* -------------------------------------------------------------------- */
/* Double ended queue. */
/* */
/* Implemented in a vector used as a circular buffer. When more space */
/* is needed we expand the vector and copy the data to the beginning */
/* of the buffer. */
/* */
/*************************************************************************/
#include "EST_error.h"
#include "EST_TDeque.h"
template <class T>
EST_TDeque<T>::EST_TDeque(unsigned int capacity, unsigned int increment)
: p_vector(capacity)
{
p_increment = increment;
p_front=0;
p_back=0;
}
template <class T>
EST_TDeque<T>::EST_TDeque(unsigned int capacity)
: p_vector(capacity)
{
p_increment = 10;
p_front=0;
p_back=0;
}
template <class T>
EST_TDeque<T>::EST_TDeque()
{
p_vector.resize(10);
p_increment = 10;
p_front=0;
p_back=0;
}
template <class T>
ostream &EST_TDeque<T>::print(ostream &s) const
{
s << "{" << p_vector.n() << "|";
if (p_front >= p_back)
{
for(int i0=0; i0<p_back; i0++)
s << "<>" << "//";
for(int i=p_back; i<p_front; i++)
s << p_vector(i) << "//";
for(int in=p_front; in <p_vector.n(); in++)
s << "<>" << "//";
}
else
{
for(int ii=0; ii<p_front; ii++)
s << p_vector(ii) << "//";
for(int i0=p_front; i0<p_back; i0++)
s << "<>" << "//";
for(int i=p_back; i<p_vector.n(); i++)
s << p_vector(i) << "//";
}
return s << "}";
}
template <class T>
void EST_TDeque<T>::expand()
{
EST_TVector<T> tmp(p_vector);
if (p_back==0)
// special case for pure stack
p_vector.resize(p_vector.n()+p_increment, true);
else
{
p_vector.resize(p_vector.n()+p_increment, false);
if (p_front >= p_back)
for(int i=p_back, j=0; i<p_front; i++, j++)
p_vector[j] = tmp[i];
else
{
int j=0;
for(int i=p_back; i<tmp.n(); i++, j++)
p_vector[j] = tmp[i];
for(int ii=0; ii<p_front; ii++, j++)
p_vector[j] = tmp[ii];
p_back=0;
p_front=j;
}
}
}
template <class T>
bool EST_TDeque<T>::is_empty() const
{
return p_front==p_back;
}
template <class T>
void EST_TDeque<T>::clear()
{
p_front=p_back=0;
for(int i=0; i<p_vector.n(); i++)
p_vector[i]=*Filler;
}
template <class T>
void EST_TDeque<T>::push(T& it)
{
int next_front= p_front+1;
if (next_front >= p_vector.n())
next_front= 0;
if (next_front==p_back)
{
expand();
push(it);
}
else
{
p_vector[p_front] = it;
p_front=next_front;
}
}
template <class T>
T &EST_TDeque<T>::pop()
{
if (is_empty())
EST_error("empty stack!");
p_front--;
if (p_front < 0)
p_front=p_vector.n()-1;
return p_vector[p_front];
}
template <class T>
T &EST_TDeque<T>::nth(int n)
{
if (is_empty())
EST_error("empty stack!");
int pos = p_front-1-n;
if (p_front < p_back)
{
if (pos < 0)
{
pos += p_vector.n();
if (pos < p_back)
EST_error("looking too far up stack!");
}
}
else
if (pos < p_back)
EST_error("looking too far up stack!");
return p_vector[pos];
}
template <class T>
void EST_TDeque<T>::back_push(T& it)
{
int next_back = p_back-1;
if (next_back < 0)
next_back = p_vector.n()-1;
if (next_back == p_front)
{
expand();
back_push(it);
}
else
{
p_vector[p_back=next_back] = it;
}
}
template <class T>
T &EST_TDeque<T>::back_pop()
{
if (is_empty())
EST_error("empty stack!");
int old_back = p_back;
p_back++;
if (p_back >= p_vector.n())
p_back=0;
return p_vector[old_back];
}

270
base_class/EST_THash.cc Normal file
View File

@ -0,0 +1,270 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Fri Apr 4 1997 */
/************************************************************************/
/* */
/* Simple Hash classes. */
/* */
/************************************************************************/
#include "EST_THash.h"
template<class K, class V>
EST_THash<K,V>::EST_THash(int size, unsigned int (*hash_function)(const K &key, unsigned int size))
{
p_num_entries =0;
p_num_buckets = size;
p_buckets = new EST_Hash_Pair<K,V> *[size];
for(int i=0; i<size;i++)
p_buckets[i] = NULL;
p_hash_function = hash_function;
}
template<class K, class V>
EST_THash<K,V>::EST_THash(const EST_THash<K,V> &from)
{
p_buckets=NULL;
copy(from);
}
template<class K, class V>
void EST_THash<K,V>::clear(void)
{
if (p_buckets != NULL)
{
for(unsigned int i=0; i<p_num_buckets;i++)
{
EST_Hash_Pair<K,V> *p, *n;
for(p=p_buckets[i]; p != NULL; p=n)
{
n = p->next;
delete p;
}
p_buckets[i]=NULL;
}
}
p_num_entries=0;
}
template<class K, class V>
EST_THash<K,V>::~EST_THash(void)
{
if (p_buckets)
{
clear();
delete[] p_buckets;
}
}
template<class K, class V>
int EST_THash<K,V>::present(const K &key) const
{
unsigned int b;
if (p_hash_function)
b = (*p_hash_function)(key, p_num_buckets);
else
b = DefaultHashFunction((void *)&key, sizeof(key), p_num_buckets);
EST_Hash_Pair<K,V> *p;
for(p=p_buckets[b]; p!=NULL; p=p->next)
if (p->k == key)
return TRUE;
return FALSE;
}
template<class K, class V>
V &EST_THash<K,V>::val(const K &key, int &found) const
{
unsigned int b;
if (p_hash_function)
b = (*p_hash_function)(key, p_num_buckets);
else
b = DefaultHashFunction((void *)&key, sizeof(key), p_num_buckets);
EST_Hash_Pair<K,V> *p;
for(p=p_buckets[b]; p!=NULL; p=p->next)
if (p->k == key)
{
found=1;
return p->v;
}
found=0;
return Dummy_Value;
}
template<class K, class V>
const K &EST_THash<K,V>::key(const V &val, int &found) const
{
for(unsigned int b=0; b<p_num_buckets; b++)
{
EST_Hash_Pair<K,V> *p;
for(p=p_buckets[b]; p!=NULL; p=p->next)
if (p->v == val)
{
found=1;
return p->k;
}
}
found=0;
return Dummy_Key;
}
template<class K, class V>
void EST_THash<K,V>::map(void (*func)(K&, V&))
{
for(unsigned int i=0; i<p_num_buckets; i++)
{
EST_Hash_Pair<K,V> *p;
for(p=p_buckets[i]; p!=NULL; p=p->next)
(*func)(p->k, p->v);
}
}
template<class K, class V>
int EST_THash<K,V>::add_item(const K &key, const V &value, int no_search)
{
unsigned int b;
if (p_hash_function)
b = (*p_hash_function)(key, p_num_buckets);
else
b = DefaultHashFunction((void *)&key, sizeof(key), p_num_buckets);
EST_Hash_Pair<K,V> *p;
if (!no_search)
for(p=p_buckets[b]; p!=NULL; p=p->next)
if (p->k == key)
{
p->v = value;
return FALSE;
}
p = new EST_Hash_Pair<K,V>;
p->k = key;
p->v = value;
p->next = p_buckets[b];
p_buckets[b] = p;
p_num_entries++;
return TRUE;
}
template<class K, class V>
int EST_THash<K,V>::remove_item(const K &rkey, int quiet)
{
unsigned int b;
if (p_hash_function)
b = (*p_hash_function)(rkey, p_num_buckets);
else
b = DefaultHashFunction((void *)&rkey, sizeof(rkey), p_num_buckets);
EST_Hash_Pair<K,V> **p;
for (p = &(p_buckets[b]); *p!=NULL; p=&((*p)->next))
if ( (*p)->k == rkey )
{
EST_Hash_Pair<K,V> *n = (*p)->next;
delete *p;
*p = n;
p_num_entries--;
return 0;
}
if (!quiet)
cerr << "THash: no item labelled \"" << rkey << "\"" << endl;
return -1;
}
template<class K, class V>
EST_THash<K,V> &EST_THash<K,V>::operator = (const EST_THash<K,V> &from)
{
copy(from);
return *this;
}
template<class K, class V>
void EST_THash<K,V>::dump(ostream &stream, int all)
{
for(unsigned int i=0; i<p_num_buckets; i++)
if (all || p_buckets[i])
{
stream << i << ": ";
EST_Hash_Pair<K,V> *p;
for(p=p_buckets[i]; p!=NULL; p=p->next)
stream << "[" << p->k << "],(" << p->v << ") ";
stream << "\n";
}
}
template<class K, class V>
void EST_THash<K,V>::copy(const EST_THash<K,V> &from)
{
clear();
p_num_entries = from.p_num_entries;
p_num_buckets = from.p_num_buckets;
p_hash_function = from.p_hash_function;
if (p_buckets != NULL)
delete [] p_buckets;
p_buckets = new EST_Hash_Pair<K,V> *[p_num_buckets];
for(unsigned int b=0; b<p_num_buckets; b++)
{
p_buckets[b]=NULL;
for(EST_Hash_Pair<K,V> *p=from.p_buckets[b]; p; p=p->next)
{
EST_Hash_Pair<K,V> *n = new EST_Hash_Pair<K,V>(*p);
n->next = p_buckets[b];
p_buckets[b]=n;
}
}
}

304
base_class/EST_TKVL.cc Normal file
View File

@ -0,0 +1,304 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : May 1995 */
/*-----------------------------------------------------------------------*/
/* Key/value List Class source file */
/* */
/*=======================================================================*/
#include <cstdlib>
#include "EST_TKVL.h"
#include "EST_error.h"
template <class K, class V> EST_TKVL<K, V>::EST_TKVL(const EST_TKVL<K, V> &kv)
{
list = kv.list;
}
template <class K, class V>
void EST_TKVL<K, V>::clear(void)
{
list.clear();
}
template <class K, class V>
EST_Litem *EST_TKVL<K, V>::find_pair_key(const K &key) const
{
EST_Litem *ptr;
for (ptr = list.head(); ptr != 0; ptr= ptr->next())
if (list.item(ptr).k == key)
return ptr;
return 0;
}
template <class K, class V>
EST_Litem *EST_TKVL<K, V>::find_pair_val(const V &val) const
{
EST_Litem *ptr;
/// cout << "function list\n" << endl;
for (ptr = list.head(); ptr != 0; ptr= ptr->next())
{
// cout << "ff: " << list.item(ptr).k << endl;
if (list.item(ptr).v == val)
return ptr;
}
return 0;
}
// look for pointer kptr in list. If found, change its value to rval and
// return true, otherwise return false.
template <class K, class V>
int EST_TKVL<K, V>::change_val(EST_Litem *kptr, const V &rval)
{
if (list.index(kptr) == -1)
return 0;
else
{
list.item(kptr).v = rval;
return 1;
}
}
template <class K, class V>
int EST_TKVL<K, V>::change_key(EST_Litem *kptr, const K &rkey)
{
if (list.index(kptr) == -1)
return 0;
else
{
list.item(kptr).k = rkey;
return 1;
}
}
// look for key rkey in list. If found, change its value to rval and
// return true, otherwise return false.
template <class K, class V>
int EST_TKVL<K, V>::change_val(const K &rkey,const V &rval)
{
EST_Litem *ptr=find_pair_key(rkey);
if (ptr == 0)
return 0;
else
{
list.item(ptr).v = rval;
return 1;
}
}
// NOTE: This _MUST_NOT_ change the EST_TKVL, if it needs to, a separate
// const version will need to replace the dummy one below.
template<class K, class V>
V &EST_TKVL<K, V>::val(const K &rkey, bool must)
{
EST_Litem *ptr = find_pair_key(rkey);
if (ptr == 0)
{
if (must)
EST_error("No value set for '%s'", error_name(rkey));
return *default_val;
}
else
return list.item(ptr).v;
}
template<class K, class V>
const V &EST_TKVL<K, V>::val(const K &rkey, bool must) const
{
return ((EST_TKVL<K, V> *)this)->val(rkey, must);
}
template<class K, class V>
const V &EST_TKVL<K, V>::val_def(const K &rkey, const V &def) const
{
EST_Litem *ptr = find_pair_key(rkey);
if (ptr == 0)
return def;
else
return list.item(ptr).v;
}
// NOTE: This _MUST_NOT_ change the EST_TKVL, if it needs to, a separate
// const version will need to replace the dummy one below.
template<class K, class V>
V &EST_TKVL<K, V>::val(EST_Litem *kptr, bool must)
{
if (must == 0)
return list.item(kptr).v;
/* check kptr is one of mine */
if (list.index(kptr) == -1)
{
if (must)
EST_error("No value set in EST_TKVL");
return *default_val;
}
else
return list.item(kptr).v;
}
template<class K, class V>
const V &EST_TKVL<K, V>::val(EST_Litem *kptr, bool must) const
{
return ((EST_TKVL<K, V> *)this)->val(kptr, must);
}
// NOTE: This _MUST_NOT_ change the EST_TKVL, if it needs to, a separate
// const version will need to replace the dummy one below.
template<class K, class V>
K &EST_TKVL<K, V>::key(EST_Litem *kptr, int must)
{
if (must == 0)
return list.item(kptr).k;
if (list.index(kptr) == -1)
EST_error("No value set in EST_TKVL");
return list.item(kptr).k;
}
template<class K, class V>
const K &EST_TKVL<K, V>::key(EST_Litem *kptr, int must) const
{
return ((EST_TKVL<K, V> *)this)->key(kptr, must);
}
template<class K, class V>
const K &EST_TKVL<K, V>::key(const V &v, int must) const
{
EST_Litem *ptr = find_pair_val(v);
if (ptr == 0)
{
if (must)
EST_error("No value set for '%s'", error_name(v));
return *default_key;
}
return list.item(ptr).k;
}
template<class K, class V>
const int EST_TKVL<K, V>::present(const K &rkey) const
{
if (find_pair_key(rkey) == 0)
return 0;
else
return 1;
}
// map a function over the pairs
template<class K, class V>
void EST_TKVL<K,V>::map(void (*func)(K&, V&))
{
EST_Litem *p;
for(p=list.head(); p; p=p->next())
{
EST_TKVI<K,V> item = list.item(p);
(*func)(item.k, item.v);
}
}
// add item to list. By default, the list is searched to see if the
// item exists already. If so, its value is overwritten. This facility
// can be turned off by setting no_search = 1;
template<class K, class V>
int EST_TKVL<K, V>::add_item(const K &rkey, const V &rval, int no_search)
{
if (!no_search)
if (change_val(rkey, rval)) // first see if key exists
return 1;
EST_TKVI<K,V> item;
item.k = rkey;
item.v = rval;
list.append(item);
return 1;
}
template<class K, class V>
int EST_TKVL<K, V>::remove_item(const K &rkey, int quiet)
{
EST_Litem *ptr = find_pair_key(rkey);
const char *en;
if (ptr == 0)
{
if (!quiet)
{
en = error_name(rkey);
EST_warning("EST_TKVL: no item labelled '%s'", en);
}
return -1;
}
else
{
list.remove(ptr);
return 0;
}
}
template<class K, class V> EST_TKVL<K, V> &EST_TKVL<K, V>::operator =
(const EST_TKVL<K, V> &kv)
{
list = kv.list;
return *this;
}
template<class K, class V> EST_TKVL<K, V> &EST_TKVL<K, V>::operator +=
(const EST_TKVL<K, V> &kv)
{
list += kv.list;
return *this;
}
template<class K, class V> EST_TKVL<K, V> EST_TKVL<K, V>::operator + (const EST_TKVL<K, V> &kv)
{
EST_TKVL<K, V> result;
result = *this;
result += kv;
return result;
}

133
base_class/EST_TList.cc Normal file
View File

@ -0,0 +1,133 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Paul Taylor */
/* Date : April 1995 */
/* --------------------------------------------------------------------- */
/* Template List Class */
/* */
/* Modified by RJC, 21/7/97. Now much of the working code is in the */
/* UList class, this template class provides a type safe front end to */
/* the untyped list. */
/* */
/*************************************************************************/
#include "EST_TList.h"
template<class T> EST_TItem<T> *EST_TItem<T>::make(const T &val)
{
EST_TItem<T> *it=NULL;
if (s_free!=NULL)
{
void *mem = s_free;
s_free=(EST_TItem<T> *)s_free->n;
s_nfree--;
// Create an item in the retrieved memory.
it=new (mem) EST_TItem<T>(val);
}
else
it = new EST_TItem<T>(val);
return it;
}
template<class T> void EST_TItem<T>::release(EST_TItem<T> *it)
{
if (0) // (s_nfree < s_maxFree)
{
// Destroy the value in case it holds resources.
it->EST_TItem<T>::~EST_TItem();
// I suppose it's a bit weird to use 'n' after calling the destructor.
it->n=s_free;
s_free=it;
s_nfree++;
}
else
{
delete it;
}
}
template<class T> void EST_TList<T>::copy_items(const EST_TList<T> &l)
{
EST_UItem *p;
for (p = l.head(); p; p = p->next())
append(l.item(p));
}
template<class T> void EST_TList<T>::free_item(EST_UItem *item)
{ EST_TItem<T>::release((EST_TItem<T> *)item); }
template<class T> EST_TList<T>::EST_TList(const EST_TList<T> &l)
{
init();
copy_items(l);
}
template<class T> void EST_TList<T>::exchange_contents(EST_Litem *a,EST_Litem *b)
{
if(a==b)
return;
T temp;
temp = ((EST_TItem<T> *)a)->val;
((EST_TItem<T> *)a)->val = ((EST_TItem<T> *)b)->val;
((EST_TItem<T> *)b)->val = temp;
}
template<class T> EST_TList<T> &EST_TList<T>::operator=(const EST_TList<T> &a)
{
clear(); // clear out all current items in list.
copy_items(a);
return *this;
}
template<class T> EST_TList<T> &EST_TList<T>::operator+=(const EST_TList<T> &a)
{
if (this == &a)
{
cerr << "EST_TList: error: tried to add list to itself\n";
return *this;
}
copy_items(a);
return *this;
}

601
base_class/EST_TMatrix.cc Normal file
View File

@ -0,0 +1,601 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Paul Taylor */
/* Rewritten : Richard Caley */
/* ------------------------------------------------------------------- */
/* Template EST_TMatrix Class */
/* */
/*************************************************************************/
#include "EST_TMatrix.h"
#include <fstream>
#include <iostream>
#include "EST_bool.h"
#include "EST_matrix_support.h"
#include "EST_TVector.h"
#include "EST_cutils.h"
#include "EST_error.h"
/* Construction and destruction
*/
template<class T>
void EST_TMatrix<T>::default_vals()
{
EST_TVector<T>::default_vals();
p_num_rows = 0;
p_row_step=0;
}
template<class T>
EST_TMatrix<T>::EST_TMatrix()
{
default_vals();
}
template<class T>
EST_TMatrix<T>::EST_TMatrix(const EST_TMatrix<T> &in)
{
default_vals();
copy(in);
}
template<class T>
EST_TMatrix<T>::EST_TMatrix(int rows, int cols)
{
default_vals();
resize(rows, cols);
}
template<class T>
EST_TMatrix<T>::EST_TMatrix(int rows, int cols,
T *memory, int offset, int free_when_destroyed)
{
default_vals();
set_memory(memory, offset, rows, cols, free_when_destroyed);
}
template<class T>
EST_TMatrix<T>::~EST_TMatrix()
{
p_num_rows = 0;
p_row_step=0;
}
/* Basic access
*/
template<class T>
T &EST_TMatrix<T>::a_check(int row, int col)
{
if (!EST_matrix_bounds_check(row, col, num_rows(), num_columns(), FALSE))
return *this->error_return;
return a_no_check(row,col);
}
/* Since we know a() itself doesn't change the matrix, we can cast away
* the const here. Isn't the C++ syntax beautiful!
*/
template<class T>
const T &EST_TMatrix<T>::a_check(int row, int col) const
{
return ((EST_TMatrix<T> *)this)->a(row,col);
}
template<class T>
void EST_TMatrix<T>::copy_data(const EST_TMatrix<T> &a)
{
set_values(a.p_memory,
a.p_row_step, a.p_column_step,
0, a.num_rows(),
0, a.num_columns());
}
template<class T>
void EST_TMatrix<T>::set_values(const T *data,
int r_step, int c_step,
int start_r, int num_r,
int start_c, int num_c
)
{
for(int r=start_r, i=0, rp=0; i< num_r; i++, r++, rp+=r_step)
for(int c=start_c, j=0, cp=0; j< num_c; j++, c++, cp+=c_step)
a_no_check(r,c) = data[rp+cp];
}
template<class T>
void EST_TMatrix<T>::get_values(T *data,
int r_step, int c_step,
int start_r, int num_r,
int start_c, int num_c
) const
{
for(int r=start_r, i=0, rp=0; i< num_r; i++, r++, rp+=r_step)
for(int c=start_c, j=0, cp=0; j< num_c; j++, c++, cp+=c_step)
data[rp+cp] = a_no_check(r,c);
}
template<class T>
void EST_TMatrix<T>::copy(const EST_TMatrix<T> &a)
{
resize(a.num_rows(), a.num_columns(), 0);
copy_data(a);
}
template<class T>
EST_TMatrix<T> &EST_TMatrix<T>::operator=(const EST_TMatrix<T> &in)
{
copy(in);
return *this;
}
template<class T>
EST_TMatrix<T> &EST_TMatrix<T>::add_rows(const EST_TMatrix<T> &in)
{
if (in.num_columns() != num_columns())
EST_error("Can't add rows with differnet number of columns (%d vs %d)",
in.num_columns(),
num_columns()
);
else
{
int old_num_rows = num_rows();
resize(num_rows()+in.num_rows(), num_columns(), TRUE);
for(int i=old_num_rows, i1=0; i<num_rows(); i++, i1++)
for(int j=0; j<num_columns(); j++)
a(i,j) = in.a(i1,j);
}
return *this;
}
template<class T>
EST_TMatrix<T> &EST_TMatrix<T>::add_columns(const EST_TMatrix<T> &in)
{
if (in.num_rows() != num_rows())
EST_error("Can't add columns with differnet number of rows (%d vs %d)",
in.num_rows(),
num_rows()
);
else
{
int old_num_columns = num_columns();
resize(num_columns()+in.num_columns(), num_rows(), TRUE);
for(int i=old_num_columns, i1=0; i<num_columns(); i++, i1++)
for(int j=0; j<num_rows(); j++)
a(i,j) = in.a(i1,j);
}
return *this;
}
template<class T>
void EST_TMatrix<T>::just_resize(int new_rows,
int new_cols,
T** old_vals)
{
T *new_m;
if (num_rows() != new_rows || num_columns() != new_cols || this->p_memory == NULL )
{
if (this->p_sub_matrix)
EST_error("Attempt to resize Sub-Matrix");
if (new_cols < 0 || new_rows < 0)
EST_error("Attempt to resize matrix to negative size: %d x %d",
new_rows,
new_cols);
new_m = new T[new_rows*new_cols];
if (this->p_memory != NULL)
{
if (old_vals != NULL)
*old_vals = this->p_memory;
else if (!this->p_sub_matrix)
delete [] (this->p_memory-this->p_offset);
}
p_num_rows = new_rows;
this->p_num_columns = new_cols;
this->p_offset=0;
p_row_step=this->p_num_columns;
this->p_column_step=1;
this->p_memory = new_m;
}
else
*old_vals = this->p_memory;
}
template<class T>
void EST_TMatrix<T>::resize(int new_rows, int new_cols, int set)
{
int i,j;
T * old_vals = this->p_memory;
int old_rows = num_rows();
int old_cols = num_columns();
int old_row_step = p_row_step;
int old_offset = this->p_offset;
int old_column_step = this->p_column_step;
if (new_rows<0)
new_rows = old_rows;
if (new_cols<0)
new_cols = old_cols;
just_resize(new_rows, new_cols, &old_vals);
if (set)
{
int copy_r = 0;
int copy_c = 0;
if (old_vals != NULL)
{
copy_r = Lof(num_rows(), old_rows);
copy_c = Lof(num_columns(), old_cols);
set_values(old_vals,
old_row_step, old_column_step,
0, copy_r,
0, copy_c);
}
else
{
copy_r = old_rows;
copy_c = old_cols;
}
for(i=0; i<copy_r; i++)
for(j=copy_c; j<new_cols; j++)
a_no_check(i,j) = *this->def_val;
for(i=copy_r; i<new_rows; i++)
for(j=0; j<new_cols; j++)
a_no_check(i,j) = *this->def_val;
}
if (old_vals && old_vals != this->p_memory && !this->p_sub_matrix)
delete [] (old_vals-old_offset);
}
template<class T>
bool EST_TMatrix<T>::have_rows_before(int n) const
{
return this->p_offset >= n*p_row_step;
}
template<class T>
bool EST_TMatrix<T>::have_columns_before(int n) const
{
return this->p_offset >= n*this->p_column_step;
}
template<class T>
void EST_TMatrix<T>::fill(const T &v)
{
int i, j;
for (i = 0; i < num_rows(); ++i)
for (j = 0; j < num_columns(); ++j)
fast_a_m(i,j) = v;
}
template<class T>
EST_write_status EST_TMatrix<T>::save(const EST_String &filename) const
{
int i, j;
ostream *outf;
if (filename == "-" || filename == "")
outf = &cout;
else
outf = new ofstream(filename);
for (i = 0; i < num_rows(); ++i)
{
for (j = 0; j < num_columns(); ++j)
{
*outf
#if 0
<< "{" <<i<<","<<j
<<",m="<<((int)this->p_memory)<<","
<<"r'="<<((int)((T *) mx_move_pointer_f(this->p_memory, sizeof(T)*p_row_step, i)))<<","
<<"r="<<((int)mx_move_pointer(this->p_memory, T, p_row_step, i))<<","
<<"c="<<((int)mx_move_pointer(this->p_memory, T, this->p_column_step, j))<<","
<<((int)(&fast_a_m_gcc(i,j)))
<<"}"
#endif
<< a_no_check(i,j) << "\t";
}
*outf << endl;
}
if (outf != &cout)
delete outf;
return write_ok;
}
template<class T>
EST_read_status
EST_TMatrix<T>::load(const EST_String &filename)
{
// this function can only be written if we can find a way of parsing
// an unknown type;
(void) filename;
EST_error("Matrix loading not implemented yet.");
return misc_read_error;
}
template<class T>
void EST_TMatrix<T>::set_memory(T *buffer, int offset,
int rows, int columns,
int free_when_destroyed)
{
EST_TVector<T>::set_memory(buffer, offset, columns, free_when_destroyed);
p_num_rows = rows;
p_row_step = columns;
}
template<class T>
void EST_TMatrix<T>::copy_row(int r, T *buf,
int offset, int num) const
{
int to = num >= 0 ? offset + num : num_columns();
if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), FALSE))
{
if (num_rows()>0)
r=0;
else
return;
}
for (int j = offset; j < to; j++)
buf[j-offset] = fast_a_m(r, j);
}
template<class T>
void EST_TMatrix<T>::copy_row(int r, EST_TVector<T> &buf,
int offset, int num) const
{
int to = num >= 0 ? offset + num : num_columns();
if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), FALSE))
{
if (num_rows()>0)
r=0;
else
return;
}
buf.resize(to - offset);
for (int j = offset; j < to; j++)
buf[j - offset] = fast_a_m(r, j);
}
template<class T>
void EST_TMatrix<T>::copy_column(int c, T *buf,
int offset, int num) const
{
if (num_rows() == 0)
return;
int to = num >= 0 ? offset + num : num_rows();
if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), FALSE))
{
if (num_columns()>0)
c=0;
else
return;
}
for (int i = offset; i < to; i++)
buf[i-offset] = fast_a_m(i, c);
}
template<class T>
void EST_TMatrix<T>::copy_column(int c, EST_TVector<T> &buf,
int offset, int num) const
{
if (num_rows() == 0)
return;
int to = num >= 0 ? offset + num : num_rows();
if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), FALSE))
{
if( num_columns()>0 )
c=0;
else
return;
}
buf.resize(to - offset);
for (int i = offset; i < to; i++)
buf[i-offset] = fast_a_m(i, c);
}
template<class T>
void EST_TMatrix<T>::set_row(int r, const T *buf, int offset, int num)
{
int to = num>=0?offset+num:num_columns();
if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), TRUE))
return;
for(int j=offset; j<to; j++)
fast_a_m(r, j) = buf[j-offset];
}
template<class T>
void EST_TMatrix<T>::set_column(int c, const T *buf, int offset, int num)
{
int to = num>=0?offset+num:num_rows();
if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), TRUE))
return;
for(int i=offset; i<to; i++)
fast_a_m(i, c) = buf[i-offset];
}
template<class T>
void EST_TMatrix<T>::set_row(int r,
const EST_TMatrix<T> &from, int from_r, int from_offset,
int offset, int num)
{
int to = num>=0?offset+num:num_columns();
if (!EST_matrix_bounds_check(r, 0, num_rows(), num_columns(), TRUE))
return;
if (!EST_matrix_bounds_check(from_r, 0, from.num_rows(), from.num_columns(), FALSE))
{
if (from.num_rows()>0)
from_r=0;
else
return;
}
for(int j=offset; j<to; j++)
fast_a_m(r, j) = from.fast_a_m(from_r, (j-offset)+from_offset);
}
template<class T>
void EST_TMatrix<T>::set_column(int c,
const EST_TMatrix<T> &from, int from_c, int from_offset,
int offset, int num)
{
int to = num>=0?offset+num:num_rows();
if (!EST_matrix_bounds_check(0, c, num_rows(), num_columns(), TRUE))
return;
if (!EST_matrix_bounds_check(0, from_c, from.num_rows(), from.num_columns(), FALSE))
{
if (from.num_columns()>0)
from_c=0;
else
return;
}
for(int i=offset; i<to; i++)
fast_a_m(i, c) = from.fast_a_m((i-offset)+from_offset, from_c);
}
template<class T>
void EST_TMatrix<T>::row(EST_TVector<T> &rv, int r, int start_c, int len)
{
if (len < 0)
len = num_columns()-start_c;
if (!EST_matrix_bounds_check(r, 1, start_c, len, num_rows(), num_columns(), 0))
return;
if (rv.p_memory != NULL && ! rv.p_sub_matrix)
delete [] (rv.p_memory - rv.p_offset);
rv.p_sub_matrix = TRUE;
rv.p_num_columns = len;
rv.p_offset = this->p_offset + start_c*this->p_column_step + r*p_row_step;
rv.p_memory = this->p_memory - this->p_offset + rv.p_offset;
// cout << "mrow: mem: " << rv.p_memory << " (" << (int)rv.p_memory << ")\n";
// cout << "mrow: ofset: " << rv.p_offset << " (" << (int)rv.p_offset << ")\n";
rv.p_column_step=this->p_column_step;
}
template<class T>
void EST_TMatrix<T>::column(EST_TVector<T> &cv, int c, int start_r, int len)
{
if (len < 0)
len = num_rows()-start_r;
if (!EST_matrix_bounds_check(start_r, len, c, 1,num_rows(), num_columns(), 0))
return;
if (cv.p_memory != NULL && ! cv.p_sub_matrix)
delete [] (cv.p_memory - cv.p_offset);
cv.p_sub_matrix = TRUE;
cv.p_num_columns = len;
cv.p_offset = this->p_offset + c*this->p_column_step + start_r*p_row_step;
cv.p_memory = this->p_memory - this->p_offset + cv.p_offset;
// cout << "mcol: mem: " << cv.p_memory << " (" << (int)cv.p_memory << ")\n";
// cout << "mcol: offset: " << cv.p_offset << " (" << (int)cv.p_offset << ")\n";
cv.p_column_step=p_row_step;
}
template<class T>
void EST_TMatrix<T>::sub_matrix(EST_TMatrix<T> &sm,
int r, int len_r, int c, int len_c)
{
if (len_r < 0)
len_r = num_rows()-r;
if (len_c < 0)
len_c = num_columns()-c;
if (!EST_matrix_bounds_check(r, len_r, c, len_c, num_rows(), num_columns(), 0))
return;
if (sm.p_memory != NULL && ! sm.p_sub_matrix)
delete [] (sm.p_memory - sm.p_offset);
sm.p_sub_matrix = TRUE;
sm.p_offset = this->p_offset + c*this->p_column_step + r*p_row_step;
sm.p_memory = this->p_memory - this->p_offset + sm.p_offset;
sm.p_row_step=p_row_step;
sm.p_column_step=this->p_column_step;
sm.p_num_rows = len_r;
sm.p_num_columns = len_c;
}

View File

@ -0,0 +1,330 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Fri Feb 28 1997 */
/************************************************************************/
/* */
/* A template class which allows names (const char *s) to be */
/* associated with enums, providing conversion. */
/* */
/************************************************************************/
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include "EST_walloc.h"
#include "EST_TNamedEnum.h"
// This only takes a void * because I can't manage to get the
// parameter declaration in the definition past gcc with the actual type.
template<class ENUM, class VAL, class INFO>
void EST_TValuedEnumI<ENUM,VAL,INFO>::initialise(const void *vdefs)
{
int n=0;
typedef EST_TValuedEnumDefinition<ENUM,VAL,INFO> defn;
const defn *defs = (const defn *)vdefs;
for(n=1; defs[n].token != defs[0].token; n++)
;
this->ndefinitions = n;
this->definitions = new defn[n];
this->definitions[0] = defs[0];
for(n=1; defs[n].token != defs[0].token; n++)
this->definitions[n] = defs[n];
this->p_unknown_enum = defs[n].token;
this->p_unknown_value = defs[n].values[0];
}
template<class ENUM, class VAL, class INFO>
void EST_TValuedEnumI<ENUM,VAL,INFO>::initialise(const void *vdefs, ENUM (*conv)(const char *))
{
int n=0;
// const struct EST_TValuedEnumDefinition<const char *,VAL,INFO> *defs = (const struct EST_TValuedEnumDefinition<const char *,VAL,INFO> *)vdefs;
typedef EST_TValuedEnumDefinition<const char *,VAL,INFO> _EST_TMPNAME;
const _EST_TMPNAME *defs = (const _EST_TMPNAME *)vdefs;
// fprintf(stderr, "start setup\n");
for(n=1; strcmp(defs[n].token, defs[0].token) != 0; n++)
{
//const char *a = defs[0].token;
// const char *b = defs[n].token;
// fprintf(stderr, ": %d '%s' '%s'\n", n, defs[n].token, defs[0].token);
}
this->ndefinitions = n;
typedef EST_TValuedEnumDefinition<ENUM,VAL,INFO> defn;
this->definitions = new defn[n];
this->definitions[0].token = conv(defs[0].token);
for(int i=0; i<NAMED_ENUM_MAX_SYNONYMS; i++)
this->definitions[0].values[i] = defs[0].values[i];
this->definitions[0].info = defs[0].info;
for(n=1; strcmp(defs[n].token, defs[0].token) != 0; n++)
{
this->definitions[n].token = conv(defs[n].token);
for(int i2=0; i2<NAMED_ENUM_MAX_SYNONYMS; i2++)
this->definitions[n].values[i2] = defs[n].values[i2];
this->definitions[n].info = defs[n].info;
}
this->p_unknown_enum = conv(defs[n].token);
this->p_unknown_value = defs[n].values[0];
}
template<class ENUM, class VAL, class INFO>
EST_TValuedEnumI<ENUM,VAL,INFO>::~EST_TValuedEnumI(void)
{
if (this->definitions)
delete[] this->definitions;
}
template<class ENUM, class VAL, class INFO>
int EST_TValuedEnumI<ENUM,VAL,INFO>::n(void) const
{
return this->ndefinitions;
}
template<class ENUM, class VAL, class INFO>
VAL EST_TValuedEnumI<ENUM,VAL,INFO>::value (ENUM token, int n) const
{
int i;
for(i=0; i<this->ndefinitions; i++)
if (this->definitions[i].token == token)
return this->definitions[i].values[n];
return this->p_unknown_value;
}
template<class ENUM, class VAL, class INFO>
INFO &EST_TValuedEnumI<ENUM,VAL,INFO>::info (ENUM token) const
{
int i;
for(i=0; i<this->ndefinitions; i++)
if (this->definitions[i].token == token)
return this->definitions[i].info;
cerr << "Fetching info for invalid entry\n";
abort();
static INFO dummyI;
return dummyI;
}
template<class ENUM, class VAL, class INFO>
ENUM EST_TValuedEnumI<ENUM,VAL,INFO>::nth_token (int n) const
{
if (n>=0 && n < this->ndefinitions)
return this->definitions[n].token;
return this->p_unknown_enum;
}
template<class ENUM, class VAL, class INFO>
ENUM EST_TValuedEnumI<ENUM,VAL,INFO>::token (VAL value) const
{
int i,j;
for(i=0; i<this->ndefinitions; i++)
for(j=0; j<NAMED_ENUM_MAX_SYNONYMS && this->definitions[i].values[j] ; j++)
if (eq_vals(this->definitions[i].values[j], value))
return this->definitions[i].token;
return this->p_unknown_enum;
}
template<class ENUM>
EST_read_status EST_TNamedEnum<ENUM>::priv_load(EST_String name, EST_TNamedEnum<ENUM> *definitive)
{
typedef EST_TValuedEnumDefinition<ENUM, const char *, NO_INFO> Defn;
#define LINE_LENGTH (1024)
EST_String line(NULL, 'x', LINE_LENGTH);
char *buffer = (char *)line;
EST_String tokens[NAMED_ENUM_MAX_SYNONYMS+2];
FILE *file;
char quote = '\0';
int have_unknown=0;
int n=0;
if ((file=fopen(name, "rb"))==NULL)
return misc_read_error;
if (this->definitions)
delete[] this->definitions;
this->ndefinitions= -1;
this->definitions=NULL;
buffer[LINE_LENGTH-1] = 'x';
while (fgets(buffer, LINE_LENGTH, file))
{
if ( buffer[LINE_LENGTH-1] != 'x')
{
cerr << "line too long .. '" << buffer << "'\n";
return wrong_format;
}
if (this->ndefinitions>=0 && quote != '\0' && buffer[0] == '=')
{
// definition by number
if ( n>= this->ndefinitions)
{
cerr << "too many definitions\n";
return wrong_format;
}
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, '"');
this->definitions[n].token = (ENUM)atoi(tokens[0].after(0,1));
for(int i=1; i<ntokens; i++)
this->definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote));
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++)
this->definitions[n].values[j]=NULL;
n++;
}
else if (have_unknown && this->ndefinitions>=0 && quote != '\0' && buffer[0] == quote)
{
// definition by standard name
if (!definitive)
{
cerr << "can't use names in this definition\n";
return wrong_format;
}
if ( n>= this->ndefinitions)
{
cerr << "too many definitions\n";
return wrong_format;
}
int ntokens = split(line, tokens, NAMED_ENUM_MAX_SYNONYMS+2, RXwhite, quote);
this->definitions[n].token = definitive->token(tokens[0].unquote(quote));
for(int i=1; i<ntokens; i++)
this->definitions[n].values[i-1] = wstrdup(tokens[i].unquote_if_needed(quote));
for(int j=ntokens-1 ; j< NAMED_ENUM_MAX_SYNONYMS; j++)
this->definitions[n].values[j]=NULL;
n++;
}
else
{
// parameter
int mlen;
int eq = line.search("=", 1, mlen);
if (eq <0)
{
cerr << "bad header line '" << line;
return wrong_format;
}
EST_String key(line.before(eq));
if (key == "quote")
{
quote = line[eq+1];
// cout << "quote = '" << quote << "'\n";
}
else if (key == "number")
{
this->ndefinitions=atoi(line.after(eq,1));
// cout << "n = '" << ndefinitions << "'\n";
this->definitions = new Defn[this->ndefinitions];
for(int i=0; i<this->ndefinitions; i++)
this->definitions[i].values[0] =NULL;
n=0;
}
else if (key == "unknown")
{
this->p_unknown_enum=(ENUM)atoi(line.after(eq,1));
// cout << "unknown = '" << p_unknown_enum << "'\n";
have_unknown=1;
}
else
{
cerr << "bad header line '" << line;
return wrong_format;
}
}
}
fclose(file);
return format_ok;
}
template<class ENUM>
EST_write_status EST_TNamedEnum<ENUM>::priv_save(EST_String name, EST_TNamedEnum<ENUM> *definitive, char quote) const
{
FILE *file;
if ((file=fopen(name, "wb"))==NULL)
return write_fail;
fprintf(file, "unknown=%d\n", this->p_unknown_enum);
fprintf(file, "quote=%c\n", quote);
fprintf(file, "number=%d\n", this->ndefinitions);
for(int i=0; i<this->ndefinitions; i++)
if (this->definitions[i].values[0])
{
if (definitive)
fprintf(file, "%s ", (const char *)EST_String(definitive->name(this->definitions[i].token)).quote(quote));
else
fprintf(file, "=%d ", (int)this->definitions[i].token);
for(int j=0; j<NAMED_ENUM_MAX_SYNONYMS && this->definitions[i].values[j] != NULL; j++)
fprintf(file, "%s ", (const char *) EST_String(this->definitions[i].values[j]).quote_if_needed(quote));
fputc('\n', file);
}
fclose(file);
return write_ok;
}

View File

@ -0,0 +1,174 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Fri Oct 10 1997 */
/* -------------------------------------------------------------------- */
/* A subclass of TMatrix which copies using memcopy. This isn't */
/* suitable for matrices of class objects which have to be copied */
/* using a constructor or specialised assignment operator. */
/* */
/*************************************************************************/
#include "EST_TSimpleMatrix.h"
#include "EST_TVector.h"
#include <fstream>
#include <iostream>
#include "EST_cutils.h"
#include <string.h>
template<class T>
void EST_TSimpleMatrix<T>::copy_data(const EST_TSimpleMatrix<T> &a)
{
if (!a.p_sub_matrix && !this->p_sub_matrix)
memcpy((void *)&this->a_no_check(0,0),
(const void *)&a.a_no_check(0,0),
this->num_rows()*this->num_columns()*sizeof(T)
);
else
{
for (int i = 0; i < this->num_rows(); ++i)
for (int j = 0; j < this->num_columns(); ++j)
this->a_no_check(i,j) = a.a_no_check(i,j);
}
}
template<class T>
void EST_TSimpleMatrix<T>::copy(const EST_TSimpleMatrix<T> &a)
{
if (this->num_rows() != a.num_rows() || this->num_columns() != a.num_columns())
resize(a.num_rows(), a.num_columns(), 0);
copy_data(a);
}
template<class T>
EST_TSimpleMatrix<T>::EST_TSimpleMatrix(const EST_TSimpleMatrix<T> &in)
{
copy(in);
}
template<class T>
void EST_TSimpleMatrix<T>::resize(int new_rows,
int new_cols,
int set)
{
T* old_vals=NULL;
int old_offset = this->p_offset;
unsigned int q;
if (new_rows<0)
new_rows = this->num_rows();
if (new_cols<0)
new_cols = this->num_columns();
if (set)
{
if (!this->p_sub_matrix && new_cols == this->num_columns() && new_rows != this->num_rows())
{
int copy_r = Lof(this->num_rows(), new_rows);
this->just_resize(new_rows, new_cols, &old_vals);
for (q=0; q<(copy_r*new_cols*sizeof(T)); q++) /* memcpy */
((char *)this->p_memory)[q] = ((char *)old_vals)[q];
int i,j;
if (new_rows > copy_r)
{
if (*this->def_val == 0)
{
for (q=0; q<(new_rows-copy_r)*new_cols*sizeof(T); q++) /* memset */
((char *)(this->p_memory + copy_r*this->p_row_step))[q] = 0;
}
else
{
for(j=0; j<new_cols; j++)
for(i=copy_r; i<new_rows; i++)
this->a_no_check(i,j) = *this->def_val;
}
}
}
else if (!this->p_sub_matrix)
{
int old_row_step = this->p_row_step;
int old_column_step = this->p_column_step;
int copy_r = Lof(this->num_rows(), new_rows);
int copy_c = Lof(this->num_columns(), new_cols);
this->just_resize(new_rows, new_cols, &old_vals);
this->set_values(old_vals,
old_row_step, old_column_step,
0, copy_r,
0, copy_c);
int i,j;
for(i=0; i<copy_r; i++)
for(j=copy_c; j<new_cols; j++)
this->a_no_check(i,j) = *this->def_val;
if (new_rows > copy_r)
{
if (*this->def_val == 0)
{
for (q=0; q<((new_rows-copy_r)*new_cols*sizeof(T)); q++) /* memset */
((char *)(this->p_memory + copy_r*this->p_row_step))[q] = 0;
}
else
{
for(j=0; j<new_cols; j++)
for(i=copy_r; i<new_rows; i++)
this->a_no_check(i,j) = *this->def_val;
}
}
}
else
EST_TMatrix<T>::resize(new_rows, new_cols, 1);
}
else
EST_TMatrix<T>::resize(new_rows, new_cols, 0);
if (old_vals && old_vals != this->p_memory)
delete [] (old_vals-old_offset);
}
template<class T> EST_TSimpleMatrix<T> &EST_TSimpleMatrix<T>::operator=(const EST_TSimpleMatrix<T> &in)
{
copy(in);
return *this;
}

View File

@ -0,0 +1,149 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Fri Oct 10 1997 */
/* -------------------------------------------------------------------- */
/* A subclass of TVector which copies using memcopy. This isn't */
/* suitable for matrices of class objects which have to be copied */
/* using a constructor or specialised assignment operator. */
/* */
/*************************************************************************/
#include "EST_TSimpleVector.h"
#include "EST_matrix_support.h"
#include <fstream>
#include "EST_cutils.h"
#include <string.h>
template<class T> void EST_TSimpleVector<T>::copy(const EST_TSimpleVector<T> &a)
{
if (this->p_column_step==1 && a.p_column_step==1)
{
resize(a.n(), FALSE);
memcpy((void *)(this->p_memory), (const void *)(a.p_memory), this->n() * sizeof(T));
}
else
((EST_TVector<T> *)this)->copy(a);
}
template<class T> EST_TSimpleVector<T>::EST_TSimpleVector(const EST_TSimpleVector<T> &in)
{
this->default_vals();
copy(in);
}
// should copy from and delete old version first
template<class T> void EST_TSimpleVector<T>::resize(int newn, int set)
{
int oldn = this->n();
T *old_vals =NULL;
int old_offset = this->p_offset;
unsigned int q;
this->just_resize(newn, &old_vals);
if (set && old_vals)
{
int copy_c = 0;
if (this->p_memory != NULL)
{
copy_c = Lof(this->n(), oldn);
for (q=0; q<copy_c* sizeof(T); q++) /* for memcpy */
((char *)this->p_memory)[q] = ((char *)old_vals)[q];
}
for (int i=copy_c; i < this->n(); ++i)
this->p_memory[i] = *this->def_val;
}
if (old_vals != NULL && old_vals != this->p_memory && !this->p_sub_matrix)
delete [] (old_vals - old_offset);
}
template<class T>
void EST_TSimpleVector<T>::copy_section(T* dest, int offset, int num) const
{
unsigned int q;
if (num<0)
num = this->num_columns()-offset;
if (!EST_vector_bounds_check(num+offset-1, this->num_columns(), FALSE))
return;
if (!this->p_sub_matrix && this->p_column_step==1)
{
for (q=0; q<num* sizeof(T); q++) /* for memcpy */
((char *)dest)[q] = ((char *)(this->p_memory+offset))[q];
}
else
for(int i=0; i<num; i++)
dest[i] = this->a_no_check(offset+i);
}
template<class T>
void EST_TSimpleVector<T>::set_section(const T* src, int offset, int num)
{
unsigned int q;
if (num<0)
num = this->num_columns()-offset;
if (!EST_vector_bounds_check(num+offset-1, this->num_columns(), FALSE))
return;
if (!this->p_sub_matrix && this->p_column_step==1)
{
for (q=0; q<num* sizeof(T); q++) /* for memcpy */
((char *)(this->p_memory+offset))[q] = ((char *)(src))[q];
}
else
for(int i=0; i<num; i++)
this->a_no_check(offset+i) = src[i];
}
template<class T> EST_TSimpleVector<T> &EST_TSimpleVector<T>::operator=(const EST_TSimpleVector<T> &in)
{
copy(in);
return *this;
}
template<class T> void EST_TSimpleVector<T>::zero()
{
if (this->p_column_step==1)
memset((void *)(this->p_memory), 0, this->n() * sizeof(T));
else
((EST_TVector<T> *)this)->fill(*this->def_val);
}

View File

@ -0,0 +1,70 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Simon King, Richard Caley */
/* Date : November 1996 */
/* --------------------------------------------------------------------- */
/* Sorting order definitions. */
/* */
/*************************************************************************/
//#include <cstdlib>
//#include <cstdio>
#include "EST_TSortable.h"
// requires operators '<' and '>' for type T
template<class T>
bool EST_TSortable<T>::items_eq(const EST_UItem *item1, const EST_UItem *item2)
{
return ((EST_TItem<T> *)item1)->val == ((EST_TItem<T> *)item2)->val;
}
template<class T>
bool EST_TSortable<T>::items_lt(const EST_UItem *item1, const EST_UItem *item2)
{
return ((EST_TItem<T> *)item1)->val < ((EST_TItem<T> *)item2)->val;
}
template<class T>
bool EST_TSortable<T>::items_gt(const EST_UItem *item1, const EST_UItem *item2)
{
return ((EST_TItem<T> *)item1)->val > ((EST_TItem<T> *)item2)->val;
}

View File

@ -0,0 +1,137 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Wed Mar 25 1998 */
/* -------------------------------------------------------------------- */
/* Indexing a container by time. */
/* */
/*************************************************************************/
#include "EST_TTimeIndex.h"
template<class CONTAINER>
void EST_TTimeIndex<CONTAINER>::initialise()
{
p_time_step=0;
p_entries.resize(0);
}
template<class CONTAINER>
EST_TTimeIndex<CONTAINER>::EST_TTimeIndex()
{
initialise();
}
template<class CONTAINER>
EST_TTimeIndex<CONTAINER>::EST_TTimeIndex(CONTAINER &c, int bunch)
{
initialise();
index(c, bunch);
}
template<class CONTAINER>
void EST_TTimeIndex<CONTAINER>::index(CONTAINER &c, int bunch)
{
int n_objects = c.length();
float total_time = c.end();
int n_buckets = n_objects/bunch +1;
p_time_step = total_time / n_buckets;
p_entries.resize(n_buckets);
p_container = &c;
Index i;
i=c.first_index();
p_entries[0].t = 0.0;
p_entries[0].i = i;
for(; c.valid_index(i); i=c.next_index(i))
{
float t = c.time_of(i);
int b = (int)(t/p_time_step);
if (b>=p_entries.num_columns())
b = p_entries.num_columns()-1;
for (int bb=b+1; bb < n_buckets ; bb++)
if ( t > p_entries(bb).t )
{
p_entries[bb].t = t;
p_entries[bb].i = i;
}
else
break;
}
}
template<class CONTAINER>
void EST_TTimeIndex<CONTAINER>::just_before(float t,
void *inp) const
{
CONTAINER::Index &in(*(Index *)inp);
in= CONTAINER::bad_index();
if (p_container==NULL)
return;
int b = (int)(t/p_time_step);
if (b>=p_entries.num_columns())
b = p_entries.num_columns()-1;
Index i = p_entries(b).i;
for(Index j=i; p_container->valid_index(j); j = p_container->next_index(j))
{
if (p_container->time_of(j) > t)
{
in=i;
return;
}
i=j;
}
in =i;
return;
}
template<class CONTAINER>
int operator !=(const EST_TTI_Entry<CONTAINER> &e1,
const EST_TTI_Entry<CONTAINER> &e2)
{ (void)e1; (void)e2; return 1; }
template<class CONTAINER>
ostream& operator <<(ostream &s,
const EST_TTI_Entry<CONTAINER> &e)
{ (void)e; return s << "entry"; }

324
base_class/EST_TVector.cc Normal file
View File

@ -0,0 +1,324 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author : Paul Taylor */
/* Date : April 1995 */
/* --------------------------------------------------------------------- */
/* Template Vector Class */
/* */
/*************************************************************************/
#include <iostream>
#include <fstream>
#include "EST_TVector.h"
#include "EST_matrix_support.h"
#include "EST_cutils.h"
#include "EST_error.h"
template<class T>
void EST_TVector<T>::default_vals()
{
p_num_columns = 0;
p_offset=0;
p_column_step=0;
p_memory = NULL;
p_sub_matrix=FALSE;
}
template<class T>
EST_TVector<T>::EST_TVector()
{
default_vals();
}
template<class T>
EST_TVector<T>::EST_TVector(int n)
{
default_vals();
resize(n);
}
template<class T>
EST_TVector<T>::EST_TVector(const EST_TVector<T> &in)
{
default_vals();
copy(in);
}
template<class T>
EST_TVector<T>::EST_TVector(int n,
T *memory, int offset, int free_when_destroyed)
{
default_vals();
set_memory(memory, offset, n, free_when_destroyed);
}
template<class T>
EST_TVector<T>::~EST_TVector()
{
p_num_columns = 0;
p_offset=0;
p_column_step=0;
if (p_memory != NULL && !p_sub_matrix)
{
delete [] (p_memory-p_offset);
p_memory = NULL;
}
}
template<class T>
void EST_TVector<T>::fill(const T &v)
{
for (int i = 0; i < num_columns(); ++i)
fast_a_v(i) = v;
}
template<class T>
void EST_TVector<T>::set_memory(T *buffer, int offset, int columns,
int free_when_destroyed)
{
if (p_memory != NULL && !p_sub_matrix)
delete [] (p_memory-p_offset);
p_memory = buffer-offset;
p_offset=offset;
p_num_columns = columns;
p_column_step=1;
p_sub_matrix = !free_when_destroyed;
}
template<class T>
void EST_TVector<T>::set_values(const T *data,
int step,
int start_c,
int num_c)
{
for(int i=0, c=start_c, p=0; i<num_c; i++, c++, p+=step)
a_no_check(c) = data[p];
}
template<class T>
void EST_TVector<T>::get_values(T *data,
int step,
int start_c,
int num_c) const
{
for(int i=0, c=start_c, p=0; i<num_c; i++, c++, p+=step)
data[p] = a_no_check(c);
}
template<class T>
void EST_TVector<T>::copy_data(const EST_TVector<T> &a)
{
set_values(a.p_memory, a.p_column_step, 0, num_columns());
}
template<class T>
void EST_TVector<T>::copy(const EST_TVector<T> &a)
{
resize(a.n(), FALSE);
copy_data(a);
}
template<class T>
void EST_TVector<T>::just_resize(int new_cols, T** old_vals)
{
T *new_m;
if (num_columns() != new_cols || p_memory == NULL )
{
if (p_sub_matrix)
EST_error("Attempt to resize Sub-Vector");
if (new_cols < 0)
EST_error("Attempt to resize vector to negative size: %d",
new_cols);
new_m = new T[new_cols];
if (p_memory != NULL)
{
if (old_vals != NULL)
*old_vals = p_memory;
else if (!p_sub_matrix)
delete [] (p_memory-p_offset);
}
p_memory = new_m;
//cout << "vr: mem: " << p_memory << " (" << (int)p_memory << ")\n";
p_offset=0;
p_num_columns = new_cols;
p_column_step=1;
}
else
*old_vals = p_memory;
}
template<class T>
void EST_TVector<T>::resize(int new_cols, int set)
{
int i;
T * old_vals = p_memory;
int old_cols = num_columns();
int old_offset = p_offset;
int old_column_step = p_column_step;
just_resize(new_cols, &old_vals);
if (set)
{
int copy_c = 0;
if (!old_vals)
copy_c=0;
else if (old_vals != p_memory)
{
copy_c = Lof(num_columns(), old_cols);
for(i=0; i<copy_c; i++)
a_no_check(i)
= old_vals[vcell_pos(i,
old_column_step)];
}
else
copy_c = old_cols;
for(i=copy_c; i<new_cols; i++)
a_no_check(i) = *def_val;
}
if (old_vals && old_vals != p_memory && !p_sub_matrix)
delete [] (old_vals-old_offset);
}
template<class T>
EST_TVector<T> &EST_TVector<T>::operator=(const EST_TVector<T> &in)
{
copy(in);
return *this;
}
template<class T>
T &EST_TVector<T>::a_check(int n)
{
if (!EST_vector_bounds_check(n, num_columns(), FALSE))
return *error_return;
return fast_a_v(n);
}
template<class T>
const T &EST_TVector<T>::a_check(int n) const
{
return ((EST_TVector<T> *)this)->a(n);
}
template<class T>
int EST_TVector<T>::operator == (const EST_TVector<T> &v) const
{
if (num_columns() != v.num_columns())
return 0;
for(int i=0; i<num_columns() ; i++)
{
if (fast_a_v(i) == v.fast_a_v(i))
continue;
else
return 0;
}
return 1;
}
template<class T>
void EST_TVector<T>::copy_section(T* dest, int offset, int num) const
{
if (num<0)
num = num_columns()-offset;
if (!EST_vector_bounds_check(num+offset-1, num_columns(), FALSE))
return;
for(int i=0; i<num; i++)
dest[i] = a_no_check(offset+i);
}
template<class T>
void EST_TVector<T>::set_section(const T* src, int offset, int num)
{
if (num<0)
num = num_columns()-offset;
if (!EST_vector_bounds_check(num+offset-1, num_columns(), FALSE))
return;
for(int i=0; i<num; i++)
a_no_check(offset+i) = src[i];
}
template<class T>
void EST_TVector<T>::sub_vector(EST_TVector<T> &sv,
int start_c, int len)
{
if (len < 0)
len = num_columns()-start_c;
if (sv.p_memory != NULL && ! sv.p_sub_matrix)
delete [] (sv.p_memory - sv.p_offset);
sv.p_sub_matrix = TRUE;
sv.p_offset = p_offset + start_c*p_column_step;
sv.p_memory = p_memory - p_offset + sv.p_offset;
sv.p_column_step=p_column_step;
sv.p_num_columns = len;
}
template<class T>
void EST_TVector<T>::integrity() const
{
cout << "integrity: p_memory=" << p_memory << endl;
if(p_memory == (T *)0x00080102)
{
cout << "fatal value!!!\n";
}
}

868
base_class/EST_Token.cc Normal file
View File

@ -0,0 +1,868 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : April 1996 */
/*-----------------------------------------------------------------------*/
/* */
/* A Tokenize class, both for Tokens (Strings plus alpha) */
/* EST_TokenStream for strings, FILE *, files, pipes etc */
/* */
/*=======================================================================*/
#include <cstdio>
#include <iostream>
#include "EST_unix.h"
#include <cstdlib>
#include <climits>
#include <cstring>
#include "EST_math.h"
#include "EST_Token.h"
#include "EST_string_aux.h"
#include "EST_cutils.h"
#include "EST_error.h"
const EST_String EST_Token_Default_WhiteSpaceChars = " \t\n\r";
const EST_String EST_Token_Default_SingleCharSymbols = "(){}[]";
const EST_String EST_Token_Default_PrePunctuationSymbols = "\"'`({[";
const EST_String EST_Token_Default_PunctuationSymbols = "\"'`.,:;!?]})";
const EST_String Token_Origin_FD = "existing file descriptor";
const EST_String Token_Origin_Stream = "existing istream";
const EST_String Token_Origin_String = "existing string";
static EST_Regex RXanywhitespace("[ \t\n\r]");
static inline char *check_extend_str_in(char *str, int pos, int *max)
{
// Check we are not at the end of the string, if so get some more
// and copy the old one into the new one
char *newstuff;
if (pos >= *max)
{
if (pos > *max)
*max = 2 * pos;
else
*max *= 2;
newstuff = new char[*max];
strncpy(newstuff,str,pos);
delete [] str;
return newstuff;
}
else
return str;
}
#define check_extend_str(STR, POS, MAX) \
(((POS)>= *(MAX))?check_extend_str_in((STR),(POS),(MAX)):(STR))
ostream& operator<<(ostream& s, const EST_Token &p)
{
s << "[TOKEN " << p.pname << "]";
return s;
}
EST_Token &EST_Token::operator = (const EST_Token &a)
{
linenum = a.linenum;
linepos = a.linepos;
p_filepos = a.p_filepos;
p_quoted = a.p_quoted;
space = a.space;
prepunc = a.prepunc;
pname = a.pname;
punc = a.punc;
return *this;
}
const EST_String EST_Token::pos_description() const
{
return "line "+itoString(linenum)+" char "+itoString(linepos);
}
EST_Token &EST_Token::operator = (const EST_String &a)
{
pname = a;
return *this;
}
EST_TokenStream::EST_TokenStream()
{
tok_wspacelen = 64; // will grow if necessary
tok_wspace = new char[tok_wspacelen];
tok_stufflen = 512; // will grow if necessary
tok_stuff = new char[tok_stufflen];
tok_prepuncslen = 32; // will grow if necessary
tok_prepuncs = new char[tok_prepuncslen];
default_values();
}
EST_TokenStream::EST_TokenStream(EST_TokenStream &s)
{
(void)s;
cerr << "TokenStream: warning passing TokenStream not as reference"
<< endl;
// You *really* shouldn't use this AT ALL unless you
// fully understand its consequences, you'll be copying open
// files and moving file pointers all over the place
// basically *DON'T* do this, pass the stream by reference
// Now there may be occasions when you do want to do this for example
// when you need to do far look ahead or check point as you read
// but they are obscure and I'm not sure how to do that for all
// the file forms supported by the TokenStream. If you do
// I can write a clone function that might do it.
}
void EST_TokenStream::default_values()
{
type = tst_none;
peeked_tokp = FALSE;
peeked_charp = FALSE;
eof_flag = FALSE;
quotes = FALSE;
p_filepos = 0;
linepos = 1;
WhiteSpaceChars = EST_Token_Default_WhiteSpaceChars;
SingleCharSymbols = EST_String::Empty;
PrePunctuationSymbols = EST_String::Empty;
PunctuationSymbols = EST_String::Empty;
build_table();
close_at_end=TRUE;
}
EST_TokenStream::~EST_TokenStream()
{
if (type != tst_none)
close();
delete [] tok_wspace;
delete [] tok_stuff;
delete [] tok_prepuncs;
}
ostream& operator<<(ostream& s, EST_TokenStream &p)
{
s << "[TOKENSTREAM ";
switch (p.type)
{
case tst_none:
cerr << "UNSET"; break;
case tst_file:
cerr << "FILE"; break;
case tst_pipe:
cerr << "PIPE"; break;
case tst_istream:
cerr << "ISTREAM"; break;
case tst_string:
cerr << "STRING"; break;
default:
cerr << "UNKNOWN" << endl;
}
s << "]";
return s;
}
int EST_TokenStream::open(const EST_String &filename)
{
if (type != tst_none)
close();
default_values();
fp = fopen(filename,"rb");
if (fp == NULL)
{
cerr << "Cannot open file " << filename << " as tokenstream"
<< endl;
return -1;
}
Origin = filename;
type = tst_file;
return 0;
}
int EST_TokenStream::open(FILE *ofp, int close_when_finished)
{
// absorb already open stream
if (type != tst_none)
close();
default_values();
fp = ofp;
if (fp == NULL)
{
cerr << "Cannot absorb NULL filestream as tokenstream" << endl;
return -1;
}
Origin = Token_Origin_FD;
type = tst_file;
close_at_end = close_when_finished;
return 0;
}
int EST_TokenStream::open(istream &newis)
{
// absorb already open istream
if (type != tst_none)
close();
default_values();
is = &newis;
Origin = Token_Origin_Stream;
type = tst_istream;
return 0;
}
int EST_TokenStream::open_string(const EST_String &newbuffer)
{
// Make a tokenstream from an internal existing string/buffer
const char *buf;
if (type != tst_none)
close();
default_values();
buf = (const char *)newbuffer;
buffer_length = newbuffer.length();
buffer = new char[buffer_length+1];
memmove(buffer,buf,buffer_length+1);
pos = 0;
Origin = Token_Origin_String;
type = tst_string;
return 0;
}
int EST_TokenStream::seek_end()
{
// This isn't actually useful but people expect it
peeked_charp = FALSE;
peeked_tokp = FALSE;
switch (type)
{
case tst_none:
cerr << "EST_TokenStream unset" << endl;
return -1;
break;
case tst_file:
fseek(fp,0,SEEK_END);
p_filepos = ftell(fp);
return p_filepos;
case tst_pipe:
cerr << "EST_TokenStream seek on pipe not supported" << endl;
return -1;
break;
case tst_istream:
cerr << "EST_TokenStream seek on istream not yet supported" << endl;
return -1;
break;
case tst_string:
pos = buffer_length;
return pos;
default:
cerr << "EST_TokenStream: unknown type" << endl;
return -1;
}
return -1; // can't get here
}
int EST_TokenStream::seek(int position)
{
peeked_charp = FALSE;
peeked_tokp = FALSE;
switch (type)
{
case tst_none:
cerr << "EST_TokenStream unset" << endl;
return -1;
break;
case tst_file:
p_filepos = position;
return fseek(fp,position,SEEK_SET);
case tst_pipe:
cerr << "EST_TokenStream seek on pipe not supported" << endl;
return -1;
break;
case tst_istream:
cerr << "EST_TokenStream seek on istream not yet supported" << endl;
return -1;
break;
case tst_string:
if (position >= pos)
{
pos = position;
return -1;
}
else
{
pos = position;
return 0;
}
break;
default:
cerr << "EST_TokenStream: unknown type" << endl;
return -1;
}
return -1; // can't get here
}
static int stdio_fread(void *buff,int size,int nitems,FILE *fp)
{
// So it can find the stdio one rather than the TokenStream one
return fread(buff,size,nitems,fp);
}
int EST_TokenStream::fread(void *buff, int size, int nitems)
{
// switching into binary mode for current position
int items_read;
// so we can continue to read afterwards
if (peeked_tokp)
{
cerr << "ERROR " << pos_description()
<< " peeked into binary data" << endl;
return 0;
}
peeked_charp = FALSE;
peeked_tokp = FALSE;
switch (type)
{
case tst_none:
cerr << "EST_TokenStream unset" << endl;
return 0;
break;
case tst_file:
items_read = stdio_fread(buff,(size_t)size,(size_t)nitems,fp);
p_filepos += items_read*size;
return items_read;
case tst_pipe:
cerr << "EST_TokenStream fread pipe not yet supported" << endl;
return 0;
break;
case tst_istream:
cerr << "EST_TokenStream fread istream not yet supported" << endl;
return 0;
case tst_string:
if ((buffer_length-pos)/size < nitems)
items_read = (buffer_length-pos)/size;
else
items_read = nitems;
memcpy(buff,&buffer[pos],items_read*size);
pos += items_read*size;
return items_read;
default:
cerr << "EST_TokenStream: unknown type" << endl;
return EOF;
}
return 0; // can't get here
}
void EST_TokenStream::close(void)
{
// close any files (if they were used)
switch (type)
{
case tst_none:
break;
case tst_file:
if (close_at_end)
fclose(fp);
case tst_pipe:
// close(fd);
break;
case tst_istream:
break;
case tst_string:
delete [] buffer;
buffer = 0;
break;
default:
cerr << "EST_TokenStream: unknown type" << endl;
break;
}
type = tst_none;
peeked_charp = FALSE;
peeked_tokp = FALSE;
}
int EST_TokenStream::restart(void)
{
// For paul, the only person I know who uses this
switch (type)
{
case tst_none:
break;
case tst_file:
fp = freopen(Origin,"rb",fp);
p_filepos = 0;
break;
case tst_pipe:
cerr << "EST_TokenStream: can't rewind pipe" << endl;
return -1;
break;
case tst_istream:
cerr << "EST_TokenStream: can't rewind istream" << endl;
break;
case tst_string:
pos = 0;
break;
default:
cerr << "EST_TokenStream: unknown type" << endl;
break;
}
linepos = 1;
peeked_charp = FALSE;
peeked_tokp = FALSE;
eof_flag = FALSE;
return 0;
}
EST_TokenStream & EST_TokenStream::operator >>(EST_Token &p)
{
return get(p);
}
EST_TokenStream & EST_TokenStream::operator >>(EST_String &p)
{
EST_Token t;
get(t);
p = t.string();
return *this;
}
EST_TokenStream &EST_TokenStream::get(EST_Token &tok)
{
tok = get();
return *this;
}
EST_Token EST_TokenStream::get_upto(const EST_String &s)
{
// Returns a concatenated token form here to next symbol that matches s
// including s (though not adding s on the result)
// Not really for the purist but lots of times very handy
// Note this is not very efficient
EST_String result;
EST_Token t;
for (result=EST_String::Empty; (t=get()) != s; )
{
result += t.whitespace() + t.prepunctuation() +
t.string() + t.punctuation();
if (eof())
{
cerr << "EST_TokenStream: end of file when looking for \"" <<
s << "\"" << endl;
break;
}
}
return EST_Token(result);
}
EST_Token EST_TokenStream::get_upto_eoln(void)
{
// Swallow the lot up to end of line
// assumes \n is a whitespace character
EST_String result(EST_String::Empty);
while (!eoln())
{
EST_Token &t=get();
result += t.whitespace() + t.prepunctuation();
if (quotes)
result += quote_string(t.string());
else
result += t.string();
result += t.punctuation();
if (eof())
{
// cerr << "EST_TokenStream: end of file when looking for end of line"
// << endl;
break;
}
}
// So that the next call works I have to step over the eoln condition
// That involves removing the whitespace upto and including the next
// \n in the peek token.
char *w = wstrdup(peek().whitespace());
int i;
for (i=0; w[i] != 0; i++)
if (w[i] == '\n') // maybe not portable
peek().set_whitespace(&w[i+1]);
wfree(w);
static EST_Token result_t;
result_t.set_token(result);
return result_t;
}
EST_Token &EST_TokenStream::must_get(EST_String expected, bool *ok)
{
EST_Token &tok = get();
if (tok != expected)
{
if (ok != NULL)
{
*ok=FALSE;
return tok;
}
else
EST_error("Expected '%s' got '%s' at %s",
(const char *)expected,
(const char *)(EST_String)tok,
(const char *)pos_description());
}
if (ok != NULL)
*ok=TRUE;
return tok;
}
void EST_TokenStream::build_table()
{
int i;
const char *p;
unsigned char c;
for (i=0; i<256; ++i)
p_table[i]=0;
for (p=WhiteSpaceChars; *p; ++p)
if (p_table[c=(unsigned char)*p])
EST_warning("Character '%c' has two classes, '%c' and '%c'",
*p, c, ' ');
else
p_table[c] = ' ';
for (p=SingleCharSymbols; *p; ++p)
if (p_table[c=(unsigned char)*p])
EST_warning("Character '%c' has two classes, '%c' and '%c'",
*p, p_table[c], '!');
else
p_table[c] = '@';
for (p=PunctuationSymbols; *p; ++p)
if (p_table[c=(unsigned char)*p] == '@')
continue;
else if (p_table[c])
EST_warning("Character '%c' has two classes, '%c' and '%c'",
*p, p_table[c], '.');
else
p_table[c] = '.';
for(p=PrePunctuationSymbols; *p; ++p)
if (p_table[c=(unsigned char)*p] == '@')
continue;
else if (p_table[c] == '.')
p_table[c] = '"';
else if (p_table[c])
EST_warning("Character '%c' has two classes, '%c' and '%c'",
*p, p_table[c], '$');
else
p_table[c] = '$';
p_table_wrong=0;
}
inline int EST_TokenStream::getpeeked_internal(void)
{
peeked_charp = FALSE;
return peeked_char;
}
inline
int EST_TokenStream::getch_internal()
{
// Return next character in stream
if (EST_TokenStream::peeked_charp)
{
return getpeeked_internal();
}
switch (type)
{
case tst_none:
cerr << "EST_TokenStream unset" << endl;
return EOF;
break;
case tst_file:
p_filepos++;
{
char lc;
if (stdio_fread(&lc,1,1,fp) == 0)
return EOF;
else
return (int)lc;
}
/* return getc(fp); */
case tst_pipe:
cerr << "EST_TokenStream pipe not yet supported" << endl;
return EOF;
break;
case tst_istream:
p_filepos++;
return is->get();
case tst_string:
if (pos < buffer_length)
{
p_filepos++;
return buffer[pos++];
}
else
return EOF;
default:
cerr << "EST_TokenStream: unknown type" << endl;
return EOF;
}
return EOF; // can't get here
}
int EST_TokenStream::getch(void)
{
return getch_internal();
}
inline int EST_TokenStream::peekch_internal()
{
// Return next character in stream (without reading it)
if (!peeked_charp)
peeked_char = getch_internal();
peeked_charp = TRUE;
return peeked_char;
}
int EST_TokenStream::peekch(void)
{
return peekch_internal();
}
#define CLASS(C,CL) (p_table[(unsigned char)(C)]==(CL))
#define CLASS2(C,CL1,CL2) (p_table[(unsigned char)(C)]==(CL1)||p_table[(unsigned char)(C)]==(CL2))
EST_Token &EST_TokenStream::get(void)
{
if (peeked_tokp)
{
peeked_tokp = FALSE;
return current_tok;
}
if (p_table_wrong)
build_table();
char *word;
int c,i,j;
for (i=0; (CLASS(c=getch_internal(),' ') &&
( c != EOF )); i++)
{
if (c == '\n') linepos++;
tok_wspace = check_extend_str(tok_wspace,i,&tok_wspacelen);
tok_wspace[i] = c;
}
tok_wspace[i] = '\0';
current_tok.init();
if (c != EOF)
{
current_tok.set_filepos(p_filepos-1);
if ((quotes) && // quoted strings (with escapes) are allowed
(c == quote))
{
for (i=0;
((c = getch_internal()) != EOF)
;)
{
if (c == quote)
break;
tok_stuff = check_extend_str(tok_stuff,i,&tok_stufflen);
if (c == escape)
c = getch_internal();
tok_stuff[i++] = c;
}
current_tok.set_quoted(TRUE);
}
else // standard whitespace separated tokens
{
for (i=0,tok_stuff[i++]=c;
(
!CLASS(c,'@') &&
!CLASS(c=peekch_internal(),' ') &&
!CLASS(c,'@') &&
( c != EOF )) ;)
{
tok_stuff = check_extend_str(tok_stuff,i,&tok_stufflen);
// note, we must have peeked to get here.
tok_stuff[i++] = getpeeked_internal();
}
}
tok_stuff[i] = '\0';
// Are there any punctuation symbols at the start?
for (j=0;
((j < i) && CLASS2(tok_stuff[j], '$', '"'));
j++);
if ((j > 0) && (j < i)) // there are
{
tok_prepuncs = check_extend_str(tok_prepuncs,j+1,&tok_prepuncslen);
memmove(tok_prepuncs,tok_stuff,j);
tok_prepuncs[j] = '\0';
current_tok.set_prepunctuation(tok_prepuncs);
word=&tok_stuff[j];
i-=j; // reduce size by number of prepuncs
}
else
{
current_tok.set_prepunctuation(EST_String::Empty);
word = tok_stuff;
}
// Are there any punctuation symbols at the end
for (j=i-1;
((j > 0) && CLASS2(word[j],'.','"'));
j--);
if (word[j+1] != '\0')
{
current_tok.set_punctuation(&word[j+1]);
word[j+1] = '\0';
}
else
current_tok.set_punctuation(EST_String::Empty);
current_tok.set_token(word);
if (tok_wspace[0] == '\0') // feature paths will have null whitespace
current_tok.set_whitespace(EST_String::Empty);
else
current_tok.set_whitespace(tok_wspace);
}
else
{
current_tok.set_token(EST_String::Empty);
current_tok.set_whitespace(tok_wspace);
current_tok.set_punctuation(EST_String::Empty);
current_tok.set_prepunctuation(EST_String::Empty);
eof_flag = TRUE;
}
return current_tok;
}
int EST_TokenStream::eoln(void)
{
// This doesn't really work if there are blank lines (and you want
// to know about them)
if ((peek().whitespace().contains("\n")) || eof())
return TRUE;
else
return FALSE;
}
EST_String quote_string(const EST_String &s,
const EST_String &quote,
const EST_String &escape,
int force)
{
// Quotes s always if force true, or iff s contains whitespace,
// quotes or escapes force is false
// Note quote and escape are assumed to be string of length 1
EST_String quoted_form;
if ((force) ||
(s.contains(quote)) ||
(s.contains(escape)) ||
(s.contains(RXanywhitespace)) ||
(s.length() == 0))
{
// bigger than the quoted form could ever be
int i,j;
char *quoted = new char[s.length()*(quote.length()+escape.length())+
1+quote.length()+quote.length()];
quoted[0] = quote(0);
for (i=1,j=0; j < s.length(); j++,i++)
{
if (s(j) == quote(0))
quoted[i++] = escape(0);
else if (s(j) == escape(0))
quoted[i++] = escape(0);
quoted[i] = s(j);
}
quoted[i++] = quote(0);
quoted[i] = '\0';
quoted_form = quoted;
delete [] quoted;
return quoted_form;
}
else
return s;
}
const EST_String EST_TokenStream::pos_description()
{
return Origin+":"+itoString(linepos);
}

View File

@ -0,0 +1,67 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : April 1995 */
/*-----------------------------------------------------------------------*/
/* Vector/List conversion templates */
/* only include this if you define both vectors and lists for the class */
/* */
/*=======================================================================*/
#include <fstream>
#include "EST_TList.h"
#include "EST_TVector.h"
#include "EST_cutils.h"
template<class T>
EST_TVector<T> &set(EST_TVector<T> &v, const EST_TList<T> &in)
{
v.resize(in.length(), FALSE);
EST_Litem *p;
int i = 0;
for (p = in.head(); p!= 0; p = p->next(), ++i)
v.a_no_check(i) = in.item(p);
return v;
}
template<class T> EST_TVector<T> &copy(EST_TVector<T> a,const EST_TList<T> &in)
{
a.resize(in.length(), FALSE);
EST_Litem *p;
int i = 0;
for (p = in.head(); p!= 0; p = p->next(), ++i)
a[i] = in.item(p);
return a;
}

461
base_class/EST_UList.cc Normal file
View File

@ -0,0 +1,461 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1997,1998 */
/* All Rights Reserved. */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Mon Jul 21 1997 */
/* -------------------------------------------------------------------- */
/* Untyped list used as the basis of the TList class */
/* */
/*************************************************************************/
#include <EST_UList.h>
void EST_UList::clear_and_free(void (*item_free)(EST_UItem *p))
{
EST_UItem *q, *np;
for (q=head(); q != 0; q = np)
{
np=q->next();
if (item_free)
item_free(q);
else
delete q;
}
h = t = 0;
}
int EST_UList::length() const
{
EST_UItem *ptr;
int n = 0;
for (ptr = head(); ptr != 0; ptr = ptr->next())
++n;
return n;
}
int EST_UList::index(EST_UItem *item) const
{
EST_UItem *ptr;
int n = 0;
for (ptr = head(); ptr != 0; ptr = ptr->next(), ++n)
if (item == ptr)
return n;
return -1;
}
EST_UItem *EST_UList::nth_pointer(int n) const
{
EST_UItem *ptr;
int i;
for (i = 0, ptr = head(); ptr != 0; ptr = ptr->next(), ++i)
if (i == n)
return ptr;
cerr << "Requested item #" << n << " off end of list" << endl;
return head();
}
EST_UItem * EST_UList::remove(EST_UItem *item,
void (*free_item)(EST_UItem *item))
{
if (item == 0)
return 0;
EST_UItem *prev = item->p;
if (item->p == 0) // at start
h = item->n;
else
item->p->n = item->n;
if (item->n == 0) // at end
t = item->p;
else
item->n->p = item->p;
if (free_item)
free_item(item);
else
delete item;
return prev;
}
EST_UItem * EST_UList::remove(int n,
void (*item_free)(EST_UItem *item))
{
return remove(nth_pointer(n), item_free);
}
// This should check if the incoming prev_item actually is in the list
EST_UItem *EST_UList::insert_after(EST_UItem *prev_item, EST_UItem *new_item)
{
if (new_item == 0)
return new_item;
if (prev_item == 0) // insert it at start of list
{
new_item->n = h;
h = new_item;
}
else
{
new_item->n = prev_item->n;
prev_item->n = new_item;
}
new_item->p = prev_item;
if (new_item->n == 0)
t = new_item;
else
new_item->n->p = new_item;
return new_item;
}
EST_UItem *EST_UList::insert_before(EST_UItem *next_item, EST_UItem *new_item)
{
if (new_item == 0)
return new_item;
if (next_item == 0) // put it on the end of the list
{
new_item->p = t;
t = new_item;
}
else
{
new_item->p = next_item->p;
next_item->p = new_item;
}
new_item->n = next_item;
if (new_item->p == 0)
h = new_item;
else
new_item->p->n = new_item;
return next_item;
}
void EST_UList::exchange(EST_UItem *a, EST_UItem *b)
{
if (a==b)
return;
if ((a==0) || (b==0))
{
cerr << "EST_UList:exchange: can't exchange NULL items" << endl;
return;
}
// I know this isn't very readable but there are eight pointers
// that need to be changed, and half of them are trivial back pointers
// care need only be taken when b and a are adjacent, this actual
// sets p and n twice if they are adjacent but still gets the right answer
EST_UItem *ap=a->p,*an=a->n,*bn=b->n,*bp=b->p;
a->n = bn == a ? b : bn;
if (a->n)
a->n->p = a;
a->p = bp == a ? b : bp;
if (a->p)
a->p->n = a;
b->n = an == b ? a : an;
if (b->n)
b->n->p = b;
b->p = ap == b ? a : ap;
if (b->p)
b->p->n = b;
// Fix t and h
if (a == h)
h = b;
else if (b == h)
h = a;
else if (a == t)
t = b;
else if (b == t)
t = a;
}
void EST_UList::exchange(int i, int j)
{
EST_UItem *p;
EST_UItem *a=0,*b=0;
int k;
for (k=0,p = head(); p != 0; p = p->next(),k++)
{
if(i==k)
a = p;
if(j==k)
b = p;
}
if ((a==0) || (b==0))
{
cerr << "EST_UList:exchange: can't exchange items " << i <<
" and " << j << " (off end of list)" << endl;
return;
}
exchange(a,b);
}
void EST_UList::reverse()
{
EST_UItem *p,*q;
for (p=head(); p != 0; p=q)
{
q = p->n;
p->n = p->p;
p->p = q;
}
q = h;
h = t;
t = q;
}
void EST_UList::append(EST_UItem *new_item)
{
if (new_item == 0) return;
new_item->n = 0;
new_item->p = t;
if (t == 0)
h = new_item;
else
t->n = new_item;
t = new_item;
}
void EST_UList::prepend(EST_UItem *new_item)
{
if (new_item == 0) return;
new_item->p = 0;
new_item->n = h;
if (h == 0)
t = new_item;
else
h->p = new_item;
h = new_item;
}
bool EST_UList::operator_eq(const EST_UList &a,
const EST_UList &b,
bool (*eq)(const EST_UItem *item1, const EST_UItem *item2))
{
EST_UItem *p,*q;
q=b.head();
for (p = a.head(); p != NULL; p = p->next()){
if(q == NULL)
return false;
if(eq(q, p))
q=q->next();
else
return false;
}
if(q == NULL)
return true;
else
return false;
}
int EST_UList::index(const EST_UList &l,
const EST_UItem &val,
bool (*eq)(const EST_UItem *item1, const EST_UItem *item2))
{
EST_UItem *ptr;
int n = 0;
for (ptr = l.head(); ptr != 0; ptr = ptr->next(), ++n)
if (eq(&val,ptr))
return n;
return -1;
}
void EST_UList::sort(EST_UList &l,
bool (*gt)(const EST_UItem *item1,
const EST_UItem *item2))
{
// just bubble sort for now
// use EST_String::operator > for comparisons
EST_UItem *l_ptr,*m_ptr;
bool sorted=false;
while(!sorted){
sorted=true;
for(l_ptr=l.head(); l_ptr != 0; l_ptr=l_ptr->next()){
m_ptr=l_ptr->next();
if(m_ptr != 0)
if(gt(l_ptr, m_ptr)){
l.exchange(l_ptr,m_ptr);
sorted=false;
}
}
}
}
// quicksort from 'Algorithms'
// by Cormen, Leiserson & Rivest
static EST_UItem *partition(EST_UItem *p, EST_UItem *r,
bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
void (*exchange)(EST_UItem *item1, EST_UItem *item2))
{
// this can be tidied up / sped up
EST_UItem *i,*j,*i2,*j2;
EST_UItem *x = p;
i = p;
j = r;
while(true){
while(gt(j, x) )
j = j->prev();
while(gt(x, i))
i = i->next();
if((i != j) && (i->prev() != j)){
i2=i;
j2=j;
i=i->next();
j=j->prev();
exchange(i2,j2);
}else
return j;
}
return NULL;
}
static void qsort_sub(EST_UList &l, EST_UItem *p, EST_UItem *r,
bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
void (*exchange)(EST_UItem *item1, EST_UItem *item2))
{
EST_UItem *q;
if(p != r){
q = partition(p,r, gt, exchange);
qsort_sub(l,p,q, gt, exchange);
qsort_sub(l,q->next(),r, gt, exchange);
}
}
void EST_UList::qsort(EST_UList &l,
bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
void (*exchange)(EST_UItem *item1, EST_UItem *item2))
{
qsort_sub(l,l.head(),l.tail(), gt, exchange);
}
void EST_UList::sort_unique(EST_UList &l,
bool (*eq)(const EST_UItem *item1, const EST_UItem *item2),
bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
void (*item_free)(EST_UItem *item))
{
// as sort(..) but delete any repeated items
EST_UItem *l_ptr,*m_ptr;
bool sorted=false;
while(!sorted){
sorted=true;
for(l_ptr=l.head(); l_ptr != 0; l_ptr=l_ptr->next()){
m_ptr=l_ptr->next();
if(m_ptr != 0)
{
if(gt(l_ptr, m_ptr)){
l.exchange(l_ptr,m_ptr);
sorted=false;
} else if(eq(l_ptr, m_ptr)){
l.remove(m_ptr, item_free);
sorted=false;
}
}
}
}
}
void EST_UList::merge_sort_unique(EST_UList &l, EST_UList &m,
bool (*eq)(const EST_UItem *item1, const EST_UItem *item2),
bool (*gt)(const EST_UItem *item1, const EST_UItem *item2),
void (*item_free)(EST_UItem *item))
{
// keep all unique items in l, and add any new items from m to l
EST_UItem *l_ptr,*m_ptr;
bool flag;
// make sure
sort_unique(l, eq, gt, item_free);
for(m_ptr=m.head(); m_ptr != 0; m_ptr=m_ptr->next()){
// try and put item from m in list
flag=false;
for(l_ptr=l.head(); l_ptr != 0; l_ptr=l_ptr->next()){
if( gt(l_ptr, m_ptr) ){
l.insert_before(l_ptr, m_ptr);
flag=true;
break;
}else if( eq(m_ptr, l_ptr) ){
flag=true;
break;
}
}
// or try and append it
if(!flag && ( gt(m_ptr, l.tail()) ) )
l.append(m_ptr);
}
}

150
base_class/EST_Val.cc Normal file
View File

@ -0,0 +1,150 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : May 1996 */
/*-----------------------------------------------------------------------*/
/* Class to represent ints, floats and strings */
/* and other arbitrary objects */
/*=======================================================================*/
#include <cstdlib>
#include "EST_Val.h"
#include "EST_string_aux.h"
val_type val_unset = "unset";
val_type val_int = "int";
val_type val_float = "float";
val_type val_string = "string";
EST_Val::EST_Val(const EST_Val &c)
{
if (c.t == val_string)
sval = c.sval;
else if (c.t == val_int)
v.ival = c.v.ival;
else if (c.t == val_float)
v.fval = c.v.fval;
else if (c.t != val_unset)
{ // does references not a real copy
v.pval = new EST_Contents;
*v.pval = *c.v.pval;
}
t=c.t;
}
EST_Val::EST_Val(val_type type,void *p, void (*f)(void *))
{
t=type;
v.pval = new EST_Contents;
v.pval->set_contents(p,f);
}
EST_Val::~EST_Val(void)
{
if ((t != val_int) &&
(t != val_float) &&
(t != val_unset) &&
(t != val_string))
delete v.pval;
}
EST_Val &EST_Val::operator=(const EST_Val &c)
{
// Have to be careful with the case where they are different types
if ((t != val_int) &&
(t != val_float) &&
(t != val_unset) &&
(t != val_string))
delete v.pval;
if (c.t == val_string)
sval = c.sval;
else if (c.t == val_int)
v.ival = c.v.ival;
else if (c.t == val_float)
v.fval = c.v.fval;
else if (c.t != val_unset)
{ // does references not a real copy
v.pval = new EST_Contents;
*v.pval = *c.v.pval;
}
t=c.t;
return *this;
}
const int EST_Val::to_int(void) const
{
// coerce this to an int
if (t==val_float)
return (int)v.fval;
else if (t==val_string)
return atoi(sval);
else
return v.ival; // just for completeness
}
const float EST_Val::to_flt(void) const
{
// coerce this to a float
if (t==val_int)
return (float)v.ival;
else if (t==val_string)
return atof(sval);
else
return v.fval; // just for completeness
}
const EST_String &EST_Val::to_str(void) const
{
// coerce this to and save it for later
// This requires the following casting, so we can still tell the
// compiler this is a const function. If this was properly declared
// non-const vast amounts of the rest of this would also have to be
// non-const. So we do one nasty bit here for uniformity elsewhere.
// Not saving the result is also a possibility but probably too
// inefficient (maybe not with rjc's string class)
EST_String *n = (EST_String *)((void *)&sval);
if (t==val_int)
*n = itoString(v.ival);
else if (t==val_float)
{
if (v.fval == 0)
*n = "0"; // to be compatible with other's notion of fstrings
else
*n = ftoString(v.fval);
}
else if (t != val_string)
*n = EST_String("[Val ")+t+"]";
return sval;
}

View File

@ -0,0 +1,97 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* -------------------------------------------------------------------- */
/* Auxiliary functions related to features. */
/* */
/*************************************************************************/
#include "EST_features_aux.h"
#include "EST_Features.h"
#include "EST_String.h"
#include "EST_error.h"
#include "EST_get_function_template.h"
defineGetFunction(EST_Features, val, EST_Val, getVal)
defineGetFunction(EST_Features, val, EST_String, getString)
defineGetFunction(EST_Features, val, float, getFloat)
defineGetFunction(EST_Features, val, int, getInteger)
VAL_REGISTER_FUNCPTR(pointer, void *)
void value_sort(EST_Features &f, const EST_String &field)
{
int work_to_do = 1;
(void)field;
EST_Features::RwEntries p;
EST_Features::RwEntries n;
EST_Features::Entry e;
float p_score, n_score;
while(work_to_do)
{
work_to_do = 0;
for (p.begin(f); p; ++p)
{
n = p;
n++;
if (n == 0)
break;
if (p->v.type() != val_type_feats)
{
cerr << "Not a features in val\n";
break;
}
p_score = feats(p->v)->F(field, 1.0);
n_score = feats(n->v)->F(field, 1.0);
if (n_score > p_score)
{
cout << "swapping\n";
e = *p;
*p = *n;
*n = e;
work_to_do = 1;
}
}
}
}

View File

@ -0,0 +1,313 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1998 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Alan W Black */
/* Date : March 1998 */
/*-----------------------------------------------------------------------*/
/* Features i/o */
/* This is kept separate from EST_Features to help reduce dependencies */
/*=======================================================================*/
#include <cstdlib>
#include "EST_Features.h"
#include "ling_class/EST_Item.h"
#include "EST_error.h"
#include "EST_String.h"
#include "EST_Token.h"
void EST_Features::set_function(const EST_String &name,
const EST_String &funcname)
{
EST_Item_featfunc f = get_featfunc(funcname,1);
set_path(name, est_val(f));
}
void EST_Features::save_fpair(ostream &outf,
const EST_String &fname,
const EST_Val &fvalue) const
{
/* Feature valued features themselves (so can't denot empty ones) */
if (fvalue.type() == val_type_feats)
{
EST_Features *f = feats(fvalue);
if (f->features->list.head() == 0)
{
// An empty feature set
outf << fname << " () ; ";
}
else
for (EST_Litem *q=f->features->list.head();
q != 0; q=q->next() )
save_fpair(outf,
fname+"."+f->features->list(q).k,
f->features->list(q).v);
return;
}
/* a non feature valued one */
// in case someone has () in their feature names (ought to be shot)
if (fname.contains("(") ||
fname.contains(")") ||
fname.contains(" ") || // bang, bang
fname.contains("\t") || // what smoking gun ?
fname.contains(";") ||
(fname == ""))
outf << quote_string(fname,"\"","\\",1) << " ";
else
outf << fname << " ";
if (fvalue == ";")
outf << "\";\"";
else if ((fvalue.type() == val_string) &&
((fvalue.string().matches(RXint)) ||
(fvalue.string().matches(RXdouble)) ||
(fvalue.string().contains("(")) ||
(fvalue.string().contains(")")) ||
(fvalue.string().contains(";")) ))
// force quoting, cause it looks like a number but isn't
outf << quote_string(fvalue.string(),"\"","\\",1);
else if (fvalue.type() == val_float)
{
char b[20];
sprintf(b,"%g",fvalue.Float());
outf << b;
}
else if (fvalue.type() == val_type_featfunc)
{
outf << "F:"<<get_featname(featfunc(fvalue));
}
else
outf << quote_string(fvalue.string());
outf << " ; ";
}
EST_write_status EST_Features::save(ostream &outf) const
{
// Save features
if (features->list.head() == 0)
outf << "()";
else
for (EST_Litem *p=features->list.head(); p != 0; p=p->next() )
save_fpair(outf,
features->list(p).k,
features->list(p).v);
return write_ok;
}
EST_write_status EST_Features::save_sexpr(ostream &outf) const
{
// Save features as an sexpression
outf << "(";
for (EST_Litem *p=features->list.head(); p != 0; p=p->next() )
{
const EST_String &fname = features->list(p).k;
const EST_Val &fvalue = features->list(p).v;
outf << "(";
// in case someone has () in their feature names (ought to be shot)
if (fname.contains("(") ||
fname.contains(")") ||
fname.contains(" ") ||
fname.contains("\t") ||
fname.contains(";"))
outf << quote_string(fname,"\"","\\",1);
else
outf << fname;
outf << " ";
if (fvalue == ";")
outf << "\";\"";
else if ((fvalue.type() == val_string) &&
((fvalue.string().matches(RXint)) ||
(fvalue.string().matches(RXdouble)) ||
(fvalue.string().contains("(")) ||
(fvalue.string().contains(")"))))
// force quoting, cause it looks like a number but isn't
// or contains a paren
outf << quote_string(fvalue.string(),"\"","\\",1);
else if (fvalue.type() == val_float)
{
char b[20];
sprintf(b,"%g",fvalue.Float());
outf << b;
}
else if (fvalue.type() == val_type_featfunc)
{
outf << "F:"<<get_featname(featfunc(fvalue));
}
else if (fvalue.type() == val_type_feats)
{
feats(fvalue)->save_sexpr(outf);
}
else
outf << quote_string(fvalue.string());
outf << ")";
if (p->next())
outf << " ";
}
outf << ")";
return write_ok;
}
EST_read_status EST_Features::load_sexpr(EST_TokenStream &ts)
{
/* Load in feature structure from sexpression */
if (ts.peek() != "(")
{
cerr << "load_features: no sexpression found\n";
return misc_read_error;
}
else
{
EST_String f;
EST_Token v;
ts.get(); /* skip opening paren */
for (; ts.peek() != ")"; )
{
if (ts.peek() != "(")
{
cerr << "load_features: no sexpression found\n";
return misc_read_error;
}
ts.get();
f = ts.get().string(); /* feature name */
if ((ts.peek() == "(") && (ts.peek().quoted() == FALSE))
{
EST_Features fv;
set(f,fv);
A(f).load_sexpr(ts);
}
else
{
v = ts.get();
if (v.quoted())
set(f,v.string());
else if (v.string().matches(RXint))
set(f,atoi(v.string()));
else if (v.string().matches(RXdouble))
set(f,atof(v.string()));
else if (v.string().contains("F:"))
{
EST_Item_featfunc func =
get_featfunc(v.string().after("F:"));
if (func != NULL)
set_val(f,est_val(func));
else
{
cerr << "load_features: Unknown Function '" << f <<"'\n";
set_val(f,feature_default_value);
}
}
else
set(f,v.string());
}
if (ts.get() != ")")
{
cerr << "load_features: no sexpression found\n";
return misc_read_error;
}
}
if (ts.get() != ")")
{
cerr << "load_features: no sexpression found\n";
return misc_read_error;
}
}
return format_ok;
}
EST_read_status EST_Features::load(EST_TokenStream &ts)
{
// load features from here to end of line separated by semicolons
EST_String f;
EST_Token v;
static EST_Val val0 = EST_Val(0);
while (!ts.eoln())
{
if (ts.eof())
{
cerr << "load_features: unexpected end of file\n";
return misc_read_error;
}
f = ts.get().string();
v = EST_String::Empty;
while (((ts.peek() != ";") || (ts.peek().quoted())) &&
(!ts.eof()) && (!ts.eoln()))
if (v == "")
v = ts.get();
else
v = v.string()
+ ts.peek().whitespace()
+ ts.get().string();
if (v.quoted() || (v.string() == ""))
set_path(f,EST_Val(v.string()));
else if (v.string() == "0") // very common cases for speed
set_path(f,val0);
else if ((strchr("0123456789-.",v.string()(0)) != NULL) &&
(v.string().matches(RXdouble)))
{
if (v.string().matches(RXint))
set_path(f, EST_Val(atoi(v.string())));
else
set_path(f, EST_Val(atof(v.string())));
}
else if (v.string().contains("F:"))
{
EST_Item_featfunc func = get_featfunc(v.string().after("F:"));
if (func != NULL)
set_path(f, est_val(func));
else
{
cerr << "load_features: Unknown Function '" << f <<"'\n";
set_path(f, feature_default_value);
}
}
else if (v.string() == "()")
{ // An empty feature set
EST_Features *fs = new EST_Features;
set_path(f,est_val(fs));
}
else if (v != "<contents>") // unsupported type
set_path(f,EST_Val(v.string()));
if (ts.peek() == ";")
ts.get();
else if (!ts.eoln())
{
cerr << "load_features: " << ts.pos_description() <<
" missing semicolon in feature list\n";
return misc_read_error;
}
}
return format_ok;
}

View File

@ -0,0 +1,86 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* -------------------------------------------------------------------- */
/* Uses preprocessor to define a template for asafe feature access */
/* function. This is just here to avoid massive duplication. */
/* */
/*************************************************************************/
#include "EST_features_aux.h"
#define defineGetFunction(FTYPE, VAL, RTYPE, NAME) \
RTYPE NAME(const FTYPE &it, \
const EST_String name, \
const RTYPE &def, \
EST_feat_status &status) \
{ \
RTYPE val; \
EST_Val defv; \
\
defv = est_val((void *)&defv); \
\
CATCH_ERRORS() \
{ \
if (strncmp(EST_error_message,"{FND}",5)==0) \
{ \
status = efs_not_set; \
return def; \
} \
\
status=efs_error; \
return def; \
} \
\
EST_Val valr = it.VAL(name, defv); \
\
if (valr.type() == val_type_pointer && &defv == pointer(valr))\
{ \
status=efs_not_set; \
val = def; \
} \
else \
{ \
status=efs_ok; \
val = (RTYPE)valr; \
} \
\
END_CATCH_ERRORS(); \
\
return val; \
}

110
base_class/EST_ilist_aux.cc Normal file
View File

@ -0,0 +1,110 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1994,1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor, Simon King */
/* Date : 1994-99 */
/*-----------------------------------------------------------------------*/
/* IList i/o utility functions */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include "EST_types.h"
#include "EST_String.h"
#include "EST_Pathname.h"
#include "EST_string_aux.h"
#include "EST_cutils.h"
#include "EST_Token.h"
int ilist_member(const EST_IList &l,int i)
{
EST_Litem *p;
for (p = l.head(); p != 0; p = p->next())
if (l.item(p) == i)
return TRUE;
return FALSE;
}
int ilist_index(const EST_IList &l,int i)
{
EST_Litem *p;
int j=0;
for (p = l.head(); p != 0; p = p->next())
{
if (l.item(p) == i)
return j;
j++;
}
return -1;
}
void IList_to_IVector(EST_IList &l, EST_IVector &v)
{
int len,i;
len = l.length();
v.resize(len);
//EST_TBI *p;
EST_Litem *p;
for (p = l.head(),i=0; p != 0; p = p->next(),i++)
v[i] = l(p);
}
void IVector_to_IList(EST_IVector &v, EST_IList &l)
{
int i;
l.clear();
for (i=0;i<v.length();i++)
l.append(v[i]);
}
int IVector_index(const EST_IVector &v,const int s)
{
int i;
for(i=0;i<v.length();i++)
if(v(i) == s)
return i;
return -1;
}

View File

@ -0,0 +1,145 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Mar 10 1998 */
/* -------------------------------------------------------------------- */
/* Support functions for all matrix types. */
/* */
/*************************************************************************/
#include <iostream>
#include "EST_TVector.h"
#include "EST_matrix_support.h"
#include "EST_bool.h"
const int EST_CURRENT=-1;
const int EST_ALL=-1;
bool EST_matrix_bounds_check(int r,
int c,
int num_rows,
int num_columns,
bool set)
{
const char *what = set?"set":"access";
if ((r < 0) || (r >= num_rows))
{
cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
return FALSE;
}
if ((c < 0) || (c >= num_columns))
{
cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
return FALSE;
}
return TRUE;
}
bool EST_matrix_bounds_check(int r, int nr,
int c, int nc,
int num_rows,
int num_columns,
bool set)
{
const char *what = set?"set":"access";
if (nr>0)
{
if ((r < 0) || (r >= num_rows))
{
cerr << "Tried to " << what << " row " << r << " of " << num_rows << " row matrix\n";
return FALSE;
}
if (r+nr-1 >= num_rows)
{
cerr << "Tried to " << what << " row " << r+nr-1 << " of " << num_rows << " row matrix\n";
return FALSE;
}
}
if (nc>0)
{
if ((c < 0) || (c >= num_columns))
{
cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column matrix\n";
return FALSE;
}
if (c+nc-1 >= num_columns)
{
cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column matrix\n";
return FALSE;
}
}
return TRUE;
}
bool EST_vector_bounds_check(int c,
int num_columns,
bool set)
{
const char *what = set?"set":"access";
if ((c < 0) || (c >= num_columns))
{
cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
return FALSE;
}
return TRUE;
}
bool EST_vector_bounds_check(int c, int nc,
int num_columns,
bool set)
{
const char *what = set?"set":"access";
if (nc>0)
{
if ((c < 0) || (c >= num_columns))
{
cerr << "Tried to " << what << " column " << c << " of " << num_columns << " column vector\n";
return FALSE;
}
if (c+nc-1 >= num_columns)
{
cerr << "Tried to " << what << " column " << c+nc-1 << " of " << num_columns << " column vector\n";
return FALSE;
}
}
return TRUE;
}

View File

@ -0,0 +1,65 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
#ifndef __EST_MATRIX_SUPPORT_H__
#define __EST_MATRIX_SUPPORT_H__
/** Support functions for all matrices.
*
* @author Richard Caley <rjc@cstr.ed.ac.uk>
* @version $Id: EST_matrix_support.h,v 1.3 2004/05/04 00:00:16 awb Exp $
*/
bool EST_matrix_bounds_check(int r,
int c,
int num_rows,
int num_columns,
bool set);
bool EST_matrix_bounds_check(int r, int nr,
int c, int nc,
int num_rows,
int num_columns,
bool set);
bool EST_vector_bounds_check(int c,
int num_columns,
bool set);
bool EST_vector_bounds_check(int c, int nc,
int num_columns,
bool set);
#endif

240
base_class/EST_slist_aux.cc Normal file
View File

@ -0,0 +1,240 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1994,1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : May 1994 */
/*-----------------------------------------------------------------------*/
/* StrList/Vector i/o utility functions */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include "EST_types.h"
#include "EST_String.h"
#include "EST_Pathname.h"
#include "EST_string_aux.h"
#include "EST_cutils.h"
#include "EST_Token.h"
int StrListtoFList(EST_StrList &s, EST_FList &f)
{
EST_Litem *p;
for (p = s.head(); p; p = p->next())
if (!s(p).matches(RXdouble))
{
cout <<
"Expecting a floating point value in StrListtoFlist(): got "
<< s(p) << endl;
return -1;
}
else
f.append(atof(s(p)));
return 0;
}
int StrListtoIList(EST_StrList &s, EST_IList &il)
{
EST_Litem *p;
for (p = s.head(); p; p = p->next())
if (!s(p).matches(RXint))
{
cout <<
"Expecting a integer value in StrListtoIList(): got "
<< s(p) << endl;
return -1;
}
else
il.append(atoi(s(p)));
return 0;
}
// read string list eclosed in brackets. Simply a place holder for
// future use with more complicate lists.
void BracketStringtoStrList(EST_String s, EST_StrList &l, EST_String sep)
{
s.gsub("(", "");
s.gsub(")", "");
StringtoStrList(s, l, sep);
}
void StringtoStrList(EST_String s, EST_StrList &l, EST_String sep)
{
EST_TokenStream ts;
EST_String tmp;
ts.open_string(s);
(void)sep;
if (sep != "") // default is standard white space
ts.set_WhiteSpaceChars(sep);
ts.set_SingleCharSymbols(";");
// modified by simonk - was appending an empty
// string at end of list.
// unmodified back again by pault
while (!ts.eof())
l.append(ts.get().string());
ts.close();
return;
}
void StrListtoString(EST_StrList &l, EST_String &s, EST_String sep)
{
for (EST_Litem *p = l.head(); p; p = p->next())
s += l(p) + sep;
}
EST_read_status load_StrList(EST_String filename, EST_StrList &l)
{
EST_TokenStream ts;
EST_String s;
if(ts.open(filename) != 0){
cerr << "Can't open EST_StrList file " << filename << endl;
return misc_read_error;
}
ts.set_SingleCharSymbols("");
ts.set_PunctuationSymbols("");
while (!ts.eof())
l.append(ts.get().string());
ts.close();
return format_ok;
}
EST_write_status save_StrList(EST_String filename, EST_StrList &l,
EST_String style)
{
ostream *outf;
EST_Litem *p;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
if (!(*outf))
return write_fail;
if (style == "words")
{
for (p = l.head(); p; p = p->next())
{
*outf << l(p);
if (p->next() != 0)
*outf << " ";
}
*outf << endl;
}
else if (style == "lines")
for (p = l.head(); p; p = p->next())
*outf << l(p) << endl;
else
{
cerr << "Unknown style for writing StrLists: " << style << endl;
return misc_write_error;
}
delete outf;
return write_ok;
}
int strlist_member(const EST_StrList &l,const EST_String &s)
{
EST_Litem *p;
for (p = l.head(); p != 0; p = p->next())
if (l.item(p) == s)
return TRUE;
return FALSE;
}
int strlist_index(const EST_StrList &l,const EST_String &s)
{
EST_Litem *p;
int j=0;
for (p = l.head(); p != 0; p = p->next())
{
if (l.item(p) == s)
return j;
j++;
}
return -1;
}
void StrList_to_StrVector(EST_StrList &l, EST_StrVector &v)
{
int len,i;
len = l.length();
v.resize(len);
//EST_TBI *p;
EST_Litem *p;
for (p = l.head(),i=0; p != 0; p = p->next(),i++)
v[i] = l(p);
}
void StrVector_to_StrList(EST_StrVector &v, EST_StrList &l)
{
int i;
l.clear();
for (i=0;i<v.length();i++)
l.append(v[i]);
}
int StrVector_index(const EST_StrVector &v,const EST_String &s)
{
int i;
for(i=0;i<v.length();i++)
if(v(i) == s)
return i;
return -1;
}

107
base_class/EST_svec_aux.cc Normal file
View File

@ -0,0 +1,107 @@
/*************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1994,1995,1996 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* Author : Paul Taylor */
/* Date : May 1994 */
/*-----------------------------------------------------------------------*/
/* StrVector i/o utility functions */
/* */
/*=======================================================================*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include "EST_types.h"
#include "EST_String.h"
#include "EST_Pathname.h"
#include "EST_string_aux.h"
#include "EST_cutils.h"
#include "EST_Token.h"
EST_read_status load_TList_of_StrVector(EST_TList<EST_StrVector> &w,
const EST_String &filename,
const int vec_len)
{
EST_TokenStream ts;
EST_String s;
EST_StrVector v;
int c;
if(ts.open(filename) != 0){
cerr << "Can't open EST_TList<EST_StrVector> file " << filename << endl;
return misc_read_error;
}
v.resize(vec_len);
// ts.set_SingleCharSymbols("");
// ts.set_PunctuationSymbols("");
c=0;
while (!ts.eof())
{
s = ts.get().string();
if(s != "")
{
if(c == vec_len)
{
cerr << "Too many points in line - expected " << vec_len << endl;
return wrong_format;
}
else
v[c++] = s;
}
if(ts.eoln())
{
if(c != vec_len)
{
cerr << "Too few points in line - got "
<< c << ", expected " << vec_len << endl;
return wrong_format;
}
else
{
w.append(v);
c=0;
}
}
}
ts.close();
return format_ok;
}

78
base_class/Makefile Normal file
View File

@ -0,0 +1,78 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
# Makefile for base classes #
# #
#=========================================================================#
TOP=..
DIRNAME=base_class
LIB_BUILD_DIRS = string inst_tmpl
BUILD_DIRS = $(LIB_BUILD_DIRS)
ALL_DIRS = $(BUILD_DIRS)
LOCAL_DEFAULT_LIBRARY = estbase
H = EST_matrix_support.h rateconv.h EST_get_function_template.h
T = EST_TList.cc EST_TSortable.cc EST_TKVL.cc \
EST_TMatrix.cc EST_TSimpleMatrix.cc \
EST_TVector.cc EST_TSimpleVector.cc \
EST_THash.cc EST_Tvectlist.cc \
EST_TTimeIndex.cc EST_TDeque.cc \
EST_TBuffer.cc EST_TNamedEnum.cc
TSRCS = EST_Featured.cc EST_Features.cc
CPPSRCS = EST_UList.cc EST_Option.cc EST_StringTrie.cc EST_Token.cc \
vec_mat_aux.cc EST_Pathname_unix.cc THash_aux.cc \
EST_FMatrix.cc EST_Complex.cc EST_Val.cc \
EST_matrix_support.cc rateconv.cc \
EST_IMatrix.cc EST_SMatrix.cc \
EST_DMatrix.cc vec_mat_aux_d.cc EST_FeatureData.cc\
EST_slist_aux.cc EST_svec_aux.cc EST_ilist_aux.cc \
EST_features_aux.cc EST_features_io.cc vec_mat_aux_i.cc \
$(TSRCS)
SRCS = $(CPPSRCS)
OBJS = $(CPPSRCS:.cc=.o)
FILES = $(SRCS) EST_Pathname_win32.cc $(T) $(H)\
Makefile
ALL = .buildlib $(BUILD_DIRS)
include $(TOP)/config/common_make_rules
# Always compile with -O3 as its an important function
rateconv.o:
$(CXX_COMMAND) -O3 rateconv.cc -o rateconv.o

54
base_class/THash_aux.cc Normal file
View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Fri Apr 4 1997 */
/************************************************************************/
/* */
/* Default has functions and stuff. */
/* */
/************************************************************************/
#include "EST_THash.h"
// default hash function, something like the one in Perl.
unsigned int EST_HashFunctions::DefaultHash(const void *data, size_t size, unsigned int n)
{
return DefaultHashFunction(data, size, n);
}
unsigned int EST_HashFunctions::StringHash(const EST_String &key, unsigned int n)
{
return DefaultHashFunction((const char *)key, key.length(), n);
}

View File

@ -0,0 +1,82 @@
###########################################################################
## ##
## Centre for Speech Technology Research ##
## University of Edinburgh, UK ##
## Copyright (c) 1996 ##
## All Rights Reserved. ##
## ##
## Permission is hereby granted, free of charge, to use and distribute ##
## this software and its documentation without restriction, including ##
## without limitation the rights to use, copy, modify, merge, publish, ##
## distribute, sublicense, and/or sell copies of this work, and to ##
## permit persons to whom this work is furnished to do so, subject to ##
## the following conditions: ##
## 1. The code must retain the above copyright notice, this list of ##
## conditions and the following disclaimer. ##
## 2. Any modifications must be clearly marked as such. ##
## 3. Original authors' names are not deleted. ##
## 4. The authors' names are not used to endorse or promote products ##
## derived from this software without specific prior written ##
## permission. ##
## ##
## THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK ##
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
## SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE ##
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
## THIS SOFTWARE. ##
## ##
###########################################################################
# Makefile for base class instantiations #
# #
# Keeping these as different .o files makes the binaries a lot smaller #
# #
#=========================================================================#
TOP=../..
DIRNAME=base_class/inst_tmpl
LOCAL_DEFAULT_LIBRARY = estbase
TSRCS = list_i_t.cc list_si_t.cc list_f_t.cc list_d_t.cc \
list_c_t.cc list_s_t.cc \
list_val_t.cc \
list_li_t.cc list_vs_t.cc list_vi_t.cc \
\
matrix_i_t.cc matrix_si_t.cc matrix_f_t.cc matrix_d_t.cc \
matrix_s_t.cc \
matrix_val_t.cc \
\
vector_i_t.cc vector_si_t.cc vector_f_t.cc vector_d_t.cc \
vector_c_t.cc vector_s_t.cc \
vector_val_t.cc vector_ls_t.cc \
vector_fvector_t.cc vector_fmatrix_t.cc \
vector_dvector_t.cc vector_dmatrix_t.cc \
\
kvl_fi_t.cc kvl_ii_t.cc kvl_sd_t.cc kvl_sf_t.cc \
kvl_ss_t.cc kvl_si_t.cc kvl_sv_t.cc kvl_rs_t.cc kvl_vpi_t.cc \
\
hash_fi_t.cc hash_ii_t.cc hash_sd_t.cc hash_sf_t.cc \
hash_ss_t.cc hash_si_t.cc hash_sv_t.cc hash_iv_t.cc \
hash_sfmp_t.cc hash_srp.cc \
\
tbuffer_t.cc \
\
deq_s_t.cc deq_i_t.cc \
\
# kvl_srcfmp_t.cc kvl_scsmm_t.cc matrix_c_t.cc
CPPSRCS = $(TSRCS)
SRCS = $(CPPSRCS)
OBJS = $(CPPSRCS:.cc=.o)
FILES = $(SRCS) Makefile timeindex_tr.cc
ALL = .buildlib $(BUILD_DIRS)
include $(TOP)/config/common_make_rules

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* -------------------------------------------------------------------- */
/* Instantiate queue class for integers. */
/* */
/*************************************************************************/
#include "EST_String.h"
#include "EST_TDeque.h"
Declare_TDEQ_Base(int,0)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TDeque.cc"
Instantiate_TDEQ(int)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* ---------------------------------------------------------------------*/
/* Instantiate DEQ string base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TDeque.h"
Declare_TDEQ_Class(EST_String,"FILLER")
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TDeque.cc"
Instantiate_TDEQ(EST_String)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash float int base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> float EST_THash<float, int>::Dummy_Key = 0.0;
template <> int EST_THash<float, int>::Dummy_Value = 0;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_THash(float, int)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash int int base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> int EST_THash<int, int>::Dummy_Key = 0;
template <> int EST_THash<int, int>::Dummy_Value = 0;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_THash(int,int)
#endif

View File

@ -0,0 +1,57 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1999 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: March 1999 */
/* ---------------------------------------------------------------------*/
/* */
/* Instantiate THash int val base class. */
/* */
/************************************************************************/
#include "EST_THash.h"
#include "EST_Val.h"
static EST_Val Dummy_Val;
template <> int EST_THash<int, EST_Val>::Dummy_Key = 0;
template <> EST_Val EST_THash<int, EST_Val>::Dummy_Value = Dummy_Val;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_THash(int,EST_Val)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash/L base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, double>::Dummy_Key = "DUMMY";
template <> double EST_THash<EST_String, double>::Dummy_Value = 0.0;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash(double)
#endif

View File

@ -0,0 +1,53 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash string float classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, float>::Dummy_Key = "DUMMY";
template <> float EST_THash<EST_String, float>::Dummy_Value = 0.0;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash(float)
#endif

View File

@ -0,0 +1,53 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash/L base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_FMatrix.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, EST_FMatrix *>::Dummy_Key = "DUMMY";
template <> EST_FMatrix *EST_THash<EST_String, EST_FMatrix *>::Dummy_Value = NULL;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash_T(EST_FMatrix*,EST_StringFMatrixP)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash string int base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, int>::Dummy_Key = "DUMMY";
template <> int EST_THash<EST_String, int>::Dummy_Value = 0;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash(int)
#endif

View File

@ -0,0 +1,53 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash/L base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "ling_class/EST_Relation.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, EST_Relation *>::Dummy_Key = "DUMMY";
template <> EST_Relation *EST_THash<EST_String, EST_Relation *>::Dummy_Value = NULL;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash_T_MIN(EST_Relation*,EST_StringRelationP)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash string string base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_THash.h"
template <> EST_String EST_THash<EST_String, EST_String>::Dummy_Key = "DUMMY";
template <> EST_String EST_THash<EST_String, EST_String>::Dummy_Value = "DUMMY";
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash(EST_String)
#endif

View File

@ -0,0 +1,57 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate THash string string base class. */
/* */
/************************************************************************/
#include "EST_THash.h"
#include "EST_String.h"
#include "EST_Val.h"
static EST_Val Dummy_Val;
template <> EST_String EST_THash<EST_String, EST_Val>::Dummy_Key = "DUMMY";
template <> EST_Val EST_THash<EST_String, EST_Val>::Dummy_Value = Dummy_Val;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_THash.cc"
Instantiate_TStringHash(EST_Val)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL float int base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(float, int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(float, int)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL int int base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(int,int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(int,int)
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL string string base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_Regex.h"
#include "EST_TKVL.h"
Declare_KVL(EST_Regex, EST_String)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_Regex, EST_String)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate KV/L base classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(EST_String, double)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_String, double)
#endif

View File

@ -0,0 +1,53 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL string float classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(EST_String, float)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_String, float)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL string int base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(EST_String, int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_String, int)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL string string base class. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TKVL.h"
Declare_KVL(EST_String, EST_String)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_String, EST_String)
#endif

View File

@ -0,0 +1,56 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black (awb@cstr.ed.ac.uk) */
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL string string base class. */
/* */
/************************************************************************/
#include "EST_TKVL.h"
#include "EST_String.h"
#include "EST_Val.h"
Declare_KVL_N(EST_String, EST_Val, 100)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL(EST_String, EST_Val)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* Date: December 1997 */
/* ---------------------------------------------------------------------*/
/* Instantiate EST_TKVL void * int base classes. */
/* */
/************************************************************************/
#include "EST_TKVL.h"
Declare_KVL_T(void *,int, voidP_int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TKVL.cc"
Instantiate_KVL_T(void*,int,voidP_int)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(char)
Declare_TSortable(char)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(char)
Instantiate_TSortable(char)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate double list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(double)
Declare_TSortable(double)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(double)
Instantiate_TSortable(double)
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate float lists. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(float)
Declare_TSortable(float)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(float)
Instantiate_TSortable(float)
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(int)
Declare_TSortable(int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(int)
Instantiate_TSortable(int)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_types.h"
Declare_TList_T(EST_IList, LIST_INT)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
Instantiate_TList_T(EST_IList, LIST_INT)
#endif

View File

@ -0,0 +1,57 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black */
/* Date: December 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate some basic string classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(EST_String)
Declare_TSortable(EST_String)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(EST_String)
Instantiate_TSortable(EST_String)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
Declare_TList(short)
Declare_TSortable(short)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(short)
Instantiate_TSortable(short)
#endif

View File

@ -0,0 +1,53 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TList.h"
#include "EST_TSortable.h"
#include "EST_Val.h"
Declare_TList(EST_Val)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
#include "../base_class/EST_TSortable.cc"
Instantiate_TList(EST_Val)
#endif

View File

@ -0,0 +1,61 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black */
/* Date: December 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate some basic string classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TList.h"
#include "EST_TVector.h"
#include "EST_TSimpleVector.h"
#include "EST_TSortable.h"
Declare_TList_T(EST_TVector<int>, VEC_INT)
Declare_TList_T(EST_TSimpleVector<int>, SVEC_INT)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
typedef EST_TVector<int> tvector_int_t;
typedef EST_TSimpleVector<int> tsimplevector_int_t;
Instantiate_TList_T(tvector_int_t, VEC_INT)
Instantiate_TList_T(tsimplevector_int_t, SVEC_INT)
#endif

View File

@ -0,0 +1,57 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Alan W Black */
/* Date: December 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate some basic string classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TList.h"
#include "EST_TVector.h"
#include "EST_TSortable.h"
Declare_TList_T(EST_TVector<EST_String>, VEC_STRING)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TList.cc"
typedef EST_TVector<EST_String> tvector_string_t;
Instantiate_TList_T(tvector_string_t, VEC_STRING)
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate double basic matrix classes. */
/* */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_TSimpleMatrix.h"
Declare_TMatrix(double)
Declare_TSimpleMatrix(double)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleMatrix.cc"
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(double)
Instantiate_TSimpleMatrix(double)
#endif

View File

@ -0,0 +1,81 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate float basic matrix classes. */
/* */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_TSimpleMatrix.h"
Declare_TMatrix(float)
Declare_TSimpleMatrix(float)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleMatrix.cc"
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(float)
Instantiate_TSimpleMatrix(float)
EST_write_status save(const EST_String &filename, const EST_TMatrix<float> &a)
{
int i,j;
ostream *outf;
EST_String s;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
if (!(*outf)) return misc_write_error;
for (i=0; i < a.num_rows(); i++)
{
for (j = 0; j < a.num_columns(); ++j)
{
*outf << a(i,j) << "\t";
}
*outf << endl;
}
if (outf != &cout)
delete outf;
return write_ok;
}
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate int basic matrix classes. */
/* */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_TSimpleMatrix.h"
Declare_TMatrix(int)
Declare_TSimpleMatrix(int)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleMatrix.cc"
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(int)
Instantiate_TSimpleMatrix(int)
#endif

View File

@ -0,0 +1,52 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate short basic matrix classes. */
/* */
/************************************************************************/
#include "EST_String.h"
#include "EST_TMatrix.h"
Declare_TMatrix(EST_String)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(EST_String)
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate short basic matrix classes. */
/* */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_TSimpleMatrix.h"
Declare_TMatrix(short)
Declare_TSimpleMatrix(short)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleMatrix.cc"
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(short)
Instantiate_TSimpleMatrix(short)
#endif

View File

@ -0,0 +1,51 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Paul Taylor */
/* Date: July 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate EST_Val basic matrix classes. */
/************************************************************************/
#include "EST_TMatrix.h"
#include "EST_Val.h"
Declare_TMatrix(EST_Val)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TMatrix.cc"
Instantiate_TMatrix(EST_Val)
#endif

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate some basic list classes. */
/* */
/************************************************************************/
#include "EST_TBuffer.h"
struct old_tbuffer EST_old_buffers[TBUFFER_N_OLD];
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TBuffer.cc"
template class EST_TBuffer<short>;
template class EST_TBuffer<float>;
template class EST_TBuffer<int>;
template class EST_TBuffer<double>;
#endif

View File

@ -0,0 +1,63 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/*************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Wed Mar 25 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate the templates for time index on tracks. */
/* */
/*************************************************************************/
#include "EST_TTimeIndex.h"
#include "EST_Track.h"
static EST_TTI_Entry<EST_Track> def_val_s;
static EST_TTI_Entry<EST_Track> error_return_s;
const EST_TTI_Entry<EST_Track> *EST_TVector<EST_TTI_Entry<EST_Track> >::def_val(&def_val_s);
EST_TTI_Entry<EST_Track> *EST_TVector<EST_TTI_Entry<EST_Track> >::error_return(&error_return_s);
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TTimeIndex.cc"
#include "../base_class/EST_TVector.cc"
template class EST_TTimeIndex<EST_Track>;
template class EST_TTI_Entry<EST_Track>;
template class EST_TVector<EST_TTI_Entry<EST_Track> >;
template int operator !=(const EST_TTI_Entry<EST_Track> &e1,
const EST_TTI_Entry<EST_Track> &e2);
template ostream& operator <<(ostream &s,
const EST_TTI_Entry<EST_Track> &e);
#endif

View File

@ -0,0 +1,55 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: December 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate char basic vector classes. */
/* */
/************************************************************************/
#include "EST_TVector.h"
#include "EST_TSimpleVector.h"
Declare_TVector_Base(char, 0, -123)
Declare_TSimpleVector(char)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleVector.cc"
#include "../base_class/EST_TVector.cc"
#include "../base_class/EST_Tvectlist.cc"
Instantiate_TVector(char)
Instantiate_TSimpleVector(char)
#endif

View File

@ -0,0 +1,56 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* -------------------------------------------------------------------- */
/* Instantiate double basic vector classes. */
/* */
/************************************************************************/
#include "EST_TVector.h"
#include "EST_TSimpleVector.h"
Declare_TVector_Base(double, 0, -123.456)
Declare_TSimpleVector(double)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleVector.cc"
#include "../base_class/EST_TVector.cc"
#include "../base_class/EST_Tvectlist.cc"
Instantiate_TVector(double)
Instantiate_TSimpleVector(double)
#endif

View File

@ -0,0 +1,72 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: October 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate vector of double matrices. */
/* */
/************************************************************************/
#include "EST_types.h"
#include "EST_TVector.h"
static const EST_DMatrix def_val_DMatrix;
static EST_DMatrix error_return_DMatrix;
template <> const EST_DMatrix *EST_TVector<EST_DMatrix>::def_val = &def_val_DMatrix;
template <> EST_DMatrix *EST_TVector<EST_DMatrix>::error_return = &error_return_DMatrix;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TVector.cc"
template class EST_TVector<EST_DMatrix>;
#endif
int operator !=(const EST_DMatrix &fm1,
const EST_DMatrix &fm2)
{
int i,j;
if(fm1.num_rows() != fm2.num_rows() ||
fm1.num_columns() != fm2.num_columns() )
return FALSE;
for(i=0;i<fm1.num_rows();i++)
for(j=0;j<fm1.num_columns();j++)
if(fm1.a_no_check(i,j) != fm1.a_no_check(i,j))
return FALSE;
return TRUE;
}

View File

@ -0,0 +1,69 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: October 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate vector of double vectors (not a matrix !). */
/* */
/************************************************************************/
#include "EST_types.h"
#include "EST_TVector.h"
static const EST_DVector def_val_DVector;
static EST_DVector error_return_DVector;
template <> const EST_DVector *EST_TVector<EST_DVector>::def_val = &def_val_DVector;
template <> EST_DVector *EST_TVector<EST_DVector>::error_return = &error_return_DVector;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TVector.cc"
template class EST_TVector<EST_DVector>;
#endif
int operator !=(const EST_DVector &fv1,
const EST_DVector &fv2)
{
int i;
if(fv1.length() != fv2.length())
return FALSE;
for(i=0;i<fv1.length();i++)
if(fv1.a_no_check(i) != fv2.a_no_check(i))
return FALSE;
return TRUE;
}

View File

@ -0,0 +1,79 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
/* Date: Tue Aug 26 1997 */
/* ------------------------------------------------------------------- */
/* Instantiate float basic vector classes. */
/* */
/************************************************************************/
#include "EST_TVector.h"
#include "EST_TSimpleVector.h"
Declare_TVector_Base(float, 0, -123.456)
Declare_TSimpleVector(float)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TSimpleVector.cc"
#include "../base_class/EST_TVector.cc"
#include "../base_class/EST_Tvectlist.cc"
Instantiate_TVector(float)
Instantiate_TSimpleVector(float)
EST_write_status save(const EST_String &filename, const EST_TVector<float> &a)
{
int i;
ostream *outf;
EST_String s;
if (filename == "-")
outf = &cout;
else
outf = new ofstream(filename);
if (!(*outf)) return misc_write_error;
for (i = 0; i < a.n(); ++i)
{
*outf << a(i) << "\t";
}
*outf << endl;
if (outf != &cout)
delete outf;
return write_ok;
}
#endif

View File

@ -0,0 +1,73 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: October 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate vector of float matrices. */
/* */
/************************************************************************/
#include "EST_types.h"
#include "EST_TVector.h"
static const EST_FMatrix def_val_FMatrix;
static EST_FMatrix error_return_FMatrix;
template <> const EST_FMatrix *EST_TVector<EST_FMatrix>::def_val = &def_val_FMatrix;
template <> EST_FMatrix *EST_TVector<EST_FMatrix>::error_return = &error_return_FMatrix;
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TVector.cc"
template class EST_TVector<EST_FMatrix>;
#endif
int operator !=(const EST_FMatrix &fm1,
const EST_FMatrix &fm2)
{
int i,j;
if(fm1.num_rows() != fm2.num_rows() ||
fm1.num_columns() != fm2.num_columns() )
return FALSE;
for(i=0;i<fm1.num_rows();i++)
for(j=0;j<fm1.num_columns();j++)
if(fm1.a_no_check(i,j) != fm1.a_no_check(i,j))
return FALSE;
return TRUE;
}

View File

@ -0,0 +1,54 @@
/************************************************************************/
/* */
/* Centre for Speech Technology Research */
/* University of Edinburgh, UK */
/* Copyright (c) 1996,1997 */
/* All Rights Reserved. */
/* */
/* Permission is hereby granted, free of charge, to use and distribute */
/* this software and its documentation without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of this work, and to */
/* permit persons to whom this work is furnished to do so, subject to */
/* the following conditions: */
/* 1. The code must retain the above copyright notice, this list of */
/* conditions and the following disclaimer. */
/* 2. Any modifications must be clearly marked as such. */
/* 3. Original authors' names are not deleted. */
/* 4. The authors' names are not used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
/* THIS SOFTWARE. */
/* */
/************************************************************************/
/* */
/* Date: October 1998 */
/* -------------------------------------------------------------------- */
/* Instantiate vector of float vectors (not a matrix !). */
/* */
/************************************************************************/
#include "EST_types.h"
#include "EST_TVector.h"
Declare_TVector_T(EST_FVector, tvector_fvector)
#if defined(INSTANTIATE_TEMPLATES)
#include "../base_class/EST_TVector.cc"
Instantiate_TVector_T(EST_FVector, tvector_fvector)
#endif

Some files were not shown because too many files have changed in this diff Show More