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

« back to all changes in this revision

Viewing changes to kernel/fir.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
 * fir.h - General telephony FIR routines
 
5
 *
 
6
 * Written by Steve Underwood <steveu@coppice.org>
 
7
 *
 
8
 * Copyright (C) 2002 Steve Underwood
 
9
 *
 
10
 * All rights reserved.
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify
 
13
 * it under the terms of the GNU General Public License as published by
 
14
 * the Free Software Foundation; either version 2 of the License, or
 
15
 * (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
25
 *
 
26
 */
 
27
 
 
28
#if !defined(_FIR_H_)
 
29
#define _FIR_H_
 
30
 
 
31
typedef struct
 
32
{
 
33
    int taps;
 
34
    int curr_pos;
 
35
    int16_t *coeffs;
 
36
    int16_t *history;
 
37
} fir16_state_t;
 
38
 
 
39
typedef struct
 
40
{
 
41
    int taps;
 
42
    int curr_pos;
 
43
    int32_t *coeffs;
 
44
    int16_t *history;
 
45
} fir32_state_t;
 
46
 
 
47
static inline void fir16_create (fir16_state_t *fir,
 
48
                                 int16_t *coeffs,
 
49
                                 int taps)
 
50
{
 
51
    fir->taps = taps;
 
52
    fir->curr_pos = taps - 1;
 
53
    fir->coeffs = coeffs;
 
54
    fir->history = MALLOC (taps*sizeof (int16_t));
 
55
    if (fir->history)
 
56
        memset (fir->history, '\0', taps*sizeof (int16_t));
 
57
}
 
58
/*- End of function --------------------------------------------------------*/
 
59
    
 
60
static inline void fir16_free (fir16_state_t *fir)
 
61
{
 
62
    FREE (fir->history);
 
63
}
 
64
/*- End of function --------------------------------------------------------*/
 
65
    
 
66
static inline int16_t fir16 (fir16_state_t *fir, int16_t sample)
 
67
{
 
68
    int i;
 
69
    int offset1;
 
70
    int offset2;
 
71
    int32_t y;
 
72
 
 
73
    fir->history[fir->curr_pos] = sample;
 
74
    offset2 = fir->curr_pos + 1;
 
75
    offset1 = fir->taps - offset2;
 
76
    y = 0;
 
77
    for (i = fir->taps - 1;  i >= offset1;  i--)
 
78
        y += fir->coeffs[i]*fir->history[i - offset1];
 
79
    for (  ;  i >= 0;  i--)
 
80
        y += fir->coeffs[i]*fir->history[i + offset2];
 
81
    if (fir->curr_pos <= 0)
 
82
        fir->curr_pos = fir->taps;
 
83
    fir->curr_pos--;
 
84
    return  y >> 15;
 
85
}
 
86
/*- End of function --------------------------------------------------------*/
 
87
 
 
88
static inline void fir32_create (fir32_state_t *fir,
 
89
                                 int32_t *coeffs,
 
90
                                 int taps)
 
91
{
 
92
    fir->taps = taps;
 
93
    fir->curr_pos = taps - 1;
 
94
    fir->coeffs = coeffs;
 
95
    fir->history = MALLOC (taps*sizeof (int16_t));
 
96
    if (fir->history)
 
97
        memset (fir->history, '\0', taps*sizeof (int16_t));
 
98
}
 
99
/*- End of function --------------------------------------------------------*/
 
100
    
 
101
static inline void fir32_free (fir32_state_t *fir)
 
102
{
 
103
    FREE (fir->history);
 
104
}
 
105
/*- End of function --------------------------------------------------------*/
 
106
    
 
107
static inline int16_t fir32 (fir32_state_t *fir, int16_t sample)
 
108
{
 
109
    int i;
 
110
    int offset1;
 
111
    int offset2;
 
112
    int32_t y;
 
113
 
 
114
    fir->history[fir->curr_pos] = sample;
 
115
    offset2 = fir->curr_pos + 1;
 
116
    offset1 = fir->taps - offset2;
 
117
    y = 0;
 
118
    for (i = fir->taps - 1;  i >= offset1;  i--)
 
119
        y += fir->coeffs[i]*fir->history[i - offset1];
 
120
    for (  ;  i >= 0;  i--)
 
121
        y += fir->coeffs[i]*fir->history[i + offset2];
 
122
    if (fir->curr_pos <= 0)
 
123
        fir->curr_pos = fir->taps;
 
124
    fir->curr_pos--;
 
125
    return  y >> 15;
 
126
}
 
127
/*- End of function --------------------------------------------------------*/
 
128
 
 
129
#endif
 
130
/*- End of file ------------------------------------------------------------*/