├── .gitignore ├── LICENSE ├── README.md ├── Sphinx ├── include │ ├── module.modulemap │ ├── pocketsphinx │ │ ├── cmdln_macro.h │ │ ├── pocketsphinx.h │ │ ├── pocketsphinx_export.h │ │ ├── ps_lattice.h │ │ ├── ps_mllr.h │ │ └── ps_search.h │ └── sphinxbase │ │ ├── ad.h │ │ ├── agc.h │ │ ├── bio.h │ │ ├── bitvec.h │ │ ├── byteorder.h │ │ ├── case.h │ │ ├── ckd_alloc.h │ │ ├── clapack_lite.h │ │ ├── cmd_ln.h │ │ ├── cmn.h │ │ ├── err.h │ │ ├── f2c.h │ │ ├── fe.h │ │ ├── feat.h │ │ ├── filename.h │ │ ├── fixpoint.h │ │ ├── fsg_model.h │ │ ├── genrand.h │ │ ├── glist.h │ │ ├── hash_table.h │ │ ├── heap.h │ │ ├── huff_code.h │ │ ├── jsgf.h │ │ ├── listelem_alloc.h │ │ ├── logmath.h │ │ ├── matrix.h │ │ ├── mmio.h │ │ ├── mulaw.h │ │ ├── ngram_model.h │ │ ├── pio.h │ │ ├── prim_type.h │ │ ├── profile.h │ │ ├── sbthread.h │ │ ├── sphinx_config.h │ │ ├── sphinxbase_export.h │ │ ├── strfuncs.h │ │ └── yin.h ├── lib │ ├── pocketsphinx │ │ ├── arm64 │ │ │ └── libpocketsphinx.a │ │ ├── armv7 │ │ │ └── libpocketsphinx.a │ │ ├── armv7s │ │ │ └── libpocketsphinx.a │ │ ├── i386 │ │ │ └── libpocketsphinx.a │ │ ├── libpocketsphinx.a │ │ └── x86_64 │ │ │ └── libpocketsphinx.a │ └── sphinxbase │ │ ├── arm64 │ │ ├── libsphinxad.a │ │ └── libsphinxbase.a │ │ ├── armv7 │ │ ├── libsphinxad.a │ │ └── libsphinxbase.a │ │ ├── armv7s │ │ ├── libsphinxad.a │ │ └── libsphinxbase.a │ │ ├── i386 │ │ ├── libsphinxad.a │ │ └── libsphinxbase.a │ │ ├── libsphinxad.a │ │ ├── libsphinxbase.a │ │ └── x86_64 │ │ ├── libsphinxad.a │ │ └── libsphinxbase.a └── share │ └── pocketsphinx │ └── model │ └── en-us │ ├── cmudict-en-us.dict │ ├── en-us.lm.dmp │ ├── en-us │ ├── feat.params │ ├── mdef │ ├── means │ ├── noisedict │ ├── sendump │ ├── transition_matrices │ └── variances │ └── goforward.raw ├── TLSphinx.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── TLSphinx.xcscheme ├── TLSphinx ├── Config.swift ├── Decoder.swift ├── Globals.swift ├── Hypotesis.swift ├── Info.plist └── TLSphinx.h └── TLSphinxTests ├── Basic.swift ├── Info.plist └── LiveDecode.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | # Note: if you ignore the Pods directory, make sure to uncomment 30 | # `pod install` in .travis.yml 31 | # 32 | # Pods/ 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tryolabs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TLSphinx 2 | 3 | TLSphinx is a Swift wrapper around [Pocketsphinx], a portable library based on [CMU Sphinx], that allow an application to perform speech recognition **without the audio ever leaving the device** 4 | 5 | This repository has two main parts. The first is a syntetized version of the [pocketsphinx](http://sourceforge.net/projects/cmusphinx/files/pocketsphinx/5prealpha/) and [sphinx base] repositories with a module map to access the library as a [Clang module]. This module is accessed under the name `Shpinx` and has two submodules: `Pocket` and `Base` in reference to _pocketsphinx_ and _sphinx base_. 6 | 7 | The second part is `TLSphinx`, a Swift framework that uses the `Sphinx` Clang module and exposes a Swift-like API that talks to _pocketsphinx_. 8 | 9 | _Note: I write a blog post about `TLSphinx` [here](http://blog.tryolabs.com/2015/06/15/tlsphinx-automatic-speech-recognition-asr-in-swift/) at the [Tryolabs Blog]. Check it out for a short history about why I wrote this._ 10 | 11 | ## Usage 12 | 13 | The framework provides three classes: 14 | - `Config` describe the configuration needed to recognize speech. 15 | - `Decoder` is the main class that provides the API to perform all decoding. 16 | - `Hypotesis` is the result of a decode attempt. It has a `text` and a `score` properties. 17 | 18 | #### Config 19 | 20 | Represents the _cmd_ln_t_ opaque structure in `Sphinx`. The default constructor takes an array of tuples with the form `(param name, param value)` where _"param name"_ is the name of one of the parameters recognized by `Sphinx`. In this example we are passing the acustic model, the language model and the dictionary. For a complete list of recognized parameters check the [Sphinx docs]. 21 | 22 | The class has a public property to turn on/off the debug info from `Sphinx`: 23 | ```swift 24 | public var showDebugInfo: Bool 25 | ``` 26 | 27 | #### Decoder 28 | 29 | Represent the _ps_decoder_t_ opaque struct in `Sphinx`. The default constructor take a `Config` object as parameter. 30 | 31 | This has the functions to perform the decode from a file or from the mic. The result is returned in an optional `Hypotesis` object, following the naming convention of the _Pocketsphinx_ API. The functions are: 32 | 33 | To decode speech from a file: 34 | ```swift 35 | public func decodeSpeechAtPath (filePath: String, complete: (Hypotesis?) -> ()) 36 | ``` 37 | The audio pointed by `filePath` must have the following characteristics: 38 | - single-channel (monaural) 39 | - little-endian 40 | - unheadered 41 | - 16-bit signed 42 | - PCM 43 | - sampled at 16000 Hz 44 | 45 | To control the size of the buffer used to read the file, the `Decoder` class has a public property 46 | ```swift 47 | public var bufferSize: Int 48 | ``` 49 | 50 | To decode a live audio stream from the mic: 51 | ```swift 52 | public func startDecodingSpeech (utteranceComplete: (Hypotesis?) -> ()) 53 | public func stopDecodingSpeech () 54 | ``` 55 | 56 | You can use the same `Decoder` instance many times. 57 | 58 | #### Hypotesis 59 | 60 | This struct represents the result of a _decode_ attempt. It has a `text` property with the best scored text and a `score` with the score value. This struct implements `Printable` so you can print it with `println(hypotesis_value)`. 61 | 62 | ### Examples 63 | 64 | #### Processing an Audio File 65 | 66 | As an example let's see how to decode the speech in an audio file. To do so you first need to create a `Config` object and pass it to the `Decoder` constructor. With the decoder you can perform automatic speech recognition from an audio file like so: 67 | 68 | ```swift 69 | import TLSphinx 70 | 71 | let hmm = ... // Path to the acustic model 72 | let lm = ... // Path to the languaje model 73 | let dict = ... // Path to the languaje dictionary 74 | 75 | if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { 76 | if let decoder = Decoder(config:config) { 77 | 78 | let audioFile = ... // Path to an audio file 79 | 80 | decoder.decodeSpeechAtPath(audioFile) { 81 | 82 | if let hyp: Hypotesis = $0 { 83 | // Print the decoder text and score 84 | println("Text: \(hyp.text) - Score: \(hyp.score)") 85 | } else { 86 | // Can't decode any speech because of an error 87 | } 88 | } 89 | } else { 90 | // Handle Decoder() fail 91 | } 92 | } else { 93 | // Handle Config() fail 94 | } 95 | ``` 96 | The decode is performed with the `decodeSpeechAtPath` function in the bacground. Once the process finishes, the `complete` closure is called in the main thread. 97 | 98 | #### Speech from the Mic 99 | 100 | ```swift 101 | import TLSphinx 102 | 103 | let hmm = ... // Path to the acoustic model 104 | let lm = ... // Path to the language model 105 | let dict = ... // Path to the language dictionary 106 | 107 | if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { 108 | if let decoder = Decoder(config:config) { 109 | 110 | decoder.startDecodingSpeech { 111 | 112 | if let hyp: Hypotesis = $0 { 113 | println(hyp) 114 | } else { 115 | // Can't decode any speech because an error 116 | } 117 | } 118 | } else { 119 | // Handle Decoder() fail 120 | } 121 | } else { 122 | // Handle Config() fail 123 | } 124 | 125 | //At some point in the future stop listen to the mic 126 | decoder.stopDecodingSpeech() 127 | 128 | ``` 129 | 130 | ## Installation 131 | 132 | The easiest way to integrate `TLSphinx` is using [Carthage] or a similar method to get the framework bundle. This lets you integrate the framework and the `Sphinx` module without _magic_. 133 | 134 | #### Carthage 135 | 136 | In your `Cartfile` add a reference to the last version of `TLSphinx`: 137 | ```` 138 | github "Tryolabs/TLSphinx" ~> 0.0.4 139 | ```` 140 | 141 | Then run `carthage update`, this should fetch and build the last version of `TLSphinx`. Once it's done, drag the _TLSphinx.framewok_ bundle to the XCode _Linked Frameworks and Libraries_. You must tell XCode where to find `Sphinx` module that is located in the Carthage checkout. To do so: 142 | - add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/include` to _Header Search Paths_ recursive 143 | - add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/lib` to _Library Search Paths_ recursive 144 | - in _Swift Compiler - Search Paths_ add `$(SRCROOT)/Carthage/Checkouts/TLSphinx/Sphinx/include` to _Import Paths_ 145 | 146 | #### Manual 147 | 148 | Download the project from this repository and drag the _TLSpinx_ project to your XCode project. If you encounter any errors about missing headers and/or libraries for _Sphinx_ please add the `Spinx/include` directory to your header search path and `Sphinx/lib` to the library search path and mark it as `recursive`. 149 | 150 | ## Author 151 | 152 | BrunoBerisso, bruno@tryolabs.com 153 | 154 | ## License 155 | 156 | TLSphinx is available under the MIT license. See the LICENSE file for more info. 157 | 158 | [CMU Sphinx]: http://cmusphinx.sourceforge.net/ 159 | [Pocketsphinx]: http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx 160 | [sphinx base]: http://sourceforge.net/projects/cmusphinx/files/sphinxbase/5prealpha/ 161 | [Clang module]: http://clang.llvm.org/docs/Modules.html 162 | [Sphinx docs]: http://cmusphinx.sourceforge.net/wiki/ 163 | [Tryolabs Blog]: http://blog.tryolabs.com/ 164 | [Carthage]: https://github.com/Carthage/Carthage 165 | -------------------------------------------------------------------------------- /Sphinx/include/module.modulemap: -------------------------------------------------------------------------------- 1 | module Sphinx { 2 | 3 | module Base { 4 | umbrella "sphinxbase" 5 | link "sphinxbase" 6 | link "sphinxad" 7 | } 8 | 9 | module Pocket { 10 | umbrella header "pocketsphinx/pocketsphinx.h" 11 | link "pocketsphinx" 12 | export Base 13 | } 14 | } -------------------------------------------------------------------------------- /Sphinx/include/pocketsphinx/pocketsphinx_export.h: -------------------------------------------------------------------------------- 1 | #ifndef __POCKETSPHINX_EXPORT_H__ 2 | #define __POCKETSPHINX_EXPORT_H__ 3 | 4 | /* Win32/WinCE DLL gunk */ 5 | #if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(_WIN32_WP) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__WINSCW__) && !defined(__SYMBIAN32__) 6 | #ifdef POCKETSPHINX_EXPORTS /* Visual Studio */ 7 | #define POCKETSPHINX_EXPORT __declspec(dllexport) 8 | #else 9 | #define POCKETSPHINX_EXPORT __declspec(dllimport) 10 | #endif 11 | #else /* !_WIN32 */ 12 | #define POCKETSPHINX_EXPORT 13 | #endif 14 | 15 | #endif /* __POCKETSPHINX_EXPORT_H__ */ 16 | -------------------------------------------------------------------------------- /Sphinx/include/pocketsphinx/ps_mllr.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2008 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | /** 39 | * @file ps_mllr.h Model-space linear transforms for speaker adaptation 40 | */ 41 | 42 | #ifndef __PS_MLLR_H__ 43 | #define __PS_MLLR_H__ 44 | 45 | /* SphinxBase headers. */ 46 | #include 47 | #include 48 | 49 | /* PocketSphinx headers. */ 50 | #include 51 | 52 | /** 53 | * Feature space linear transform object. 54 | */ 55 | typedef struct ps_mllr_s ps_mllr_t; 56 | 57 | /** 58 | * Read a speaker-adaptive linear transform from a file. 59 | */ 60 | POCKETSPHINX_EXPORT 61 | ps_mllr_t *ps_mllr_read(char const *file); 62 | 63 | /** 64 | * Retain a pointer to a linear transform. 65 | */ 66 | POCKETSPHINX_EXPORT 67 | ps_mllr_t *ps_mllr_retain(ps_mllr_t *mllr); 68 | 69 | /** 70 | * Release a pointer to a linear transform. 71 | */ 72 | POCKETSPHINX_EXPORT 73 | int ps_mllr_free(ps_mllr_t *mllr); 74 | 75 | #endif /* __PS_MLLR_H__ */ 76 | -------------------------------------------------------------------------------- /Sphinx/include/pocketsphinx/ps_search.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset:4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2014 Alpha Cephei Inc.. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY ALPHA CEPHEI INC. ``AS IS'' AND 20 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 23 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * ==================================================================== 32 | * 33 | */ 34 | /** 35 | * @file ps_search.h User can configure several "search" objects with 36 | * different grammars and langauge models and switch them in runtime to 37 | * provide interactive experience for the user. 38 | * 39 | * There are different possible search modes: 40 | * 41 | *
    42 | *
  • keyword - efficiently looks for keyphrase and ignores other speech. allows to configure detection threshold.
  • 43 | *
  • grammar - recognizes speech according to JSGF grammar. Unlike keyphrase grammar search doesn't ignore words which are not in grammar but tries to recognize them.
  • 44 | *
  • ngram/lm - recognizes natural speech with a language model.
  • 45 | *
  • allphone - recognizes phonemes with a phonetic language model.
  • 46 | *
47 | * 48 | * Each search has a name and can be referenced by a name, names are 49 | * application-specific. The function ps_set_search allows to activate 50 | * the search previously added by a name. 51 | * 52 | * To add the search one needs to point to the grammar/language model 53 | * describing the search. The location of the grammar is specific to the 54 | * application. 55 | * 56 | * The exact design of a searches depends on your application. For 57 | * example, you might want to listen for activation keyword first and once 58 | * keyword is recognized switch to ngram search to recognize actual 59 | * command. Once you recognized the command you can switch to grammar 60 | * search to recognize the confirmation and then switch back to keyword listening 61 | * mode to wait for another command. 62 | * 63 | * If only a simple recognition is required it is sufficient to add a single search or 64 | * just configure the required mode with configuration options. 65 | */ 66 | 67 | #ifndef __PS_SEARCH_H__ 68 | #define __PS_SEARCH_H__ 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | #include 75 | #include 76 | 77 | /** 78 | * PocketSphinx search iterator. 79 | */ 80 | typedef struct ps_search_iter_s ps_search_iter_t; 81 | 82 | 83 | /** 84 | * Actives search with the provided name. 85 | * 86 | * Activates search with the provided name. The search must be added before 87 | * using either ps_set_fsg(), ps_set_lm() or ps_set_kws(). 88 | * 89 | * @return 0 on success, 1 on failure 90 | */ 91 | POCKETSPHINX_EXPORT 92 | int ps_set_search(ps_decoder_t *ps, const char *name); 93 | 94 | /** 95 | * Returns name of curent search in decoder 96 | * 97 | * @see ps_set_search 98 | */ 99 | POCKETSPHINX_EXPORT 100 | const char* ps_get_search(ps_decoder_t *ps); 101 | 102 | /** 103 | * Unsets the search and releases related resources. 104 | * 105 | * Unsets the search previously added with 106 | * using either ps_set_fsg(), ps_set_lm() or ps_set_kws(). 107 | * 108 | * @see ps_set_fsg 109 | * @see ps_set_lm 110 | * @see ps_set_kws 111 | */ 112 | POCKETSPHINX_EXPORT 113 | int ps_unset_search(ps_decoder_t *ps, const char *name); 114 | 115 | /** 116 | * Returns iterator over current searches 117 | * 118 | * @see ps_set_search 119 | */ 120 | POCKETSPHINX_EXPORT 121 | ps_search_iter_t *ps_search_iter(ps_decoder_t *ps); 122 | 123 | /** 124 | * Updates search iterator to point to the next position. 125 | * 126 | * This function automatically frees the iterator object upon reaching 127 | * the final entry. 128 | * @see ps_set_search 129 | */ 130 | POCKETSPHINX_EXPORT 131 | ps_search_iter_t *ps_search_iter_next(ps_search_iter_t *itor); 132 | 133 | /** 134 | * Retrieves the name of the search the iterator points to. 135 | * 136 | * @see ps_set_search 137 | */ 138 | POCKETSPHINX_EXPORT 139 | const char* ps_search_iter_val(ps_search_iter_t *itor); 140 | 141 | /** 142 | * Delete an unfinished search iterator 143 | * 144 | * @see ps_set_search 145 | */ 146 | POCKETSPHINX_EXPORT 147 | void ps_search_iter_free(ps_search_iter_t *itor); 148 | 149 | /** 150 | * Updates search iterator to point to the next position. 151 | * 152 | * This function automatically frees the iterator object upon reaching 153 | * the final entry. 154 | * @see ps_set_search 155 | */ 156 | POCKETSPHINX_EXPORT 157 | const char* ps_search_iter_val(ps_search_iter_t *itor); 158 | 159 | 160 | /** 161 | * Get the language model set object for this decoder. 162 | * 163 | * If N-Gram decoding is not enabled, this will return NULL. You will 164 | * need to enable it using ps_set_lmset(). 165 | * 166 | * @return The language model set object for this decoder. The 167 | * decoder retains ownership of this pointer, so you should 168 | * not attempt to free it manually. Use ngram_model_retain() 169 | * if you wish to reuse it elsewhere. 170 | */ 171 | POCKETSPHINX_EXPORT 172 | ngram_model_t *ps_get_lm(ps_decoder_t *ps, const char *name); 173 | 174 | /** 175 | * Adds new search based on N-gram language model. 176 | * 177 | * Associates N-gram search with the provided name. The search can be activated 178 | * using ps_set_search(). 179 | * 180 | * @see ps_set_search. 181 | */ 182 | POCKETSPHINX_EXPORT 183 | int ps_set_lm(ps_decoder_t *ps, const char *name, ngram_model_t *lm); 184 | 185 | /** 186 | * Adds new search based on N-gram language model. 187 | * 188 | * Convenient method to load N-gram model and create a search. 189 | * 190 | * @see ps_set_lm 191 | */ 192 | POCKETSPHINX_EXPORT 193 | int ps_set_lm_file(ps_decoder_t *ps, const char *name, const char *path); 194 | 195 | /** 196 | * Get the finite-state grammar set object for this decoder. 197 | * 198 | * If FSG decoding is not enabled, this returns NULL. Call 199 | * ps_set_fsgset() to enable it. 200 | * 201 | * @return The current FSG set object for this decoder, or 202 | * NULL if none is available. 203 | */ 204 | POCKETSPHINX_EXPORT 205 | fsg_model_t *ps_get_fsg(ps_decoder_t *ps, const char *name); 206 | 207 | /** 208 | * Adds new search based on finite state grammar. 209 | * 210 | * Associates FSG search with the provided name. The search can be activated 211 | * using ps_set_search(). 212 | * 213 | * @see ps_set_search 214 | */ 215 | POCKETSPHINX_EXPORT 216 | int ps_set_fsg(ps_decoder_t *ps, const char *name, fsg_model_t *fsg); 217 | 218 | /** 219 | * Adds new search using JSGF model. 220 | * 221 | * Convenient method to load JSGF model and create a search. 222 | * 223 | * @see ps_set_fsg 224 | */ 225 | POCKETSPHINX_EXPORT 226 | int ps_set_jsgf_file(ps_decoder_t *ps, const char *name, const char *path); 227 | 228 | /** 229 | * Adds new search using JSGF model. 230 | * 231 | * Convenience method to parse JSGF model from string and create a search. 232 | * 233 | * @see ps_set_fsg 234 | */ 235 | POCKETSPHINX_EXPORT 236 | int ps_set_jsgf_string(ps_decoder_t *ps, const char *name, const char *jsgf_string); 237 | 238 | /** 239 | * Get the current Key phrase to spot 240 | * 241 | * If KWS is not enabled, this returns NULL. Call 242 | * ps_update_kws() to enable it. 243 | * 244 | * @return The current keyphrase to spot 245 | */ 246 | POCKETSPHINX_EXPORT 247 | const char* ps_get_kws(ps_decoder_t *ps, const char *name); 248 | 249 | /** 250 | * Adds keywords from a file to spotting 251 | * 252 | * Associates KWS search with the provided name. The search can be activated 253 | * using ps_set_search(). 254 | * 255 | * @see ps_set_search 256 | */ 257 | POCKETSPHINX_EXPORT 258 | int ps_set_kws(ps_decoder_t *ps, const char *name, const char *keyfile); 259 | 260 | /** 261 | * Adds new keyword to spot 262 | * 263 | * Associates KWS search with the provided name. The search can be activated 264 | * using ps_set_search(). 265 | * 266 | * @see ps_set_search 267 | */ 268 | POCKETSPHINX_EXPORT 269 | int ps_set_keyphrase(ps_decoder_t *ps, const char *name, const char *keyphrase); 270 | 271 | /** 272 | * Adds new search based on phone N-gram language model. 273 | * 274 | * Associates N-gram search with the provided name. The search can be activated 275 | * using ps_set_search(). 276 | * 277 | * @see ps_set_search. 278 | */ 279 | POCKETSPHINX_EXPORT 280 | int ps_set_allphone(ps_decoder_t *ps, const char *name, ngram_model_t *lm); 281 | 282 | /** 283 | * Adds new search based on phone N-gram language model. 284 | * 285 | * Convenient method to load N-gram model and create a search. 286 | * 287 | * @see ps_set_allphone 288 | */ 289 | POCKETSPHINX_EXPORT 290 | int ps_set_allphone_file(ps_decoder_t *ps, const char *name, const char *path); 291 | 292 | #ifdef __cplusplus 293 | } 294 | #endif 295 | 296 | #endif /* __PS_SEARCH_H__ */ 297 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/ad.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2014 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /** \file ad.h 38 | * \brief generic live audio interface for recording and playback 39 | */ 40 | 41 | #ifndef _AD_H_ 42 | #define _AD_H_ 43 | 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | #if 0 53 | /* Fool Emacs. */ 54 | } 55 | #endif 56 | 57 | #define DEFAULT_SAMPLES_PER_SEC 16000 58 | 59 | /* Return codes */ 60 | #define AD_OK 0 61 | #define AD_EOF -1 62 | #define AD_ERR_GEN -1 63 | #define AD_ERR_NOT_OPEN -2 64 | #define AD_ERR_WAVE -3 65 | 66 | typedef struct ad_rec_s ad_rec_t; 67 | 68 | /** 69 | * Open a specific audio device for recording. 70 | * 71 | * The device is opened in non-blocking mode and placed in idle state. 72 | * 73 | * @return pointer to read-only ad_rec_t structure if successful, NULL 74 | * otherwise. The return value to be used as the first argument to 75 | * other recording functions. 76 | */ 77 | SPHINXBASE_EXPORT 78 | ad_rec_t *ad_open_dev ( 79 | const char *dev, /**< Device name (platform-specific) */ 80 | int32 samples_per_sec /**< Samples per second */ 81 | ); 82 | 83 | /** 84 | * Open the default audio device with a given sampling rate. 85 | */ 86 | SPHINXBASE_EXPORT 87 | ad_rec_t *ad_open_sps ( 88 | int32 samples_per_sec /**< Samples per second */ 89 | ); 90 | 91 | 92 | /** 93 | * Open the default audio device. 94 | */ 95 | SPHINXBASE_EXPORT 96 | ad_rec_t *ad_open ( void ); 97 | 98 | 99 | /* Start audio recording. Return value: 0 if successful, <0 otherwise */ 100 | SPHINXBASE_EXPORT 101 | int32 ad_start_rec (ad_rec_t *); 102 | 103 | 104 | /* Stop audio recording. Return value: 0 if successful, <0 otherwise */ 105 | SPHINXBASE_EXPORT 106 | int32 ad_stop_rec (ad_rec_t *); 107 | 108 | 109 | /* Close the recording device. Return value: 0 if successful, <0 otherwise */ 110 | SPHINXBASE_EXPORT 111 | int32 ad_close (ad_rec_t *); 112 | 113 | /* 114 | * Read next block of audio samples while recording; read upto max samples into buf. 115 | * Return value: # samples actually read (could be 0 since non-blocking); -1 if not 116 | * recording and no more samples remaining to be read from most recent recording. 117 | */ 118 | SPHINXBASE_EXPORT 119 | int32 ad_read (ad_rec_t *, int16 *buf, int32 max); 120 | 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/agc.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * agc.h -- Various forms of automatic gain control (AGC) 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log$ 49 | * Revision 1.1 2006/04/05 20:27:30 dhdfu 50 | * A Great Reorganzation of header files and executables 51 | * 52 | * Revision 1.8 2005/06/21 19:25:41 arthchan2003 53 | * 1, Fixed doxygen documentation. 2, Added $ keyword. 54 | * 55 | * Revision 1.4 2005/06/13 04:02:56 archan 56 | * Fixed most doxygen-style documentation under libs3decoder. 57 | * 58 | * Revision 1.3 2005/03/30 01:22:46 archan 59 | * Fixed mistakes in last updates. Add 60 | * 61 | * 62 | * 28-Apr-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 63 | * Copied from previous version. 64 | */ 65 | 66 | 67 | #ifndef _S3_AGC_H_ 68 | #define _S3_AGC_H_ 69 | 70 | /* Win32/WinCE DLL gunk */ 71 | #include 72 | 73 | #include 74 | #include 75 | 76 | /** \file agc.h 77 | * \brief routine that implements automatic gain control 78 | * 79 | * \warning This function may not be fully compatible with 80 | * SphinxTrain's family of AGC. 81 | * 82 | * This implements AGC. 83 | */ 84 | #ifdef __cplusplus 85 | extern "C" { 86 | #endif 87 | #if 0 88 | /* Fool Emacs. */ 89 | } 90 | #endif 91 | 92 | /** 93 | * Types of acoustic gain control to apply to the features. 94 | */ 95 | typedef enum agc_type_e { 96 | AGC_NONE = 0, 97 | AGC_MAX, 98 | AGC_EMAX, 99 | AGC_NOISE 100 | } agc_type_t; 101 | 102 | /** Convert string representation (from command-line) to agc_type_t */ 103 | SPHINXBASE_EXPORT 104 | agc_type_t agc_type_from_str(const char *str); 105 | 106 | /** String representations of agc_type_t values. */ 107 | SPHINXBASE_EXPORT 108 | extern const char *agc_type_str[]; 109 | 110 | /** 111 | * Structure holding data for doing AGC. 112 | **/ 113 | typedef struct agc_s { 114 | mfcc_t max; /**< Estimated max for current utterance (for AGC_EMAX) */ 115 | mfcc_t obs_max; /**< Observed max in current utterance */ 116 | int32 obs_frame; /**< Whether any data was observed after prev update */ 117 | int32 obs_utt; /**< Whether any utterances have been observed */ 118 | mfcc_t obs_max_sum; 119 | mfcc_t noise_thresh; /**< Noise threshold (for AGC_NOISE only) */ 120 | } agc_t; 121 | 122 | /** 123 | * Initialize AGC structure with default values. 124 | */ 125 | SPHINXBASE_EXPORT 126 | agc_t *agc_init(void); 127 | 128 | /** 129 | * Free AGC structure. 130 | */ 131 | SPHINXBASE_EXPORT 132 | void agc_free(agc_t *agc); 133 | 134 | /** 135 | * Apply AGC to the given mfc vectors (normalize all C0 mfc coefficients in the given 136 | * input such that the max C0 value is 0, by subtracting the input max C0 from all). 137 | * This function operates on an entire utterance at a time. Hence, the entire utterance 138 | * must be available beforehand (batchmode). 139 | */ 140 | SPHINXBASE_EXPORT 141 | void agc_max(agc_t *agc, /**< In: AGC structure (not used) */ 142 | mfcc_t **mfc, /**< In/Out: mfc[f] = cepstrum vector in frame f */ 143 | int32 n_frame /**< In: number of frames of cepstrum vectors supplied */ 144 | ); 145 | 146 | /** 147 | * Apply AGC to the given block of MFC vectors. 148 | * Unlike agc_max() this does not require the entire utterance to be 149 | * available. Call agc_emax_update() at the end of each utterance to 150 | * update the AGC parameters. */ 151 | SPHINXBASE_EXPORT 152 | void agc_emax(agc_t *agc, /**< In: AGC structure */ 153 | mfcc_t **mfc, /**< In/Out: mfc[f] = cepstrum vector in frame f */ 154 | int32 n_frame /**< In: number of frames of cepstrum vectors supplied */ 155 | ); 156 | 157 | /** 158 | * Update AGC parameters for next utterance. 159 | **/ 160 | SPHINXBASE_EXPORT 161 | void agc_emax_update(agc_t *agc /**< In: AGC structure */ 162 | ); 163 | 164 | /** 165 | * Get the current AGC maximum estimate. 166 | **/ 167 | SPHINXBASE_EXPORT 168 | float32 agc_emax_get(agc_t *agc); 169 | 170 | /** 171 | * Set the current AGC maximum estimate. 172 | **/ 173 | SPHINXBASE_EXPORT 174 | void agc_emax_set(agc_t *agc, float32 m); 175 | 176 | /** 177 | * Apply AGC using noise threshold to the given block of MFC vectors. 178 | **/ 179 | SPHINXBASE_EXPORT 180 | void agc_noise(agc_t *agc, /**< In: AGC structure */ 181 | mfcc_t **mfc, /**< In/Out: mfc[f] = cepstrum vector in frame f */ 182 | int32 n_frame /**< In: number of frames of cepstrum vectors supplied */ 183 | ); 184 | 185 | /** 186 | * Get the current AGC noise threshold. 187 | **/ 188 | SPHINXBASE_EXPORT 189 | float32 agc_get_threshold(agc_t *agc); 190 | 191 | /** 192 | * Set the current AGC noise threshold. 193 | **/ 194 | SPHINXBASE_EXPORT 195 | void agc_set_threshold(agc_t *agc, float32 threshold); 196 | 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif 203 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/bitvec.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | #ifndef _LIBUTIL_BITVEC_H_ 39 | #define _LIBUTIL_BITVEC_H_ 40 | 41 | #include 42 | 43 | /* Win32/WinCE DLL gunk */ 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | /** 50 | * @file bitvec.h 51 | * @brief An implementation of bit vectors. 52 | * 53 | * Implementation of basic operations of bit vectors. 54 | */ 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | #if 0 60 | /* Fool Emacs. */ 61 | } 62 | #endif 63 | 64 | #define BITVEC_BITS 32 65 | typedef uint32 bitvec_t; 66 | 67 | /** 68 | * Number of bitvec_t in a bit vector 69 | */ 70 | #define bitvec_size(n) (((n)+BITVEC_BITS-1)/BITVEC_BITS) 71 | 72 | /** 73 | * Allocate a bit vector, all bits are clear 74 | */ 75 | #define bitvec_alloc(n) ckd_calloc(bitvec_size(n), sizeof(bitvec_t)) 76 | 77 | /** 78 | * Resize a bit vector, clear the remaining bits 79 | */ 80 | SPHINXBASE_EXPORT 81 | bitvec_t *bitvec_realloc(bitvec_t *vec, /* In: Bit vector to search */ 82 | size_t old_len, /* In: Old length */ 83 | size_t new_len); /* In: New lenght of above bit vector */ 84 | /** 85 | * Free a bit vector. 86 | */ 87 | #define bitvec_free(v) ckd_free(v) 88 | 89 | /** 90 | * Set the b-th bit of bit vector v 91 | * @param v is a vector 92 | * @param b is the bit which will be set 93 | */ 94 | 95 | #define bitvec_set(v,b) (v[(b)/BITVEC_BITS] |= (1UL << ((b) & (BITVEC_BITS-1)))) 96 | 97 | /** 98 | * Set all n bits in bit vector v 99 | * @param v is a vector 100 | * @param n is the number of bits 101 | */ 102 | 103 | #define bitvec_set_all(v,n) memset(v, (bitvec_t)-1, \ 104 | (((n)+BITVEC_BITS-1)/BITVEC_BITS) * \ 105 | sizeof(bitvec_t)) 106 | /** 107 | * Clear the b-th bit of bit vector v 108 | * @param v is a vector 109 | * @param b is the bit which will be set 110 | */ 111 | 112 | #define bitvec_clear(v,b) (v[(b)/BITVEC_BITS] &= ~(1UL << ((b) & (BITVEC_BITS-1)))) 113 | 114 | /** 115 | * Clear all n bits in bit vector v 116 | * @param v is a vector 117 | * @param n is the number of bits 118 | */ 119 | 120 | #define bitvec_clear_all(v,n) memset(v, 0, (((n)+BITVEC_BITS-1)/BITVEC_BITS) * \ 121 | sizeof(bitvec_t)) 122 | 123 | /** 124 | * Check whether the b-th bit is set in vector v 125 | * @param v is a vector 126 | * @param b is the bit which will be checked 127 | */ 128 | 129 | #define bitvec_is_set(v,b) (v[(b)/BITVEC_BITS] & (1UL << ((b) & (BITVEC_BITS-1)))) 130 | 131 | /** 132 | * Check whether the b-th bit is cleared in vector v 133 | * @param v is a vector 134 | * @param b is the bit which will be checked 135 | */ 136 | 137 | #define bitvec_is_clear(v,b) (! (bitvec_is_set(v,b))) 138 | 139 | 140 | /** 141 | * Return the number of bits set in the given bitvector. 142 | * 143 | * @param vec is the bit vector 144 | * @param len is the length of bit vector vec 145 | * @return the number of bits being set in vector vec 146 | */ 147 | SPHINXBASE_EXPORT 148 | size_t bitvec_count_set(bitvec_t *vec, /* In: Bit vector to search */ 149 | size_t len); /* In: Lenght of above bit vector */ 150 | 151 | #ifdef __cplusplus 152 | } 153 | #endif 154 | 155 | #endif 156 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/byteorder.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2001 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | /* 39 | * byteorder.h -- Byte swapping ordering macros. 40 | * 41 | * ********************************************** 42 | * CMU ARPA Speech Project 43 | * 44 | * Copyright (c) 1996 Carnegie Mellon University. 45 | * ALL RIGHTS RESERVED. 46 | * ********************************************** 47 | * 48 | * HISTORY 49 | * 50 | * $Log: byteorder.h,v $ 51 | * Revision 1.8 2005/09/01 21:09:54 dhdfu 52 | * Really, actually, truly consolidate byteswapping operations into 53 | * byteorder.h. Where unconditional byteswapping is needed, SWAP_INT32() 54 | * and SWAP_INT16() are to be used. The WORDS_BIGENDIAN macro from 55 | * autoconf controls the functioning of the conditional swap macros 56 | * (SWAP_?[LW]) whose names and semantics have been regularized. 57 | * Private, adhoc macros have been removed. 58 | * 59 | */ 60 | 61 | #ifndef __S2_BYTEORDER_H__ 62 | #define __S2_BYTEORDER_H__ 1 63 | 64 | /* Macro to byteswap an int16 variable. x = ptr to variable */ 65 | #define SWAP_INT16(x) *(x) = ((0x00ff & (*(x))>>8) | (0xff00 & (*(x))<<8)) 66 | 67 | /* Macro to byteswap an int32 variable. x = ptr to variable */ 68 | #define SWAP_INT32(x) *(x) = ((0x000000ff & (*(x))>>24) | \ 69 | (0x0000ff00 & (*(x))>>8) | \ 70 | (0x00ff0000 & (*(x))<<8) | \ 71 | (0xff000000 & (*(x))<<24)) 72 | 73 | /* Macro to byteswap a float32 variable. x = ptr to variable */ 74 | #define SWAP_FLOAT32(x) SWAP_INT32((int32 *) x) 75 | 76 | /* Macro to byteswap a float64 variable. x = ptr to variable */ 77 | #define SWAP_FLOAT64(x) { int *low = (int *) (x), *high = (int *) (x) + 1,\ 78 | temp;\ 79 | SWAP_INT32(low); SWAP_INT32(high);\ 80 | temp = *low; *low = *high; *high = temp;} 81 | 82 | #ifdef WORDS_BIGENDIAN 83 | #define SWAP_BE_64(x) 84 | #define SWAP_BE_32(x) 85 | #define SWAP_BE_16(x) 86 | #define SWAP_LE_64(x) SWAP_FLOAT64(x) 87 | #define SWAP_LE_32(x) SWAP_INT32(x) 88 | #define SWAP_LE_16(x) SWAP_INT16(x) 89 | #else 90 | #define SWAP_LE_64(x) 91 | #define SWAP_LE_32(x) 92 | #define SWAP_LE_16(x) 93 | #define SWAP_BE_64(x) SWAP_FLOAT64(x) 94 | #define SWAP_BE_32(x) SWAP_INT32(x) 95 | #define SWAP_BE_16(x) SWAP_INT16(x) 96 | #endif 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/case.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * case.h -- Upper/lower case conversion routines 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: case.h,v $ 49 | * Revision 1.7 2005/06/22 02:58:54 arthchan2003 50 | * Added keyword 51 | * 52 | * Revision 1.3 2005/03/30 01:22:48 archan 53 | * Fixed mistakes in last updates. Add 54 | * 55 | * 56 | * 18-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 57 | * Added strcmp_nocase, UPPER_CASE and LOWER_CASE definitions. 58 | * 59 | * 16-Feb-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 60 | * Created. 61 | */ 62 | 63 | 64 | /** 65 | * @file case.h 66 | * @brief Locale-independent implementation of case swapping operation. 67 | * 68 | * This function implements ASCII-only case switching and comparison 69 | * related operations, which do not depend on the locale and are 70 | * guaranteed to exist on all versions of Windows. 71 | */ 72 | 73 | #ifndef _LIBUTIL_CASE_H_ 74 | #define _LIBUTIL_CASE_H_ 75 | 76 | #include 77 | 78 | #include 79 | #include 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | #if 0 85 | /* Fool Emacs. */ 86 | } 87 | #endif 88 | 89 | /** 90 | * Return upper case form for c 91 | */ 92 | #define UPPER_CASE(c) ((((c) >= 'a') && ((c) <= 'z')) ? (c-32) : c) 93 | 94 | /** 95 | * Return lower case form for c 96 | */ 97 | #define LOWER_CASE(c) ((((c) >= 'A') && ((c) <= 'Z')) ? (c+32) : c) 98 | 99 | 100 | /** 101 | * Convert str to all upper case. 102 | * @param str is a string. 103 | */ 104 | SPHINXBASE_EXPORT 105 | void ucase(char *str); 106 | 107 | /** 108 | * Convert str to all lower case 109 | * @param str is a string. 110 | */ 111 | SPHINXBASE_EXPORT 112 | void lcase(char *str); 113 | 114 | /** 115 | * (FIXME! The implementation is incorrect!) 116 | * Case insensitive string compare. Return the usual -1, 0, +1, depending on 117 | * str1 <, =, > str2 (case insensitive, of course). 118 | * @param str1 is the first string. 119 | * @param str2 is the second string. 120 | */ 121 | SPHINXBASE_EXPORT 122 | int32 strcmp_nocase(const char *str1, const char *str2); 123 | 124 | /** 125 | * Like strcmp_nocase() but with a maximum length. 126 | */ 127 | SPHINXBASE_EXPORT 128 | int32 strncmp_nocase(const char *str1, const char *str2, size_t len); 129 | 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/ckd_alloc.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * ckd_alloc.h -- Memory allocation package. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: ckd_alloc.h,v $ 49 | * Revision 1.10 2005/06/22 02:59:25 arthchan2003 50 | * Added keyword 51 | * 52 | * Revision 1.3 2005/03/30 01:22:48 archan 53 | * Fixed mistakes in last updates. Add 54 | * 55 | * 56 | * 19-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 57 | * Removed file,line arguments from free functions. 58 | * 59 | * 01-Jan-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 60 | * Created. 61 | */ 62 | 63 | 64 | /********************************************************************* 65 | * 66 | * $Header: /cvsroot/cmusphinx/sphinx3/src/libutil/ckd_alloc.h,v 1.10 2005/06/22 02:59:25 arthchan2003 Exp $ 67 | * 68 | * Carnegie Mellon ARPA Speech Group 69 | * 70 | * Copyright (c) 1994 Carnegie Mellon University. 71 | * All rights reserved. 72 | * 73 | ********************************************************************* 74 | * 75 | * file: ckd_alloc.h 76 | * 77 | * traceability: 78 | * 79 | * description: 80 | * 81 | * author: 82 | * 83 | *********************************************************************/ 84 | 85 | 86 | #ifndef _LIBUTIL_CKD_ALLOC_H_ 87 | #define _LIBUTIL_CKD_ALLOC_H_ 88 | 89 | #include 90 | #include 91 | 92 | /* Win32/WinCE DLL gunk */ 93 | #include 94 | #include 95 | 96 | /** \file ckd_alloc.h 97 | *\brief Sphinx's memory allocation/deallocation routines. 98 | * 99 | *Implementation of efficient memory allocation deallocation for 100 | *multiple dimensional arrays. 101 | * 102 | */ 103 | 104 | #ifdef __cplusplus 105 | extern "C" { 106 | #endif 107 | #if 0 108 | /* Fool Emacs. */ 109 | } 110 | #endif 111 | 112 | /** 113 | * Control behaviour of the program when allocation fails. 114 | * 115 | * Although your program is probably toast when memory allocation 116 | * fails, it is also probably a good idea to be able to catch these 117 | * errors and alert the user in some way. Either that, or you might 118 | * want the program to call abort() so that you can debug the failed 119 | * code. This function allows you to control that behaviour. 120 | * 121 | * @param env Pointer to a jmp_buf initialized with 122 | * setjmp(), or NULL to remove a previously set jump target. 123 | * @param abort If non-zero, the program will call abort() when 124 | * allocation fails rather than exiting or calling longjmp(). 125 | * @return Pointer to a previously set jmp_buf, if any. 126 | */ 127 | jmp_buf *ckd_set_jump(jmp_buf *env, int abort); 128 | 129 | /** 130 | * Fail (with a message) according to behaviour specified by ckd_set_jump(). 131 | */ 132 | void ckd_fail(char *format, ...); 133 | 134 | /* 135 | * The following functions are similar to the malloc family, except 136 | * that they have two additional parameters, caller_file and 137 | * caller_line, for error reporting. All functions print a diagnostic 138 | * message if any error occurs, with any other behaviour determined by 139 | * ckd_set_jump(), above. 140 | */ 141 | 142 | SPHINXBASE_EXPORT 143 | void *__ckd_calloc__(size_t n_elem, size_t elem_size, 144 | const char *caller_file, int caller_line); 145 | 146 | SPHINXBASE_EXPORT 147 | void *__ckd_malloc__(size_t size, 148 | const char *caller_file, int caller_line); 149 | 150 | SPHINXBASE_EXPORT 151 | void *__ckd_realloc__(void *ptr, size_t new_size, 152 | const char *caller_file, int caller_line); 153 | 154 | /** 155 | * Like strdup, except that if an error occurs it prints a diagnostic message and 156 | * exits. If origin in NULL the function also returns NULL. 157 | */ 158 | SPHINXBASE_EXPORT 159 | char *__ckd_salloc__(const char *origstr, 160 | const char *caller_file, int caller_line); 161 | 162 | /** 163 | * Allocate a 2-D array and return ptr to it (ie, ptr to vector of ptrs). 164 | * The data area is allocated in one block so it can also be treated as a 1-D array. 165 | */ 166 | SPHINXBASE_EXPORT 167 | void *__ckd_calloc_2d__(size_t d1, size_t d2, /* In: #elements in the 2 dimensions */ 168 | size_t elemsize, /* In: Size (#bytes) of each element */ 169 | const char *caller_file, int caller_line); /* In */ 170 | 171 | /** 172 | * Allocate a 3-D array and return ptr to it. 173 | * The data area is allocated in one block so it can also be treated as a 1-D array. 174 | */ 175 | SPHINXBASE_EXPORT 176 | void *__ckd_calloc_3d__(size_t d1, size_t d2, size_t d3, /* In: #elems in the dims */ 177 | size_t elemsize, /* In: Size (#bytes) per element */ 178 | const char *caller_file, int caller_line); /* In */ 179 | 180 | /** 181 | * Allocate a 34D array and return ptr to it. 182 | * The data area is allocated in one block so it can also be treated as a 1-D array. 183 | */ 184 | SPHINXBASE_EXPORT 185 | void ****__ckd_calloc_4d__(size_t d1, 186 | size_t d2, 187 | size_t d3, 188 | size_t d4, 189 | size_t elem_size, 190 | char *caller_file, 191 | int caller_line); 192 | 193 | /** 194 | * Overlay a 3-D array over a previously allocated storage area. 195 | **/ 196 | SPHINXBASE_EXPORT 197 | void * __ckd_alloc_3d_ptr(size_t d1, 198 | size_t d2, 199 | size_t d3, 200 | void *store, 201 | size_t elem_size, 202 | char *caller_file, 203 | int caller_line); 204 | 205 | /** 206 | * Overlay a s-D array over a previously allocated storage area. 207 | **/ 208 | SPHINXBASE_EXPORT 209 | void *__ckd_alloc_2d_ptr(size_t d1, 210 | size_t d2, 211 | void *store, 212 | size_t elem_size, 213 | char *caller_file, 214 | int caller_line); 215 | 216 | /** 217 | * Test and free a 1-D array 218 | */ 219 | SPHINXBASE_EXPORT 220 | void ckd_free(void *ptr); 221 | 222 | /** 223 | * Free a 2-D array (ptr) previously allocated by ckd_calloc_2d 224 | */ 225 | SPHINXBASE_EXPORT 226 | void ckd_free_2d(void *ptr); 227 | 228 | /** 229 | * Free a 3-D array (ptr) previously allocated by ckd_calloc_3d 230 | */ 231 | SPHINXBASE_EXPORT 232 | void ckd_free_3d(void *ptr); 233 | 234 | /** 235 | * Free a 4-D array (ptr) previously allocated by ckd_calloc_4d 236 | */ 237 | SPHINXBASE_EXPORT 238 | void ckd_free_4d(void *ptr); 239 | 240 | /** 241 | * Macros to simplify the use of above functions. 242 | * One should use these, rather than target functions directly. 243 | */ 244 | 245 | /** 246 | * Macro for __ckd_calloc__ 247 | */ 248 | #define ckd_calloc(n,sz) __ckd_calloc__((n),(sz),__FILE__,__LINE__) 249 | 250 | /** 251 | * Macro for __ckd_malloc__ 252 | */ 253 | #define ckd_malloc(sz) __ckd_malloc__((sz),__FILE__,__LINE__) 254 | 255 | /** 256 | * Macro for __ckd_realloc__ 257 | */ 258 | #define ckd_realloc(ptr,sz) __ckd_realloc__(ptr,(sz),__FILE__,__LINE__) 259 | 260 | /** 261 | * Macro for __ckd_salloc__ 262 | */ 263 | 264 | #define ckd_salloc(ptr) __ckd_salloc__(ptr,__FILE__,__LINE__) 265 | 266 | /** 267 | * Macro for __ckd_calloc_2d__ 268 | */ 269 | 270 | #define ckd_calloc_2d(d1,d2,sz) __ckd_calloc_2d__((d1),(d2),(sz),__FILE__,__LINE__) 271 | 272 | /** 273 | * Macro for __ckd_calloc_3d__ 274 | */ 275 | 276 | #define ckd_calloc_3d(d1,d2,d3,sz) __ckd_calloc_3d__((d1),(d2),(d3),(sz),__FILE__,__LINE__) 277 | 278 | /** 279 | * Macro for __ckd_calloc_4d__ 280 | */ 281 | #define ckd_calloc_4d(d1, d2, d3, d4, s) __ckd_calloc_4d__((d1), (d2), (d3), (d4), (s), __FILE__, __LINE__) 282 | 283 | /** 284 | * Macro for __ckd_alloc_2d_ptr__ 285 | */ 286 | 287 | #define ckd_alloc_2d_ptr(d1, d2, bf, sz) __ckd_alloc_2d_ptr((d1), (d2), (bf), (sz), __FILE__, __LINE__) 288 | 289 | /** 290 | * Free only the pointer arrays allocated with ckd_alloc_2d_ptr(). 291 | */ 292 | #define ckd_free_2d_ptr(bf) ckd_free(bf) 293 | 294 | /** 295 | * Macro for __ckd_alloc_3d_ptr__ 296 | */ 297 | 298 | #define ckd_alloc_3d_ptr(d1, d2, d3, bf, sz) __ckd_alloc_3d_ptr((d1), (d2), (d3), (bf), (sz), __FILE__, __LINE__) 299 | 300 | /** 301 | * Free only the pointer arrays allocated with ckd_alloc_3d_ptr(). 302 | */ 303 | #define ckd_free_3d_ptr(bf) ckd_free_2d(bf) 304 | 305 | 306 | #ifdef __cplusplus 307 | } 308 | #endif 309 | 310 | #endif 311 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/clapack_lite.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef __CLAPACK_LITE_H 3 | #define __CLAPACK_LITE_H 4 | 5 | #include "f2c.h" 6 | 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | #if 0 12 | /* Fool Emacs. */ 13 | } 14 | #endif 15 | 16 | /* Subroutine */ int sgemm_(char *transa, char *transb, integer *m, integer * 17 | n, integer *k, real *alpha, real *a, integer *lda, real *b, integer * 18 | ldb, real *beta, real *c__, integer *ldc); 19 | /* Subroutine */ int sgemv_(char *trans, integer *m, integer *n, real *alpha, 20 | real *a, integer *lda, real *x, integer *incx, real *beta, real *y, 21 | integer *incy); 22 | /* Subroutine */ int ssymm_(char *side, char *uplo, integer *m, integer *n, 23 | real *alpha, real *a, integer *lda, real *b, integer *ldb, real *beta, 24 | real *c__, integer *ldc); 25 | 26 | /* Subroutine */ int sposv_(char *uplo, integer *n, integer *nrhs, real *a, 27 | integer *lda, real *b, integer *ldb, integer *info); 28 | /* Subroutine */ int spotrf_(char *uplo, integer *n, real *a, integer *lda, 29 | integer *info); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | 36 | #endif /* __CLAPACK_LITE_H */ 37 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/cmn.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * cmn.h -- Various forms of cepstral mean normalization 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log$ 49 | * Revision 1.1 2006/04/05 20:27:30 dhdfu 50 | * A Great Reorganzation of header files and executables 51 | * 52 | * Revision 1.13 2006/02/23 03:48:27 arthchan2003 53 | * Resolved conflict in cmn.h 54 | * 55 | * 56 | * Revision 1.12 2006/02/22 23:43:55 arthchan2003 57 | * Merged from the branch SPHINX3_5_2_RCI_IRII_BRANCH: Put data structure into the cmn_t structure. 58 | * 59 | * Revision 1.11.4.2 2005/10/17 04:45:57 arthchan2003 60 | * Free stuffs in cmn and feat corectly. 61 | * 62 | * Revision 1.11.4.1 2005/07/05 06:25:08 arthchan2003 63 | * Fixed dox-doc. 64 | * 65 | * Revision 1.11 2005/06/21 19:28:00 arthchan2003 66 | * 1, Fixed doxygen documentation. 2, Added $ keyword. 67 | * 68 | * Revision 1.4 2005/06/13 04:02:56 archan 69 | * Fixed most doxygen-style documentation under libs3decoder. 70 | * 71 | * Revision 1.3 2005/03/30 01:22:46 archan 72 | * Fixed mistakes in last updates. Add 73 | * 74 | * 75 | * 20.Apr.2001 RAH (rhoughton@mediasite.com, ricky.houghton@cs.cmu.edu) 76 | * Added cmn_free() and moved *mean and *var out global space and named them cmn_mean and cmn_var 77 | * 78 | * 28-Apr-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 79 | * Copied from previous version. 80 | */ 81 | 82 | 83 | #ifndef _S3_CMN_H_ 84 | #define _S3_CMN_H_ 85 | 86 | /* Win32/WinCE DLL gunk */ 87 | #include 88 | #include 89 | #include 90 | 91 | #ifdef __cplusplus 92 | extern "C" { 93 | #endif 94 | #if 0 95 | /* Fool Emacs. */ 96 | } 97 | #endif 98 | 99 | /** \file cmn.h 100 | * \brief Apply Cepstral Mean Normalization (CMN) to the set of input mfc frames. 101 | * 102 | * By subtractingthe mean of the input from each frame. C0 is also included in this process. 103 | * This function operates on an entire utterance at a time. Hence, the entire utterance 104 | * must be available beforehand (batchmode). 105 | */ 106 | 107 | /** 108 | * Types of cepstral mean normalization to apply to the features. 109 | */ 110 | typedef enum cmn_type_e { 111 | CMN_NONE = 0, 112 | CMN_CURRENT, 113 | CMN_PRIOR 114 | } cmn_type_t; 115 | 116 | /** String representations of cmn_type_t values. */ 117 | SPHINXBASE_EXPORT 118 | extern const char *cmn_type_str[]; 119 | 120 | /** Convert string representation (from command-line) to cmn_type_t */ 121 | SPHINXBASE_EXPORT 122 | cmn_type_t cmn_type_from_str(const char *str); 123 | 124 | /** \struct cmn_t 125 | * \brief wrapper of operation of the cepstral mean normalization. 126 | */ 127 | 128 | typedef struct { 129 | mfcc_t *cmn_mean; /**< Temporary variable: current means */ 130 | mfcc_t *cmn_var; /**< Temporary variables: stored the cmn variance */ 131 | mfcc_t *sum; /**< The sum of the cmn frames */ 132 | int32 nframe; /**< Number of frames */ 133 | int32 veclen; /**< Length of cepstral vector */ 134 | } cmn_t; 135 | 136 | SPHINXBASE_EXPORT 137 | cmn_t* cmn_init(int32 veclen); 138 | 139 | /** 140 | * CMN for the whole sentence 141 | */ 142 | SPHINXBASE_EXPORT 143 | void cmn (cmn_t *cmn, /**< In/Out: cmn normalization, which contains the cmn_mean and cmn_var) */ 144 | mfcc_t **mfc, /**< In/Out: mfc[f] = mfc vector in frame f */ 145 | int32 varnorm,/**< In: if not FALSE, variance normalize the input vectors 146 | to have unit variance (along each dimension independently); 147 | Irrelevant if no cmn is performed */ 148 | int32 n_frame /**< In: Number of frames of mfc vectors */ 149 | ); 150 | 151 | #define CMN_WIN_HWM 800 /* #frames after which window shifted */ 152 | #define CMN_WIN 500 153 | 154 | /** 155 | * CMN for one block of data, using prior mean 156 | */ 157 | SPHINXBASE_EXPORT 158 | void cmn_prior(cmn_t *cmn, /**< In/Out: cmn normalization, which contains 159 | the cmn_mean and cmn_var) */ 160 | mfcc_t **incep, /**< In/Out: mfc[f] = mfc vector in frame f*/ 161 | int32 varnorm, /**< This flag should always be 0 for live */ 162 | int32 nfr /**< Number of incoming frames */ 163 | ); 164 | 165 | /** 166 | * Update prior mean based on observed data 167 | */ 168 | SPHINXBASE_EXPORT 169 | void cmn_prior_update(cmn_t *cmn); 170 | 171 | /** 172 | * Set the prior mean. 173 | */ 174 | SPHINXBASE_EXPORT 175 | void cmn_prior_set(cmn_t *cmn, mfcc_t const *vec); 176 | 177 | /** 178 | * Get the prior mean. 179 | */ 180 | SPHINXBASE_EXPORT 181 | void cmn_prior_get(cmn_t *cmn, mfcc_t *vec); 182 | 183 | /* RAH, free previously allocated memory */ 184 | SPHINXBASE_EXPORT 185 | void cmn_free (cmn_t *cmn); 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/err.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | #ifndef _LIBUTIL_ERR_H_ 39 | #define _LIBUTIL_ERR_H_ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | /* Win32/WinCE DLL gunk */ 47 | #include 48 | 49 | /** 50 | * @file err.h 51 | * @brief Implementation of logging routines. 52 | * 53 | * Logging, warning, debug and error message output funtionality is provided in this file. 54 | * Sphinxbase defines several level of logging messages - INFO, WARNING, ERROR, FATAL. By 55 | * default output goes to standard error output. 56 | * 57 | * Logging is implemented through macros. They take same arguments as printf: format string and 58 | * values. By default source file name and source line are prepended to the message. Log output 59 | * could be redirected to any file using err_set_logfp() and err_set_logfile() functions. To disable 60 | * logging in your application, call err_set_logfp(NULL). 61 | * 62 | * It's possible to log multiline info messages, to do that you need to start message with 63 | * E_INFO and output other lines with E_INFOCONT. 64 | */ 65 | 66 | #ifdef __cplusplus 67 | extern "C" { 68 | #endif 69 | #if 0 70 | /* Fool Emacs. */ 71 | } 72 | #endif 73 | 74 | #define E_SYSCALL(stmt, ...) if (stmt) E_FATAL_SYSTEM(__VA_ARGS__); 75 | 76 | #define FILELINE __FILE__ , __LINE__ 77 | 78 | /** 79 | * Exit with non-zero status after error message 80 | */ 81 | #define E_FATAL(...) \ 82 | do { \ 83 | err_msg(ERR_FATAL, FILELINE, __VA_ARGS__); \ 84 | exit(EXIT_FAILURE); \ 85 | } while (0) 86 | 87 | /** 88 | * Print error text; Call perror(""); exit(errno); 89 | */ 90 | #define E_FATAL_SYSTEM(...) \ 91 | do { \ 92 | err_msg_system(ERR_FATAL, FILELINE, __VA_ARGS__); \ 93 | exit(EXIT_FAILURE); \ 94 | } while (0) 95 | 96 | /** 97 | * Print error text; Call perror(""); 98 | */ 99 | #define E_ERROR_SYSTEM(...) err_msg_system(ERR_ERROR, FILELINE, __VA_ARGS__) 100 | 101 | /** 102 | * Print error message to error log 103 | */ 104 | #define E_ERROR(...) err_msg(ERR_ERROR, FILELINE, __VA_ARGS__) 105 | 106 | /** 107 | * Print warning message to error log 108 | */ 109 | #define E_WARN(...) err_msg(ERR_WARN, FILELINE, __VA_ARGS__) 110 | 111 | /** 112 | * Print logging information to standard error stream 113 | */ 114 | #define E_INFO(...) err_msg(ERR_INFO, FILELINE, __VA_ARGS__) 115 | 116 | /** 117 | * Continue printing the information to standard error stream 118 | */ 119 | #define E_INFOCONT(...) err_msg(ERR_INFOCONT, NULL, 0, __VA_ARGS__) 120 | 121 | /** 122 | * Print logging information without filename. 123 | */ 124 | #define E_INFO_NOFN(...) err_msg(ERR_INFO, NULL, 0, __VA_ARGS__) 125 | 126 | /** 127 | * Print debugging information to standard error stream. 128 | * 129 | * This will only print a message if: 130 | * 1. Debugging is enabled at compile time 131 | * 2. The debug level is greater than or equal to \a level 132 | * 133 | * Note that for portability reasons the format and arguments must be 134 | * enclosed in an extra set of parentheses. 135 | */ 136 | #ifdef SPHINX_DEBUG 137 | #define E_DEBUG(level, ...) \ 138 | if (err_get_debug_level() >= level) \ 139 | err_msg(ERR_DEBUG, FILELINE, __VA_ARGS__) 140 | #define E_DEBUGCONT(level, ...) \ 141 | if (err_get_debug_level() >= level) \ 142 | err_msg(ERR_DEBUG, NULL, 0, __VA_ARGS__) 143 | #else 144 | #define E_DEBUG(level,x) 145 | #define E_DEBUGCONT(level,x) 146 | #endif 147 | 148 | typedef enum err_e { 149 | ERR_DEBUG, 150 | ERR_INFO, 151 | ERR_INFOCONT, 152 | ERR_WARN, 153 | ERR_ERROR, 154 | ERR_FATAL, 155 | ERR_MAX 156 | } err_lvl_t; 157 | 158 | SPHINXBASE_EXPORT void 159 | err_msg(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...); 160 | 161 | SPHINXBASE_EXPORT void 162 | err_msg_system(err_lvl_t lvl, const char *path, long ln, const char *fmt, ...); 163 | 164 | SPHINXBASE_EXPORT void 165 | err_logfp_cb(void * user_data, err_lvl_t level, const char *fmt, ...); 166 | 167 | typedef void (*err_cb_f)(void* user_data, err_lvl_t, const char *, ...); 168 | 169 | /** 170 | * Sets function to output error messages. Use it to redirect the logging 171 | * to your application. By default the handler which dumps messages to 172 | * stderr is set. 173 | * 174 | * @param - callback to pass messages too. 175 | */ 176 | SPHINXBASE_EXPORT void 177 | err_set_callback(err_cb_f callback, void *user_data); 178 | 179 | /** 180 | * Direct all logging to a given filehandle if default logfp callback is set. 181 | * 182 | * @param logfp Filehandle to send log messages to, or NULL to disable logging. 183 | */ 184 | SPHINXBASE_EXPORT void 185 | err_set_logfp(FILE *stream); 186 | 187 | /** 188 | * Get the current logging filehandle. 189 | * 190 | * @return Current logging filehandle, NULL if logging is disabled. Initially 191 | * it returns stderr 192 | */ 193 | SPHINXBASE_EXPORT FILE * 194 | err_get_logfp(void); 195 | 196 | /** 197 | * Append all log messages to a given file. 198 | * 199 | * Previous logging filehandle is closed (unless it was stdout or stderr). 200 | * 201 | * @param file File path to send log messages to 202 | * @return 0 for success, <0 for failure (e.g. if file does not exist) 203 | */ 204 | SPHINXBASE_EXPORT int 205 | err_set_logfile(const char *path); 206 | 207 | /** 208 | * Set debugging verbosity level. 209 | * 210 | * Note that debugging messages are only enabled when compiled with -DDEBUG. 211 | * 212 | * @param level Verbosity level to set, or 0 to disable debug messages. 213 | */ 214 | SPHINXBASE_EXPORT 215 | int err_set_debug_level(int level); 216 | 217 | /** 218 | * Get debugging verbosity level. 219 | * 220 | * Note that debugging messages are only enabled when compiled with -DDEBUG. 221 | */ 222 | SPHINXBASE_EXPORT 223 | int err_get_debug_level(void); 224 | 225 | #ifdef __cplusplus 226 | } 227 | #endif 228 | 229 | #endif /* !_ERR_H */ 230 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/f2c.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* f2c.h -- Standard Fortran to C header file */ 3 | 4 | /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." 5 | 6 | - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ 7 | 8 | #ifndef F2C_INCLUDE 9 | #define F2C_INCLUDE 10 | 11 | typedef int integer; 12 | typedef char *address; 13 | typedef short int shortint; 14 | typedef float real; 15 | typedef double doublereal; 16 | typedef struct { real r, i; } complex; 17 | typedef struct { doublereal r, i; } doublecomplex; 18 | typedef int logical; 19 | typedef short int shortlogical; 20 | typedef char logical1; 21 | typedef char integer1; 22 | 23 | #define TRUE_ (1) 24 | #define FALSE_ (0) 25 | 26 | /* Extern is for use with -E */ 27 | #ifndef Extern 28 | #define Extern extern 29 | #endif 30 | 31 | /* I/O stuff */ 32 | 33 | #ifdef f2c_i2 34 | /* for -i2 */ 35 | typedef short flag; 36 | typedef short ftnlen; 37 | typedef short ftnint; 38 | #else 39 | typedef int flag; 40 | typedef int ftnlen; 41 | typedef int ftnint; 42 | #endif 43 | 44 | /*external read, write*/ 45 | typedef struct 46 | { flag cierr; 47 | ftnint ciunit; 48 | flag ciend; 49 | char *cifmt; 50 | ftnint cirec; 51 | } cilist; 52 | 53 | /*internal read, write*/ 54 | typedef struct 55 | { flag icierr; 56 | char *iciunit; 57 | flag iciend; 58 | char *icifmt; 59 | ftnint icirlen; 60 | ftnint icirnum; 61 | } icilist; 62 | 63 | /*open*/ 64 | typedef struct 65 | { flag oerr; 66 | ftnint ounit; 67 | char *ofnm; 68 | ftnlen ofnmlen; 69 | char *osta; 70 | char *oacc; 71 | char *ofm; 72 | ftnint orl; 73 | char *oblnk; 74 | } olist; 75 | 76 | /*close*/ 77 | typedef struct 78 | { flag cerr; 79 | ftnint cunit; 80 | char *csta; 81 | } cllist; 82 | 83 | /*rewind, backspace, endfile*/ 84 | typedef struct 85 | { flag aerr; 86 | ftnint aunit; 87 | } alist; 88 | 89 | /* inquire */ 90 | typedef struct 91 | { flag inerr; 92 | ftnint inunit; 93 | char *infile; 94 | ftnlen infilen; 95 | ftnint *inex; /*parameters in standard's order*/ 96 | ftnint *inopen; 97 | ftnint *innum; 98 | ftnint *innamed; 99 | char *inname; 100 | ftnlen innamlen; 101 | char *inacc; 102 | ftnlen inacclen; 103 | char *inseq; 104 | ftnlen inseqlen; 105 | char *indir; 106 | ftnlen indirlen; 107 | char *infmt; 108 | ftnlen infmtlen; 109 | char *inform; 110 | ftnint informlen; 111 | char *inunf; 112 | ftnlen inunflen; 113 | ftnint *inrecl; 114 | ftnint *innrec; 115 | char *inblank; 116 | ftnlen inblanklen; 117 | } inlist; 118 | 119 | #define VOID void 120 | 121 | union Multitype { /* for multiple entry points */ 122 | shortint h; 123 | integer i; 124 | real r; 125 | doublereal d; 126 | complex c; 127 | doublecomplex z; 128 | }; 129 | 130 | typedef union Multitype Multitype; 131 | 132 | typedef long Long; /* No longer used; formerly in Namelist */ 133 | 134 | struct Vardesc { /* for Namelist */ 135 | char *name; 136 | char *addr; 137 | ftnlen *dims; 138 | int type; 139 | }; 140 | typedef struct Vardesc Vardesc; 141 | 142 | struct Namelist { 143 | char *name; 144 | Vardesc **vars; 145 | int nvars; 146 | }; 147 | typedef struct Namelist Namelist; 148 | 149 | #ifndef abs 150 | #define abs(x) ((x) >= 0 ? (x) : -(x)) 151 | #endif 152 | #define dabs(x) (doublereal)abs(x) 153 | #ifndef min 154 | #define min(a,b) ((a) <= (b) ? (a) : (b)) 155 | #endif 156 | #ifndef max 157 | #define max(a,b) ((a) >= (b) ? (a) : (b)) 158 | #endif 159 | #define dmin(a,b) (doublereal)min(a,b) 160 | #define dmax(a,b) (doublereal)max(a,b) 161 | 162 | /* procedure parameter types for -A and -C++ */ 163 | 164 | #define F2C_proc_par_types 1 165 | #ifdef __cplusplus 166 | typedef int /* Unknown procedure type */ (*U_fp)(...); 167 | typedef shortint (*J_fp)(...); 168 | typedef integer (*I_fp)(...); 169 | typedef real (*R_fp)(...); 170 | typedef doublereal (*D_fp)(...), (*E_fp)(...); 171 | typedef /* Complex */ VOID (*C_fp)(...); 172 | typedef /* Double Complex */ VOID (*Z_fp)(...); 173 | typedef logical (*L_fp)(...); 174 | typedef shortlogical (*K_fp)(...); 175 | typedef /* Character */ VOID (*H_fp)(...); 176 | typedef /* Subroutine */ int (*S_fp)(...); 177 | #else 178 | typedef int /* Unknown procedure type */ (*U_fp)(void); 179 | typedef shortint (*J_fp)(void); 180 | typedef integer (*I_fp)(void); 181 | typedef real (*R_fp)(void); 182 | typedef doublereal (*D_fp)(void), (*E_fp)(void); 183 | typedef /* Complex */ VOID (*C_fp)(void); 184 | typedef /* Double Complex */ VOID (*Z_fp)(void); 185 | typedef logical (*L_fp)(void); 186 | typedef shortlogical (*K_fp)(void); 187 | typedef /* Character */ VOID (*H_fp)(void); 188 | typedef /* Subroutine */ int (*S_fp)(void); 189 | #endif 190 | /* E_fp is for real functions when -R is not specified */ 191 | typedef VOID C_f; /* complex function */ 192 | typedef VOID H_f; /* character function */ 193 | typedef VOID Z_f; /* double complex function */ 194 | typedef doublereal E_f; /* real function with -R not specified */ 195 | 196 | /* undef any lower-case symbols that your C compiler predefines, e.g.: */ 197 | 198 | #ifndef Skip_f2c_Undefs 199 | #undef cray 200 | #undef gcos 201 | #undef mc68010 202 | #undef mc68020 203 | #undef mips 204 | #undef pdp11 205 | #undef sgi 206 | #undef sparc 207 | #undef sun 208 | #undef sun2 209 | #undef sun3 210 | #undef sun4 211 | #undef u370 212 | #undef u3b 213 | #undef u3b2 214 | #undef u3b5 215 | #undef unix 216 | #undef vax 217 | #endif 218 | #endif 219 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/filename.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * filename.h -- File and path name operations. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: filename.h,v $ 49 | * Revision 1.7 2005/06/22 03:01:07 arthchan2003 50 | * Added keyword 51 | * 52 | * Revision 1.3 2005/03/30 01:22:48 archan 53 | * Fixed mistakes in last updates. Add 54 | * 55 | * 56 | * 30-Oct-1997 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University. 57 | * Started. 58 | */ 59 | 60 | 61 | #ifndef _LIBUTIL_FILENAME_H_ 62 | #define _LIBUTIL_FILENAME_H_ 63 | 64 | /* Win32/WinCE DLL gunk */ 65 | #include 66 | #include 67 | 68 | /**\file filename.h 69 | *\brief File names related operation 70 | */ 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | #if 0 75 | /* Fool Emacs. */ 76 | } 77 | #endif 78 | 79 | /** 80 | * Returns the last part of the path, without modifying anything in memory. 81 | */ 82 | SPHINXBASE_EXPORT 83 | const char *path2basename(const char *path); 84 | 85 | /** 86 | * Strip off filename from the given path and copy the directory name into dir 87 | * Caller must have allocated dir (hint: it's always shorter than path). 88 | */ 89 | SPHINXBASE_EXPORT 90 | void path2dirname(const char *path, char *dir); 91 | 92 | 93 | /** 94 | * Strip off the smallest trailing file-extension suffix and copy 95 | * the rest into the given root argument. Caller must have 96 | * allocated root. 97 | */ 98 | SPHINXBASE_EXPORT 99 | void strip_fileext(const char *file, char *root); 100 | 101 | /** 102 | * Test whether a pathname is absolute for the current OS. 103 | */ 104 | SPHINXBASE_EXPORT 105 | int path_is_absolute(const char *file); 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/fixpoint.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2005 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== */ 35 | 36 | /* Fixed-point arithmetic macros. 37 | * 38 | * Author: David Huggins-Daines 39 | */ 40 | 41 | #ifndef _FIXPOINT_H_ 42 | #define _FIXPOINT_H_ 43 | 44 | #include 45 | 46 | /* Win32/WinCE DLL gunk */ 47 | #include 48 | #include 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | #if 0 54 | /* Fool Emacs. */ 55 | } 56 | #endif 57 | 58 | #ifndef DEFAULT_RADIX 59 | #define DEFAULT_RADIX 12 60 | #endif 61 | 62 | /** Fixed-point computation type. */ 63 | typedef int32 fixed32; 64 | 65 | /** Convert floating point to fixed point. */ 66 | #define FLOAT2FIX_ANY(x,radix) \ 67 | (((x)<0.0) ? \ 68 | ((fixed32)((x)*(float32)(1<<(radix)) - 0.5)) \ 69 | : ((fixed32)((x)*(float32)(1<<(radix)) + 0.5))) 70 | #define FLOAT2FIX(x) FLOAT2FIX_ANY(x,DEFAULT_RADIX) 71 | /** Convert fixed point to floating point. */ 72 | #define FIX2FLOAT_ANY(x,radix) ((float32)(x)/(1<<(radix))) 73 | #define FIX2FLOAT(x) FIX2FLOAT_ANY(x,DEFAULT_RADIX) 74 | 75 | /** 76 | * Multiply two fixed point numbers with an arbitrary radix point. 77 | * 78 | * A veritable multiplicity of implementations exist, starting with 79 | * the fastest ones... 80 | */ 81 | 82 | #if defined(__arm__) && !defined(__thumb__) 83 | /* 84 | * This works on most modern ARMs but *only* in ARM mode (for obvious 85 | * reasons), so don't use it in Thumb mode (but why are you building 86 | * signal processing code in Thumb mode?!) 87 | */ 88 | #define FIXMUL(a,b) FIXMUL_ANY(a,b,DEFAULT_RADIX) 89 | #define FIXMUL_ANY(a,b,r) ({ \ 90 | int cl, ch, _a = a, _b = b; \ 91 | __asm__ ("smull %0, %1, %2, %3\n" \ 92 | "mov %0, %0, lsr %4\n" \ 93 | "orr %0, %0, %1, lsl %5\n" \ 94 | : "=&r" (cl), "=&r" (ch) \ 95 | : "r" (_a), "r" (_b), "i" (r), "i" (32-(r)));\ 96 | cl; }) 97 | 98 | #elif defined(_MSC_VER) || (defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8) 99 | /* Standard systems*/ 100 | #define FIXMUL(a,b) FIXMUL_ANY(a,b,DEFAULT_RADIX) 101 | #define FIXMUL_ANY(a,b,radix) ((fixed32)(((int64)(a)*(b))>>(radix))) 102 | 103 | #else 104 | /* Most general case where 'long long' doesn't exist or is slow. */ 105 | #define FIXMUL(a,b) FIXMUL_ANY(a,b,DEFAULT_RADIX) 106 | #define FIXMUL_ANY(a,b,radix) ({ \ 107 | int32 _ah, _bh; \ 108 | uint32 _al, _bl, _t, c; \ 109 | _ah = ((int32)(a)) >> 16; \ 110 | _bh = ((int32)(b)) >> 16; \ 111 | _al = ((uint32)(a)) & 0xffff; \ 112 | _bl = ((uint32)(b)) & 0xffff; \ 113 | _t = _ah * _bl + _al * _bh; \ 114 | c = (fixed32)(((_al * _bl) >> (radix)) \ 115 | + ((_ah * _bh) << (32 - (radix))) \ 116 | + ((radix) > 16 ? (_t >> (radix - 16)) : (_t << (16 - radix)))); \ 117 | c;}) 118 | #endif 119 | 120 | /* Various fixed-point logarithmic functions that we need. */ 121 | /** Minimum value representable in log format. */ 122 | #define MIN_FIXLOG -2829416 /* log(1e-300) * (1< 119 | 120 | /* Win32/WinCE DLL gunk */ 121 | #include 122 | 123 | /** \file genrand.h 124 | *\brief High performance prortable random generator created by Takuji 125 | *Nishimura and Makoto Matsumoto. 126 | * 127 | * A high performance which applied Mersene twister primes to generate 128 | * random number. If probably seeded, the random generator can achieve 129 | * 19937-bits period. For technical detail. Please take a look at 130 | * (FIXME! Need to search for the web site.) http://www. 131 | */ 132 | #ifdef __cplusplus 133 | extern "C" { 134 | #endif 135 | #if 0 136 | /* Fool Emacs. */ 137 | } 138 | #endif 139 | 140 | /** 141 | * Macros to simplify calling of random generator function. 142 | * 143 | */ 144 | #define s3_rand_seed(s) genrand_seed(s); 145 | #define s3_rand_int31() genrand_int31() 146 | #define s3_rand_real() genrand_real3() 147 | #define s3_rand_res53() genrand_res53() 148 | 149 | /** 150 | *Initialize the seed of the random generator. 151 | */ 152 | SPHINXBASE_EXPORT 153 | void genrand_seed(unsigned long s); 154 | 155 | /** 156 | *generates a random number on [0,0x7fffffff]-interval 157 | */ 158 | SPHINXBASE_EXPORT 159 | long genrand_int31(void); 160 | 161 | /** 162 | *generates a random number on (0,1)-real-interval 163 | */ 164 | SPHINXBASE_EXPORT 165 | double genrand_real3(void); 166 | 167 | /** 168 | *generates a random number on [0,1) with 53-bit resolution 169 | */ 170 | SPHINXBASE_EXPORT 171 | double genrand_res53(void); 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif /*_LIBUTIL_GENRAND_H_*/ 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/glist.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * glist.h -- Module for maintaining a generic, linear linked-list structure. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: glist.h,v $ 49 | * Revision 1.9 2005/06/22 03:02:51 arthchan2003 50 | * 1, Fixed doxygen documentation, 2, add keyword. 51 | * 52 | * Revision 1.4 2005/05/03 04:09:11 archan 53 | * Implemented the heart of word copy search. For every ci-phone, every word end, a tree will be allocated to preserve its pathscore. This is different from 3.5 or below, only the best score for a particular ci-phone, regardless of the word-ends will be preserved at every frame. The graph propagation will not collect unused word tree at this point. srch_WST_propagate_wd_lv2 is also as the most stupid in the century. But well, after all, everything needs a start. I will then really get the results from the search and see how it looks. 54 | * 55 | * Revision 1.3 2005/03/30 01:22:48 archan 56 | * Fixed mistakes in last updates. Add 57 | * 58 | * 59 | * 09-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 60 | * Added glist_chkdup_*(). 61 | * 62 | * 13-Feb-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 63 | * Created from earlier version. 64 | */ 65 | 66 | 67 | /** 68 | * \file glist.h 69 | * \brief Generic linked-lists maintenance. 70 | * 71 | * Only insert at the head of the list. A convenient little 72 | * linked-list package, but a double-edged sword: the user must keep 73 | * track of the data type within the linked list elements. When it 74 | * was first written, there was no selective deletions except to 75 | * destroy the entire list. This is modified in later version. 76 | * 77 | * 78 | * (C++ would be good for this, but that's a double-edged sword as well.) 79 | */ 80 | 81 | 82 | #ifndef _LIBUTIL_GLIST_H_ 83 | #define _LIBUTIL_GLIST_H_ 84 | 85 | #include 86 | /* Win32/WinCE DLL gunk */ 87 | #include 88 | #include 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | #if 0 94 | /* Fool Emacs. */ 95 | } 96 | #endif 97 | 98 | /** A node in a generic list 99 | */ 100 | typedef struct gnode_s { 101 | anytype_t data; /** See prim_type.h */ 102 | struct gnode_s *next; /** Next node in list */ 103 | } gnode_t; 104 | typedef gnode_t *glist_t; /** Head of a list of gnodes */ 105 | 106 | 107 | /** Access macros, for convenience 108 | */ 109 | #define gnode_ptr(g) ((g)->data.ptr) 110 | #define gnode_int32(g) ((g)->data.i) 111 | #define gnode_uint32(g) ((g)->data.ui) 112 | #define gnode_float32(g) ((float32)(g)->data.fl) 113 | #define gnode_float64(g) ((g)->data.fl) 114 | #define gnode_next(g) ((g)->next) 115 | 116 | 117 | /** 118 | * Create and prepend a new list node, with the given user-defined data, at the HEAD 119 | * of the given generic list. Return the new list thus formed. 120 | * g may be NULL to indicate an initially empty list. 121 | */ 122 | SPHINXBASE_EXPORT 123 | glist_t glist_add_ptr (glist_t g, /**< a link list */ 124 | void *ptr /**< a pointer */ 125 | ); 126 | 127 | /** 128 | * Create and prepend a new list node containing an integer. 129 | */ 130 | SPHINXBASE_EXPORT 131 | glist_t glist_add_int32 (glist_t g, /**< a link list */ 132 | int32 val /**< an integer value */ 133 | ); 134 | /** 135 | * Create and prepend a new list node containing an unsigned integer. 136 | */ 137 | SPHINXBASE_EXPORT 138 | glist_t glist_add_uint32 (glist_t g, /**< a link list */ 139 | uint32 val /**< an unsigned integer value */ 140 | ); 141 | /** 142 | * Create and prepend a new list node containing a single-precision float. 143 | */ 144 | SPHINXBASE_EXPORT 145 | glist_t glist_add_float32 (glist_t g, /**< a link list */ 146 | float32 val /**< a float32 vlaue */ 147 | ); 148 | /** 149 | * Create and prepend a new list node containing a double-precision float. 150 | */ 151 | SPHINXBASE_EXPORT 152 | glist_t glist_add_float64 (glist_t g, /**< a link list */ 153 | float64 val /**< a float64 vlaue */ 154 | ); 155 | 156 | 157 | 158 | /** 159 | * Create and insert a new list node, with the given user-defined data, after 160 | * the given generic node gn. gn cannot be NULL. 161 | * Return ptr to the newly created gnode_t. 162 | */ 163 | SPHINXBASE_EXPORT 164 | gnode_t *glist_insert_ptr (gnode_t *gn, /**< a generic node which ptr will be inserted after it*/ 165 | void *ptr /**< pointer inserted */ 166 | ); 167 | /** 168 | * Create and insert a new list node containing an integer. 169 | */ 170 | SPHINXBASE_EXPORT 171 | gnode_t *glist_insert_int32 (gnode_t *gn, /**< a generic node which a value will be inserted after it*/ 172 | int32 val /**< int32 inserted */ 173 | ); 174 | /** 175 | * Create and insert a new list node containing an unsigned integer. 176 | */ 177 | SPHINXBASE_EXPORT 178 | gnode_t *glist_insert_uint32 (gnode_t *gn, /**< a generic node which a value will be inserted after it*/ 179 | uint32 val /**< uint32 inserted */ 180 | ); 181 | /** 182 | * Create and insert a new list node containing a single-precision float. 183 | */ 184 | SPHINXBASE_EXPORT 185 | gnode_t *glist_insert_float32 (gnode_t *gn, /**< a generic node which a value will be inserted after it*/ 186 | float32 val /**< float32 inserted */ 187 | ); 188 | /** 189 | * Create and insert a new list node containing a double-precision float. 190 | */ 191 | SPHINXBASE_EXPORT 192 | gnode_t *glist_insert_float64 (gnode_t *gn, /**< a generic node which a value will be inserted after it*/ 193 | float64 val /**< float64 inserted */ 194 | ); 195 | 196 | /** 197 | * Reverse the order of the given glist. (glist_add() adds to the head; one might 198 | * ultimately want the reverse of that.) 199 | * NOTE: The list is reversed "in place"; i.e., no new memory is allocated. 200 | * @return: The head of the new list. 201 | */ 202 | SPHINXBASE_EXPORT 203 | glist_t glist_reverse (glist_t g /**< input link list */ 204 | ); 205 | 206 | 207 | /** 208 | Count the number of element in a given link list 209 | @return the number of elements in the given glist_t 210 | */ 211 | SPHINXBASE_EXPORT 212 | int32 glist_count (glist_t g /**< input link list */ 213 | ); 214 | 215 | /** 216 | * Free the given generic list; user-defined data contained within is not 217 | * automatically freed. The caller must have done that already. 218 | */ 219 | SPHINXBASE_EXPORT 220 | void glist_free (glist_t g); 221 | 222 | 223 | /** 224 | * Free the given node, gn, of a glist, pred being its predecessor in the list. 225 | * Return ptr to the next node in the list after the freed node. 226 | */ 227 | SPHINXBASE_EXPORT 228 | gnode_t *gnode_free(gnode_t *gn, 229 | gnode_t *pred 230 | ); 231 | 232 | /** 233 | * Return the last node in the given list. 234 | */ 235 | SPHINXBASE_EXPORT 236 | gnode_t *glist_tail (glist_t g); 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif 241 | 242 | #endif 243 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/heap.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * heap.h -- Generic heap structure for inserting in any and popping in sorted 39 | * order. 40 | * 41 | * ********************************************** 42 | * CMU ARPA Speech Project 43 | * 44 | * Copyright (c) 1999 Carnegie Mellon University. 45 | * ALL RIGHTS RESERVED. 46 | * ********************************************** 47 | * 48 | * HISTORY 49 | * $Log: heap.h,v $ 50 | * Revision 1.7 2005/06/22 03:05:49 arthchan2003 51 | * 1, Fixed doxygen documentation, 2, Add keyword. 52 | * 53 | * Revision 1.4 2005/06/15 04:21:46 archan 54 | * 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file. 55 | * 56 | * Revision 1.3 2005/03/30 01:22:48 archan 57 | * Fixed mistakes in last updates. Add 58 | * 59 | * 60 | * 23-Dec-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 61 | * Started. 62 | */ 63 | 64 | 65 | #ifndef _LIBUTIL_HEAP_H_ 66 | #define _LIBUTIL_HEAP_H_ 67 | 68 | #include 69 | 70 | /* Win32/WinCE DLL gunk */ 71 | #include 72 | #include 73 | 74 | /** \file heap.h 75 | * \brief Heap Implementation. 76 | * 77 | * General Comment: Sorted heap structure with three main operations: 78 | * 79 | * 1. Insert a data item (with two attributes: an application supplied pointer and an 80 | * integer value; the heap is maintained in ascending order of the integer value). 81 | * 2. Return the currently topmost item (i.e., item with smallest associated value). 82 | * 3. Return the currently topmost item and pop it off the heap. 83 | */ 84 | 85 | #ifdef __cplusplus 86 | extern "C" { 87 | #endif 88 | #if 0 89 | /* Fool Emacs. */ 90 | } 91 | #endif 92 | 93 | 94 | typedef struct heap_s heap_t; 95 | 96 | 97 | /** 98 | * Allocate a new heap and return handle to it. 99 | */ 100 | SPHINXBASE_EXPORT 101 | heap_t *heap_new(void); 102 | 103 | 104 | /** 105 | * Insert a new item into the given heap. 106 | * Return value: 0 if successful, -1 otherwise. 107 | */ 108 | SPHINXBASE_EXPORT 109 | int heap_insert(heap_t *heap, /**< In: Heap into which item is to be inserted */ 110 | void *data, /**< In: Application-determined data pointer */ 111 | int32 val /**< In: According to item entered in sorted heap */ 112 | ); 113 | /** 114 | * Return the topmost item in the heap. 115 | * Return value: 1 if heap is not empty and the topmost value is returned; 116 | * 0 if heap is empty; -1 if some error occurred. 117 | */ 118 | SPHINXBASE_EXPORT 119 | int heap_top(heap_t *heap, /**< In: Heap whose topmost item is to be returned */ 120 | void **data, /**< Out: Data pointer associated with the topmost item */ 121 | int32 *val /**< Out: Value associated with the topmost item */ 122 | ); 123 | /** 124 | * Like heap_top but also pop the top item off the heap. 125 | */ 126 | SPHINXBASE_EXPORT 127 | int heap_pop(heap_t *heap, void **data, int32 *val); 128 | 129 | /** 130 | * Remove an item from the heap. 131 | */ 132 | SPHINXBASE_EXPORT 133 | int heap_remove(heap_t *heap, void *data); 134 | 135 | /** 136 | * Return the number of items in the heap. 137 | */ 138 | SPHINXBASE_EXPORT 139 | size_t heap_size(heap_t *heap); 140 | 141 | /** 142 | * Destroy the given heap; free the heap nodes. NOTE: Data pointers in the nodes are NOT freed. 143 | * Return value: 0 if successful, -1 otherwise. 144 | */ 145 | 146 | SPHINXBASE_EXPORT 147 | int heap_destroy(heap_t *heap); 148 | 149 | #ifdef __cplusplus 150 | } 151 | #endif 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/huff_code.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2009 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | /** 39 | * @file huff_code.h 40 | * @brief Huffman code and bitstream implementation 41 | * 42 | * This interface supports building canonical Huffman codes from 43 | * string and integer values. It also provides support for encoding 44 | * and decoding from strings and files, and for reading and writing 45 | * codebooks from files. 46 | */ 47 | 48 | #ifndef __HUFF_CODE_H__ 49 | #define __HUFF_CODE_H__ 50 | 51 | #include 52 | 53 | #include 54 | #include 55 | #include 56 | 57 | typedef struct huff_code_s huff_code_t; 58 | 59 | /** 60 | * Create a codebook from 32-bit integer data. 61 | */ 62 | SPHINXBASE_EXPORT 63 | huff_code_t *huff_code_build_int(int32 const *values, int32 const *frequencies, int nvals); 64 | 65 | /** 66 | * Create a codebook from string data. 67 | */ 68 | SPHINXBASE_EXPORT 69 | huff_code_t *huff_code_build_str(char * const *values, int32 const *frequencies, int nvals); 70 | 71 | /** 72 | * Read a codebook from a file. 73 | */ 74 | SPHINXBASE_EXPORT 75 | huff_code_t *huff_code_read(FILE *infh); 76 | 77 | /** 78 | * Write a codebook to a file. 79 | */ 80 | SPHINXBASE_EXPORT 81 | int huff_code_write(huff_code_t *hc, FILE *outfh); 82 | 83 | /** 84 | * Print a codebook to a file as text (for debugging) 85 | */ 86 | SPHINXBASE_EXPORT 87 | int huff_code_dump(huff_code_t *hc, FILE *dumpfh); 88 | 89 | /** 90 | * Retain a pointer to a Huffman codec object. 91 | */ 92 | SPHINXBASE_EXPORT 93 | huff_code_t *huff_code_retain(huff_code_t *hc); 94 | 95 | /** 96 | * Release a pointer to a Huffman codec object. 97 | */ 98 | SPHINXBASE_EXPORT 99 | int huff_code_free(huff_code_t *hc); 100 | 101 | /** 102 | * Attach a Huffman codec to a file handle for input/output. 103 | */ 104 | SPHINXBASE_EXPORT 105 | FILE *huff_code_attach(huff_code_t *hc, FILE *fh, char const *mode); 106 | 107 | /** 108 | * Detach a Huffman codec from its file handle. 109 | */ 110 | SPHINXBASE_EXPORT 111 | FILE *huff_code_detach(huff_code_t *hc); 112 | 113 | /** 114 | * Encode an integer, writing it to the file handle, if any. 115 | */ 116 | SPHINXBASE_EXPORT 117 | int huff_code_encode_int(huff_code_t *hc, int32 sym, uint32 *outcw); 118 | 119 | /** 120 | * Encode a string, writing it to the file handle, if any. 121 | */ 122 | SPHINXBASE_EXPORT 123 | int huff_code_encode_str(huff_code_t *hc, char const *sym, uint32 *outcw); 124 | 125 | /** 126 | * Decode an integer, reading it from the file if no data given. 127 | */ 128 | SPHINXBASE_EXPORT 129 | int huff_code_decode_int(huff_code_t *hc, int *outval, 130 | char const **inout_data, 131 | size_t *inout_data_len, 132 | int *inout_offset); 133 | 134 | /** 135 | * Decode a string, reading it from the file if no data given. 136 | */ 137 | SPHINXBASE_EXPORT 138 | char const *huff_code_decode_str(huff_code_t *hc, 139 | char const **inout_data, 140 | size_t *inout_data_len, 141 | int *inout_offset); 142 | 143 | #endif /* __HUFF_CODE_H__ */ 144 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/jsgf.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2007 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | #ifndef __JSGF_H__ 39 | #define __JSGF_H__ 40 | 41 | /** 42 | * @file jsgf.h JSGF grammar compiler 43 | * 44 | * This file defines the data structures for parsing JSGF grammars 45 | * into Sphinx finite-state grammars. 46 | **/ 47 | 48 | #include 49 | 50 | /* Win32/WinCE DLL gunk */ 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | #if 0 60 | /* Fool Emacs. */ 61 | } 62 | #endif 63 | 64 | typedef struct jsgf_s jsgf_t; 65 | typedef struct jsgf_rule_s jsgf_rule_t; 66 | 67 | /** 68 | * Create a new JSGF grammar. 69 | * 70 | * @param parent optional parent grammar for this one (NULL, usually). 71 | * @return new JSGF grammar object, or NULL on failure. 72 | */ 73 | SPHINXBASE_EXPORT 74 | jsgf_t *jsgf_grammar_new(jsgf_t *parent); 75 | 76 | /** 77 | * Parse a JSGF grammar from a file. 78 | * 79 | * @param filename the name of the file to parse. 80 | * @param parent optional parent grammar for this one (NULL, usually). 81 | * @return new JSGF grammar object, or NULL on failure. 82 | */ 83 | SPHINXBASE_EXPORT 84 | jsgf_t *jsgf_parse_file(const char *filename, jsgf_t *parent); 85 | 86 | /** 87 | * Parse a JSGF grammar from a string. 88 | * 89 | * @param 0-terminated string with grammar. 90 | * @param parent optional parent grammar for this one (NULL, usually). 91 | * @return new JSGF grammar object, or NULL on failure. 92 | */ 93 | SPHINXBASE_EXPORT 94 | jsgf_t *jsgf_parse_string(const char *string, jsgf_t *parent); 95 | 96 | /** 97 | * Get the grammar name from the file. 98 | */ 99 | SPHINXBASE_EXPORT 100 | char const *jsgf_grammar_name(jsgf_t *jsgf); 101 | 102 | /** 103 | * Free a JSGF grammar. 104 | */ 105 | SPHINXBASE_EXPORT 106 | void jsgf_grammar_free(jsgf_t *jsgf); 107 | 108 | /** 109 | * Iterator over rules in a grammar. 110 | */ 111 | typedef hash_iter_t jsgf_rule_iter_t; 112 | 113 | /** 114 | * Get an iterator over all rules in a grammar. 115 | */ 116 | SPHINXBASE_EXPORT 117 | jsgf_rule_iter_t *jsgf_rule_iter(jsgf_t *grammar); 118 | 119 | /** 120 | * Advance an iterator to the next rule in the grammar. 121 | */ 122 | #define jsgf_rule_iter_next(itor) hash_table_iter_next(itor) 123 | 124 | /** 125 | * Get the current rule in a rule iterator. 126 | */ 127 | #define jsgf_rule_iter_rule(itor) ((jsgf_rule_t *)(itor)->ent->val) 128 | 129 | /** 130 | * Free a rule iterator (if the end hasn't been reached). 131 | */ 132 | #define jsgf_rule_iter_free(itor) hash_table_iter_free(itor) 133 | 134 | /** 135 | * Get a rule by name from a grammar. Name should not contain brackets. 136 | */ 137 | SPHINXBASE_EXPORT 138 | jsgf_rule_t *jsgf_get_rule(jsgf_t *grammar, const char *name); 139 | 140 | /** 141 | * Returns the first public rule of the grammar 142 | */ 143 | SPHINXBASE_EXPORT 144 | jsgf_rule_t *jsgf_get_public_rule(jsgf_t *grammar); 145 | 146 | /** 147 | * Get the rule name from a rule. 148 | */ 149 | SPHINXBASE_EXPORT 150 | char const *jsgf_rule_name(jsgf_rule_t *rule); 151 | 152 | /** 153 | * Test if a rule is public or not. 154 | */ 155 | SPHINXBASE_EXPORT 156 | int jsgf_rule_public(jsgf_rule_t *rule); 157 | 158 | /** 159 | * Build a Sphinx FSG object from a JSGF rule. 160 | */ 161 | SPHINXBASE_EXPORT 162 | fsg_model_t *jsgf_build_fsg(jsgf_t *grammar, jsgf_rule_t *rule, 163 | logmath_t *lmath, float32 lw); 164 | 165 | /** 166 | * Build a Sphinx FSG object from a JSGF rule. 167 | * 168 | * This differs from jsgf_build_fsg() in that it does not do closure 169 | * on epsilon transitions or any other postprocessing. For the time 170 | * being this is necessary in order to write it to a file - the FSG 171 | * code will be fixed soon. 172 | */ 173 | SPHINXBASE_EXPORT 174 | fsg_model_t *jsgf_build_fsg_raw(jsgf_t *grammar, jsgf_rule_t *rule, 175 | logmath_t *lmath, float32 lw); 176 | 177 | 178 | /** 179 | * Read JSGF from file and return FSG object from it. 180 | * 181 | * This function looks for a first public rule in jsgf and constructs JSGF from it. 182 | */ 183 | SPHINXBASE_EXPORT 184 | fsg_model_t *jsgf_read_file(const char *file, logmath_t * lmath, float32 lw); 185 | 186 | /** 187 | * Read JSGF from string and return FSG object from it. 188 | * 189 | * This function looks for a first public rule in jsgf and constructs JSGF from it. 190 | */ 191 | SPHINXBASE_EXPORT 192 | fsg_model_t *jsgf_read_string(const char *string, logmath_t * lmath, float32 lw); 193 | 194 | 195 | /** 196 | * Convert a JSGF rule to Sphinx FSG text form. 197 | * 198 | * This does a direct conversion without doing transitive closure on 199 | * null transitions and so forth. 200 | */ 201 | SPHINXBASE_EXPORT 202 | int jsgf_write_fsg(jsgf_t *grammar, jsgf_rule_t *rule, FILE *outfh); 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | 208 | 209 | #endif /* __JSGF_H__ */ 210 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/listelem_alloc.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | 38 | #ifndef __LISTELEM_ALLOC_H__ 39 | #define __LISTELEM_ALLOC_H__ 40 | 41 | /** @file listelem_alloc.h 42 | * @brief Fast memory allocator for uniformly sized objects 43 | * @author M K Ravishankar 44 | */ 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | #if 0 49 | /* Fool Emacs. */ 50 | } 51 | #endif 52 | 53 | #include 54 | #ifdef S60 55 | #include 56 | #endif 57 | 58 | /* Win32/WinCE DLL gunk */ 59 | #include 60 | #include 61 | 62 | /** 63 | * List element allocator object. 64 | */ 65 | typedef struct listelem_alloc_s listelem_alloc_t; 66 | 67 | /** 68 | * Initialize and return a list element allocator. 69 | */ 70 | SPHINXBASE_EXPORT 71 | listelem_alloc_t * listelem_alloc_init(size_t elemsize); 72 | 73 | /** 74 | * Finalize and release all memory associated with a list element allocator. 75 | */ 76 | SPHINXBASE_EXPORT 77 | void listelem_alloc_free(listelem_alloc_t *le); 78 | 79 | 80 | SPHINXBASE_EXPORT 81 | void *__listelem_malloc__(listelem_alloc_t *le, char *file, int line); 82 | 83 | /** 84 | * Allocate a list element and return pointer to it. 85 | */ 86 | #define listelem_malloc(le) __listelem_malloc__((le),__FILE__,__LINE__) 87 | 88 | SPHINXBASE_EXPORT 89 | void *__listelem_malloc_id__(listelem_alloc_t *le, char *file, int line, 90 | int32 *out_id); 91 | 92 | /** 93 | * Allocate a list element, returning a unique identifier. 94 | */ 95 | #define listelem_malloc_id(le, oid) __listelem_malloc_id__((le),__FILE__,__LINE__,(oid)) 96 | 97 | /** 98 | * Retrieve a list element by its identifier. 99 | */ 100 | SPHINXBASE_EXPORT 101 | void *listelem_get_item(listelem_alloc_t *le, int32 id); 102 | 103 | /** 104 | * Free list element of given size 105 | */ 106 | SPHINXBASE_EXPORT 107 | void __listelem_free__(listelem_alloc_t *le, void *elem, char *file, int line); 108 | 109 | /** 110 | * Macro of __listelem_free__ 111 | */ 112 | #define listelem_free(le,el) __listelem_free__((le),(el),__FILE__,__LINE__) 113 | 114 | /** 115 | Print number of allocation, numer of free operation stats 116 | */ 117 | SPHINXBASE_EXPORT 118 | void listelem_stats(listelem_alloc_t *le); 119 | 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/logmath.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2007 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /** 38 | * @file logmath.h 39 | * @brief Fast integer logarithmic addition operations. 40 | * 41 | * In evaluating HMM models, probability values are often kept in log 42 | * domain, to avoid overflow. To enable these logprob values to be 43 | * held in int32 variables without significant loss of precision, a 44 | * logbase of (1+epsilon) (where epsilon < 0.01 or so) is used. This 45 | * module maintains this logbase (B). 46 | * 47 | * However, maintaining probabilities in log domain creates a problem 48 | * when adding two probability values. This problem can be solved by 49 | * table lookup. Note that: 50 | * 51 | * - \f$ b^z = b^x + b^y \f$ 52 | * - \f$ b^z = b^x(1 + b^{y-x}) = b^y(1 + e^{x-y}) \f$ 53 | * - \f$ z = x + log_b(1 + b^{y-x}) = y + log_b(1 + b^{x-y}) \f$ 54 | * 55 | * So: 56 | * 57 | * - when \f$ y > x, z = y + logadd\_table[-(x-y)] \f$ 58 | * - when \f$ x > y, z = x + logadd\_table[-(y-x)] \f$ 59 | * - where \f$ logadd\_table[n] = log_b(1 + b^{-n}) \f$ 60 | * 61 | * The first entry in logadd_table is 62 | * simply \f$ log_b(2.0) \f$, for 63 | * the case where \f$ y = x \f$ and thus 64 | * \f$ z = log_b(2x) = log_b(2) + x \f$. The last entry is zero, 65 | * where \f$ log_b(x+y) = x = y \f$ due to loss of precision. 66 | * 67 | * Since this table can be quite large particularly for small 68 | * logbases, an option is provided to compress it by dropping the 69 | * least significant bits of the table. 70 | */ 71 | 72 | #ifndef __LOGMATH_H__ 73 | #define __LOGMATH_H__ 74 | 75 | #include 76 | #include 77 | #include 78 | 79 | 80 | #ifdef __cplusplus 81 | extern "C" { 82 | #endif 83 | #if 0 84 | /* Fool Emacs. */ 85 | } 86 | #endif 87 | 88 | /** 89 | * Integer log math computation table. 90 | * 91 | * This is exposed here to allow log-add computations to be inlined. 92 | */ 93 | typedef struct logadd_s logadd_t; 94 | struct logadd_s { 95 | /** Table, in unsigned integers of (width) bytes. */ 96 | void *table; 97 | /** Number of elements in (table). This is never smaller than 256 (important!) */ 98 | uint32 table_size; 99 | /** Width of elements of (table). */ 100 | uint8 width; 101 | /** Right shift applied to elements in (table). */ 102 | int8 shift; 103 | }; 104 | 105 | /** 106 | * Integer log math computation class. 107 | */ 108 | typedef struct logmath_s logmath_t; 109 | 110 | /** 111 | * Obtain the log-add table from a logmath_t * 112 | */ 113 | #define LOGMATH_TABLE(lm) ((logadd_t *)lm) 114 | 115 | /** 116 | * Initialize a log math computation table. 117 | * @param base The base B in which computation is to be done. 118 | * @param shift Log values are shifted right by this many bits. 119 | * @param use_table Whether to use an add table or not 120 | * @return The newly created log math table. 121 | */ 122 | SPHINXBASE_EXPORT 123 | logmath_t *logmath_init(float64 base, int shift, int use_table); 124 | 125 | /** 126 | * Memory-map (or read) a log table from a file. 127 | */ 128 | SPHINXBASE_EXPORT 129 | logmath_t *logmath_read(const char *filename); 130 | 131 | /** 132 | * Write a log table to a file. 133 | */ 134 | SPHINXBASE_EXPORT 135 | int32 logmath_write(logmath_t *lmath, const char *filename); 136 | 137 | /** 138 | * Get the log table size and dimensions. 139 | */ 140 | SPHINXBASE_EXPORT 141 | int32 logmath_get_table_shape(logmath_t *lmath, uint32 *out_size, 142 | uint32 *out_width, uint32 *out_shift); 143 | 144 | /** 145 | * Get the log base. 146 | */ 147 | SPHINXBASE_EXPORT 148 | float64 logmath_get_base(logmath_t *lmath); 149 | 150 | /** 151 | * Get the smallest possible value represented in this base. 152 | */ 153 | SPHINXBASE_EXPORT 154 | int logmath_get_zero(logmath_t *lmath); 155 | 156 | /** 157 | * Get the width of the values in a log table. 158 | */ 159 | SPHINXBASE_EXPORT 160 | int logmath_get_width(logmath_t *lmath); 161 | 162 | /** 163 | * Get the shift of the values in a log table. 164 | */ 165 | SPHINXBASE_EXPORT 166 | int logmath_get_shift(logmath_t *lmath); 167 | 168 | /** 169 | * Retain ownership of a log table. 170 | * 171 | * @return pointer to retained log table. 172 | */ 173 | SPHINXBASE_EXPORT 174 | logmath_t *logmath_retain(logmath_t *lmath); 175 | 176 | /** 177 | * Free a log table. 178 | * 179 | * @return new reference count (0 if freed completely) 180 | */ 181 | SPHINXBASE_EXPORT 182 | int logmath_free(logmath_t *lmath); 183 | 184 | /** 185 | * Add two values in log space exactly and slowly (without using add table). 186 | */ 187 | SPHINXBASE_EXPORT 188 | int logmath_add_exact(logmath_t *lmath, int logb_p, int logb_q); 189 | 190 | /** 191 | * Add two values in log space (i.e. return log(exp(p)+exp(q))) 192 | */ 193 | SPHINXBASE_EXPORT 194 | int logmath_add(logmath_t *lmath, int logb_p, int logb_q); 195 | 196 | /** 197 | * Convert linear floating point number to integer log in base B. 198 | */ 199 | SPHINXBASE_EXPORT 200 | int logmath_log(logmath_t *lmath, float64 p); 201 | 202 | /** 203 | * Convert integer log in base B to linear floating point. 204 | */ 205 | SPHINXBASE_EXPORT 206 | float64 logmath_exp(logmath_t *lmath, int logb_p); 207 | 208 | /** 209 | * Convert natural log (in floating point) to integer log in base B. 210 | */ 211 | SPHINXBASE_EXPORT 212 | int logmath_ln_to_log(logmath_t *lmath, float64 log_p); 213 | 214 | /** 215 | * Convert integer log in base B to natural log (in floating point). 216 | */ 217 | SPHINXBASE_EXPORT 218 | float64 logmath_log_to_ln(logmath_t *lmath, int logb_p); 219 | 220 | /** 221 | * Convert base 10 log (in floating point) to integer log in base B. 222 | */ 223 | SPHINXBASE_EXPORT 224 | int logmath_log10_to_log(logmath_t *lmath, float64 log_p); 225 | 226 | /** 227 | * Convert integer log in base B to base 10 log (in floating point). 228 | */ 229 | SPHINXBASE_EXPORT 230 | float64 logmath_log_to_log10(logmath_t *lmath, int logb_p); 231 | 232 | #ifdef __cplusplus 233 | } 234 | #endif 235 | 236 | 237 | #endif /* __LOGMATH_H__ */ 238 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/matrix.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1997-2000 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /********************************************************************* 38 | * 39 | * File: matrix.h 40 | * 41 | * Description: Matrix and linear algebra functions 42 | * 43 | * Author: 44 | * 45 | *********************************************************************/ 46 | 47 | #ifndef MATRIX_H 48 | #define MATRIX_H 49 | 50 | /** \file matrix.h 51 | * \brief Matrix and linear algebra functions. 52 | * 53 | * This file contains some basic matrix and linear algebra operations. 54 | * In general these operate on positive definite matrices ONLY, 55 | * because all matrices we're likely to encounter are either 56 | * covariance matrices or are derived from them, and therefore a 57 | * non-positive-definite matrix indicates some kind of pathological 58 | * condition. 59 | */ 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | #if 0 64 | /* Fool Emacs. */ 65 | } 66 | #endif 67 | 68 | /* Win32/WinCE DLL gunk */ 69 | #include 70 | #include 71 | 72 | 73 | /** 74 | * Norm an array 75 | * @param arr array 76 | * @param d1 dimension 77 | * @param d2 dimension 78 | * @param d3 dimension 79 | **/ 80 | SPHINXBASE_EXPORT void norm_3d(float32 ***arr, uint32 d1, uint32 d2, uint32 d3); 81 | 82 | /** 83 | * Floor 3-d array 84 | * @param out output array 85 | * @para in input array 86 | * @param d1 dimension 87 | * @param d2 dimension 88 | * @param d3 dimension 89 | **/ 90 | SPHINXBASE_EXPORT void 91 | accum_3d(float32 ***out, float32 ***in, uint32 d1, uint32 d2, uint32 d3); 92 | 93 | /** Ensures that non-zero values x such that -band < x < band, band > 0 are set to -band if x < 0 and band if x > 0. 94 | * @param v array 95 | * @param d1 array size 96 | * @param band band value 97 | */ 98 | SPHINXBASE_EXPORT void band_nz_1d(float32 *v, uint32 d1, float32 band); 99 | 100 | /** 101 | * Floor 3-d array 102 | * @param m array 103 | * @param d1 dimension 104 | * @param d2 dimension 105 | * @param d3 dimension 106 | * @param floor floor value 107 | **/ 108 | SPHINXBASE_EXPORT void floor_nz_3d(float32 ***m, uint32 d1, uint32 d2, uint32 d3, float32 floor); 109 | 110 | /** 111 | * Floor 1-d array 112 | * @param m array 113 | * @param d1 dimension 114 | * @param floor floor value 115 | **/ 116 | SPHINXBASE_EXPORT void floor_nz_1d(float32 *v, uint32 d1, float32 floor); 117 | 118 | /** 119 | * Calculate the determinant of a positive definite matrix. 120 | * @param a The input matrix, must be positive definite. 121 | * @param len The dimension of the input matrix. 122 | * @return The determinant of the input matrix, or -1.0 if the matrix is 123 | * not positive definite. 124 | * 125 | * \note These can be vanishingly small hence the float64 return type. 126 | * Also note that only the upper triangular portion of a is 127 | * considered, therefore the check for positive-definiteness is not 128 | * reliable. 129 | **/ 130 | SPHINXBASE_EXPORT 131 | float64 determinant(float32 **a, int32 len); 132 | 133 | /** 134 | * Invert (if possible) a positive definite matrix. 135 | * @param out_ainv The inverse of a will be stored here. 136 | * @param a The input matrix, must be positive definite. 137 | * @param len The dimension of the input matrix. 138 | * @return 0 for success or -1 for a non-positive-definite matrix. 139 | * 140 | * \note Only the upper triangular portion of a is considered, 141 | * therefore the check for positive-definiteness is not reliable. 142 | **/ 143 | SPHINXBASE_EXPORT 144 | int32 invert(float32 **out_ainv, float32 **a, int32 len); 145 | 146 | /** 147 | * Solve (if possible) a positive-definite system of linear equations AX=B for X. 148 | * @param a The A matrix on the left-hand side of the equation, must be positive-definite. 149 | * @param b The B vector on the right-hand side of the equation. 150 | * @param out_x The X vector will be stored here. 151 | * @param n The dimension of the A matrix (n by n) and the B and X vectors. 152 | * @return 0 for success or -1 for a non-positive-definite matrix. 153 | * 154 | * \note Only the upper triangular portion of a is considered, 155 | * therefore the check for positive-definiteness is not reliable. 156 | **/ 157 | SPHINXBASE_EXPORT 158 | int32 solve(float32 **a, float32 *b, 159 | float32 *out_x, int32 n); 160 | 161 | /** 162 | * Calculate the outer product of two vectors. 163 | * @param out_a A (pre-allocated) len x len array. The outer product 164 | * will be stored here. 165 | * @param x A vector of length len. 166 | * @param y A vector of length len. 167 | * @param len The length of the input vectors. 168 | **/ 169 | SPHINXBASE_EXPORT 170 | void outerproduct(float32 **out_a, float32 *x, float32 *y, int32 len); 171 | 172 | /** 173 | * Multiply C=AB where A and B are symmetric matrices. 174 | * @param out_c The output matrix C. 175 | * @param a The input matrix A. 176 | * @param b The input matrix B. 177 | * @param n Dimensionality of A and B. 178 | **/ 179 | SPHINXBASE_EXPORT 180 | void matrixmultiply(float32 **out_c, /* = */ 181 | float32 **a, /* * */ float32 **b, 182 | int32 n); 183 | 184 | /** 185 | * Multiply a symmetric matrix by a constant in-place. 186 | * @param inout_a The matrix to multiply. 187 | * @param x The constant to multiply it by. 188 | * @param n dimension of a. 189 | **/ 190 | SPHINXBASE_EXPORT 191 | void scalarmultiply(float32 **inout_a, float32 x, int32 n); 192 | 193 | /** 194 | * Add A += B. 195 | * @param inout_a The A matrix to add. 196 | * @param b The B matrix to add to A. 197 | * @param n dimension of a and b. 198 | **/ 199 | SPHINXBASE_EXPORT 200 | void matrixadd(float32 **inout_a, float32 **b, int32 n); 201 | 202 | #if 0 203 | { /* Fool indent. */ 204 | #endif 205 | #ifdef __cplusplus 206 | } 207 | #endif 208 | 209 | #endif /* MATRIX_H */ 210 | 211 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/mmio.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2006-2007 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /** 38 | * @file mmio.h 39 | * @brief Memory-mapped I/O wrappers for files. 40 | * @author David Huggins-Daines 41 | **/ 42 | 43 | #ifndef __MMIO_H__ 44 | #define __MMIO_H__ 45 | 46 | #include 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | #if 0 52 | /* Fool Emacs. */ 53 | } 54 | #endif 55 | 56 | /** 57 | * Abstract structure representing a memory-mapped file. 58 | **/ 59 | typedef struct mmio_file_s mmio_file_t; 60 | 61 | /** 62 | * Memory-map a file for reading. 63 | * @return a mmio_file_t * or NULL for failure. 64 | **/ 65 | SPHINXBASE_EXPORT 66 | mmio_file_t *mmio_file_read(const char *filename); 67 | 68 | /** 69 | * Get a pointer to the memory mapped for a file. 70 | **/ 71 | SPHINXBASE_EXPORT 72 | void *mmio_file_ptr(mmio_file_t *mf); 73 | 74 | /** 75 | * Unmap a file, releasing memory associated with it. 76 | **/ 77 | SPHINXBASE_EXPORT 78 | void mmio_file_unmap(mmio_file_t *mf); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | 85 | #endif /* __MMIO_H__ */ 86 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/mulaw.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2001 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * muLaw.h -- Table for converting mu-law data into 16-bit linear PCM format. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1996 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * 49 | * 21-Jul-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 50 | * Created from Sunil Issar's version. 51 | */ 52 | 53 | /** 54 | * \file mulaw.h 55 | * \brief Table for converting mu-law data into 16-bit linear PCM format. 56 | */ 57 | 58 | 59 | #ifndef _MULAW_H_ 60 | #define _MULAW_H_ 61 | 62 | 63 | static int16 muLaw[256] = { 64 | -0x1f5f, -0x1e5f, -0x1d5f, -0x1c5f, -0x1b5f, -0x1a5f, -0x195f, -0x185f, 65 | -0x175f, -0x165f, -0x155f, -0x145f, -0x135f, -0x125f, -0x115f, -0x105f, 66 | -0x0f9f, -0x0f1f, -0x0e9f, -0x0e1f, -0x0d9f, -0x0d1f, -0x0c9f, -0x0c1f, 67 | -0x0b9f, -0x0b1f, -0x0a9f, -0x0a1f, -0x099f, -0x091f, -0x089f, -0x081f, 68 | -0x07bf, -0x077f, -0x073f, -0x06ff, -0x06bf, -0x067f, -0x063f, -0x05ff, 69 | -0x05bf, -0x057f, -0x053f, -0x04ff, -0x04bf, -0x047f, -0x043f, -0x03ff, 70 | -0x03cf, -0x03af, -0x038f, -0x036f, -0x034f, -0x032f, -0x030f, -0x02ef, 71 | -0x02cf, -0x02af, -0x028f, -0x026f, -0x024f, -0x022f, -0x020f, -0x01ef, 72 | -0x01d7, -0x01c7, -0x01b7, -0x01a7, -0x0197, -0x0187, -0x0177, -0x0167, 73 | -0x0157, -0x0147, -0x0137, -0x0127, -0x0117, -0x0107, -0x00f7, -0x00e7, 74 | -0x00db, -0x00d3, -0x00cb, -0x00c3, -0x00bb, -0x00b3, -0x00ab, -0x00a3, 75 | -0x009b, -0x0093, -0x008b, -0x0083, -0x007b, -0x0073, -0x006b, -0x0063, 76 | -0x005d, -0x0059, -0x0055, -0x0051, -0x004d, -0x0049, -0x0045, -0x0041, 77 | -0x003d, -0x0039, -0x0035, -0x0031, -0x002d, -0x0029, -0x0025, -0x0021, 78 | -0x001e, -0x001c, -0x001a, -0x0018, -0x0016, -0x0014, -0x0012, -0x0010, 79 | -0x000e, -0x000c, -0x000a, -0x0008, -0x0006, -0x0004, -0x0002, 0x0000, 80 | 0x1f5f, 0x1e5f, 0x1d5f, 0x1c5f, 0x1b5f, 0x1a5f, 0x195f, 0x185f, 81 | 0x175f, 0x165f, 0x155f, 0x145f, 0x135f, 0x125f, 0x115f, 0x105f, 82 | 0x0f9f, 0x0f1f, 0x0e9f, 0x0e1f, 0x0d9f, 0x0d1f, 0x0c9f, 0x0c1f, 83 | 0x0b9f, 0x0b1f, 0x0a9f, 0x0a1f, 0x099f, 0x091f, 0x089f, 0x081f, 84 | 0x07bf, 0x077f, 0x073f, 0x06ff, 0x06bf, 0x067f, 0x063f, 0x05ff, 85 | 0x05bf, 0x057f, 0x053f, 0x04ff, 0x04bf, 0x047f, 0x043f, 0x03ff, 86 | 0x03cf, 0x03af, 0x038f, 0x036f, 0x034f, 0x032f, 0x030f, 0x02ef, 87 | 0x02cf, 0x02af, 0x028f, 0x026f, 0x024f, 0x022f, 0x020f, 0x01ef, 88 | 0x01d7, 0x01c7, 0x01b7, 0x01a7, 0x0197, 0x0187, 0x0177, 0x0167, 89 | 0x0157, 0x0147, 0x0137, 0x0127, 0x0117, 0x0107, 0x00f7, 0x00e7, 90 | 0x00db, 0x00d3, 0x00cb, 0x00c3, 0x00bb, 0x00b3, 0x00ab, 0x00a3, 91 | 0x009b, 0x0093, 0x008b, 0x0083, 0x007b, 0x0073, 0x006b, 0x0063, 92 | 0x005d, 0x0059, 0x0055, 0x0051, 0x004d, 0x0049, 0x0045, 0x0041, 93 | 0x003d, 0x0039, 0x0035, 0x0031, 0x002d, 0x0029, 0x0025, 0x0021, 94 | 0x001e, 0x001c, 0x001a, 0x0018, 0x0016, 0x0014, 0x0012, 0x0010, 95 | 0x000e, 0x000c, 0x000a, 0x0008, 0x0006, 0x0004, 0x0002, 0x0000, 96 | }; 97 | 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/pio.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * pio.h -- Packaged I/O routines. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: pio.h,v $ 49 | * Revision 1.3 2005/06/22 08:00:09 arthchan2003 50 | * Completed all doxygen documentation on file description for libs3decoder/libutil/libs3audio and programs. 51 | * 52 | * Revision 1.2 2005/06/22 03:09:52 arthchan2003 53 | * 1, Fixed doxygen documentation, 2, Added keyword. 54 | * 55 | * Revision 1.2 2005/06/16 00:14:08 archan 56 | * Added const keyword to file argument for file_open 57 | * 58 | * Revision 1.1 2005/06/15 06:11:03 archan 59 | * sphinx3 to s3.generic: change io.[ch] to pio.[ch] 60 | * 61 | * Revision 1.5 2005/06/15 04:21:46 archan 62 | * 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file. 63 | * 64 | * Revision 1.4 2005/04/20 03:49:32 archan 65 | * Add const to string argument of myfopen. 66 | * 67 | * Revision 1.3 2005/03/30 01:22:48 archan 68 | * Fixed mistakes in last updates. Add 69 | * 70 | * 71 | * 08-Dec-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 72 | * Added stat_mtime(). 73 | * 74 | * 11-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 75 | * Added _myfopen() and myfopen macro. 76 | * 77 | * 05-Sep-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 78 | * Started. 79 | */ 80 | 81 | 82 | #ifndef _LIBUTIL_IO_H_ 83 | #define _LIBUTIL_IO_H_ 84 | 85 | #include 86 | #if !defined(_WIN32_WCE) && !(defined(__ADSPBLACKFIN__) && !defined(__linux__)) 87 | #include 88 | #endif 89 | 90 | /* Win32/WinCE DLL gunk */ 91 | #include 92 | #include 93 | 94 | /** \file pio.h 95 | * \brief file IO related operations. 96 | * 97 | * Custom fopen with error checking is implemented. fopen_comp can 98 | * open a file with .z, .Z, .gz or .GZ extension 99 | * 100 | * WARNING: Usage of stat_retry will results in 100s of waiting time 101 | * if the file doesn't exist. 102 | */ 103 | 104 | #ifdef __cplusplus 105 | extern "C" { 106 | #endif 107 | #if 0 108 | /* Fool Emacs. */ 109 | } 110 | #endif 111 | 112 | /** 113 | * Like fopen, but use popen and zcat if it is determined that "file" is compressed 114 | * (i.e., has a .z, .Z, .gz, or .GZ extension). 115 | */ 116 | SPHINXBASE_EXPORT 117 | FILE *fopen_comp (const char *file, /**< In: File to be opened */ 118 | const char *mode, /**< In: "r" or "w", as with normal fopen */ 119 | int32 *ispipe /**< Out: On return *ispipe is TRUE iff file 120 | was opened via a pipe */ 121 | ); 122 | 123 | /** 124 | * Close a file opened using fopen_comp. 125 | */ 126 | SPHINXBASE_EXPORT 127 | void fclose_comp (FILE *fp, /**< In: File pointer to be closed */ 128 | int32 ispipe /**< In: ispipe argument that was returned by the 129 | corresponding fopen_comp() call */ 130 | ); 131 | 132 | /** 133 | * Open a file for reading, but if file not present try to open compressed version (if 134 | * file is uncompressed, and vice versa). 135 | */ 136 | SPHINXBASE_EXPORT 137 | FILE *fopen_compchk (const char *file, /**< In: File to be opened */ 138 | int32 *ispipe /**< Out: On return *ispipe is TRUE iff file 139 | was opened via a pipe */ 140 | ); 141 | 142 | /** 143 | * Wrapper around fopen to check for failure and E_FATAL if failed. 144 | */ 145 | SPHINXBASE_EXPORT 146 | FILE *_myfopen(const char *file, const char *mode, 147 | const char *pgm, int32 line); /* In: __FILE__, __LINE__ from where called */ 148 | #define myfopen(file,mode) _myfopen((file),(mode),__FILE__,__LINE__) 149 | 150 | 151 | /** 152 | * NFS file reads seem to fail now and then. Use the following functions in place of 153 | * the regular fread. It retries failed freads several times and quits only if all of 154 | * them fail. Be aware, however, that even normal failures such as attempting to read 155 | * beyond EOF will trigger such retries, wasting about a minute in retries. 156 | * Arguments identical to regular fread. 157 | */ 158 | SPHINXBASE_EXPORT 159 | int32 fread_retry(void *pointer, int32 size, int32 num_items, FILE *stream); 160 | 161 | /** 162 | * Read a line of arbitrary length from a file and return it as a 163 | * newly allocated string. 164 | * 165 | * @deprecated Use line iterators instead. 166 | * 167 | * @param stream The file handle to read from. 168 | * @param out_len Output: if not NULL, length of the string read. 169 | * @return allocated string containing the line, or NULL on error or EOF. 170 | */ 171 | SPHINXBASE_EXPORT 172 | char *fread_line(FILE *stream, size_t *out_len); 173 | 174 | /** 175 | * Line iterator for files. 176 | */ 177 | typedef struct lineiter_t { 178 | char *buf; 179 | FILE *fh; 180 | int32 bsiz; 181 | int32 len; 182 | int32 clean; 183 | int32 lineno; 184 | } lineiter_t; 185 | 186 | /** 187 | * Start reading lines from a file. 188 | */ 189 | SPHINXBASE_EXPORT 190 | lineiter_t *lineiter_start(FILE *fh); 191 | 192 | /** 193 | * Start reading lines from a file, skip comments and trim lines. 194 | */ 195 | SPHINXBASE_EXPORT 196 | lineiter_t *lineiter_start_clean(FILE *fh); 197 | 198 | /** 199 | * Move to the next line in the file. 200 | */ 201 | SPHINXBASE_EXPORT 202 | lineiter_t *lineiter_next(lineiter_t *li); 203 | 204 | /** 205 | * Stop reading lines from a file. 206 | */ 207 | SPHINXBASE_EXPORT 208 | void lineiter_free(lineiter_t *li); 209 | 210 | /** 211 | * Returns current line number. 212 | */ 213 | SPHINXBASE_EXPORT 214 | int lineiter_lineno(lineiter_t *li); 215 | 216 | 217 | #ifdef _WIN32_WCE 218 | /* Fake this for WinCE which has no stat() */ 219 | #include 220 | struct stat { 221 | DWORD st_mtime; 222 | DWORD st_size; 223 | }; 224 | #endif /* _WIN32_WCE */ 225 | 226 | #if defined(__ADSPBLACKFIN__) && !defined(__linux__) 227 | struct stat { 228 | int32 st_mtime; 229 | int32 st_size; 230 | }; 231 | 232 | #endif 233 | 234 | /** 235 | * Bitstream encoder - for writing compressed files. 236 | */ 237 | typedef struct bit_encode_s bit_encode_t; 238 | 239 | /** 240 | * Attach bitstream encoder to a file. 241 | */ 242 | bit_encode_t *bit_encode_attach(FILE *outfh); 243 | 244 | /** 245 | * Retain pointer to a bit encoder. 246 | */ 247 | bit_encode_t *bit_encode_retain(bit_encode_t *be); 248 | 249 | /** 250 | * Release pointer to a bit encoder. 251 | * 252 | * Note that this does NOT flush any leftover bits. 253 | */ 254 | int bit_encode_free(bit_encode_t *be); 255 | 256 | /** 257 | * Write bits to encoder. 258 | */ 259 | int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits); 260 | 261 | /** 262 | * Write lowest-order bits of codeword to encoder. 263 | */ 264 | int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits); 265 | 266 | /** 267 | * Flush any unwritten bits, zero-padding if necessary. 268 | */ 269 | int bit_encode_flush(bit_encode_t *be); 270 | 271 | /** 272 | * There is no bitstream decoder, because a stream abstraction is too 273 | * slow. Instead we read blocks of bits and treat them as bitvectors. 274 | */ 275 | 276 | /** 277 | * Like fread_retry, but for stat. Arguments identical to regular stat. 278 | * Return value: 0 if successful, -1 if stat failed several attempts. 279 | */ 280 | SPHINXBASE_EXPORT 281 | int32 stat_retry (const char *file, struct stat *statbuf); 282 | 283 | /** 284 | * Return time of last modification for the given file, or -1 if stat fails. 285 | */ 286 | 287 | SPHINXBASE_EXPORT 288 | int32 stat_mtime (const char *file); 289 | 290 | /** 291 | * Create a directory and all of its parent directories, as needed. 292 | * 293 | * @return 0 on success, <0 on failure. 294 | */ 295 | SPHINXBASE_EXPORT 296 | int build_directory(const char *path); 297 | 298 | #ifdef __cplusplus 299 | } 300 | #endif 301 | 302 | #endif 303 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/prim_type.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * prim_type.h -- Primitive types; more machine-independent. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: prim_type.h,v $ 49 | * Revision 1.12 2005/10/05 00:31:14 dhdfu 50 | * Make int8 be explicitly signed (signedness of 'char' is 51 | * architecture-dependent). Then make a bunch of things use uint8 where 52 | * signedness is unimportant, because on the architecture where 'char' is 53 | * unsigned, it is that way for a reason (signed chars are slower). 54 | * 55 | * Revision 1.11 2005/06/22 03:10:23 arthchan2003 56 | * Added keyword. 57 | * 58 | * Revision 1.3 2005/03/30 01:22:48 archan 59 | * Fixed mistakes in last updates. Add 60 | * 61 | * 62 | * 12-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 63 | * Added arraysize_t, point_t, fpoint_t. 64 | * 65 | * 01-Feb-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 66 | * Added anytype_t. 67 | * 68 | * 08-31-95 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 69 | * Created. 70 | */ 71 | 72 | 73 | #ifndef _LIBUTIL_PRIM_TYPE_H_ 74 | #define _LIBUTIL_PRIM_TYPE_H_ 75 | 76 | /** 77 | * @file prim_type.h 78 | * @brief Basic type definitions used in Sphinx. 79 | */ 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | #if 0 85 | } /* Fool Emacs into not indenting things. */ 86 | #endif 87 | 88 | #include 89 | 90 | /* Define some things for VisualDSP++ */ 91 | #if defined(__ADSPBLACKFIN__) && !defined(__GNUC__) 92 | # ifndef HAVE_LONG_LONG 93 | # define HAVE_LONG_LONG 94 | # endif 95 | # ifndef ssize_t 96 | typedef signed int ssize_t; 97 | # endif 98 | # define SIZEOF_LONG_LONG 8 99 | # define __BIGSTACKVARIABLE__ static 100 | #else /* Not VisualDSP++ */ 101 | # define __BIGSTACKVARIABLE__ 102 | #endif 103 | 104 | /** 105 | * Union of basic types. 106 | */ 107 | typedef union anytype_s { 108 | void *ptr; 109 | long i; 110 | unsigned long ui; 111 | double fl; 112 | } anytype_t; 113 | 114 | /* 115 | * Assume P64 or LP64. If you need to port this to a DSP, let us know. 116 | */ 117 | typedef int int32; 118 | typedef short int16; 119 | typedef signed char int8; 120 | typedef unsigned int uint32; 121 | typedef unsigned short uint16; 122 | typedef unsigned char uint8; 123 | typedef float float32; 124 | typedef double float64; 125 | #if defined(_MSC_VER) 126 | typedef __int64 int64; 127 | typedef unsigned __int64 uint64; 128 | #elif defined(HAVE_LONG_LONG) && (SIZEOF_LONG_LONG == 8) 129 | typedef long long int64; 130 | typedef unsigned long long uint64; 131 | #else /* !HAVE_LONG_LONG && SIZEOF_LONG_LONG == 8 */ 132 | typedef double int64; 133 | typedef double uint64; 134 | #endif /* !HAVE_LONG_LONG && SIZEOF_LONG_LONG == 8 */ 135 | 136 | #ifndef TRUE 137 | #define TRUE 1 138 | #endif 139 | #ifndef FALSE 140 | #define FALSE 0 141 | #endif 142 | 143 | #ifndef NULL 144 | #define NULL (void *)0 145 | #endif 146 | 147 | /* These really ought to come from , but not everybody has that. */ 148 | /* Useful constants */ 149 | #define MAX_INT32 ((int32) 0x7fffffff) 150 | #define MAX_INT16 ((int16) 0x00007fff) 151 | #define MAX_INT8 ((int8) 0x0000007f) 152 | 153 | #define MAX_NEG_INT32 ((int32) 0x80000000) 154 | #define MAX_NEG_INT16 ((int16) 0xffff8000) 155 | #define MAX_NEG_INT8 ((int8) 0xffffff80) 156 | 157 | #define MAX_UINT32 ((uint32) 0xffffffff) 158 | #define MAX_UINT16 ((uint16) 0x0000ffff) 159 | #define MAX_UINT8 ((uint8) 0x000000ff) 160 | 161 | /* The following are approximate; IEEE floating point standards might quibble! */ 162 | #define MAX_POS_FLOAT32 3.4e+38f 163 | #define MIN_POS_FLOAT32 1.2e-38f /* But not 0 */ 164 | #define MAX_POS_FLOAT64 1.8e+307 165 | #define MIN_POS_FLOAT64 2.2e-308 166 | 167 | #define MAX_IEEE_NORM_POS_FLOAT32 3.4e+38f 168 | #define MIN_IEEE_NORM_POS_FLOAT32 1.2e-38f 169 | #define MIN_IEEE_NORM_NEG_FLOAT32 -3.4e+38f 170 | #define MAX_IEEE_NORM_POS_FLOAT64 1.8e+307 171 | #define MIN_IEEE_NORM_POS_FLOAT64 2.2e-308 172 | #define MIN_IEEE_NORM_NEG_FLOAT64 -1.8e+307 173 | 174 | /* Will the following really work?? */ 175 | #define MIN_NEG_FLOAT32 ((float32) (-MIN_POS_FLOAT32)) 176 | #define MIN_NEG_FLOAT64 ((float64) (-MIN_POS_FLOAT64)) 177 | 178 | 179 | #ifdef __cplusplus 180 | } 181 | #endif 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/profile.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1999-2001 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /* 38 | * profile.h -- For timing and event counting. 39 | * 40 | * ********************************************** 41 | * CMU ARPA Speech Project 42 | * 43 | * Copyright (c) 1999 Carnegie Mellon University. 44 | * ALL RIGHTS RESERVED. 45 | * ********************************************** 46 | * 47 | * HISTORY 48 | * $Log: profile.h,v $ 49 | * Revision 1.10 2005/06/22 03:10:59 arthchan2003 50 | * 1, Fixed doxygen documentation, 2, Added keyword. 51 | * 52 | * Revision 1.5 2005/06/15 04:21:47 archan 53 | * 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file. 54 | * 55 | * Revision 1.4 2005/04/25 19:22:48 archan 56 | * Refactor out the code of rescoring from lexical tree. Potentially we want to turn off the rescoring if we need. 57 | * 58 | * Revision 1.3 2005/03/30 01:22:48 archan 59 | * Fixed mistakes in last updates. Add 60 | * 61 | * 62 | * 11-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 63 | * Added ptmr_init(). 64 | * 65 | * 19-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 66 | * Created from earlier Sphinx-3 version. 67 | */ 68 | 69 | 70 | #ifndef _LIBUTIL_PROFILE_H_ 71 | #define _LIBUTIL_PROFILE_H_ 72 | 73 | #ifdef __cplusplus 74 | extern "C" { 75 | #endif 76 | #if 0 77 | } /* Fool Emacs into not indenting things. */ 78 | #endif 79 | 80 | /** \file profile.h 81 | * \brief Implementation of profiling, include counting , timing, cpu clock checking 82 | * 83 | * Currently, function host_endian is also in this function. It is 84 | * not documented. 85 | */ 86 | 87 | #include 88 | 89 | /* Win32/WinCE DLL gunk */ 90 | #include 91 | #include 92 | 93 | 94 | /** 95 | * \struct pctr_t 96 | * 97 | * Generic event counter for profiling. User is responsible for allocating an array 98 | * of the desired number. There should be a sentinel with name = NULL. 99 | */ 100 | typedef struct { 101 | char *name; /**< Counter print name; NULL 102 | terminates array of counters 103 | Used by pctr_print_all */ 104 | int32 count; /**< Counter value */ 105 | } pctr_t; 106 | 107 | /** 108 | * operations of pctr_t 109 | */ 110 | 111 | /** 112 | * Initialize a counter 113 | * @return an initialized counter 114 | */ 115 | SPHINXBASE_EXPORT 116 | pctr_t* pctr_new ( 117 | char *name /**< The name of the counter */ 118 | ); 119 | 120 | /** 121 | * Reset a counter 122 | */ 123 | 124 | SPHINXBASE_EXPORT 125 | void pctr_reset (pctr_t *ctr /**< A pointer of a counter */ 126 | ); 127 | 128 | /** 129 | * Print a counter 130 | */ 131 | SPHINXBASE_EXPORT 132 | void pctr_print(FILE *fp, /**< A file pointer */ 133 | pctr_t *ctr /**< A pointer of a counter */ 134 | ); 135 | 136 | /** 137 | * Increment a counter 138 | */ 139 | SPHINXBASE_EXPORT 140 | void pctr_increment (pctr_t *ctr, /**< A pointer of a counter */ 141 | int32 inc /**< The increment of the counter */ 142 | ); 143 | 144 | /** 145 | Free the counter 146 | */ 147 | SPHINXBASE_EXPORT 148 | void pctr_free(pctr_t* ctr /**< A pointer of a counter */ 149 | ); 150 | 151 | 152 | /** 153 | * \struct ptmr_t 154 | * Generic timer structures and functions for coarse-grained performance measurements 155 | * using standard system calls. 156 | */ 157 | typedef struct { 158 | const char *name; /**< Timer print name; NULL terminates an array of timers. 159 | Used by ptmr_print_all */ 160 | float64 t_cpu; /**< CPU time accumulated since most recent reset op */ 161 | float64 t_elapsed; /**< Elapsed time accumulated since most recent reset */ 162 | float64 t_tot_cpu; /**< Total CPU time since creation */ 163 | float64 t_tot_elapsed; /**< Total elapsed time since creation */ 164 | float64 start_cpu; /**< ---- FOR INTERNAL USE ONLY ---- */ 165 | float64 start_elapsed; /**< ---- FOR INTERNAL USE ONLY ---- */ 166 | } ptmr_t; 167 | 168 | 169 | 170 | /** Start timing using tmr */ 171 | SPHINXBASE_EXPORT 172 | void ptmr_start (ptmr_t *tmr /**< The timer*/ 173 | ); 174 | 175 | /** Stop timing and accumulate tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed} */ 176 | SPHINXBASE_EXPORT 177 | void ptmr_stop (ptmr_t *tmr /**< The timer*/ 178 | ); 179 | 180 | /** Reset tmr->{t_cpu, t_elapsed} to 0.0 */ 181 | SPHINXBASE_EXPORT 182 | void ptmr_reset (ptmr_t *tmr /**< The timer*/ 183 | ); 184 | 185 | /** Reset tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed} to 0.0 186 | */ 187 | SPHINXBASE_EXPORT 188 | void ptmr_init (ptmr_t *tmr /**< The timer*/ 189 | ); 190 | 191 | 192 | /** 193 | * Reset t_cpu, t_elapsed of all timer modules in array tmr[] to 0.0. 194 | * The array should be terminated with a sentinel with .name = NULL. 195 | */ 196 | SPHINXBASE_EXPORT 197 | void ptmr_reset_all (ptmr_t *tmr /**< The timer*/ 198 | ); 199 | 200 | /** 201 | * Print t_cpu for all timer modules in tmr[], normalized by norm (i.e., t_cpu/norm). 202 | * The array should be terminated with a sentinel with .name = NULL. 203 | */ 204 | SPHINXBASE_EXPORT 205 | void ptmr_print_all (FILE *fp, /**< The file pointer */ 206 | ptmr_t *tmr, /**< The timer*/ 207 | float64 norm 208 | ); 209 | 210 | 211 | /** 212 | * Return the processor clock speed (in MHz); only available on some machines (Alphas). 213 | * The dummy argument can be any integer value. 214 | */ 215 | SPHINXBASE_EXPORT 216 | int32 host_pclk (int32 dummy); 217 | 218 | 219 | /* 220 | * Check the native byte-ordering of the machine by writing a magic 221 | * number to a temporary file and reading it back. * Return value: 222 | * 0 if BIG-ENDIAN, 1 if LITTLE-ENDIAN, -1 if error. 223 | */ 224 | SPHINXBASE_EXPORT 225 | int32 host_endian ( void ); 226 | 227 | #ifdef __cplusplus 228 | } 229 | #endif 230 | 231 | #endif 232 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/sbthread.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 2008 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /** 38 | * @file sbthread.h 39 | * @brief Simple portable thread functions. 40 | * @author David Huggins-Daines 41 | **/ 42 | 43 | #ifndef __SBTHREAD_H__ 44 | #define __SBTHREAD_H__ 45 | 46 | #include 47 | 48 | #include 49 | #include 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | #if 0 55 | /* Fool Emacs. */ 56 | } 57 | #endif 58 | 59 | /** 60 | * Thread object. 61 | */ 62 | typedef struct sbthread_s sbthread_t; 63 | 64 | /** 65 | * Asynchronous message queue object. 66 | */ 67 | typedef struct sbmsgq_s sbmsgq_t; 68 | 69 | /** 70 | * Mutex (critical section) object. 71 | */ 72 | typedef struct sbmtx_s sbmtx_t; 73 | 74 | /** 75 | * Event object. 76 | */ 77 | typedef struct sbevent_s sbevent_t; 78 | 79 | /** 80 | * Entry point for a thread. 81 | */ 82 | typedef int (*sbthread_main)(sbthread_t *th); 83 | 84 | /** 85 | * Start a new thread. 86 | */ 87 | SPHINXBASE_EXPORT 88 | sbthread_t *sbthread_start(cmd_ln_t *config, sbthread_main func, void *arg); 89 | 90 | /** 91 | * Wait for a thread to complete. 92 | */ 93 | SPHINXBASE_EXPORT 94 | int sbthread_wait(sbthread_t *th); 95 | 96 | /** 97 | * Free a thread object. 98 | */ 99 | SPHINXBASE_EXPORT 100 | void sbthread_free(sbthread_t *th); 101 | 102 | /** 103 | * Get configuration object from a thread. 104 | */ 105 | SPHINXBASE_EXPORT 106 | cmd_ln_t *sbthread_config(sbthread_t *th); 107 | 108 | /** 109 | * Get argument pointer from a thread. 110 | */ 111 | SPHINXBASE_EXPORT 112 | void *sbthread_arg(sbthread_t *th); 113 | 114 | /** 115 | * Get message queue from a thread. 116 | */ 117 | SPHINXBASE_EXPORT 118 | sbmsgq_t *sbthread_msgq(sbthread_t *th); 119 | 120 | /** 121 | * Wait for a thread to complete. 122 | */ 123 | SPHINXBASE_EXPORT 124 | int sbthread_wait(sbthread_t *th); 125 | 126 | /** 127 | * Send an asynchronous message to a thread. 128 | * 129 | * Each thread gets a message queue by default, so this is just a 130 | * wrapper around sbmsgq_send(). 131 | */ 132 | SPHINXBASE_EXPORT 133 | int sbthread_send(sbthread_t *th, size_t len, void const *data); 134 | 135 | /** 136 | * Create a message queue. 137 | * 138 | * @param depth Depth of the queue. 139 | */ 140 | SPHINXBASE_EXPORT 141 | sbmsgq_t *sbmsgq_init(size_t depth); 142 | 143 | /** 144 | * Free a message queue. 145 | */ 146 | SPHINXBASE_EXPORT 147 | void sbmsgq_free(sbmsgq_t *q); 148 | 149 | /** 150 | * Post a message to a queue. 151 | */ 152 | SPHINXBASE_EXPORT 153 | int sbmsgq_send(sbmsgq_t *q, size_t len, void const *data); 154 | 155 | /** 156 | * Wait for a message from a queue. 157 | */ 158 | SPHINXBASE_EXPORT 159 | void *sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec); 160 | 161 | /** 162 | * Create a mutex. 163 | */ 164 | SPHINXBASE_EXPORT 165 | sbmtx_t *sbmtx_init(void); 166 | 167 | /** 168 | * Try to acquire a mutex. 169 | */ 170 | SPHINXBASE_EXPORT 171 | int sbmtx_trylock(sbmtx_t *mtx); 172 | 173 | /** 174 | * Acquire a mutex. 175 | */ 176 | SPHINXBASE_EXPORT 177 | int sbmtx_lock(sbmtx_t *mtx); 178 | 179 | /** 180 | * Release a mutex. 181 | */ 182 | SPHINXBASE_EXPORT 183 | int sbmtx_unlock(sbmtx_t *mtx); 184 | 185 | /** 186 | * Dispose of a mutex. 187 | */ 188 | SPHINXBASE_EXPORT 189 | void sbmtx_free(sbmtx_t *mtx); 190 | 191 | /** 192 | * Initialize an event. 193 | */ 194 | SPHINXBASE_EXPORT 195 | sbevent_t *sbevent_init(void); 196 | 197 | /** 198 | * Free an event. 199 | */ 200 | SPHINXBASE_EXPORT 201 | void sbevent_free(sbevent_t *evt); 202 | 203 | /** 204 | * Signal an event. 205 | */ 206 | SPHINXBASE_EXPORT 207 | int sbevent_signal(sbevent_t *evt); 208 | 209 | /** 210 | * Wait for an event to be signalled. 211 | */ 212 | SPHINXBASE_EXPORT 213 | int sbevent_wait(sbevent_t *evt, int sec, int nsec); 214 | 215 | 216 | #ifdef __cplusplus 217 | } 218 | #endif 219 | 220 | 221 | #endif /* __SBTHREAD_H__ */ 222 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/sphinx_config.h: -------------------------------------------------------------------------------- 1 | /* include/sphinx_config.h. Generated from sphinx_config.h.in by configure. */ 2 | /* sphinx_config.h: Externally visible configuration parameters */ 3 | 4 | /* Default radix point for fixed-point */ 5 | /* #undef DEFAULT_RADIX */ 6 | 7 | /* Use Q15 fixed-point computation */ 8 | /* #undef FIXED16 */ 9 | 10 | /* Use fixed-point computation */ 11 | /* #undef FIXED_POINT */ 12 | 13 | /* The size of `long', as computed by sizeof. */ 14 | #define SIZEOF_LONG 4 15 | 16 | /* Define to 1 if the system has the type `long long'. */ 17 | #define HAVE_LONG_LONG 1 18 | 19 | /* The size of `long long', as computed by sizeof. */ 20 | #define SIZEOF_LONG_LONG 8 21 | 22 | /* Enable debugging output */ 23 | /* #undef SPHINX_DEBUG */ 24 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/sphinxbase_export.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPHINXBASE_EXPORT_H__ 2 | #define __SPHINXBASE_EXPORT_H__ 3 | 4 | /* Win32/WinCE DLL gunk */ 5 | #if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(_WIN32_WP) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__WINSCW__) && !defined(__SYMBIAN32__) 6 | #if defined(SPHINXBASE_EXPORTS) /* Visual Studio */ 7 | #define SPHINXBASE_EXPORT __declspec(dllexport) 8 | #else 9 | #define SPHINXBASE_EXPORT __declspec(dllimport) 10 | #endif 11 | #else /* !_WIN32 */ 12 | #define SPHINXBASE_EXPORT 13 | #endif 14 | 15 | #endif /* __SPHINXBASE_EXPORT_H__ */ 16 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/strfuncs.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1995-2004 Carnegie Mellon University. All rights 4 | * reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * This work was supported in part by funding from the Defense Advanced 19 | * Research Projects Agency and the National Science Foundation of the 20 | * United States of America, and the CMU Sphinx Speech Consortium. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 23 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 26 | * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * ==================================================================== 35 | * 36 | */ 37 | /** 38 | * @file strfuncs.h 39 | * @brief Miscellaneous useful string functions 40 | */ 41 | 42 | #ifndef __SB_STRFUNCS_H__ 43 | #define __SB_STRFUNCS_H__ 44 | 45 | #include 46 | 47 | /* Win32/WinCE DLL gunk */ 48 | #include 49 | #include 50 | 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | #if 0 56 | /* Fool Emacs. */ 57 | } 58 | #endif 59 | 60 | /** 61 | * Concatenate a NULL-terminated argument list of strings, returning a 62 | * newly allocated string. 63 | **/ 64 | SPHINXBASE_EXPORT 65 | char *string_join(const char *base, ...); 66 | 67 | /** 68 | * Which end of a string to operate on for string_trim(). 69 | */ 70 | enum string_edge_e { 71 | STRING_START, /**< Beginning of string. */ 72 | STRING_END, /**< End of string. */ 73 | STRING_BOTH /**< Both ends of string. */ 74 | }; 75 | 76 | /** 77 | * Remove whitespace from a string, modifying it in-place. 78 | * 79 | * @param string string to trim, contents will be modified. 80 | * @param which one of STRING_START, STRING_END, or STRING_BOTH. 81 | */ 82 | SPHINXBASE_EXPORT 83 | char *string_trim(char *string, enum string_edge_e which); 84 | 85 | /** 86 | * Locale independent version of atof(). 87 | * 88 | * This function behaves like atof() in the "C" locale. Switching 89 | * locale in a threaded program is extremely uncool, therefore we need 90 | * this since we pass floats as strings in 1000 different places. 91 | */ 92 | SPHINXBASE_EXPORT 93 | double atof_c(char const *str); 94 | 95 | /* FIXME: Both of these string splitting functions basically suck. I 96 | have attempted to fix them as best I can. (dhuggins@cs, 20070808) */ 97 | 98 | /** 99 | * Convert a line to an array of "words", based on whitespace separators. A word 100 | * is a string with no whitespace chars in it. 101 | * Note that the string line is modified as a result: NULL chars are placed after 102 | * every word in the line. 103 | * Return value: No. of words found; -1 if no. of words in line exceeds n_wptr. 104 | */ 105 | SPHINXBASE_EXPORT 106 | int32 str2words (char *line, /**< In/Out: line to be parsed. This 107 | string will be modified! (NUL 108 | characters inserted at word 109 | boundaries) */ 110 | char **wptr, /**< In/Out: Array of pointers to 111 | words found in line. The array 112 | must be allocated by the caller. 113 | It may be NULL in which case the 114 | number of words will be counted. 115 | This allows you to allcate it to 116 | the proper size, e.g.: 117 | 118 | n = str2words(line, NULL, 0); 119 | wptr = ckd_calloc(n, sizeof(*wptr)); 120 | str2words(line, wptr, n); 121 | */ 122 | int32 n_wptr /**< In: Size of wptr array, ignored 123 | if wptr == NULL */ 124 | ); 125 | 126 | /** 127 | * Yet another attempt at a clean "next-word-in-string" function. See arguments below. 128 | * @return Length of word returned, or -1 if nothing found. 129 | * This allows you to scan through a line: 130 | * 131 | *
132 |  * while ((n = nextword(line, delim, &word, &delimfound)) >= 0) {
133 |  *     ... do something with word ..
134 |  *     word[n] = delimfound;
135 |  *     line = word + n;
136 |  * }
137 |  * 
138 | */ 139 | SPHINXBASE_EXPORT 140 | int32 nextword (char *line, /**< Input: String being searched for next word. 141 | Will be modified by this function (NUL characters inserted) */ 142 | const char *delim, /**< Input: A word, if found, must be delimited at either 143 | end by a character from this string (or at the end 144 | by the NULL char) */ 145 | char **word,/**< Output: *word = ptr within line to beginning of first 146 | word, if found. Delimiter at the end of word replaced 147 | with the NULL char. */ 148 | char *delimfound /**< Output: *delimfound = original delimiter found at the end 149 | of the word. (This way, the caller can restore the 150 | delimiter, preserving the original string.) */ 151 | ); 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | 158 | #endif /* __SB_STRFUNCS_H__ */ 159 | -------------------------------------------------------------------------------- /Sphinx/include/sphinxbase/yin.h: -------------------------------------------------------------------------------- 1 | /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright (c) 2008 Beyond Access, Inc. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY BEYOND ACCESS, INC. ``AS IS'' AND ANY 18 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEYOND ACCESS, INC. NOR 21 | * ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /** 31 | * @file yin.h 32 | * @brief Implementation of pitch estimation 33 | * @author David Huggins-Daines 34 | * 35 | * This implements part of the YIN algorithm: 36 | * 37 | * "YIN, a fundamental frequency estimator for speech and music". 38 | * Alain de Cheveigné and Hideki Kawahara. Journal of the Acoustical 39 | * Society of America, 111 (4), April 2002. 40 | */ 41 | 42 | #ifndef __YIN_H__ 43 | #define __YIN_H__ 44 | 45 | #ifdef __cplusplus 46 | extern "C" 47 | #endif 48 | #if 0 49 | } /* Fool Emacs. */ 50 | #endif 51 | 52 | /* Win32/WinCE DLL gunk */ 53 | #include 54 | #include 55 | 56 | /** 57 | * Frame-based moving-window pitch estimator. 58 | */ 59 | typedef struct yin_s yin_t; 60 | 61 | /** 62 | * Initialize moving-window pitch estimation. 63 | */ 64 | SPHINXBASE_EXPORT 65 | yin_t *yin_init(int frame_size, float search_threshold, 66 | float search_range, int smooth_window); 67 | 68 | /** 69 | * Free a moving-window pitch estimator. 70 | */ 71 | SPHINXBASE_EXPORT 72 | void yin_free(yin_t *pe); 73 | 74 | /** 75 | * Start processing an utterance. 76 | */ 77 | SPHINXBASE_EXPORT 78 | void yin_start(yin_t *pe); 79 | 80 | /** 81 | * Mark the end of an utterance. 82 | */ 83 | SPHINXBASE_EXPORT 84 | void yin_end(yin_t *pe); 85 | 86 | /** 87 | * Store a frame of data to the pitch estimator. 88 | * 89 | * @param pe Pitch estimator. 90 | * @param frame Frame of frame_size (see 91 | * yin_init()) samples of audio data. 92 | */ 93 | SPHINXBASE_EXPORT 94 | void yin_store(yin_t *pe, int16 const *frame); 95 | 96 | /** 97 | * Feed a frame of data to the pitch estimator. 98 | * 99 | * @param pe Pitch estimator. 100 | * @param frame Frame of frame_size (see 101 | * yin_init()) samples of audio data. 102 | */ 103 | SPHINXBASE_EXPORT 104 | void yin_write(yin_t *pe, int16 const *frame); 105 | 106 | /** 107 | * Feed stored frame of data to the pitch estimator. 108 | * (see yin_store()) 109 | * 110 | * @param pe Pitch estimator. 111 | */ 112 | SPHINXBASE_EXPORT 113 | void yin_write_stored(yin_t *pe); 114 | 115 | /** 116 | * Read a raw estimated pitch value from the pitch estimator. 117 | * 118 | * @param pe Pitch estimator. 119 | * @param out_period Output: an estimate of the period (*not* the pitch) 120 | * of the signal in samples. 121 | * @param out_bestdiff Output: the minimum normalized difference value 122 | * associated with *out_pitch, in Q15 123 | * format (i.e. scaled by 32768). This can be 124 | * interpreted as one minus the probability of voicing. 125 | * @return Non-zero if enough data was avaliable to return a pitch 126 | * estimate, zero otherwise. 127 | */ 128 | SPHINXBASE_EXPORT 129 | int yin_read(yin_t *pe, uint16 *out_period, float *out_bestdiff); 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif /* __YIN_H__ */ 136 | 137 | -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/arm64/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/arm64/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/armv7/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/armv7/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/armv7s/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/armv7s/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/i386/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/i386/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/pocketsphinx/x86_64/libpocketsphinx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/pocketsphinx/x86_64/libpocketsphinx.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/arm64/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/arm64/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/arm64/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/arm64/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/armv7/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/armv7/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/armv7/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/armv7/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/armv7s/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/armv7s/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/armv7s/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/armv7s/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/i386/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/i386/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/i386/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/i386/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/x86_64/libsphinxad.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/x86_64/libsphinxad.a -------------------------------------------------------------------------------- /Sphinx/lib/sphinxbase/x86_64/libsphinxbase.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/lib/sphinxbase/x86_64/libsphinxbase.a -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us.lm.dmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us.lm.dmp -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/feat.params: -------------------------------------------------------------------------------- 1 | -lowerf 130 2 | -upperf 6800 3 | -nfilt 25 4 | -transform dct 5 | -lifter 22 6 | -feat 1s_c_d_dd 7 | -svspec 0-12/13-25/26-38 8 | -agc none 9 | -cmn current 10 | -varnorm no 11 | -model ptm 12 | -cmninit 40,3,-1 13 | -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/mdef: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us/mdef -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/means: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us/means -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/noisedict: -------------------------------------------------------------------------------- 1 | SIL 2 | SIL 3 | SIL 4 | [NOISE] +NSN+ 5 | [SPEECH] +SPN+ 6 | -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/sendump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us/sendump -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/transition_matrices: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us/transition_matrices -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/en-us/variances: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/en-us/variances -------------------------------------------------------------------------------- /Sphinx/share/pocketsphinx/model/en-us/goforward.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmusphinx/TLSphinx/21ebea1c8c568e44d7194a3ca31d9d0ca4745e5d/Sphinx/share/pocketsphinx/model/en-us/goforward.raw -------------------------------------------------------------------------------- /TLSphinx.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TLSphinx.xcodeproj/xcshareddata/xcschemes/TLSphinx.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 79 | 85 | 86 | 87 | 88 | 89 | 90 | 96 | 97 | 103 | 104 | 105 | 106 | 108 | 109 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /TLSphinx/Config.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Config.swift 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Sphinx.Base 11 | 12 | public class Config { 13 | 14 | var cmdLnConf: COpaquePointer 15 | private var cArgs: [UnsafeMutablePointer] 16 | 17 | public init?(args: (String,String)...) { 18 | 19 | // Create [UnsafeMutablePointer]. 20 | cArgs = args.flatMap { (name, value) -> [UnsafeMutablePointer] in 21 | //strdup move the strings to the heap and return a UnsageMutablePointer 22 | return [strdup(name),strdup(value)] 23 | } 24 | 25 | cmdLnConf = cmd_ln_parse_r(nil, ps_args(), CInt(cArgs.count), &cArgs, STrue) 26 | 27 | if cmdLnConf == nil { 28 | return nil 29 | } 30 | } 31 | 32 | deinit { 33 | for cString in cArgs { 34 | free(cString) 35 | } 36 | 37 | cmd_ln_free_r(cmdLnConf) 38 | } 39 | 40 | 41 | public var showDebugInfo: Bool { 42 | get { 43 | if cmdLnConf != nil { 44 | return cmd_ln_str_r(cmdLnConf, "-logfn") == nil 45 | } else { 46 | return false 47 | } 48 | } 49 | set { 50 | if cmdLnConf != nil { 51 | if newValue { 52 | cmd_ln_set_str_r(cmdLnConf, "-logfn", nil) 53 | } else { 54 | cmd_ln_set_str_r(cmdLnConf, "-logfn", "/dev/null") 55 | } 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /TLSphinx/Decoder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Decoder.swift 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | import Sphinx 12 | 13 | 14 | private enum SpeechStateEnum : CustomStringConvertible { 15 | case Silence 16 | case Speech 17 | case Utterance 18 | 19 | var description: String { 20 | get { 21 | switch(self) { 22 | case .Silence: 23 | return "Silence" 24 | case .Speech: 25 | return "Speech" 26 | case .Utterance: 27 | return "Utterance" 28 | } 29 | } 30 | } 31 | } 32 | 33 | 34 | private extension AVAudioPCMBuffer { 35 | 36 | func toNSDate() -> NSData { 37 | let channels = UnsafeBufferPointer(start: int16ChannelData, count: 1) 38 | let ch0Data = NSData(bytes: channels[0], length:Int(frameCapacity * format.streamDescription.memory.mBytesPerFrame)) 39 | return ch0Data 40 | } 41 | 42 | } 43 | 44 | 45 | public class Decoder { 46 | 47 | private var psDecoder: COpaquePointer 48 | private var engine: AVAudioEngine! 49 | private var speechState: SpeechStateEnum 50 | 51 | public var bufferSize: Int = 2048 52 | 53 | public init?(config: Config) { 54 | 55 | speechState = .Silence 56 | 57 | if config.cmdLnConf != nil{ 58 | psDecoder = ps_init(config.cmdLnConf) 59 | 60 | if psDecoder == nil { 61 | return nil 62 | } 63 | 64 | } else { 65 | psDecoder = nil 66 | return nil 67 | } 68 | } 69 | 70 | deinit { 71 | let refCount = ps_free(psDecoder) 72 | assert(refCount == 0, "Can't free decoder, it's shared among instances") 73 | } 74 | 75 | private func process_raw(data: NSData) -> CInt { 76 | //Sphinx expect words of 2 bytes but the NSFileHandle read one byte at time so the lenght of the data for sphinx is the half of the real one. 77 | let dataLenght = data.length / 2 78 | let numberOfFrames = ps_process_raw(psDecoder, UnsafePointer(data.bytes), dataLenght, SFalse, SFalse) 79 | let hasSpeech = in_speech() 80 | 81 | switch (speechState) { 82 | case .Silence where hasSpeech: 83 | speechState = .Speech 84 | case .Speech where !hasSpeech: 85 | speechState = .Utterance 86 | case .Utterance where !hasSpeech: 87 | speechState = .Silence 88 | default: 89 | break 90 | } 91 | 92 | return numberOfFrames 93 | } 94 | 95 | private func in_speech() -> Bool { 96 | return ps_get_in_speech(psDecoder) == 1 97 | } 98 | 99 | private func start_utt() -> Bool { 100 | return ps_start_utt(psDecoder) == 0 101 | } 102 | 103 | private func end_utt() -> Bool { 104 | return ps_end_utt(psDecoder) == 0 105 | } 106 | 107 | private func get_hyp() -> Hypothesis? { 108 | var score: CInt = 0 109 | let string: UnsafePointer = ps_get_hyp(psDecoder, &score) 110 | 111 | if let text = String.fromCString(string) { 112 | return Hypothesis(text: text, score: Int(score)) 113 | } else { 114 | return nil 115 | } 116 | } 117 | 118 | private func hypotesisForSpeechAtPath (filePath: String) -> Hypothesis? { 119 | 120 | if let fileHandle = NSFileHandle(forReadingAtPath: filePath) { 121 | 122 | start_utt() 123 | 124 | let hypothesis = fileHandle.reduceChunks(bufferSize, initial: nil, reducer: { [unowned self] (data: NSData, partialHyp: Hypothesis?) -> Hypothesis? in 125 | 126 | self.process_raw(data) 127 | 128 | var resultantHyp = partialHyp 129 | if self.speechState == .Utterance { 130 | 131 | self.end_utt() 132 | resultantHyp = partialHyp + self.get_hyp() 133 | self.start_utt() 134 | } 135 | 136 | return resultantHyp 137 | }) 138 | 139 | end_utt() 140 | fileHandle.closeFile() 141 | 142 | //Process any pending speech 143 | if speechState == .Speech { 144 | return hypothesis + get_hyp() 145 | } else { 146 | return hypothesis 147 | } 148 | 149 | } else { 150 | return nil 151 | } 152 | } 153 | 154 | public func decodeSpeechAtPath (filePath: String, complete: (Hypothesis?) -> ()) { 155 | 156 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { 157 | 158 | let hypothesis = self.hypotesisForSpeechAtPath(filePath) 159 | 160 | dispatch_async(dispatch_get_main_queue()) { 161 | complete(hypothesis) 162 | } 163 | } 164 | } 165 | 166 | public func startDecodingSpeech (utteranceComplete: (Hypothesis?) -> ()) { 167 | 168 | do { 169 | try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord) 170 | } catch let error as NSError { 171 | print("Error setting the shared AVAudioSession: \(error)") 172 | return 173 | } 174 | 175 | engine = AVAudioEngine() 176 | 177 | guard let input = engine.inputNode else { 178 | print("Can't get input node") 179 | return 180 | } 181 | 182 | let formatIn = AVAudioFormat(commonFormat: .PCMFormatInt16, sampleRate: 44100, channels: 1, interleaved: false) 183 | engine.connect(input, to: engine.outputNode, format: formatIn) 184 | 185 | input.installTapOnBus(0, bufferSize: 4096, format: formatIn, block: { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in 186 | 187 | let audioData = buffer.toNSDate() 188 | self.process_raw(audioData) 189 | 190 | if self.speechState == .Utterance { 191 | 192 | self.end_utt() 193 | let hypothesis = self.get_hyp() 194 | 195 | dispatch_async(dispatch_get_main_queue(), { 196 | utteranceComplete(hypothesis) 197 | }) 198 | 199 | self.start_utt() 200 | } 201 | }) 202 | 203 | engine.mainMixerNode.outputVolume = 0.0 204 | engine.prepare() 205 | 206 | start_utt() 207 | 208 | do { 209 | try engine.start() 210 | } catch let error as NSError { 211 | end_utt() 212 | print("Can't start AVAudioEngine: \(error)") 213 | } 214 | } 215 | 216 | public func stopDecodingSpeech () { 217 | engine.stop() 218 | engine.mainMixerNode.removeTapOnBus(0) 219 | engine.reset() 220 | engine = nil 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /TLSphinx/Globals.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileHandle+Extension.swift 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | let STrue: CInt = 1 12 | let SFalse: CInt = 0 13 | 14 | extension NSFileHandle { 15 | 16 | func reduceChunks(size: Int, initial: T, reducer: (NSData, T) -> T) -> T { 17 | 18 | var reduceValue = initial 19 | var chuckData = readDataOfLength(size) 20 | 21 | while chuckData.length > 0 { 22 | reduceValue = reducer(chuckData, reduceValue) 23 | chuckData = readDataOfLength(size) 24 | } 25 | 26 | return reduceValue 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /TLSphinx/Hypotesis.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Hypothesis.swift 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 6/1/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Hypothesis { 12 | public let text: String 13 | public let score: Int 14 | } 15 | 16 | extension Hypothesis : CustomStringConvertible { 17 | 18 | public var description: String { 19 | get { 20 | return "Text: \(text) - Score: \(score)" 21 | } 22 | } 23 | 24 | } 25 | 26 | func +(lhs: Hypothesis, rhs: Hypothesis) -> Hypothesis { 27 | return Hypothesis(text: lhs.text + " " + rhs.text, score: (lhs.score + rhs.score) / 2) 28 | } 29 | 30 | func +(lhs: Hypothesis?, rhs: Hypothesis?) -> Hypothesis? { 31 | if let _lhs = lhs, let _rhs = rhs { 32 | return _lhs + _rhs 33 | } else { 34 | if let _lhs = lhs { 35 | return _lhs 36 | } else { 37 | return rhs 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /TLSphinx/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /TLSphinx/TLSphinx.h: -------------------------------------------------------------------------------- 1 | // 2 | // TLSphinx.h 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for TLSphinx. 12 | FOUNDATION_EXPORT double TLSphinxVersionNumber; 13 | 14 | //! Project version string for TLSphinx. 15 | FOUNDATION_EXPORT const unsigned char TLSphinxVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | @import Sphinx; -------------------------------------------------------------------------------- /TLSphinxTests/Basic.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TLSphinxTests.swift 3 | // TLSphinxTests 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | import TLSphinx 12 | 13 | 14 | class BasicTests: XCTestCase { 15 | 16 | func getModelPath() -> String? { 17 | return NSBundle(forClass: BasicTests.self).pathForResource("en-us", ofType: nil) 18 | } 19 | 20 | func testConfig() { 21 | 22 | if let modelPath = getModelPath() { 23 | 24 | let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us") 25 | let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp") 26 | let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict") 27 | 28 | let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) 29 | 30 | XCTAssert(config != nil, "Pass") 31 | 32 | } else { 33 | XCTFail("Can't access pocketsphinx model. Bundle root: \(NSBundle.mainBundle())") 34 | } 35 | } 36 | 37 | func testDecoder() { 38 | 39 | if let modelPath = getModelPath() { 40 | 41 | let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us") 42 | let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp") 43 | let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict") 44 | 45 | if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { 46 | let decoder = Decoder(config:config) 47 | 48 | XCTAssert(decoder != nil, "Pass") 49 | } else { 50 | XCTFail("Can't run test without a valid config") 51 | } 52 | 53 | } else { 54 | XCTFail("Can't access pocketsphinx model. Bundle root: \(NSBundle.mainBundle())") 55 | } 56 | } 57 | 58 | func testSpeechFromFile() { 59 | 60 | if let modelPath = getModelPath() { 61 | 62 | let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us") 63 | let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp") 64 | let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict") 65 | 66 | if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { 67 | if let decoder = Decoder(config:config) { 68 | 69 | let audioFile = (modelPath as NSString).stringByAppendingPathComponent("goforward.raw") 70 | let expectation = expectationWithDescription("Decode finish") 71 | 72 | decoder.decodeSpeechAtPath(audioFile) { 73 | 74 | if let hyp = $0 { 75 | 76 | print("Text: \(hyp.text) - Score: \(hyp.score)") 77 | XCTAssert(hyp.text == "go forward ten meters", "Pass") 78 | 79 | } else { 80 | XCTFail("Fail to decode audio") 81 | } 82 | 83 | expectation.fulfill() 84 | } 85 | 86 | waitForExpectationsWithTimeout(NSTimeIntervalSince1970, handler: { (_) -> Void in 87 | 88 | }) 89 | 90 | } else { 91 | XCTFail("Can't run test without a decoder") 92 | } 93 | 94 | } else { 95 | XCTFail("Can't run test without a valid config") 96 | } 97 | 98 | } else { 99 | XCTFail("Can't access pocketsphinx model. Bundle root: \(NSBundle.mainBundle())") 100 | } 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /TLSphinxTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /TLSphinxTests/LiveDecode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LiveDecode.swift 3 | // TLSphinx 4 | // 5 | // Created by Bruno Berisso on 5/29/15. 6 | // Copyright (c) 2015 Bruno Berisso. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | import AVFoundation 12 | import TLSphinx 13 | 14 | class LiveDecode: XCTestCase { 15 | 16 | func getModelPath() -> String? { 17 | return NSBundle(forClass: LiveDecode.self).pathForResource("en-us", ofType: nil) 18 | } 19 | 20 | func testAVAudioRecorder() { 21 | 22 | if let modelPath = getModelPath() { 23 | 24 | let hmm = (modelPath as NSString).stringByAppendingPathComponent("en-us") 25 | let lm = (modelPath as NSString).stringByAppendingPathComponent("en-us.lm.dmp") 26 | let dict = (modelPath as NSString).stringByAppendingPathComponent("cmudict-en-us.dict") 27 | 28 | if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) { 29 | 30 | config.showDebugInfo = false 31 | 32 | if let decoder = Decoder(config:config) { 33 | decoder.startDecodingSpeech { (hyp) -> () in 34 | print("Utterance: \(hyp)") 35 | } 36 | 37 | let expectation = expectationWithDescription("") 38 | 39 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(15.0 * Double(NSEC_PER_SEC))) , dispatch_get_main_queue(), { () -> Void in 40 | decoder.stopDecodingSpeech() 41 | expectation.fulfill() 42 | }) 43 | 44 | waitForExpectationsWithTimeout(NSTimeIntervalSince1970, handler: nil) 45 | } 46 | 47 | } else { 48 | XCTFail("Can't run test without a valid config") 49 | } 50 | 51 | } else { 52 | XCTFail("Can't access pocketsphinx model. Bundle root: \(NSBundle.mainBundle())") 53 | } 54 | } 55 | 56 | } 57 | --------------------------------------------------------------------------------