1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 1996-2004 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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.
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.
34 * ====================================================================
38 #ifndef __FE_INTERNAL_H__
39 #define __FE_INTERNAL_H__
45 #include "sphinxbase/fe.h"
46 #include "sphinxbase/fixpoint.h"
58 typedef int16 frame_t;
59 typedef int16 window_t;
60 typedef int32 powspec_t;
61 typedef struct { int16 r, i; } complex;
62 #elif defined(FIXED_POINT)
63 typedef fixed32 frame_t;
64 typedef int32 powspec_t;
65 typedef fixed32 window_t;
66 typedef struct { fixed32 r, i; } complex;
67 #else /* FIXED_POINT */
68 typedef float64 frame_t;
69 typedef float64 powspec_t;
70 typedef float64 window_t;
71 typedef struct { float64 r, i; } complex;
72 #endif /* FIXED_POINT */
74 /* Values for the 'logspec' field. */
80 /* Values for the 'transform' field. */
87 typedef struct melfb_s melfb_t;
88 /** Base Struct to hold all structure for MFCC computation. */
90 float32 sampling_rate;
94 float32 lower_filt_freq;
95 float32 upper_filt_freq;
96 /* DCT coefficients. */
98 /* Filter coefficients. */
103 /* Luxury mobile home. */
105 char const *warp_type;
106 char const *warp_params;
108 /* Precomputed normalization constants for unitary DCT-II/DCT-III */
109 mfcc_t sqrt_inv_n, sqrt_inv_2n;
110 /* Value and coefficients for HTK-style liftering */
113 /* Normalize filters to unit area */
115 /* Round filter frequencies to DFT points (hurts accuracy, but is
116 useful for legacy purposes) */
120 /* sqrt(1/2), also used for unitary DCT-II/DCT-III */
121 #define SQRT_HALF FLOAT2MFCC(0.707106781186548)
123 /** Structure for the front-end computation. */
128 float32 sampling_rate;
132 float32 window_length;
137 uint8 feature_dimension;
145 float32 pre_emphasis_alpha;
152 /* Twiddle factors for FFT. */
154 /* Mel filter parameters. */
156 /* Half of a Hamming Window. */
157 window_t *hamming_window;
159 /* Temporary buffers for processing. */
160 /* FIXME: too many of these. */
163 powspec_t *spec, *mfspec;
164 int16 *overflow_samps;
165 int16 num_overflow_samps;
169 #define BB_SAMPLING_RATE 16000
170 #define DEFAULT_BB_FFT_SIZE 512
171 #define DEFAULT_BB_FRAME_SHIFT 160
172 #define DEFAULT_BB_NUM_FILTERS 40
173 #define DEFAULT_BB_LOWER_FILT_FREQ 133.33334
174 #define DEFAULT_BB_UPPER_FILT_FREQ 6855.4976
176 #define NB_SAMPLING_RATE 8000
177 #define DEFAULT_NB_FFT_SIZE 256
178 #define DEFAULT_NB_FRAME_SHIFT 80
179 #define DEFAULT_NB_NUM_FILTERS 31
180 #define DEFAULT_NB_LOWER_FILT_FREQ 200
181 #define DEFAULT_NB_UPPER_FILT_FREQ 3500
183 void fe_init_dither(int32 seed);
185 /* Apply 1/2 bit noise to a buffer of audio. */
186 int32 fe_dither(int16 *buffer, int32 nsamps);
188 /* Load a frame of data into the fe. */
189 int fe_read_frame(fe_t *fe, int16 const *in, int32 len);
191 /* Shift the input buffer back and read more data. */
192 int fe_shift_frame(fe_t *fe, int16 const *in, int32 len);
194 /* Process a frame of data into features. */
195 int32 fe_write_frame(fe_t *fe, mfcc_t *fea);
197 /* Initialization functions. */
198 int32 fe_build_melfilters(melfb_t *MEL_FB);
199 int32 fe_compute_melcosine(melfb_t *MEL_FB);
200 void fe_create_hamming(window_t *in, int32 in_len);
201 void fe_create_twiddle(fe_t *fe);
203 /* Miscellaneous processing functions. */
204 void fe_spec2cep(fe_t * fe, const powspec_t * mflogspec, mfcc_t * mfcep);
205 void fe_dct2(fe_t *fe, const powspec_t *mflogspec, mfcc_t *mfcep, int htk);
206 void fe_dct3(fe_t *fe, const mfcc_t *mfcep, powspec_t *mflogspec);
212 #endif /* __FE_INTERNAL_H__ */