0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "dsp_biquad.h"
0017
0018 struct ec_disable_detector_state {
0019 struct biquad2_state notch;
0020 int notch_level;
0021 int channel_level;
0022 int tone_present;
0023 int tone_cycle_duration;
0024 int good_cycles;
0025 int hit;
0026 };
0027
0028
0029 #define FALSE 0
0030 #define TRUE (!FALSE)
0031
0032 static inline void
0033 echo_can_disable_detector_init(struct ec_disable_detector_state *det)
0034 {
0035
0036
0037
0038 biquad2_init(&det->notch,
0039 (int32_t)(-0.7600000 * 32768.0),
0040 (int32_t)(-0.1183852 * 32768.0),
0041 (int32_t)(-0.5104039 * 32768.0),
0042 (int32_t)(0.1567596 * 32768.0),
0043 (int32_t)(1.0000000 * 32768.0));
0044
0045 det->channel_level = 0;
0046 det->notch_level = 0;
0047 det->tone_present = FALSE;
0048 det->tone_cycle_duration = 0;
0049 det->good_cycles = 0;
0050 det->hit = 0;
0051 }
0052
0053
0054 static inline int
0055 echo_can_disable_detector_update(struct ec_disable_detector_state *det,
0056 int16_t amp)
0057 {
0058 int16_t notched;
0059
0060 notched = biquad2(&det->notch, amp);
0061
0062
0063
0064
0065
0066
0067 det->channel_level += ((abs(amp) - det->channel_level) >> 5);
0068 det->notch_level += ((abs(notched) - det->notch_level) >> 4);
0069 if (det->channel_level > 280) {
0070
0071
0072 if (det->notch_level * 6 < det->channel_level) {
0073
0074 if (!det->tone_present) {
0075
0076 if (det->tone_cycle_duration >= 425 * 8
0077 && det->tone_cycle_duration <= 475 * 8) {
0078 det->good_cycles++;
0079 if (det->good_cycles > 2)
0080 det->hit = TRUE;
0081 }
0082 det->tone_cycle_duration = 0;
0083 }
0084 det->tone_present = TRUE;
0085 } else
0086 det->tone_present = FALSE;
0087 det->tone_cycle_duration++;
0088 } else {
0089 det->tone_present = FALSE;
0090 det->tone_cycle_duration = 0;
0091 det->good_cycles = 0;
0092 }
0093 return det->hit;
0094 }
0095
0096