~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to ecdis.h

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <steveu@coppice.org>
9
 
 *
10
 
 * Copyright (C) 2001 Steve Underwood
11
 
 *
12
 
 * All rights reserved.
13
 
 *
14
 
 * This program is free software; you can redistribute it and/or modify
15
 
 * it under the terms of the GNU General Public License as published by
16
 
 * the Free Software Foundation; either version 2 of the License, or
17
 
 * (at your option) any later version.
18
 
 *
19
 
 * This program is distributed in the hope that it will be useful,
20
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
 * GNU General Public License for more details.
23
 
 *
24
 
 * You should have received a copy of the GNU General Public License
25
 
 * along with this program; if not, write to the Free Software
26
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
 
 *
28
 
 */
29
 
 
30
 
#include "biquad.h"
31
 
 
32
 
typedef struct
33
 
{
34
 
    biquad2_state_t notch;
35
 
    int notch_level;
36
 
    int channel_level;
37
 
    int tone_present;
38
 
    int tone_cycle_duration;
39
 
    int good_cycles;
40
 
    int hit;
41
 
} echo_can_disable_detector_state_t;
42
 
 
43
 
 
44
 
#define FALSE 0
45
 
#define TRUE (!FALSE)
46
 
 
47
 
static inline void echo_can_disable_detector_init (echo_can_disable_detector_state_t *det)
48
 
{
49
 
    /* Elliptic notch */
50
 
    /* This is actually centred at 2095Hz, but gets the balance we want, due
51
 
       to the asymmetric walls of the notch */
52
 
    biquad2_init (&det->notch,
53
 
                  (int32_t) (-0.7600000*32768.0),
54
 
                  (int32_t) (-0.1183852*32768.0),
55
 
                  (int32_t) (-0.5104039*32768.0),
56
 
                  (int32_t) ( 0.1567596*32768.0),
57
 
                  (int32_t) ( 1.0000000*32768.0));
58
 
 
59
 
    det->channel_level = 0;
60
 
    det->notch_level = 0;    
61
 
    det->tone_present = FALSE;
62
 
    det->tone_cycle_duration = 0;
63
 
    det->good_cycles = 0;
64
 
    det->hit = 0;
65
 
}
66
 
/*- End of function --------------------------------------------------------*/
67
 
 
68
 
static inline int echo_can_disable_detector_update (echo_can_disable_detector_state_t *det,
69
 
                                      int16_t amp)
70
 
{
71
 
    int16_t notched;
72
 
    
73
 
        notched = biquad2 (&det->notch, amp);
74
 
        /* Estimate the overall energy in the channel, and the energy in
75
 
           the notch (i.e. overall channel energy - tone energy => noise).
76
 
           Use abs instead of multiply for speed (is it really faster?).
77
 
           Damp the overall energy a little more for a stable result.
78
 
           Damp the notch energy a little less, so we don't damp out the
79
 
           blip every time the phase reverses */
80
 
        det->channel_level += ((abs(amp) - det->channel_level) >> 5);
81
 
        det->notch_level += ((abs(notched) - det->notch_level) >> 4);
82
 
        if (det->channel_level > 280)
83
 
        {
84
 
            /* There is adequate energy in the channel. Is it mostly at 2100Hz? */
85
 
            if (det->notch_level*6 < det->channel_level)
86
 
            {
87
 
                /* The notch says yes, so we have the tone. */
88
 
                if (!det->tone_present)
89
 
                {
90
 
                    /* Do we get a kick every 450+-25ms? */
91
 
                    if (det->tone_cycle_duration >= 425*8
92
 
                        &&
93
 
                        det->tone_cycle_duration <= 475*8)
94
 
                    {
95
 
                        det->good_cycles++;
96
 
                        if (det->good_cycles > 2)
97
 
                            det->hit = TRUE;
98
 
                    }
99
 
                    det->tone_cycle_duration = 0;
100
 
                }
101
 
                det->tone_present = TRUE;
102
 
            }
103
 
            else
104
 
            {
105
 
                det->tone_present = FALSE;
106
 
            }
107
 
            det->tone_cycle_duration++;
108
 
        }
109
 
        else
110
 
        {
111
 
            det->tone_present = FALSE;
112
 
            det->tone_cycle_duration = 0;
113
 
            det->good_cycles = 0;
114
 
        }
115
 
    return  det->hit;
116
 
}
117
 
/*- End of function --------------------------------------------------------*/
118
 
/*- End of file ------------------------------------------------------------*/