-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
51 lines (40 loc) · 1.21 KB
/
main.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
#include "usermodfx.h"
#include "dsp/biquad.h"
#define k_samplerate_recipf (2.08333333333333e-005f)
static biquad bq;
static biquad *bqp = &bq;
static float freq;
static float res;
void MODFX_INIT(uint32_t platform, uint32_t api) {
(void)platform; (void)api;
biquad_flush(bqp);
}
void MODFX_PROCESS(const float *main_xn, float *main_yn,
const float *sub_xn, float *sub_yn,
uint32_t frames) {
(void)*sub_xn; (void)*sub_yn;
for (uint32_t i = 0; i < frames; i++) {
const float in_l = main_xn[i * 2];
const float in_r = main_xn[i * 2 + 1];
const float out_m = biquad_process_so(bqp, (in_l + in_r) / 2);
main_yn[i * 2] = out_m;
main_yn[i * 2 + 1] = out_m;
}
}
void MODFX_PARAM(uint8_t idx, int32_t val) {
const float val_f = q31_to_f32(val);
switch (idx) {
case k_user_modfx_param_time:
freq = 40.0f + (clip01f(-0.1f * fastlog2f(clip01f(1.0f - val_f)))) * 16000;
break;
case k_user_modfx_param_depth:
res = 1.0f + val_f * 9.0f;
break;
default:
break;
}
biquad_so_lp(bqp,
fasttanfullf(M_PI * biquad_wc(freq,
k_samplerate_recipf)),
res);
}