00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __FE_INTERNAL_H__
00039 #define __FE_INTERNAL_H__
00040
00041 #ifdef HAVE_CONFIG_H
00042 #include <config.h>
00043 #endif
00044
00045 #include <fe.h>
00046 #include <fixpoint.h>
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 #if 0
00052
00053 }
00054 #endif
00055
00056 #ifdef FIXED16
00057
00058 typedef int16 frame_t;
00059 typedef int16 window_t;
00060 typedef int32 powspec_t;
00061 typedef struct { int16 r, i; } complex;
00062 #elif defined(FIXED_POINT)
00063 typedef fixed32 frame_t;
00064 typedef int32 powspec_t;
00065 typedef fixed32 window_t;
00066 typedef struct { fixed32 r, i; } complex;
00067 #else
00068 typedef float64 frame_t;
00069 typedef float64 powspec_t;
00070 typedef float64 window_t;
00071 typedef struct { float64 r, i; } complex;
00072 #endif
00073
00074 #ifndef M_PI
00075 #define M_PI (3.14159265358979323846)
00076 #endif
00077
00078
00079 enum {
00080 RAW_LOG_SPEC = 1,
00081 SMOOTH_LOG_SPEC = 2
00082 };
00083
00084
00085 enum {
00086 LEGACY_DCT = 0,
00087 DCT_II = 1,
00088 DCT_HTK = 2
00089 };
00090
00091 typedef struct melfb_s melfb_t;
00093 struct melfb_s {
00094 float32 sampling_rate;
00095 int32 num_cepstra;
00096 int32 num_filters;
00097 int32 fft_size;
00098 float32 lower_filt_freq;
00099 float32 upper_filt_freq;
00100
00101 mfcc_t **mel_cosine;
00102
00103 mfcc_t *filt_coeffs;
00104 int16 *spec_start;
00105 int16 *filt_start;
00106 int16 *filt_width;
00107
00108 int32 doublewide;
00109 char const *warp_type;
00110 char const *warp_params;
00111 uint32 warp_id;
00112
00113 mfcc_t sqrt_inv_n, sqrt_inv_2n;
00114
00115 int32 lifter_val;
00116 mfcc_t *lifter;
00117
00118 int32 unit_area;
00119
00120
00121 int32 round_filters;
00122 };
00123
00124
00125 #define SQRT_HALF FLOAT2MFCC(0.707106781186548)
00126
00128 struct fe_s {
00129 cmd_ln_t *config;
00130 int refcount;
00131
00132 float32 sampling_rate;
00133 int16 frame_rate;
00134 int16 frame_shift;
00135
00136 float32 window_length;
00137 int16 frame_size;
00138 int16 fft_size;
00139
00140 uint8 fft_order;
00141 uint8 feature_dimension;
00142 uint8 num_cepstra;
00143 uint8 remove_dc;
00144 uint8 log_spec;
00145 uint8 swap;
00146 uint8 dither;
00147 uint8 transform;
00148
00149 float32 pre_emphasis_alpha;
00150 int32 seed;
00151
00152 int16 frame_counter;
00153 uint8 start_flag;
00154 uint8 reserved;
00155
00156
00157 frame_t *ccc, *sss;
00158
00159 melfb_t *mel_fb;
00160
00161 window_t *hamming_window;
00162
00163
00164
00165 int16 *spch;
00166 frame_t *frame;
00167 powspec_t *spec, *mfspec;
00168 int16 *overflow_samps;
00169 int16 num_overflow_samps;
00170 int16 prior;
00171 };
00172
00173 #define BB_SAMPLING_RATE 16000
00174 #define DEFAULT_BB_FFT_SIZE 512
00175 #define DEFAULT_BB_FRAME_SHIFT 160
00176 #define DEFAULT_BB_NUM_FILTERS 40
00177 #define DEFAULT_BB_LOWER_FILT_FREQ 133.33334
00178 #define DEFAULT_BB_UPPER_FILT_FREQ 6855.4976
00179
00180 #define NB_SAMPLING_RATE 8000
00181 #define DEFAULT_NB_FFT_SIZE 256
00182 #define DEFAULT_NB_FRAME_SHIFT 80
00183 #define DEFAULT_NB_NUM_FILTERS 31
00184 #define DEFAULT_NB_LOWER_FILT_FREQ 200
00185 #define DEFAULT_NB_UPPER_FILT_FREQ 3500
00186
00187 void fe_init_dither(int32 seed);
00188
00189
00190 int32 fe_dither(int16 *buffer, int32 nsamps);
00191
00192
00193 int fe_read_frame(fe_t *fe, int16 const *in, int32 len);
00194
00195
00196 int fe_shift_frame(fe_t *fe, int16 const *in, int32 len);
00197
00198
00199 int32 fe_write_frame(fe_t *fe, mfcc_t *fea);
00200
00201
00202 int32 fe_build_melfilters(melfb_t *MEL_FB);
00203 int32 fe_compute_melcosine(melfb_t *MEL_FB);
00204 void fe_create_hamming(window_t *in, int32 in_len);
00205 void fe_create_twiddle(fe_t *fe);
00206
00207
00208 void fe_spec2cep(fe_t * fe, const powspec_t * mflogspec, mfcc_t * mfcep);
00209 void fe_dct2(fe_t *fe, const powspec_t *mflogspec, mfcc_t *mfcep, int htk);
00210 void fe_dct3(fe_t *fe, const mfcc_t *mfcep, powspec_t *mflogspec);
00211
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215
00216 #endif