Skip to content

Commit fd68c2e

Browse files
* Added filter gain compensation parameter
- No longer hard-wired to 0.5 (50%)
1 parent d8ba1dc commit fd68c2e

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

Filter.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ float CubicSaturate(float const x)
3636
#define Saturate(x) FastTanh(x)
3737
//#define Saturate(x) tanhf(x)
3838

39-
// compensate for reduced gain at low frequencies as resonance increases
40-
// 0.0: no compensation, -12dB at low frequencies
41-
// 0.5: half compensation, -6dB at low frequencies
42-
// 1.0: full compensation, -0dB at low frequencies
43-
static float const GAIN_COMPENSATION = 0.5f;
44-
4539
// filter configuration
46-
FilterConfig flt_config(false, FilterConfig::LOWPASS_4, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
40+
FilterConfig flt_config(false, FilterConfig::LOWPASS_4, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
4741

4842
// filter envelope config
4943
EnvelopeConfig flt_env_config(false, 0.0f, 1.0f, 0.0f, 0.1f);
@@ -303,7 +297,7 @@ void FilterState::Setup(float const cutoff, float const resonance, float const s
303297
float FilterState::Update(FilterConfig const &config, float const input)
304298
{
305299
// input with drive and gain compensation
306-
float const input_adjusted = config.drive * (input + input * feedback * GAIN_COMPENSATION);
300+
float const input_adjusted = input * config.drive * (1.0f + feedback * config.compensation);
307301

308302
#if FILTER == FILTER_IMPROVED_MOOG
309303

Filter.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class FilterConfig
5656
// drive parameter
5757
float drive;
5858

59+
// gain compensation
60+
float compensation;
61+
5962
// resonance parameter
6063
float resonance;
6164

@@ -68,9 +71,10 @@ class FilterConfig
6871
// key follow
6972
float key_follow;
7073

71-
FilterConfig(bool const enable, Mode const mode, float const drive, float const resonance, float const cutoff_base, float const cutoff_lfo, float const cutoff_env, float const cutoff_env_vel, float const key_follow)
74+
FilterConfig(bool const enable, Mode const mode, float const drive, float const compensation, float const resonance, float const cutoff_base, float const cutoff_lfo, float const cutoff_env, float const cutoff_env_vel, float const key_follow)
7275
: enable(enable)
7376
, drive(drive)
77+
, compensation(compensation)
7478
, resonance(resonance)
7579
, cutoff_base(cutoff_base)
7680
, cutoff_lfo(cutoff_lfo)

MenuFLT.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ namespace Menu
3030
case DRIVE:
3131
UpdatePercentageProperty(flt_config.drive, sign, modifiers, 0, 10);
3232
break;
33+
case COMPENSATION:
34+
UpdatePercentageProperty(flt_config.compensation, sign, modifiers, 0, 1);
35+
break;
3336
case RESONANCE:
3437
UpdatePercentageProperty(flt_config.resonance, sign, modifiers, 0, 4);
3538
break;
@@ -81,6 +84,9 @@ namespace Menu
8184
case DRIVE:
8285
PrintItemFloat(hOut, pos, flags, "Drive: % 7.1f%%", flt_config.drive * 100.0f);
8386
break;
87+
case COMPENSATION:
88+
PrintItemFloat(hOut, pos, flags, "Gain Comp:% 7.1f%%", flt_config.compensation * 100.0f);
89+
break;
8490
case RESONANCE:
8591
PrintItemFloat(hOut, pos, flags, "Resonance:% 7.1f%%", flt_config.resonance * 100.0f);
8692
break;

MenuFLT.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Menu
1818
TITLE,
1919
MODE,
2020
DRIVE,
21+
COMPENSATION,
2122
RESONANCE,
2223
CUTOFF_BASE,
2324
CUTOFF_LFO,

0 commit comments

Comments
 (0)