This source file includes following definitions.
- echo_can_disable_detector_init
- echo_can_disable_detector_update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include "dsp_biquad.h"
17
18 struct ec_disable_detector_state {
19 struct biquad2_state notch;
20 int notch_level;
21 int channel_level;
22 int tone_present;
23 int tone_cycle_duration;
24 int good_cycles;
25 int hit;
26 };
27
28
29 #define FALSE 0
30 #define TRUE (!FALSE)
31
32 static inline void
33 echo_can_disable_detector_init(struct ec_disable_detector_state *det)
34 {
35
36
37
38 biquad2_init(&det->notch,
39 (int32_t)(-0.7600000 * 32768.0),
40 (int32_t)(-0.1183852 * 32768.0),
41 (int32_t)(-0.5104039 * 32768.0),
42 (int32_t)(0.1567596 * 32768.0),
43 (int32_t)(1.0000000 * 32768.0));
44
45 det->channel_level = 0;
46 det->notch_level = 0;
47 det->tone_present = FALSE;
48 det->tone_cycle_duration = 0;
49 det->good_cycles = 0;
50 det->hit = 0;
51 }
52
53
54 static inline int
55 echo_can_disable_detector_update(struct ec_disable_detector_state *det,
56 int16_t amp)
57 {
58 int16_t notched;
59
60 notched = biquad2(&det->notch, amp);
61
62
63
64
65
66
67 det->channel_level += ((abs(amp) - det->channel_level) >> 5);
68 det->notch_level += ((abs(notched) - det->notch_level) >> 4);
69 if (det->channel_level > 280) {
70
71
72 if (det->notch_level * 6 < det->channel_level) {
73
74 if (!det->tone_present) {
75
76 if (det->tone_cycle_duration >= 425 * 8
77 && det->tone_cycle_duration <= 475 * 8) {
78 det->good_cycles++;
79 if (det->good_cycles > 2)
80 det->hit = TRUE;
81 }
82 det->tone_cycle_duration = 0;
83 }
84 det->tone_present = TRUE;
85 } else
86 det->tone_present = FALSE;
87 det->tone_cycle_duration++;
88 } else {
89 det->tone_present = FALSE;
90 det->tone_cycle_duration = 0;
91 det->good_cycles = 0;
92 }
93 return det->hit;
94 }
95
96