This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter.c
113 lines (92 loc) · 3.27 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
/*
ITU-T G.729A Speech Coder with Annex B ANSI-C Source Code
*/
/*
----------------------------------------------------------------------
COPYRIGHT NOTICE
----------------------------------------------------------------------
ITU-T G.729 Annex C ANSI C source code
Copyright (C) 1998, AT&T, France Telecom, NTT, University of
Sherbrooke. All rights reserved.
----------------------------------------------------------------------
*/
/***************************************/
/* General filter routines */
/***************************************/
#include "typedef.h"
#include "ld8a.h"
/*-----------------------------------------------------------*
* convolve - convolve vectors x and h and put result in y *
*-----------------------------------------------------------*/
void convolve(
FLOAT x[], /* input : input vector x[0:l] */
FLOAT h[], /* input : impulse response or second input h[0:l] */
FLOAT y[], /* output: x convolved with h , y[0:l] */
int l /* input : dimension of all vectors */
)
{
FLOAT temp;
int i, n;
for (n = 0; n < l; n++)
{
temp = (F)0.0;
for (i = 0; i <= n; i++)
temp += x[i]*h[n-i];
y[n] = temp;
}
return;
}
/*-----------------------------------------------------------*
* syn_filt - filter with synthesis filter 1/A(z) *
*-----------------------------------------------------------*/
void syn_filt(
FLOAT a[], /* input : predictor coefficients a[0:m] */
FLOAT x[], /* input : excitation signal */
FLOAT y[], /* output: filtered output signal */
int l, /* input : vector dimension */
FLOAT mem[], /* in/out: filter memory */
int update /* input : 0 = no memory update, 1 = update */
)
{
int i,j;
/* This is usually done by memory allocation (l+m) */
FLOAT yy_b[L_SUBFR+M];
FLOAT s, *yy, *py, *pa;
/* Copy mem[] to yy[] */
yy = yy_b;
for (i = 0; i <M; i++) *yy++ = *mem++;
/* Filtering */
for (i = 0; i < l; i++)
{
py=yy;
pa=a;
s = *x++;
for (j = 0; j <M; j++) s -= (*++pa) * (*--py);
*yy++ = s;
*y++ = s;
}
/* Update memory if required */
if(update !=0 ) for (i = 0; i <M; i++) *--mem =*--yy;
return;
}
/*-----------------------------------------------------------*
* residu - filter input vector with all-zero filter A(Z) *
*-----------------------------------------------------------*/
void residu( /* filter A(z) */
FLOAT *a, /* input : prediction coefficients a[0:m+1], a[0]=1. */
FLOAT *x, /* input : input signal x[0:l-1], x[-1:m] are needed */
FLOAT *y, /* output: output signal y[0:l-1] NOTE: x[] and y[]
cannot point to same array */
int l /* input : dimension of x and y */
)
{
FLOAT s;
int i, j;
for (i = 0; i < l; i++)
{
s = x[i];
for (j = 1; j <= M; j++) s += a[j]*x[i-j];
*y++ = s;
}
return;
}