Debian Codegraph @

plugins/LadspaEffect/swh/util/ls_filter.h

raw
1 #ifndef LS_FILTER_H
2 #define LS_FILTER_H
3
4 #include <util/biquad.h>
5
6 #define FILT_MIDI_2_FREQ(m) (m * 80.0f + 10.0f)
7 #define FILT_MIDI_2_RESO(m) (m * 0.00787f)
8
9 #define LSF_BW 0.9
10 #define LSF_FB 0.9f
11
12 typedef struct {
13 biquad filt;
14 biquad bp_filt;
15 bq_t scale;
16 bq_t resonance;
17 } ls_filt;
18
19 typedef enum {
20 LS_FILT_TYPE_LP = 0,
21 LS_FILT_TYPE_BP = 1,
22 LS_FILT_TYPE_HP = 2
23 } ls_filt_type;
24
25 static inline void ls_filt_init(ls_filt *f)
26 {
27 biquad_init(&(f->filt));
28 biquad_init(&(f->bp_filt));
29 }
30
31 static inline void ls_filt_setup(ls_filt *f, ls_filt_type t, bq_t cutoff,
32 bq_t resonance, bq_t fs)
33 {
34 bp_set_params(&(f->bp_filt), cutoff, 0.7, fs);
35
36 switch(t) {
37 case LS_FILT_TYPE_LP:
38 lp_set_params(&(f->filt), cutoff, 1.0 - resonance * LSF_BW, fs);
39 break;
40 case LS_FILT_TYPE_BP:
41 bp_set_params(&(f->filt), cutoff, 1.0 - resonance * LSF_BW, fs);
42 break;
43 case LS_FILT_TYPE_HP:
44 hp_set_params(&(f->filt), cutoff, 1.0 - resonance * LSF_BW, fs);
45 break;
46 default:
47 /* oops, its not a known type - should really happen, but
48 lets make the output silent just in case */
49 lp_set_params(&(f->filt), 1.0, 1.0, fs);
50 break;
51 }
52
53 f->scale = 1.0f - resonance * 0.7f;
54 f->resonance = resonance;
55 }
56
57 static inline bq_t ls_filt_run(ls_filt *f, bq_t in)
58 {
59 return biquad_run(&(f->filt), in) * f->scale +
60 biquad_run_fb(&(f->bp_filt), in, f->resonance * LSF_FB) *
61 f->resonance;
62 }
63
64 #endif