1 
2    /******************************************************************
3 
4        iLBC Speech Coder ANSI-C Source Code
5 
6        iLBC_define.h
7 
8        Copyright (C) The Internet Society (2004).
9        All Rights Reserved.
10 
11    ******************************************************************/
12    #include <string.h>
13 
14    #ifndef __iLBC_ILBCDEFINE_H
15    #define __iLBC_ILBCDEFINE_H
16 
17    /* general codec settings */
18 
19    #define FS                      (float)8000.0
20    #define BLOCKL_20MS             160
21    #define BLOCKL_30MS             240
22    #define BLOCKL_MAX              240
23    #define NSUB_20MS               4
24    #define NSUB_30MS               6
25    #define NSUB_MAX            6
26    #define NASUB_20MS              2
27    #define NASUB_30MS              4
28    #define NASUB_MAX               4
29    #define SUBL                40
30    #define STATE_LEN               80
31    #define STATE_SHORT_LEN_30MS    58
32    #define STATE_SHORT_LEN_20MS    57
33 
34    /* LPC settings */
35 
36    #define LPC_FILTERORDER         10
37    #define LPC_CHIRP_SYNTDENUM     (float)0.9025
38    #define LPC_CHIRP_WEIGHTDENUM   (float)0.4222
39    #define LPC_LOOKBACK        60
40    #define LPC_N_20MS              1
41    #define LPC_N_30MS              2
42    #define LPC_N_MAX               2
43    #define LPC_ASYMDIFF        20
44    #define LPC_BW                  (float)60.0
45    #define LPC_WN                  (float)1.0001
46    #define LSF_NSPLIT              3
47 
48 
49    #define LSF_NUMBER_OF_STEPS     4
50    #define LPC_HALFORDER           (LPC_FILTERORDER/2)
51 
52    /* cb settings */
53 
54    #define CB_NSTAGES              3
55    #define CB_EXPAND               2
56    #define CB_MEML                 147
57    #define CB_FILTERLEN        2*4
58    #define CB_HALFFILTERLEN    4
59    #define CB_RESRANGE             34
60    #define CB_MAXGAIN              (float)1.3
61 
62    /* enhancer */
63 
64    #define ENH_BLOCKL              80  /* block length */
65    #define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)
66    #define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks
67                                           in said second sequence */
68    #define ENH_SLOP            2   /* max difference estimated and
69                                           correct pitch period */
70    #define ENH_PLOCSL              20  /* pitch-estimates and pitch-
71                                           locations buffer length */
72    #define ENH_OVERHANG        2
73    #define ENH_UPS0            4   /* upsampling rate */
74    #define ENH_FL0                 3   /* 2*FLO+1 is the length of
75                                           each filter */
76    #define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)
77    #define ENH_CORRDIM             (2*ENH_SLOP+1)
78    #define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)
79    #define ENH_NBLOCKS_EXTRA       5
80    #define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS +
81                                           ENH_NBLOCKS_EXTRA */
82    #define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL
83    #define ENH_ALPHA0              (float)0.05
84 
85    /* Down sampling */
86 
87    #define FILTERORDER_DS          7
88    #define DELAY_DS            3
89    #define FACTOR_DS               2
90 
91    /* bit stream defs */
92 
93    #define NO_OF_BYTES_20MS    38
94    #define NO_OF_BYTES_30MS    50
95    #define NO_OF_WORDS_20MS    19
96    #define NO_OF_WORDS_30MS    25
97    #define STATE_BITS              3
98    #define BYTE_LEN            8
99    #define ULP_CLASSES             3
100 
101    /* help parameters */
102 
103 
104 
105    #define FLOAT_MAX               (float)1.0e37
106    #define EPS                     (float)2.220446049250313e-016
107    #define PI                      (float)3.14159265358979323846
108    #define MIN_SAMPLE              -32768
109    #define MAX_SAMPLE              32767
110    #define TWO_PI                  (float)6.283185307
111    #define PI2                     (float)0.159154943
112 
113    /* type definition encoder instance */
114    typedef struct iLBC_ULP_Inst_t_ {
115        int lsf_bits[6][ULP_CLASSES+2];
116        int start_bits[ULP_CLASSES+2];
117        int startfirst_bits[ULP_CLASSES+2];
118        int scale_bits[ULP_CLASSES+2];
119        int state_bits[ULP_CLASSES+2];
120        int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];
121        int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];
122        int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
123        int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
124    } iLBC_ULP_Inst_t;
125 
126    /* type definition encoder instance */
127    typedef struct iLBC_Enc_Inst_t_ {
128 
129        /* flag for frame size mode */
130        int mode;
131 
132        /* basic parameters for different frame sizes */
133        int blockl;
134        int nsub;
135        int nasub;
136        int no_of_bytes, no_of_words;
137        int lpc_n;
138        int state_short_len;
139        const iLBC_ULP_Inst_t *ULP_inst;
140 
141        /* analysis filter state */
142        float anaMem[LPC_FILTERORDER];
143 
144        /* old lsf parameters for interpolation */
145        float lsfold[LPC_FILTERORDER];
146        float lsfdeqold[LPC_FILTERORDER];
147 
148        /* signal buffer for LP analysis */
149        float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
150 
151        /* state of input HP filter */
152        float hpimem[4];
153 
154    } iLBC_Enc_Inst_t;
155 
156    /* type definition decoder instance */
157    typedef struct iLBC_Dec_Inst_t_ {
158 
159 
160 
161        /* flag for frame size mode */
162        int mode;
163 
164        /* basic parameters for different frame sizes */
165        int blockl;
166        int nsub;
167        int nasub;
168        int no_of_bytes, no_of_words;
169        int lpc_n;
170        int state_short_len;
171        const iLBC_ULP_Inst_t *ULP_inst;
172 
173        /* synthesis filter state */
174        float syntMem[LPC_FILTERORDER];
175 
176        /* old LSF for interpolation */
177        float lsfdeqold[LPC_FILTERORDER];
178 
179        /* pitch lag estimated in enhancer and used in PLC */
180        int last_lag;
181 
182        /* PLC state information */
183        int prevLag, consPLICount, prevPLI, prev_enh_pl;
184        float prevLpc[LPC_FILTERORDER+1];
185        float prevResidual[NSUB_MAX*SUBL];
186        float per;
187        unsigned long seed;
188 
189        /* previous synthesis filter parameters */
190        float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
191 
192        /* state of output HP filter */
193        float hpomem[4];
194 
195        /* enhancer state information */
196        int use_enhancer;
197        float enh_buf[ENH_BUFL];
198        float enh_period[ENH_NBLOCKS_TOT];
199 
200    } iLBC_Dec_Inst_t;
201 
202    #endif
203 
204 
205