commit 8e94c7783738e5cf17b651c5d6e1d7437a9da579
parent 30710967d15f43778b0391a9151e2cb67f7edc31
Author: falkTX <falktx@falktx.com>
Date: Thu, 27 May 2021 13:44:57 +0100
Small fixing to metronome example, works again
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/examples/Metronome/ExamplePluginMetronome.cpp b/examples/Metronome/ExamplePluginMetronome.cpp
@@ -46,13 +46,15 @@ public:
- Single-pole IIR low-pass filter - which is the correct formula for the decay coefficient?
https://dsp.stackexchange.com/questions/54086/single-pole-iir-low-pass-filter-which-is-the-correct-formula-for-the-decay-coe
*/
- void setCutoff(float sampleRate, float cutoffHz) {
+ void setCutoff(const float sampleRate, const float cutoffHz)
+ {
double omega_c = 2.0 * M_PI * cutoffHz / sampleRate;
double y = 1.0 - std::cos(omega_c);
kp = float(-y + std::sqrt((y + 2.0) * y));
}
- float process(float input) {
+ inline float process(const float input)
+ {
return value += kp * (input - value);
}
};
@@ -77,6 +79,7 @@ public:
cent(0),
decayTime(0.2f)
{
+ sampleRateChanged(sampleRate);
}
protected:
@@ -158,7 +161,7 @@ protected:
case 0:
parameter.name = "Gain";
parameter.hints |= kParameterIsLogarithmic;
- parameter.ranges.min = 0.0f;
+ parameter.ranges.min = 0.001f;
parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.5f;
break;
@@ -237,6 +240,17 @@ protected:
* Process */
/**
+ Activate this plugin.
+ We use this to reset our filter states.
+ */
+ void activate() override
+ {
+ deltaPhaseSmoother.value = 0.0f;
+ envelopeSmoother.value = 0.0f;
+ gainSmoother.value = gain;
+ }
+
+ /**
Run/process function for plugins without MIDI input.
`inputs` is commented out because this plugin has no inputs.
*/
@@ -274,8 +288,8 @@ protected:
phase = 0.0f;
deltaPhaseSmoother.value = deltaPhase;
- gainSmoother.value = 1.0f;
envelopeSmoother.value = 0.0f;
+ gainSmoother.value = 0.0f;
}
for (uint32_t i = 0; i < frames; ++i)
@@ -336,8 +350,8 @@ private:
float decay; // Coefficient to decay envelope in a frame.
Smoother deltaPhaseSmoother;
- Smoother gainSmoother;
Smoother envelopeSmoother;
+ Smoother gainSmoother;
// Parameters.
float gain;
diff --git a/examples/Metronome/README.md b/examples/Metronome/README.md
@@ -2,7 +2,7 @@
This example will show tempo sync in DPF.<br/>
-This plugin will output sine wave at the start of every beat.<br/>
+This plugin will output a sine wave at the start of every beat.<br/>
The pitch of sine wave is 1 octave higher at the start of every bar.<br/>
4 parameters are avaialble:
@@ -17,15 +17,15 @@ To calculate frames to the next beat from the start of current audio buffer, fol
```c++
const TimePosition& timePos(getTimePosition());
-if (timePos.bbt.valid) {
+if (timePos.bbt.valid)
+{
double secondsPerBeat = 60.0 / timePos.bbt.beatsPerMinute;
double framesPerBeat = sampleRate * secondsPerBeat;
double beatFraction = timePos.bbt.tick / timePos.bbt.ticksPerBeat;
- uint32_t framesToNextBeat = beatFraction == 0.0
- ? 0
- : static_cast<uint32_t>(framesPerBeat * (1.0 - beatFraction));
-
+ uint32_t framesToNextBeat = d_isZero(beatFraction)
+ ? 0
+ : static_cast<uint32_t>(framesPerBeat * (1.0 - beatFraction));
// ...
}
```