-
Notifications
You must be signed in to change notification settings - Fork 13
/
cha_fb.c
95 lines (82 loc) · 2.3 KB
/
cha_fb.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
// cha_fb.c - CHA filterbank-compressor processing functions
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "chapro.h"
#include "version.h"
/***********************************************************/
// compressor defaults
static void
cha_compressor_default_level(float *Lc, int np, int nc, double lv)
{
float Lcs, Lcm, Lce;
int k, kk;
static float Lmx = 120;
Lcs = (float) lv;
Lce = (Lcs < 100) ? 100 : Lcs;
Lcm = (Lcs + Lce) / 2;
/* loop over filterbank channel */
for (k = 0; k < nc; k++) {
kk = k * np;
Lc[kk + 0] = Lcs;
Lc[kk + 1] = Lcm;
Lc[kk + 2] = Lce;
Lc[kk + 3] = Lmx;
}
}
static void
cha_compressor_default_gain(float *Gc, int np, int nc, double gn)
{
float Gcs, Gcm, Gce;
int k, kk;
static float Gmx = 90;
Gcs = (float) gn;
Gce = 0;
Gcm = (Gcs + Gce) / 2;
/* loop over filterbank channel */
for (k = 0; k < nc; k++) {
kk = k * np;
Gc[kk + 0] = Gcs;
Gc[kk + 1] = Gcm;
Gc[kk + 2] = Gce;
Gc[kk + 3] = Gmx;
}
}
/***********************************************************/
#ifndef CHAPRO_H
FUNC(char *)
cha_version(void)
{
return (VER);
};
#endif
FUNC(void)
cha_fb_prepare(CHA_CLS *ss, double sr, double gn, double kp, int ds)
{
float Lc[32*4], Gc[32*4];
static int np = 4; /* number of level & gain parameters */
static double gd = 4; /* filterbank target delay (ms) [4] */
static double tw = 200; /* zero_gain buffer size (ms) [500] */
static double lr = 2e-5; /* level reference (Pa) */
// prepare filterbank
cha_filterbank_configure(ss, sr, gd, tw);
cha_filterbank_prepare(ss);
// prepare compressor
cha_compressor_default_level(Lc, np, ss->nc, kp);
cha_compressor_default_gain(Gc, np, ss->nc, gn);
cha_compressor_set_level(ss, Lc, lr, np, ds);
cha_compressor_set_gain(ss, Gc, np);
}
FUNC(void)
cha_fb_process(CHA_CLS *ss, float *x, float *y, int n)
{
cha_filterbank_analyze(ss, x, n);
cha_compressor_process(ss, n);
cha_filterbank_synthesize(ss, y, n);
}
FUNC(void)
cha_fb_cleanup(CHA_CLS *ss)
{
cha_filterbank_cleanup(ss);
cha_compressor_cleanup(ss);
}