-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter.c
129 lines (106 loc) · 3.64 KB
/
filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
ITU-T G.729A Speech Coder ANSI-C Source Code
Version 1.1 Last modified: September 1996
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies
All rights reserved.
*/
/*-------------------------------------------------------------------*
* Function Convolve: *
* ~~~~~~~~~ *
*-------------------------------------------------------------------*
* Perform the convolution between two vectors x[] and h[] and *
* write the result in the vector y[]. *
* All vectors are of length N. *
*-------------------------------------------------------------------*/
#include "typedef.h"
#include "basic_op.h"
#include "ld8a.h"
void Convolve(
int16_t x[], /* (i) : input vector */
int16_t h[], /* (i) Q12 : impulse response */
int16_t y[], /* (o) : output vector */
int16_t L /* (i) : vector size */
)
{
int16_t i, n;
int32_t s;
for (n = 0; n < L; n++)
{
s = 0;
for (i = 0; i <= n; i++)
s = L_mac(s, x[i], h[n-i]);
s = L_shl(s, 3); /* h is in Q12 and saturation */
y[n] = extract_h(s);
}
return;
}
/*-----------------------------------------------------*
* procedure Syn_filt: *
* ~~~~~~~~ *
* Do the synthesis filtering 1/A(z). *
*-----------------------------------------------------*/
void Syn_filt(
int16_t a[], /* (i) Q12 : a[m+1] prediction coefficients (m=10) */
int16_t x[], /* (i) : input signal */
int16_t y[], /* (o) : output signal */
int16_t lg, /* (i) : size of filtering */
int16_t mem[], /* (i/o) : memory associated with this filtering. */
int16_t update /* (i) : 0=no update, 1=update of memory. */
)
{
int16_t i, j;
int32_t s;
int16_t tmp[100]; /* This is usually done by memory allocation (lg+M) */
int16_t *yy;
/* Copy mem[] to yy[] */
yy = tmp;
for(i=0; i<M; i++)
{
*yy++ = mem[i];
}
/* Do the filtering. */
for (i = 0; i < lg; i++)
{
s = L_mult(x[i], a[0]);
for (j = 1; j <= M; j++)
s = L_msu(s, a[j], yy[-j]);
s = L_shl(s, 3);
*yy++ = _round(s);
}
for(i=0; i<lg; i++)
{
y[i] = tmp[i+M];
}
/* Update of memory if update==1 */
if(update != 0)
for (i = 0; i < M; i++)
{
mem[i] = y[lg-M+i];
}
return;
}
/*-----------------------------------------------------------------------*
* procedure Residu: *
* ~~~~~~ *
* Compute the LPC residual by filtering the input speech through A(z) *
*-----------------------------------------------------------------------*/
void Residu(
int16_t a[], /* (i) Q12 : prediction coefficients */
int16_t x[], /* (i) : speech (values x[-m..-1] are needed */
int16_t y[], /* (o) : residual signal */
int16_t lg /* (i) : size of filtering */
)
{
int16_t i, j;
int32_t s;
for (i = 0; i < lg; i++)
{
s = L_mult(x[i], a[0]);
for (j = 1; j <= M; j++)
s = L_mac(s, a[j], x[i-j]);
s = L_shl(s, 3);
y[i] = _round(s);
}
return;
}