-
Notifications
You must be signed in to change notification settings - Fork 1
/
agc.c
139 lines (119 loc) · 3.58 KB
/
agc.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
130
131
132
133
134
135
136
137
// agc.c - CHAPRO/GHA plugin example for BTMHA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chapro.h>
#include "plugin_helper.h"
//===========================================================
static int icf = 0;
static int32_t nchan[2] = {1,1};
static CHA_DSL dsl = {0};
static CHA_WDRC agc = {0};
//===========================================================
static void
process0(void **cp, float *x, float *y, int cs)
{
cha_agc_input(cp, x, y, cs);
}
static void
process1(void **cp, float *x, float *y, int cs)
{
cha_agc_channel(cp, x, y, cs);
}
static void
process2(void **cp, float *x, float *y, int cs)
{
cha_agc_output(cp, x, y, cs);
}
//===========================================================
// prepare compressor
static void
prepare_compressor(CHA_PTR cp, int cs)
{
cha_chunk_size(cp, cs);
cha_agc_prepare(cp, &dsl, &agc);
}
static void
prepare(CHA_STA *state, void *v, MHA *mha, int entry)
{
int nc;
void **cp;
var_transfer(v);
cp = calloc(NPTR, sizeof(void *));
cha_prepare(cp);
prepare_compressor(cp, mha->cs);
cha_state_save(cp, state);
cha_cleanup(cp);
nc = pvl[icf].cols + 1;
if (entry == 0) {
state->proc = process0;
nchan[0] = 1;
nchan[1] = 1;
} else if (entry == 1) {
state->proc = process1;
nchan[0] = nc;
nchan[1] = nc;
} else if (entry == 2) {
state->proc = process2;
nchan[0] = 1;
nchan[1] = 1;
} else {
state->proc = NULL;
nchan[0] = 0;
nchan[1] = 0;
}
state->type = 0; // state type is "plugin"
state->entry = entry; // index of entry point
state->rprt = NULL;
}
//===========================================================
static void
configure_compressor()
{
// DSL prescription example
static CHA_DSL dsl_ex = {5, 50, 119, 0, 8,
{317.1666,502.9734,797.6319,1264.9,2005.9,3181.1,5044.7},
{-13.5942,-16.5909,-3.7978,6.6176,11.3050,23.7183,35.8586,37.3885},
{0.7,0.9,1,1.1,1.2,1.4,1.6,1.7},
{32.2,26.5,26.7,26.7,29.8,33.6,34.3,32.7},
{78.7667,88.2,90.7,92.8333,98.2,103.3,101.9,99.8}
};
static CHA_WDRC agc_ex = {1, 50, 24000, 119, 0, 105, 10, 105};
memcpy(&dsl, &dsl_ex, sizeof(CHA_DSL));
memcpy(&agc, &agc_ex, sizeof(CHA_WDRC));
}
static void
configure(void *v, int *nv)
{
int nc;
// initialize local variables
configure_compressor();
// specify configurable parameters
nc = dsl.nchannel;
var_list_init(v);
put_list_i4a("nchan" , nchan, 2, 0); // read only
put_list_f8n("agc_attack" , &agc.attack);
put_list_f8n("agc_release" , &agc.release);
put_list_f8n("agc_maxdB" , &agc.maxdB);
put_list_f8n("agc_tkgain" , &agc.tkgain);
put_list_f8n("agc_tk" , &agc.tk);
put_list_f8n("agc_cr" , &agc.cr);
put_list_f8n("agc_bolt" , &agc.bolt);
put_list_i4n("dsl_ear" , &dsl.ear);
put_list_f8n("dsl_attack" , &dsl.attack);
put_list_f8n("dsl_release" , &dsl.release);
put_list_f8n("dsl_maxdB" , &dsl.maxdB);
put_list_f8a("dsl_tkgain" , dsl.tkgain, nc, DSL_MXCH);
put_list_f8a("dsl_tk" , dsl.tk, nc, DSL_MXCH);
put_list_f8a("dsl_cr" , dsl.cr, nc, DSL_MXCH);
put_list_f8a("dsl_bolt" , dsl.bolt, nc, DSL_MXCH);
put_list_f8a("cross_freq" , dsl.cross_freq, nc-1, DSL_MXCH);
icf = npv - 1; // index to cross_freq
var_list_return(nv);
}
void
agc_bind(PLUG* plugin)
{
plugin->configure = configure;
plugin->prepare = prepare;
}