-
Notifications
You must be signed in to change notification settings - Fork 1
/
firfb.c
100 lines (84 loc) · 2.28 KB
/
firfb.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
// firfb.c - CHAPRO/FIRFB plugin example for BTMHA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chapro.h>
#include "plugin_helper.h"
//===========================================================
static double cross_freq[MAX_CHN] = {
317.1666,502.9734,797.6319,1264.9,2005.9,3181.1,5044.7};
static int nchannel = 8;
static int icf = 0;
static int32_t nchan[2] = {1,1};
//===========================================================
static void
process0(void **cp, float *x, float *y, int cs)
{
cha_firfb_analyze(cp, x, y, cs);
}
static void
process1(void **cp, float *x, float *y, int cs)
{
cha_firfb_synthesize(cp, x, y, cs);
}
//===========================================================
// prepare FIR filterbank
static void
prepare_filterbank_fir(CHA_PTR cp, double sr, int cs)
{
double *cf;
int nc, nw, wt;
// prepare FIRFB
nc = pvl[icf].cols + 1;
cf = cross_freq;
nw = 256; // window size
wt = 0; // window type: 0=Hamming, 1=Blackman
cha_firfb_prepare(cp, cf, nc, sr, nw, wt, cs);
}
static void
prepare(CHA_STA *state, void *v, MHA *mha, int entry)
{
void **cp;
var_transfer(v);
cp = calloc(NPTR, sizeof(void *));
cha_prepare(cp);
prepare_filterbank_fir(cp, mha->sr, mha->cs);
cha_state_save(cp, state);
cha_cleanup(cp);
nchannel = pvl[icf].cols + 1;
if (entry == 0) {
state->proc = process0;
nchan[0] = 1;
nchan[1] = nchannel;
} else if (entry == 1) {
state->proc = process1;
nchan[0] = nchannel;
nchan[1] = 1;
} else {
state->proc = NULL;
nchan[0] = 0;
nchan[1] = 0;
}
state->type = 0; // state type is "plugin"
state->rprt = NULL;
state->entry = entry; // index of entry point
}
//===========================================================
static void
configure(void *v, int *nv)
{
int ncf;
// specify configurable parameters
ncf = nchannel - 1; // number of crossover frequencies
var_list_init(v);
put_list_i4a("nchan" , nchan, 2, 0); // read only
put_list_f8a("cross_freq" , cross_freq, ncf, MAX_CHN);
icf = npv - 1; // index to cross_freq
var_list_return(nv);
}
void
firfb_bind(PLUG* plugin)
{
plugin->configure = configure;
plugin->prepare = prepare;
}