Debian Codegraph @

drivers/dahdi/ecdis.h

raw
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * ec_disable_detector.h - A detector which should eventually meet the
5 * G.164/G.165 requirements for detecting the
6 * 2100Hz echo cancellor disable tone.
7 *
8 * Written by Steve Underwood <[email protected]>
9 *
10 * Copyright (C) 2001 Steve Underwood
11 *
12 * All rights reserved.
13 *
14 */
15
16 /*
17 * See http://www.asterisk.org for more information about
18 * the Asterisk project. Please do not directly contact
19 * any of the maintainers of this project for assistance;
20 * the project provides a web site, mailing lists and IRC
21 * channels for your use.
22 *
23 * This program is free software, distributed under the terms of
24 * the GNU General Public License Version 2 as published by the
25 * Free Software Foundation. See the LICENSE file included with
26 * this program for more details.
27 */
28
29 #include "biquad.h"
30
31 #define FALSE 0
32 #define TRUE (!FALSE)
33
34 static inline void echo_can_disable_detector_init (echo_can_disable_detector_state_t *det)
35 {
36 /* Elliptic notch */
37 /* This is actually centred at 2095Hz, but gets the balance we want, due
38 to the asymmetric walls of the notch */
39 biquad2_init (&det->notch,
40 (int32_t) (-0.7600000*32768.0),
41 (int32_t) (-0.1183852*32768.0),
42 (int32_t) (-0.5104039*32768.0),
43 (int32_t) ( 0.1567596*32768.0),
44 (int32_t) ( 1.0000000*32768.0));
45
46 det->channel_level = 0;
47 det->notch_level = 0;
48 det->tone_present = FALSE;
49 det->tone_cycle_duration = 0;
50 det->good_cycles = 0;
51 det->hit = 0;
52 }
53 /*- End of function --------------------------------------------------------*/
54
55 static inline int echo_can_disable_detector_update (echo_can_disable_detector_state_t *det,
56 int16_t amp)
57 {
58 int16_t notched;
59
60 notched = biquad2 (&det->notch, amp);
61 /* Estimate the overall energy in the channel, and the energy in
62 the notch (i.e. overall channel energy - tone energy => noise).
63 Use abs instead of multiply for speed (is it really faster?).
64 Damp the overall energy a little more for a stable result.
65 Damp the notch energy a little less, so we don't damp out the
66 blip every time the phase reverses */
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 >= 70) {
70 /* There is adequate energy in the channel. Is it mostly at 2100Hz? */
71 if (det->notch_level*6 < det->channel_level) {
72 det->tone_cycle_duration++;
73 /* The notch says yes, so we have the tone. */
74 if (!det->tone_present) {
75 /* Do we get a kick every 450+-25ms? */
76 if ((det->tone_cycle_duration >= (425 * 8)) &&
77 (det->tone_cycle_duration <= (475 * 8))) {
78 /* It's ANS/PR (CED with polarity reversals), so wait
79 for at least three cycles before returning a hit. */
80 det->good_cycles++;
81 if (det->good_cycles > 2)
82 det->hit = TRUE;
83 }
84 det->tone_cycle_duration = 0;
85 det->tone_present = TRUE;
86 } else if (det->tone_cycle_duration >= 600 * 8) {
87 /* It's ANS (CED without polarity reversals)
88 so return a hit. */
89 det->hit = TRUE;
90 }
91 } else {
92 det->tone_present = FALSE;
93 }
94 } else {
95 det->tone_present = FALSE;
96 det->tone_cycle_duration = 0;
97 det->good_cycles = 0;
98 }
99
100 return det->hit;
101 }
102 /*- End of function --------------------------------------------------------*/
103 /*- End of file ------------------------------------------------------------*/