Browse Source

Small fixing to metronome example, works again

Signed-off-by: falkTX <falktx@falktx.com>
pull/281/head
falkTX 4 years ago
parent
commit
8e94c77837
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 25 additions and 11 deletions
  1. +19
    -5
      examples/Metronome/ExamplePluginMetronome.cpp
  2. +6
    -6
      examples/Metronome/README.md

+ 19
- 5
examples/Metronome/ExamplePluginMetronome.cpp View File

@@ -46,13 +46,15 @@ public:
- Single-pole IIR low-pass filter - which is the correct formula for the decay coefficient? - 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 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 omega_c = 2.0 * M_PI * cutoffHz / sampleRate;
double y = 1.0 - std::cos(omega_c); double y = 1.0 - std::cos(omega_c);
kp = float(-y + std::sqrt((y + 2.0) * y)); kp = float(-y + std::sqrt((y + 2.0) * y));
} }
float process(float input) {
inline float process(const float input)
{
return value += kp * (input - value); return value += kp * (input - value);
} }
}; };
@@ -77,6 +79,7 @@ public:
cent(0), cent(0),
decayTime(0.2f) decayTime(0.2f)
{ {
sampleRateChanged(sampleRate);
} }
protected: protected:
@@ -158,7 +161,7 @@ protected:
case 0: case 0:
parameter.name = "Gain"; parameter.name = "Gain";
parameter.hints |= kParameterIsLogarithmic; parameter.hints |= kParameterIsLogarithmic;
parameter.ranges.min = 0.0f;
parameter.ranges.min = 0.001f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.5f; parameter.ranges.def = 0.5f;
break; break;
@@ -236,6 +239,17 @@ protected:
/* -------------------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------------------
* Process */ * 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. Run/process function for plugins without MIDI input.
`inputs` is commented out because this plugin has no inputs. `inputs` is commented out because this plugin has no inputs.
@@ -274,8 +288,8 @@ protected:
phase = 0.0f; phase = 0.0f;
deltaPhaseSmoother.value = deltaPhase; deltaPhaseSmoother.value = deltaPhase;
gainSmoother.value = 1.0f;
envelopeSmoother.value = 0.0f; envelopeSmoother.value = 0.0f;
gainSmoother.value = 0.0f;
} }
for (uint32_t i = 0; i < frames; ++i) for (uint32_t i = 0; i < frames; ++i)
@@ -336,8 +350,8 @@ private:
float decay; // Coefficient to decay envelope in a frame. float decay; // Coefficient to decay envelope in a frame.
Smoother deltaPhaseSmoother; Smoother deltaPhaseSmoother;
Smoother gainSmoother;
Smoother envelopeSmoother; Smoother envelopeSmoother;
Smoother gainSmoother;
// Parameters. // Parameters.
float gain; float gain;


+ 6
- 6
examples/Metronome/README.md View File

@@ -2,7 +2,7 @@


This example will show tempo sync in DPF.<br/> 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/> The pitch of sine wave is 1 octave higher at the start of every bar.<br/>


4 parameters are avaialble: 4 parameters are avaialble:
@@ -17,15 +17,15 @@ To calculate frames to the next beat from the start of current audio buffer, fol
```c++ ```c++
const TimePosition& timePos(getTimePosition()); const TimePosition& timePos(getTimePosition());


if (timePos.bbt.valid) {
if (timePos.bbt.valid)
{
double secondsPerBeat = 60.0 / timePos.bbt.beatsPerMinute; double secondsPerBeat = 60.0 / timePos.bbt.beatsPerMinute;
double framesPerBeat = sampleRate * secondsPerBeat; double framesPerBeat = sampleRate * secondsPerBeat;
double beatFraction = timePos.bbt.tick / timePos.bbt.ticksPerBeat; 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));
// ... // ...
} }
``` ```


Loading…
Cancel
Save