-
Notifications
You must be signed in to change notification settings - Fork 13
/
ciirfb_prepare.c
109 lines (97 loc) · 2.54 KB
/
ciirfb_prepare.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
// ciirfb_prepare.c - complex filterbank preparation functions
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "chapro.h"
/***********************************************************/
static void
root2poly(
float *yr, float *yi,
float *x,
float *g,
int n
) {
float yyr, yyi;
int i, j, jr, ji;
fzero(yr, n + 1);
fzero(yi, n + 1);
yr[0] = 1;
for (j = 0; j < n; j++) {
jr = j * 2;
ji = jr + 1;
for (i = j; i >= 0; i--) {
yr[i + 1] -= yr[i] * x[jr] - yi[i] * x[ji];
yi[i + 1] -= yi[i] * x[jr] + yr[i] * x[ji];
}
}
if (g) {
for (i = 0; i <= n; i++) {
yyr = yr[i] * g[0] - yi[i] * g[1];
yyi = yi[i] * g[0] + yr[i] * g[1];
yr[i] = yyr;
yi[i] = yyi;
}
}
}
static void
zp2tf(
float *coef,
float *z, float *p, float *g,
int no, int nc
) {
float *br, *bi, *ar, *ai;
float *zz, *pp, *gg;
int j, op;
op = no + 1;
for (j = 0; j < nc; j++) {
zz = z + j * no * 2;
pp = p + j * no * 2;
br = coef + j * op * 4;
bi = br + op;
ar = bi + op;
ai = ar + op;
gg = g + j * 2;
root2poly(br, bi, zz, gg, no);
root2poly(ar, ai, pp, 0, no);
}
}
/***********************************************************/
static void
filterbank_prepare(CHA_PTR cp, float *z, float *p, float *g, int *d,
int nc, int no, double sr, int cs)
{
float *br;
int k, mxd, ns, op, *dn;
op = no + 1;
br = (float *) cha_allocate(cp, nc * op * 4, sizeof(float), _br);
zp2tf(br, z, p, g, no, nc);
cha_allocate(cp, nc * op * 4, sizeof(float), _zr);
//-----------------------------
dn = (int *) cha_allocate(cp, nc, sizeof(int), _dn);
mxd = 0;
/* find maximum delay */
for (k = 0; k < nc; k++) {
dn[k] = d[k];
if (mxd < dn[k]) {
mxd = dn[k];
}
}
ns = mxd + 1;
CHA_IVAR[_ns] = ns;
cha_allocate(cp, ns * nc * 2, sizeof(float), _ydr);
//-----------------------------
CHA_IVAR[_cs] = cs;
CHA_DVAR[_fs] = sr / 1000;
CHA_IVAR[_nc] = nc;
}
/***********************************************************/
FUNC(int)
cha_ciirfb_prepare(CHA_PTR cp, float *z, float *p, float *g, int *d,
int nc, int no, double sr, int cs)
{
cha_prepare(cp);
filterbank_prepare(cp, z, p, g, d, nc, no, sr, cs);
// allocate chunk buffer
cha_allocate(cp, nc * cs * 2, sizeof(float), _cc);
return (0);
}