FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/vad2.h @ 468:4104b0390fab
efrtest: new program gsmefr-dlcap-sync
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 13 May 2024 07:21:09 +0000 |
parents | 0152c069d01f |
children |
rev | line source |
---|---|
410
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : vad2.h |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Voice Activity Detection (VAD) for AMR (option 2) |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #ifndef vad2_h |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #define vad2_h "$Id $" |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "typedef.h" |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 /***** Defines ****/ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #define YES 1 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #define NO 0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 #define ON 1 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #define OFF 0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #define TRUE 1 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #define FALSE 0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #define FRM_LEN 80 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #define DELAY 24 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #define FFT_LEN 128 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #define NUM_CHAN 16 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #define LO_CHAN 0 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #define HI_CHAN 15 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #define UPDATE_THLD 35 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 #define HYSTER_CNT_THLD 6 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #define UPDATE_CNT_THLD 50 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 #define SHIFT_STATE_0 0 /* channel energy scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 #define SHIFT_STATE_1 1 /* channel energy scaled as 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 #define NOISE_FLOOR_CHAN_0 512 /* 1.0 scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 #define MIN_CHAN_ENRG_0 32 /* 0.0625 scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 #define MIN_NOISE_ENRG_0 32 /* 0.0625 scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 #define INE_NOISE_0 8192 /* 16.0 scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 #define FRACTIONAL_BITS_0 9 /* used as input to fn10Log10() */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 #define NOISE_FLOOR_CHAN_1 16 /* 1.0 scaled as 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 #define MIN_CHAN_ENRG_1 1 /* 0.0625 scaled as 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 #define MIN_NOISE_ENRG_1 1 /* 0.0625 scaled as 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 #define INE_NOISE_1 256 /* 16.0 scaled as 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 #define FRACTIONAL_BITS_1 4 /* used as input to fn10Log10() */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 #define STATE_1_TO_0_SHIFT_R (FRACTIONAL_BITS_1-FRACTIONAL_BITS_0) /* state correction factor */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 #define STATE_0_TO_1_SHIFT_R (FRACTIONAL_BITS_0-FRACTIONAL_BITS_1) /* state correction factor */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 #define HIGH_ALPHA 29491 /* 0.9 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 #define LOW_ALPHA 22938 /* 0.7 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 #define ALPHA_RANGE (HIGH_ALPHA - LOW_ALPHA) |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 #define DEV_THLD 7168 /* 28.0 scaled as 7,8 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 #define PRE_EMP_FAC (-26214) /* -0.8 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 #define CEE_SM_FAC 18022 /* 0.55 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 #define ONE_MINUS_CEE_SM_FAC 14746 /* 0.45 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 #define CNE_SM_FAC 3277 /* 0.1 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 #define ONE_MINUS_CNE_SM_FAC 29491 /* 0.9 scaled as 0,15 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 #define FFT_HEADROOM 2 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 typedef struct |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 { |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 Word16 pre_emp_mem; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 Word16 update_cnt; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 Word16 hyster_cnt; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 Word16 last_update_cnt; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 Word16 ch_enrg_long_db[NUM_CHAN]; /* scaled as 7,8 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 Word32 Lframe_cnt; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 Word32 Lch_enrg[NUM_CHAN]; /* scaled as 22,9 or 27,4 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 Word32 Lch_noise[NUM_CHAN]; /* scaled as 22,9 */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 Word16 last_normb_shift; /* last block norm shift count */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 Word16 tsnr; /* total signal-to-noise ratio in dB (scaled as 7,8) */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 Word16 hangover; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 Word16 burstcount; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 Word16 fupdate_flag; /* forced update flag from previous frame */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 Word16 negSNRvar; /* Negative SNR variance (scaled as 7,8) */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 Word16 negSNRbias; /* sensitivity bias from negative SNR variance (scaled as 15,0) */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 Word16 shift_state; /* use 22,9 or 27,4 scaling for ch_enrg[] */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 Word32 L_R0; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 Word32 L_Rmax; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 Flag LTP_flag; /* Use to indicate the the LTP gain is > LTP_THRESH */ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } vadState2; |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 /**** Prototypes ****/ |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 Word16 vad2 (Word16 *farray_ptr, vadState2 *st); |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 void vad2_reset (vadState2 *st); |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 void r_fft (Word16 *farray_ptr); |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 void LTP_flag_update (vadState2 *st, Word16 mode); |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
0152c069d01f
libtwamr: integrate VAD2 main body
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 #endif |