[feat]: Filter LFO (#23)
Reviewed-on: #23 Co-authored-by: HiveBeats <e1lama@protonmail.com> Co-committed-by: HiveBeats <e1lama@protonmail.com>
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Filter.h"
|
||||
|
||||
class BandPassFilter : public Filter {
|
||||
private:
|
||||
void CalculateCoefficients() override;
|
||||
protected:
|
||||
float GetSampleForFilterType() override;
|
||||
|
||||
public:
|
||||
BandPassFilter();
|
||||
BandPassFilter(Filter* filter);
|
||||
BandPassFilter(float freq, float res, float q);
|
||||
BandPassFilter(/* args */);
|
||||
~BandPassFilter();
|
||||
bool IsSameFilterType(FilterType type) override { return type == BandPass; };
|
||||
};
|
||||
|
||||
|
||||
|
||||
41
inc/Filter.h
41
inc/Filter.h
@@ -1,24 +1,25 @@
|
||||
#pragma once
|
||||
#include "IEffect.h"
|
||||
#include "Settings.h"
|
||||
|
||||
enum FilterType {
|
||||
LowPass,
|
||||
BandPass,
|
||||
HighPass
|
||||
};
|
||||
enum FilterType { LowPass, BandPass, HighPass };
|
||||
|
||||
class Filter : public IEffect {
|
||||
protected:
|
||||
float m_freq; // cutoff frequency
|
||||
float m_q; // filter quantity (resonance)
|
||||
float m_order; // filter order (peakGain)
|
||||
/* todo: filter adsr */
|
||||
float m_norm, m_v, m_k;
|
||||
float m_a0, m_a1, m_a2, m_b1, m_b2;
|
||||
float m_z1, m_z2;
|
||||
|
||||
void CalculateNormals();
|
||||
virtual void CalculateCoefficients(){};
|
||||
// float* m_output; // output buffer
|
||||
float m_fs = SAMPLE_RATE; // sampling frequency;
|
||||
float m_fc; // cutoff frequency normally something like: 440.0*pow(2.0,
|
||||
// (midi_note - 69.0)/12.0);
|
||||
float m_res; // resonance 0 to 1;
|
||||
float m_drive; // internal distortion 0 to 0.1
|
||||
float m_freq;
|
||||
float m_damp;
|
||||
float m_notcho; // notch output
|
||||
float m_lowo; // low pass output
|
||||
float m_higho; // high pass output
|
||||
float m_bando; // band pass output
|
||||
float m_peako; // peaking output = low - high
|
||||
virtual float GetSampleForFilterType(){ return 0.0; };
|
||||
|
||||
public:
|
||||
Filter(/* args */);
|
||||
@@ -27,9 +28,9 @@ class Filter : public IEffect {
|
||||
void Release() override final;
|
||||
float Process(float in);
|
||||
void Process(std::vector<float>& samples) override final;
|
||||
void SetParameters(float freq, float res, float q);
|
||||
float GetFreq() { return m_freq; }
|
||||
float GetRes() { return m_q; }
|
||||
float GetPeakGain() { return m_norm; }
|
||||
virtual bool IsSameFilterType(FilterType type){ return false; };
|
||||
void SetParameters(float freq, float res, float drive);
|
||||
float GetFreq() { return m_fc; }
|
||||
float GetRes() { return m_res; }
|
||||
float GetPeakGain() { return m_drive; }
|
||||
virtual bool IsSameFilterType(FilterType type) { return false; };
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "Filter.h"
|
||||
|
||||
class HighPassFilter : public Filter {
|
||||
private:
|
||||
void CalculateCoefficients() override;
|
||||
protected:
|
||||
float GetSampleForFilterType() override;
|
||||
|
||||
public:
|
||||
HighPassFilter();
|
||||
|
||||
@@ -11,10 +11,3 @@ public:
|
||||
void SetFreq(float freq) { m_phase_dt = (this->*m_dt_function)(freq); }
|
||||
};
|
||||
|
||||
LFO::LFO(/* args */): Oscillator(Sine, 0.f, 0.5f)
|
||||
{
|
||||
}
|
||||
|
||||
LFO::~LFO()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
class LowPassFilter : public Filter {
|
||||
protected:
|
||||
void CalculateCoefficients() override;
|
||||
float GetSampleForFilterType() override;
|
||||
|
||||
public:
|
||||
LowPassFilter();
|
||||
@@ -13,3 +13,4 @@ class LowPassFilter : public Filter {
|
||||
~LowPassFilter();
|
||||
bool IsSameFilterType(FilterType type) override { return type == LowPass; };
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Oscillator.h"
|
||||
#include "Settings.h"
|
||||
#include <vector>
|
||||
#include "LFO.h"
|
||||
|
||||
class Synth {
|
||||
private:
|
||||
@@ -15,7 +16,7 @@ class Synth {
|
||||
std::vector<Oscillator*> m_oscillators;
|
||||
std::vector<IEffect*> m_effects;
|
||||
std::vector<float> m_out_signal;
|
||||
Oscillator* m_lfo;
|
||||
LFO* m_lfo;
|
||||
void ZeroSignal();
|
||||
void GetNote();
|
||||
void TriggerNoteOnEffects();
|
||||
|
||||
Reference in New Issue
Block a user