chenlh
2026-03-20 f761b6198e2e98f02adb84c83dbf59529e51b2ef
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
#pragma once
 
#include <EffectProcessorBase.h>
#include <LinearInterpolationCircularBuffer.h>
#include <LFO.h>
 
/**
 * Base Class for Modulation Effect Processors
 * 
 */
template <typename SampleType>
class ModulationProcessor : public EffectProcessorBase<SampleType>
{
public:
    
    /**
     * @brief Sets modulation rate
     * 
     * @param newRate New rate value
     */
    virtual void setRate(SampleType newRate) = 0;
 
    /**
     * @brief Sets modulation depth
     * 
     * @param newDepth New depth value
     */
    virtual void setDepth(SampleType newDepth) = 0;
 
protected:
 
    SampleType doUnipolarModulationFromMin(SampleType unipolarModulatorValue, SampleType minValue, SampleType maxValue)
    {
        // --- UNIPOLAR bound
        unipolarModulatorValue = fmin(unipolarModulatorValue, 1.0f);
        unipolarModulatorValue = fmax(unipolarModulatorValue, 0.0f);
 
        // --- modulate from minimum value upwards
        return unipolarModulatorValue * (maxValue - minValue) + minValue;
    };
 
    SampleType bipolarToUnipolar(SampleType value)
    {
        return 0.5 * value + 0.5;
    };
 
protected:
    SampleType sampleRate;
    LinearInterpolationCircularBuffer<SampleType> delayLine;
    LFO lfo;
};